Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_PatCandidates_TriggerFilter_h
0002 #define DataFormats_PatCandidates_TriggerFilter_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    PatCandidates
0007 // Class:      pat::TriggerFilter
0008 //
0009 //
0010 /**
0011   \class    pat::TriggerFilter TriggerFilter.h "DataFormats/PatCandidates/interface/TriggerFilter.h"
0012   \brief    Analysis-level HLTrigger filter class
0013 
0014    TriggerFilter implements a container for trigger filters' information within the 'pat' namespace.
0015    For detailed information, consult
0016    https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePATTrigger#TriggerFilter
0017 
0018   \author   Volker Adler
0019 */
0020 
0021 #include <string>
0022 #include <vector>
0023 
0024 #include "FWCore/Utilities/interface/InputTag.h"
0025 #include "DataFormats/Common/interface/Ref.h"
0026 #include "DataFormats/Common/interface/RefProd.h"
0027 #include "DataFormats/Common/interface/RefVector.h"
0028 #include "DataFormats/Common/interface/RefVectorIterator.h"
0029 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0030 
0031 namespace pat {
0032 
0033   class TriggerFilter {
0034     /// Data Members
0035 
0036     /// Label of the filter
0037     std::string label_;
0038     /// CMSSW module type
0039     std::string type_;
0040     /// Indeces of trigger objects in pat::TriggerObjectCollection in event
0041     /// as produced together with the pat::TriggerFilterCollection
0042     std::vector<unsigned> objectKeys_;
0043     /// List of (unique) special identifiers for the used trigger object types as defined in
0044     /// trigger::TriggerObjectType (DataFormats/HLTReco/interface/TriggerTypeDefs.h),
0045     /// possibly empty or containing also zeroes
0046     std::vector<trigger::TriggerObjectType> triggerObjectTypes_;
0047     /// Indicator for filter status: -1: not run, 0: failed, 1: succeeded
0048     int status_;
0049     /// Indicator for being an L3 filter
0050     /// available starting from CMSSW_4_2_3
0051     bool saveTags_;
0052 
0053   public:
0054     /// Constructors and Desctructor
0055 
0056     /// Default constructor
0057     TriggerFilter();
0058     /// Constructor from std::string for filter label
0059     TriggerFilter(const std::string& label, int status = -1, bool saveTags = false);
0060     /// Constructor from edm::InputTag for filter label
0061     TriggerFilter(const edm::InputTag& tag, int status = -1, bool saveTags = false);
0062 
0063     /// Destructor
0064     virtual ~TriggerFilter(){};
0065 
0066     /// Methods
0067 
0068     /// Set the filter label
0069     void setLabel(const std::string& label) { label_ = label; };
0070     /// Set the filter module type
0071     void setType(const std::string& type) { type_ = type; };
0072     /// Add a new trigger object collection index
0073     void addObjectKey(unsigned objectKey) {
0074       if (!hasObjectKey(objectKey))
0075         objectKeys_.push_back(objectKey);
0076     };
0077     /// Add a new trigger object type identifier
0078     void addTriggerObjectType(trigger::TriggerObjectType triggerObjectType) {
0079       if (!hasTriggerObjectType(triggerObjectType))
0080         triggerObjectTypes_.push_back(triggerObjectType);
0081     };
0082     void addTriggerObjectType(int triggerObjectType) {
0083       addTriggerObjectType(trigger::TriggerObjectType(triggerObjectType));
0084     };
0085     void addObjectId(trigger::TriggerObjectType triggerObjectType) {
0086       addTriggerObjectType(triggerObjectType);
0087     };  // for backward compatibility
0088     void addObjectId(int triggerObjectType) {
0089       addTriggerObjectType(trigger::TriggerObjectType(triggerObjectType));
0090     };  // for backward compatibility
0091     /// Set the filter status,
0092     /// only -1,0,1 accepted; returns 'false' (and does not modify the status) otherwise
0093     bool setStatus(int status);
0094     /// Set the L3 status
0095     void setSaveTags(bool saveTags) { saveTags_ = saveTags; };
0096     /// Get the filter label
0097     const std::string& label() const { return label_; };
0098     /// Get the filter module type
0099     const std::string& type() const { return type_; };
0100     /// Get all trigger object collection indeces
0101     const std::vector<unsigned>& objectKeys() const { return objectKeys_; };
0102     /// Get all trigger object type identifiers
0103     //       std::vector< trigger::TriggerObjectType > triggerObjectTypes() const { return triggerObjectTypes_; };
0104     //       std::vector< trigger::TriggerObjectType > objectIds()          const { return triggerObjectTypes(); }; // for backward compatibility
0105     std::vector<int> triggerObjectTypes() const;                          // for backward compatibilit
0106     std::vector<int> objectIds() const { return triggerObjectTypes(); };  // for double backward compatibility
0107     /// Get the filter status
0108     int status() const { return status_; };
0109     /// Get the L3 status
0110     bool saveTags() const { return saveTags_; };
0111     bool isL3() const { return saveTags(); };
0112     bool isFiring() const { return (saveTags() && status() == 1); };
0113     /// Checks, if a certain trigger object collection index is assigned
0114     bool hasObjectKey(unsigned objectKey) const;
0115     /// Checks, if a certain trigger object type identifier is assigned
0116     bool hasTriggerObjectType(trigger::TriggerObjectType triggerObjectType) const;
0117     bool hasTriggerObjectType(int triggerObjectType) const {
0118       return hasTriggerObjectType(trigger::TriggerObjectType(triggerObjectType));
0119     };
0120     bool hasObjectId(trigger::TriggerObjectType triggerObjectType) const {
0121       return hasTriggerObjectType(triggerObjectType);
0122     };  // for backward compatibility
0123     bool hasObjectId(int triggerObjectType) const {
0124       return hasTriggerObjectType(trigger::TriggerObjectType(triggerObjectType));
0125     };  // for backward compatibility
0126   };
0127 
0128   /// Collection of TriggerFilter
0129   typedef std::vector<TriggerFilter> TriggerFilterCollection;
0130   /// Persistent reference to an item in a TriggerFilterCollection
0131   typedef edm::Ref<TriggerFilterCollection> TriggerFilterRef;
0132   /// Persistent reference to a TriggerFilterCollection product
0133   typedef edm::RefProd<TriggerFilterCollection> TriggerFilterRefProd;
0134   /// Vector of persistent references to items in the same TriggerFilterCollection
0135   typedef edm::RefVector<TriggerFilterCollection> TriggerFilterRefVector;
0136   /// Const iterator over vector of persistent references to items in the same TriggerFilterCollection
0137   typedef edm::RefVectorIterator<TriggerFilterCollection> TriggerFilterRefVectorIterator;
0138 
0139 }  // namespace pat
0140 
0141 #endif