Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:56

0001 #ifndef DataFormats_PatCandidates_TriggerPath_h
0002 #define DataFormats_PatCandidates_TriggerPath_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    PatCandidates
0007 // Class:      pat::TriggerPath
0008 //
0009 //
0010 /*
0011   \class    pat::TriggerPath TriggerPath.h "DataFormats/PatCandidates/interface/TriggerPath.h"
0012   \brief    Analysis-level HLTrigger path class
0013 
0014    TriggerPath implements a container for trigger paths' information within the 'pat' namespace.
0015    For detailed information, consult
0016    https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePATTrigger#TriggerPath
0017 
0018   \author   Volker Adler
0019 */
0020 
0021 #include <string>
0022 #include <vector>
0023 #include <type_traits>
0024 
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 
0030 namespace pat {
0031 
0032   /// Pair to store decision and name of L1 seeds
0033   typedef std::pair<bool, std::string> L1Seed;
0034   /// Collection of L1Seed
0035   typedef std::vector<L1Seed> L1SeedCollection;
0036 
0037   class TriggerPath {
0038     /// Data Members
0039 
0040     /// Path name
0041     std::string name_;
0042     /// Path index in trigger table
0043     unsigned index_;
0044     /// Pre-scale
0045     double prescale_;
0046     /// Was path run?
0047     bool run_;
0048     /// Did path succeed?
0049     bool accept_;
0050     /// Was path in error?
0051     bool error_;
0052     /// List of all module labels in the path
0053     /// filled in correct order by PATTriggerProducer;
0054     /// modules not necessarily in filter collection;
0055     /// consumes disc space
0056     std::vector<std::string> modules_;
0057     /// Indeces of trigger filters in pat::TriggerFilterCollection in event
0058     /// as produced together with the pat::TriggerPathCollection;
0059     /// also filled in correct order by PATTriggerProducer;
0060     /// indices of active filters in filter collection
0061     std::vector<unsigned> filterIndices_;
0062     /// Index of the last active filter in the list of modules
0063     unsigned lastActiveFilterSlot_;
0064     /// Number of modules identified as L3 filters by the 'saveTags' parameter
0065     /// available starting from CMSSW_4_2_3
0066     unsigned l3Filters_;
0067     /// List of L1 seeds and their decisions
0068     L1SeedCollection l1Seeds_;
0069 
0070   public:
0071     /// Constructors and Desctructor
0072 
0073     /// Default constructor
0074     TriggerPath();
0075     /// Constructor from path name only
0076     TriggerPath(const std::string& name);
0077     /// Constructor from values
0078     TriggerPath(const std::string& name,
0079                 unsigned index,
0080                 double prescale,
0081                 bool run,
0082                 bool accept,
0083                 bool error,
0084                 unsigned lastActiveFilterSlot,
0085                 unsigned l3Filters = 0);
0086 
0087     /// Destructor
0088     virtual ~TriggerPath() = default;
0089 
0090     /// Methods
0091 
0092     /// Set the path name
0093     void setName(const std::string& name) { name_ = name; };
0094     /// Set the path index
0095     void setIndex(unsigned index) { index_ = index; };
0096     /// Set the path pre-scale
0097     void setPrescale(double prescale) { prescale_ = prescale; };
0098     /// Set the run flag
0099     void setRun(bool run) { run_ = run; };
0100     /// Set the success flag
0101     void setAccept(bool accept) { accept_ = accept; };
0102     /// Set the error flag
0103     void setError(bool error) { error_ = error; };
0104     /// Set the index of the last active filter
0105     void setLastActiveFilterSlot(unsigned lastActiveFilterSlot) { lastActiveFilterSlot_ = lastActiveFilterSlot; };
0106     /// Set the number of modules identified as L3 filter
0107     void setL3Filters(unsigned l3Filters) { l3Filters_ = l3Filters; };
0108     /// Add a new module label
0109     void addModule(const std::string& name) { modules_.push_back(name); };
0110     /// Add a new trigger fillter collection index
0111     void addFilterIndex(const unsigned index) { filterIndices_.push_back(index); };
0112     /// Add a new L1 seed
0113     void addL1Seed(const L1Seed& seed) { l1Seeds_.push_back(seed); };
0114     void addL1Seed(bool decision, const std::string& expression) { l1Seeds_.push_back(L1Seed(decision, expression)); };
0115     /// Get the path name
0116     const std::string& name() const { return name_; };
0117     /// Get the path index
0118     unsigned index() const { return index_; };
0119     /// Get the path pre-scale
0120     template <typename T = unsigned int>
0121     T prescale() const {
0122       static_assert(std::is_same_v<T, double>,
0123                     "\n\tPlease use prescale<double>"
0124                     "\n\t(other types for prescales are not supported anymore by pat::TriggerPath");
0125       return prescale_;
0126     };
0127     /// Get the run flag
0128     bool wasRun() const { return run_; };
0129     /// Get the success flag
0130     bool wasAccept() const { return accept_; };
0131     /// Get the error flag
0132     bool wasError() const { return error_; };
0133     /// Get the index of the last active filter
0134     unsigned lastActiveFilterSlot() const { return lastActiveFilterSlot_; };
0135     /// Get the number of modules identified as L3 filter
0136     /// available starting from CMSSW_4_2_3
0137     unsigned l3Filters() const { return l3Filters_; };
0138     /// Determines, if the path is a x-trigger, based on the number of modules identified as L3 filter
0139     /// available starting from CMSSW_4_2_3
0140     bool xTrigger() const { return (l3Filters_ > 2); };
0141     /// Get all module labels
0142     const std::vector<std::string>& modules() const { return modules_; };
0143     /// Get all trigger fillter collection indeces
0144     const std::vector<unsigned>& filterIndices() const { return filterIndices_; };
0145     /// Get the index of a certain module;
0146     /// returns size of 'modules_' ( modules().size() ) if name is unknown
0147     /// and -1 if list of modules is not filled
0148     int indexModule(const std::string& name) const;
0149     /// Get all L1 seeds
0150     const L1SeedCollection& l1Seeds() const { return l1Seeds_; };
0151     /// Get names of all L1 seeds with a certain decision
0152     std::vector<std::string> l1Seeds(const bool decision) const;
0153     /// Get names of all succeeding L1 seeds
0154     std::vector<std::string> acceptedL1Seeds() const { return l1Seeds(true); };
0155     /// Get names of all failing L1 seeds
0156     std::vector<std::string> failedL1Seeds() const { return l1Seeds(false); };
0157   };
0158 
0159   /// Collection of TriggerPath
0160   typedef std::vector<TriggerPath> TriggerPathCollection;
0161   /// Persistent reference to an item in a TriggerPathCollection
0162   typedef edm::Ref<TriggerPathCollection> TriggerPathRef;
0163   /// Persistent reference to a TriggerPathCollection product
0164   typedef edm::RefProd<TriggerPathCollection> TriggerPathRefProd;
0165   /// Vector of persistent references to items in the same TriggerPathCollection
0166   typedef edm::RefVector<TriggerPathCollection> TriggerPathRefVector;
0167   /// Const iterator over vector of persistent references to items in the same TriggerPathCollection
0168   typedef edm::RefVectorIterator<TriggerPathCollection> TriggerPathRefVectorIterator;
0169 
0170 }  // namespace pat
0171 
0172 #endif