CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFClient_JetRes.cc
Go to the documentation of this file.
2 
7 
8 
12 
13 #include "TGraph.h"
14 #include "TCanvas.h"
15 //
16 // -- Constructor
17 //
19 {
20  folderNames_ = parameterSet.getParameter< std::vector<std::string> >( "FolderNames" );
21  histogramNames_ = parameterSet.getParameter< std::vector<std::string> >( "HistogramNames" );
22  efficiencyFlag_ = parameterSet.getParameter< bool> ("CreateEfficiencyPlots" );
23  effHistogramNames_ = parameterSet.getParameter< std::vector<std::string> >( "HistogramNamesForEfficiencyPlots" );
24  PtBins_ = parameterSet.getParameter< std::vector<int> >( "VariablePtBins" ) ;
25 
26 }
27 //
28 // -- BeginJob
29 //
31 
33 }
34 //
35 // -- EndJobBegin Run
36 //
37 void PFClient_JetRes::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
38  doSummaries();
40 }
41 //
42 // -- EndJob
43 //
45 
46 }
47 //
48 // -- Create Summaries
49 //
51 
52  for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin();
53  ifolder != folderNames_.end(); ifolder++) {
54  std::string path = "ParticleFlow/"+(*ifolder);
55 
56  for (std::vector<std::string>::const_iterator ihist = histogramNames_.begin();
57  ihist != histogramNames_.end(); ihist++) {
58  std::string hname = (*ihist);
59  createResolutionPlots(path, hname);
60  }
61  }
62 }
63 //
64 // -- Create Summaries
65 //
67  for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin();
68  ifolder != folderNames_.end(); ifolder++) {
69  std::string path = "ParticleFlow/"+(*ifolder);
70 
71  for (std::vector<std::string>::const_iterator ihist = effHistogramNames_.begin();
72  ihist != effHistogramNames_.end(); ihist++) {
73  std::string hname = (*ihist);
74  createEfficiencyPlots(path, hname);
75  }
76  }
77 }
78 //
79 // -- Create Resolution Plots
80 //
82  MonitorElement* me = dqmStore_->get(folder+"/"+name);
83  if (!me) return;
84 
85  MonitorElement* pT[PtBins_.size() -1];
86  std::vector<double> pTEntries(PtBins_.size()-1, 0) ;
87 
88  //std::vector<std::string> pTRange (PtBins_.size() -1) ;
89  //char* pTRange[PtBins_.size() -1] ;
90  TString pTRange[PtBins_.size() -1] ;
91  //float pTCenter[PtBins_.size() -1] ;
92 
93  MonitorElement* me_average;
94  MonitorElement* me_rms;
95  MonitorElement* me_mean;
96  MonitorElement* me_sigma;
97 
98  if ( (me->kind() == MonitorElement::DQM_KIND_TH2F) ||
100  (me->kind() == MonitorElement::DQM_KIND_TH2D) ) {
101  TH2* th = me->getTH2F();
102  //size_t nbinx = me->getNbinsX();
103  size_t nbinx = PtBins_.size() -1;
104  size_t nbiny = me->getNbinsY();
105 
106  float ymin = th->GetYaxis()->GetXmin();
107  float ymax = th->GetYaxis()->GetXmax();
108  std::string xtit = th->GetXaxis()->GetTitle();
109  //std::string ytit = th->GetYaxis()->GetTitle();
110  std::string ytit = "#Deltap_{T}/p_{T}";
111 
112  float* xbins = new float[nbinx+1];
113  for (size_t ix = 1; ix < nbinx+1; ++ix) {
114  //xbins[ix-1] = th->GetBinLowEdge(ix);
115  xbins[ix-1] = PtBins_[ix-1];
116  //snprintf(pTRange[ix-1].data(), 15, "Pt%d_%d", PtBins_[ix-1], PtBins_[ix]);
117  pTRange[ix-1] = TString::Format("Pt%d_%d", PtBins_[ix-1], PtBins_[ix]) ;
118  if (name == "BRdelta_et_Over_et_VS_et_") pTRange[ix-1] = TString::Format("BRPt%d_%d", PtBins_[ix-1], PtBins_[ix]) ;
119  else if (name == "ERdelta_et_Over_et_VS_et_") pTRange[ix-1] = TString::Format("ERPt%d_%d", PtBins_[ix-1], PtBins_[ix]) ;
120 
121  //pTCenter[ix-1] = (PtBins_[ix] - PtBins_[ix-1]) / 2. ;
122  if (ix == nbinx) {
123  //xbins[ix] = th->GetXaxis()->GetBinUpEdge(ix);
124  xbins[ix] = PtBins_[ix];
125  }
126  }
127 
128  std::string tit_new;
129  dqmStore_->setCurrentFolder(folder);
130  //MonitorElement* me_slice = dqmStore_->book1D("PFlowSlice", "PFlowSlice", nbiny, ymin, ymax);
131 
132  tit_new = "Average "+ytit+";"+xtit+";Average_"+ytit ;
133  me_average = dqmStore_->book1D("average_"+name,tit_new, nbinx, xbins);
134  me_average->setEfficiencyFlag();
135  tit_new = "RMS "+ytit+";"+xtit+";RMS_"+ytit ;
136  me_rms = dqmStore_->book1D("rms_"+name,tit_new, nbinx, xbins);
137  me_rms->setEfficiencyFlag();
138  tit_new = ";"+xtit+";Mean_"+ytit;
139  me_mean = dqmStore_->book1D("mean_"+name,tit_new, nbinx, xbins);
140  me_mean->setEfficiencyFlag();
141  tit_new = ";"+xtit+";Sigma_"+ytit;
142  me_sigma = dqmStore_->book1D("sigma_"+name,tit_new, nbinx, xbins);
143  me_sigma->setEfficiencyFlag();
144 
145  double average, rms, mean, sigma;
146  for (size_t ix = 1; ix < nbinx+1; ++ix) {
147  //me_slice->Reset();
148  if (name == "delta_et_Over_et_VS_et_") pT[ix-1] = dqmStore_->book1D(pTRange[ix-1], TString::Format("Total %s;%s;Events", ytit.data(), ytit.data() ), nbiny, ymin, ymax) ;
149  if (name == "BRdelta_et_Over_et_VS_et_") pT[ix-1] = dqmStore_->book1D(pTRange[ix-1], TString::Format("Barrel %s;%s;Events", ytit.data(), ytit.data()), nbiny, ymin, ymax) ;
150  else if (name == "ERdelta_et_Over_et_VS_et_") pT[ix-1] = dqmStore_->book1D(pTRange[ix-1], TString::Format("Endcap %s;%s;Events", ytit.data(), ytit.data() ), nbiny, ymin, ymax) ;
151 
152  for (size_t iy = 0; iy <= nbiny+1; ++iy) // add under and overflow
153  if (th->GetBinContent(ix,iy)) {
154  //me_slice->setBinContent(iy,th->GetBinContent(ix,iy));
155  pT[ix-1]->setBinContent(iy, th->GetBinContent(ix,iy));
156  pT[ix-1]->setBinError(iy, th->GetBinError(ix,iy));
157  pTEntries[ix-1] += th->GetBinContent(ix,iy); }
158 
159  pT[ix-1]->setEntries( pTEntries[ix-1] ) ;
160 
161  //getHistogramParameters(me_slice, average, rms, mean, sigma);
162  getHistogramParameters(pT[ix-1], average, rms, mean, sigma);
163  me_average->setBinContent(ix,average);
164  me_rms->setBinContent(ix,rms);
165  me_mean->setBinContent(ix,mean);
166  me_sigma->setBinContent(ix,sigma);
167  }
168  //if (me_slice) dqmStore_->removeElement(me_slice->getName());
169  delete [] xbins;
170  }
171 }
172 //
173 // -- Get Histogram Parameters
174 //
176  double& rms,double& mean, double& sigma) {
177  average = 0.0;
178  rms = 0.0;
179  mean = 0.0;
180  sigma = 0.0;
181 
182  if (!me_slice) return;
183  if (me_slice->kind() == MonitorElement::DQM_KIND_TH1F) {
184  average = me_slice->getMean();
185  rms = me_slice->getRMS();
186  TH1F* th_slice = me_slice->getTH1F();
187  if (th_slice && th_slice->GetEntries() > 0) {
188  th_slice->Fit( "gaus","Q0");
189  TF1* gaus = th_slice->GetFunction( "gaus" );
190  if (gaus) {
191  sigma = gaus->GetParameter(2);
192  mean = gaus->GetParameter(1);
193  }
194  }
195  }
196 }
197 //
198 // -- Create Resolution Plots
199 //
201  MonitorElement* me1 = dqmStore_->get(folder+"/"+name);
202  MonitorElement* me2 = dqmStore_->get(folder+"/"+name+"ref_");
203  if (!me1 || !me2) return;
204  MonitorElement* me_eff;
205  if ( (me1->kind() == MonitorElement::DQM_KIND_TH1F) &&
206  (me1->kind() == MonitorElement::DQM_KIND_TH1F) ) {
207  TH1* th1 = me1->getTH1F();
208  size_t nbinx = me1->getNbinsX();
209 
210  float xmin = th1->GetXaxis()->GetXmin();
211  float xmax = th1->GetXaxis()->GetXmax();
212  std::string xtit = me1->getAxisTitle(1);
213  std::string tit_new;
214  tit_new = ";"+xtit+";Efficiency";
215 
216  dqmStore_->setCurrentFolder(folder);
217  me_eff = dqmStore_->book1D("efficiency_"+name,tit_new, nbinx, xmin, xmax);
218 
219  double efficiency;
220  me_eff->Reset(); me_eff->setEfficiencyFlag();
221  for (size_t ix = 1; ix < nbinx+1; ++ix) {
222  float val1 = me1->getBinContent(ix);
223  float val2 = me2->getBinContent(ix);
224  if (val2 > 0.0) efficiency = val1/val2;
225  else efficiency = 0;
226  me_eff->setBinContent(ix,efficiency);
227  }
228  }
229 }
T getParameter(std::string const &) const
void setBinContent(int binx, double content)
set content of bin (1-D)
const double xbins[]
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:942
#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)
double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
PFClient_JetRes(const edm::ParameterSet &parameterSet)
int getNbinsY(void) const
get # of bins in Y-axis
DQMStore * dqmStore_
tuple path
else: Piece not in the list, fine.
void createEfficiencyPlots(std::string &folder, std::string &name)
void getHistogramParameters(MonitorElement *me_slice, double &avarage, double &rms, double &mean, double &sigma)
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
Kind kind(void) const
Get the type of the monitor element.
void setEntries(double nentries)
set # of entries
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1696
std::vector< std::string > effHistogramNames_
TH1F * getTH1F(void) const
void createResolutionPlots(std::string &folder, std::string &name)
std::vector< int > PtBins_
int average
Definition: PDRates.py:137
double getBinContent(int binx) const
get content of bin (1-D)
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 > folderNames_
int getNbinsX(void) const
get # of bins in X-axis
void endRun(edm::Run const &run, edm::EventSetup const &eSetup)
void setEfficiencyFlag(void)
TH2F * getTH2F(void) const
void Reset(void)
reset ME (ie. contents, errors, etc)
std::vector< std::string > histogramNames_
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:655
Definition: Run.h:41