CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTTauDQMOfflineSource.cc
Go to the documentation of this file.
2 
4 
6 
7 using namespace std;
8 using namespace edm;
9 using namespace reco;
10 using namespace trigger;
11 
12 //
13 // constructors and destructor
14 //
16  hltProcessName_(ps.getUntrackedParameter<std::string>("HLTProcessName","HLT")),
17  triggerResultsSrc_(ps.getUntrackedParameter<edm::InputTag>("TriggerResultsSrc")),
18  triggerResultsToken_(consumes<edm::TriggerResults>(triggerResultsSrc_)),
19  triggerEventSrc_(ps.getUntrackedParameter<edm::InputTag>("TriggerEventSrc")),
20  triggerEventToken_(consumes<trigger::TriggerEvent>(triggerEventSrc_)),
21  pathRegex_(ps.getUntrackedParameter<std::string>("Paths")),
22  nPtBins_(ps.getUntrackedParameter<int>("PtHistoBins", 20)),
23  nEtaBins_(ps.getUntrackedParameter<int>("EtaHistoBins",12)),
24  nPhiBins_(ps.getUntrackedParameter<int>("PhiHistoBins",18)),
25  ptMax_(ps.getUntrackedParameter<double>("PtHistoMax",200)),
26  highPtMax_(ps.getUntrackedParameter<double>("HighPtHistoMax",1000)),
27  l1MatchDr_(ps.getUntrackedParameter<double>("L1MatchDeltaR", 0.5)),
28  hltMatchDr_(ps.getUntrackedParameter<double>("HLTMatchDeltaR", 0.5)),
29  dqmBaseFolder_(ps.getUntrackedParameter<std::string>("DQMBaseFolder")),
30  counterEvt_(0),
31  prescaleEvt_(ps.getUntrackedParameter<int>("prescaleEvt", -1))
32 {
33  edm::ParameterSet matching = ps.getParameter<edm::ParameterSet>("Matching");
34  doRefAnalysis_ = matching.getUntrackedParameter<bool>("doMatching");
35 
36  if(ps.exists("L1Plotter")) {
38  nPhiBins_, ptMax_, highPtMax_, doRefAnalysis_, l1MatchDr_, dqmBaseFolder_));
39  }
40  if(ps.exists("PathSummaryPlotter")) {
42  doRefAnalysis_, dqmBaseFolder_, hltMatchDr_));
43  }
44 
45  if(doRefAnalysis_) {
46  using VPSet = std::vector<edm::ParameterSet>;
47  VPSet matchObjects = matching.getUntrackedParameter<VPSet>("matchFilters");
48  for(const edm::ParameterSet& pset: matchObjects) {
49  refObjects_.push_back(RefObject{pset.getUntrackedParameter<int>("matchObjectID"),
50  consumes<LVColl>(pset.getUntrackedParameter<edm::InputTag>("FilterName"))});
51  }
52  }
53 }
54 
56 }
57 
58 //--------------------------------------------------------
60  //Evaluate configuration for every new trigger menu
61  bool hltMenuChanged = false;
62  if(HLTCP_.init(iRun, iSetup, hltProcessName_, hltMenuChanged)) {
63  LogDebug("HLTTauDQMOffline") << "dqmBeginRun(), hltMenuChanged " << hltMenuChanged;
64  if(hltMenuChanged) {
65  // Find all paths to monitor
66  std::vector<std::string> foundPaths;
67  boost::smatch what;
68  LogDebug("HLTTauDQMOffline") << "Looking for paths with regex " << pathRegex_;
69  for(const std::string& pathName: HLTCP_.triggerNames()) {
70  if(boost::regex_search(pathName, what, pathRegex_)) {
71  LogDebug("HLTTauDQMOffline") << "Found path " << pathName;
72  foundPaths.emplace_back(pathName);
73  }
74  }
75  std::sort(foundPaths.begin(), foundPaths.end());
76 
77  // Construct path plotters
78  std::vector<const HLTTauDQMPath *> pathObjects;
79  pathPlotters_.reserve(foundPaths.size());
80  pathObjects.reserve(foundPaths.size());
81  for(const std::string& pathName: foundPaths) {
83  if(pathPlotters_.back().isValid()) {
84  pathObjects.push_back(pathPlotters_.back().getPathObject());
85  }
86  }
87 
88  // Update paths to the summary plotter
90  pathSummaryPlotter_->setPathObjects(pathObjects);
91  }
92  }
93  } else {
94  edm::LogWarning("HLTTauDQMOffline") << "HLT config extraction failure with process name '" << hltProcessName_ << "'";
95  }
96 }
97 
98 //--------------------------------------------------------
99 void HLTTauDQMOfflineSource::bookHistograms(DQMStore::IBooker &iBooker, const edm::Run& iRun, const EventSetup& iSetup ) {
100  if(l1Plotter_) {
101  l1Plotter_->bookHistograms(iBooker);
102  }
103  for(auto& pathPlotter: pathPlotters_) {
104  pathPlotter.bookHistograms(iBooker);
105  }
106  if(pathSummaryPlotter_) {
107  pathSummaryPlotter_->bookHistograms(iBooker);
108  }
109 }
110 
111 // ----------------------------------------------------------
113  //Apply the prescaler
114  if (counterEvt_ > prescaleEvt_) {
115  //Do Analysis here
116  counterEvt_ = 0;
117 
118  edm::Handle<edm::TriggerResults> triggerResultsHandle;
119  iEvent.getByToken(triggerResultsToken_, triggerResultsHandle);
120  if(!triggerResultsHandle.isValid()) {
121  edm::LogWarning("HLTTauDQMOffline") << "Unable to read edm::TriggerResults with label " << triggerResultsSrc_;
122  return;
123  }
124 
125  edm::Handle<trigger::TriggerEvent> triggerEventHandle;
126  iEvent.getByToken(triggerEventToken_, triggerEventHandle);
127  if(!triggerEventHandle.isValid()) {
128  edm::LogWarning("HLTTauDQMOffline") << "Unable to read trigger::TriggerEvent with label " << triggerEventSrc_;
129  return;
130  }
131 
132  //Create match collections
134  if (doRefAnalysis_) {
135  for(RefObject& refObj: refObjects_) {
136  edm::Handle<LVColl> collHandle;
137  iEvent.getByToken(refObj.token, collHandle);
138  if(!collHandle.isValid())
139  continue;
140 
141  if(refObj.objID == 11) {
142  refC.electrons.insert(refC.electrons.end(), collHandle->begin(), collHandle->end());
143  }
144  else if(refObj.objID == 13) {
145  refC.muons.insert(refC.muons.end(), collHandle->begin(), collHandle->end());
146  }
147  else if(refObj.objID == 15) {
148  refC.taus.insert(refC.taus.end(), collHandle->begin(), collHandle->end());
149  }
150  else if(refObj.objID == 0) {
151  refC.met.insert(refC.met.end(), collHandle->begin(), collHandle->end());
152  }
153  }
154  }
155 
156  //Path Plotters
157  for(auto& pathPlotter: pathPlotters_) {
158  if(pathPlotter.isValid())
159  pathPlotter.analyze(*triggerResultsHandle, *triggerEventHandle, refC);
160  }
161 
162  if(pathSummaryPlotter_ && pathSummaryPlotter_->isValid()) {
163  pathSummaryPlotter_->analyze(*triggerResultsHandle, *triggerEventHandle, refC);
164  }
165 
166  //L1 Plotter
167  if(l1Plotter_ && l1Plotter_->isValid()) {
168  l1Plotter_->analyze(iEvent, iSetup, refC);
169  }
170  } else {
171  counterEvt_++;
172  }
173 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const std::string dqmBaseFolder_
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override
std::vector< LV > electrons
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
std::vector< LV > taus
edm::EDGetTokenT< trigger::TriggerEvent > triggerEventToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
std::vector< RefObject > refObjects_
void bookHistograms(DQMStore::IBooker &iBooker, const edm::Run &r, const edm::EventSetup &c) override
const std::vector< std::string > & triggerNames() const
names of trigger paths
bool exists(std::string const &parameterName) const
checks if a parameter exists
triggerResultsToken_(consumes< edm::TriggerResults >(edm::InputTag("TriggerResults")))
int iEvent
Definition: GenABIO.cc:230
HLTTauDQMOfflineSource(const edm::ParameterSet &)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::vector< HLTTauDQMPathPlotter > pathPlotters_
bool isValid() const
Definition: HandleBase.h:75
std::unique_ptr< HLTTauDQMPathSummaryPlotter > pathSummaryPlotter_
std::vector< LV > met
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
const boost::regex pathRegex_
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
Definition: Run.h:42
std::vector< LV > muons
std::unique_ptr< HLTTauDQML1Plotter > l1Plotter_
void analyze(const edm::Event &e, const edm::EventSetup &c) override