00001
00002
00003
00004
00005 #include <vector>
00006 #include <utility>
00007 #include "finish.h"
00008 #include "common/Name.cc"
00009 #include "commonmacro/histutil.h"
00010
00011 char* inrootname="~/wrk/real/links/P01hi.minbias.2000.hist/hispectra_cut2100.hist.root";
00012 char* correctname="~/wrk/assoc/links/P01hi.central.HighpT_piminus_101.hist/momcorrection_cut2100.hist.root";
00013 char* bkgname = "~/afs/real/background_test.hist.root";
00014 char* outrootname="~/wrk/real/links/temp.hist/finish_test.root";
00015 char* textdir = "TEXT";
00016
00017 void finish(const char* inRootName=inrootname,
00018 const char* correctionName=correctname,
00019 const char* backgroundName=bkgname,
00020 const char* outRootName=outrootname,
00021 const char* textDir=textdir,
00022 int cut = 2100,
00023 int iter = 0)
00024 {
00025
00026 cout << "In file : " << inRootName << endl
00027 << "mom correct : " << correctionName << endl
00028 << "bkg : " << backgroundName << endl
00029 << "out file : " << outRootName << endl
00030 << "text dir : " << textDir << endl
00031 << "cut : " << cut << endl
00032 << "iter : " << iter << endl
00033 << "offset type : " << offSetType << endl
00034 << "fit high : " << fitHighPt << endl
00035 << "cor high : " << corHighPt << endl;
00036
00037 Int_t stat=0;
00038 int doMomCorrection = (iter>0);
00039
00040 gSystem->Load("StHiMicroAnalysis");
00041 Cut::SetCut(cut); Cut::ShowCuts();
00042
00043 char *trigger = "test";
00044
00045
00046
00047 initTextFiles(textDir,cut,iter);
00048
00049 *ofVal << ">>>>>>>>>>" << endl;
00050 *ofVal << "Doing momentum correction? " << doMomCorrection << endl;
00051 cout << ">>>>>>>>>>>" << endl;
00052 cout << "Doing momentum correction? " << doMomCorrection << endl;
00053
00054
00055
00056
00057 if(doMomCorrection) getCorrectionHistograms(correctionName);
00058
00059
00060
00061
00062
00063 getBackgroundHistograms(backgroundName);
00064
00065
00066
00067
00068
00069 getHistograms(inRootName);
00070
00071
00072
00073
00074 doBothChargeSigns();
00075
00076
00077
00078
00079 outRoot = new TFile(outRootName,"RECREATE");
00080
00081
00082
00083
00084 doCorrections();
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 initFit();
00096
00097 switch(offSetType){
00098 case 1:
00099 fitHistograms();
00100 doOffSetGraphs(1);
00101 break;
00102 case 2:
00103 doOffSetGraphs(2);
00104 break;
00105 default:
00106 cout << "wrong type"; return;
00107 }
00108
00109
00110
00111
00112 fitGraphs();
00113
00114
00115
00116
00117 doSpectraGraphs();
00118
00119
00120
00121
00122
00123
00124
00125
00126 if(1){
00127 writeHistograms(outRootName);
00128 }
00129
00130
00131
00132 }
00133
00134
00135 void initTextFiles(const char* textDir, int cut, int iter)
00136 {
00137
00138 sprintf(name,"%s/corValues_cut%d_iter%d.txt",textDir,cut,iter);
00139 cout << "correction values : " << name << endl;
00140 ofCor = new ofstream(name);
00141 if(!ofCor) { cout << "cannot create " << name << endl;}
00142
00143
00144
00145
00146 sprintf(name,"%s/values_cut%d_iter%d.txt",textDir,cut,iter);
00147 cout << "values : " << name << endl;
00148 ofVal = new ofstream(name);
00149
00150
00151
00152 }
00153
00154
00155
00156
00157 void getCorrectionHistograms(const char* correctionName)
00158 {
00159 cout << "\t**getCorrectionHistograms**" << endl;
00160
00161 Int_t stat = 0;;
00162
00163
00164
00165 TFile* corRoot = new TFile(correctionName);
00166
00167 if(!corRoot) return 1;
00168
00169 for(Int_t iBin=0; iBin<nVarBin; iBin++){
00170
00171 setName(name,"h1PtDCrRatio",iBin);
00172 correction[iBin].crip.h1PtDCrRatio = (TH1D*) corRoot->Get(name);
00173 if(!correction[iBin].crip.h1PtDCrRatio) {
00174 cout << "no " << name << endl; exit(1);
00175 }
00176 showHistogramValues(correction[iBin].crip.h1PtDCrRatio,
00177 "MOMENTUM CORRECTIONS");
00178
00179
00180 setName(name,"fCorrected",iBin);
00181 correction[iBin].crip.fCorrected = (TF1*)corRoot->Get(name);
00182 if(!correction[iBin].crip.fCorrected){
00183 cout << "no " << name << endl; exit(1);
00184 }
00185 for(Int_t iCharge=0; iCharge<2; iCharge++){
00186
00187 setName(name,"h1PtDCrRatio",iBin,sPM[iCharge].Data());
00188 correction[iBin].cripPM[iCharge].h1PtDCrRatio = (TH1D*)corRoot->Get(name);
00189 showHistogramValues(correction[iBin].cripPM[iCharge].h1PtDCrRatio,
00190 "MOMENTUM CORRECTIONS");
00191
00192 if(!correction[iBin].cripPM[iCharge].h1PtDCrRatio) {
00193 cout << "no " << name << endl; exit(1);
00194 }
00195 setName(name,"fCorrected",iBin,sPM[iCharge].Data());
00196 correction[iBin].cripPM[iCharge].fCorrected = (TF1*)corRoot->Get(name);
00197 if(!correction[iBin].cripPM[iCharge].fCorrected){
00198 cout << "no " << name << endl; exit(1);
00199 stat++;
00200 }
00201 }
00202
00203
00204 }
00205
00206
00207
00208
00209
00210 cout << "Momentum correction used weights ..." << endl;
00211
00212 for(Int_t iBin=0; iBin<nVarBin; iBin++){
00213 cout << "Bin " << iBin << endl;
00214 cout << "\tBoth charges"
00215 << "\tpt0="
00216 <<correction[iBin].crip.fCorrected->GetParameter(0)
00217 << "\t\tptPow="
00218 <<correction[iBin].crip.fCorrected->GetParameter(1)
00219 <<endl;
00220
00221 for(Int_t iCharge=0; iCharge<2; iCharge++){
00222 cout << "\t"<< sPM[iCharge].Data()
00223 << "\tpt0="
00224 <<correction[iBin].cripPM[iCharge].fCorrected->GetParameter(0)
00225 << "\t\tptPow="
00226 <<correction[iBin].cripPM[iCharge].fCorrected->GetParameter(1)
00227 <<endl;
00228
00229 }
00230 }
00231
00232 }
00233
00234
00235
00236
00237
00238 void getBackgroundHistograms(const char* backgroundName)
00239 {
00240 cout << "\t**getBackgroundHistograms()**" << endl;
00241
00242 TFile* bkgRoot = new TFile(backgroundName);
00243 Int_t stat = 0;
00244
00245
00246
00247 strcpy(name,"h1BackGround");
00248
00249 char* dcaType = "DcaGl";
00250
00251 for(int iBin=0; iBin<nVarBin; iBin++){
00252 setName(name,"h1Background",iBin);
00253 sprintf(name,"%s%s",name,dcaType);
00254 correction[iBin].bkg.h1Background=(TH1D*) bkgRoot->Get(name);
00255
00256 if(!correction[iBin].bkg.h1Background){
00257 cout << "Cannot find " << name << " in "
00258 << backgroundName << endl; exit(1);
00259 }
00260 showHistogramValues(correction[iBin].bkg.h1Background,"");
00261
00262 for(int ic=0; ic<2; ic++){
00263 setName(name,"h1Background",iBin,sPM[ic].Data());
00264 sprintf(name,"%s%s",name,dcaType);
00265 correction[iBin].bkgPM[ic].h1Background=(TH1D*) bkgRoot->Get(name);
00266
00267 if(!correction[iBin].bkg.h1Background){
00268 cout << "Cannot find " << name << " in "
00269 << backgroundName << endl; exit(1);
00270 }
00271 showHistogramValues(correction[iBin].bkgPM[ic].h1Background,"");
00272 }
00273 }
00274
00275 }
00276
00277
00278 void getHistograms(const char* inRootName)
00279 {
00280 cout <<"\t**getHistograms()**" << endl;
00281
00282
00283 TFile* inRoot = new TFile(inRootName);
00284 if(!inRoot || !inRoot->IsOpen()){
00285 cout << "cannot open " << inRootName << endl; exit(1);
00286 }
00287
00288
00289
00290 h1VertexZCut = (TH1D*)inRoot->Get("h1VertexZCut");
00291
00292
00293
00294 h1NEvent = (TH1D*) inRoot->Get("h1NEvent");
00295 h1EtaCut = (TH1D*) inRoot->Get("h1EtaCut");
00296
00297
00298 nEvent = h1NEvent->GetBinContent(1);
00299 etaCut[0] = h1EtaCut->GetBinContent(1);
00300 etaCut[1] = h1EtaCut->GetBinContent(2);
00301 scale = (1./nEvent)*(1./(etaCut[1]-etaCut[0]));
00302
00303 cout << "n event : " << nEvent << endl;
00304 cout << "eta cut : " << etaCut[0] << ", " << etaCut[1] << endl;
00305 cout << "scale : " << scale << endl;
00306
00307 *ofVal << "n event : " << nEvent << endl
00308 << "eta cut : " << etaCut[0] << ", " << etaCut[1] << endl
00309 << "scale : " << scale << endl;
00310
00311 for(Int_t iBin=0; iBin<nVarBin; iBin++){
00312
00313 setName(name,"h1OneOverPt",iBin);
00314 varBin[iBin].mean.h1OneOverPt = (TH1D*)inRoot->Get(name);
00315
00316 setName(name,"h1WeightedMean",iBin);
00317 varBin[iBin].mean.h1WeightedMean = (TH1D*)inRoot->Get(name);
00318
00319
00320
00321 setName(name,"h1Raw",iBin);
00322 varBin[iBin].spec.h1Raw = (TH1D*) inRoot->Get(name);
00323
00324 showHistogramValues(varBin[iBin].spec.h1Raw,"YIELDS");
00325
00326
00327
00328
00329 setName(name,"h1EffCorrected",iBin);
00330 varBin[iBin].spec.h1EffCorrected = (TH1D*) inRoot->Get(name);
00331 showHistogramValues(varBin[iBin].spec.h1EffCorrected,"YIELDS");
00332
00333
00334
00335
00336 setName(name,"h1Corrected",iBin);
00337 varBin[iBin].spec.h1Corrected = (TH1D*) inRoot->Get(name);
00338 showHistogramValues(varBin[iBin].spec.h1Corrected,"YIELDS");
00339
00340
00341
00342
00343 for(Int_t iCharge=0; iCharge<2; iCharge++){
00344
00345
00346
00347 setName(name,"h1OneOverPt",iBin,sPM[iCharge].Data());
00348 varBin[iBin].meanPM[iCharge].h1OneOverPt = (TH1D*)inRoot->Get(name);
00349
00350 setName(name,"h1WeightedMean",iBin,sPM[iCharge].Data());
00351 varBin[iBin].meanPM[iCharge].h1WeightedMean = (TH1D*)inRoot->Get(name);
00352
00353
00354
00355
00356 setName(name,"h1Raw",iBin,sPM[iCharge].Data());
00357 varBin[iBin].specPM[iCharge].h1Raw =
00358 (TH1D*) inRoot->Get(name);
00359 showHistogramValues(varBin[iBin].specPM[iCharge].h1Raw,"YIELDS");
00360
00361
00362
00363 setName(name,"h1EffCorrected",iBin,sPM[iCharge].Data());
00364 varBin[iBin].specPM[iCharge].h1EffCorrected =
00365 (TH1D*) inRoot->Get(name);
00366 showHistogramValues(varBin[iBin].specPM[iCharge].h1EffCorrected,"YIELDS");
00367
00368
00369
00370
00371 setName(name,"h1Corrected",iBin,sPM[iCharge].Data());
00372 varBin[iBin].specPM[iCharge].h1Corrected =
00373 (TH1D*) inRoot->Get(name);
00374 showHistogramValues(varBin[iBin].specPM[iCharge].h1Corrected,"YIELDS");
00375 }
00376
00377
00378
00379 setName(name,"h1RawRatio",iBin);
00380 varBin[iBin].h1RawRatio = (TH1D*) inRoot->Get(name);
00381
00382 setName(name,"h1CorrectedRatio",iBin);
00383 varBin[iBin].h1CorrectedRatio = (TH1D*) inRoot->Get(name);
00384
00385 }
00386
00387 }
00388
00389
00390 void doBothChargeSigns()
00391 {
00392 cout << "\t**doBothChargsSigns()**" << endl;
00393
00394
00395
00396
00397
00398 for(Int_t iBin=0; iBin<nVarBin; iBin++){
00399 varBin[iBin].spec.h1Raw->Scale(0.5);
00400
00401
00402 varBin[iBin].spec.h1EffCorrected->Scale(0.5);
00403
00404
00405 varBin[iBin].spec.h1Corrected->Scale(0.5);
00406
00407 }
00408
00409 }
00410
00411
00412
00413 void doCorrections()
00414 {
00415 cout << "\t**doCorrections()**" << endl;
00416
00417
00418
00419 for(Int_t iBin=0; iBin<nVarBin; iBin++){
00420
00421 computeCorrection(varBin[iBin].spec.h1EffCorrected,
00422 correction[iBin].crip.h1PtDCrRatio,
00423 correction[iBin].bkg.h1Background,
00424 varBin[iBin].spec.h1Corrected);
00425
00426 showHistogramValues(varBin[iBin].spec.h1Corrected,"CORRECTED");
00427
00428 for(Int_t iCharge=0; iCharge<2; iCharge++){
00429
00430 computeCorrection(varBin[iBin].specPM[iCharge].h1EffCorrected,
00431 correction[iBin].cripPM[iCharge].h1PtDCrRatio,
00432 correction[iBin].bkgPM[iCharge].h1Background,
00433 varBin[iBin].specPM[iCharge].h1Corrected);
00434 showHistogramValues(varBin[iBin].specPM[iCharge].h1Corrected,
00435 "CORRECTED");
00436 }
00437
00438
00439 }
00440
00441
00442
00443 for(Int_t iBin=0; iBin<nVarBin; iBin++){
00444 varBin[iBin].spec.h1Raw->Scale(scale);
00445 varBin[iBin].spec.h1Corrected->Scale(scale);
00446 varBin[iBin].spec.h1EffCorrected->Scale(scale);
00447 for(Int_t iCharge=0; iCharge<2; iCharge++){
00448 varBin[iBin].specPM[iCharge].h1Raw->Scale(scale);
00449 varBin[iBin].specPM[iCharge].h1Corrected->Scale(scale);
00450 varBin[iBin].specPM[iCharge].h1EffCorrected->Scale(scale);
00451 }
00452
00453 }
00454
00455
00456
00457
00458 for(Int_t iBin=0; iBin<nVarBin; iBin++){
00459 computePtBin(varBin[iBin].spec.h1Raw);
00460 computePtBin(varBin[iBin].spec.h1EffCorrected);
00461 computePtBin(varBin[iBin].spec.h1Corrected);
00462
00463 for(Int_t iCharge=0; iCharge<2; iCharge++){
00464 computePtBin(varBin[iBin].specPM[iCharge].h1Raw);
00465 computePtBin(varBin[iBin].specPM[iCharge].h1EffCorrected);
00466 computePtBin(varBin[iBin].specPM[iCharge].h1Corrected);
00467
00468 }
00469 }
00470 }
00471
00472
00473
00474 void initFit()
00475 {
00476 cout << "\tinitFit()" << endl;
00477
00478
00479 fDist = new TF1("fDist",dist,fitLowPt,fitHighPt);
00480 fMean = new TF1("fMean",mean,fitLowPt,fitHighPt);
00481
00482 Double_t p2 = 1e4;
00483
00484 fDist->SetParameters(2.0,13.,p2);
00485 fMean->SetParameters(2.0,13.,p2);
00486 const int nParam = 3;
00487
00488 Double_t param[nParam];
00489 fDist->GetParameters(param);
00490
00491
00492
00493
00494
00495 cout << endl;
00496 }
00497
00498
00499
00500
00501
00502
00503 void fitHistograms()
00504 {
00505 cout << "\t**fit histograms**" << endl;
00506
00507
00508
00509
00510 TCanvas* dummy = new TCanvas("dummy","dummy",100,100,500,500);
00511 gPad->SetLogy();
00512
00513
00514 for(Int_t iBin=0; iBin<nVarBin; iBin++){
00515 varBin[iBin].spec.fRawTmp =
00516 fit(varBin[iBin].spec.h1Raw);
00517
00518 varBin[iBin].spec.fEffCorrectedTmp =
00519 fit(varBin[iBin].spec.h1EffCorrected);
00520
00521 varBin[iBin].spec.fCorrectedTmp =
00522 fit(varBin[iBin].spec.h1Corrected);
00523
00524 for(Int_t iCharge=0; iCharge<2; iCharge++){
00525 varBin[iBin].specPM[iCharge].fRawTmp =
00526 fit(varBin[iBin].specPM[iCharge].h1Raw);
00527
00528 varBin[iBin].specPM[iCharge].fEffCorrectedTmp =
00529 fit(varBin[iBin].specPM[iCharge].h1EffCorrected);
00530
00531 varBin[iBin].specPM[iCharge].fCorrectedTmp =
00532 fit(varBin[iBin].specPM[iCharge].h1Corrected);
00533 }
00534 }
00535
00536 delete dummy;
00537 }
00538
00539
00540
00541
00542
00543
00544
00545 TF1* fit(TH1* h1)
00546 {
00547 cout << "\tfitting " << h1->GetName() << endl;
00548
00549 double param[3];
00550 TF1* f=0;
00551
00552
00553 TH1* hClone=(TH1*)h1->Clone();
00554 hClone->Fit("fDist","QR");
00555 f = hClone->GetFunction("fDist");
00556
00557 f->GetParameters(param);
00558 fDist->SetParameters(param);
00559
00560
00561 hClone->Fit("fDist","QR");
00562 f = hClone->GetFunction("fDist");
00563
00564
00565
00566
00567
00568
00569
00570 TString sName = h1->GetName();
00571
00572 Ssiz_t last = findLast(sName,".");
00573
00574 sName.Replace(last,2,"fTmp");
00575
00576 f->SetName(sName.Data());
00577 f->SetTitle(sName.Data());
00578
00579 return f;
00580 }
00581
00582
00583
00584
00585
00586
00587 TF1* fit(TGraphAsymmErrors* g)
00588 {
00589 cout << "\tfitting " << g->GetName() << endl;
00590
00591 double param[3];
00592 TF1* f=0;
00593
00594
00595 TGraphAsymmErrors* gClone=(TGraphAsymmErrors*)g->Clone();
00596 gClone->Fit("fDist","QR");
00597 f = gClone->GetFunction("fDist");
00598
00599 f->GetParameters(param);
00600 fDist->SetParameters(param);
00601
00602
00603 gClone->Fit("fDist","QR");
00604 f = gClone->GetFunction("fDist");
00605
00606 cout << "\t\tparams : "
00607 << "p0=" << f->GetParameter(0)
00608 << ",p1=" << f->GetParameter(1)
00609 << ",p2=" << f->GetParameter(2)
00610 << endl;
00611
00612 TString sName = g->GetName();
00613
00614 Ssiz_t last = findLast(sName,".");
00615
00616 sName.Replace(last,1,"f");
00617 f->SetName(sName.Data());
00618 f->SetTitle(sName.Data());
00619
00620 cout << "\t\t fcn name " << f->GetName() << endl;
00621
00622 return f;
00623 }
00624
00625
00626
00627
00628 Double_t getWeightedMean(TF1* f,Double_t lowEdge, Double_t upEdge)
00629 {
00630 Double_t param[3];
00631
00632 f->GetParameters(param);
00633
00634
00635
00636
00637 fMean->SetParameters(param);
00638
00639 return fMean->Integral(lowEdge,upEdge)/f->Integral(lowEdge,upEdge);
00640
00641 }
00642
00643
00644
00645
00646
00647
00648 TGraphAsymmErrors*
00649 graphOffset(TH1D* h1,TF1* f,TH1* hMean,Int_t type)
00650 {
00651
00652 Int_t lowBin = h1->GetXaxis()->FindBin(fitLowPt);
00653 Int_t highBin = h1->GetXaxis()->FindBin(fitHighPt-.0001);
00654 Int_t nBin = highBin-lowBin+1;
00655
00656 TArrayD yErrorAry(nBin), yValueAry(nBin), xValueAry(nBin),
00657 xLowErrorAry(nBin), xHighErrorAry(nBin);
00658
00659
00660
00661
00662
00663 Int_t binAry(0);
00664
00665 for(Int_t iBin=lowBin; iBin<=highBin; iBin++,binAry++){
00666
00667
00668
00669
00670 Double_t lowEdge = h1->GetXaxis()->GetBinLowEdge(iBin);
00671 Double_t upEdge = h1->GetXaxis()->GetBinUpEdge(iBin);
00672 Double_t mean = 0;
00673
00674 switch(type){
00675 case 1:
00676 mean = getWeightedMean(f,lowEdge,upEdge); break;
00677 case 2:
00678 mean = h1Mean->GetBinContent(h1Mean->GetXaxis()->FindBin((lowEdge+upEdge)/2)); break;
00679 default:
00680 mean = getWeightedMean(f,lowEdge,upEdge);
00681 }
00682
00683 xLowErrorAry.AddAt(fabs(mean-lowEdge),binAry);
00684 xHighErrorAry.AddAt(fabs(mean-upEdge),binAry);
00685
00686 xValueAry.AddAt(mean,binAry);
00687
00688 yErrorAry.AddAt(h1->GetBinError(iBin),binAry);
00689
00690 yValueAry.AddAt(h1->GetBinContent(iBin),binAry);
00691
00692 }
00693
00694
00695
00696
00697
00698 TGraphAsymmErrors* g = new TGraphAsymmErrors(nBin,
00699 xValueAry.GetArray(),
00700 yValueAry.GetArray(),
00701 xLowErrorAry.GetArray(),
00702 xHighErrorAry.GetArray(),
00703 yErrorAry.GetArray(),
00704 yErrorAry.GetArray());
00705
00706 TString sName = h1->GetName();
00707 Ssiz_t last = findLast(sName,".");
00708
00709 sName.Replace(last,2,"g");
00710
00711 g->SetName(sName.Data());
00712 g->SetTitle(sName.Data());
00713
00714 return g;
00715 }
00716
00717
00718 TGraphAsymmErrors*
00719 graphSpectra(TGraphAsymmErrors* g)
00720 {
00721
00722 const Int_t nBin = g->GetN();
00723
00724 Double_t* x = g->GetX();
00725 Double_t* y = g->GetY();
00726 Double_t* eXlow = g->GetEXlow();
00727 Double_t* eXhigh = g->GetEXhigh();
00728 Double_t* eYlow = g->GetEYlow();
00729
00730 TArrayD yErrorAry(nBin), yValueAry(nBin);
00731
00732
00733
00734
00735
00736 for(Int_t i=0; i<nBin; i++){
00737 Double_t mean = x[i];
00738
00739 yErrorAry.AddAt(eYlow[i]/mean,i);
00740 yValueAry.AddAt(y[i]/mean,i);
00741 }
00742
00743
00744 TGraphAsymmErrors* gSpec
00745 = new TGraphAsymmErrors(nBin,x,yValueAry.GetArray(),eXlow,eXhigh,
00746 yErrorAry.GetArray(),yErrorAry.GetArray());
00747
00748 TString sName = g->GetName();
00749 Ssiz_t last = findLast(sName,".");
00750
00751 sName.Replace(last,1,"gSpec");
00752
00753 gSpec->SetName(sName.Data());
00754 gSpec->SetTitle(sName.Data());
00755
00756 return gSpec;
00757
00758
00759 }
00760
00761
00762
00763
00764
00765 void doOffSetGraphs(Int_t type)
00766 {
00767
00768 for(Int_t iBin=0; iBin<nVarBin; iBin++){
00769
00770 varBin[iBin].spec.gRaw =
00771 graphOffset(varBin[iBin].spec.h1Raw,
00772 varBin[iBin].spec.fRawTmp,
00773 varBin[iBin].mean.h1WeightedMean,type);
00774
00775 varBin[iBin].spec.gEffCorrected =
00776 graphOffset(varBin[iBin].spec.h1EffCorrected,
00777 varBin[iBin].spec.fEffCorrectedTmp,
00778 varBin[iBin].mean.h1WeightedMean,type);
00779
00780 varBin[iBin].spec.gCorrected =
00781 graphOffset(varBin[iBin].spec.h1Corrected,
00782 varBin[iBin].spec.fCorrectedTmp,
00783 varBin[iBin].mean.h1WeightedMean,type);
00784
00785
00786 for(Int_t iCharge=0; iCharge<2; iCharge++){
00787
00788 varBin[iBin].specPM[iCharge].gRaw =
00789 graphOffset(varBin[iBin].specPM[iCharge].h1Raw,
00790 varBin[iBin].specPM[iCharge].fRawTmp,
00791 varBin[iBin].mean.h1WeightedMean,type);
00792
00793
00794 varBin[iBin].specPM[iCharge].gEffCorrected =
00795 graphOffset(varBin[iBin].specPM[iCharge].h1EffCorrected,
00796 varBin[iBin].specPM[iCharge].fEffCorrectedTmp,
00797 varBin[iBin].meanPM[iCharge].h1WeightedMean,type);
00798
00799 varBin[iBin].specPM[iCharge].gCorrected =
00800 graphOffset(varBin[iBin].specPM[iCharge].h1Corrected,
00801 varBin[iBin].specPM[iCharge].fCorrectedTmp,
00802 varBin[iBin].meanPM[iCharge].h1WeightedMean,type);
00803
00804 }
00805
00806 }
00807 }
00808
00809
00810
00811
00812
00813
00814
00815 void fitGraphs()
00816 {
00817 cout << "\t**fitGraphs()**" << endl;
00818
00819
00820
00821
00822 TCanvas* dummy = new TCanvas("dummy","dummy",100,100,500,500);
00823 gPad->SetLogy();
00824
00825 for(Int_t iBin=0; iBin<nVarBin; iBin++){
00826
00827 varBin[iBin].spec.fEffCorrected =
00828 fit(varBin[iBin].spec.gEffCorrected);
00829
00830 varBin[iBin].spec.fCorrected =
00831 fit(varBin[iBin].spec.gCorrected);
00832
00833 for(Int_t iCharge=0; iCharge<2; iCharge++){
00834
00835 varBin[iBin].specPM[iCharge].fEffCorrected =
00836 fit(varBin[iBin].specPM[iCharge].gEffCorrected);
00837
00838 varBin[iBin].specPM[iCharge].fCorrected =
00839 fit(varBin[iBin].specPM[iCharge].gCorrected);
00840 }
00841 }
00842
00843 delete dummy;
00844
00845 }
00846
00847
00848 void doSpectraGraphs()
00849 {
00850 cout << "\t**doSpectraGraphs()**" << endl;
00851
00852 for(Int_t iBin=0; iBin<nVarBin; iBin++){
00853 varBin[iBin].spec.gSpecCorrected =
00854 graphSpectra(varBin[iBin].spec.gCorrected);
00855
00856 for(Int_t iCharge=0; iCharge<2; iCharge++){
00857
00858 varBin[iBin].specPM[iCharge].gSpecCorrected =
00859 graphSpectra(varBin[iBin].specPM[iCharge].gCorrected);
00860 }
00861
00862 }
00863
00864 }
00865
00866
00867
00868
00869
00870
00871 void draw(const char* psDir, const char* trigger, const char* cut)
00872 {
00873
00874 }
00875
00876
00877
00878
00879
00880
00881
00882 void computeCorrection(TH1D* hRc, TH1D* hDCrOverRc,
00883 TH1D* hBkg, TH1D* hCorrected)
00884 {
00885
00886 Stat_t rc, dCr, rcError, dCrError, error, corrected, bkgCorrected,
00887 bkgCorrectedError, center, bkg, bkgError;
00888
00889 Int_t bin;
00890 Int_t nBin = hRc->GetNbinsX();
00891 Int_t maxBkgBin = hBkg->GetNbinsX();
00892
00893 *ofCor << "******************************************************" << endl;
00894 *ofCor << "## computeCorrection ##" << endl;
00895 *ofCor << "## corrected=" << hCorrected->GetName() << endl
00896 << " rc=" << hRc->GetName() << endl
00897 << " bkg=" << hBkg->GetName() << endl;
00898
00899 int firstCorBin=hRc->GetXaxis()->FindBin(corLowPt);
00900 *ofCor << "First correction bin is " << firstCorBin << endl;
00901 for(Int_t iBin=1; iBin<=nBin; iBin++){
00902
00903 rc = hRc->GetBinContent(iBin);
00904
00905
00906 dCr = (hDCrOverRc) ? hDCrOverRc->GetBinContent(iBin) :0;
00907
00908
00909 center = hRc->GetXaxis()->GetBinCenter(iBin);
00910 bin = hBkg->GetXaxis()->FindBin(center);
00911 if(bin==0 || bin>maxBkgBin){
00912 bkg = 0;
00913 }
00914 else{
00915 bkg = hBkg->GetBinContent(bin);
00916 }
00917
00918
00919
00920 bkgCorrected = rc*(1-bkg);
00921
00922 rcError = hRc->GetBinError(iBin);
00923
00924
00925 bkgError = bkg;
00926
00927 bkgCorrectedError
00928 = TMath::Sqrt(rcError*rcError*(1+bkg*bkg) + rc*rc*bkgError*bkgError);
00929
00930
00931
00932 if(iBin>=firstCorBin){
00933 corrected = bkgCorrected*(1-dCr);
00934 }
00935 else{
00936 *ofCor << "\tskipping momentum correction for this bin" << endl;
00937 corrected = bkgCorrected;
00938 }
00939
00940
00941 error = bkgCorrectedError;
00942
00943 hCorrected->SetBinContent(iBin,corrected);
00944 hCorrected->SetBinError(iBin,error);
00945
00946 float fracError = (rc>0) ? ((error/rc)*100) : 0;
00947 float fracRcError = (rc>0) ? ((rcError/rc)*100) : 0;
00948
00949
00950 *ofCor << " rc : " << hRc->GetXaxis()->GetBinLowEdge(iBin) << "-"
00951 << hRc->GetXaxis()->GetBinUpEdge(iBin)
00952 << "\trc bin content : " << rc
00953 << ", crippled : " << dCr
00954 << ", background : " << bkg << endl
00955 << "\tbkg corrected : " << bkgCorrected << endl
00956 << "\tcorrected : " << corrected << endl;
00957 *ofCor << "\t rc error : " << rcError
00958 << "(" << fracRcError << " %)"
00959 << ", dCrError : " << dCrError
00960 << ", bkg error: " << bkgError
00961 << endl
00962 << "\tbkg cor error : " << bkgCorrectedError << endl
00963 << "\ttotal error : " << error << endl
00964 << "\ttotal err % : " << fracError << endl;
00965
00966 }
00967 }
00968
00969
00970
00971
00972 void ptDivide(TH1* h1)
00973 {
00974 Int_t nBin=h1->GetNbinsX();
00975 for(int iBin=1; iBin<=nBin; iBin++){
00976 double content= h1->GetBinContent(iBin);
00977 double center = h1->GetBinCenter(iBin);
00978 double error = h1->GetBinError(iBin);
00979 if(content) h1->SetBinContent(iBin,content/center);
00980 if(error)h1->SetBinError(iBin,error/center);
00981 }
00982
00983 }
00984
00985
00986 void computePtBin(TH1* h1)
00987 {
00988
00989 double binWidth;
00990 double binContent;
00991 double binError;
00992
00993 Int_t nBin = h1->GetNbinsX();
00994 for(Int_t iBin=1; iBin<=nBin; iBin++){
00995 binWidth = h1->GetBinWidth(iBin);
00996 binContent= h1->GetBinContent(iBin);
00997 if(binContent>0) binContent /= binWidth;
00998 binError = h1->GetBinError(iBin);
00999 if(binError!=0) binError /= binWidth;
01000
01001 h1->SetBinContent(iBin,binContent);
01002 h1->SetBinError(iBin,binError);
01003
01004 }
01005 }
01006
01007
01008
01009
01010
01011 void writeHistograms(const char* outRootName)
01012 {
01013 cout << "writeHistograms() : " << outRootName << endl;
01014
01015
01016
01017 for(Int_t iBin=0; iBin<nVarBin; iBin++){
01018
01019 varBin[iBin].spec.h1Raw->Write();
01020 varBin[iBin].spec.h1EffCorrected->Write();
01021 varBin[iBin].spec.h1Corrected->Write();
01022 varBin[iBin].spec.gRaw->Write();
01023 varBin[iBin].spec.gEffCorrected->Write();
01024 varBin[iBin].spec.gCorrected->Write();
01025 varBin[iBin].spec.gSpecCorrected->Write();
01026 varBin[iBin].spec.fCorrected->Write();
01027
01028 showHistogramValues(varBin[iBin].spec.h1Raw,"FINAL");
01029 showHistogramValues(varBin[iBin].spec.h1EffCorrected,"FINAL");
01030 showHistogramValues(varBin[iBin].spec.h1Corrected,"FINAL");
01031
01032 showTGraphValues(varBin[iBin].spec.gRaw,"FINAL");
01033 showTGraphValues(varBin[iBin].spec.gEffCorrected,"FINAL");
01034 showTGraphValues(varBin[iBin].spec.gCorrected,"FINAL");
01035 showTGraphValues(varBin[iBin].spec.gSpecCorrected,"FINAL");
01036
01037 for(Int_t iCharge=0; iCharge<2; iCharge++){
01038
01039
01040
01041
01042
01043 varBin[iBin].specPM[iCharge].h1Raw->Write();
01044 varBin[iBin].specPM[iCharge].h1EffCorrected->Write();
01045 varBin[iBin].specPM[iCharge].h1Corrected->Write();
01046 varBin[iBin].specPM[iCharge].gEffCorrected->Write();
01047 varBin[iBin].specPM[iCharge].gCorrected->Write();
01048 varBin[iBin].specPM[iCharge].gSpecCorrected->Write();
01049 varBin[iBin].specPM[iCharge].fCorrected->Write();
01050
01051 showHistogramValues(varBin[iBin].specPM[iCharge].h1Raw,"FINAL");
01052 showHistogramValues(varBin[iBin].specPM[iCharge].h1EffCorrected,"FINAL");
01053 showHistogramValues(varBin[iBin].specPM[iCharge].h1Corrected,"FINAL");
01054
01055 showTGraphValues(varBin[iBin].specPM[iCharge].gRaw,"FINAL");
01056 showTGraphValues(varBin[iBin].specPM[iCharge].gEffCorrected,"FINAL");
01057 showTGraphValues(varBin[iBin].specPM[iCharge].gCorrected,"FINAL");
01058 showTGraphValues(varBin[iBin].specPM[iCharge].gSpecCorrected,"FINAL");
01059
01060 }
01061
01062 }
01063
01064 }
01065
01066
01067
01068
01069
01070
01071 Ssiz_t findLast(TString temp, const char* a)
01072 {
01073 Ssiz_t last = 0;
01074
01075 while(1){
01076 Ssiz_t pos = temp.First(a);
01077 if(pos<0) break;
01078 last += ++pos;
01079 temp.Remove(0,pos);
01080 }
01081
01082 return last;
01083
01084 }