Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //-------------------------------------------------
0002 //
0003 //   Class: DTBtiCard
0004 //
0005 //   Description: Contains active DTBtiChips
0006 //
0007 //
0008 //   Author List:
0009 //   C. Grandi
0010 //   Modifications:
0011 //   S. Vanini
0012 //   22/VI/04 SV: last trigger code update - digi offset subtracted from digi time
0013 //   III/05 SV  : NEWGEO : trigger in new geometry !
0014 //   05/II/07 SV : new DTConfig update
0015 //   30/III/07 SV : config with DTConfigManager every single chip
0016 //----------------------------------------------------------------
0017 
0018 //-----------------------
0019 // This Class's Header --
0020 //-----------------------
0021 #include "L1Trigger/DTBti/interface/DTBtiCard.h"
0022 
0023 //-------------------------------
0024 // Collaborating Class Headers --
0025 //-------------------------------
0026 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0027 #include "DataFormats/GeometryVector/interface/LocalVector.h"
0028 #include "L1Trigger/DTBti/interface/DTBtiChip.h"
0029 #include "L1Trigger/DTBti/interface/DTBtiTrig.h"
0030 
0031 #include "FWCore/Framework/interface/Event.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "DataFormats/Common/interface/Handle.h"
0034 
0035 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0036 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0037 #include "Geometry/DTGeometry/interface/DTLayer.h"
0038 #include "Geometry/DTGeometry/interface/DTChamber.h"
0039 
0040 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0041 #include "DataFormats/MuonDetId/interface/DTLayerId.h"
0042 #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
0043 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0044 #include "DataFormats/DTDigi/interface/DTDigiCollection.h"
0045 
0046 //---------------
0047 // C++ Headers --
0048 //---------------
0049 #include <iostream>
0050 #include <cmath>
0051 #include <utility>
0052 #include <vector>
0053 
0054 using namespace edm;
0055 
0056 //----------------
0057 // Constructors --
0058 //----------------
0059 
0060 DTBtiCard::DTBtiCard(DTTrigGeom* geom) : DTGeomSupplier(geom) {
0061   //_configBti = new DTConfigBti(bti_pset);
0062   //_configBti->print();
0063 
0064   //DTChamberId sid = ChamberId();
0065   //_conf_bti_map = conf_manager->getDTConfigBtiMap(sid);
0066   //_debug = conf_manager->getDTTPGDebug();
0067 
0068   //_finedelay   = conf_manager->getDTConfigTrigUnit(sid)->MCSetupTime();
0069   //_MCdelay     = conf_manager->getDTConfigTrigUnit(sid)->MCDigiOffset();
0070 }
0071 
0072 //--------------
0073 // Destructor --
0074 //--------------
0075 
0076 DTBtiCard::~DTBtiCard() {
0077   localClear();
0078   //delete _conf_Bti;
0079 }
0080 
0081 //--------------
0082 // Operations --
0083 //--------------
0084 
0085 void DTBtiCard::clearCache() {
0086   BTICache::clearCache();
0087   localClear();
0088 }
0089 
0090 void DTBtiCard::setConfig(const DTConfigManager* conf) {
0091   DTChamberId sid = ChamberId();
0092   _conf_bti_map = conf->getDTConfigBtiMap(sid);
0093   _debug = conf->getDTTPGDebug();
0094   _pedestals = conf->getDTConfigPedestals();
0095 
0096   // get bti acceptance flag
0097   _flag_acc = conf->useAcceptParam();
0098 }
0099 
0100 void DTBtiCard::localClear() {
0101   // Clear the maps
0102   for (int i = 0; i < 3; i++) {
0103     for (BTI_iter p = _btimap[i].begin(); p != _btimap[i].end(); p++) {
0104       delete (*p).second;
0105     }
0106     _btimap[i].clear();
0107   }
0108 
0109   //clear digis
0110   std::vector<DTDigi*>::const_iterator p;
0111   for (p = _digis.begin(); p < _digis.end(); p++)
0112     delete (*p);
0113   _digis.clear();
0114 }
0115 
0116 // void
0117 // //DTBtiCard::loadBTI() {
0118 // DTBtiCard::loadBTI(const DTDigiCollection dtDigis) {
0119 
0120 //   localClear();
0121 
0122 //    int ndigis = stat()->ndigis();
0123 
0124 // // /*
0125 // //   //SV version for tb2003 data
0126 // //   // loop over chambers, superlayers and layers
0127 // //   DTBXSetUp* setup = Singleton<DTBXSetUp>::instance();
0128 // //   DTDetectorMap* detMap = setup->chamberMap();
0129 // //   std::vector<DTChamber*> chambers = detMap->chambers();
0130 // //   DTDetectorMap::ChamIter stat;
0131 // //   for ( stat = chambers.begin(); stat != chambers.end(); stat++ ) {
0132 // // */
0133 
0134 // //   // Get DTDigi's from DTChamber  (stat is DTChamber*)
0135 // //   // Loop over all Digis and make a local copy
0136 // //   // Store a pointer to them in the relevant DTBtiChip's
0137 
0138 //   if(ndigis){
0139 
0140 //     if(debug()){
0141 //       std::cout << "====================================================" << std::endl;
0142 //       std::cout <<  ndigis << " DIGIS in  wheel " << wheel() <<
0143 //               " station " << station() <<
0144 //               " sector "  << sector() << std::endl;
0145 //     }
0146 
0147 //     std::vector<DTDigi> digi_container = stat()->digis();
0148 //     std::vector<DTDigi>::const_iterator       digi_iter;
0149 
0150 //     for(digi_iter=digi_container.begin(); digi_iter<digi_container.end(); digi_iter++){
0151 
0152 //     /*Testbeam 2004 specific code
0153 //     //digi.time in ns; digi.countsTDC in tdcunits
0154 //     //float tdrift = (*digi_iter).time()-1.0*DTDigiParameters::offset;
0155 //     //TB2004 version: no offset subtraction because digi are already t0 off!!!!
0156 //     //tdrift must be float, otherwise DTDigi constructor assumes tdcunits!
0157 //     //add chamber specific delay
0158 //     int tdctime = (*digi_iter).countsTDC();
0159 //     int mcdelay = (stat()->id().station()==1) ? config()->SetupTimeMB1() : config()->SetupTimeMB
0160 // 3();
0161 //     tdctime += mcdelay;
0162 //     */
0163 //       float tdrift = (*digi_iter).time()-1.0*DTDigiParameters::offset;
0164 //       DTWireId idwire( wheel(), station(), sector(), (*digi_iter).slayer(),
0165 //                         (*digi_iter).layer(), (*digi_iter).wire() );
0166 
0167 // /*
0168 //   //NEWGEO TEST: sw testpulse for testing new geometry in wire 1 of each sl
0169 //   for(int l=0;l<12;l++){
0170 //     int sl = int(l/4.) + 1;
0171 //     if(station()!=4 || sl!=2){
0172 //     int lay = int(fmod(l,4.)) + 1;
0173 //     int wire = 2*sector();
0174 //     if(geom()->posFE(sl)==0 || station()==1 || sl==2)
0175 //       wire += lay==4? 1:2;
0176 //     else if(geom()->posFE(sl)==1)
0177 //       wire += lay==3? 3:2;
0178 
0179 //     //int wire = 1;
0180 //     //tmax=400ns, straight tracks in middle : 200ns (float for ns, int for tdc_counts)
0181 //     //float tdrift = 187.5;
0182 //     float tdrift = 200.0;
0183 //     DTWireId idwire( wheel(), station(), sector(), sl, lay, wire);
0184 // */
0185 
0186 //       DTDigi* pdigi = new DTDigi(idwire,tdrift);
0187 //       _digis.push_back(const_cast<DTDigi*>(pdigi));
0188 
0189 //       if(debug())
0190 //         pdigi->print();
0191 
0192 //       int sln = pdigi->slayer();
0193 //       int layn = pdigi->layer();
0194 //       int tube = pdigi->wire();
0195 
0196 //       // map in FE channel number:
0197 //       int nch = geom()->mapTubeInFEch(sln,layn,tube);
0198 
0199 //       // assign ch numbers to btis: depends on layer staggering!
0200 //       int nbti = nch + geom()->layerFEStaggering(sln,layn);
0201 
0202 //       if(debug()){
0203 //         std::cout << "FE ch " << nch;
0204 //         std::cout << " of bti " << nbti;
0205 //         std::cout << " staggering " <<  geom()->layerFEStaggering(sln,layn);
0206 //         std::cout << " now nbti is " << nch;
0207 //         std::cout << " SL phi offset " << geom()->phiSLOffset() << std::endl;
0208 //       }
0209 
0210 //       switch(layn) {
0211 //       case 1:
0212 //         if(activeGetBTI(sln, nbti  )) activeGetBTI(sln, nbti  )->add_digi(4, pdigi);
0213 //         if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(8, pdigi);
0214 //       break;
0215 //       case 2:
0216 //         if(activeGetBTI(sln, nbti  )) activeGetBTI(sln, nbti  )->add_digi(2, pdigi);
0217 //         if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(6, pdigi);
0218 //       break;
0219 //       case 3:
0220 //         if(activeGetBTI(sln, nbti  )) activeGetBTI(sln, nbti  )->add_digi(3, pdigi);
0221 //         if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(7, pdigi);
0222 //       break;
0223 //       case 4:
0224 //         if(activeGetBTI(sln, nbti  )) activeGetBTI(sln, nbti  )->add_digi(1, pdigi);
0225 //         if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(5, pdigi);
0226 //         if(activeGetBTI(sln, nbti-2)) activeGetBTI(sln, nbti-2)->add_digi(9, pdigi);
0227 //       break;
0228 //       }
0229 //     }//end loop on digi
0230 
0231 //     if(debug())
0232 //       std::cout << "====================================================" << std::endl;
0233 
0234 //   }//end if(ndigis)
0235 // }
0236 
0237 void DTBtiCard::loadBTI(const DTDigiCollection dtDigis) {
0238   localClear();
0239 
0240   if (debug()) {
0241     std::cout << "DTBtiCard::loadBTI called for wheel=" << wheel();
0242     std::cout << ", station=" << station();
0243     std::cout << ", sector=" << sector() << std::endl;
0244   }
0245 
0246   DTDigiCollection::DigiRangeIterator detUnitIt;
0247   for (detUnitIt = dtDigis.begin(); detUnitIt != dtDigis.end(); ++detUnitIt) {
0248     const DTLayerId& id = (*detUnitIt).first;
0249     const DTDigiCollection::Range& range = (*detUnitIt).second;
0250 
0251     // DTLayerId print-out
0252     if (debug()) {
0253       std::cout << "--------------" << std::endl;
0254       std::cout << "id: " << id;
0255     }
0256 
0257     // Loop over the digis of this DetUnit
0258     for (DTDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
0259       int tube = (*digiIt).wire();
0260       const DTWireId tubeid(id, tube);
0261       float tdrift = (*digiIt).time() - _pedestals->getOffset(tubeid);
0262 
0263       if (debug()) {
0264         std::cout << " digi time : " << (*digiIt).time();
0265         std::cout << " pedestal offset : " << _pedestals->getOffset(tubeid) << std::endl;
0266         std::cout << " drift time after subtraction : " << tdrift << std::endl;
0267       }
0268 
0269       if (tdrift < 500 && tdrift > -500) {
0270         if (debug())
0271           (*digiIt).print();
0272 
0273         // get bti number for access to the configuration for this bti chip : SV
0274         // FIX: for the moment take first bti configuration!!!!! ok fixed
0275         DTSuperLayerId slnum = id.superlayerId();
0276         //DTChamberId dtcham =id.chamberId();
0277         int sln = slnum.superlayer();
0278         int layn = id.layer();
0279         //int tube = (*digiIt).wire();
0280 
0281         // map in FE channel number: SL theta tubes are numbered inversely w.r.t. hardware setup in new geometry 19/06/06
0282         // assign ch numbers to btis: in new geometry does not depend on layer staggering anymore! Same staggering anywhere.
0283         //int nch = geom()->mapTubeInFEch(sln,layn,tube);
0284         //  int nbti = nch + geom()->layerFEStaggering(sln,layn);
0285 
0286         int nch = geom()->mapTubeInFEch(sln, layn, tube);
0287         int nbti = nch;
0288 
0289         if (debug()) {
0290           std::cout << "FE ch " << nch;
0291           std::cout << " of bti " << nbti;
0292           //      std::cout << " staggering " <<  geom()->layerFEStaggering(sln,layn);
0293           std::cout << " now nbti is " << nch << std::endl;
0294           //      std::cout << " SL phi offset " << geom()->phiSLOffset() << std::endl;
0295         }
0296 
0297         // FIXED get configuration for the nbti chip Identifier, and from it MCdelay + finedelay
0298         //DTChamberId sid = geom()->statId();
0299         //DTBtiId _id = DTBtiId(sid, sln, nbti);
0300 
0301         DTDigi* pdigi = new DTDigi((*digiIt).wire(), tdrift);
0302         _digis.push_back(pdigi);
0303 
0304         switch (layn) {
0305           case 1:
0306             if (activeGetBTI(sln, nbti))
0307               activeGetBTI(sln, nbti)->add_digi(4, pdigi);
0308             if (activeGetBTI(sln, nbti - 1))
0309               activeGetBTI(sln, nbti - 1)->add_digi(8, pdigi);
0310             break;
0311           case 2:
0312             if (activeGetBTI(sln, nbti))
0313               activeGetBTI(sln, nbti)->add_digi(2, pdigi);
0314             if (activeGetBTI(sln, nbti - 1))
0315               activeGetBTI(sln, nbti - 1)->add_digi(6, pdigi);
0316             break;
0317           case 3:
0318             if (activeGetBTI(sln, nbti))
0319               activeGetBTI(sln, nbti)->add_digi(3, pdigi);
0320             if (activeGetBTI(sln, nbti - 1))
0321               activeGetBTI(sln, nbti - 1)->add_digi(7, pdigi);
0322             break;
0323           case 4:
0324             if (activeGetBTI(sln, nbti))
0325               activeGetBTI(sln, nbti)->add_digi(1, pdigi);
0326             if (activeGetBTI(sln, nbti - 1))
0327               activeGetBTI(sln, nbti - 1)->add_digi(5, pdigi);
0328             if (activeGetBTI(sln, nbti - 2))
0329               activeGetBTI(sln, nbti - 2)->add_digi(9, pdigi);
0330             break;
0331         }
0332       }  //end loop on digi
0333       //    }//end loop on lay
0334       //  }//end loop on sl
0335     }
0336   }
0337 }
0338 
0339 void DTBtiCard::runBTI() {
0340   int nbtisig = _btimap[0].size() + _btimap[1].size() + _btimap[2].size();
0341 
0342   if (debug()) {
0343     std::cout << "DTBtiCard::runBTI called for wheel=" << wheel();
0344     std::cout << ", station=" << station();
0345     std::cout << ", sector=" << sector();
0346     std::cout << ", " << nbtisig << " BTIs with signal" << std::endl;
0347   }
0348 
0349   if (nbtisig) {
0350     if (debug()) {
0351       std::cout << "====================================================" << std::endl;
0352       std::cout << "              BTI triggers                          " << std::endl;
0353     }
0354 
0355     // run DTBtiChip algorithm on all non-empty BTI
0356     for (int sl = 1; sl <= 3; sl++) {
0357       if (!_btimap[sl - 1].empty()) {
0358         BTI_iter pbti;
0359         for (pbti = _btimap[sl - 1].begin(); pbti != _btimap[sl - 1].end(); pbti++) {
0360           DTBtiChip* bti = (*pbti).second;
0361           if (bti->number() < 200)
0362             bti->run();
0363           for (int step = DTConfig::NSTEPF; step <= DTConfig::NSTEPL; step++) {
0364             if (bti->nTrig(step) > 0) {
0365               _cache.push_back(bti->triggerData(step, 1));
0366               //localPosition(&(bti->triggerData(step,1)));
0367               //localDirection(&(bti->triggerData(step,1)));
0368             }
0369           }
0370         }
0371       }
0372     }
0373 
0374     if (debug())
0375       std::cout << "====================================================" << std::endl;
0376   }  //end if(nbtisig)
0377 }
0378 
0379 DTBtiChip* DTBtiCard::activeGetBTI(int sl, int n) {
0380   DTBtiChip* bti = nullptr;
0381   //check if BTi is out of range before all
0382   if (n < 1 || n > geom()->nCell(sl)) {
0383     if (debug()) {
0384       std::cout << "DTBtiCard::activeGetBTI :";
0385       std::cout << " invalid bti number: " << n;
0386       std::cout << " not in range [1," << geom()->nCell(sl) << "]";
0387       std::cout << " dummy BTI returned!" << std::endl;
0388     }
0389     sl = 1;
0390     n = 999;
0391     return bti;
0392   }
0393 
0394   // get configuration for this chip Identifier
0395   DTChamberId sid = geom()->statId();
0396   DTBtiId _id = DTBtiId(sid, sl, n);
0397 
0398   //debug this chip
0399   int _debug_bti = config_bti(_id)->debug();
0400 
0401   if (_debug_bti == 3) {
0402     std::cout << "DTBtiCard::activeGetBTI :";
0403     std::cout << " bti number: " << n << std::endl;
0404   }
0405 
0406   if (sl < 1 || sl > 3) {
0407     if (_debug_bti > 1) {
0408       std::cout << "DTBtiCard::activeGetBTI :";
0409       std::cout << " invalid superlayer number: " << sl;
0410       std::cout << " dummy BTI returned!" << std::endl;
0411     }
0412     sl = 1;
0413     n = 999;
0414     return bti;
0415   }
0416 
0417   BTI_iter pbti = _btimap[sl - 1].find(n);
0418   if (pbti != _btimap[sl - 1].end()) {
0419     bti = (*pbti).second;
0420   } else {
0421     bti = new DTBtiChip(this, geom(), sl, n, config_bti(_id));
0422     _btimap[sl - 1][n] = bti;
0423   }
0424   return bti;
0425 }
0426 
0427 DTBtiChip* DTBtiCard::getBTI(int sl, int n) const {
0428   if (sl < 1 || sl > 3 || n == 999) {
0429     std::cout << "DTBtiCard::getBTI :";
0430     std::cout << " invalid superlayer number: " << sl;
0431     std::cout << " 0 returned!" << std::endl;
0432     return nullptr;
0433   }
0434   BTI_const_iter pbti = _btimap[sl - 1].find(n);
0435   if (pbti == _btimap[sl - 1].end()) {
0436     return nullptr;
0437   }
0438   return (*pbti).second;
0439 }
0440 
0441 std::vector<DTBtiChip*> DTBtiCard::btiList(int sl) {
0442   std::vector<DTBtiChip*> blist;
0443 
0444   if (size() < 1)
0445     return blist;
0446 
0447   if (sl < 1 || sl > 3) {
0448     std::cout << "DTBtiCard::btiList :";
0449     std::cout << " invalid superlayer number: " << sl;
0450     std::cout << " empty list returned" << std::endl;
0451     return blist;
0452   }
0453 
0454   for (BTI_const_iter p = _btimap[sl - 1].begin(); p != _btimap[sl - 1].end(); p++) {
0455     blist.push_back((*p).second);
0456   }
0457   return blist;
0458 }
0459 
0460 DTBtiTrig* DTBtiCard::storeTrigger(DTBtiTrigData td) {
0461   DTBtiId btiid = td.parentId();
0462   if (!(btiid.wheel() == wheel() && btiid.sector() == sector() && btiid.station() == station()))
0463     return nullptr;
0464   std::cout << "DTBtiCard::trigger: trigger not belonging to this card! ";
0465   std::cout << "card=(" << wheel() << "," << station() << "," << sector() << ") ";
0466   std::cout << "trig=(" << btiid.wheel() << "," << btiid.station() << "," << btiid.sector() << ")";
0467   // get the appropriate BTI
0468   DTBtiChip* bti = activeGetBTI(btiid.superlayer(), btiid.bti());
0469   // create a new trigger in the BTI
0470   auto trig = std::make_unique<DTBtiTrig>(bti, td);
0471   auto pTrig = trig.get();
0472   // add the trigger to the BTI
0473   bti->addTrig(td.step(), std::move(trig));
0474   // return the trigger
0475   return pTrig;
0476 }
0477 
0478 /*
0479 LocalPoint 
0480 DTBtiCard::localPosition(const DTTrigData* tr) const {
0481 //OBSOLETE!!!!!
0482   //@@ patch for Sun 4.2 compiler
0483   DTBtiTrigData* trig = dynamic_cast<DTBtiTrigData*>(const_cast<DTTrigData*>(tr));
0484   //  const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
0485   if(!trig) {
0486     std::cout << "DTBtiCard::localPosition called with wrong argument!" << std::endl;
0487     return LocalPoint(0,0,0);
0488   }
0489   float x = geom()->localPosition(trig->parentId()).x();
0490   float y = geom()->localPosition(trig->parentId()).y();
0491   float z = geom()->localPosition(trig->parentId()).z();
0492   
0493   //FE position
0494   int FE = geom()->posFE(trig->parentId().superlayer());
0495 
0496   //trigger position in the BTI frame
0497   float xt = 0;
0498   float yt = 0;
0499   float xtrig = (float)trig->X() * geom()->cellPitch() / (config()->ST());
0500   if(trig->btiSL()==2) 
0501     yt = - xtrig;
0502   else
0503     xt = + xtrig;
0504 
0505   if(FE==1){//FE in negative y
0506       xt = - xt;
0507       yt = - yt;
0508   }
0509 
0510   std::cout << "DTBtiCard::localPosition of BTI in ("<<x<<","<<y<<","<<z<<")"<<std::endl;
0511   std::cout << " called for trig "; 
0512   trig->print(); 
0513   std::cout << "in Local Point ("<<x+xt<<","<<y+yt<<","<<z<<")"<<std::endl;
0514 
0515   return LocalPoint(x+xt,y+yt,z);
0516 }
0517 */
0518 
0519 LocalPoint DTBtiCard::localPosition(const DTTrigData* tr) const {
0520   //NEWGEO!!!
0521   const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
0522   if (!trig) {
0523     std::cout << "DTBtiCard::localPosition called with wrong argument!" << std::endl;
0524     return LocalPoint(0, 0, 0);
0525   }
0526 
0527   //BTI position in chamber frame
0528   float x = geom()->localPosition(trig->parentId()).x();
0529   float y = geom()->localPosition(trig->parentId()).y();
0530   float z = geom()->localPosition(trig->parentId()).z();
0531 
0532   //FE position
0533   //int FE = geom()->posFE(trig->parentId().superlayer());
0534 
0535   //trigger position in the BTI frame
0536   float xt = 0;
0537   float yt = 0;
0538 
0539   DTBtiId _btiid = trig->parentId();
0540   float xtrig = (float)trig->X() * geom()->cellPitch() / (config_bti(_btiid)->ST());
0541   if (trig->btiSL() == 2)
0542     yt = -xtrig;
0543   else
0544     xt = +xtrig;
0545 
0546   //   17/07/06 Should be obsolete in CMSSW
0547   //   if(FE==1){//FE in negative y
0548   //       xt = - xt;
0549   //       yt = - yt;
0550   //   }
0551 
0552   if (debug()) {
0553     std::cout << "DTBtiCard::localPosition of BTI in (" << x << "," << y << "," << z << ")" << std::endl;
0554     std::cout << " called for trig ";
0555     trig->print();
0556     std::cout << "in Local Point (" << x + xt << "," << y + yt << "," << z << ")" << std::endl;
0557   }
0558 
0559   return LocalPoint(x + xt, y + yt, z);
0560 }
0561 
0562 LocalVector DTBtiCard::localDirection(const DTTrigData* tr) const {
0563   //NEWGEO
0564   const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
0565   //this method is only for check purpose
0566   if (!trig) {
0567     std::cout << "DTBtiCard::localDirection called with wrong argument!" << std::endl;
0568     return LocalVector(0, 0, 0);
0569   }
0570 
0571   //FE position
0572   //int FE = geom()->posFE(trig->parentId().superlayer());
0573 
0574   // psi in BTI frame
0575   DTBtiId _btiid = trig->parentId();
0576   float psi = atan((float)(trig->K() - config_bti(_btiid)->ST()) * geom()->cellPitch() /
0577                    (2 * geom()->cellH() * config_bti(_btiid)->ST()));
0578   // (xd,yd,zd) in chamber frame
0579   float xd = 0;
0580   float yd = 0;
0581   float zd = -cos(psi);
0582   if (trig->btiSL() == 2)
0583     yd = sin(psi);
0584   else
0585     xd = -sin(psi);
0586 
0587   // 17/07/06 Ths should be obsolete in CMSSW
0588   //   if(FE==1){//FE in negative y
0589   //       xd = - xd;
0590   //       yd = - yd;
0591   //  }
0592 
0593   if (debug()) {
0594     //BTI position in chamber frame
0595     float xb = geom()->localPosition(trig->parentId()).x();
0596     float yb = geom()->localPosition(trig->parentId()).y();
0597     float zb = geom()->localPosition(trig->parentId()).z();
0598 
0599     std::cout << "DTBtiCard::localDirection of BTI in (" << xb << "," << yb << "," << zb << ")" << std::endl;
0600     std::cout << " called for trig ";
0601     trig->print();
0602     std::cout << "in Local Direction (" << xd << "," << yd << "," << zd << ")" << std::endl;
0603   }
0604 
0605   return LocalVector(xd, yd, zd);
0606 }
0607 
0608 /*
0609 
0610 LocalVector
0611 DTBtiCard::localDirection(const DTTrigData* tr) const {
0612 //OBSOLETE!!!!
0613   //@@ patch for Sun 4.2 compiler
0614   const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(const_cast<DTTrigData*>(tr));
0615   //  const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
0616   if(!trig) {
0617     std::cout << "DTBtiCard::localDirection called with wrong argument!" << std::endl;
0618     return LocalVector(0,0,0);
0619   }
0620   float x1,r,x,y,z;
0621   x1 = -(float)trig->K() * geom()->cellPitch() /
0622                       (float)(config()->ST());
0623   z = - 2 * geom()->cellH();
0624   r = sqrt(x1*x1+z*z);
0625   if(trig->btiSL()!=2) {
0626     x = x1/r;
0627     y = 0;
0628   } else {
0629     x = 0;
0630     y = x1/r;
0631   }
0632   z /= r;
0633   return LocalVector(x,y,z);
0634 }
0635 */
0636 
0637 DTConfigBti* DTBtiCard::config_bti(DTBtiId& btiid) const {
0638   //loop on map to find bti
0639   ConfBtiMap::const_iterator biter = _conf_bti_map.find(btiid);
0640   if (biter == _conf_bti_map.end()) {
0641     std::cout << "DTBtiCard::config_bti : BTI (" << btiid.wheel() << "," << btiid.sector() << "," << btiid.station()
0642               << "," << btiid.superlayer() << "," << btiid.bti() << ") not found, return 0" << std::endl;
0643     return nullptr;
0644   }
0645 
0646   return const_cast<DTConfigBti*>(&(*biter).second);
0647 }