CMS 3D CMS Logo

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