Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:19

0001 #ifndef DQMOnline_Trigger_HLTDQMHist_h
0002 #define DQMOnline_Trigger_HLTDQMHist_h
0003 
0004 //********************************************************************************
0005 //
0006 // Description:
0007 //   A histogram together with the necessary information to fill it when pass an
0008 //   object and minimal selection cuts. These selection cuts are intended to be
0009 //   simple selections on kinematic variables. There are two levels of these
0010 //   selection cuts, global (which apply to all histograms in the group and passed
0011 //   by the calling function) and   local (which are stored with the histogram
0012 //   and are specific to that histogram. Global selection cuts on the variable being
0013 //   plotted are ignored, for example Et cuts are removed for turn on plots
0014 //
0015 // Implimentation:
0016 //   std::function holds the function which generates the vs variable
0017 //   the name of the vs variable is also stored so we can determine if we should not apply
0018 //   a given selection cut
0019 //   selection is done by VarRangeCutColl
0020 //
0021 // Author : Sam Harper , RAL, May 2017
0022 //
0023 //***********************************************************************************
0024 
0025 #include "DQMOffline/Trigger/interface/FunctionDefs.h"
0026 #include "DQMOffline/Trigger/interface/VarRangeCutColl.h"
0027 
0028 #include "FWCore/Framework/interface/Event.h"
0029 
0030 #include <TH1.h>
0031 #include <TH2.h>
0032 
0033 //our base class for our histograms
0034 //takes an object, edm::Event,edm::EventSetup and fills the histogram
0035 //with the predetermined variable (or varaibles)
0036 template <typename ObjType>
0037 class HLTDQMHist {
0038 public:
0039   HLTDQMHist() = default;
0040   virtual ~HLTDQMHist() = default;
0041   virtual void fill(const ObjType& objType,
0042                     const edm::Event& event,
0043                     const edm::EventSetup& setup,
0044                     const VarRangeCutColl<ObjType>& rangeCuts) = 0;
0045 };
0046 
0047 //this class is a specific implimentation of a HLTDQMHist
0048 //it has the value with which to fill the histogram
0049 //and the histogram itself
0050 //we do not own the histogram
0051 template <typename ObjType, typename ValType>
0052 class HLTDQMHist1D : public HLTDQMHist<ObjType> {
0053 public:
0054   HLTDQMHist1D(TH1* hist,
0055                std::string varName,
0056                std::function<ValType(const ObjType&)> func,
0057                VarRangeCutColl<ObjType> rangeCuts)
0058       : var_(std::move(func)), varName_(std::move(varName)), localRangeCuts_(std::move(rangeCuts)), hist_(hist) {}
0059 
0060   void fill(const ObjType& obj,
0061             const edm::Event& event,
0062             const edm::EventSetup& setup,
0063             const VarRangeCutColl<ObjType>& globalRangeCuts) override {
0064     //local range cuts are specific to a histogram so dont ignore variables
0065     //like global ones (all local cuts should be approprate to the histogram in question
0066     if (globalRangeCuts(obj, varName_) && localRangeCuts_(obj)) {
0067       hist_->Fill(var_(obj));
0068     }
0069   }
0070 
0071 private:
0072   std::function<ValType(const ObjType&)> var_;
0073   std::string varName_;
0074   VarRangeCutColl<ObjType> localRangeCuts_;
0075   TH1* hist_;  //we do not own this
0076 };
0077 
0078 template <typename ObjType, typename XValType, typename YValType = XValType>
0079 class HLTDQMHist2D : public HLTDQMHist<ObjType> {
0080 public:
0081   HLTDQMHist2D(TH2* hist,
0082                std::string xVarName,
0083                std::string yVarName,
0084                std::function<XValType(const ObjType&)> xFunc,
0085                std::function<YValType(const ObjType&)> yFunc,
0086                VarRangeCutColl<ObjType> rangeCuts)
0087       : xVar_(std::move(xFunc)),
0088         yVar_(std::move(yFunc)),
0089         xVarName_(std::move(xVarName)),
0090         yVarName_(std::move(yVarName)),
0091         localRangeCuts_(std::move(rangeCuts)),
0092         hist_(hist) {}
0093 
0094   void fill(const ObjType& obj,
0095             const edm::Event& event,
0096             const edm::EventSetup& setup,
0097             const VarRangeCutColl<ObjType>& globalRangeCuts) override {
0098     //local range cuts are specific to a histogram so dont ignore variables
0099     //like global ones (all local cuts should be approprate to the histogram in question
0100     if (globalRangeCuts(obj, std::vector<std::string>{xVarName_, yVarName_}) && localRangeCuts_(obj)) {
0101       hist_->Fill(xVar_(obj), yVar_(obj));
0102     }
0103   }
0104 
0105 private:
0106   std::function<XValType(const ObjType&)> xVar_;
0107   std::function<YValType(const ObjType&)> yVar_;
0108   std::string xVarName_;
0109   std::string yVarName_;
0110   VarRangeCutColl<ObjType> localRangeCuts_;
0111   TH2* hist_;  //we do not own this
0112 };
0113 
0114 #endif