Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-16 06:15:44

0001 #ifndef HLTcore_TriggerSummaryProducerAOD_h
0002 #define HLTcore_TriggerSummaryProducerAOD_h
0003 
0004 /** \class TriggerSummaryProducerAOD
0005  *
0006  *
0007  *  This class is an EDProducer making the HLT summary object for AOD
0008  *
0009  *
0010  *  \author Martin Grunewald
0011  *
0012  */
0013 
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/global/EDProducer.h"
0016 #include "FWCore/Framework/interface/GetterOfProducts.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/Utilities/interface/InputTag.h"
0019 #include "DataFormats/Common/interface/Ref.h"
0020 #include "DataFormats/Provenance/interface/ProductID.h"
0021 
0022 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0023 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0024 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0025 
0026 #include "DataFormats/L1Trigger/interface/L1HFRingsFwd.h"
0027 #include "DataFormats/L1Trigger/interface/L1EtMissParticleFwd.h"
0028 #include "DataFormats/METReco/interface/METFwd.h"
0029 #include "DataFormats/METReco/interface/CaloMETFwd.h"
0030 #include "DataFormats/METReco/interface/PFMETFwd.h"
0031 
0032 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateFwd.h"
0033 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
0034 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0035 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
0036 #include "DataFormats/Candidate/interface/CompositeCandidateFwd.h"
0037 #include "DataFormats/METReco/interface/METCollection.h"
0038 #include "DataFormats/METReco/interface/CaloMETCollection.h"
0039 #include "DataFormats/METReco/interface/PFMETCollection.h"
0040 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidateFwd.h"
0041 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
0042 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
0043 #include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
0044 #include "DataFormats/L1Trigger/interface/L1EtMissParticleFwd.h"
0045 #include "DataFormats/L1Trigger/interface/L1HFRingsFwd.h"
0046 #include "DataFormats/JetReco/interface/PFJetCollection.h"
0047 #include "DataFormats/TauReco/interface/PFTauFwd.h"
0048 
0049 #include "DataFormats/L1TCorrelator/interface/TkMuon.h"
0050 #include "DataFormats/L1TCorrelator/interface/TkElectron.h"
0051 #include "DataFormats/L1TCorrelator/interface/TkEm.h"
0052 #include "DataFormats/L1TParticleFlow/interface/PFJet.h"
0053 #include "DataFormats/L1TParticleFlow/interface/PFTau.h"
0054 #include "DataFormats/L1TParticleFlow/interface/HPSPFTau.h"
0055 #include "DataFormats/L1TParticleFlow/interface/HPSPFTauFwd.h"
0056 #include "DataFormats/L1TParticleFlow/interface/PFTrack.h"
0057 
0058 #include <map>
0059 #include <set>
0060 #include <string>
0061 #include <vector>
0062 
0063 #include <functional>
0064 #include "oneapi/tbb/concurrent_unordered_set.h"
0065 #include <regex>
0066 
0067 namespace edm {
0068   class EventSetup;
0069 }
0070 
0071 namespace edm {
0072   class ConfigurationDescriptions;
0073 }
0074 
0075 //
0076 // class declaration
0077 //
0078 
0079 /// GlobalCache
0080 struct InputTagHash {
0081   std::size_t operator()(const edm::InputTag& inputTag) const {
0082     std::hash<std::string> Hash;
0083     // bit-wise xor
0084     return Hash(inputTag.label()) ^ Hash(inputTag.instance()) ^ Hash(inputTag.process());
0085   }
0086 };
0087 class TriggerSummaryProducerAOD : public edm::global::EDProducer<> {
0088 public:
0089   explicit TriggerSummaryProducerAOD(const edm::ParameterSet&);
0090   ~TriggerSummaryProducerAOD() override;
0091   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0092   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0093   void endJob() override;
0094 
0095 private:
0096   /// InputTag ordering class
0097   struct OrderInputTag {
0098     bool ignoreProcess_;
0099     OrderInputTag(bool ignoreProcess) : ignoreProcess_(ignoreProcess){};
0100     inline bool operator()(const edm::InputTag& l, const edm::InputTag& r) const {
0101       int c = l.label().compare(r.label());
0102       if (0 == c) {
0103         if (ignoreProcess_) {
0104           return l.instance() < r.instance();
0105         }
0106         c = l.instance().compare(r.instance());
0107         if (0 == c) {
0108           return l.process() < r.process();
0109         }
0110       }
0111       return c < 0;
0112     };
0113   };
0114 
0115   using ProductIDtoIndex = std::map<edm::ProductID, unsigned int>;
0116   using InputTagSet = std::set<edm::InputTag, OrderInputTag>;
0117   template <typename C>
0118   void fillTriggerObjectCollections(trigger::TriggerObjectCollection&,
0119                                     ProductIDtoIndex&,
0120                                     std::vector<std::string>&,
0121                                     trigger::Keys&,
0122                                     const edm::Event&,
0123                                     const edm::GetterOfProducts<C>&,
0124                                     const InputTagSet&) const;
0125 
0126   template <typename T>
0127   void fillTriggerObject(trigger::TriggerObjectCollection&, const T&) const;
0128   void fillTriggerObject(trigger::TriggerObjectCollection&, const l1extra::L1HFRings&) const;
0129   void fillTriggerObject(trigger::TriggerObjectCollection&, const l1extra::L1EtMissParticle&) const;
0130   void fillTriggerObject(trigger::TriggerObjectCollection&, const reco::PFMET&) const;
0131   void fillTriggerObject(trigger::TriggerObjectCollection&, const reco::CaloMET&) const;
0132   void fillTriggerObject(trigger::TriggerObjectCollection&, const reco::MET&) const;
0133 
0134   template <typename C>
0135   void fillFilterObjectMembers(const edm::Event&,
0136                                const edm::InputTag& tag,
0137                                const trigger::Vids&,
0138                                const std::vector<edm::Ref<C>>&,
0139                                const ProductIDtoIndex&,
0140                                trigger::Keys& keys,
0141                                trigger::Vids& oIds) const;
0142 
0143   template <typename C>
0144   void fillFilterObjectMember(trigger::Keys& keys, trigger::Vids& ids, const int&, const int&, const edm::Ref<C>&) const;
0145   void fillFilterObjectMember(trigger::Keys& keys,
0146                               trigger::Vids& ids,
0147                               const int&,
0148                               const int&,
0149                               const edm::Ref<l1extra::L1HFRingsCollection>&) const;
0150   void fillFilterObjectMember(trigger::Keys& keys,
0151                               trigger::Vids& ids,
0152                               const int&,
0153                               const int&,
0154                               const edm::Ref<l1extra::L1EtMissParticleCollection>&) const;
0155   void fillFilterObjectMember(
0156       trigger::Keys& keys, trigger::Vids& ids, const int&, const int&, const edm::Ref<reco::PFMETCollection>&) const;
0157   void fillFilterObjectMember(
0158       trigger::Keys& keys, trigger::Vids& ids, const int&, const int&, const edm::Ref<reco::CaloMETCollection>&) const;
0159   void fillFilterObjectMember(
0160       trigger::Keys& keys, trigger::Vids& ids, const int&, const int&, const edm::Ref<reco::METCollection>&) const;
0161 
0162   /// throw on error
0163   const bool throw_;
0164   /// process name
0165   std::string pn_;
0166   /// module labels which should be avoided
0167   std::vector<std::regex> moduleLabelPatternsToMatch_;
0168   std::vector<std::regex> moduleLabelPatternsToSkip_;
0169 
0170   /// list of L3 filter tags
0171   mutable tbb::concurrent_unordered_set<edm::InputTag, InputTagHash> filterTagsGlobal_;
0172 
0173   /// list of L3 collection tags
0174   mutable tbb::concurrent_unordered_set<edm::InputTag, InputTagHash> collectionTagsGlobal_;
0175 
0176   /// trigger object collection
0177   //trigger::TriggerObjectCollection toc_;
0178   //std::vector<std::string> tags_;
0179   /// global map for indices into toc_: offset per input L3 collection
0180   //std::map<edm::ProductID, unsigned int> offset_;
0181 
0182   /// keys
0183   //trigger::Keys keys_;
0184   /// ids
0185   //trigger::Vids ids_;
0186 
0187   /// packing decision
0188   //std::vector<bool> maskFilters_;
0189 
0190   edm::GetterOfProducts<trigger::TriggerFilterObjectWithRefs> getTriggerFilterObjectWithRefs_;
0191   edm::GetterOfProducts<reco::RecoEcalCandidateCollection> getRecoEcalCandidateCollection_;
0192   edm::GetterOfProducts<reco::ElectronCollection> getElectronCollection_;
0193   edm::GetterOfProducts<reco::RecoChargedCandidateCollection> getRecoChargedCandidateCollection_;
0194   edm::GetterOfProducts<reco::CaloJetCollection> getCaloJetCollection_;
0195   edm::GetterOfProducts<reco::CompositeCandidateCollection> getCompositeCandidateCollection_;
0196   edm::GetterOfProducts<reco::METCollection> getMETCollection_;
0197   edm::GetterOfProducts<reco::CaloMETCollection> getCaloMETCollection_;
0198   edm::GetterOfProducts<reco::PFMETCollection> getPFMETCollection_;
0199   edm::GetterOfProducts<reco::IsolatedPixelTrackCandidateCollection> getIsolatedPixelTrackCandidateCollection_;
0200   edm::GetterOfProducts<l1extra::L1EmParticleCollection> getL1EmParticleCollection_;
0201   edm::GetterOfProducts<l1extra::L1MuonParticleCollection> getL1MuonParticleCollection_;
0202   edm::GetterOfProducts<l1extra::L1JetParticleCollection> getL1JetParticleCollection_;
0203   edm::GetterOfProducts<l1extra::L1EtMissParticleCollection> getL1EtMissParticleCollection_;
0204   edm::GetterOfProducts<l1extra::L1HFRingsCollection> getL1HFRingsCollection_;
0205   edm::GetterOfProducts<reco::PFJetCollection> getPFJetCollection_;
0206   edm::GetterOfProducts<reco::PFTauCollection> getPFTauCollection_;
0207   edm::GetterOfProducts<l1t::MuonBxCollection> getL1TMuonParticleCollection_;
0208   edm::GetterOfProducts<l1t::MuonShowerBxCollection> getL1TMuonShowerParticleCollection_;
0209   edm::GetterOfProducts<l1t::EGammaBxCollection> getL1TEGammaParticleCollection_;
0210   edm::GetterOfProducts<l1t::JetBxCollection> getL1TJetParticleCollection_;
0211   edm::GetterOfProducts<l1t::TauBxCollection> getL1TTauParticleCollection_;
0212   edm::GetterOfProducts<l1t::EtSumBxCollection> getL1TEtSumParticleCollection_;
0213   edm::GetterOfProducts<l1t::TkMuonCollection> getL1TTkMuonCollection_;
0214   edm::GetterOfProducts<l1t::TkElectronCollection> getL1TTkElectronCollection_;
0215   edm::GetterOfProducts<l1t::TkEmCollection> getL1TTkEmCollection_;
0216   edm::GetterOfProducts<l1t::PFJetCollection> getL1TPFJetCollection_;
0217   edm::GetterOfProducts<l1t::PFTauCollection> getL1TPFTauCollection_;
0218   edm::GetterOfProducts<l1t::HPSPFTauCollection> getL1THPSPFTauCollection_;
0219   edm::GetterOfProducts<l1t::PFTrackCollection> getL1TPFTrackCollection_;
0220 };
0221 #endif