CMS 3D CMS Logo

PFClient.cc
Go to the documentation of this file.
2 
7 
8 
12 
13 
14 //
15 // -- Constructor
16 //
18 {
19  folderNames_ = parameterSet.getParameter< std::vector<std::string> >( "FolderNames" );
20  histogramNames_ = parameterSet.getParameter< std::vector<std::string> >( "HistogramNames" );
21  efficiencyFlag_ = parameterSet.getParameter< bool> ("CreateEfficiencyPlots" );
22  effHistogramNames_ = parameterSet.getParameter< std::vector<std::string> >( "HistogramNamesForEfficiencyPlots" );
23  projectionHistogramNames_ = parameterSet.getParameter< std::vector<std::string> >( "HistogramNamesForProjectionPlots" );
24  profileFlag_ = parameterSet.getParameter< bool> ("CreateProfilePlots" );
25  profileHistogramNames_ = parameterSet.getParameter< std::vector<std::string> >( "HistogramNamesForProfilePlots" );
26 }
27 
28 
29 //
30 // -- EndJobBegin Run
31 //
33 {
34  doSummaries(ibooker, igetter);
35  doProjection(ibooker, igetter);
36  if (efficiencyFlag_) doEfficiency(ibooker, igetter);
37  if (profileFlag_) doProfiles(ibooker, igetter);
38 }
39 
40 
41 //
42 // -- Create Summaries
43 //
45 
46  for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin(); ifolder != folderNames_.end(); ifolder++) {
47  std::string path = "ParticleFlow/"+(*ifolder);
48 
49  for (std::vector<std::string>::const_iterator ihist = histogramNames_.begin(); ihist != histogramNames_.end(); ihist++) {
50  std::string hname = (*ihist);
51  createResolutionPlots(ibooker, igetter, path, hname);
52  }
53  }
54 }
55 
56 
57 //
58 // -- Create Projection
59 //
61 
62  for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin();
63  ifolder != folderNames_.end(); ifolder++) {
64  std::string path = "ParticleFlow/"+(*ifolder);
65 
66  for (std::vector<std::string>::const_iterator ihist = projectionHistogramNames_.begin();
67  ihist != projectionHistogramNames_.end(); ihist++) {
68  std::string hname = (*ihist);
69  createProjectionPlots(ibooker, igetter, path, hname);
70  }
71  }
72 }
73 
74 
75 //
76 // -- Create Profile
77 //
79 
80  for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin();
81  ifolder != folderNames_.end(); ifolder++) {
82  std::string path = "ParticleFlow/"+(*ifolder);
83 
84  for (std::vector<std::string>::const_iterator ihist = profileHistogramNames_.begin();
85  ihist != profileHistogramNames_.end(); ihist++) {
86  std::string hname = (*ihist);
87  createProfilePlots(ibooker, igetter, path, hname);
88  }
89  }
90 }
91 
92 
93 //
94 // -- Create Efficiency
95 //
97  for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin();
98  ifolder != folderNames_.end(); ifolder++) {
99  std::string path = "ParticleFlow/"+(*ifolder);
100 
101  for (std::vector<std::string>::const_iterator ihist = effHistogramNames_.begin();
102  ihist != effHistogramNames_.end(); ihist++) {
103  std::string hname = (*ihist);
104  createEfficiencyPlots(ibooker, igetter, path, hname);
105  }
106  }
107 }
108 
109 
110 //
111 // -- Create Resolution Plots
112 //
114  MonitorElement* me = igetter.get(folder+"/"+name);
115 
116  if (!me) return;
117 
118  MonitorElement* me_average;
119  MonitorElement* me_rms;
120  MonitorElement* me_mean;
121  MonitorElement* me_sigma;
122 
123  if ( (me->kind() == MonitorElement::DQM_KIND_TH2F) ||
124  (me->kind() == MonitorElement::DQM_KIND_TH2S) ||
125  (me->kind() == MonitorElement::DQM_KIND_TH2D) ) {
126  TH2* th = me->getTH2F();
127  size_t nbinx = me->getNbinsX();
128  size_t nbiny = me->getNbinsY();
129 
130  float ymin = th->GetYaxis()->GetXmin();
131  float ymax = th->GetYaxis()->GetXmax();
132  std::string xtit = th->GetXaxis()->GetTitle();
133  std::string ytit = th->GetYaxis()->GetTitle();
134  float* xbins = new float[nbinx+1];
135  for (size_t ix = 1; ix < nbinx+1; ++ix) {
136  xbins[ix-1] = th->GetXaxis()->GetBinLowEdge(ix);
137  if (ix == nbinx) xbins[ix] = th->GetXaxis()->GetBinUpEdge(ix);
138  }
139  std::string tit_new = ";"+xtit+";"+ytit;
140  ibooker.setCurrentFolder(folder);
141  MonitorElement* me_slice = ibooker.book1D("PFlowSlice","PFlowSlice",nbiny,ymin,ymax);
142 
143  tit_new = ";"+xtit+";Average_"+ytit;
144  me_average = ibooker.book1D("average_"+name,tit_new, nbinx, xbins);
145  me_average->setEfficiencyFlag();
146  tit_new = ";"+xtit+";RMS_"+ytit;
147  me_rms = ibooker.book1D("rms_"+name,tit_new, nbinx, xbins);
148  me_rms->setEfficiencyFlag();
149  tit_new = ";"+xtit+";Mean_"+ytit;
150  me_mean = ibooker.book1D("mean_"+name,tit_new, nbinx, xbins);
151  me_mean->setEfficiencyFlag();
152  tit_new = ";"+xtit+";Sigma_"+ytit;
153  me_sigma = ibooker.book1D("sigma_"+name,tit_new, nbinx, xbins);
154  me_sigma->setEfficiencyFlag();
155 
156  double average, rms, mean, sigma;
157 
158  for (size_t ix = 1; ix < nbinx+1; ++ix) {
159  me_slice->Reset();
160  for (size_t iy = 1; iy < nbiny+1; ++iy) {
161  me_slice->setBinContent(iy,th->GetBinContent(ix,iy));
162  }
163  getHistogramParameters(me_slice, average, rms, mean, sigma);
164  me_average->setBinContent(ix,average);
165  me_rms->setBinContent(ix,rms);
166  me_mean->setBinContent(ix,mean);
167  me_sigma->setBinContent(ix,sigma);
168  }
169  if (me_slice) igetter.removeElement(me_slice->getName()); //?
170  delete [] xbins;
171  }
172 }
173 
174 
175 //
176 // -- Create Projection Plots
177 //
179  MonitorElement* me = igetter.get(folder+"/"+name);
180  if (!me) return;
181 
182  MonitorElement* projection = nullptr;
183 
184  if ( (me->kind() == MonitorElement::DQM_KIND_TH2F) ||
185  (me->kind() == MonitorElement::DQM_KIND_TH2S) ||
186  (me->kind() == MonitorElement::DQM_KIND_TH2D) ) {
187  TH2* th = me->getTH2F();
188  size_t nbinx = me->getNbinsX();
189  size_t nbiny = me->getNbinsY();
190 
191  float ymin = th->GetYaxis()->GetXmin();
192  float ymax = th->GetYaxis()->GetXmax();
193  std::string xtit = th->GetXaxis()->GetTitle();
194  std::string ytit = th->GetYaxis()->GetTitle();
195  float* xbins = new float[nbinx+1];
196  for (size_t ix = 1; ix < nbinx+1; ++ix) {
197  xbins[ix-1] = th->GetXaxis()->GetBinLowEdge(ix);
198  if (ix == nbinx) xbins[ix] = th->GetXaxis()->GetBinUpEdge(ix);
199  }
200 
201  std::string tit_new;
202  ibooker.setCurrentFolder(folder);
203 
204  if (folder == "ParticleFlow/PFElectronValidation/CompWithGenElectron") {
205  if (name == "delta_et_Over_et_VS_et_") projection = ibooker.book1D("delta_et_Over_et","E_{T} resolution;#DeltaE_{T}/E_{T}",nbiny,ymin,ymax) ;
206  if (name == "delta_et_VS_et_") projection = ibooker.book1D("delta_et_","#DeltaE_{T};#DeltaE_{T}",nbiny,ymin,ymax) ;
207  if (name == "delta_eta_VS_et_") projection = ibooker.book1D("delta_eta_","#Delta#eta;#Delta#eta",nbiny,ymin,ymax) ;
208  if (name == "delta_phi_VS_et_") projection = ibooker.book1D("delta_phi_","#Delta#phi;#Delta#phi",nbiny,ymin,ymax) ;
209  }
210 
211  if (projection) {
212  for (size_t iy = 1; iy < nbiny+1; ++iy) {
213  projection->setBinContent(iy, th->ProjectionY("e")->GetBinContent(iy) ); }
214  projection->setEntries( me->getEntries() ) ;
215  }
216 
217  delete [] xbins;
218  }
219 }
220 
221 
222 //
223 // -- Create Profile Plots
224 //
226  MonitorElement* me = igetter.get(folder+"/"+name);
227  if (!me) return;
228 
229  if ( (me->kind() == MonitorElement::DQM_KIND_TH2F) ||
230  (me->kind() == MonitorElement::DQM_KIND_TH2S) ||
231  (me->kind() == MonitorElement::DQM_KIND_TH2D) ) {
232  TH2* th = me->getTH2F();
233  size_t nbinx = me->getNbinsX();
234 
235  float ymin = th->GetYaxis()->GetXmin();
236  float ymax = th->GetYaxis()->GetXmax();
237  std::string xtit = th->GetXaxis()->GetTitle();
238  std::string ytit = th->GetYaxis()->GetTitle();
239  double* xbins = new double[nbinx+1];
240  for (size_t ix = 1; ix < nbinx+1; ++ix) {
241  xbins[ix-1] = th->GetXaxis()->GetBinLowEdge(ix);
242  if (ix == nbinx) xbins[ix] = th->GetXaxis()->GetBinUpEdge(ix);
243  }
244 
245  std::string tit_new;
246  ibooker.setCurrentFolder(folder);
247  //TProfiles
248  MonitorElement* me_profile[2];
249  me_profile[0] = ibooker.bookProfile("profile_"+name, tit_new,
250  nbinx, xbins, ymin, ymax, "" );
251  me_profile[1] = ibooker.bookProfile("profileRMS_"+name, tit_new,
252  nbinx, xbins, ymin, ymax, "s" );
253  TProfile* profileX = th->ProfileX();
254  //size_t nbiny = me->getNbinsY();
255  //TProfile* profileX = th->ProfileX("",0,nbiny+1); add underflow and overflow
256  static const Int_t NUM_STAT = 7;
257  Double_t stats[NUM_STAT] = {0}; th->GetStats(stats);
258 
259  for (Int_t i = 0; i<2; i++) {
260  if (me_profile[i]) {
261  for (size_t ix = 0; ix <= nbinx+1; ++ix) {
262  me_profile[i]->setBinContent( ix, profileX->GetBinContent(ix)*profileX->GetBinEntries(ix) ) ;
263  //me_profile[i]->Fill( profileX->GetBinCenter(ix), profileX->GetBinContent(ix)*profileX->GetBinEntries(ix) ) ;
264  me_profile[i]->setBinEntries( ix, profileX->GetBinEntries(ix) );
265  me_profile[i]->getTProfile()->GetSumw2()->fArray[ix] = profileX->GetSumw2()->fArray[ix];
266  //me_profile[i]->getTProfile()->GetBinSumw2()->fArray[ix] = profileX->GetBinSumw2()->fArray[ix]; // segmentation violation
267  }
268  }
269  me_profile[i]->getTProfile()->PutStats(stats);
270  me_profile[i]->setEntries( profileX->GetEntries() ) ;
271  }
272 
273  delete [] xbins;
274  }
275 }
276 
277 
278 //
279 // -- Get Histogram Parameters
280 //
282  double& rms,double& mean, double& sigma) {
283  average = 0.0;
284  rms = 0.0;
285  mean = 0.0;
286  sigma = 0.0;
287 
288  if (!me_slice) return;
289  if (me_slice->kind() == MonitorElement::DQM_KIND_TH1F) {
290  average = me_slice->getMean();
291  rms = me_slice->getRMS();
292  TH1F* th_slice = me_slice->getTH1F();
293  if (th_slice && th_slice->GetEntries() > 0) {
294  //need our own copy for thread safety
295  TF1 gaus("mygaus","gaus");
296  th_slice->Fit( &gaus,"Q0");
297  sigma = gaus.GetParameter(2);
298  mean = gaus.GetParameter(1);
299  }
300  }
301 }
302 
303 
304 //
305 // -- Create Efficiency Plots
306 //
308  MonitorElement* me1 = igetter.get(folder+"/"+name+"ref_");
309  MonitorElement* me2 = igetter.get(folder+"/"+name+"gen_");
310  if (!me1 || !me2) return;
311 
312  TH1F* me1_forEff = (TH1F*)me1->getTH1F()->Rebin(2,"me1_forEff");
313  TH1F* me2_forEff = (TH1F*)me2->getTH1F()->Rebin(2,"me2_forEff");
314 
315  MonitorElement* me_eff;
316  if ( (me1->kind() == MonitorElement::DQM_KIND_TH1F) &&
317  (me1->kind() == MonitorElement::DQM_KIND_TH1F) ) {
318  //TH1* th1 = me1->getTH1F();
319  //size_t nbinx = me1->getNbinsX();
320  size_t nbinx = me1_forEff->GetNbinsX();
321 
322  //float xmin = th1->GetXaxis()->GetXmin();
323  //float xmax = th1->GetXaxis()->GetXmax();
324  float xmin = me1_forEff->GetXaxis()->GetXmin();
325  float xmax = me1_forEff->GetXaxis()->GetXmax();
326  std::string xtit = me1->getAxisTitle(1);
327  std::string tit_new;
328  tit_new = ";"+xtit+";"+xtit+" efficiency";
329 
330  ibooker.setCurrentFolder(folder);
331  me_eff = ibooker.book1D("efficiency_"+name,tit_new, nbinx, xmin, xmax);
332 
333  me_eff->Reset(); me_eff->setEfficiencyFlag();
334  /*
335  double efficiency;
336  for (size_t ix = 1; ix < nbinx+1; ++ix) {
337  float val1 = me1->getBinContent(ix);
338  float val2 = me2->getBinContent(ix);
339  if (val2 > 0.0) efficiency = val1/val2;
340  else efficiency = 0;
341  me_eff->setBinContent(ix,efficiency);
342  }
343  */
344  // Binomial errors "B" asked by Florian
345  /*me1_forEff->Sumw2(); me2_forEff->Sumw2();*/ me_eff->getTH1F()->Sumw2();
346  me_eff->getTH1F()->Divide( me1_forEff, me2_forEff, 1, 1, "B");
347  }
348 }
349 
TProfile * getTProfile() const
T getParameter(std::string const &) const
void setBinContent(int binx, double content)
set content of bin (1-D)
const double xbins[]
void createResolutionPlots(DQMStore::IBooker &, DQMStore::IGetter &, std::string &folder, std::string &name)
Definition: PFClient.cc:113
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:160
TH1F * getTH1F() const
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:302
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::string getAxisTitle(int axis=1) const
get x-, y- or z-axis title (axis=1, 2, 3 respectively)
void doProjection(DQMStore::IBooker &, DQMStore::IGetter &)
Definition: PFClient.cc:60
const std::string & getName() const
get name of ME
std::vector< std::string > projectionHistogramNames_
Definition: PFClient.h:36
std::vector< std::string > histogramNames_
Definition: PFClient.h:34
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
Definition: PFClient.cc:32
double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
void doSummaries(DQMStore::IBooker &, DQMStore::IGetter &)
Definition: PFClient.cc:44
void setEfficiencyFlag()
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
void setEntries(double nentries)
set # of entries
void Reset()
reset ME (ie. contents, errors, etc)
TH2F * getTH2F() const
void createEfficiencyPlots(DQMStore::IBooker &, DQMStore::IGetter &, std::string &folder, std::string &name)
Definition: PFClient.cc:307
std::vector< std::string > profileHistogramNames_
Definition: PFClient.h:37
void createProfilePlots(DQMStore::IBooker &, DQMStore::IGetter &, std::string &folder, std::string &name)
Definition: PFClient.cc:225
double getEntries() const
get # of entries
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
PFClient(const edm::ParameterSet &parameterSet)
Definition: PFClient.cc:17
std::vector< std::string > folderNames_
Definition: PFClient.h:33
int getNbinsY() const
get # of bins in Y-axis
void doEfficiency(DQMStore::IBooker &, DQMStore::IGetter &)
Definition: PFClient.cc:96
bool profileFlag_
Definition: PFClient.h:39
double getRMS(int axis=1) const
get RMS of histogram along x, y or z axis (axis=1, 2, 3 respectively)
std::vector< std::string > effHistogramNames_
Definition: PFClient.h:35
void doProfiles(DQMStore::IBooker &, DQMStore::IGetter &)
Definition: PFClient.cc:78
void createProjectionPlots(DQMStore::IBooker &, DQMStore::IGetter &, std::string &folder, std::string &name)
Definition: PFClient.cc:178
int getNbinsX() const
get # of bins in X-axis
void removeElement(Args &&...args)
Definition: DQMStore.h:310
void setBinEntries(int bin, double nentries)
set # of bin entries (to be used for profiles)
Kind kind() const
Get the type of the monitor element.
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
bool efficiencyFlag_
Definition: PFClient.h:38
void getHistogramParameters(MonitorElement *me_slice, double &avarage, double &rms, double &mean, double &sigma)
Definition: PFClient.cc:281