CMS 3D CMS Logo

SmartSelectionMonitor.cc
Go to the documentation of this file.
2 
3 // add new histogram
5  if (!h->GetDefaultSumw2())
6  h->Sumw2();
7  if (!hasBaseHisto(histo)) {
8  allMonitors_[histo] = new std::map<std::string, TH1 *>;
9  }
10  (*allMonitors_[histo])["all"] = h;
11  return (*allMonitors_[histo])["all"];
12 }
13 
15  if (h == nullptr)
16  return nullptr;
17  return addHistogram(h, h->GetName());
18 }
19 
20 // takes care of filling an histogram
21 bool SmartSelectionMonitor::fillHisto(std::string name, std::string tag, double val, double weight, bool useBinWidth) {
22  TH1 *h = getHisto(name, tag);
23  if (h == nullptr)
24  return false;
25  if (useBinWidth) {
26  int ibin = h->FindBin(val);
27  double width = h->GetBinWidth(ibin);
28  weight /= width;
29  }
30  h->Fill(val, weight);
31  return true;
32 }
33 
35  std::string name, std::vector<std::string> tags, double val, double weight, bool useBinWidth) {
36  for (unsigned int i = 0; i < tags.size(); i++) {
37  fillHisto(name, tags[i], val, weight, useBinWidth);
38  }
39  return true;
40 }
41 
43  std::string name, std::vector<std::string> tags, double val, std::vector<double> weights, bool useBinWidth) {
44  for (unsigned int i = 0; i < tags.size(); i++) {
45  fillHisto(name, tags[i], val, weights[i], useBinWidth);
46  }
47  return true;
48 }
49 
50 // takes care of filling a 2d histogram
52  std::string name, std::string tag, double valx, double valy, double weight, bool useBinWidth) {
53  TH2 *h = (TH2 *)getHisto(name, tag);
54  if (h == nullptr)
55  return false;
56  if (useBinWidth) {
57  int ibin = h->FindBin(valx, valy);
58  double width = h->GetBinWidth(ibin);
59  weight /= width;
60  }
61  h->Fill(valx, valy, weight);
62  return true;
63 }
64 
66  std::string name, std::vector<std::string> tags, double valx, double valy, double weight, bool useBinWidth) {
67  for (unsigned int i = 0; i < tags.size(); i++) {
68  fillHisto(name, tags[i], valx, valy, weight, useBinWidth);
69  }
70  return true;
71 }
72 
74  std::vector<std::string> tags,
75  double valx,
76  double valy,
77  std::vector<double> weights,
78  bool useBinWidth) {
79  for (unsigned int i = 0; i < tags.size(); i++) {
80  fillHisto(name, tags[i], valx, valy, weights[i], useBinWidth);
81  }
82  return true;
83 }
84 
85 // takes care of filling a profile
86 bool SmartSelectionMonitor::fillProfile(std::string name, std::string tag, double valx, double valy, double weight) {
87  TProfile *h = (TProfile *)getHisto(name, tag);
88  if (h == nullptr)
89  return false;
90  h->Fill(valx, valy, weight);
91  return true;
92 }
93 
95  std::string name, std::vector<std::string> tags, double valx, double valy, double weight) {
96  for (unsigned int i = 0; i < tags.size(); i++) {
97  fillProfile(name, tags[i], valx, valy, weight);
98  }
99  return true;
100 }
101 
103  std::string name, std::vector<std::string> tags, double valx, double valy, std::vector<double> weights) {
104  for (unsigned int i = 0; i < tags.size(); i++) {
105  fillProfile(name, tags[i], valx, valy, weights[i]);
106  }
107  return true;
108 }
TH1 * getHisto(std::string histo, std::string tag="all")
bool fillHisto(std::string name, std::string tag, double valx, double weight, bool useBinWidth=false)
Definition: weight.py:1
TH1 * addHistogram(TH1 *h, std::string tag)
bool fillProfile(std::string name, std::string tag, double valx, double valy, double weight)
bool hasBaseHisto(std::string histo)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4