Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-29 01:21:19

0001 #include "DQM/EcalMonitorTasks/interface/TrigPrimTask.h"
0002 
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Common/interface/TriggerResultsByName.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 
0010 #include <iomanip>
0011 
0012 namespace ecaldqm {
0013   TrigPrimTask::TrigPrimTask()
0014       : DQWorkerTask(),
0015         realTps_(nullptr),
0016         runOnEmul_(false),
0017         //     HLTCaloPath_(""),
0018         //     HLTMuonPath_(""),
0019         //     HLTCaloBit_(false),
0020         //     HLTMuonBit_(false),
0021         bxBinEdges_(),
0022         bxBinEdgesFine_(),
0023         bxBin_(0.),
0024         bxBinFine_(0.),
0025         towerReadouts_(),
0026         lhcStatusInfoCollectionTag_() {}
0027 
0028   void TrigPrimTask::setParams(edm::ParameterSet const& _params) {
0029     runOnEmul_ = _params.getUntrackedParameter<bool>("runOnEmul");
0030     if (!runOnEmul_) {
0031       MEs_.erase(std::string("EtMaxEmul"));
0032       MEs_.erase(std::string("EmulMaxIndex"));
0033       MEs_.erase(std::string("MatchedIndex"));
0034       MEs_.erase(std::string("EtEmulError"));
0035       MEs_.erase(std::string("FGEmulError"));
0036       MEs_.erase(std::string("RealvEmulEt"));
0037     }
0038     lhcStatusInfoCollectionTag_ = _params.getUntrackedParameter<edm::InputTag>(
0039         "lhcStatusInfoCollectionTag", edm::InputTag("tcdsDigis", "tcdsRecord"));
0040     bxBinEdges_ = _params.getUntrackedParameter<std::vector<int> >("bxBins");
0041     bxBinEdgesFine_ = _params.getUntrackedParameter<std::vector<int> >("bxBinsFine");
0042   }
0043 
0044   void TrigPrimTask::addDependencies(DependencySet& _dependencies) {
0045     if (runOnEmul_)
0046       _dependencies.push_back(Dependency(kTrigPrimEmulDigi, kEBDigi, kEEDigi, kTrigPrimDigi));
0047   }
0048 
0049   void TrigPrimTask::beginRun(edm::Run const&, edm::EventSetup const& _es) {
0050     // Read-in Status records:
0051     // Status records stay constant over run so they are read-in only once here
0052     // but filled by LS in runOnRealTPs() because MEs are not yet booked at beginRun()
0053     TTStatus = &_es.getData(TTStatusRcd_);
0054     StripStatus = &_es.getData(StripStatusRcd_);
0055   }
0056 
0057   void TrigPrimTask::beginEvent(edm::Event const& _evt,
0058                                 edm::EventSetup const& _es,
0059                                 bool const& ByLumiResetSwitch,
0060                                 bool& lhcStatusSet) {
0061     using namespace std;
0062 
0063     towerReadouts_.clear();
0064 
0065     if (ByLumiResetSwitch) {
0066       MEs_.at("EtSummaryByLumi").reset(GetElectronicsMap());
0067       MEs_.at("TTFlags4ByLumi").reset(GetElectronicsMap());
0068       MEs_.at("LHCStatusByLumi").reset(GetElectronicsMap(), -1);
0069     }
0070 
0071     if (!lhcStatusSet) {
0072       // Update LHC status once each LS
0073       MESet& meLHCStatusByLumi(static_cast<MESet&>(MEs_.at("LHCStatusByLumi")));
0074       edm::Handle<TCDSRecord> tcdsData;
0075       _evt.getByToken(lhcStatusInfoRecordToken_, tcdsData);
0076       if (tcdsData.isValid()) {
0077         meLHCStatusByLumi.fill(getEcalDQMSetupObjects(), double(tcdsData->getBST().getBeamMode()));
0078         lhcStatusSet = true;
0079       }
0080     }
0081 
0082     realTps_ = nullptr;
0083 
0084     //     HLTCaloBit_ = false;
0085     //     HLTMuonBit_ = false;
0086 
0087     std::vector<int>::iterator pBin(std::upper_bound(bxBinEdges_.begin(), bxBinEdges_.end(), _evt.bunchCrossing()));
0088     bxBin_ = static_cast<int>(pBin - bxBinEdges_.begin()) - 0.5;
0089     // fine binning for TP Occ vs BX plot as requested by DAQ in March 2021
0090     std::vector<int>::iterator pBinFine(
0091         std::upper_bound(bxBinEdgesFine_.begin(), bxBinEdgesFine_.end(), _evt.bunchCrossing()));
0092     bxBinFine_ = static_cast<int>(pBinFine - bxBinEdgesFine_.begin()) - 0.5;
0093 
0094     const EcalTPGTowerStatusMap& towerMap = TTStatus->getMap();
0095     const EcalTPGStripStatusMap& stripMap = StripStatus->getMap();
0096 
0097     MESet& meTTMaskMap(MEs_.at("TTMaskMap"));
0098 
0099     for (EcalTPGTowerStatusMap::const_iterator ttItr(towerMap.begin()); ttItr != towerMap.end(); ++ttItr) {
0100       if ((*ttItr).second > 0) {
0101         const EcalTrigTowerDetId ttid((*ttItr).first);
0102         //if(ttid.subDet() == EcalBarrel)
0103         meTTMaskMap.fill(getEcalDQMSetupObjects(), ttid, 1);
0104       }  //masked
0105     }    //loop on towers
0106 
0107     for (EcalTPGStripStatusMap::const_iterator stItr(stripMap.begin()); stItr != stripMap.end(); ++stItr) {
0108       if ((*stItr).second > 0) {
0109         const EcalElectronicsId stid((*stItr).first);
0110         //if(stid.subdet() == EcalEndcap);
0111         meTTMaskMap.fill(getEcalDQMSetupObjects(), stid, 1);
0112       }  //masked
0113     }    //loop on pseudo-strips
0114 
0115     //     if(HLTCaloPath_.size() || HLTMuonPath_.size()){
0116     //       edm::TriggerResultsByName results(_evt.triggerResultsByName("HLT"));
0117     //       if(!results.isValid()) results = _evt.triggerResultsByName("RECO");
0118     //       if(results.isValid()){
0119     //  const vector<string>& pathNames(results.triggerNames());
0120 
0121     //  size_t caloStar(HLTCaloPath_.find('*'));
0122     //  if(caloStar != string::npos){
0123     //    string caloSub(HLTCaloPath_.substr(0, caloStar));
0124     //    bool found(false);
0125     //    for(unsigned iP(0); iP < pathNames.size(); ++iP){
0126     //      if(pathNames[iP].substr(0, caloStar) == caloSub){
0127     //        HLTCaloPath_ = pathNames[iP];
0128     //        found = true;
0129     //        break;
0130     //      }
0131     //    }
0132     //    if(!found) HLTCaloPath_ = "";
0133     //  }
0134 
0135     //  size_t muonStar(HLTMuonPath_.find('*'));
0136     //  if(muonStar != string::npos){
0137     //    string muonSub(HLTMuonPath_.substr(0, muonStar));
0138     //    bool found(false);
0139     //    for(unsigned iP(0); iP < pathNames.size(); ++iP){
0140     //      if(pathNames[iP].substr(0, muonStar) == muonSub){
0141     //        HLTMuonPath_ = pathNames[iP];
0142     //        found = true;
0143     //        break;
0144     //      }
0145     //    }
0146     //    if(!found) HLTMuonPath_ = "";
0147     //  }
0148 
0149     //  if(HLTCaloPath_.size()){
0150     //    try{
0151     //      HLTCaloBit_ = results.accept(HLTCaloPath_);
0152     //    }
0153     //    catch(cms::Exception e){
0154     //      if(e.category() != "LogicError") throw e;
0155     //      HLTCaloPath_ = "";
0156     //    }
0157     //  }
0158     //  if(HLTMuonPath_.size()){
0159     //    try{
0160     //      HLTMuonBit_ = results.accept(HLTMuonPath_);
0161     //    }
0162     //    catch(cms::Exception e){
0163     //      if(e.category() != "LogicError") throw e;
0164     //      HLTMuonPath_ = "";
0165     //    }
0166     //  }
0167     //       }
0168     //     }
0169   }
0170 
0171   template <typename DigiCollection>
0172   void TrigPrimTask::runOnDigis(DigiCollection const& _digis) {
0173     for (typename DigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
0174       EcalTrigTowerDetId ttid(GetTrigTowerMap()->towerOf(digiItr->id()));
0175       towerReadouts_[ttid.rawId()]++;
0176     }
0177   }
0178 
0179   void TrigPrimTask::setTokens(edm::ConsumesCollector& _collector) {
0180     lhcStatusInfoRecordToken_ = _collector.consumes<TCDSRecord>(lhcStatusInfoCollectionTag_);
0181     TTStatusRcd_ = _collector.esConsumes<edm::Transition::BeginRun>();
0182     StripStatusRcd_ = _collector.esConsumes<edm::Transition::BeginRun>();
0183   }
0184 
0185   void TrigPrimTask::runOnRealTPs(EcalTrigPrimDigiCollection const& _tps) {
0186     MESet& meEtVsBx(MEs_.at("EtVsBx"));
0187     MESet& meEtReal(MEs_.at("EtReal"));
0188     MESet& meEtRealMap(MEs_.at("EtRealMap"));
0189     MESet& meEtSummary(MEs_.at("EtSummary"));
0190     MESet& meEtSummaryByLumi(MEs_.at("EtSummaryByLumi"));
0191     MESet& meLowIntMap(MEs_.at("LowIntMap"));
0192     MESet& meMedIntMap(MEs_.at("MedIntMap"));
0193     MESet& meHighIntMap(MEs_.at("HighIntMap"));
0194     MESet& meTTFlags(MEs_.at("TTFlags"));
0195     MESet& meTTFlagsVsEt(MEs_.at("TTFlagsVsEt"));
0196     MESet& meTTFlags4(MEs_.at("TTFlags4"));
0197     MESet& meTTFlags4ByLumi(MEs_.at("TTFlags4ByLumi"));
0198     MESet& meTTFMismatch(MEs_.at("TTFMismatch"));
0199     MESet& meOccVsBx(MEs_.at("OccVsBx"));
0200 
0201     realTps_ = &_tps;
0202 
0203     double nTP[] = {0., 0., 0.};
0204 
0205     for (EcalTrigPrimDigiCollection::const_iterator tpItr(_tps.begin()); tpItr != _tps.end(); ++tpItr) {
0206       EcalTrigTowerDetId ttid(tpItr->id());
0207       float et(tpItr->compressedEt());
0208 
0209       if (et > 0.) {
0210         if (ttid.subDet() == EcalBarrel)
0211           nTP[0] += 1.;
0212         else if (ttid.zside() < 0)
0213           nTP[1] += 1.;
0214         else
0215           nTP[2] += 2.;
0216         meEtVsBx.fill(getEcalDQMSetupObjects(), ttid, bxBin_, et);
0217       }
0218 
0219       meEtReal.fill(getEcalDQMSetupObjects(), ttid, et);
0220       meEtRealMap.fill(getEcalDQMSetupObjects(), ttid, et);
0221       meEtSummary.fill(getEcalDQMSetupObjects(), ttid, et);
0222       meEtSummaryByLumi.fill(getEcalDQMSetupObjects(), ttid, et);
0223 
0224       int interest(tpItr->ttFlag() & 0x3);
0225 
0226       switch (interest) {
0227         case 0:
0228           meLowIntMap.fill(getEcalDQMSetupObjects(), ttid);
0229           break;
0230         case 1:
0231           meMedIntMap.fill(getEcalDQMSetupObjects(), ttid);
0232           break;
0233         case 3:
0234           meHighIntMap.fill(getEcalDQMSetupObjects(), ttid);
0235           break;
0236         default:
0237           break;
0238       }
0239 
0240       // Fill TT Flag MEs
0241       int ttF(tpItr->ttFlag());
0242       meTTFlags.fill(getEcalDQMSetupObjects(), ttid, 1.0 * ttF);
0243       meTTFlagsVsEt.fill(getEcalDQMSetupObjects(), ttid, et, 1.0 * ttF);
0244       // Monitor occupancy of TTF=4
0245       // which contains info about TT auto-masking
0246       if (ttF >= 4) {
0247         meTTFlags4.fill(getEcalDQMSetupObjects(), ttid);
0248         meTTFlags4ByLumi.fill(getEcalDQMSetupObjects(), ttid);
0249       }
0250       if ((ttF == 1 || ttF == 3) && towerReadouts_[ttid.rawId()] != GetTrigTowerMap()->constituentsOf(ttid).size())
0251         meTTFMismatch.fill(getEcalDQMSetupObjects(), ttid);
0252     }
0253 
0254     meOccVsBx.fill(getEcalDQMSetupObjects(), EcalBarrel, bxBinFine_, nTP[0]);
0255     meOccVsBx.fill(getEcalDQMSetupObjects(), -EcalEndcap, bxBinFine_, nTP[1]);
0256     meOccVsBx.fill(getEcalDQMSetupObjects(), EcalEndcap, bxBinFine_, nTP[2]);
0257 
0258     // Set TT/Strip Masking status in Ecal3P view
0259     // Status Records are read-in at beginRun() but filled here
0260     // Requestied by ECAL Trigger in addition to TTMaskMap plots in SM view
0261     MESet& meTTMaskMapAll(MEs_.at("TTMaskMapAll"));
0262 
0263     // Fill from TT Status Rcd
0264     const EcalTPGTowerStatusMap& TTStatusMap(TTStatus->getMap());
0265     for (EcalTPGTowerStatusMap::const_iterator ttItr(TTStatusMap.begin()); ttItr != TTStatusMap.end(); ++ttItr) {
0266       const EcalTrigTowerDetId ttid(ttItr->first);
0267       if (ttItr->second > 0)
0268         meTTMaskMapAll.setBinContent(getEcalDQMSetupObjects(), ttid, 1);  // TT is masked
0269     }                                                                     // TTs
0270 
0271     // Fill from Strip Status Rcd
0272     const EcalTPGStripStatusMap& StripStatusMap(StripStatus->getMap());
0273     for (EcalTPGStripStatusMap::const_iterator stItr(StripStatusMap.begin()); stItr != StripStatusMap.end(); ++stItr) {
0274       const EcalTriggerElectronicsId stid(stItr->first);
0275       // Since ME has kTriggerTower binning, convert to EcalTrigTowerDetId first
0276       // In principle, setBinContent() could be implemented for EcalTriggerElectronicsId class as well
0277       const EcalTrigTowerDetId ttid(GetElectronicsMap()->getTrigTowerDetId(stid.tccId(), stid.ttId()));
0278       if (stItr->second > 0)
0279         meTTMaskMapAll.setBinContent(getEcalDQMSetupObjects(), ttid, 1);  // PseudoStrip is masked
0280     }                                                                     // PseudoStrips
0281 
0282   }  // TrigPrimTask::runOnRealTPs()
0283 
0284   void TrigPrimTask::runOnEmulTPs(EcalTrigPrimDigiCollection const& _tps) {
0285     MESet& meEtMaxEmul(MEs_.at("EtMaxEmul"));
0286     MESet& meEmulMaxIndex(MEs_.at("EmulMaxIndex"));
0287     MESet& meMatchedIndex(MEs_.at("MatchedIndex"));
0288     MESet& meEtEmulError(MEs_.at("EtEmulError"));
0289     MESet& meFGEmulError(MEs_.at("FGEmulError"));
0290     MESet& meRealvEmulEt(MEs_.at("RealvEmulEt"));
0291 
0292     for (EcalTrigPrimDigiCollection::const_iterator tpItr(_tps.begin()); tpItr != _tps.end(); ++tpItr) {
0293       EcalTrigTowerDetId ttid(tpItr->id());
0294 
0295       int et(tpItr->compressedEt());
0296 
0297       float maxEt(0.);
0298       int iMax(0);
0299       for (int iDigi(0); iDigi < 5; iDigi++) {
0300         float sampleEt((*tpItr)[iDigi].compressedEt());
0301 
0302         if (sampleEt > maxEt) {
0303           maxEt = sampleEt;
0304           iMax = iDigi + 1;
0305         }
0306       }
0307 
0308       meEtMaxEmul.fill(getEcalDQMSetupObjects(), ttid, maxEt);
0309       if (maxEt > 0.)
0310         meEmulMaxIndex.fill(getEcalDQMSetupObjects(), ttid, iMax);
0311 
0312       bool match(true);
0313       bool matchFG(true);
0314 
0315       // Loop over real TPs and look for an emulated TP index with matching Et:
0316       // If an Et match is found, return TP index correpsonding to BX of emulated TP where match was found
0317       // Standard TPG comparison: { TP index:matched BX } = { no emul:No Et match, 0:BX-2, 1:BX-1, 2:in-time, 3:BX+1, 4:BX+2 }
0318       EcalTrigPrimDigiCollection::const_iterator realItr(realTps_->find(ttid));
0319       if (realItr != realTps_->end()) {
0320         int realEt(realItr->compressedEt());
0321 
0322         if (realEt > 0) {
0323           int ttF(realItr->ttFlag());
0324           if ((ttF == 1 || ttF == 3) &&
0325               towerReadouts_[ttid.rawId()] == GetTrigTowerMap()->constituentsOf(ttid).size()) {
0326             if (et != realEt)
0327               match = false;
0328             if (tpItr->fineGrain() != realItr->fineGrain())
0329               matchFG = false;
0330 
0331             // NOTE: matchedIndex comparison differs from Standard TPG comparison:
0332             // { matchedIndex:TP index } = { 0:no emul, 1:BX-2, 2:BX-1, 3:in-time, 4:BX+1, 5:BX+2 }
0333             std::vector<int> matchedIndex(0);
0334             // iDigi only loops over explicit Et matches:
0335             // { iDigi:TP index } = { 0:BX-2, 1:BX-1, 2:in-time, 3:BX+1, 4:BX+2 }
0336             for (int iDigi(0); iDigi < 5; iDigi++) {
0337               if ((*tpItr)[iDigi].compressedEt() == realEt) {
0338                 // matchedIndex = iDigi + 1
0339                 if (iDigi != 2) {
0340                   matchedIndex.push_back(iDigi + 1);
0341                 }
0342                 // If an in-time match is found, exit loop and clear out any other matches:
0343                 // Ensures multiple matches are not returned (e.g. during saturation)
0344                 else {
0345                   matchedIndex.clear();
0346                   matchedIndex.push_back(3);  // Et match is to in-time emulated TP
0347                   break;
0348                 }
0349               }  // Et match found
0350             }    // iDigi
0351             if (matchedIndex.empty())
0352               matchedIndex.push_back(0);  // no Et match found => no emul
0353 
0354             // Fill Real vs Emulated TP Et
0355             meRealvEmulEt.fill(
0356                 getEcalDQMSetupObjects(), ttid, realEt, (*tpItr)[2].compressedEt());  // iDigi=2:in-time BX
0357 
0358             // Fill matchedIndex ME
0359             for (std::vector<int>::iterator matchItr(matchedIndex.begin()); matchItr != matchedIndex.end();
0360                  ++matchItr) {
0361               meMatchedIndex.fill(getEcalDQMSetupObjects(), ttid, *matchItr + 0.5);
0362 
0363               // timing information is only within emulated TPs (real TPs have one time sample)
0364               //      if(HLTCaloBit_) MEs_[kTimingCalo].fill(ttid, float(*matchItr));
0365               //      if(HLTMuonBit_) MEs_[kTimingMuon].fill(ttid, float(*matchItr));
0366             }
0367           }
0368         }
0369       } else {
0370         match = false;
0371         matchFG = false;
0372       }
0373 
0374       if (!match)
0375         meEtEmulError.fill(getEcalDQMSetupObjects(), ttid);
0376       if (!matchFG)
0377         meFGEmulError.fill(getEcalDQMSetupObjects(), ttid);
0378     }
0379   }
0380 
0381   DEFINE_ECALDQM_WORKER(TrigPrimTask);
0382 }  // namespace ecaldqm