]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/SPECTRA/PiKaPr/TestAOD/MainAnalysis.C
- Qvector distribution added - runGridModified - Asymmetric eta cut implemented ...
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / PiKaPr / TestAOD / MainAnalysis.C
CommitLineData
6da07d74 1class AliPID;
2#include "QAPlots.C"
624a6bb0 3
4TString Charge[]={"Pos","Neg"};
5TString Sign[]={"Plus","Minus"};
6TString Particle[]={"Pion","Kaon","Proton"};
7Int_t Color[3]={1,2,4};
8Int_t Marker[6]={20,21,22,24,25,26};
9Double_t projl[3]={0,20,80};
10Double_t proju[3]={10,40,90};
6da07d74 11Double_t Range[3]={0.3,0.3,0.5}; // LowPt range for pi k p
12enum ECharge_t {
13 kPositive,
14 kNegative,
15 kNCharges
16};
624a6bb0 17
18
6da07d74 19void MainAnalysis() {
624a6bb0 20
acef4f19 21 gSystem->Load("libCore.so");
6da07d74 22 //gSystem->Load("libGeom.so");
624a6bb0 23 gSystem->Load("libPhysics.so");
6da07d74 24 //gSystem->Load("libVMC");
acef4f19 25 gSystem->Load("libTree");
6da07d74 26 //gSystem->Load("libProof");
acef4f19 27 gSystem->Load("libMatrix");
28 gSystem->Load("libSTEERBase");
29 gSystem->Load("libESD");
30 gSystem->Load("libAOD");
624a6bb0 31 gSystem->Load("libANALYSIS");
acef4f19 32 gSystem->Load("libOADB");
624a6bb0 33 gSystem->Load("libANALYSISalice");
acef4f19 34 gSystem->Load("libTENDER");
35 gSystem->Load("libCORRFW");
36 //gSystem->Load("libPWG0base");
6da07d74 37 //gSystem->Load("libMinuit");
acef4f19 38 gSystem->Load("libPWGTools");
39 gSystem->Load("libPWGLFSPECTRA");
624a6bb0 40 gSystem->AddIncludePath("-I$ALICE_ROOT/include");
decf69d9 41
6da07d74 42 // Set Masses
43 Double_t mass[3];
44 mass[0] = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
45 mass[1] = TDatabasePDG::Instance()->GetParticle("K+")->Mass();
46 mass[2] = TDatabasePDG::Instance()->GetParticle("proton")->Mass();
47
decf69d9 48 TString fold="3SigmaPID_AOD086-090_FilterBit1";
6da07d74 49
decf69d9 50 //LOOP OVER SELECTION
00493191 51 Double_t CentCutMin[6]= { 0 , 20, 20, 20, 20, 20};
52 Double_t CentCutMax[6]= { 5 , 40, 40, 40, 40, 40};
53 Double_t QvecPosCutMin[6]= {0 , 0, 0, 3, 0, 0};
54 Double_t QvecPosCutMax[6]={100,100, 2,100,100,100};
55 Double_t QvecNegCutMin[6]={0 , 0, 0, 0, 0, 3};
56 Double_t QvecNegCutMax[6]={100,100,100,100, 2,100};
57 Double_t EtaMin[6]={-0.8,-0.8,-0.8,-0.8,0,0};
58 Double_t EtaMax[6]={0.8,0.8,0,0,0.8,0.8};
decf69d9 59
00493191 60 Int_t icut=2;
decf69d9 61
62 Int_t ibinToCompare=0;
63
64 TString sname=Form("Cent%.0fto%.0f_QVecPos%.1fto%.1f_QVecNeg%.1fto%.1f_Eta%.1fto%.1f",CentCutMin[icut],CentCutMax[icut],QvecPosCutMin[icut],QvecPosCutMax[icut],QvecNegCutMin[icut],QvecNegCutMax[icut],EtaMin[icut],EtaMax[icut]);
6da07d74 65
decf69d9 66 TString dataFile = Form("output/%s/OutputAODSpectraTask_data_%s.root",fold.Data(),sname.Data());
67 TString mcFile = Form("output/%s/OutputAODSpectraTask_mc_%s.root",fold.Data(),sname.Data());
68
00493191 69
70
71
72 Printf("\n\n-> Creating Output file Out_%s_%s.root",sname.Data(),fold.Data());
73 TFile * fout=new TFile(Form("results/Out_%s_%s.root",sname.Data(),fold.Data()),"RECREATE");
74
decf69d9 75 gStyle->SetPalette(1);
624a6bb0 76 // Open root MC file and get classes
77 cout << "Analysis Macro" << endl;
78 cout << " > Reading MC data" << endl;
79 TFile *_mc = TFile::Open(mcFile.Data());
80 AliSpectraAODHistoManager* hman_mc = (AliSpectraAODHistoManager*) _mc->Get("SpectraHistos");
81 AliSpectraAODEventCuts* ecuts_mc = (AliSpectraAODEventCuts*) _mc->Get("Event Cuts");
82 AliSpectraAODTrackCuts* tcuts_mc = (AliSpectraAODTrackCuts*) _mc->Get("Track Cuts");
83 // print info about mc track and Event cuts
84 cout << " -- Info about MC -- "<< endl;
85 ecuts_mc->PrintCuts();
86 // tcuts_mc->PrintCuts();
87 // proceed likewise for data
88 TFile *_data = TFile::Open(dataFile.Data());
89 AliSpectraAODHistoManager* hman_data = (AliSpectraAODHistoManager*) _data->Get("SpectraHistos");
90 AliSpectraAODEventCuts* ecuts_data = (AliSpectraAODEventCuts*) _data->Get("Event Cuts");
91 AliSpectraAODTrackCuts* tcuts_data = (AliSpectraAODTrackCuts*) _data->Get("Track Cuts");
92 // print info about track and Event cuts
93 cout << " -- Info about data -- " << endl;
94 ecuts_data->PrintCuts();
95 tcuts_data->PrintCuts();
96
00493191 97 QAPlots(hman_data,hman_mc,ecuts_data,ecuts_mc,tcuts_data,tcuts_mc,fout);
972a21ad 98
624a6bb0 99 //efficiencies
100 Printf("\n\n-> Calculating MC Correction Factors");
101 TH1F *CorrFact[6];
102 TCanvas *ceff=new TCanvas("ceff","ceff",700,500);
ed06106e 103 Bool_t UseMCDCACorrection=kTRUE;
624a6bb0 104 for(Int_t icharge=0;icharge<2;icharge++){
105 for(Int_t ipart=0;ipart<3;ipart++){
106 Int_t index=ipart+3*icharge;
ed06106e 107 //BE CAREFUL! depending on the efficiency you choose, you must change the DCA correction (data or data/mc)
108
6da07d74 109 TString hname=Form("hHistPtRecSigma%s%s",Particle[ipart].Data(),Sign[icharge].Data()); //MC correction for Prim+Cont+Eff
ae0fdd7d 110 //TString hname=Form("hHistPtRecTrue%s%s",Particle[ipart].Data(),Sign[icharge].Data());//MC correction for Prim+Eff if (idRec == idGen)
111 //TString hname=Form("hHistPtRecSigmaPrimary%s%s",Particle[ipart].Data(),Sign[icharge].Data());UseMCDCACorrection=kFALSE; //MC correction for Cont+Eff. filled with idRec
112 //TString hname=Form("hHistPtRecPrimary%s%s",Particle[ipart].Data(),Sign[icharge].Data());UseMCDCACorrection=kFALSE; //MC correction for Cont+Eff. filled with idGen
113 //TString hname=Form("hHistPtRecTruePrimary%s%s",Particle[ipart].Data(),Sign[icharge].Data());UseMCDCACorrection=kFALSE; // Pure MC efficiency for Prim. BE CAREFUL WITH MUONS!!! (idRec == idGen)
624a6bb0 114 Printf("Getting %s",hname.Data());
115 CorrFact[index]=(TH1F*)((TH1F*) hman_mc->GetPtHistogram1D(hname.Data(),-1,-1))->Clone();
116 CorrFact[index]->SetName(Form("CorrFact_%s%s",Particle[ipart].Data(),Sign[icharge].Data()));
117 CorrFact[index]->SetTitle(Form("CorrFact %s%s",Particle[ipart].Data(),Sign[icharge].Data()));
118 CorrFact[index]->SetMarkerStyle(Marker[index]);
119 CorrFact[index]->SetMarkerColor(Color[ipart]);
120 CorrFact[index]->SetLineColor(Color[ipart]);
6da07d74 121 hname=Form("hHistPtGenTruePrimary%s%s",Particle[ipart].Data(),Sign[icharge].Data());
624a6bb0 122 Printf("... and divide it by %s",hname.Data());
123 CorrFact[index]->Divide(CorrFact[index],(TH1F*)((TH1F*)hman_mc->GetPtHistogram1D(hname.Data(),1,1))->Clone(),1,1,"B");//binomial error
124 if(index==0)CorrFact[index]->DrawClone();
125 else CorrFact[index]->DrawClone("same");
126 }
127 }
acef4f19 128 TFile *fESD=new TFile("EffAlex/pionEffPbPb.root");
129 TH1F *hEffESD=(TH1F*)fESD->Get("effMapPionTpcOnlyNeg0");
130 hEffESD->DrawClone("same");
972a21ad 131 gPad->BuildLegend()->SetFillColor(0);
ed06106e 132
6da07d74 133 //Normalization
624a6bb0 134 printf("\n\n-> Spectra Normalization");
135 AliSpectraAODEventCuts* ecuts_data = (AliSpectraAODEventCuts*) _data->Get("Event Cuts");
136 Double_t events_data = ecuts_data->NumberOfEvents();
137 Printf(": accepted events: %.0f",events_data);
6da07d74 138 Double_t events_mc = ecuts_mc->NumberOfEvents();
139 Printf(": accepted events (MC): %.0f",events_mc);
624a6bb0 140
624a6bb0 141 //divide RAW for Correction Factor
142 Printf("\n\n-> Using MC correction factor to correct RAW spectra");
143 TH1F *Spectra[6];
144 for(Int_t icharge=0;icharge<2;icharge++){
145 for(Int_t ipart=0;ipart<3;ipart++){
146 Int_t index=ipart+3*icharge;
6da07d74 147 TString hname=Form("hHistPtRecSigma%s%s",Particle[ipart].Data(),Sign[icharge].Data());
624a6bb0 148 printf("Getting %s",hname.Data());
149 Spectra[index] =(TH1F*)((TH1F*) hman_data->GetPtHistogram1D(hname.Data(),-1,-1))->Clone();
150 Spectra[index]->SetName(Form("Spectra_%s%s",Particle[ipart].Data(),Sign[icharge].Data()));
151 Spectra[index]->SetTitle(Form("Spectra %s%s",Particle[ipart].Data(),Sign[icharge].Data()));
152 Spectra[index]->SetMarkerStyle(Marker[index]);
153 Spectra[index]->SetMarkerColor(Color[ipart]);
154 Spectra[index]->SetLineColor(Color[ipart]);
155 Printf("... and divide it by %s",hname.Data());
6da07d74 156 Spectra[index]->Divide(CorrFact[index]);
624a6bb0 157 Spectra[index]->Scale(1./events_data,"width");//NORMALIZATION
158 }
159 }
160
ae0fdd7d 161
162
163 //Put Bin Content = 0 for bin below the the range
6da07d74 164 for(Int_t icharge=0;icharge<2;icharge++){
165 for(Int_t ipart=0;ipart<3;ipart++){
166 Int_t index=ipart+3*icharge;
167 for(Int_t ibin=0;ibin<Spectra[index]->GetNbinsX();ibin++){
168 if(Spectra[index]->GetBinCenter(ibin)<Range[ipart]){
169 Spectra[index]->SetBinContent(ibin,0);
170 Spectra[index]->SetBinError(ibin,0);
171 }
624a6bb0 172 }
6da07d74 173 }
624a6bb0 174 }
ae0fdd7d 175
6da07d74 176 //DCA Correction with the "right" DCA sample
00493191 177 //DCACorrection(Spectra,hman_data,hman_mc,UseMCDCACorrection,fout);
ed06106e 178
6da07d74 179 //DCA Correction forcing loose DCA
180 // TString fold_LooseDCA="5SigmaPID_AOD046_FilterBit5";
181 // TString dataFile_LooseDCA = Form("output/%s/Pt.AOD.1._data_ptcut_%s.root",fold_LooseDCA.Data(),sname.Data());
182 // TString mcFile_LooseDCA =Form("output/%s/Pt.AOD.1._MC_%s.root",fold_LooseDCA.Data(),sname.Data());
183 // TFile *_mc_LooseDCA = TFile::Open(mcFile_LooseDCA.Data());
184 // AliSpectraAODHistoManager* hman_mc_LooseDCA = (AliSpectraAODHistoManager*) _mc_LooseDCA->Get("SpectraHistos");
185 // TFile *_data_LooseDCA = TFile::Open(dataFile_LooseDCA.Data());
186 // AliSpectraAODHistoManager* hman_data_LooseDCA = (AliSpectraAODHistoManager*) _data_LooseDCA->Get("SpectraHistos");
187 // DCACorrection(Spectra,hman_data_LooseDCA,hman_mc_LooseDCA,UseMCDCACorrection);
188
6da07d74 189 //GFCorrection
00493191 190 GFCorrection(Spectra,tcuts_data,fout);
624a6bb0 191
192 TH1F *MCTruth[6];
193 for(Int_t icharge=0;icharge<2;icharge++){
194 for(Int_t ipart=0;ipart<3;ipart++){
195 Int_t index=ipart+3*icharge;
6da07d74 196 hname=Form("hHistPtGenTruePrimary%s%s",Particle[ipart].Data(),Sign[icharge].Data());
197 MCTruth[index]=(TH1F*)((TH1F*)hman_mc->GetPtHistogram1D(hname.Data(),1,1))->Clone();
198 MCTruth[index]->SetName(Form("MCTruth_%s%s",Particle[ipart].Data(),Sign[icharge].Data()));
199 MCTruth[index]->SetTitle(Form("MCTruth_%s%s",Particle[ipart].Data(),Sign[icharge].Data()));
200 MCTruth[index]->Scale(1./events_mc,"width");//NORMALIZATION
624a6bb0 201 }
202 }
203
ae0fdd7d 204
205 //Matching efficiency in data and Monte Carlo
206 TCanvas *cMatchingEff=new TCanvas("MatchingEff","MatchingEff",700,500);
207 TH1F *hMatcEffPos_data=(TH1F*)tcuts_data->GetHistoNMatchedPos();
208 hMatcEffPos_data->Divide((TH1F*)tcuts_data->GetHistoNSelectedPos());
209 hMatcEffPos_data->SetTitle("Matching Eff Pos - data");
210 TH1F *hMatcEffNeg_data=(TH1F*)tcuts_data->GetHistoNMatchedNeg();
211 hMatcEffNeg_data->Divide((TH1F*)tcuts_data->GetHistoNSelectedNeg());
212 hMatcEffNeg_data->SetTitle("Matching Eff Neg - data");
213 hMatcEffNeg_data->SetLineColor(2);
214 TH1F *hMatcEffPos_mc=(TH1F*)tcuts_mc->GetHistoNMatchedPos();
215 hMatcEffPos_mc->Divide((TH1F*)tcuts_mc->GetHistoNSelectedPos());
216 hMatcEffPos_mc->SetTitle("Matching Eff Pos - mc");
217 hMatcEffPos_mc->SetLineStyle(2);
218 TH1F *hMatcEffNeg_mc=(TH1F*)tcuts_mc->GetHistoNMatchedNeg();
219 hMatcEffNeg_mc->Divide((TH1F*)tcuts_mc->GetHistoNSelectedNeg());
220 hMatcEffNeg_mc->SetTitle("Matching Eff Neg - mc");
221 hMatcEffNeg_mc->SetLineColor(2);
222 hMatcEffNeg_mc->SetLineStyle(2);
223 cMatchingEff->Divide(1,2);
224 cMatchingEff->cd(1);
225 gPad->SetGridy();
226 gPad->SetGridx();
227 hMatcEffPos_data->DrawClone("lhist");
228 hMatcEffNeg_data->DrawClone("lhistsame");
229 hMatcEffPos_mc->DrawClone("lhistsame");
230 hMatcEffNeg_mc->DrawClone("lhistsame");
972a21ad 231 gPad->BuildLegend()->SetFillColor(0);
ae0fdd7d 232 hMatcEffPos_data->Divide(hMatcEffPos_mc);
233 hMatcEffNeg_data->Divide(hMatcEffNeg_mc);
234 cMatchingEff->cd(2);
235 gPad->SetGridy();
236 gPad->SetGridx();
237 hMatcEffPos_data->DrawClone("lhist");
238 hMatcEffNeg_data->DrawClone("lhistsame");
239 TF1 *pol0MatchPos_data=new TF1("pol0MatchPos_data","pol0",2.5,5);
240 hMatcEffPos_data->Fit("pol0MatchPos_data","MNR");
241 pol0MatchPos_data->DrawClone("same");
242 TF1 *pol0MatchNeg_data=new TF1("pol0MatchNeg_data","pol0",2.5,5);
243 hMatcEffNeg_data->Fit("pol0MatchNeg_data","MNR");
244 pol0MatchNeg_data->SetLineColor(2);
245 pol0MatchNeg_data->DrawClone("same");
246 Float_t ScalingMatchingPos=pol0MatchPos_data->GetParameter(0);
247 Float_t ScalingMatchingNeg=pol0MatchNeg_data->GetParameter(0);
248
249 //Correction spectra for matching efficiency
250 //For the moment I'm using the inclusive correction
251 for(Int_t ipart=0;ipart<3;ipart++){
252 for(Int_t ibin=1;ibin<Spectra[ipart]->GetNbinsX();ibin++){
253 Float_t ptspectra=Spectra[ipart]->GetBinCenter(ibin);
254 if(ptspectra<tcuts_data->GetPtTOFMatching())continue;
255 //Spectra[ipart]->SetBinContent(ibin,( Spectra[ipart]->GetBinContent(ibin)/hMatcEffPos_data->GetBinContent(hMatcEffPos_data->FindBin(ptspectra))));
256 //Spectra[ipart+3]->SetBinContent(ibin,( Spectra[ipart+3]->GetBinContent(ibin)/hMatcEffNeg_data->GetBinContent(hMatcEffNeg_data->FindBin(ptspectra))));
257 Spectra[ipart]->SetBinContent(ibin,( Spectra[ipart]->GetBinContent(ibin)/ScalingMatchingPos));
258 Spectra[ipart+3]->SetBinContent(ibin,( Spectra[ipart+3]->GetBinContent(ibin)/ScalingMatchingNeg));
259 }
260 }
261
624a6bb0 262 //Drawing Final Spectra
263 TCanvas *cspectra=new TCanvas("cspectra","cspectra",700,500);
6da07d74 264 gPad->SetGridy();
265 gPad->SetGridy();
266 gPad->SetLogy();
624a6bb0 267 for(Int_t icharge=0;icharge<2;icharge++){
268 for(Int_t ipart=0;ipart<3;ipart++){
269 Int_t index=ipart+3*icharge;
270 if(index==0)Spectra[index]->DrawClone();
271 else Spectra[index]->DrawClone("same");
624a6bb0 272 }
273 }
972a21ad 274 gPad->BuildLegend()->SetFillColor(0);
ed06106e 275
00493191 276
624a6bb0 277 //if Bin 0-5% with no cut ratio with combined analysis
00493191 278 TCanvas *CratioComb=new TCanvas("CratioComb","CratioComb",700,500);
279 CratioComb->Divide(3,2);
280 TString nameComb[6]={Form("cent%d_pion_plus",ibinToCompare),Form("cent%d_kaon_plus",ibinToCompare),Form("cent%d_proton_plus",ibinToCompare),
624a6bb0 281 Form("cent%d_pion_minus",ibinToCompare),Form("cent%d_kaon_minus",ibinToCompare),Form("cent%d_proton_minus",ibinToCompare)};
6da07d74 282 TFile *fComb=new TFile("Combined05/SPECTRA_COMB_20120412.root");
283 TH1F *Spectra_copy[6]=0x0;
624a6bb0 284 for(Int_t icharge=0;icharge<2;icharge++){
285 for(Int_t ipart=0;ipart<3;ipart++){
6da07d74 286 Int_t index=ipart+3*icharge;
287 TH1F *htmp=(TH1F*)((TH1F*)Spectra[index])->Clone("");
288 htmp->GetXaxis()->SetRangeUser(0,2.5);
624a6bb0 289 TH1F *hcomb=fComb->Get(nameComb[index].Data())->Clone();
290 CratioComb->cd(ipart+1);
291 gPad->SetGridy();
292 gPad->SetGridx();
972a21ad 293 //for(Int_t ibin=1;ibin<hcomb->GetNbinsX();ibin++)hcomb->SetBinError(ibin,0);
00493191 294
6da07d74 295 if(icharge==0)htmp->DrawClone();
296 else htmp->DrawClone("same");
972a21ad 297 //MCTruth[index]->DrawClone("same");
ae0fdd7d 298 hcomb->DrawClone("same");
299 htmp->Divide(hcomb);
6da07d74 300 htmp->SetMaximum(1.3);
301 htmp->SetMinimum(0.7);
624a6bb0 302 CratioComb->cd(ipart+4);
303 gPad->SetGridy();
304 gPad->SetGridx();
6da07d74 305 if(icharge==0)htmp->DrawClone();
306 else htmp->DrawClone("same");
624a6bb0 307 }
308 }
ed06106e 309
acef4f19 310 //comparison with charged hadron
311 Printf("\n\n-> ChargedHadron comparison");
6da07d74 312 TH1F *hChHad_data=(TH1F*)((TH1F*)hman_data->GetPtHistogram1D("hHistPtRec",-1,-1))->Clone();
ae0fdd7d 313 TH1F* hMatchCorrectionAllCh=(TH1F*)hMatcEffPos_data->Clone("hMatchCorrectionAllCh");
314 hMatchCorrectionAllCh->Add(hMatcEffNeg_data); //correction for Matching efficiency!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
315 hMatchCorrectionAllCh->Scale(0.5);
316 for(Int_t ibin=1;ibin<hChHad_data->GetNbinsX();ibin++){
317 Float_t ptch=hChHad_data->GetBinCenter(ibin);
318 if(ptch<tcuts_data->GetPtTOFMatching())continue;
319 //hChHad_data->SetBinContent(ibin,(hChHad_data->GetBinContent(ibin)/hMatchCorrectionAllCh->GetBinContent(hMatchCorrectionAllCh->FindBin(ptch))));
320 hChHad_data->SetBinContent(ibin,2*(hChHad_data->GetBinContent(ibin)/(ScalingMatchingPos+ScalingMatchingNeg)));
321 }
acef4f19 322 //fraction of sec in MC
6da07d74 323 TH1F *hPrimRec_mc=(TH1F*)((TH1F*)hman_mc->GetPtHistogram1D("hHistPtRecPrimary",-1,-1))->Clone();
324 TH1F *hAllRec_mc=(TH1F*)((TH1F*)hman_mc->GetPtHistogram1D("hHistPtRec",-1,-1))->Clone();
acef4f19 325 for(Int_t ibin=1;ibin<=hChHad_data->GetNbinsX();ibin++){
ed06106e 326 Double_t en_data=hChHad_data->GetBinContent(ibin);
327 Double_t en_mc=hAllRec_mc->GetBinContent(ibin);
328 Double_t prim_mc=hPrimRec_mc->GetBinContent(ibin);
ae0fdd7d 329 if(en_mc!=0)hChHad_data->SetBinContent(ibin,en_data-(en_data*(en_mc-prim_mc)*1.2/en_mc));
f6a38178 330 //Printf("Before: %.0f After: %.0f fraction: %.1f",en_data,hChHad_data->GetBinContent(ibin),hChHad_data->GetBinContent(ibin)/en_data);
acef4f19 331 }
ed06106e 332 hPrimRec_mc->Divide(hAllRec_mc);
acef4f19 333 //efficiency for primaries
6da07d74 334 TH1F *hEff_mc=(TH1F*)((TH1F*)hman_mc->GetPtHistogram1D("hHistPtRecPrimary",-1,-1))->Clone();
335 hEff_mc->Divide((TH1F*)((TH1F*)hman_mc->GetPtHistogram1D("hHistPtGen",1,1))->Clone());
f6a38178 336 TCanvas *cAllChFactors=new TCanvas("cAllChFactors","cAllChFactors",700,500);
337 cAllChFactors->Divide(1,2);
338 cAllChFactors->cd(1);
339 gPad->SetGridy();
340 gPad->SetGridx();
341 hPrimRec_mc->SetTitle("Prim/All, charged hadron pure MC");
342 hPrimRec_mc->DrawClone("lhist");
972a21ad 343 gPad->BuildLegend()->SetFillColor(0);
f6a38178 344 cAllChFactors->cd(2);
345 gPad->SetGridy();
346 gPad->SetGridx();
347 hEff_mc->SetTitle("Efficiency for Primaries, charged hadron pure MC");
348 hEff_mc->DrawClone("lhist");
972a21ad 349 gPad->BuildLegend()->SetFillColor(0);
6da07d74 350 //Printf("--------%f ",((TH1F*)hman_mc->GetPtHistogram1D("hHistPtGen",1,1))->GetEntries()/1.6/ecuts_mc->NumberOfEvents());
ed06106e 351 hChHad_data->Scale(1./events_data,"width");//NORMALIZATION
352 hChHad_data->Divide(hEff_mc);//Efficiency
00493191 353 hChHad_data->Scale(1./(TMath::Abs(tcuts_data->GetEtaMin())+TMath::Abs(tcuts_data->GetEtaMax())));
6da07d74 354 hChHad_data->SetTitle("All Ch from AOD");
00493191 355 hChHad_data->SetName("AllCh");
f6a38178 356 TCanvas *cAllCh=new TCanvas("cAllCh","cAllCh",700,500);
357 cAllCh->Divide(1,2);
6da07d74 358 cAllCh->cd(1);
ed06106e 359 gPad->SetGridy();
360 gPad->SetGridx();
361 hChHad_data->DrawClone();
362 TFile *fCh=new TFile("ChargedHadron/SPECTRA_UNID_110906.root");
363 TH1F *hCh=fCh->Get("hpt_c0_5");
6da07d74 364 hCh->SetTitle("All Ch from Jacek");
365 hCh->SetMarkerColor(2);
366 hCh->SetLineColor(2);
ed06106e 367 //invariant yield
368 for(Int_t ibin=0;ibin<hCh->GetNbinsX();ibin++){
369 hCh->SetBinContent(ibin,hCh->GetBinContent(ibin)*(2*TMath::Pi()*hCh->GetBinCenter(ibin)));
370 hCh->SetBinError(ibin,hCh->GetBinError(ibin)*(2*TMath::Pi()*hCh->GetBinCenter(ibin)));
371 }
372 hCh->DrawClone("same");
972a21ad 373 gPad->BuildLegend()->SetFillColor(0);
ed06106e 374 TH1F *gRatio=AliPWGHistoTools::MyDivideHistosDifferentBins(hChHad_data,hCh);
6da07d74 375 gRatio->SetMaximum(1.3);
376 gRatio->SetMinimum(.7);
377 cAllCh->cd(2);
ed06106e 378 gPad->SetGridy();
379 gPad->SetGridx();
380 gRatio->DrawClone("");
6da07d74 381 //fitting
382 TCanvas *cFitChargHad=new TCanvas("cFitChargHad","cFitChargHad",700,500);
383 gPad->SetGridy();
384 gPad->SetGridx();
385 hChHad_data->DrawClone();
386 //Fitting the sum of all particles
387 AliPWGFunc * fm = new AliPWGFunc;
388 fm->SetVarType(AliPWGFunc::kdNdpt);
389 Float_t fitmin = 0.3;
390 Float_t fitmax = 3;
391 TF1 * func = 0;
392 Int_t normPar = 0;
393 func = fm->GetBGBW(0.13,0.6,0.3, 1, 1e5);
394 func->SetParLimits(1, 0.1, 0.99);
395 func->SetParLimits(2, 0.01, 1);
396 func->SetParLimits(3, 0.01, 2);
397 TH1F * hToFit = hChHad_data;
398 hToFit->Fit(func,"N","VMRN",fitmin,fitmax);
399 // // if(!AliPWGHistoTools::Fit(hToFit,func,fitmin,fitmax)) {
400 // // cout << " FIT ERROR " << endl;
401 // // return;
402 // // }
403 Double_t yieldTools, yieldETools;
404 Double_t partialYields[3],partialYieldsErrors[3];
405 AliPWGHistoTools::GetYield(hToFit, func, yieldTools, yieldETools,0, 100, partialYields,partialYieldsErrors);
406 func->DrawClone("same");
407 Printf("TOTAL YIELD (AOD Charged Hadron) : %f +- %f",yieldTools,yieldETools);
408 //Fit All Charged
409 hToFit = hCh;
410 hToFit->Fit(func,"N","VMRN",fitmin,fitmax);
411 AliPWGHistoTools::GetYield(hToFit, func, yieldTools, yieldETools,0, 100, partialYields,partialYieldsErrors);
412 func->SetLineColor(2);
413 hCh->DrawClone("same");
414 func->DrawClone("same");
972a21ad 415 gPad->BuildLegend()->SetFillColor(0);
6da07d74 416 Printf("TOTAL YIELD (JACEK): %f +- %f",yieldTools,yieldETools);
417 //sumID vs AllCh
418 //Convert spectra to dNdeta and sum
419 TH1F * hsum = (TH1F*) Spectra[0]->Clone();
420 hsum->Reset("all");
421 Double_t epsilon = 0.0001;
422 for(Int_t icharge = 0; icharge < 2; icharge++){
423 for(Int_t ipart = 0; ipart < 3; ipart++){
424 Int_t index=ipart+3*icharge;
425 TH1F *htmp =(TH1F*)Spectra[index]->Clone("htmp");
426 Int_t nbin = htmp->GetNbinsX();
427 for(Int_t ibin = 1; ibin <= nbin; ibin++){
428 Double_t pt = htmp->GetBinCenter(ibin);
429 Double_t eta=0.8;//////////////////eta range///////////////////////////////////////
430 Double_t jacobian =eta2y(pt,mass[ipart],eta)/eta;
431 //Printf("jacobian: %f pt:%f BinContent:%f mass:%f",jacobian,pt,htmp->GetBinContent(ibin),mass[ipart]);
432 htmp->SetBinContent(ibin,htmp->GetBinContent(ibin)*jacobian);
433 htmp->SetBinError(ibin,htmp->GetBinError(ibin)*jacobian);
434 Int_t ibinSum = hsum->FindBin(pt);
435 if ( htmp->GetBinContent(ibin) > 0 &&
436 (TMath::Abs(htmp->GetBinLowEdge(ibin) - hsum->GetBinLowEdge(ibinSum)) > epsilon ||
437 TMath::Abs(htmp->GetBinLowEdge(ibin+1) - hsum->GetBinLowEdge(ibinSum+1)) )
438 ) {
439 cout << "DISCREPANCY IN BIN RANGES" << endl;
440 cout << pt << " " << ibinSum << " " << ibin << "; " << h->GetBinContent(ibin) << endl
441 << h->GetBinLowEdge(ibin) << "-" << h->GetBinLowEdge(ibin+1) << endl
442 << hsum->GetBinLowEdge(ibinSum) << "-" << hsum->GetBinLowEdge(ibinSum+1) << endl;
443 cout << "" << endl;
444 }
445 }
446 hsum->Add(htmp);
447 }
448 }
449 hsum->SetTitle("Sum ID from AOD");
450 TCanvas *cChargHadComp=new TCanvas("cChargHadComp","cChargHadComp",700,500);
451 cChargHadComp->Divide(1,2);
452 cChargHadComp->cd(1);
453 gPad->SetGridy();
454 gPad->SetGridx();
455 hsum->DrawClone();
456 hToFit = hsum;
457 hToFit->Fit(func,"N","VMRN",fitmin,fitmax);
458 AliPWGHistoTools::GetYield(hToFit, func, yieldTools, yieldETools,0, 100, partialYields,partialYieldsErrors);
459 func->SetLineColor(2);
460 Printf("TOTAL YIELD (Pi+K+p): %f +- %f",yieldTools,yieldETools);
461 hChHad_data->SetMarkerColor(2);
462 hChHad_data->SetLineColor(2);
463 hChHad_data->DrawClone("same");
972a21ad 464 gPad->BuildLegend()->SetFillColor(0);
6da07d74 465 cChargHadComp->cd(2);
466 gPad->SetGridy();
467 gPad->SetGridx();
468 hsum->Divide(hChHad_data);
469 hsum->SetMaximum(1.2);
470 hsum->SetMinimum(.8);
471 hsum->DrawClone("");
ed06106e 472
00493191 473 //saving spectra
474 fout->cd();
475 for(Int_t icharge=0;icharge<2;icharge++){
476 for(Int_t ipart=0;ipart<3;ipart++){
477 Int_t index=ipart+3*icharge;
478 Spectra[index]->Write();
479 CorrFact[index]->Write();
480 MCTruth[index]->Write();
481 }
482 }
483 hChHad_data->Write();
484 cRaw->Write();
485 ceff->Write();
486 cMatchingEff->Write();
487 cspectra->Write();
488 CratioComb->Write();
489 cAllChFactors->Write();
490 cAllCh->Write();
491 cFitChargHad->Write();
492 cChargHadComp->Write();
493
494 fout->Close();
495 delete fout;
acef4f19 496
624a6bb0 497}
498
499
500
6da07d74 501
00493191 502void DCACorrection(TH1F **Spectra, AliSpectraAODHistoManager* hman_data, AliSpectraAODHistoManager* hman_mc,Bool_t UseMCDCACorrection,TFile *fout){
6da07d74 503 printf("\n\n-> DCA Correction");
624a6bb0 504
00493191 505 Double_t FitRange[2]={-3.,3.};
6da07d74 506 Int_t nrebin=2;
624a6bb0 507 Printf("\DCACorr");
508 TH1F *hcorrection[2];
509 TCanvas *ccorrection=new TCanvas("DCAcorrection","DCAcorrection",700,500);
6da07d74 510 TCanvas *cRatiocorrection=new TCanvas("DCARatiocorrection","DCARatiocorrection",700,500);
511 cRatiocorrection->Divide(2,1);
624a6bb0 512 ccorrection->Divide(2,1);
513 TString sample[2]={"data","mc"};
514 for(Int_t icharge=0;icharge<2;icharge++){
515 for(Int_t ipart=0;ipart<3;ipart++){
516 Int_t index=ipart+3*icharge;
517 for(Int_t isample=0;isample<2;isample++){
518 TCanvas *cDCA=new TCanvas(Form("cDCA%d%s",index,sample[isample].Data()),Form("cDCA%d%s",index,sample[isample].Data()),700,500);
519 hcorrection[isample]=(TH1F*)Spectra[index]->Clone();
520 hcorrection[isample]->Reset("all");
521 cDCA->Divide(8,4);
522 for(Int_t ibin_data=6;ibin_data<38;ibin_data++){
523 Double_t lowedge=Spectra[index]->GetBinLowEdge(ibin_data);
524 Double_t binwidth=Spectra[index]->GetBinWidth(ibin_data);
6da07d74 525 if(isample==0)TH1F *hToFit =(TH1F*) ((TH1F*)hman_data->GetDCAHistogram1D(Form("hHistPtRecSigma%s%s",Particle[ipart].Data(),Sign[icharge].Data()),lowedge,lowedge+binwidth))->Clone();
526 if(isample==1)TH1F *hToFit =(TH1F*) ((TH1F*)hman_mc->GetDCAHistogram1D(Form("hHistPtRecSigma%s%s",Particle[ipart].Data(),Sign[icharge].Data()),lowedge,lowedge+binwidth))->Clone();
527 TH1F *hmc1=(TH1F*) ((TH1F*)hman_mc->GetDCAHistogram1D(Form("hHistPtRecSigmaPrimary%s%s",Particle[ipart].Data(),Sign[icharge].Data()),lowedge,lowedge+binwidth))->Clone();
528 TH1F *hmc2=(TH1F*) ((TH1F*)hman_mc->GetDCAHistogram1D(Form("hHistPtRecSigmaSecondaryWeakDecay%s%s",Particle[ipart].Data(),Sign[icharge].Data()),lowedge,lowedge+binwidth))->Clone();
529 TH1F *hmc3=(TH1F*) ((TH1F*)hman_mc->GetDCAHistogram1D(Form("hHistPtRecSigmaSecondaryMaterial%s%s",Particle[ipart].Data(),Sign[icharge].Data()),lowedge,lowedge+binwidth))->Clone();
ae0fdd7d 530 Double_t minentries=1;
6da07d74 531 //if(hToFit->GetEntries()<=minentries || hmc1->GetEntries()<=minentries || hmc2->GetEntries()<=minentries || hmc3->GetEntries()<=minentries)continue;
00493191 532 // hmc1->Rebin(nrebin);
533 // hmc2->Rebin(nrebin);
534 // hmc3->Rebin(nrebin);
535 // hToFit->Rebin(nrebin);
624a6bb0 536 //Data and MC can have different stat
537 hToFit->Sumw2();
538 hmc1->Sumw2();
539 hmc2->Sumw2();
540 hmc3->Sumw2();
541 hToFit->Scale(1./hToFit->GetEntries());
542 Double_t normMC=hmc1->GetEntries()+hmc2->GetEntries()+hmc3->GetEntries();
543 hmc1->Scale(1./normMC);
544 hmc2->Scale(1./normMC);
545 hmc3->Scale(1./normMC);
546 cDCA->cd(ibin_data-5);
547 gPad->SetGridy();
548 gPad->SetGridx();
549 gPad->SetLogy();
550 hToFit->DrawClone("lhist");
551 hmc3->DrawClone("lhist");
552 TObjArray *mc = new TObjArray(3); // MC histograms are put in this array
553 mc->Add(hmc1);
554 mc->Add(hmc2);
555 mc->Add(hmc3);
556 TFractionFitter* fit = new TFractionFitter(hToFit,mc); // initialise
557 fit->Constrain(0,0.0,1.0); // constrain fraction 1 to be between 0 and 1
558 fit->Constrain(1,0.0,1.0); // constrain fraction 1 to be between 0 and 1
559 fit->Constrain(2,0.0,1.0); // constrain fraction 1 to be between 0 and 1
560 fit->SetRangeX(hToFit->GetXaxis()->FindBin(FitRange[0]),hToFit->GetXaxis()->FindBin(FitRange[1]));
561 hToFit->GetXaxis()->SetRange(hToFit->GetXaxis()->FindBin(FitRange[0]),hToFit->GetXaxis()->FindBin(FitRange[1]));
562 hToFit->SetTitle(Form("DCA distr - %s",sample[isample].Data()));
563 Int_t status = fit->Fit(); // perform the fit
564 cout << "fit status: " << status << endl;
565 if (status == 0) { // check on fit status
566 TH1F* result = (TH1F*) fit->GetPlot();
567 TH1F* PrimMCPred=(TH1F*)fit->GetMCPrediction(0);
568 TH1F* secStMCPred=(TH1F*)fit->GetMCPrediction(1);
569 TH1F* secMCPred=(TH1F*)fit->GetMCPrediction(2);
6da07d74 570
571 Double_t v1=0,v2=0,v3=0;
572 Double_t ev1=0,ev2=0,ev3=0;
573 //first method, use directly the fit result
574 fit->GetResult(0,v1,ev1);
575 fit->GetResult(1,v2,ev2);
576 fit->GetResult(2,v3,ev3);
577 result->Scale(hToFit->GetSumOfWeights()/result->GetSumOfWeights());
578 PrimMCPred->Scale(hToFit->GetSumOfWeights()*v1/PrimMCPred->GetSumOfWeights());
579 secStMCPred->Scale(hToFit->GetSumOfWeights()*v2/secStMCPred->GetSumOfWeights());
580 secMCPred->Scale(hToFit->GetSumOfWeights()*v3/secMCPred->GetSumOfWeights());
581 //second method, integrated the MC predisction, it should give the same as the first method
582 // v1=PrimMCPred->Integral();
583 // v2=secStMCPred->Integral();
584 // v3=secMCPred->Integral();
585 //Printf("\n\n\n\n\nv1:%f v2:%f v3:%f ev1:%f ev2:%f ev3:%f ",v1,v2,v3,ev1,ev2,ev3);
586 hcorrection[isample]->SetBinContent(ibin_data,v1/(v1+v2+v3));
587 hcorrection[isample]->SetBinError(ibin_data,0);
624a6bb0 588 //Drawing section
589 PrimMCPred->SetLineColor(2);
590 secStMCPred->SetLineColor(6);
591 secMCPred->SetLineColor(4);
6da07d74 592 hToFit->SetMinimum(0.0001);
624a6bb0 593 hToFit->DrawClone("lhist");
594 result->SetTitle("Fit result");
595 result->DrawClone("lhistsame");
596 PrimMCPred->DrawClone("lhistsame");
597 secStMCPred->DrawClone("lhistsame");
598 secMCPred->DrawClone("lhistsame");
624a6bb0 599 }
600 else{
601 hcorrection[isample]->SetBinContent(ibin_data,1);
602 hcorrection[isample]->SetBinError(ibin_data,0);
603 }
604 Printf("deleting");
605 delete hToFit;
606 }
ed06106e 607
624a6bb0 608 ccorrection->cd(icharge+1);
609 gPad->SetGridy();
610 gPad->SetGridx();
611 hcorrection[isample]->SetTitle(Form("DCA corr %s %s %s",Particle[ipart].Data(),Charge[icharge].Data(),sample[isample].Data()));
612 hcorrection[isample]->SetLineWidth(2);
613 hcorrection[isample]->SetLineColor(Color[ipart]);
614 hcorrection[isample]->SetLineStyle(isample+1);
615 hcorrection[isample]->SetMarkerColor(Color[ipart]);
616 hcorrection[isample]->GetXaxis()->SetRangeUser(0.2,2.5);
617 if(ipart==0 && isample==0)hcorrection[isample]->DrawClone("lhist");
618 else hcorrection[isample]->DrawClone("lhistsame");
619 // smooth the DCA correction
6da07d74 620 // TF1 *fitfun = new TF1("fitfun","[0]+[1]*x^[2]+[3]*x^[4]",0.2,2.5);
621 // hcorrection[isample]->Fit(fitfun,"WRN","N",0.35,2);
624a6bb0 622 // fitfun->SetLineWidth(1.5);
6da07d74 623 // fitfun->SetLineColor(Color[ipart]);
624 // fitfun->SetLineStyle(isample);
624a6bb0 625 // fitfun->DrawClone("same");
626 // for(Int_t ibin=1;ibin<30;ibin++){
6da07d74 627 // hcorrection[isample]->SetBinContent(ibin,fitfun->Eval(hcorrection[isample]->GetBinCenter(ibin)));
624a6bb0 628 // }
00493191 629 fout->cd();
630 cDCA->Write();
624a6bb0 631 }
632 Spectra[index]->Multiply(hcorrection[0]);//multiply for data
ed06106e 633 Printf("DCACorrection for DATA used: Spectra[index]->Multiply(hcorrection[0])")
634 if(UseMCDCACorrection){
635 Spectra[index]->Divide(hcorrection[1]); //divide by Monte Carlo
636 Printf("DCACorrection for MC used: Spectra[index]->Divide(hcorrection[1]")
637 }
6da07d74 638 cRatiocorrection->cd(icharge+1);
639 gPad->SetGridy();
640 gPad->SetGridx();
641 hcorrection[0]->Divide(hcorrection[1]);
642 if(ipart==0)hcorrection[0]->DrawClone("lhist");
643 else hcorrection[0]->DrawClone("lhistsame");
624a6bb0 644 }
645 }
646 ccorrection->cd(1);
972a21ad 647 gPad->BuildLegend()->SetFillColor(0);
624a6bb0 648 ccorrection->cd(2);
972a21ad 649 gPad->BuildLegend()->SetFillColor(0);
00493191 650 fout->cd();
651 cRatiocorrection->Write();
652 ccorrection->Write();
624a6bb0 653}
654
655
6da07d74 656//////////////
657
658Double_t eta2y(Double_t pt, Double_t mass, Double_t eta){
659 Double_t mt = TMath::Sqrt(mass * mass + pt * pt);
660 return TMath::ASinH(pt / mt * TMath::SinH(eta));
661}
662///////////////////////
00493191 663void GFCorrection(TH1F **Spectra,AliSpectraAODTrackCuts* tcuts_data, TFile * fout){
6da07d74 664 //Geant/Fluka Correction
665 Printf("\nGF correction for Kaons");
666 //Getting GF For Kaons in TPC
667 TGraph *gGFCorrectionKaonPlus=new TGraph();
668 gGFCorrectionKaonPlus->SetName("gGFCorrectionKaonPlus");
669 gGFCorrectionKaonPlus->SetTitle("gGFCorrectionKaonPlus");
670 TGraph *gGFCorrectionKaonMinus=new TGraph();
671 gGFCorrectionKaonMinus->SetName("gGFCorrectionKaonMinus");
672 gGFCorrectionKaonMinus->SetTitle("gGFCorrectionKaonMinus");
673 TString fnameGeanFlukaK="GFCorrection/correctionForCrossSection.321.root";
674 TFile *fGeanFlukaK= new TFile(fnameGeanFlukaK.Data());
675 TH1F *hGeantFlukaKPos=(TH1F*)fGeanFlukaK->Get("gHistCorrectionForCrossSectionParticles");
676 TH1F *hGeantFlukaKNeg=(TH1F*)fGeanFlukaK->Get("gHistCorrectionForCrossSectionAntiParticles");
677 //getting GF func for Kaons with TOF
678 TF1 *fGFKPosTracking;
679 fGFKPosTracking = TrackingEff_geantflukaCorrection(3,kPositive);
680 TF1 *fGFKNegTracking;
681 fGFKNegTracking = TrackingEff_geantflukaCorrection(3,kNegative);
682 TF1 *fGFKPosMatching;
683 fGFKPosMatching = TOFmatchMC_geantflukaCorrection(3,kPositive);
684 TF1 *fGFKNegMatching;
685 fGFKNegMatching = TOFmatchMC_geantflukaCorrection(3,kNegative);
686 for(Int_t binK=0;binK<=Spectra[1]->GetNbinsX();binK++){
687 if(Spectra[1]->GetBinCenter(binK)<tcuts_data->GetPtTOFMatching()){//use TPC GeantFlukaCorrection
688 Float_t FlukaCorrKPos=hGeantFlukaKPos->GetBinContent(hGeantFlukaKPos->FindBin(Spectra[1]->GetBinCenter(binK)));
689 Float_t FlukaCorrKNeg=hGeantFlukaKNeg->GetBinContent(hGeantFlukaKNeg->FindBin(Spectra[4]->GetBinCenter(binK)));
690 Printf("TPC Geant/Fluka: pt:%f Pos:%f Neg:%f",Spectra[1]->GetBinCenter(binK),FlukaCorrKPos,FlukaCorrKNeg);
691 Spectra[1]->SetBinContent(binK,Spectra[1]->GetBinContent(binK)*FlukaCorrKPos);
692 Spectra[4]->SetBinContent(binK,Spectra[4]->GetBinContent(binK)*FlukaCorrKNeg);
693 Spectra[1]->SetBinError(binK,Spectra[1]->GetBinError(binK)*FlukaCorrKPos);
694 Spectra[4]->SetBinError(binK,Spectra[4]->GetBinError(binK)*FlukaCorrKNeg);
695 gGFCorrectionKaonPlus->SetPoint(binK,Spectra[1]->GetBinCenter(binK),FlukaCorrKPos);
696 gGFCorrectionKaonMinus->SetPoint(binK,Spectra[4]->GetBinCenter(binK),FlukaCorrKNeg);
697 }else{
698 gGFCorrectionKaonPlus->SetPoint(binK,Spectra[1]->GetBinCenter(binK),0);
699 gGFCorrectionKaonMinus->SetPoint(binK,Spectra[4]->GetBinCenter(binK),0);
700 Float_t FlukaCorrKPosTracking=fGFKPosTracking->Eval(Spectra[1]->GetBinCenter(binK));
701 Float_t FlukaCorrKNegTracking=fGFKNegTracking->Eval(Spectra[1]->GetBinCenter(binK));
702 Printf("TPC/TOF Geant/Fluka Tracking: pt:%f Pos:%f Neg:%f",Spectra[1]->GetBinCenter(binK),FlukaCorrKPosTracking,FlukaCorrKNegTracking);
703 Spectra[1]->SetBinContent(binK,Spectra[1]->GetBinContent(binK)*FlukaCorrKPosTracking);
704 Spectra[4]->SetBinContent(binK,Spectra[4]->GetBinContent(binK)*FlukaCorrKNegTracking);
705 Spectra[1]->SetBinError(binK,Spectra[1]->GetBinError(binK)*FlukaCorrKPosTracking);
706 Spectra[4]->SetBinError(binK,Spectra[4]->GetBinError(binK)*FlukaCorrKNegTracking);
707 Float_t FlukaCorrKPosMatching=fGFKPosMatching->Eval(Spectra[1]->GetBinCenter(binK));
708 Float_t FlukaCorrKNegMatching=fGFKNegMatching->Eval(Spectra[1]->GetBinCenter(binK));
709 Printf("TPC/TOF Geant/Fluka Matching: pt:%f Pos:%f Neg:%f",Spectra[1]->GetBinCenter(binK),FlukaCorrKPosMatching,FlukaCorrKNegMatching);
710 Spectra[1]->SetBinContent(binK,Spectra[1]->GetBinContent(binK)*FlukaCorrKPosMatching);
711 Spectra[4]->SetBinContent(binK,Spectra[4]->GetBinContent(binK)*FlukaCorrKNegMatching);
712 Spectra[1]->SetBinError(binK,Spectra[1]->GetBinError(binK)*FlukaCorrKPosMatching);
713 Spectra[4]->SetBinError(binK,Spectra[4]->GetBinError(binK)*FlukaCorrKNegMatching);
714 }
715 }
716
717 //Geant Fluka for P in TPC
718 Printf("\nGF correction for Protons");
719 const Int_t kNCharge=2;
720 Int_t kPos=0;
721 Int_t kNeg=1;
722 TFile* fGFProtons = new TFile ("GFCorrection/correctionForCrossSection.root");
723 TH2D * hCorrFluka[kNCharge];
724 TH2D * hCorrFluka[2];
725 hCorrFluka[kPos] = (TH2D*)fGFProtons->Get("gHistCorrectionForCrossSectionProtons");
726 hCorrFluka[kNeg] = (TH2D*)fGFProtons->Get("gHistCorrectionForCrossSectionAntiProtons");
727 TGraph *gGFCorrectionProtonPlus=new TGraph();
728 gGFCorrectionProtonPlus->SetName("gGFCorrectionProtonPlus");
729 gGFCorrectionProtonPlus->SetTitle("gGFCorrectionProtonPlus");
730 TGraph *gGFCorrectionProtonMinus=new TGraph();
731 gGFCorrectionProtonMinus->SetName("gGFCorrectionProtonMinus");
732 gGFCorrectionProtonMinus->SetTitle("gGFCorrectionProtonMinus");
00493191 733 //getting GF func for Kaons with TPCTOF
6da07d74 734 TF1 *fGFpPosTracking;
735 fGFpPosTracking = TrackingEff_geantflukaCorrection(4,kPositive);
736 TF1 *fGFpNegTracking;
737 fGFpNegTracking = TrackingEff_geantflukaCorrection(4,kNegative);
738 TF1 *fGFpPosMatching;
739 fGFpPosMatching = TOFmatchMC_geantflukaCorrection(4,kPositive);
740 TF1 *fGFpNegMatching;
741 fGFpNegMatching = TOFmatchMC_geantflukaCorrection(4,kNegative);
742
743 for(Int_t icharge = 0; icharge < kNCharge; icharge++){
744 Int_t nbins = Spectra[2]->GetNbinsX();
745 Int_t nbinsy=hCorrFluka[icharge]->GetNbinsY();
746 for(Int_t ibin = 0; ibin < nbins; ibin++){
747 if(Spectra[2]->GetBinCenter(ibin)<tcuts_data->GetPtTOFMatching()){//use TPC GeantFlukaCorrection
00493191 748 Float_t pt = Spectra[2]->GetBinCenter(ibin);
749 Float_t minPtCorrection = hCorrFluka[icharge]->GetYaxis()->GetBinLowEdge(1);
750 Float_t maxPtCorrection = hCorrFluka[icharge]->GetYaxis()->GetBinLowEdge(nbinsy+1);
751 if (pt < minPtCorrection) pt = minPtCorrection+0.0001;
752 if (pt > maxPtCorrection) pt = maxPtCorrection;
753 Float_t correction = hCorrFluka[icharge]->GetBinContent(1,hCorrFluka[icharge]->GetYaxis()->FindBin(pt));
754 //cout<<correction<<" charge "<<icharge<<endl;
755 if(icharge==0){
756 if (correction != 0) {// If the bin is empty this is a 0
757 Spectra[2]->SetBinContent(ibin,Spectra[2]->GetBinContent(ibin)*correction);
758 Spectra[2]->SetBinError(ibin,Spectra[2]->GetBinError (ibin)*correction);
759 gGFCorrectionProtonPlus->SetPoint(ibin,pt,correction);
760 }else if (Spectra[2]->GetBinContent(ibin) > 0) { // If we are skipping a non-empty bin, we notify the user
761 cout << "Fluka/GEANT: Not correcting bin "<<ibin << " for protons secondaries, Pt:"<< pt<< endl;
762 cout << " Bin content: " << Spectra[2]->GetBinContent(ibin) << endl;
763 }
764 }
765 if(icharge==1){
766 if (correction != 0) {// If the bin is empty this is a 0
767 Spectra[5]->SetBinContent(ibin,Spectra[5]->GetBinContent(ibin)*correction);
768 Spectra[5]->SetBinError(ibin,Spectra[5]->GetBinError (ibin)*correction);
769 gGFCorrectionProtonMinus->SetPoint(ibin,pt,correction);
770 }else if (Spectra[5]->GetBinContent(ibin) > 0) { // If we are skipping a non-empty bin, we notify the user
771 cout << "Fluka/GEANT: Not correcting bin "<<ibin << " for Antiprotons secondaries, Pt:"<< pt<< endl;
772 cout << " Bin content: " << Spectra[5]->GetBinContent(ibin) << endl;
773 }
774 }
6da07d74 775 }else{
ae0fdd7d 776 gGFCorrectionProtonPlus->SetPoint(ibin,Spectra[2]->GetBinCenter(ibin),0);
777 gGFCorrectionProtonMinus->SetPoint(ibin,Spectra[5]->GetBinCenter(ibin),0);
778 Float_t FlukaCorrpPosTracking=fGFpPosTracking->Eval(Spectra[2]->GetBinCenter(ibin));
779 Float_t FlukaCorrpNegTracking=fGFpNegTracking->Eval(Spectra[2]->GetBinCenter(ibin));
780 Printf("TPC/TOF Geant/Fluka Tracking: pt:%f Pos:%f Neg:%f",Spectra[2]->GetBinCenter(ibin),FlukaCorrpPosTracking,FlukaCorrpNegTracking);
781 Spectra[2]->SetBinContent(ibin,Spectra[2]->GetBinContent(ibin)*FlukaCorrpPosTracking);
782 Spectra[5]->SetBinContent(ibin,Spectra[5]->GetBinContent(ibin)*FlukaCorrpNegTracking);
783 Spectra[2]->SetBinError(ibin,Spectra[2]->GetBinError(ibin)*FlukaCorrpPosTracking);
784 Spectra[5]->SetBinError(ibin,Spectra[5]->GetBinError(ibin)*FlukaCorrpNegTracking);
785 Float_t FlukaCorrpPosMatching=fGFpPosMatching->Eval(Spectra[2]->GetBinCenter(ibin));
786 Float_t FlukaCorrpNegMatching=fGFpNegMatching->Eval(Spectra[2]->GetBinCenter(ibin));
787 Printf("TPC/TOF Geant/Fluka Matching: pt:%f Pos:%f Neg:%f",Spectra[2]->GetBinCenter(ibin),FlukaCorrpPosMatching,FlukaCorrpNegMatching);
788 Spectra[2]->SetBinContent(ibin,Spectra[2]->GetBinContent(ibin)*FlukaCorrpPosMatching);
789 Spectra[5]->SetBinContent(ibin,Spectra[5]->GetBinContent(ibin)*FlukaCorrpNegMatching);
790 Spectra[2]->SetBinError(ibin,Spectra[2]->GetBinError(ibin)*FlukaCorrpPosMatching);
791 Spectra[5]->SetBinError(ibin,Spectra[5]->GetBinError(ibin)*FlukaCorrpNegMatching);
6da07d74 792 }
793 }//end loop on bins
794 }
795 gGFCorrectionKaonPlus->SetLineColor(kRed);
796 gGFCorrectionKaonMinus->SetLineColor(kRed+2);
797 gGFCorrectionProtonPlus->SetLineColor(kGreen);
798 gGFCorrectionProtonMinus->SetLineColor(kGreen+2);
799 fGFKPosTracking->SetLineColor(kRed);
800 fGFKNegTracking->SetLineColor(kRed+2);
801 fGFKPosMatching->SetLineColor(kRed);
802 fGFKNegMatching->SetLineColor(kRed+2);
803 fGFpPosTracking->SetLineColor(kGreen);
804 fGFpNegTracking->SetLineColor(kGreen+2);
805 fGFpPosMatching->SetLineColor(kGreen);
806 fGFpNegMatching->SetLineColor(kGreen+2);
807 fGFKPosTracking->SetLineStyle(2);
808 fGFKNegTracking->SetLineStyle(2);
809 fGFKPosMatching->SetLineStyle(3);
810 fGFKNegMatching->SetLineStyle(3);
811 fGFpPosTracking->SetLineStyle(2);
812 fGFpNegTracking->SetLineStyle(2);
813 fGFpPosMatching->SetLineStyle(3);
814 fGFpNegMatching->SetLineStyle(3);
815 fGFKPosTracking->SetRange(.6,5);
816 fGFKNegTracking->SetRange(.6,5);
817 fGFKPosMatching->SetRange(.6,5);
818 fGFKNegMatching->SetRange(.6,5);
819 fGFpPosTracking->SetRange(.6,5);
820 fGFpNegTracking->SetRange(.6,5);
821 fGFpPosMatching->SetRange(.6,5);
822 fGFpNegMatching->SetRange(.6,5);
823
00493191 824 TCanvas * cGFCorrection = new TCanvas ("GFCorrection","GFCorrection",700,500);
6da07d74 825 gPad->SetGridx();
826 gPad->SetGridy();
827 gGFCorrectionKaonPlus->DrawClone("al");
828 gGFCorrectionKaonMinus->DrawClone("lsame");
829 gGFCorrectionProtonPlus->DrawClone("lsame");
830 gGFCorrectionProtonMinus->DrawClone("lsame");
831 fGFKPosTracking->DrawClone("lsame");
832 fGFKNegTracking->DrawClone("lsame");
833 fGFKPosMatching->DrawClone("lsame");
834 fGFKNegMatching->DrawClone("lsame");
835 fGFpPosTracking->DrawClone("lsame");
836 fGFpNegTracking->DrawClone("lsame");
837 fGFpPosMatching->DrawClone("lsame");
838 fGFpNegMatching->DrawClone("lsame");
972a21ad 839 gPad->BuildLegend()->SetFillColor(0);
00493191 840 fout->cd();
841 cGFCorrection->Write();
6da07d74 842}
843
844
845
846///////////
847TF1 *
848TrackingEff_geantflukaCorrection(Int_t ipart, Int_t icharge)
849{
850
851 if (ipart == 3 && icharge == kNegative) {
852 TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "TrackingPtGeantFlukaCorrectionKaMinus(x)", 0., 5.);
853 return f;
854 }
855 else if (ipart == 4 && icharge == kNegative) {
856 TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "TrackingPtGeantFlukaCorrectionPrMinus(x)", 0., 5.);
857 }
858 else
859 TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "TrackingPtGeantFlukaCorrectionNull(x)", 0., 5.);
860
861 return f;
862}
863
864Double_t
865TrackingPtGeantFlukaCorrectionNull(Double_t pTmc)
866{
867 return 1.;
868}
869
870Double_t
871TrackingPtGeantFlukaCorrectionPrMinus(Double_t pTmc)
872{
873 return (1 - 0.129758 *TMath::Exp(-pTmc*0.679612));
874}
875
876Double_t
877TrackingPtGeantFlukaCorrectionKaMinus(Double_t pTmc)
878{
879 return TMath::Min((0.972865 + 0.0117093*pTmc), 1.);
880}
881///////////////////////////////////////////
882TF1 *
883TOFmatchMC_geantflukaCorrection(Int_t ipart, Int_t icharge)
884{
885
886 if (ipart == 3 && icharge == kNegative) {
887 TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "MatchingPtGeantFlukaCorrectionKaMinus(x)", 0., 5.);
888 return f;
889 }
890 else if (ipart == 4 && icharge == kNegative) {
891 TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "MatchingPtGeantFlukaCorrectionPrMinus(x)", 0., 5.);
892 }
893 else
894 TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "MatchingPtGeantFlukaCorrectionNull(x)", 0., 5.);
895
896 return f;
897}
898
899
900Double_t
901MatchingPtGeantFlukaCorrectionNull(Double_t pTmc)
902{
903 return 1.;
904}
905
906Double_t
907MatchingPtGeantFlukaCorrectionPrMinus(Double_t pTmc)
908{
909 Float_t ptTPCoutP =pTmc*(1-6.81059e-01*TMath::Exp(-pTmc*4.20094));
910 return (TMath::Power(1 - 0.129758*TMath::Exp(-ptTPCoutP*0.679612),0.07162/0.03471));
911}
912
913Double_t
914MatchingPtGeantFlukaCorrectionKaMinus(Double_t pTmc)
915{
916 Float_t ptTPCoutK=pTmc*(1- 3.37297e-03/pTmc/pTmc - 3.26544e-03/pTmc);
917 return TMath::Min((TMath::Power(0.972865 + 0.0117093*ptTPCoutK,0.07162/0.03471)), 1.);
918}