File indexing completed on 2024-09-07 04:36:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
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
0033
0034 #include <iostream>
0035 #include <string>
0036
0037
0038
0039
0040 #include "Geometry/DTGeometry/interface/DTChamber.h"
0041
0042
0043
0044
0045
0046 DTTrig::DTTrig(const edm::ParameterSet& params, edm::ConsumesCollector&& iC)
0047 : _inputexist(true), _configid(0), _geomid(0) {
0048
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
0065
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
0107
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
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
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
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
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
0241 _cache.clear();
0242 _cache1.clear();
0243 }
0244
0245 DTSCTrigUnit* DTTrig::trigUnit(DTChamberId chid) { return const_cast<DTSCTrigUnit*>(constTrigUnit(chid)); }
0246
0247 DTSCTrigUnit const* DTTrig::constTrigUnit(DTChamberId chid) const {
0248
0249 TU_const_iterator it = _cache.find(chid);
0250 if (it == _cache.end()) {
0251 std::cout << "DTTrig::trigUnit: Trigger Unit not in the map: ";
0252 std::cout << " wheel=" << chid.wheel();
0253 std::cout << ", station=" << chid.station();
0254 std::cout << ", sector=" << chid.sector();
0255 std::cout << std::endl;
0256 return nullptr;
0257 }
0258
0259 return &(*it).second;
0260 }
0261
0262 DTSectColl const* DTTrig::SCUnit(DTSectCollId scid) const {
0263 SC_const_iterator it = _cache1.find(scid);
0264 if (it == _cache1.end()) {
0265 std::cout << "DTTrig::SCUnit: Trigger Unit not in the map: ";
0266 std::cout << " wheel=" << scid.wheel();
0267 std::cout << ", sector=" << scid.sector();
0268 std::cout << std::endl;
0269 return nullptr;
0270 }
0271
0272 return &(*it).second;
0273 }
0274
0275 DTSCTrigUnit* DTTrig::trigUnit(int wheel, int stat, int sect) {
0276 return const_cast<DTSCTrigUnit*>(constTrigUnit(wheel, stat, sect));
0277 }
0278
0279 DTSectColl const* DTTrig::SCUnit(int wheel, int sect) const {
0280 sect++;
0281 return SCUnit(DTSectCollId(wheel, sect));
0282 }
0283
0284 DTSCTrigUnit const* DTTrig::constTrigUnit(int wheel, int stat, int sect) const {
0285 sect++;
0286 return constTrigUnit(DTChamberId(wheel, stat, sect));
0287 }
0288
0289 DTChambPhSegm* DTTrig::chPhiSegm1(DTSCTrigUnit* unit, int step) {
0290 if (unit == nullptr)
0291 return nullptr;
0292 if (unit->nPhiSegm(step) < 1)
0293 return nullptr;
0294 return const_cast<DTChambPhSegm*>(unit->phiSegment(step, 1));
0295 }
0296
0297 DTChambPhSegm* DTTrig::chPhiSegm2(DTSCTrigUnit* unit, int step) {
0298 if (unit == nullptr)
0299 return nullptr;
0300 if (unit->nPhiSegm(step) < 2)
0301 return nullptr;
0302 return const_cast<DTChambPhSegm*>(unit->phiSegment(step, 2));
0303 }
0304
0305 DTChambThSegm* DTTrig::chThetaSegm(DTSCTrigUnit* unit, int step) {
0306 if (unit == nullptr)
0307 return nullptr;
0308 if (unit->nThetaSegm(step) < 1)
0309 return nullptr;
0310 return const_cast<DTChambThSegm*>(unit->thetaSegment(step, 1));
0311 }
0312
0313 DTChambPhSegm* DTTrig::chPhiSegm1(DTChamberId sid, int step) { return chPhiSegm1(trigUnit(sid), step); }
0314
0315 DTChambPhSegm* DTTrig::chPhiSegm2(DTChamberId sid, int step) { return chPhiSegm2(trigUnit(sid), step); }
0316
0317 DTChambThSegm* DTTrig::chThetaSegm(DTChamberId sid, int step) {
0318 if (sid.station() == 4)
0319 return nullptr;
0320 return chThetaSegm(trigUnit(sid), step);
0321 }
0322
0323 DTChambPhSegm* DTTrig::chPhiSegm1(int wheel, int stat, int sect, int step) {
0324 return chPhiSegm1(trigUnit(wheel, stat, sect), step);
0325
0326
0327 }
0328
0329 DTChambPhSegm* DTTrig::chPhiSegm2(int wheel, int stat, int sect, int step) {
0330
0331
0332
0333
0334 return chPhiSegm2(trigUnit(wheel, stat, sect), step);
0335
0336
0337
0338 }
0339
0340 DTChambThSegm* DTTrig::chThetaSegm(int wheel, int stat, int sect, int step) {
0341 if (stat == 4)
0342 return nullptr;
0343 return chThetaSegm(trigUnit(wheel, stat, sect), step);
0344 }
0345
0346
0347 DTSectCollPhSegm* DTTrig::chSectCollPhSegm1(DTSectColl* unit, int step) {
0348 if (unit == nullptr)
0349 return nullptr;
0350 if (unit->nSegmPh(step) < 1)
0351 return nullptr;
0352 return const_cast<DTSectCollPhSegm*>(unit->SectCollPhSegment(step, 1));
0353 }
0354
0355 DTSectCollPhSegm* DTTrig::chSectCollPhSegm2(DTSectColl* unit, int step) {
0356 if (unit == nullptr)
0357 return nullptr;
0358 if (unit->nSegmPh(step) < 2)
0359 return nullptr;
0360 return const_cast<DTSectCollPhSegm*>(unit->SectCollPhSegment(step, 2));
0361 }
0362
0363 DTSectCollPhSegm* DTTrig::chSectCollPhSegm1(int wheel, int sect, int step) {
0364 return chSectCollPhSegm1(const_cast<DTSectColl*>(SCUnit(wheel, sect)), step);
0365 }
0366
0367 DTSectCollPhSegm* DTTrig::chSectCollPhSegm2(int wheel, int sect, int step) {
0368
0369
0370
0371
0372 return chSectCollPhSegm2(const_cast<DTSectColl*>(SCUnit(wheel, sect)), step);
0373
0374 }
0375
0376 DTSectCollThSegm* DTTrig::chSectCollThSegm(DTSectColl* unit, int step) {
0377 if (unit == nullptr)
0378 return nullptr;
0379 if (unit->nSegmTh(step) < 1)
0380 return nullptr;
0381 return const_cast<DTSectCollThSegm*>(unit->SectCollThSegment(step));
0382 }
0383
0384 DTSectCollThSegm* DTTrig::chSectCollThSegm(int wheel, int sect, int step) {
0385 return chSectCollThSegm(const_cast<DTSectColl*>(SCUnit(wheel, sect)), step);
0386 }
0387
0388
0389
0390 void DTTrig::dumpGeom() const {
0391
0392 for (TU_const_iterator it = _cache.begin(); it != _cache.end(); it++) {
0393 ((*it).second).dumpGeom();
0394 }
0395 }
0396
0397 void DTTrig::dumpLuts(short int lut_btic, const DTConfigManager* conf) const {
0398 for (TU_const_iterator it = _cache.begin(); it != _cache.end(); it++) {
0399 const DTSCTrigUnit& thisTU = (*it).second;
0400
0401
0402 thisTU.dumpLUT(lut_btic);
0403
0404
0405 DTChamberId chid = thisTU.statId();
0406 conf->dumpLUTParam(chid);
0407 }
0408
0409 return;
0410 }
0411
0412 std::vector<DTBtiTrigData> DTTrig::BtiTrigs() const {
0413
0414 std::vector<DTBtiTrigData> trigs;
0415 for (auto ptu = _cache.begin(); ptu != _cache.end(); ptu++) {
0416 const DTSCTrigUnit& tu = (*ptu).second;
0417 auto peb = tu.BtiTrigs()->end();
0418 for (auto p = tu.BtiTrigs()->begin(); p != peb; p++) {
0419 trigs.push_back(*p);
0420 }
0421 }
0422 return trigs;
0423 }
0424
0425 std::vector<DTTracoTrigData> DTTrig::TracoTrigs() const {
0426 std::vector<DTTracoTrigData> trigs;
0427
0428 for (auto ptu = _cache.begin(); ptu != _cache.end(); ptu++) {
0429 const DTSCTrigUnit& tu = (*ptu).second;
0430 auto peb = tu.TracoTrigs()->end();
0431 for (auto p = tu.TracoTrigs()->begin(); p != peb; p++) {
0432 trigs.push_back(*p);
0433 }
0434 }
0435 return trigs;
0436 }
0437
0438 std::vector<DTChambPhSegm> DTTrig::TSPhTrigs() const {
0439
0440 std::vector<DTChambPhSegm> trigs;
0441 for (auto ptu = _cache.begin(); ptu != _cache.end(); ptu++) {
0442 const DTSCTrigUnit& tu = (*ptu).second;
0443 auto peb = tu.TSPhTrigs()->end();
0444 for (auto p = tu.TSPhTrigs()->begin(); p != peb; p++) {
0445 trigs.push_back(*p);
0446 }
0447 }
0448 return trigs;
0449 }
0450
0451 std::vector<DTChambThSegm> DTTrig::TSThTrigs() const {
0452
0453 std::vector<DTChambThSegm> trigs;
0454 for (auto ptu = _cache.begin(); ptu != _cache.end(); ptu++) {
0455 const DTSCTrigUnit& tu = (*ptu).second;
0456 auto peb = tu.TSThTrigs()->end();
0457 for (auto p = tu.TSThTrigs()->begin(); p != peb; p++) {
0458 trigs.push_back(*p);
0459 }
0460 }
0461 return trigs;
0462 }
0463
0464 std::vector<DTSectCollPhSegm> DTTrig::SCPhTrigs() const {
0465
0466 std::vector<DTSectCollPhSegm> trigs;
0467 for (auto psc = _cache1.begin(); psc != _cache1.end(); psc++) {
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478 const DTSectColl& sc = (*psc).second;
0479 auto peb = sc.endPh();
0480 for (auto p = sc.beginPh(); p != peb; p++) {
0481 trigs.push_back(*p);
0482 }
0483 }
0484 return trigs;
0485 }
0486
0487 std::vector<DTSectCollThSegm> DTTrig::SCThTrigs() const {
0488
0489 std::vector<DTSectCollThSegm> trigs;
0490 for (auto psc = _cache1.begin(); psc != _cache1.end(); psc++) {
0491 const DTSectColl& sc = (*psc).second;
0492 auto peb = sc.endTh();
0493 for (auto p = sc.beginTh(); p != peb; p++) {
0494 trigs.push_back(*p);
0495 }
0496 }
0497 return trigs;
0498 }