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 {
52  dbe_path_ = std::string("MuonGEMHitsV/GEMHitsTask/");
53  outputFile_ = ps.getUntrackedParameter<std::string>("outputFile", "myfile.root");
54 }
55 
56 
58 {
59 }
60 TProfile* MuonGEMHitsHarvestor::ComputeEff(TH1F* num, TH1F* denum )
61 {
62  if ( num==nullptr || denum==nullptr) { std::cout<<"num or denum are missing"<<std::endl; }
63  std::string name = "eff_"+std::string(num->GetName());
64  std::string title = "Eff. "+std::string(num->GetTitle());
65  TProfile * efficHist = new TProfile(name.c_str(), title.c_str(),num->GetXaxis()->GetNbins(), num->GetXaxis()->GetXmin(),num->GetXaxis()->GetXmax());
66  if ( num->GetNbinsX() != denum->GetNbinsX()) { std::cout<<"Wrong Xbin. Please, check histogram's name"<<std::endl; return nullptr; }
67  for (int i=1; i <= num->GetNbinsX(); i++) {
68  const double nNum = num->GetBinContent(i);
69  const double nDenum = denum->GetBinContent(i);
70  if ( nDenum == 0 || nNum > nDenum ) continue;
71  if ( nNum == 0 ) continue;
72  const double effVal = nNum/nDenum;
73  const double errLo = TEfficiency::ClopperPearson((int)nDenum,(int)nNum,0.683,false);
74  const double errUp = TEfficiency::ClopperPearson((int)nDenum,(int)nNum,0.683,true);
75  const double errVal = (effVal - errLo > errUp - effVal) ? effVal - errLo : errUp - effVal;
76  efficHist->SetBinContent(i, effVal);
77  efficHist->SetBinEntries(i, 1);
78  efficHist->SetBinError(i, sqrt(effVal * effVal + errVal * errVal));
79  }
80  return efficHist;
81 }
82 void MuonGEMHitsHarvestor::ProcessBooking( DQMStore::IBooker& ibooker, DQMStore::IGetter& ig, std::string label_suffix, TH1F* track_hist, TH1F* sh_hist )
83 {
84  TString dbe_label = TString(dbe_path_)+label_suffix;
85  //std::cout<<dbe_label<<" "<<track_hist->GetName()<<std::endl;
86  if( ig.get(dbe_label.Data()) != nullptr && track_hist !=nullptr ) {
87  TH1F* hist = (TH1F*)ig.get( dbe_label.Data() )->getTH1F()->Clone();
88  TProfile* profile = ComputeEff( hist, track_hist);
89  TString x_axis_title = TString(hist->GetXaxis()->GetTitle());
90  TString title = TString::Format("Eff. for a SimTrack to have an associated GEM Strip in %s;%s;Eff.",label_suffix.c_str(),x_axis_title.Data());
91  profile->SetTitle( title.Data());
92  ibooker.bookProfile( profile->GetName(),profile);
93  if ( sh_hist!=nullptr) {
94  TProfile* profile_sh = ComputeEff( hist, sh_hist );
95  profile_sh->SetName( (profile->GetName()+std::string("_sh")).c_str());
96  TString title2 = TString::Format("Eff. for a SimTrack to have an associated GEM Strip in %s with a matched SimHit;%s;Eff.",label_suffix.c_str(),x_axis_title.Data() );
97  profile_sh->SetTitle( title2.Data() );
98  ibooker.bookProfile( profile_sh->GetName(),profile_sh);
99  }
100  }
101  return;
102 }
103 
104 void
106 {
107  ig.setCurrentFolder(dbe_path_);
108  TH1F* track_eta[3];
109  TH1F* track_phi[3][3];
110 
111  for (unsigned int i = 0; i < 3; i++) {
112  track_eta[i]=nullptr;
113  for (unsigned int j=0; j < 3; j++) {
114  track_phi[i][j]=nullptr;
115  }
116  }
117 
118  for (unsigned int i = 0; i < s_suffix.size(); i++) {
119  string suffix = s_suffix[i];
120  string track_eta_name = dbe_path_+"track_eta"+suffix;
121  if ( ig.get(track_eta_name) != nullptr) track_eta[i] = (TH1F*)ig.get(track_eta_name)->getTH1F()->Clone();
122  for (unsigned int j = 0; j < l_suffix.size(); j++) {
123  suffix = s_suffix[i]+l_suffix[j];
124  ProcessBooking( ibooker, ig, "sh_eta"+suffix,track_eta[i]);
125  }
126  }
127  for (unsigned int i = 0; i < s_suffix.size(); i++) {
128  for (unsigned int j = 0 ; j < c_suffix.size(); j++) {
129  string suffix = s_suffix[i]+c_suffix[j];
130  string track_phi_name = dbe_path_+"track_phi"+suffix;
131  if ( ig.get(track_phi_name) != nullptr) track_phi[i][j] = (TH1F*)ig.get(track_phi_name)->getTH1F()->Clone();
132  for (unsigned int k = 0; k < l_suffix.size(); k++) {
133  suffix = s_suffix[i]+l_suffix[k]+c_suffix[j];
134  ProcessBooking( ibooker, ig, "sh_phi"+suffix,track_phi[i][j]);
135  }
136  }
137  }
138 }
139 
140 
141 
142 //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
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:113
TH1F * getTH1F() const
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:361
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:18
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:303
int k[5][pyjets_maxn]
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
void ProcessBooking(DQMStore::IBooker &, DQMStore::IGetter &, std::string label_suffix, TH1F *track_hist, TH1F *sh_hist=0)
static const std::array< std::string, 3 > c_suffix
Definition: GEMDetLabel.h:6