Belle II Software  release-05-02-19
SliceFit.h
1 #include "TH2D.h"
2 #include "TH2.h"
3 #include "TH1D.h"
4 #include "TF1.h"
5 #include "TDirectory.h"
6 #include "TError.h"
7 #include "TROOT.h"
8 #include "TString.h"
9 namespace Belle2 {
18  class SliceFit {
19  public:
23  static TH1D* doSliceFitY(TH2D* h2, int minHitCut = 0)
24  {
25  gPrintViaErrorHandler = kTRUE;
26  gErrorIgnoreLevel = 3001;
27  TString hist_name = h2->GetName();
28  double ub = h2->GetYaxis()->GetXmax();
29  double lb = h2->GetYaxis()->GetXmin();
30  B2DEBUG(199, "Axis: " << lb << " " << ub);
31  if ((h2->GetEntries() / h2->GetNbinsX()) < 30) {
32  B2WARNING("Low statictic: " << h2->GetEntries() << " Hits");
33  h2->Rebin2D(2, 2, hist_name);
34  }
35 
36  B2DEBUG(199, "Slice fit for histo " << hist_name);
37  B2DEBUG(199, "Number of entries: " << h2->GetEntries());
38  TF1* g1 = new TF1("g1", "gaus", lb, ub);
39  h2->FitSlicesY(0, 0, -1, minHitCut);
40 
41 
42  TString m_name = hist_name + "_1";
43  TH1D* hm = (TH1D*)gDirectory->Get(m_name)->Clone("hm");
44  if (!hm) return 0;
45 
46  B2DEBUG(199, "Number of entries: " << hm->GetEntries());
47  TH1D* hlast = (TH1D*)hm->Clone("hlast");
48  hlast->Reset();
49  hlast->SetName(m_name);
50  for (int i = 1; i < h2->GetNbinsX(); ++i) {
51  double sum = 0;
52  double err = 0;
53  double mean = -99;
54  TH1D* h1d = h2->ProjectionY("h1d", i, i);
55  if (!h1d) continue;
56  sum = h1d->GetEntries();
57  if (sum < minHitCut) continue; //skip low data slice
58  mean = h1d->GetMean();
59  double sg = h1d->GetRMS();
60  double max = h1d->GetMaximum();
61  g1->SetParameters(max, mean, sg);
62  h1d->Fit("g1", "QNR", "");
63  // TF1 *f1=h1d->GetFunction("gaus");
64  mean = g1->GetParameter(1);
65  err = g1->GetParError(1);
66  if (sum > 50) {
67  double sg2 = g1->GetParameter(2);
68  h1d->Fit("g1", "Q0", "", mean - 1.1 * sg2, mean + 1.1 * sg2);
69  mean = g1->GetParameter(1);
70  // err=g1->GetParError(1);
71  }
72  hlast->SetBinContent(i, mean);
73  hlast->SetBinError(i, err);
74  h1d->Delete();
75  }
76  return hlast;
77  }
78  };
80 }
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SliceFit
Class to do the slice fit.
Definition: SliceFit.h:18
Belle2::SliceFit::doSliceFitY
static TH1D * doSliceFitY(TH2D *h2, int minHitCut=0)
Do the slice fit for the 2d histogram.
Definition: SliceFit.h:23