CMS 3D CMS Logo

JetMETDQMPostProcessor.cc
Go to the documentation of this file.
1 // Migrated to use DQMEDHarvester by: Jyothsna Rani Komaragiri, Oct 2014
2 
4 
9 
10 
11 #include <iostream>
12 #include <cstring>
13 #include <iomanip>
14 #include<fstream>
15 #include <cmath>
16 
17 
19 {
20  subDir_ = pset.getUntrackedParameter<std::string>("subDir");
21  patternJetTrg_ = pset.getUntrackedParameter<std::string>("PatternJetTrg","");
22  patternMetTrg_ = pset.getUntrackedParameter<std::string>("PatternMetTrg","");
23 }
24 
26 {
28  // setup DQM stor //
30 
31  bool isJetDir = false;
32  bool isMetDir = false;
33 
34  TPRegexp patternJet(patternJetTrg_);
35  TPRegexp patternMet(patternMetTrg_);
36 
37  //go to the directory to be processed
38  if(igetter.dirExists(subDir_)) ibooker.cd(subDir_);
39  else {
40  edm::LogWarning("JetMETDQMPostProcessor") << "cannot find directory: " << subDir_ << " , skipping";
41  return;
42  }
43 
44  std::vector<std::string> subdirectories = igetter.getSubdirs();
45  for(std::vector<std::string>::iterator dir = subdirectories.begin() ;dir!= subdirectories.end(); dir++ ){
46 
47  ibooker.cd(*dir);
48 
49  isJetDir = false;
50  isMetDir = false;
51 
52  if (TString(*dir).Contains(patternJet)) isJetDir = true;
53  if (TString(*dir).Contains(patternMet)) isMetDir = true;
54 
55  if (isMetDir) {
56 
57  //std::cout << "JetMETDQMPostProcessor - Met paths: " << ibooker.pwd() << " " << *dir << std::endl;
58 
59  //GenMET
60  dividehistos(ibooker, igetter, "_meGenMETTrgMC", "_meGenMET", "_meTurnOngMET", "Gen Missing ET", "Gen Missing ET Turn-On RelVal");
61  dividehistos(ibooker, igetter, "_meGenMETTrg", "_meGenMETTrgLow", "_meTurnOngMETLow", "Gen Missing ETLow", "Gen Missing ET Turn-On Data");
62 
63  //HLTMET
64  dividehistos(ibooker, igetter, "_meHLTMETTrgMC", "_meHLTMET", "_meTurnOnhMET", "HLT Missing ET", "HLT Missing ET Turn-On RelVal");
65  dividehistos(ibooker, igetter, "_meHLTMETTrg", "_meHLTMETTrgLow", "_meTurnOnhMETLow", "HLT Missing ETLow", "HLT Missing ET Turn-On Data");
66 
67  }
68 
69  if (isJetDir) {
70 
71  //std::cout << "JetMETDQMPostProcessor - Jet paths: " << ibooker.pwd() << " " << *dir << std::endl;
72 
73  //GenJets
74  dividehistos(ibooker, igetter, "_meGenJetPtTrgMC", "_meGenJetPt", "_meTurnOngJetPt", "Gen Jet Pt", "Gen Jet Pt Turn-On RelVal");
75  dividehistos(ibooker, igetter, "_meGenJetPtTrg", "_meGenJetPtTrgLow", "_meTurnOngJetPt", "Gen Jet PtLow", "Gen Jet Pt Turn-On Data");
76  dividehistos(ibooker, igetter, "_meGenJetEtaTrgMC", "_meGenJetEta", "_meTurnOngJetEta", "Gen Jet Eta", "Gen Jet Eta Turn-On RelVal");
77  dividehistos(ibooker, igetter, "_meGenJetEtaTrg", "_meGenJetEtaTrgLow", "_meTurnOngJetEta", "Gen Jet EtaLow", "Gen Jet Eta Turn-On Data");
78  dividehistos(ibooker, igetter, "_meGenJetPhiTrgMC", "_meGenJetPhi", "_meTurnOngJetPhi", "Gen Jet Phi", "Gen Jet Phi Turn-On RelVal");
79  dividehistos(ibooker, igetter, "_meGenJetPhiTrg", "_meGenJetPhiTrgLow", "_meTurnOngJetPhi", "Gen Jet PhiLow", "Gen Jet Phi Turn-On Data");
80 
81  //HLTJets
82  dividehistos(ibooker, igetter, "_meHLTJetPtTrgMC", "_meHLTJetPt", "_meTurnOnhJetPt", "HLT Jet Pt", "HLT Jet Pt Turn-On RelVal");
83  dividehistos(ibooker, igetter, "_meHLTJetPtTrg", "_meHLTJetPtTrgLow", "_meTurnOnhJetPt", "HLT Jet PtLow", "HLT Jet Pt Turn-On Data");
84  dividehistos(ibooker, igetter, "_meHLTJetEtaTrgMC", "_meHLTJetEta", "_meTurnOnhJetEta", "HLT Jet Eta", "HLT Jet Eta Turn-On RelVal");
85  dividehistos(ibooker, igetter, "_meHLTJetEtaTrg", "_meHLTJetEtaTrgLow", "_meTurnOnhJetEta", "HLT Jet EtaLow", "HLT Jet Eta Turn-On Data");
86  dividehistos(ibooker, igetter, "_meHLTJetPhiTrgMC", "_meHLTJetPhi", "_meTurnOnhJetPhi", "HLT Jet Phi", "HLT Jet Phi Turn-On RelVal");
87  dividehistos(ibooker, igetter, "_meHLTJetPhiTrg", "_meHLTJetPhiTrgLow", "_meTurnOnhJetPhi", "HLT Jet PhiLow", "HLT Jet Phi Turn-On Data");
88 
89  }
90 
91  ibooker.goUp();
92  }
93 }
94 
95 //----------------------------------------------------------------------
96 TProfile*
98  const std::string& outName, const std::string& label, const std::string& titel)
99 {
100  //ibooker.pwd();
101  //std::cout << "In dividehistos: " << ibooker.pwd() << std::endl;
102 
103  //std::cout << numName <<std::endl;
104  TH1F* num = getHistogram(ibooker, igetter, ibooker.pwd()+"/"+numName);
105 
106  //std::cout << denomName << std::endl;
107  TH1F* denom = getHistogram(ibooker, igetter, ibooker.pwd()+"/"+denomName);
108 
109  if (num == nullptr)
110  edm::LogWarning("JetMETDQMPostProcessor") << "numerator histogram " << ibooker.pwd()+"/"+numName << " does not exist";
111  if (denom == nullptr)
112  edm::LogWarning("JetMETDQMPostProcessor") << "denominator histogram " << ibooker.pwd()+"/"+denomName << " does not exist";
113 
114  // Check if histograms actually exist
115  if(!num || !denom) return nullptr;
116 
117  MonitorElement* meOut = ibooker.bookProfile(outName, titel, num->GetXaxis()->GetNbins(), num->GetXaxis()->GetXmin(), num->GetXaxis()->GetXmax(),0.,1.2);
118  meOut->setEfficiencyFlag();
119  TProfile* out = meOut->getTProfile();
120  out->GetXaxis()->SetTitle(label.c_str());
121  out->SetYTitle("Efficiency");
122  out->SetOption("PE");
123  out->SetLineColor(2);
124  out->SetLineWidth(2);
125  out->SetMarkerStyle(20);
126  out->SetMarkerSize(0.8);
127  out->SetStats(kFALSE);
128 
129  for(int i=1;i<=num->GetNbinsX();i++){
130  double e, low, high;
131  Efficiency( (int)num->GetBinContent(i), (int)denom->GetBinContent(i), 0.683, e, low, high );
132  double err = e-low>high-e ? e-low : high-e;
133  //here is the trick to store info in TProfile:
134  out->SetBinContent( i, e );
135  out->SetBinEntries( i, 1 );
136  out->SetBinError( i, sqrt(e*e+err*err) );
137  }
138  return out;
139 }
140 
141 //----------------------------------------------------------------------
142 TH1F *
144 {
145  ibooker.pwd();
146  MonitorElement *monElement = igetter.get(histoPath);
147  if (monElement != nullptr)
148  return monElement->getTH1F();
149  else
150  return nullptr;
151 }
152 
153 //----------------------------------------------------------------------
154 void
155 JetMETDQMPostProcessor::Efficiency(int passing, int total, double level, double &mode, double &lowerBound, double &upperBound)
156 {
157  // protection
158  if (total == 0)
159  {
160  mode = 0.5;
161  lowerBound = 0;
162  upperBound = 1;
163  return;
164  }
165  mode = passing / ((double) total);
166 
167  // see http://root.cern.ch/root/html/TEfficiency.html#compare
168  lowerBound = TEfficiency::Wilson(total, passing, level, false);
169  upperBound = TEfficiency::Wilson(total, passing, level, true);
170 }
171 
172 //----------------------------------------------------------------------
173 
TProfile * getTProfile() const
T getUntrackedParameter(std::string const &, T const &) const
void Efficiency(int passing, int total, double level, double &mode, double &lowerBound, double &upperBound)
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:160
TH1F * getTH1F() const
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:307
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
JetMETDQMPostProcessor(const edm::ParameterSet &pset)
void setEfficiencyFlag()
T sqrt(T t)
Definition: SSEVec.h:18
TH1F * getHistogram(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const std::string &histoPath)
TProfile * dividehistos(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const std::string &numName, const std::string &denomName, const std::string &outName, const std::string &label, const std::string &titel)
bool dirExists(const std::string &path)
Definition: DQMStore.cc:337
const std::string & pwd()
Definition: DQMStore.cc:287
std::vector< std::string > getSubdirs()
Definition: DQMStore.cc:325
dbl *** dir
Definition: mlp_gen.cc:35
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override