CMS 3D CMS Logo

HLTExoticaPlotter.cc
Go to the documentation of this file.
1 
5 
9 
10 #include "TPRegexp.h"
11 
13 
14 #include <cctype>
15 #include <set>
16 
18  const std::string &hltPath,
19  const std::vector<unsigned int> &objectsType)
20  : _hltPath(hltPath),
21  _hltProcessName(pset.getParameter<std::string>("hltProcessName")),
22  _objectsType(std::set<unsigned int>(objectsType.begin(), objectsType.end())),
23  _nObjects(objectsType.size()),
24  _parametersEta(pset.getParameter<std::vector<double>>("parametersEta")),
25  _parametersPhi(pset.getParameter<std::vector<double>>("parametersPhi")),
26  _parametersTurnOn(pset.getParameter<std::vector<double>>("parametersTurnOn")),
27  _parametersTurnOnSumEt(pset.getParameter<std::vector<double>>("parametersTurnOnSumEt")),
28  _parametersDxy(pset.getParameter<std::vector<double>>("parametersDxy")),
29  _drop_pt2(false),
30  _drop_pt3(false) {
31  if (pset.exists("dropPt2")) {
32  _drop_pt2 = pset.getParameter<bool>("dropPt2");
33  }
34  if (pset.exists("dropPt3")) {
35  _drop_pt3 = pset.getParameter<bool>("dropPt3");
36  }
37  LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::constructor()";
38 }
39 
41 
43 
45  const edm::Run &iRun,
46  const edm::EventSetup &iSetup) {
47  LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::plotterBookHistos()";
48  for (std::set<unsigned int>::iterator it = _objectsType.begin(); it != _objectsType.end(); ++it) {
49  std::vector<std::string> sources(2);
50  sources[0] = "gen";
51  sources[1] = "rec";
52 
53  const std::string objTypeStr = EVTColContainer::getTypeString(*it);
54 
55  for (size_t i = 0; i < sources.size(); i++) {
57 
58  if (source == "gen") {
59  if (TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT") ||
60  TString(objTypeStr).Contains("Jet")) {
61  continue;
62  } else {
63  bookHist(iBooker, source, objTypeStr, "MaxPt1");
64  if (!_drop_pt2)
65  bookHist(iBooker, source, objTypeStr, "MaxPt2");
66  if (!_drop_pt3)
67  bookHist(iBooker, source, objTypeStr, "MaxPt3");
68  bookHist(iBooker, source, objTypeStr, "Eta");
69  bookHist(iBooker, source, objTypeStr, "Phi");
70 
71  // If the target is electron or muon,
72  // we will add Dxy plots.
74  bookHist(iBooker, source, objTypeStr, "Dxy");
75  }
76  }
77  } else { // reco
78  if (TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT")) {
79  bookHist(iBooker, source, objTypeStr, "MaxPt1");
80  bookHist(iBooker, source, objTypeStr, "SumEt");
81  } else {
82  bookHist(iBooker, source, objTypeStr, "MaxPt1");
83  if (!_drop_pt2)
84  bookHist(iBooker, source, objTypeStr, "MaxPt2");
85  if (!_drop_pt3)
86  bookHist(iBooker, source, objTypeStr, "MaxPt3");
87  bookHist(iBooker, source, objTypeStr, "Eta");
88  bookHist(iBooker, source, objTypeStr, "Phi");
89 
90  // If the target is electron or muon,
91  // we will add Dxy plots.
93  bookHist(iBooker, source, objTypeStr, "Dxy");
94  }
95  }
96  }
97  }
98  }
99 }
100 
101 void HLTExoticaPlotter::analyze(const bool &isPassTrigger,
102  const std::string &source,
103  const std::vector<reco::LeafCandidate> &matches,
104  std::map<int, double> theSumEt,
105  std::vector<float> &dxys) {
106  LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::analyze()";
107  if (!isPassTrigger) {
108  return;
109  }
110 
111  std::map<unsigned int, int> countobjects;
112  // Initializing the count of the used object
113  for (std::set<unsigned int>::iterator co = _objectsType.begin(); co != _objectsType.end(); ++co) {
114  countobjects[*co] = 0;
115  }
116 
117  int counttotal = 0;
118 
119  // 3 : pt1, pt2, pt3
120  int totalobjectssize = 1;
121  if (!_drop_pt2)
122  totalobjectssize++;
123  if (!_drop_pt3)
124  totalobjectssize++;
125  totalobjectssize *= countobjects.size();
126  // Fill the histos if pass the trigger (just the two with higher pt)
127  unsigned int jaux = 0;
128  // jaux is being used as a dedicated counter to avoid getting
129  // a non-existent element inside dxys
130  // more information in the issue https://github.com/cms-sw/cmssw/issues/32550
131  for (size_t j = 0; j < matches.size(); ++j) {
132  // Is this object owned by this trigger? If not we are not interested...
133  if (_objectsType.find(matches[j].pdgId()) == _objectsType.end()) {
134  ++jaux;
135  continue;
136  }
137 
138  const unsigned int objType = matches[j].pdgId();
140 
141  float pt = matches[j].pt();
142  float eta = matches[j].eta();
143  float phi = matches[j].phi();
144 
145  if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
146  this->fillHist(isPassTrigger, source, objTypeStr, "Eta", eta);
147  this->fillHist(isPassTrigger, source, objTypeStr, "Phi", phi);
148  } else if (source != "gen") {
149  if (theSumEt[objType] >= 0 && countobjects[objType] == 0) {
150  this->fillHist(isPassTrigger, source, objTypeStr, "SumEt", theSumEt[objType]);
151  }
152  }
153 
154  if (!dxys.empty() &&
156  this->fillHist(isPassTrigger, source, objTypeStr, "Dxy", dxys[jaux]);
157  ++jaux;
158  }
159 
160  if (countobjects[objType] == 0) {
161  if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT")) || source != "gen") {
162  this->fillHist(isPassTrigger, source, objTypeStr, "MaxPt1", pt);
163  }
164  // Filled the high pt ...
165  ++(countobjects[objType]);
166  ++counttotal;
167  } else if (countobjects[objType] == 1 && !_drop_pt2) {
168  if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
169  this->fillHist(isPassTrigger, source, objTypeStr, "MaxPt2", pt);
170  }
171  // Filled the second high pt ...
172  ++(countobjects[objType]);
173  ++counttotal;
174  } else if (countobjects[objType] == 2 && !_drop_pt3) {
175  if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
176  this->fillHist(isPassTrigger, source, objTypeStr, "MaxPt3", pt);
177  }
178  // Filled the third highest pt ...
179  ++(countobjects[objType]);
180  ++counttotal;
181  } else {
182  if (counttotal == totalobjectssize) {
183  break;
184  }
185  }
186 
187  } // end loop over matches
188 }
189 
191  const std::string &source,
192  const std::string &objType,
193  const std::string &variable) {
194  LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::bookHist()";
195  std::string sourceUpper = source;
196  sourceUpper[0] = std::toupper(sourceUpper[0]);
198  TH1F *h = nullptr;
199 
200  if (variable.find("SumEt") != std::string::npos) {
201  std::string title = "Sum ET of " + sourceUpper + " " + objType;
202  const size_t nBins = _parametersTurnOnSumEt.size() - 1;
203  float *edges = new float[nBins + 1];
204  for (size_t i = 0; i < nBins + 1; i++) {
206  }
207  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
208  delete[] edges;
209  } else if (variable.find("Dxy") != std::string::npos) {
210  std::string title = "Dxy " + sourceUpper + " " + objType;
211  int nBins = _parametersDxy[0];
212  double min = _parametersDxy[1];
213  double max = _parametersDxy[2];
214  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
215  } else if (variable.find("MaxPt") != std::string::npos) {
216  std::string desc; //=
217  // (variable == "MaxPt1") ? "Leading" : (variable == "MaxPt2") ? "Next-to-Leading" : "Next-to-next-to-Leading";
218  if (variable == "MaxPt1") {
219  desc = "Leading";
220  } else if (variable == "MaxPt2") {
221  desc = "Next-to-Leading";
222  } else {
223  desc = "Next-to-next-to-Leading";
224  }
225  std::string title = "pT of " + desc + " " + sourceUpper + " " + objType +
226  " "
227  "where event pass the " +
228  _hltPath;
229  const size_t nBins = _parametersTurnOn.size() - 1;
230  float *edges = new float[nBins + 1];
231  for (size_t i = 0; i < nBins + 1; i++) {
233  }
234  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
235  delete[] edges;
236  }
237 
238  else {
239  std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
240  std::string title = symbol + " of " + sourceUpper + " " + objType + " " + "where event pass the " + _hltPath;
241  std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
242 
243  int nBins = (int)params[0];
244  double min = params[1];
245  double max = params[2];
246  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
247  }
248 
249  h->Sumw2();
250  _elements[name] = iBooker.book1D(name, h);
251  // LogDebug("ExoticaValidation") << " booked histo
252  // with name " << name << "\n"
253  // << " at location " <<
254  //(unsigned long int)_elements[name];
255  delete h;
256 }
257 
258 void HLTExoticaPlotter::fillHist(const bool &passTrigger,
259  const std::string &source,
260  const std::string &objType,
261  const std::string &variable,
262  const float &value) {
263  std::string sourceUpper = source;
264  sourceUpper[0] = toupper(sourceUpper[0]);
266 
267  LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::fillHist()" << name << " " << value;
268  _elements[name]->Fill(value);
269  LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::fillHist()" << name << " worked";
270 }
size
Write out results.
void plotterBookHistos(DQMStore::IBooker &iBooker, const edm::Run &iRun, const edm::EventSetup &iSetup)
std::set< unsigned int > _objectsType
std::vector< double > _parametersDxy
__host__ __device__ VT * co
Definition: prefixScan.h:47
std::vector< double > _parametersTurnOnSumEt
HLTExoticaPlotter(const edm::ParameterSet &pset, const std::string &hltPath, const std::vector< unsigned int > &objectsType)
std::vector< double > _parametersEta
Definition: value.py:1
std::vector< double > _parametersTurnOn
void fillHist(const bool &passTrigger, const std::string &source, const std::string &objType, const std::string &var, const float &value)
std::vector< double > _parametersPhi
void bookHist(DQMStore::IBooker &iBooker, const std::string &source, const std::string &objType, const std::string &variable)
void analyze(const bool &isPassTrigger, const std::string &source, const std::vector< reco::LeafCandidate > &matches, std::map< int, double > theSumEt, std::vector< float > &dxys)
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:49
Definition: Run.h:45
std::map< std::string, MonitorElement * > _elements
#define LogDebug(id)