CMS 3D CMS Logo

ConversionPostprocessing.cc
Go to the documentation of this file.
1 #include <iostream>
2 //
3 
5 
6 //
7 
18 using namespace std;
19 
21  dbe_ = nullptr;
23  parameters_ = pset;
24 
25  standAlone_ = pset.getParameter<bool>("standAlone");
26  batch_ = pset.getParameter<bool>("batch");
27  outputFileName_ = pset.getParameter<string>("OutputFileName");
28  inputFileName_ = pset.getParameter<std::string>("InputFileName");
29 
30  etMin = parameters_.getParameter<double>("etMin");
31  etMax = parameters_.getParameter<double>("etMax");
32  etBin = parameters_.getParameter<int>("etBin");
33 
34  etaMin = parameters_.getParameter<double>("etaMin");
35  etaMax = parameters_.getParameter<double>("etaMax");
36  etaBin = parameters_.getParameter<int>("etaBin");
37  etaBin2 = parameters_.getParameter<int>("etaBin2");
38 
39  phiMin = parameters_.getParameter<double>("phiMin");
40  phiMax = parameters_.getParameter<double>("phiMax");
41  phiBin = parameters_.getParameter<int>("phiBin");
42 
43  rMin = parameters_.getParameter<double>("rMin");
44  rMax = parameters_.getParameter<double>("rMax");
45  rBin = parameters_.getParameter<int>("rBin");
46 
47  zMin = parameters_.getParameter<double>("zMin");
48  zMax = parameters_.getParameter<double>("zMax");
49  zBin = parameters_.getParameter<int>("zBin");
50 }
51 
53 
55 
57 
59  if (standAlone_)
60  runPostprocessing();
61 }
62 
64  if (!standAlone_)
65  runPostprocessing();
66 }
67 
69  std::string simInfoPathName = "EgammaV/ConversionValidator/SimulationInfo/";
70  std::string convPathName = "EgammaV/ConversionValidator/ConversionInfo/";
71  std::string effPathName = "EgammaV/ConversionValidator/EfficienciesAndFakeRate/";
72 
73  if (batch_)
74  dbe_->open(inputFileName_);
75 
76  dbe_->setCurrentFolder(effPathName);
77  // Conversion reconstruction efficiency
78  std::string histname = "convEffVsEtaTwoTracks";
79  convEffEtaTwoTracks_ = dbe_->book1D(histname, histname, etaBin2, etaMin, etaMax);
80 
81  histname = "convEffVsPhiTwoTracks";
82  convEffPhiTwoTracks_ = dbe_->book1D(histname, histname, phiBin, phiMin, phiMax);
83 
84  histname = "convEffVsRTwoTracks";
85  convEffRTwoTracks_ = dbe_->book1D(histname, histname, rBin, rMin, rMax);
86 
87  histname = "convEffVsZTwoTracks";
88  convEffZTwoTracks_ = dbe_->book1D(histname, histname, zBin, zMin, zMax);
89 
90  histname = "convEffVsEtTwoTracks";
91  convEffEtTwoTracks_ = dbe_->book1D(histname, histname, etBin, etMin, etMax);
92  //
93  histname = "convEffVsEtaTwoTracksAndVtxProbGT0";
94  convEffEtaTwoTracksAndVtxProbGT0_ = dbe_->book1D(histname, histname, etaBin2, etaMin, etaMax);
95  histname = "convEffVsEtaTwoTracksAndVtxProbGT0005";
96  convEffEtaTwoTracksAndVtxProbGT0005_ = dbe_->book1D(histname, histname, etaBin2, etaMin, etaMax);
97  histname = "convEffVsRTwoTracksAndVtxProbGT0";
98  convEffRTwoTracksAndVtxProbGT0_ = dbe_->book1D(histname, histname, rBin, rMin, rMax);
99  histname = "convEffVsRTwoTracksAndVtxProbGT0005";
100  convEffRTwoTracksAndVtxProbGT0005_ = dbe_->book1D(histname, histname, rBin, rMin, rMax);
101  //
102  // Fake rate
103  histname = "convFakeRateVsEtaTwoTracks";
104  convFakeRateEtaTwoTracks_ = dbe_->book1D(histname, histname, etaBin2, etaMin, etaMax);
105  histname = "convFakeRateVsPhiTwoTracks";
106  convFakeRatePhiTwoTracks_ = dbe_->book1D(histname, histname, phiBin, phiMin, phiMax);
107  histname = "convFakeRateVsRTwoTracks";
108  convFakeRateRTwoTracks_ = dbe_->book1D(histname, histname, rBin, rMin, rMax);
109  histname = "convFakeRateVsZTwoTracks";
110  convFakeRateZTwoTracks_ = dbe_->book1D(histname, histname, zBin, zMin, zMax);
111  histname = "convFakeRateVsEtTwoTracks";
112  convFakeRateEtTwoTracks_ = dbe_->book1D(histname, histname, etBin, etMin, etMax);
113 
114  // efficiencies
115  dividePlots(dbe_->get(effPathName + "convEffVsEtaTwoTracks"),
116  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksEta"),
117  dbe_->get(simInfoPathName + "h_VisSimConvEta"),
118  "effic");
119  dividePlots(dbe_->get(effPathName + "convEffVsPhiTwoTracks"),
120  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksPhi"),
121  dbe_->get(simInfoPathName + "h_VisSimConvPhi"),
122  "effic");
123  dividePlots(dbe_->get(effPathName + "convEffVsRTwoTracks"),
124  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksR"),
125  dbe_->get(simInfoPathName + "h_VisSimConvR"),
126  "effic");
127  dividePlots(dbe_->get(effPathName + "convEffVsZTwoTracks"),
128  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksZ"),
129  dbe_->get(simInfoPathName + "h_VisSimConvZ"),
130  "effic");
131  dividePlots(dbe_->get(effPathName + "convEffVsEtTwoTracks"),
132  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksEt"),
133  dbe_->get(simInfoPathName + "h_VisSimConvEt"),
134  "effic");
135  dividePlots(dbe_->get(effPathName + "convEffVsEtaTwoTracksAndVtxProbGT0"),
136  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksEtaAndVtxPGT0"),
137  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksEta"),
138  "effic");
139  dividePlots(dbe_->get(effPathName + "convEffVsEtaTwoTracksAndVtxProbGT0005"),
140  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksEtaAndVtxPGT0005"),
141  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksEta"),
142  "effic");
143  dividePlots(dbe_->get(effPathName + "convEffVsRTwoTracksAndVtxProbGT0"),
144  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksRAndVtxPGT0"),
145  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksR"),
146  "effic");
147  dividePlots(dbe_->get(effPathName + "convEffVsRTwoTracksAndVtxProbGT0005"),
148  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksRAndVtxPGT0005"),
149  dbe_->get(simInfoPathName + "h_SimConvTwoMTracksR"),
150  "effic");
151 
152  // fake rate
153  dividePlots(dbe_->get(effPathName + "convFakeRateVsEtaTwoTracks"),
154  dbe_->get(convPathName + "convEtaAss2"),
155  dbe_->get(convPathName + "convEta2"),
156  "fakerate");
157  dividePlots(dbe_->get(effPathName + "convFakeRateVsPhiTwoTracks"),
158  dbe_->get(convPathName + "convPhiAss"),
159  dbe_->get(convPathName + "convPhi"),
160  "fakerate");
161  dividePlots(dbe_->get(effPathName + "convFakeRateVsRTwoTracks"),
162  dbe_->get(convPathName + "convRAss"),
163  dbe_->get(convPathName + "convR"),
164  "fakerate");
165  dividePlots(dbe_->get(effPathName + "convFakeRateVsZTwoTracks"),
166  dbe_->get(convPathName + "convZAss"),
167  dbe_->get(convPathName + "convZ"),
168  "fakerate");
169  dividePlots(dbe_->get(effPathName + "convFakeRateVsEtTwoTracks"),
170  dbe_->get(convPathName + "convPtAss"),
171  dbe_->get(convPathName + "convPt"),
172  "fakerate");
173 
174  if (standAlone_)
175  dbe_->save(outputFileName_);
176  else if (batch_)
177  dbe_->save(inputFileName_);
178 }
179 
183  std::string type) {
184  double value, err;
185 
186  //quick fix to avoid seg. faults due to null pointers.
187  if (dividend == nullptr || numerator == nullptr || denominator == nullptr)
188  return;
189 
190  for (int j = 1; j <= numerator->getNbinsX(); j++) {
191  if (denominator->getBinContent(j) != 0) {
192  if (type == "effic")
193  value = ((double)numerator->getBinContent(j)) / ((double)denominator->getBinContent(j));
194  else if (type == "fakerate")
195  value = 1 - ((double)numerator->getBinContent(j)) / ((double)denominator->getBinContent(j));
196  else
197  return;
198  err = sqrt(value * (1 - value) / ((double)denominator->getBinContent(j)));
199  dividend->setBinContent(j, value);
200  if (err != 0)
201  dividend->setBinError(j, err);
202  } else {
203  dividend->setBinContent(j, 0);
204  dividend->setBinError(j, 0);
205  }
206  }
207 }
208 
210  double value, err;
211 
212  //quick fix to avoid seg. faults due to null pointers.
213  if (dividend == nullptr || numerator == nullptr)
214  return;
215 
216  for (int j = 1; j <= numerator->getNbinsX(); j++) {
217  if (denominator != 0) {
218  value = ((double)numerator->getBinContent(j)) / denominator;
219  err = sqrt(value * (1 - value) / denominator);
220  dividend->setBinContent(j, value);
221  dividend->setBinError(j, err);
222  } else {
223  dividend->setBinContent(j, 0);
224  }
225  }
226 }
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
void analyze(const edm::Event &, const edm::EventSetup &) override
dqm::legacy::DQMStore * dbe_
void dividePlots(MonitorElement *dividend, MonitorElement *numerator, MonitorElement *denominator, std::string type)
void endRun(const edm::Run &, const edm::EventSetup &) override
MonitorElement * get(std::string const &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1509
virtual int getNbinsX() const
get # of bins in X-axis
T sqrt(T t)
Definition: SSEVec.h:19
virtual double getBinContent(int binx) const
get content of bin (1-D)
ConversionPostprocessing(const edm::ParameterSet &pset)
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:639
bool open(std::string const &filename, bool overwrite=false, std::string const &path="", std::string const &prepend="", OpenRunDirs stripdirs=KeepRunDirs, bool fileMustExist=true)
Definition: DQMStore.cc:2626
MonitorElement * book1D(char_string const &name, char_string const &title, int const nchX, double const lowX, double const highX)
Book 1D histogram.
Definition: DQMStore.cc:1121
virtual void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
void save(std::string const &filename, std::string const &path="", std::string const &pattern="", std::string const &rewrite="", uint32_t run=0, uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, std::string const &fileupdate="RECREATE")
Definition: DQMStore.cc:2244
Definition: Run.h:45