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