28 static std::atomic<bool> config_dumped{
false};
77 if ((
infoV > 0) && !config_dumped) {
85 if ((i_layer + 1) % 2 == 0)
99 cclut_ = std::make_unique<ComparatorCodeLUT>(conf.
conf());
105 thresholds_ = shower.getParameter<std::vector<unsigned>>(
"showerThresholds");
108 peakCheck_ = shower.getParameter<
bool>(
"peakCheck");
136 static std::atomic<bool> config_dumped{
false};
149 if (!config_dumped) {
151 config_dumped =
true;
163 static const unsigned int max_fifo_tbins = 1 << 5;
164 static const unsigned int max_fifo_pretrig = 1 << 5;
165 static const unsigned int max_hit_persist = 1 << 4;
166 static const unsigned int max_drift_delay = 1 << 2;
167 static const unsigned int max_nplanes_hit_pretrig = 1 << 3;
168 static const unsigned int max_nplanes_hit_pattern = 1 << 3;
169 static const unsigned int max_pid_thresh_pretrig = 1 << 4;
171 static const unsigned int max_tmb_l1a_window_size = 1 << 4;
206 static std::atomic<bool> config_dumped{
false};
207 if ((
infoV > 0) && !config_dumped) {
209 config_dumped =
true;
227 <<
"+++ Invalid ring number for this processor " <<
theRing <<
" was set in the config." 229 <<
"+++ CSC geometry looks garbled; no emulation possible +++\n";
247 <<
"+++ CSC geometry looks garbled; no emulation possible +++\n";
272 <<
" is not defined in current geometry! +++\n" 273 <<
"+++ CSC geometry looks garbled; no emulation possible +++\n";
284 <<
" numStrips_ = " <<
numStrips_ <<
"; CLCT emulation skipped! +++";
285 std::vector<CSCCLCTDigi> emptyV;
303 unsigned int layersHit = 0;
306 if (!halfStripTimes[i_layer][i_hstrip].
empty()) {
323 std::vector<CSCCLCTDigi> tmpV =
getCLCTs();
332 for (
auto&
p : tmpV) {
351 std::vector<CSCCLCTDigi> CLCTlist =
findLCTs(halfstrip);
353 for (
const auto&
p : CLCTlist) {
354 const int bx =
p.getBX();
359 <<
"; skipping it... +++\n";
418 for (
int hstrip = minHS; hstrip < maxHS; hstrip++) {
426 LogDebug(
"CSCCathodeLCTProcessor") <<
" bx " <<
bx <<
" bestCLCT key HS " << keyHS
427 <<
" localshower zone: " << minHS <<
", " << maxHS <<
" totalHits " 434 bool hasDigis =
false;
438 digiV[i_layer].clear();
451 LogTrace(
"CSCCathodeLCTProcessor") <<
"found " <<
digiV[i_layer].size() <<
" comparator digi(s) in layer " 462 const bool me1a = (
id.station() == 1) && (
id.
ring() == 4);
465 const unsigned int origStrip = digiIt->getStrip();
466 const unsigned int maxStripsME1a =
470 if (me1a && origStrip <= maxStripsME1a && !
disableME1a_) {
475 digiV[
id.layer() - 1].push_back(digi_corr);
477 digiV[
id.layer() - 1].push_back(*digiIt);
486 for (std::vector<CSCComparatorDigi>::iterator pld =
digiV[i_layer].begin(); pld !=
digiV[i_layer].end();
490 std::ostringstream strstrm;
491 strstrm <<
"Comparator digi: comparator = " << pld->getComparator() <<
" strip #" << pld->getStrip()
493 std::vector<int> bx_times = pld->getTimeBinsOn();
494 for (
unsigned int tbin = 0; tbin < bx_times.size(); tbin++)
495 strstrm <<
" " << bx_times[tbin];
496 LogTrace(
"CSCCathodeLCTProcessor") << strstrm.str();
501 int thisComparator = pld->getComparator();
502 if (thisComparator != 0 && thisComparator != 1) {
506 <<
" Found comparator digi with wrong comparator value = " << thisComparator <<
"; skipping it... +++\n";
511 int thisStrip = pld->getStrip() - 1;
512 if (thisStrip < 0 || thisStrip >=
numStrips_) {
516 <<
" Found comparator digi with wrong strip number = " << thisStrip <<
" (max strips = " <<
numStrips_ 517 <<
"); skipping it... +++\n";
523 int thisHalfstrip = 2 * thisStrip + thisComparator +
stagger[i_layer];
528 <<
" Found wrong halfstrip number = " << thisHalfstrip <<
"; skipping this digi... +++\n";
533 std::vector<int> bx_times = pld->getTimeBinsOn();
534 for (
unsigned int i = 0;
i < bx_times.size();
i++) {
544 if (bx_times[
i] > 1 && bx_times[
i] < static_cast<int>(
fifo_tbins)) {
545 if (
i == 0 || (
i > 0 && bx_times[
i] - bx_times[
i - 1] >= static_cast<int>(
hit_persist))) {
551 <<
"Comp digi: layer " << i_layer + 1 <<
" digi #" << i_digi + 1 <<
" strip " << thisStrip
552 <<
" halfstrip " << thisHalfstrip <<
" time " << bx_times[
i] <<
" comparator " << thisComparator
553 <<
" stagger " <<
stagger[i_layer];
554 halfstrip[i_layer][thisHalfstrip].push_back(bx_times[
i]);
559 <<
" Skipping comparator digi: strip = " << thisStrip <<
", layer = " << i_layer + 1
560 <<
", bx = " << bx_times[
i] <<
", bx of previous hit = " << bx_times[
i - 1];
565 <<
theChamber <<
"+++ Skipping comparator digi: strip = " << thisStrip
566 <<
", layer = " << i_layer + 1 <<
", bx = " << bx_times[
i] <<
" +++";
576 std::vector<CSCCLCTDigi> lctList;
589 while (start_bx < stop_bx) {
597 bool pre_trig =
preTrigger(start_bx, first_bx);
604 LogTrace(
"CSCCathodeLCTProcessor") <<
"..... pretrigger at bx = " << first_bx <<
"; waiting drift delay .....";
615 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>> hits_in_patterns;
616 hits_in_patterns.clear();
624 if (
nhits[hstrip] > 0) {
626 <<
" bx = " << std::setw(2) << latch_bx <<
" --->" 627 <<
" halfstrip = " << std::setw(3) << hstrip <<
" best pid = " << std::setw(2) <<
best_pid[hstrip]
628 <<
" nhits = " <<
nhits[hstrip];
646 best_halfstrip[ilct] = -1;
647 best_quality[ilct] = 0;
657 if (
quality[hstrip] > best_quality[0]) {
658 best_halfstrip[0] = hstrip;
659 best_quality[0] =
quality[hstrip];
662 const int best_hs(best_halfstrip[0]);
672 if (best_halfstrip[0] >= 0) {
683 if (
quality[hstrip] > best_quality[1]) {
684 best_halfstrip[1] = hstrip;
685 best_quality[1] =
quality[hstrip];
688 const int best_hs(best_halfstrip[1]);
699 bool changeOrder =
false;
701 unsigned qualityBest = 0, qualitySecond = 0;
702 unsigned patternBest = 0, patternSecond = 0;
703 unsigned halfStripBest = 0, halfStripSecond = 0;
718 if (qualitySecond > qualityBest)
720 else if ((qualitySecond == qualityBest) and (
int(patternSecond / 2) >
int(patternBest / 2)))
722 else if ((qualitySecond == qualityBest) and (
int(patternSecond / 2) ==
int(patternBest / 2)) and
723 (halfStripSecond < halfStripBest))
729 tempCLCT = tempBestCLCT;
730 tempBestCLCT = tempSecondCLCT;
731 tempSecondCLCT = tempCLCT;
736 lctList.push_back(tempBestCLCT);
738 if (tempSecondCLCT.
isValid()) {
739 lctList.push_back(tempSecondCLCT);
753 for (
unsigned int bx = latch_bx + 1;
bx < stop_time;
bx++) {
754 bool return_to_idle =
true;
761 LogTrace(
"CSCCathodeLCTProcessor") <<
" State machine busy at bx = " <<
bx;
762 return_to_idle =
false;
767 if (return_to_idle) {
769 LogTrace(
"CSCCathodeLCTProcessor") <<
" State machine returns to idle state at bx = " <<
bx;
776 start_bx = first_bx + 1;
804 std::vector<int> bx_times =
time[i_layer][i_strip];
805 for (
unsigned int i = 0;
i < bx_times.size();
i++) {
807 if (bx_times[
i] < 0 || bx_times[
i] +
hit_persist >= bits_in_pulse) {
810 <<
"+++ BX time of comparator digi (halfstrip = " << i_strip <<
" layer = " << i_layer
811 <<
") bx = " << bx_times[
i] <<
" is not within the range (0-" << bits_in_pulse
812 <<
"] allowed for pulse extension. Skip this digi! +++\n";
827 LogTrace(
"CSCCathodeLCTProcessor") <<
"....................PreTrigger...........................";
829 int nPreTriggers = 0;
831 bool pre_trig =
false;
833 for (
unsigned int bx_time = start_bx; bx_time <
fifo_tbins; bx_time++) {
840 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>> hits_in_patterns;
841 hits_in_patterns.clear();
851 if (
nhits[hstrip] > 0) {
853 <<
" bx = " << std::setw(2) << bx_time <<
" --->" 854 <<
" halfstrip = " << std::setw(3) << hstrip <<
" best pid = " << std::setw(2) <<
best_pid[hstrip]
855 <<
" nhits = " <<
nhits[hstrip];
878 LogTrace(
"CSCCathodeLCTProcessor") <<
"no pretrigger, returning \n";
885 const unsigned int bx_time,
std::map<
int, std::map<int, CSCCLCTDigi::ComparatorContainer>>& hits_in_patterns) {
893 for (
int key_hstrip = 0; key_hstrip <
numHalfStrips_; key_hstrip++) {
895 nhits[key_hstrip] = 0;
907 hit_layer[ilayer] =
false;
912 hits_single_pattern.resize(6);
913 for (
auto&
p : hits_single_pattern) {
918 double num_pattern_hits = 0., times_sum = 0.;
919 std::multiset<int> mset_for_median;
920 mset_for_median.clear();
936 LogTrace(
"CSCCathodeLCTProcessor") <<
" In patternFinding: key_strip = " << key_hstrip <<
" pid = " << pid
937 <<
" layer = " << this_layer <<
" strip = " << this_strip << std::endl;
941 if (hit_layer[this_layer] ==
false) {
942 hit_layer[this_layer] =
true;
945 hits_single_pattern[this_layer][strip_num] = this_strip -
stagger[this_layer];
950 int first_bx_layer = bx_time;
951 for (
unsigned int dbx = 0; dbx <
hit_persist; dbx++) {
957 times_sum += (double)first_bx_layer;
958 num_pattern_hits += 1.;
959 mset_for_median.insert(first_bx_layer);
961 LogTrace(
"CSCCathodeLCTProcessor") <<
" 1st bx in layer: " << first_bx_layer <<
" sum bx: " << times_sum
962 <<
" #pat. hits: " << num_pattern_hits;
970 hits_in_patterns[key_hstrip][pid] = hits_single_pattern;
974 if (layers_hit >
nhits[key_hstrip]) {
976 nhits[key_hstrip] = layers_hit;
992 const int best_patid,
997 for (
int hstrip = best_hstrip - nspan; hstrip <= best_hstrip + pspan; hstrip++) {
1005 const unsigned halfstrip_withstagger,
1042 LogTrace(
"CSCCathodeLCTProcessor") <<
"Produce CLCT " << clct << std::endl;
1049 const unsigned hstrip,
1050 const unsigned nPreTriggers)
const {
1065 for (
auto&
p : newHits) {
1078 std::ostringstream strm;
1080 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1081 strm <<
"+ CLCT configuration parameters: +\n";
1082 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1083 strm <<
" fifo_tbins [total number of time bins in DAQ readout] = " <<
fifo_tbins <<
"\n";
1084 strm <<
" fifo_pretrig [start time of cathode raw hits in DAQ readout] = " <<
fifo_pretrig <<
"\n";
1085 strm <<
" hit_persist [duration of signal pulse, in 25 ns bins] = " <<
hit_persist <<
"\n";
1086 strm <<
" drift_delay [time after pre-trigger before TMB latches LCTs] = " <<
drift_delay <<
"\n";
1087 strm <<
" nplanes_hit_pretrig [min. number of layers hit for pre-trigger] = " <<
nplanes_hit_pretrig <<
"\n";
1088 strm <<
" nplanes_hit_pattern [min. number of layers hit for trigger] = " <<
nplanes_hit_pattern <<
"\n";
1089 strm <<
" pid_thresh_pretrig [lower threshold on pattern id] = " <<
pid_thresh_pretrig <<
"\n";
1090 strm <<
" min_separation [region of busy key strips] = " <<
min_separation <<
"\n";
1091 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1092 LogDebug(
"CSCCathodeLCTProcessor") << strm.str();
1100 std::ostringstream strstrm;
1102 if (i_strip % 10 == 0) {
1104 strstrm << i_strip / 10;
1106 strstrm << (i_strip - 100) / 10;
1114 strstrm << i_strip % 10;
1122 std::vector<int> bx_times =
strip[i_layer][i_strip];
1124 strstrm << std::hex << bx_times[0] <<
std::dec;
1132 LogTrace(
"CSCCathodeLCTProcessor") << strstrm.str();
1139 std::vector<CSCCLCTDigi> tmpV;
1160 if (early_tbin < 0) {
1162 <<
"Early time bin (early_tbin) smaller than minimum allowed, which is 0. set early_tbin to 0.";
1165 if (late_tbin > max_late_tbin) {
1167 <<
"Late time bin (late_tbin) larger than maximum allowed, which is " << max_late_tbin
1168 <<
". set early_tbin to max allowed";
1173 const auto& all_clcts =
getCLCTs();
1177 int bx_readout = -1;
1178 for (
const auto& clct : all_clcts) {
1180 if (!clct.isValid())
1183 const int bx = clct.getBX();
1185 if (
bx < early_tbin) {
1188 <<
" Do not report correlated CLCT on key halfstrip " << clct.getStrip() <<
": found at bx " <<
bx 1189 <<
", whereas the earliest allowed bx is " << early_tbin;
1194 if (
bx > late_tbin) {
1197 <<
" Do not report correlated CLCT on key halfstrip " << clct.getStrip() <<
": found at bx " <<
bx 1198 <<
", whereas the latest allowed bx is " << late_tbin;
1206 if (bx_readout == -1 ||
bx == bx_readout) {
1207 tmpV.push_back(clct);
1208 if (bx_readout == -1)
1212 tmpV.push_back(clct);
1217 for (
const auto& clct : tmpV) {
1226 std::vector<CSCCLCTDigi> tmpV;
1271 std::vector<CSCShowerDigi> showerOut;
1288 bool atLeastOneCompHit =
false;
1289 for (
const auto& compdigi :
digiV[i_layer]) {
1290 std::vector<int> bx_times = compdigi.getTimeBinsOn();
1292 if (
std::find(bx_times.begin(), bx_times.end(),
bx) != bx_times.end()) {
1293 hitsInTime[
bx] += 1;
1294 atLeastOneCompHit =
true;
1298 if (atLeastOneCompHit) {
1299 layersWithHits[
bx].insert(i_layer);
1309 std::vector<unsigned> station_thresholds = {
1316 unsigned int deadtime =
1318 unsigned int dead_count = 0;
1324 unsigned this_hitsInTime = 0;
1327 for (
unsigned mbx = minbx; mbx <= maxbx; mbx++) {
1328 this_hitsInTime += hitsInTime[mbx];
1332 if (hitsInTime[minbx] < hitsInTime[maxbx + 1]
or 1333 (hitsInTime[minbx] == hitsInTime[maxbx + 1] and hitsInTime[
bx] < hitsInTime[
bx + 1]))
1336 bool dead_status = dead_count > 0;
1340 unsigned this_inTimeHMT = 0;
1345 if (!station_thresholds.empty()) {
1346 for (
int i = station_thresholds.size() - 1;
i >= 0;
i--) {
1347 if (this_hitsInTime >= station_thresholds[
i]) {
1348 this_inTimeHMT =
i + 1;
1349 dead_count = deadtime;
1357 this_inTimeHMT,
false,
theTrigChamber,
bx, CSCShowerDigi::ShowerType::kCLCTShower, 0, this_hitsInTime);
std::unique_ptr< ComparatorCodeLUT > cclut_
void setESLookupTables(const CSCL1TPLookupTableCCLUT *conf)
unsigned int clctNplanesHitPattern() const
static const unsigned int def_drift_delay
std::vector< CSCCLCTDigi > readoutCLCTs() const
CSCCLCTDigi bestCLCT[CSCConstants::MAX_CLCT_TBINS]
T getParameter(std::string const &) const
void setDefaultConfigParameters()
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
unsigned int nplanes_hit_pretrig
static const unsigned int def_fifo_tbins
bool isOneShotHighAtBX(const unsigned layer, const unsigned channel, const unsigned bx) const
unsigned int clctMinSeparation() const
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
unsigned int min_separation
static std::string chamberName(int endcap, int station, int ring, int chamber)
const CSCChamber * cscChamber_
void checkConfigParameters(unsigned int &var, const unsigned int var_max, const unsigned int var_def, const std::string &var_str)
unsigned int clctFifoTbins() const
uint16_t getQuality() const
return quality of a pattern (number of layers hit!)
ParameterSet const & getParameterSet(std::string const &) const
void pulseExtension(const std::vector< int > time[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
uint16_t getKeyStrip(const uint16_t n=2) const
unsigned int clctNplanesHitPretrig() const
static const unsigned int def_min_separation
CSCPatternBank::LCTPatterns clct_pattern_
bool patternFinding(const unsigned int bx_time, std::map< int, std::map< int, CSCCLCTDigi::ComparatorContainer > > &hits_in_patterns)
bool getLocalShowerFlag(int bx) const
Log< level::Error, false > LogError
std::unique_ptr< LCTQualityControl > qualityControl_
edm::ParameterSet const & showerParams() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
unsigned short iChamberType() const
static const unsigned int def_nplanes_hit_pretrig
CSCShowerDigi cathode_showers_[CSCConstants::MAX_CLCT_TBINS]
std::vector< CSCShowerDigi > readoutShower() const
void cleanComparatorContainer(CSCCLCTDigi &lct) const
edm::ParameterSet const & clctParams() const
const CSCLayerGeometry * geometry() const
static const unsigned int def_pid_thresh_pretrig
unsigned int fifo_pretrig
std::vector< std::vector< uint16_t > > ComparatorContainer
CSCCathodeLCTProcessor(unsigned endcap, unsigned station, unsigned sector, unsigned subsector, unsigned chamber, CSCBaseboard::Parameters &conf)
unsigned int nhits[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]
const unsigned theTrigChamber
CSCCLCTPreTriggerDigi constructPreCLCT(const int bx, const unsigned halfstrip, const unsigned index) const
static const LCTPatterns clct_pattern_run3_
CSCCLCTDigi getSecondCLCT(int bx) const
std::string chamberName() const
std::vector< CSCCLCTDigi > getCLCTs() const
int numberOfStrips() const
static const unsigned int def_tmb_l1a_window_size
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
unsigned int clctFifoPretrig() const
edm::ParameterSet const & tmbParams() const
bool getDigis(const CSCComparatorDigiCollection *compdc)
static const unsigned int def_nplanes_hit_pattern
void setHits(const ComparatorContainer &hits)
unsigned int clctPidThreshPretrig() const
static const int clct_pattern_offset_[CSCConstants::CLCT_PATTERN_WIDTH]
bool isValid() const
check CLCT validity (1 - valid CLCT)
static int getPatternBend(const LCTPattern &pattern)
unsigned int clctHitPersist() const
std::vector< CSCCLCTPreTriggerDigi > thePreTriggerDigis
unsigned int nplanes_hit_pattern
void encodeHighMultiplicityBits()
unsigned numberOfLayersAtBX(const unsigned bx) const
static const LCTPatterns clct_pattern_legacy_
virtual std::vector< CSCCLCTDigi > findLCTs(const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
void markBusyKeys(const int best_hstrip, const int best_patid, int quality[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
void checkConfigParameters()
static const unsigned int def_fifo_pretrig
bool localShowerFlag[CSCConstants::MAX_CLCT_TBINS]
std::vector< int > thePreTriggerBXs
std::pair< const_iterator, const_iterator > Range
static const unsigned int def_hit_persist
void dumpDigis(const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]) const
const unsigned theStation
CSCCLCTDigi getBestCLCT(int bx) const
int stagger[CSCConstants::NUM_LAYERS]
std::vector< DigiType >::const_iterator const_iterator
uint16_t getBX() const
return BX
uint16_t getPattern() const
return pattern
std::vector< CSCCLCTDigi > run(const CSCComparatorDigiCollection *compdc)
edm::ParameterSet const & conf() const
void initialize(unsigned numberOfChannels)
void setBX(const uint16_t bx)
set bx
const ComparatorContainer & getHits() const
virtual bool preTrigger(const int start_bx, int &first_bx)
unsigned minLayersCentralTBin_
uint16_t getRun3Pattern() const
return pattern
CSCCLCTDigi secondCLCT[CSCConstants::MAX_CLCT_TBINS]
void clear()
clear this CLCT
std::vector< CSCComparatorDigi > digiV[CSCConstants::NUM_LAYERS]
unsigned bitsInPulse() const
void dumpConfigParams() const
void clear()
clear this Shower
unsigned int tmb_l1a_window_size
Log< level::Warning, false > LogWarning
void readComparatorDigis(std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
CSCCLCTDigi constructCLCT(const int bx, const unsigned halfstrip_withstagger, const CSCCLCTDigi::ComparatorContainer &hits)
std::vector< CSCShowerDigi > getAllShower() const
void extend(const unsigned layer, const unsigned channel, const unsigned bx, const unsigned hit_persist)
unsigned int pid_thresh_pretrig
bool ispretrig_[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]
void setConfigParameters(const CSCDBL1TPParameters *conf)
const unsigned theSubsector
void setTrknmb(const uint16_t number)
Set track number (1,2) after sorting CLCTs.
void checkLocalShower(int zone, const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
unsigned int clctDriftDelay() const
unsigned int best_pid[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]
std::vector< unsigned > thresholds_