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