Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:43

0001 //-------------------------------------------------
0002 //
0003 //   Class: DTTracoCard
0004 //
0005 //   Description: Contains active DTTracoChips
0006 //
0007 //
0008 //   Author List:
0009 //   C. Grandi
0010 //   Modifications:
0011 //   X/03 Sara Vanini
0012 //   22/VI/04 SV: last trigger code update
0013 //   13/XII/04 SV: Zotto's traco acceptance routine implemented
0014 //   V/05 SV: NEWGEO
0015 //   9/V/05 SV: mt ports ing K units, bug fixed
0016 //   30/III/07 SV : config with DTConfigManager every single chip
0017 //   2/XI/09 SV : bti acceptance windows included
0018 //--------------------------------------------------
0019 
0020 //-----------------------
0021 // This Class's Header --
0022 //-----------------------
0023 #include "L1Trigger/DTTraco/interface/DTTracoCard.h"
0024 
0025 //-------------------------------
0026 // Collaborating Class Headers --
0027 //-------------------------------
0028 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0029 #include "DataFormats/GeometryVector/interface/LocalVector.h"
0030 #include "L1Trigger/DTBti/interface/DTBtiCard.h"
0031 #include "L1Trigger/DTBti/interface/DTBtiTrigData.h"
0032 #include "L1Trigger/DTTraco/interface/DTTracoChip.h"
0033 #include "L1Trigger/DTTraco/interface/DTTracoTrig.h"
0034 #include "L1Trigger/DTTriggerServerTheta/interface/DTTSTheta.h"
0035 
0036 //---------------
0037 // C++ Headers --
0038 //---------------
0039 #include <cmath>
0040 #include <iomanip>
0041 #include <iostream>
0042 #include <utility>
0043 
0044 //----------------
0045 // Constructors --
0046 //----------------
0047 
0048 DTTracoCard::DTTracoCard(DTTrigGeom *geo, DTBtiCard *bticard, DTTSTheta *tstheta)
0049     : DTGeomSupplier(geo), _bticard(bticard), _tstheta(tstheta) {}
0050 
0051 //--------------
0052 // Destructor --
0053 //--------------
0054 
0055 DTTracoCard::~DTTracoCard() { localClear(); }
0056 
0057 //--------------
0058 // Operations --
0059 //--------------
0060 
0061 void DTTracoCard::clearCache() {
0062   TRACOCache::clearCache();
0063   localClear();
0064 }
0065 
0066 void DTTracoCard::setConfig(const DTConfigManager *conf) {
0067   // get traco configuration map
0068   DTChamberId sid = ChamberId();
0069   _conf_traco_map = conf->getDTConfigTracoMap(sid);
0070   _debug = conf->getDTTPGDebug();
0071 
0072   // get bti acceptance flag
0073   _flag_acc = conf->useAcceptParam();
0074 
0075   // get lut computation flag
0076   _lut_from_db = conf->lutFromDB();
0077 
0078   // get lut configuration for this chamber
0079   // 100511 SV only if luts are read from OMDS
0080   if (_lut_from_db)
0081     _conf_luts = conf->getDTConfigLUTs(sid);
0082 }
0083 
0084 void DTTracoCard::localClear() {
0085   // Clear the map
0086   for (TRACO_iter p = _tracomap.begin(); p != _tracomap.end(); p++) {
0087     delete (*p).second;
0088   }
0089   _tracomap.clear();
0090 }
0091 
0092 void DTTracoCard::loadTRACO() {
0093   localClear();
0094 
0095   if (debug()) {
0096     std::cout << "DTTracoCard::loadTRACO called for wheel=" << wheel();
0097     std::cout << ", station=" << station();
0098     std::cout << ", sector=" << sector() << std::endl;
0099   }
0100 
0101   int maxtc = int(ceil(float(geom()->nCell(1)) / float(DTConfig::NBTITC)));
0102 
0103   // loop on all BTI triggers
0104   std::vector<DTBtiTrigData>::const_iterator p;
0105   std::vector<DTBtiTrigData>::const_iterator pend = _bticard->end();
0106   for (p = _bticard->begin(); p != pend; p++) {
0107     if (debug()) {
0108       std::cout << "Found bti trigger: ";
0109       (*p).print();
0110     }
0111 
0112     // BTI data
0113     int nbti = (*p).btiNumber();
0114     int nsl = (*p).btiSL();
0115     int step = (*p).step();
0116     int K = (*p).K();
0117     DTBtiId id_bti = (*p).parentId();
0118 
0119     DTConfigBti *conf_bti = _bticard->config_bti(id_bti);
0120     int LL = conf_bti->LL();
0121     int LH = conf_bti->LH();
0122     int CL = conf_bti->CL();
0123     int CH = conf_bti->CH();
0124     int RL = conf_bti->RL();
0125     int RH = conf_bti->RH();
0126     /*
0127         if(debug())
0128           std::cout << "Bti trigger acceptances: \n"
0129                     << " LL " << LL << ", LH " << LH << "\n"
0130                     << " CL " << CL << ", CH " << CH << "\n"
0131                     << " RL " << RL << ", RH " << RH << std::endl;
0132     */
0133     // assign BTI to TRACO (central TRACO for sl=3); ntc=1,2...maxtc
0134     int ntc = static_cast<int>((nbti - 1) / DTConfig::NBTITC) + 1;
0135     if (ntc < 1 || ntc > maxtc)
0136       continue;
0137 
0138     if (debug())
0139       std::cout << "Bti trigger assigned to traco " << ntc << " (maxtc " << maxtc << ")" << std::endl;
0140 
0141     // TRACO information
0142     DTTracoId tracoid = DTTracoId(wheel(), station(), sector(), ntc);
0143 
0144     // position inside TRACO:
0145     int pos = nbti - (ntc - 1) * DTConfig::NBTITC;
0146 
0147     // store trigger in TRACO. Create TRACO if it doesn't exist
0148     // SV tb2003 : check if traco is connected!
0149 
0150     // SV 091103 : add bti trigger filtering in acceptance windows
0151     // if flag is useAcceptParam() = true
0152 
0153     // Load master TRACO plane
0154     if (nsl == 1) {
0155       if (!_flag_acc || (K >= CL && K <= CH))
0156         activeGetTRACO(ntc)->add_btiT(step, pos, &(*p));
0157       else if (debug())
0158         std::cout << "ATTENTION: in TRACO n. " << ntc << " bti pos " << pos << " trigger K= " << K
0159                   << " outside acceptance " << CL << "<K<" << CH << std::endl;
0160     }
0161 
0162     // Load slave TRACO plane
0163     if (nsl == 3) {
0164       // 3 TRACO's
0165       // for(int tci=-1;tci<=1;tci++) {
0166       //  if( (ntc+tci)>0 && (ntc+tci)<=maxtc )
0167       //    activeGetTRACO(ntc+tci)->add_btiT( step, pos+8-4*tci, &(*p) );
0168       //  else{
0169       //    if(debug())
0170       //      std::cout << "ATTENTION: traco " << ntc+tci << " is disconnected!"
0171       //      << std::endl;
0172       //  }
0173 
0174       // Left Traco
0175       if ((ntc - 1) > 0 && (ntc - 1) <= maxtc) {
0176         if (!_flag_acc || (K >= LL && K <= LH)) {
0177           activeGetTRACO(ntc - 1)->add_btiT(step, pos + 8 - 4 * (-1), &(*p));
0178         } else {
0179           if (debug()) {
0180             std::cout << "ATTENTION: in TRACO n. " << ntc - 1 << " bti pos " << pos + 8 - 4 * (-1)
0181                       << " trigger K= " << K << " outside acceptance " << LL << "<K<" << LH << std::endl;
0182           }
0183         }
0184       }
0185 
0186       // Central Traco
0187       if ((ntc) > 0 && (ntc) <= maxtc) {
0188         if (!_flag_acc || (K >= CL && K <= CH)) {
0189           activeGetTRACO(ntc)->add_btiT(step, pos + 8 - 4 * (0), &(*p));
0190         } else {
0191           if (debug())
0192             std::cout << "ATTENTION: in TRACO n. " << ntc << " bti pos " << pos + 8 - 4 * (0) << " trigger K= " << K
0193                       << " outside acceptance " << CL << "<K<" << CH << std::endl;
0194         }
0195       }
0196 
0197       // Right Traco
0198       if ((ntc + 1) > 0 && (ntc + 1) <= maxtc) {
0199         if (!_flag_acc || (K >= RL && K <= RH)) {
0200           activeGetTRACO(ntc + 1)->add_btiT(step, pos + 8 - 4 * (+1), &(*p));
0201         } else {
0202           if (debug())
0203             std::cout << "ATTENTION: in TRACO n. " << ntc + 1 << " bti pos " << pos + 8 - 4 * (+1)
0204                       << " trigger K= " << K << " outside acceptance " << RL << "<K<" << RH << std::endl;
0205         }
0206       }
0207     }
0208 
0209     // Filter Theta BTIs -> this is done in DTBtiChip
0210 
0211   }  // end loop on bti trigs
0212 }
0213 
0214 void DTTracoCard::runTRACO() {
0215   if (debug()) {
0216     std::cout << "DTTracoCard:runTRACO called for wheel=" << wheel();
0217     std::cout << ", station=" << station();
0218     std::cout << ", sector=" << sector();
0219     std::cout << ", " << _tracomap.size() << " TRACOs with signal" << std::endl;
0220   }
0221 
0222   // run TRACO algorithm on all non-empty TRACO
0223   if (!_tracomap.empty()) {
0224     if (debug()) {
0225       std::cout << "====================================================" << std::endl;
0226       std::cout << "              TRACO triggers                        " << std::endl;
0227     }
0228 
0229     TRACO_iter ptraco;
0230     for (ptraco = _tracomap.begin(); ptraco != _tracomap.end(); ptraco++) {
0231       DTTracoChip *traco = (*ptraco).second;
0232       traco->run();
0233       for (int step = DTConfig::NSTEPF; step <= DTConfig::NSTEPL; step++) {
0234         if (traco->nTrig(step) > 0) {
0235           _cache.push_back(traco->triggerData(step, 1));
0236           /*
0237           std::cout<<"first bti sl3:
0238           "<<geom()->localPosition(DTBtiId(wheel(),station(),sector(),3,1))<<std::endl;
0239           std::cout<<"traco pos: " <<
0240           geom()->localPosition((traco->triggerData(step,1).parentId()))<<std::endl;
0241           traco->triggerData(step,1).print();
0242           std::cout<<"pos: " << localPosition(&(traco->triggerData(step,1))) <<
0243           std::endl; std::cout<<"dir: " <<
0244           localDirection(&(traco->triggerData(step,1))) << std::endl; std::cout
0245           << std::endl;
0246           */
0247         }
0248         // Store second track only if no first track at previous BX
0249         if (traco->nTrig(step) > 1 && traco->useSecondTrack(step)) {
0250           _cache.push_back(traco->triggerData(step, 2));
0251           /*
0252           std::cout<<"first bti sl3:
0253           "<<geom()->localPosition(DTBtiId(wheel(),station(),sector(),3,1))<<std::endl;
0254           std::cout<<"traco pos: " <<
0255           geom()->localPosition((traco->triggerData(step,2).parentId()))<<std::endl;
0256           traco->triggerData(step,2).print();
0257           std::cout<<"pos: " << localPosition(&(traco->triggerData(step,2))) <<
0258           std::endl; std::cout<<"dir: " <<
0259           localDirection(&(traco->triggerData(step,2))) << std::endl; std::cout
0260           << std::endl;
0261           */
0262         }
0263       }
0264     }
0265     if (debug())
0266       std::cout << "====================================================" << std::endl;
0267   }
0268 }
0269 
0270 DTTracoChip *DTTracoCard::activeGetTRACO(int n) {
0271   // the traco identifier
0272   DTChamberId sid = geom()->statId();
0273   DTTracoId _id = DTTracoId(sid, n);
0274 
0275   DTTracoChip *traco = nullptr;
0276   TRACO_iter ptraco = _tracomap.find(n);
0277   if (ptraco != _tracomap.end()) {
0278     traco = (*ptraco).second;
0279   } else {
0280     traco = new DTTracoChip(this, n, config_traco(_id));
0281     _tracomap[n] = traco;
0282   }
0283   return traco;
0284 }
0285 
0286 DTTracoChip *DTTracoCard::getTRACO(int n) const {
0287   TRACO_const_iter ptraco = _tracomap.find(n);
0288   if (ptraco == _tracomap.end())
0289     return nullptr;
0290   return (*ptraco).second;
0291 }
0292 
0293 std::vector<DTTracoChip *> DTTracoCard::tracoList() {
0294   std::vector<DTTracoChip *> blist;
0295 
0296   if (size() < 1)
0297     return blist;
0298 
0299   for (TRACO_const_iter p = _tracomap.begin(); p != _tracomap.end(); p++) {
0300     blist.push_back((*p).second);
0301   }
0302   return blist;
0303 }
0304 
0305 DTTracoTrig *DTTracoCard::storeTrigger(DTTracoTrigData td) {
0306   DTTracoId tracoid = td.parentId();
0307   if (!(tracoid.wheel() == wheel() && tracoid.sector() == sector() && tracoid.station() == station()))
0308     return nullptr;
0309   std::cout << "DTTracoChip::trigger: trigger not belonging to this card! ";
0310   std::cout << "card=(" << wheel() << "," << station() << "," << sector() << ") ";
0311   std::cout << "trig=(" << tracoid.wheel() << "," << tracoid.station() << "," << tracoid.sector() << ")";
0312   // get the appropriate Traco
0313   DTTracoChip *traco = activeGetTRACO(tracoid.traco());
0314   // create a new trigger in the Traco
0315   DTTracoTrig *trig = new DTTracoTrig(traco, td);
0316   // add the trigger to the Traco
0317   traco->addTrig(td.step(), trig);
0318   // return the trigger
0319   return trig;
0320 }
0321 
0322 /*
0323 LocalPoint
0324 DTTracoCard::localPosition(const DTTrigData* tr) const {
0325 std::cout<<"oldgeo";
0326 
0327   //@@ patch for Sun 4.2 compiler
0328   DTTracoTrigData* trig =
0329 dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
0330   //  const DTTracoTrigData* trig = dynamic_cast<const DTTracoTrigData*>(tr);
0331   if(!trig) {
0332     std::cout << "DTTracoCard::localPosition called with wrong argument!" <<
0333 std::endl; return LocalPoint(0,0,0);
0334   }
0335   float x = geom()->localPosition(trig->parentId()).x();
0336   float y = geom()->localPosition(trig->parentId()).y();
0337   float z = geom()->localPosition(trig->parentId()).z();
0338 
0339   x += geom()->cellPitch() * ( (float)trig->X() / (float)(config()->BTIC())
0340                               - 1.5 * (float)(DTConfig::NBTITC) );
0341   // If not correlated get the position of the SL instead of the chamber center
0342   if       (trig->posIn()==0 ) {
0343     z -= 0.5 * geom()->distSL(); // no inner ==> only outer
0344   } else if(trig->posOut()==0) {
0345     z += 0.5 * geom()->distSL(); // no outer ==> only inner
0346   }
0347   return LocalPoint(x,y,z);
0348 }
0349 */
0350 
0351 LocalPoint DTTracoCard::localPosition(const DTTrigData *tr) const {
0352   // NEWGEO
0353   DTTracoTrigData *trig = dynamic_cast<DTTracoTrigData *>(const_cast<DTTrigData *>(tr));
0354   if (!trig) {
0355     std::cout << "DTTracoCard::localPosition called with wrong argument!" << std::endl;
0356     return LocalPoint(0, 0, 0);
0357   }
0358   float x = geom()->localPosition(trig->parentId()).x();
0359   float y = geom()->localPosition(trig->parentId()).y();
0360   float z = geom()->localPosition(trig->parentId()).z();
0361 
0362   float trig_pos = geom()->cellPitch() * ((float)trig->X() / (float)(config_traco(trig->parentId())->BTIC()));
0363 
0364   //  10/7/06 May be not needed anymore in new geometry
0365   //   if(geom()->posFE(1)==1)
0366   //   trig_pos = -trig_pos;
0367 
0368   x += trig_pos;
0369 
0370   // If not correlated get the position of the SL instead of the chamber center
0371   // z axis toward vertex
0372   if (trig->posIn() == 0) {
0373     z -= 0.5 * geom()->distSL();  // no inner ==> only outer
0374   } else if (trig->posOut() == 0) {
0375     z += 0.5 * geom()->distSL();  // no outer ==> only inner
0376   }
0377   return LocalPoint(x, y, z);
0378 }
0379 
0380 /* OLDGEO
0381 LocalVector
0382 DTTracoCard::localDirection(const DTTrigData* tr) const {
0383   //@@ patch for Sun 4.2 compiler
0384   DTTracoTrigData* trig =
0385 dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
0386   //  const DTTracoTrigData* trig = dynamic_cast<const DTTracoTrigData*>(tr);
0387   if(!trig) {
0388     std::cout << "DTtracoCard::localDirection called with wrong argument!" <<
0389 std::endl; return LocalVector(0,0,0);
0390   }
0391   float r,x,y,z;
0392   x = -(float)trig->K() * geom()->cellPitch() /
0393                       (float)(config_traco(trig->parentId())->BTIC());
0394   y = 0;
0395   z = -geom()->distSL();
0396   r = sqrt(x*x+z*z);
0397   x /= r;
0398   z /= r;
0399   return LocalVector(x,y,z);
0400 }
0401 */
0402 
0403 LocalVector DTTracoCard::localDirection(const DTTrigData *tr) const {
0404   // NEWGEO
0405   DTTracoTrigData *trig = dynamic_cast<DTTracoTrigData *>(const_cast<DTTrigData *>(tr));
0406   if (!trig) {
0407     std::cout << "DTtracoCard::localDirection called with wrong argument!" << std::endl;
0408     return LocalVector(0, 0, 0);
0409   }
0410 
0411   // FE position
0412   // int FE = geom()->posFE(3);
0413 
0414   float psi =
0415       atan((float)(trig->K()) * geom()->cellPitch() / (geom()->distSL() * config_traco(trig->parentId())->BTIC()));
0416 
0417   if (config_traco(trig->parentId())->debug() == 4)
0418     std::cout << "K " << trig->K() << " == psi " << psi << " in FE frame " << std::endl;
0419 
0420   // (xd,yd,zd) in chamber frame
0421   float xd = -sin(psi);
0422   float yd = 0;
0423   float zd = -cos(psi);
0424 
0425   // 10/07/06 Not needed anymore (chages in geometry)
0426   // if(FE==1){//FE in negative y
0427   //    xd = - xd;
0428   //}
0429 
0430   if (config_traco(trig->parentId())->debug() == 4)
0431     std::cout << "Direction in chamber frame is (" << xd << "," << yd << "," << zd << ")" << std::endl;
0432 
0433   return LocalVector(xd, yd, zd);
0434 }
0435 
0436 DTConfigTraco *DTTracoCard::config_traco(const DTTracoId &tracoid) const {
0437   // loop on map to find traco
0438   ConfTracoMap::const_iterator titer = _conf_traco_map.find(tracoid);
0439   if (titer == _conf_traco_map.end()) {
0440     std::cout << "DTTracoCard::config_traco : TRACO (" << tracoid.wheel() << "," << tracoid.sector() << ","
0441               << tracoid.station() << "," << tracoid.traco() << ") not found, return 0" << std::endl;
0442     return nullptr;
0443   }
0444 
0445   return const_cast<DTConfigTraco *>(&(*titer).second);
0446 }