Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_PatCandidates_TriggerEvent_h
0002 #define DataFormats_PatCandidates_TriggerEvent_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    PatCandidates
0007 // Class:      pat::TriggerEvent
0008 //
0009 //
0010 /**
0011   \class    pat::TriggerEvent TriggerEvent.h "DataFormats/PatCandidates/interface/TriggerEvent.h"
0012   \brief    Analysis-level trigger event class
0013 
0014    TriggerEvent implements a container for trigger event's information within the 'pat' namespace
0015    and provides the central entry point to all trigger information in the PAT.
0016    For detailed information, consult
0017    https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePATTrigger#TriggerEvent
0018 
0019   \author   Volker Adler
0020 */
0021 
0022 #include "DataFormats/PatCandidates/interface/TriggerAlgorithm.h"
0023 #include "DataFormats/PatCandidates/interface/TriggerCondition.h"
0024 #include "DataFormats/PatCandidates/interface/TriggerPath.h"
0025 #include "DataFormats/PatCandidates/interface/TriggerFilter.h"
0026 #include "DataFormats/PatCandidates/interface/TriggerObject.h"
0027 
0028 #include <string>
0029 #include <vector>
0030 
0031 #include "FWCore/Utilities/interface/InputTag.h"
0032 #include "DataFormats/Common/interface/Handle.h"
0033 #include "DataFormats/Common/interface/OrphanHandle.h"
0034 #include "DataFormats/Candidate/interface/Candidate.h"
0035 #include <cstdint>
0036 
0037 namespace pat {
0038 
0039   class TriggerEvent {
0040     /// Data Members
0041 
0042     /// Name of the L1 trigger menu
0043     std::string nameL1Menu_;
0044     /// Name of the HLT trigger table
0045     std::string nameHltTable_;
0046     /// Was HLT run?
0047     bool run_;
0048     /// Did HLT succeed?
0049     bool accept_;
0050     /// Was HLT in error?
0051     bool error_;
0052     /// PhysicsDeclared GT bit
0053     bool physDecl_;
0054     /// LHC fill number
0055     uint32_t lhcFill_;
0056     /// LHC beam mode
0057     /// as defined in http://bdidev1.cern.ch/bdisoft/operational/abbdisw_wiki/LHC/BST-config --> Beam mode.
0058     uint16_t beamMode_;
0059     /// LHC beam momentum in GeV
0060     uint16_t beamMomentum_;
0061     /// LHC beam 1 intensity in ???
0062     uint32_t intensityBeam1_;
0063     /// LHC beam 2 intensity in ???
0064     uint32_t intensityBeam2_;
0065     /// LHC master status
0066     /// as defined in http://bdidev1.cern.ch/bdisoft/operational/abbdisw_wiki/LHC/BST-config
0067     uint16_t bstMasterStatus_;
0068     /// LHC beam turn counter
0069     uint32_t turnCount_;
0070     /// CMS magnet current in ??? at start of run
0071     float bCurrentStart_;
0072     /// CMS magnet current in ??? at end of run
0073     float bCurrentStop_;
0074     /// CMS magnet current in ??? averaged over run
0075     float bCurrentAvg_;
0076 
0077     /// Member collection related data members
0078     /// Reference to pat::TriggerAlgorithmCollection in event
0079     TriggerAlgorithmRefProd algorithms_;
0080     /// Reference to pat::TriggerConditionCollection in event
0081     TriggerConditionRefProd conditions_;
0082     /// Reference to pat::TriggerPathCollection in event
0083     TriggerPathRefProd paths_;
0084     /// Reference to pat::TriggerAlgorithmCollection in event
0085     TriggerFilterRefProd filters_;
0086     /// Reference to pat::TriggerObjectCollection in event
0087     TriggerObjectRefProd objects_;
0088     /// Table of references to pat::TriggerObjectMatch associations in event
0089     TriggerObjectMatchContainer objectMatchResults_;
0090 
0091   public:
0092     /// Constructors and Desctructor
0093 
0094     /// Default constructor
0095     TriggerEvent();
0096     /// Constructor from values, HLT only
0097     TriggerEvent(
0098         const std::string& nameHltTable, bool run = true, bool accept = true, bool error = false, bool physDecl = true);
0099     /// Constructor from values, HLT and L1/GT
0100     TriggerEvent(const std::string& nameL1Menu,
0101                  const std::string& nameHltTable,
0102                  bool run = true,
0103                  bool accept = true,
0104                  bool error = false,
0105                  bool physDecl = true);
0106 
0107     /// Destructor
0108     virtual ~TriggerEvent(){};
0109 
0110     /// Methods
0111 
0112     /// Trigger event
0113     /// Set the name of the L1 trigger menu
0114     void setNameL1Menu(const std::string& name) { nameL1Menu_ = name; };
0115     /// Set the name of the HLT trigger table
0116     void setNameHltTable(const std::string& name) { nameHltTable_ = name; };
0117     /// Set the run flag
0118     void setRun(bool run) { run_ = run; };
0119     /// Set the success flag
0120     void setAccept(bool accept) { accept_ = accept; };
0121     /// Set the error flag
0122     void setError(bool error) { error_ = error; };
0123     /// Set the PhysicsDeclared GT bit
0124     void setPhysDecl(bool physDecl) { physDecl_ = physDecl; };
0125     /// Set the LHC fill number
0126     void setLhcFill(uint32_t lhcFill) { lhcFill_ = lhcFill; };
0127     /// Set the LHC beam mode
0128     void setBeamMode(uint16_t beamMode) { beamMode_ = beamMode; };
0129     /// Set the LHC beam momentum
0130     void setBeamMomentum(uint16_t beamMomentum) { beamMomentum_ = beamMomentum; };
0131     /// Set the LHC beam 1 intensity
0132     void setIntensityBeam1(uint32_t intensityBeam1) { intensityBeam1_ = intensityBeam1; };
0133     /// Set the LHC beam 2 intensity
0134     void setIntensityBeam2(uint32_t intensityBeam2) { intensityBeam2_ = intensityBeam2; };
0135     /// Set the LHC master status
0136     void setBstMasterStatus(uint16_t bstMasterStatus) { bstMasterStatus_ = bstMasterStatus; };
0137     /// Set the LHC beam turn counter
0138     void setTurnCount(uint32_t turnCount) { turnCount_ = turnCount; };
0139     /// Set the CMS magnet current at start of run
0140     void setBCurrentStart(float bCurrentStart) { bCurrentStart_ = bCurrentStart; };
0141     /// Set the CMS magnet current at end of run
0142     void setBCurrentStop(float bCurrentStop) { bCurrentStop_ = bCurrentStop; };
0143     /// Set the CMS magnet current averaged over run
0144     void setBCurrentAvg(float bCurrentAvg) { bCurrentAvg_ = bCurrentAvg; };
0145     /// Get the name of the L1 trigger menu
0146     const std::string& nameL1Menu() const { return nameL1Menu_; };
0147     /// Get the name of the HLT trigger table
0148     const std::string& nameHltTable() const { return nameHltTable_; };
0149     /// Get the run flag
0150     bool wasRun() const { return run_; };
0151     /// Get the success flag
0152     bool wasAccept() const { return accept_; };
0153     /// Get the error flag
0154     bool wasError() const { return error_; };
0155     /// Get the PhysicsDeclared GT bit
0156     bool wasPhysDecl() const { return physDecl_; };
0157     /// Get the LHC fill number
0158     uint32_t lhcFill() const { return lhcFill_; };
0159     /// Get the LHC beam mode
0160     uint16_t beamMode() const { return beamMode_; };
0161     /// Get the LHC beam momentum
0162     uint16_t beamMomentum() const { return beamMomentum_; };
0163     /// Get the LHC beam 1 intensity
0164     uint32_t intensityBeam1() const { return intensityBeam1_; };
0165     /// Get the LHC beam 2 intensity
0166     uint32_t intensityBeam2() const { return intensityBeam2_; };
0167     /// Get the LHC master status
0168     uint16_t bstMasterStatus() const { return bstMasterStatus_; };
0169     /// Get the LHC beam turn counter
0170     uint32_t turnCount() const { return turnCount_; };
0171     /// Get the CMS magnet current at start of run
0172     float bCurrentStart() const { return bCurrentStart_; };
0173     /// Get the CMS magnet current at end of run
0174     float bCurrentStop() const { return bCurrentStop_; };
0175     /// Get the CMS magnet current averaged over run
0176     float bCurrentAvg() const { return bCurrentAvg_; };
0177 
0178     /// L1 algorithms
0179     /// Set the reference to the pat::TriggerAlgorithmCollection in the event
0180     void setAlgorithms(const edm::Handle<TriggerAlgorithmCollection>& handleTriggerAlgorithms) {
0181       algorithms_ = TriggerAlgorithmRefProd(handleTriggerAlgorithms);
0182     };
0183     /// Get a pointer to all L1 algorithms,
0184     /// returns 0, if RefProd is NULL
0185     const TriggerAlgorithmCollection* algorithms() const { return algorithms_.get(); };
0186     /// Get a vector of references to all L1 algorithms,
0187     /// empty, if RefProd is NULL
0188     const TriggerAlgorithmRefVector algorithmRefs() const;
0189     /// Get a pointer to a certain L1 algorithm by name,
0190     /// returns 0, if algorithm is not found
0191     const TriggerAlgorithm* algorithm(const std::string& nameAlgorithm) const;
0192     /// Get a reference to a certain L1 algorithm by name,
0193     /// NULL, if algorithm is not found
0194     const TriggerAlgorithmRef algorithmRef(const std::string& nameAlgorithm) const;
0195     /// Get the name of a certain L1 algorithm in the event collection by bit number physics or technical (default) algorithms,
0196     /// returns empty string, if algorithm is not found
0197     std::string nameAlgorithm(const unsigned bitAlgorithm, const bool techAlgorithm = true) const;
0198     /// Get the index of a certain L1 algorithm in the event collection by name,
0199     /// returns size of algorithm collection, if algorithm is not found
0200     unsigned indexAlgorithm(const std::string& nameAlgorithm) const;
0201     /// Get a vector of references to all succeeding L1 algorithms
0202     TriggerAlgorithmRefVector acceptedAlgorithms() const;
0203     /// Get a vector of references to all L1 algorithms succeeding on the GTL board
0204     TriggerAlgorithmRefVector acceptedAlgorithmsGtl() const;
0205     /// Get a vector of references to all technical L1 algorithms
0206     TriggerAlgorithmRefVector techAlgorithms() const;
0207     /// Get a vector of references to all succeeding technical L1 algorithms
0208     TriggerAlgorithmRefVector acceptedTechAlgorithms() const;
0209     /// Get a vector of references to all technical L1 algorithms succeeding on the GTL board
0210     TriggerAlgorithmRefVector acceptedTechAlgorithmsGtl() const;
0211     /// Get a vector of references to all physics L1 algorithms
0212     TriggerAlgorithmRefVector physAlgorithms() const;
0213     /// Get a vector of references to all succeeding physics L1 algorithms
0214     TriggerAlgorithmRefVector acceptedPhysAlgorithms() const;
0215     /// Get a vector of references to all physics L1 algorithms succeeding on the GTL board
0216     TriggerAlgorithmRefVector acceptedPhysAlgorithmsGtl() const;
0217 
0218     /// L1 conditions
0219     /// Set the reference to the pat::TriggerConditionCollection in the event
0220     void setConditions(const edm::Handle<TriggerConditionCollection>& handleTriggerConditions) {
0221       conditions_ = TriggerConditionRefProd(handleTriggerConditions);
0222     };
0223     /// Get a pointer to all L1 condition,
0224     /// returns 0, if RefProd is NULL
0225     const TriggerConditionCollection* conditions() const { return conditions_.get(); };
0226     /// Get a vector of references to all L1 conditions,
0227     /// empty, if RefProd is NULL
0228     const TriggerConditionRefVector conditionRefs() const;
0229     /// Get a pointer to a certain L1 condition by name,
0230     /// returns 0, if condition is not found
0231     const TriggerCondition* condition(const std::string& nameCondition) const;
0232     /// Get a reference to a certain L1 condition by name,
0233     /// NULL, if condition is not found
0234     const TriggerConditionRef conditionRef(const std::string& nameCondition) const;
0235     /// Get the index of a certain L1 condition in the event collection by name,
0236     /// returns size of condition collection, if condition is not found
0237     unsigned indexCondition(const std::string& nameCondition) const;
0238     /// Get a vector of references to all succeeding L1 condition
0239     TriggerConditionRefVector acceptedConditions() const;
0240 
0241     /// HLT paths
0242     /// Set the reference to the pat::TriggerPathCollection in the event
0243     void setPaths(const edm::Handle<TriggerPathCollection>& handleTriggerPaths) {
0244       paths_ = TriggerPathRefProd(handleTriggerPaths);
0245     };
0246     /// Get a pointer to all HLT paths,
0247     /// returns 0, if RefProd is NULL
0248     const TriggerPathCollection* paths() const { return paths_.get(); };
0249     /// Get a vector of references to all HLT paths,
0250     /// empty, if RefProd is NULL
0251     const TriggerPathRefVector pathRefs() const;
0252     /// Get a pointer to a certain HLT path by name,
0253     /// returns 0, if algorithm is not found
0254     const TriggerPath* path(const std::string& namePath) const;
0255     /// Get a reference to a certain HLT path by name,
0256     /// NULL, if path is not found
0257     const TriggerPathRef pathRef(const std::string& namePath) const;
0258     /// Get the index of a certain HLT path in the event collection by name,
0259     /// returns size of algorithm collection, if algorithm is not found
0260     unsigned indexPath(const std::string& namePath) const;
0261     /// Get a vector of references to all succeeding HLT paths
0262     TriggerPathRefVector acceptedPaths() const;
0263 
0264     /// HLT filters
0265     /// Set the reference to the pat::TriggerFilterCollection in the event
0266     void setFilters(const edm::Handle<TriggerFilterCollection>& handleTriggerFilters) {
0267       filters_ = TriggerFilterRefProd(handleTriggerFilters);
0268     };
0269     /// Get a pointer to all HLT filters,
0270     /// returns 0, if RefProd is NULL
0271     const TriggerFilterCollection* filters() const { return filters_.get(); };
0272     /// Get a vector of references to all HLT filters,
0273     /// empty, if RefProd is NULL
0274     const TriggerFilterRefVector filterRefs() const;
0275     /// Get a pointer to a certain HLT filter by label,
0276     /// returns 0, if algorithm is not found
0277     const TriggerFilter* filter(const std::string& labelFilter) const;
0278     /// Get a reference to a certain HLT filter by label,
0279     /// NULL, if filter is not found
0280     const TriggerFilterRef filterRef(const std::string& labelFilter) const;
0281     /// Get the index of a certain HLT filter in the event collection by label,
0282     /// returns size of algorithm collection, if algorithm is not found
0283     unsigned indexFilter(const std::string& labelFilter) const;
0284     /// Get a vector of references to all succeeding HLT filters
0285     TriggerFilterRefVector acceptedFilters() const;
0286 
0287     /// Trigger objects
0288     /// Set the reference to the pat::TriggerObjectCollection in the event
0289     void setObjects(const edm::Handle<TriggerObjectCollection>& handleTriggerObjects) {
0290       objects_ = TriggerObjectRefProd(handleTriggerObjects);
0291     };
0292     /// Get a pointer to all trigger objects,
0293     /// returns 0, if RefProd is NULL
0294     const TriggerObjectCollection* objects() const { return objects_.get(); };
0295     /// Get a vector of references to all trigger objects,
0296     /// empty, if RefProd is NULL
0297     const TriggerObjectRefVector objectRefs() const;
0298     /// Get a vector of references to all trigger objects by trigger object type
0299     TriggerObjectRefVector objects(trigger::TriggerObjectType triggerObjectType) const;
0300     TriggerObjectRefVector objects(int triggerObjectType) const {
0301       return objects(trigger::TriggerObjectType(triggerObjectType));
0302     };  // for backward compatibility
0303 
0304     /// L1 x-links
0305     /// Get a vector of references to all conditions assigned to a certain algorithm given by name
0306     TriggerConditionRefVector algorithmConditions(const std::string& nameAlgorithm) const;
0307     /// Checks, if a condition is assigned to a certain algorithm given by name
0308     bool conditionInAlgorithm(const TriggerConditionRef& conditionRef, const std::string& nameAlgorithm) const;
0309     /// Get a vector of references to all algorithms, which have a certain condition assigned
0310     TriggerAlgorithmRefVector conditionAlgorithms(const TriggerConditionRef& conditionRef) const;
0311     /// Get a list of all trigger object collections used in a certain condition given by name
0312     std::vector<std::string> conditionCollections(const std::string& nameAlgorithm) const;
0313     /// Get a vector of references to all objects, which were used in a certain condition given by name
0314     TriggerObjectRefVector conditionObjects(const std::string& nameCondition) const;
0315     /// Checks, if an object was used in a certain condition given by name
0316     bool objectInCondition(const TriggerObjectRef& objectRef, const std::string& nameCondition) const;
0317     /// Get a vector of references to all conditions, which have a certain object assigned
0318     TriggerConditionRefVector objectConditions(const TriggerObjectRef& objectRef) const;
0319     /// Get a vector of references to all objects, which were used in a certain algorithm given by name
0320     TriggerObjectRefVector algorithmObjects(const std::string& nameAlgorithm) const;
0321     /// Checks, if an object was used in a certain algorithm given by name
0322     bool objectInAlgorithm(const TriggerObjectRef& objectRef, const std::string& nameAlgorithm) const;
0323     /// Get a vector of references to all algorithms, which have a certain object assigned
0324     TriggerAlgorithmRefVector objectAlgorithms(const TriggerObjectRef& objectRef) const;
0325 
0326     /// HLT x-links
0327     /// Get a vector of references to all modules assigned to a certain path given by name,
0328     /// setting 'all' to 'false' returns the run filters only.
0329     TriggerFilterRefVector pathModules(const std::string& namePath, bool all = true) const;
0330     /// Get a vector of references to all active HLT filters assigned to a certain path given by name
0331     TriggerFilterRefVector pathFilters(const std::string& namePath, bool firing = true) const;
0332     /// Checks, if a filter is assigned to and was run in a certain path given by name
0333     bool filterInPath(const TriggerFilterRef& filterRef, const std::string& namePath, bool firing = true) const;
0334     /// Get a vector of references to all paths, which have a certain filter assigned
0335     TriggerPathRefVector filterPaths(const TriggerFilterRef& filterRef, bool firing = true) const;
0336     /// Get a list of all trigger object collections used in a certain filter given by name
0337     std::vector<std::string> filterCollections(const std::string& labelFilter) const;
0338     /// Get a vector of references to all objects, which were used in a certain filter given by name
0339     TriggerObjectRefVector filterObjects(const std::string& labelFilter) const;
0340     /// Checks, if an object was used in a certain filter given by name
0341     bool objectInFilter(const TriggerObjectRef& objectRef, const std::string& labelFilter) const;
0342     /// Get a vector of references to all filters, which have a certain object assigned
0343     TriggerFilterRefVector objectFilters(const TriggerObjectRef& objectRef, bool firing = true) const;
0344     /// Get a vector of references to all objects, which were used in a certain path given by name
0345     TriggerObjectRefVector pathObjects(const std::string& namePath, bool firing = true) const;
0346     /// Checks, if an object was used in a certain path given by name
0347     bool objectInPath(const TriggerObjectRef& objectRef, const std::string& namePath, bool firing = true) const;
0348     /// Get a vector of references to all paths, which have a certain object assigned
0349     TriggerPathRefVector objectPaths(const TriggerObjectRef& objectRef, bool firing = true) const;
0350 
0351     /// Add a pat::TriggerObjectMatch association
0352     /// returns 'false', if 'matcher' alreadey exists
0353     bool addObjectMatchResult(const TriggerObjectMatchRefProd& trigMatches, const std::string& labelMatcher);
0354     bool addObjectMatchResult(const edm::Handle<TriggerObjectMatch>& trigMatches, const std::string& labelMatcher) {
0355       return addObjectMatchResult(TriggerObjectMatchRefProd(trigMatches), labelMatcher);
0356     };
0357     bool addObjectMatchResult(const edm::OrphanHandle<TriggerObjectMatch>& trigMatches,
0358                               const std::string& labelMatcher) {
0359       return addObjectMatchResult(TriggerObjectMatchRefProd(trigMatches), labelMatcher);
0360     };
0361     /// Get a list of all linked trigger matches
0362     std::vector<std::string> triggerMatchers() const;
0363     /// Get all trigger matches
0364     const TriggerObjectMatchContainer* triggerObjectMatchResults() const { return &objectMatchResults_; };
0365     /// Get a pointer to a certain trigger match given by label,
0366     /// performs proper "range check" (better than '(*triggerObjectMatchResults())[labelMatcher]'),
0367     /// returns 0, if matcher not found
0368     const TriggerObjectMatch* triggerObjectMatchResult(const std::string& labelMatcher) const;
0369 
0370     /// Further methods are provided by the pat::helper::TriggerMatchHelper in PhysicsTools/PatUtils/interface/TriggerHelper.h
0371   };
0372 
0373 }  // namespace pat
0374 
0375 #endif