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");
100 peakCheck_ = shower.getParameter<
bool>(
"peakCheck");
128 static std::atomic<bool> config_dumped{
false};
141 if (!config_dumped) {
143 config_dumped =
true;
155 static const unsigned int max_fifo_tbins = 1 << 5;
156 static const unsigned int max_fifo_pretrig = 1 << 5;
157 static const unsigned int max_hit_persist = 1 << 4;
158 static const unsigned int max_drift_delay = 1 << 2;
159 static const unsigned int max_nplanes_hit_pretrig = 1 << 3;
160 static const unsigned int max_nplanes_hit_pattern = 1 << 3;
161 static const unsigned int max_pid_thresh_pretrig = 1 << 4;
163 static const unsigned int max_tmb_l1a_window_size = 1 << 4;
197 static std::atomic<bool> config_dumped{
false};
198 if ((
infoV > 0) && !config_dumped) {
200 config_dumped =
true;
218 <<
"+++ Invalid ring number for this processor " <<
theRing <<
" was set in the config." 220 <<
"+++ CSC geometry looks garbled; no emulation possible +++\n";
238 <<
"+++ CSC geometry looks garbled; no emulation possible +++\n";
263 <<
" is not defined in current geometry! +++\n" 264 <<
"+++ CSC geometry looks garbled; no emulation possible +++\n";
275 <<
" numStrips_ = " <<
numStrips_ <<
"; CLCT emulation skipped! +++";
276 std::vector<CSCCLCTDigi> emptyV;
294 unsigned int layersHit = 0;
297 if (!halfStripTimes[i_layer][i_hstrip].
empty()) {
314 std::vector<CSCCLCTDigi> tmpV =
getCLCTs();
323 for (
auto&
p : tmpV) {
342 std::vector<CSCCLCTDigi> CLCTlist =
findLCTs(halfstrip);
344 for (
const auto&
p : CLCTlist) {
345 const int bx =
p.getBX();
350 <<
"; skipping it... +++\n";
392 bool hasDigis =
false;
396 digiV[i_layer].clear();
409 LogTrace(
"CSCCathodeLCTProcessor") <<
"found " <<
digiV[i_layer].size() <<
" comparator digi(s) in layer " 420 const bool me1a = (
id.station() == 1) && (
id.
ring() == 4);
423 const unsigned int origStrip = digiIt->getStrip();
424 const unsigned int maxStripsME1a =
428 if (me1a && origStrip <= maxStripsME1a && !
disableME1a_) {
433 digiV[
id.layer() - 1].push_back(digi_corr);
435 digiV[
id.layer() - 1].push_back(*digiIt);
444 for (std::vector<CSCComparatorDigi>::iterator pld =
digiV[i_layer].begin(); pld !=
digiV[i_layer].end();
448 std::ostringstream strstrm;
449 strstrm <<
"Comparator digi: comparator = " << pld->getComparator() <<
" strip #" << pld->getStrip()
451 std::vector<int> bx_times = pld->getTimeBinsOn();
452 for (
unsigned int tbin = 0; tbin < bx_times.size(); tbin++)
453 strstrm <<
" " << bx_times[tbin];
454 LogTrace(
"CSCCathodeLCTProcessor") << strstrm.str();
459 int thisComparator = pld->getComparator();
460 if (thisComparator != 0 && thisComparator != 1) {
464 <<
" Found comparator digi with wrong comparator value = " << thisComparator <<
"; skipping it... +++\n";
469 int thisStrip = pld->getStrip() - 1;
470 if (thisStrip < 0 || thisStrip >=
numStrips_) {
474 <<
" Found comparator digi with wrong strip number = " << thisStrip <<
" (max strips = " <<
numStrips_ 475 <<
"); skipping it... +++\n";
481 int thisHalfstrip = 2 * thisStrip + thisComparator +
stagger[i_layer];
486 <<
" Found wrong halfstrip number = " << thisHalfstrip <<
"; skipping this digi... +++\n";
491 std::vector<int> bx_times = pld->getTimeBinsOn();
492 for (
unsigned int i = 0;
i < bx_times.size();
i++) {
502 if (bx_times[
i] > 1 && bx_times[
i] < static_cast<int>(
fifo_tbins)) {
503 if (
i == 0 || (
i > 0 && bx_times[
i] - bx_times[
i - 1] >= static_cast<int>(
hit_persist))) {
509 <<
"Comp digi: layer " << i_layer + 1 <<
" digi #" << i_digi + 1 <<
" strip " << thisStrip
510 <<
" halfstrip " << thisHalfstrip <<
" time " << bx_times[
i] <<
" comparator " << thisComparator
511 <<
" stagger " <<
stagger[i_layer];
512 halfstrip[i_layer][thisHalfstrip].push_back(bx_times[
i]);
517 <<
" Skipping comparator digi: strip = " << thisStrip <<
", layer = " << i_layer + 1
518 <<
", bx = " << bx_times[
i] <<
", bx of previous hit = " << bx_times[
i - 1];
523 <<
theChamber <<
"+++ Skipping comparator digi: strip = " << thisStrip
524 <<
", layer = " << i_layer + 1 <<
", bx = " << bx_times[
i] <<
" +++";
534 std::vector<CSCCLCTDigi> lctList;
547 while (start_bx < stop_bx) {
555 bool pre_trig =
preTrigger(start_bx, first_bx);
562 LogTrace(
"CSCCathodeLCTProcessor") <<
"..... pretrigger at bx = " << first_bx <<
"; waiting drift delay .....";
573 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>> hits_in_patterns;
574 hits_in_patterns.clear();
582 if (
nhits[hstrip] > 0) {
584 <<
" bx = " << std::setw(2) << latch_bx <<
" --->" 585 <<
" halfstrip = " << std::setw(3) << hstrip <<
" best pid = " << std::setw(2) <<
best_pid[hstrip]
586 <<
" nhits = " <<
nhits[hstrip];
604 best_halfstrip[ilct] = -1;
605 best_quality[ilct] = 0;
615 if (
quality[hstrip] > best_quality[0]) {
616 best_halfstrip[0] = hstrip;
617 best_quality[0] =
quality[hstrip];
620 const int best_hs(best_halfstrip[0]);
630 if (best_halfstrip[0] >= 0) {
641 if (
quality[hstrip] > best_quality[1]) {
642 best_halfstrip[1] = hstrip;
643 best_quality[1] =
quality[hstrip];
646 const int best_hs(best_halfstrip[1]);
657 bool changeOrder =
false;
659 unsigned qualityBest = 0, qualitySecond = 0;
660 unsigned patternBest = 0, patternSecond = 0;
661 unsigned halfStripBest = 0, halfStripSecond = 0;
676 if (qualitySecond > qualityBest)
678 else if ((qualitySecond == qualityBest) and (
int(patternSecond / 2) >
int(patternBest / 2)))
680 else if ((qualitySecond == qualityBest) and (
int(patternSecond / 2) ==
int(patternBest / 2)) and
681 (halfStripSecond < halfStripBest))
687 tempCLCT = tempBestCLCT;
688 tempBestCLCT = tempSecondCLCT;
689 tempSecondCLCT = tempCLCT;
694 lctList.push_back(tempBestCLCT);
696 if (tempSecondCLCT.
isValid()) {
697 lctList.push_back(tempSecondCLCT);
711 for (
unsigned int bx = latch_bx + 1;
bx < stop_time;
bx++) {
712 bool return_to_idle =
true;
719 LogTrace(
"CSCCathodeLCTProcessor") <<
" State machine busy at bx = " <<
bx;
720 return_to_idle =
false;
725 if (return_to_idle) {
727 LogTrace(
"CSCCathodeLCTProcessor") <<
" State machine returns to idle state at bx = " <<
bx;
734 start_bx = first_bx + 1;
762 std::vector<int> bx_times =
time[i_layer][i_strip];
763 for (
unsigned int i = 0;
i < bx_times.size();
i++) {
765 if (bx_times[
i] < 0 || bx_times[
i] +
hit_persist >= bits_in_pulse) {
768 <<
"+++ BX time of comparator digi (halfstrip = " << i_strip <<
" layer = " << i_layer
769 <<
") bx = " << bx_times[
i] <<
" is not within the range (0-" << bits_in_pulse
770 <<
"] allowed for pulse extension. Skip this digi! +++\n";
785 LogTrace(
"CSCCathodeLCTProcessor") <<
"....................PreTrigger...........................";
787 int nPreTriggers = 0;
789 bool pre_trig =
false;
791 for (
unsigned int bx_time = start_bx; bx_time <
fifo_tbins; bx_time++) {
798 std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>> hits_in_patterns;
799 hits_in_patterns.clear();
809 if (
nhits[hstrip] > 0) {
811 <<
" bx = " << std::setw(2) << bx_time <<
" --->" 812 <<
" halfstrip = " << std::setw(3) << hstrip <<
" best pid = " << std::setw(2) <<
best_pid[hstrip]
813 <<
" nhits = " <<
nhits[hstrip];
836 LogTrace(
"CSCCathodeLCTProcessor") <<
"no pretrigger, returning \n";
843 const unsigned int bx_time,
std::map<
int, std::map<int, CSCCLCTDigi::ComparatorContainer>>& hits_in_patterns) {
851 for (
int key_hstrip = 0; key_hstrip <
numHalfStrips_; key_hstrip++) {
853 nhits[key_hstrip] = 0;
865 hit_layer[ilayer] =
false;
870 hits_single_pattern.resize(6);
871 for (
auto&
p : hits_single_pattern) {
876 double num_pattern_hits = 0., times_sum = 0.;
877 std::multiset<int> mset_for_median;
878 mset_for_median.clear();
894 LogTrace(
"CSCCathodeLCTProcessor") <<
" In patternFinding: key_strip = " << key_hstrip <<
" pid = " << pid
895 <<
" layer = " << this_layer <<
" strip = " << this_strip << std::endl;
899 if (hit_layer[this_layer] ==
false) {
900 hit_layer[this_layer] =
true;
903 hits_single_pattern[this_layer][strip_num] = this_strip -
stagger[this_layer];
908 int first_bx_layer = bx_time;
909 for (
unsigned int dbx = 0; dbx <
hit_persist; dbx++) {
915 times_sum += (double)first_bx_layer;
916 num_pattern_hits += 1.;
917 mset_for_median.insert(first_bx_layer);
919 LogTrace(
"CSCCathodeLCTProcessor") <<
" 1st bx in layer: " << first_bx_layer <<
" sum bx: " << times_sum
920 <<
" #pat. hits: " << num_pattern_hits;
928 hits_in_patterns[key_hstrip][pid] = hits_single_pattern;
932 if (layers_hit >
nhits[key_hstrip]) {
934 nhits[key_hstrip] = layers_hit;
950 const int best_patid,
955 for (
int hstrip = best_hstrip - nspan; hstrip <= best_hstrip + pspan; hstrip++) {
963 const unsigned halfstrip_withstagger,
1000 LogTrace(
"CSCCathodeLCTProcessor") <<
"Produce CLCT " << clct << std::endl;
1007 const unsigned hstrip,
1008 const unsigned nPreTriggers)
const {
1023 for (
auto&
p : newHits) {
1036 std::ostringstream strm;
1038 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1039 strm <<
"+ CLCT configuration parameters: +\n";
1040 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1041 strm <<
" fifo_tbins [total number of time bins in DAQ readout] = " <<
fifo_tbins <<
"\n";
1042 strm <<
" fifo_pretrig [start time of cathode raw hits in DAQ readout] = " <<
fifo_pretrig <<
"\n";
1043 strm <<
" hit_persist [duration of signal pulse, in 25 ns bins] = " <<
hit_persist <<
"\n";
1044 strm <<
" drift_delay [time after pre-trigger before TMB latches LCTs] = " <<
drift_delay <<
"\n";
1045 strm <<
" nplanes_hit_pretrig [min. number of layers hit for pre-trigger] = " <<
nplanes_hit_pretrig <<
"\n";
1046 strm <<
" nplanes_hit_pattern [min. number of layers hit for trigger] = " <<
nplanes_hit_pattern <<
"\n";
1047 strm <<
" pid_thresh_pretrig [lower threshold on pattern id] = " <<
pid_thresh_pretrig <<
"\n";
1048 strm <<
" min_separation [region of busy key strips] = " <<
min_separation <<
"\n";
1049 strm <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1050 LogDebug(
"CSCCathodeLCTProcessor") << strm.str();
1058 std::ostringstream strstrm;
1060 if (i_strip % 10 == 0) {
1062 strstrm << i_strip / 10;
1064 strstrm << (i_strip - 100) / 10;
1072 strstrm << i_strip % 10;
1080 std::vector<int> bx_times =
strip[i_layer][i_strip];
1082 strstrm << std::hex << bx_times[0] <<
std::dec;
1090 LogTrace(
"CSCCathodeLCTProcessor") << strstrm.str();
1097 std::vector<CSCCLCTDigi> tmpV;
1118 if (early_tbin < 0) {
1120 <<
"Early time bin (early_tbin) smaller than minimum allowed, which is 0. set early_tbin to 0.";
1123 if (late_tbin > max_late_tbin) {
1125 <<
"Late time bin (late_tbin) larger than maximum allowed, which is " << max_late_tbin
1126 <<
". set early_tbin to max allowed";
1131 const auto& all_clcts =
getCLCTs();
1135 int bx_readout = -1;
1136 for (
const auto& clct : all_clcts) {
1138 if (!clct.isValid())
1141 const int bx = clct.getBX();
1143 if (
bx < early_tbin) {
1146 <<
" Do not report correlated CLCT on key halfstrip " << clct.getStrip() <<
": found at bx " <<
bx 1147 <<
", whereas the earliest allowed bx is " << early_tbin;
1152 if (
bx > late_tbin) {
1155 <<
" Do not report correlated CLCT on key halfstrip " << clct.getStrip() <<
": found at bx " <<
bx 1156 <<
", whereas the latest allowed bx is " << late_tbin;
1164 if (bx_readout == -1 ||
bx == bx_readout) {
1165 tmpV.push_back(clct);
1166 if (bx_readout == -1)
1170 tmpV.push_back(clct);
1175 for (
const auto& clct : tmpV) {
1184 std::vector<CSCCLCTDigi> tmpV;
1219 std::vector<CSCShowerDigi> showerOut;
1236 bool atLeastOneCompHit =
false;
1237 for (
const auto& compdigi :
digiV[i_layer]) {
1238 std::vector<int> bx_times = compdigi.getTimeBinsOn();
1240 if (
std::find(bx_times.begin(), bx_times.end(),
bx) != bx_times.end()) {
1241 hitsInTime[
bx] += 1;
1242 atLeastOneCompHit =
true;
1246 if (atLeastOneCompHit) {
1247 layersWithHits[
bx].insert(i_layer);
1257 std::vector<unsigned> station_thresholds = {
1264 unsigned int deadtime =
1266 unsigned int dead_count = 0;
1272 unsigned this_hitsInTime = 0;
1275 for (
unsigned mbx = minbx; mbx <= maxbx; mbx++) {
1276 this_hitsInTime += hitsInTime[mbx];
1280 if (hitsInTime[minbx] < hitsInTime[maxbx + 1]
or 1281 (hitsInTime[minbx] == hitsInTime[maxbx + 1] and hitsInTime[
bx] < hitsInTime[
bx + 1]))
1284 bool dead_status = dead_count > 0;
1288 unsigned this_inTimeHMT = 0;
1293 if (!station_thresholds.empty()) {
1294 for (
int i = station_thresholds.size() - 1;
i >= 0;
i--) {
1295 if (this_hitsInTime >= station_thresholds[
i]) {
1296 this_inTimeHMT =
i + 1;
1297 dead_count = deadtime;
1305 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)
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
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()
static const unsigned int def_fifo_pretrig
std::vector< int > thePreTriggerBXs
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
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.
unsigned int clctDriftDelay() const
unsigned int best_pid[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]
std::vector< unsigned > thresholds_