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