Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-11 03:31:20

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     return bti;
0390   }
0391 
0392   // get configuration for this chip Identifier
0393   DTChamberId sid = geom()->statId();
0394   DTBtiId _id = DTBtiId(sid, sl, n);
0395 
0396   //debug this chip
0397   int _debug_bti = config_bti(_id)->debug();
0398 
0399   if (_debug_bti == 3) {
0400     std::cout << "DTBtiCard::activeGetBTI :";
0401     std::cout << " bti number: " << n << std::endl;
0402   }
0403 
0404   if (sl < 1 || sl > 3) {
0405     if (_debug_bti > 1) {
0406       std::cout << "DTBtiCard::activeGetBTI :";
0407       std::cout << " invalid superlayer number: " << sl;
0408       std::cout << " dummy BTI returned!" << std::endl;
0409     }
0410     return bti;
0411   }
0412 
0413   BTI_iter pbti = _btimap[sl - 1].find(n);
0414   if (pbti != _btimap[sl - 1].end()) {
0415     bti = (*pbti).second;
0416   } else {
0417     bti = new DTBtiChip(this, geom(), sl, n, config_bti(_id));
0418     _btimap[sl - 1][n] = bti;
0419   }
0420   return bti;
0421 }
0422 
0423 DTBtiChip* DTBtiCard::getBTI(int sl, int n) const {
0424   if (sl < 1 || sl > 3 || n == 999) {
0425     std::cout << "DTBtiCard::getBTI :";
0426     std::cout << " invalid superlayer number: " << sl;
0427     std::cout << " 0 returned!" << std::endl;
0428     return nullptr;
0429   }
0430   BTI_const_iter pbti = _btimap[sl - 1].find(n);
0431   if (pbti == _btimap[sl - 1].end()) {
0432     return nullptr;
0433   }
0434   return (*pbti).second;
0435 }
0436 
0437 std::vector<DTBtiChip*> DTBtiCard::btiList(int sl) {
0438   std::vector<DTBtiChip*> blist;
0439 
0440   if (size() < 1)
0441     return blist;
0442 
0443   if (sl < 1 || sl > 3) {
0444     std::cout << "DTBtiCard::btiList :";
0445     std::cout << " invalid superlayer number: " << sl;
0446     std::cout << " empty list returned" << std::endl;
0447     return blist;
0448   }
0449 
0450   for (BTI_const_iter p = _btimap[sl - 1].begin(); p != _btimap[sl - 1].end(); p++) {
0451     blist.push_back((*p).second);
0452   }
0453   return blist;
0454 }
0455 
0456 DTBtiTrig* DTBtiCard::storeTrigger(DTBtiTrigData td) {
0457   DTBtiId btiid = td.parentId();
0458   if (!(btiid.wheel() == wheel() && btiid.sector() == sector() && btiid.station() == station()))
0459     return nullptr;
0460   std::cout << "DTBtiCard::trigger: trigger not belonging to this card! ";
0461   std::cout << "card=(" << wheel() << "," << station() << "," << sector() << ") ";
0462   std::cout << "trig=(" << btiid.wheel() << "," << btiid.station() << "," << btiid.sector() << ")";
0463   // get the appropriate BTI
0464   DTBtiChip* bti = activeGetBTI(btiid.superlayer(), btiid.bti());
0465   // create a new trigger in the BTI
0466   auto trig = std::make_unique<DTBtiTrig>(bti, td);
0467   auto pTrig = trig.get();
0468   // add the trigger to the BTI
0469   bti->addTrig(td.step(), std::move(trig));
0470   // return the trigger
0471   return pTrig;
0472 }
0473 
0474 /*
0475 LocalPoint 
0476 DTBtiCard::localPosition(const DTTrigData* tr) const {
0477 //OBSOLETE!!!!!
0478   //@@ patch for Sun 4.2 compiler
0479   DTBtiTrigData* trig = dynamic_cast<DTBtiTrigData*>(const_cast<DTTrigData*>(tr));
0480   //  const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
0481   if(!trig) {
0482     std::cout << "DTBtiCard::localPosition called with wrong argument!" << std::endl;
0483     return LocalPoint(0,0,0);
0484   }
0485   float x = geom()->localPosition(trig->parentId()).x();
0486   float y = geom()->localPosition(trig->parentId()).y();
0487   float z = geom()->localPosition(trig->parentId()).z();
0488   
0489   //FE position
0490   int FE = geom()->posFE(trig->parentId().superlayer());
0491 
0492   //trigger position in the BTI frame
0493   float xt = 0;
0494   float yt = 0;
0495   float xtrig = (float)trig->X() * geom()->cellPitch() / (config()->ST());
0496   if(trig->btiSL()==2) 
0497     yt = - xtrig;
0498   else
0499     xt = + xtrig;
0500 
0501   if(FE==1){//FE in negative y
0502       xt = - xt;
0503       yt = - yt;
0504   }
0505 
0506   std::cout << "DTBtiCard::localPosition of BTI in ("<<x<<","<<y<<","<<z<<")"<<std::endl;
0507   std::cout << " called for trig "; 
0508   trig->print(); 
0509   std::cout << "in Local Point ("<<x+xt<<","<<y+yt<<","<<z<<")"<<std::endl;
0510 
0511   return LocalPoint(x+xt,y+yt,z);
0512 }
0513 */
0514 
0515 LocalPoint DTBtiCard::localPosition(const DTTrigData* tr) const {
0516   //NEWGEO!!!
0517   const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
0518   if (!trig) {
0519     std::cout << "DTBtiCard::localPosition called with wrong argument!" << std::endl;
0520     return LocalPoint(0, 0, 0);
0521   }
0522 
0523   //BTI position in chamber frame
0524   float x = geom()->localPosition(trig->parentId()).x();
0525   float y = geom()->localPosition(trig->parentId()).y();
0526   float z = geom()->localPosition(trig->parentId()).z();
0527 
0528   //FE position
0529   //int FE = geom()->posFE(trig->parentId().superlayer());
0530 
0531   //trigger position in the BTI frame
0532   float xt = 0;
0533   float yt = 0;
0534 
0535   DTBtiId _btiid = trig->parentId();
0536   float xtrig = (float)trig->X() * geom()->cellPitch() / (config_bti(_btiid)->ST());
0537   if (trig->btiSL() == 2)
0538     yt = -xtrig;
0539   else
0540     xt = +xtrig;
0541 
0542   //   17/07/06 Should be obsolete in CMSSW
0543   //   if(FE==1){//FE in negative y
0544   //       xt = - xt;
0545   //       yt = - yt;
0546   //   }
0547 
0548   if (debug()) {
0549     std::cout << "DTBtiCard::localPosition of BTI in (" << x << "," << y << "," << z << ")" << std::endl;
0550     std::cout << " called for trig ";
0551     trig->print();
0552     std::cout << "in Local Point (" << x + xt << "," << y + yt << "," << z << ")" << std::endl;
0553   }
0554 
0555   return LocalPoint(x + xt, y + yt, z);
0556 }
0557 
0558 LocalVector DTBtiCard::localDirection(const DTTrigData* tr) const {
0559   //NEWGEO
0560   const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
0561   //this method is only for check purpose
0562   if (!trig) {
0563     std::cout << "DTBtiCard::localDirection called with wrong argument!" << std::endl;
0564     return LocalVector(0, 0, 0);
0565   }
0566 
0567   //FE position
0568   //int FE = geom()->posFE(trig->parentId().superlayer());
0569 
0570   // psi in BTI frame
0571   DTBtiId _btiid = trig->parentId();
0572   float psi = atan((float)(trig->K() - config_bti(_btiid)->ST()) * geom()->cellPitch() /
0573                    (2 * geom()->cellH() * config_bti(_btiid)->ST()));
0574   // (xd,yd,zd) in chamber frame
0575   float xd = 0;
0576   float yd = 0;
0577   float zd = -cos(psi);
0578   if (trig->btiSL() == 2)
0579     yd = sin(psi);
0580   else
0581     xd = -sin(psi);
0582 
0583   // 17/07/06 Ths should be obsolete in CMSSW
0584   //   if(FE==1){//FE in negative y
0585   //       xd = - xd;
0586   //       yd = - yd;
0587   //  }
0588 
0589   if (debug()) {
0590     //BTI position in chamber frame
0591     float xb = geom()->localPosition(trig->parentId()).x();
0592     float yb = geom()->localPosition(trig->parentId()).y();
0593     float zb = geom()->localPosition(trig->parentId()).z();
0594 
0595     std::cout << "DTBtiCard::localDirection of BTI in (" << xb << "," << yb << "," << zb << ")" << std::endl;
0596     std::cout << " called for trig ";
0597     trig->print();
0598     std::cout << "in Local Direction (" << xd << "," << yd << "," << zd << ")" << std::endl;
0599   }
0600 
0601   return LocalVector(xd, yd, zd);
0602 }
0603 
0604 /*
0605 
0606 LocalVector
0607 DTBtiCard::localDirection(const DTTrigData* tr) const {
0608 //OBSOLETE!!!!
0609   //@@ patch for Sun 4.2 compiler
0610   const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(const_cast<DTTrigData*>(tr));
0611   //  const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
0612   if(!trig) {
0613     std::cout << "DTBtiCard::localDirection called with wrong argument!" << std::endl;
0614     return LocalVector(0,0,0);
0615   }
0616   float x1,r,x,y,z;
0617   x1 = -(float)trig->K() * geom()->cellPitch() /
0618                       (float)(config()->ST());
0619   z = - 2 * geom()->cellH();
0620   r = sqrt(x1*x1+z*z);
0621   if(trig->btiSL()!=2) {
0622     x = x1/r;
0623     y = 0;
0624   } else {
0625     x = 0;
0626     y = x1/r;
0627   }
0628   z /= r;
0629   return LocalVector(x,y,z);
0630 }
0631 */
0632 
0633 DTConfigBti* DTBtiCard::config_bti(DTBtiId& btiid) const {
0634   //loop on map to find bti
0635   ConfBtiMap::const_iterator biter = _conf_bti_map.find(btiid);
0636   if (biter == _conf_bti_map.end()) {
0637     std::cout << "DTBtiCard::config_bti : BTI (" << btiid.wheel() << "," << btiid.sector() << "," << btiid.station()
0638               << "," << btiid.superlayer() << "," << btiid.bti() << ") not found, return 0" << std::endl;
0639     return nullptr;
0640   }
0641 
0642   return const_cast<DTConfigBti*>(&(*biter).second);
0643 }