CMS 3D CMS Logo

HLTHiggsPlotter.cc
Go to the documentation of this file.
1 
9 
11 
12 #include "HLTHiggsPlotter.h"
13 #include "HLTHiggsSubAnalysis.h"
14 #include "EVTColContainer.h"
15 
16 #include "TPRegexp.h"
17 
18 #include <set>
19 #include <cctype>
20 
22  const std::string &hltPath,
23  const std::vector<unsigned int> &objectsType,
24  const unsigned int &NptPlots,
25  const std::vector<double> &NminOneCuts)
26  : _hltPath(hltPath),
27  _hltProcessName(pset.getParameter<std::string>("hltProcessName")),
28  _objectsType(std::set<unsigned int>(objectsType.begin(), objectsType.end())),
29  _nObjects(objectsType.size()),
30  _parametersEta(pset.getParameter<std::vector<double> >("parametersEta")),
31  _parametersPhi(pset.getParameter<std::vector<double> >("parametersPhi")),
32  _parametersTurnOn(pset.getParameter<std::vector<double> >("parametersTurnOn")),
33  _NptPlots(NptPlots),
34  _NminOneCuts(NminOneCuts) {
35  for (std::set<unsigned int>::iterator it = _objectsType.begin(); it != _objectsType.end(); ++it) {
36  // Some parameters extracted from the .py
38  _cutMinPt[*it] = pset.getParameter<double>(std::string(objStr + "_cutMinPt").c_str());
39  _cutMaxEta[*it] = pset.getParameter<double>(std::string(objStr + "_cutMaxEta").c_str());
40  }
41 }
42 
44 
46 
47 void HLTHiggsPlotter::beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {}
48 
49 void HLTHiggsPlotter::bookHistograms(DQMStore::IBooker &ibooker, const bool &useNminOneCuts) {
50  for (std::set<unsigned int>::iterator it = _objectsType.begin(); it != _objectsType.end(); ++it) {
51  std::vector<std::string> sources(2);
52  sources[0] = "gen";
53  sources[1] = "rec";
54  TString maxPt;
55 
56  const std::string objTypeStr = EVTColContainer::getTypeString(*it);
57 
58  for (size_t i = 0; i < sources.size(); i++) {
60 
61  if (useNminOneCuts && *it == EVTColContainer::PFJET) {
62  if (source == "gen")
63  continue;
64  else {
65  // N-1 jet plots (dEtaqq, mqq, dPhibb, CSV1, maxCSV_jets, maxCSV_E, PFMET, pt1, pt2, pt3, pt4)
66  if (_NminOneCuts[0])
67  bookHist(source, objTypeStr, "dEtaqq", ibooker);
68  if (_NminOneCuts[1])
69  bookHist(source, objTypeStr, "mqq", ibooker);
70  if (_NminOneCuts[2])
71  bookHist(source, objTypeStr, "dPhibb", ibooker);
72  if (_NminOneCuts[3]) {
73  if (_NminOneCuts[6])
74  bookHist(source, objTypeStr, "maxCSV", ibooker);
75  else
76  bookHist(source, objTypeStr, "CSV1", ibooker);
77  }
78  if (_NminOneCuts[4])
79  bookHist(source, objTypeStr, "CSV2", ibooker);
80  if (_NminOneCuts[5])
81  bookHist(source, objTypeStr, "CSV3", ibooker);
82  }
83  }
84 
85  bookHist(source, objTypeStr, "Eta", ibooker);
86  bookHist(source, objTypeStr, "Phi", ibooker);
87  for (unsigned int i = 0; i < _NptPlots; i++) {
88  maxPt = "MaxPt";
89  maxPt += i + 1;
90  bookHist(source, objTypeStr, maxPt.Data(), ibooker);
91  }
92  }
93  }
94 }
95 
96 void HLTHiggsPlotter::analyze(const bool &isPassTrigger,
97  const std::string &source,
98  const std::vector<MatchStruct> &matches,
99  const unsigned int &minCandidates) {
100  if (!isPassTrigger) {
101  return;
102  }
103  std::map<unsigned int, int> countobjects;
104  // Initializing the count of the used object
105  for (std::set<unsigned int>::iterator co = _objectsType.begin(); co != _objectsType.end(); ++co) {
106  countobjects[*co] = 0;
107  }
108 
109  int counttotal = 0;
110  const int totalobjectssize2 = _NptPlots * countobjects.size();
111  // Fill the histos if pass the trigger (just the two with higher pt)
112  for (size_t j = 0; j < matches.size(); ++j) {
113  // Is this object owned by this trigger? If not we are not interested...
114  if (_objectsType.find(matches[j].objType) == _objectsType.end()) {
115  continue;
116  }
117 
118  const unsigned int objType = matches[j].objType;
120 
121  float pt = matches[j].pt;
122  float eta = matches[j].eta;
123  float phi = matches[j].phi;
124 
125  TString maxPt;
126  if ((unsigned)countobjects[objType] < _NptPlots) {
127  maxPt = "MaxPt";
128  maxPt += (countobjects[objType] + 1);
129  this->fillHist(isPassTrigger, source, objTypeStr, maxPt.Data(), pt);
130  // Filled the high pt ...
131  ++(countobjects[objType]);
132  ++counttotal;
133  } else {
134  if ((unsigned)countobjects[objType] < minCandidates) { // To get correct results for HZZ
135  ++(countobjects[objType]);
136  ++counttotal;
137  } else
138  continue; // Otherwise too many entries in Eta and Phi distributions
139  }
140 
141  this->fillHist(isPassTrigger, source, objTypeStr, "Eta", eta);
142  this->fillHist(isPassTrigger, source, objTypeStr, "Phi", phi);
143 
144  if (counttotal == totalobjectssize2) {
145  break;
146  }
147  }
148 }
149 
150 void HLTHiggsPlotter::analyze(const bool &isPassTrigger,
151  const std::string &source,
152  const std::vector<MatchStruct> &matches,
153  std::map<std::string, bool> &nMinOne,
154  const float &dEtaqq,
155  const float &mqq,
156  const float &dPhibb,
157  const float &CSV1,
158  const float &CSV2,
159  const float &CSV3,
160  const bool &passAllCuts) {
161  if (!isPassTrigger) {
162  return;
163  }
164  std::map<unsigned int, int> countobjects;
165  // Initializing the count of the used object
166  for (std::set<unsigned int>::iterator co = _objectsType.begin(); co != _objectsType.end(); ++co) {
167  if (!(*co == EVTColContainer::PFJET && source == "gen")) // genJets are not there
168  countobjects[*co] = 0;
169  }
170 
171  int counttotal = 0;
172  const int totalobjectssize2 = _NptPlots * countobjects.size();
173  // Fill the histos if pass the trigger (just the two with higher pt)
174  for (size_t j = 0; j < matches.size(); ++j) {
175  // Is this object owned by this trigger? If not we are not interested...
176  if (_objectsType.find(matches[j].objType) == _objectsType.end()) {
177  continue;
178  }
179 
180  const unsigned int objType = matches[j].objType;
182 
183  float pt = matches[j].pt;
184  float eta = matches[j].eta;
185  float phi = matches[j].phi;
186 
187  // PFMET N-1 cut
188  if (objType == EVTColContainer::PFMET && _NminOneCuts[8] && !nMinOne["PFMET"])
189  continue;
190 
191  TString maxPt;
192  if ((unsigned)(countobjects)[objType] < _NptPlots) {
193  maxPt = "MaxPt";
194  maxPt += (countobjects[objType] + 1);
195  if (objType != EVTColContainer::PFJET || nMinOne[maxPt.Data()]) {
196  this->fillHist(isPassTrigger, source, objTypeStr, maxPt.Data(), pt);
197  }
198  ++(countobjects[objType]);
199  ++counttotal;
200  } else
201  continue; // if not needed (minCandidates == _NptPlots if _useNminOneCuts
202  if (objType != EVTColContainer::PFJET || passAllCuts) {
203  this->fillHist(isPassTrigger, source, objTypeStr, "Eta", eta);
204  this->fillHist(isPassTrigger, source, objTypeStr, "Phi", phi);
205  }
206 
207  if (counttotal == totalobjectssize2) {
208  break;
209  }
210  }
211  if (source == "rec" && _objectsType.find(EVTColContainer::PFJET) != _objectsType.end()) {
212  if (_NminOneCuts[0] && nMinOne["dEtaqq"]) {
213  this->fillHist(isPassTrigger, source, EVTColContainer::getTypeString(EVTColContainer::PFJET), "dEtaqq", dEtaqq);
214  }
215  if (_NminOneCuts[1] && nMinOne["mqq"]) {
216  this->fillHist(isPassTrigger, source, EVTColContainer::getTypeString(EVTColContainer::PFJET), "mqq", mqq);
217  }
218  if (_NminOneCuts[2] && nMinOne["dPhibb"]) {
219  this->fillHist(isPassTrigger, source, EVTColContainer::getTypeString(EVTColContainer::PFJET), "dPhibb", dPhibb);
220  }
221  if (_NminOneCuts[3]) {
222  std::string nameCSVplot = "CSV1";
223  if (_NminOneCuts[6])
224  nameCSVplot = "maxCSV";
225  if (nMinOne[nameCSVplot])
226  this->fillHist(
227  isPassTrigger, source, EVTColContainer::getTypeString(EVTColContainer::PFJET), nameCSVplot, CSV1);
228  }
229  if (_NminOneCuts[4] && nMinOne["CSV2"]) {
230  this->fillHist(isPassTrigger, source, EVTColContainer::getTypeString(EVTColContainer::PFJET), "CSV2", CSV2);
231  }
232  if (_NminOneCuts[5] && nMinOne["CSV3"]) {
233  this->fillHist(isPassTrigger, source, EVTColContainer::getTypeString(EVTColContainer::PFJET), "CSV3", CSV3);
234  }
235  }
236 }
237 
239  const std::string &objType,
240  const std::string &variable,
241  DQMStore::IBooker &ibooker) {
242  std::string sourceUpper = source;
243  sourceUpper[0] = std::toupper(sourceUpper[0]);
245  TH1F *h = nullptr;
246 
247  if (variable.find("MaxPt") != std::string::npos) {
249  if (variable == "MaxPt1")
250  desc = "Leading";
251  else if (variable == "MaxPt2")
252  desc = "Next-to-Leading";
253  else
254  desc = variable.substr(5, 6) + "th Leading";
255  std::string title = "pT of " + desc + " " + sourceUpper + " " + objType +
256  " "
257  "where event pass the " +
258  _hltPath;
259  const size_t nBinsStandard = _parametersTurnOn.size() - 1;
260  size_t nBins = nBinsStandard;
261  float *edges = new float[nBinsStandard + 1];
262  for (size_t i = 0; i < nBinsStandard + 1; i++) {
264  }
265 
267  if (objType == jetObj) {
268  const size_t nBinsJets = 25;
269  nBins = nBinsJets;
270  delete[] edges;
271  edges = new float[nBinsJets + 1];
272  for (size_t i = 0; i < nBinsJets + 1; i++) {
273  edges[i] = i * 10;
274  }
275  }
277  const size_t nBinsJets = 30;
278  nBins = nBinsJets;
279  delete[] edges;
280  edges = new float[nBinsJets + 1];
281  for (size_t i = 0; i < nBinsJets + 1; i++) {
282  edges[i] = i * 10;
283  }
284  }
285  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
286  delete[] edges;
287  } else {
288  if (variable == "dEtaqq") {
289  std::string title = "#Delta #eta_{qq} of " + sourceUpper + " " + objType;
290  int nBins = 20;
291  double min = 0;
292  double max = 4.8;
293  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
294  } else if (variable == "mqq") {
295  std::string title = "m_{qq} of " + sourceUpper + " " + objType;
296  int nBins = 20;
297  double min = 0;
298  double max = 1000;
299  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
300  } else if (variable == "dPhibb") {
301  std::string title = "#Delta #phi_{bb} of " + sourceUpper + " " + objType;
302  int nBins = 10;
303  double min = 0;
304  double max = 3.1416;
305  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
306  } else if (variable == "CSV1") {
307  std::string title = "CSV1 of " + sourceUpper + " " + objType;
308  int nBins = 20;
309  double min = 0;
310  double max = 1;
311  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
312  } else if (variable == "CSV2") {
313  std::string title = "CSV2 of " + sourceUpper + " " + objType;
314  int nBins = 20;
315  double min = 0;
316  double max = 1;
317  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
318  } else if (variable == "CSV3") {
319  std::string title = "CSV3 of " + sourceUpper + " " + objType;
320  int nBins = 20;
321  double min = 0;
322  double max = 1;
323  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
324  } else if (variable == "maxCSV") {
325  std::string title = "max CSV of " + sourceUpper + " " + objType;
326  int nBins = 20;
327  double min = 0;
328  double max = 1;
329  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
330  } else {
331  std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
332  std::string title = symbol + " of " + sourceUpper + " " + objType + " " + "where event pass the " + _hltPath;
333  std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
334 
335  int nBins = (int)params[0];
336  double min = params[1];
337  double max = params[2];
338  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
339  }
340  }
341  h->Sumw2();
342  _elements[name] = ibooker.book1D(name.c_str(), h);
343  delete h;
344 }
345 
346 void HLTHiggsPlotter::fillHist(const bool &passTrigger,
347  const std::string &source,
348  const std::string &objType,
349  const std::string &variable,
350  const float &value) {
351  std::string sourceUpper = source;
352  sourceUpper[0] = toupper(sourceUpper[0]);
354 
355  _elements[name]->Fill(value);
356 }
size
Write out results.
std::map< unsigned int, double > _cutMaxEta
unsigned int _NptPlots
HLTHiggsPlotter(const edm::ParameterSet &pset, const std::string &hltPath, const std::vector< unsigned int > &objectsType, const unsigned int &minCandidates, const std::vector< double > &NminOneCuts)
std::vector< double > _parametersPhi
__host__ __device__ VT * co
Definition: prefixScan.h:47
std::set< unsigned int > _objectsType
std::map< std::string, MonitorElement * > _elements
std::string _hltPath
std::vector< double > _parametersTurnOn
Definition: value.py:1
void fillHist(const bool &passTrigger, const std::string &source, const std::string &objType, const std::string &var, const float &value)
void bookHist(const std::string &source, const std::string &objType, const std::string &variable, DQMStore::IBooker &)
std::vector< double > _parametersEta
void beginRun(const edm::Run &, const edm::EventSetup &)
void bookHistograms(DQMStore::IBooker &, const bool &)
void analyze(const bool &isPassTrigger, const std::string &source, const std::vector< MatchStruct > &matches, const unsigned int &minCandidates)
std::map< unsigned int, double > _cutMinPt
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
static const std::string getTypeString(const unsigned int &objtype)
Tranform types into strings.
static std::string const source
Definition: EdmProvDump.cc:46
std::vector< double > _NminOneCuts
Definition: Run.h:45