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