4054f68953ccf7215fdbba52e6f5fbe18c775e7c
[u/mrichter/AliRoot.git] / PWGDQ / dielectron / AliDielectronBtoJPSItoEleCDFfitFCN.h
1 #ifndef ALIDIELECTRONBTOJPSITOELECDFFITFCN_H\r
2 #define ALIDIELECTRONBTOJPSITOELECDFFITFCN_H\r
3 /* Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *\r
4  * See cxx source for full Copyright notice                               */\r
5 \r
6 //_________________________________________________________________________\r
7 //                      Class AliDielectronBtoJPSItoEleCDFfitFCN\r
8 //                    Definition of main function used in \r
9 //                     unbinned log-likelihood fit for\r
10 //                 the channel B -> JPsi + X -> e+e- + X\r
11 //      \r
12 //                          Origin: C.Di Giglio\r
13 //     Contact: Carmelo.Digiglio@ba.infn.it , Giuseppe.Bruno@ba.infn.it\r
14 //_________________________________________________________________________\r
15 \r
16 #include <TNamed.h>\r
17 #include <TDatabasePDG.h>\r
18 #include "TH1F.h"\r
19 \r
20 class TRandom3;\r
21 class TF1;\r
22 \r
23 enum IntegralType {kBkg, \r
24         kBkgNorm, \r
25         kSig, \r
26         kSigNorm};\r
27 \r
28 enum PtBins       {kallpt, \r
29         kptbin1,kptbin2,kptbin3,\r
30         kptbin4,kptbin5,kptbin6,\r
31         kptbin7,kptbin8,kptbin9};\r
32 //_________________________________________________________________________________________________\r
33 class AliDielectronBtoJPSItoEleCDFfitFCN : public TNamed {\r
34         public:\r
35                 //\r
36                 AliDielectronBtoJPSItoEleCDFfitFCN();\r
37                 AliDielectronBtoJPSItoEleCDFfitFCN(const AliDielectronBtoJPSItoEleCDFfitFCN& source); \r
38                 AliDielectronBtoJPSItoEleCDFfitFCN& operator=(const AliDielectronBtoJPSItoEleCDFfitFCN& source);  \r
39                 virtual ~AliDielectronBtoJPSItoEleCDFfitFCN();\r
40 \r
41                 Double_t EvaluateLikelihood(const Double_t* pseudoproperdecaytime,\r
42                                 const Double_t* invariantmass, const Int_t* type, const Int_t ncand) const;\r
43 \r
44                 Double_t GetResWeight()                    const { return fParameters[0]; }\r
45                 Double_t GetFPlus()                        const { return fParameters[1]; }\r
46                 Double_t GetFMinus()                       const { return fParameters[2]; }\r
47                 Double_t GetFSym()                         const { return fParameters[3]; } \r
48                 Double_t GetLamPlus()                      const { return fParameters[4]; }\r
49                 Double_t GetLamMinus()                     const { return fParameters[5]; }\r
50                 Double_t GetLamSym()                       const { return fParameters[6]; }\r
51                 Double_t GetFractionJpsiFromBeauty()       const { return fParameters[7]; }\r
52                 Double_t GetFsig()                         const { return fParameters[8]; }\r
53                 Double_t GetCrystalBallMmean()             const { return fParameters[9]; }\r
54                 Double_t GetCrystalBallNexp()              const { return fParameters[10]; }\r
55                 Double_t GetCrystalBallSigma()             const { return fParameters[11]; }\r
56                 Double_t GetCrystalBallAlpha()             const { return fParameters[12]; }\r
57                 Double_t GetCrystalBallNorm()              const { return fParameters[13]; }\r
58                 Double_t GetBkgInvMassNorm()               const { return fParameters[14]; }\r
59                 Double_t GetBkgInvMassMean()               const { return fParameters[15]; }\r
60                 Double_t GetBkgInvMassSlope()              const { return fParameters[16]; }  \r
61                 Double_t GetBkgInvMassConst()              const { return fParameters[17]; } \r
62                 Double_t GetNormGaus1ResFunc(Int_t type)   const { return fParameters[18+(2-type)*9]; }\r
63                 Double_t GetNormGaus2ResFunc(Int_t type)   const { return fParameters[19+(2-type)*9]; }\r
64                 Double_t GetIntegralMassSig()              const { return fintmMassSig; }\r
65                 Double_t GetIntegralMassBkg()              const { return fintmMassBkg; }\r
66                 Double_t GetResMean1(Int_t type)           const { return fParameters[20+(2-type)*9]; } \r
67                 Double_t GetResSigma1(Int_t type)          const { return fParameters[21+(2-type)*9]; }\r
68                 Double_t GetResMean2(Int_t type)           const { return fParameters[22+(2-type)*9]; }\r
69                 Double_t GetResSigma2(Int_t type)          const { return fParameters[23+(2-type)*9]; }\r
70                 \r
71                 Double_t GetResAlfa(Int_t type)            const { return fParameters[24+(2-type)*9]; }   \r
72                 Double_t GetResLambda(Int_t type)          const { return fParameters[25+(2-type)*9]; } \r
73                 Double_t GetResNormExp(Int_t type)         const { return fParameters[26+(2-type)*9]; }\r
74 \r
75                 Bool_t GetCrystalBallParam()               const { return fCrystalBallParam; }\r
76                 TH1F * GetCsiMcHisto()                     const { return fhCsiMC; }\r
77                 Double_t GetResWeight(Int_t iW)            const { return fWeightType[iW]; }\r
78                 \r
79                 Double_t* GetParameters()                         { return fParameters;}\r
80 \r
81                 // return pointer to likelihood functions  \r
82                 TF1* GetCsiMC(Double_t xmin, Double_t xmax,Double_t normalization);\r
83                 TF1* GetResolutionFunc(Double_t xmin, Double_t xmax,Double_t normalization, Double_t type=2);\r
84                 TF1* GetResolutionFuncAllTypes(Double_t xmin, Double_t xmax,Double_t normalization);\r
85                 TF1* GetFunB(Double_t xmin, Double_t xmax, Double_t normalization, Double_t type=2);\r
86                 TF1* GetFunBAllTypes(Double_t xmin, Double_t xmax, Double_t normalization);\r
87                 TF1* GetEvaluateCDFDecayTimeBkgDistr(Double_t xmin, Double_t xmax, Double_t normalization,Double_t type = 2);\r
88                 TF1* GetEvaluateCDFDecayTimeBkgDistrAllTypes(Double_t xmin, Double_t xmax, Double_t normalization);\r
89                 TF1* GetEvaluateCDFDecayTimeSigDistr(Double_t xmin, Double_t xmax, Double_t normalization, Double_t type);\r
90                 TF1* GetEvaluateCDFInvMassBkgDistr(Double_t mMin, Double_t mMax, Double_t normalization);\r
91                 TF1* GetEvaluateCDFInvMassSigDistr(Double_t mMin, Double_t mMax, Double_t normalization);\r
92                 TF1* GetEvaluateCDFInvMassTotalDistr(Double_t mMin, Double_t mMax, Double_t normalization);\r
93                 TF1* GetEvaluateCDFDecayTimeTotalDistr(Double_t xMin, Double_t xMax, Double_t normalization, Double_t type=2);\r
94                 TF1 *GetEvaluateCDFDecayTimeTotalDistrAllTypes(Double_t xMin, Double_t xMax, Double_t normalization);\r
95 \r
96                 void SetResWeight(Double_t resWgt) {fParameters[0] = resWgt;}\r
97                 void SetFPlus(Double_t plus) {fParameters[1] = plus;}\r
98                 void SetFMinus(Double_t minus) {fParameters[2]  = minus;}\r
99                 void SetFSym(Double_t sym) {fParameters[3] = sym;}\r
100                 void SetLamPlus(Double_t lamplus) {fParameters[4] = lamplus;}\r
101                 void SetLamMinus(Double_t lamminus) {fParameters[5] = lamminus;}\r
102                 void SetLamSym(Double_t lamsym) {fParameters[6] = lamsym;}\r
103                 void SetFractionJpsiFromBeauty(Double_t B) {fParameters[7] = B;}\r
104                 void SetFsig(Double_t Fsig) {fParameters[8] = Fsig;}\r
105                 void SetCrystalBallMmean(Double_t CrystalBallMmean) {fParameters[9] = CrystalBallMmean;}\r
106                 void SetCrystalBallNexp(Double_t CrystalBallNexp) {fParameters[10] = CrystalBallNexp;}\r
107                 void SetCrystalBallSigma(Double_t CrystalBallSigma) {fParameters[11] = CrystalBallSigma;}\r
108                 void SetCrystalBallAlpha(Double_t CrystalBallAlpha) {fParameters[12] = CrystalBallAlpha;}\r
109                 void SetCrystalBallNorm(Double_t CrystalBallNorm) {fParameters[13] = CrystalBallNorm;}\r
110                 void SetBkgInvMassNorm(Double_t BkgInvMassNorm) {fParameters[14] = BkgInvMassNorm;}\r
111                 void SetBkgInvMassMean(Double_t BkgInvMassMean) {fParameters[15] = BkgInvMassMean;}\r
112                 void SetBkgInvMassSlope(Double_t BkgInvMassSlope) {fParameters[16] = BkgInvMassSlope;}\r
113                 void SetBkgInvMassConst(Double_t BkgInvMassConst) {fParameters[17] = BkgInvMassConst;}\r
114                 void SetNormGaus1ResFunc(Double_t norm1) {fParameters[18] = norm1;}\r
115                 void SetNormGaus2ResFunc(Double_t norm2) {fParameters[19] = norm2;}\r
116                 void SetAllParameters(const Double_t* parameters);\r
117                 void SetIntegralMassSig(Double_t integral) { fintmMassSig = integral; }\r
118                 void SetIntegralMassBkg(Double_t integral) { fintmMassBkg = integral; }\r
119                 void SetCsiMC(const TH1F* MCtemplate) {fhCsiMC = (TH1F*)MCtemplate->Clone("fhCsiMC");}\r
120 \r
121                 void SetResolutionConstants(const Double_t* resolutionConst, Int_t type);\r
122                 void SetMassWndHigh(Double_t limit) { fMassWndHigh = TDatabasePDG::Instance()->GetParticle(443)->Mass() + limit ;}\r
123                 void SetMassWndLow(Double_t limit) { fMassWndLow = TDatabasePDG::Instance()->GetParticle(443)->Mass() - limit ;}\r
124                 void SetCrystalBallFunction(Bool_t okCB) {fCrystalBallParam = okCB;}\r
125  \r
126                 void SetWeightType(Double_t wFF, Double_t wFS, Double_t wSS) {fWeightType[0]= wSS; fWeightType[1]= wFS; fWeightType[2]= wFF;}\r
127                 void ComputeMassIntegral(); \r
128 \r
129                 void ReadMCtemplates(Int_t BinNum);\r
130 \r
131                 void PrintStatus();\r
132 \r
133                 Double_t EvaluateCDFInvMassSigDistr(Double_t m) const ;\r
134                 Double_t EvaluateCDFInvMassBkgDistr(Double_t m) const;\r
135                 Double_t ResolutionFunc(Double_t x, Int_t type) const;\r
136                 Double_t EvaluateCDFDecayTimeBkgDistr(Double_t x, Int_t type) const ;\r
137 \r
138         private:  \r
139                 Double_t fParameters[45];        /*  par[0]  = weightRes;                \r
140                                                      par[1]  = fPos;\r
141                                                      par[2]  = fNeg;\r
142                                                      par[3]  = fSym\r
143                                                      par[4]  = fOneOvLamPlus;\r
144                                                      par[5]  = fOneOvLamMinus;\r
145                                                      par[6]  = fOneOvLamSym;\r
146                                                      par[7]  = fFractionJpsiFromBeauty;\r
147                                                      par[8]  = fFsig;\r
148                                                      par[9]  = fCrystalBallMmean;\r
149                                                      par[10] = fCrystalBallNexp;\r
150                                                      par[11] = fCrystalBallSigma;\r
151                                                      par[12] = fCrystalBallAlpha;\r
152                                                      par[13] = fCrystalBallNorm;\r
153                                                      par[14] = fBkgNorm;\r
154                                                      par[15] = fBkgMean; \r
155                                                      par[16] = fBkgSlope;\r
156                                                      par[17] = fBkgConst;\r
157                                                      par[18] = norm1Gaus; // resolution param used for First-First\r
158                                                      par[19] = norm2Gaus;\r
159                                                      par[20] = fMean1ResFunc;\r
160                                                      par[21] = fSigma1ResFunc;\r
161                                                      par[22] = fMean2ResFunc;\r
162                                                      par[23] = fSigma2ResFunc;\r
163                                                      par[24] = fResAlfa;  \r
164                                                      par[25] = fResLambda;\r
165                                                      par[26] = fResNormExp;\r
166                                                      par[27] = norm1Gaus;    // resolution param used for First-Second\r
167                                                      par[28] = norm2Gaus;\r
168                                                      par[29] = fMean1ResFunc;\r
169                                                      par[30] = fSigma1ResFunc;\r
170                                                      par[31] = fMean2ResFunc;\r
171                                                      par[32] = fSigma2ResFunc;\r
172                                                      par[33] = fResAlfa;  \r
173                                                      par[34] = fResLambda;\r
174                                                      par[35] = fResNormExp;\r
175                                                      par[36] = norm1Gaus;    // resolution param used for Second-Second\r
176                                                      par[37] = norm2Gaus;\r
177                                                      par[38] = fMean1ResFunc;\r
178                                                      par[39] = fSigma1ResFunc;\r
179                                                      par[40] = fMean2ResFunc;\r
180                                                      par[41] = fSigma2ResFunc;\r
181                                                      par[42] = fResAlfa; \r
182                                                      par[43] = fResLambda;\r
183                                                      par[44] = fResNormExp;\r
184                                                      */\r
185 \r
186                 Double_t fFPlus;                     // parameters of the log-likelihood function\r
187                 Double_t fFMinus;                    // Slopes of the x distributions of the background \r
188                 Double_t fFSym;                      // functions \r
189 \r
190                 Double_t fintmMassSig;               // integral of invariant mass distribution for the signal\r
191                 Double_t fintmMassBkg;               // integral of invariant mass distribution for the bkg\r
192 \r
193                 TH1F *fhCsiMC;                       // X distribution used as MC template for JPSI from B\r
194                 Double_t fMassWndHigh;               // JPSI Mass window higher limit\r
195                 Double_t fMassWndLow;                // JPSI Mass window lower limit\r
196                 Bool_t fCrystalBallParam;            // Boolean to switch to Crystall Ball parameterisation\r
197 \r
198                 Double_t fWeightType[3];             // vector with weights of candidates types (used to draw functions)            \r
199                 ////\r
200 \r
201                 Double_t EvaluateCDFfunc(Double_t x, Double_t m, Int_t type) const ;\r
202                 Double_t EvaluateCDFfuncNorm(Double_t x, Double_t m, Int_t type) const ;\r
203 \r
204                 ////\r
205 \r
206                 Double_t EvaluateCDFfuncSignalPart(Double_t x, Double_t m, Int_t type) const ;      // Signal part \r
207                 Double_t EvaluateCDFDecayTimeSigDistr(Double_t x, Int_t type) const ;\r
208                 Double_t EvaluateCDFDecayTimeSigDistrFunc(const Double_t* x, const Double_t *par) const { return par[0]*EvaluateCDFDecayTimeSigDistr(x[0],(Int_t)par[1]);}\r
209                 Double_t EvaluateCDFInvMassSigDistrFunc(const Double_t* x, const Double_t *par) const {return par[0]*EvaluateCDFInvMassSigDistr(x[0])/fintmMassSig;}\r
210                 Double_t EvaluateCDFfuncBkgPart(Double_t x,Double_t m,Int_t type) const ;          // Background part\r
211                 Double_t EvaluateCDFDecayTimeBkgDistrFunc(const Double_t* x, const Double_t *par) const { return EvaluateCDFDecayTimeBkgDistr(x[0],(Int_t)par[1])*par[0];}\r
212                 Double_t EvaluateCDFDecayTimeBkgDistrFuncAllTypes(const Double_t* x, const Double_t *par) const {return (fWeightType[2]*EvaluateCDFDecayTimeBkgDistr(x[0],2)+fWeightType[1]*EvaluateCDFDecayTimeBkgDistr(x[0],1)+fWeightType[0]*EvaluateCDFDecayTimeBkgDistr(x[0],0))*par[0];}\r
213                 Double_t EvaluateCDFInvMassBkgDistrFunc(const Double_t* x, const Double_t *par) const {return par[0]*EvaluateCDFInvMassBkgDistr(x[0])/fintmMassBkg;} \r
214                   \r
215                 Double_t EvaluateCDFInvMassTotalDistr(const Double_t* x, const Double_t *par) const;\r
216                 Double_t EvaluateCDFDecayTimeTotalDistr(const Double_t* x, const Double_t *par) const;  \r
217                 ////\r
218                 Double_t EvaluateCDFDecayTimeTotalDistrAllTypes(const Double_t* x, const Double_t *par) const;\r
219 \r
220                 Double_t FunB(Double_t x, Int_t type) const;\r
221                 Double_t FunBfunc(const Double_t *x, const Double_t *par) const {return FunB(x[0],(Int_t)par[1])*par[0];}\r
222                 Double_t FunBfuncAllTypes(const Double_t *x, const Double_t *par) const {return (fWeightType[2]*FunB(x[0],2)+fWeightType[1]*FunB(x[0],1)+fWeightType[0]*FunB(x[0],0))*par[0];}\r
223                 Double_t FunP(Double_t x, Int_t type) const ;\r
224                 Double_t CsiMC(Double_t x) const;\r
225                 Double_t CsiMCfunc(const Double_t* x, const Double_t *par) const {  return CsiMC(x[0])*par[0];}\r
226                 Double_t FunBkgPos(Double_t x, Int_t type) const ;\r
227                 Double_t FunBkgNeg(Double_t x, Int_t type) const ;\r
228                 Double_t FunBkgSym(Double_t x, Int_t type) const ;\r
229                 Double_t ResolutionFuncf(const Double_t* x, const Double_t *par) const { return ResolutionFunc(x[0],(Int_t)par[1])*par[0];}\r
230                 Double_t ResolutionFuncAllTypes(const Double_t* x, const Double_t *par) const { return (fWeightType[2]*ResolutionFunc(x[0],2)+fWeightType[1]*ResolutionFunc(x[0],1)+fWeightType[0]*ResolutionFunc(x[0],0))*par[0]; }                 \r
231  \r
232 \r
233                 ClassDef (AliDielectronBtoJPSItoEleCDFfitFCN,1);         // Unbinned log-likelihood fit \r
234 \r
235 };\r
236 \r
237 #endif\r