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, const int binxmin, const int binxmax, const int rebin, const bool cst_binning=true)
 
 TH2Analyzer (const TH2 *h, int rebin=1)
 
 ~TH2Analyzer () override
 

Private Member Functions

 ClassDefOverride (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() [1/2]

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

Definition at line 22 of file TH2Analyzer.h.

23  : hist2D_(h),
24  rebinnedHist2D_(nullptr),
25  average_(nullptr),
26  RMS_(nullptr),
27  sigmaGauss_(nullptr),
28  meanXslice_(nullptr) {
29  Eval(rebin);
30  }

References Eval().

◆ TH2Analyzer() [2/2]

TH2Analyzer::TH2Analyzer ( const TH2 *  h,
const int  binxmin,
const int  binxmax,
const int  rebin,
const bool  cst_binning = true 
)
inline

Definition at line 32 of file TH2Analyzer.h.

33  : hist2D_(h),
34  rebinnedHist2D_(nullptr),
35  average_(nullptr),
36  RMS_(nullptr),
37  sigmaGauss_(nullptr),
38  meanXslice_(nullptr) {
39  Eval(rebin, binxmin, binxmax, cst_binning);
40  }

References Eval().

◆ ~TH2Analyzer()

TH2Analyzer::~TH2Analyzer ( )
inlineoverride

Definition at line 42 of file TH2Analyzer.h.

42 { Reset(); }

References Reset().

Member Function Documentation

◆ Average()

TH1D* TH2Analyzer::Average ( )
inline

Definition at line 51 of file TH2Analyzer.h.

51 { return average_; }

References average_.

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

◆ ClassDefOverride()

TH2Analyzer::ClassDefOverride ( TH2Analyzer  ,
 
)
private

◆ Eval() [1/2]

void TH2Analyzer::Eval ( const int  rebinFactor)

Definition at line 16 of file TH2Analyzer.cc.

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(),
28  "arithmetic average",
29  rebinnedHist2D_->GetNbinsX(),
30  rebinnedHist2D_->GetXaxis()->GetXmin(),
31  rebinnedHist2D_->GetXaxis()->GetXmax());
32 
33  const string rmsName = bname + "_RMS";
34  RMS_ = new TH1D(rmsName.c_str(),
35  "RMS",
36  rebinnedHist2D_->GetNbinsX(),
37  rebinnedHist2D_->GetXaxis()->GetXmin(),
38  rebinnedHist2D_->GetXaxis()->GetXmax());
39 
40  const string sigmaGaussName = bname + "_sigmaGauss";
41  sigmaGauss_ = new TH1D(sigmaGaussName.c_str(),
42  "sigmaGauss",
43  rebinnedHist2D_->GetNbinsX(),
44  rebinnedHist2D_->GetXaxis()->GetXmin(),
45  rebinnedHist2D_->GetXaxis()->GetXmax());
46 
47  const string meanXName = bname + "_meanX";
48  meanXslice_ = new TH1D(meanXName.c_str(),
49  "meanX",
50  rebinnedHist2D_->GetNbinsX(),
51  rebinnedHist2D_->GetXaxis()->GetXmin(),
52  rebinnedHist2D_->GetXaxis()->GetXmax());
53 
55 }

References HcalObjRepresent::Reset().

Referenced by TH2Analyzer().

◆ Eval() [2/2]

void TH2Analyzer::Eval ( const int  rebinFactor,
const int  binxmin,
const int  binxmax,
const bool  cst_binning 
)

Definition at line 76 of file TH2Analyzer.cc.

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

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

◆ MeanX()

TH1D* TH2Analyzer::MeanX ( )
inline

Definition at line 54 of file TH2Analyzer.h.

54 { return meanXslice_; }

References meanXslice_.

Referenced by Comparator::DrawGaussSigmaOverMeanXSlice().

◆ ProcessSlice()

void TH2Analyzer::ProcessSlice ( const int  i,
TH1D *  histo 
) const
private

Definition at line 261 of file TH2Analyzer.cc.

261  {
262  // const double mean = proj->GetMean();
263  const double rms = proj->GetRMS();
264  // std::cout << "FL: mean = " << mean << std::endl;
265  // std::cout << "FL: rms = " << rms << std::endl;
266 
267  if (rms != 0.0) {
268  const double fitmin = proj->GetMean() - proj->GetRMS();
269  const double fitmax = proj->GetMean() + proj->GetRMS();
270 
271  // std::cout << "i = " << i << std::endl;
272  // std::cout << "fitmin = " << fitmin << std::endl;
273  // std::cout << "fitmax = " << fitmax << std::endl;
274 
275  // proj->Draw();
276  TF1 *f1 = new TF1("f1", "gaus", fitmin, fitmax);
277  f1->SetParameters(proj->GetRMS(), proj->GetMean(), proj->GetBinContent(proj->GetMaximumBin()));
278  proj->Fit(f1, "R", "", proj->GetXaxis()->GetXmin(), proj->GetXaxis()->GetXmax());
279 
280  // std::ostringstream oss;
281  // oss << i;
282  // const std::string plotfitname="Plots/fitbin_"+oss.str()+".eps";
283  // gPad->SaveAs( plotfitname.c_str() );
284  // std::cout << "param1 = " << f1->GetParameter(1) << std::endl;
285  // std::cout << "param2 = " << f1->GetParameter(2) << std::endl;
286  // std::cout << "paramError2 = " << f1->GetParError(2) << std::endl;
287 
288  sigmaGauss_->SetBinContent(i, f1->GetParameter(2));
289  sigmaGauss_->SetBinError(i, f1->GetParError(2));
290  delete f1;
291  } else {
292  sigmaGauss_->SetBinContent(i, 0.0);
293  sigmaGauss_->SetBinError(i, 0.0);
294  }
295 }

References DeadROC_duringRun::f1, mps_fire::i, amptDefault_cfi::proj, and SiStripPI::rms.

◆ ProcessSlices()

void TH2Analyzer::ProcessSlices ( const TH2D *  histo)
private

Definition at line 230 of file TH2Analyzer.cc.

230  {
231  // std::cout << "ProcessSlices!" << std::endl;
232 
233  TH1::AddDirectory(false);
234 
235  for (int i = 1; i <= histo->GetNbinsX(); ++i) {
236  TH1D *proj = histo->ProjectionY("toto", i, i);
237  const double mean = proj->GetMean();
238  const double rms = proj->GetRMS();
239  // std::cout << "mean = " << mean << std::endl;
240  // std::cout << "rms = " << rms << std::endl;
241  average_->SetBinContent(i, mean);
242  average_->SetBinError(i, proj->GetMeanError());
243  RMS_->SetBinContent(i, rms);
244  RMS_->SetBinError(i, proj->GetRMSError());
245 
246  const double error = (histo->GetXaxis()->GetBinUpEdge(i) - histo->GetXaxis()->GetBinLowEdge(i)) / 2.0;
247  // std::cout << "error = " << error << std::endl;
248  meanXslice_->SetBinContent(i, histo->GetXaxis()->GetBinLowEdge(i) + error);
249  meanXslice_->SetBinError(i, error);
250  // std::cout << "histo->GetXaxis()->GetBinLowEdge(" << i << ") = "
251  // << histo->GetXaxis()->GetBinLowEdge(i) << std::endl;
252  // std::cout << "meanXslice_->GetBinError(" << i << ") = "
253  // << meanXslice_->GetBinError(i) << std::endl;
254  ProcessSlice(i, proj);
255  delete proj;
256  }
257 
258  TH1::AddDirectory(true);
259 }

References relativeConstraints::error, timingPdfMaker::histo, mps_fire::i, SiStripPI::mean, amptDefault_cfi::proj, and SiStripPI::rms.

◆ Reset()

void TH2Analyzer::Reset ( )

Definition at line 57 of file TH2Analyzer.cc.

57  {
58  if (rebinnedHist2D_)
59  delete rebinnedHist2D_;
60  if (average_)
61  delete average_;
62  if (RMS_)
63  delete RMS_;
64  if (sigmaGauss_)
65  delete sigmaGauss_;
66  if (meanXslice_)
67  delete meanXslice_;
68 
69  // for( unsigned i=0; i<parameters_.size(); ++i) {
70  // delete parameters_[i];
71  //}
72 
73  // parameters_.clear();
74 }

Referenced by ~TH2Analyzer().

◆ RMS()

TH1D* TH2Analyzer::RMS ( )
inline

Definition at line 52 of file TH2Analyzer.h.

52 { return RMS_; }

References RMS_.

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

◆ SetHisto()

void TH2Analyzer::SetHisto ( const TH2 *  h)
inline

Definition at line 46 of file TH2Analyzer.h.

46 { hist2D_ = h; }

References h, and hist2D_.

◆ SigmaGauss()

TH1D* TH2Analyzer::SigmaGauss ( )
inline

Member Data Documentation

◆ average_

TH1D* TH2Analyzer::average_
private

Definition at line 68 of file TH2Analyzer.h.

Referenced by Average().

◆ hist2D_

const TH2* TH2Analyzer::hist2D_
private

Definition at line 66 of file TH2Analyzer.h.

Referenced by SetHisto().

◆ meanXslice_

TH1D* TH2Analyzer::meanXslice_
private

Definition at line 71 of file TH2Analyzer.h.

Referenced by MeanX().

◆ rebinnedHist2D_

TH2D* TH2Analyzer::rebinnedHist2D_
private

Definition at line 67 of file TH2Analyzer.h.

◆ RMS_

TH1D* TH2Analyzer::RMS_
private

Definition at line 69 of file TH2Analyzer.h.

Referenced by RMS().

◆ sigmaGauss_

TH1D* TH2Analyzer::sigmaGauss_
private

Definition at line 70 of file TH2Analyzer.h.

Referenced by SigmaGauss().

TH2Analyzer::Eval
void Eval(const int rebinFactor)
Definition: TH2Analyzer.cc:16
mps_fire.i
i
Definition: mps_fire.py:428
SiStripPI::mean
Definition: SiStripPayloadInspectorHelper.h:169
TH2Analyzer::meanXslice_
TH1D * meanXslice_
Definition: TH2Analyzer.h:71
gather_cfg.cout
cout
Definition: gather_cfg.py:144
timingPdfMaker.histo
histo
Definition: timingPdfMaker.py:278
h
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
SiStripPI::rms
Definition: SiStripPayloadInspectorHelper.h:169
relativeConstraints.error
error
Definition: relativeConstraints.py:53
TH2Analyzer::Reset
void Reset()
Definition: TH2Analyzer.cc:57
TH2Analyzer::rebinnedHist2D_
TH2D * rebinnedHist2D_
Definition: TH2Analyzer.h:67
TH2Analyzer::average_
TH1D * average_
Definition: TH2Analyzer.h:68
h
TH2Analyzer::hist2D_
const TH2 * hist2D_
Definition: TH2Analyzer.h:66
TH2Analyzer::ProcessSlice
void ProcessSlice(const int i, TH1D *histo) const
Definition: TH2Analyzer.cc:261
TH2Analyzer::RMS_
TH1D * RMS_
Definition: TH2Analyzer.h:69
amptDefault_cfi.proj
proj
Definition: amptDefault_cfi.py:13
TH2Analyzer::ProcessSlices
void ProcessSlices(const TH2D *histo)
Definition: TH2Analyzer.cc:230
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DeadROC_duringRun.f1
f1
Definition: DeadROC_duringRun.py:219
TH2Analyzer::sigmaGauss_
TH1D * sigmaGauss_
Definition: TH2Analyzer.h:70