CMS 3D CMS Logo

MuonGEMDigisHarvestor.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
13 #include "TFile.h"
14 #include "TGraphAsymmErrors.h"
15 #include "TTree.h"
16 
26 
29 
33 
38 
40 
44 
47 
49  dbe_path_ = ps.getParameter<std::string>("dbePath");
50  dbe_hist_prefix_ = ps.getParameter<std::string>("dbeHistPrefix");
51  compareable_dbe_path_ = ps.getParameter<std::string>("compareDBEPath");
52  compareable_dbe_hist_prefix_ = ps.getParameter<std::string>("compareDBEHistPrefix");
53 
54  outputFile_ = ps.getUntrackedParameter<std::string>("outputFile", "myfile.root");
55 }
56 
58 TProfile *MuonGEMDigisHarvestor::ComputeEff(TH1F *num, TH1F *denum) {
59  std::string name = "eff_" + std::string(num->GetName());
60  std::string title = "Eff. " + std::string(num->GetTitle());
61  TProfile *efficHist = new TProfile(name.c_str(),
62  title.c_str(),
63  denum->GetXaxis()->GetNbins(),
64  denum->GetXaxis()->GetXmin(),
65  denum->GetXaxis()->GetXmax());
66 
67  for (int i = 1; i <= denum->GetNbinsX(); i++) {
68  double nNum = num->GetBinContent(i);
69  double nDenum = denum->GetBinContent(i);
70  if (nDenum == 0 || nNum == 0) {
71  continue;
72  }
73  if (nNum > nDenum) {
74  double temp = nDenum;
75  nDenum = nNum;
76  nNum = temp;
77  LogDebug("MuonGEMDigisHarvestor") << "Alert! specific bin's num is bigger than denum";
78  }
79  const double effVal = nNum / nDenum;
80  efficHist->SetBinContent(i, effVal);
81  efficHist->SetBinEntries(i, 1);
82  efficHist->SetBinError(i, 0);
83  const double errLo = TEfficiency::ClopperPearson((int)nDenum, (int)nNum, 0.683, false);
84  const double errUp = TEfficiency::ClopperPearson((int)nDenum, (int)nNum, 0.683, true);
85  const double errVal = (effVal - errLo > errUp - effVal) ? effVal - errLo : errUp - effVal;
86  efficHist->SetBinError(i, sqrt(effVal * effVal + errVal * errVal));
87  }
88  return efficHist;
89 }
90 
93  const char *label,
94  TString suffix,
95  TH1F *track_hist,
96  TH1F *sh_hist) {
97  TString dbe_label = TString(dbe_path_) + label + suffix;
98  if (ig.get(dbe_label.Data()) != nullptr && sh_hist != nullptr && track_hist != nullptr) {
99  TH1F *hist = (TH1F *)ig.get(dbe_label.Data())->getTH1F()->Clone();
100  TProfile *profile = ComputeEff(hist, track_hist);
101  TProfile *profile_sh = ComputeEff(hist, sh_hist);
102  profile_sh->SetName((profile->GetName() + std::string("_sh")).c_str());
103  TString x_axis_title = TString(hist->GetXaxis()->GetTitle());
104  TString title = TString::Format(
105  "Eff. for a SimTrack to have an associated GEM digi in %s;%s;Eff.", suffix.Data(), x_axis_title.Data());
106  TString title2 = TString::Format(
107  "Eff. for a SimTrack to have an associated GEM digi in "
108  "%s with a matched SimHit;%s;Eff.",
109  suffix.Data(),
110  x_axis_title.Data());
111  profile->SetTitle(title.Data());
112  profile_sh->SetTitle(title2.Data());
113  ibooker.bookProfile(profile->GetName(), profile);
114  ibooker.bookProfile(profile_sh->GetName(), profile_sh);
115  } else {
116  LogDebug("MuonGEMDigisHarvestor") << "Can not found histogram of " << dbe_label;
117  if (track_hist == nullptr)
118  LogDebug("MuonGEMDigisHarvestor") << "track not found";
119  if (sh_hist == nullptr)
120  LogDebug("MuonGEMDigisHarvestor") << "sh_hist not found";
121  }
122  return;
123 }
124 
127  TH1F *gem_trk_eta[3];
128  TH1F *gem_trk_phi[3][2];
129 
130  TH1F *sh_eta[3][4];
131  TH1F *sh_phi[3][4][3];
132 
133  // simplePlots
134  /*
135  for( int region = -1 ; region <= 1 ; region = region+2) {
136  for ( int station = 0 ; station <2 ; station++) {
137  if ( station ==1 ) station=2 ;
138  TString dcEta_label =
139  TString::Format("%s%s_r%d%s",dbe_path_.c_str(),dbe_hist_prefix_.c_str(),
140  region, s_suffix[station].c_str()); TString denum_dcEta_label =
141  TString::Format("%s%s_r%d%s",compareable_dbe_path_.c_str(),compareable_dbe_hist_prefix_.c_str(),
142  region, s_suffix[station].c_str());
143 
144 
145  if ( ig.get( dcEta_label.Data()) != nullptr && ig.get(
146  denum_dcEta_label.Data()) != nullptr) { TH2F* dcEta = (TH2F*)ig.get(
147  dcEta_label.Data())->getTH2F()->Clone(); TH2F* denum_dcEta = (TH2F*)ig.get(
148  denum_dcEta_label.Data())->getTH2F()->Clone(); dcEta->Divide(denum_dcEta);
149  TH2F* eff_dcEta = (TH2F*)dcEta->Clone();
150 
151  TString eff_dcEta_title = TString::Format("Hits Efficiency on detector
152  component at r%d%s",region,s_suffix[station].c_str()); TString eff_dcEta_label
153  = TString::Format("eff_DigiHit_r%d%s",region,s_suffix[station].c_str());
154 
155 
156  eff_dcEta->SetName( eff_dcEta_label.Data());
157  eff_dcEta->SetTitle( eff_dcEta_title.Data());
158 
159  ibooker.book2D(eff_dcEta->GetName(), eff_dcEta);
160  }
161  else {
162  std::cout<<"Failed to get histograms"<<std::endl;
163  std::cout<<dcEta_label<<std::endl;
164  std::cout<<denum_dcEta_label<<std::endl;
165  }
166  }
167  }
168  */
169 
170  using namespace GEMDetLabel;
171 
172  // detailPlots
173  for (unsigned int i = 0; i < s_suffix.size(); i++) {
174  TString eta_label = TString(dbe_path_) + "track_eta" + s_suffix[i];
175  TString phi_label;
176  if (ig.get(eta_label.Data()) != nullptr) {
177  gem_trk_eta[i] = (TH1F *)ig.get(eta_label.Data())->getTH1F()->Clone();
178  gem_trk_eta[i]->Sumw2();
179  } else
180  LogDebug("MuonGEMDigisHarvestor") << "Can not found track_eta";
181  for (unsigned int k = 0; k < c_suffix.size(); k++) {
182  phi_label = TString(dbe_path_.c_str()) + "track_phi" + s_suffix[i] + c_suffix[k];
183  if (ig.get(phi_label.Data()) != nullptr) {
184  gem_trk_phi[i][k] = (TH1F *)ig.get(phi_label.Data())->getTH1F()->Clone();
185  gem_trk_phi[i][k]->Sumw2();
186  } else
187  LogDebug("MuonGEMDigisHarvestor") << "Can not found track_phi";
188  }
189 
190  if (ig.get(eta_label.Data()) != nullptr && ig.get(phi_label.Data()) != nullptr) {
191  for (unsigned int j = 0; j < l_suffix.size(); j++) {
192  TString suffix = TString(s_suffix[i]) + TString(l_suffix[j]);
193  TString eta_label = TString(dbe_path_) + "dg_sh_eta" + suffix;
194  if (ig.get(eta_label.Data()) != nullptr) {
195  sh_eta[i][j] = (TH1F *)ig.get(eta_label.Data())->getTH1F()->Clone();
196  sh_eta[i][j]->Sumw2();
197  } else
198  LogDebug("MuonGEMDigisHarvestor") << "Can not found eta histogram : " << eta_label;
199  ProcessBooking(ibooker, ig, "dg_eta", suffix, gem_trk_eta[i], sh_eta[i][j]);
200  ProcessBooking(ibooker, ig, "pad_eta", suffix, gem_trk_eta[i], sh_eta[i][j]);
201  ProcessBooking(ibooker, ig, "copad_eta", suffix, gem_trk_eta[i], sh_eta[i][j]);
202  for (unsigned int k = 0; k < c_suffix.size(); k++) {
203  suffix = TString(s_suffix[i]) + TString(l_suffix[j]) + TString(c_suffix[k]);
204  TString phi_label = TString(dbe_path_) + "dg_sh_phi" + suffix;
205  if (ig.get(phi_label.Data()) != nullptr) {
206  sh_phi[i][j][k] = (TH1F *)ig.get(phi_label.Data())->getTH1F()->Clone();
207  sh_phi[i][j][k]->Sumw2();
208  } else {
209  LogDebug("MuonGEMDigisHarvestor") << "Can not found phi plots : " << phi_label;
210  continue;
211  }
212  ProcessBooking(ibooker, ig, "dg_phi", suffix, gem_trk_phi[i][k], sh_phi[i][j][k]);
213  ProcessBooking(ibooker, ig, "pad_phi", suffix, gem_trk_phi[i][k], sh_phi[i][j][k]);
214  ProcessBooking(ibooker, ig, "copad_phi", suffix, gem_trk_phi[i][k], sh_phi[i][j][k]);
215  }
216  }
217  } else
218  LogDebug("MuonGEMDigisHarvestor") << "Can not find eta or phi of all track";
219  }
220 }
221 
222 // define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
static const std::array< std::string, 4 > l_suffix
Definition: GEMDetLabel.h:4
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:113
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:361
TProfile * ComputeEff(TH1F *num, TH1F *denum)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
char const * label
static const std::array< std::string, 2 > s_suffix
Definition: GEMDetLabel.h:5
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T sqrt(T t)
Definition: SSEVec.h:18
MuonGEMDigisHarvestor(const edm::ParameterSet &)
constructor
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:303
std::string compareable_dbe_hist_prefix_
int k[5][pyjets_maxn]
~MuonGEMDigisHarvestor() override
destructor
void ProcessBooking(DQMStore::IBooker &, DQMStore::IGetter &, const char *label, TString suffix, TH1F *track_hist, TH1F *sh_hist)
static const std::array< std::string, 3 > c_suffix
Definition: GEMDetLabel.h:6