CMS 3D CMS Logo

MuonGEMHitsHarvestor.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
12 #include "TTree.h"
13 #include "TFile.h"
14 #include "TGraphAsymmErrors.h"
17 
26 
29 
33 
38 
40 
44 
47 
48 using namespace GEMDetLabel;
49 using namespace std;
51  dbe_path_ = std::string("MuonGEMHitsV/GEMHitsTask/");
52  outputFile_ = ps.getUntrackedParameter<std::string>("outputFile", "myfile.root");
53 }
54 
56 TProfile* MuonGEMHitsHarvestor::ComputeEff(TH1F* num, TH1F* denum) {
57  if (num == nullptr || denum == nullptr) {
58  std::cout << "num or denum are missing" << std::endl;
59  return nullptr;
60  }
61  if (num->GetNbinsX() != denum->GetNbinsX()) {
62  std::cout << "Wrong Xbin. Please, check histogram's name" << std::endl;
63  return nullptr;
64  }
65  std::string name = "eff_" + std::string(num->GetName());
66  std::string title = "Eff. " + std::string(num->GetTitle());
67  TProfile* efficHist = new TProfile(
68  name.c_str(), title.c_str(), num->GetXaxis()->GetNbins(), num->GetXaxis()->GetXmin(), num->GetXaxis()->GetXmax());
69  for (int i = 1; i <= num->GetNbinsX(); i++) {
70  const double nNum = num->GetBinContent(i);
71  const double nDenum = denum->GetBinContent(i);
72  if (nDenum == 0 || nNum > nDenum)
73  continue;
74  if (nNum == 0)
75  continue;
76  const double effVal = nNum / nDenum;
77  const double errLo = TEfficiency::ClopperPearson((int)nDenum, (int)nNum, 0.683, false);
78  const double errUp = TEfficiency::ClopperPearson((int)nDenum, (int)nNum, 0.683, true);
79  const double errVal = (effVal - errLo > errUp - effVal) ? effVal - errLo : errUp - effVal;
80  efficHist->SetBinContent(i, effVal);
81  efficHist->SetBinEntries(i, 1);
82  efficHist->SetBinError(i, sqrt(effVal * effVal + errVal * errVal));
83  }
84  return efficHist;
85 }
87  DQMStore::IBooker& ibooker, DQMStore::IGetter& ig, std::string label_suffix, TH1F* track_hist, TH1F* sh_hist) {
88  TString dbe_label = TString(dbe_path_) + label_suffix;
89  //std::cout<<dbe_label<<" "<<track_hist->GetName()<<std::endl;
90  if (ig.get(dbe_label.Data()) != nullptr && track_hist != nullptr) {
91  TH1F* hist = (TH1F*)ig.get(dbe_label.Data())->getTH1F()->Clone();
92  TProfile* profile = ComputeEff(hist, track_hist);
93  TString x_axis_title = TString(hist->GetXaxis()->GetTitle());
94  TString title = TString::Format(
95  "Eff. for a SimTrack to have an associated GEM Strip in %s;%s;Eff.", label_suffix.c_str(), x_axis_title.Data());
96  profile->SetTitle(title.Data());
97  ibooker.bookProfile(profile->GetName(), profile);
98  if (sh_hist != nullptr) {
99  TProfile* profile_sh = ComputeEff(hist, sh_hist);
100  profile_sh->SetName((profile->GetName() + std::string("_sh")).c_str());
101  TString title2 =
102  TString::Format("Eff. for a SimTrack to have an associated GEM Strip in %s with a matched SimHit;%s;Eff.",
103  label_suffix.c_str(),
104  x_axis_title.Data());
105  profile_sh->SetTitle(title2.Data());
106  ibooker.bookProfile(profile_sh->GetName(), profile_sh);
107  }
108  }
109  return;
110 }
111 
113  ig.setCurrentFolder(dbe_path_);
114  TH1F* track_eta[3];
115  TH1F* track_phi[3][3];
116 
117  for (unsigned int i = 0; i < 3; i++) {
118  track_eta[i] = nullptr;
119  for (unsigned int j = 0; j < 3; j++) {
120  track_phi[i][j] = nullptr;
121  }
122  }
123 
124  for (unsigned int i = 0; i < s_suffix.size(); i++) {
125  string suffix = s_suffix[i];
126  string track_eta_name = dbe_path_ + "track_eta" + suffix;
127  if (ig.get(track_eta_name) != nullptr)
128  track_eta[i] = (TH1F*)ig.get(track_eta_name)->getTH1F()->Clone();
129  for (unsigned int j = 0; j < l_suffix.size(); j++) {
130  suffix = s_suffix[i] + l_suffix[j];
131  ProcessBooking(ibooker, ig, "sh_eta" + suffix, track_eta[i]);
132  }
133  }
134  for (unsigned int i = 0; i < s_suffix.size(); i++) {
135  for (unsigned int j = 0; j < c_suffix.size(); j++) {
136  string suffix = s_suffix[i] + c_suffix[j];
137  string track_phi_name = dbe_path_ + "track_phi" + suffix;
138  if (ig.get(track_phi_name) != nullptr)
139  track_phi[i][j] = (TH1F*)ig.get(track_phi_name)->getTH1F()->Clone();
140  for (unsigned int k = 0; k < l_suffix.size(); k++) {
141  suffix = s_suffix[i] + l_suffix[k] + c_suffix[j];
142  ProcessBooking(ibooker, ig, "sh_phi" + suffix, track_phi[i][j]);
143  }
144  }
145  }
146 }
147 
148 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
static const std::array< std::string, 4 > l_suffix
Definition: GEMDetLabel.h:4
MuonGEMHitsHarvestor(const edm::ParameterSet &)
constructor
virtual TH1F * getTH1F() const
static const std::array< std::string, 2 > s_suffix
Definition: GEMDetLabel.h:5
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TProfile * ComputeEff(TH1F *num, TH1F *denum)
~MuonGEMHitsHarvestor() override
destructor
T sqrt(T t)
Definition: SSEVec.h:19
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char const *option="s")
Definition: DQMStore.cc:333
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
void ProcessBooking(DQMStore::IBooker &, DQMStore::IGetter &, std::string label_suffix, TH1F *track_hist, TH1F *sh_hist=0)
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:437
static const std::array< std::string, 3 > c_suffix
Definition: GEMDetLabel.h:6
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:424