CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MatchCandidateBenchmark.cc
Go to the documentation of this file.
2 
4 
5 
6 // #include "DQMServices/Core/interface/MonitorElement.h"
7 // #include "DQMServices/Core/interface/DQMStore.h"
8 
9 #include <TROOT.h>
10 #include <TFile.h>
11 #include <TH1.h>
12 #include <TH2.h>
13 
14 #include <TProfile.h>
15 
16 using namespace std;
17 
19 
21  delta_et_VS_et_ = 0;
22  delta_eta_VS_et_ = 0;
23  delta_phi_VS_et_ = 0;
24 
27  // pTRes are initialzied in the setup since ptBinsPS.size() is needed
28 
29  histogramBooked_ = false;
30 }
31 
33 
34 
36  if (!histogramBooked_) {
37  PhaseSpace ptPS;
38  PhaseSpace dptOvptPS;
39  PhaseSpace dptPS;
40  PhaseSpace detaPS;
41  PhaseSpace dphiPS;
42  switch(mode_) {
43  case VALIDATION:
44  ptPS = PhaseSpace(100,0,1000);
45  dptOvptPS = PhaseSpace( 200, -1, 1);
46  dphiPS = PhaseSpace( 200, -1, 1);
47  detaPS = PhaseSpace( 200, -1, 1);
48  dptPS = PhaseSpace( 100, -100, 100);
49  break;
50  case DQMOFFLINE:
51  default:
52  ptPS = PhaseSpace(50,0,100);
53  dptOvptPS = PhaseSpace( 50, -1, 1);
54  dphiPS = PhaseSpace( 50, -1, 1);
55  detaPS = PhaseSpace( 50, -1, 1);
56  dptPS = PhaseSpace( 50, -50, 50);
57  break;
58  }
59  float ptBins[11] = {0, 1, 2, 5, 10, 20, 50, 100, 200, 400, 1000};
60  int size = sizeof(ptBins)/sizeof(*ptBins);
61 
62  delta_et_Over_et_VS_et_ = book2D("delta_et_Over_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
63  size, ptBins,
64  dptOvptPS.n, dptOvptPS.m, dptOvptPS.M );
65 
66  BRdelta_et_Over_et_VS_et_ = book2D("BRdelta_et_Over_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
67  size, ptBins,
68  dptOvptPS.n, dptOvptPS.m, dptOvptPS.M );
69  ERdelta_et_Over_et_VS_et_ = book2D("ERdelta_et_Over_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
70  size, ptBins,
71  dptOvptPS.n, dptOvptPS.m, dptOvptPS.M );
72 
73  delta_et_VS_et_ = book2D("delta_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}",
74  size, ptBins,
75  dptPS.n, dptPS.m, dptPS.M );
76 
77  delta_eta_VS_et_ = book2D("delta_eta_VS_et_", ";#E_{T, true} (GeV);#Delta#eta",
78  size, ptBins,
79  detaPS.n, detaPS.m, detaPS.M );
80 
81  delta_phi_VS_et_ = book2D("delta_phi_VS_et_", ";E_{T, true} (GeV);#Delta#phi",
82  size, ptBins,
83  dphiPS.n, dphiPS.m, dphiPS.M );
84  /*
85  // TProfile
86  profile_delta_et_Over_et_VS_et_ = bookProfile("profile_delta_et_Over_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
87  size, ptBins,
88  dptOvptPS.m, dptOvptPS.M, "" );
89 
90  profile_delta_et_VS_et_ = bookProfile("profile_delta_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}",
91  size, ptBins,
92  dptPS.m, dptPS.M, "" );
93 
94  profile_delta_eta_VS_et_ = bookProfile("profile_delta_eta_VS_et_", ";#E_{T, true} (GeV);#Delta#eta",
95  size, ptBins,
96  detaPS.m, detaPS.M, "" );
97 
98  profile_delta_phi_VS_et_ = bookProfile("profile_delta_phi_VS_et_", ";E_{T, true} (GeV);#Delta#phi",
99  size, ptBins,
100  dphiPS.m, dphiPS.M, "" );
101  // TProfile RMS
102  profileRMS_delta_et_Over_et_VS_et_ = bookProfile("profileRMS_delta_et_Over_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
103  size, ptBins,
104  dptOvptPS.m, dptOvptPS.M, "s" );
105 
106  profileRMS_delta_et_VS_et_ = bookProfile("profileRMS_delta_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}",
107  size, ptBins,
108  dptPS.m, dptPS.M, "s" );
109 
110  profileRMS_delta_eta_VS_et_ = bookProfile("profileRMS_delta_eta_VS_et_", ";#E_{T, true} (GeV);#Delta#eta",
111  size, ptBins,
112  detaPS.m, detaPS.M, "s" );
113 
114  profileRMS_delta_phi_VS_et_ = bookProfile("profileRMS_delta_phi_VS_et_", ";E_{T, true} (GeV);#Delta#phi",
115  size, ptBins,
116  dphiPS.m, dphiPS.M, "s" );
117  */
118  pTRes_.resize(size); BRpTRes_.resize(size); ERpTRes_.resize(size);
119  for (size_t i = 0; i < pTRes_.size(); i++) {
120  pTRes_[i] = 0; BRpTRes_[i] = 0; ERpTRes_[i] = 0; }
121 
122  histogramBooked_ = true;
123  }
124 }
126 
127  std::vector<double> ptBinsPS = parameterSet.getParameter< std::vector<double> >( "VariablePtBins" );
128  pTRes_.resize(ptBinsPS.size()-1); BRpTRes_.resize(ptBinsPS.size()-1); ERpTRes_.resize(ptBinsPS.size()-1);
129  if (pTRes_.size() > 0)
130  for (size_t i = 0; i < pTRes_.size(); i++) {
131  pTRes_[i] = 0; BRpTRes_[i] = 0; ERpTRes_[i] = 0; }
132 
133  if (!histogramBooked_) {
134 
135  edm::ParameterSet ptPS = parameterSet.getParameter<edm::ParameterSet>("PtHistoParameter");
136  edm::ParameterSet dptPS = parameterSet.getParameter<edm::ParameterSet>("DeltaPtHistoParameter");
137  edm::ParameterSet dptOvptPS = parameterSet.getParameter<edm::ParameterSet>("DeltaPtOvPtHistoParameter");
138  edm::ParameterSet detaPS = parameterSet.getParameter<edm::ParameterSet>("DeltaEtaHistoParameter");
139  edm::ParameterSet dphiPS = parameterSet.getParameter<edm::ParameterSet>("DeltaPhiHistoParameter");
140 
141  std::vector<float> ptBins;
142  if (ptBinsPS.size() > 1) {
143  ptBins.reserve(ptBinsPS.size());
144  for (size_t i = 0; i < ptBinsPS.size(); i++)
145  ptBins.push_back(ptBinsPS[i]);
146  } else {
147  Int_t nFixedBins = ptPS.getParameter<int32_t>("nBin");
148  ptBins.reserve(nFixedBins+1);
149  for (Int_t i = 0; i <= nFixedBins; i++)
150  ptBins.push_back(ptPS.getParameter<double>("xMin") + i*((ptPS.getParameter<double>("xMax") - ptPS.getParameter<double>("xMin")) / nFixedBins)) ;
151  ptBinsPS.resize(nFixedBins);
152  }
153 
154  if (dptOvptPS.getParameter<bool>("switchOn")) {
155  delta_et_Over_et_VS_et_ = book2D("delta_et_Over_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
156  ptBinsPS.size()-1, &(ptBins.front()),
157  dptOvptPS.getParameter<int32_t>("nBin"),
158  dptOvptPS.getParameter<double>("xMin"),
159  dptOvptPS.getParameter<double>("xMax"));
160  }
161  if (dptOvptPS.getParameter<bool>("slicingOn")) {
162  for (size_t i = 0; i < pTRes_.size(); i++) {
163  pTRes_[i] = book1D( TString::Format("Pt%d_%d", (int)ptBins[i], (int)ptBins[i+1]), ";#Deltap_{T}/p_{T};Entries",
164  dptOvptPS.getParameter<int32_t>("nBin"),
165  dptOvptPS.getParameter<double>("xMin"),
166  dptOvptPS.getParameter<double>("xMax"));
167  BRpTRes_[i] = book1D( TString::Format("BRPt%d_%d", (int)ptBins[i], (int)ptBins[i+1]), ";#Deltap_{T}/p_{T};Entries",
168  dptOvptPS.getParameter<int32_t>("nBin"),
169  dptOvptPS.getParameter<double>("xMin"),
170  dptOvptPS.getParameter<double>("xMax"));
171  ERpTRes_[i] = book1D( TString::Format("ERPt%d_%d", (int)ptBins[i], (int)ptBins[i+1]), ";#Deltap_{T}/p_{T};Entries",
172  dptOvptPS.getParameter<int32_t>("nBin"),
173  dptOvptPS.getParameter<double>("xMin"),
174  dptOvptPS.getParameter<double>("xMax"));
175  }
176  }
177  if (dptOvptPS.getParameter<bool>("BROn")) {
178  BRdelta_et_Over_et_VS_et_ = book2D("BRdelta_et_Over_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
179  ptBinsPS.size()-1, &(ptBins.front()),
180  dptOvptPS.getParameter<int32_t>("nBin"),
181  dptOvptPS.getParameter<double>("xMin"),
182  dptOvptPS.getParameter<double>("xMax"));
183  }
184  if (dptOvptPS.getParameter<bool>("EROn")) {
185  ERdelta_et_Over_et_VS_et_ = book2D("ERdelta_et_Over_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
186  ptBinsPS.size()-1, &(ptBins.front()),
187  dptOvptPS.getParameter<int32_t>("nBin"),
188  dptOvptPS.getParameter<double>("xMin"),
189  dptOvptPS.getParameter<double>("xMax"));
190  }
191 
192  if (dptPS.getParameter<bool>("switchOn")) {
193  delta_et_VS_et_ = book2D("delta_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}",
194  ptBinsPS.size()-1, &(ptBins.front()),
195  dptPS.getParameter<int32_t>("nBin"),
196  dptPS.getParameter<double>("xMin"),
197  dptPS.getParameter<double>("xMax"));
198  }
199 
200  if (detaPS.getParameter<bool>("switchOn")) {
201  delta_eta_VS_et_ = book2D("delta_eta_VS_et_", ";E_{T, true} (GeV);#Delta#eta",
202  ptBinsPS.size()-1, &(ptBins.front()),
203  detaPS.getParameter<int32_t>("nBin"),
204  detaPS.getParameter<double>("xMin"),
205  detaPS.getParameter<double>("xMax"));
206  }
207 
208  if (dphiPS.getParameter<bool>("switchOn")) {
209  delta_phi_VS_et_ = book2D("delta_phi_VS_et_", ";E_{T, true} (GeV);#Delta#phi",
210  ptBinsPS.size()-1, &(ptBins.front()),
211  dphiPS.getParameter<int32_t>("nBin"),
212  dphiPS.getParameter<double>("xMin"),
213  dphiPS.getParameter<double>("xMax"));
214  }
215  /*
216  // TProfile
217  if (dptOvptPS.getParameter<bool>("switchOn")) {
218  profile_delta_et_Over_et_VS_et_ = bookProfile("profile_delta_et_Over_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
219  ptBinsPS.size()-1, &(ptBins.front()),
220  dptOvptPS.getParameter<double>("xMin"),
221  dptOvptPS.getParameter<double>("xMax"), "" );
222  profileRMS_delta_et_Over_et_VS_et_ = bookProfile("profileRMS_delta_et_Over_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
223  ptBinsPS.size()-1, &(ptBins.front()),
224  dptOvptPS.getParameter<double>("xMin"),
225  dptOvptPS.getParameter<double>("xMax"), "s" );
226  }
227 
228  if (dptPS.getParameter<bool>("switchOn")) {
229  profile_delta_et_VS_et_ = bookProfile("profile_delta_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}",
230  ptBinsPS.size()-1, &(ptBins.front()),
231  dptPS.getParameter<double>("xMin"),
232  dptPS.getParameter<double>("xMax"), "" );
233  profileRMS_delta_et_VS_et_ = bookProfile("profileRMS_delta_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}",
234  ptBinsPS.size()-1, &(ptBins.front()),
235  dptPS.getParameter<double>("xMin"),
236  dptPS.getParameter<double>("xMax"), "s" );
237  }
238 
239  if (detaPS.getParameter<bool>("switchOn")) {
240  profile_delta_eta_VS_et_ = bookProfile("profile_delta_eta_VS_et_", ";E_{T, true} (GeV);#Delta#eta",
241  ptBinsPS.size()-1, &(ptBins.front()),
242  detaPS.getParameter<double>("xMin"),
243  detaPS.getParameter<double>("xMax"), "" );
244  profileRMS_delta_eta_VS_et_ = bookProfile("profileRMS_delta_eta_VS_et_", ";E_{T, true} (GeV);#Delta#eta",
245  ptBinsPS.size()-1, &(ptBins.front()),
246  detaPS.getParameter<double>("xMin"),
247  detaPS.getParameter<double>("xMax"), "s" );
248  }
249 
250  if (dphiPS.getParameter<bool>("switchOn")) {
251  profile_delta_phi_VS_et_ = bookProfile("profile_delta_phi_VS_et_", ";E_{T, true} (GeV);#Delta#phi",
252  ptBinsPS.size()-1, &(ptBins.front()),
253  dphiPS.getParameter<double>("xMin"),
254  dphiPS.getParameter<double>("xMax"), "" );
255  profileRMS_delta_phi_VS_et_ = bookProfile("profileRMS_delta_phi_VS_et_", ";E_{T, true} (GeV);#Delta#phi",
256  ptBinsPS.size()-1, &(ptBins.front()),
257  dphiPS.getParameter<double>("xMin"),
258  dphiPS.getParameter<double>("xMax"), "s" );
259  }*/
260 
261  histogramBooked_ = true;
262  }
263 }
264 
266  const reco::Candidate& matchedCand) {
267 
268  if( !isInRange(cand.pt(), cand.eta(), cand.phi() ) ) return;
269 
270  if (histogramBooked_) {
271  if (delta_et_Over_et_VS_et_) delta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() - matchedCand.pt())/matchedCand.pt() );
272  if ( fabs(cand.eta()) <= 1.4 )
273  if (BRdelta_et_Over_et_VS_et_) BRdelta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() - matchedCand.pt())/matchedCand.pt() );
274  if ( fabs(cand.eta()) >= 1.6 && fabs(cand.eta()) <= 2.4 )
275  if (ERdelta_et_Over_et_VS_et_) ERdelta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() - matchedCand.pt())/matchedCand.pt() );
276  if (delta_et_VS_et_) delta_et_VS_et_->Fill( matchedCand.pt(), cand.pt() - matchedCand.pt() );
277  if (delta_eta_VS_et_) delta_eta_VS_et_->Fill( matchedCand.pt(), cand.eta() - matchedCand.eta() );
278  if (delta_phi_VS_et_) delta_phi_VS_et_->Fill( matchedCand.pt(), cand.phi() - matchedCand.phi() );
279  /*
280  // TProfile
281  if (profile_delta_et_Over_et_VS_et_) {
282  profile_delta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() - matchedCand.pt())/matchedCand.pt() );
283  profileRMS_delta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() - matchedCand.pt())/matchedCand.pt() ); }
284  if (profile_delta_et_VS_et_) {
285  profile_delta_et_VS_et_->Fill( matchedCand.pt(), cand.pt() - matchedCand.pt() );
286  profileRMS_delta_et_VS_et_->Fill( matchedCand.pt(), cand.pt() - matchedCand.pt() ); }
287  if (profile_delta_eta_VS_et_) {
288  profile_delta_eta_VS_et_->Fill( matchedCand.pt(), cand.eta() - matchedCand.eta() );
289  profileRMS_delta_eta_VS_et_->Fill( matchedCand.pt(), cand.eta() - matchedCand.eta() ); }
290  if (profile_delta_phi_VS_et_) {
291  profile_delta_phi_VS_et_->Fill( matchedCand.pt(), cand.phi() - matchedCand.phi() );
292  profileRMS_delta_phi_VS_et_->Fill( matchedCand.pt(), cand.phi() - matchedCand.phi() ); }
293  */
294  }
295 }
296 
298  const reco::Candidate& matchedCand,
300  if( !isInRange(cand.pt(), cand.eta(), cand.phi() ) ) return;
301 
302  if (histogramBooked_) {
303 
304  std::vector<double> ptBinsPS = parameterSet.getParameter< std::vector<double> >( "VariablePtBins" );
305  edm::ParameterSet ptPS = parameterSet.getParameter<edm::ParameterSet>("PtHistoParameter");
306  std::vector<float> ptBins;
307  if (ptBinsPS.size() > 1) {
308  ptBins.reserve(ptBinsPS.size());
309  for (size_t i = 0; i < ptBinsPS.size(); i++) {
310  ptBins.push_back(ptBinsPS[i]);
311  }
312  } else {
313  Int_t nFixedBins = ptPS.getParameter<int32_t>("nBin");
314  ptBins.reserve(nFixedBins + 1);
315  for (Int_t i = 0; i <= nFixedBins; i++) {
316  ptBins.push_back( ptPS.getParameter<double>("xMin") + i*((ptPS.getParameter<double>("xMax") - ptPS.getParameter<double>("xMin")) / nFixedBins) );
317  }
318  ptBinsPS.resize(nFixedBins);
319  }
320 
321  edm::ParameterSet dptOvptPS = parameterSet.getParameter<edm::ParameterSet>("DeltaPtOvPtHistoParameter");
322  if (matchedCand.pt() > ptBins.at(0)) { // underflow problem
323  if (delta_et_Over_et_VS_et_) delta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() - matchedCand.pt()) / matchedCand.pt() );
324  if ( fabs(cand.eta()) >= dptOvptPS.getParameter<double>("BREtaMin") && fabs(cand.eta()) <= dptOvptPS.getParameter<double>("BREtaMax"))
325  if (BRdelta_et_Over_et_VS_et_) BRdelta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() - matchedCand.pt())/matchedCand.pt() );
326  if ( fabs(cand.eta()) >= dptOvptPS.getParameter<double>("EREtaMin") && fabs(cand.eta()) <= dptOvptPS.getParameter<double>("EREtaMax"))
327  if (ERdelta_et_Over_et_VS_et_) ERdelta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() - matchedCand.pt())/matchedCand.pt() );
328  if (delta_et_VS_et_) delta_et_VS_et_->Fill( matchedCand.pt(), cand.pt() - matchedCand.pt() );
329  if (delta_eta_VS_et_) delta_eta_VS_et_->Fill( matchedCand.pt(), cand.eta() - matchedCand.eta() );
330  if (delta_phi_VS_et_) delta_phi_VS_et_->Fill( matchedCand.pt(), cand.phi() - matchedCand.phi() );
331  }
332  /*
333  // TProfile
334  if (profile_delta_et_Over_et_VS_et_) {
335  profile_delta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() - matchedCand.pt())/matchedCand.pt() );
336  profileRMS_delta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() - matchedCand.pt())/matchedCand.pt() ); }
337  if (profile_delta_et_VS_et_) {
338  profile_delta_et_VS_et_->Fill( matchedCand.pt(), cand.pt() - matchedCand.pt() );
339  profileRMS_delta_et_VS_et_->Fill( matchedCand.pt(), cand.pt() - matchedCand.pt() ); }
340  if (profile_delta_eta_VS_et_) {
341  profile_delta_eta_VS_et_->Fill( matchedCand.pt(), cand.eta() - matchedCand.eta() );
342  profileRMS_delta_eta_VS_et_->Fill( matchedCand.pt(), cand.eta() - matchedCand.eta() ); }
343  if (profile_delta_phi_VS_et_) {
344  profile_delta_phi_VS_et_->Fill( matchedCand.pt(), cand.phi() - matchedCand.phi() );
345  profileRMS_delta_phi_VS_et_->Fill( matchedCand.pt(), cand.phi() - matchedCand.phi() ); }
346  */
347 
348  for (size_t i = 0; i < pTRes_.size(); i++) {
349  if (matchedCand.pt() >= ptBins.at(i) && matchedCand.pt() < ptBins.at(i+1)) {
350  if (pTRes_[i]) pTRes_[i]->Fill( (cand.pt() - matchedCand.pt()) / matchedCand.pt() ) ;
351  if ( fabs(cand.eta()) >= dptOvptPS.getParameter<double>("BREtaMin") && fabs(cand.eta()) <= dptOvptPS.getParameter<double>("BREtaMax"))
352  if (BRpTRes_[i]) BRpTRes_[i]->Fill( (cand.pt() - matchedCand.pt()) / matchedCand.pt() ) ; // Fill Barrel
353  if ( fabs(cand.eta()) >= dptOvptPS.getParameter<double>("EREtaMin") && fabs(cand.eta()) <= dptOvptPS.getParameter<double>("EREtaMax"))
354  if (ERpTRes_[i]) ERpTRes_[i]->Fill( (cand.pt() - matchedCand.pt()) / matchedCand.pt() ) ; // Fill Endcap
355  }
356  }
357  }
358 }
359 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void fillOne(const reco::Candidate &candidate, const reco::Candidate &matchedCandidate)
fill histograms with a given particle
virtual float eta() const =0
momentum pseudorapidity
void setup()
book histograms
abstract base class
Definition: Benchmark.h:21
virtual float phi() const =0
momentum azimuthal angle
TH2F * BRdelta_et_Over_et_VS_et_
LEONARDO add these histos.
std::vector< TH1F * > pTRes_
std::vector< TH1F * > BRpTRes_
virtual float pt() const =0
transverse momentum
TH2F * book2D(const char *histname, const char *title, int nbinsx, float xmin, float xmax, int nbinsy, float ymin, float ymax)
book a 2D histogram, either with DQM or plain root.
Definition: Benchmark.cc:43
std::vector< TH1F * > ERpTRes_
Mode mode_
Definition: Benchmark.h:96
bool isInRange(float pt, float eta, float phi) const
Definition: Benchmark.h:59
tuple size
Write out results.
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
TH1F * book1D(const char *histname, const char *title, int nbins, float xmin, float xmax)
book a 1D histogram, either with DQM or plain root.
Definition: Benchmark.cc:25