Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLCT comparator code calculation (CCLUT-5) #30103

Merged
merged 3 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions L1Trigger/CSCTriggerPrimitives/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The C++ code is located in `L1Trigger/CSCTriggerPrimitives/src/` and `L1Trigger/

The `plugins/` directory contains the producer module `CSCTriggerPrimitivesProducer`. The `CSCTriggerPrimitivesReader` should be used for firmware vs emulator comparisons.

The `src/` directory contains the builder `CSCTriggerPrimitivesBuilder`, processors (`CSCAnodeLCTProcessor`, `CSCCathodeLCTProcessor`, `GEMCoPadProcessor`), motherboards (`CSCMotherboard` and similar names), a muon port card (`CSCMuonPortCard`), auxiliary classes to produce and access look-up-tables (`CSCUpgradeMotherboardLUT` and `CSCUpgradeMotherboardLUTGenerator`) and a module to fit a straight line to comparator digis (`CSCComparatorDigiFitter`). Trigger patterns are stored in `CSCPatternBank`.
The `src/` directory contains the builder `CSCTriggerPrimitivesBuilder`, processors (`CSCAnodeLCTProcessor`, `CSCCathodeLCTProcessor`, `GEMCoPadProcessor`), motherboards (`CSCMotherboard` and similar names), a muon port card (`CSCMuonPortCard`), auxiliary classes to produce and access look-up-tables (`CSCUpgradeMotherboardLUT` and `CSCUpgradeMotherboardLUTGenerator`). Trigger patterns are stored in `CSCPatternBank`.

The `CSCTriggerPrimitivesBuilder` instantiates the TMBs for each chamber and the MPCs for each trigger sector. TMBs and MPC are organized in trigger sectors. A trigger sector has 9 associated TMBs and a single MPC. Once instantiated, the TMBs are configured and run according to settings defined `cscTriggerPrimitiveDigis_cfi` (see Configuration). After running the TMB the ALCT/CLCT/LCT collections are read out and put into the event. After all TMBs are run, the MPCs produce LCTs to be sent to the OMTF and EMTF.

Expand All @@ -37,7 +37,7 @@ The `CSCMuonPortCard` class collects LCTs from a trigger sector and relays them

The `CSCUpgradeMotherboardLUTGenerator` and `CSCUpgradeMotherboardLUT` produce and contain look-up-tables that are used in the CSC upgrade algorithm and/or the GEM-CSC algorithm.

The `CSCComparatorDigiFitter` is a relatively new feature in CSC trigger. It fits a straight line to a set of comparator digis associated to an LCT. The fitted LCT position has a resolution which is better by about a factor 2 than for non-fitted LCTs. This module will at some point be integrated into the `CSCCathodeLCTProcessor` to produce CLCTs with a better position resolution. Better LCT position is critical to reconstruct L1 muons for displaced signatures, one of the cornerstones of the Phase-2 muon upgrade.
A new class is `CSCComparatorCodeLUT` which provides access to look-up-tables for improved local bending and position in Run-3 (CCLUT). Better LCT position and bending is critical to reconstruct L1 muons for displaced signatures, one of the cornerstones of the Phase-2 muon upgrade.

The `test/` directory contains python configuration to test the CSC local trigger and analyzer the data.

Expand Down Expand Up @@ -96,3 +96,8 @@ Recent work includes:
* The removal of outdated classes `CSCTriggerGeometry` and `CSCTriggerGeomManager` (https://github.com/cms-sw/cmssw/pull/21655)
* The removal of a lot of outdated code (https://github.com/cms-sw/cmssw/pull/24171), which was used for very early MC studies (early 2000s) or to emulate beam-test data from the Magnet Test and Cosmic Challenge (MTCC - 2006). In case you need to look back at this code, please look at the [CMSSW_10_2_X branch](https://github.com/cms-sw/cmssw/tree/CMSSW_10_2_X/L1Trigger/CSCTriggerPrimitives).
* The removal of an outdated DQM module (https://github.com/cms-sw/cmssw/pull/24196).
* The removal of pre-2007 code (https://github.com/cms-sw/cmssw/pull/24254)
* Implementation of a common baseboard class (https://github.com/cms-sw/cmssw/pull/24403)
* Update GE1/1-ME1/1 and GE2/1-ME2/1 local triggers (https://github.com/cms-sw/cmssw/pull/27957, https://github.com/cms-sw/cmssw/pull/28334, https://github.com/cms-sw/cmssw/pull/28605)
* Improvements to the CLCT algorithm following data vs emulator studies Summer and Fall of 2018 (https://github.com/cms-sw/cmssw/pull/25165)
* Implementation of the CCLUT algorithm (https://github.com/cms-sw/cmssw/pull/28044, https://github.com/cms-sw/cmssw/pull/28600, https://github.com/cms-sw/cmssw/pull/29205, https://github.com/cms-sw/cmssw/pull/28846)
30 changes: 26 additions & 4 deletions L1Trigger/CSCTriggerPrimitives/interface/CSCCathodeLCTProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
#include "DataFormats/CSCDigi/interface/CSCCLCTDigi.h"
#include "DataFormats/CSCDigi/interface/CSCCLCTPreTriggerDigi.h"
#include "L1Trigger/CSCTriggerPrimitives/interface/CSCBaseboard.h"
#include "L1Trigger/CSCTriggerPrimitives/interface/CSCComparatorCodeLUT.h"

#include <vector>
#include <array>
#include <string>

class CSCCathodeLCTProcessor : public CSCBaseboard {
public:
Expand Down Expand Up @@ -88,6 +91,10 @@ class CSCCathodeLCTProcessor : public CSCBaseboard {
/** LCTs in this chamber, as found by the processor. */
CSCCLCTDigi CLCTContainer_[CSCConstants::MAX_CLCT_TBINS][CSCConstants::MAX_CLCTS_PER_PROCESSOR];

// unique pointers to the luts
std::array<std::unique_ptr<CSCComparatorCodeLUT>, 5> lutpos_;
std::array<std::unique_ptr<CSCComparatorCodeLUT>, 5> lutslope_;

/** Access routines to comparator digis. */
bool getDigis(const CSCComparatorDigiCollection* compdc);
void getDigis(const CSCComparatorDigiCollection* compdc, const CSCDetId& id);
Expand Down Expand Up @@ -125,7 +132,7 @@ class CSCCathodeLCTProcessor : public CSCBaseboard {
// enum used in the comparator code logic
enum CLCT_CompCode { INVALID_HALFSTRIP = 65535 };

void cleanComparatorContainer(CSCCLCTDigi::ComparatorContainer& compHits) const;
void cleanComparatorContainer(CSCCLCTDigi& lct) const;

/* Mark the half-strips around the best half-strip as busy */
void markBusyKeys(const int best_hstrip, const int best_patid, int quality[CSCConstants::NUM_HALF_STRIPS_7CFEBS]);
Expand All @@ -138,6 +145,19 @@ class CSCCathodeLCTProcessor : public CSCBaseboard {
void dumpDigis(const std::vector<int> strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS],
const int nStrips) const;

// --------Functions for the comparator code algorith for Run-3 ---------//
//calculates the id based on location of hits
int calculateComparatorCode(const std::array<std::array<int, 3>, 6>& halfStripPattern) const;

// sets the 1/4 and 1/8 strip bits given a floating point position offset
void calculatePositionCC(float offset, uint16_t& halfstrip, bool& quartstrip, bool& eightstrip) const;

// converts the floating point slope into integer slope
int calculateSlopeCC(float slope, int nBits) const;

// runs the CCLUT procedure
void runCCLUT(CSCCLCTDigi& digi) const;

//--------------------------- Member variables -----------------------------

/* best pattern Id for a given half-strip */
Expand Down Expand Up @@ -196,9 +216,8 @@ class CSCCathodeLCTProcessor : public CSCBaseboard {
// Use the new patterns according to the comparator code format
bool use_run3_patterns_;
bool use_comparator_codes_;

// which hits per CLCT?
PulseArray hitsCLCT[99];
unsigned int nbits_position_cc_;
unsigned int nbits_slope_cc_;

/** Default values of configuration parameters. */
static const unsigned int def_fifo_tbins, def_fifo_pretrig;
Expand All @@ -207,6 +226,9 @@ class CSCCathodeLCTProcessor : public CSCBaseboard {
static const unsigned int def_nplanes_hit_pattern;
static const unsigned int def_pid_thresh_pretrig, def_min_separation;
static const unsigned int def_tmb_l1a_window_size;

std::vector<std::string> positionLUTFiles_;
std::vector<std::string> slopeLUTFiles_;
};

#endif
67 changes: 67 additions & 0 deletions L1Trigger/CSCTriggerPrimitives/interface/CSCComparatorCodeLUT.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef L1Trigger_CSCTriggerPrimitives_CSCComparatorCodeLUT
#define L1Trigger_CSCTriggerPrimitives_CSCComparatorCodeLUT

#include <fstream>
#include <sstream>
#include <bitset>
#include <iostream>
#include <vector>
#include <limits>

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

class CSCComparatorCodeLUT {
public:
enum ReadCodes {
SUCCESS = 0,
NO_ENTRIES = 1,
DUP_ENTRIES = 2,
MISS_ENTRIES = 3,
MAX_ADDRESS_OUTOFRANGE = 4,
NO_HEADER = 5
};

/* CSCComparatorCodeLUT(); */
explicit CSCComparatorCodeLUT(const std::string&);
/* explicit CSCComparatorCodeLUT(l1t::LUT*); */
~CSCComparatorCodeLUT() {}

float lookup(int code) const;
float lookupPacked(const int input) const;

// populates the map.
void initialize();

unsigned checkedInput(unsigned in, unsigned maxWidth) const;

// I/O functions
void save(std::ofstream& output);
int load(const std::string& inFileName);

float data(unsigned int address) const;
int read(std::istream& stream);
void write(std::ostream& stream) const;

unsigned int nrBitsAddress() const { return nrBitsAddress_; }
unsigned int nrBitsData() const { return nrBitsData_; }
//following the convention of vector::size()
unsigned int maxSize() const;
bool empty() const { return data_.empty(); }

private:
int readHeader(std::istream&);

unsigned int nrBitsAddress_; //technically redundant with addressMask
unsigned int nrBitsData_; //technically redundant with dataMask
unsigned int addressMask_;
unsigned int dataMask_;

std::vector<float> data_;

int m_codeInWidth;
unsigned m_outWidth;
bool m_initialized;
};

#endif
3 changes: 3 additions & 0 deletions L1Trigger/CSCTriggerPrimitives/interface/CSCMotherboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ class CSCMotherboard : public CSCBaseboard {
unsigned int highMultiplicityBits_;
bool useHighMultiplicityBits_;

// Use the new patterns according to the comparator code format
bool use_run3_patterns_;

/** Default values of configuration parameters. */
static const unsigned int def_mpc_block_me1a;
static const unsigned int def_alct_trig_enable, def_clct_trig_enable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@
# Write out pre-triggers
savePreTriggers = cms.bool(False),

positionLUTFiles = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/CSCComparatorCodePosOffsetLUT_pat0_ideal_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CSCComparatorCodePosOffsetLUT_pat1_ideal_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CSCComparatorCodePosOffsetLUT_pat2_ideal_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CSCComparatorCodePosOffsetLUT_pat3_ideal_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CSCComparatorCodePosOffsetLUT_pat4_ideal_v1.txt"
),

slopeLUTFiles = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/CSCComparatorCodeSlopeLUT_pat0_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CSCComparatorCodeSlopeLUT_pat1_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CSCComparatorCodeSlopeLUT_pat2_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CSCComparatorCodeSlopeLUT_pat3_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CSCComparatorCodeSlopeLUT_pat4_v1.txt"
),

# Parameters common for all boards
commonParam = cms.PSet(
# Master flag for SLHC studies
Expand Down Expand Up @@ -165,6 +181,8 @@
useRun3Patterns = cms.bool(False),

useComparatorCodes = cms.bool(False),
nBitsPositionCC = cms.uint32(10),
nBitsSlopeCC = cms.uint32(5)
),

# Parameters for CLCT processors: SLHC studies
Expand Down Expand Up @@ -211,6 +229,9 @@
useRun3Patterns = cms.bool(False),

useComparatorCodes = cms.bool(False),

nBitsPositionCC = cms.uint32(10),
nBitsSlopeCC = cms.uint32(5)
),

tmbParam = cms.PSet(
Expand Down
Loading