00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 #include "CalibMuon/DTDigiSync/interface/DTTTrigSyncFactory.h"
00028 #include "CalibMuon/DTDigiSync/interface/DTTTrigBaseSync.h"
00029
00030 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00031 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00032 #include "Geometry/DTGeometry/interface/DTLayer.h"
00033 #include "Geometry/DTGeometry/interface/DTChamber.h"
00034 #include "CondFormats/DTObjects/interface/DTT0.h"
00035 #include "CondFormats/DataRecord/interface/DTT0Rcd.h"
00036 #include "CondFormats/DTObjects/interface/DTTtrig.h"
00037 #include "CondFormats/DataRecord/interface/DTTtrigRcd.h"
00038 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigManager.h"
00039 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigManagerRcd.h"
00040
00041
00042
00043
00044 #include <iostream>
00045 #include <string>
00046
00047
00048
00049
00050 #include "Geometry/DTGeometry/interface/DTChamber.h"
00051
00052
00053
00054
00055
00056 DTTrig::DTTrig(const edm::ParameterSet ¶ms) :
00057 _inputexist(1) , _configid(0) , _geomid(0) , _t0id(0) , _ttrigid(0) {
00058
00059
00060
00061 _debug = params.getUntrackedParameter<bool>("debug");
00062
00063 if(_debug){
00064 std::cout << std::endl;
00065 std::cout << "**** Initialization of DTTrigger ****" << std::endl;
00066 std::cout << std::endl;
00067 std::cout << "DTTrig::DTTrig creating synchronizer" << std::endl;
00068 }
00069
00070 _digitag = params.getParameter<edm::InputTag>("digiTag");
00071 _digi_sync = DTTTrigSyncFactory::get()->create(params.getParameter<std::string>("tTrigMode"),
00072 params.getParameter<edm::ParameterSet>("tTrigModeConfig"));
00073 _usesyncdb = params.getParameter<std::string>("tTrigMode")!="DTTTrigSyncTOFCorr";
00074 }
00075
00076
00077
00078
00079
00080 DTTrig::~DTTrig(){
00081
00082 clear();
00083 delete _digi_sync;
00084
00085 }
00086
00087 void
00088 DTTrig::createTUs(const edm::EventSetup& iSetup ){
00089
00090
00091
00092 for(int iwh=-2;iwh<=2;iwh++){
00093 for(int ise=1;ise<=12;ise++){
00094 if(_debug){
00095 std::cout << "calling sectcollid wh sc " << iwh << " " << ise << std::endl;}
00096 DTSectCollId scid(iwh,ise);
00097 SC_iterator it = _cache1.find(scid);
00098 if ( it != _cache1.end()) {
00099 std::cout << "DTTrig::createTUs: Sector Collector unit already exists"<<std::endl;
00100 continue;
00101 }
00102
00103
00104
00105 DTSectColl* sc;
00106
00107 sc = new DTSectColl(scid);
00108
00109
00110
00111
00112
00113
00114
00115
00116 if(_debug){
00117 std::cout << " DTTrig::createTUs new SC sc = " << sc
00118 << " at scid.sector() " << scid.sector()
00119 << " at scid.wheel() " << scid.wheel()
00120 << std::endl;
00121 }
00122 _cache1[scid] = sc;
00123 }
00124 }
00125
00126 edm::ESHandle<DTGeometry>pDD;
00127 iSetup.get<MuonGeometryRecord>().get(pDD);
00128 for (std::vector<DTChamber*>::const_iterator ich=pDD->chambers().begin(); ich!=pDD->chambers().end();ich++){
00129
00130 DTChamber* chamb = (*ich);
00131 DTChamberId chid = chamb->id();
00132 TU_iterator it = _cache.find(chid);
00133 if ( it != _cache.end()) {
00134 std::cout << "DTTrig::init: Trigger unit already exists" << std::endl;
00135 continue;
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 DTSCTrigUnit* tru = new DTSCTrigUnit(chamb,_digi_sync);
00149 _cache[chid] = tru;
00150
00151
00152
00153 DTSectCollId scid;
00154 if(chid.sector()==13) {
00155 scid = DTSectCollId(chid.wheel(), 4);}
00156 else if(chid.sector()==14) {
00157 scid = DTSectCollId(chid.wheel(), 10);}
00158 else {
00159 scid = DTSectCollId(chid.wheel(), chid.sector() );}
00160
00161 SC_iterator it1 = _cache1.find(scid);
00162
00163 if ( it1 != _cache1.end()) {
00164
00165 DTSectColl* sc = (*it1).second;
00166 if(_debug) {
00167 std::cout << "DTTrig::init: adding TU in SC << "
00168 << " sector = " << scid.sector()
00169 << " wheel = " << scid.wheel()
00170 << std::endl;}
00171 sc->addTU(tru);
00172 }
00173 else {
00174 std::cout << "DTTrig::createTUs: Trigger Unit not in the map: ";
00175 }
00176
00177 }
00178
00179 }
00180
00181
00182 void
00183 DTTrig::triggerReco(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00184
00185 updateES(iSetup);
00186 if (!_inputexist) return;
00187
00188 DTDigiMap digiMap;
00189
00190 edm::Handle<DTDigiCollection> dtDigis;
00191 iEvent.getByLabel(_digitag, dtDigis);
00192
00193 if (!dtDigis.isValid()) {
00194 LogDebug("DTTrig")
00195 << "DTTrig::triggerReco DTDigiCollection with input tag " << _digitag
00196 << "requested in configuration, but not found in the event." << std::endl;
00197
00198 _inputexist = false;
00199 return;
00200 }
00201
00202 DTDigiCollection::DigiRangeIterator detUnitIt;
00203
00204 for (detUnitIt=dtDigis->begin();
00205 detUnitIt!=dtDigis->end();
00206 ++detUnitIt){
00207 const DTLayerId& layId = (*detUnitIt).first;
00208 const DTChamberId chambId=layId.superlayerId().chamberId();
00209 const DTDigiCollection::Range& range = (*detUnitIt).second;
00210
00211
00212 digiMap[chambId].put(range,layId);
00213
00214
00215
00216
00217
00218
00219
00220
00221 }
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 for (TU_iterator it=_cache.begin();it!=_cache.end();it++){
00251 DTSCTrigUnit* thisTU=(*it).second;
00252 if (thisTU->BtiTrigs()->size()>0){
00253 thisTU->BtiTrigs()->clearCache();
00254 thisTU->TSThTrigs()->clearCache();
00255 thisTU->TracoTrigs()->clearCache();
00256 thisTU->TSPhTrigs()->clearCache();
00257 }
00258 DTChamberId chid=thisTU->statId();
00259 DTDigiMap_iterator dmit = digiMap.find(chid);
00260 if (dmit !=digiMap.end()){
00261 thisTU->BtiTrigs()->reconstruct((*dmit).second);
00262 if(thisTU->BtiTrigs()->size()>0){
00263 thisTU->TSThTrigs()->reconstruct();
00264 thisTU->TracoTrigs()->reconstruct();
00265 if(thisTU->TracoTrigs()->size()>0)
00266 thisTU->TSPhTrigs()->reconstruct();
00267 }
00268 }
00269 }
00270
00271 for (SC_iterator it=_cache1.begin();it!=_cache1.end();it++){
00272 DTSectColl* sectcoll = (*it).second;
00273 DTSectCollId scid = (*it).first;
00274 if (sectcoll->sizePh()>0 || sectcoll->sizeTh()>0)
00275 sectcoll->clearCache();
00276 bool mustreco = false;
00277 for (int i=1;i<5;i++) {
00278 if (sectcoll->getTSPhi(i)->size()>0) {
00279 mustreco = true;
00280 break;
00281 }
00282 }
00283 for (int i=1;i<4;i++) {
00284 if (sectcoll->getTSTheta(i)->size()>0) {
00285 mustreco = true;
00286 break;
00287 }
00288 }
00289 if (scid.sector()==4 || scid.sector()==10){
00290 if (sectcoll->getTSPhi(5)->size()>0)
00291 mustreco = true;
00292 }
00293 if (mustreco)
00294 sectcoll->reconstruct();
00295 }
00296
00297 }
00298
00299 void
00300 DTTrig::updateES(const edm::EventSetup& iSetup){
00301
00302
00303 edm::ESHandle<DTConfigManager> confHandle;
00304 edm::ESHandle<DTGeometry> geomHandle;
00305 edm::ESHandle<DTT0> t0Handle;
00306 edm::ESHandle<DTTtrig> ttrigHandle;
00307
00308 if (iSetup.get<DTConfigManagerRcd>().cacheIdentifier()!=_configid) {
00309
00310 if (_debug)
00311 std::cout << "DTTrig::updateES updating DTTPG configuration" << std::endl;
00312
00313 _configid = iSetup.get<DTConfigManagerRcd>().cacheIdentifier();
00314 iSetup.get<DTConfigManagerRcd>().get(confHandle);
00315 _conf_manager = confHandle.product();
00316 for (TU_iterator it=_cache.begin();it!=_cache.end();it++){
00317 (*it).second->setConfig(_conf_manager);
00318 }
00319 for (SC_iterator it=_cache1.begin();it!=_cache1.end();it++){
00320 (*it).second->setConfig(_conf_manager);
00321 }
00322
00323 }
00324
00325 if (iSetup.get<MuonGeometryRecord>().cacheIdentifier()!=_configid) {
00326
00327 if (_debug)
00328 std::cout << "DTTrig::updateES updating muon geometry" << std::endl;
00329
00330 _geomid = iSetup.get<MuonGeometryRecord>().cacheIdentifier();
00331 iSetup.get<MuonGeometryRecord>().get(geomHandle);
00332 for (TU_iterator it=_cache.begin();it!=_cache.end();it++){
00333 (*it).second->setGeom(geomHandle->chamber((*it).second->statId()));
00334 }
00335
00336 }
00337
00338 if (_usesyncdb &&
00339 (iSetup.get<DTT0Rcd>().cacheIdentifier()!=_t0id ||
00340 iSetup.get<DTTtrigRcd>().cacheIdentifier()!=_ttrigid)) {
00341
00342 if (_debug)
00343 std::cout << "DTTrig::updateES updating synchronizer" << std::endl;
00344
00345 _t0id = iSetup.get<DTT0Rcd>().cacheIdentifier();
00346 _ttrigid = iSetup.get<DTTtrigRcd>().cacheIdentifier();
00347 _digi_sync->setES(iSetup);
00348
00349 }
00350
00351 }
00352
00353
00354 void
00355 DTTrig::clear() {
00356
00357 for (TU_iterator it=_cache.begin();it!=_cache.end();it++){
00358
00359 delete (*it).second;
00360 }
00361 _cache.clear();
00362
00363 for (SC_iterator it=_cache1.begin();it!=_cache1.end();it++){
00364
00365 delete (*it).second;
00366 }
00367 _cache1.clear();
00368
00369 }
00370
00371 DTSCTrigUnit*
00372 DTTrig::trigUnit(DTChamberId chid) {
00373 return constTrigUnit(chid);
00374
00375 }
00376
00377
00378
00379 DTSCTrigUnit*
00380 DTTrig::constTrigUnit(DTChamberId chid) const {
00381
00382 TU_const_iterator it = _cache.find(chid);
00383 if ( it == _cache.end()) {
00384 std::cout << "DTTrig::trigUnit: Trigger Unit not in the map: ";
00385 std::cout << " wheel=" << chid.wheel() ;
00386 std::cout << ", station=" << chid.station();
00387 std::cout << ", sector=" << chid.sector();
00388 std::cout << std::endl;
00389 return 0;
00390 }
00391
00392 return (*it).second;
00393 }
00394
00395 DTSectColl*
00396 DTTrig::SCUnit(DTSectCollId scid) const {
00397 SC_const_iterator it = _cache1.find(scid);
00398 if ( it == _cache1.end()) {
00399 std::cout << "DTTrig::SCUnit: Trigger Unit not in the map: ";
00400 std::cout << " wheel=" << scid.wheel() ;
00401 std::cout << ", sector=" << scid.sector();
00402 std::cout << std::endl;
00403 return 0;
00404 }
00405
00406 return (*it).second;
00407 }
00408
00409 DTSCTrigUnit*
00410 DTTrig::trigUnit(int wheel, int stat, int sect) {
00411 return constTrigUnit(wheel, stat, sect);
00412 }
00413
00414 DTSectColl*
00415 DTTrig::SCUnit(int wheel, int sect) const {
00416 sect++;
00417 return SCUnit(DTSectCollId(wheel,sect));
00418 }
00419
00420
00421 DTSCTrigUnit*
00422 DTTrig::constTrigUnit(int wheel, int stat, int sect) const {
00423 sect++;
00424 return constTrigUnit(DTChamberId(wheel,stat,sect));
00425
00426 }
00427
00428
00429 DTChambPhSegm*
00430 DTTrig::chPhiSegm1(DTSCTrigUnit* unit, int step) {
00431 if(unit==0)return 0;
00432 if(unit->nPhiSegm(step)<1)return 0;
00433 return const_cast<DTChambPhSegm*>(unit->phiSegment(step,1));
00434 }
00435
00436 DTChambPhSegm*
00437 DTTrig::chPhiSegm2(DTSCTrigUnit* unit, int step) {
00438 if(unit==0)return 0;
00439 if(unit->nPhiSegm(step)<2)return 0;
00440 return const_cast<DTChambPhSegm*>(unit->phiSegment(step,2));
00441 }
00442
00443 DTChambThSegm*
00444 DTTrig::chThetaSegm(DTSCTrigUnit* unit, int step) {
00445 if(unit==0)return 0;
00446 if(unit->nThetaSegm(step)<1)return 0;
00447 return const_cast<DTChambThSegm*>(unit->thetaSegment(step,1));
00448 }
00449
00450 DTChambPhSegm*
00451 DTTrig::chPhiSegm1(DTChamberId sid, int step) {
00452 return chPhiSegm1(trigUnit(sid),step);
00453 }
00454
00455 DTChambPhSegm*
00456 DTTrig::chPhiSegm2(DTChamberId sid, int step) {
00457 return chPhiSegm2(trigUnit(sid),step);
00458 }
00459
00460 DTChambThSegm*
00461 DTTrig::chThetaSegm(DTChamberId sid, int step) {
00462 if(sid.station()==4)return 0;
00463 return chThetaSegm(trigUnit(sid),step);
00464 }
00465
00466 DTChambPhSegm*
00467 DTTrig::chPhiSegm1(int wheel, int stat, int sect, int step) {
00468 return chPhiSegm1(trigUnit(wheel,stat,sect),step);
00469
00470
00471
00472 }
00473
00474 DTChambPhSegm*
00475 DTTrig::chPhiSegm2(int wheel, int stat, int sect, int step) {
00476
00477
00478
00479
00480 return chPhiSegm2(trigUnit(wheel,stat,sect),step);
00481
00482
00483
00484 }
00485
00486 DTChambThSegm*
00487 DTTrig::chThetaSegm(int wheel, int stat, int sect, int step) {
00488 if(stat==4)return 0;
00489 return chThetaSegm(trigUnit(wheel,stat,sect),step);
00490 }
00491
00492
00493 DTSectCollPhSegm*
00494 DTTrig::chSectCollPhSegm1(DTSectColl* unit, int step) {
00495
00496 if(unit==0)return 0;
00497 if(unit->nSegmPh(step)<1)return 0;
00498 return const_cast<DTSectCollPhSegm*>(unit->SectCollPhSegment(step,1));
00499 }
00500
00501 DTSectCollPhSegm*
00502 DTTrig::chSectCollPhSegm2(DTSectColl* unit, int step) {
00503 if(unit==0)return 0;
00504 if(unit->nSegmPh(step)<2)return 0;
00505 return const_cast<DTSectCollPhSegm*>(unit->SectCollPhSegment(step,2));
00506 }
00507
00508
00509 DTSectCollPhSegm*
00510 DTTrig::chSectCollPhSegm1(int wheel, int sect, int step) {
00511
00512 return chSectCollPhSegm1(SCUnit(wheel,sect),step);
00513 }
00514
00515 DTSectCollPhSegm*
00516 DTTrig::chSectCollPhSegm2(int wheel, int sect, int step) {
00517
00518
00519
00520
00521 return chSectCollPhSegm2(SCUnit(wheel,sect),step);
00522
00523 }
00524
00525 DTSectCollThSegm*
00526 DTTrig::chSectCollThSegm(DTSectColl* unit, int step) {
00527
00528 if(unit==0)return 0;
00529 if(unit->nSegmTh(step)<1)return 0;
00530 return const_cast<DTSectCollThSegm*>(unit->SectCollThSegment(step));
00531 }
00532
00533 DTSectCollThSegm*
00534 DTTrig::chSectCollThSegm(int wheel, int sect, int step) {
00535
00536 return chSectCollThSegm(SCUnit(wheel,sect),step);
00537 }
00538
00539
00540
00541
00542 void
00543 DTTrig::dumpGeom() {
00544
00545 for (TU_const_iterator it=_cache.begin();it!=_cache.end();it++){
00546 ((*it).second)->dumpGeom();
00547 }
00548 }
00549
00550 void
00551 DTTrig::dumpLuts(short int lut_btic, const DTConfigManager *conf) {
00552 for (TU_const_iterator it=_cache.begin();it!=_cache.end();it++){
00553
00554 DTSCTrigUnit* thisTU = (*it).second;
00555
00556
00557 thisTU->dumpLUT(lut_btic);
00558
00559
00560 DTChamberId chid = thisTU->statId();
00561 conf->dumpLUTParam(chid);
00562
00563 }
00564
00565 return;
00566
00567 }
00568
00569 std::vector<DTBtiTrigData>
00570 DTTrig::BtiTrigs() {
00571
00572 std::vector<DTBtiTrigData> trigs;
00573 TU_iterator ptu;
00574 for(ptu=_cache.begin();ptu!=_cache.end();ptu++) {
00575 DTSCTrigUnit* tu = (*ptu).second;
00576 std::vector<DTBtiTrigData>::const_iterator p;
00577 std::vector<DTBtiTrigData>::const_iterator peb=tu->BtiTrigs()->end();
00578 for(p=tu->BtiTrigs()->begin();p!=peb;p++){
00579 trigs.push_back(*p);
00580 }
00581 }
00582 return trigs;
00583 }
00584
00585 std::vector<DTTracoTrigData>
00586 DTTrig::TracoTrigs() {
00587 std::vector<DTTracoTrigData> trigs;
00588 TU_iterator ptu;
00589
00590 for(ptu=_cache.begin();ptu!=_cache.end();ptu++) {
00591 DTSCTrigUnit* tu = (*ptu).second;
00592 std::vector<DTTracoTrigData>::const_iterator p;
00593 std::vector<DTTracoTrigData>::const_iterator peb=tu->TracoTrigs()->end();
00594 for(p=tu->TracoTrigs()->begin();p!=peb;p++){
00595 trigs.push_back(*p);
00596 }
00597 }
00598 return trigs;
00599 }
00600
00601 std::vector<DTChambPhSegm>
00602 DTTrig::TSPhTrigs() {
00603
00604 std::vector<DTChambPhSegm> trigs;
00605 TU_iterator ptu;
00606 for(ptu=_cache.begin();ptu!=_cache.end();ptu++) {
00607 DTSCTrigUnit* tu = (*ptu).second;
00608 std::vector<DTChambPhSegm>::const_iterator p;
00609 std::vector<DTChambPhSegm>::const_iterator peb=tu->TSPhTrigs()->end();
00610 for(p=tu->TSPhTrigs()->begin();p!=peb;p++){
00611 trigs.push_back(*p);
00612 }
00613 }
00614 return trigs;
00615 }
00616
00617 std::vector<DTChambThSegm>
00618 DTTrig::TSThTrigs() {
00619
00620 std::vector<DTChambThSegm> trigs;
00621 TU_iterator ptu;
00622 for(ptu=_cache.begin();ptu!=_cache.end();ptu++) {
00623 DTSCTrigUnit* tu = (*ptu).second;
00624 std::vector<DTChambThSegm>::const_iterator p;
00625 std::vector<DTChambThSegm>::const_iterator peb=tu->TSThTrigs()->end();
00626 for(p=tu->TSThTrigs()->begin();p!=peb;p++){
00627 trigs.push_back(*p);
00628 }
00629 }
00630 return trigs;
00631 }
00632
00633 std::vector<DTSectCollPhSegm>
00634 DTTrig::SCPhTrigs() {
00635
00636 std::vector<DTSectCollPhSegm> trigs;
00637
00638 SC_iterator psc;
00639 for(psc=_cache1.begin();psc!=_cache1.end();psc++) {
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650 DTSectColl* sc = (*psc).second;
00651 std::vector<DTSectCollPhSegm>::const_iterator p;
00652 std::vector<DTSectCollPhSegm>::const_iterator peb=sc->endPh();
00653 for(p=sc->beginPh();p!=peb;p++){
00654 trigs.push_back(*p);
00655 }
00656
00657 }
00658 return trigs;
00659 }
00660
00661
00662 std::vector<DTSectCollThSegm>
00663 DTTrig::SCThTrigs() {
00664
00665 std::vector<DTSectCollThSegm> trigs;
00666 SC_iterator psc;
00667 for(psc=_cache1.begin();psc!=_cache1.end();psc++) {
00668 DTSectColl* sc = (*psc).second;
00669 std::vector<DTSectCollThSegm>::const_iterator p;
00670 std::vector<DTSectCollThSegm>::const_iterator peb=sc->endTh();
00671 for(p=sc->beginTh();p!=peb;p++){
00672 trigs.push_back(*p);
00673 }
00674
00675 }
00676 return trigs;
00677 }