CMS 3D CMS Logo

CSCUpgradeMotherboard.cc
Go to the documentation of this file.
2 
4  : match_trig_window_size_(trig_window_size)
5 {
6 }
7 
9 CSCUpgradeMotherboard::LCTContainer::operator()(int bx, int match_bx, int lct)
10 {
11  return data[bx][match_bx][lct];
12 }
13 
14 void
16  std::vector<CSCCorrelatedLCTDigi>& lcts) const
17 {
18  for (unsigned int mbx = 0; mbx < match_trig_window_size_; mbx++) {
19  for (int i=0; i < CSCConstants::MAX_LCTS_PER_CSC ;i++) {
20  // consider only valid LCTs
21  if (not data[bx][mbx][i].isValid()) continue;
22 
23  // remove duplicated LCTs
24  if (std::find(lcts.begin(), lcts.end(), data[bx][mbx][i]) != lcts.end()) continue;
25 
26  lcts.push_back(data[bx][mbx][i]);
27  }
28  }
29 }
30 
31 void
32 CSCUpgradeMotherboard::LCTContainer::getMatched(std::vector<CSCCorrelatedLCTDigi>& lcts) const
33 {
34  for (int bx = 0; bx < CSCConstants::MAX_LCT_TBINS; bx++){
35  std::vector<CSCCorrelatedLCTDigi> temp_lcts;
37  lcts.insert(std::end(lcts), std::begin(temp_lcts), std::end(temp_lcts));
38  }
39 }
40 
41 void
43 {
44  // Loop over all time windows
45  for (int bx = 0; bx < CSCConstants::MAX_LCT_TBINS; bx++) {
46  // Loop over all matched trigger windows
47  for (unsigned int mbx = 0; mbx < match_trig_window_size_; mbx++) {
48  // Loop over all stubs
49  for (int i=0;i<CSCConstants::MAX_LCTS_PER_CSC;i++) {
50  data[bx][mbx][i].clear();
51  }
52  }
53  }
54 }
55 
57  unsigned sector, unsigned subsector,
58  unsigned chamber,
59  const edm::ParameterSet& conf) :
60  // special configuration parameters for ME11 treatment
61  CSCMotherboard(endcap, station, sector, subsector, chamber, conf)
63 {
64  if (!isSLHC_) edm::LogError("CSCUpgradeMotherboard|ConfigError")
65  << "+++ Upgrade CSCUpgradeMotherboard constructed while isSLHC_ is not set! +++\n";
66 
68 
69  // generate the LUTs
71 
72  // enable the upgrade processors
73  if (isSLHC_ and theRing == 1) {
74  clctProc.reset( new CSCUpgradeCathodeLCTProcessor(endcap, station, sector, subsector, chamber, conf) );
75  if (enableAlctSLHC_) {
76  alctProc.reset( new CSCUpgradeAnodeLCTProcessor(endcap, station, sector, subsector, chamber, conf) );
77  }
78  }
79 
80  match_earliest_alct_only = tmbParams_.getParameter<bool>("matchEarliestAlctOnly");
81  match_earliest_clct_only = tmbParams_.getParameter<bool>("matchEarliestClctOnly");
82  clct_to_alct = tmbParams_.getParameter<bool>("clctToAlct");
83  drop_used_clcts = tmbParams_.getParameter<bool>("tmbDropUsedClcts");
84  tmb_cross_bx_algo = tmbParams_.getParameter<unsigned int>("tmbCrossBxAlgorithm");
85  max_lcts = tmbParams_.getParameter<unsigned int>("maxLCTs");
86  debug_matching = tmbParams_.getParameter<bool>("debugMatching");
87  debug_luts = tmbParams_.getParameter<bool>("debugLUTs");
88 
89  setPrefIndex();
90 }
91 
93  : CSCMotherboard()
95 {
96  if (!isSLHC_) edm::LogError("CSCUpgradeMotherboard|ConfigError")
97  << "+++ Upgrade CSCUpgradeMotherboard constructed while isSLHC_ is not set! +++\n";
98 
99  setPrefIndex();
100 }
101 
102 void
104  const CSCComparatorDigiCollection* compdc)
105 {
106  clear();
107 
108  if (!( alctProc and clctProc))
109  {
110  if (infoV >= 0) edm::LogError("CSCUpgradeMotherboard|SetupError")
111  << "+++ run() called for non-existing ALCT/CLCT processor! +++ \n";
112  return;
113  }
114 
115  alctProc->setCSCGeometry(cscGeometry_);
116  clctProc->setCSCGeometry(cscGeometry_);
117 
118  alctV = alctProc->run(wiredc); // run anodeLCT
119  clctV = clctProc->run(compdc); // run cathodeLCT
120 
121  // if there are no ALCTs and no CLCTs, it does not make sense to run this TMB
122  if (alctV.empty() and clctV.empty()) return;
123 
124  int used_clct_mask[20];
125  for (int c=0;c<20;++c) used_clct_mask[c]=0;
126 
127  // ALCT centric matching
128  for (int bx_alct = 0; bx_alct < CSCConstants::MAX_ALCT_TBINS; bx_alct++) {
129  if (alctProc->bestALCT[bx_alct].isValid()) {
130  const int bx_clct_start(bx_alct - match_trig_window_size/2 - alctClctOffset_);
131  const int bx_clct_stop(bx_alct + match_trig_window_size/2 - alctClctOffset_);
132 
133  if (debug_matching){
134  LogTrace("CSCUpgradeMotherboard") << "========================================================================" << std::endl;
135  LogTrace("CSCUpgradeMotherboard") << "ALCT-CLCT matching in ME34/1 chamber: " << cscId_ << std::endl;
136  LogTrace("CSCUpgradeMotherboard") << "------------------------------------------------------------------------" << std::endl;
137  LogTrace("CSCUpgradeMotherboard") << "+++ Best ALCT Details: ";
138  alctProc->bestALCT[bx_alct].print();
139  LogTrace("CSCUpgradeMotherboard") << "+++ Second ALCT Details: ";
140  alctProc->secondALCT[bx_alct].print();
141 
142  LogTrace("CSCUpgradeMotherboard") << "------------------------------------------------------------------------" << std::endl;
143  LogTrace("CSCUpgradeMotherboard") << "Attempt ALCT-CLCT matching in ME34/13 in bx range: [" << bx_clct_start << "," << bx_clct_stop << "]" << std::endl;
144  }
145 
146  // ALCT-to-CLCT
147  for (int bx_clct = bx_clct_start; bx_clct <= bx_clct_stop; bx_clct++) {
148  if (bx_clct < 0 or bx_clct >= CSCConstants::MAX_CLCT_TBINS) continue;
149  if (drop_used_clcts and used_clct_mask[bx_clct]) continue;
150  if (clctProc->bestCLCT[bx_clct].isValid()) {
151  if (debug_matching) LogTrace("CSCUpgradeMotherboard") << "++Valid ME21 CLCT: " << clctProc->bestCLCT[bx_clct] << std::endl;
152 
153  int mbx = bx_clct-bx_clct_start;
154  CSCUpgradeMotherboard::correlateLCTs(alctProc->bestALCT[bx_alct], alctProc->secondALCT[bx_alct],
155  clctProc->bestCLCT[bx_clct], clctProc->secondCLCT[bx_clct],
156  allLCTs(bx_alct,mbx,0), allLCTs(bx_alct,mbx,1));
157  if (infoV > 1)
158  LogTrace("CSCUpgradeMotherboard") << "Successful ALCT-CLCT match in ME21: bx_alct = " << bx_alct
159  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop
160  << "]; bx_clct = " << bx_clct << std::endl;
161  LogTrace("CSCUpgradeMotherboard") << "+++ Best CLCT Details: ";
162  clctProc->bestCLCT[bx_clct].print();
163  LogTrace("CSCUpgradeMotherboard") << "+++ Second CLCT Details: ";
164  clctProc->secondCLCT[bx_clct].print();
165  if (allLCTs(bx_alct,mbx,0).isValid()) {
166  used_clct_mask[bx_clct] += 1;
167  if (match_earliest_clct_only) break;
168  }
169  }
170  }
171  }
172  }
173 
174  // reduction of nLCTs per each BX
175  for (int bx = 0; bx < CSCConstants::MAX_LCT_TBINS; bx++) {
176  // counting
177  unsigned int n=0;
178  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++) {
179  for (int i=0;i<CSCConstants::MAX_LCTS_PER_CSC;i++) {
180  if (allLCTs(bx,mbx,i).isValid()) {
181  ++n;
182  if (infoV > 0) {
183  LogDebug("CSCUpgradeMotherboard")
184  << "LCT"<<i+1<<" "<<bx<<"/"<<bx + mbx - match_trig_window_size/2<<": "<<allLCTs(bx,mbx,i)<<std::endl;
185  }
186  }
187  }
188  }
189 
190  // some simple cross-bx sorting algorithms
191  if (tmb_cross_bx_algo == 1 and (n>2)) {
192  n=0;
193  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++) {
194  for (int i=0;i<CSCConstants::MAX_LCTS_PER_CSC;i++) {
195  if (allLCTs(bx,pref[mbx],i).isValid()) {
196  n++;
197  if (n>2) allLCTs(bx,pref[mbx],i).clear();
198  }
199  }
200  }
201 
202  n=0;
203  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++) {
204  for (int i=0;i<CSCConstants::MAX_LCTS_PER_CSC;i++) {
205  if (allLCTs(bx,mbx,i).isValid()) {
206  n++;
207  if (infoV > 0) {
208  LogDebug("CSCUpgradeMotherboard")
209  << "LCT"<<i+1<<" "<<bx<<"/"<<bx + mbx - match_trig_window_size/2<<": "<<allLCTs(bx,mbx,i)<< std::endl;
210  }
211  }
212  }
213  }
214  if (infoV > 0 and n>0) LogDebug("CSCUpgradeMotherboard")
215  <<"bx "<<bx<<" nnLCT:"<<n<<" "<<n<<std::endl;
216  } // x-bx sorting
217  }
218 
219  bool first = true;
220  unsigned int n=0;
221  for (const auto& p : readoutLCTs()) {
222  if (debug_matching and first){
223  LogTrace("CSCUpgradeMotherboard") << "========================================================================" << std::endl;
224  LogTrace("CSCUpgradeMotherboard") << "Counting the final LCTs" << std::endl;
225  LogTrace("CSCUpgradeMotherboard") << "========================================================================" << std::endl;
226  first = false;
227  LogTrace("CSCUpgradeMotherboard") << "tmb_cross_bx_algo: " << tmb_cross_bx_algo << std::endl;
228  }
229  n++;
230  if (debug_matching)
231  LogTrace("CSCUpgradeMotherboard") << "LCT "<<n<<" " << p <<std::endl;
232  }
233 }
234 
236  const CSCCLCTDigi& bCLCT, const CSCCLCTDigi& sCLCT,
237  CSCCorrelatedLCTDigi& lct1, CSCCorrelatedLCTDigi& lct2) const
238 {
239  CSCALCTDigi bestALCT = bALCT;
240  CSCALCTDigi secondALCT = sALCT;
241  CSCCLCTDigi bestCLCT = bCLCT;
242  CSCCLCTDigi secondCLCT = sCLCT;
243 
244  const bool anodeBestValid = bestALCT.isValid();
245  const bool anodeSecondValid = secondALCT.isValid();
246  const bool cathodeBestValid = bestCLCT.isValid();
247  const bool cathodeSecondValid = secondCLCT.isValid();
248 
249  if (anodeBestValid and !anodeSecondValid) secondALCT = bestALCT;
250  if (!anodeBestValid and anodeSecondValid) bestALCT = secondALCT;
251  if (cathodeBestValid and !cathodeSecondValid) secondCLCT = bestCLCT;
252  if (!cathodeBestValid and cathodeSecondValid) bestCLCT = secondCLCT;
253 
254  // ALCT-CLCT matching conditions are defined by "trig_enable" configuration
255  // parameters.
256  if ((alct_trig_enable and bestALCT.isValid()) or
257  (clct_trig_enable and bestCLCT.isValid()) or
258  (match_trig_enable and bestALCT.isValid() and bestCLCT.isValid())){
259  lct1 = constructLCTs(bestALCT, bestCLCT, CSCCorrelatedLCTDigi::ALCTCLCT, 1);
260  }
261 
262  if (((secondALCT != bestALCT) or (secondCLCT != bestCLCT)) and
263  ((alct_trig_enable and secondALCT.isValid()) or
264  (clct_trig_enable and secondCLCT.isValid()) or
265  (match_trig_enable and secondALCT.isValid() and secondCLCT.isValid()))){
266  lct2 = constructLCTs(secondALCT, secondCLCT, CSCCorrelatedLCTDigi::ALCTCLCT, 2);
267  }
268 }
269 
270 //readout LCTs
271 std::vector<CSCCorrelatedLCTDigi> CSCUpgradeMotherboard::readoutLCTs() const
272 {
273  std::vector<CSCCorrelatedLCTDigi> result;
274  allLCTs.getMatched(result);
276  return result;
277 }
278 
280 {
281 }
282 
284 {
285  if (theStation == 1 and (theRing ==1 or theRing == 4)){
286  if (keystrip > CSCConstants::MAX_HALF_STRIP_ME1B){
287  if ( gangedME1a_ )
288  return CSCPart::ME1Ag;
289  else
290  return CSCPart::ME1A;
291  }else if (keystrip <= CSCConstants::MAX_HALF_STRIP_ME1B and keystrip >= 0)
292  return CSCPart::ME1B;
293  else
294  return CSCPart::ME11;
295  }else if (theStation == 2 and theRing == 1 )
296  return CSCPart::ME21;
297  else if (theStation == 3 and theRing == 1 )
298  return CSCPart::ME31;
299  else if (theStation == 4 and theRing == 1 )
300  return CSCPart::ME41;
301  else{
302  edm::LogError("CSCUpgradeMotherboard|Error") <<" ++ getCSCPart() failed to find the CSC chamber for in case ";
303  return CSCPart::ME11;// return ME11 by default
304  }
305 }
306 
308 {
310 }
311 
313 {
314  return lct1.getQuality() > lct2.getQuality();
315 }
316 
318 {
319  return true;
320 }
321 
322 void CSCUpgradeMotherboard::sortLCTs(std::vector<CSCCorrelatedLCTDigi>& lcts,
323  bool (*sorter)(const CSCCorrelatedLCTDigi&, const CSCCorrelatedLCTDigi&)) const
324 {
325  std::sort(lcts.begin(), lcts.end(), *sorter);
326  if (lcts.size() > max_lcts) lcts.erase(lcts.begin()+max_lcts, lcts.end());
327 }
328 
329 
331 {
332  generator_->setCSCGeometry(cscGeometry_);
333 }
334 
335 
337 {
339  for (unsigned int m=2; m<match_trig_window_size; m+=2)
340  {
341  pref[m-1] = pref[0] - m/2;
342  pref[m] = pref[0] + m/2;
343  }
344 }
345 
346 
348 {
350  allLCTs.clear();
351 }
#define LogDebug(id)
CSCCorrelatedLCTDigi data[CSCConstants::MAX_LCT_TBINS][CSCConstants::MAX_MATCH_WINDOW_SIZE][CSCConstants::MAX_LCTS_PER_CSC]
T getParameter(std::string const &) const
std::vector< CSCCLCTDigi > clctV
unsigned int clct_trig_enable
const unsigned theEndcap
Definition: CSCBaseboard.h:33
unsigned int match_trig_window_size
std::unique_ptr< CSCUpgradeMotherboardLUTGenerator > generator_
bool isValid() const
check ALCT validity (1 - valid ALCT)
Definition: CSCALCTDigi.h:32
int getQuality() const
return the 4 bit Correlated LCT Quality
const unsigned theSector
Definition: CSCBaseboard.h:35
bool enableAlctSLHC_
Definition: CSCBaseboard.h:74
std::unique_ptr< CSCCathodeLCTProcessor > clctProc
static bool sortLCTsByQuality(const CSCCorrelatedLCTDigi &, const CSCCorrelatedLCTDigi &)
int pref[CSCConstants::MAX_LCT_TBINS]
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
CSCDetId cscId_
Definition: CSCBaseboard.h:46
bool gangedME1a_
Definition: CSCBaseboard.h:77
void sortLCTs(std::vector< CSCCorrelatedLCTDigi > &lcts, bool(*sorter)(const CSCCorrelatedLCTDigi &, const CSCCorrelatedLCTDigi &)) const
const unsigned theTrigChamber
Definition: CSCBaseboard.h:37
LCTContainer(unsigned int trig_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
Definition: Activities.doc:12
std::vector< CSCALCTDigi > alctV
static bool sortLCTsByGEMDphi(const CSCCorrelatedLCTDigi &, const CSCCorrelatedLCTDigi &)
bool isValid() const
check CLCT validity (1 - valid CLCT)
Definition: CSCCLCTDigi.h:35
unsigned int match_trig_enable
CSCCorrelatedLCTDigi constructLCTs(const CSCALCTDigi &aLCT, const CSCCLCTDigi &cLCT, int type, int trknmb) const
#define end
Definition: vmac.h:39
unsigned theChamber
Definition: CSCBaseboard.h:40
void getTimeMatched(const int bx, std::vector< CSCCorrelatedLCTDigi > &) const
#define LogTrace(id)
const CSCGeometry * cscGeometry_
Definition: CSCBaseboard.h:54
CSCCorrelatedLCTDigi & operator()(int bx, int match_bx, int lct)
edm::ParameterSet tmbParams_
Definition: CSCBaseboard.h:61
void correlateLCTs(const CSCALCTDigi &bestALCT, const CSCALCTDigi &secondALCT, const CSCCLCTDigi &bestCLCT, const CSCCLCTDigi &secondCLCT, CSCCorrelatedLCTDigi &lct1, CSCCorrelatedLCTDigi &lct2) const
void getMatched(std::vector< CSCCorrelatedLCTDigi > &) const
const unsigned theStation
Definition: CSCBaseboard.h:34
unsigned int alct_trig_enable
std::vector< CSCCorrelatedLCTDigi > readoutLCTs() const override
std::unique_ptr< CSCAnodeLCTProcessor > alctProc
#define begin
Definition: vmac.h:32
unsigned theRing
Definition: CSCBaseboard.h:39
void run(const CSCWireDigiCollection *wiredc, const CSCComparatorDigiCollection *compdc) override
unsigned int alctClctOffset_
Definition: CSCBaseboard.h:86
const unsigned theSubsector
Definition: CSCBaseboard.h:36
enum CSCPart getCSCPart(int keystrip) const