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 
47 
48 
50 {
51  dbe_path_ = std::string("MuonGEMRecHitsV/GEMRecHitsTask/");
52  outputFile_ = ps.getUntrackedParameter<std::string>("outputFile", "myfile.root");
53 }
54 
55 
57 {
58 }
59 TProfile* MuonGEMRecHitsHarvestor::ComputeEff(TH1F* num, TH1F* denum )
60 {
61  std::string name = "eff_"+std::string(num->GetName());
62  std::string title = "Eff. "+std::string(num->GetTitle());
63  TProfile * efficHist = new TProfile(name.c_str(), title.c_str(),denum->GetXaxis()->GetNbins(), denum->GetXaxis()->GetXmin(),denum->GetXaxis()->GetXmax());
64 
65  for (int i=1; i <= denum->GetNbinsX(); i++) {
66 
67  double nNum = num->GetBinContent(i);
68  double nDenum = denum->GetBinContent(i);
69  if ( nDenum == 0 || nNum ==0 ) {
70  continue;
71  }
72  if ( nNum > nDenum ) {
73  double temp = nDenum;
74  nDenum = nNum;
75  nNum = temp;
76  std::cout<<"Alert! specific bin's num is bigger than denum"<<std::endl;
77  }
78  const double effVal = nNum/nDenum;
79  efficHist->SetBinContent(i, effVal);
80  efficHist->SetBinEntries(i,1);
81  efficHist->SetBinError(i,0);
82  const double errLo = TEfficiency::ClopperPearson((int)nDenum,(int)nNum,0.683,false);
83  const double errUp = TEfficiency::ClopperPearson((int)nDenum,(int)nNum,0.683,true);
84  const double errVal = (effVal - errLo > errUp - effVal) ? effVal - errLo : errUp - effVal;
85  efficHist->SetBinError(i, sqrt(effVal * effVal + errVal * errVal));
86  }
87  return efficHist;
88 }
89 
90 void MuonGEMRecHitsHarvestor::ProcessBooking( DQMStore::IBooker& ibooker, DQMStore::IGetter& ig, const char* label, TString suffix, TH1F* track_hist, TH1F* sh_hist )
91 {
92  TString dbe_label = TString(dbe_path_)+label+suffix;
93  if( ig.get(dbe_label.Data()) != nullptr && sh_hist !=nullptr && track_hist !=nullptr ) {
94  TH1F* hist = (TH1F*)ig.get( dbe_label.Data() )->getTH1F()->Clone();
95  TProfile* profile = ComputeEff( hist, track_hist);
96  TProfile* profile_sh = ComputeEff( hist, sh_hist );
97  profile_sh->SetName( (profile->GetName()+std::string("_sh")).c_str());
98  TString x_axis_title = TString(hist->GetXaxis()->GetTitle());
99  TString title = TString::Format("Eff. for a SimTrack to have an associated GEM RecHits in %s;%s;Eff.",suffix.Data(),x_axis_title.Data());
100  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() );
101  profile->SetTitle( title.Data());
102  profile_sh->SetTitle( title2.Data() );
103  ibooker.bookProfile( profile->GetName(),profile);
104  ibooker.bookProfile( profile_sh->GetName(),profile_sh);
105  }
106  else {
107  std::cout<<"Can not found histogram of "<<dbe_label<<std::endl;
108  if ( track_hist == nullptr) std::cout<<"track not found"<<std::endl;
109  if ( sh_hist == nullptr) std::cout<<"sh_hist not found"<<std::endl;
110  }
111  return;
112 }
113 
114 
115 void
117 {
118  ig.setCurrentFolder(dbe_path_.c_str());
119 
120  const char* l_suffix[4] = {"_l1","_l2","_l1or2","_l1and2"};
121  const char* s_suffix[2] = {"_st1","_st2"};
122  const char* c_suffix[3] = {"_even","_odd","_all"};
123 
124  TH1F* gem_trk_eta[2];
125  TH1F* gem_trk_phi[2][2];
126 
127  TH1F* sh_eta[2][4];
128  TH1F* sh_phi[2][4][3];
129 
130  for( int i = 0 ; i < 2 ; i++) {
131  TString eta_label = TString(dbe_path_)+"track_eta"+s_suffix[i];
132  TString phi_label;
133  if ( ig.get(eta_label.Data()) != nullptr ) {
134  gem_trk_eta[i] = (TH1F*)ig.get(eta_label.Data())->getTH1F()->Clone();
135  gem_trk_eta[i]->Sumw2();
136  }
137  else std::cout<<"Can not found track_eta"<<std::endl;
138  for ( int k=0 ; k <3 ; k++) {
139  phi_label = TString(dbe_path_.c_str())+"track_phi"+s_suffix[i]+c_suffix[k];
140  if ( ig.get(phi_label.Data()) !=nullptr ) {
141  gem_trk_phi[i][k] = (TH1F*)ig.get(phi_label.Data())->getTH1F()->Clone();
142  gem_trk_phi[i][k]->Sumw2();
143  }
144  else std::cout<<"Can not found track_phi"<<std::endl;
145  }
146 
147  if ( ig.get(eta_label.Data()) != nullptr && ig.get(phi_label.Data()) !=nullptr ) {
148  for( int j = 0; j < 4 ; j++) {
149  TString suffix = TString( s_suffix[i] )+TString( l_suffix[j]);
150  TString eta_label = TString(dbe_path_)+"rh_sh_eta"+suffix;
151  if( ig.get(eta_label.Data()) !=nullptr ) {
152  sh_eta[i][j] = (TH1F*)ig.get(eta_label.Data())->getTH1F()->Clone();
153  sh_eta[i][j]->Sumw2();
154  }
155  else std::cout<<"Can not found eta histogram : "<<eta_label<<std::endl;
156  ProcessBooking( ibooker, ig, "rh_eta", suffix, gem_trk_eta[i], sh_eta[i][j]);
157  for ( int k= 0 ; k< 3 ; k++) {
158  suffix = TString( s_suffix[i])+TString( l_suffix[j]) +TString(c_suffix[k]);
159  TString phi_label = TString(dbe_path_)+"rh_sh_phi"+suffix;
160  if( ig.get(phi_label.Data()) !=nullptr ) {
161  sh_phi[i][j][k] = (TH1F*)ig.get(phi_label.Data())->getTH1F()->Clone();
162  sh_phi[i][j][k]->Sumw2();
163  }
164  else { std::cout<<"Can not found phi plots : "<<phi_label<<std::endl; continue; }
165  ProcessBooking( ibooker, ig, "rh_phi",suffix, gem_trk_phi[i][k], sh_phi[i][j][k]);
166  }
167  }
168  }
169  else std::cout<<"Can not find eta or phi of all track"<<std::endl;
170  }
171 }
172 
173 
174 //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:157
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:305
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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]
virtual ~MuonGEMRecHitsHarvestor()
destructor
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:347
void ProcessBooking(DQMStore::IBooker &, DQMStore::IGetter &, const char *label, TString suffix, TH1F *track_hist, TH1F *sh_hist)
virtual void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &)
static const std::array< std::string, 3 > c_suffix
Definition: GEMDetLabel.h:6