Skip to content

Commit

Permalink
Merge pull request #19375 from Sam-Harper/EgTnPDQMCrossTrigger
Browse files Browse the repository at this point in the history
Adding Cross Trigger Support to E/gamma TnP DQM
  • Loading branch information
cmsbuild authored Jun 26, 2017
2 parents 4fd75fa + a173e4c commit fc51b5b
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 60 deletions.
9 changes: 8 additions & 1 deletion DQMOffline/Trigger/interface/FunctionDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <functional>

#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/EgammaCandidates/interface/Photon.h"

namespace hltdqm {
//here we define needed functions that otherwise dont exist
Expand Down Expand Up @@ -69,7 +70,13 @@ namespace hltdqm {
else if(varName=="hOverE") varFunc = &reco::GsfElectron::hcalOverEcal;
return varFunc;
}

template<>
std::function<float(const reco::Photon&)> getUnaryFuncExtraFloat<reco::Photon>(const std::string& varName){
std::function<float(const reco::Photon&)> varFunc;
if(varName=="scEta") varFunc = scEtaFunc<reco::Photon>;
else if(varName=="hOverE") varFunc = &reco::Photon::hadTowOverEm;
return varFunc;
}

}

Expand Down
11 changes: 6 additions & 5 deletions DQMOffline/Trigger/interface/HLTDQMFilterTnPEffHists.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include <string>

template <typename ObjType>
template <typename TagType,typename ProbeType=TagType>
class HLTDQMFilterTnPEffHists {
public:
HLTDQMFilterTnPEffHists(const edm::ParameterSet& config,
Expand All @@ -35,26 +35,27 @@ class HLTDQMFilterTnPEffHists {
hltProcess_(hltProcess){}

static edm::ParameterSetDescription makePSetDescription(){
edm::ParameterSetDescription desc = HLTDQMFilterEffHists<ObjType>::makePSetDescription();
edm::ParameterSetDescription desc = HLTDQMFilterEffHists<ProbeType>::makePSetDescription();
desc.add<std::string>("tagExtraFilter","");
return desc;
}
static edm::ParameterSetDescription makePSetDescriptionHistConfigs(){
return HLTDQMFilterEffHists<ObjType>::makePSetDescriptionHistConfigs();
return HLTDQMFilterEffHists<ProbeType>::makePSetDescriptionHistConfigs();
}

void bookHists(DQMStore::IBooker& iBooker,const std::vector<edm::ParameterSet>& histConfigs){
histColl_.bookHists(iBooker,histConfigs);
}
void fillHists(const ObjType& tag,const ObjType& probe,
void fillHists(const TagType& tag,const ProbeType& probe,
const edm::Event& event,const edm::EventSetup& setup,
const trigger::TriggerEvent& trigEvt){
if(tagExtraFilter_.empty() || hltdqm::passTrig(tag.eta(),tag.phi(),trigEvt,tagExtraFilter_,hltProcess_)){
histColl_.fillHists(probe,event,setup,trigEvt);
}
}
private:
HLTDQMFilterEffHists<ObjType> histColl_;
//these hists take the probe as input hence they are of ProbeType
HLTDQMFilterEffHists<ProbeType> histColl_;
std::string tagExtraFilter_;
//really wondering whether to put an accessor to HLTDQMFilterEffHists for this
//feels ineligant though so I made another copy here
Expand Down
94 changes: 61 additions & 33 deletions DQMOffline/Trigger/interface/HLTDQMTagAndProbeEff.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@

#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/HLTReco/interface/TriggerEvent.h"
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/HLTReco/interface/TriggerEvent.h"
#include "DataFormats/Math/interface/deltaR.h"

#include "DQMOffline/Trigger/interface/UtilFuncs.h"
#include "DQMOffline/Trigger/interface/VarRangeCutColl.h"
Expand All @@ -55,7 +56,7 @@ namespace{
}
}

template <typename ObjType,typename ObjCollType>
template <typename TagType,typename TagCollType,typename ProbeType=TagType,typename ProbeCollType=TagCollType>
class HLTDQMTagAndProbeEff {
public:

Expand All @@ -68,6 +69,7 @@ class HLTDQMTagAndProbeEff {
void fill(const edm::Event& event,const edm::EventSetup& setup);

private:
template<typename ObjType,typename ObjCollType>
std::vector<edm::Ref<ObjCollType> >
getPassingRefs(const edm::Handle<ObjCollType>& objCollHandle,
const trigger::TriggerEvent& trigEvt,
Expand All @@ -76,7 +78,8 @@ class HLTDQMTagAndProbeEff {
const edm::Handle<edm::ValueMap<bool> >& vidHandle,
const VarRangeCutColl<ObjType>& rangeCuts);
private:
edm::EDGetTokenT<ObjCollType> objToken_;
edm::EDGetTokenT<TagCollType> tagToken_;
edm::EDGetTokenT<ProbeCollType> probeToken_;
edm::EDGetTokenT<trigger::TriggerEvent> trigEvtToken_;
edm::EDGetTokenT<edm::ValueMap<bool> >tagVIDToken_;
edm::EDGetTokenT<edm::ValueMap<bool> >probeVIDToken_;
Expand All @@ -87,32 +90,34 @@ class HLTDQMTagAndProbeEff {

std::vector<std::string> tagFilters_;
bool tagFiltersORed_;//true=ORed, false=ANDed
VarRangeCutColl<ObjType> tagRangeCuts_;
VarRangeCutColl<TagType> tagRangeCuts_;

std::vector<std::string> probeFilters_;
bool probeFiltersORed_;//true=ORed, false=ANDed
VarRangeCutColl<ObjType> probeRangeCuts_;
VarRangeCutColl<ProbeType> probeRangeCuts_;

float minTagProbeDR2_;
float minMass_;
float maxMass_;
bool requireOpSign_;

std::vector<edm::ParameterSet> histConfigs_;
std::vector<HLTDQMFilterTnPEffHists<ObjType> > filterHists_;
std::vector<HLTDQMFilterTnPEffHists<TagType,ProbeType> > filterHists_;

GenericTriggerEventFlag sampleTrigRequirements_;

};

template <typename ObjType,typename ObjCollType>
HLTDQMTagAndProbeEff<ObjType,ObjCollType>::HLTDQMTagAndProbeEff(const edm::ParameterSet& pset,edm::ConsumesCollector && cc):
template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
HLTDQMTagAndProbeEff<TagType,TagCollType,ProbeType,ProbeCollType>::HLTDQMTagAndProbeEff(const edm::ParameterSet& pset,edm::ConsumesCollector && cc):
tagRangeCuts_(pset.getParameter<std::vector<edm::ParameterSet> >("tagRangeCuts")),
probeRangeCuts_(pset.getParameter<std::vector<edm::ParameterSet> >("probeRangeCuts")),
sampleTrigRequirements_(pset.getParameter<edm::ParameterSet>("sampleTrigRequirements"),cc)
{
edm::InputTag trigEvtTag = pset.getParameter<edm::InputTag>("trigEvent");

objToken_ = cc.consumes<ObjCollType>(pset.getParameter<edm::InputTag>("objColl"));
tagToken_ = cc.consumes<TagCollType>(pset.getParameter<edm::InputTag>("tagColl"));
probeToken_ = cc.consumes<ProbeCollType>(pset.getParameter<edm::InputTag>("probeColl"));
trigEvtToken_ = cc.consumes<trigger::TriggerEvent>(trigEvtTag);
tagVIDToken_ = cc.consumes<edm::ValueMap<bool> >(pset.getParameter<edm::InputTag>("tagVIDCuts"));
probeVIDToken_ = cc.consumes<edm::ValueMap<bool> >(pset.getParameter<edm::InputTag>("probeVIDCuts"));
Expand All @@ -124,7 +129,8 @@ HLTDQMTagAndProbeEff<ObjType,ObjCollType>::HLTDQMTagAndProbeEff(const edm::Param
probeFilters_ = pset.getParameter<std::vector<std::string> >("probeFilters");
probeFiltersORed_ = pset.getParameter<bool>("tagFiltersORed");


double minDR = pset.getParameter<double>("minTagProbeDR");
minTagProbeDR2_ = minDR*minDR;
minMass_ = pset.getParameter<double>("minMass");
maxMass_ = pset.getParameter<double>("maxMass");
requireOpSign_ = pset.getParameter<bool>("requireOpSign");
Expand All @@ -135,30 +141,33 @@ HLTDQMTagAndProbeEff<ObjType,ObjCollType>::HLTDQMTagAndProbeEff(const edm::Param
std::string baseHistName = pset.getParameter<std::string>("baseHistName");

for(auto& config: filterConfigs){
filterHists_.emplace_back(HLTDQMFilterTnPEffHists<ObjType>(config,baseHistName,hltProcess_));
filterHists_.emplace_back(HLTDQMFilterTnPEffHists<TagType,ProbeType>(config,baseHistName,hltProcess_));
}
}

template <typename ObjType,typename ObjCollType>
edm::ParameterSetDescription HLTDQMTagAndProbeEff<ObjType,ObjCollType>::
template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
edm::ParameterSetDescription HLTDQMTagAndProbeEff<TagType,TagCollType,ProbeType,ProbeCollType>::
makePSetDescription()
{
edm::ParameterSetDescription desc;
desc.addVPSet("tagRangeCuts",VarRangeCut<ObjType>::makePSetDescription(),std::vector<edm::ParameterSet>());
desc.addVPSet("probeRangeCuts",VarRangeCut<ObjType>::makePSetDescription(),std::vector<edm::ParameterSet>());
//it does not matter for makePSetDescription whether tag or probe types are used
desc.addVPSet("tagRangeCuts",VarRangeCut<TagType>::makePSetDescription(),std::vector<edm::ParameterSet>());
desc.addVPSet("probeRangeCuts",VarRangeCut<TagType>::makePSetDescription(),std::vector<edm::ParameterSet>());
desc.add<edm::InputTag>("trigEvent",edm::InputTag("hltTriggerSummaryAOD","","HLT"));
desc.add<edm::InputTag>("objColl",edm::InputTag());
desc.add<edm::InputTag>("tagColl",edm::InputTag());
desc.add<edm::InputTag>("probeColl",edm::InputTag());
desc.add<edm::InputTag>("tagVIDCuts",edm::InputTag());
desc.add<edm::InputTag>("probeVIDCuts",edm::InputTag());
desc.add<std::vector<std::string> >("tagFilters",std::vector<std::string>());
desc.add<std::vector<std::string> >("probeFilters",std::vector<std::string>());
desc.add<bool>("tagFiltersORed",true);//default to OR probe filters (use case is multiple tag triggers, eg Ele27, Ele32, Ele35 tight etc)
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)
desc.add<double>("minTagProbeDR",0);
desc.add<double>("minMass");
desc.add<double>("maxMass");
desc.add<bool>("requireOpSign");
desc.addVPSet("histConfigs",HLTDQMFilterTnPEffHists<ObjType>::makePSetDescriptionHistConfigs(),std::vector<edm::ParameterSet>());
desc.addVPSet("filterConfigs",HLTDQMFilterTnPEffHists<ObjType>::makePSetDescription(),std::vector<edm::ParameterSet>());
desc.addVPSet("histConfigs",HLTDQMFilterTnPEffHists<TagType,ProbeType>::makePSetDescriptionHistConfigs(),std::vector<edm::ParameterSet>());
desc.addVPSet("filterConfigs",HLTDQMFilterTnPEffHists<TagType,ProbeType>::makePSetDescription(),std::vector<edm::ParameterSet>());
desc.add<std::string>("baseHistName");

edm::ParameterSetDescription trigEvtFlagDesc;
Expand All @@ -179,50 +188,59 @@ makePSetDescription()
return desc;
}

template <typename ObjType,typename ObjCollType>
void HLTDQMTagAndProbeEff<ObjType,ObjCollType>::bookHists(DQMStore::IBooker& iBooker)
template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
void HLTDQMTagAndProbeEff<TagType,TagCollType,ProbeType,ProbeCollType>::bookHists(DQMStore::IBooker& iBooker)
{
for(auto& filterHist: filterHists_) filterHist.bookHists(iBooker,histConfigs_);
}

template <typename ObjType,typename ObjCollType>
void HLTDQMTagAndProbeEff<ObjType,ObjCollType>::
template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
void HLTDQMTagAndProbeEff<TagType,TagCollType,ProbeType,ProbeCollType>::
beginRun(const edm::Run& run,const edm::EventSetup& setup)
{
if(sampleTrigRequirements_.on()) sampleTrigRequirements_.initRun(run,setup);
}


template <typename ObjType,typename ObjCollType>
void HLTDQMTagAndProbeEff<ObjType,ObjCollType>::fill(const edm::Event& event,const edm::EventSetup& setup)
template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
void HLTDQMTagAndProbeEff<TagType,TagCollType,ProbeType,ProbeCollType>::fill(const edm::Event& event,const edm::EventSetup& setup)
{
auto objCollHandle = getHandle(event,objToken_);
auto tagCollHandle = getHandle(event,tagToken_);
auto probeCollHandle = getHandle(event,probeToken_);
auto trigEvtHandle = getHandle(event,trigEvtToken_);
auto tagVIDHandle = getHandle(event,tagVIDToken_);
auto probeVIDHandle = getHandle(event,probeVIDToken_);

//we need the object collection and trigger info at the minimum
if(!objCollHandle.isValid() || !trigEvtHandle.isValid()) return;
if(!tagCollHandle.isValid() || !probeCollHandle.isValid() || !trigEvtHandle.isValid()) return;

//if GenericTriggerEventFlag is "off", it'll return true regardless
//if so if its off, we auto pass which is the behaviour we wish to have
//if its null, we auto fail (because that shouldnt happen)
if(sampleTrigRequirements_.accept(event,setup)==false) return;

std::vector<edm::Ref<ObjCollType> > tagRefs = getPassingRefs(objCollHandle,*trigEvtHandle,
std::vector<edm::Ref<TagCollType> > tagRefs = getPassingRefs(tagCollHandle,*trigEvtHandle,
tagFilters_,tagFiltersORed_,
tagVIDHandle,tagRangeCuts_);

std::vector<edm::Ref<ObjCollType> > probeRefs = getPassingRefs(objCollHandle,*trigEvtHandle,
probeFilters_,probeFiltersORed_,
probeVIDHandle,probeRangeCuts_);
std::vector<edm::Ref<ProbeCollType> > probeRefs = getPassingRefs(probeCollHandle,*trigEvtHandle,
probeFilters_,probeFiltersORed_,
probeVIDHandle,probeRangeCuts_);

for(auto& tagRef : tagRefs){
float tagEta = tagRef->eta();
float tagPhi = tagRef->phi();
for(auto& probeRef : probeRefs){
if(tagRef==probeRef) continue; //otherwise its the same object...
//first check if its the same object via its memory localation
//note for different collections another method is needed to determine
//if the probe and tag are the same object just recoed differently
//suggest dR cut (although mass cut should also help here)
if(static_cast<const void*>(&*tagRef)==static_cast<const void*>(&*probeRef)) continue;
float dR2 = reco::deltaR2(tagEta,tagPhi,probeRef->eta(),probeRef->phi());
float mass = (tagRef->p4()+probeRef->p4()).mag();
if( ( mass>minMass_ || minMass_<0 ) &&
if( ( mass>=minMass_ || minMass_<0 ) &&
( mass<maxMass_ || maxMass_<0 ) &&
( dR2>=minTagProbeDR2_ ) &&
( !requireOpSign_ || tagRef->charge()!=probeRef->charge()) ){
for(auto& filterHist : filterHists_){
filterHist.fillHists(*tagRef,*probeRef,event,setup,*trigEvtHandle);
Expand All @@ -232,8 +250,18 @@ void HLTDQMTagAndProbeEff<ObjType,ObjCollType>::fill(const edm::Event& event,con
}//end of tag loop
}

//yo dawg, I heard you like templates...
//okay this might be a little confusing to the student expected to maintain this
//here we have a templated function inside a templated class as it needs to be able to take probe or tag types
//so this is function of a class HLTDQMTagAndProbeEff<TagType,TagCollType,ProbeType,ProbeCollType>
//hence why it needs to specify that those types even if it doesnt use them
//However also templated to take a type of ObjCollType
//(which we know will either be ProbeCollType or TagCollType but c++ doesnt and therefore it can anything)
//this is why there are two seperate template declarations
template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
template <typename ObjType,typename ObjCollType>
std::vector<edm::Ref<ObjCollType> > HLTDQMTagAndProbeEff<ObjType,ObjCollType>::
std::vector<edm::Ref<ObjCollType> >
HLTDQMTagAndProbeEff<TagType,TagCollType,ProbeType,ProbeCollType>::
getPassingRefs(const edm::Handle<ObjCollType>& objCollHandle,
const trigger::TriggerEvent& trigEvt,
const std::vector<std::string>& filterNames,
Expand Down
37 changes: 25 additions & 12 deletions DQMOffline/Trigger/plugins/HLTTagAndProbeOfflineSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <string>


template <typename ObjType,typename ObjCollType>
template <typename TagType,typename TagCollType,typename ProbeType=TagType,typename ProbeCollType=TagCollType>
class HLTTagAndProbeOfflineSource : public DQMEDAnalyzer {
public:
explicit HLTTagAndProbeOfflineSource(const edm::ParameterSet&);
Expand All @@ -41,43 +41,43 @@ class HLTTagAndProbeOfflineSource : public DQMEDAnalyzer {
virtual void dqmBeginRun(edm::Run const& run, edm::EventSetup const& c) override{}

private:
std::vector<HLTDQMTagAndProbeEff<ObjType,ObjCollType> > tagAndProbeEffs_;
std::vector<HLTDQMTagAndProbeEff<TagType,TagCollType,ProbeType,ProbeCollType> > tagAndProbeEffs_;

};

template <typename ObjType,typename ObjCollType>
HLTTagAndProbeOfflineSource<ObjType,ObjCollType>::
template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
HLTTagAndProbeOfflineSource<TagType,TagCollType,ProbeType,ProbeCollType>::
HLTTagAndProbeOfflineSource(const edm::ParameterSet& config)
{
auto histCollConfigs = config.getParameter<std::vector<edm::ParameterSet> >("tagAndProbeCollections");
for(auto& histCollConfig : histCollConfigs){
tagAndProbeEffs_.emplace_back(HLTDQMTagAndProbeEff<ObjType,ObjCollType>(histCollConfig,consumesCollector()));
tagAndProbeEffs_.emplace_back(HLTDQMTagAndProbeEff<TagType,TagCollType,ProbeType,ProbeCollType>(histCollConfig,consumesCollector()));
}
}


template <typename ObjType,typename ObjCollType>
void HLTTagAndProbeOfflineSource<ObjType,ObjCollType>::
template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
void HLTTagAndProbeOfflineSource<TagType,TagCollType,ProbeType,ProbeCollType>::
fillDescriptions(edm::ConfigurationDescriptions& descriptions)
{
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("objs", edm::InputTag(""));
desc.addVPSet("tagAndProbeCollections",
HLTDQMTagAndProbeEff<ObjType,ObjCollType>::makePSetDescription(),
HLTDQMTagAndProbeEff<TagType,TagCollType,ProbeType,ProbeCollType>::makePSetDescription(),
std::vector<edm::ParameterSet>());
descriptions.add("hltTagAndProbeOfflineSource", desc);

}

template <typename ObjType,typename ObjCollType>
void HLTTagAndProbeOfflineSource<ObjType,ObjCollType>::
template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
void HLTTagAndProbeOfflineSource<TagType,TagCollType,ProbeType,ProbeCollType>::
bookHistograms(DQMStore::IBooker& iBooker,const edm::Run& run,const edm::EventSetup& setup)
{
for(auto& tpEff : tagAndProbeEffs_) tpEff.bookHists(iBooker);
}

template <typename ObjType,typename ObjCollType>
void HLTTagAndProbeOfflineSource<ObjType,ObjCollType>::
template <typename TagType,typename TagCollType,typename ProbeType,typename ProbeCollType>
void HLTTagAndProbeOfflineSource<TagType,TagCollType,ProbeType,ProbeCollType>::
analyze(const edm::Event& event,const edm::EventSetup& setup)
{
for(auto& tpEff : tagAndProbeEffs_) tpEff.fill(event,setup);
Expand All @@ -86,5 +86,18 @@ analyze(const edm::Event& event,const edm::EventSetup& setup)
#include "FWCore/Framework/interface/MakerMacros.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
#include "DataFormats/EgammaCandidates/interface/Photon.h"
#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/MuonReco/interface/MuonFwd.h"
using HLTEleTagAndProbeOfflineSource = HLTTagAndProbeOfflineSource<reco::GsfElectron,reco::GsfElectronCollection>;
using HLTPhoTagAndProbeOfflineSource = HLTTagAndProbeOfflineSource<reco::Photon,reco::PhotonCollection>;
using HLTElePhoTagAndProbeOfflineSource = HLTTagAndProbeOfflineSource<reco::GsfElectron,reco::GsfElectronCollection,reco::Photon,reco::PhotonCollection>;
using HLTMuEleTagAndProbeOfflineSource = HLTTagAndProbeOfflineSource<reco::Muon,reco::MuonCollection,reco::GsfElectron,reco::GsfElectronCollection>;
using HLTMuTagAndProbeOfflineSource = HLTTagAndProbeOfflineSource<reco::Muon,reco::MuonCollection>;
DEFINE_FWK_MODULE(HLTEleTagAndProbeOfflineSource);
DEFINE_FWK_MODULE(HLTPhoTagAndProbeOfflineSource);
DEFINE_FWK_MODULE(HLTElePhoTagAndProbeOfflineSource);
DEFINE_FWK_MODULE(HLTMuEleTagAndProbeOfflineSource);
DEFINE_FWK_MODULE(HLTMuTagAndProbeOfflineSource);

Loading

0 comments on commit fc51b5b

Please sign in to comment.