CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/L1Trigger/DTTrigger/src/DTTrig.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: DTTrig
00004 //
00005 //   Description: Steering routine for L1 trigger simulation in
00006 //                a muon barrel station
00007 //
00008 //
00009 //   Author List:
00010 //   C. Grandi
00011 //   Modifications: 
00012 //   S Vanini, S. Marcellini, D. Bonacorsi,  C.Battilana
00013 //
00014 //   07/03/30 : configuration now through DTConfigManager SV
00015 //-------------------------------------------------------
00016 
00017 //-----------------------
00018 // This Class's Header --
00019 //-----------------------
00020 #include "L1Trigger/DTTrigger/interface/DTTrig.h"
00021 
00022 #include "FWCore/Framework/interface/Event.h"
00023 #include "FWCore/Framework/interface/ESHandle.h"
00024 #include "DataFormats/Common/interface/Handle.h"
00025 #include "FWCore/Utilities/interface/InputTag.h"
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027 
00028 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00029 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00030 #include "Geometry/DTGeometry/interface/DTLayer.h"
00031 #include "Geometry/DTGeometry/interface/DTChamber.h"
00032 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigManager.h"
00033 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigManagerRcd.h"
00034 
00035 //---------------
00036 // C++ Headers --
00037 //---------------
00038 #include <iostream>
00039 #include <string>
00040 
00041 //-------------------------------
00042 // Collaborating Class Headers --
00043 //-------------------------------
00044 #include "Geometry/DTGeometry/interface/DTChamber.h"
00045 
00046 //----------------
00047 // Constructors --
00048 //----------------
00049 
00050 DTTrig::DTTrig(const  edm::ParameterSet &params) :
00051  _inputexist(1) ,  _configid(0) , _geomid(0) {
00052 
00053   // Set configuration parameters
00054   _debug = params.getUntrackedParameter<bool>("debug");
00055 
00056   if(_debug){
00057     std::cout << std::endl;
00058     std::cout << "**** Initialization of DTTrigger ****" << std::endl;
00059   }
00060 
00061   _digitag   = params.getParameter<edm::InputTag>("digiTag");
00062 
00063 }
00064 
00065 
00066 //--------------
00067 // Destructor --
00068 //--------------
00069 DTTrig::~DTTrig(){
00070 
00071   clear();
00072 
00073 }
00074 
00075 void 
00076 DTTrig::createTUs(const edm::EventSetup& iSetup ){
00077   
00078   // build up Sector Collectors and then
00079   // build the trrigger units (one for each chamber)
00080   for(int iwh=-2;iwh<=2;iwh++){ 
00081     for(int ise=1;ise<=12;ise++){ 
00082       if(_debug){
00083         std::cout << "calling sectcollid wh sc " << iwh <<  " " << ise << std::endl;}
00084       DTSectCollId scid(iwh,ise);
00085       SC_iterator it =  _cache1.find(scid);
00086       if ( it != _cache1.end()) {
00087         std::cout << "DTTrig::createTUs: Sector Collector unit already exists"<<std::endl;
00088         continue;
00089       }    
00090       DTSectColl* sc;
00091       sc = new DTSectColl(scid);
00092       if(_debug){
00093         std::cout << " DTTrig::createTUs new SC sc = " << sc  
00094                   << " at scid.sector() " << scid.sector() 
00095                   << " at scid.wheel() " << scid.wheel()   
00096                   << std::endl;
00097       }
00098       _cache1[scid] = sc;  
00099     }
00100   }
00101   
00102   edm::ESHandle<DTGeometry>dtGeom;
00103   iSetup.get<MuonGeometryRecord>().get(dtGeom);
00104   for (std::vector<DTChamber*>::const_iterator ich=dtGeom->chambers().begin(); ich!=dtGeom->chambers().end();ich++){
00105        
00106     DTChamber* chamb = (*ich);
00107     DTChamberId chid = chamb->id();
00108     TU_iterator it = _cache.find(chid);
00109     if ( it != _cache.end()) {
00110       std::cout << "DTTrig::init: Trigger unit already exists" << std::endl;
00111       continue;
00112     }
00113 
00114     DTSCTrigUnit* tru = new DTSCTrigUnit(chamb);
00115     _cache[chid] = tru;
00116     
00117     //----------- add TU to corresponding SC
00118     // returning correspondent SC id
00119     DTSectCollId scid;
00120     if(chid.sector()==13) { 
00121       scid = DTSectCollId(chid.wheel(), 4);}
00122     else if(chid.sector()==14)  {
00123       scid = DTSectCollId(chid.wheel(), 10);}
00124     else  { 
00125       scid = DTSectCollId(chid.wheel(), chid.sector() );}
00126     
00127     SC_iterator it1 =  _cache1.find(scid);
00128     
00129     if ( it1 != _cache1.end()) {
00130       
00131       DTSectColl* sc = (*it1).second;
00132       if(_debug) {
00133         std::cout << "DTTrig::init:  adding TU in SC << " 
00134                   << " sector = " << scid.sector() 
00135                   << " wheel = " << scid.wheel() 
00136                   << std::endl;
00137       }
00138       sc->addTU(tru);    
00139     }
00140     else {
00141       std::cout << "DTTrig::createTUs: Trigger Unit not in the map: ";
00142     }
00143     
00144   }
00145 
00146 }
00147 
00148 
00149 void 
00150 DTTrig::triggerReco(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00151  
00152   updateES(iSetup);
00153   if (!_inputexist) return;
00154 
00155   DTDigiMap digiMap;
00156   //Sort digis by chamber so they can be used by BTIs
00157   edm::Handle<DTDigiCollection> dtDigis;
00158   iEvent.getByLabel(_digitag, dtDigis);
00159 
00160   if (!dtDigis.isValid()) {
00161     LogDebug("DTTrig")
00162       << "DTTrig::triggerReco DTDigiCollection  with input tag " << _digitag
00163       << "requested in configuration, but not found in the event." << std::endl;
00164     _inputexist = false;
00165     return;
00166   }
00167    
00168   DTDigiCollection::DigiRangeIterator detUnitIt;
00169   
00170   for (detUnitIt=dtDigis->begin();
00171        detUnitIt!=dtDigis->end();
00172        ++detUnitIt){
00173 
00174     const DTLayerId& layId = (*detUnitIt).first;
00175     const DTChamberId chambId=layId.superlayerId().chamberId();
00176     const DTDigiCollection::Range& range = (*detUnitIt).second; 
00177     digiMap[chambId].put(range,layId); 
00178 
00179   }
00180   
00181   //Run reconstruct for single trigger subsystem (Bti, Traco TS)
00182   for (TU_iterator it=_cache.begin();it!=_cache.end();it++){
00183     DTSCTrigUnit* thisTU=(*it).second;
00184     if (thisTU->BtiTrigs()->size()>0){
00185       thisTU->BtiTrigs()->clearCache();
00186       thisTU->TSThTrigs()->clearCache();
00187       thisTU->TracoTrigs()->clearCache();
00188       thisTU->TSPhTrigs()->clearCache();
00189     }
00190     DTChamberId chid=thisTU->statId();
00191     DTDigiMap_iterator dmit = digiMap.find(chid);
00192     if (dmit !=digiMap.end()){
00193       thisTU->BtiTrigs()->reconstruct((*dmit).second); 
00194       if(thisTU->BtiTrigs()->size()>0){
00195         thisTU->TSThTrigs()->reconstruct();
00196         thisTU->TracoTrigs()->reconstruct();
00197         if(thisTU->TracoTrigs()->size()>0)
00198           thisTU->TSPhTrigs()->reconstruct();
00199       }
00200     }
00201   }
00202   //Run reconstruct for Sector Collector
00203   for (SC_iterator it=_cache1.begin();it!=_cache1.end();it++){
00204     DTSectColl* sectcoll = (*it).second;
00205     DTSectCollId scid = (*it).first;
00206     if (sectcoll->sizePh()>0 || sectcoll->sizeTh()>0)
00207       sectcoll->clearCache();
00208     bool mustreco = false;
00209     for (int i=1;i<5;i++) {
00210       if (sectcoll->getTSPhi(i)->size()>0) {
00211         mustreco = true;
00212         break;
00213       }
00214     }
00215     for (int i=1;i<4;i++) {
00216       if (sectcoll->getTSTheta(i)->size()>0) {
00217         mustreco = true;
00218         break;
00219       }
00220     }
00221     if (scid.sector()==4 || scid.sector()==10){
00222       if (sectcoll->getTSPhi(5)->size()>0)
00223         mustreco = true;
00224     }
00225     if (mustreco)
00226       sectcoll->reconstruct();
00227   }
00228 
00229 }
00230 
00231 void
00232 DTTrig::updateES(const edm::EventSetup& iSetup){
00233 
00234   // Check for updatets in config
00235   edm::ESHandle<DTConfigManager> confHandle;
00236   edm::ESHandle<DTGeometry> geomHandle;
00237 
00238   if (iSetup.get<DTConfigManagerRcd>().cacheIdentifier()!=_configid) {
00239     
00240     if (_debug)
00241       std::cout << "DTTrig::updateES updating DTTPG configuration" << std::endl;
00242     
00243     _configid = iSetup.get<DTConfigManagerRcd>().cacheIdentifier();
00244     iSetup.get<DTConfigManagerRcd>().get(confHandle);
00245     _conf_manager = confHandle.product();
00246     for (TU_iterator it=_cache.begin();it!=_cache.end();it++){
00247       (*it).second->setConfig(_conf_manager);
00248     }
00249     for (SC_iterator it=_cache1.begin();it!=_cache1.end();it++){
00250       (*it).second->setConfig(_conf_manager);
00251     }
00252 
00253   }
00254 
00255   if (iSetup.get<MuonGeometryRecord>().cacheIdentifier()!=_configid) {
00256 
00257     if (_debug)
00258       std::cout << "DTTrig::updateES updating muon geometry" << std::endl;
00259 
00260     _geomid = iSetup.get<MuonGeometryRecord>().cacheIdentifier();
00261     iSetup.get<MuonGeometryRecord>().get(geomHandle);
00262     for (TU_iterator it=_cache.begin();it!=_cache.end();it++){
00263       (*it).second->setGeom(geomHandle->chamber((*it).second->statId()));
00264     }
00265 
00266   }
00267 
00268 } 
00269 
00270 
00271 void
00272 DTTrig::clear() {
00273   // Delete the map
00274   for (TU_iterator it=_cache.begin();it!=_cache.end();it++){
00275     // Delete all the trigger units 
00276     delete (*it).second;
00277   }
00278   _cache.clear(); 
00279 
00280   for (SC_iterator it=_cache1.begin();it!=_cache1.end();it++){
00281     // Delete all the Sector Collectors
00282     delete (*it).second;
00283   }
00284   _cache1.clear();
00285 
00286 }
00287 
00288 DTSCTrigUnit*
00289 DTTrig::trigUnit(DTChamberId chid) {
00290   /*check();*/  return constTrigUnit(chid);
00291 
00292 }
00293 
00294 
00295 
00296 DTSCTrigUnit*
00297 DTTrig::constTrigUnit(DTChamberId chid) const {
00298 //    std::cout << " SC: running DTTrig::constTrigUnit(DTChamberId chid)" << std::endl;
00299   TU_const_iterator it = _cache.find(chid);
00300   if ( it == _cache.end()) {
00301     std::cout << "DTTrig::trigUnit: Trigger Unit not in the map: ";
00302     std::cout << " wheel=" << chid.wheel() ;
00303     std::cout << ", station=" << chid.station();
00304     std::cout << ", sector=" << chid.sector();
00305     std::cout << std::endl;
00306     return 0;
00307   }
00308 
00309   return (*it).second;
00310 }
00311 
00312 DTSectColl*
00313 DTTrig::SCUnit(DTSectCollId scid) const {
00314 SC_const_iterator it = _cache1.find(scid);
00315   if ( it == _cache1.end()) {
00316     std::cout << "DTTrig::SCUnit: Trigger Unit not in the map: ";
00317     std::cout << " wheel=" << scid.wheel() ;
00318     std::cout << ", sector=" << scid.sector();
00319     std::cout << std::endl;
00320     return 0;
00321   }
00322 
00323   return (*it).second;
00324 }
00325 
00326 DTSCTrigUnit*
00327 DTTrig::trigUnit(int wheel, int stat, int sect) {
00328   return constTrigUnit(wheel, stat, sect);
00329 }
00330 
00331 DTSectColl*
00332 DTTrig::SCUnit(int wheel, int sect) const {
00333   sect++;
00334   return SCUnit(DTSectCollId(wheel,sect));
00335 }
00336 
00337 
00338 DTSCTrigUnit*
00339 DTTrig::constTrigUnit(int wheel, int stat, int sect) const {
00340   sect++;   // offset 1 for sector number ([0,11] --> [1,12])
00341   return constTrigUnit(DTChamberId(wheel,stat,sect));
00342 
00343 }
00344 
00345 
00346 DTChambPhSegm* 
00347 DTTrig::chPhiSegm1(DTSCTrigUnit* unit, int step) {
00348   if(unit==0)return 0;
00349   if(unit->nPhiSegm(step)<1)return 0;
00350   return const_cast<DTChambPhSegm*>(unit->phiSegment(step,1));
00351 }
00352 
00353 DTChambPhSegm* 
00354 DTTrig::chPhiSegm2(DTSCTrigUnit* unit, int step) {
00355   if(unit==0)return 0;
00356   if(unit->nPhiSegm(step)<2)return 0;
00357   return const_cast<DTChambPhSegm*>(unit->phiSegment(step,2));
00358 }
00359 
00360 DTChambThSegm* 
00361 DTTrig::chThetaSegm(DTSCTrigUnit* unit, int step) {
00362   if(unit==0)return 0;
00363   if(unit->nThetaSegm(step)<1)return 0;
00364   return const_cast<DTChambThSegm*>(unit->thetaSegment(step,1));
00365 }
00366 
00367 DTChambPhSegm* 
00368 DTTrig::chPhiSegm1(DTChamberId sid, int step) {
00369   return chPhiSegm1(trigUnit(sid),step);
00370 }
00371 
00372 DTChambPhSegm* 
00373 DTTrig::chPhiSegm2(DTChamberId sid, int step) {
00374   return chPhiSegm2(trigUnit(sid),step);
00375 }
00376 
00377 DTChambThSegm* 
00378 DTTrig::chThetaSegm(DTChamberId sid, int step) {
00379   if(sid.station()==4)return 0;
00380   return chThetaSegm(trigUnit(sid),step);
00381 }
00382 
00383 DTChambPhSegm*
00384 DTTrig::chPhiSegm1(int wheel, int stat, int sect, int step) {
00385    return chPhiSegm1(trigUnit(wheel,stat,sect),step);
00386   // to make it transparent to the outside world
00387   //  return chSectCollSegm1(wheel,stat,sect,step);
00388 
00389 }
00390 
00391 DTChambPhSegm* 
00392 DTTrig::chPhiSegm2(int wheel, int stat, int sect, int step) {
00393   //  if(stat==4&&(sect==3||sect==9)) {
00394   // if hrizontal chambers of MB4 get first track of twin chamber (flag=1)
00395   //   return chPhiSegm1(trigUnit(wheel,stat,sect,1),step);
00396   //  } else {
00397     return chPhiSegm2(trigUnit(wheel,stat,sect),step);
00398   // to make it transparent to the outside world
00399   // return chSectCollSegm2(wheel,stat,sect,step);
00400   //}
00401 }
00402 
00403 DTChambThSegm* 
00404 DTTrig::chThetaSegm(int wheel, int stat, int sect, int step) {
00405   if(stat==4)return 0;
00406   return chThetaSegm(trigUnit(wheel,stat,sect),step);
00407 }
00408 
00409 // SM sector collector section
00410 DTSectCollPhSegm* 
00411 DTTrig::chSectCollPhSegm1(DTSectColl* unit, int step) {
00412 
00413   if(unit==0)return 0;
00414    if(unit->nSegmPh(step)<1)return 0;
00415    return const_cast<DTSectCollPhSegm*>(unit->SectCollPhSegment(step,1));
00416 }
00417 
00418 DTSectCollPhSegm* 
00419 DTTrig::chSectCollPhSegm2(DTSectColl* unit, int step) {
00420   if(unit==0)return 0;
00421     if(unit->nSegmPh(step)<2)return 0;
00422   return const_cast<DTSectCollPhSegm*>(unit->SectCollPhSegment(step,2));
00423 }
00424 
00425 
00426 DTSectCollPhSegm*
00427 DTTrig::chSectCollPhSegm1(int wheel, int sect, int step) {
00428 
00429   return chSectCollPhSegm1(SCUnit(wheel,sect),step);
00430 }
00431 
00432 DTSectCollPhSegm* 
00433 DTTrig::chSectCollPhSegm2(int wheel, int sect, int step) {
00434   //  if(stat==4&&(sect==3||sect==9)) {
00435     // if hrizontal chambers of MB4 get first track of twin chamber (flag=1)
00436   //return chSectCollSegm1(trigUnit(wheel,stat,sect,1),step);
00437   //} else {
00438     return chSectCollPhSegm2(SCUnit(wheel,sect),step);
00439     //}
00440 }
00441 
00442 DTSectCollThSegm* 
00443 DTTrig::chSectCollThSegm(DTSectColl* unit, int step) {
00444 
00445   if(unit==0)return 0;
00446    if(unit->nSegmTh(step)<1)return 0;
00447   return const_cast<DTSectCollThSegm*>(unit->SectCollThSegment(step));
00448 }
00449 
00450 DTSectCollThSegm*
00451 DTTrig::chSectCollThSegm(int wheel, int sect, int step) {
00452 
00453   return chSectCollThSegm(SCUnit(wheel,sect),step);
00454 }
00455 
00456   // end SM
00457 
00458 
00459 void 
00460 DTTrig::dumpGeom() {
00461   /*check();*/
00462   for (TU_const_iterator it=_cache.begin();it!=_cache.end();it++){
00463     ((*it).second)->dumpGeom();
00464   }
00465 }
00466 
00467 void 
00468 DTTrig::dumpLuts(short int lut_btic, const DTConfigManager *conf) {
00469   for (TU_const_iterator it=_cache.begin();it!=_cache.end();it++){
00470 
00471     DTSCTrigUnit* thisTU = (*it).second;
00472 
00473     // dump lut command file from geometry
00474     thisTU->dumpLUT(lut_btic);
00475 
00476     // dump lut command file from parameters (DB or CMSSW)
00477     DTChamberId chid = thisTU->statId();
00478     conf->dumpLUTParam(chid);
00479 
00480   }
00481  
00482   return;
00483 
00484 }
00485 
00486 std::vector<DTBtiTrigData> 
00487 DTTrig::BtiTrigs() {
00488   /*check();*/
00489   std::vector<DTBtiTrigData> trigs;
00490   TU_iterator ptu;
00491   for(ptu=_cache.begin();ptu!=_cache.end();ptu++) {
00492     DTSCTrigUnit* tu = (*ptu).second;
00493     std::vector<DTBtiTrigData>::const_iterator p; //p=0;
00494     std::vector<DTBtiTrigData>::const_iterator peb=tu->BtiTrigs()->end();
00495     for(p=tu->BtiTrigs()->begin();p!=peb;p++){
00496       trigs.push_back(*p);
00497     }
00498   }
00499   return trigs;
00500 }
00501 
00502 std::vector<DTTracoTrigData> 
00503 DTTrig::TracoTrigs()  {
00504   std::vector<DTTracoTrigData> trigs;
00505   TU_iterator ptu;
00506   /*check();*/
00507   for(ptu=_cache.begin();ptu!=_cache.end();ptu++) {
00508     DTSCTrigUnit* tu = (*ptu).second;
00509     std::vector<DTTracoTrigData>::const_iterator p; //p=0;
00510     std::vector<DTTracoTrigData>::const_iterator peb=tu->TracoTrigs()->end();
00511     for(p=tu->TracoTrigs()->begin();p!=peb;p++){
00512       trigs.push_back(*p);
00513     }
00514   }
00515   return trigs;
00516 }
00517 
00518 std::vector<DTChambPhSegm> 
00519 DTTrig::TSPhTrigs()  {
00520   /*check();*/
00521   std::vector<DTChambPhSegm> trigs;
00522   TU_iterator ptu;
00523   for(ptu=_cache.begin();ptu!=_cache.end();ptu++) {
00524     DTSCTrigUnit* tu = (*ptu).second;
00525     std::vector<DTChambPhSegm>::const_iterator p; //p=0;
00526     std::vector<DTChambPhSegm>::const_iterator peb=tu->TSPhTrigs()->end();
00527     for(p=tu->TSPhTrigs()->begin();p!=peb;p++){
00528       trigs.push_back(*p);
00529     }
00530   }
00531   return trigs;
00532 }
00533 
00534 std::vector<DTChambThSegm> 
00535 DTTrig::TSThTrigs()  {
00536   /*check();*/
00537   std::vector<DTChambThSegm> trigs;
00538   TU_iterator ptu;
00539   for(ptu=_cache.begin();ptu!=_cache.end();ptu++) {
00540     DTSCTrigUnit* tu = (*ptu).second;
00541     std::vector<DTChambThSegm>::const_iterator p; //p=0;
00542     std::vector<DTChambThSegm>::const_iterator peb=tu->TSThTrigs()->end();
00543     for(p=tu->TSThTrigs()->begin();p!=peb;p++){
00544       trigs.push_back(*p);
00545     }
00546   }
00547   return trigs;
00548 }
00549 
00550 std::vector<DTSectCollPhSegm> 
00551 DTTrig::SCPhTrigs()  {
00552   /*check();*/
00553   std::vector<DTSectCollPhSegm> trigs;
00554   //  SC_iterator ptu;
00555   SC_iterator psc;
00556   for(psc=_cache1.begin();psc!=_cache1.end();psc++) {
00557     //    DTSCTrigUnit* tu = (*ptu).second;
00558     //
00559     // old SMDB:    
00560     //      DTSectColl* tu = (*ptu).second;
00561     //      std::vector<DTChambPhSegm>::const_iterator p=0;
00562     //      std::vector<DTChambPhSegm>::const_iterator peb=tu->SCTrigs()->end();
00563     //      for(p=tu->SCTrigs()->begin();p!=peb;p++){
00564     //        trigs.push_back(*p);
00565     //      } 
00566 
00567     DTSectColl* sc = (*psc).second;
00568     std::vector<DTSectCollPhSegm>::const_iterator p;
00569     std::vector<DTSectCollPhSegm>::const_iterator peb=sc->endPh();
00570     for(p=sc->beginPh();p!=peb;p++){
00571       trigs.push_back(*p);
00572     }
00573 
00574   }
00575   return trigs;
00576 }
00577 
00578 
00579 std::vector<DTSectCollThSegm> 
00580 DTTrig::SCThTrigs()  {
00581   /*check();*/
00582   std::vector<DTSectCollThSegm> trigs;
00583   SC_iterator psc;
00584   for(psc=_cache1.begin();psc!=_cache1.end();psc++) {
00585     DTSectColl* sc = (*psc).second;
00586     std::vector<DTSectCollThSegm>::const_iterator p; //p=0;
00587     std::vector<DTSectCollThSegm>::const_iterator peb=sc->endTh();
00588     for(p=sc->beginTh();p!=peb;p++){
00589       trigs.push_back(*p);
00590     }
00591 
00592   }
00593   return trigs;
00594 }