CMS 3D CMS Logo

FlavourHistorgrams2D.h
Go to the documentation of this file.
1 
2 #ifndef FlavourHistograms2D_H
3 #define FlavourHistograms2D_H
4 
7 
8 // #include "BTagPlotPrintC.h"
9 
10 #include "TH2F.h"
11 #include "TProfile.h"
12 #include "TCanvas.h"
13 #include "TROOT.h"
14 #include "TSystem.h"
15 #include "TStyle.h"
16 
19 
20 #include <iostream>
21 #include <vector>
22 #include <string>
23 
24 //
25 // class to describe Histo
26 //
27 template <class T, class G>
29 public:
32 
33  FlavourHistograms2D(TString baseNameTitle_,
34  TString baseNameDescription_,
35  int nBinsX_,
36  double lowerBoundX_,
37  double upperBoundX_,
38  int nBinsY_,
39  double lowerBoundY_,
40  double upperBoundY_,
42  unsigned int mc,
43  bool createProfile,
44  DQMStore::IGetter &iget);
45 
46  FlavourHistograms2D(TString baseNameTitle_,
47  TString baseNameDescription_,
48  int nBinsX_,
49  double lowerBoundX_,
50  double upperBoundX_,
51  int nBinsY_,
52  double lowerBoundY_,
53  double upperBoundY_,
54  bool statistics_,
56  unsigned int mc,
57  bool createProfile,
58  DQMStore::IBooker &ibook);
59 
60  virtual ~FlavourHistograms2D();
61 
62  // define arrays (if needed)
63  // void defineArray ( int * dimension , int max , int indexToPlot ) ;
64 
65  // fill entry
66  // For single variables and arrays (for arrays only a single index can be filled)
67  void fill(const int &flavour, const T &variableX, const G &variableY) const;
68  void fill(const int &flavour, const T &variableX, const G &variableY, const float &w) const;
69 
70  // For single variables and arrays
71  void fill(const int &flavour, const T *variableX, const G *variableY) const;
72  void fill(const int &flavour, const T *variableX, const G *variableY, const float &w) const;
73 
74  void settitle(const char *titleX, const char *titleY);
75 
76  void plot(TPad *theCanvas = nullptr);
77  void epsPlot(const std::string &name);
78 
79  // needed for efficiency computations -> this / b
80  // (void : alternative would be not to overwrite the histos but to return a cloned HistoDescription)
81  void divide(const FlavourHistograms2D<T, G> &bHD) const;
82  void setEfficiencyFlag();
83 
84  inline void SetMaximum(const double &max) { theMax = max; }
85  inline void SetMinimum(const double &min) { theMin = min; }
86 
87  // trivial access functions
88  inline std::string baseNameTitle() const { return theBaseNameTitle; }
90  inline int nBinsX() const { return theNBinsX; }
91  inline int nBinsY() const { return theNBinsY; }
92  inline double lowerBoundX() const { return theLowerBoundX; }
93  inline double upperBoundX() const { return theUpperBoundX; }
94  inline double lowerBoundY() const { return theLowerBoundY; }
95  inline double upperBoundY() const { return theUpperBoundY; }
96  inline bool statistics() const { return theStatistics; }
97 
98  // access to the histos
99  inline TH2F *histo_all() const { return theHisto_all->getTH2F(); }
100  inline TH2F *histo_d() const { return theHisto_d->getTH2F(); }
101  inline TH2F *histo_u() const { return theHisto_u->getTH2F(); }
102  inline TH2F *histo_s() const { return theHisto_s->getTH2F(); }
103  inline TH2F *histo_c() const { return theHisto_c->getTH2F(); }
104  inline TH2F *histo_b() const { return theHisto_b->getTH2F(); }
105  inline TH2F *histo_g() const { return theHisto_g->getTH2F(); }
106  inline TH2F *histo_ni() const { return theHisto_ni->getTH2F(); }
107  inline TH2F *histo_dus() const { return theHisto_dus->getTH2F(); }
108  inline TH2F *histo_dusg() const { return theHisto_dusg->getTH2F(); }
109  inline TH2F *histo_pu() const { return theHisto_pu->getTH2F(); }
110 
111  TProfile *profile_all() const { return theProfile_all->getTProfile(); }
112  TProfile *profile_d() const { return theProfile_d->getTProfile(); }
113  TProfile *profile_u() const { return theProfile_u->getTProfile(); }
114  TProfile *profile_s() const { return theProfile_s->getTProfile(); }
115  TProfile *profile_c() const { return theProfile_c->getTProfile(); }
116  TProfile *profile_b() const { return theProfile_b->getTProfile(); }
117  TProfile *profile_g() const { return theProfile_g->getTProfile(); }
118  TProfile *profile_ni() const { return theProfile_ni->getTProfile(); }
119  TProfile *profile_dus() const { return theProfile_dus->getTProfile(); }
120  TProfile *profile_dusg() const { return theProfile_dusg->getTProfile(); }
121  TProfile *profile_pu() const { return theProfile_pu->getTProfile(); }
122 
123  std::vector<TH2F *> getHistoVector() const;
124 
125  std::vector<TProfile *> getProfileVector() const;
126 
127 protected:
128  void fillVariable(const int &flavour, const T &varX, const G &varY, const float &w) const;
129 
130  //
131  // the data members
132  //
133 
134  // T * theVariable ;
135 
136  // for arrays
139  int theIndexToPlot; // in case that not the complete array has to be plotted
140 
150  double theMin, theMax;
151 
152  // the histos
164 
165  // the profiles
177 
178  // DQMStore * dqmStore_;
179 
180  // the canvas to plot
181 private:
183 
184  unsigned int mcPlots_;
186 };
187 
188 template <class T, class G>
190  TString baseNameDescription_,
191  int nBinsX_,
192  double lowerBoundX_,
193  double upperBoundX_,
194  int nBinsY_,
195  double lowerBoundY_,
196  double upperBoundY_,
198  unsigned int mc,
199  bool createProfile,
200  DQMStore::IGetter &iget)
201  : // BaseFlavourHistograms2D () ,
202  // theVariable ( variable_ ) ,
203  theMaxDimension(-1),
204  theIndexToPlot(-1),
205  theBaseNameTitle(baseNameTitle_.Data()),
206  theBaseNameDescription(baseNameDescription_.Data()),
207  theNBinsX(nBinsX_),
208  theNBinsY(nBinsY_),
209  theLowerBoundX(lowerBoundX_),
210  theUpperBoundX(upperBoundX_),
211  theLowerBoundY(lowerBoundY_),
212  theUpperBoundY(upperBoundY_),
213  theMin(-1.),
214  theMax(-1.),
215  mcPlots_(mc),
216  createProfile_(createProfile) {
217  // defaults for array dimensions
218  theArrayDimension = nullptr;
219 
220  if (mcPlots_ % 2 == 0)
221  theHisto_all = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "ALL");
222  else
223  theHisto_all = nullptr;
224  if (mcPlots_) {
225  if (mcPlots_ > 2) {
226  theHisto_d = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "D");
227  theHisto_u = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "U");
228  theHisto_s = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "S");
229  theHisto_g = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "G");
230  theHisto_dus = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "DUS");
231  } else {
232  theHisto_d = nullptr;
233  theHisto_u = nullptr;
234  theHisto_s = nullptr;
235  theHisto_g = nullptr;
236  theHisto_dus = nullptr;
237  }
238  theHisto_c = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "C");
239  theHisto_b = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "B");
240  theHisto_ni = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "NI");
241  theHisto_dusg = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "DUSG");
242  theHisto_pu = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "PU");
243  } else {
244  theHisto_d = nullptr;
245  theHisto_u = nullptr;
246  theHisto_s = nullptr;
247  theHisto_c = nullptr;
248  theHisto_b = nullptr;
249  theHisto_g = nullptr;
250  theHisto_ni = nullptr;
251  theHisto_dus = nullptr;
252  theHisto_dusg = nullptr;
253  theHisto_pu = nullptr;
254  }
255 
256  if (createProfile_) {
257  if (mcPlots_ % 2 == 0)
258  theProfile_all = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "_Profile_ALL");
259  else
260  theProfile_all = nullptr;
261  if (mcPlots_) {
262  if (mcPlots_ > 2) {
263  theProfile_d = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "_Profile_D");
264  theProfile_u = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "_Profile_U");
265  theProfile_s = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "_Profile_S");
266  theProfile_g = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "_Profile_G");
267  theProfile_dus = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "_Profile_DUS");
268  } else {
269  theProfile_d = nullptr;
270  theProfile_u = nullptr;
271  theProfile_s = nullptr;
272  theProfile_g = nullptr;
273  theProfile_dus = nullptr;
274  }
275  theProfile_c = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "_Profile_C");
276  theProfile_b = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "_Profile_B");
277  theProfile_ni = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "_Profile_NI");
278  theProfile_dusg = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "_Profile_DUSG");
279  theProfile_pu = iget.get("Btag/" + folder + "/" + theBaseNameTitle + "_Profile_PU");
280  } else {
281  theProfile_d = nullptr;
282  theProfile_u = nullptr;
283  theProfile_s = nullptr;
284  theProfile_c = nullptr;
285  theProfile_b = nullptr;
286  theProfile_g = nullptr;
287  theProfile_ni = nullptr;
288  theProfile_dus = nullptr;
289  theProfile_dusg = nullptr;
290  theProfile_pu = nullptr;
291  }
292  } else {
293  theProfile_all = nullptr;
294  theProfile_d = nullptr;
295  theProfile_u = nullptr;
296  theProfile_s = nullptr;
297  theProfile_c = nullptr;
298  theProfile_b = nullptr;
299  theProfile_g = nullptr;
300  theProfile_ni = nullptr;
301  theProfile_dus = nullptr;
302  theProfile_dusg = nullptr;
303  theProfile_pu = nullptr;
304  }
305 }
306 
307 template <class T, class G>
309  TString baseNameDescription_,
310  int nBinsX_,
311  double lowerBoundX_,
312  double upperBoundX_,
313  int nBinsY_,
314  double lowerBoundY_,
315  double upperBoundY_,
316  bool statistics_,
318  unsigned int mc,
319  bool createProfile,
320  DQMStore::IBooker &ibook)
321  : theMaxDimension(-1),
322  theIndexToPlot(-1),
323  theBaseNameTitle(baseNameTitle_.Data()),
324  theBaseNameDescription(baseNameDescription_.Data()),
325  theNBinsX(nBinsX_),
326  theNBinsY(nBinsY_),
327  theLowerBoundX(lowerBoundX_),
328  theUpperBoundX(upperBoundX_),
329  theLowerBoundY(lowerBoundY_),
330  theUpperBoundY(upperBoundY_),
331  theStatistics(statistics_),
332  theMin(-1.),
333  theMax(-1.),
334  mcPlots_(mc),
335  createProfile_(createProfile) {
336  // defaults for array dimensions
337  theArrayDimension = nullptr;
338 
339  // book histos
340  HistoProviderDQM prov("Btag", folder, ibook);
341  if (mcPlots_ % 2 == 0)
342  theHisto_all = (prov.book2D(theBaseNameTitle + "ALL",
343  theBaseNameDescription + " all jets",
344  theNBinsX,
347  theNBinsY,
349  theUpperBoundY));
350  else
351  theHisto_all = nullptr;
352  if (mcPlots_) {
353  if (mcPlots_ > 2) {
354  theHisto_d = (prov.book2D(theBaseNameTitle + "D",
355  theBaseNameDescription + " d-jets",
356  theNBinsX,
359  theNBinsY,
361  theUpperBoundY));
362  theHisto_u = (prov.book2D(theBaseNameTitle + "U",
363  theBaseNameDescription + " u-jets",
364  theNBinsX,
367  theNBinsY,
369  theUpperBoundY));
370  theHisto_s = (prov.book2D(theBaseNameTitle + "S",
371  theBaseNameDescription + " s-jets",
372  theNBinsX,
375  theNBinsY,
377  theUpperBoundY));
378  theHisto_g = (prov.book2D(theBaseNameTitle + "G",
379  theBaseNameDescription + " g-jets",
380  theNBinsX,
383  theNBinsY,
385  theUpperBoundY));
386  theHisto_dus = (prov.book2D(theBaseNameTitle + "DUS",
387  theBaseNameDescription + " dus-jets",
388  theNBinsX,
391  theNBinsY,
393  theUpperBoundY));
394  } else {
395  theHisto_d = nullptr;
396  theHisto_u = nullptr;
397  theHisto_s = nullptr;
398  theHisto_g = nullptr;
399  theHisto_dus = nullptr;
400  }
401  theHisto_c = (prov.book2D(theBaseNameTitle + "C",
402  theBaseNameDescription + " c-jets",
403  theNBinsX,
406  theNBinsY,
408  theUpperBoundY));
409  theHisto_b = (prov.book2D(theBaseNameTitle + "B",
410  theBaseNameDescription + " b-jets",
411  theNBinsX,
414  theNBinsY,
416  theUpperBoundY));
417  theHisto_ni = (prov.book2D(theBaseNameTitle + "NI",
418  theBaseNameDescription + " ni-jets",
419  theNBinsX,
422  theNBinsY,
424  theUpperBoundY));
425  theHisto_dusg = (prov.book2D(theBaseNameTitle + "DUSG",
426  theBaseNameDescription + " dusg-jets",
427  theNBinsX,
430  theNBinsY,
432  theUpperBoundY));
433  theHisto_pu = (prov.book2D(theBaseNameTitle + "PU",
434  theBaseNameDescription + " pu-jets",
435  theNBinsX,
438  theNBinsY,
440  theUpperBoundY));
441  } else {
442  theHisto_d = nullptr;
443  theHisto_u = nullptr;
444  theHisto_s = nullptr;
445  theHisto_c = nullptr;
446  theHisto_b = nullptr;
447  theHisto_g = nullptr;
448  theHisto_ni = nullptr;
449  theHisto_dus = nullptr;
450  theHisto_dusg = nullptr;
451  theHisto_pu = nullptr;
452  }
453 
454  if (createProfile_) {
455  if (mcPlots_ % 2 == 0)
456  theProfile_all = (prov.bookProfile(theBaseNameTitle + "_Profile_ALL",
457  theBaseNameDescription + " all jets",
458  theNBinsX,
461  theNBinsY,
463  theUpperBoundY));
464  else
465  theProfile_all = nullptr;
466  if (mcPlots_) {
467  if (mcPlots_ > 2) {
468  theProfile_d = (prov.bookProfile(theBaseNameTitle + "_Profile_D",
469  theBaseNameDescription + " d-jets",
470  theNBinsX,
473  theNBinsY,
475  theUpperBoundY));
476  theProfile_u = (prov.bookProfile(theBaseNameTitle + "_Profile_U",
477  theBaseNameDescription + " u-jets",
478  theNBinsX,
481  theNBinsY,
483  theUpperBoundY));
484  theProfile_s = (prov.bookProfile(theBaseNameTitle + "_Profile_S",
485  theBaseNameDescription + " s-jets",
486  theNBinsX,
489  theNBinsY,
491  theUpperBoundY));
492  theProfile_g = (prov.bookProfile(theBaseNameTitle + "_Profile_G",
493  theBaseNameDescription + " g-jets",
494  theNBinsX,
497  theNBinsY,
499  theUpperBoundY));
500  theProfile_dus = (prov.bookProfile(theBaseNameTitle + "_Profile_DUS",
501  theBaseNameDescription + " dus-jets",
502  theNBinsX,
505  theNBinsY,
507  theUpperBoundY));
508  } else {
509  theProfile_d = nullptr;
510  theProfile_u = nullptr;
511  theProfile_s = nullptr;
512  theProfile_g = nullptr;
513  theProfile_dus = nullptr;
514  }
515  theProfile_c = (prov.bookProfile(theBaseNameTitle + "_Profile_C",
516  theBaseNameDescription + " c-jets",
517  theNBinsX,
520  theNBinsY,
522  theUpperBoundY));
523  theProfile_b = (prov.bookProfile(theBaseNameTitle + "_Profile_B",
524  theBaseNameDescription + " b-jets",
525  theNBinsX,
528  theNBinsY,
530  theUpperBoundY));
531  theProfile_ni = (prov.bookProfile(theBaseNameTitle + "_Profile_NI",
532  theBaseNameDescription + " ni-jets",
533  theNBinsX,
536  theNBinsY,
538  theUpperBoundY));
539  theProfile_dusg = (prov.bookProfile(theBaseNameTitle + "_Profile_DUSG",
540  theBaseNameDescription + " dusg-jets",
541  theNBinsX,
544  theNBinsY,
546  theUpperBoundY));
547  theProfile_pu = (prov.bookProfile(theBaseNameTitle + "_Profile_PU",
548  theBaseNameDescription + " pu-jets",
549  theNBinsX,
552  theNBinsY,
554  theUpperBoundY));
555  } else {
556  theProfile_d = nullptr;
557  theProfile_u = nullptr;
558  theProfile_s = nullptr;
559  theProfile_c = nullptr;
560  theProfile_b = nullptr;
561  theProfile_g = nullptr;
562  theProfile_ni = nullptr;
563  theProfile_dus = nullptr;
564  theProfile_dusg = nullptr;
565  theProfile_pu = nullptr;
566  }
567  } else {
568  theProfile_all = nullptr;
569  theProfile_d = nullptr;
570  theProfile_u = nullptr;
571  theProfile_s = nullptr;
572  theProfile_c = nullptr;
573  theProfile_b = nullptr;
574  theProfile_g = nullptr;
575  theProfile_ni = nullptr;
576  theProfile_dus = nullptr;
577  theProfile_dusg = nullptr;
578  theProfile_pu = nullptr;
579  }
580  // statistics if requested
581  if (theStatistics) {
582  if (theHisto_all)
584  if (createProfile)
585  if (theProfile_all)
586  theProfile_all->getTProfile()->Sumw2();
587  if (mcPlots_) {
588  if (mcPlots_ > 2) {
594  }
600 
601  if (createProfile) {
602  if (mcPlots_ > 2) {
603  theProfile_d->getTProfile()->Sumw2();
604  theProfile_u->getTProfile()->Sumw2();
605  theProfile_s->getTProfile()->Sumw2();
606  theProfile_g->getTProfile()->Sumw2();
607  theProfile_dus->getTProfile()->Sumw2();
608  }
609  theProfile_c->getTProfile()->Sumw2();
610  theProfile_b->getTProfile()->Sumw2();
611  theProfile_ni->getTProfile()->Sumw2();
612  theProfile_dusg->getTProfile()->Sumw2();
613  theProfile_pu->getTProfile()->Sumw2();
614  }
615  }
616  }
617 }
618 
619 template <class T, class G>
621 
622 // fill entry
623 template <class T, class G>
624 void FlavourHistograms2D<T, G>::fill(const int &flavour, const T &variableX, const G &variableY, const float &w) const {
625  // For single variables and arrays (for arrays only a single index can be filled)
626  fillVariable(flavour, variableX, variableY, w);
627 }
628 
629 template <class T, class G>
630 void FlavourHistograms2D<T, G>::fill(const int &flavour, const T &variableX, const G &variableY) const {
631  fill(flavour, variableX, variableY, 1.);
632 }
633 
634 template <class T, class G>
635 void FlavourHistograms2D<T, G>::fill(const int &flavour, const T *variableX, const G *variableY, const float &w) const {
636  if (theArrayDimension == nullptr) {
637  // single variable
638  fillVariable(flavour, *variableX, *variableY, w);
639  } else {
640  // array
641  int iMax = *theArrayDimension;
642  if (*theArrayDimension > theMaxDimension)
643  iMax = theMaxDimension;
644  //
645  for (int i = 0; i != iMax; ++i) {
646  // check if only one index to be plotted (<0: switched off -> plot all)
647  if ((theIndexToPlot < 0) || (i == theIndexToPlot)) {
648  fillVariable(flavour, *(variableX + i), *(variableY + i), w);
649  }
650  }
651 
652  // if single index to be filled but not enough entries: fill 0.0 (convention!)
653  if (theIndexToPlot >= iMax) {
654  // cout << "==>> The index to be filled is too big -> fill 0.0 : " << theBaseNameTitle << " : " << theIndexToPlot << " >= " << iMax << endl ;
655  const T &theZeroT = static_cast<T>(0.0);
656  const G &theZeroG = static_cast<T>(0.0);
657  fillVariable(flavour, theZeroT, theZeroG, w);
658  }
659  }
660 }
661 
662 template <class T, class G>
663 void FlavourHistograms2D<T, G>::fill(const int &flavour, const T *variableX, const G *variableY) const {
664  fill(flavour, variableX, variableY, 1.);
665 }
666 
667 template <class T, class G>
668 void FlavourHistograms2D<T, G>::settitle(const char *titleX, const char *titleY) {
669  if (theHisto_all)
670  theHisto_all->setAxisTitle(titleX);
671  if (theHisto_all)
672  theHisto_all->setAxisTitle(titleY, 2);
673  if (mcPlots_) {
674  if (theHisto_d)
675  theHisto_d->setAxisTitle(titleX);
676  if (theHisto_u)
677  theHisto_u->setAxisTitle(titleX);
678  if (theHisto_s)
679  theHisto_s->setAxisTitle(titleX);
680  if (theHisto_c)
681  theHisto_c->setAxisTitle(titleX);
682  if (theHisto_b)
683  theHisto_b->setAxisTitle(titleX);
684  if (theHisto_g)
685  theHisto_g->setAxisTitle(titleX);
686  if (theHisto_ni)
687  theHisto_ni->setAxisTitle(titleX);
688  if (theHisto_dus)
689  theHisto_dus->setAxisTitle(titleX);
690  if (theHisto_dusg)
691  theHisto_dusg->setAxisTitle(titleX);
692  if (theHisto_d)
693  theHisto_d->setAxisTitle(titleY, 2);
694  if (theHisto_u)
695  theHisto_u->setAxisTitle(titleY, 2);
696  if (theHisto_s)
697  theHisto_s->setAxisTitle(titleY, 2);
698  if (theHisto_c)
699  theHisto_c->setAxisTitle(titleY, 2);
700  if (theHisto_b)
701  theHisto_b->setAxisTitle(titleY, 2);
702  if (theHisto_g)
703  theHisto_g->setAxisTitle(titleY, 2);
704  if (theHisto_ni)
705  theHisto_ni->setAxisTitle(titleY, 2);
706  if (theHisto_dus)
707  theHisto_dus->setAxisTitle(titleY, 2);
708  if (theHisto_dusg)
709  theHisto_dusg->setAxisTitle(titleY, 2);
710  if (theHisto_pu)
711  theHisto_pu->setAxisTitle(titleY, 2);
712  }
713 
714  if (createProfile_) {
715  if (theProfile_all)
716  theProfile_all->setAxisTitle(titleX);
717  if (theProfile_all)
718  theProfile_all->setAxisTitle(titleY, 2);
719  if (mcPlots_) {
720  if (theProfile_d)
721  theProfile_d->setAxisTitle(titleX);
722  if (theProfile_u)
723  theProfile_u->setAxisTitle(titleX);
724  if (theProfile_s)
725  theProfile_s->setAxisTitle(titleX);
726  if (theProfile_c)
727  theProfile_c->setAxisTitle(titleX);
728  if (theProfile_b)
729  theProfile_b->setAxisTitle(titleX);
730  if (theProfile_g)
731  theProfile_g->setAxisTitle(titleX);
732  if (theProfile_ni)
733  theProfile_ni->setAxisTitle(titleX);
734  if (theProfile_dus)
735  theProfile_dus->setAxisTitle(titleX);
736  if (theProfile_dusg)
737  theProfile_dusg->setAxisTitle(titleX);
738  if (theProfile_d)
739  theProfile_d->setAxisTitle(titleY, 2);
740  if (theProfile_u)
741  theProfile_u->setAxisTitle(titleY, 2);
742  if (theProfile_s)
743  theProfile_s->setAxisTitle(titleY, 2);
744  if (theProfile_c)
745  theProfile_c->setAxisTitle(titleY, 2);
746  if (theProfile_b)
747  theProfile_b->setAxisTitle(titleY, 2);
748  if (theProfile_g)
749  theProfile_g->setAxisTitle(titleY, 2);
750  if (theProfile_ni)
751  theProfile_ni->setAxisTitle(titleY, 2);
752  if (theProfile_dus)
753  theProfile_dus->setAxisTitle(titleY, 2);
754  if (theProfile_dusg)
755  theProfile_dusg->setAxisTitle(titleY, 2);
756  if (theProfile_pu)
757  theProfile_pu->setAxisTitle(titleY, 2);
758  }
759  }
760 }
761 
762 template <class T, class G>
763 void FlavourHistograms2D<T, G>::plot(TPad *theCanvas /* = 0 */) {
764  //fixme:
765  bool btppNI = false;
766  bool btppColour = true;
767 
768  if (theCanvas)
769  theCanvas->cd();
770 
771  RecoBTag::setTDRStyle()->cd();
772  gPad->UseCurrentStyle();
773  gPad->SetLogy(0);
774  gPad->SetGridx(0);
775  gPad->SetGridy(0);
776  gPad->SetTitle(nullptr);
777 
778  MonitorElement *histo[4];
779  int col[4], lineStyle[4], markerStyle[4];
780  int lineWidth = 1;
781 
782  const double markerSize = gPad->GetWh() * gPad->GetHNDC() / 500.;
783  histo[0] = theHisto_dusg;
784  histo[1] = theHisto_b;
785  histo[2] = theHisto_c;
786  histo[3] = nullptr;
787 
788  double max = theMax;
789  if (theMax <= 0.) {
790  max = theHisto_dusg->getTH2F()->GetMaximum();
791  if (theHisto_b->getTH2F()->GetMaximum() > max)
792  max = theHisto_b->getTH2F()->GetMaximum();
793  if (theHisto_c->getTH2F()->GetMaximum() > max)
794  max = theHisto_c->getTH2F()->GetMaximum();
795  }
796 
797  if (btppNI) {
798  histo[3] = theHisto_ni;
799  if (theHisto_ni->getTH2F()->GetMaximum() > max)
800  max = theHisto_ni->getTH2F()->GetMaximum();
801  }
802 
803  if (btppColour) { // print colours
804  col[0] = 4;
805  col[1] = 2;
806  col[2] = 6;
807  col[3] = 3;
808  lineStyle[0] = 1;
809  lineStyle[1] = 1;
810  lineStyle[2] = 1;
811  lineStyle[3] = 1;
812  markerStyle[0] = 20;
813  markerStyle[1] = 21;
814  markerStyle[2] = 22;
815  markerStyle[3] = 23;
816  lineWidth = 1;
817  } else { // different marker/line styles
818  col[1] = 1;
819  col[2] = 1;
820  col[3] = 1;
821  col[0] = 1;
822  lineStyle[0] = 2;
823  lineStyle[1] = 1;
824  lineStyle[2] = 3;
825  lineStyle[3] = 4;
826  markerStyle[0] = 20;
827  markerStyle[1] = 21;
828  markerStyle[2] = 22;
829  markerStyle[3] = 23;
830  }
831 
832  histo[0]->setAxisTitle(theBaseNameDescription);
833  histo[0]->getTH2F()->GetYaxis()->SetTitle("Arbitrary Units");
834  histo[0]->getTH2F()->GetYaxis()->SetTitleOffset(1.25);
835 
836  for (int i = 0; i != 4; ++i) {
837  if (histo[i] == nullptr)
838  continue;
839  histo[i]->getTH2F()->SetStats(false);
840  histo[i]->getTH2F()->SetLineStyle(lineStyle[i]);
841  histo[i]->getTH2F()->SetLineWidth(lineWidth);
842  histo[i]->getTH2F()->SetLineColor(col[i]);
843  histo[i]->getTH2F()->SetMarkerStyle(markerStyle[i]);
844  histo[i]->getTH2F()->SetMarkerColor(col[i]);
845  histo[i]->getTH2F()->SetMarkerSize(markerSize);
846  }
847 
848  histo[0]->getTH2F()->SetMaximum(max * 1.05);
849  if (theMin != -1.)
850  histo[0]->getTH2F()->SetMinimum(theMin);
851  histo[0]->getTH2F()->Draw();
852  histo[1]->getTH2F()->Draw("Same");
853  histo[2]->getTH2F()->Draw("Same");
854  if (histo[3] != nullptr)
855  histo[3]->getTH2F()->Draw("Same");
856 }
857 
858 template <class T, class G>
860  TCanvas tc(theBaseNameTitle.c_str(), theBaseNameDescription.c_str());
861 
862  plot(&tc);
863  tc.Print((name + theBaseNameTitle + ".eps").c_str());
864 }
865 
866 // needed for efficiency computations -> this / b
867 // (void : alternative would be not to overwrite the histos but to return a cloned HistoDescription)
868 template <class T, class G>
870  // divide histos using binomial errors
871  //
872  // ATTENTION: It's the responsability of the user to make sure that the HistoDescriptions
873  // involved in this operation have been constructed with the statistics option switched on!!
874  //
875  if (theHisto_all)
876  theHisto_all->getTH2F()->Divide(theHisto_all->getTH2F(), bHD.histo_all(), 1.0, 1.0, "b");
877  if (mcPlots_) {
878  if (mcPlots_ > 2) {
879  theHisto_d->getTH2F()->Divide(theHisto_d->getTH2F(), bHD.histo_d(), 1.0, 1.0, "b");
880  theHisto_u->getTH2F()->Divide(theHisto_u->getTH2F(), bHD.histo_u(), 1.0, 1.0, "b");
881  theHisto_s->getTH2F()->Divide(theHisto_s->getTH2F(), bHD.histo_s(), 1.0, 1.0, "b");
882  theHisto_g->getTH2F()->Divide(theHisto_g->getTH2F(), bHD.histo_g(), 1.0, 1.0, "b");
883  theHisto_dus->getTH2F()->Divide(theHisto_dus->getTH2F(), bHD.histo_dus(), 1.0, 1.0, "b");
884  }
885  theHisto_c->getTH2F()->Divide(theHisto_c->getTH2F(), bHD.histo_c(), 1.0, 1.0, "b");
886  theHisto_b->getTH2F()->Divide(theHisto_b->getTH2F(), bHD.histo_b(), 1.0, 1.0, "b");
887  theHisto_ni->getTH2F()->Divide(theHisto_ni->getTH2F(), bHD.histo_ni(), 1.0, 1.0, "b");
888  theHisto_dusg->getTH2F()->Divide(theHisto_dusg->getTH2F(), bHD.histo_dusg(), 1.0, 1.0, "b");
889  theHisto_pu->getTH2F()->Divide(theHisto_pu->getTH2F(), bHD.histo_pu(), 1.0, 1.0, "b");
890  }
891 }
892 
893 template <class T, class G>
895  if (theHisto_all)
896  theHisto_all->setEfficiencyFlag();
897  if (mcPlots_) {
898  if (mcPlots_ > 2) {
899  theHisto_d->setEfficiencyFlag();
900  theHisto_u->setEfficiencyFlag();
901  theHisto_s->setEfficiencyFlag();
902  theHisto_g->setEfficiencyFlag();
903  theHisto_dus->setEfficiencyFlag();
904  }
905  theHisto_c->setEfficiencyFlag();
906  theHisto_b->setEfficiencyFlag();
907  theHisto_ni->setEfficiencyFlag();
908  theHisto_dusg->setEfficiencyFlag();
909  theHisto_pu->setEfficiencyFlag();
910  }
911 }
912 
913 template <class T, class G>
914 void FlavourHistograms2D<T, G>::fillVariable(const int &flavour, const T &varX, const G &varY, const float &w) const {
915  // all
916  if (theHisto_all)
917  theHisto_all->Fill(varX, varY, w);
918  if (createProfile_)
919  //if(theProfile_all) theProfile_all->Fill( varX, varY, w );
920  if (theProfile_all)
921  theProfile_all->Fill(varX, varY);
922 
923  //exit(-1);
924  // flavour specific
925  if (!mcPlots_)
926  return;
927 
928  switch (flavour) {
929  case 1:
930  if (mcPlots_ > 2) {
931  theHisto_d->Fill(varX, varY, w);
932  theHisto_dus->Fill(varX, varY, w);
933  }
934  theHisto_dusg->Fill(varX, varY, w);
935  if (createProfile_) {
936  //theProfile_d->Fill(varX, varY,w);
937  //theProfile_dus->Fill(varX, varY,w);
938  //theProfile_dusg->Fill(varX, varY,w);
939  if (mcPlots_ > 2) {
940  theProfile_d->Fill(varX, varY);
941  theProfile_dus->Fill(varX, varY);
942  }
943  theProfile_dusg->Fill(varX, varY);
944  }
945  return;
946  case 2:
947  if (mcPlots_ > 2) {
948  theHisto_u->Fill(varX, varY, w);
949  theHisto_dus->Fill(varX, varY, w);
950  }
951  theHisto_dusg->Fill(varX, varY, w);
952  if (createProfile_) {
953  //theProfile_u->Fill(varX, varY,w);
954  //theProfile_dus->Fill(varX, varY,w);
955  //theProfile_dusg->Fill(varX, varY,w);
956  if (mcPlots_ > 2) {
957  theProfile_u->Fill(varX, varY);
958  theProfile_dus->Fill(varX, varY);
959  }
960  theProfile_dusg->Fill(varX, varY);
961  }
962  return;
963  case 3:
964  if (mcPlots_ > 2) {
965  theHisto_s->Fill(varX, varY, w);
966  theHisto_dus->Fill(varX, varY, w);
967  }
968  theHisto_dusg->Fill(varX, varY, w);
969  if (createProfile_) {
970  //theProfile_s->Fill(varX, varY,w);
971  //theProfile_dus->Fill(varX, varY,w);
972  //theProfile_dusg->Fill(varX, varY,w);
973  if (mcPlots_ > 2) {
974  theProfile_s->Fill(varX, varY);
975  theProfile_dus->Fill(varX, varY);
976  }
977  theProfile_dusg->Fill(varX, varY);
978  }
979  return;
980  case 4:
981  theHisto_c->Fill(varX, varY, w);
982  //if(createProfile_) theProfile_c->Fill(varX, varY,w);
983  if (createProfile_)
984  theProfile_c->Fill(varX, varY);
985  return;
986  case 5:
987  theHisto_b->Fill(varX, varY, w);
988  //if(createProfile_) theProfile_b->Fill(varX, varY,w);
989  if (createProfile_)
990  theProfile_b->Fill(varX, varY);
991  return;
992  case 21:
993  if (mcPlots_ > 2)
994  theHisto_g->Fill(varX, varY, w);
995  theHisto_dusg->Fill(varX, varY, w);
996  if (createProfile_) {
997  //theProfile_g->Fill(varX, varY,w);
998  //theProfile_dusg->Fill(varX, varY,w);
999  if (mcPlots_ > 2)
1000  theProfile_g->Fill(varX, varY);
1001  theProfile_dusg->Fill(varX, varY);
1002  }
1003  return;
1004  case 20:
1005  theHisto_pu->Fill(varX, varY, w);
1006  //if(createProfile_) theProfile_pu->Fill(varX, varY,w);
1007  if (createProfile_)
1008  theProfile_pu->Fill(varX, varY);
1009  return;
1010  default:
1011  theHisto_ni->Fill(varX, varY, w);
1012  //if(createProfile_) theProfile_ni->Fill(varX, varY,w);
1013  if (createProfile_)
1014  theProfile_ni->Fill(varX, varY);
1015  return;
1016  }
1017 }
1018 
1019 template <class T, class G>
1020 std::vector<TH2F *> FlavourHistograms2D<T, G>::getHistoVector() const {
1021  std::vector<TH2F *> histoVector;
1022  if (theHisto_all)
1023  histoVector.push_back(theHisto_all->getTH2F());
1024  if (mcPlots_) {
1025  if (mcPlots_ > 2) {
1026  histoVector.push_back(theHisto_d->getTH2F());
1027  histoVector.push_back(theHisto_u->getTH2F());
1028  histoVector.push_back(theHisto_s->getTH2F());
1029  histoVector.push_back(theHisto_g->getTH2F());
1030  histoVector.push_back(theHisto_dus->getTH2F());
1031  }
1032  histoVector.push_back(theHisto_c->getTH2F());
1033  histoVector.push_back(theHisto_b->getTH2F());
1034  histoVector.push_back(theHisto_ni->getTH2F());
1035  histoVector.push_back(theHisto_dusg->getTH2F());
1036  histoVector.push_back(theHisto_pu->getTH2F());
1037  }
1038  return histoVector;
1039 }
1040 
1041 template <class T, class G>
1042 std::vector<TProfile *> FlavourHistograms2D<T, G>::getProfileVector() const {
1043  std::vector<TProfile *> profileVector;
1044  if (createProfile_) {
1045  if (theProfile_all)
1046  profileVector.push_back(theProfile_all->getTProfile());
1047  if (mcPlots_) {
1048  if (mcPlots_ > 2) {
1049  profileVector.push_back(theProfile_d->getTProfile());
1050  profileVector.push_back(theProfile_u->getTProfile());
1051  profileVector.push_back(theProfile_s->getTProfile());
1052  profileVector.push_back(theProfile_g->getTProfile());
1053  profileVector.push_back(theProfile_dus->getTProfile());
1054  }
1055  profileVector.push_back(theProfile_c->getTProfile());
1056  profileVector.push_back(theProfile_b->getTProfile());
1057  profileVector.push_back(theProfile_ni->getTProfile());
1058  profileVector.push_back(theProfile_dusg->getTProfile());
1059  profileVector.push_back(theProfile_pu->getTProfile());
1060  }
1061  }
1062  return profileVector;
1063 }
1064 
1065 #endif
std::string theBaseNameDescription
MonitorElement * theProfile_s
void fillVariable(const int &flavour, const T &varX, const G &varY, const float &w) const
MonitorElement * theProfile_pu
virtual TProfile * getTProfile() const
double upperBoundY() const
TProfile * profile_all() const
virtual MonitorElement * bookProfile(const std::string &name, const std::string &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
MonitorElement * theHisto_g
void SetMaximum(const double &max)
T w() const
MonitorElement * theProfile_dusg
void settitle(const char *titleX, const char *titleY)
MonitorElement * theHisto_dusg
MonitorElement * theHisto_u
TStyle * setTDRStyle()
Definition: Tools.cc:343
TProfile * profile_c() const
TProfile * profile_g() const
TProfile * profile_dus() const
TProfile * profile_u() const
void fill(const int &flavour, const T &variableX, const G &variableY) const
void plot(TPad *theCanvas=nullptr)
double lowerBoundY() const
MonitorElement * theHisto_c
virtual TH2F * getTH2F() const
MonitorElement * theHisto_pu
void divide(const FlavourHistograms2D< T, G > &bHD) const
MonitorElement * theProfile_all
MonitorElement * theProfile_ni
MonitorElement * theHisto_dus
MonitorElement * theProfile_u
std::vector< TProfile * > getProfileVector() const
MonitorElement * theHisto_s
dqm::legacy::MonitorElement MonitorElement
TProfile * profile_ni() const
TProfile * profile_b() const
std::vector< TH2F * > getHistoVector() const
MonitorElement * theProfile_b
void SetMinimum(const double &min)
MonitorElement * theProfile_c
double upperBoundX() const
MonitorElement * theProfile_d
double lowerBoundX() const
virtual MonitorElement * book2D(const std::string &name, const std::string &title, const int &nchX, const double &lowX, const double &highX, const int &nchY, const double &lowY, const double &highY)
MonitorElement * theProfile_dus
TProfile * profile_dusg() const
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:690
std::string baseNameDescription() const
dqm::legacy::DQMStore DQMStore
MonitorElement * theHisto_all
TProfile * profile_s() const
void epsPlot(const std::string &name)
TProfile * profile_pu() const
col
Definition: cuy.py:1009
MonitorElement * theProfile_g
long double T
MonitorElement * theHisto_b
TProfile * profile_d() const
MonitorElement * theHisto_ni
MonitorElement * theHisto_d
std::string baseNameTitle() const