CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
HeavyFlavorHarvesting Class Reference
Inheritance diagram for HeavyFlavorHarvesting:

Public Member Functions

 HeavyFlavorHarvesting (const edm::ParameterSet &pset)
 
 ~HeavyFlavorHarvesting () override
 

Protected Member Functions

void dqmEndJob (DQMStore::IBooker &, DQMStore::IGetter &) override
 

Private Member Functions

void calculateEfficiency (const ParameterSet &pset, DQMStore::IBooker &, DQMStore::IGetter &)
 
void calculateEfficiency1D (TH1 *num, TH1 *den, string name, DQMStore::IBooker &, DQMStore::IGetter &)
 
void calculateEfficiency2D (TH2F *num, TH2F *den, string name, DQMStore::IBooker &, DQMStore::IGetter &)
 

Private Attributes

const VParameterSet efficiencies
 
string myDQMrootFolder
 

Detailed Description

Definition at line 21 of file HeavyFlavorHarvesting.cc.

Constructor & Destructor Documentation

◆ HeavyFlavorHarvesting()

HeavyFlavorHarvesting::HeavyFlavorHarvesting ( const edm::ParameterSet pset)

Definition at line 38 of file HeavyFlavorHarvesting.cc.

39  : myDQMrootFolder(pset.getUntrackedParameter<string>("MyDQMrootFolder")),
40  efficiencies(pset.getUntrackedParameter<VParameterSet>("Efficiencies")) {}
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
const VParameterSet efficiencies

◆ ~HeavyFlavorHarvesting()

HeavyFlavorHarvesting::~HeavyFlavorHarvesting ( )
override

Definition at line 208 of file HeavyFlavorHarvesting.cc.

208 {}

Member Function Documentation

◆ calculateEfficiency()

void HeavyFlavorHarvesting::calculateEfficiency ( const ParameterSet pset,
DQMStore::IBooker ibooker_,
DQMStore::IGetter igetter_ 
)
private

Definition at line 48 of file HeavyFlavorHarvesting.cc.

References calculateEfficiency1D(), calculateEfficiency2D(), HistogramManager_cfi::dimensions, dqm::implementation::IGetter::get(), dqm::legacy::MonitorElement::getTH1(), LogDebug, myDQMrootFolder, EgammaValidation_cff::num, muonDTDigis_cfi::pset, and dqm::implementation::NavigatorBase::setCurrentFolder().

Referenced by dqmEndJob().

50  {
51  //get hold of numerator and denominator histograms
52  vector<string> numDenEffMEnames = pset.getUntrackedParameter<vector<string> >("NumDenEffMEnames");
53  if (numDenEffMEnames.size() != 3) {
54  LogDebug("HLTriggerOfflineHeavyFlavor") << "NumDenEffMEnames must have three names" << endl;
55  return;
56  }
57  string denMEname = myDQMrootFolder + "/" + numDenEffMEnames[1];
58  string numMEname = myDQMrootFolder + "/" + numDenEffMEnames[0];
59  MonitorElement* denME = igetter_.get(denMEname);
60  MonitorElement* numME = igetter_.get(numMEname);
61  if (denME == nullptr || numME == nullptr) {
62  LogDebug("HLTriggerOfflineHeavyFlavor") << "Could not find MEs: " << denMEname << " or " << numMEname << endl;
63  return;
64  }
65  TH1* den = denME->getTH1();
66  TH1* num = numME->getTH1();
67  //check compatibility of the histograms
68  if (den->GetNbinsX() != num->GetNbinsX() || den->GetNbinsY() != num->GetNbinsY() ||
69  den->GetNbinsZ() != num->GetNbinsZ()) {
70  LogDebug("HLTriggerOfflineHeavyFlavor")
71  << "Monitoring elements " << numMEname << " and " << denMEname << "are incompatible" << endl;
72  return;
73  }
74  //figure out the directory and efficiency name
75  string effName = numDenEffMEnames[2];
76  string effDir = myDQMrootFolder;
77  string::size_type slashPos = effName.rfind('/');
78  if (string::npos != slashPos) {
79  effDir += "/" + effName.substr(0, slashPos);
80  effName.erase(0, slashPos + 1);
81  }
82  ibooker_.setCurrentFolder(effDir);
83  //calculate the efficiencies
84  int dimensions = num->GetDimension();
85  if (dimensions == 1) {
86  calculateEfficiency1D(num, den, effName, ibooker_, igetter_);
87  } else if (dimensions == 2) {
88  calculateEfficiency2D((TH2F*)num, (TH2F*)den, effName, ibooker_, igetter_);
89  TH1D* numX = ((TH2F*)num)->ProjectionX();
90  TH1D* denX = ((TH2F*)den)->ProjectionX();
91  calculateEfficiency1D(numX, denX, effName + "X", ibooker_, igetter_);
92  delete numX;
93  delete denX;
94  TH1D* numY = ((TH2F*)num)->ProjectionY();
95  TH1D* denY = ((TH2F*)den)->ProjectionY();
96  calculateEfficiency1D(numY, denY, effName + "Y", ibooker_, igetter_);
97  delete numY;
98  delete denY;
99  } else {
100  return;
101  }
102 }
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void calculateEfficiency1D(TH1 *num, TH1 *den, string name, DQMStore::IBooker &, DQMStore::IGetter &)
uint16_t size_type
void calculateEfficiency2D(TH2F *num, TH2F *den, string name, DQMStore::IBooker &, DQMStore::IGetter &)
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
virtual TH1 * getTH1() const
#define LogDebug(id)

◆ calculateEfficiency1D()

void HeavyFlavorHarvesting::calculateEfficiency1D ( TH1 *  num,
TH1 *  den,
string  name,
DQMStore::IBooker ibooker_,
DQMStore::IGetter igetter_ 
)
private

Definition at line 104 of file HeavyFlavorHarvesting.cc.

References dqm::implementation::IBooker::bookProfile(), MillePedeFileConverter_cfg::e, submitPVResolutionJobs::err, LaserClient_cfi::high, mps_fire::i, LaserClient_cfi::low, EgammaValidation_cff::num, and mathSSE::sqrt().

Referenced by calculateEfficiency().

105  {
106  TProfile* eff;
107  if (num->GetXaxis()->GetXbins()->GetSize() == 0) {
108  eff = new TProfile(effName.c_str(),
109  effName.c_str(),
110  num->GetXaxis()->GetNbins(),
111  num->GetXaxis()->GetXmin(),
112  num->GetXaxis()->GetXmax());
113  } else {
114  eff = new TProfile(
115  effName.c_str(), effName.c_str(), num->GetXaxis()->GetNbins(), num->GetXaxis()->GetXbins()->GetArray());
116  }
117  eff->SetTitle(effName.c_str());
118  eff->SetXTitle(num->GetXaxis()->GetTitle());
119  eff->SetYTitle("Efficiency");
120  eff->SetOption("PE");
121  eff->SetLineColor(2);
122  eff->SetLineWidth(2);
123  eff->SetMarkerStyle(20);
124  eff->SetMarkerSize(0.8);
125  eff->GetYaxis()->SetRangeUser(-0.001, 1.001);
126  eff->SetStats(kFALSE);
127  for (int i = 1; i <= num->GetNbinsX(); i++) {
128  double e, low, high;
129  if (int(den->GetBinContent(i)) > 0.)
130  e = double(num->GetBinContent(i)) / double(den->GetBinContent(i));
131  else
132  e = 0.;
133  low = TEfficiency::Wilson((double)den->GetBinContent(i), (double)num->GetBinContent(i), 0.683, false);
134  high = TEfficiency::Wilson((double)den->GetBinContent(i), (double)num->GetBinContent(i), 0.683, true);
135 
136  double err = e - low > high - e ? e - low : high - e;
137  //here is the trick to store info in TProfile:
138  eff->SetBinContent(i, e);
139  eff->SetBinEntries(i, 1);
140  eff->SetBinError(i, sqrt(e * e + err * err));
141  }
142  ibooker_.bookProfile(effName, eff);
143  delete eff;
144 }
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
T sqrt(T t)
Definition: SSEVec.h:19

◆ calculateEfficiency2D()

void HeavyFlavorHarvesting::calculateEfficiency2D ( TH2F *  num,
TH2F *  den,
string  name,
DQMStore::IBooker ibooker_,
DQMStore::IGetter igetter_ 
)
private

Definition at line 146 of file HeavyFlavorHarvesting.cc.

References dqm::implementation::IBooker::bookProfile2D(), MillePedeFileConverter_cfg::e, submitPVResolutionJobs::err, LaserClient_cfi::high, mps_fire::i, LaserClient_cfi::low, EgammaValidation_cff::num, and mathSSE::sqrt().

Referenced by calculateEfficiency().

147  {
148  TProfile2D* eff;
149  if (num->GetXaxis()->GetXbins()->GetSize() == 0 && num->GetYaxis()->GetXbins()->GetSize() == 0) {
150  eff = new TProfile2D(effName.c_str(),
151  effName.c_str(),
152  num->GetXaxis()->GetNbins(),
153  num->GetXaxis()->GetXmin(),
154  num->GetXaxis()->GetXmax(),
155  num->GetYaxis()->GetNbins(),
156  num->GetYaxis()->GetXmin(),
157  num->GetYaxis()->GetXmax());
158  } else if (num->GetXaxis()->GetXbins()->GetSize() != 0 && num->GetYaxis()->GetXbins()->GetSize() == 0) {
159  eff = new TProfile2D(effName.c_str(),
160  effName.c_str(),
161  num->GetXaxis()->GetNbins(),
162  num->GetXaxis()->GetXbins()->GetArray(),
163  num->GetYaxis()->GetNbins(),
164  num->GetYaxis()->GetXmin(),
165  num->GetYaxis()->GetXmax());
166  } else if (num->GetXaxis()->GetXbins()->GetSize() == 0 && num->GetYaxis()->GetXbins()->GetSize() != 0) {
167  eff = new TProfile2D(effName.c_str(),
168  effName.c_str(),
169  num->GetXaxis()->GetNbins(),
170  num->GetXaxis()->GetXmin(),
171  num->GetXaxis()->GetXmax(),
172  num->GetYaxis()->GetNbins(),
173  num->GetYaxis()->GetXbins()->GetArray());
174  } else {
175  eff = new TProfile2D(effName.c_str(),
176  effName.c_str(),
177  num->GetXaxis()->GetNbins(),
178  num->GetXaxis()->GetXbins()->GetArray(),
179  num->GetYaxis()->GetNbins(),
180  num->GetYaxis()->GetXbins()->GetArray());
181  }
182  eff->SetTitle(effName.c_str());
183  eff->SetXTitle(num->GetXaxis()->GetTitle());
184  eff->SetYTitle(num->GetYaxis()->GetTitle());
185  eff->SetZTitle("Efficiency");
186  eff->SetOption("colztexte");
187  eff->GetZaxis()->SetRangeUser(-0.001, 1.001);
188  eff->SetStats(kFALSE);
189  for (int i = 0; i < num->GetSize(); i++) {
190  double e, low, high;
191  if (int(den->GetBinContent(i)) > 0.)
192  e = double(num->GetBinContent(i)) / double(den->GetBinContent(i));
193  else
194  e = 0.;
195  low = TEfficiency::Wilson((double)den->GetBinContent(i), (double)num->GetBinContent(i), 0.683, false);
196  high = TEfficiency::Wilson((double)den->GetBinContent(i), (double)num->GetBinContent(i), 0.683, true);
197 
198  double err = e - low > high - e ? e - low : high - e;
199  //here is the trick to store info in TProfile:
200  eff->SetBinContent(i, e);
201  eff->SetBinEntries(i, 1);
202  eff->SetBinError(i, sqrt(e * e + err * err));
203  }
204  ibooker_.bookProfile2D(effName, eff);
205  delete eff;
206 }
MonitorElement * bookProfile2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:476
T sqrt(T t)
Definition: SSEVec.h:19

◆ dqmEndJob()

void HeavyFlavorHarvesting::dqmEndJob ( DQMStore::IBooker ibooker_,
DQMStore::IGetter igetter_ 
)
overrideprotected

Definition at line 42 of file HeavyFlavorHarvesting.cc.

References calculateEfficiency(), efficiencies, and muonDTDigis_cfi::pset.

42  {
43  for (VParameterSet::const_iterator pset = efficiencies.begin(); pset != efficiencies.end(); pset++) {
44  calculateEfficiency(*pset, ibooker_, igetter_);
45  }
46 }
const VParameterSet efficiencies
void calculateEfficiency(const ParameterSet &pset, DQMStore::IBooker &, DQMStore::IGetter &)

Member Data Documentation

◆ efficiencies

const VParameterSet HeavyFlavorHarvesting::efficiencies
private

Definition at line 32 of file HeavyFlavorHarvesting.cc.

Referenced by dqmEndJob().

◆ myDQMrootFolder

string HeavyFlavorHarvesting::myDQMrootFolder
private

Definition at line 31 of file HeavyFlavorHarvesting.cc.

Referenced by calculateEfficiency().