CMS 3D CMS Logo

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 {
34  doRefAnalysis_ = matching.getUntrackedParameter<bool>("doMatching");
35 
36  if(ps.exists("L1Plotter") && !ps.exists("TagAndProbe")) {
37  l1Plotter_ = std::make_unique<HLTTauDQML1Plotter>(ps.getUntrackedParameter<edm::ParameterSet>("L1Plotter"), consumesCollector(),
39  }
40  if(ps.exists("PathSummaryPlotter")) {
41  pathSummaryPlotter_ = std::make_unique<HLTTauDQMPathSummaryPlotter>(ps.getUntrackedParameter<edm::ParameterSet>("PathSummaryPlotter"),
42  doRefAnalysis_, dqmBaseFolder_, hltMatchDr_);
43  }
44  tagAndProbe_ = false;
45  if(ps.exists("TagAndProbe")) {
46  tagAndProbePaths = ps.getUntrackedParameter<std::vector<edm::ParameterSet> >("TagAndProbe");
47  tagAndProbe_ = true;
48  }
49 
50  if(doRefAnalysis_) {
51  using VPSet = std::vector<edm::ParameterSet>;
52  VPSet matchObjects = matching.getUntrackedParameter<VPSet>("matchFilters");
53  for(const edm::ParameterSet& pset: matchObjects) {
54  refObjects_.push_back(RefObject{pset.getUntrackedParameter<int>("matchObjectID"),
55  consumes<LVColl>(pset.getUntrackedParameter<edm::InputTag>("FilterName"))});
56  }
57  }
58 }
59 
61 
62 //--------------------------------------------------------
64  //Evaluate configuration for every new trigger menu
65  bool hltMenuChanged = false;
66  if(HLTCP_.init(iRun, iSetup, hltProcessName_, hltMenuChanged)) {
67  LogDebug("HLTTauDQMOffline") << "dqmBeginRun(), hltMenuChanged " << hltMenuChanged;
68  if(hltMenuChanged) {
69  if(!tagAndProbe_) {
70  // Find all paths to monitor
71  std::vector<std::string> foundPaths;
72  std::smatch what;
73  LogDebug("HLTTauDQMOffline") << "Looking for paths with regex " << pathRegex_;
74  for(const std::string& pathName: HLTCP_.triggerNames()) {
75  if(std::regex_search(pathName, what, pathRegex_)) {
76  LogDebug("HLTTauDQMOffline") << "Found path " << pathName;
77  foundPaths.emplace_back(pathName);
78  }
79  }
80  std::sort(foundPaths.begin(), foundPaths.end());
81 
82  // Construct path plotters
83  std::vector<const HLTTauDQMPath *> pathObjects;
84  pathPlotters_.reserve(foundPaths.size());
85  pathObjects.reserve(foundPaths.size());
86  for(const std::string& pathName: foundPaths) {
88  if(pathPlotters_.back().isValid()) {
89  pathObjects.push_back(pathPlotters_.back().getPathObject());
90  }
91  }
92 
93  // Update paths to the summary plotter
95  pathSummaryPlotter_->setPathObjects(pathObjects);
96  }
97  }else{ // tag and probe
98  // Find all paths to monitor
99  std::vector<std::string> foundPaths;
100  std::smatch what;
101 
102  for(const edm::ParameterSet& tpset: tagAndProbePaths) {
103  std::vector<std::string> moduleLabels;
104  edm::ParameterSet denpset = tpset.getParameter<edm::ParameterSet>("denominator");
105  std::vector<std::string> denominators = denpset.getParameter<std::vector<std::string> >("hltPaths");
106  std::vector<std::string> updatedDenominators;
107  for(size_t i = 0; i < denominators.size(); ++i){
108  const std::regex denRegex_(denominators[i]);
109  for(const std::string& pathName: HLTCP_.triggerNames()) {
110  if(std::regex_search(pathName, what, denRegex_)) {
111  updatedDenominators.push_back(pathName);
112  moduleLabels = HLTCP_.moduleLabels(pathName);
113  }
114  }
115  }
116  denpset.addParameter<std::vector<std::string> >("hltPaths",updatedDenominators);
117 
118 
119 
120  edm::ParameterSet numpset = tpset.getParameter<edm::ParameterSet>("numerator");
121  std::vector<std::string> numerators = numpset.getParameter<std::vector<std::string> >("hltPaths");
122 
123  const std::regex numRegex_(numerators[0]);
124  for(const std::string& pathName: HLTCP_.triggerNames()) {
125  if(std::regex_search(pathName, what, numRegex_)) {
126 
127  edm::ParameterSet new_tpset = tpset;
128  new_tpset.addParameter<std::string>("name",pathName);
129  std::vector<std::string> updatedHltPaths;
130  updatedHltPaths.push_back(pathName);
131  numpset.addParameter<std::vector<std::string> >("hltPaths",updatedHltPaths);
132  new_tpset.addParameter<edm::ParameterSet>("numerator",numpset);
133  new_tpset.addParameter<edm::ParameterSet>("denominator",denpset);
134 
135  tagandprobePlotters_.emplace_back( new HLTTauDQMTagAndProbePlotter(new_tpset,moduleLabels,dqmBaseFolder_));
136  }
137  }
138  }
139  }
140  }
141  } else {
142  edm::LogWarning("HLTTauDQMOffline") << "HLT config extraction failure with process name '" << hltProcessName_ << "'";
143  }
144 }
145 
146 //--------------------------------------------------------
148  if(l1Plotter_) {
149  l1Plotter_->bookHistograms(iBooker);
150  }
151  for(auto& pathPlotter: pathPlotters_) {
152  pathPlotter.bookHistograms(iBooker);
153  }
154  for(auto& tpPlotter: tagandprobePlotters_) {
155  tpPlotter->bookHistograms(iBooker,iRun,iSetup);
156  }
157  if(pathSummaryPlotter_) {
158  pathSummaryPlotter_->bookHistograms(iBooker);
159  }
160 }
161 
162 // ----------------------------------------------------------
164  //Apply the prescaler
165  if (counterEvt_ > prescaleEvt_) {
166  //Do Analysis here
167  counterEvt_ = 0;
168 
169  edm::Handle<edm::TriggerResults> triggerResultsHandle;
170  iEvent.getByToken(triggerResultsToken_, triggerResultsHandle);
171  if(!triggerResultsHandle.isValid()) {
172  edm::LogWarning("HLTTauDQMOffline") << "Unable to read edm::TriggerResults with label " << triggerResultsSrc_;
173  return;
174  }
175 
176  edm::Handle<trigger::TriggerEvent> triggerEventHandle;
177  iEvent.getByToken(triggerEventToken_, triggerEventHandle);
178  if(!triggerEventHandle.isValid()) {
179  edm::LogWarning("HLTTauDQMOffline") << "Unable to read trigger::TriggerEvent with label " << triggerEventSrc_;
180  return;
181  }
182 
183  //Create match collections
185  if (doRefAnalysis_) {
186  for(RefObject& refObj: refObjects_) {
187  edm::Handle<LVColl> collHandle;
188  iEvent.getByToken(refObj.token, collHandle);
189  if(!collHandle.isValid())
190  continue;
191 
192  if(refObj.objID == 11) {
193  refC.electrons.insert(refC.electrons.end(), collHandle->begin(), collHandle->end());
194  }
195  else if(refObj.objID == 13) {
196  refC.muons.insert(refC.muons.end(), collHandle->begin(), collHandle->end());
197  }
198  else if(refObj.objID == 15) {
199  refC.taus.insert(refC.taus.end(), collHandle->begin(), collHandle->end());
200  }
201  else if(refObj.objID == 0) {
202  refC.met.insert(refC.met.end(), collHandle->begin(), collHandle->end());
203  }
204  }
205  }
206 
207  //Path Plotters
208  for(auto& pathPlotter: pathPlotters_) {
209  if(pathPlotter.isValid())
210  pathPlotter.analyze(*triggerResultsHandle, *triggerEventHandle, refC);
211  }
212 
213  if(pathSummaryPlotter_ && pathSummaryPlotter_->isValid()) {
214  pathSummaryPlotter_->analyze(*triggerResultsHandle, *triggerEventHandle, refC);
215  }
216 
217  //L1 Plotter
218  if(l1Plotter_ && l1Plotter_->isValid()) {
219  l1Plotter_->analyze(iEvent, iSetup, refC);
220  }
221 
222  //Tag and probe plotters
223  for(auto& tpPlotter: tagandprobePlotters_) {
224  if(tpPlotter->isValid())
225  tpPlotter->analyze(iEvent,*triggerResultsHandle, *triggerEventHandle, refC);
226  }
227 
228  } else {
229  counterEvt_++;
230  }
231 }
#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:517
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
std::vector< edm::ParameterSet > tagAndProbePaths
int iEvent
Definition: GenABIO.cc:224
~HLTTauDQMOfflineSource() override
HLTTauDQMOfflineSource(const edm::ParameterSet &)
std::vector< HLTTauDQMPathPlotter > pathPlotters_
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:125
bool isValid() const
Definition: HandleBase.h:74
std::vector< std::unique_ptr< HLTTauDQMTagAndProbePlotter > > tagandprobePlotters_
std::unique_ptr< HLTTauDQMPathSummaryPlotter > pathSummaryPlotter_
std::vector< LV > met
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
fixed size matrix
HLT enums.
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
Definition: Run.h:45
std::vector< LV > muons
std::unique_ptr< HLTTauDQML1Plotter > l1Plotter_
void analyze(const edm::Event &e, const edm::EventSetup &c) override