CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/L1Trigger/DTTraco/src/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 //   2/XI/09 SV : bti acceptance windows included
00018 //--------------------------------------------------
00019 
00020 //-----------------------
00021 // This Class's Header --
00022 //-----------------------
00023 #include "L1Trigger/DTTraco/interface/DTTracoCard.h"
00024 
00025 //-------------------------------
00026 // Collaborating Class Headers --
00027 //-------------------------------
00028 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00029 #include "DataFormats/GeometryVector/interface/LocalVector.h"
00030 #include "L1Trigger/DTTraco/interface/DTTracoChip.h"
00031 #include "L1Trigger/DTTraco/interface/DTTracoTrig.h"
00032 #include "L1Trigger/DTBti/interface/DTBtiCard.h"
00033 #include "L1Trigger/DTBti/interface/DTBtiTrigData.h"
00034 #include "L1Trigger/DTTriggerServerTheta/interface/DTTSTheta.h"
00035 
00036 //---------------
00037 // C++ Headers --
00038 //---------------
00039 #include <iostream>
00040 #include <cmath>
00041 #include <utility>  
00042 #include <iomanip>
00043 #include <math.h>
00044 
00045 //----------------
00046 // Constructors --
00047 //----------------
00048 
00049 DTTracoCard::DTTracoCard(DTTrigGeom* geo, DTBtiCard* bticard,
00050   DTTSTheta* tstheta) : DTGeomSupplier(geo) , 
00051   _bticard(bticard), _tstheta(tstheta) { 
00052 
00053 }
00054 
00055 //--------------
00056 // Destructor --
00057 //--------------
00058 
00059 DTTracoCard::~DTTracoCard(){
00060 
00061 localClear();
00062 
00063 }
00064 
00065 //--------------
00066 // Operations --
00067 //--------------
00068 
00069 void
00070 DTTracoCard::clearCache(){
00071 
00072   TRACOCache::clearCache();
00073   localClear();
00074 
00075 }
00076 
00077 void
00078 DTTracoCard::setConfig(const DTConfigManager *conf){
00079   // get traco configuration map  
00080   DTChamberId sid = ChamberId();
00081   _conf_traco_map = conf->getDTConfigTracoMap(sid);     
00082   _debug = conf->getDTTPGDebug();
00083 
00084   // get bti acceptance flag
00085   _flag_acc = conf->useAcceptParam();
00086 
00087   // get lut computation flag
00088   _lut_from_db = conf->lutFromDB();
00089 
00090   // get lut configuration for this chamber
00091   // 100511 SV only if luts are read from OMDS
00092   if(_lut_from_db)
00093     _conf_luts = conf->getDTConfigLUTs(sid);
00094 
00095 }
00096 
00097 void
00098 DTTracoCard::localClear(){
00099   // Clear the map
00100   for(TRACO_iter p=_tracomap.begin();p!=_tracomap.end();p++){
00101     delete (*p).second;
00102   }
00103   _tracomap.clear();
00104 }
00105 
00106 void 
00107 DTTracoCard::loadTRACO() {
00108  
00109   localClear();
00110 
00111   if(debug()){
00112     std::cout << "DTTracoCard::loadTRACO called for wheel=" << wheel() ;
00113     std::cout <<                                ", station=" << station();
00114     std::cout <<                                ", sector="  << sector() << std::endl;
00115   }
00116 
00117   int maxtc = int(ceil( float(geom()->nCell(1)) / float(DTConfig::NBTITC) ));
00118 
00119   // loop on all BTI triggers
00120   std::vector<DTBtiTrigData>::const_iterator p;
00121   std::vector<DTBtiTrigData>::const_iterator pend=_bticard->end();
00122   for(p=_bticard->begin();p!=pend;p++){
00123     if(debug()){
00124       std::cout << "Found bti trigger: ";
00125       (*p).print();
00126     }
00127 
00128     // BTI data
00129     int nbti    = (*p).btiNumber();
00130     int nsl     = (*p).btiSL(); 
00131     int step    = (*p).step();
00132     int K       = (*p).K();
00133     DTBtiId id_bti = (*p).parentId();
00134 
00135     DTConfigBti* conf_bti = _bticard->config_bti( id_bti ); 
00136     int LL      = conf_bti->LL();
00137     int LH      = conf_bti->LH();
00138     int CL      = conf_bti->CL();
00139     int CH      = conf_bti->CH();
00140     int RL      = conf_bti->RL();
00141     int RH      = conf_bti->RH();
00142 /*
00143     if(debug())
00144       std::cout << "Bti trigger acceptances: \n" 
00145                 << " LL " << LL << ", LH " << LH << "\n"
00146                 << " CL " << CL << ", CH " << CH << "\n"
00147                 << " RL " << RL << ", RH " << RH << std::endl;
00148 */
00149     // assign BTI to TRACO (central TRACO for sl=3); ntc=1,2...maxtc
00150     int ntc = static_cast<int>((nbti-1)/DTConfig::NBTITC)+1;
00151     if( ntc<1 || ntc>maxtc ) 
00152       continue;
00153     
00154     if(debug())
00155       std::cout << "Bti trigger assigned to traco " << ntc << " (maxtc " << maxtc << ")" << std::endl;
00156 
00157     // TRACO information
00158     DTTracoId tracoid = DTTracoId(wheel(),station(),sector(),ntc);
00159      
00160     // position inside TRACO: 
00161     int pos = nbti-(ntc-1)*DTConfig::NBTITC;
00162 
00163     // store trigger in TRACO. Create TRACO if it doesn't exist
00164     // SV tb2003 : check if traco is connected!
00165 
00166     // SV 091103 : add bti trigger filtering in acceptance windows
00167     // if flag is useAcceptParam() = true
00168 
00169     // Load master TRACO plane
00170     if( nsl==1 ) {
00171       if( !_flag_acc || (K>=CL && K<=CH) )
00172         activeGetTRACO(ntc)->add_btiT( step, pos, &(*p) );
00173       else
00174         if(debug())
00175           std::cout     << "ATTENTION: in TRACO n. " << ntc 
00176                         << " bti pos " << pos << " trigger K= " << K 
00177                         << " outside acceptance " << CL << "<K<" << CH << std::endl;
00178     } 
00179 
00180     // Load slave TRACO plane
00181     if( nsl==3 ) {
00182       // 3 TRACO's
00183       //for(int tci=-1;tci<=1;tci++) {
00184       //  if( (ntc+tci)>0 && (ntc+tci)<=maxtc )
00185       //    activeGetTRACO(ntc+tci)->add_btiT( step, pos+8-4*tci, &(*p) );
00186       //  else{
00187       //    if(debug())
00188       //      std::cout << "ATTENTION: traco " << ntc+tci << " is disconnected!" << std::endl;
00189       //  }
00190 
00191       // Left Traco
00192       if( (ntc-1)>0 && (ntc-1)<=maxtc ) {
00193         if( !_flag_acc || (K>=LL && K<=LH) ) {
00194           activeGetTRACO(ntc-1)->add_btiT( step, pos+8-4*(-1), &(*p) );
00195         } else {
00196           if(debug()) {
00197             std::cout   << "ATTENTION: in TRACO n. " << ntc-1
00198                         << " bti pos " << pos+8-4*(-1) << " trigger K= " << K 
00199                         << " outside acceptance " << LL << "<K<" << LH << std::endl;
00200           }
00201         }
00202       }
00203 
00204       // Central Traco
00205       if( (ntc)>0 && (ntc)<=maxtc ) {
00206         if( !_flag_acc || (K>=CL && K<=CH) ) {
00207           activeGetTRACO(ntc)->add_btiT( step, pos+8-4*(0), &(*p) );
00208         } else {
00209           if(debug())
00210             std::cout   << "ATTENTION: in TRACO n. " << ntc 
00211                         << " bti pos " << pos+8-4*(0) << " trigger K= " << K 
00212                         << " outside acceptance " << CL << "<K<" << CH << std::endl;
00213         }
00214       }
00215       
00216       // Right Traco
00217       if( (ntc+1)>0 && (ntc+1)<=maxtc ) {
00218         if( !_flag_acc || (K>=RL && K<=RH) ) {
00219           activeGetTRACO(ntc+1)->add_btiT( step, pos+8-4*(+1), &(*p) );
00220         } else {
00221           if(debug())
00222             std::cout   << "ATTENTION: in TRACO n. " << ntc+1 
00223                         << " bti pos " << pos+8-4*(+1) << " trigger K= " << K 
00224                         << " outside acceptance " << RL << "<K<" << RH << std::endl;
00225         }
00226       }
00227     }
00228 
00229     // Filter Theta BTIs -> this is done in DTBtiChip 
00230 
00231   }//end loop on bti trigs
00232 }
00233 
00234 void 
00235 DTTracoCard::runTRACO() {
00236 
00237   if(debug()){
00238     std::cout << "DTTracoCard:runTRACO called for wheel=" << wheel() ;
00239     std::cout <<                               ", station=" << station();
00240     std::cout <<                               ", sector="  << sector();
00241     std::cout << ", " << _tracomap.size() << " TRACOs with signal" << std::endl;
00242   }
00243 
00244   // run TRACO algorithm on all non-empty TRACO
00245   if(_tracomap.size()>0){
00246 
00247     if(debug()){
00248       std::cout << "====================================================" << std::endl;
00249       std::cout << "              TRACO triggers                        " << std::endl; 
00250     }
00251 
00252 
00253     TRACO_iter ptraco;
00254     for(ptraco=_tracomap.begin(); ptraco!=_tracomap.end(); ptraco++) {
00255       DTTracoChip* traco = (*ptraco).second;
00256       traco->run();
00257       for(int step=DTConfig::NSTEPF; step<=DTConfig::NSTEPL; step++){
00258         if( traco->nTrig(step)>0 ){ 
00259           _cache.push_back( traco->triggerData(step,1) );
00260           /*
00261           std::cout<<"first bti sl3: "<<geom()->localPosition(DTBtiId(wheel(),station(),sector(),3,1))<<std::endl;
00262           std::cout<<"traco pos: " << geom()->localPosition((traco->triggerData(step,1).parentId()))<<std::endl; 
00263           traco->triggerData(step,1).print();
00264           std::cout<<"pos: " << localPosition(&(traco->triggerData(step,1))) << std::endl;
00265           std::cout<<"dir: " << localDirection(&(traco->triggerData(step,1))) << std::endl;
00266           std::cout << std::endl;
00267           */
00268         }  
00269         // Store second track only if no first track at previous BX
00270           if( traco->nTrig(step)>1 && traco->useSecondTrack(step) ){
00271             _cache.push_back( traco->triggerData(step,2) );
00272           /*
00273           std::cout<<"first bti sl3: "<<geom()->localPosition(DTBtiId(wheel(),station(),sector(),3,1))<<std::endl;
00274           std::cout<<"traco pos: " << geom()->localPosition((traco->triggerData(step,2).parentId()))<<std::endl; 
00275           traco->triggerData(step,2).print();
00276           std::cout<<"pos: " << localPosition(&(traco->triggerData(step,2))) << std::endl;
00277           std::cout<<"dir: " << localDirection(&(traco->triggerData(step,2))) << std::endl;
00278           std::cout << std::endl;
00279           */
00280         }
00281       }
00282     }
00283     if(debug())
00284       std::cout << "====================================================" << std::endl;
00285   }
00286 }
00287 
00288 DTTracoChip*
00289 DTTracoCard::activeGetTRACO(int n) {
00290 
00291   // the traco identifier
00292   DTChamberId sid = geom()->statId();
00293   DTTracoId _id = DTTracoId(sid,n);
00294  
00295   DTTracoChip* traco = 0;
00296   TRACO_iter ptraco = _tracomap.find(n);
00297   if( ptraco!=_tracomap.end() ) {
00298     traco=(*ptraco).second;
00299   } else {
00300     traco = new DTTracoChip(this,n,config_traco(_id));
00301     _tracomap[n]=traco;
00302   }
00303   return traco;
00304 }
00305 
00306 DTTracoChip*
00307 DTTracoCard::getTRACO(int n) const {
00308   TRACO_const_iter ptraco = _tracomap.find(n);
00309   if( ptraco==_tracomap.end() ) return 0;
00310   return (*ptraco).second;
00311 }
00312 
00313 std::vector<DTTracoChip*> 
00314 DTTracoCard::tracoList() {
00315 
00316   std::vector<DTTracoChip*> blist;
00317 
00318   if(size()<1)return blist;
00319 
00320   for(TRACO_const_iter p=_tracomap.begin();p!=_tracomap.end();p++){
00321     blist.push_back((*p).second);
00322   }
00323   return blist;
00324 
00325 }
00326 
00327 DTTracoTrig*
00328 DTTracoCard::storeTrigger(DTTracoTrigData td) {
00329   DTTracoId tracoid = td.parentId();
00330   if(!(tracoid.wheel()==wheel() &&
00331        tracoid.sector()==sector() &&
00332        tracoid.station()==station()) ) return 0;
00333   std::cout << "DTTracoChip::trigger: trigger not belonging to this card! ";
00334   std::cout << "card=(" << wheel() << "," << station() << "," << sector() << ") ";
00335   std::cout << "trig=(" << tracoid.wheel() << "," << tracoid.station() << "," 
00336        << tracoid.sector() << ")";
00337   // get the appropriate Traco
00338   DTTracoChip* traco = activeGetTRACO(tracoid.traco());
00339   // create a new trigger in the Traco
00340   DTTracoTrig* trig = new DTTracoTrig(traco,td);
00341   // add the trigger to the Traco
00342   traco->addTrig(td.step(),trig);
00343   // return the trigger
00344   return trig;
00345 }
00346 
00347 /*
00348 LocalPoint 
00349 DTTracoCard::localPosition(const DTTrigData* tr) const {
00350 std::cout<<"oldgeo";
00351 
00352   //@@ patch for Sun 4.2 compiler
00353   DTTracoTrigData* trig = dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
00354   //  const DTTracoTrigData* trig = dynamic_cast<const DTTracoTrigData*>(tr);
00355   if(!trig) {
00356     std::cout << "DTTracoCard::localPosition called with wrong argument!" << std::endl;
00357     return LocalPoint(0,0,0);
00358   }
00359   float x = geom()->localPosition(trig->parentId()).x();
00360   float y = geom()->localPosition(trig->parentId()).y();
00361   float z = geom()->localPosition(trig->parentId()).z();
00362 
00363   x += geom()->cellPitch() * ( (float)trig->X() / (float)(config()->BTIC())
00364                               - 1.5 * (float)(DTConfig::NBTITC) );
00365   // If not correlated get the position of the SL instead of the chamber center
00366   if       (trig->posIn()==0 ) {
00367     z -= 0.5 * geom()->distSL(); // no inner ==> only outer
00368   } else if(trig->posOut()==0) {
00369     z += 0.5 * geom()->distSL(); // no outer ==> only inner
00370   }
00371   return LocalPoint(x,y,z);
00372 }
00373 */
00374 
00375 LocalPoint 
00376 DTTracoCard::localPosition(const DTTrigData* tr) const {
00377   //NEWGEO
00378   DTTracoTrigData* trig = dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
00379   if(!trig) {
00380     std::cout << "DTTracoCard::localPosition called with wrong argument!" << std::endl;
00381     return LocalPoint(0,0,0);
00382   }
00383   float x = geom()->localPosition(trig->parentId()).x();
00384   float y = geom()->localPosition(trig->parentId()).y();
00385   float z = geom()->localPosition(trig->parentId()).z();
00386 
00387   float trig_pos = geom()->cellPitch() * ( (float)trig->X() / (float)(config_traco(trig->parentId())->BTIC()));
00388 
00389 //  10/7/06 May be not needed anymore in new geometry 
00390 //   if(geom()->posFE(1)==1)
00391 //   trig_pos = -trig_pos;
00392 
00393   x += trig_pos;
00394 
00395   // If not correlated get the position of the SL instead of the chamber center
00396   // z axis toward vertex
00397   if(trig->posIn()==0 ) {
00398     z -= 0.5 * geom()->distSL(); // no inner ==> only outer
00399   } 
00400   else if(trig->posOut()==0) {
00401     z += 0.5 * geom()->distSL(); // no outer ==> only inner
00402   }
00403   return LocalPoint(x,y,z);
00404 }
00405 
00406 /* OLDGEO
00407 LocalVector 
00408 DTTracoCard::localDirection(const DTTrigData* tr) const {
00409   //@@ patch for Sun 4.2 compiler
00410   DTTracoTrigData* trig = dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
00411   //  const DTTracoTrigData* trig = dynamic_cast<const DTTracoTrigData*>(tr);
00412   if(!trig) {
00413     std::cout << "DTtracoCard::localDirection called with wrong argument!" << std::endl;
00414     return LocalVector(0,0,0);
00415   }
00416   float r,x,y,z;
00417   x = -(float)trig->K() * geom()->cellPitch() /
00418                       (float)(config_traco(trig->parentId())->BTIC());
00419   y = 0;
00420   z = -geom()->distSL();
00421   r = sqrt(x*x+z*z);
00422   x /= r;
00423   z /= r;
00424   return LocalVector(x,y,z);
00425 }
00426 */
00427 
00428 LocalVector 
00429 DTTracoCard::localDirection(const DTTrigData* tr) const {
00430   //NEWGEO
00431   DTTracoTrigData* trig = dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
00432   if(!trig) {
00433     std::cout << "DTtracoCard::localDirection called with wrong argument!" << std::endl;
00434     return LocalVector(0,0,0);
00435   }
00436 
00437   //FE position
00438   //int FE = geom()->posFE(3);
00439 
00440   float psi = atan((float)(trig->K())*geom()->cellPitch()
00441                    /( geom()->distSL() * config_traco(trig->parentId())->BTIC()) );
00442 
00443   if(config_traco(trig->parentId())->debug()==4)
00444     std::cout << "K " << trig->K() << " == psi " << psi << " in FE frame " << std::endl;
00445     
00446   // (xd,yd,zd) in chamber frame
00447   float xd=-sin(psi);
00448   float yd=0;
00449   float zd=-cos(psi);
00450 
00451   // 10/07/06 Not needed anymore (chages in geometry)
00452   // if(FE==1){//FE in negative y
00453   //    xd = - xd;
00454   //}
00455 
00456  
00457   if(config_traco(trig->parentId())->debug()==4)
00458     std::cout << "Direction in chamber frame is (" << xd << "," << yd << "," << zd << ")" << std::endl;
00459  
00460   return LocalVector(xd,yd,zd);
00461 }
00462 
00463 DTConfigTraco* 
00464 DTTracoCard::config_traco(const DTTracoId& tracoid) const
00465 {
00466   //loop on map to find traco
00467   ConfTracoMap::const_iterator titer = _conf_traco_map.find(tracoid);
00468   if (titer == _conf_traco_map.end()){
00469     std::cout << "DTTracoCard::config_traco : TRACO (" << tracoid.wheel()
00470               << "," << tracoid.sector()
00471               << "," << tracoid.station()
00472               << "," << tracoid.traco()
00473               << ") not found, return 0" << std::endl;
00474     return 0;
00475   }
00476 
00477   return const_cast<DTConfigTraco*>(&(*titer).second);
00478 } 
00479