Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:10:22

0001 #ifndef DQM_HLTEvF_TrigObjTnPHistColl_h
0002 #define DQM_HLTEvF_TrigObjTnPHistColl_h
0003 
0004 //********************************************************************************
0005 //
0006 // Description:
0007 //   Manages a set of histograms intended for tag and probe efficiency measurements
0008 //   using TriggerObjects stored in TriggerEvent as the input
0009 //   selection is limited to basic et/eta/phi cuts and trigger filter requirements
0010 //   The idea that this can run on any of the following data formats RAW,RECO,AOD
0011 //   or even as part of the HLT job
0012 //
0013 //   All histograms in a TrigObjTnPHistColl share the same tag defination and
0014 //   currently the same probe et/eta/phi cuts. The tag trigger requirements may be
0015 //   to pass multiple triggers anded or ored together
0016 //
0017 //   The TrigObjTnPHistColl then has a series of histograms which are filled for
0018 //   probes which pass a specified filter. For each specified filter, a set of
0019 //   2D histograms are produced, <var> vs mass where var is configuable via python
0020 //   These histograms may have additional cuts, eg eta cuts which limit them to barrel
0021 //   or endcap
0022 
0023 //   This allows us to get the mass spectrum in each bin to allow signal & bkg fits
0024 //
0025 // Class Structure
0026 //   TrigObjTnPHistColl : master object which manages a series of histograms which
0027 //                        share a common tag defination. It selects tag and probe pairs
0028 //                        and then sends selected probes to fill the relavent histograms
0029 //
0030 //   FilterSelector : specifies and cuts on the trigger filters an object has to pass.
0031 //                    It allows ANDed and ORing of trigger filter requirements.
0032 //                    It acheives this by grouping the filters in sets of filters (FilterSet)
0033 //                    and an object either has to pass all of those filters in the sets or
0034 //                    any of those filters in the set.
0035 //                    An object can then be required to pass all defined FilterSets or any of them
0036 //
0037 //   PathSelector : checks that a given path has fired. Was originally supposed to use instead
0038 //                  GenericTriggerEventFlag but that class was awkward to use in the
0039 //                  concurrentME workflow so PathSelector was created to mimic the required
0040 //                  functionality. It was a quick port of GenericTriggerEventFlag adapted to
0041 //                  to work in our desired workflow and may be replaced/reworked in the future
0042 //
0043 //   TrigObjVarF : allows arbitary access to a given float variable of trigger::TriggerObject
0044 //                 it can also return the abs value of that variable if so requested
0045 //
0046 //   HistFiller : stores the variable a histogram is to be filled with and any cuts the object
0047 //                must additional pass. It then can fill/not fill a histogram using this information
0048 //
0049 //   HistDefs : has all the information necesary to define a histograms to be produced.
0050 //              The Data sub struct containts the HistFiller object, the binning of the
0051 //              histogram and name /title suffexs. There is one set of histogram definations
0052 //              for a TrigObjTnPHistColl so each probe filter has identical binning
0053 //              Each booked histogram contains a local copy of the approprate HistFiller
0054 //
0055 //   HistColl : a collection of histograms to be filled by a probe passing a particular trigger
0056 //              and kinematic selection. Histograms may have additional further selection on the
0057 //              probe (eg limiting to the barrel etc). Each histogram is booked using the central
0058 //              histogram definations and contains a copy of the approprate HistFiller
0059 //
0060 //   ProbeData : a specific filter for a probe object to pass with a collection of histograms to
0061 //               fill managed by HistColl. The filter is not measured by FilterSelector as it is
0062 //               intentionally limited to only a single filter
0063 //
0064 //   TrigObjTnPHistColl : single tag selection and generic requirements for a probe
0065 //      |
0066 //      |--> collection of ProbeData : a set of histos to fill for probes passing a given filter
0067 //              |
0068 //              |--> ProbeData : filter to pass to fill histograms + histograms
0069 //                    |
0070 //                    |--> HistColl : hists for it to be filled
0071 //                           |
0072 //                           |--> collection of HistFillters+their hists, histfillter fills the hist
0073 //
0074 // Author : Sam Harper , RAL, Aug 2018
0075 //
0076 //***********************************************************************************
0077 
0078 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0079 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0080 
0081 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
0082 #include "DQMOffline/Trigger/interface/VarRangeCutColl.h"
0083 #include "DQMServices/Core/interface/DQMStore.h"
0084 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0085 
0086 class TrigObjTnPHistColl {
0087 public:
0088   typedef dqm::legacy::DQMStore DQMStore;
0089   typedef dqm::legacy::MonitorElement MonitorElement;
0090 
0091   class FilterSelector {
0092   public:
0093     class FilterSet {
0094     public:
0095       explicit FilterSet(const edm::ParameterSet& config);
0096       static edm::ParameterSetDescription makePSetDescription();
0097       const trigger::Keys getPassingKeys(const trigger::TriggerEvent& trigEvt) const;
0098 
0099     private:
0100       std::vector<std::string> filters_;
0101       bool isAND_;
0102     };
0103 
0104   public:
0105     explicit FilterSelector(const edm::ParameterSet& config);
0106     static edm::ParameterSetDescription makePSetDescription();
0107     const trigger::Keys getPassingKeys(const trigger::TriggerEvent& trigEvt) const;
0108 
0109   private:
0110     //helper functions
0111     static void mergeTrigKeys(trigger::Keys& keys, const trigger::Keys& keysToMerge, bool isAND);
0112     static void cleanTrigKeys(trigger::Keys& keys);
0113 
0114     std::vector<FilterSet> filterSets_;
0115     bool isAND_;
0116   };
0117 
0118   //A rather late addition to replace GenericTriggerEventFlag as it was incompatible with the
0119   //move to concurrentMEs as GenericTriggerEventFlag owns tokens
0120   //its more or less a direct port of that class, with the functions inspired by it
0121   //obviously much less feature rich, only handles HLT
0122   class PathSelector {
0123   public:
0124     PathSelector(const edm::ParameterSet& config);
0125     static edm::ParameterSetDescription makePSetDescription();
0126     void init(const HLTConfigProvider& hltConfig);
0127     bool operator()(const edm::TriggerResults& trigResults, const edm::TriggerNames& trigNames) const;
0128 
0129   private:
0130     static std::string expandSelectionStr(const std::string& selStr,
0131                                           const HLTConfigProvider& hltConfig,
0132                                           bool isAND,
0133                                           int verbose);
0134     static std::string expandPath(const std::string& pathPattern,
0135                                   const HLTConfigProvider& hltConfig,
0136                                   bool isAND,
0137                                   int verbose);
0138 
0139     std::string selectionStr_;    //with wildcard etc
0140     std::string expandedSelStr_;  //with wildcards expanded, set by init
0141     bool isANDForExpandedPaths_;
0142     int verbose_;
0143     bool isInited_;
0144   };
0145 
0146   class TrigObjVarF {
0147   public:
0148     explicit TrigObjVarF(std::string varName);
0149     float operator()(const trigger::TriggerObject& obj) const {
0150       return isAbs_ ? std::abs((obj.*varFunc_)()) : (obj.*varFunc_)();
0151     }
0152 
0153   private:
0154     float (trigger::TriggerObject::*varFunc_)() const;
0155     bool isAbs_;
0156   };
0157 
0158   class HistFiller {
0159   public:
0160     explicit HistFiller(const edm::ParameterSet& config);
0161     static edm::ParameterSetDescription makePSetDescription();
0162     void operator()(const trigger::TriggerObject& probe, float mass, dqm::reco::MonitorElement* hist) const;
0163 
0164   private:
0165     VarRangeCutColl<trigger::TriggerObject> localCuts_;
0166     TrigObjVarF var_;
0167   };
0168 
0169   //Histogram Defination, defines the histogram (name,title,bins,how its filled)
0170   class HistDefs {
0171   private:
0172     class Data {
0173     public:
0174       explicit Data(const edm::ParameterSet& config);
0175       static edm::ParameterSetDescription makePSetDescription();
0176       dqm::reco::MonitorElement* book(DQMStore::IBooker& iBooker,
0177                                       const std::string& name,
0178                                       const std::string& title,
0179                                       const std::vector<float>& massBins) const;
0180       const HistFiller& filler() const { return histFiller_; }
0181 
0182     private:
0183       HistFiller histFiller_;
0184       std::vector<float> bins_;
0185       std::string nameSuffex_;
0186       std::string titleSuffex_;
0187     };
0188 
0189   public:
0190     explicit HistDefs(const edm::ParameterSet& config);
0191     static edm::ParameterSetDescription makePSetDescription();
0192     std::vector<std::pair<HistFiller, dqm::reco::MonitorElement*> > bookHists(DQMStore::IBooker& iBooker,
0193                                                                               const std::string& name,
0194                                                                               const std::string& title) const;
0195 
0196   private:
0197     std::vector<Data> histData_;
0198     std::vector<float> massBins_;
0199   };
0200 
0201   class HistColl {
0202   public:
0203     HistColl() {}
0204     void bookHists(DQMStore::IBooker& iBooker,
0205                    const std::string& name,
0206                    const std::string& title,
0207                    const HistDefs& histDefs);
0208     void fill(const trigger::TriggerObject& probe, float mass) const;
0209 
0210   private:
0211     std::vector<std::pair<HistFiller, dqm::reco::MonitorElement*> > hists_;
0212   };
0213 
0214   class ProbeData {
0215   public:
0216     explicit ProbeData(std::string probeFilter) : probeFilter_(std::move(probeFilter)) {}
0217     void bookHists(const std::string& tagName, DQMStore::IBooker& iBooker, const HistDefs& histDefs);
0218     void fill(const trigger::size_type tagKey,
0219               const trigger::TriggerEvent& trigEvt,
0220               const VarRangeCutColl<trigger::TriggerObject>& probeCuts) const;
0221 
0222   private:
0223     std::string probeFilter_;
0224     HistColl hists_;
0225   };
0226 
0227 public:
0228   TrigObjTnPHistColl(const edm::ParameterSet& config);
0229   static edm::ParameterSetDescription makePSetDescription();
0230   void init(const HLTConfigProvider& hltConfig) { evtTrigSel_.init(hltConfig); }
0231   void bookHists(DQMStore::IBooker& iBooker);
0232   void fill(const trigger::TriggerEvent& trigEvt,
0233             const edm::TriggerResults& trigResults,
0234             const edm::TriggerNames& trigNames) const;
0235 
0236 private:
0237   //helper function, probably should go in a utilty class
0238   static const trigger::Keys getKeys(const trigger::TriggerEvent& trigEvt, const std::string& filterName);
0239 
0240   VarRangeCutColl<trigger::TriggerObject> tagCuts_, probeCuts_;
0241   FilterSelector tagFilters_;
0242   std::string collName_;
0243   std::string folderName_;
0244   HistDefs histDefs_;
0245   std::vector<ProbeData> probeHists_;
0246   PathSelector evtTrigSel_;
0247 };
0248 
0249 #endif