CMS 3D CMS Logo

HLTDQMTagAndProbeEff.h
Go to the documentation of this file.
1 #ifndef DQMOffline_Trigger_HLTTagAndProbeEff_h
2 #define DQMOffline_Trigger_HLTTagAndProbeEff_h
3 
4 //***************************************************************************
5 //
6 // Description:
7 // This class produces histograms which can be used to make tag&probe efficiencies
8 // for specified HLT filters
9 // These histograms can be binned in various variables
10 //
11 // In a nutshell:
12 // 1) requires the tag trigger to pass for the event
13 // 2) creates a collection of tags, with the tags required to pass the a specified
14 // filter and selection ID. The selection is in the form of a value map calculated
15 // by a previous module. Additional kinematic cuts can be applied (its not limited to
16 // kinematic cuts per se but thats the intention)
17 // 3) likewise creates a collection of probes passing filter, ID and kinematic requirements
18 // 4) applies selection like mass & opp sign to the t&p pair
19 // 5) passes the t&p pair to HLTDQMFilterTnPEffHists, with each one corresponding to a
20 // specific HLT filter whose efficiency we wish to measure. This class then creates the
21 // numerator and denominator histograms for the efficiency calculation done at harvesting
22 //
23 //
24 // Author: Sam Harper (RAL) , 2017
25 //
26 //***************************************************************************
27 
28 
29 
33 
35 
41 
45 
47 
48 #include <vector>
49 #include <string>
50 
51 namespace{
52  template<typename T> edm::Handle<T> getHandle(const edm::Event& event,const edm::EDGetTokenT<T>& token){
54  event.getByToken(token,handle);
55  return handle;
56  }
57 }
58 
59 template <typename TagType,typename TagCollType,typename ProbeType=TagType,typename ProbeCollType=TagCollType>
61 public:
62 
64 
66 
67  void beginRun(const edm::Run& run,const edm::EventSetup& setup);
68  void bookHists(DQMStore::IBooker& iBooker);
69  void fill(const edm::Event& event,const edm::EventSetup& setup);
70 
71 private:
72  template<typename ObjType,typename ObjCollType>
73  std::vector<edm::Ref<ObjCollType> >
74  getPassingRefs(const edm::Handle<ObjCollType>& objCollHandle,
75  const trigger::TriggerEvent& trigEvt,
76  const std::vector<std::string>& filterNames,
77  const bool orFilters,
78  const edm::Handle<edm::ValueMap<bool> >& vidHandle,
79  const VarRangeCutColl<ObjType>& rangeCuts);
80 private:
86 
88 
90 
91  std::vector<std::string> tagFilters_;
92  bool tagFiltersORed_;//true=ORed, false=ANDed
94 
95  std::vector<std::string> probeFilters_;
96  bool probeFiltersORed_;//true=ORed, false=ANDed
98 
100  float minMass_;
101  float maxMass_;
103 
104  std::vector<edm::ParameterSet> histConfigs_;
105  std::vector<HLTDQMFilterTnPEffHists<TagType,ProbeType> > filterHists_;
106 
108 
109 };
110 
111 template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
113  tagRangeCuts_(pset.getParameter<std::vector<edm::ParameterSet> >("tagRangeCuts")),
114  probeRangeCuts_(pset.getParameter<std::vector<edm::ParameterSet> >("probeRangeCuts")),
115  sampleTrigRequirements_(pset.getParameter<edm::ParameterSet>("sampleTrigRequirements"),cc)
116 {
117  edm::InputTag trigEvtTag = pset.getParameter<edm::InputTag>("trigEvent");
118 
119  tagToken_ = cc.consumes<TagCollType>(pset.getParameter<edm::InputTag>("tagColl"));
120  probeToken_ = cc.consumes<ProbeCollType>(pset.getParameter<edm::InputTag>("probeColl"));
121  trigEvtToken_ = cc.consumes<trigger::TriggerEvent>(trigEvtTag);
122  tagVIDToken_ = cc.consumes<edm::ValueMap<bool> >(pset.getParameter<edm::InputTag>("tagVIDCuts"));
123  probeVIDToken_ = cc.consumes<edm::ValueMap<bool> >(pset.getParameter<edm::InputTag>("probeVIDCuts"));
124 
125  hltProcess_ = trigEvtTag.process();
126 
127  tagFilters_ = pset.getParameter<std::vector<std::string> >("tagFilters");
128  tagFiltersORed_ = pset.getParameter<bool>("tagFiltersORed");
129  probeFilters_ = pset.getParameter<std::vector<std::string> >("probeFilters");
130  probeFiltersORed_ = pset.getParameter<bool>("tagFiltersORed");
131 
132  double minDR = pset.getParameter<double>("minTagProbeDR");
133  minTagProbeDR2_ = minDR*minDR;
134  minMass_ = pset.getParameter<double>("minMass");
135  maxMass_ = pset.getParameter<double>("maxMass");
136  requireOpSign_ = pset.getParameter<bool>("requireOpSign");
137 
138  histConfigs_ = pset.getParameter<std::vector<edm::ParameterSet> >("histConfigs");
139  const auto& filterConfigs = pset.getParameter<std::vector<edm::ParameterSet> >("filterConfigs");
140 
141  std::string baseHistName = pset.getParameter<std::string>("baseHistName");
142 
143  for(auto& config: filterConfigs){
145  }
146 }
147 
148 template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
151 {
153  //it does not matter for makePSetDescription whether tag or probe types are used
154  desc.addVPSet("tagRangeCuts",VarRangeCut<TagType>::makePSetDescription(),std::vector<edm::ParameterSet>());
155  desc.addVPSet("probeRangeCuts",VarRangeCut<TagType>::makePSetDescription(),std::vector<edm::ParameterSet>());
156  desc.add<edm::InputTag>("trigEvent",edm::InputTag("hltTriggerSummaryAOD","","HLT"));
157  desc.add<edm::InputTag>("tagColl",edm::InputTag());
158  desc.add<edm::InputTag>("probeColl",edm::InputTag());
159  desc.add<edm::InputTag>("tagVIDCuts",edm::InputTag());
160  desc.add<edm::InputTag>("probeVIDCuts",edm::InputTag());
161  desc.add<std::vector<std::string> >("tagFilters",std::vector<std::string>());
162  desc.add<std::vector<std::string> >("probeFilters",std::vector<std::string>());
163  desc.add<bool>("tagFiltersORed",true);//default to OR probe filters (use case is multiple tag triggers, eg Ele27, Ele32, Ele35 tight etc)
164  desc.add<bool>("probeFiltersORed",false); //default to AND probe filters (cant think why you would want to OR them but made if configurable just in case)
165  desc.add<double>("minTagProbeDR",0);
166  desc.add<double>("minMass");
167  desc.add<double>("maxMass");
168  desc.add<bool>("requireOpSign");
169  desc.addVPSet("histConfigs",HLTDQMFilterTnPEffHists<TagType,ProbeType>::makePSetDescriptionHistConfigs(),std::vector<edm::ParameterSet>());
170  desc.addVPSet("filterConfigs",HLTDQMFilterTnPEffHists<TagType,ProbeType>::makePSetDescription(),std::vector<edm::ParameterSet>());
171  desc.add<std::string>("baseHistName");
172 
173  edm::ParameterSetDescription trigEvtFlagDesc;
174  trigEvtFlagDesc.add<bool>("andOr",false);
175  trigEvtFlagDesc.add<unsigned int>("verbosityLevel",1);
176  trigEvtFlagDesc.add<bool>("andOrDcs", false);
177  trigEvtFlagDesc.add<edm::InputTag>("dcsInputTag", edm::InputTag("scalersRawToDigi") );
178  trigEvtFlagDesc.add<std::vector<int> >("dcsPartitions",{24,25,26,27,28,29});
179  trigEvtFlagDesc.add<bool>("errorReplyDcs", true);
180  trigEvtFlagDesc.add<std::string>("dbLabel","");
181  trigEvtFlagDesc.add<bool>("andOrHlt", true); //true = OR, false = and
182  trigEvtFlagDesc.add<edm::InputTag>("hltInputTag", edm::InputTag("TriggerResults::HLT") );
183  trigEvtFlagDesc.add<std::vector<std::string> >("hltPaths",{});
184  trigEvtFlagDesc.add<std::string>("hltDBKey","");
185  trigEvtFlagDesc.add<bool>("errorReplyHlt",false);
186  desc.add<edm::ParameterSetDescription>("sampleTrigRequirements",trigEvtFlagDesc);
187 
188  return desc;
189 }
190 
191 template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
193 {
194  for(auto& filterHist: filterHists_) filterHist.bookHists(iBooker,histConfigs_);
195 }
196 
197 template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
200 {
202 }
203 
204 
205 template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
207 {
208  auto tagCollHandle = getHandle(event,tagToken_);
209  auto probeCollHandle = getHandle(event,probeToken_);
210  auto trigEvtHandle = getHandle(event,trigEvtToken_);
211  auto tagVIDHandle = getHandle(event,tagVIDToken_);
212  auto probeVIDHandle = getHandle(event,probeVIDToken_);
213 
214  //we need the object collection and trigger info at the minimum
215  if(!tagCollHandle.isValid() || !probeCollHandle.isValid() || !trigEvtHandle.isValid()) return;
216 
217  //if GenericTriggerEventFlag is "off", it'll return true regardless
218  //if so if its off, we auto pass which is the behaviour we wish to have
219  //if its null, we auto fail (because that shouldnt happen)
220  if(sampleTrigRequirements_.accept(event,setup)==false) return;
221 
222  std::vector<edm::Ref<TagCollType> > tagRefs = getPassingRefs(tagCollHandle,*trigEvtHandle,
224  tagVIDHandle,tagRangeCuts_);
225 
226  std::vector<edm::Ref<ProbeCollType> > probeRefs = getPassingRefs(probeCollHandle,*trigEvtHandle,
228  probeVIDHandle,probeRangeCuts_);
229 
230  for(auto& tagRef : tagRefs){
231  float tagEta = tagRef->eta();
232  float tagPhi = tagRef->phi();
233  for(auto& probeRef : probeRefs){
234  //first check if its the same object via its memory localation
235  //note for different collections another method is needed to determine
236  //if the probe and tag are the same object just recoed differently
237  //suggest dR cut (although mass cut should also help here)
238  if(static_cast<const void*>(&*tagRef)==static_cast<const void*>(&*probeRef)) continue;
239  float dR2 = reco::deltaR2(tagEta,tagPhi,probeRef->eta(),probeRef->phi());
240  float mass = (tagRef->p4()+probeRef->p4()).mag();
241  if( ( mass>=minMass_ || minMass_<0 ) &&
242  ( mass<maxMass_ || maxMass_<0 ) &&
243  ( dR2>=minTagProbeDR2_ ) &&
244  ( !requireOpSign_ || tagRef->charge()!=probeRef->charge()) ){
245  for(auto& filterHist : filterHists_){
246  filterHist.fillHists(*tagRef,*probeRef,event,setup,*trigEvtHandle);
247  }
248  }//end of t&p pair cuts
249  }//end of probe loop
250  }//end of tag loop
251 }
252 
253 //yo dawg, I heard you like templates...
254 //okay this might be a little confusing to the student expected to maintain this
255 //here we have a templated function inside a templated class as it needs to be able to take probe or tag types
256 //so this is function of a class HLTDQMTagAndProbeEff<TagType,TagCollType,ProbeType,ProbeCollType>
257 //hence why it needs to specify that those types even if it doesnt use them
258 //However also templated to take a type of ObjCollType
259 //(which we know will either be ProbeCollType or TagCollType but c++ doesnt and therefore it can anything)
260 //this is why there are two seperate template declarations
261 template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
262 template <typename ObjType,typename ObjCollType>
263 std::vector<edm::Ref<ObjCollType> >
266  const trigger::TriggerEvent& trigEvt,
267  const std::vector<std::string>& filterNames,
268  const bool orFilters,
269  const edm::Handle<edm::ValueMap<bool> >& vidHandle,
270  const VarRangeCutColl<ObjType>& rangeCuts)
271 {
272  std::vector<edm::Ref<ObjCollType> > passingRefs;
273  for(size_t objNr=0;objNr<objCollHandle->size();objNr++){
274  edm::Ref<ObjCollType> ref(objCollHandle,objNr);
275  if(rangeCuts(*ref) &&
276  hltdqm::passTrig(ref->eta(),ref->phi(),trigEvt,filterNames,orFilters,hltProcess_) &&
277  (vidHandle.isValid()==false || (*vidHandle)[ref]==true)){
278  passingRefs.push_back(ref);
279  }
280  }
281  return passingRefs;
282 }
283 #endif
T getParameter(std::string const &) const
std::vector< edm::Ref< ObjCollType > > getPassingRefs(const edm::Handle< ObjCollType > &objCollHandle, const trigger::TriggerEvent &trigEvt, const std::vector< std::string > &filterNames, const bool orFilters, const edm::Handle< edm::ValueMap< bool > > &vidHandle, const VarRangeCutColl< ObjType > &rangeCuts)
void beginRun(const edm::Run &run, const edm::EventSetup &setup)
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
void bookHists(DQMStore::IBooker &iBooker)
GenericTriggerEventFlag sampleTrigRequirements_
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
std::vector< std::string > probeFilters_
edm::EDGetTokenT< edm::ValueMap< bool > > probeVIDToken_
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
Definition: config.py:1
std::vector< edm::ParameterSet > histConfigs_
VarRangeCutColl< TagType > tagRangeCuts_
edm::EDGetTokenT< ProbeCollType > probeToken_
edm::EDGetTokenT< trigger::TriggerEvent > trigEvtToken_
bool accept(const edm::Event &event, const edm::EventSetup &setup)
To be called from analyze/filter() methods.
std::vector< HLTDQMFilterTnPEffHists< TagType, ProbeType > > filterHists_
edm::EDGetTokenT< edm::ValueMap< bool > > tagVIDToken_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void fill(const edm::Event &event, const edm::EventSetup &setup)
HLTDQMTagAndProbeEff(const edm::ParameterSet &pset, edm::ConsumesCollector &&cc)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
std::vector< std::string > tagFilters_
std::string const & process() const
Definition: InputTag.h:40
HLT enums.
VarRangeCutColl< ProbeType > probeRangeCuts_
static edm::ParameterSetDescription makePSetDescription()
edm::EDGetTokenT< TagCollType > tagToken_
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
Definition: event.py:1
Definition: Run.h:45
bool passTrig(const float objEta, float objPhi, const trigger::TriggerEvent &trigEvt, const std::string &filterName, const std::string &processName)
Definition: UtilFuncs.h:14