Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:09:23

0001 /** \class HLTEventAnalyzerRAW
0002  *
0003  * See header file for documentation
0004  *
0005  *
0006  *  \author Martin Grunewald
0007  *
0008  */
0009 
0010 #include "FWCore/Common/interface/TriggerNames.h"
0011 #include "FWCore/Common/interface/TriggerResultsByName.h"
0012 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0013 #include "HLTrigger/HLTcore/interface/HLTEventAnalyzerRAW.h"
0014 
0015 // need access to class objects being referenced to get their content!
0016 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
0017 #include "DataFormats/EgammaCandidates/interface/Electron.h"
0018 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0019 #include "DataFormats/JetReco/interface/CaloJet.h"
0020 #include "DataFormats/Candidate/interface/CompositeCandidate.h"
0021 #include "DataFormats/METReco/interface/MET.h"
0022 #include "DataFormats/METReco/interface/CaloMET.h"
0023 #include "DataFormats/METReco/interface/PFMET.h"
0024 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h"
0025 
0026 #include "DataFormats/L1Trigger/interface/L1HFRings.h"         // deprecate
0027 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"      // deprecate
0028 #include "DataFormats/L1Trigger/interface/L1JetParticle.h"     // deprecate
0029 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"    // deprecate
0030 #include "DataFormats/L1Trigger/interface/L1EtMissParticle.h"  // deprecate
0031 
0032 #include "DataFormats/L1Trigger/interface/Muon.h"
0033 #include "DataFormats/L1Trigger/interface/MuonShower.h"
0034 #include "DataFormats/L1Trigger/interface/EGamma.h"
0035 #include "DataFormats/L1Trigger/interface/Jet.h"
0036 #include "DataFormats/L1Trigger/interface/Tau.h"
0037 #include "DataFormats/L1Trigger/interface/EtSum.h"
0038 
0039 #include "DataFormats/L1TMuonPhase2/interface/TrackerMuon.h"
0040 #include "DataFormats/L1TCorrelator/interface/TkElectron.h"
0041 #include "DataFormats/L1TCorrelator/interface/TkEm.h"
0042 #include "DataFormats/L1TParticleFlow/interface/PFJet.h"
0043 #include "DataFormats/L1TParticleFlow/interface/PFTau.h"
0044 #include "DataFormats/L1TParticleFlow/interface/HPSPFTau.h"
0045 #include "DataFormats/L1TParticleFlow/interface/PFTrack.h"
0046 #include "DataFormats/JetReco/interface/PFJet.h"
0047 #include "DataFormats/TauReco/interface/PFTau.h"
0048 
0049 #include <cassert>
0050 
0051 //
0052 // constructor
0053 //
0054 HLTEventAnalyzerRAW::HLTEventAnalyzerRAW(const edm::ParameterSet& ps)
0055     : processName_(ps.getParameter<std::string>("processName")),
0056       triggerName_(ps.getParameter<std::string>("triggerName")),
0057       triggerResultsTag_(ps.getParameter<edm::InputTag>("triggerResults")),
0058       triggerResultsToken_(consumes<edm::TriggerResults>(triggerResultsTag_)),
0059       triggerEventWithRefsTag_(ps.getParameter<edm::InputTag>("triggerEventWithRefs")),
0060       triggerEventWithRefsToken_(consumes<trigger::TriggerEventWithRefs>(triggerEventWithRefsTag_)),
0061       verbose_(ps.getParameter<bool>("verbose")),
0062       permissive_(ps.getParameter<bool>("permissive")) {
0063   LOG(logMsgType_) << logMsgType_ << " configuration:\n"
0064                    << "   ProcessName = " << processName_ << "\n"
0065                    << "   TriggerName = " << triggerName_ << "\n"
0066                    << "   TriggerResultsTag = " << triggerResultsTag_.encode() << "\n"
0067                    << "   TriggerEventWithRefsTag = " << triggerEventWithRefsTag_.encode();
0068 }
0069 
0070 //
0071 // member functions
0072 //
0073 void HLTEventAnalyzerRAW::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0074   edm::ParameterSetDescription desc;
0075   desc.add<std::string>("processName", "HLT");
0076   desc.add<std::string>("triggerName", "@")
0077       ->setComment("name of trigger Path to consider (use \"@\" to consider all Paths)");
0078   desc.add<edm::InputTag>("triggerResults", edm::InputTag("TriggerResults", "", "HLT"));
0079   desc.add<edm::InputTag>("triggerEventWithRefs", edm::InputTag("hltTriggerSummaryRAW", "", "HLT"));
0080   desc.add<bool>("verbose", false)->setComment("enable verbose mode");
0081   desc.add<bool>("permissive", false)
0082       ->setComment("if true, exceptions due to Refs pointing to unavailable collections are bypassed");
0083   descriptions.add("hltEventAnalyzerRAW", desc);
0084 }
0085 
0086 void HLTEventAnalyzerRAW::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
0087   bool changed(true);
0088   if (hltConfig_.init(iRun, iSetup, processName_, changed)) {
0089     if (changed) {
0090       // check if trigger name in (new) config
0091       if (triggerName_ != "@") {  // "@" means: analyze all triggers in config
0092         const unsigned int n(hltConfig_.size());
0093         const unsigned int triggerIndex(hltConfig_.triggerIndex(triggerName_));
0094         if (triggerIndex >= n) {
0095           LOG(logMsgType_) << logMsgType_ << "::beginRun: TriggerName " << triggerName_
0096                            << " not available in (new) config!";
0097           LOG(logMsgType_) << "Available TriggerNames are: ";
0098           hltConfig_.dump("Triggers");
0099         }
0100       }
0101       // in verbose mode, print process info to stdout
0102       if (verbose_) {
0103         hltConfig_.dump("ProcessName");
0104         hltConfig_.dump("GlobalTag");
0105         hltConfig_.dump("TableName");
0106         hltConfig_.dump("Streams");
0107         hltConfig_.dump("Datasets");
0108         hltConfig_.dump("PrescaleTable");
0109         hltConfig_.dump("ProcessPSet");
0110       }
0111     }
0112   } else {
0113     LOG(logMsgType_) << logMsgType_ << "::beginRun: config extraction failure with process name " << processName_;
0114   }
0115 }
0116 
0117 void HLTEventAnalyzerRAW::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0118   // get event products
0119   triggerResultsHandle_ = iEvent.getHandle(triggerResultsToken_);
0120   if (not triggerResultsHandle_.isValid()) {
0121     LOG(logMsgType_) << logMsgType_ << "::analyze: Error in getting TriggerResults product from Event!";
0122     return;
0123   }
0124   triggerEventWithRefsHandle_ = iEvent.getHandle(triggerEventWithRefsToken_);
0125   if (not triggerEventWithRefsHandle_.isValid()) {
0126     LOG(logMsgType_) << logMsgType_ << "::analyze: Error in getting TriggerEventWithRefs product from Event!";
0127     return;
0128   }
0129 
0130   // sanity check
0131   assert(triggerResultsHandle_->size() == hltConfig_.size());
0132 
0133   // analyze this event for the triggers requested
0134   if (triggerName_ == "@") {
0135     const unsigned int n(hltConfig_.size());
0136     for (unsigned int i = 0; i != n; ++i) {
0137       analyzeTrigger(iEvent, iSetup, hltConfig_.triggerName(i));
0138     }
0139   } else {
0140     analyzeTrigger(iEvent, iSetup, triggerName_);
0141   }
0142 
0143   return;
0144 }
0145 
0146 void HLTEventAnalyzerRAW::analyzeTrigger(const edm::Event& iEvent,
0147                                          const edm::EventSetup& iSetup,
0148                                          const std::string& triggerName) {
0149   const unsigned int n(hltConfig_.size());
0150   const unsigned int triggerIndex(hltConfig_.triggerIndex(triggerName));
0151   assert(triggerIndex == iEvent.triggerNames(*triggerResultsHandle_).triggerIndex(triggerName));
0152 
0153   // abort on invalid trigger name
0154   if (triggerIndex >= n) {
0155     LOG(logMsgType_) << logMsgType_ << "::analyzeTrigger: path " << triggerName << " - not found!";
0156     return;
0157   }
0158 
0159   LOG(logMsgType_) << logMsgType_ << "::analyzeTrigger: path " << triggerName << " [" << triggerIndex << "]";
0160 
0161   // results from TriggerResults product
0162   LOG(logMsgType_) << " Trigger path status:"
0163                    << " WasRun=" << triggerResultsHandle_->wasrun(triggerIndex)
0164                    << " Accept=" << triggerResultsHandle_->accept(triggerIndex)
0165                    << " Error=" << triggerResultsHandle_->error(triggerIndex);
0166 
0167   // modules on this trigger path
0168   const unsigned int m(hltConfig_.size(triggerIndex));
0169   const std::vector<std::string>& moduleLabels(hltConfig_.moduleLabels(triggerIndex));
0170   assert(m == moduleLabels.size());
0171 
0172   // skip empty Path
0173   if (m == 0) {
0174     LOG(logMsgType_) << logMsgType_ << "::analyzeTrigger: path " << triggerName << " [" << triggerIndex
0175                      << "] is empty!";
0176     return;
0177   }
0178 
0179   // index of last module executed in this Path
0180   const unsigned int moduleIndex(triggerResultsHandle_->index(triggerIndex));
0181   assert(moduleIndex < m);
0182 
0183   LOG(logMsgType_) << " Last active module - label/type: " << moduleLabels[moduleIndex] << "/"
0184                    << hltConfig_.moduleType(moduleLabels[moduleIndex]) << " [" << moduleIndex << " out of 0-" << (m - 1)
0185                    << " on this path]";
0186 
0187   // results from TriggerEventWithRefs product
0188   photonIds_.clear();
0189   photonRefs_.clear();
0190   electronIds_.clear();
0191   electronRefs_.clear();
0192   muonIds_.clear();
0193   muonRefs_.clear();
0194   jetIds_.clear();
0195   jetRefs_.clear();
0196   compositeIds_.clear();
0197   compositeRefs_.clear();
0198   basemetIds_.clear();
0199   basemetRefs_.clear();
0200   calometIds_.clear();
0201   calometRefs_.clear();
0202   pixtrackIds_.clear();
0203   pixtrackRefs_.clear();
0204 
0205   l1emIds_.clear();
0206   l1emRefs_.clear();
0207   l1muonIds_.clear();
0208   l1muonRefs_.clear();
0209   l1jetIds_.clear();
0210   l1jetRefs_.clear();
0211   l1etmissIds_.clear();
0212   l1etmissRefs_.clear();
0213   l1hfringsIds_.clear();
0214   l1hfringsRefs_.clear();
0215 
0216   l1tmuonIds_.clear();
0217   l1tmuonRefs_.clear();
0218   l1tmuonShowerIds_.clear();
0219   l1tmuonShowerRefs_.clear();
0220   l1tegammaIds_.clear();
0221   l1tegammaRefs_.clear();
0222   l1tjetIds_.clear();
0223   l1tjetRefs_.clear();
0224   l1ttauIds_.clear();
0225   l1ttauRefs_.clear();
0226   l1tetsumIds_.clear();
0227   l1tetsumRefs_.clear();
0228 
0229   l1ttkmuIds_.clear();
0230   l1ttkmuRefs_.clear();
0231   l1ttkeleIds_.clear();
0232   l1ttkeleRefs_.clear();
0233   l1ttkemIds_.clear();
0234   l1ttkemRefs_.clear();
0235   l1tpfjetIds_.clear();
0236   l1tpfjetRefs_.clear();
0237   l1tpftauIds_.clear();
0238   l1tpftauRefs_.clear();
0239   l1thpspftauIds_.clear();
0240   l1thpspftauRefs_.clear();
0241   l1tpftrackIds_.clear();
0242   l1tpftrackRefs_.clear();
0243 
0244   pfjetIds_.clear();
0245   pfjetRefs_.clear();
0246   pftauIds_.clear();
0247   pftauRefs_.clear();
0248   pfmetIds_.clear();
0249   pfmetRefs_.clear();
0250 
0251   // Attention: must look only for modules actually run in this path for this event!
0252   for (unsigned int j = 0; j <= moduleIndex; ++j) {
0253     const std::string& moduleLabel(moduleLabels[j]);
0254     const std::string moduleType(hltConfig_.moduleType(moduleLabel));
0255     // check whether the module is packed up in TriggerEventWithRefs product
0256     const unsigned int filterIndex(
0257         triggerEventWithRefsHandle_->filterIndex(edm::InputTag(moduleLabel, "", processName_)));
0258     if (filterIndex < triggerEventWithRefsHandle_->size()) {
0259       LOG(logMsgType_) << " Filter in slot " << j << " - label/type " << moduleLabel << "/" << moduleType;
0260       LOG(logMsgType_) << " Filter packed up at: " << filterIndex;
0261       LOG(logMsgType_) << "  Accepted objects:";
0262 
0263       // Photons
0264       triggerEventWithRefsHandle_->getObjects(filterIndex, photonIds_, photonRefs_);
0265       showObjects(photonIds_, photonRefs_, "Photons");
0266 
0267       // Electrons
0268       triggerEventWithRefsHandle_->getObjects(filterIndex, electronIds_, electronRefs_);
0269       showObjects(electronIds_, electronRefs_, "Electrons");
0270 
0271       // Muons
0272       triggerEventWithRefsHandle_->getObjects(filterIndex, muonIds_, muonRefs_);
0273       showObjects(muonIds_, muonRefs_, "Muons");
0274 
0275       // Jets
0276       triggerEventWithRefsHandle_->getObjects(filterIndex, jetIds_, jetRefs_);
0277       showObjects(jetIds_, jetRefs_, "Jets");
0278 
0279       // Composites
0280       triggerEventWithRefsHandle_->getObjects(filterIndex, compositeIds_, compositeRefs_);
0281       showObjects(compositeIds_, compositeRefs_, "Composites");
0282 
0283       // BaseMETs
0284       triggerEventWithRefsHandle_->getObjects(filterIndex, basemetIds_, basemetRefs_);
0285       showObjects(basemetIds_, basemetRefs_, "BaseMETs");
0286 
0287       // CaloMETs
0288       triggerEventWithRefsHandle_->getObjects(filterIndex, calometIds_, calometRefs_);
0289       showObjects(calometIds_, calometRefs_, "CaloMETs");
0290 
0291       // PixTracks
0292       triggerEventWithRefsHandle_->getObjects(filterIndex, pixtrackIds_, pixtrackRefs_);
0293       showObjects(pixtrackIds_, pixtrackRefs_, "PixTracks");
0294 
0295       // L1EMs
0296       triggerEventWithRefsHandle_->getObjects(filterIndex, l1emIds_, l1emRefs_);
0297       showObjects(l1emIds_, l1emRefs_, "L1EMs");
0298 
0299       // L1Muons
0300       triggerEventWithRefsHandle_->getObjects(filterIndex, l1muonIds_, l1muonRefs_);
0301       showObjects(l1muonIds_, l1muonRefs_, "L1Muons");
0302 
0303       // L1Jets
0304       triggerEventWithRefsHandle_->getObjects(filterIndex, l1jetIds_, l1jetRefs_);
0305       showObjects(l1jetIds_, l1jetRefs_, "L1Jets");
0306 
0307       // L1EtMiss
0308       triggerEventWithRefsHandle_->getObjects(filterIndex, l1etmissIds_, l1etmissRefs_);
0309       showObjects(l1etmissIds_, l1etmissRefs_, "L1EtMiss");
0310 
0311       // L1HFRings
0312       triggerEventWithRefsHandle_->getObjects(filterIndex, l1hfringsIds_, l1hfringsRefs_);
0313       showObjects(l1hfringsIds_, l1hfringsRefs_, "L1HFRings");
0314 
0315       // L1TMuons
0316       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tmuonIds_, l1tmuonRefs_);
0317       showObjects(l1tmuonIds_, l1tmuonRefs_, "L1TMuons");
0318 
0319       // L1TMuonShowers
0320       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tmuonShowerIds_, l1tmuonShowerRefs_);
0321       showObjects(l1tmuonShowerIds_, l1tmuonShowerRefs_, "L1TMuonShowers");
0322 
0323       // L1TEGammas
0324       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tegammaIds_, l1tegammaRefs_);
0325       showObjects(l1tegammaIds_, l1tegammaRefs_, "L1TEGammas");
0326 
0327       // L1TJets
0328       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tjetIds_, l1tjetRefs_);
0329       showObjects(l1tjetIds_, l1tjetRefs_, "L1TJets");
0330 
0331       // L1TTaus
0332       triggerEventWithRefsHandle_->getObjects(filterIndex, l1ttauIds_, l1ttauRefs_);
0333       showObjects(l1ttauIds_, l1ttauRefs_, "L1TTaus");
0334 
0335       // L1TEtSums
0336       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tetsumIds_, l1tetsumRefs_);
0337       showObjects(l1tetsumIds_, l1tetsumRefs_, "L1TEtSum");
0338 
0339       /// Phase 2
0340 
0341       // L1TTkMuons
0342       triggerEventWithRefsHandle_->getObjects(filterIndex, l1ttkmuIds_, l1ttkmuRefs_);
0343       showObjects(l1ttkmuIds_, l1ttkmuRefs_, "L1TTkMuons");
0344 
0345       // L1TTkElectrons
0346       triggerEventWithRefsHandle_->getObjects(filterIndex, l1ttkeleIds_, l1ttkeleRefs_);
0347       showObjects(l1ttkeleIds_, l1ttkeleRefs_, "L1TTkElectrons");
0348 
0349       // L1TTkEMs
0350       triggerEventWithRefsHandle_->getObjects(filterIndex, l1ttkemIds_, l1ttkemRefs_);
0351       showObjects(l1ttkemIds_, l1ttkemRefs_, "L1TTkEMs");
0352 
0353       // L1TPFJets
0354       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tpfjetIds_, l1tpfjetRefs_);
0355       showObjects(l1tpfjetIds_, l1tpfjetRefs_, "L1TPFJets");
0356 
0357       // L1TPFTaus
0358       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tpftauIds_, l1tpftauRefs_);
0359       showObjects(l1tpftauIds_, l1tpftauRefs_, "L1TPFTaus");
0360 
0361       // L1THPSPFTaus
0362       triggerEventWithRefsHandle_->getObjects(filterIndex, l1thpspftauIds_, l1thpspftauRefs_);
0363       showObjects(l1thpspftauIds_, l1thpspftauRefs_, "L1THPSPFTaus");
0364 
0365       // L1TPFTracks
0366       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tpftrackIds_, l1tpftrackRefs_);
0367       showObjects(l1tpftrackIds_, l1tpftrackRefs_, "L1TPFTracks");
0368 
0369       // PFJets
0370       triggerEventWithRefsHandle_->getObjects(filterIndex, pfjetIds_, pfjetRefs_);
0371       showObjects(pfjetIds_, pfjetRefs_, "PFJets");
0372 
0373       // PFTaus
0374       triggerEventWithRefsHandle_->getObjects(filterIndex, pftauIds_, pftauRefs_);
0375       showObjects(pftauIds_, pftauRefs_, "PFTaus");
0376 
0377       // PFMETs
0378       triggerEventWithRefsHandle_->getObjects(filterIndex, pfmetIds_, pfmetRefs_);
0379       showObjects(pfmetIds_, pfmetRefs_, "PFMETs");
0380     }
0381   }
0382 
0383   return;
0384 }
0385 
0386 template <>
0387 void HLTEventAnalyzerRAW::showObject(LOG& log, trigger::VRl1hfrings::value_type const& ref) const {
0388   log << "hfEtSum(ring1PosEta)=" << ref->hfEtSum(l1extra::L1HFRings::kRing1PosEta)
0389       << " hfEtSum(ring1NegEta)=" << ref->hfEtSum(l1extra::L1HFRings::kRing1NegEta)
0390       << " hfEtSum(ring2PosEta)=" << ref->hfEtSum(l1extra::L1HFRings::kRing2PosEta)
0391       << " hfEtSum(ring2NegEta)=" << ref->hfEtSum(l1extra::L1HFRings::kRing2NegEta)
0392       << " hfBitCount(ring1PosEta)=" << ref->hfBitCount(l1extra::L1HFRings::kRing1PosEta)
0393       << " hfBitCount(ring1NegEta)=" << ref->hfBitCount(l1extra::L1HFRings::kRing1NegEta)
0394       << " hfBitCount(ring2PosEta)=" << ref->hfBitCount(l1extra::L1HFRings::kRing2PosEta)
0395       << " hfBitCount(ring2NegEta)=" << ref->hfBitCount(l1extra::L1HFRings::kRing2NegEta);
0396 }