Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:25

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   l1tp2gtcandIds_.clear();
0252   l1tp2gtcandRefs_.clear();
0253 
0254   // Attention: must look only for modules actually run in this path for this event!
0255   for (unsigned int j = 0; j <= moduleIndex; ++j) {
0256     const std::string& moduleLabel(moduleLabels[j]);
0257     const std::string moduleType(hltConfig_.moduleType(moduleLabel));
0258     // check whether the module is packed up in TriggerEventWithRefs product
0259     const unsigned int filterIndex(
0260         triggerEventWithRefsHandle_->filterIndex(edm::InputTag(moduleLabel, "", processName_)));
0261     if (filterIndex < triggerEventWithRefsHandle_->size()) {
0262       LOG(logMsgType_) << " Filter in slot " << j << " - label/type " << moduleLabel << "/" << moduleType;
0263       LOG(logMsgType_) << " Filter packed up at: " << filterIndex;
0264       LOG(logMsgType_) << "  Accepted objects:";
0265 
0266       // Photons
0267       triggerEventWithRefsHandle_->getObjects(filterIndex, photonIds_, photonRefs_);
0268       showObjects(photonIds_, photonRefs_, "Photons");
0269 
0270       // Electrons
0271       triggerEventWithRefsHandle_->getObjects(filterIndex, electronIds_, electronRefs_);
0272       showObjects(electronIds_, electronRefs_, "Electrons");
0273 
0274       // Muons
0275       triggerEventWithRefsHandle_->getObjects(filterIndex, muonIds_, muonRefs_);
0276       showObjects(muonIds_, muonRefs_, "Muons");
0277 
0278       // Jets
0279       triggerEventWithRefsHandle_->getObjects(filterIndex, jetIds_, jetRefs_);
0280       showObjects(jetIds_, jetRefs_, "Jets");
0281 
0282       // Composites
0283       triggerEventWithRefsHandle_->getObjects(filterIndex, compositeIds_, compositeRefs_);
0284       showObjects(compositeIds_, compositeRefs_, "Composites");
0285 
0286       // BaseMETs
0287       triggerEventWithRefsHandle_->getObjects(filterIndex, basemetIds_, basemetRefs_);
0288       showObjects(basemetIds_, basemetRefs_, "BaseMETs");
0289 
0290       // CaloMETs
0291       triggerEventWithRefsHandle_->getObjects(filterIndex, calometIds_, calometRefs_);
0292       showObjects(calometIds_, calometRefs_, "CaloMETs");
0293 
0294       // PixTracks
0295       triggerEventWithRefsHandle_->getObjects(filterIndex, pixtrackIds_, pixtrackRefs_);
0296       showObjects(pixtrackIds_, pixtrackRefs_, "PixTracks");
0297 
0298       // L1EMs
0299       triggerEventWithRefsHandle_->getObjects(filterIndex, l1emIds_, l1emRefs_);
0300       showObjects(l1emIds_, l1emRefs_, "L1EMs");
0301 
0302       // L1Muons
0303       triggerEventWithRefsHandle_->getObjects(filterIndex, l1muonIds_, l1muonRefs_);
0304       showObjects(l1muonIds_, l1muonRefs_, "L1Muons");
0305 
0306       // L1Jets
0307       triggerEventWithRefsHandle_->getObjects(filterIndex, l1jetIds_, l1jetRefs_);
0308       showObjects(l1jetIds_, l1jetRefs_, "L1Jets");
0309 
0310       // L1EtMiss
0311       triggerEventWithRefsHandle_->getObjects(filterIndex, l1etmissIds_, l1etmissRefs_);
0312       showObjects(l1etmissIds_, l1etmissRefs_, "L1EtMiss");
0313 
0314       // L1HFRings
0315       triggerEventWithRefsHandle_->getObjects(filterIndex, l1hfringsIds_, l1hfringsRefs_);
0316       showObjects(l1hfringsIds_, l1hfringsRefs_, "L1HFRings");
0317 
0318       // L1TMuons
0319       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tmuonIds_, l1tmuonRefs_);
0320       showObjects(l1tmuonIds_, l1tmuonRefs_, "L1TMuons");
0321 
0322       // L1TMuonShowers
0323       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tmuonShowerIds_, l1tmuonShowerRefs_);
0324       showObjects(l1tmuonShowerIds_, l1tmuonShowerRefs_, "L1TMuonShowers");
0325 
0326       // L1TEGammas
0327       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tegammaIds_, l1tegammaRefs_);
0328       showObjects(l1tegammaIds_, l1tegammaRefs_, "L1TEGammas");
0329 
0330       // L1TJets
0331       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tjetIds_, l1tjetRefs_);
0332       showObjects(l1tjetIds_, l1tjetRefs_, "L1TJets");
0333 
0334       // L1TTaus
0335       triggerEventWithRefsHandle_->getObjects(filterIndex, l1ttauIds_, l1ttauRefs_);
0336       showObjects(l1ttauIds_, l1ttauRefs_, "L1TTaus");
0337 
0338       // L1TEtSums
0339       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tetsumIds_, l1tetsumRefs_);
0340       showObjects(l1tetsumIds_, l1tetsumRefs_, "L1TEtSum");
0341 
0342       /// Phase 2
0343 
0344       // L1TTkMuons
0345       triggerEventWithRefsHandle_->getObjects(filterIndex, l1ttkmuIds_, l1ttkmuRefs_);
0346       showObjects(l1ttkmuIds_, l1ttkmuRefs_, "L1TTkMuons");
0347 
0348       // L1TTkElectrons
0349       triggerEventWithRefsHandle_->getObjects(filterIndex, l1ttkeleIds_, l1ttkeleRefs_);
0350       showObjects(l1ttkeleIds_, l1ttkeleRefs_, "L1TTkElectrons");
0351 
0352       // L1TTkEMs
0353       triggerEventWithRefsHandle_->getObjects(filterIndex, l1ttkemIds_, l1ttkemRefs_);
0354       showObjects(l1ttkemIds_, l1ttkemRefs_, "L1TTkEMs");
0355 
0356       // L1TPFJets
0357       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tpfjetIds_, l1tpfjetRefs_);
0358       showObjects(l1tpfjetIds_, l1tpfjetRefs_, "L1TPFJets");
0359 
0360       // L1TPFTaus
0361       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tpftauIds_, l1tpftauRefs_);
0362       showObjects(l1tpftauIds_, l1tpftauRefs_, "L1TPFTaus");
0363 
0364       // L1THPSPFTaus
0365       triggerEventWithRefsHandle_->getObjects(filterIndex, l1thpspftauIds_, l1thpspftauRefs_);
0366       showObjects(l1thpspftauIds_, l1thpspftauRefs_, "L1THPSPFTaus");
0367 
0368       // L1TPFTracks
0369       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tpftrackIds_, l1tpftrackRefs_);
0370       showObjects(l1tpftrackIds_, l1tpftrackRefs_, "L1TPFTracks");
0371 
0372       // PFJets
0373       triggerEventWithRefsHandle_->getObjects(filterIndex, pfjetIds_, pfjetRefs_);
0374       showObjects(pfjetIds_, pfjetRefs_, "PFJets");
0375 
0376       // PFTaus
0377       triggerEventWithRefsHandle_->getObjects(filterIndex, pftauIds_, pftauRefs_);
0378       showObjects(pftauIds_, pftauRefs_, "PFTaus");
0379 
0380       // PFMETs
0381       triggerEventWithRefsHandle_->getObjects(filterIndex, pfmetIds_, pfmetRefs_);
0382       showObjects(pfmetIds_, pfmetRefs_, "PFMETs");
0383 
0384       // L1TP2GTCandidates
0385       triggerEventWithRefsHandle_->getObjects(filterIndex, l1tp2gtcandIds_, l1tp2gtcandRefs_);
0386       showObjects(l1tp2gtcandIds_, l1tp2gtcandRefs_, "L1TP2GTCandidates");
0387     }
0388   }
0389 
0390   return;
0391 }
0392 
0393 template <>
0394 void HLTEventAnalyzerRAW::showObject(LOG& log, trigger::VRl1hfrings::value_type const& ref) const {
0395   log << "hfEtSum(ring1PosEta)=" << ref->hfEtSum(l1extra::L1HFRings::kRing1PosEta)
0396       << " hfEtSum(ring1NegEta)=" << ref->hfEtSum(l1extra::L1HFRings::kRing1NegEta)
0397       << " hfEtSum(ring2PosEta)=" << ref->hfEtSum(l1extra::L1HFRings::kRing2PosEta)
0398       << " hfEtSum(ring2NegEta)=" << ref->hfEtSum(l1extra::L1HFRings::kRing2NegEta)
0399       << " hfBitCount(ring1PosEta)=" << ref->hfBitCount(l1extra::L1HFRings::kRing1PosEta)
0400       << " hfBitCount(ring1NegEta)=" << ref->hfBitCount(l1extra::L1HFRings::kRing1NegEta)
0401       << " hfBitCount(ring2PosEta)=" << ref->hfBitCount(l1extra::L1HFRings::kRing2PosEta)
0402       << " hfBitCount(ring2NegEta)=" << ref->hfBitCount(l1extra::L1HFRings::kRing2NegEta);
0403 }