major dielectron update (included also the data and plotting macros for paper)
[u/mrichter/AliRoot.git] / PWG3 / dielectron / AliDielectronBtoJPSItoEleCDFfitHandler.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 #include <TVirtualFitter.h>
16 #include <TStopwatch.h>
17 #include "AliLog.h"
18 #include "AliDielectronBtoJPSItoEleCDFfitHandler.h"
19 #include "AliDielectronBtoJPSItoEleCDFfitFCN.h"
20
21 //-------------------------------------------------------------------------
22 //                      Class AliDielectronBtoJPSItoEleCDFfitHandler
23 //            Class to perform unbinned log-likelihood fit
24 //      
25 //                        Origin: C. Di Giglio
26 //     Contact: carmelo.digiglio@ba.infn.it , giuseppe.bruno@ba.infn.it
27 //-------------------------------------------------------------------------
28
29 void CDFFunction(Int_t &npar, Double_t *gin, Double_t &f, Double_t *x, Int_t iflag);
30
31 ClassImp(AliDielectronBtoJPSItoEleCDFfitHandler)
32
33         //______________________________________________________________________________
34 void CDFFunction(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
35 {
36         // This function is called by minuit
37         // The corresponding member method is called
38         // using SetObjectFit/GetObjectFit methods of TMinuit
39         AliDielectronBtoJPSItoEleCDFfitHandler* dummy = (AliDielectronBtoJPSItoEleCDFfitHandler *)TVirtualFitter::GetFitter()->GetObjectFit();
40         dummy->CdfFCN(npar, gin, f, par, iflag);
41 }
42
43
44 //_________________________________________________________________________________________________
45 AliDielectronBtoJPSItoEleCDFfitHandler::AliDielectronBtoJPSItoEleCDFfitHandler():
46         fIsParamFixed(20),
47         fPrintStatus(kFALSE),
48         fUp(0),
49         fX(0x0),
50         fM(0x0),
51         fLikely(0x0),
52         fNcand(0)
53 {
54         //
55         // default constructor
56         //
57 }
58 //_________________________________________________________________________________________________
59 AliDielectronBtoJPSItoEleCDFfitHandler::AliDielectronBtoJPSItoEleCDFfitHandler(Double_t* decaytime, 
60                 Double_t* invariantmass, Int_t ncand) :
61         fIsParamFixed(20),
62         fPrintStatus(kFALSE),
63         fUp(0),
64         fX(decaytime),
65         fM(invariantmass),
66         fLikely(0x0),
67         fNcand(ncand)
68 {
69         //
70         // constructor
71         //
72         AliInfo("\n+++\n+++ Minimization object AliDielectronBtoJPSItoEleCDFfitHandler created\n+++\n");
73         fLikely = new AliDielectronBtoJPSItoEleCDFfitFCN();
74         AliInfo("\n+++\n+++ CDF fit function object AliDielectronBtoJPSItoEleCDFfitFCN created\n+++\n");
75         AliInfo("Parameter 0  ----> fWeightRes");
76         AliInfo("Parameter 1  ----> fPos");
77         AliInfo("Parameter 2  ----> fNeg");
78         AliInfo("Parameter 3  ----> fSym");
79         AliInfo("Parameter 4  ----> fOneOvLamPlus");
80         AliInfo("Parameter 5  ----> fOneOvLamMinus");
81         AliInfo("Parameter 6  ----> fOneOvLamSym");
82         AliInfo("Parameter 7  ----> fB");
83         AliInfo("Parameter 8  ----> fFsig");
84         AliInfo("Parameter 9  ----> fMmean");
85         AliInfo("Parameter 10 ----> fNexp");
86         AliInfo("Parameter 11 ----> fSigma");
87         AliInfo("Parameter 12 ----> fAlpha");
88         AliInfo("Parameter 13 ----> fNorm");
89         AliInfo("Parameter 14 ----> fBkgNorm");
90         AliInfo("Parameter 15 ----> fBkgMean");
91         AliInfo("Parameter 16 ----> fBkgSlope");
92         AliInfo("Parameter 17 ----> fBkgConst");
93         AliInfo("Parameter 18 ----> fNormGaus1");
94         AliInfo("Parameter 19 ----> fNormGaus2");
95
96         AliInfo(Form("\n+++\n+++ Number of candidates ---> %d\n+++\n ", ncand));
97 }
98 //___________________________________________________________________________
99 AliDielectronBtoJPSItoEleCDFfitHandler& AliDielectronBtoJPSItoEleCDFfitHandler::operator=(const AliDielectronBtoJPSItoEleCDFfitHandler& c)
100 {
101         //
102         // Assignment operator
103         //
104         if (this!=&c) {
105                 fIsParamFixed = c.fIsParamFixed;
106                 fPrintStatus  = c.fPrintStatus;
107                 fUp           = c.fUp;
108                 fX            = c.fX;
109                 fM            = c.fM;
110                 fLikely       = c.fLikely;
111                 fNcand        = c.fNcand;
112         }
113         return *this;
114 }
115
116 //_______________________________________________________________________________________
117 AliDielectronBtoJPSItoEleCDFfitHandler::AliDielectronBtoJPSItoEleCDFfitHandler(const AliDielectronBtoJPSItoEleCDFfitHandler& c) :
118         TNamed(c),
119         fIsParamFixed(c.fIsParamFixed),
120         fPrintStatus(c.fPrintStatus),
121         fUp(c.fUp),
122         fX(c.fX),
123         fM(c.fM),
124         fLikely(c.fLikely),
125         fNcand(c.fNcand)
126 {
127         //
128         // Copy Constructor
129         //
130 }
131 //_______________________________________________________________________________________
132 AliDielectronBtoJPSItoEleCDFfitHandler::~AliDielectronBtoJPSItoEleCDFfitHandler()
133 {
134         //
135         //destructor
136         //
137         delete fLikely;
138 }
139 //_______________________________________________________________________________________
140 Int_t AliDielectronBtoJPSItoEleCDFfitHandler::DoMinimization()
141 {
142         //
143         // performs the minimization
144         //
145         static TVirtualFitter *fitter = TVirtualFitter::Fitter(this,20);
146         fitter->SetFCN(CDFFunction);
147
148         fitter->SetParameter(0,"fWeightRes",fParamStartValues[0], 1.e-08, 0., 1.e+06);
149         fitter->SetParameter(1,"fPos",fParamStartValues[1], 1.e-08, 0.,1.e+06);
150         fitter->SetParameter(2,"fNeg",fParamStartValues[2], 1.e-08, 0.,1.e+06);
151         fitter->SetParameter(3,"fSym",fParamStartValues[3], 1.e-08, 0.,1.e+06);
152         fitter->SetParameter(4,"fOneOvLamPlus",fParamStartValues[4], 1.e-10, 0.0000001, 5.e+01);
153         fitter->SetParameter(5,"fOneOvLamMinus",fParamStartValues[5], 1.e-10, 0.00000001, 5.e+01);
154         fitter->SetParameter(6,"fOneOvLamSym",fParamStartValues[6], 1.e-10, 0.00000001, 5.e+01);
155         fitter->SetParameter(7,"fB",fParamStartValues[7], 1.e-10, 0., 1.);
156         fitter->SetParameter(8,"fFsig",fParamStartValues[8], 1.e-10, 0., 1.);
157         fitter->SetParameter(9,"fMmean",fParamStartValues[9], 1.e-08, 0., 1.e+04);
158         fitter->SetParameter(10,"fNexp",fParamStartValues[10], 1.e-08, 0., 1.e+02);
159         fitter->SetParameter(11,"fSigma",fParamStartValues[11], 1.e-08, 0., 1.e+04);
160         fitter->SetParameter(12,"fAlpha",fParamStartValues[12], 1.e-08, 0., 1.e+04);
161         fitter->SetParameter(13,"fNorm",fParamStartValues[13], 1.e-08, 0., 1.e+04);
162         fitter->SetParameter(14,"fBkgNorm",fParamStartValues[14], 1.e-08, 0., 1.e+04);
163         fitter->SetParameter(15,"fBkgMean",fParamStartValues[15], 1.e-08, 0., 1.e+04);
164         fitter->SetParameter(16,"fBkgSlope",fParamStartValues[16], 1.e-08, 0., 1.e+04);
165         fitter->SetParameter(17,"fBkgSlope",fParamStartValues[17], 1.e-08, 0., 1.e+04);
166         fitter->SetParameter(18,"fNormGaus1",fParamStartValues[18], 1.e-08, 0., 1.e+05);
167         fitter->SetParameter(19,"fNormGaus2",fParamStartValues[19], 1.e-08, 0., 1.e+05); 
168
169         for(UInt_t indexparam = 0; indexparam < 20; indexparam++){
170                 if(IsParamFixed(indexparam))fitter->FixParameter((Int_t)indexparam);
171         }
172
173         Double_t arglist[2]={10000,1.0}; 
174         Int_t iret=fitter->ExecuteCommand("MIGRAD", arglist ,2);
175         fitter->PrintResults(4,0);
176
177         AliInfo("Minimization procedure finished\n");
178
179         return iret;
180 }
181 //_______________________________________________________________________________________
182 void AliDielectronBtoJPSItoEleCDFfitHandler::CdfFCN(Int_t & /* npar */, 
183                 Double_t * /* gin */,Double_t &f,Double_t *par,Int_t /* iflag */)
184 {
185         // 
186         // Definition of the FCN to be used by minuit
187         //
188         fLikely->SetAllParameters(par);
189         fLikely->ComputeMassIntegral();
190         if(fPrintStatus)fLikely->PrintStatus();
191
192         TStopwatch t;
193         t.Start();
194
195         f = fLikely->EvaluateLikelihood(fX,fM,fNcand);
196
197         t.Stop();
198         AliDebug(2,Form("Real time spent to calculate function == %f \n", t.RealTime()));
199         AliDebug(2,Form("CPU time spent to calculate function == %f \n", t.CpuTime()));
200         AliDebug(2,Form("Actual value of the AliDielectronBtoJPSItoEleCDFfitFCN function == %f \n", f));
201
202         return;
203 }
204 //_______________________________________________________________________________________
205 void AliDielectronBtoJPSItoEleCDFfitHandler::SetParamStartValues(Double_t inputparamvalues[20])
206 {
207         for(Int_t index=0; index < 20; index++) fParamStartValues[index] = inputparamvalues[index];
208 }
209 //_______________________________________________________________________________________
210 void AliDielectronBtoJPSItoEleCDFfitHandler::SetResolutionConstants(Double_t* resolutionConst)
211 {
212         //
213         // Sets constants for the resolution function
214         //
215         fLikely->SetResolutionConstants(resolutionConst);
216
217 }
218 //_______________________________________________________________________________________
219 void AliDielectronBtoJPSItoEleCDFfitHandler::SetCrystalBallFunction(Bool_t okCB) 
220 {
221         //
222         // Sets the CB as the parametrization for the signal invariant mass spectrum 
223         // (otherwise Landau is chosen)
224         //
225         fLikely->SetCrystalBallFunction(okCB);
226 }
227 //_______________________________________________________________________________________
228 void AliDielectronBtoJPSItoEleCDFfitHandler::SetMassWndHigh(Double_t limit) 
229
230         //
231         // Sets upper limit for the invariant mass window (under J/PSI mass peak)
232         //
233         fLikely->SetMassWndHigh(limit);
234 }
235 //_______________________________________________________________________________________
236 void AliDielectronBtoJPSItoEleCDFfitHandler::SetMassWndLow(Double_t limit)
237 {
238         //
239         // Sets lower limit for the invariant mass window (under J/PSI mass peak)
240         //
241         fLikely->SetMassWndLow(limit);
242 }
243