CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCTriggerPrimitivesBuilder.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // Class: CSCTriggerPrimitivesBuilder
4 //
5 // Description: Algorithm to build anode, cathode, and correlated LCTs
6 // in each endcap muon CSC chamber from wire and comparator
7 // digis.
8 //
9 // Author List: S. Valuev, UCLA.
10 //
11 //
12 // Modifications:
13 //
14 //-----------------------------------------------------------------------------
15 
20 
22 
26 
27 //------------------
28 // Static variables
29 //------------------
40 
41 //-------------
42 // Constructor
43 //-------------
45 {
46  // Receives ParameterSet percolated down from EDProducer.
47 
48  // special configuration parameters for ME11 treatment
49  edm::ParameterSet commonParams = conf.getParameter<edm::ParameterSet>("commonParam");
50  smartME1aME1b = commonParams.getUntrackedParameter<bool>("smartME1aME1b", false);
51  disableME1a = commonParams.getUntrackedParameter<bool>("disableME1a", false);
52  disableME42 = commonParams.getUntrackedParameter<bool>("disableME42", false);
53 
54  checkBadChambers_ = conf.getUntrackedParameter<bool>("checkBadChambers", true);
55 
56  // ORCA way of initializing boards.
57  for (int endc = min_endcap; endc <= max_endcap; endc++)
58  {
59  for (int stat = min_station; stat <= max_station; stat++)
60  {
61  int numsubs = ((stat == 1) ? max_subsector : 1);
62  for (int sect = min_sector; sect <= max_sector; sect++)
63  {
64  for (int subs = min_subsector; subs <= numsubs; subs++)
65  {
66  for (int cham = min_chamber; cham <= max_chamber; cham++)
67  {
68  if ((endc <= 0 || endc > MAX_ENDCAPS) ||
69  (stat <= 0 || stat > MAX_STATIONS) ||
70  (sect <= 0 || sect > MAX_SECTORS) ||
71  (subs <= 0 || subs > MAX_SUBSECTORS) ||
72  (cham <= 0 || stat > MAX_CHAMBERS))
73  {
74  edm::LogError("L1CSCTPEmulatorSetupError")
75  << "+++ trying to instantiate TMB of illegal CSC id ["
76  << " endcap = " << endc << " station = " << stat
77  << " sector = " << sect << " subsector = " << subs
78  << " chamber = " << cham << "]; skipping it... +++\n";
79  continue;
80  }
82  // When the motherboard is instantiated, it instantiates ALCT
83  // and CLCT processors.
84  if (stat==1 && ring==1 && smartME1aME1b)
85  tmb_[endc-1][stat-1][sect-1][subs-1][cham-1] = new CSCMotherboardME11(endc, stat, sect, subs, cham, conf);
86  else
87  tmb_[endc-1][stat-1][sect-1][subs-1][cham-1] = new CSCMotherboard(endc, stat, sect, subs, cham, conf);
88  }
89  }
90  }
91  }
92  }
93 
94  // Get min and max BX to sort LCTs in MPC.
95  m_minBX = conf.getParameter<int>("MinBX");
96  m_maxBX = conf.getParameter<int>("MaxBX");
97 
98  // Init MPC
99  m_muonportcard = new CSCMuonPortCard(conf);
100 }
101 
102 //------------
103 // Destructor
104 //------------
106 {
107  for (int endc = min_endcap; endc <= max_endcap; endc++)
108  {
109  for (int stat = min_station; stat <= max_station; stat++)
110  {
111  int numsubs = ((stat == 1) ? max_subsector : 1);
112  for (int sect = min_sector; sect <= max_sector; sect++)
113  {
114  for (int subs = min_subsector; subs <= numsubs; subs++)
115  {
116  for (int cham = min_chamber; cham <= max_chamber; cham++)
117  {
118  delete tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
119  }
120  }
121  }
122  }
123  }
124  delete m_muonportcard;
125 }
126 
127 //------------
128 // Operations
129 //------------
130 // Set configuration parameters obtained via EventSetup mechanism.
132 {
133  // Receives CSCDBL1TPParameters percolated down from ESProducer.
134 
135  for (int endc = min_endcap; endc <= max_endcap; endc++)
136  {
137  for (int stat = min_station; stat <= max_station; stat++)
138  {
139  int numsubs = ((stat == 1) ? max_subsector : 1);
140  for (int sect = min_sector; sect <= max_sector; sect++)
141  {
142  for (int subs = min_subsector; subs <= numsubs; subs++)
143  {
144  for (int cham = min_chamber; cham <= max_chamber; cham++)
145  {
146  CSCMotherboard* tmb = tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
147  tmb->setConfigParameters(conf);
148  }
149  }
150  }
151  }
152  }
153 }
154 
155 // Build anode, cathode, and correlated LCTs in each chamber and fill them
156 // into output collections. Pass collections of wire and comparator digis
157 // to Trigger MotherBoard (TMB) processors, which, in turn, pass them to
158 // ALCT and CLCT processors. Up to 2 anode and 2 cathode LCTs can be found
159 // in each chamber during any bunch crossing. The 2 projections are then
160 // combined into three-dimensional "correlated" LCTs in the TMB. Finally,
161 // MPC processor sorts up to 18 LCTs from 9 TMBs and writes collections of
162 // up to 3 best LCTs per (sub)sector into Event (to be used by the Sector
163 // Receiver).
165  const CSCWireDigiCollection* wiredc,
166  const CSCComparatorDigiCollection* compdc,
167  CSCALCTDigiCollection& oc_alct,
168  CSCCLCTDigiCollection& oc_clct,
169  CSCCLCTPreTriggerCollection & oc_pretrig,
171  CSCCorrelatedLCTDigiCollection& oc_sorted_lct)
172 {
173  // CSC geometry.
175 
176  for (int endc = min_endcap; endc <= max_endcap; endc++)
177  {
178  for (int stat = min_station; stat <= max_station; stat++)
179  {
180  int numsubs = ((stat == 1) ? max_subsector : 1);
181  for (int sect = min_sector; sect <= max_sector; sect++)
182  {
183  for (int subs = min_subsector; subs <= numsubs; subs++)
184  {
185  for (int cham = min_chamber; cham <= max_chamber; cham++)
186  {
187 
189 
190  if (disableME42 && stat==4 && ring==2) continue;
191 
192  CSCMotherboard* tmb = tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
193 
194  // Run processors only if chamber exists in geometry.
195  if (tmb == 0 || theGeom->chamber(endc, stat, sect, subs, cham) == 0) continue;
196 
197  int chid = CSCTriggerNumbering::chamberFromTriggerLabels(sect, subs, stat, cham);
198 
199  // 0th layer means whole chamber.
200  CSCDetId detid(endc, stat, ring, chid, 0);
201 
202  // Skip chambers marked as bad (usually includes most of ME4/2 chambers;
203  // also, there's no ME1/a-1/b separation, it's whole ME1/1)
204  if (checkBadChambers_ && badChambers->isInBadChamber(detid)) continue;
205 
206 
207  // running upgraded ME1/1 TMBs (non-upgraded)
208  if (stat==1 && ring==1 && smartME1aME1b)
209  {
210  CSCMotherboardME11* tmb11 = static_cast<CSCMotherboardME11*>(tmb);
211 
212  //LogTrace("CSCTriggerPrimitivesBuilder")<<"CSCTriggerPrimitivesBuilder::build in E:"<<endc<<" S:"<<stat<<" R:"<<ring;
213 
214  tmb11->run(wiredc,compdc);
215  std::vector<CSCCorrelatedLCTDigi> lctV = tmb11->readoutLCTs1b();
216  std::vector<CSCCorrelatedLCTDigi> lctV1a = tmb11->readoutLCTs1a();
217 
218  std::vector<CSCALCTDigi> alctV1a, alctV = tmb11->alct->readoutALCTs();
219 
220  std::vector<CSCCLCTDigi> clctV = tmb11->clct->readoutCLCTs();
221  std::vector<int> preTriggerBXs = tmb11->clct->preTriggerBXs();
222  std::vector<CSCCLCTDigi> clctV1a = tmb11->clct1a->readoutCLCTs();
223  std::vector<int> preTriggerBXs1a = tmb11->clct1a->preTriggerBXs();
224 
225  // perform simple separation of ALCTs into 1/a and 1/b
226  // for 'smart' case. Some duplication occurs for WG [10,15]
227  std::vector<CSCALCTDigi> tmpV(alctV);
228  alctV.clear();
229  for (unsigned int al=0; al < tmpV.size(); al++)
230  {
231  if (tmpV[al].getKeyWG()<=15) alctV1a.push_back(tmpV[al]);
232  if (tmpV[al].getKeyWG()>=10) alctV.push_back(tmpV[al]);
233  }
234  //LogTrace("CSCTriggerPrimitivesBuilder")<<"CSCTriggerPrimitivesBuilder:: a="<<alctV.size()<<" c="<<clctV.size()<<" l="<<lctV.size()
235  // <<" 1a: a="<<alctV1a.size()<<" c="<<clctV1a.size()<<" l="<<lctV1a.size();
236 
237  // ME1/b
238 
239  if (!(lctV.empty()&&alctV.empty()&&clctV.empty())) {
240  LogTrace("L1CSCTrigger")
241  << "CSCTriggerPrimitivesBuilder results in " <<detid;
242  }
243 
244  // Correlated LCTs.
245  if (!lctV.empty()) {
246  LogTrace("L1CSCTrigger")
247  << "Put " << lctV.size() << " ME1b LCT digi"
248  << ((lctV.size() > 1) ? "s " : " ") << "in collection\n";
249  oc_lct.put(std::make_pair(lctV.begin(),lctV.end()), detid);
250  }
251 
252  // Anode LCTs.
253  if (!alctV.empty()) {
254  LogTrace("L1CSCTrigger")
255  << "Put " << alctV.size() << " ME1b ALCT digi"
256  << ((alctV.size() > 1) ? "s " : " ") << "in collection\n";
257  oc_alct.put(std::make_pair(alctV.begin(),alctV.end()), detid);
258  }
259 
260  // Cathode LCTs.
261  if (!clctV.empty()) {
262  LogTrace("L1CSCTrigger")
263  << "Put " << clctV.size() << " ME1b CLCT digi"
264  << ((clctV.size() > 1) ? "s " : " ") << "in collection\n";
265  oc_clct.put(std::make_pair(clctV.begin(),clctV.end()), detid);
266  }
267 
268  // Cathode LCTs pretriggers
269  if (!preTriggerBXs.empty()) {
270  LogTrace("L1CSCTrigger")
271  << "Put " << preTriggerBXs.size() << " CLCT pretrigger"
272  << ((preTriggerBXs.size() > 1) ? "s " : " ") << "in collection\n";
273  oc_pretrig.put(std::make_pair(preTriggerBXs.begin(),preTriggerBXs.end()), detid);
274  }
275 
276  // ME1/a
277 
278  if (disableME1a) continue;
279 
280  CSCDetId detid1a(endc, stat, 4, chid, 0);
281 
282  if (!(lctV1a.empty()&&alctV1a.empty()&&clctV1a.empty())){
283  LogTrace("L1CSCTrigger") << "CSCTriggerPrimitivesBuilder results in " <<detid1a;
284  }
285 
286  // Correlated LCTs.
287  if (!lctV1a.empty()) {
288  LogTrace("L1CSCTrigger")
289  << "Put " << lctV1a.size() << " ME1a LCT digi"
290  << ((lctV1a.size() > 1) ? "s " : " ") << "in collection\n";
291  oc_lct.put(std::make_pair(lctV1a.begin(),lctV1a.end()), detid1a);
292  }
293 
294  // Anode LCTs.
295  if (!alctV1a.empty()) {
296  LogTrace("L1CSCTrigger")
297  << "Put " << alctV1a.size() << " ME1a ALCT digi"
298  << ((alctV1a.size() > 1) ? "s " : " ") << "in collection\n";
299  oc_alct.put(std::make_pair(alctV1a.begin(),alctV1a.end()), detid1a);
300  }
301 
302  // Cathode LCTs.
303  if (!clctV1a.empty()) {
304  LogTrace("L1CSCTrigger")
305  << "Put " << clctV1a.size() << " ME1a CLCT digi"
306  << ((clctV1a.size() > 1) ? "s " : " ") << "in collection\n";
307  oc_clct.put(std::make_pair(clctV1a.begin(),clctV1a.end()), detid1a);
308  }
309 
310  // Cathode LCTs pretriggers
311  if (!preTriggerBXs1a.empty()) {
312  LogTrace("L1CSCTrigger")
313  << "Put " << preTriggerBXs1a.size() << " CLCT pretrigger"
314  << ((preTriggerBXs1a.size() > 1) ? "s " : " ") << "in collection\n";
315  oc_pretrig.put(std::make_pair(preTriggerBXs1a.begin(),preTriggerBXs1a.end()), detid1a);
316  }
317  } // upgraded TMB
318 
319  // running non-upgraded TMB
320  else
321  {
322  tmb->run(wiredc,compdc);
323 
324  std::vector<CSCCorrelatedLCTDigi> lctV = tmb->readoutLCTs();
325  std::vector<CSCALCTDigi> alctV = tmb->alct->readoutALCTs();
326  std::vector<CSCCLCTDigi> clctV = tmb->clct->readoutCLCTs();
327  std::vector<int> preTriggerBXs = tmb->clct->preTriggerBXs();
328 
329  if (!(alctV.empty() && clctV.empty() && lctV.empty())) {
330  LogTrace("L1CSCTrigger")
331  << "CSCTriggerPrimitivesBuilder got results in " <<detid;
332  }
333 
334  /*
335  // tmp kludge: tightening of ME1a LCTs
336  if (stat==1 && ring==1) {
337  std::vector<CSCCorrelatedLCTDigi> lctV11;
338  for (unsigned t=0;t<lctV.size();t++){
339  if (lctV[t].getStrip() < 127) lctV11.push_back(lctV[t]);
340  else if (lctV[t].getQuality() >= 14) lctV11.push_back(lctV[t]);
341  }
342  lctV = lctV11;
343  }
344  */
345 
346  // Correlated LCTs.
347  if (!lctV.empty()) {
348  LogTrace("L1CSCTrigger")
349  << "Put " << lctV.size() << " LCT digi"
350  << ((lctV.size() > 1) ? "s " : " ") << "in collection\n";
351  oc_lct.put(std::make_pair(lctV.begin(),lctV.end()), detid);
352  }
353 
354  // Anode LCTs.
355  if (!alctV.empty()) {
356  LogTrace("L1CSCTrigger")
357  << "Put " << alctV.size() << " ALCT digi"
358  << ((alctV.size() > 1) ? "s " : " ") << "in collection\n";
359  oc_alct.put(std::make_pair(alctV.begin(),alctV.end()), detid);
360  }
361 
362  // Cathode LCTs.
363  if (!clctV.empty()) {
364  LogTrace("L1CSCTrigger")
365  << "Put " << clctV.size() << " CLCT digi"
366  << ((clctV.size() > 1) ? "s " : " ") << "in collection\n";
367  oc_clct.put(std::make_pair(clctV.begin(),clctV.end()), detid);
368  }
369 
370  // Cathode LCTs pretriggers
371  if (!preTriggerBXs.empty()) {
372  LogTrace("L1CSCTrigger")
373  << "Put " << preTriggerBXs.size() << " CLCT pretrigger"
374  << ((preTriggerBXs.size() > 1) ? "s " : " ") << "in collection\n";
375  oc_pretrig.put(std::make_pair(preTriggerBXs.begin(),preTriggerBXs.end()), detid);
376  }
377  } // non-upgraded TMB
378  }
379  }
380  }
381  }
382  }
383 
384  // run MPC simulation
385  m_muonportcard->loadDigis(oc_lct);
386 
387  std::vector<csctf::TrackStub> result;
388  for(int bx = m_minBX; bx <= m_maxBX; ++bx)
389  for(int e = min_endcap; e <= max_endcap; ++e)
390  for(int st = min_station; st <= max_station; ++st)
391  for(int se = min_sector; se <= max_sector; ++se)
392  {
393  if(st == 1)
394  {
395  std::vector<csctf::TrackStub> subs1, subs2;
396  subs1 = m_muonportcard->sort(e, st, se, 1, bx);
397  subs2 = m_muonportcard->sort(e, st, se, 2, bx);
398  result.insert(result.end(), subs1.begin(), subs1.end());
399  result.insert(result.end(), subs2.begin(), subs2.end());
400  }
401  else
402  {
403  std::vector<csctf::TrackStub> sector;
404  sector = m_muonportcard->sort(e, st, se, 0, bx);
405  result.insert(result.end(), sector.begin(), sector.end());
406  }
407  }
408 
409  std::vector<csctf::TrackStub>::const_iterator itr = result.begin();
410  for (; itr != result.end(); itr++)
411  {
412  oc_sorted_lct.insertDigi(CSCDetId(itr->getDetId().rawId()), *(itr->getDigi()));
413  LogDebug("L1CSCTrigger")
414  << "MPC " << *(itr->getDigi()) << " found in ME"
415  << ((itr->endcap() == 1) ? "+" : "-") << itr->station() << "/"
416  << CSCDetId(itr->getDetId().rawId()).ring() << "/"
417  << CSCDetId(itr->getDetId().rawId()).chamber()
418  << " (sector " << itr->sector()
419  << " trig id. " << itr->cscid() << ")" << "\n";
420  }
421 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< CSCCLCTDigi > readoutCLCTs()
void run(const CSCWireDigiCollection *wiredc, const CSCComparatorDigiCollection *compdc)
CSCChamber * chamber(unsigned endcap, unsigned station, unsigned sector, unsigned subsector, unsigned tcscid) const
Return the CSCChamber for a corresponding endcap/station/sector/subsector/trigger cscid...
std::vector< CSCCorrelatedLCTDigi > readoutLCTs()
static int minEndcapId()
Definition: CSCDetId.h:249
static int maxTriggerSectorId()
void build(const CSCBadChambers *badChambers, const CSCWireDigiCollection *wiredc, const CSCComparatorDigiCollection *compdc, CSCALCTDigiCollection &oc_alct, CSCCLCTDigiCollection &oc_clct, CSCCLCTPreTriggerCollection &oc_pretrig, CSCCorrelatedLCTDigiCollection &oc_lct, CSCCorrelatedLCTDigiCollection &oc_sorted_lct)
static int maxStationId()
Definition: CSCDetId.h:252
static int minTriggerSectorId()
static int ringFromTriggerLabels(int station, int triggerCSCID)
void setConfigParameters(const CSCDBL1TPParameters *conf)
bool isInBadChamber(IndexType ichamber) const
Is the chamber with index &#39;ichamber&#39; flagged as bad?
void loadDigis(const CSCCorrelatedLCTDigiCollection &thedigis)
CSCTriggerPrimitivesBuilder(const edm::ParameterSet &)
static CSCTriggerGeomManager * get()
static int minStationId()
Definition: CSCDetId.h:251
tuple result
Definition: query.py:137
void run(const std::vector< int > w_time[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_WIRES], const std::vector< int > hs_times[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS], const std::vector< int > ds_times[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS])
static int maxEndcapId()
Definition: CSCDetId.h:250
CSCMotherboard * tmb_[MAX_ENDCAPS][MAX_STATIONS][MAX_SECTORS][MAX_SUBSECTORS][MAX_CHAMBERS]
#define LogTrace(id)
CSCAnodeLCTProcessor * alct
tuple conf
Definition: dbtoconf.py:185
std::vector< int > preTriggerBXs() const
std::vector< CSCALCTDigi > readoutALCTs()
static int minTriggerSubSectorId()
CSCCathodeLCTProcessor * clct
bool checkBadChambers_
a flag whether to skip chambers from the bad chambers map
std::vector< csctf::TrackStub > sort(const unsigned endcap, const unsigned station, const unsigned sector, const unsigned subsector, const int bx)
std::vector< CSCCorrelatedLCTDigi > readoutLCTs1b()
CSCCathodeLCTProcessor * clct1a
void setConfigParameters(const CSCDBL1TPParameters *conf)
static int chamberFromTriggerLabels(int TriggerSector, int TriggerSubSector, int station, int TriggerCSCID)
static int maxTriggerSubSectorId()
std::vector< CSCCorrelatedLCTDigi > readoutLCTs1a()