00001 #include "StHbtMaker/CorrFctn/QinvEbyECorrFctn.h"
00002 #include <cstdio>
00003
00004 #ifdef __ROOT__
00005 ClassImp(QinvEbyECorrFctn)
00006 #endif
00007
00008 QinvEbyECorrFctn::QinvEbyECorrFctn(char* title, const int& nbins, const float& QinvLo, const float& QinvHi){
00009
00010
00011 char TitNum[100] = "Num";
00012 strcat(TitNum,title);
00013 mNumerator = new StHbt1DHisto(TitNum,title,nbins,QinvLo,QinvHi);
00014
00015
00016 char TitDen[100] = "Den";
00017 strcat(TitDen,title);
00018 mDenominator = new StHbt1DHisto(TitDen,title,nbins,QinvLo,QinvHi);
00019
00020
00021 char TitRat[100] = "Rat";
00022 strcat(TitRat,title);
00023 mRatio = new StHbt1DHisto(TitRat,title,nbins,QinvLo,QinvHi);
00024
00025
00026 mNumerator->SetDirectory(0);
00027 mDenominator->SetDirectory(0);
00028 mRatio->SetDirectory(0);
00029
00030 mCorrection = 0;
00031
00032
00033
00034 char TitIntNum[100] = "IntNum";
00035 strcat(TitIntNum,title);
00036 mIntNumerator = new StHbt1DHisto(TitIntNum,title,nbins,QinvLo,QinvHi);
00037
00038 char TitIntDen[100] = "IntDen";
00039 strcat(TitIntDen,title);
00040 mIntDenominator = new StHbt1DHisto(TitIntDen,title,nbins,QinvLo,QinvHi);
00041
00042 char TitIntRat[100] = "IntRat";
00043 strcat(TitIntRat,title);
00044 mIntRatio = new StHbt1DHisto(TitIntRat,title,nbins,QinvLo,QinvHi);
00045
00046
00047
00048 mThreeFitLambda = new StHbt1DHisto("ThreeFitLambda","ThreeFitLambda",100,0,2);
00049 mThreeFitRadius = new StHbt1DHisto("ThreeFitRadius","ThreeFitRadius",100,0,50);
00050 mTwoFitLambda = new StHbt1DHisto("TwoFitLambda","TwoFitLambda",100,0,2);
00051 mTwoFitRadius = new StHbt1DHisto("TwoFitRadius","TwoFitRadius",100,0,50);
00052 mRmsByHandMeV = new StHbt1DHisto("RmsByHandMeV","RmsByHandMeV",100,0.0,0.2);
00053 mRmsByHandFm = new StHbt1DHisto("RmsByHandFm","RmsByHandFm",100,0,20);
00054 mThreeFitLambda->SetDirectory(0);
00055 mThreeFitRadius->SetDirectory(0);
00056 mTwoFitLambda->SetDirectory(0);
00057 mTwoFitRadius->SetDirectory(0);
00058 mRmsByHandMeV->SetDirectory(0);
00059 mRmsByHandFm->SetDirectory(0);
00060
00061
00062 m_Debug_ebye = 1 ;
00063
00064
00065 mNumerator->Sumw2();
00066 mDenominator->Sumw2();
00067 mRatio->Sumw2();
00068
00069
00070 }
00071
00072
00073 QinvEbyECorrFctn::~QinvEbyECorrFctn(){
00074 delete mThreeFitLambda;
00075 delete mThreeFitRadius;
00076 delete mTwoFitLambda;
00077 delete mTwoFitRadius;
00078 delete mRmsByHandMeV;
00079 delete mRmsByHandFm;
00080 delete mNumerator;
00081 delete mDenominator;
00082 delete mRatio;
00083 delete mIntNumerator;
00084 delete mIntDenominator;
00085 delete mIntRatio;
00086 if (mCorrection) delete mCorrection;
00087 }
00088
00089 void QinvEbyECorrFctn::Finish(){
00090
00091 mIntRatio->Divide(mIntNumerator,mIntDenominator,1.0,1.0) ;
00092
00093
00094 threeFit fit3 = { 0,0,0,0,0,0,0,0 };
00095 Three_param_fit( fit3 , mRatio);
00096 cout << " Inclusive fit : " << fit3.radius << endl ;
00097 }
00098
00099
00100 StHbtString QinvEbyECorrFctn::Report(){
00101 string stemp = "Qinv Correlation Function Report:\n";
00102 char ctemp[100];
00103 sprintf(ctemp,"Number of entries in numerator:\t%E\n",mNumerator->GetEntries());
00104 stemp += ctemp;
00105 sprintf(ctemp,"Number of entries in denominator:\t%E\n",mDenominator->GetEntries());
00106 stemp += ctemp;
00107 sprintf(ctemp,"Number of entries in ratio:\t%E\n",mRatio->GetEntries());
00108 stemp += ctemp;
00109
00110 StHbtString returnThis = stemp;
00111 return returnThis;
00112 }
00113
00114 void QinvEbyECorrFctn::AddRealPair(const StHbtPair* pair){
00115 mNumerator->Fill( fabs(pair->qInv()) );
00116 }
00117
00118 void QinvEbyECorrFctn::AddMixedPair(const StHbtPair* pair){
00119 mDenominator->Fill( fabs(pair->qInv()) );
00120 }
00121
00122 void QinvEbyECorrFctn::SetCorrection(const StHbt1DHisto* correc){
00123 mCorrection = (StHbt1DHisto*)correc;
00124 }
00125
00126 void QinvEbyECorrFctn::EventBegin(const StHbtEvent* myev)
00127 {
00128
00129 mNumerator->Reset();
00130 mDenominator->Reset();
00131 mRatio->Reset();
00132 }
00133
00134 void QinvEbyECorrFctn::EventEnd(const StHbtEvent* myev)
00135 {
00136
00137
00138 if (mDenominator->GetEntries() == 0) return ;
00139 if (m_Debug_ebye)
00140 {
00141 cout << "Start ebye." << endl ;
00142 }
00143
00144
00145 mRatio->Divide(mNumerator,mDenominator,1.0,1.0) ;
00146
00147
00148
00149
00150 cout << "Scale ratio by (integral method) : " << Norm_by_integral(0.1,0.2) << endl ;
00151 mRatio->Scale(Norm_by_integral(0.1,0.2)) ;
00152
00153
00154 if (mCorrection){
00155 cout << "Going to Coulomb correct now..." << endl;
00156 mRatio->Divide(mCorrection);
00157 }
00158 else {
00159 cout << "NOT Coulomb correcting..." << endl;
00160 }
00161
00162
00163 mIntNumerator->Add(mNumerator);
00164 mIntDenominator->Add(mDenominator);
00165
00166
00167
00168 double Width_MeV = 0 ;
00169 double Width_fm = 0 ;
00170 Rms_by_hand(Width_MeV, Width_fm) ;
00171 mRmsByHandMeV->Fill(Width_MeV) ;
00172 mRmsByHandFm->Fill(Width_fm) ;
00173
00174
00175 twoFit fit2 = { 0.,0.,0.,0., 0., 0. };
00176 Two_param_fit( fit2 );
00177 mTwoFitLambda->Fill( fit2.lambda);
00178 mTwoFitRadius->Fill( fit2.radius);
00179
00180
00181 mRatio->Reset();
00182 mRatio->Divide(mNumerator,mDenominator,1.0,1.0) ;
00183
00184 if (mCorrection){
00185 cout << "Going to Coulomb correct now for the 3 Fit ..." << endl;
00186 mRatio->Divide(mCorrection);
00187 }
00188 else {
00189 cout << "NOT Coulomb correcting for the 3 Fit ..." << endl;
00190 }
00191 threeFit fit3 = { 0.2,0.0,0.5,0.0,10.,0., 0., 0. };
00192 Three_param_fit( fit3 , mRatio);
00193 mThreeFitLambda->Fill( (fit3.lambda*1/(fit3.constant+0.000001)) );
00194 mThreeFitRadius->Fill( fit3.radius );
00195
00196
00197 if (m_Debug_ebye)
00198 {
00199
00200 if (mCorrection){
00201 cout << "Going to Coulomb correct a second time just to see it ..." << endl;
00202 mRatio->Divide(mCorrection);
00203 }
00204 else {
00205 cout << "NOT Coulomb correcting..." << endl;
00206 }
00207
00208 cout << endl << endl ;
00209 cout << " twoFit: ";
00210 cout << " lambda=" << fit2.lambda << " radius=" << fit2.radius << endl;
00211 cout << " threeFit: ";
00212 cout << " lambda=" << (fit3.lambda/(fit3.constant+0.000001)) << " radius=" << fit3.radius ;
00213 cout <<" constant :" << fit3.constant << endl;
00214 cout << " RmsByHand ";
00215 cout << " Width MeV " << Width_MeV << " Width FM " << Width_fm << endl;
00216 double norm3=0;
00217 if (fit3.constant!=0) norm3 = 1/(fit3.constant) ;
00218
00219 cout << " Norm by integ : " << Norm_by_integral(0.1,0.2) << endl;
00220 cout << " Norm by line fit : " << Norm_by_fit(0.1,0.2) << endl;
00221 cout << " Norm by 3d fit : " << norm3 << endl;
00222
00223 cout << " Scaled by : " << Norm_by_integral(0.1,0.2) << endl;
00224 cout << endl << endl ;
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 } ;
00242
00243 void QinvEbyECorrFctn::Three_param_fit( threeFit& fit , StHbt1DHisto* histo ) {
00244
00245
00246
00247 StHbtTF1* f3param = new StHbtTF1("f3param","[0]+[1]*exp(- (x**2) * ([2]**2) / (0.197327**2))",0.0,0.2) ;
00248 f3param->SetParNames("Normfactor","Lambda","Rinv") ;
00249 f3param->SetParameters(0.2,0.5,10) ;
00250 histo->Fit("f3param","R0") ;
00251
00252
00253 fit.constant = histo->GetFunction("f3param")->GetParameter(0);
00254 fit.lambda = histo->GetFunction("f3param")->GetParameter(1);
00255 fit.radius = histo->GetFunction("f3param")->GetParameter(2);
00256 fit.constantErr = histo->GetFunction("f3param")->GetParError(0);
00257 fit.lambdaErr = histo->GetFunction("f3param")->GetParError(1);
00258 fit.radiusErr = histo->GetFunction("f3param")->GetParError(2);
00259 fit.chi2 = histo->GetFunction("f3param")->GetChisquare();
00260 fit.ndf = histo->GetFunction("f3param")->GetNDF() ;
00261
00262
00263 delete f3param ;
00264 } ;
00265
00266 void QinvEbyECorrFctn::Two_param_fit(twoFit& fit) {
00267
00268
00269
00270 StHbtTF1* f2param = new StHbtTF1("f2param"," 1 + [0]*exp(- (x**2) * ([1]**2) / (0.197327**2))",0.0,0.2) ;
00271 f2param->SetParNames("Lambda","Rinv") ;
00272 f2param->SetParameters(0.5,10) ;
00273 mRatio->Fit("f2param","R0+") ;
00274
00275
00276 fit.lambda = mRatio->GetFunction("f2param")->GetParameter(0);
00277 fit.radius = mRatio->GetFunction("f2param")->GetParameter(1);
00278 fit.lambdaErr = mRatio->GetFunction("f2param")->GetParError(0);
00279 fit.radiusErr = mRatio->GetFunction("f2param")->GetParError(1);
00280 fit.chi2 = mRatio->GetFunction("f2param")->GetChisquare();
00281 fit.ndf = mRatio->GetFunction("f2param")->GetNDF() ;
00282
00283
00284 delete f2param ;
00285 } ;
00286
00287 void QinvEbyECorrFctn::Rms_by_hand(double& Width_MeV, double& Width_fm) {
00288
00289 double sum =0 ;
00290 double S_y =0 ;
00291
00292
00293 for(int hist_index=1; hist_index <= (int) mRatio->GetNbinsX() ; hist_index++)
00294 {
00295 double x = (double) (mRatio->GetBinCenter(hist_index)) ;
00296 double y = (double) (mRatio->GetBinContent(hist_index)) ;
00297 sum = sum + x * x * ( y -1 ) ;
00298 S_y = S_y + ( y -1 ) ;
00299 }
00300
00301
00302
00303 Width_MeV = ::sqrt(fabs(sum/(S_y))) ;
00304 Width_fm = 0.197327/Width_MeV ;
00305
00306 cout << "Rough rms calculation : " << (double) Width_MeV << "\t";
00307 cout << "Rough rms calculation : " << (double) Width_fm << endl ;
00308 }
00309
00310 void QinvEbyECorrFctn::Fill_ratio_artificial()
00311 {
00312
00313
00314 mRatio->Reset() ;
00315 double radius = 10 ;
00316 for(int i = 1 ; i < mRatio->GetNbinsX() ; i++)
00317 {
00318 double x = (double) (mRatio->GetBinCenter(i));
00319 double y = 1 + exp(-(x*x)*(radius*radius)/(0.2*0.2));
00320 mRatio->Fill(x,y) ;
00321
00322
00323 };
00324 };
00325
00326 void QinvEbyECorrFctn::Fill_ratio_artificial_random()
00327 {
00328
00329
00330 mRatio->Reset();
00331 double lam = rand()/RAND_MAX;
00332 double R = 1 + 10 * rand()/RAND_MAX;
00333 R =10 ; lam = 0.5 ;
00334 for(int i = 1 ; i < mRatio->GetNbinsX() ; i++)
00335 {
00336 double x = (double) (mRatio->GetBinCenter(i));
00337 double y = 1 + lam * exp(-(x*x)*(R*R)/(0.2*0.2));
00338 mRatio->Fill(x,y) ;
00339
00340
00341 } ;
00342 } ;
00343
00344 double QinvEbyECorrFctn::Norm_by_integral(double min_GeV = 0.1,double max_GeV = 0.2 )
00345 {
00346
00347 double norm = 0;
00348 int minbin = mDenominator->GetXaxis()->FindFixBin(min_GeV);
00349 int maxbin = mDenominator->GetXaxis()->FindFixBin(max_GeV);
00350 double numinteg = mNumerator->Integral(minbin,maxbin) ;
00351 double denominteg = mDenominator->Integral(minbin,maxbin) ;
00352
00353 if ( numinteg != 0 )
00354 {
00355 norm = denominteg / numinteg ;
00356
00357 }
00358 else
00359 {
00360 cout << "Cannot normlize, because denominator equals 0." << endl ;
00361 }
00362 return norm ;
00363 } ;
00364
00365 double QinvEbyECorrFctn::Norm_by_fit(double min_GeV = 0.1,double max_GeV = 0.2)
00366 {
00367
00368 StHbtTF1* line = new StHbtTF1("line","[0]+[1] * x",min_GeV,max_GeV) ;
00369 line->SetParameters(0.3,0.0) ;
00370 mRatio->Fit("line","QR0") ;
00371 if ( m_Debug_ebye )
00372 {
00373
00374 cout << "Fit result line fit, norm : " << mRatio->GetFunction("line")->GetParameter(0) << " " << mRatio->GetFunction("line")->GetParameter(1) << endl ;
00375 }
00376
00377 double norm = 0 ;
00378 double a = mRatio->GetFunction("line")->GetParameter(0) ;
00379 double b = mRatio->GetFunction("line")->GetParameter(1) ;
00380 double c = (max_GeV+min_GeV)/2 * b + a ;
00381 if ( c!= 0 )
00382 {
00383 norm = 1/c ;
00384 }
00385
00386
00387 delete line ;
00388 return norm ;
00389 } ;