Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:02

0001 //-------------------------------------------------
0002 //
0003 //   Class: DTTrig
0004 //
0005 //   Description: Steering routine for L1 trigger simulation in
0006 //                a muon barrel station
0007 //
0008 //
0009 //   Author List:
0010 //   C. Grandi
0011 //   Modifications:
0012 //   S Vanini, S. Marcellini, D. Bonacorsi,  C.Battilana
0013 //
0014 //   07/03/30 : configuration now through DTConfigManager SV
0015 //-------------------------------------------------------
0016 
0017 //-----------------------
0018 // This Class's Header --
0019 //-----------------------
0020 #include "L1Trigger/DTTrigger/interface/DTTrig.h"
0021 
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "FWCore/Framework/interface/ESHandle.h"
0024 #include "DataFormats/Common/interface/Handle.h"
0025 #include "FWCore/Utilities/interface/InputTag.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 
0028 #include "Geometry/DTGeometry/interface/DTLayer.h"
0029 #include "Geometry/DTGeometry/interface/DTChamber.h"
0030 
0031 //---------------
0032 // C++ Headers --
0033 //---------------
0034 #include <iostream>
0035 #include <string>
0036 
0037 //-------------------------------
0038 // Collaborating Class Headers --
0039 //-------------------------------
0040 #include "Geometry/DTGeometry/interface/DTChamber.h"
0041 
0042 //----------------
0043 // Constructors --
0044 //----------------
0045 
0046 DTTrig::DTTrig(const edm::ParameterSet& params, edm::ConsumesCollector&& iC)
0047     : _inputexist(true), _configid(0), _geomid(0) {
0048   // Set configuration parameters
0049   _debug = params.getUntrackedParameter<bool>("debug");
0050 
0051   if (_debug) {
0052     std::cout << std::endl;
0053     std::cout << "**** Initialization of DTTrigger ****" << std::endl;
0054   }
0055 
0056   _digitag = params.getParameter<edm::InputTag>("digiTag");
0057   iC.consumes<DTDigiCollection>(_digitag);
0058   dtGeomToken_ = iC.esConsumes<DTGeometry, MuonGeometryRecord>();
0059   confToken_ = iC.esConsumes<DTConfigManager, DTConfigManagerRcd>();
0060   dtGeomBeginRunToken_ = iC.esConsumes<DTGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
0061 }
0062 
0063 void DTTrig::createTUs(const edm::EventSetup& iSetup) {
0064   // build up Sector Collectors and then
0065   // build the trrigger units (one for each chamber)
0066   for (int iwh = -2; iwh <= 2; iwh++) {
0067     for (int ise = 1; ise <= 12; ise++) {
0068       if (_debug) {
0069         std::cout << "calling sectcollid wh sc " << iwh << " " << ise << std::endl;
0070       }
0071       DTSectCollId scid(iwh, ise);
0072       {
0073         SC_iterator it = _cache1.find(scid);
0074         if (it != _cache1.end()) {
0075           if (_debug) {
0076             std::cout << "DTTrig::createTUs: Sector Collector unit already exists" << std::endl;
0077           }
0078           continue;
0079         }
0080       }
0081       {
0082         auto element = _cache1.emplace(scid, scid);
0083         if (_debug) {
0084           std::cout << " DTTrig::createTUs new SC sc = " << &(element.first->second) << " at scid.sector() "
0085                     << scid.sector() << " at scid.wheel() " << scid.wheel() << std::endl;
0086         }
0087       }
0088     }
0089   }
0090 
0091   edm::ESHandle<DTGeometry> dtGeom = iSetup.getHandle(dtGeomBeginRunToken_);
0092   for (std::vector<const DTChamber*>::const_iterator ich = dtGeom->chambers().begin(); ich != dtGeom->chambers().end();
0093        ich++) {
0094     const DTChamber* chamb = (*ich);
0095     DTChamberId chid = chamb->id();
0096     TU_iterator it = _cache.find(chid);
0097     if (it != _cache.end()) {
0098       if (_debug)
0099         std::cout << "DTTrig::init: Trigger unit already exists" << std::endl;
0100       continue;
0101     }
0102 
0103     auto info = _cache.emplace(chid, chamb);
0104     auto tru = &(info.first->second);
0105 
0106     //----------- add TU to corresponding SC
0107     // returning correspondent SC id
0108     DTSectCollId scid;
0109     if (chid.sector() == 13) {
0110       scid = DTSectCollId(chid.wheel(), 4);
0111     } else if (chid.sector() == 14) {
0112       scid = DTSectCollId(chid.wheel(), 10);
0113     } else {
0114       scid = DTSectCollId(chid.wheel(), chid.sector());
0115     }
0116 
0117     SC_iterator it1 = _cache1.find(scid);
0118 
0119     if (it1 != _cache1.end()) {
0120       auto& sc = (*it1).second;
0121       if (_debug) {
0122         std::cout << "DTTrig::init:  adding TU in SC << "
0123                   << " sector = " << scid.sector() << " wheel = " << scid.wheel() << std::endl;
0124       }
0125       sc.addTU(tru);
0126     } else {
0127       std::cout << "DTTrig::createTUs: Trigger Unit not in the map: ";
0128     }
0129   }
0130 }
0131 
0132 void DTTrig::triggerReco(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0133   updateES(iSetup);
0134   if (!_inputexist)
0135     return;
0136 
0137   DTDigiMap digiMap;
0138   //Sort digis by chamber so they can be used by BTIs
0139   edm::Handle<DTDigiCollection> dtDigis;
0140   iEvent.getByLabel(_digitag, dtDigis);
0141 
0142   if (!dtDigis.isValid()) {
0143     LogDebug("DTTrig") << "DTTrig::triggerReco DTDigiCollection  with input tag " << _digitag
0144                        << "requested in configuration, but not found in the event." << std::endl;
0145     _inputexist = false;
0146     return;
0147   }
0148 
0149   DTDigiCollection::DigiRangeIterator detUnitIt;
0150 
0151   for (detUnitIt = dtDigis->begin(); detUnitIt != dtDigis->end(); ++detUnitIt) {
0152     const DTLayerId& layId = (*detUnitIt).first;
0153     const DTChamberId chambId = layId.superlayerId().chamberId();
0154     const DTDigiCollection::Range& range = (*detUnitIt).second;
0155     digiMap[chambId].put(range, layId);
0156   }
0157 
0158   //Run reconstruct for single trigger subsystem (Bti, Traco TS)
0159   for (TU_iterator it = _cache.begin(); it != _cache.end(); it++) {
0160     DTSCTrigUnit& thisTU = (*it).second;
0161     if (thisTU.BtiTrigs()->size() > 0) {
0162       thisTU.BtiTrigs()->clearCache();
0163       thisTU.TSThTrigs()->clearCache();
0164       thisTU.TracoTrigs()->clearCache();
0165       thisTU.TSPhTrigs()->clearCache();
0166     }
0167     DTChamberId chid = thisTU.statId();
0168     DTDigiMap_iterator dmit = digiMap.find(chid);
0169     if (dmit != digiMap.end()) {
0170       thisTU.BtiTrigs()->reconstruct((*dmit).second);
0171       if (thisTU.BtiTrigs()->size() > 0) {
0172         thisTU.TSThTrigs()->reconstruct();
0173         thisTU.TracoTrigs()->reconstruct();
0174         if (thisTU.TracoTrigs()->size() > 0)
0175           thisTU.TSPhTrigs()->reconstruct();
0176       }
0177     }
0178   }
0179   //Run reconstruct for Sector Collector
0180   for (SC_iterator it = _cache1.begin(); it != _cache1.end(); it++) {
0181     DTSectColl& sectcoll = (*it).second;
0182     DTSectCollId scid = (*it).first;
0183     if (sectcoll.sizePh() > 0 || sectcoll.sizeTh() > 0)
0184       sectcoll.clearCache();
0185     bool mustreco = false;
0186     for (int i = 1; i < 5; i++) {
0187       if (sectcoll.getTSPhi(i)->size() > 0) {
0188         mustreco = true;
0189         break;
0190       }
0191     }
0192     for (int i = 1; i < 4; i++) {
0193       if (sectcoll.getTSTheta(i)->size() > 0) {
0194         mustreco = true;
0195         break;
0196       }
0197     }
0198     if (scid.sector() == 4 || scid.sector() == 10) {
0199       if (sectcoll.getTSPhi(5)->size() > 0)
0200         mustreco = true;
0201     }
0202     if (mustreco)
0203       sectcoll.reconstruct();
0204   }
0205 }
0206 
0207 void DTTrig::updateES(const edm::EventSetup& iSetup) {
0208   // Check for updatets in config
0209   edm::ESHandle<DTConfigManager> confHandle;
0210   edm::ESHandle<DTGeometry> geomHandle;
0211 
0212   if (iSetup.get<DTConfigManagerRcd>().cacheIdentifier() != _configid) {
0213     if (_debug)
0214       std::cout << "DTTrig::updateES updating DTTPG configuration" << std::endl;
0215 
0216     _configid = iSetup.get<DTConfigManagerRcd>().cacheIdentifier();
0217     confHandle = iSetup.getHandle(confToken_);
0218     _conf_manager = confHandle.product();
0219     for (TU_iterator it = _cache.begin(); it != _cache.end(); it++) {
0220       (*it).second.setConfig(_conf_manager);
0221     }
0222     for (SC_iterator it = _cache1.begin(); it != _cache1.end(); it++) {
0223       (*it).second.setConfig(_conf_manager);
0224     }
0225   }
0226 
0227   if (iSetup.get<MuonGeometryRecord>().cacheIdentifier() != _configid) {
0228     if (_debug)
0229       std::cout << "DTTrig::updateES updating muon geometry" << std::endl;
0230 
0231     _geomid = iSetup.get<MuonGeometryRecord>().cacheIdentifier();
0232     geomHandle = iSetup.getHandle(dtGeomToken_);
0233     for (TU_iterator it = _cache.begin(); it != _cache.end(); it++) {
0234       (*it).second.setGeom(geomHandle->chamber((*it).second.statId()));
0235     }
0236   }
0237 }
0238 
0239 void DTTrig::clear() {
0240   // Delete the map
0241   _cache.clear();
0242   _cache1.clear();
0243 }
0244 
0245 DTSCTrigUnit* DTTrig::trigUnit(DTChamberId chid) { /*check();*/
0246   return const_cast<DTSCTrigUnit*>(constTrigUnit(chid));
0247 }
0248 
0249 DTSCTrigUnit const* DTTrig::constTrigUnit(DTChamberId chid) const {
0250   //    std::cout << " SC: running DTTrig::constTrigUnit(DTChamberId chid)" << std::endl;
0251   TU_const_iterator it = _cache.find(chid);
0252   if (it == _cache.end()) {
0253     std::cout << "DTTrig::trigUnit: Trigger Unit not in the map: ";
0254     std::cout << " wheel=" << chid.wheel();
0255     std::cout << ", station=" << chid.station();
0256     std::cout << ", sector=" << chid.sector();
0257     std::cout << std::endl;
0258     return nullptr;
0259   }
0260 
0261   return &(*it).second;
0262 }
0263 
0264 DTSectColl const* DTTrig::SCUnit(DTSectCollId scid) const {
0265   SC_const_iterator it = _cache1.find(scid);
0266   if (it == _cache1.end()) {
0267     std::cout << "DTTrig::SCUnit: Trigger Unit not in the map: ";
0268     std::cout << " wheel=" << scid.wheel();
0269     std::cout << ", sector=" << scid.sector();
0270     std::cout << std::endl;
0271     return nullptr;
0272   }
0273 
0274   return &(*it).second;
0275 }
0276 
0277 DTSCTrigUnit* DTTrig::trigUnit(int wheel, int stat, int sect) {
0278   return const_cast<DTSCTrigUnit*>(constTrigUnit(wheel, stat, sect));
0279 }
0280 
0281 DTSectColl const* DTTrig::SCUnit(int wheel, int sect) const {
0282   sect++;
0283   return SCUnit(DTSectCollId(wheel, sect));
0284 }
0285 
0286 DTSCTrigUnit const* DTTrig::constTrigUnit(int wheel, int stat, int sect) const {
0287   sect++;  // offset 1 for sector number ([0,11] --> [1,12])
0288   return constTrigUnit(DTChamberId(wheel, stat, sect));
0289 }
0290 
0291 DTChambPhSegm* DTTrig::chPhiSegm1(DTSCTrigUnit* unit, int step) {
0292   if (unit == nullptr)
0293     return nullptr;
0294   if (unit->nPhiSegm(step) < 1)
0295     return nullptr;
0296   return const_cast<DTChambPhSegm*>(unit->phiSegment(step, 1));
0297 }
0298 
0299 DTChambPhSegm* DTTrig::chPhiSegm2(DTSCTrigUnit* unit, int step) {
0300   if (unit == nullptr)
0301     return nullptr;
0302   if (unit->nPhiSegm(step) < 2)
0303     return nullptr;
0304   return const_cast<DTChambPhSegm*>(unit->phiSegment(step, 2));
0305 }
0306 
0307 DTChambThSegm* DTTrig::chThetaSegm(DTSCTrigUnit* unit, int step) {
0308   if (unit == nullptr)
0309     return nullptr;
0310   if (unit->nThetaSegm(step) < 1)
0311     return nullptr;
0312   return const_cast<DTChambThSegm*>(unit->thetaSegment(step, 1));
0313 }
0314 
0315 DTChambPhSegm* DTTrig::chPhiSegm1(DTChamberId sid, int step) { return chPhiSegm1(trigUnit(sid), step); }
0316 
0317 DTChambPhSegm* DTTrig::chPhiSegm2(DTChamberId sid, int step) { return chPhiSegm2(trigUnit(sid), step); }
0318 
0319 DTChambThSegm* DTTrig::chThetaSegm(DTChamberId sid, int step) {
0320   if (sid.station() == 4)
0321     return nullptr;
0322   return chThetaSegm(trigUnit(sid), step);
0323 }
0324 
0325 DTChambPhSegm* DTTrig::chPhiSegm1(int wheel, int stat, int sect, int step) {
0326   return chPhiSegm1(trigUnit(wheel, stat, sect), step);
0327   // to make it transparent to the outside world
0328   //  return chSectCollSegm1(wheel,stat,sect,step);
0329 }
0330 
0331 DTChambPhSegm* DTTrig::chPhiSegm2(int wheel, int stat, int sect, int step) {
0332   //  if(stat==4&&(sect==3||sect==9)) {
0333   // if hrizontal chambers of MB4 get first track of twin chamber (flag=1)
0334   //   return chPhiSegm1(trigUnit(wheel,stat,sect,1),step);
0335   //  } else {
0336   return chPhiSegm2(trigUnit(wheel, stat, sect), step);
0337   // to make it transparent to the outside world
0338   // return chSectCollSegm2(wheel,stat,sect,step);
0339   //}
0340 }
0341 
0342 DTChambThSegm* DTTrig::chThetaSegm(int wheel, int stat, int sect, int step) {
0343   if (stat == 4)
0344     return nullptr;
0345   return chThetaSegm(trigUnit(wheel, stat, sect), step);
0346 }
0347 
0348 // SM sector collector section
0349 DTSectCollPhSegm* DTTrig::chSectCollPhSegm1(DTSectColl* unit, int step) {
0350   if (unit == nullptr)
0351     return nullptr;
0352   if (unit->nSegmPh(step) < 1)
0353     return nullptr;
0354   return const_cast<DTSectCollPhSegm*>(unit->SectCollPhSegment(step, 1));
0355 }
0356 
0357 DTSectCollPhSegm* DTTrig::chSectCollPhSegm2(DTSectColl* unit, int step) {
0358   if (unit == nullptr)
0359     return nullptr;
0360   if (unit->nSegmPh(step) < 2)
0361     return nullptr;
0362   return const_cast<DTSectCollPhSegm*>(unit->SectCollPhSegment(step, 2));
0363 }
0364 
0365 DTSectCollPhSegm* DTTrig::chSectCollPhSegm1(int wheel, int sect, int step) {
0366   return chSectCollPhSegm1(const_cast<DTSectColl*>(SCUnit(wheel, sect)), step);
0367 }
0368 
0369 DTSectCollPhSegm* DTTrig::chSectCollPhSegm2(int wheel, int sect, int step) {
0370   //  if(stat==4&&(sect==3||sect==9)) {
0371   // if hrizontal chambers of MB4 get first track of twin chamber (flag=1)
0372   //return chSectCollSegm1(trigUnit(wheel,stat,sect,1),step);
0373   //} else {
0374   return chSectCollPhSegm2(const_cast<DTSectColl*>(SCUnit(wheel, sect)), step);
0375   //}
0376 }
0377 
0378 DTSectCollThSegm* DTTrig::chSectCollThSegm(DTSectColl* unit, int step) {
0379   if (unit == nullptr)
0380     return nullptr;
0381   if (unit->nSegmTh(step) < 1)
0382     return nullptr;
0383   return const_cast<DTSectCollThSegm*>(unit->SectCollThSegment(step));
0384 }
0385 
0386 DTSectCollThSegm* DTTrig::chSectCollThSegm(int wheel, int sect, int step) {
0387   return chSectCollThSegm(const_cast<DTSectColl*>(SCUnit(wheel, sect)), step);
0388 }
0389 
0390 // end SM
0391 
0392 void DTTrig::dumpGeom() const {
0393   /*check();*/
0394   for (TU_const_iterator it = _cache.begin(); it != _cache.end(); it++) {
0395     ((*it).second).dumpGeom();
0396   }
0397 }
0398 
0399 void DTTrig::dumpLuts(short int lut_btic, const DTConfigManager* conf) const {
0400   for (TU_const_iterator it = _cache.begin(); it != _cache.end(); it++) {
0401     const DTSCTrigUnit& thisTU = (*it).second;
0402 
0403     // dump lut command file from geometry
0404     thisTU.dumpLUT(lut_btic);
0405 
0406     // dump lut command file from parameters (DB or CMSSW)
0407     DTChamberId chid = thisTU.statId();
0408     conf->dumpLUTParam(chid);
0409   }
0410 
0411   return;
0412 }
0413 
0414 std::vector<DTBtiTrigData> DTTrig::BtiTrigs() const {
0415   /*check();*/
0416   std::vector<DTBtiTrigData> trigs;
0417   for (auto ptu = _cache.begin(); ptu != _cache.end(); ptu++) {
0418     const DTSCTrigUnit& tu = (*ptu).second;
0419     auto peb = tu.BtiTrigs()->end();
0420     for (auto p = tu.BtiTrigs()->begin(); p != peb; p++) {
0421       trigs.push_back(*p);
0422     }
0423   }
0424   return trigs;
0425 }
0426 
0427 std::vector<DTTracoTrigData> DTTrig::TracoTrigs() const {
0428   std::vector<DTTracoTrigData> trigs;
0429   /*check();*/
0430   for (auto ptu = _cache.begin(); ptu != _cache.end(); ptu++) {
0431     const DTSCTrigUnit& tu = (*ptu).second;
0432     auto peb = tu.TracoTrigs()->end();
0433     for (auto p = tu.TracoTrigs()->begin(); p != peb; p++) {
0434       trigs.push_back(*p);
0435     }
0436   }
0437   return trigs;
0438 }
0439 
0440 std::vector<DTChambPhSegm> DTTrig::TSPhTrigs() const {
0441   /*check();*/
0442   std::vector<DTChambPhSegm> trigs;
0443   for (auto ptu = _cache.begin(); ptu != _cache.end(); ptu++) {
0444     const DTSCTrigUnit& tu = (*ptu).second;
0445     auto peb = tu.TSPhTrigs()->end();
0446     for (auto p = tu.TSPhTrigs()->begin(); p != peb; p++) {
0447       trigs.push_back(*p);
0448     }
0449   }
0450   return trigs;
0451 }
0452 
0453 std::vector<DTChambThSegm> DTTrig::TSThTrigs() const {
0454   /*check();*/
0455   std::vector<DTChambThSegm> trigs;
0456   for (auto ptu = _cache.begin(); ptu != _cache.end(); ptu++) {
0457     const DTSCTrigUnit& tu = (*ptu).second;
0458     auto peb = tu.TSThTrigs()->end();
0459     for (auto p = tu.TSThTrigs()->begin(); p != peb; p++) {
0460       trigs.push_back(*p);
0461     }
0462   }
0463   return trigs;
0464 }
0465 
0466 std::vector<DTSectCollPhSegm> DTTrig::SCPhTrigs() const {
0467   /*check();*/
0468   std::vector<DTSectCollPhSegm> trigs;
0469   for (auto psc = _cache1.begin(); psc != _cache1.end(); psc++) {
0470     //    DTSCTrigUnit* tu = (*ptu).second;
0471     //
0472     // old SMDB:
0473     //      DTSectColl* tu = (*ptu).second;
0474     //      std::vector<DTChambPhSegm>::const_iterator p=0;
0475     //      std::vector<DTChambPhSegm>::const_iterator peb=tu->SCTrigs()->end();
0476     //      for(p=tu->SCTrigs()->begin();p!=peb;p++){
0477     //        trigs.push_back(*p);
0478     //      }
0479 
0480     const DTSectColl& sc = (*psc).second;
0481     auto peb = sc.endPh();
0482     for (auto p = sc.beginPh(); p != peb; p++) {
0483       trigs.push_back(*p);
0484     }
0485   }
0486   return trigs;
0487 }
0488 
0489 std::vector<DTSectCollThSegm> DTTrig::SCThTrigs() const {
0490   /*check();*/
0491   std::vector<DTSectCollThSegm> trigs;
0492   for (auto psc = _cache1.begin(); psc != _cache1.end(); psc++) {
0493     const DTSectColl& sc = (*psc).second;
0494     auto peb = sc.endTh();
0495     for (auto p = sc.beginTh(); p != peb; p++) {
0496       trigs.push_back(*p);
0497     }
0498   }
0499   return trigs;
0500 }