CMS 3D CMS Logo

MuonGEMRecHitsHarvestor.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 
49 
51 {
52  dbe_path_ = std::string("MuonGEMRecHitsV/GEMRecHitsTask/");
53  outputFile_ = ps.getUntrackedParameter<std::string>("outputFile", "myfile.root");
54 }
55 
56 
58 {
59 }
60 TProfile* MuonGEMRecHitsHarvestor::ComputeEff(TH1F* num, TH1F* denum )
61 {
62  std::string name = "eff_"+std::string(num->GetName());
63  std::string title = "Eff. "+std::string(num->GetTitle());
64  TProfile * efficHist = new TProfile(name.c_str(), title.c_str(),denum->GetXaxis()->GetNbins(), denum->GetXaxis()->GetXmin(),denum->GetXaxis()->GetXmax());
65 
66  for (int i=1; i <= denum->GetNbinsX(); i++) {
67 
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  std::cout<<"Alert! specific bin's num is bigger than denum"<<std::endl;
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 
91 void MuonGEMRecHitsHarvestor::ProcessBooking( DQMStore::IBooker& ibooker, DQMStore::IGetter& ig, const char* label, TString suffix, TH1F* track_hist, TH1F* sh_hist )
92 {
93  TString dbe_label = TString(dbe_path_)+label+suffix;
94  if( ig.get(dbe_label.Data()) != nullptr && sh_hist !=nullptr && track_hist !=nullptr ) {
95  TH1F* hist = (TH1F*)ig.get( dbe_label.Data() )->getTH1F()->Clone();
96  TProfile* profile = ComputeEff( hist, track_hist);
97  TProfile* profile_sh = ComputeEff( hist, sh_hist );
98  profile_sh->SetName( (profile->GetName()+std::string("_sh")).c_str());
99  TString x_axis_title = TString(hist->GetXaxis()->GetTitle());
100  TString title = TString::Format("Eff. for a SimTrack to have an associated GEM RecHits in %s;%s;Eff.",suffix.Data(),x_axis_title.Data());
101  TString title2 = TString::Format("Eff. for a SimTrack to have an associated GEM RecHits in %s with a matched SimHit;%s;Eff.",suffix.Data(),x_axis_title.Data() );
102  profile->SetTitle( title.Data());
103  profile_sh->SetTitle( title2.Data() );
104  ibooker.bookProfile( profile->GetName(),profile);
105  ibooker.bookProfile( profile_sh->GetName(),profile_sh);
106  }
107  else {
108  std::cout<<"Can not found histogram of "<<dbe_label<<std::endl;
109  if ( track_hist == nullptr) std::cout<<"track not found"<<std::endl;
110  if ( sh_hist == nullptr) std::cout<<"sh_hist not found"<<std::endl;
111  }
112  return;
113 }
114 
115 
116 void
118 {
120 
121  using namespace GEMDetLabel;
122 
123  TH1F* gem_trk_eta[s_suffix.size()];
124  TH1F* gem_trk_phi[s_suffix.size()][c_suffix.size()];
125 
126  TH1F* sh_eta[s_suffix.size()][l_suffix.size()];
127  TH1F* sh_phi[s_suffix.size()][l_suffix.size()][c_suffix.size()];
128 
129  for( unsigned int i = 0 ; i < s_suffix.size() ; i++) {
130  TString eta_label = TString(dbe_path_)+"track_eta"+s_suffix[i];
131  TString phi_label;
132  if ( ig.get(eta_label.Data()) != nullptr ) {
133  gem_trk_eta[i] = (TH1F*)ig.get(eta_label.Data())->getTH1F()->Clone();
134  gem_trk_eta[i]->Sumw2();
135  }
136  else std::cout<<"Can not found track_eta"<<std::endl;
137  for ( unsigned int k=0 ; k < c_suffix.size() ; k++) {
138  phi_label = TString(dbe_path_.c_str())+"track_phi"+s_suffix[i]+c_suffix[k];
139  if ( ig.get(phi_label.Data()) !=nullptr ) {
140  gem_trk_phi[i][k] = (TH1F*)ig.get(phi_label.Data())->getTH1F()->Clone();
141  gem_trk_phi[i][k]->Sumw2();
142  }
143  else std::cout<<"Can not found track_phi"<<std::endl;
144  }
145 
146  if ( ig.get(eta_label.Data()) != nullptr && ig.get(phi_label.Data()) !=nullptr ) {
147  for( unsigned int j = 0; j < l_suffix.size() ; j++) {
148  TString suffix = TString( s_suffix[i] )+TString( l_suffix[j]);
149  TString eta_label = TString(dbe_path_)+"rh_sh_eta"+suffix;
150  if( ig.get(eta_label.Data()) !=nullptr ) {
151  sh_eta[i][j] = (TH1F*)ig.get(eta_label.Data())->getTH1F()->Clone();
152  sh_eta[i][j]->Sumw2();
153  }
154  else std::cout<<"Can not found eta histogram : "<<eta_label<<std::endl;
155  ProcessBooking( ibooker, ig, "rh_eta", suffix, gem_trk_eta[i], sh_eta[i][j]);
156  for ( unsigned int k= 0 ; k < c_suffix.size() ; k++) {
157  suffix = TString( s_suffix[i])+TString( l_suffix[j]) +TString(c_suffix[k]);
158  TString phi_label = TString(dbe_path_)+"rh_sh_phi"+suffix;
159  if( ig.get(phi_label.Data()) !=nullptr ) {
160  sh_phi[i][j][k] = (TH1F*)ig.get(phi_label.Data())->getTH1F()->Clone();
161  sh_phi[i][j][k]->Sumw2();
162  }
163  else { std::cout<<"Can not found phi plots : "<<phi_label<<std::endl; continue; }
164  ProcessBooking( ibooker, ig, "rh_phi",suffix, gem_trk_phi[i][k], sh_phi[i][j][k]);
165  }
166  }
167  }
168  else std::cout<<"Can not find eta or phi of all track"<<std::endl;
169  }
170 }
171 
172 
173 //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
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:160
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:302
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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
TProfile * ComputeEff(TH1F *num, TH1F *denum)
MuonGEMRecHitsHarvestor(const edm::ParameterSet &)
constructor
int k[5][pyjets_maxn]
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:344
void ProcessBooking(DQMStore::IBooker &, DQMStore::IGetter &, const char *label, TString suffix, TH1F *track_hist, TH1F *sh_hist)
~MuonGEMRecHitsHarvestor() override
destructor
static const std::array< std::string, 3 > c_suffix
Definition: GEMDetLabel.h:6