Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:58:25

0001 #ifndef PhysicsTools_PatUtils_TriggerHelper_h
0002 #define PhysicsTools_PatUtils_TriggerHelper_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    PatUtils
0007 // Class:      pat::helper::TriggerHelper
0008 //
0009 //
0010 /**
0011   \class    pat::helper::TriggerHelper TriggerHelper.h "PhysicsTools/PatUtils/interface/TriggerHelper.h"
0012   \brief    Helper class to remove unwanted dependencies from DataFormats/PatCandidates related to PAT trigger data formats
0013 
0014             The following class(es) are implemented in the pat::helper namespace:
0015             - TriggerMatchHelper:
0016               + provides the usage of functions which need the edm::AssociativeIterator;
0017 
0018   \author   Volker Adler
0019   \version  $Id: TriggerHelper.h,v 1.6 2010/12/20 11:55:48 vadler Exp $
0020 */
0021 
0022 #include <string>
0023 
0024 #include "DataFormats/PatCandidates/interface/TriggerEvent.h"
0025 #include "DataFormats/Candidate/interface/Candidate.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 
0028 namespace pat {
0029 
0030   namespace helper {
0031 
0032     class TriggerMatchHelper {
0033     public:
0034       /// Constructors and Destructor
0035 
0036       /// Default constructor
0037       TriggerMatchHelper(){};
0038 
0039       /// Destructor
0040       ~TriggerMatchHelper(){};
0041 
0042       /// Methods
0043 
0044       /// Get a reference to the trigger objects matched to a certain physics object given by a reference for a certain matcher module
0045       /// ... by resulting association
0046       TriggerObjectRef triggerMatchObject(const reco::CandidateBaseRef& candRef,
0047                                           const TriggerObjectMatch* matchResult,
0048                                           const edm::Event& event,
0049                                           const TriggerEvent& triggerEvent) const;
0050       /// ... by matcher module label
0051       TriggerObjectRef triggerMatchObject(const reco::CandidateBaseRef& candRef,
0052                                           const std::string& labelMatcher,
0053                                           const edm::Event& event,
0054                                           const TriggerEvent& triggerEvent) const;
0055       /// Get a reference to the trigger objects matched to a certain physics object given by a collection and index for a certain matcher module
0056       /// ... by resulting association
0057       template <class C>
0058       TriggerObjectRef triggerMatchObject(const edm::Handle<C>& candCollHandle,
0059                                           const size_t iCand,
0060                                           const TriggerObjectMatch* matchResult,
0061                                           const edm::Event& event,
0062                                           const TriggerEvent& triggerEvent) const;
0063       /// ... by matcher module label
0064       template <class C>
0065       TriggerObjectRef triggerMatchObject(const edm::Handle<C>& candCollHandle,
0066                                           const size_t iCand,
0067                                           const std::string& labelMatcher,
0068                                           const edm::Event& event,
0069                                           const TriggerEvent& triggerEvent) const;
0070       /// Get a table of references to all trigger objects matched to a certain physics object given by a reference
0071       TriggerObjectMatchMap triggerMatchObjects(const reco::CandidateBaseRef& candRef,
0072                                                 const edm::Event& event,
0073                                                 const TriggerEvent& triggerEvent) const;
0074       /// Get a table of references to all trigger objects matched to a certain physics object given by a collection and index
0075       template <class C>
0076       TriggerObjectMatchMap triggerMatchObjects(const edm::Handle<C>& candCollHandle,
0077                                                 const size_t iCand,
0078                                                 const edm::Event& event,
0079                                                 const TriggerEvent& triggerEvent) const;
0080       /// Get a vector of references to the phyics objects matched to a certain trigger object given by a reference for a certain matcher module
0081       /// ... by resulting association
0082       reco::CandidateBaseRefVector triggerMatchCandidates(const pat::TriggerObjectRef& objectRef,
0083                                                           const TriggerObjectMatch* matchResult,
0084                                                           const edm::Event& event,
0085                                                           const TriggerEvent& triggerEvent) const;
0086       /// ... by matcher module label
0087       reco::CandidateBaseRefVector triggerMatchCandidates(const pat::TriggerObjectRef& objectRef,
0088                                                           const std::string& labelMatcher,
0089                                                           const edm::Event& event,
0090                                                           const TriggerEvent& triggerEvent) const;
0091       /// Get a vector of references to the phyics objects matched to a certain trigger object given by a collection and index for a certain matcher module
0092       /// ... by resulting association
0093       reco::CandidateBaseRefVector triggerMatchCandidates(const edm::Handle<TriggerObjectCollection>& trigCollHandle,
0094                                                           const size_t iTrig,
0095                                                           const TriggerObjectMatch* matchResult,
0096                                                           const edm::Event& event,
0097                                                           const TriggerEvent& triggerEvent) const;
0098       /// ... by matcher module label
0099       reco::CandidateBaseRefVector triggerMatchCandidates(const edm::Handle<TriggerObjectCollection>& trigCollHandle,
0100                                                           const size_t iTrig,
0101                                                           const std::string& labelMatcher,
0102                                                           const edm::Event& event,
0103                                                           const TriggerEvent& triggerEvent) const;
0104     };
0105 
0106     // Method Templates
0107 
0108     // Get a reference to the trigger objects matched to a certain physics object given by a collection and index for a certain matcher module
0109     template <class C>
0110     TriggerObjectRef TriggerMatchHelper::triggerMatchObject(const edm::Handle<C>& candCollHandle,
0111                                                             const size_t iCand,
0112                                                             const TriggerObjectMatch* matchResult,
0113                                                             const edm::Event& event,
0114                                                             const TriggerEvent& triggerEvent) const {
0115       const reco::CandidateBaseRef candRef(edm::Ref<C>(candCollHandle, iCand));
0116       return triggerMatchObject(candRef, matchResult, event, triggerEvent);
0117     }
0118     template <class C>
0119     TriggerObjectRef TriggerMatchHelper::triggerMatchObject(const edm::Handle<C>& candCollHandle,
0120                                                             const size_t iCand,
0121                                                             const std::string& labelMatcher,
0122                                                             const edm::Event& event,
0123                                                             const TriggerEvent& triggerEvent) const {
0124       return triggerMatchObject(
0125           candCollHandle, iCand, triggerEvent.triggerObjectMatchResult(labelMatcher), event, triggerEvent);
0126     }
0127 
0128     // Get a table of references to all trigger objects matched to a certain physics object given by a collection and index
0129     template <class C>
0130     TriggerObjectMatchMap TriggerMatchHelper::triggerMatchObjects(const edm::Handle<C>& candCollHandle,
0131                                                                   const size_t iCand,
0132                                                                   const edm::Event& event,
0133                                                                   const TriggerEvent& triggerEvent) const {
0134       const reco::CandidateBaseRef candRef(edm::Ref<C>(candCollHandle, iCand));
0135       return triggerMatchObjects(candRef, event, triggerEvent);
0136     }
0137 
0138   }  // namespace helper
0139 
0140 }  // namespace pat
0141 
0142 #endif