28 static std::atomic<bool> config_dumped{
false};
73 if ((
infoV > 0) && !config_dumped) {
81 if ((i_layer + 1) % 2 == 0)
91 cclut_ = std::make_unique<ComparatorCodeLUT>(conf);
97 thresholds_ = shower.getParameter<std::vector<unsigned>>(
"showerThresholds");
124 static std::atomic<bool> config_dumped{
false};
137 if (!config_dumped) {
139 config_dumped =
true;
149 static const unsigned int max_fifo_tbins = 1 << 5;
150 static const unsigned int max_fifo_pretrig = 1 << 5;
151 static const unsigned int max_hit_persist = 1 << 4;
152 static const unsigned int max_drift_delay = 1 << 2;
153 static const unsigned int max_nplanes_hit_pretrig = 1 << 3;
154 static const unsigned int max_nplanes_hit_pattern = 1 << 3;
155 static const unsigned int max_pid_thresh_pretrig = 1 << 4;
157 static const unsigned int max_tmb_l1a_window_size = 1 << 4;
190 static std::atomic<bool> config_dumped{
false};
191 if ((
infoV > 0) && !config_dumped) {
193 config_dumped =
true;
211 <<
"+++ Invalid ring number for this processor " <<
theRing <<
" was set in the config." 213 <<
"+++ CSC geometry looks garbled; no emulation possible +++\n";
231 <<
"+++ CSC geometry looks garbled; no emulation possible +++\n";
256 <<
" is not defined in current geometry! +++\n" 257 <<
"+++ CSC geometry looks garbled; no emulation possible +++\n";
268 <<
" numStrips_ = " <<
numStrips_ <<
"; CLCT emulation skipped! +++";
269 std::vector<CSCCLCTDigi> emptyV;
287 unsigned int layersHit = 0;
290 if (!halfStripTimes[i_layer][i_hstrip].
empty()) {
307 std::vector<CSCCLCTDigi> tmpV =
getCLCTs();
316 for (
auto&
p : tmpV) {
335 std::vector<CSCCLCTDigi> CLCTlist =
findLCTs(halfstrip);
337 for (
const auto&
p : CLCTlist) {
338 const int bx =
p.getBX();
343 <<
"; skipping it... +++\n";
385 bool hasDigis =
false;
389 digiV[i_layer].clear();
402 LogTrace(
"CSCCathodeLCTProcessor") <<
"found " <<
digiV[i_layer].size() <<
" comparator digi(s) in layer " 413 const bool me1a = (
id.station() == 1) && (
id.
ring() == 4);
416 const unsigned int origStrip = digiIt->getStrip();
417 const unsigned int maxStripsME1a =
421 if (me1a && origStrip <= maxStripsME1a && !
disableME1a_) {
426 digiV[
id.layer() - 1].push_back(digi_corr);
428 digiV[
id.layer() - 1].push_back(*digiIt);
437 for (std::vector<CSCComparatorDigi>::iterator pld =
digiV[i_layer].begin(); pld !=
digiV[i_layer].end();
441 std::ostringstream strstrm;
442 strstrm <<
"Comparator digi: comparator = " << pld->getComparator() <<
" strip #" << pld->getStrip()
444 std::vector<int> bx_times = pld->getTimeBinsOn();
445 for (
unsigned int tbin = 0; tbin < bx_times.size(); tbin++)
446 strstrm <<
" " << bx_times[tbin];
447 LogTrace(
"CSCCathodeLCTProcessor") << strstrm.str();
452 int thisComparator = pld->getComparator();
453 if (thisComparator != 0 && thisComparator != 1) {
457 <<
" Found comparator digi with wrong comparator value = " << thisComparator <<
"; skipping it... +++\n";
462 int thisStrip = pld->getStrip() - 1;
463 if (thisStrip < 0 || thisStrip >=
numStrips_) {
467 <<
" Found comparator digi with wrong strip number = " << thisStrip <<
" (max strips = " <<
numStrips_ 468 <<
"); skipping it... +++\n";
474 int thisHalfstrip = 2 * thisStrip + thisComparator +
stagger[i_layer];
479 <<
" Found wrong halfstrip number = " << thisHalfstrip <<
"; skipping this digi... +++\n";
484 std::vector<int> bx_times = pld->getTimeBinsOn();
485 for (
unsigned int i = 0;
i < bx_times.size();
i++) {
495 if (bx_times[
i] > 1 && bx_times[
i] < static_cast<int>(
fifo_tbins)) {
496 if (
i == 0 || (
i > 0 && bx_times[
i] - bx_times[
i - 1] >= static_cast<int>(
hit_persist))) {
502 <<
"Comp digi: layer " << i_layer + 1 <<
" digi #" << i_digi + 1 <<
" strip " << thisStrip
503 <<
" halfstrip " << thisHalfstrip <<
" time " << bx_times[
i] <<
" comparator " << thisComparator
504 <<
" stagger " <<
stagger[i_layer];
505 halfstrip[i_layer][thisHalfstrip].push_back(bx_times[
i]);
510 <<
" Skipping comparator digi: strip = " << thisStrip <<
", layer = " << i_layer + 1
511 <<
", bx = " << bx_times[
i] <<
", bx of previous hit = " << bx_times[
i - 1];
516 <<
theChamber <<
"+++ Skipping comparator digi: strip = " << thisStrip
517 <<
", layer = " << i_layer + 1 <<
", bx = " << bx_times[
i] <<
" +++";
527 std::vector<CSCCLCTDigi> lctList;
540 while (start_bx < stop_bx) {
548 bool pre_trig =
preTrigger(start_bx, first_bx);
555 LogTrace(
"CSCCathodeLCTProcessor") <<
"..... pretrigger at bx = " << first_bx <<
"; waiting drift delay .....";
566 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>> hits_in_patterns;
567 hits_in_patterns.clear();
575 if (
nhits[hstrip] > 0) {
577 <<
" bx = " << std::setw(2) << latch_bx <<
" --->" 578 <<
" halfstrip = " << std::setw(3) << hstrip <<
" best pid = " << std::setw(2) <<
best_pid[hstrip]
579 <<
" nhits = " <<
nhits[hstrip];
597 best_halfstrip[ilct] = -1;
598 best_quality[ilct] = 0;
608 if (
quality[hstrip] > best_quality[0]) {
609 best_halfstrip[0] = hstrip;
610 best_quality[0] =
quality[hstrip];
613 const int best_hs(best_halfstrip[0]);
623 if (best_halfstrip[0] >= 0) {
634 if (
quality[hstrip] > best_quality[1]) {
635 best_halfstrip[1] = hstrip;
636 best_quality[1] =
quality[hstrip];
639 const int best_hs(best_halfstrip[1]);
650 bool changeOrder =
false;
652 unsigned qualityBest = 0, qualitySecond = 0;
653 unsigned patternBest = 0, patternSecond = 0;
654 unsigned halfStripBest = 0, halfStripSecond = 0;
669 if (qualitySecond > qualityBest)
671 else if ((qualitySecond == qualityBest) and (
int(patternSecond / 2) >
int(patternBest / 2)))
673 else if ((qualitySecond == qualityBest) and (
int(patternSecond / 2) ==
int(patternBest / 2)) and
674 (halfStripSecond < halfStripBest))
680 tempCLCT = tempBestCLCT;
681 tempBestCLCT = tempSecondCLCT;
682 tempSecondCLCT = tempCLCT;
687 lctList.push_back(tempBestCLCT);
689 if (tempSecondCLCT.
isValid()) {
690 lctList.push_back(tempSecondCLCT);
704 for (
unsigned int bx = latch_bx + 1;
bx < stop_time;
bx++) {
705 bool return_to_idle =
true;
712 LogTrace(
"CSCCathodeLCTProcessor") <<
" State machine busy at bx = " <<
bx;
713 return_to_idle =
false;
718 if (return_to_idle) {
720 LogTrace(
"CSCCathodeLCTProcessor") <<
" State machine returns to idle state at bx = " <<
bx;
727 start_bx = first_bx + 1;
755 std::vector<int> bx_times =
time[i_layer][i_strip];
756 for (
unsigned int i = 0;
i < bx_times.size();
i++) {
758 if (bx_times[
i] < 0 || bx_times[
i] +
hit_persist >= bits_in_pulse) {
761 <<
"+++ BX time of comparator digi (halfstrip = " << i_strip <<
" layer = " << i_layer
762 <<
") bx = " << bx_times[
i] <<
" is not within the range (0-" << bits_in_pulse
763 <<
"] allowed for pulse extension. Skip this digi! +++\n";
778 LogTrace(
"CSCCathodeLCTProcessor") <<
"....................PreTrigger...........................";
780 int nPreTriggers = 0;
782 bool pre_trig =
false;
784 for (
unsigned int bx_time = start_bx; bx_time <
fifo_tbins; bx_time++) {
791 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>> hits_in_patterns;
792 hits_in_patterns.clear();
802 if (
nhits[hstrip] > 0) {
804 <<
" bx = " << std::setw(2) << bx_time <<
" --->" 805 <<
" halfstrip = " << std::setw(3) << hstrip <<
" best pid = " << std::setw(2) <<
best_pid[hstrip]
806 <<
" nhits = " <<
nhits[hstrip];
829 LogTrace(
"CSCCathodeLCTProcessor") <<
"no pretrigger, returning \n";
836 const unsigned int bx_time,
std::map<
int, std::map<int, CSCCLCTDigi::ComparatorContainer>>& hits_in_patterns) {
844 for (
int key_hstrip = 0; key_hstrip <
numHalfStrips_; key_hstrip++) {
846 nhits[key_hstrip] = 0;
858 hit_layer[ilayer] =
false;
863 hits_single_pattern.resize(6);
864 for (
auto&
p : hits_single_pattern) {
869 double num_pattern_hits = 0., times_sum = 0.;
870 std::multiset<int> mset_for_median;
871 mset_for_median.clear();
887 LogTrace(
"CSCCathodeLCTProcessor") <<
" In patternFinding: key_strip = " << key_hstrip <<
" pid = " << pid
888 <<
" layer = " << this_layer <<
" strip = " << this_strip << std::endl;
892 if (hit_layer[this_layer] ==
false) {
893 hit_layer[this_layer] =
true;
896 hits_single_pattern[this_layer][strip_num] = this_strip -
stagger[this_layer];
901 int first_bx_layer = bx_time;
902 for (
unsigned int dbx = 0; dbx <
hit_persist; dbx++) {
908 times_sum += (double)first_bx_layer;
909 num_pattern_hits += 1.;
910 mset_for_median.insert(first_bx_layer);
912 LogTrace(
"CSCCathodeLCTProcessor") <<
" 1st bx in layer: " << first_bx_layer <<
" sum bx: " << times_sum
913 <<
" #pat. hits: " << num_pattern_hits;
921 hits_in_patterns[key_hstrip][pid] = hits_single_pattern;
925 if (layers_hit >
nhits[key_hstrip]) {
927 nhits[key_hstrip] = layers_hit;
943 const int best_patid,
948 for (
int hstrip = best_hstrip - nspan; hstrip <= best_hstrip + pspan; hstrip++) {
956 const unsigned halfstrip_withstagger,
993 LogTrace(
"CSCCathodeLCTProcessor") <<
"Produce CLCT " << clct << std::endl;
1000 const unsigned hstrip,
1001 const unsigned nPreTriggers)
const {
1016 for (
auto&
p : newHits) {
1029 std::ostringstream strm;
1031 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1032 strm <<
"+ CLCT configuration parameters: +\n";
1033 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1034 strm <<
" fifo_tbins [total number of time bins in DAQ readout] = " <<
fifo_tbins <<
"\n";
1035 strm <<
" fifo_pretrig [start time of cathode raw hits in DAQ readout] = " <<
fifo_pretrig <<
"\n";
1036 strm <<
" hit_persist [duration of signal pulse, in 25 ns bins] = " <<
hit_persist <<
"\n";
1037 strm <<
" drift_delay [time after pre-trigger before TMB latches LCTs] = " <<
drift_delay <<
"\n";
1038 strm <<
" nplanes_hit_pretrig [min. number of layers hit for pre-trigger] = " <<
nplanes_hit_pretrig <<
"\n";
1039 strm <<
" nplanes_hit_pattern [min. number of layers hit for trigger] = " <<
nplanes_hit_pattern <<
"\n";
1040 strm <<
" pid_thresh_pretrig [lower threshold on pattern id] = " <<
pid_thresh_pretrig <<
"\n";
1041 strm <<
" min_separation [region of busy key strips] = " <<
min_separation <<
"\n";
1042 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1043 LogDebug(
"CSCCathodeLCTProcessor") << strm.str();
1051 std::ostringstream strstrm;
1053 if (i_strip % 10 == 0) {
1055 strstrm << i_strip / 10;
1057 strstrm << (i_strip - 100) / 10;
1065 strstrm << i_strip % 10;
1073 std::vector<int> bx_times =
strip[i_layer][i_strip];
1075 strstrm << std::hex << bx_times[0] <<
std::dec;
1083 LogTrace(
"CSCCathodeLCTProcessor") << strstrm.str();
1090 std::vector<CSCCLCTDigi> tmpV;
1111 if (early_tbin < 0) {
1113 <<
"Early time bin (early_tbin) smaller than minimum allowed, which is 0. set early_tbin to 0.";
1116 if (late_tbin > max_late_tbin) {
1118 <<
"Late time bin (late_tbin) larger than maximum allowed, which is " << max_late_tbin
1119 <<
". set early_tbin to max allowed";
1124 const auto& all_clcts =
getCLCTs();
1128 int bx_readout = -1;
1129 for (
const auto& clct : all_clcts) {
1131 if (!clct.isValid())
1134 const int bx = clct.getBX();
1136 if (
bx < early_tbin) {
1139 <<
" Do not report correlated CLCT on key halfstrip " << clct.getStrip() <<
": found at bx " <<
bx 1140 <<
", whereas the earliest allowed bx is " << early_tbin;
1145 if (
bx > late_tbin) {
1148 <<
" Do not report correlated CLCT on key halfstrip " << clct.getStrip() <<
": found at bx " <<
bx 1149 <<
", whereas the latest allowed bx is " << late_tbin;
1157 if (bx_readout == -1 ||
bx == bx_readout) {
1158 tmpV.push_back(clct);
1159 if (bx_readout == -1)
1163 tmpV.push_back(clct);
1168 for (
const auto& clct : tmpV) {
1177 std::vector<CSCCLCTDigi> tmpV;
1213 unsigned nLayersWithHits = 0;
1215 bool atLeastOneWGHit =
false;
1218 if (!halfstrip[i_layer][i_hstrip].
empty()) {
1219 auto times = halfstrip[i_layer][i_hstrip];
1220 int nLayerTime = std::count_if(times.begin(), times.end(), layerTime);
1222 if (nLayerTime > 0) {
1223 atLeastOneWGHit =
true;
1229 if (atLeastOneWGHit) {
1243 unsigned hitsInTime = 0;
1246 auto times = halfstrip[i_layer][i_hstrip];
1247 hitsInTime += std::count_if(times.begin(), times.end(), inTime);
1256 std::vector<unsigned> station_thresholds = {
1260 for (
unsigned i = 0;
i < station_thresholds.size();
i++) {
1261 if (hitsInTime >= station_thresholds[
i]) {
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.
CSCShowerDigi readoutShower() const
unsigned int nplanes_hit_pretrig
static const unsigned int def_fifo_tbins
CSCCathodeLCTProcessor(unsigned endcap, unsigned station, unsigned sector, unsigned subsector, unsigned chamber, const edm::ParameterSet &conf)
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)
Log< level::Error, false > LogError
std::unique_ptr< LCTQualityControl > qualityControl_
unsigned short iChamberType() const
static const unsigned int def_nplanes_hit_pretrig
void cleanComparatorContainer(CSCCLCTDigi &lct) const
const CSCLayerGeometry * geometry() const
static const unsigned int def_pid_thresh_pretrig
unsigned int fifo_pretrig
unsigned showerMinInTBin_
std::vector< std::vector< uint16_t > > ComparatorContainer
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
bool getDigis(const CSCComparatorDigiCollection *compdc)
static const unsigned int def_nplanes_hit_pattern
void setHits(const ComparatorContainer &hits)
unsigned int clctPidThreshPretrig() const
unsigned showerMinOutTBin_
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)
edm::ParameterSet clctParams_
unsigned int clctHitPersist() const
std::vector< CSCCLCTPreTriggerDigi > thePreTriggerDigis
unsigned int nplanes_hit_pattern
unsigned numberOfLayersAtBX(const unsigned bx) const
void dumpDigis(const std::vector< int > strip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]) const
static const LCTPatterns clct_pattern_legacy_
edm::ParameterSet tmbParams_
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()
unsigned showerMaxInTBin_
static const unsigned int def_fifo_pretrig
std::vector< int > thePreTriggerBXs
unsigned showerMaxOutTBin_
std::pair< const_iterator, const_iterator > Range
static const unsigned int def_hit_persist
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)
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
unsigned int tmb_l1a_window_size
Log< level::Warning, false > LogWarning
edm::ParameterSet showerParams_
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)
void encodeHighMultiplicityBits(const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
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.
unsigned int clctDriftDelay() const
unsigned int best_pid[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]
std::vector< unsigned > thresholds_