28 static std::atomic<bool> config_dumped{
false};
77 if ((
infoV > 0) && !config_dumped) {
85 if ((i_layer + 1) % 2 == 0)
95 cclut_ = std::make_unique<ComparatorCodeLUT>(conf);
101 thresholds_ = shower.getParameter<std::vector<unsigned>>(
"showerThresholds");
104 peakCheck_ = shower.getParameter<
bool>(
"peakCheck");
132 static std::atomic<bool> config_dumped{
false};
145 if (!config_dumped) {
147 config_dumped =
true;
159 static const unsigned int max_fifo_tbins = 1 << 5;
160 static const unsigned int max_fifo_pretrig = 1 << 5;
161 static const unsigned int max_hit_persist = 1 << 4;
162 static const unsigned int max_drift_delay = 1 << 2;
163 static const unsigned int max_nplanes_hit_pretrig = 1 << 3;
164 static const unsigned int max_nplanes_hit_pattern = 1 << 3;
165 static const unsigned int max_pid_thresh_pretrig = 1 << 4;
167 static const unsigned int max_tmb_l1a_window_size = 1 << 4;
202 static std::atomic<bool> config_dumped{
false};
203 if ((
infoV > 0) && !config_dumped) {
205 config_dumped =
true;
223 <<
"+++ Invalid ring number for this processor " <<
theRing <<
" was set in the config." 225 <<
"+++ CSC geometry looks garbled; no emulation possible +++\n";
243 <<
"+++ CSC geometry looks garbled; no emulation possible +++\n";
268 <<
" is not defined in current geometry! +++\n" 269 <<
"+++ CSC geometry looks garbled; no emulation possible +++\n";
280 <<
" numStrips_ = " <<
numStrips_ <<
"; CLCT emulation skipped! +++";
281 std::vector<CSCCLCTDigi> emptyV;
299 unsigned int layersHit = 0;
302 if (!halfStripTimes[i_layer][i_hstrip].
empty()) {
319 std::vector<CSCCLCTDigi> tmpV =
getCLCTs();
328 for (
auto&
p : tmpV) {
347 std::vector<CSCCLCTDigi> CLCTlist =
findLCTs(halfstrip);
349 for (
const auto&
p : CLCTlist) {
350 const int bx =
p.getBX();
355 <<
"; skipping it... +++\n";
414 for (
int hstrip = minHS; hstrip < maxHS; hstrip++) {
422 LogDebug(
"CSCCathodeLCTProcessor") <<
" bx " <<
bx <<
" bestCLCT key HS " << keyHS
423 <<
" localshower zone: " << minHS <<
", " << maxHS <<
" totalHits " 430 bool hasDigis =
false;
434 digiV[i_layer].clear();
447 LogTrace(
"CSCCathodeLCTProcessor") <<
"found " <<
digiV[i_layer].size() <<
" comparator digi(s) in layer " 458 const bool me1a = (
id.station() == 1) && (
id.
ring() == 4);
461 const unsigned int origStrip = digiIt->getStrip();
462 const unsigned int maxStripsME1a =
466 if (me1a && origStrip <= maxStripsME1a && !
disableME1a_) {
471 digiV[
id.layer() - 1].push_back(digi_corr);
473 digiV[
id.layer() - 1].push_back(*digiIt);
482 for (std::vector<CSCComparatorDigi>::iterator pld =
digiV[i_layer].begin(); pld !=
digiV[i_layer].end();
486 std::ostringstream strstrm;
487 strstrm <<
"Comparator digi: comparator = " << pld->getComparator() <<
" strip #" << pld->getStrip()
489 std::vector<int> bx_times = pld->getTimeBinsOn();
490 for (
unsigned int tbin = 0; tbin < bx_times.size(); tbin++)
491 strstrm <<
" " << bx_times[tbin];
492 LogTrace(
"CSCCathodeLCTProcessor") << strstrm.str();
497 int thisComparator = pld->getComparator();
498 if (thisComparator != 0 && thisComparator != 1) {
502 <<
" Found comparator digi with wrong comparator value = " << thisComparator <<
"; skipping it... +++\n";
507 int thisStrip = pld->getStrip() - 1;
508 if (thisStrip < 0 || thisStrip >=
numStrips_) {
512 <<
" Found comparator digi with wrong strip number = " << thisStrip <<
" (max strips = " <<
numStrips_ 513 <<
"); skipping it... +++\n";
519 int thisHalfstrip = 2 * thisStrip + thisComparator +
stagger[i_layer];
524 <<
" Found wrong halfstrip number = " << thisHalfstrip <<
"; skipping this digi... +++\n";
529 std::vector<int> bx_times = pld->getTimeBinsOn();
530 for (
unsigned int i = 0;
i < bx_times.size();
i++) {
540 if (bx_times[
i] > 1 && bx_times[
i] < static_cast<int>(
fifo_tbins)) {
541 if (
i == 0 || (
i > 0 && bx_times[
i] - bx_times[
i - 1] >= static_cast<int>(
hit_persist))) {
547 <<
"Comp digi: layer " << i_layer + 1 <<
" digi #" << i_digi + 1 <<
" strip " << thisStrip
548 <<
" halfstrip " << thisHalfstrip <<
" time " << bx_times[
i] <<
" comparator " << thisComparator
549 <<
" stagger " <<
stagger[i_layer];
550 halfstrip[i_layer][thisHalfstrip].push_back(bx_times[
i]);
555 <<
" Skipping comparator digi: strip = " << thisStrip <<
", layer = " << i_layer + 1
556 <<
", bx = " << bx_times[
i] <<
", bx of previous hit = " << bx_times[
i - 1];
561 <<
theChamber <<
"+++ Skipping comparator digi: strip = " << thisStrip
562 <<
", layer = " << i_layer + 1 <<
", bx = " << bx_times[
i] <<
" +++";
572 std::vector<CSCCLCTDigi> lctList;
585 while (start_bx < stop_bx) {
593 bool pre_trig =
preTrigger(start_bx, first_bx);
600 LogTrace(
"CSCCathodeLCTProcessor") <<
"..... pretrigger at bx = " << first_bx <<
"; waiting drift delay .....";
611 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>> hits_in_patterns;
612 hits_in_patterns.clear();
620 if (
nhits[hstrip] > 0) {
622 <<
" bx = " << std::setw(2) << latch_bx <<
" --->" 623 <<
" halfstrip = " << std::setw(3) << hstrip <<
" best pid = " << std::setw(2) <<
best_pid[hstrip]
624 <<
" nhits = " <<
nhits[hstrip];
642 best_halfstrip[ilct] = -1;
643 best_quality[ilct] = 0;
653 if (
quality[hstrip] > best_quality[0]) {
654 best_halfstrip[0] = hstrip;
655 best_quality[0] =
quality[hstrip];
658 const int best_hs(best_halfstrip[0]);
668 if (best_halfstrip[0] >= 0) {
679 if (
quality[hstrip] > best_quality[1]) {
680 best_halfstrip[1] = hstrip;
681 best_quality[1] =
quality[hstrip];
684 const int best_hs(best_halfstrip[1]);
695 bool changeOrder =
false;
697 unsigned qualityBest = 0, qualitySecond = 0;
698 unsigned patternBest = 0, patternSecond = 0;
699 unsigned halfStripBest = 0, halfStripSecond = 0;
714 if (qualitySecond > qualityBest)
716 else if ((qualitySecond == qualityBest) and (
int(patternSecond / 2) >
int(patternBest / 2)))
718 else if ((qualitySecond == qualityBest) and (
int(patternSecond / 2) ==
int(patternBest / 2)) and
719 (halfStripSecond < halfStripBest))
725 tempCLCT = tempBestCLCT;
726 tempBestCLCT = tempSecondCLCT;
727 tempSecondCLCT = tempCLCT;
732 lctList.push_back(tempBestCLCT);
734 if (tempSecondCLCT.
isValid()) {
735 lctList.push_back(tempSecondCLCT);
749 for (
unsigned int bx = latch_bx + 1;
bx < stop_time;
bx++) {
750 bool return_to_idle =
true;
757 LogTrace(
"CSCCathodeLCTProcessor") <<
" State machine busy at bx = " <<
bx;
758 return_to_idle =
false;
763 if (return_to_idle) {
765 LogTrace(
"CSCCathodeLCTProcessor") <<
" State machine returns to idle state at bx = " <<
bx;
772 start_bx = first_bx + 1;
800 std::vector<int> bx_times =
time[i_layer][i_strip];
801 for (
unsigned int i = 0;
i < bx_times.size();
i++) {
803 if (bx_times[
i] < 0 || bx_times[
i] +
hit_persist >= bits_in_pulse) {
806 <<
"+++ BX time of comparator digi (halfstrip = " << i_strip <<
" layer = " << i_layer
807 <<
") bx = " << bx_times[
i] <<
" is not within the range (0-" << bits_in_pulse
808 <<
"] allowed for pulse extension. Skip this digi! +++\n";
823 LogTrace(
"CSCCathodeLCTProcessor") <<
"....................PreTrigger...........................";
825 int nPreTriggers = 0;
827 bool pre_trig =
false;
829 for (
unsigned int bx_time = start_bx; bx_time <
fifo_tbins; bx_time++) {
836 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>> hits_in_patterns;
837 hits_in_patterns.clear();
847 if (
nhits[hstrip] > 0) {
849 <<
" bx = " << std::setw(2) << bx_time <<
" --->" 850 <<
" halfstrip = " << std::setw(3) << hstrip <<
" best pid = " << std::setw(2) <<
best_pid[hstrip]
851 <<
" nhits = " <<
nhits[hstrip];
874 LogTrace(
"CSCCathodeLCTProcessor") <<
"no pretrigger, returning \n";
881 const unsigned int bx_time,
std::map<
int, std::map<int, CSCCLCTDigi::ComparatorContainer>>& hits_in_patterns) {
889 for (
int key_hstrip = 0; key_hstrip <
numHalfStrips_; key_hstrip++) {
891 nhits[key_hstrip] = 0;
903 hit_layer[ilayer] =
false;
908 hits_single_pattern.resize(6);
909 for (
auto&
p : hits_single_pattern) {
914 double num_pattern_hits = 0., times_sum = 0.;
915 std::multiset<int> mset_for_median;
916 mset_for_median.clear();
932 LogTrace(
"CSCCathodeLCTProcessor") <<
" In patternFinding: key_strip = " << key_hstrip <<
" pid = " << pid
933 <<
" layer = " << this_layer <<
" strip = " << this_strip << std::endl;
937 if (hit_layer[this_layer] ==
false) {
938 hit_layer[this_layer] =
true;
941 hits_single_pattern[this_layer][strip_num] = this_strip -
stagger[this_layer];
946 int first_bx_layer = bx_time;
947 for (
unsigned int dbx = 0; dbx <
hit_persist; dbx++) {
953 times_sum += (double)first_bx_layer;
954 num_pattern_hits += 1.;
955 mset_for_median.insert(first_bx_layer);
957 LogTrace(
"CSCCathodeLCTProcessor") <<
" 1st bx in layer: " << first_bx_layer <<
" sum bx: " << times_sum
958 <<
" #pat. hits: " << num_pattern_hits;
966 hits_in_patterns[key_hstrip][pid] = hits_single_pattern;
970 if (layers_hit >
nhits[key_hstrip]) {
972 nhits[key_hstrip] = layers_hit;
988 const int best_patid,
993 for (
int hstrip = best_hstrip - nspan; hstrip <= best_hstrip + pspan; hstrip++) {
1001 const unsigned halfstrip_withstagger,
1038 LogTrace(
"CSCCathodeLCTProcessor") <<
"Produce CLCT " << clct << std::endl;
1045 const unsigned hstrip,
1046 const unsigned nPreTriggers)
const {
1061 for (
auto&
p : newHits) {
1074 std::ostringstream strm;
1076 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1077 strm <<
"+ CLCT configuration parameters: +\n";
1078 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1079 strm <<
" fifo_tbins [total number of time bins in DAQ readout] = " <<
fifo_tbins <<
"\n";
1080 strm <<
" fifo_pretrig [start time of cathode raw hits in DAQ readout] = " <<
fifo_pretrig <<
"\n";
1081 strm <<
" hit_persist [duration of signal pulse, in 25 ns bins] = " <<
hit_persist <<
"\n";
1082 strm <<
" drift_delay [time after pre-trigger before TMB latches LCTs] = " <<
drift_delay <<
"\n";
1083 strm <<
" nplanes_hit_pretrig [min. number of layers hit for pre-trigger] = " <<
nplanes_hit_pretrig <<
"\n";
1084 strm <<
" nplanes_hit_pattern [min. number of layers hit for trigger] = " <<
nplanes_hit_pattern <<
"\n";
1085 strm <<
" pid_thresh_pretrig [lower threshold on pattern id] = " <<
pid_thresh_pretrig <<
"\n";
1086 strm <<
" min_separation [region of busy key strips] = " <<
min_separation <<
"\n";
1087 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1088 LogDebug(
"CSCCathodeLCTProcessor") << strm.str();
1096 std::ostringstream strstrm;
1098 if (i_strip % 10 == 0) {
1100 strstrm << i_strip / 10;
1102 strstrm << (i_strip - 100) / 10;
1110 strstrm << i_strip % 10;
1118 std::vector<int> bx_times =
strip[i_layer][i_strip];
1120 strstrm << std::hex << bx_times[0] <<
std::dec;
1128 LogTrace(
"CSCCathodeLCTProcessor") << strstrm.str();
1135 std::vector<CSCCLCTDigi> tmpV;
1156 if (early_tbin < 0) {
1158 <<
"Early time bin (early_tbin) smaller than minimum allowed, which is 0. set early_tbin to 0.";
1161 if (late_tbin > max_late_tbin) {
1163 <<
"Late time bin (late_tbin) larger than maximum allowed, which is " << max_late_tbin
1164 <<
". set early_tbin to max allowed";
1169 const auto& all_clcts =
getCLCTs();
1173 int bx_readout = -1;
1174 for (
const auto& clct : all_clcts) {
1176 if (!clct.isValid())
1179 const int bx = clct.getBX();
1181 if (
bx < early_tbin) {
1184 <<
" Do not report correlated CLCT on key halfstrip " << clct.getStrip() <<
": found at bx " <<
bx 1185 <<
", whereas the earliest allowed bx is " << early_tbin;
1190 if (
bx > late_tbin) {
1193 <<
" Do not report correlated CLCT on key halfstrip " << clct.getStrip() <<
": found at bx " <<
bx 1194 <<
", whereas the latest allowed bx is " << late_tbin;
1202 if (bx_readout == -1 ||
bx == bx_readout) {
1203 tmpV.push_back(clct);
1204 if (bx_readout == -1)
1208 tmpV.push_back(clct);
1213 for (
const auto& clct : tmpV) {
1222 std::vector<CSCCLCTDigi> tmpV;
1267 std::vector<CSCShowerDigi> showerOut;
1284 bool atLeastOneCompHit =
false;
1285 for (
const auto& compdigi :
digiV[i_layer]) {
1286 std::vector<int> bx_times = compdigi.getTimeBinsOn();
1288 if (
std::find(bx_times.begin(), bx_times.end(),
bx) != bx_times.end()) {
1289 hitsInTime[
bx] += 1;
1290 atLeastOneCompHit =
true;
1294 if (atLeastOneCompHit) {
1295 layersWithHits[
bx].insert(i_layer);
1305 std::vector<unsigned> station_thresholds = {
1312 unsigned int deadtime =
1314 unsigned int dead_count = 0;
1320 unsigned this_hitsInTime = 0;
1323 for (
unsigned mbx = minbx; mbx <= maxbx; mbx++) {
1324 this_hitsInTime += hitsInTime[mbx];
1328 if (hitsInTime[minbx] < hitsInTime[maxbx + 1]
or 1329 (hitsInTime[minbx] == hitsInTime[maxbx + 1] and hitsInTime[
bx] < hitsInTime[
bx + 1]))
1332 bool dead_status = dead_count > 0;
1336 unsigned this_inTimeHMT = 0;
1341 if (!station_thresholds.empty()) {
1342 for (
int i = station_thresholds.size() - 1;
i >= 0;
i--) {
1343 if (this_hitsInTime >= station_thresholds[
i]) {
1344 this_inTimeHMT =
i + 1;
1345 dead_count = deadtime;
1353 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
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)
bool getLocalShowerFlag(int bx) const
Log< level::Error, false > LogError
std::unique_ptr< LCTQualityControl > qualityControl_
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
const CSCLayerGeometry * geometry() const
static const unsigned int def_pid_thresh_pretrig
unsigned int fifo_pretrig
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
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
void encodeHighMultiplicityBits()
unsigned numberOfLayersAtBX(const unsigned bx) 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()
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)
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
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)
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_