AliPhysics  vAN-20150827 (3e81cbb)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliHFMassFitter.h
Go to the documentation of this file.
1 #ifndef ALIHFMASSFITTER_H
2 #define ALIHFMASSFITTER_H
3 /* Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice */
5 
6 /* $Id$ */
7 
16 
17 #include <TNamed.h>
18 #include <TString.h>
19 
20 class TF1;
21 class TNtuple;
22 class TFile;
23 class TList;
24 class TH1F;
25 class TVirtualPad;
26 class TPaveText;
27 
28 class AliHFMassFitter : public TNamed {
29 
30  public:
31 
32  enum ETypeOfBkg{ kExpo=0, kLin=1, kPol2=2, kNoBk=3, kPow=4, kPowEx=5 };
33  enum ETypeOfSgn{ kGaus=0, k2Gaus=1 };
34 
36  AliHFMassFitter(const TH1F* histoToFit, Double_t minvalue, Double_t maxvalue, Int_t rebin=1, Int_t fittypeb=kExpo, Int_t fittypes=kGaus);
37  virtual ~AliHFMassFitter();
38 
39  AliHFMassFitter(const AliHFMassFitter &mfit);
41 
43  void SetHisto(const TH1F *histoToFit);
44  void SetRangeFit(Double_t minvalue, Double_t maxvalue){fminMass=minvalue; fmaxMass=maxvalue; CheckRangeFit();}
45  void SetMinRangeFit(Double_t minvalue){fminMass=minvalue;printf("CheckRangeFit after SetMaxRangeFit is also set\n");}
46  void SetMaxRangeFit(Double_t maxvalue){fmaxMass=maxvalue;printf("CheckRangeFit after SetMinRangeFit is also set\n");}
47  void SetBinN(Int_t newbinN){fNbin=newbinN;}
48  void SetType(Int_t fittypeb, Int_t fittypes);
49  void SetReflectionSigmaFactor(Int_t constant) {ffactor=constant;}
50  void SetInitialGaussianMean(Double_t mean) {fMass=mean;}
52  void SetSideBands(Bool_t onlysidebands=kTRUE) {fSideBands=onlysidebands;}
53  void SetFixParam(Bool_t *fixpar){fFixPar=fixpar;}
54  virtual void SetDefaultFixParam();
55  virtual Bool_t SetFixThisParam(Int_t thispar,Bool_t fixpar);
56  virtual void SetFixGaussianMean(Double_t mean=1.865,Bool_t fixpar=kTRUE){SetInitialGaussianMean(mean); SetFixThisParam(fNFinalPars-2,fixpar);}
57  virtual void SetFixGaussianSigma(Double_t sigma=0.012, Bool_t fixpar=kTRUE){SetInitialGaussianSigma(sigma); SetFixThisParam(fNFinalPars-1,fixpar);}
58 
59  //getters
60  TH1F* GetHistoClone() const;
61  void GetRangeFit(Double_t &minvalue, Double_t &maxvalue) const {minvalue=fminMass; maxvalue=fmaxMass;}
62  Double_t GetMinRangeFit()const {return fminMass;}
63  Double_t GetMaxRangeFit()const {return fmaxMass;}
64  Int_t GetBinN() const {return fNbin;}
65  void GetFitPars(Float_t* pars) const;
66  Int_t GetNFinalPars() const {return fNFinalPars;}
67  void GetTypeOfFit(Bool_t &background, Int_t &typeb) const {background = fWithBkg; typeb = ftypeOfFit4Bkg;}
68  Int_t GetReflectionSigmaFactor() const {return ffactor;}
69  Double_t GetMean() const {return fMass;}
70  Double_t GetMeanUncertainty() const {return fMassErr;}
71  Double_t GetSigma()const {return fSigmaSgn;}
72  Double_t GetSigmaUncertainty()const { return fSigmaSgnErr;}
73  Double_t GetRawYield()const {return fRawYield;}
74  Double_t GetRawYieldError()const {return fRawYieldErr;}
75  Double_t GetChiSquare() const;
76  Double_t GetBkgChiSquare();
77  Double_t GetReducedChiSquare() const;
78  Double_t GetBkgReducedChiSquare();
79  Double_t GetFitProbability() const;
80  void GetSideBandsBounds(Int_t& lb, Int_t& hb) const;
81  Bool_t* GetFixParam()const {return fFixPar;}
82  Bool_t GetFixThisParam(Int_t thispar)const;
83  virtual TH1F* GetAllRangeResidualsAndPulls(Double_t minrange=0,Double_t maxrange=-1,TH1 *hPulls=0x0,TH1 *hResidualTrend=0x0,TH1 *hPullsTrend=0x0);
84  virtual TH1F* GetOverBackgroundResidualsAndPulls(Double_t minrange=0,Double_t maxrange=-1,TH1 *hPulls=0x0,TH1 *hResidualTrend=0x0,TH1 *hPullsTrend=0x0);
85  TH1F* GetResidualsAndPulls(TH1 *h,TF1 *f,Double_t minrange=0,Double_t maxrange=-1,TH1 *hPulls=0x0,TH1 *hResidualTrend=0x0,TH1 *hPullsTrend=0x0);
86  virtual TPaveText* GetYieldBox(Double_t nsigma=3.);
87  virtual TPaveText* GetFitParametersBox(Double_t nsigma=3.,Int_t mode=0);
88  TVirtualPad* GetPad(Double_t nsigma=3,Int_t writeFitInfo=1)const;
89 
90  void PrintParTitles() const;
91 
92  void InitNtuParam(TString ntuname="ntupar");
93  void FillNtuParam(); //Fill the TNtuple with the current parameters
94  TNtuple* GetNtuParam() const {return fntuParam;}
95  TNtuple* NtuParamOneShot(TString ntuname="ntupar");
96  void WriteHisto(TString path="./") const;
97  void WriteNtuple(TString path="./") const;
98  virtual void WriteCanvas(TString userIDstring="",TString path="./",Double_t nsigma=3,Int_t writeFitInfo=1,Bool_t draw=kFALSE) const;
99  void DrawHere(TVirtualPad* pd,Double_t nsigma=3,Int_t writeFitInfo=1) const;
100  void DrawFit(Double_t nsigma=3) const;
101  void Reset();
102 
103  virtual void IntS(Float_t *valuewitherror) const;
104  virtual Double_t IntTot() const {return fhistoInvMass->Integral("width");}
105  virtual void Signal(Double_t nOfSigma,Double_t &signal,Double_t &errsignal) const;
106  virtual void Signal(Double_t min,Double_t max,Double_t &signal,Double_t &errsignal) const;
107  virtual void Background(Double_t nOfSigma,Double_t &background,Double_t &errbackground) const;
108  virtual void Background(Double_t min,Double_t max,Double_t &background,Double_t &errbackground) const;
109  void Significance(Double_t nOfSigma,Double_t &significance,Double_t &errsignificance) const;
110  void Significance(Double_t min,Double_t max,Double_t &significance,Double_t &errsignificance) const;
111 
112  virtual Double_t FitFunction4MassDistr (Double_t* x, Double_t* par);
113  virtual Double_t FitFunction4Sgn (Double_t* x, Double_t* par);
114  virtual Double_t FitFunction4Bkg (Double_t* x, Double_t* par);
115  virtual Bool_t MassFitter(Bool_t draw=kTRUE);
116  virtual Bool_t RefitWithBkgOnly(Bool_t draw=kTRUE);
117  void RebinMass(Int_t bingroup=1);
119  return fhistoInvMass->GetFunction("funcbkgFullRange");
120  }
122  return fhistoInvMass->GetFunction("funcbkgRecalc");
123  }
124  TF1* GetMassFunc(){
125  return fhistoInvMass->GetFunction("funcmass");
126  }
130  void SetFitOption(TString opt){fFitOption=opt.Data();};
131 
132 
133  protected:
134 
135  virtual void PlotFit(TVirtualPad* pd,Double_t nsigma=3,Int_t writeFitInfo=1)const;
136 
137  virtual void ComputeParSize();
138  virtual void ComputeNFinalPars();
139  Bool_t SideBandsBounds();
140  virtual Bool_t CheckRangeFit();
141  virtual void AddFunctionsToHisto();
142 
144  Double_t fminMass;
145  Double_t fmaxMass;
146  Int_t fminBinMass;
147  Int_t fmaxBinMass;
148  Int_t fNbin;
149  Int_t fParsSize;
150  Int_t fNFinalPars;
151  Float_t* fFitPars; //[fParsSize] array of fit parameters
152  Bool_t fWithBkg;
155  Int_t ffactor;
156  TNtuple* fntuParam;
157  Double_t fMass;
158  Double_t fMassErr;
159  Double_t fSigmaSgn;
160  Double_t fSigmaSgnErr;
161  Double_t fRawYield;
162  Double_t fRawYieldErr;
163  Bool_t fSideBands;
164  Bool_t* fFixPar; //[fNFinalPars] for each par if kTRUE it is fixed in fit
165  Int_t fSideBandl;
166  Int_t fSideBandr;
167  Int_t fcounter;
168  Int_t fNpfits;
169  TString fFitOption;
170  TList* fContourGraph;
171 
173  ClassDef(AliHFMassFitter,9);
174 };
176 
177 #endif
178 
179 
virtual TH1F * GetOverBackgroundResidualsAndPulls(Double_t minrange=0, Double_t maxrange=-1, TH1 *hPulls=0x0, TH1 *hResidualTrend=0x0, TH1 *hPullsTrend=0x0)
TVirtualPad * GetPad(Double_t nsigma=3, Int_t writeFitInfo=1) const
TH1F * GetHistoClone() const
Float_t * fFitPars
number of parameters of the final function
void DrawHere(TVirtualPad *pd, Double_t nsigma=3, Int_t writeFitInfo=1) const
write the canvas in a root file
Bool_t * fFixPar
kTRUE = only side bands considered
virtual Bool_t CheckRangeFit()
virtual TPaveText * GetFitParametersBox(Double_t nsigma=3., Int_t mode=0)
void SetHisto(const TH1F *histoToFit)
setters
void WriteNtuple(TString path="./") const
write the histogram
Int_t fSideBandr
left side band limit (bin number)
Int_t GetNFinalPars() const
void GetTypeOfFit(Bool_t &background, Int_t &typeb) const
void GetSideBandsBounds(Int_t &lb, Int_t &hb) const
virtual void PlotFit(TVirtualPad *pd, Double_t nsigma=3, Int_t writeFitInfo=1) const
void DrawFit(Double_t nsigma=3) const
void SetInitialGaussianMean(Double_t mean)
Int_t fParsSize
number of bins
virtual void IntS(Float_t *valuewitherror) const
Int_t ftypeOfFit4Sgn
0 = exponential; 1 = linear; 2 = pol2
virtual void SetFixGaussianMean(Double_t mean=1.865, Bool_t fixpar=kTRUE)
virtual void ComputeParSize()
Double_t fmaxMass
lower mass limit
Int_t ftypeOfFit4Bkg
signal+background (kTRUE) or signal only (kFALSE)
TNtuple * GetNtuParam() const
Int_t GetReflectionSigmaFactor() const
Double_t GetFitProbability() const
virtual ~AliHFMassFitter()
Double_t fMassErr
signal gaussian mean value
virtual Double_t IntTot() const
integral of signal given my the fit with error
TF1 * GetBackgroundFullRangeFunc()
TF1 * GetBackgroundRecalcFunc()
virtual Bool_t RefitWithBkgOnly(Bool_t draw=kTRUE)
virtual void AddFunctionsToHisto()
void SetMinRangeFit(Double_t minvalue)
void PrintParTitles() const
Int_t fmaxBinMass
bin corresponding to fminMass
virtual TPaveText * GetYieldBox(Double_t nsigma=3.)
void SetSideBands(Bool_t onlysidebands=kTRUE)
change the default value of the sigma
Double_t fminMass
histogram to fit
Double_t GetRawYieldError() const
Int_t typeb
Double_t * sigma
virtual void Signal(Double_t nOfSigma, Double_t &signal, Double_t &errsignal) const
return total integral of the histogram
void SetUseLikelihoodWithWeightsFit()
Int_t fNbin
bin corresponding to fmaxMass
void SetRangeFit(Double_t minvalue, Double_t maxvalue)
virtual Double_t FitFunction4Bkg(Double_t *x, Double_t *par)
Double_t fRawYieldErr
signal gaussian integral
Double_t GetMeanUncertainty() const
Double_t fSigmaSgnErr
signal gaussian sigma
Double_t GetChiSquare() const
Double_t GetMean() const
void SetMaxRangeFit(Double_t maxvalue)
Double_t GetReducedChiSquare() const
Double_t fMass
contains fit parameters
void SetReflectionSigmaFactor(Int_t constant)
Bool_t GetFixThisParam(Int_t thispar) const
void SetFixParam(Bool_t *fixpar)
consider only side bands
Int_t GetBinN() const
void SetBinN(Int_t newbinN)
Int_t fcounter
right side band limit (bin number)
void FillNtuParam()
initialize TNtuple to store the parameters
void SetType(Int_t fittypeb, Int_t fittypes)
Int_t fNFinalPars
size of fFitPars array
void SetUseLikelihoodFit()
void InitNtuParam(TString ntuname="ntupar")
void GetFitPars(Float_t *pars) const
Double_t GetMaxRangeFit() const
virtual void Background(Double_t nOfSigma, Double_t &background, Double_t &errbackground) const
signal in (min, max) with error
Double_t nsigma
Double_t GetRawYield() const
Int_t mode
Definition: anaM.C:40
void SetInitialGaussianSigma(Double_t sigma)
change the default value of the mean
virtual Double_t FitFunction4MassDistr(Double_t *x, Double_t *par)
significance in (min, max) with error
Double_t fRawYield
err signal gaussian sigma
TH1F * GetResidualsAndPulls(TH1 *h, TF1 *f, Double_t minrange=0, Double_t maxrange=-1, TH1 *hPulls=0x0, TH1 *hResidualTrend=0x0, TH1 *hPullsTrend=0x0)
virtual void SetFixGaussianSigma(Double_t sigma=0.012, Bool_t fixpar=kTRUE)
void RebinMass(Int_t bingroup=1)
virtual Bool_t MassFitter(Bool_t draw=kTRUE)
Double_t GetMinRangeFit() const
TNtuple * fntuParam
number to multiply to the sigma of the signal to obtain the reflected gaussian
virtual void ComputeNFinalPars()
virtual void SetDefaultFixParam()
Double_t fSigmaSgn
err signal gaussian mean value
TList * fContourGraph
L, LW or Chi2.
Double_t GetBkgChiSquare()
void GetRangeFit(Double_t &minvalue, Double_t &maxvalue) const
return the histogram
void SetFitOption(TString opt)
Double_t GetBkgReducedChiSquare()
virtual TH1F * GetAllRangeResidualsAndPulls(Double_t minrange=0, Double_t maxrange=-1, TH1 *hPulls=0x0, TH1 *hResidualTrend=0x0, TH1 *hPullsTrend=0x0)
Int_t rebin
Int_t ffactor
0 = gaus; 1 = gaus+gaus broadened
void WriteHisto(TString path="./") const
the three functions above all together
Bool_t * GetFixParam() const
Int_t fminBinMass
upper mass limit
Double_t GetSigma() const
virtual Bool_t SetFixThisParam(Int_t thispar, Bool_t fixpar)
Bool_t fSideBands
err on signal gaussian integral
Int_t fNpfits
internal counter
void Significance(Double_t nOfSigma, Double_t &significance, Double_t &errsignificance) const
backgournd in (min, max) with error
TString fFitOption
Number of points used in the fit.
virtual Double_t FitFunction4Sgn(Double_t *x, Double_t *par)
AliHFMassFitter for the fit of invariant mass distribution of charmed mesons.
Double_t GetSigmaUncertainty() const
virtual void WriteCanvas(TString userIDstring="", TString path="./", Double_t nsigma=3, Int_t writeFitInfo=1, Bool_t draw=kFALSE) const
write the TNtuple
AliHFMassFitter & operator=(const AliHFMassFitter &mfit)
TNtuple * NtuParamOneShot(TString ntuname="ntupar")
return the TNtuple