27 :
CSCBaseboard(endcap, station, sector, subsector, chamber, conf) {
28 static std::atomic<bool> config_dumped{
false};
68 pid_thresh_pretrig = 0;
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";
226 if (
numStrips_ > CSCConstants::MAX_NUM_STRIPS_RUN2) {
230 <<
" exceeds max expected, " << CSCConstants::MAX_NUM_STRIPS_RUN2 <<
" +++\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);
338 if (CLCTlist.size() > 1)
339 sort(CLCTlist.begin(), CLCTlist.end(), std::greater<CSCCLCTDigi>());
341 for (
const auto&
p : CLCTlist) {
342 const int bx =
p.getBX();
347 <<
"; skipping it... +++\n";
389 bool hasDigis =
false;
393 digiV[i_layer].clear();
406 LogTrace(
"CSCCathodeLCTProcessor") <<
"found " <<
digiV[i_layer].size() <<
" comparator digi(s) in layer "
417 const bool me1a = (
id.station() == 1) && (
id.
ring() == 4);
420 const unsigned int origStrip = digiIt->getStrip();
421 const unsigned int maxStripsME1a =
425 if (me1a && origStrip <= maxStripsME1a && !
disableME1a_) {
430 digiV[
id.layer() - 1].push_back(digi_corr);
432 digiV[
id.layer() - 1].push_back(*digiIt);
441 for (std::vector<CSCComparatorDigi>::iterator pld =
digiV[i_layer].
begin(); pld !=
digiV[i_layer].end();
445 std::ostringstream strstrm;
446 strstrm <<
"Comparator digi: comparator = " << pld->getComparator() <<
" strip #" << pld->getStrip()
448 std::vector<int> bx_times = pld->getTimeBinsOn();
449 for (
unsigned int tbin = 0; tbin < bx_times.size(); tbin++)
450 strstrm <<
" " << bx_times[tbin];
451 LogTrace(
"CSCCathodeLCTProcessor") << strstrm.str();
456 int thisComparator = pld->getComparator();
457 if (thisComparator != 0 && thisComparator != 1) {
461 <<
" Found comparator digi with wrong comparator value = " << thisComparator <<
"; skipping it... +++\n";
466 int thisStrip = pld->getStrip() - 1;
467 if (thisStrip < 0 || thisStrip >=
numStrips_) {
471 <<
" Found comparator digi with wrong strip number = " << thisStrip <<
" (max strips = " <<
numStrips_
472 <<
"); skipping it... +++\n";
478 int thisHalfstrip = 2 * thisStrip + thisComparator +
stagger[i_layer];
483 <<
" Found wrong halfstrip number = " << thisHalfstrip <<
"; skipping this digi... +++\n";
488 std::vector<int> bx_times = pld->getTimeBinsOn();
489 for (
unsigned int i = 0;
i < bx_times.size();
i++) {
499 if (bx_times[
i] > 1 && bx_times[
i] < static_cast<int>(
fifo_tbins)) {
500 if (
i == 0 || (
i > 0 && bx_times[
i] - bx_times[
i - 1] >= static_cast<int>(
hit_persist))) {
506 <<
"Comp digi: layer " << i_layer + 1 <<
" digi #" << i_digi + 1 <<
" strip " << thisStrip
507 <<
" halfstrip " << thisHalfstrip <<
" time " << bx_times[
i] <<
" comparator " << thisComparator
508 <<
" stagger " << stagger[i_layer];
509 halfstrip[i_layer][thisHalfstrip].push_back(bx_times[
i]);
514 <<
" Skipping comparator digi: strip = " << thisStrip <<
", layer = " << i_layer + 1
515 <<
", bx = " << bx_times[
i] <<
", bx of previous hit = " << bx_times[
i - 1];
520 <<
theChamber <<
"+++ Skipping comparator digi: strip = " << thisStrip
521 <<
", layer = " << i_layer + 1 <<
", bx = " << bx_times[
i] <<
" +++";
531 std::vector<CSCCLCTDigi> lctList;
544 while (start_bx < stop_bx) {
552 bool pre_trig =
preTrigger(start_bx, first_bx);
559 LogTrace(
"CSCCathodeLCTProcessor") <<
"..... pretrigger at bx = " << first_bx <<
"; waiting drift delay .....";
570 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>> hits_in_patterns;
571 hits_in_patterns.clear();
579 if (
nhits[hstrip] > 0) {
581 <<
" bx = " << std::setw(2) << latch_bx <<
" --->"
582 <<
" halfstrip = " << std::setw(3) << hstrip <<
" best pid = " << std::setw(2) <<
best_pid[hstrip]
583 <<
" nhits = " <<
nhits[hstrip];
601 best_halfstrip[ilct] = -1;
602 best_quality[ilct] = 0;
611 quality[hstrip] = (
best_pid[hstrip] & 14) | (
nhits[hstrip] << 5);
612 if (quality[hstrip] > best_quality[0]) {
613 best_halfstrip[0] = hstrip;
614 best_quality[0] = quality[hstrip];
617 const int best_hs(best_halfstrip[0]);
627 if (best_halfstrip[0] >= 0) {
638 if (quality[hstrip] > best_quality[1]) {
639 best_halfstrip[1] = hstrip;
640 best_quality[1] = quality[hstrip];
643 const int best_hs(best_halfstrip[1]);
652 lctList.push_back(tempBestCLCT);
654 if (tempSecondCLCT.
isValid()) {
655 lctList.push_back(tempSecondCLCT);
669 for (
unsigned int bx = latch_bx + 1;
bx < stop_time;
bx++) {
670 bool return_to_idle =
true;
677 LogTrace(
"CSCCathodeLCTProcessor") <<
" State machine busy at bx = " <<
bx;
678 return_to_idle =
false;
683 if (return_to_idle) {
685 LogTrace(
"CSCCathodeLCTProcessor") <<
" State machine returns to idle state at bx = " <<
bx;
692 start_bx = first_bx + 1;
719 if (!time[i_layer][i_strip].
empty()) {
720 std::vector<int> bx_times = time[i_layer][i_strip];
721 for (
unsigned int i = 0;
i < bx_times.size();
i++) {
723 if (bx_times[
i] < 0 || bx_times[
i] +
hit_persist >= bits_in_pulse) {
726 <<
"+++ BX time of comparator digi (halfstrip = " << i_strip <<
" layer = " << i_layer
727 <<
") bx = " << bx_times[
i] <<
" is not within the range (0-" << bits_in_pulse
728 <<
"] allowed for pulse extension. Skip this digi! +++\n";
743 LogTrace(
"CSCCathodeLCTProcessor") <<
"....................PreTrigger...........................";
745 int nPreTriggers = 0;
747 bool pre_trig =
false;
749 for (
unsigned int bx_time = start_bx; bx_time <
fifo_tbins; bx_time++) {
756 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>> hits_in_patterns;
757 hits_in_patterns.clear();
767 if (
nhits[hstrip] > 0) {
769 <<
" bx = " << std::setw(2) << bx_time <<
" --->"
770 <<
" halfstrip = " << std::setw(3) << hstrip <<
" best pid = " << std::setw(2) <<
best_pid[hstrip]
771 <<
" nhits = " <<
nhits[hstrip];
794 LogTrace(
"CSCCathodeLCTProcessor") <<
"no pretrigger, returning \n";
801 const unsigned int bx_time, std::map<
int, std::map<int, CSCCLCTDigi::ComparatorContainer>>& hits_in_patterns) {
809 for (
int key_hstrip = 0; key_hstrip <
numHalfStrips_; key_hstrip++) {
811 nhits[key_hstrip] = 0;
823 hit_layer[ilayer] =
false;
828 hits_single_pattern.resize(6);
829 for (
auto&
p : hits_single_pattern) {
834 double num_pattern_hits = 0., times_sum = 0.;
835 std::multiset<int> mset_for_median;
836 mset_for_median.clear();
850 if (this_strip >= 0 && this_strip < numHalfStrips_) {
852 LogTrace(
"CSCCathodeLCTProcessor") <<
" In patternFinding: key_strip = " << key_hstrip <<
" pid = " << pid
853 <<
" layer = " << this_layer <<
" strip = " << this_strip << std::endl;
857 if (hit_layer[this_layer] ==
false) {
858 hit_layer[this_layer] =
true;
861 hits_single_pattern[this_layer][strip_num] = this_strip -
stagger[this_layer];
866 int first_bx_layer = bx_time;
867 for (
unsigned int dbx = 0; dbx <
hit_persist; dbx++) {
873 times_sum += (double)first_bx_layer;
874 num_pattern_hits += 1.;
875 mset_for_median.insert(first_bx_layer);
877 LogTrace(
"CSCCathodeLCTProcessor") <<
" 1st bx in layer: " << first_bx_layer <<
" sum bx: " << times_sum
878 <<
" #pat. hits: " << num_pattern_hits;
886 hits_in_patterns[key_hstrip][pid] = hits_single_pattern;
890 if (layers_hit >
nhits[key_hstrip]) {
892 nhits[key_hstrip] = layers_hit;
895 if (
nhits[key_hstrip] == CSCConstants::NUM_LAYERS)
908 const int best_patid,
913 for (
int hstrip = best_hstrip - nspan; hstrip <= best_hstrip + pspan; hstrip++) {
914 if (hstrip >= 0 && hstrip < CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER) {
921 const unsigned halfstrip_withstagger,
925 const unsigned pattern =
best_pid[halfstrip_withstagger];
958 LogTrace(
"CSCCathodeLCTProcessor") <<
"Produce CLCT " << clct << std::endl;
965 const unsigned hstrip,
966 const unsigned nPreTriggers)
const {
981 for (
auto&
p : newHits) {
994 std::ostringstream strm;
996 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
997 strm <<
"+ CLCT configuration parameters: +\n";
998 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
999 strm <<
" fifo_tbins [total number of time bins in DAQ readout] = " <<
fifo_tbins <<
"\n";
1000 strm <<
" fifo_pretrig [start time of cathode raw hits in DAQ readout] = " <<
fifo_pretrig <<
"\n";
1001 strm <<
" hit_persist [duration of signal pulse, in 25 ns bins] = " <<
hit_persist <<
"\n";
1002 strm <<
" drift_delay [time after pre-trigger before TMB latches LCTs] = " <<
drift_delay <<
"\n";
1003 strm <<
" nplanes_hit_pretrig [min. number of layers hit for pre-trigger] = " <<
nplanes_hit_pretrig <<
"\n";
1004 strm <<
" nplanes_hit_pattern [min. number of layers hit for trigger] = " <<
nplanes_hit_pattern <<
"\n";
1005 strm <<
" pid_thresh_pretrig [lower threshold on pattern id] = " <<
pid_thresh_pretrig <<
"\n";
1006 strm <<
" min_separation [region of busy key strips] = " <<
min_separation <<
"\n";
1007 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1008 LogDebug(
"CSCCathodeLCTProcessor") << strm.str();
1016 std::ostringstream strstrm;
1018 if (i_strip % 10 == 0) {
1020 strstrm << i_strip / 10;
1022 strstrm << (i_strip - 100) / 10;
1030 strstrm << i_strip % 10;
1038 std::vector<int> bx_times =
strip[i_layer][i_strip];
1040 strstrm << std::hex << bx_times[0] <<
std::dec;
1048 LogTrace(
"CSCCathodeLCTProcessor") << strstrm.str();
1055 std::vector<CSCCLCTDigi> tmpV;
1076 if (early_tbin < 0) {
1078 <<
"Early time bin (early_tbin) smaller than minimum allowed, which is 0. set early_tbin to 0.";
1081 if (late_tbin > max_late_tbin) {
1083 <<
"Late time bin (late_tbin) larger than maximum allowed, which is " << max_late_tbin
1084 <<
". set early_tbin to max allowed";
1089 const auto& all_clcts =
getCLCTs();
1093 int bx_readout = -1;
1094 for (
const auto& clct : all_clcts) {
1096 if (!clct.isValid())
1099 const int bx = clct.getBX();
1101 if (bx < early_tbin) {
1104 <<
" Do not report correlated CLCT on key halfstrip " << clct.getStrip() <<
": found at bx " << bx
1105 <<
", whereas the earliest allowed bx is " << early_tbin;
1110 if (bx > late_tbin) {
1113 <<
" Do not report correlated CLCT on key halfstrip " << clct.getStrip() <<
": found at bx " << bx
1114 <<
", whereas the latest allowed bx is " << late_tbin;
1122 if (bx_readout == -1 || bx == bx_readout) {
1123 tmpV.push_back(clct);
1124 if (bx_readout == -1)
1128 tmpV.push_back(clct);
1133 for (
const auto& clct : tmpV) {
1142 std::vector<CSCCLCTDigi> tmpV;
1178 unsigned nLayersWithHits = 0;
1180 bool atLeastOneWGHit =
false;
1183 if (!halfstrip[i_layer][i_hstrip].
empty()) {
1184 auto times = halfstrip[i_layer][i_hstrip];
1185 int nLayerTime = std::count_if(times.begin(), times.end(), layerTime);
1187 if (nLayerTime > 0) {
1188 atLeastOneWGHit =
true;
1194 if (atLeastOneWGHit) {
1208 unsigned hitsInTime = 0;
1211 auto times = halfstrip[i_layer][i_hstrip];
1212 hitsInTime += std::count_if(times.begin(), times.end(), inTime);
1221 std::vector<unsigned> station_thresholds = {
1225 for (
unsigned i = 0;
i < station_thresholds.size();
i++) {
1226 if (hitsInTime >= station_thresholds[
i]) {
std::unique_ptr< ComparatorCodeLUT > cclut_
void setESLookupTables(const CSCL1TPLookupTableCCLUT *conf)
static const unsigned int def_drift_delay
void dumpDigis(const std::vector< int > strip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]) const
CSCCLCTDigi bestCLCT[CSCConstants::MAX_CLCT_TBINS]
void setDefaultConfigParameters()
std::vector< CSCCLCTDigi > readoutCLCTs() 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)
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
uint16_t getBX() const
return BX
unsigned int min_separation
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
unsigned int clctHitPersist() const
static std::string chamberName(int endcap, int station, int ring, int chamber)
const CSCChamber * cscChamber_
uint32_t const *__restrict__ Quality * quality
CSCShowerDigi readoutShower() const
void checkConfigParameters(unsigned int &var, const unsigned int var_max, const unsigned int var_def, const std::string &var_str)
unsigned int clctNplanesHitPattern() const
void pulseExtension(const std::vector< int > time[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
void dumpConfigParams() const
static const unsigned int def_min_separation
int numberOfStrips() const
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 int clctMinSeparation() const
unsigned int clctNplanesHitPretrig() const
static const unsigned int def_nplanes_hit_pretrig
unsigned int clctDriftDelay() const
uint16_t getKeyStrip(const uint16_t n=2) const
static const unsigned int def_pid_thresh_pretrig
unsigned numberOfLayersAtBX(const unsigned bx) const
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
static const LCTPatterns clct_pattern_run3_
CSCCLCTDigi getSecondCLCT(int bx) const
unsigned int clctPidThreshPretrig() const
unsigned bitsInPulse() const
static const unsigned int def_tmb_l1a_window_size
bool getDigis(const CSCComparatorDigiCollection *compdc)
static const unsigned int def_nplanes_hit_pattern
void setHits(const ComparatorContainer &hits)
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
unsigned showerMinOutTBin_
bool isValid() const
check CLCT validity (1 - valid CLCT)
static const int clct_pattern_offset_[CSCConstants::CLCT_PATTERN_WIDTH]
unsigned short iChamberType() const
bool isOneShotHighAtBX(const unsigned layer, const unsigned channel, const unsigned bx) const
static int getPatternBend(const LCTPattern &pattern)
unsigned int clctFifoPretrig() const
edm::ParameterSet clctParams_
CSCCLCTDigi getBestCLCT(int bx) const
CSCCLCTPreTriggerDigi constructPreCLCT(const int bx, const unsigned halfstrip, const unsigned index) const
std::vector< CSCCLCTPreTriggerDigi > thePreTriggerDigis
unsigned int nplanes_hit_pattern
static const LCTPatterns clct_pattern_legacy_
edm::ParameterSet tmbParams_
std::string chamberName() const
std::vector< CSCCLCTDigi > getCLCTs() const
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()
ParameterSet const & getParameterSet(std::string const &) const
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
T getParameter(std::string const &) const
const unsigned theStation
int stagger[CSCConstants::NUM_LAYERS]
std::vector< DigiType >::const_iterator const_iterator
const ComparatorContainer & getHits() const
void cleanComparatorContainer(CSCCLCTDigi &lct) const
std::vector< CSCCLCTDigi > run(const CSCComparatorDigiCollection *compdc)
void initialize(unsigned numberOfChannels)
void setBX(const uint16_t bx)
set bx
unsigned int clctFifoTbins() const
virtual bool preTrigger(const int start_bx, int &first_bx)
unsigned minLayersCentralTBin_
CSCCLCTDigi secondCLCT[CSCConstants::MAX_CLCT_TBINS]
void clear()
clear this CLCT
std::vector< CSCComparatorDigi > digiV[CSCConstants::NUM_LAYERS]
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])
const CSCLayerGeometry * geometry() 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.
unsigned int best_pid[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]
std::vector< unsigned > thresholds_