Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:22

0001 #ifndef DataFormats_PatCandidates_TriggerObject_h
0002 #define DataFormats_PatCandidates_TriggerObject_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    PatCandidates
0007 // Class:      pat::TriggerObject
0008 //
0009 //
0010 /**
0011   \class    pat::TriggerObject TriggerObject.h "DataFormats/PatCandidates/interface/TriggerObject.h"
0012   \brief    Analysis-level trigger object class
0013 
0014    TriggerObject implements a container for trigger objects' information within the 'pat' namespace.
0015    For detailed information, consult
0016    https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePATTrigger#TriggerObject
0017 
0018   \author   Volker Adler
0019 */
0020 
0021 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0022 
0023 #include <map>
0024 #include <string>
0025 #include <vector>
0026 #include <algorithm>
0027 
0028 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
0029 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
0030 #include "DataFormats/L1Trigger/interface/L1EtMissParticle.h"
0031 #include "DataFormats/L1Trigger/interface/L1EtMissParticleFwd.h"
0032 #include "DataFormats/L1Trigger/interface/L1JetParticle.h"
0033 #include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
0034 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
0035 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
0036 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0037 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0038 #include "DataFormats/Common/interface/RefVectorIterator.h"
0039 #include "DataFormats/Common/interface/Association.h"
0040 #include "FWCore/Utilities/interface/InputTag.h"
0041 
0042 namespace pat {
0043 
0044   class TriggerObject : public reco::LeafCandidate {
0045     /// Data Members
0046 
0047     /// Label of the collection the trigger object originates from
0048     std::string collection_;
0049     /// Vector of special identifiers for the trigger object type as defined in
0050     /// trigger::TriggerObjectType (DataFormats/HLTReco/interface/TriggerTypeDefs.h),
0051     /// possibly empty
0052     std::vector<trigger::TriggerObjectType> triggerObjectTypes_;
0053     /// Reference to trigger object,
0054     /// meant for 'l1extra' particles to access their additional functionalities,
0055     /// empty otherwise
0056     reco::CandidateBaseRef refToOrig_;
0057 
0058   public:
0059     /// Constructors and Destructor
0060 
0061     /// Default constructor
0062     TriggerObject();
0063     /// Constructor from trigger::TriggerObject
0064     TriggerObject(const trigger::TriggerObject& trigObj);
0065     /// Constructors from base class object
0066     TriggerObject(const reco::LeafCandidate& leafCand);
0067     /// Constructors from base candidate reference (for 'l1extra' particles)
0068     TriggerObject(const reco::CandidateBaseRef& candRef);
0069     /// Constructors from Lorentz-vectors and (optional) PDG ID
0070     TriggerObject(const reco::Particle::LorentzVector& vec, int id = 0);
0071     TriggerObject(const reco::Particle::PolarLorentzVector& vec, int id = 0);
0072 
0073     /// Destructor
0074     ~TriggerObject() override{};
0075 
0076     /// Methods
0077 
0078     /// Set the label of the collection the trigger object originates from
0079     void setCollection(const std::string& collName) { collection_ = collName; };
0080     void setCollection(const edm::InputTag& collName) { collection_ = collName.encode(); };
0081     /// Add a new trigger object type identifier
0082     void addTriggerObjectType(trigger::TriggerObjectType triggerObjectType) {
0083       if (!hasTriggerObjectType(triggerObjectType))
0084         triggerObjectTypes_.push_back(triggerObjectType);
0085     };
0086     void addTriggerObjectType(int triggerObjectType) {
0087       addTriggerObjectType(trigger::TriggerObjectType(triggerObjectType));
0088     };
0089     void addFilterId(trigger::TriggerObjectType triggerObjectType) {
0090       addTriggerObjectType(triggerObjectType);
0091     };  // for backward compatibility
0092     void addFilterId(int triggerObjectType) {
0093       addTriggerObjectType(trigger::TriggerObjectType(triggerObjectType));
0094     };  // for backward compatibility
0095     /// Get the label of the collection the trigger object originates from
0096     const std::string& collection() const { return collection_; };
0097     /// Get all trigger object type identifiers
0098     //       std::vector< trigger::TriggerObjectType > triggerObjectTypes() const { return triggerObjectTypes_; };
0099     //       std::vector< trigger::TriggerObjectType > filterIds()          const { return triggerObjectTypes(); }; // for backward compatibility
0100     std::vector<int> triggerObjectTypes() const;                          // for backward compatibility
0101     std::vector<int> filterIds() const { return triggerObjectTypes(); };  // for double backward compatibility
0102     /// Checks, if a certain label of original collection is assigned
0103     virtual bool hasCollection(const std::string& collName) const;
0104     virtual bool hasCollection(const edm::InputTag& collName) const { return hasCollection(collName.encode()); };
0105     /// Checks, if a certain trigger object type identifier is assigned
0106     bool hasTriggerObjectType(trigger::TriggerObjectType triggerObjectType) const;
0107     bool hasTriggerObjectType(int triggerObjectType) const {
0108       return hasTriggerObjectType(trigger::TriggerObjectType(triggerObjectType));
0109     };
0110     bool hasFilterId(trigger::TriggerObjectType triggerObjectType) const {
0111       return hasTriggerObjectType(triggerObjectType);
0112     };  // for backward compatibility
0113     bool hasFilterId(int triggerObjectType) const {
0114       return hasTriggerObjectType(trigger::TriggerObjectType(triggerObjectType));
0115     };  // for backward compatibility
0116 
0117     /// Special methods for 'l1extra' particles
0118 
0119     /// General getters
0120     const reco::CandidateBaseRef& origObjRef() const { return refToOrig_; };
0121     const reco::Candidate* origObjCand() const { return refToOrig_.get(); };
0122     /// Getters specific to the 'l1extra' particle type for
0123     /// - EM
0124     const l1extra::L1EmParticleRef origL1EmRef() const;
0125     const L1GctEmCand* origL1GctEmCand() const {
0126       return origL1EmRef().isNonnull() ? origL1EmRef()->gctEmCand() : nullptr;
0127     };
0128     /// - EtMiss
0129     const l1extra::L1EtMissParticleRef origL1EtMissRef() const;
0130     const L1GctEtMiss* origL1GctEtMiss() const {
0131       return origL1EtMissRef().isNonnull() ? origL1EtMissRef()->gctEtMiss() : nullptr;
0132     };
0133     const L1GctEtTotal* origL1GctEtTotal() const {
0134       return origL1EtMissRef().isNonnull() ? origL1EtMissRef()->gctEtTotal() : nullptr;
0135     };
0136     const L1GctHtMiss* origL1GctHtMiss() const {
0137       return origL1EtMissRef().isNonnull() ? origL1EtMissRef()->gctHtMiss() : nullptr;
0138     };
0139     const L1GctEtHad* origL1GctEtHad() const {
0140       return origL1EtMissRef().isNonnull() ? origL1EtMissRef()->gctEtHad() : nullptr;
0141     };
0142     /// - Jet
0143     const l1extra::L1JetParticleRef origL1JetRef() const;
0144     const L1GctJetCand* origL1GctJetCand() const {
0145       return origL1JetRef().isNonnull() ? origL1JetRef()->gctJetCand() : nullptr;
0146     };
0147     /// - Muon
0148     const l1extra::L1MuonParticleRef origL1MuonRef() const;
0149     const L1MuGMTExtendedCand* origL1GmtMuonCand() const {
0150       return origL1MuonRef().isNonnull() ? &(origL1MuonRef()->gmtMuonCand()) : nullptr;
0151     };
0152 
0153     /// Special methods for the cut string parser
0154     /// - argument types usable in the cut string parser
0155     /// - short names for readable configuration files
0156 
0157     /// Calls 'hasCollection(...)'
0158     virtual bool coll(const std::string& collName) const { return hasCollection(collName); };
0159     /// Calls 'hasTriggerObjectType(...)'
0160     bool type(trigger::TriggerObjectType triggerObjectType) const { return hasTriggerObjectType(triggerObjectType); };
0161     bool type(int triggerObjectType) const {
0162       return hasTriggerObjectType(trigger::TriggerObjectType(triggerObjectType));
0163     };
0164     bool id(trigger::TriggerObjectType triggerObjectType) const {
0165       return hasTriggerObjectType(triggerObjectType);
0166     };  // for backward compatibility
0167     bool id(int triggerObjectType) const {
0168       return hasTriggerObjectType(trigger::TriggerObjectType(triggerObjectType));
0169     };  // for backward compatibility
0170   };
0171 
0172   /// Collection of TriggerObject
0173   typedef std::vector<TriggerObject> TriggerObjectCollection;
0174   /// Persistent reference to an item in a TriggerObjectCollection
0175   typedef edm::Ref<TriggerObjectCollection> TriggerObjectRef;
0176   /// Container to store match references from different producers (for one PAT object)
0177   typedef std::map<std::string, TriggerObjectRef> TriggerObjectMatchMap;
0178   /// Persistent reference to a TriggerObjectCollection product
0179   typedef edm::RefProd<TriggerObjectCollection> TriggerObjectRefProd;
0180   /// Vector of persistent references to items in the same TriggerObjectCollection
0181   typedef edm::RefVector<TriggerObjectCollection> TriggerObjectRefVector;
0182   /// Const iterator over vector of persistent references to items in the same TriggerObjectCollection
0183   typedef edm::RefVectorIterator<TriggerObjectCollection> TriggerObjectRefVectorIterator;
0184   /// Association of TriggerObjects to store matches to Candidates
0185   typedef edm::Association<TriggerObjectCollection> TriggerObjectMatch;
0186   /// Persistent reference to a TriggerObjectMatch product
0187   typedef edm::RefProd<TriggerObjectMatch> TriggerObjectMatchRefProd;
0188   /// Container to store references to matches from different producers in the trigger event
0189   typedef std::map<std::string, TriggerObjectMatchRefProd> TriggerObjectMatchContainer;
0190 
0191 }  // namespace pat
0192 
0193 #endif