CMS 3D CMS Logo

GenericBenchmark.cc
Go to the documentation of this file.
3 
4 #include <TROOT.h>
5 #include <TFile.h>
6 
7 //Colin: it seems a bit strange to use the preprocessor for that kind of
8 //thing. Looks like all these macros could be replaced by plain functions.
9 
10 // preprocessor macro for booking 1d histos with DQMStore -or- bare Root
11 #define BOOK1D(name, title, nbinsx, lowx, highx) \
12  h##name = \
13  DQM ? DQM->book1D(#name, title, nbinsx, lowx, highx)->getTH1F() : new TH1F(#name, title, nbinsx, lowx, highx)
14 
15 // preprocessor macro for booking 2d histos with DQMStore -or- bare Root
16 #define BOOK2D(name, title, nbinsx, lowx, highx, nbinsy, lowy, highy) \
17  h##name = DQM ? DQM->book2D(#name, title, nbinsx, lowx, highx, nbinsy, lowy, highy)->getTH2F() \
18  : new TH2F(#name, title, nbinsx, lowx, highx, nbinsy, lowy, highy)
19 
20 // all versions OK
21 // preprocesor macro for setting axis titles
22 
23 #define SETAXES(name, xtitle, ytitle) \
24  h##name->GetXaxis()->SetTitle(xtitle); \
25  h##name->GetYaxis()->SetTitle(ytitle)
26 
27 #define ET (PlotAgainstReco_) ? "reconstructed E_{T} [GeV]" : "generated E_{T} [GeV]"
28 #define ETA (PlotAgainstReco_) ? "reconstructed #eta" : "generated #eta"
29 #define PHI (PlotAgainstReco_) ? "reconstructed #phi (rad)" : "generated #phi (rad)"
30 
31 using namespace std;
32 
34 
36 
38  bool PlotAgainstReco_,
39  float minDeltaEt,
40  float maxDeltaEt,
41  float minDeltaPhi,
42  float maxDeltaPhi,
43  bool doMetPlots) {
44  //std::cout << "minDeltaPhi = " << minDeltaPhi << std::endl;
45 
46  // CMSSW_2_X_X
47  // use bare Root if no DQM (FWLite applications)
48  //if (!DQM)
49  //{
50  // file_ = new TFile("pfmetBenchmark.root", "recreate");
51  // cout << "Info: DQM is not available to provide data storage service. Using TFile to save histograms. "<<endl;
52  //}
53  // Book Histograms
54 
55  //std::cout << "FL : pwd = ";
56  //gDirectory->pwd();
57  //std::cout << std::endl;
58 
59  int nbinsEt = 1000;
60  float minEt = 0;
61  float maxEt = 1000;
62 
63  //float minDeltaEt = -100;
64  //float maxDeltaEt = 50;
65 
66  int nbinsEta = 200;
67  float minEta = -5;
68  float maxEta = 5;
69 
70  int nbinsDeltaEta = 1000;
71  float minDeltaEta = -0.5;
72  float maxDeltaEta = 0.5;
73 
74  int nbinsDeltaPhi = 1000;
75  //float minDeltaPhi = -0.5;
76  //float maxDeltaPhi = 0.5;
77 
78  // delta et quantities
79  BOOK1D(DeltaEt, "#DeltaE_{T}", nbinsEt, minDeltaEt, maxDeltaEt);
80  BOOK1D(DeltaEx, "#DeltaE_{X}", nbinsEt, minDeltaEt, maxDeltaEt);
81  BOOK1D(DeltaEy, "#DeltaE_{Y}", nbinsEt, minDeltaEt, maxDeltaEt);
82  BOOK2D(DeltaEtvsEt, "#DeltaE_{T} vs E_{T}", nbinsEt, minEt, maxEt, nbinsEt, minDeltaEt, maxDeltaEt);
83  BOOK2D(DeltaEtOverEtvsEt, "#DeltaE_{T}/E_{T} vsE_{T}", nbinsEt, minEt, maxEt, nbinsEt, -1, 1);
84  BOOK2D(DeltaEtvsEta, "#DeltaE_{T} vs #eta", nbinsEta, minEta, maxEta, nbinsEt, minDeltaEt, maxDeltaEt);
85  BOOK2D(DeltaEtOverEtvsEta, "#DeltaE_{T}/E_{T} vs #eta", nbinsEta, minEta, maxEta, 100, -1, 1);
86  BOOK2D(DeltaEtvsPhi, "#DeltaE_{T} vs #phi", 200, -M_PI, M_PI, nbinsEt, minDeltaEt, maxDeltaEt);
87  BOOK2D(DeltaEtOverEtvsPhi, "#DeltaE_{T}/E_{T} vs #Phi", 200, -M_PI, M_PI, 100, -1, 1);
88  BOOK2D(DeltaEtvsDeltaR, "#DeltaE_{T} vs #DeltaR", 100, 0, 1, nbinsEt, minDeltaEt, maxDeltaEt);
89  BOOK2D(DeltaEtOverEtvsDeltaR, "#DeltaE_{T}/E_{T} vs #DeltaR", 100, 0, 1, 100, -1, 1);
90 
91  // delta eta quantities
93  BOOK2D(DeltaEtavsEt, "#Delta#eta vs E_{T}", nbinsEt, minEt, maxEt, nbinsDeltaEta, minDeltaEta, maxDeltaEta);
94  BOOK2D(DeltaEtavsEta, "#Delta#eta vs #eta", nbinsEta, minEta, maxEta, nbinsDeltaEta, minDeltaEta, maxDeltaEta);
95 
96  // delta phi quantities
98  BOOK2D(DeltaPhivsEt, "#Delta#phi vs E_{T}", nbinsEt, minEt, maxEt, nbinsDeltaPhi, minDeltaPhi, maxDeltaPhi);
99  BOOK2D(DeltaPhivsEta, "#Delta#phi vs #eta", nbinsEta, minEta, maxEta, nbinsDeltaPhi, minDeltaPhi, maxDeltaPhi);
100 
101  // delta R quantities
102  BOOK1D(DeltaR, "#DeltaR", 100, 0, 1);
103  BOOK2D(DeltaRvsEt, "#DeltaR vs E_{T}", nbinsEt, minEt, maxEt, 100, 0, 1);
104  BOOK2D(DeltaRvsEta, "#DeltaR vs #eta", nbinsEta, minEta, maxEta, 100, 0, 1);
105 
106  BOOK1D(NRec, "Number of reconstructed objects", 20, 0, 20);
107 
108  // seen and gen distributions, for efficiency computation
109  BOOK1D(EtaSeen, "seen #eta", 100, -5, 5);
110  BOOK1D(PhiSeen, "seen #phi", 100, -3.5, 3.5);
111  BOOK1D(EtSeen, "seen E_{T}", nbinsEt, minEt, maxEt);
112  BOOK2D(EtvsEtaSeen, "seen E_{T} vs eta", 100, -5, 5, 200, 0, 200);
113  BOOK2D(EtvsPhiSeen, "seen E_{T} vs seen #phi", 100, -3.5, 3.5, 200, 0, 200);
114 
115  BOOK1D(PhiRec, "Rec #phi", 100, -3.5, 3.5);
116  BOOK1D(EtRec, "Rec E_{T}", nbinsEt, minEt, maxEt);
117  BOOK1D(ExRec, "Rec E_{X}", nbinsEt, -maxEt, maxEt);
118  BOOK1D(EyRec, "Rec E_{Y}", nbinsEt, -maxEt, maxEt);
119 
120  BOOK2D(EtRecvsEt, "Rec E_{T} vs E_{T}", nbinsEt, minEt, maxEt, nbinsEt, minEt, maxEt);
121  BOOK2D(EtRecOverTrueEtvsTrueEt, "Rec E_{T} / E_{T} vs E_{T}", nbinsEt, minEt, maxEt, 1000, 0., 100.);
122 
123  BOOK1D(EtaGen, "generated #eta", 100, -5, 5);
124  BOOK1D(PhiGen, "generated #phi", 100, -3.5, 3.5);
125  BOOK1D(EtGen, "generated E_{T}", nbinsEt, minEt, maxEt);
126  BOOK2D(EtvsEtaGen, "generated E_{T} vs generated #eta", 100, -5, 5, 200, 0, 200);
127  BOOK2D(EtvsPhiGen, "generated E_{T} vs generated #phi", 100, -3.5, 3.5, 200, 0, 200);
128 
129  BOOK1D(NGen, "Number of generated objects", 20, 0, 20);
130 
131  if (doMetPlots) {
132  BOOK1D(SumEt, "SumEt", 1000, 0., 3000.);
133  BOOK1D(TrueSumEt, "TrueSumEt", 1000, 0., 3000.);
134  BOOK2D(DeltaSetvsSet, "#DeltaSEt vs trueSEt", 3000, 0., 3000., 1000, -1000., 1000.);
135  BOOK2D(DeltaMexvsSet, "#DeltaMEX vs trueSEt", 3000, 0., 3000., 1000, -400., 400.);
136  BOOK2D(DeltaSetOverSetvsSet, "#DeltaSetOverSet vs trueSet", 3000, 0., 3000., 1000, -1., 1.);
137  BOOK2D(RecSetvsTrueSet, "Set vs trueSet", 3000, 0., 3000., 3000, 0., 3000.);
138  BOOK2D(RecSetOverTrueSetvsTrueSet, "Set/trueSet vs trueSet", 3000, 0., 3000., 500, 0., 2.);
139  BOOK2D(TrueMexvsTrueSet, "trueMex vs trueSet", 3000, 0., 3000., nbinsEt, -maxEt, maxEt);
140  }
141  // number of truth particles found within given cone radius of reco
142  //BOOK2D(NumInConeVsConeSize,NumInConeVsConeSize,100,0,1,25,0,25);
143 
144  // Set Axis Titles
145 
146  // delta et quantities
147  SETAXES(DeltaEt, "#DeltaE_{T} [GeV]", "");
148  SETAXES(DeltaEx, "#DeltaE_{X} [GeV]", "");
149  SETAXES(DeltaEy, "#DeltaE_{Y} [GeV]", "");
150  SETAXES(DeltaEtvsEt, ET, "#DeltaE_{T} [GeV]");
151  SETAXES(DeltaEtOverEtvsEt, ET, "#DeltaE_{T}/E_{T}");
152  SETAXES(DeltaEtvsEta, ETA, "#DeltaE_{T} [GeV]");
153  SETAXES(DeltaEtOverEtvsEta, ETA, "#DeltaE_{T}/E_{T}");
154  SETAXES(DeltaEtvsPhi, PHI, "#DeltaE_{T} [GeV]");
155  SETAXES(DeltaEtOverEtvsPhi, PHI, "#DeltaE_{T}/E_{T}");
156  SETAXES(DeltaEtvsDeltaR, "#DeltaR", "#DeltaE_{T} [GeV]");
157  SETAXES(DeltaEtOverEtvsDeltaR, "#DeltaR", "#DeltaE_{T}/E_{T}");
158 
159  // delta eta quantities
160  SETAXES(DeltaEta, "#Delta#eta", "Events");
161  SETAXES(DeltaEtavsEt, ET, "#Delta#eta");
162  SETAXES(DeltaEtavsEta, ETA, "#Delta#eta");
163 
164  // delta phi quantities
165  SETAXES(DeltaPhi, "#Delta#phi [rad]", "Events");
166  SETAXES(DeltaPhivsEt, ET, "#Delta#phi [rad]");
167  SETAXES(DeltaPhivsEta, ETA, "#Delta#phi [rad]");
168 
169  // delta R quantities
170  SETAXES(DeltaR, "#DeltaR", "Events");
171  SETAXES(DeltaRvsEt, ET, "#DeltaR");
172  SETAXES(DeltaRvsEta, ETA, "#DeltaR");
173 
174  SETAXES(NRec, "Number of Rec Objects", "");
175 
176  SETAXES(EtaSeen, "seen #eta", "");
177  SETAXES(PhiSeen, "seen #phi [rad]", "");
178  SETAXES(EtSeen, "seen E_{T} [GeV]", "");
179  SETAXES(EtvsEtaSeen, "seen #eta", "seen E_{T}");
180  SETAXES(EtvsPhiSeen, "seen #phi [rad]", "seen E_{T}");
181 
182  SETAXES(PhiRec, "#phi [rad]", "");
183  SETAXES(EtRec, "E_{T} [GeV]", "");
184  SETAXES(ExRec, "E_{X} [GeV]", "");
185  SETAXES(EyRec, "E_{Y} [GeV]", "");
186  SETAXES(EtRecvsEt, ET, "Rec E_{T} [GeV]");
187  SETAXES(EtRecOverTrueEtvsTrueEt, ET, "Rec E_{T} / E_{T} [GeV]");
188 
189  SETAXES(EtaGen, "generated #eta", "");
190  SETAXES(PhiGen, "generated #phi [rad]", "");
191  SETAXES(EtGen, "generated E_{T} [GeV]", "");
192  SETAXES(EtvsPhiGen, "generated #phi [rad]", "generated E_{T} [GeV]");
193  SETAXES(EtvsEtaGen, "generated #eta", "generated E_{T} [GeV]");
194 
195  SETAXES(NGen, "Number of Gen Objects", "");
196 
197  if (doMetPlots) {
198  SETAXES(SumEt, "SumEt [GeV]", "");
199  SETAXES(TrueSumEt, "TrueSumEt [GeV]", "");
200  SETAXES(DeltaSetvsSet, "TrueSumEt", "#DeltaSumEt [GeV]");
201  SETAXES(DeltaMexvsSet, "TrueSumEt", "#DeltaMEX [GeV]");
202  SETAXES(DeltaSetOverSetvsSet, "TrueSumEt", "#DeltaSumEt/trueSumEt");
203  SETAXES(RecSetvsTrueSet, "TrueSumEt", "SumEt");
204  SETAXES(RecSetOverTrueSetvsTrueSet, "TrueSumEt", "SumEt/trueSumEt");
205  SETAXES(TrueMexvsTrueSet, "TrueSumEt", "TrueMEX");
206  }
207 
208  TDirectory* oldpwd = gDirectory;
209 
210  TIter next(gROOT->GetListOfFiles());
211 
212  const bool debug = false;
213 
214  while (TFile* file = (TFile*)next()) {
215  if (debug)
216  cout << "file " << file->GetName() << endl;
217  }
218  if (DQM) {
219  cout << "DQM subdir" << endl;
220  cout << DQM->pwd().c_str() << endl;
221 
222  DQM->cd(DQM->pwd());
223  }
224 
225  if (debug) {
226  cout << "current dir" << endl;
227  gDirectory->pwd();
228  }
229 
230  oldpwd->cd();
231  //gDirectory->pwd();
232 
233  doMetPlots_ = doMetPlots;
234 
235  // tree_ = new BenchmarkTree("genericBenchmark", "Generic Benchmark TTree");
236 }
237 
239  double ptCut,
240  double minEtaCut,
241  double maxEtaCut) const {
242  //skip reconstructed PFJets with p_t < recPt_cut
243  if (particle->pt() < ptCut and ptCut != -1.)
244  return false;
245 
246  if (fabs(particle->eta()) > maxEtaCut and maxEtaCut > 0)
247  return false;
248  if (fabs(particle->eta()) < minEtaCut and minEtaCut > 0)
249  return false;
250 
251  //accepted!
252  return true;
253 }
254 
256  const reco::Candidate* recParticle,
257  double deltaR_cut,
258  bool plotAgainstReco) {
259  // get the quantities to place on the denominator and/or divide by
260  double et = genParticle->et();
261  double eta = genParticle->eta();
262  double phi = genParticle->phi();
263  //std::cout << "FL : et = " << et << std::endl;
264  //std::cout << "FL : eta = " << eta << std::endl;
265  //std::cout << "FL : phi = " << phi << std::endl;
266  //std::cout << "FL : rec et = " << recParticle->et() << std::endl;
267  //std::cout << "FL : rec eta = " << recParticle->eta() << std::endl;
268  //std::cout << "FL : rec phi = " <<recParticle-> phi() << std::endl;
269 
270  if (plotAgainstReco) {
271  et = recParticle->et();
272  eta = recParticle->eta();
273  phi = recParticle->phi();
274  }
275 
276  // get the delta quantities
277  double deltaEt = algo_->deltaEt(recParticle, genParticle);
278  double deltaR = algo_->deltaR(recParticle, genParticle);
279  double deltaEta = algo_->deltaEta(recParticle, genParticle);
280  double deltaPhi = algo_->deltaPhi(recParticle, genParticle);
281 
282  //std::cout << "FL :deltaR_cut = " << deltaR_cut << std::endl;
283  //std::cout << "FL :deltaR = " << deltaR << std::endl;
284 
285  if (deltaR > deltaR_cut && deltaR_cut != -1.)
286  return;
287 
288  hDeltaEt->Fill(deltaEt);
289  hDeltaEx->Fill(recParticle->px() - genParticle->px());
290  hDeltaEy->Fill(recParticle->py() - genParticle->py());
291  hDeltaEtvsEt->Fill(et, deltaEt);
292  hDeltaEtOverEtvsEt->Fill(et, deltaEt / et);
293  hDeltaEtvsEta->Fill(eta, deltaEt);
294  hDeltaEtOverEtvsEta->Fill(eta, deltaEt / et);
295  hDeltaEtvsPhi->Fill(phi, deltaEt);
296  hDeltaEtOverEtvsPhi->Fill(phi, deltaEt / et);
297  hDeltaEtvsDeltaR->Fill(deltaR, deltaEt);
298  hDeltaEtOverEtvsDeltaR->Fill(deltaR, deltaEt / et);
299 
300  hDeltaEta->Fill(deltaEta);
301  hDeltaEtavsEt->Fill(et, deltaEta);
302  hDeltaEtavsEta->Fill(eta, deltaEta);
303 
304  hDeltaPhi->Fill(deltaPhi);
305  hDeltaPhivsEt->Fill(et, deltaPhi);
306  hDeltaPhivsEta->Fill(eta, deltaPhi);
307 
308  hDeltaR->Fill(deltaR);
309  hDeltaRvsEt->Fill(et, deltaR);
310  hDeltaRvsEta->Fill(eta, deltaR);
311 
313  entry.deltaEt = deltaEt;
314  entry.deltaEta = deltaEta;
315  entry.et = et;
316  entry.eta = eta;
317 
318  if (doMetPlots_) {
319  const reco::MET* met1 = static_cast<const reco::MET*>(genParticle);
320  const reco::MET* met2 = static_cast<const reco::MET*>(recParticle);
321  if (met1 != nullptr && met2 != nullptr) {
322  //std::cout << "FL: met1.sumEt() = " << (*met1).sumEt() << std::endl;
323  hTrueSumEt->Fill((*met1).sumEt());
324  hSumEt->Fill((*met2).sumEt());
325  hDeltaSetvsSet->Fill((*met1).sumEt(), (*met2).sumEt() - (*met1).sumEt());
326  hDeltaMexvsSet->Fill((*met1).sumEt(), recParticle->px() - genParticle->px());
327  hDeltaMexvsSet->Fill((*met1).sumEt(), recParticle->py() - genParticle->py());
328  if ((*met1).sumEt() > 0.01)
329  hDeltaSetOverSetvsSet->Fill((*met1).sumEt(), ((*met2).sumEt() - (*met1).sumEt()) / (*met1).sumEt());
330  hRecSetvsTrueSet->Fill((*met1).sumEt(), (*met2).sumEt());
331  hRecSetOverTrueSetvsTrueSet->Fill((*met1).sumEt(), (*met2).sumEt() / ((*met1).sumEt()));
332  hTrueMexvsTrueSet->Fill((*met1).sumEt(), (*met1).px());
333  hTrueMexvsTrueSet->Fill((*met1).sumEt(), (*met1).py());
334  } else {
335  std::cout << "Warning : reco::MET* == NULL" << std::endl;
336  }
337  }
338 
339  // tree_->Fill(entry);
340 }
341 
343  if (!Filename.empty() && file_)
344  file_->Write(Filename.c_str());
345 }
346 
347 void GenericBenchmark::setfile(TFile* file) { file_ = file; }
void fillHistos(const reco::Candidate *genParticle, const reco::Candidate *recParticle, double deltaR_cut, bool plotAgainstReco)
Definition: DeltaR.py:1
void Fill(double xEntry, double yEntry, double zEntry, double path, double path_x, double SM, double pAbs, double En, int type)
Definition: Histograms.h:464
virtual double et() const =0
transverse energy
virtual double pt() const =0
transverse momentum
#define BOOK1D(name, title, nbinsx, lowx, highx)
void setfile(TFile *file)
Definition: DQM.py:1
double maxEta
static const double deltaEta
Definition: CaloConstants.h:8
virtual ~GenericBenchmark() noexcept(false)
#define ETA
Definition: MET.h:41
#define BOOK2D(name, title, nbinsx, lowx, highx, nbinsy, lowy, highy)
virtual double py() const =0
y coordinate of momentum vector
#define M_PI
virtual double px() const =0
x coordinate of momentum vector
bool accepted(const reco::Candidate *particle, double ptCut, double minEtaCut, double maxEtaCut) const
bool plotAgainstReco
#define debug
Definition: HDRShower.cc:19
#define PHI
void write(std::string Filename)
#define ET
#define SETAXES(name, xtitle, ytitle)
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
void setup(DQMStore *DQM=nullptr, bool PlotAgainstReco_=true, float minDeltaEt=-100., float maxDeltaEt=50., float minDeltaPhi=-0.5, float maxDeltaPhi=0.5, bool doMetPlots=false)