CMS 3D CMS Logo

DTTracoCard.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: DTTracoCard
4 //
5 // Description: Contains active DTTracoChips
6 //
7 //
8 // Author List:
9 // C. Grandi
10 // Modifications:
11 // X/03 Sara Vanini
12 // 22/VI/04 SV: last trigger code update
13 // 13/XII/04 SV: Zotto's traco acceptance routine implemented
14 // V/05 SV: NEWGEO
15 // 9/V/05 SV: mt ports ing K units, bug fixed
16 // 30/III/07 SV : config with DTConfigManager every single chip
17 // 2/XI/09 SV : bti acceptance windows included
18 //--------------------------------------------------
19 
20 //-----------------------
21 // This Class's Header --
22 //-----------------------
24 
25 //-------------------------------
26 // Collaborating Class Headers --
27 //-------------------------------
35 
36 //---------------
37 // C++ Headers --
38 //---------------
39 #include <cmath>
40 #include <iomanip>
41 #include <iostream>
42 #include <utility>
43 
44 //----------------
45 // Constructors --
46 //----------------
47 
49  DTTSTheta *tstheta)
50  : DTGeomSupplier(geo), _bticard(bticard), _tstheta(tstheta) {}
51 
52 //--------------
53 // Destructor --
54 //--------------
55 
57 
58 //--------------
59 // Operations --
60 //--------------
61 
63 
65  localClear();
66 }
67 
69  // get traco configuration map
70  DTChamberId sid = ChamberId();
72  _debug = conf->getDTTPGDebug();
73 
74  // get bti acceptance flag
75  _flag_acc = conf->useAcceptParam();
76 
77  // get lut computation flag
78  _lut_from_db = conf->lutFromDB();
79 
80  // get lut configuration for this chamber
81  // 100511 SV only if luts are read from OMDS
82  if (_lut_from_db)
83  _conf_luts = conf->getDTConfigLUTs(sid);
84 }
85 
87  // Clear the map
88  for (TRACO_iter p = _tracomap.begin(); p != _tracomap.end(); p++) {
89  delete (*p).second;
90  }
91  _tracomap.clear();
92 }
93 
95 
96  localClear();
97 
98  if (debug()) {
99  std::cout << "DTTracoCard::loadTRACO called for wheel=" << wheel();
100  std::cout << ", station=" << station();
101  std::cout << ", sector=" << sector() << std::endl;
102  }
103 
104  int maxtc = int(ceil(float(geom()->nCell(1)) / float(DTConfig::NBTITC)));
105 
106  // loop on all BTI triggers
107  std::vector<DTBtiTrigData>::const_iterator p;
108  std::vector<DTBtiTrigData>::const_iterator pend = _bticard->end();
109  for (p = _bticard->begin(); p != pend; p++) {
110  if (debug()) {
111  std::cout << "Found bti trigger: ";
112  (*p).print();
113  }
114 
115  // BTI data
116  int nbti = (*p).btiNumber();
117  int nsl = (*p).btiSL();
118  int step = (*p).step();
119  int K = (*p).K();
120  DTBtiId id_bti = (*p).parentId();
121 
122  DTConfigBti *conf_bti = _bticard->config_bti(id_bti);
123  int LL = conf_bti->LL();
124  int LH = conf_bti->LH();
125  int CL = conf_bti->CL();
126  int CH = conf_bti->CH();
127  int RL = conf_bti->RL();
128  int RH = conf_bti->RH();
129  /*
130  if(debug())
131  std::cout << "Bti trigger acceptances: \n"
132  << " LL " << LL << ", LH " << LH << "\n"
133  << " CL " << CL << ", CH " << CH << "\n"
134  << " RL " << RL << ", RH " << RH << std::endl;
135  */
136  // assign BTI to TRACO (central TRACO for sl=3); ntc=1,2...maxtc
137  int ntc = static_cast<int>((nbti - 1) / DTConfig::NBTITC) + 1;
138  if (ntc < 1 || ntc > maxtc)
139  continue;
140 
141  if (debug())
142  std::cout << "Bti trigger assigned to traco " << ntc << " (maxtc "
143  << maxtc << ")" << std::endl;
144 
145  // TRACO information
146  DTTracoId tracoid = DTTracoId(wheel(), station(), sector(), ntc);
147 
148  // position inside TRACO:
149  int pos = nbti - (ntc - 1) * DTConfig::NBTITC;
150 
151  // store trigger in TRACO. Create TRACO if it doesn't exist
152  // SV tb2003 : check if traco is connected!
153 
154  // SV 091103 : add bti trigger filtering in acceptance windows
155  // if flag is useAcceptParam() = true
156 
157  // Load master TRACO plane
158  if (nsl == 1) {
159  if (!_flag_acc || (K >= CL && K <= CH))
160  activeGetTRACO(ntc)->add_btiT(step, pos, &(*p));
161  else if (debug())
162  std::cout << "ATTENTION: in TRACO n. " << ntc << " bti pos " << pos
163  << " trigger K= " << K << " outside acceptance " << CL
164  << "<K<" << CH << std::endl;
165  }
166 
167  // Load slave TRACO plane
168  if (nsl == 3) {
169  // 3 TRACO's
170  // for(int tci=-1;tci<=1;tci++) {
171  // if( (ntc+tci)>0 && (ntc+tci)<=maxtc )
172  // activeGetTRACO(ntc+tci)->add_btiT( step, pos+8-4*tci, &(*p) );
173  // else{
174  // if(debug())
175  // std::cout << "ATTENTION: traco " << ntc+tci << " is disconnected!"
176  // << std::endl;
177  // }
178 
179  // Left Traco
180  if ((ntc - 1) > 0 && (ntc - 1) <= maxtc) {
181  if (!_flag_acc || (K >= LL && K <= LH)) {
182  activeGetTRACO(ntc - 1)->add_btiT(step, pos + 8 - 4 * (-1), &(*p));
183  } else {
184  if (debug()) {
185  std::cout << "ATTENTION: in TRACO n. " << ntc - 1 << " bti pos "
186  << pos + 8 - 4 * (-1) << " trigger K= " << K
187  << " outside acceptance " << LL << "<K<" << LH
188  << std::endl;
189  }
190  }
191  }
192 
193  // Central Traco
194  if ((ntc) > 0 && (ntc) <= maxtc) {
195  if (!_flag_acc || (K >= CL && K <= CH)) {
196  activeGetTRACO(ntc)->add_btiT(step, pos + 8 - 4 * (0), &(*p));
197  } else {
198  if (debug())
199  std::cout << "ATTENTION: in TRACO n. " << ntc << " bti pos "
200  << pos + 8 - 4 * (0) << " trigger K= " << K
201  << " outside acceptance " << CL << "<K<" << CH
202  << std::endl;
203  }
204  }
205 
206  // Right Traco
207  if ((ntc + 1) > 0 && (ntc + 1) <= maxtc) {
208  if (!_flag_acc || (K >= RL && K <= RH)) {
209  activeGetTRACO(ntc + 1)->add_btiT(step, pos + 8 - 4 * (+1), &(*p));
210  } else {
211  if (debug())
212  std::cout << "ATTENTION: in TRACO n. " << ntc + 1 << " bti pos "
213  << pos + 8 - 4 * (+1) << " trigger K= " << K
214  << " outside acceptance " << RL << "<K<" << RH
215  << std::endl;
216  }
217  }
218  }
219 
220  // Filter Theta BTIs -> this is done in DTBtiChip
221 
222  } // end loop on bti trigs
223 }
224 
226 
227  if (debug()) {
228  std::cout << "DTTracoCard:runTRACO called for wheel=" << wheel();
229  std::cout << ", station=" << station();
230  std::cout << ", sector=" << sector();
231  std::cout << ", " << _tracomap.size() << " TRACOs with signal" << std::endl;
232  }
233 
234  // run TRACO algorithm on all non-empty TRACO
235  if (!_tracomap.empty()) {
236 
237  if (debug()) {
238  std::cout << "===================================================="
239  << std::endl;
240  std::cout << " TRACO triggers "
241  << std::endl;
242  }
243 
244  TRACO_iter ptraco;
245  for (ptraco = _tracomap.begin(); ptraco != _tracomap.end(); ptraco++) {
246  DTTracoChip *traco = (*ptraco).second;
247  traco->run();
248  for (int step = DTConfig::NSTEPF; step <= DTConfig::NSTEPL; step++) {
249  if (traco->nTrig(step) > 0) {
250  _cache.push_back(traco->triggerData(step, 1));
251  /*
252  std::cout<<"first bti sl3:
253  "<<geom()->localPosition(DTBtiId(wheel(),station(),sector(),3,1))<<std::endl;
254  std::cout<<"traco pos: " <<
255  geom()->localPosition((traco->triggerData(step,1).parentId()))<<std::endl;
256  traco->triggerData(step,1).print();
257  std::cout<<"pos: " << localPosition(&(traco->triggerData(step,1))) <<
258  std::endl; std::cout<<"dir: " <<
259  localDirection(&(traco->triggerData(step,1))) << std::endl; std::cout
260  << std::endl;
261  */
262  }
263  // Store second track only if no first track at previous BX
264  if (traco->nTrig(step) > 1 && traco->useSecondTrack(step)) {
265  _cache.push_back(traco->triggerData(step, 2));
266  /*
267  std::cout<<"first bti sl3:
268  "<<geom()->localPosition(DTBtiId(wheel(),station(),sector(),3,1))<<std::endl;
269  std::cout<<"traco pos: " <<
270  geom()->localPosition((traco->triggerData(step,2).parentId()))<<std::endl;
271  traco->triggerData(step,2).print();
272  std::cout<<"pos: " << localPosition(&(traco->triggerData(step,2))) <<
273  std::endl; std::cout<<"dir: " <<
274  localDirection(&(traco->triggerData(step,2))) << std::endl; std::cout
275  << std::endl;
276  */
277  }
278  }
279  }
280  if (debug())
281  std::cout << "===================================================="
282  << std::endl;
283  }
284 }
285 
287 
288  // the traco identifier
289  DTChamberId sid = geom()->statId();
290  DTTracoId _id = DTTracoId(sid, n);
291 
292  DTTracoChip *traco = nullptr;
293  TRACO_iter ptraco = _tracomap.find(n);
294  if (ptraco != _tracomap.end()) {
295  traco = (*ptraco).second;
296  } else {
297  traco = new DTTracoChip(this, n, config_traco(_id));
298  _tracomap[n] = traco;
299  }
300  return traco;
301 }
302 
304  TRACO_const_iter ptraco = _tracomap.find(n);
305  if (ptraco == _tracomap.end())
306  return nullptr;
307  return (*ptraco).second;
308 }
309 
310 std::vector<DTTracoChip *> DTTracoCard::tracoList() {
311 
312  std::vector<DTTracoChip *> blist;
313 
314  if (size() < 1)
315  return blist;
316 
317  for (TRACO_const_iter p = _tracomap.begin(); p != _tracomap.end(); p++) {
318  blist.push_back((*p).second);
319  }
320  return blist;
321 }
322 
324  DTTracoId tracoid = td.parentId();
325  if (!(tracoid.wheel() == wheel() && tracoid.sector() == sector() &&
326  tracoid.station() == station()))
327  return nullptr;
328  std::cout << "DTTracoChip::trigger: trigger not belonging to this card! ";
329  std::cout << "card=(" << wheel() << "," << station() << "," << sector()
330  << ") ";
331  std::cout << "trig=(" << tracoid.wheel() << "," << tracoid.station() << ","
332  << tracoid.sector() << ")";
333  // get the appropriate Traco
334  DTTracoChip *traco = activeGetTRACO(tracoid.traco());
335  // create a new trigger in the Traco
336  DTTracoTrig *trig = new DTTracoTrig(traco, td);
337  // add the trigger to the Traco
338  traco->addTrig(td.step(), trig);
339  // return the trigger
340  return trig;
341 }
342 
343 /*
344 LocalPoint
345 DTTracoCard::localPosition(const DTTrigData* tr) const {
346 std::cout<<"oldgeo";
347 
348  //@@ patch for Sun 4.2 compiler
349  DTTracoTrigData* trig =
350 dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
351  // const DTTracoTrigData* trig = dynamic_cast<const DTTracoTrigData*>(tr);
352  if(!trig) {
353  std::cout << "DTTracoCard::localPosition called with wrong argument!" <<
354 std::endl; return LocalPoint(0,0,0);
355  }
356  float x = geom()->localPosition(trig->parentId()).x();
357  float y = geom()->localPosition(trig->parentId()).y();
358  float z = geom()->localPosition(trig->parentId()).z();
359 
360  x += geom()->cellPitch() * ( (float)trig->X() / (float)(config()->BTIC())
361  - 1.5 * (float)(DTConfig::NBTITC) );
362  // If not correlated get the position of the SL instead of the chamber center
363  if (trig->posIn()==0 ) {
364  z -= 0.5 * geom()->distSL(); // no inner ==> only outer
365  } else if(trig->posOut()==0) {
366  z += 0.5 * geom()->distSL(); // no outer ==> only inner
367  }
368  return LocalPoint(x,y,z);
369 }
370 */
371 
373  // NEWGEO
374  DTTracoTrigData *trig =
375  dynamic_cast<DTTracoTrigData *>(const_cast<DTTrigData *>(tr));
376  if (!trig) {
377  std::cout << "DTTracoCard::localPosition called with wrong argument!"
378  << std::endl;
379  return LocalPoint(0, 0, 0);
380  }
381  float x = geom()->localPosition(trig->parentId()).x();
382  float y = geom()->localPosition(trig->parentId()).y();
383  float z = geom()->localPosition(trig->parentId()).z();
384 
385  float trig_pos =
386  geom()->cellPitch() *
387  ((float)trig->X() / (float)(config_traco(trig->parentId())->BTIC()));
388 
389  // 10/7/06 May be not needed anymore in new geometry
390  // if(geom()->posFE(1)==1)
391  // trig_pos = -trig_pos;
392 
393  x += trig_pos;
394 
395  // If not correlated get the position of the SL instead of the chamber center
396  // z axis toward vertex
397  if (trig->posIn() == 0) {
398  z -= 0.5 * geom()->distSL(); // no inner ==> only outer
399  } else if (trig->posOut() == 0) {
400  z += 0.5 * geom()->distSL(); // no outer ==> only inner
401  }
402  return LocalPoint(x, y, z);
403 }
404 
405 /* OLDGEO
406 LocalVector
407 DTTracoCard::localDirection(const DTTrigData* tr) const {
408  //@@ patch for Sun 4.2 compiler
409  DTTracoTrigData* trig =
410 dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
411  // const DTTracoTrigData* trig = dynamic_cast<const DTTracoTrigData*>(tr);
412  if(!trig) {
413  std::cout << "DTtracoCard::localDirection called with wrong argument!" <<
414 std::endl; return LocalVector(0,0,0);
415  }
416  float r,x,y,z;
417  x = -(float)trig->K() * geom()->cellPitch() /
418  (float)(config_traco(trig->parentId())->BTIC());
419  y = 0;
420  z = -geom()->distSL();
421  r = sqrt(x*x+z*z);
422  x /= r;
423  z /= r;
424  return LocalVector(x,y,z);
425 }
426 */
427 
429  // NEWGEO
430  DTTracoTrigData *trig =
431  dynamic_cast<DTTracoTrigData *>(const_cast<DTTrigData *>(tr));
432  if (!trig) {
433  std::cout << "DTtracoCard::localDirection called with wrong argument!"
434  << std::endl;
435  return LocalVector(0, 0, 0);
436  }
437 
438  // FE position
439  // int FE = geom()->posFE(3);
440 
441  float psi = atan((float)(trig->K()) * geom()->cellPitch() /
442  (geom()->distSL() * config_traco(trig->parentId())->BTIC()));
443 
444  if (config_traco(trig->parentId())->debug() == 4)
445  std::cout << "K " << trig->K() << " == psi " << psi << " in FE frame "
446  << std::endl;
447 
448  // (xd,yd,zd) in chamber frame
449  float xd = -sin(psi);
450  float yd = 0;
451  float zd = -cos(psi);
452 
453  // 10/07/06 Not needed anymore (chages in geometry)
454  // if(FE==1){//FE in negative y
455  // xd = - xd;
456  //}
457 
458  if (config_traco(trig->parentId())->debug() == 4)
459  std::cout << "Direction in chamber frame is (" << xd << "," << yd << ","
460  << zd << ")" << std::endl;
461 
462  return LocalVector(xd, yd, zd);
463 }
464 
466  // loop on map to find traco
467  ConfTracoMap::const_iterator titer = _conf_traco_map.find(tracoid);
468  if (titer == _conf_traco_map.end()) {
469  std::cout << "DTTracoCard::config_traco : TRACO (" << tracoid.wheel() << ","
470  << tracoid.sector() << "," << tracoid.station() << ","
471  << tracoid.traco() << ") not found, return 0" << std::endl;
472  return nullptr;
473  }
474 
475  return const_cast<DTConfigTraco *>(&(*titer).second);
476 }
const DTConfigLUTs * getDTConfigLUTs(DTChamberId) const
Get desired LUT configuration.
void clearCache()
Clear all traco stuff (cache & map)
Definition: DTTracoCard.cc:62
DTConfigBti * config_bti(DTBtiId &btiid) const
Return bti chip configuration.
Definition: DTBtiCard.cc:677
int RL() const
K left limit for right traco.
Definition: DTConfigBti.h:117
DTTrigGeom * geom() const
Associated geometry.
my_collection _cache
Definition: DTCache.h:53
Local3DVector LocalVector
Definition: LocalVector.h:12
void run()
Run TRACO algorithm.
Definition: DTTracoChip.cc:261
TRACOContainer _tracomap
Definition: DTTracoCard.h:144
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:32
int sector() const
Return sector number.
float cellPitch() const
Width of a cell (cm) i.e. distance between ywo wires.
Definition: DTTrigGeom.h:77
void runTRACO()
run TRACO algorithm
Definition: DTTracoCard.cc:225
int posIn() const
Return the position of inner segment.
int posOut() const
Return the position of outer segment.
DTTracoCard(DTTrigGeom *, DTBtiCard *, DTTSTheta *)
Constructor.
Definition: DTTracoCard.cc:48
void addTrig(int step, DTTracoTrig *)
Add a TRACO trigger.
DTTracoChip * activeGetTRACO(int)
Returns the required DTTracoChip. Create it if it doesn&#39;t exist.
Definition: DTTracoCard.cc:286
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
int CH() const
K right limit for center traco.
Definition: DTConfigBti.h:114
int step() const
Return step.
static const int NSTEPF
Definition: DTConfig.h:36
TRACOContainer::iterator TRACO_iter
Definition: DTTracoCard.h:52
void setConfig(const DTConfigManager *conf)
Set configuration.
Definition: DTTracoCard.cc:68
int X() const
Return trigger X parameter.
void add_btiT(int step, int pos, const DTBtiTrigData *btitrig)
Add a BTI trigger to the TRACO.
DTTracoChip * getTRACO(int n) const
Returns the required DTTracoChip. Return 0 if it doesn&#39;t exist.
Definition: DTTracoCard.cc:303
std::map< std::string, int, std::less< std::string > > psi
int sector() const
Returns sector number.
Definition: DTTracoId.h:68
int station() const
Return station number.
bool _flag_acc
Definition: DTTracoCard.h:151
~DTTracoCard() override
Destructor.
Definition: DTTracoCard.cc:56
int traco() const
Returns the traco.
Definition: DTTracoId.h:70
void localClear()
clear the TRACO map
Definition: DTTracoCard.cc:86
int LL() const
K left limit for left traco.
Definition: DTConfigBti.h:105
ConfTracoMap _conf_traco_map
Definition: DTTracoCard.h:145
int station() const
Returns station number.
Definition: DTTracoId.h:66
float distSL() const
Distance between the phi view superlayers (cms)
Definition: DTTrigGeom.h:80
int wheel() const
Return wheel number.
DTBtiCard * _bticard
Definition: DTTracoCard.h:141
DTTracoId parentId() const
Return parent TRACO identifier.
TRACOContainer::const_iterator TRACO_const_iter
Definition: DTTracoCard.h:51
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DTTracoTrig * storeTrigger(DTTracoTrigData)
Definition: DTTracoCard.cc:323
bool debug()
Return TU debug flag.
Definition: DTTracoCard.h:75
DTChamberId ChamberId() const
Identifier of the associated chamber.
DTConfigTraco * config_traco(const DTTracoId &tracoid) const
Return single TRACO config.
Definition: DTTracoCard.cc:465
bool _lut_from_db
Definition: DTTracoCard.h:152
static const int NSTEPL
Constants: first and last step to start trigger finding.
Definition: DTConfig.h:36
int wheel() const
Returns wheel number.
Definition: DTTracoId.h:64
bool getDTTPGDebug() const
Get global debug flag.
const std::map< DTTracoId, DTConfigTraco > & getDTConfigTracoMap(DTChamberId) const
Get desired TRACO configuration map for a given DTChamber.
DTChamberId statId() const
Identifier of the associated chamber.
Definition: DTTrigGeom.h:54
bool lutFromDB() const
Lut from DB flag.
std::vector< DTTracoChip * > tracoList()
Returns the active TRACO list.
Definition: DTTracoCard.cc:310
const_iterator begin() const
Get first cache element.
Definition: DTCache.h:38
DTTracoTrigData triggerData(int step, unsigned n) const
Return the data part of the requested trigger.
LocalPoint localPosition(const DTBtiId) const
Local position in chamber of a BTI.
Definition: DTTrigGeom.cc:541
int LH() const
K right limit for left traco.
Definition: DTConfigBti.h:108
int RH() const
K right limit for right traco.
Definition: DTConfigBti.h:120
void loadTRACO()
store BTI triggers in TRACO&#39;s
Definition: DTTracoCard.cc:94
int K() const
Return trigger K parameter.
int useSecondTrack(int step) const
a flag for a usable second track
step
Definition: StallMonitor.cc:94
int CL() const
K left limit for center traco.
Definition: DTConfigBti.h:111
static const int NBTITC
Definition: DTConfig.h:38
const DTConfigLUTs * _conf_luts
Definition: DTTracoCard.h:147
bool useAcceptParam() const
Use Bti acceptance parameters (LL,LH,CL,CH,RL,RH)
const_iterator end() const
Get last cache element.
Definition: DTCache.h:41
void clearCache()
Clear cache vector.
Definition: DTCache.h:47
LocalPoint localPosition(const DTTrigData *) const override
NEWGEO Local position in chamber of a trigger-data object.
Definition: DTTracoCard.cc:372
int size() const
Get cache vector&#39;s size.
Definition: DTCache.h:44
int nTrig(int step) const
Return the number of trigger candidates.
LocalVector localDirection(const DTTrigData *) const override
NEWGEO Local direction in chamber of a trigger-data object.
Definition: DTTracoCard.cc:428