CMS 3D CMS Logo

DTTracoCard.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: DTTracoCard
00004 //
00005 //   Description: Contains active DTTracoChips
00006 //
00007 //
00008 //   Author List:
00009 //   C. Grandi
00010 //   Modifications: 
00011 //   X/03 Sara Vanini
00012 //   22/VI/04 SV: last trigger code update
00013 //   13/XII/04 SV: Zotto's traco acceptance routine implemented
00014 //   V/05 SV: NEWGEO
00015 //   9/V/05 SV: mt ports ing K units, bug fixed  
00016 //   30/III/07 SV : config with DTConfigManager every single chip 
00017 //--------------------------------------------------
00018 
00019 //-----------------------
00020 // This Class's Header --
00021 //-----------------------
00022 #include "L1Trigger/DTTraco/interface/DTTracoCard.h"
00023 
00024 //-------------------------------
00025 // Collaborating Class Headers --
00026 //-------------------------------
00027 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00028 #include "DataFormats/GeometryVector/interface/LocalVector.h"
00029 #include "L1Trigger/DTTraco/interface/DTTracoChip.h"
00030 #include "L1Trigger/DTTraco/interface/DTTracoTrig.h"
00031 #include "L1Trigger/DTBti/interface/DTBtiCard.h"
00032 #include "L1Trigger/DTBti/interface/DTBtiTrigData.h"
00033 #include "L1Trigger/DTTriggerServerTheta/interface/DTTSTheta.h"
00034 
00035 //---------------
00036 // C++ Headers --
00037 //---------------
00038 #include <iostream>
00039 #include <cmath>
00040 #include <utility>  
00041 #include <iomanip>
00042 #include <math.h>
00043 
00044 //----------------
00045 // Constructors --
00046 //----------------
00047 
00048 DTTracoCard::DTTracoCard(DTTrigGeom* geo, DTBtiCard* bticard,
00049   DTTSTheta* tstheta) : DTGeomSupplier(geo) , 
00050   _bticard(bticard), _tstheta(tstheta) { 
00051 
00052   // get traco configuration map
00053   // DTChamberId sid = geom()->statId();
00054   // _debug = _conf_manager->getDTTPGDebug();
00055   // _conf_traco_map = _conf_manager->getDTConfigTracoMap(sid); 
00056 
00057 }
00058 
00059 //--------------
00060 // Destructor --
00061 //--------------
00062 
00063 DTTracoCard::~DTTracoCard(){
00064 
00065 localClear();
00066 
00067 }
00068 
00069 //--------------
00070 // Operations --
00071 //--------------
00072 
00073 void
00074 DTTracoCard::clearCache(){
00075 
00076   TRACOCache::clearCache();
00077   localClear();
00078 
00079 }
00080 
00081 void
00082 DTTracoCard::setConfig(const DTConfigManager *conf){
00083   
00084         DTChamberId sid = ChamberId();
00085         _conf_traco_map = conf->getDTConfigTracoMap(sid);       
00086         _debug = conf->getDTTPGDebug();
00087 
00088 }
00089 
00090 void
00091 DTTracoCard::localClear(){
00092   // Clear the map
00093   for(TRACO_iter p=_tracomap.begin();p!=_tracomap.end();p++){
00094     delete (*p).second;
00095   }
00096   _tracomap.clear();
00097 }
00098 
00099 void 
00100 DTTracoCard::loadTRACO() {
00101  
00102   localClear();
00103 
00104   if(debug()){
00105     std::cout << "DTTracoCard::loadTRACO called for wheel=" << wheel() ;
00106     std::cout <<                                ", station=" << station();
00107     std::cout <<                                ", sector="  << sector() << std::endl;
00108   }
00109 
00110   int maxtc = int(ceil( float(geom()->nCell(1)) / float(DTConfig::NBTITC) ));
00111 
00112   // loop on all BTI triggers
00113   std::vector<DTBtiTrigData>::const_iterator p;
00114   std::vector<DTBtiTrigData>::const_iterator pend=_bticard->end();
00115   for(p=_bticard->begin();p!=pend;p++){
00116     if(debug()){
00117       std::cout << "Found bti trigger: ";
00118       (*p).print();
00119     }
00120     // BTI number
00121     int nbti = (*p).btiNumber();
00122     int nsl  = (*p).btiSL(); 
00123     int step = (*p).step();
00124 
00125     // assign BTI to TRACO
00126     int ntc = static_cast<int>((nbti-1)/DTConfig::NBTITC)+1;
00127     if( ntc<1 || ntc>maxtc ) 
00128       continue;
00129 
00130     // position inside cor.: 
00131     int pos = nbti-(ntc-1)*DTConfig::NBTITC;
00132 
00133     // store trigger in TRACO. Create TRACO if it doesn't exist
00134     // SV tb2003 : check if traco is connected!
00135 
00136     // Load master TRACO plane
00137     if( nsl==1 ) {
00138       //FIX check traco maps !!!
00139       if( /*config()->usedTraco(ntc)==1 &&*/ ( ntc>0 && ntc<=maxtc ) )
00140         activeGetTRACO(ntc)->add_btiT( step, pos, &(*p) );
00141       else{
00142         if(debug())
00143           std::cout << "ATTENTION: traco " << ntc << " is disconnected!" << std::endl;
00144       }  
00145     } 
00146 
00147     // Load slave TRACO plane
00148     if( nsl==3 ) {
00149       // 3 TRACO's
00150       for(int tci=-1;tci<=1;tci++) {
00151         if( /*config()->usedTraco(ntc+tci)==1 &&*/ ( (ntc+tci)>0 && (ntc+tci)<=maxtc ) )
00152           activeGetTRACO(ntc+tci)->add_btiT( step, pos+8-4*tci, &(*p) );
00153         else{
00154           if(debug())
00155             std::cout << "ATTENTION: traco " << ntc+tci << " is disconnected!" << std::endl;
00156         }
00157       } 
00158     }
00159 
00160   }//end loop on bti trigs
00161 }
00162 
00163 void 
00164 DTTracoCard::runTRACO() {
00165 
00166   if(debug()){
00167     std::cout << "DTTracoCard:runTRACO called for wheel=" << wheel() ;
00168     std::cout <<                               ", station=" << station();
00169     std::cout <<                               ", sector="  << sector();
00170     std::cout << ", " << _tracomap.size() << " TRACOs with signal" << std::endl;
00171   }
00172 
00173   // run TRACO algorithm on all non-empty TRACO
00174   if(_tracomap.size()>0){
00175 
00176     if(debug()){
00177       std::cout << "====================================================" << std::endl;
00178       std::cout << "              TRACO triggers                        " << std::endl; 
00179     }
00180 
00181 
00182     TRACO_iter ptraco;
00183     for(ptraco=_tracomap.begin(); ptraco!=_tracomap.end(); ptraco++) {
00184       DTTracoChip* traco = (*ptraco).second;
00185       traco->run();
00186       for(int step=DTConfig::NSTEPF; step<=DTConfig::NSTEPL; step++){
00187         if( traco->nTrig(step)>0 ){ 
00188           _cache.push_back( traco->triggerData(step,1) );
00189           /*
00190           std::cout<<"first bti sl3: "<<geom()->localPosition(DTBtiId(wheel(),station(),sector(),3,1))<<std::endl;
00191           std::cout<<"traco pos: " << geom()->localPosition((traco->triggerData(step,1).parentId()))<<std::endl; 
00192           traco->triggerData(step,1).print();
00193           std::cout<<"pos: " << localPosition(&(traco->triggerData(step,1))) << std::endl;
00194           std::cout<<"dir: " << localDirection(&(traco->triggerData(step,1))) << std::endl;
00195           std::cout << std::endl;
00196           */
00197         }  
00198         // Store second track only if no first track at previous BX
00199           if( traco->nTrig(step)>1 && traco->useSecondTrack(step) ){
00200             _cache.push_back( traco->triggerData(step,2) );
00201           /*
00202           std::cout<<"first bti sl3: "<<geom()->localPosition(DTBtiId(wheel(),station(),sector(),3,1))<<std::endl;
00203           std::cout<<"traco pos: " << geom()->localPosition((traco->triggerData(step,2).parentId()))<<std::endl; 
00204           traco->triggerData(step,2).print();
00205           std::cout<<"pos: " << localPosition(&(traco->triggerData(step,2))) << std::endl;
00206           std::cout<<"dir: " << localDirection(&(traco->triggerData(step,2))) << std::endl;
00207           std::cout << std::endl;
00208           */
00209         }
00210       }
00211     }
00212     if(debug())
00213       std::cout << "====================================================" << std::endl;
00214   }
00215 }
00216 
00217 DTTracoChip*
00218 DTTracoCard::activeGetTRACO(int n) {
00219 
00220   // the traco identifier
00221   DTChamberId sid = geom()->statId();
00222   DTTracoId _id = DTTracoId(sid,n);
00223  
00224   DTTracoChip* traco=0;
00225   TRACO_iter ptraco = _tracomap.find(n);
00226   if( ptraco!=_tracomap.end() ) {
00227     traco=(*ptraco).second;
00228   } else {
00229     traco = new DTTracoChip(this,n,config_traco(_id));
00230     _tracomap[n]=traco;
00231   }
00232   return traco;
00233 }
00234 
00235 DTTracoChip*
00236 DTTracoCard::getTRACO(int n) const {
00237   TRACO_const_iter ptraco = _tracomap.find(n);
00238   if( ptraco==_tracomap.end() ) return 0;
00239   return (*ptraco).second;
00240 }
00241 
00242 std::vector<DTTracoChip*> 
00243 DTTracoCard::tracoList() {
00244 
00245   std::vector<DTTracoChip*> blist;
00246 
00247   if(size()<1)return blist;
00248 
00249   for(TRACO_const_iter p=_tracomap.begin();p!=_tracomap.end();p++){
00250     blist.push_back((*p).second);
00251   }
00252   return blist;
00253 
00254 }
00255 
00256 DTTracoTrig*
00257 DTTracoCard::storeTrigger(DTTracoTrigData td) {
00258   DTTracoId tracoid = td.parentId();
00259   if(!(tracoid.wheel()==wheel() &&
00260        tracoid.sector()==sector() &&
00261        tracoid.station()==station()) ) return 0;
00262   std::cout << "DTTracoChip::trigger: trigger not belonging to this card! ";
00263   std::cout << "card=(" << wheel() << "," << station() << "," << sector() << ") ";
00264   std::cout << "trig=(" << tracoid.wheel() << "," << tracoid.station() << "," 
00265        << tracoid.sector() << ")";
00266   // get the appropriate Traco
00267   DTTracoChip* traco = activeGetTRACO(tracoid.traco());
00268   // create a new trigger in the Traco
00269   DTTracoTrig* trig = new DTTracoTrig(traco,td);
00270   // add the trigger to the Traco
00271   traco->addTrig(td.step(),trig);
00272   // return the trigger
00273   return trig;
00274 }
00275 
00276 /*
00277 LocalPoint 
00278 DTTracoCard::localPosition(const DTTrigData* tr) const {
00279 std::cout<<"oldgeo";
00280 
00281   //@@ patch for Sun 4.2 compiler
00282   DTTracoTrigData* trig = dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
00283   //  const DTTracoTrigData* trig = dynamic_cast<const DTTracoTrigData*>(tr);
00284   if(!trig) {
00285     std::cout << "DTTracoCard::localPosition called with wrong argument!" << std::endl;
00286     return LocalPoint(0,0,0);
00287   }
00288   float x = geom()->localPosition(trig->parentId()).x();
00289   float y = geom()->localPosition(trig->parentId()).y();
00290   float z = geom()->localPosition(trig->parentId()).z();
00291 
00292   x += geom()->cellPitch() * ( (float)trig->X() / (float)(config()->BTIC())
00293                               - 1.5 * (float)(DTConfig::NBTITC) );
00294   // If not correlated get the position of the SL instead of the chamber center
00295   if       (trig->posIn()==0 ) {
00296     z -= 0.5 * geom()->distSL(); // no inner ==> only outer
00297   } else if(trig->posOut()==0) {
00298     z += 0.5 * geom()->distSL(); // no outer ==> only inner
00299   }
00300   return LocalPoint(x,y,z);
00301 }
00302 */
00303 
00304 LocalPoint 
00305 DTTracoCard::localPosition(const DTTrigData* tr) const {
00306   //NEWGEO
00307   DTTracoTrigData* trig = dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
00308   if(!trig) {
00309     std::cout << "DTTracoCard::localPosition called with wrong argument!" << std::endl;
00310     return LocalPoint(0,0,0);
00311   }
00312   float x = geom()->localPosition(trig->parentId()).x();
00313   float y = geom()->localPosition(trig->parentId()).y();
00314   float z = geom()->localPosition(trig->parentId()).z();
00315 
00316   float trig_pos = geom()->cellPitch() * ( (float)trig->X() / (float)(config_traco(trig->parentId())->BTIC()));
00317 
00318 //  10/7/06 May be not needed anymore in new geometry 
00319 //   if(geom()->posFE(1)==1)
00320 //   trig_pos = -trig_pos;
00321 
00322   x += trig_pos;
00323 
00324   // If not correlated get the position of the SL instead of the chamber center
00325   // z axis toward vertex
00326   if(trig->posIn()==0 ) {
00327     z -= 0.5 * geom()->distSL(); // no inner ==> only outer
00328   } 
00329   else if(trig->posOut()==0) {
00330     z += 0.5 * geom()->distSL(); // no outer ==> only inner
00331   }
00332   return LocalPoint(x,y,z);
00333 }
00334 
00335 /* OLDGEO
00336 LocalVector 
00337 DTTracoCard::localDirection(const DTTrigData* tr) const {
00338   //@@ patch for Sun 4.2 compiler
00339   DTTracoTrigData* trig = dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
00340   //  const DTTracoTrigData* trig = dynamic_cast<const DTTracoTrigData*>(tr);
00341   if(!trig) {
00342     std::cout << "DTtracoCard::localDirection called with wrong argument!" << std::endl;
00343     return LocalVector(0,0,0);
00344   }
00345   float r,x,y,z;
00346   x = -(float)trig->K() * geom()->cellPitch() /
00347                       (float)(config_traco(trig->parentId())->BTIC());
00348   y = 0;
00349   z = -geom()->distSL();
00350   r = sqrt(x*x+z*z);
00351   x /= r;
00352   z /= r;
00353   return LocalVector(x,y,z);
00354 }
00355 */
00356 
00357 LocalVector 
00358 DTTracoCard::localDirection(const DTTrigData* tr) const {
00359   //NEWGEO
00360   DTTracoTrigData* trig = dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
00361   if(!trig) {
00362     std::cout << "DTtracoCard::localDirection called with wrong argument!" << std::endl;
00363     return LocalVector(0,0,0);
00364   }
00365 
00366   //FE position
00367   //int FE = geom()->posFE(3);
00368 
00369   float psi = atan((float)(trig->K())*geom()->cellPitch()
00370                    /( geom()->distSL() * config_traco(trig->parentId())->BTIC()) );
00371 
00372   if(config_traco(trig->parentId())->debug()==4)
00373     std::cout << "K " << trig->K() << " == psi " << psi << " in FE frame " << std::endl;
00374     
00375   // (xd,yd,zd) in chamber frame
00376   float xd=-sin(psi);
00377   float yd=0;
00378   float zd=-cos(psi);
00379 
00380   // 10/07/06 Not needed anymore (chages in geometry)
00381   // if(FE==1){//FE in negative y
00382   //    xd = - xd;
00383   //}
00384 
00385  
00386   if(config_traco(trig->parentId())->debug()==4)
00387     std::cout << "Direction in chamber frame is (" << xd << "," << yd << "," << zd << ")" << std::endl;
00388  
00389   return LocalVector(xd,yd,zd);
00390 }
00391 
00392 DTConfigTraco* 
00393 DTTracoCard::config_traco(const DTTracoId& tracoid) const
00394 {
00395 
00396   // the traco identifier
00397   DTChamberId sid = geom()->statId();
00398  
00399   //loop on map to find traco
00400   ConfTracoMap::const_iterator titer = _conf_traco_map.find(tracoid);
00401   if (titer == _conf_traco_map.end()){
00402     std::cout << "DTTracoCard::config_traco : TRACO (" << tracoid.wheel()
00403               << "," << tracoid.sector()
00404               << "," << tracoid.station()
00405               << "," << tracoid.traco()
00406               << ") not found, return 0" << std::endl;
00407     return 0;
00408   }
00409 
00410   return const_cast<DTConfigTraco*>(&(*titer).second);
00411 } 
00412 

Generated on Tue Jun 9 17:40:02 2009 for CMSSW by  doxygen 1.5.4