CMS 3D CMS Logo

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