]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/vertexingHF/AliBtoJPSItoEleCDFfitHandler.cxx
New set of classes for B->J/psi->ee analysis and fit a la CDF (Carmelo, Giuseppe)
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliBtoJPSItoEleCDFfitHandler.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 "AliBtoJPSItoEleCDFfitHandler.h"
19 #include "AliBtoJPSItoEleCDFfitFCN.h"
20
21 //-------------------------------------------------------------------------
22 //                      Class AliBtoJPSItoEleCDFfitHandler
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(AliBtoJPSItoEleCDFfitHandler)
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   AliBtoJPSItoEleCDFfitHandler* dummy = (AliBtoJPSItoEleCDFfitHandler *)TVirtualFitter::GetFitter()->GetObjectFit();
40   dummy->CdfFCN(npar, gin, f, par, iflag);
41 }
42
43
44 //_________________________________________________________________________________________________
45 AliBtoJPSItoEleCDFfitHandler::AliBtoJPSItoEleCDFfitHandler():
46 fUp(0),
47 fX(0x0),
48 fM(0x0),
49 fLikely(0x0),
50 fNcand(0)
51 {
52   //
53   // default constructor
54   //
55 }
56 //_________________________________________________________________________________________________
57 AliBtoJPSItoEleCDFfitHandler::AliBtoJPSItoEleCDFfitHandler(Double_t* decaytime, 
58   Double_t* invariantmass, Int_t ncand) :
59 fUp(0),
60 fX(decaytime),
61 fM(invariantmass),
62 fLikely(0x0),
63 fNcand(ncand)
64 {
65   //
66   // constructor
67   //
68   AliInfo("\n+++\n+++ Minimization object AliBtoJPSItoEleCDFfitHandler created\n+++\n");
69   AliInfo("\n+++\n+++ Creating AliBtoJPSItoEleCDFfitFCN object\n+++\n");
70   fLikely = new AliBtoJPSItoEleCDFfitFCN();
71   fLikely->SetCrystalBallParam(kFALSE); //Landau selected; otherwise Crystal Ball is selected
72   SetErrorDef(1.);
73   AliInfo(Form("\n+++\n+++ Number of candidates ---> %d\n+++\n ", ncand));
74 }
75 //___________________________________________________________________________
76 AliBtoJPSItoEleCDFfitHandler& AliBtoJPSItoEleCDFfitHandler::operator=(const AliBtoJPSItoEleCDFfitHandler& c)
77 {
78   //
79   // Assignment operator
80   //
81   if (this!=&c) {
82       fUp     = c.fUp;
83       fX      = c.fX;
84       fM      = c.fM;
85       fLikely = c.fLikely;
86       fNcand = c.fNcand;
87      }
88   return *this;
89 }
90
91 //___________________________________________________________________________
92 AliBtoJPSItoEleCDFfitHandler::AliBtoJPSItoEleCDFfitHandler(const AliBtoJPSItoEleCDFfitHandler& c) :
93 TNamed(c),
94 fUp(c.fUp),
95 fX(c.fX),
96 fM(c.fM),
97 fLikely(c.fLikely),
98 fNcand(c.fNcand)
99 {
100   //
101   // Copy Constructor
102   //
103 }
104 //________________________________________________________________________
105 AliBtoJPSItoEleCDFfitHandler::~AliBtoJPSItoEleCDFfitHandler()
106 {
107   //
108   //destructor
109   //
110   delete fLikely;
111 }
112 //_________________________________________________________________________________________________
113 Int_t AliBtoJPSItoEleCDFfitHandler::DoMinimization()
114 {
115   //
116   // performs the minimization
117   //
118   static TVirtualFitter *fitter = TVirtualFitter::Fitter(this,13);
119   fitter->SetFCN(CDFFunction);
120   Double_t startingParamValues[13] =
121          /* startfPlus
122             startfMinus
123             startfSym
124             startfOneOvLamPlus
125             startfOneOvLamMinus
126             startfOneOvLamSym
127             startfMSlope
128             startfB
129             startfFsig
130             startfMmean
131             startfNexp
132             startfSigma
133             startfAlpha */
134             {5.00e-01,
135              TMath::Pi()/4.,
136              TMath::Pi()/4.,
137              2.0964360e-03,
138              4.8309180e-03,
139              1.582530e-04,
140              -1.5720e-02,
141              0.1800e+00,
142              0.7000e+00,
143             3.0910e+00,
144              1.0500e+00,
145              1.4250e-02,
146              6.758e-01};
147
148   fitter->SetParameter(0,"fRadius",startingParamValues[0], 0.01, 0., 1.);
149   fitter->SetParameter(1,"fTheta",startingParamValues[1], 0.001, 0., TMath::Pi()/2);
150   fitter->SetParameter(2,"fPhi",startingParamValues[2], 0.001, 0., TMath::Pi()/2);
151   fitter->SetParameter(3,"fOneOvLamPlus",startingParamValues[3], 0.0001, 0., 5.e-01);
152   fitter->SetParameter(4,"fOneOvLamMinus",startingParamValues[4], 0.0001, 0., 5.e-01);
153   fitter->SetParameter(5,"fOneOvLamSym",startingParamValues[5], 0.00001, 0., 5.e-01);
154   fitter->SetParameter(6,"fMSlope",startingParamValues[6], 0.001, -1.e-00, 1.e+00);
155   fitter->SetParameter(7,"fB",startingParamValues[7], 0.1, 0., 1.);
156   fitter->SetParameter(8,"fFsig",startingParamValues[8], 0.1, 0., 1.);
157   fitter->SetParameter(9,"fMmean",startingParamValues[9], 0.1, 0., 1.e+02);
158   fitter->SetParameter(10,"fNexp",startingParamValues[10], 0.1, 0., 1.e+02);
159   fitter->SetParameter(11,"fSigma",startingParamValues[11], 0.001, 0., 1.e+02);
160   fitter->SetParameter(12,"fAlpha",startingParamValues[12], 0.01, 0., 1.e+02);
161   fitter->FixParameter(9);
162
163   Double_t arglist[2]={10000,0.5}; 
164   Int_t iret=fitter->ExecuteCommand("MIGRAD", arglist ,2);
165   fitter->PrintResults(4,0);
166
167   AliInfo("Minimization procedure finished\n");
168
169   return iret;
170 }
171 //_______________________________________________________________________________________
172 void AliBtoJPSItoEleCDFfitHandler::CdfFCN(Int_t & /* npar */, 
173               Double_t * /* gin */,Double_t &f,Double_t *par,Int_t /* iflag */)
174 {
175 // 
176 // Definition of the FCN to be used by minuit
177 //
178   fLikely->SetAllParameters(par);
179   fLikely->ConvertFromSpherical();
180   fLikely->ComputeIntegral();
181   //printf("\n+++\n+++\n+++\n");
182   //fLikely->PrintStatus();
183
184   TStopwatch t;
185   t.Start();
186
187   f = fLikely->EvaluateLikelihood(fX,fM,fNcand);
188
189   t.Stop();
190   AliDebug(2,Form("Real time spent to calculate function == %f \n", t.RealTime()));
191   AliDebug(2,Form("CPU time spent to calculate function == %f \n", t.CpuTime()));
192   AliDebug(2,Form("Actual value of the AliBtoJPSItoEleCDFfitFCN function == %f \n", f));
193
194   return;
195 }