test
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  *it == EVTColContainer::MUTRK ) {
88  bookHist(iBooker, source, objTypeStr, "Dxy");
89  }
90  }
91  } else { // reco
92  if ( TString(objTypeStr).Contains("MET") ||
93  TString(objTypeStr).Contains("MHT") ) {
94  bookHist(iBooker, source, objTypeStr, "MaxPt1");
95  bookHist(iBooker, source, objTypeStr, "SumEt");
96  } else {
97  bookHist(iBooker, source, objTypeStr, "MaxPt1");
98  if (!_drop_pt2) bookHist(iBooker, source, objTypeStr, "MaxPt2");
99  if (!_drop_pt3) bookHist(iBooker, source, objTypeStr, "MaxPt3");
100  bookHist(iBooker, source, objTypeStr, "Eta");
101  bookHist(iBooker, source, objTypeStr, "Phi");
102 
103  // If the target is electron or muon,
104  // we will add Dxy plots.
105  if ( *it == EVTColContainer::ELEC ||
106  *it == EVTColContainer::MUON ||
107  *it == EVTColContainer::MUTRK ) {
108  bookHist(iBooker, source, objTypeStr, "Dxy");
109  }
110  }
111  }
112 
113  }
114  }
115 }
116 
117 void HLTExoticaPlotter::analyze(const bool & isPassTrigger,
118  const std::string & source,
119  const std::vector<reco::LeafCandidate> & matches,
120  std::map<int,double> theSumEt,
121  std::vector<float> & dxys)
122 {
123  LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::analyze()";
124  if (!isPassTrigger) {
125  return;
126  }
127 
128  std::map<unsigned int, int> countobjects;
129  // Initializing the count of the used object
130  for (std::set<unsigned int>::iterator co = _objectsType.begin();
131  co != _objectsType.end(); ++co) {
132  countobjects[*co] = 0;
133  }
134 
135  int counttotal = 0;
136 
137  // 3 : pt1, pt2, pt3
138  int totalobjectssize = 1;
139  if (!_drop_pt2) totalobjectssize++;
140  if (!_drop_pt3) totalobjectssize++;
141  totalobjectssize *= countobjects.size();
142  // Fill the histos if pass the trigger (just the two with higher pt)
143  for (size_t j = 0; j < matches.size(); ++j) {
144  // Is this object owned by this trigger? If not we are not interested...
145  if (_objectsType.find(matches[j].pdgId()) == _objectsType.end()) {
146  continue;
147  }
148 
149  const unsigned int objType = matches[j].pdgId();
150  const std::string objTypeStr = EVTColContainer::getTypeString(objType);
151 
152  float pt = matches[j].pt();
153  float eta = matches[j].eta();
154  float phi = matches[j].phi();
155 
156  if ( !( TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT") ) ) {
157  this->fillHist(isPassTrigger, source, objTypeStr, "Eta", eta);
158  this->fillHist(isPassTrigger, source, objTypeStr, "Phi", phi);
159  }
160  else if( source!="gen" ) {
161  if(theSumEt[objType]>=0 && countobjects[objType] == 0) {
162  this->fillHist(isPassTrigger, source, objTypeStr, "SumEt", theSumEt[objType]);
163  }
164  }
165 
166  if ( dxys.size() && (objType == EVTColContainer::ELEC || objType == EVTColContainer::MUON || objType == EVTColContainer::MUTRK) )
167  this->fillHist(isPassTrigger, source, objTypeStr, "Dxy", dxys[j] );
168 
169  if (countobjects[objType] == 0) {
170  if ( !( TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT") ) || source!="gen" ) {
171  this->fillHist(isPassTrigger, source, objTypeStr, "MaxPt1", pt);
172  }
173  // Filled the high pt ...
174  ++(countobjects[objType]);
175  ++counttotal;
176  }
177  else if (countobjects[objType] == 1 && !_drop_pt2) {
178  if( !( TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT") ) ) {
179  this->fillHist(isPassTrigger, source, objTypeStr, "MaxPt2", pt);
180  }
181  // Filled the second high pt ...
182  ++(countobjects[objType]);
183  ++counttotal;
184  }
185  else if (countobjects[objType] == 2 && !_drop_pt3) {
186  if( !( TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT") ) ) {
187  this->fillHist(isPassTrigger, source, objTypeStr, "MaxPt3", pt);
188  }
189  // Filled the third highest pt ...
190  ++(countobjects[objType]);
191  ++counttotal;
192  }
193  else {
194  if (counttotal == totalobjectssize) {
195  break;
196  }
197  }
198 
199  } // end loop over matches
200 }
201 
202 
204  const std::string & source,
205  const std::string & objType,
206  const std::string & variable)
207 {
208  LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::bookHist()";
209  std::string sourceUpper = source;
210  sourceUpper[0] = std::toupper(sourceUpper[0]);
211  std::string name = source + objType + variable + "_" + _hltPath;
212  TH1F * h = 0;
213 
214  if (variable.find("SumEt") != std::string::npos) {
215  std::string title = "Sum ET of " + sourceUpper + " " + objType;
216  const size_t nBins = _parametersTurnOnSumEt.size() - 1;
217  float * edges = new float[nBins + 1];
218  for (size_t i = 0; i < nBins + 1; i++) {
219  edges[i] = _parametersTurnOnSumEt[i];
220  }
221  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
222  delete[] edges;
223  }
224  else if (variable.find("Dxy") != std::string::npos) {
225  std::string title = "Dxy " + sourceUpper + " " + objType;
226  int nBins = _parametersDxy[0];
227  double min = _parametersDxy[1];
228  double max = _parametersDxy[2];
229  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
230  }
231  else if (variable.find("MaxPt") != std::string::npos) {
232  std::string desc = (variable == "MaxPt1") ? "Leading" :
233  (variable == "MaxPt2") ? "Next-to-Leading" : "Next-to-next-to-Leading";
234  std::string title = "pT of " + desc + " " + sourceUpper + " " + objType + " "
235  "where event pass the " + _hltPath;
236  const size_t nBins = _parametersTurnOn.size() - 1;
237  float * edges = new float[nBins + 1];
238  for (size_t i = 0; i < nBins + 1; i++) {
239  edges[i] = _parametersTurnOn[i];
240  }
241  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
242  delete [] edges;
243  }
244 
245  else {
246  std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
247  std::string title = symbol + " of " + sourceUpper + " " + objType + " " +
248  "where event pass the " + _hltPath;
249  std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
250 
251  int nBins = (int)params[0];
252  double min = params[1];
253  double max = params[2];
254  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
255  }
256 
257  h->Sumw2();
258  _elements[name] = iBooker.book1D(name, h);
259  // LogDebug("ExoticaValidation") << " booked histo with name " << name << "\n"
260  // << " at location " << (unsigned long int)_elements[name];
261  delete h;
262 }
263 
264 void HLTExoticaPlotter::fillHist(const bool & passTrigger,
265  const std::string & source,
266  const std::string & objType,
267  const std::string & variable,
268  const float & value)
269 {
270  std::string sourceUpper = source;
271  sourceUpper[0] = toupper(sourceUpper[0]);
272  std::string name = source + objType + variable + "_" + _hltPath;
273 
274  LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::fillHist()" << name << " " << value;
275  _elements[name]->Fill(value);
276  LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::fillHist()" << name << " worked";
277 }
278 
279 
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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
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
#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:43
tuple size
Write out results.
Definition: Run.h:42
std::map< std::string, MonitorElement * > _elements