13 #include "dFitter3d.h"
30 void gfcn(Int_t &nParamters, Double_t *gin, Double_t &finalChi2, Double_t *parameterSet, Int_t iflag)
33 dummy->mfcn(nParamters, gin, finalChi2 , parameterSet, iflag) ;
38 dFitter3d::dFitter3d(TMinuit* gMinuit,TH3D* numerator, TH3D* denominator, TString opt , TString opt2)
44 mNumerator = numerator ;
45 mDenominator = denominator ;
50 mCorrFctnType =
"ykp" ;
51 cout <<
"Fitting function set to Yano Koonin Podgoretskii. \n" ;
53 else if ( opt ==
"bp" )
55 mCorrFctnType =
"bp" ;
56 cout <<
"Fitting function set to Bertsch Pratt. \n" ;
60 mCorrFctnType =
"ykp" ;
61 cout <<
"Bad option : fitting function set to Yano Koonin Podgoretskii. \n" ;
68 cout <<
"Using chi2.\n" ;
70 else if ( opt2 ==
"mml" )
73 cout <<
"Using mml.\n" ;
78 cout <<
"Bad option : Using chi2 method.\n" ;
83 mhc = 0.197326960277 ;
84 mhc2 = 0.038937929230 ;
87 mThresholdNumerator = 1.0 ;
88 mThresholdDenominator = 1.0 ;
91 dFitter3d::~dFitter3d()
96 void dFitter3d::FillInternalArrays()
99 cout <<
" Filling internal arrays with norm factor : " << mNorm
100 <<
" numerator threshold : " << mThresholdNumerator
101 <<
" denominator threshold : " << mThresholdDenominator << endl ;
105 int maximumInternalArraySize = (mNumerator->GetNbinsX()+2) * (mNumerator->GetNbinsY()+2) * (mNumerator->GetNbinsZ()+2) ;
106 if ( maximumInternalArraySize != (mDenominator->GetNbinsX()+2) * (mDenominator->GetNbinsY()+2) * (mDenominator->GetNbinsZ()+2) )
107 std::cerr <<
"Warning : different histogram sizes in numerator and denominator\n " ;
110 mNumeratorInternalArray =
new double[maximumInternalArraySize] ;
111 mDenominatorInternalArray =
new double[maximumInternalArraySize] ;
112 mErrorInternalArray =
new double[maximumInternalArraySize] ;
113 mVariablePositionArray =
new TVector3[maximumInternalArraySize] ;
116 mInternalArraySize = 0 ;
119 for (
int index = 0 ; index < maximumInternalArraySize ; index++)
121 if ( mNumerator->GetBinContent(index) > mThresholdNumerator && mDenominator->GetBinContent(index) > mThresholdDenominator )
127 Bin1ToBin3(mNumerator, index, binX, binY, binZ) ;
128 double qx = mNumerator->GetXaxis()->GetBinCenter(binX) ;
129 double qy = mNumerator->GetYaxis()->GetBinCenter(binY) ;
130 double qz = mNumerator->GetZaxis()->GetBinCenter(binZ) ;
132 if ( qx*qx+qy*qy+qz*qz < mSphereLimit )
138 double num = mNumerator->GetBinContent(index) ;
139 double denom = mDenominator->GetBinContent(index) ;
141 mNumeratorInternalArray[mInternalArraySize] = num ;
143 mDenominatorInternalArray[mInternalArraySize] = denom * mNorm ;
146 double error = num/(denom*mNorm) * ::sqrt( (1/num) + (1/denom) ) ;
147 mErrorInternalArray[mInternalArraySize] = error ;
149 mVariablePositionArray[mInternalArraySize].SetX(qx) ;
150 mVariablePositionArray[mInternalArraySize].SetY(qy) ;
151 mVariablePositionArray[mInternalArraySize].SetZ(qz) ;
156 cout << (double) num <<
"\t" << (
double) (denom*mNorm) ;
157 cout <<
"\t" << (double) (num/(denom*mNorm)) ;
158 double xx = mNumerator->GetXaxis()->GetBinCenter(binX) ;
159 double yy = mNumerator->GetYaxis()->GetBinCenter(binY) ;
160 double zz = mNumerator->GetZaxis()->GetBinCenter(binZ) ;
161 cout <<
"xa " << xx <<
"\t" << binX <<
"\t" ;
162 cout <<
"ya " << yy <<
"\t" << binY <<
"\t" ;
163 cout <<
"za " << zz <<
"\t" << binZ << endl ;
167 mInternalArraySize++ ;
172 cout <<
"Internal array size :" << mInternalArraySize << endl ;
175 void dFitter3d::mfcn(Int_t &nParameters, Double_t *gin, Double_t &finalChi2, Double_t *parameterSet, Int_t iflag)
177 if ( mFitMethod ==
"chi2")
179 fcnChi2(nParameters,gin,finalChi2,parameterSet,iflag) ;
181 else if ( mFitMethod ==
"mml")
183 fcnMml(nParameters,gin,finalChi2,parameterSet,iflag) ;
187 void dFitter3d::fcnChi2(Int_t &nParameters, Double_t *gin, Double_t &finalChi2, Double_t *parameterSet, Int_t iflag)
195 for (Int_t index = 0 ; index < mInternalArraySize ; index++)
198 double theoreticalValue = mCorrelationFunction( mVariablePositionArray[index] , parameterSet) ;
200 double delta = (mNumeratorInternalArray[index]/mDenominatorInternalArray[index]-theoreticalValue)/mErrorInternalArray[index];
206 if(countMinuitCalls == 100 && index%10000==0)
208 cout <<
"ql : " << mVariablePositionArray[index].x() <<
"\t"
209 <<
"qp : " << mVariablePositionArray[index].y() <<
"\t"
210 <<
"q0 : " << mVariablePositionArray[index].z()<<
"\t"
211 <<
"thval: " << theoreticalValue <<
"\t"
212 <<
"mes " << mNumeratorInternalArray[index]/mDenominatorInternalArray[index] <<
"\t"
213 <<
"num: " << mNumeratorInternalArray[index] <<
"\t"
214 <<
"th-mea" << fabs( mNumeratorInternalArray[index]/mDenominatorInternalArray[index] - theoreticalValue) <<
"\t"
215 <<
"err " << mErrorInternalArray[index] << endl ;
227 void dFitter3d::fcnMml(Int_t &nParameters, Double_t *gin, Double_t &finalMLH, Double_t *parameterSet, Int_t iflag)
241 for (Int_t index = 0 ; index < mInternalArraySize ; index++)
244 double expectedValue = mCorrelationFunction( mVariablePositionArray[index] , parameterSet) * mDenominatorInternalArray[index] ;
246 double measueredValue = mNumeratorInternalArray[index] ;
248 MLH += -expectedValue + measueredValue * ::log(expectedValue) - lnfactorial(measueredValue) ;
257 double dFitter3d::lnfactorial(
double arg)
261 int iarg = (int) arg ;
264 for (
int index = 1; index < iarg+1 ; index++)
265 { fac *=(double)index; } ;
271 fac = 0.91 + (iarg+0.5) * ::log(
double(iarg)) - iarg ;
277 double dFitter3d::mCorrelationFunction(TVector3& position,
double* parameterSet )
279 if ( mCorrFctnType ==
"ykp")
281 return ykpCorrelationFunction( position, parameterSet ) ;
283 else if ( mCorrFctnType ==
"bp")
285 return bpCorrelationFunction( position, parameterSet ) ;
290 cout <<
"this should never happen.\n " ;
295 double dFitter3d::ykpCorrelationFunction(TVector3& position,
double* parameterSet )
307 double gamma2 = 1.0/fabs(1.0-::pow(parameterSet[4],2)) ;
308 double mhcc = 0.038937929230 ;
309 double c2 = 1.0 + parameterSet[0] * TMath::Exp(
311 (-1.0) * ::pow(position.y(),2) * ::pow(parameterSet[2],2)
312 - gamma2 * ::pow((position.x() - parameterSet[4]*position.z()),2) * ::pow(parameterSet[1],2)
313 - gamma2 * ::pow((position.z() - parameterSet[4]*position.x()),2) * ::pow(parameterSet[3],2)
319 double dFitter3d::bpCorrelationFunction(TVector3& position,
double* parameterSet )
331 double c2 = 1.0 + parameterSet[0] * TMath::Exp(
333 (-1.0) * ::pow(position.y(),2) * ::pow(parameterSet[1],2)
334 - ::pow(position.z(),2) * ::pow(parameterSet[2],2)
335 - ::pow(position.x(),2) * ::pow(parameterSet[3],2)
336 - 2* position.x() * position.z() * ::pow(parameterSet[4],2)
342 void dFitter3d::doFit()
348 if ( mCorrFctnType ==
"ykp")
351 double startValues[5] = { 0.2 , 5.0 , 7.0 , 6.0 , 0.5} ;
353 double stepSize[5] = {0.1 ,0.1, 0.1 ,0.1 ,0.1 };
355 mMinuit->mnparm(0,
"lambda", startValues[0], stepSize[0], 0,0,ierflg);
356 mMinuit->mnparm(1,
"Rlong", startValues[1], stepSize[1], 0,0,ierflg);
357 mMinuit->mnparm(2,
"Rperp", startValues[2], stepSize[2], 0,0,ierflg);
358 mMinuit->mnparm(3,
"Rnull", startValues[3], stepSize[3], 0,0,ierflg);
359 mMinuit->mnparm(4,
"beta", startValues[4], stepSize[4], 0,0,ierflg);
361 else if ( mCorrFctnType ==
"bp")
364 double startValues[5] = { 0.5 , 6.0 , 6.0 , 6.0 , 6.0} ;
366 double stepSize[5] = {0.1 ,0.1, 0.1 ,0.1 ,0.1 };
368 mMinuit->mnparm(0,
"lambda", startValues[0], stepSize[0], 0,0,ierflg);
369 mMinuit->mnparm(1,
"Rside", startValues[1], stepSize[1], 0,0,ierflg);
370 mMinuit->mnparm(2,
"Rout", startValues[2], stepSize[2], 0,0,ierflg);
371 mMinuit->mnparm(3,
"Rlong", startValues[3], stepSize[3], 0,0,ierflg);
372 mMinuit->mnparm(4,
"Routlong", startValues[4], stepSize[4], 0,0,ierflg);
377 cout <<
"this should never happen.\n " ;
383 mMinuit->SetObjectFit(
this) ;
384 mMinuit->SetFCN(gfcn) ;
404 arglist[0] = 0; mMinuit->mnexcm(
"MIGRATE", arglist ,0,ierflg) ;
429 cout <<
"Number of to Minuit calls : " << countMinuitCalls << endl ;
433 void dFitter3d::SetHistos(TH3D* numerator, TH3D* denominator)
436 mNumerator = numerator ;
437 mDenominator = denominator ;
440 mRatio = (TH3D*) numerator->Clone() ;
442 mRatio->Divide(numerator,denominator,1.0,mNorm) ;
445 void dFitter3d::Bin1ToBin3(TH3D* histo,
int bin,
int& binx,
int& biny,
int& binz)
450 int nbbinX = (histo->GetNbinsX()) + 2 ;
451 int nbbinY = (histo->GetNbinsY()) + 2 ;
454 biny = (bin/nbbinX) % nbbinY ;
455 binz = (bin/nbbinX) / nbbinY ;
459 void dFitter3d::setCorrFctn(TString opt)
464 void dFitter3d::setFitMethod(TString opt2)
467 if ( opt2 ==
"chi2" )
469 mFitMethod =
"chi2" ;
470 cout <<
"Using chi2.\n" ;
472 else if ( opt2 ==
"mml" )
475 cout <<
"Using mml.\n" ;
479 mFitMethod =
"chi2" ;
480 cout <<
"Bad option : Using chi2 method.\n" ;