CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
TH2Analyzer Class Reference

#include <TH2Analyzer.h>

Inheritance diagram for TH2Analyzer:

Public Member Functions

TH1D * Average ()
 
void Eval (const int rebinFactor)
 
void Eval (const int rebinFactor, const int binxmin, const int binxmax, const bool cst_binning)
 
TH1D * MeanX ()
 
void Reset ()
 
TH1D * RMS ()
 
void SetHisto (const TH2 *h)
 
TH1D * SigmaGauss ()
 
 TH2Analyzer (const TH2 *h, int rebin=1)
 
 TH2Analyzer (const TH2 *h, const int binxmin, const int binxmax, const int rebin, const bool cst_binning=true)
 
 ~TH2Analyzer ()
 

Private Member Functions

 ClassDef (TH2Analyzer, 1)
 
void ProcessSlice (const int i, TH1D *histo) const
 
void ProcessSlices (const TH2D *histo)
 

Private Attributes

TH1D * average_
 
const TH2 * hist2D_
 
TH1D * meanXslice_
 
TH2D * rebinnedHist2D_
 
TH1D * RMS_
 
TH1D * sigmaGauss_
 

Detailed Description

Definition at line 20 of file TH2Analyzer.h.

Constructor & Destructor Documentation

TH2Analyzer::TH2Analyzer ( const TH2 *  h,
int  rebin = 1 
)
inline

Definition at line 23 of file TH2Analyzer.h.

References Eval().

23  :
24  hist2D_(h),
25  rebinnedHist2D_(0),
26  average_(0),
27  RMS_(0),
28  sigmaGauss_(0),
29  meanXslice_(0) {
30  Eval(rebin);
31  }
TH2D * rebinnedHist2D_
Definition: TH2Analyzer.h:71
TH1D * sigmaGauss_
Definition: TH2Analyzer.h:74
void Eval(const int rebinFactor)
Definition: TH2Analyzer.cc:16
TH1D * meanXslice_
Definition: TH2Analyzer.h:75
const TH2 * hist2D_
Definition: TH2Analyzer.h:70
TH1D * RMS_
Definition: TH2Analyzer.h:73
TH1D * average_
Definition: TH2Analyzer.h:72
TH2Analyzer::TH2Analyzer ( const TH2 *  h,
const int  binxmin,
const int  binxmax,
const int  rebin,
const bool  cst_binning = true 
)
inline

Definition at line 33 of file TH2Analyzer.h.

References Eval().

34  :
35  hist2D_(h),
36  rebinnedHist2D_(0),
37  average_(0),
38  RMS_(0),
39  sigmaGauss_(0),
40  meanXslice_(0) {
41  Eval(rebin, binxmin, binxmax, cst_binning);
42  }
TH2D * rebinnedHist2D_
Definition: TH2Analyzer.h:71
TH1D * sigmaGauss_
Definition: TH2Analyzer.h:74
void Eval(const int rebinFactor)
Definition: TH2Analyzer.cc:16
TH1D * meanXslice_
Definition: TH2Analyzer.h:75
const TH2 * hist2D_
Definition: TH2Analyzer.h:70
TH1D * RMS_
Definition: TH2Analyzer.h:73
TH1D * average_
Definition: TH2Analyzer.h:72
TH2Analyzer::~TH2Analyzer ( )
inline

Definition at line 44 of file TH2Analyzer.h.

References Reset().

44 {Reset(); }
void Reset()
Definition: TH2Analyzer.cc:53

Member Function Documentation

TH1D* TH2Analyzer::Average ( )
inline

Definition at line 54 of file TH2Analyzer.h.

References average_.

Referenced by Comparator::DrawGaussSigmaOverMeanSlice(), and Comparator::DrawMeanSlice().

54 { return average_; }
TH1D * average_
Definition: TH2Analyzer.h:72
TH2Analyzer::ClassDef ( TH2Analyzer  ,
 
)
private
void TH2Analyzer::Eval ( const int  rebinFactor)

Definition at line 16 of file TH2Analyzer.cc.

References HcalObjRepresent::Reset().

Referenced by SetHisto(), and TH2Analyzer().

16  {
17  //std::cout << "Eval!" << std::endl;
18 
19  Reset();
20 
21  const string bname = hist2D_->GetName();
22  const string rebinName = bname + "_rebin";
23  rebinnedHist2D_ = (TH2D*) hist2D_ -> Clone( rebinName.c_str() );
24  rebinnedHist2D_->RebinX( rebinFactor );
25 
26  const string averageName = bname + "_average";
27  average_ = new TH1D( averageName.c_str(),"arithmetic average",
28  rebinnedHist2D_->GetNbinsX(),
29  rebinnedHist2D_->GetXaxis()->GetXmin(),
30  rebinnedHist2D_->GetXaxis()->GetXmax() );
31 
32  const string rmsName = bname + "_RMS";
33  RMS_ = new TH1D( rmsName.c_str(), "RMS",
34  rebinnedHist2D_->GetNbinsX(),
35  rebinnedHist2D_->GetXaxis()->GetXmin(),
36  rebinnedHist2D_->GetXaxis()->GetXmax() );
37 
38  const string sigmaGaussName = bname + "_sigmaGauss";
39  sigmaGauss_ = new TH1D(sigmaGaussName.c_str(), "sigmaGauss",
40  rebinnedHist2D_->GetNbinsX(),
41  rebinnedHist2D_->GetXaxis()->GetXmin(),
42  rebinnedHist2D_->GetXaxis()->GetXmax() );
43 
44  const string meanXName = bname + "_meanX";
45  meanXslice_ = new TH1D(meanXName.c_str(), "meanX",
46  rebinnedHist2D_->GetNbinsX(),
47  rebinnedHist2D_->GetXaxis()->GetXmin(),
48  rebinnedHist2D_->GetXaxis()->GetXmax() );
49 
51 }
TH2D * rebinnedHist2D_
Definition: TH2Analyzer.h:71
TH1D * sigmaGauss_
Definition: TH2Analyzer.h:74
TH1D * meanXslice_
Definition: TH2Analyzer.h:75
void ProcessSlices(const TH2D *histo)
Definition: TH2Analyzer.cc:217
const TH2 * hist2D_
Definition: TH2Analyzer.h:70
TH1D * RMS_
Definition: TH2Analyzer.h:73
void Reset()
Definition: TH2Analyzer.cc:53
TH1D * average_
Definition: TH2Analyzer.h:72
void TH2Analyzer::Eval ( const int  rebinFactor,
const int  binxmin,
const int  binxmax,
const bool  cst_binning 
)

Definition at line 67 of file TH2Analyzer.cc.

References funct::abs(), gather_cfg::cout, and HcalObjRepresent::Reset().

69 {
70  Reset();
71  const string bname = hist2D_->GetName();
72  const string rebinName = bname + "_rebin";
73 
74  if (binxmax>hist2D_->GetNbinsX())
75  {
76  std::cout << "Error: TH2Analyzer.cc: binxmax>hist2D_->GetNbinsX()" << std::endl;
77  return;
78  }
79 
80  if (cst_binning)
81  {
82  //std::cout << "hist2D_->GetXaxis()->GetBinLowEdge(" << binxmin << ") = " << hist2D_->GetXaxis()->GetBinLowEdge(binxmin) << std::endl;
83  //std::cout << "hist2D_->GetXaxis()->GetBinUpEdge(" << binxmax << ") = " << hist2D_->GetXaxis()->GetBinUpEdge(binxmax) << std::endl;
84  //std::cout << "hist2D_->GetNbinsY() = " << hist2D_->GetNbinsY() << std::endl;
85  //std::cout << "hist2D_->GetYaxis()->GetXmin() = " << hist2D_->GetYaxis()->GetXmin() << std::endl;
86  //std::cout << "hist2D_->GetYaxis()->GetXmax() = " << hist2D_->GetYaxis()->GetXmax() << std::endl;
87  rebinnedHist2D_ = new TH2D(rebinName.c_str(),"rebinned histo",
88  binxmax-binxmin+1,
89  hist2D_->GetXaxis()->GetBinLowEdge(binxmin),
90  hist2D_->GetXaxis()->GetBinUpEdge(binxmax),
91  hist2D_->GetNbinsY(),
92  hist2D_->GetYaxis()->GetXmin(),
93  hist2D_->GetYaxis()->GetXmax() );
94  for (int binyc=1;binyc<hist2D_->GetNbinsY()+1;++binyc)
95  {
96  for (int binxc=binxmin;binxc<binxmax+1;++binxc)
97  {
98  //std::cout << "hist2D_->GetBinContent(" << binxc << "," << binyc << ") = " << hist2D_->GetBinContent(binxc,binyc) << std::endl;
99  //std::cout << "hist2D_->GetBinError(" << binxc << "," << binyc << ") = " << hist2D_->GetBinError(binxc,binyc) << std::endl;
100  //std::cout << "binxc-binxmin+1 = " << binxc-binxmin+1 << std::endl;
101  rebinnedHist2D_->SetBinContent(binxc-binxmin+1,binyc,hist2D_->GetBinContent(binxc,binyc));
102  rebinnedHist2D_->SetBinError(binxc-binxmin+1,binyc,hist2D_->GetBinError(binxc,binyc));
103  }
104  }
105  rebinnedHist2D_->RebinX( rebinFactor );
106 
107  const string averageName = bname + "_average";
108  average_ = new TH1D( averageName.c_str(),"arithmetic average",
109  rebinnedHist2D_->GetNbinsX(),
110  rebinnedHist2D_->GetXaxis()->GetXmin(),
111  rebinnedHist2D_->GetXaxis()->GetXmax() );
112 
113  const string rmsName = bname + "_RMS";
114  RMS_ = new TH1D( rmsName.c_str(), "RMS",
115  rebinnedHist2D_->GetNbinsX(),
116  rebinnedHist2D_->GetXaxis()->GetXmin(),
117  rebinnedHist2D_->GetXaxis()->GetXmax() );
118 
119  const string sigmaGaussName = bname + "_sigmaGauss";
120  sigmaGauss_ = new TH1D(sigmaGaussName.c_str(), "sigmaGauss",
121  rebinnedHist2D_->GetNbinsX(),
122  rebinnedHist2D_->GetXaxis()->GetXmin(),
123  rebinnedHist2D_->GetXaxis()->GetXmax() );
124 
125  const string meanXName = bname + "_meanX";
126  meanXslice_ = new TH1D(meanXName.c_str(), "meanX",
127  rebinnedHist2D_->GetNbinsX(),
128  rebinnedHist2D_->GetXaxis()->GetXmin(),
129  rebinnedHist2D_->GetXaxis()->GetXmax() );
130  }
131  else
132  {
133  // binning is not constant, but made to obtain almost the same number of events in each bin
134 
135  //std::cout << "binxmax-binxmin+1 = " << binxmax-binxmin+1 << std::endl;
136  //std::cout << "rebinFactor = " << rebinFactor << std::endl;
137  //std::cout << "(binxmax-binxmin+1)/rebinFactor = " << (binxmax-binxmin+1)/rebinFactor << std::endl;
138  //std::cout << "((binxmax-binxmin+1)%rebinFactor) = " << ((binxmax-binxmin+1)%rebinFactor) << std::endl;
139  //std::cout << "abs((binxmax-binxmin+1)/rebinFactor) = " << std::abs((binxmax-binxmin+1)/rebinFactor) << std::endl;
140 
141  unsigned int nbin=0;
142  if (((binxmax-binxmin+1)%rebinFactor)!=0.0)
143  {
144  nbin=std::abs((binxmax-binxmin+1)/rebinFactor)+1;
145  }
146  else nbin=(binxmax-binxmin+1)/rebinFactor;
147 
148  double *xlow = new double[nbin+1];
149  int *binlow = new int[nbin+1];
150 
151  TH1D* h0_slice1 = hist2D_->ProjectionY("h0_slice1", binxmin, binxmax, "");
152  const unsigned int totalNumberOfEvents=static_cast<unsigned int>(h0_slice1->GetEntries());
153  //std::cout << "totalNumberOfEvents = " << totalNumberOfEvents << std::endl;
154  delete h0_slice1;
155 
156  unsigned int neventsc=0;
157  unsigned int binXmaxc=binxmin+1;
158  xlow[0]=hist2D_->GetXaxis()->GetBinLowEdge(binxmin);
159  binlow[0]=binxmin;
160  for (unsigned int binc=1;binc<nbin;++binc)
161  {
162  while (neventsc<binc*totalNumberOfEvents/nbin)
163  {
164  TH1D* h0_slice1c = hist2D_->ProjectionY("h0_slice1",binxmin, binXmaxc, "");
165  neventsc=static_cast<unsigned int>(h0_slice1c->GetEntries());
166  // //std::cout << "FL : neventsc = " << neventsc << std::endl;
167  // //std::cout << "FL : binXmaxc = " << binXmaxc << std::endl;
168  ++binXmaxc;
169  delete h0_slice1c;
170  }
171  //std::cout << "binXmaxc-1 = " << binXmaxc-1 << std::endl;
172  binlow[binc]=binXmaxc-1;
173  xlow[binc]=hist2D_->GetXaxis()->GetBinLowEdge(binXmaxc-1);
174  }
175  xlow[nbin]=hist2D_->GetXaxis()->GetBinUpEdge(binxmax);
176  binlow[nbin]=binxmax;
177 
178  //for (unsigned int binc=0;binc<nbin+1;++binc)
179  //{
180  // std::cout << "xlow[" << binc << "] = " << xlow[binc] << std::endl;
181  //}
182 
183  rebinnedHist2D_ = new TH2D(rebinName.c_str(),"rebinned histo",
184  nbin, xlow, hist2D_->GetNbinsY(),
185  hist2D_->GetYaxis()->GetXmin(),
186  hist2D_->GetYaxis()->GetXmax() );
187  for (int binyc=1;binyc<hist2D_->GetNbinsY()+1;++binyc)
188  {
189  for (unsigned int binxc=1;binxc<nbin+1;++binxc)
190  {
191  double sum=0.0;
192  for (int binxh2c=binlow[binxc-1];binxh2c<binlow[binxc];++binxh2c)
193  {
194  sum+=hist2D_->GetBinContent(binxh2c,binyc);
195  }
196  rebinnedHist2D_->SetBinContent(binxc,binyc,sum);
197  }
198  }
199 
200  const string averageName = bname + "_average";
201  average_ = new TH1D( averageName.c_str(),"arithmetic average", nbin, xlow);
202 
203  const string rmsName = bname + "_RMS";
204  RMS_ = new TH1D( rmsName.c_str(), "RMS", nbin, xlow);
205 
206  const string sigmaGaussName = bname + "_sigmaGauss";
207  sigmaGauss_ = new TH1D(sigmaGaussName.c_str(), "sigmaGauss", nbin, xlow);
208 
209  const string meanXName = bname + "_meanX";
210  meanXslice_ = new TH1D(meanXName.c_str(), "meanX", nbin, xlow);
211  delete [] xlow;
212  delete [] binlow;
213  }
215 }
TH2D * rebinnedHist2D_
Definition: TH2Analyzer.h:71
TH1D * sigmaGauss_
Definition: TH2Analyzer.h:74
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TH1D * meanXslice_
Definition: TH2Analyzer.h:75
void ProcessSlices(const TH2D *histo)
Definition: TH2Analyzer.cc:217
const TH2 * hist2D_
Definition: TH2Analyzer.h:70
TH1D * RMS_
Definition: TH2Analyzer.h:73
void Reset()
Definition: TH2Analyzer.cc:53
TH1D * average_
Definition: TH2Analyzer.h:72
TH1D* TH2Analyzer::MeanX ( )
inline

Definition at line 57 of file TH2Analyzer.h.

References trackerHits::histo, mps_fire::i, meanXslice_, ProcessSlice(), and ProcessSlices().

Referenced by Comparator::DrawGaussSigmaOverMeanXSlice().

57 { return meanXslice_; }
TH1D * meanXslice_
Definition: TH2Analyzer.h:75
void TH2Analyzer::ProcessSlice ( const int  i,
TH1D *  histo 
) const
private

Definition at line 250 of file TH2Analyzer.cc.

References connectstrParser::f1, and SiStripPI::rms.

Referenced by MeanX().

250  {
251 
252  //const double mean = proj->GetMean();
253  const double rms = proj->GetRMS();
254  //std::cout << "FL: mean = " << mean << std::endl;
255  //std::cout << "FL: rms = " << rms << std::endl;
256 
257  if (rms!=0.0)
258  {
259  const double fitmin=proj->GetMean()-proj->GetRMS();
260  const double fitmax=proj->GetMean()+proj->GetRMS();
261 
262  //std::cout << "i = " << i << std::endl;
263  //std::cout << "fitmin = " << fitmin << std::endl;
264  //std::cout << "fitmax = " << fitmax << std::endl;
265 
266  //proj->Draw();
267  TF1* f1= new TF1("f1", "gaus", fitmin, fitmax);
268  f1->SetParameters(proj->GetRMS(),proj->GetMean(),proj->GetBinContent(proj->GetMaximumBin()));
269  proj->Fit(f1,"R", "", proj->GetXaxis()->GetXmin(), proj->GetXaxis()->GetXmax());
270 
271  //std::ostringstream oss;
272  //oss << i;
273  //const std::string plotfitname="Plots/fitbin_"+oss.str()+".eps";
274  //gPad->SaveAs( plotfitname.c_str() );
275  //std::cout << "param1 = " << f1->GetParameter(1) << std::endl;
276  //std::cout << "param2 = " << f1->GetParameter(2) << std::endl;
277  //std::cout << "paramError2 = " << f1->GetParError(2) << std::endl;
278 
279  sigmaGauss_->SetBinContent(i, f1->GetParameter(2));
280  sigmaGauss_->SetBinError(i, f1->GetParError(2));
281  delete f1;
282  }
283  else
284  {
285  sigmaGauss_->SetBinContent(i, 0.0);
286  sigmaGauss_->SetBinError(i, 0.0);
287  }
288 }
TH1D * sigmaGauss_
Definition: TH2Analyzer.h:74
void TH2Analyzer::ProcessSlices ( const TH2D *  histo)
private

Definition at line 217 of file TH2Analyzer.cc.

References relativeConstraints::error, mps_fire::i, SiStripPI::mean, and SiStripPI::rms.

Referenced by MeanX().

217  {
218 
219  //std::cout << "ProcessSlices!" << std::endl;
220 
221  TH1::AddDirectory(0);
222 
223  for( int i=1; i<=histo->GetNbinsX(); ++i) {
224  TH1D* proj = histo->ProjectionY("toto", i, i);
225  const double mean = proj->GetMean();
226  const double rms = proj->GetRMS();
227  //std::cout << "mean = " << mean << std::endl;
228  //std::cout << "rms = " << rms << std::endl;
229  average_->SetBinContent( i, mean);
230  average_->SetBinError( i, proj->GetMeanError());
231  RMS_->SetBinContent(i, rms);
232  RMS_->SetBinError(i, proj->GetRMSError());
233 
234  const double error=(histo->GetXaxis()->GetBinUpEdge(i)-histo->GetXaxis()->GetBinLowEdge(i))/2.0;
235  //std::cout << "error = " << error << std::endl;
236  meanXslice_->SetBinContent(i, histo->GetXaxis()->GetBinLowEdge(i)+error);
237  meanXslice_->SetBinError(i, error);
238  //std::cout << "histo->GetXaxis()->GetBinLowEdge(" << i << ") = "
239  // << histo->GetXaxis()->GetBinLowEdge(i) << std::endl;
240  //std::cout << "meanXslice_->GetBinError(" << i << ") = "
241  // << meanXslice_->GetBinError(i) << std::endl;
242  ProcessSlice(i, proj );
243  delete proj;
244  }
245 
246  TH1::AddDirectory(1);
247 }
void ProcessSlice(const int i, TH1D *histo) const
Definition: TH2Analyzer.cc:250
TH1D * meanXslice_
Definition: TH2Analyzer.h:75
TH1D * RMS_
Definition: TH2Analyzer.h:73
TH1D * average_
Definition: TH2Analyzer.h:72
void TH2Analyzer::Reset ( void  )

Definition at line 53 of file TH2Analyzer.cc.

Referenced by ~TH2Analyzer().

53  {
54  if ( rebinnedHist2D_ ) delete rebinnedHist2D_;
55  if ( average_ ) delete average_;
56  if ( RMS_ ) delete RMS_;
57  if ( sigmaGauss_ ) delete sigmaGauss_;
58  if ( meanXslice_ ) delete meanXslice_;
59 
60  //for( unsigned i=0; i<parameters_.size(); ++i) {
61  // delete parameters_[i];
62  //}
63 
64  //parameters_.clear();
65 }
TH2D * rebinnedHist2D_
Definition: TH2Analyzer.h:71
TH1D * sigmaGauss_
Definition: TH2Analyzer.h:74
TH1D * meanXslice_
Definition: TH2Analyzer.h:75
TH1D * RMS_
Definition: TH2Analyzer.h:73
TH1D * average_
Definition: TH2Analyzer.h:72
TH1D* TH2Analyzer::RMS ( )
inline

Definition at line 55 of file TH2Analyzer.h.

References RMS_.

Referenced by Comparator::DrawGaussSigmaOverMeanXSlice(), Comparator::DrawGaussSigmaSlice(), and Comparator::DrawSigmaSlice().

55 { return RMS_; }
TH1D * RMS_
Definition: TH2Analyzer.h:73
void TH2Analyzer::SetHisto ( const TH2 *  h)
inline

Definition at line 48 of file TH2Analyzer.h.

References Eval(), h, and hist2D_.

48 {hist2D_ = h;}
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
const TH2 * hist2D_
Definition: TH2Analyzer.h:70
TH1D* TH2Analyzer::SigmaGauss ( )
inline

Member Data Documentation

TH1D* TH2Analyzer::average_
private

Definition at line 72 of file TH2Analyzer.h.

Referenced by Average().

const TH2* TH2Analyzer::hist2D_
private

Definition at line 70 of file TH2Analyzer.h.

Referenced by SetHisto().

TH1D* TH2Analyzer::meanXslice_
private

Definition at line 75 of file TH2Analyzer.h.

Referenced by MeanX().

TH2D* TH2Analyzer::rebinnedHist2D_
private

Definition at line 71 of file TH2Analyzer.h.

TH1D* TH2Analyzer::RMS_
private

Definition at line 73 of file TH2Analyzer.h.

Referenced by RMS().

TH1D* TH2Analyzer::sigmaGauss_
private

Definition at line 74 of file TH2Analyzer.h.

Referenced by SigmaGauss().