]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/vertexingHF/AliHFMassFitter.h
Updates D* cuts for peripheral PbPb events
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliHFMassFitter.h
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
8 /////////////////////////////////////////////////////////////
9 //
10 // AliHFMassFitter for the fit of invariant mass distribution
11 // of charmed mesons
12 //
13 // Author: C.Bianchin, chiara.bianchin@pd.infn.it
14 /////////////////////////////////////////////////////////////
15
16 #include <TNamed.h>
17 #include <TString.h>
18
19 class TF1;
20 class TNtuple;
21 class TFile;
22 class TList;
23 class TH1F;
24 class TVirtualPad;
25
26 class AliHFMassFitter : public TNamed {
27
28  public:
29   AliHFMassFitter();
30   AliHFMassFitter(const TH1F* histoToFit, Double_t minvalue, Double_t maxvalue, Int_t rebin=1,Int_t fittypeb=0,Int_t fittypes=0);
31   virtual ~AliHFMassFitter();
32
33   AliHFMassFitter(const AliHFMassFitter &mfit);
34   AliHFMassFitter& operator=(const AliHFMassFitter &mfit);
35
36   //setters
37   void     SetHisto(const TH1F *histoToFit);
38   void     SetRangeFit(Double_t minvalue, Double_t maxvalue){fminMass=minvalue; fmaxMass=maxvalue; CheckRangeFit();}
39   void     SetMinRangeFit(Double_t minvalue){fminMass=minvalue;printf("CheckRangeFit after SetMaxRangeFit is also set\n");}
40   void     SetMaxRangeFit(Double_t maxvalue){fmaxMass=maxvalue;printf("CheckRangeFit after SetMinRangeFit is also set\n");}
41   void     SetBinN(Int_t newbinN){fNbin=newbinN;}
42   void     SetType(Int_t fittypeb, Int_t fittypes);
43   void     SetReflectionSigmaFactor(Int_t constant) {ffactor=constant;}
44   void     SetInitialGaussianMean(Double_t mean) {fMass=mean;} // change the default value of the mean
45   void     SetInitialGaussianSigma(Double_t sigma) {fSigmaSgn=sigma;} // change the default value of the sigma
46   void     SetSideBands(Bool_t onlysidebands=kTRUE) {fSideBands=onlysidebands;} // consider only side bands
47   void     SetFixParam(Bool_t *fixpar){fFixPar=fixpar;}
48   void     SetDefaultFixParam();
49   Bool_t   SetFixThisParam(Int_t thispar,Bool_t fixpar);
50   void     SetFixGaussianMean(Double_t mean=1.865,Bool_t fixpar=kTRUE){SetInitialGaussianMean(mean); SetFixThisParam(fNFinalPars-2,fixpar);}
51   void     SetFixGaussianSigma(Double_t sigma=0.012, Bool_t fixpar=kTRUE){SetInitialGaussianSigma(sigma); SetFixThisParam(fNFinalPars-1,fixpar);}
52
53   //getters
54   TH1F*    GetHistoClone() const; //return the histogram
55   void     GetRangeFit(Double_t &minvalue, Double_t &maxvalue) const {minvalue=fminMass; maxvalue=fmaxMass;}
56   Double_t GetMinRangeFit()const {return fminMass;}
57   Double_t GetMaxRangeFit()const {return fmaxMass;}
58   Int_t    GetBinN()       const {return fNbin;}
59   void     GetFitPars(Float_t* pars) const;
60   Int_t    GetNFinalPars() const {return fNFinalPars;}
61   void     GetTypeOfFit(Bool_t &background, Int_t &typeb) const {background = fWithBkg; typeb = ftypeOfFit4Bkg;}
62   Int_t    GetReflectionSigmaFactor() const {return ffactor;} 
63   Double_t GetMean() const {return fMass;}
64   Double_t GetSigma()const {return fSigmaSgn;}
65   Double_t GetChiSquare() const;
66   Double_t GetReducedChiSquare() const;
67   void     GetSideBandsBounds(Int_t& lb, Int_t& hb) const;
68   Bool_t*  GetFixParam()const {return fFixPar;}
69   Bool_t   GetFixThisParam(Int_t thispar)const;
70   TVirtualPad* GetPad(Double_t nsigma=3,Int_t writeFitInfo=1)const;
71
72   void     PrintParTitles() const;
73
74   void     InitNtuParam(char *ntuname="ntupar"); // initialize TNtuple to store the parameters
75   void     FillNtuParam(); //Fill the TNtuple with the current parameters
76   TNtuple* GetNtuParam() const {return fntuParam;} // return the TNtuple
77   TNtuple* NtuParamOneShot(char *ntuname="ntupar"); // the three functions above all together
78   void     WriteHisto(TString path="./") const; // write the histogram
79   void     WriteNtuple(TString path="./") const; // write the TNtuple
80   void     WriteCanvas(TString userIDstring="",TString path="./",Double_t nsigma=3,Int_t writeFitInfo=1,Bool_t draw=kFALSE) const; //write the canvas in a root file
81   void     DrawHere(TVirtualPad* pd,Double_t nsigma=3,Int_t writeFitInfo=1) const;
82   void     DrawFit(Double_t nsigma=3) const;
83   void     Reset();
84
85   void     IntS(Float_t *valuewitherror) const;    // integral of signal given my the fit with error
86   Double_t IntTot() const {return fhistoInvMass->Integral("width");}  // return total integral of the histogram
87   void     Signal(Double_t nOfSigma,Double_t &signal,Double_t &errsignal) const; // signal in nsigma with error 
88   void     Signal(Double_t min,Double_t max,Double_t &signal,Double_t &errsignal) const; // signal in (min, max) with error 
89   void     Background(Double_t nOfSigma,Double_t &background,Double_t &errbackground) const; // backgournd in nsigma with error 
90   void     Background(Double_t min,Double_t max,Double_t &background,Double_t &errbackground) const; // backgournd in (min, max) with error 
91   void     Significance(Double_t nOfSigma,Double_t &significance,Double_t &errsignificance) const; // significance in nsigma with error 
92   void     Significance(Double_t min,Double_t max,Double_t &significance,Double_t &errsignificance) const; // significance in (min, max) with error 
93
94   Double_t FitFunction4MassDistr (Double_t* x, Double_t* par);
95   Double_t FitFunction4Sgn (Double_t* x, Double_t* par);
96   Double_t FitFunction4Bkg (Double_t* x, Double_t* par);
97   Bool_t   MassFitter(Bool_t draw=kTRUE);
98   Bool_t   RefitWithBkgOnly(Bool_t draw=kTRUE);
99   void     RebinMass(Int_t bingroup=1);
100   TF1*     GetBackgroundFullRangeFunc(){
101     return fhistoInvMass->GetFunction("funcbkgFullRange");
102   }
103   TF1*     GetBackgroundRecalcFunc(){
104     return fhistoInvMass->GetFunction("funcbkgRecalc");
105   }
106   TF1*     GetMassFunc(){
107     return fhistoInvMass->GetFunction("funcmass");
108   }
109
110
111  private:
112
113   void     PlotFit(TVirtualPad* pd,Double_t nsigma=3,Int_t writeFitInfo=1)const;
114
115   void     ComputeParSize();
116   void     ComputeNFinalPars();
117   Bool_t   SideBandsBounds();
118   Bool_t   CheckRangeFit();
119   void     AddFunctionsToHisto();
120
121   TH1F*     fhistoInvMass;     // histogram to fit
122   Double_t  fminMass;          // lower mass limit
123   Double_t  fmaxMass;          // upper mass limit
124   Int_t     fminBinMass;       // bin corresponding to fminMass
125   Int_t     fmaxBinMass;       // bin corresponding to fmaxMass
126   Int_t     fNbin;             // number of bins
127   Int_t     fParsSize;         // size of fFitPars array
128   Int_t     fNFinalPars;       // number of parameters of the final function
129   Float_t*  fFitPars;          //[fParsSize] array of fit parameters
130   Bool_t    fWithBkg;          // signal+background (kTRUE) or signal only (kFALSE)
131   Int_t     ftypeOfFit4Bkg;    // 0 = exponential; 1 = linear; 2 = pol2
132   Int_t     ftypeOfFit4Sgn;    // 0 = gaus; 1 = gaus+gaus broadened
133   Int_t     ffactor;           // number to multiply to the sigma of the signal to obtain the reflected gaussian
134   TNtuple*  fntuParam;         // contains fit parameters
135   Double_t  fMass;             // signal gaussian mean value
136   Double_t  fSigmaSgn;         // signal gaussian sigma
137   Bool_t    fSideBands;        // kTRUE = only side bands considered
138   Bool_t*   fFixPar;           //[fNFinalPars] for each par if kTRUE it is fixed in fit
139   Int_t     fSideBandl;        // left side band limit (bin number)
140   Int_t     fSideBandr;        // right side band limit (bin number)
141   Int_t     fcounter;          // internal counter
142   TList*    fContourGraph;     // TList of TGraph containing contour plots
143   ClassDef(AliHFMassFitter,4); // class for invariant mass fit
144 };
145
146 #endif
147
148