1 // *************************************************************************
3 // * corrections to Fragmentation Functions *
5 // *************************************************************************
8 /**************************************************************************
9 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
11 * Author: The ALICE Off-line Project. *
12 * Contributors are mentioned in the code where appropriate. *
14 * Permission to use, copy, modify and distribute this software and its *
15 * documentation strictly for non-commercial purposes is hereby granted *
16 * without fee, provided that the above copyright notice appears in all *
17 * copies and that both the copyright notice and this permission notice *
18 * appear in the supporting documentation. The authors make no claims *
19 * about the suitability of this software for any purpose. It is *
20 * provided "as is" without express or implied warranty. *
21 **************************************************************************/
27 #include "THnSparse.h"
29 #include "TDirectory.h"
30 #include "AliCFUnfolding.h"
31 #include "AliFragmentationFunctionCorrections.h"
33 ///////////////////////////////////////////////////////////////////////////////
35 // correction class for ouput of AliAnalysisTaskFragmentationFunction //
37 // corrections for: reconstruction efficiency, momentum resolution, //
38 // secondaries, UE / HI background, fluctuations //
39 // back-correction on jet energy on dN/dxi //
41 // read MC ouput and write out efficiency histos, response matrices etc. //
42 // read measured distributions and apply efficiency, response matrices etc. //
44 // contact: o.busch@gsi.de //
46 ///////////////////////////////////////////////////////////////////////////////
49 ClassImp(AliFragmentationFunctionCorrections)
51 //________________________________________________________________________
52 AliFragmentationFunctionCorrections::AliFragmentationFunctionCorrections()
59 ,fNHistoBinsSinglePt(0)
60 ,fHistoBinsSinglePt(0)
67 ,fNCorrectionLevels(0)
69 ,fNCorrectionLevelsBgr(0)
71 ,fNCorrectionLevelsSinglePt(0)
81 ,fh1FFTrackPtBackFolded(0)
84 ,fh1FFRatioTrackPtFolded(0)
86 ,fh1FFRatioXiFolded(0)
87 ,fh1FFRatioTrackPtBackFolded(0)
88 ,fh1FFRatioZBackFolded(0)
89 ,fh1FFRatioXiBackFolded(0)
90 ,fh1SingleTrackPtBackFolded(0)
91 ,fh1RatioSingleTrackPtFolded(0)
92 ,fh1RatioSingleTrackPtBackFolded(0)
93 ,fhnResponseSinglePt(0)
100 ,fh1SecCorrSinglePt(0)
102 // default constructor
105 //________________________________________________________________________________________________________________________
106 AliFragmentationFunctionCorrections::AliFragmentationFunctionCorrections(const AliFragmentationFunctionCorrections ©)
109 ,fNJetPtSlices(copy.fNJetPtSlices)
110 ,fJetPtSlices(copy.fJetPtSlices)
112 ,fNJetsBgr(copy.fNJetsBgr)
113 ,fNHistoBinsSinglePt(copy.fNHistoBinsSinglePt)
114 ,fHistoBinsSinglePt(copy.fHistoBinsSinglePt)
115 ,fNHistoBinsPt(copy.fNHistoBinsPt)
116 ,fNHistoBinsZ(copy.fNHistoBinsZ)
117 ,fNHistoBinsXi(copy.fNHistoBinsXi)
118 ,fHistoBinsPt(copy.fHistoBinsPt)
119 ,fHistoBinsZ(copy.fHistoBinsZ)
120 ,fHistoBinsXi(copy.fHistoBinsXi)
121 ,fNCorrectionLevels(copy.fNCorrectionLevels)
122 ,fCorrFF(copy.fCorrFF)
123 ,fNCorrectionLevelsBgr(copy.fNCorrectionLevelsBgr)
124 ,fCorrBgr(copy.fCorrBgr)
125 ,fNCorrectionLevelsSinglePt(copy.fNCorrectionLevelsSinglePt)
126 ,fCorrSinglePt(copy.fCorrSinglePt)
127 ,fh1FFXiShift(copy.fh1FFXiShift)
128 ,fh1EffSinglePt(copy.fh1EffSinglePt)
129 ,fh1EffPt(copy.fh1EffPt)
130 ,fh1EffZ(copy.fh1EffZ)
131 ,fh1EffXi(copy.fh1EffXi)
132 ,fh1EffBgrPt(copy.fh1EffBgrPt)
133 ,fh1EffBgrZ(copy.fh1EffBgrZ)
134 ,fh1EffBgrXi(copy.fh1EffBgrXi)
135 ,fh1FFTrackPtBackFolded(copy.fh1FFTrackPtBackFolded)
136 ,fh1FFZBackFolded(copy.fh1FFZBackFolded)
137 ,fh1FFXiBackFolded(copy.fh1FFXiBackFolded)
138 ,fh1FFRatioTrackPtFolded(copy.fh1FFRatioTrackPtFolded)
139 ,fh1FFRatioZFolded(copy.fh1FFRatioZFolded)
140 ,fh1FFRatioXiFolded(copy.fh1FFRatioXiFolded)
141 ,fh1FFRatioTrackPtBackFolded(copy.fh1FFRatioTrackPtBackFolded)
142 ,fh1FFRatioZBackFolded(copy.fh1FFRatioZBackFolded)
143 ,fh1FFRatioXiBackFolded(copy.fh1FFRatioXiBackFolded)
144 ,fh1SingleTrackPtBackFolded(copy.fh1SingleTrackPtBackFolded)
145 ,fh1RatioSingleTrackPtFolded(copy.fh1RatioSingleTrackPtFolded)
146 ,fh1RatioSingleTrackPtBackFolded(copy.fh1RatioSingleTrackPtBackFolded)
147 ,fhnResponseSinglePt(copy.fhnResponseSinglePt)
148 ,fhnResponsePt(copy.fhnResponsePt)
149 ,fhnResponseZ(copy.fhnResponseZ)
150 ,fhnResponseXi(copy.fhnResponseXi)
151 ,fh1FFTrackPtPrior(copy.fh1FFTrackPtPrior)
152 ,fh1FFZPrior(copy.fh1FFZPrior)
153 ,fh1FFXiPrior(copy.fh1FFXiPrior)
154 ,fh1SecCorrSinglePt(copy.fh1SecCorrSinglePt)
160 // ______________________________________________________________________________________________________________________________
161 AliFragmentationFunctionCorrections& AliFragmentationFunctionCorrections::operator=(const AliFragmentationFunctionCorrections& o)
166 TObject::operator=(o);
168 fNJetPtSlices = o.fNJetPtSlices;
169 fJetPtSlices = o.fJetPtSlices;
171 fNJetsBgr = o.fNJetsBgr;
172 fNHistoBinsSinglePt = o.fNHistoBinsSinglePt;
173 fHistoBinsSinglePt = o.fHistoBinsSinglePt;
174 fNHistoBinsPt = o.fNHistoBinsPt;
175 fNHistoBinsZ = o.fNHistoBinsZ;
176 fNHistoBinsXi = o.fNHistoBinsXi;
177 fHistoBinsPt = o.fHistoBinsPt;
178 fHistoBinsZ = o.fHistoBinsZ;
179 fHistoBinsXi = o.fHistoBinsXi;
180 fNCorrectionLevels = o.fNCorrectionLevels;
182 fNCorrectionLevelsBgr = o.fNCorrectionLevelsBgr;
183 fCorrBgr = o.fCorrBgr;
184 fNCorrectionLevelsSinglePt = o.fNCorrectionLevelsSinglePt;
185 fCorrSinglePt = o.fCorrSinglePt;
186 fh1FFXiShift = o.fh1FFXiShift;
187 fh1EffSinglePt = o.fh1EffSinglePt;
188 fh1EffPt = o.fh1EffPt;
190 fh1EffXi = o.fh1EffXi;
191 fh1EffBgrPt = o.fh1EffBgrPt;
192 fh1EffBgrZ = o.fh1EffBgrZ;
193 fh1EffBgrXi = o.fh1EffBgrXi;
194 fh1FFTrackPtBackFolded = o.fh1FFTrackPtBackFolded;
195 fh1FFZBackFolded = o.fh1FFZBackFolded;
196 fh1FFXiBackFolded = o.fh1FFXiBackFolded;
197 fh1FFRatioTrackPtFolded = o.fh1FFRatioTrackPtFolded;
198 fh1FFRatioZFolded = o.fh1FFRatioZFolded;
199 fh1FFRatioXiFolded = o.fh1FFRatioXiFolded;
200 fh1FFRatioTrackPtBackFolded = o.fh1FFRatioTrackPtBackFolded;
201 fh1FFRatioZBackFolded = o.fh1FFRatioZBackFolded;
202 fh1FFRatioXiBackFolded = o.fh1FFRatioXiBackFolded;
203 fh1SingleTrackPtBackFolded = o.fh1SingleTrackPtBackFolded;
204 fh1RatioSingleTrackPtFolded = o.fh1RatioSingleTrackPtFolded;
205 fh1RatioSingleTrackPtBackFolded = o.fh1RatioSingleTrackPtBackFolded;
206 fhnResponseSinglePt = o.fhnResponseSinglePt;
207 fhnResponsePt = o.fhnResponsePt;
208 fhnResponseZ = o.fhnResponseZ;
209 fhnResponseXi = o.fhnResponseXi;
210 fh1FFTrackPtPrior = o.fh1FFTrackPtPrior;
211 fh1FFZPrior = o.fh1FFZPrior;
212 fh1FFXiPrior = o.fh1FFXiPrior;
213 fh1SecCorrSinglePt = o.fh1SecCorrSinglePt;
219 //_________________________________________________________________________
220 AliFragmentationFunctionCorrections::~AliFragmentationFunctionCorrections()
224 if(fJetPtSlices) delete fJetPtSlices;
225 if(fNJets) delete fNJets;
226 if(fNJetsBgr) delete fNJetsBgr;
228 DeleteHistoArray(fh1FFXiShift);
230 DeleteHistoArray(fh1EffPt);
231 DeleteHistoArray(fh1EffXi);
232 DeleteHistoArray(fh1EffZ );
234 DeleteHistoArray(fh1EffBgrPt);
235 DeleteHistoArray(fh1EffBgrXi);
236 DeleteHistoArray(fh1EffBgrZ);
240 DeleteHistoArray(fh1FFTrackPtBackFolded);
241 DeleteHistoArray(fh1FFZBackFolded);
242 DeleteHistoArray(fh1FFXiBackFolded);
244 DeleteHistoArray(fh1FFRatioTrackPtFolded);
245 DeleteHistoArray(fh1FFRatioZFolded);
246 DeleteHistoArray(fh1FFRatioXiFolded);
248 DeleteHistoArray(fh1FFRatioTrackPtBackFolded);
249 DeleteHistoArray(fh1FFRatioZBackFolded);
250 DeleteHistoArray(fh1FFRatioXiBackFolded);
252 DeleteTHnSparseArray(fhnResponsePt);
253 DeleteTHnSparseArray(fhnResponseZ);
254 DeleteTHnSparseArray(fhnResponseXi);
256 DeleteHistoArray(fh1FFTrackPtPrior);
257 DeleteHistoArray(fh1FFZPrior);
258 DeleteHistoArray(fh1FFXiPrior);
261 // clean up corrected FF
263 for(Int_t c=0; c<fNCorrectionLevels; c++) delete fCorrFF[c];
268 for(Int_t c=0; c<fNCorrectionLevelsBgr; c++) delete fCorrBgr[c];
271 // clean up inclusive pt
272 for(Int_t c=0; c<fNCorrectionLevelsSinglePt; c++) delete fCorrSinglePt[c];
273 delete[] fCorrSinglePt;
275 delete[] fNHistoBinsPt;
276 delete[] fNHistoBinsZ;
277 delete[] fNHistoBinsXi;
279 // clean up histo bins
281 if(fHistoBinsSinglePt) delete fHistoBinsSinglePt;
283 for(Int_t i=0; i<fNJetPtSlices; i++) delete fHistoBinsPt[i];
284 for(Int_t i=0; i<fNJetPtSlices; i++) delete fHistoBinsZ[i];
285 for(Int_t i=0; i<fNJetPtSlices; i++) delete fHistoBinsXi[i];
287 delete[] fHistoBinsPt;
288 delete[] fHistoBinsZ;
289 delete[] fHistoBinsXi;
292 //_________________________________________________________________________________
293 AliFragmentationFunctionCorrections::AliFragFuncCorrHistos::AliFragFuncCorrHistos()
301 // default constructor
305 //__________________________________________________________________________________________________________________
306 AliFragmentationFunctionCorrections::AliFragFuncCorrHistos::AliFragFuncCorrHistos(const AliFragFuncCorrHistos& copy)
308 ,fArraySize(copy.fArraySize)
309 ,fh1CorrFFTrackPt(copy.fh1CorrFFTrackPt)
310 ,fh1CorrFFZ(copy.fh1CorrFFZ)
311 ,fh1CorrFFXi(copy.fh1CorrFFXi)
312 ,fCorrLabel(copy.fCorrLabel)
315 for(Int_t i=0; i<copy.fArraySize; i++){
316 fh1CorrFFTrackPt[i] = copy.fh1CorrFFTrackPt[i];
317 fh1CorrFFZ[i] = copy.fh1CorrFFZ[i];
318 fh1CorrFFXi[i] = copy.fh1CorrFFXi[i];
322 //_______________________________________________________________________________________________________________________________________________________________
323 AliFragmentationFunctionCorrections::AliFragFuncCorrHistos& AliFragmentationFunctionCorrections::AliFragFuncCorrHistos::operator=(const AliFragmentationFunctionCorrections::AliFragFuncCorrHistos& o)
328 TObject::operator=(o);
329 fArraySize = o.fArraySize;
330 fCorrLabel = o.fCorrLabel;
332 for(Int_t i=0; i<o.fArraySize; i++){
333 fh1CorrFFTrackPt[i] = o.fh1CorrFFTrackPt[i];
334 fh1CorrFFZ[i] = o.fh1CorrFFZ[i];
335 fh1CorrFFXi[i] = o.fh1CorrFFXi[i];
342 //__________________________________________________________________________________
343 AliFragmentationFunctionCorrections::AliFragFuncCorrHistos::~AliFragFuncCorrHistos()
348 for(int i=0; i<fArraySize; i++) delete fh1CorrFFTrackPt[i];
349 for(int i=0; i<fArraySize; i++) delete fh1CorrFFZ[i];
350 for(int i=0; i<fArraySize; i++) delete fh1CorrFFXi[i];
353 if(fh1CorrFFTrackPt) delete[] fh1CorrFFTrackPt;
354 if(fh1CorrFFZ) delete[] fh1CorrFFZ;
355 if(fh1CorrFFXi) delete[] fh1CorrFFXi;
359 //___________________________________________________________________________________________________________________
360 AliFragmentationFunctionCorrections::AliFragFuncCorrHistos::AliFragFuncCorrHistos(const char* label, Int_t arraySize)
370 fArraySize = arraySize;
371 fh1CorrFFTrackPt = new TH1F*[arraySize];
372 fh1CorrFFZ = new TH1F*[arraySize];
373 fh1CorrFFXi = new TH1F*[arraySize];
375 for(int i=0; i<arraySize; i++) fh1CorrFFTrackPt[i] = new TH1F;
376 for(int i=0; i<arraySize; i++) fh1CorrFFZ[i] = new TH1F;
377 for(int i=0; i<arraySize; i++) fh1CorrFFXi[i] = new TH1F;
380 //_______________________________________________________________________________________________________________________________
381 void AliFragmentationFunctionCorrections::AliFragFuncCorrHistos::AddCorrHistos(Int_t slice,TH1F* histPt,TH1F* histZ,TH1F* histXi)
383 // place histo in array, add corrLabel to histo name
385 if(slice>=fArraySize){
386 Printf("%s:%d -- slice > array size", (char*)__FILE__,__LINE__);
391 TString name = histPt->GetName();
392 if(fCorrLabel.Length()>0) name += "_"+fCorrLabel;
393 histPt->SetName(name);
395 if(!(histPt->GetSumw2())) histPt->Sumw2();
397 new(fh1CorrFFTrackPt[slice]) TH1F(*histPt);
401 TString name = histZ->GetName();
402 if(fCorrLabel.Length()>0) name += "_"+fCorrLabel;
403 histZ->SetName(name);
405 if(!(histZ->GetSumw2())) histZ->Sumw2();
407 new(fh1CorrFFZ[slice]) TH1F(*histZ);
411 TString name = histXi->GetName();
412 if(fCorrLabel.Length()>0) name += "_"+fCorrLabel;
413 histXi->SetName(name);
415 if(!(histXi->GetSumw2())) histXi->Sumw2();
417 new(fh1CorrFFXi[slice]) TH1F(*histXi);
421 //___________________________________________________________________________________________________________________________________
422 void AliFragmentationFunctionCorrections::AliFragFuncCorrHistos::ReplaceCorrHistos(Int_t slice,TH1F* histPt,TH1F* histZ,TH1F* histXi)
424 // replace histo in array
426 if(slice>=fArraySize){
427 Printf("%s:%d -- slice > array size", (char*)__FILE__,__LINE__);
432 if(!(histPt->GetSumw2())) histPt->Sumw2();
434 TString name = histPt->GetName();
435 histPt->SetName(name);
437 delete fh1CorrFFTrackPt[slice];
438 fh1CorrFFTrackPt[slice] = new TH1F;
439 new(fh1CorrFFTrackPt[slice]) TH1F(*histPt);
443 if(!(histZ->GetSumw2())) histZ->Sumw2();
445 TString name = histZ->GetName();
446 histZ->SetName(name);
448 delete fh1CorrFFZ[slice];
449 fh1CorrFFZ[slice] = new TH1F;
450 new(fh1CorrFFZ[slice]) TH1F(*histZ);
454 if(!(histXi->GetSumw2())) histXi->Sumw2();
456 TString name = histXi->GetName();
457 histXi->SetName(name);
459 delete fh1CorrFFXi[slice];
460 fh1CorrFFXi[slice] = new TH1F;
461 new(fh1CorrFFXi[slice]) TH1F(*histXi);
465 // ___________________________________________________________________________________________
466 TH1F* AliFragmentationFunctionCorrections::AliFragFuncCorrHistos::GetTrackPt(const Int_t slice)
470 if(slice>=fArraySize){
471 Printf("%s:%d -- slice > array size", (char*)__FILE__,__LINE__);
475 return fh1CorrFFTrackPt[slice];
479 // ______________________________________________________________________________________
480 TH1F* AliFragmentationFunctionCorrections::AliFragFuncCorrHistos::GetZ(const Int_t slice)
484 if(slice>=fArraySize){
485 Printf("%s:%d -- slice > array size", (char*)__FILE__,__LINE__);
489 return fh1CorrFFZ[slice];
492 // ________________________________________________________________________________________
493 TH1F* AliFragmentationFunctionCorrections::AliFragFuncCorrHistos::GetXi(const Int_t slice)
497 if(slice>=fArraySize){
498 Printf("%s:%d -- slice > array size", (char*)__FILE__,__LINE__);
502 return fh1CorrFFXi[slice];
505 // __________________________________________________________________________
506 void AliFragmentationFunctionCorrections::DeleteHistoArray(TH1F** hist) const
508 // delete array of TH1
511 for(Int_t i=0; i<fNJetPtSlices; i++) delete hist[i];
516 // ____________________________________________________________________________________
517 void AliFragmentationFunctionCorrections::DeleteTHnSparseArray(THnSparse** hist) const
519 // delete array of THnSparse
522 for(Int_t i=0; i<fNJetPtSlices; i++) delete hist[i];
527 // _________________________________________________________
528 TH1F** AliFragmentationFunctionCorrections::BookHistoArray()
533 Printf("%s:%d -- jetPtSlices not defined", (char*)__FILE__,__LINE__);
537 TH1F** hist = new TH1F*[fNJetPtSlices];
538 for(Int_t i=0; i<fNJetPtSlices; i++) hist[i] = new TH1F();
543 //__________________________________________________________________
544 THnSparse** AliFragmentationFunctionCorrections::BookTHnSparseArray()
546 // book array of THnSparse
549 Printf("%s:%d -- jetPtSlices not defined", (char*)__FILE__,__LINE__);
553 THnSparse** hist = new THnSparse*[fNJetPtSlices];
554 for(Int_t i=0; i<fNJetPtSlices; i++) hist[i] = new THnSparseF();
559 //_____________________________________________________________________________
560 void AliFragmentationFunctionCorrections::AddCorrectionLevel(const char* label)
562 // increase corr level
565 Printf("%s:%d -- jetPtSlices not defined", (char*)__FILE__,__LINE__);
569 if(fNCorrectionLevels >= fgMaxNCorrectionLevels){
570 Printf("%s:%d -- max correction level exceeded", (char*)__FILE__,__LINE__);
574 fCorrFF[fNCorrectionLevels] = new AliFragFuncCorrHistos(label,fNJetPtSlices);
575 fNCorrectionLevels++;
579 //________________________________________________________________________________
580 void AliFragmentationFunctionCorrections::AddCorrectionLevelBgr(const char* label)
582 // increase corr level for bgr FF
585 if(fDebug>0) Printf("%s:%d -- jetPtSlices not defined", (char*)__FILE__,__LINE__);
589 if(fNCorrectionLevelsBgr >= fgMaxNCorrectionLevels){
590 Printf("%s:%d -- max correction level exceeded", (char*)__FILE__,__LINE__);
594 fCorrBgr[fNCorrectionLevelsBgr] = new AliFragFuncCorrHistos(label,fNJetPtSlices);
595 fNCorrectionLevelsBgr++;
598 //_____________________________________________________________________________________
599 void AliFragmentationFunctionCorrections::AddCorrectionLevelSinglePt(const char* label)
601 // increase corr level single pt spec
603 Int_t nJetPtSlicesSingle = 1; // pro forma
605 if(fNCorrectionLevelsSinglePt >= fgMaxNCorrectionLevels){
606 Printf("%s:%d -- max correction level exceeded", (char*)__FILE__,__LINE__);
610 fCorrSinglePt[fNCorrectionLevelsSinglePt] = new AliFragFuncCorrHistos(label,nJetPtSlicesSingle);
611 fNCorrectionLevelsSinglePt++;
614 //_____________________________________________________________________________________________
615 void AliFragmentationFunctionCorrections::SetJetPtSlices(Float_t* bins, const Int_t nJetPtSlices)
618 // once slices are known, can book all other histos
620 fNJetPtSlices = nJetPtSlices;
622 const Int_t size = nJetPtSlices+1;
623 fJetPtSlices = new TArrayF(size,bins);
627 fNJets = new TArrayF(size);
630 fNJetsBgr = new TArrayF(size);
635 fNCorrectionLevels = 0;
636 fCorrFF = new AliFragFuncCorrHistos*[fgMaxNCorrectionLevels];
637 AddCorrectionLevel(); // first 'correction' level = raw FF
639 fNCorrectionLevelsBgr = 0;
640 fCorrBgr = new AliFragFuncCorrHistos*[fgMaxNCorrectionLevels];
641 AddCorrectionLevelBgr(); // first 'correction' level = raw bgr dist
643 fh1FFXiShift = BookHistoArray();
647 fh1EffPt = BookHistoArray();
648 fh1EffXi = BookHistoArray();
649 fh1EffZ = BookHistoArray();
651 fh1EffBgrPt = BookHistoArray();
652 fh1EffBgrXi = BookHistoArray();
653 fh1EffBgrZ = BookHistoArray();
658 fh1FFTrackPtBackFolded = BookHistoArray();
659 fh1FFXiBackFolded = BookHistoArray();
660 fh1FFZBackFolded = BookHistoArray();
662 fh1FFRatioTrackPtFolded = BookHistoArray();
663 fh1FFRatioXiFolded = BookHistoArray();
664 fh1FFRatioZFolded = BookHistoArray();
666 fh1FFRatioTrackPtBackFolded = BookHistoArray();
667 fh1FFRatioXiBackFolded = BookHistoArray();
668 fh1FFRatioZBackFolded = BookHistoArray();
672 fhnResponsePt = BookTHnSparseArray();
673 fhnResponseZ = BookTHnSparseArray();
674 fhnResponseXi = BookTHnSparseArray();
676 fh1FFTrackPtPrior = BookHistoArray();
677 fh1FFZPrior = BookHistoArray();
678 fh1FFXiPrior = BookHistoArray();
683 fNHistoBinsPt = new Int_t[fNJetPtSlices];
684 fNHistoBinsXi = new Int_t[fNJetPtSlices];
685 fNHistoBinsZ = new Int_t[fNJetPtSlices];
687 for(Int_t i=0; i<fNJetPtSlices; i++) fNHistoBinsPt[i] = 0;
688 for(Int_t i=0; i<fNJetPtSlices; i++) fNHistoBinsXi[i] = 0;
689 for(Int_t i=0; i<fNJetPtSlices; i++) fNHistoBinsZ[i] = 0;
691 fHistoBinsPt = new TArrayD*[fNJetPtSlices];
692 fHistoBinsXi = new TArrayD*[fNJetPtSlices];
693 fHistoBinsZ = new TArrayD*[fNJetPtSlices];
695 for(Int_t i=0; i<fNJetPtSlices; i++) fHistoBinsPt[i] = new TArrayD(0);
696 for(Int_t i=0; i<fNJetPtSlices; i++) fHistoBinsXi[i] = new TArrayD(0);
697 for(Int_t i=0; i<fNJetPtSlices; i++) fHistoBinsZ[i] = new TArrayD(0);
700 //_____________________________________________________________________________________________________________________________________
701 void AliFragmentationFunctionCorrections::SetHistoBins(const Int_t jetPtSlice, const Int_t sizeBins, Double_t* bins, const Int_t type)
703 // set histo bins for jet pt slice
704 // if binning undefined for any slice, original binning will be used
707 Printf("%s:%d -- jetPtSlices not defined", (char*)__FILE__,__LINE__);
711 if(jetPtSlice>=fNJetPtSlices){
712 Printf("%s:%d -- jetPtSlice %d exceeds max",(char*)__FILE__,__LINE__,jetPtSlice);
717 fNHistoBinsPt[jetPtSlice] = sizeBins-1;
718 fHistoBinsPt[jetPtSlice]->Set(sizeBins,bins);
720 else if(type==kFlagZ){
721 fNHistoBinsZ[jetPtSlice] = sizeBins-1;
722 fHistoBinsZ[jetPtSlice]->Set(sizeBins,bins);
725 else if(type==kFlagXi){
726 fNHistoBinsXi[jetPtSlice] = sizeBins-1;
727 fHistoBinsXi[jetPtSlice]->Set(sizeBins,bins);
731 //__________________________________________________________________________________________________________________________________________________________________
732 void AliFragmentationFunctionCorrections::SetHistoBins(const Int_t jetPtSlice, const Int_t nBinsLimits, Double_t* binsLimits, Double_t* binsWidth, const Int_t type)
734 // set histo bins for jet pt slice
735 // function takes array of limits and widths (e.g. 1 GeV bins up to 10 GeV, 2 GeV width up to 20 GeV, ...)
736 // array size of binsLimits: nBinsLimits
737 // array size of binsWidth: nBinsLimits-1
738 // binsLimits have to be in increasing order
739 // if binning undefined for any slice, original binning will be used
742 Printf("%s:%d -- jetPtSlices not defined", (char*)__FILE__,__LINE__);
746 if(jetPtSlice>=fNJetPtSlices){
747 Printf("%s:%d -- jetPtSlice %d exceeds max",(char*)__FILE__,__LINE__,jetPtSlice);
752 Double_t binLimitMin = binsLimits[0];
753 Double_t binLimitMax = binsLimits[nBinsLimits-1];
755 Double_t binLimit = binLimitMin; // start value
757 Int_t sizeUpperLim = 10000; //static_cast<Int_t>(binLimitMax/binsWidth[0])+1;
758 TArrayD binsArray(sizeUpperLim);
760 binsArray.SetAt(binLimitMin,nBins++);
762 while(binLimit<binLimitMax && nBins<sizeUpperLim){
764 Int_t currentSlice = -1;
765 for(Int_t i=0; i<nBinsLimits; i++){
766 if(binLimit >= 0.999*binsLimits[i]) currentSlice = i; // 0.999 numerical saftey factor
769 Double_t currentBinWidth = binsWidth[currentSlice];
770 binLimit += currentBinWidth;
772 binsArray.SetAt(binLimit,nBins++);
775 Double_t* bins = binsArray.GetArray();
777 SetHistoBins(jetPtSlice,nBins,bins,type);
780 //__________________________________________________________________________________________________
781 void AliFragmentationFunctionCorrections::SetHistoBinsSinglePt(const Int_t sizeBins, Double_t* bins)
783 // set histo bins for inclusive pt spectra
784 // if binning undefined, original binning will be used
786 fNHistoBinsSinglePt = sizeBins-1;
788 fHistoBinsSinglePt = new TArrayD(sizeBins);
789 fHistoBinsSinglePt->Set(sizeBins,bins);
792 //__________________________________________________________________________________________________________________________________________________________________
793 void AliFragmentationFunctionCorrections::SetHistoBinsSinglePt(const Int_t nBinsLimits, Double_t* binsLimits, Double_t* binsWidth)
795 // set histo bins for inclusive pt spectra
796 // function takes array of limits and widths (e.g. 1 GeV bins up to 10 GeV, 2 GeV width up to 20 GeV, ...)
797 // array size of binsLimits: nBinsLimits
798 // array size of binsWidth: nBinsLimits-1
799 // binsLimits have to be in increasing order
800 // if binning undefined for any slice, original binning will be used
803 Double_t binLimitMin = binsLimits[0];
804 Double_t binLimitMax = binsLimits[nBinsLimits-1];
806 Double_t binLimit = binLimitMin; // start value
808 Int_t sizeUpperLim = 10000; //static_cast<Int_t>(binLimitMax/binsWidth[0])+1;
809 TArrayD binsArray(sizeUpperLim);
811 binsArray.SetAt(binLimitMin,nBins++);
813 while(binLimit<binLimitMax && nBins<sizeUpperLim){
815 Int_t currentSlice = -1;
816 for(Int_t i=0; i<nBinsLimits; i++){
817 if(binLimit >= 0.999*binsLimits[i]) currentSlice = i; // 0.999 numerical saftey factor
820 Double_t currentBinWidth = binsWidth[currentSlice];
821 binLimit += currentBinWidth;
823 binsArray.SetAt(binLimit,nBins++);
826 Double_t* bins = binsArray.GetArray();
828 SetHistoBinsSinglePt(nBins,bins);
831 //____________________________________________________________________________________
832 void AliFragmentationFunctionCorrections::NormalizeTH1(TH1* hist, const Float_t nJets)
834 // FF normalization: divide by bin width and normalize to entries/jets
835 // should also work for TH2, but to be tested !!!
837 if(nJets == 0){ // nothing to do
838 if(fDebug>0) Printf("%s:%d -- normalize: nJets = 0, do nothing", (char*)__FILE__,__LINE__);
842 Int_t nBins = hist->GetNbinsX()*hist->GetNbinsY()*hist->GetNbinsZ();
844 for(Int_t bin=0; bin<=nBins; bin++){ // include under-/overflow (?)
846 Double_t binWidth = hist->GetBinWidth(bin);
847 Double_t binCont = hist->GetBinContent(bin);
848 Double_t binErr = hist->GetBinError(bin);
853 hist->SetBinContent(bin,binCont);
854 hist->SetBinError(bin,binErr);
857 hist->Scale(1/nJets);
860 //_____________________________________________________
861 void AliFragmentationFunctionCorrections::NormalizeFF()
865 if(fNCorrectionLevels>1){
866 Printf("%s:%d -- FF normalization should be done BEFORE any correction !!!", (char*)__FILE__,__LINE__);
869 for(Int_t i=0; i<fNJetPtSlices; i++){
871 if(fDebug>0) Printf(" normalizeFF: i %d, nJets %f",i,fNJets->At(i));
873 NormalizeTH1(fCorrFF[0]->GetTrackPt(i),fNJets->At(i)); // always normalize corr level 0 = raw FF
874 NormalizeTH1(fCorrFF[0]->GetZ(i),fNJets->At(i));
875 NormalizeTH1(fCorrFF[0]->GetXi(i),fNJets->At(i));
879 //______________________________________________________
880 void AliFragmentationFunctionCorrections::NormalizeBgr()
882 // normalize bgr/UE FF
884 if(fNCorrectionLevelsBgr>1){
885 Printf("%s:%d -- FF normalization should be done BEFORE any correction !!!", (char*)__FILE__,__LINE__);
888 for(Int_t i=0; i<fNJetPtSlices; i++){
889 NormalizeTH1(fCorrBgr[0]->GetTrackPt(i), fNJetsBgr->At(i)); // always normalize corr level 0 = raw FF
890 NormalizeTH1(fCorrBgr[0]->GetZ(i), fNJetsBgr->At(i));
891 NormalizeTH1(fCorrBgr[0]->GetXi(i),fNJetsBgr->At(i));
896 //__________________________________________________________________________________________________
897 void AliFragmentationFunctionCorrections::ReadRawFF(TString strfile, TString strID, TString strFFID)
899 // read raw FF - standard dir/list name
901 TString strdir = "PWG4_FragmentationFunction_" + strID;
902 TString strlist = "fracfunc_" + strID;
904 ReadRawFF(strfile,strdir,strlist,strFFID);
907 //____________________________________________________________________________________________________________________
908 void AliFragmentationFunctionCorrections::ReadRawFF(TString strfile, TString strdir, TString strlist, TString strFFID)
910 // get raw FF from input file, project in jet pt slice
911 // normalization done separately
913 TFile f(strfile,"READ");
916 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
920 if(fDebug>0) Printf("%s:%d -- read FF from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
922 gDirectory->cd(strdir);
926 if(!(list = (TList*) gDirectory->Get(strlist))){
927 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
931 TString hnameJetPt(Form("fh1FFJetPt%s",strFFID.Data()));
932 TString hnameTrackPt(Form("fh2FFTrackPt%s",strFFID.Data()));
933 TString hnameZ(Form("fh2FFZ%s",strFFID.Data()));
934 TString hnameXi(Form("fh2FFXi%s",strFFID.Data()));
936 TH1F* fh1FFJetPt = (TH1F*) list->FindObject(hnameJetPt);
937 TH2F* fh2FFTrackPt = (TH2F*) list->FindObject(hnameTrackPt);
938 TH2F* fh2FFZ = (TH2F*) list->FindObject(hnameZ);
939 TH2F* fh2FFXi = (TH2F*) list->FindObject(hnameXi);
941 if(!fh1FFJetPt) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameJetPt.Data()); return; }
942 if(!fh2FFTrackPt){ Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameTrackPt.Data()); return; }
943 if(!fh2FFZ) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameZ.Data()); return; }
944 if(!fh2FFXi) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameXi.Data()); return; }
946 fh1FFJetPt->SetDirectory(0);
947 fh2FFTrackPt->SetDirectory(0);
948 fh2FFZ->SetDirectory(0);
949 fh2FFXi->SetDirectory(0);
956 for(Int_t i=0; i<fNJetPtSlices; i++){
958 Float_t jetPtLoLim = fJetPtSlices->At(i);
959 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
961 Int_t binLo = static_cast<Int_t>(fh1FFJetPt->FindBin(jetPtLoLim));
962 Int_t binUp = static_cast<Int_t>(fh1FFJetPt->FindBin(jetPtUpLim)) - 1;
964 Float_t nJetsBin = fh1FFJetPt->Integral(binLo,binUp);
966 fNJets->SetAt(nJetsBin,i);
968 if(fDebug>0) Printf("jet pt %d to %d: nJets %f",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim),fNJets->At(i));
973 for(Int_t i=0; i<fNJetPtSlices; i++){
975 Float_t jetPtLoLim = fJetPtSlices->At(i);
976 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
978 Int_t binLo = static_cast<Int_t>(fh2FFTrackPt->GetXaxis()->FindBin(jetPtLoLim));
979 Int_t binUp = static_cast<Int_t>(fh2FFTrackPt->GetXaxis()->FindBin(jetPtUpLim))-1;
981 if(binUp > fh2FFTrackPt->GetNbinsX()){
982 Printf("%s:%d -- jet pt range %0.3f exceeds histo limits",(char*)__FILE__,__LINE__,jetPtUpLim);
986 TString strNameFFPt(Form("fh1FFTrackPt%s_%02d_%02d",strFFID.Data(),static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
987 TString strNameFFZ(Form("fh1FFZ%s_%02d_%02d",strFFID.Data(),static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
988 TString strNameFFXi(Form("fh1FFXi%s_%02d_%02d",strFFID.Data(),static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
990 // appendix 'unbinned' to avoid histos with same name after rebinning
991 TH1F* projPt = (TH1F*) fh2FFTrackPt->ProjectionY(strNameFFPt+"_unBinned",binLo,binUp,"o"); // option "o": original axis range
992 TH1F* projZ = (TH1F*) fh2FFZ->ProjectionY(strNameFFZ+"_unBinned",binLo,binUp,"o");
993 TH1F* projXi = (TH1F*) fh2FFXi->ProjectionY(strNameFFXi+"_unBinned",binLo,binUp,"o");
995 if(fNHistoBinsPt[i]) projPt = (TH1F*) projPt->Rebin(fNHistoBinsPt[i],strNameFFPt,fHistoBinsPt[i]->GetArray());
996 if(fNHistoBinsZ[i]) projZ = (TH1F*) projZ->Rebin(fNHistoBinsZ[i],strNameFFZ,fHistoBinsZ[i]->GetArray());
997 if(fNHistoBinsXi[i]) projXi = (TH1F*) projXi->Rebin(fNHistoBinsXi[i],strNameFFXi,fHistoBinsXi[i]->GetArray());
999 projPt->SetNameTitle(strNameFFPt,"");
1000 projZ->SetNameTitle(strNameFFZ,"");
1001 projXi->SetNameTitle(strNameFFXi,"");
1003 // raw FF = corr level 0
1004 fCorrFF[0]->AddCorrHistos(i,projPt,projZ,projXi);
1008 //_____________________________________________________________________________________________________________________
1009 void AliFragmentationFunctionCorrections::ReadRawBgr(TString strfile, TString strID, TString strBgrID, TString strFFID)
1011 // read raw FF - standard dir/list name
1013 TString strdir = "PWG4_FragmentationFunction_" + strID;
1014 TString strlist = "fracfunc_" + strID;
1016 ReadRawBgr(strfile,strdir,strlist,strBgrID,strFFID);
1019 //_______________________________________________________________________________________________________________________________________
1020 void AliFragmentationFunctionCorrections::ReadRawBgr(TString strfile, TString strdir, TString strlist, TString strBgrID, TString strFFID)
1022 // get raw FF from input file, project in jet pt slice
1023 // use jet dN/dpt corresponding to strFFID, bgr FF to strBgrID+strFFID
1024 // e.g. "fh1FFJetPtRecCuts", "fh2FFXiBgrPerpRecCuts"
1025 // normalization done separately
1027 TString strID = strBgrID + strFFID;
1029 TFile f(strfile,"READ");
1032 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
1036 if(fDebug>0) Printf("%s:%d -- read Bgr %s from file %s ",(char*)__FILE__,__LINE__,strBgrID.Data(),strfile.Data());
1038 gDirectory->cd(strdir);
1042 if(!(list = (TList*) gDirectory->Get(strlist))){
1043 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
1047 TString hnameNJets = "fh1nRecJetsCuts";
1048 TString hnameJetPt(Form("fh1FFJetPt%s",strFFID.Data())); // not: strID.Data() !!! would not be proper normalization
1049 TString hnameBgrTrackPt(Form("fh2FFTrackPt%s",strID.Data()));
1050 TString hnameBgrZ(Form("fh2FFZ%s",strID.Data()));
1051 TString hnameBgrXi(Form("fh2FFXi%s",strID.Data()));
1053 TH1F* fh1NJets = (TH1F*) list->FindObject(hnameNJets); // needed for normalization of bgr out of 2 jets
1054 TH1F* fh1FFJetPtBgr = (TH1F*) list->FindObject(hnameJetPt);
1055 TH2F* fh2FFTrackPtBgr = (TH2F*) list->FindObject(hnameBgrTrackPt);
1056 TH2F* fh2FFZBgr = (TH2F*) list->FindObject(hnameBgrZ);
1057 TH2F* fh2FFXiBgr = (TH2F*) list->FindObject(hnameBgrXi);
1059 if(!fh1FFJetPtBgr) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameJetPt.Data()); return; }
1060 if(!fh1NJets) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameNJets.Data()); return; }
1061 if(!fh2FFTrackPtBgr){ Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameBgrTrackPt.Data()); return; }
1062 if(!fh2FFZBgr) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameBgrZ.Data()); return; }
1063 if(!fh2FFXiBgr) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameBgrXi.Data()); return; }
1065 fh1FFJetPtBgr->SetDirectory(0);
1066 fh1NJets->SetDirectory(0);
1067 fh2FFTrackPtBgr->SetDirectory(0);
1068 fh2FFZBgr->SetDirectory(0);
1069 fh2FFXiBgr->SetDirectory(0);
1075 for(Int_t i=0; i<fNJetPtSlices; i++){
1077 Float_t jetPtLoLim = fJetPtSlices->At(i);
1078 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
1080 Int_t binLo = static_cast<Int_t>(fh1FFJetPtBgr->FindBin(jetPtLoLim));
1081 Int_t binUp = static_cast<Int_t>(fh1FFJetPtBgr->FindBin(jetPtUpLim)) - 1;
1083 Float_t nJetsBin = fh1FFJetPtBgr->Integral(binLo,binUp);
1084 Double_t scaleF = 1;
1086 //if(strBgrID.Contains("Out2Jets")){ // scale by ratio 2 jets events / all events
1087 // scaleF = fh1NJets->Integral(fh1NJets->FindBin(2),fh1NJets->GetNbinsX())
1088 // / fh1NJets->Integral(fh1NJets->FindBin(1),fh1NJets->GetNbinsX());}
1091 if(strBgrID.Contains("OutAllJets")){ // scale by ratio >3 jets events / all events
1092 scaleF = fh1NJets->Integral(fh1NJets->FindBin(4),fh1NJets->GetNbinsX())
1093 / fh1NJets->Integral(fh1NJets->FindBin(1),fh1NJets->GetNbinsX());
1096 fNJetsBgr->SetAt(nJetsBin*scaleF,i);
1098 if(fDebug>0) Printf("bgr jet pt %d to %d: nJets %f, scaleF %.2f",
1099 static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim),nJetsBin,scaleF);
1105 for(Int_t i=0; i<fNJetPtSlices; i++){
1107 Float_t jetPtLoLim = fJetPtSlices->At(i);
1108 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
1110 Int_t binLo = static_cast<Int_t>(fh2FFTrackPtBgr->GetXaxis()->FindBin(jetPtLoLim));
1111 Int_t binUp = static_cast<Int_t>(fh2FFTrackPtBgr->GetXaxis()->FindBin(jetPtUpLim))-1;
1113 if(binUp > fh2FFTrackPtBgr->GetNbinsX()){
1114 Printf("%s:%d -- jet pt range %0.3f exceeds histo limits",(char*)__FILE__,__LINE__,jetPtUpLim);
1118 TString strNameBgrPt(Form("fh1BgrTrackPt%s_%02d_%02d",strID.Data(),static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
1119 TString strNameBgrZ(Form("fh1BgrZ%s_%02d_%02d",strID.Data(),static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
1120 TString strNameBgrXi(Form("fh1BgrXi%s_%02d_%02d",strID.Data(),static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
1122 // appendix 'unbinned' to avoid histos with same name after rebinning
1123 TH1F* projPt = (TH1F*) fh2FFTrackPtBgr->ProjectionY(strNameBgrPt+"_unBinned",binLo,binUp,"o"); // option "o": original axis range
1124 TH1F* projZ = (TH1F*) fh2FFZBgr->ProjectionY(strNameBgrZ+"_unBinned",binLo,binUp,"o");
1125 TH1F* projXi = (TH1F*) fh2FFXiBgr->ProjectionY(strNameBgrXi+"_unBinned",binLo,binUp,"o");
1127 if(fNHistoBinsPt[i]) projPt = (TH1F*) projPt->Rebin(fNHistoBinsPt[i],strNameBgrPt,fHistoBinsPt[i]->GetArray());
1128 if(fNHistoBinsZ[i]) projZ = (TH1F*) projZ->Rebin(fNHistoBinsZ[i],strNameBgrZ,fHistoBinsZ[i]->GetArray());
1129 if(fNHistoBinsXi[i]) projXi = (TH1F*) projXi->Rebin(fNHistoBinsXi[i],strNameBgrXi,fHistoBinsXi[i]->GetArray());
1131 projPt->SetNameTitle(strNameBgrPt,"");
1132 projZ->SetNameTitle(strNameBgrZ,"");
1133 projXi->SetNameTitle(strNameBgrXi,"");
1135 // raw bgr = corr level 0
1136 fCorrBgr[0]->AddCorrHistos(i,projPt,projZ,projXi);
1140 //_____________________________________________________________________________________________________________________
1141 void AliFragmentationFunctionCorrections::ReadRawBgrEmbedding(TString strfile, TString strID, TString strFFID)
1143 // read raw FF - standard dir/list name
1145 TString strdir = "PWG4_FragmentationFunction_" + strID;
1146 TString strlist = "fracfunc_" + strID;
1148 ReadRawBgrEmbedding(strfile,strdir,strlist,strFFID);
1151 //_______________________________________________________________________________________________________________________________________
1152 void AliFragmentationFunctionCorrections::ReadRawBgrEmbedding(TString strfile, TString strdir, TString strlist, TString strFFID)
1154 // get raw FF from input file, project in jet pt slice
1155 // for embedding, the bgr FF are taken from histos "fh1FFJetPtRecCuts", "fh2FFXiRecCuts"
1156 // normalization done separately
1158 TString strBgrID = "BckgEmbed";
1159 TString strID = strBgrID + strFFID;
1161 TFile f(strfile,"READ");
1164 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
1168 if(fDebug>0) Printf("%s:%d -- read Bgr %s from file %s ",(char*)__FILE__,__LINE__,strFFID.Data(),strfile.Data());
1170 gDirectory->cd(strdir);
1174 if(!(list = (TList*) gDirectory->Get(strlist))){
1175 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
1179 TString hnameNJets = "fh1nRecJetsCuts";
1180 TString hnameJetPt(Form("fh1FFJetPt%s",strFFID.Data()));
1181 TString hnameBgrTrackPt(Form("fh2FFTrackPt%s",strFFID.Data()));
1182 TString hnameBgrZ(Form("fh2FFZ%s",strFFID.Data()));
1183 TString hnameBgrXi(Form("fh2FFXi%s",strFFID.Data()));
1185 TH1F* fh1NJets = (TH1F*) list->FindObject(hnameNJets); // needed for normalization of bgr out of 2 jets
1186 TH1F* fh1FFJetPtBgr = (TH1F*) list->FindObject(hnameJetPt);
1187 TH2F* fh2FFTrackPtBgr = (TH2F*) list->FindObject(hnameBgrTrackPt);
1188 TH2F* fh2FFZBgr = (TH2F*) list->FindObject(hnameBgrZ);
1189 TH2F* fh2FFXiBgr = (TH2F*) list->FindObject(hnameBgrXi);
1191 if(!fh1FFJetPtBgr) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameJetPt.Data()); return; }
1192 if(!fh1NJets) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameNJets.Data()); return; }
1193 if(!fh2FFTrackPtBgr){ Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameBgrTrackPt.Data()); return; }
1194 if(!fh2FFZBgr) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameBgrZ.Data()); return; }
1195 if(!fh2FFXiBgr) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameBgrXi.Data()); return; }
1197 fh1FFJetPtBgr->SetDirectory(0);
1198 fh1NJets->SetDirectory(0);
1199 fh2FFTrackPtBgr->SetDirectory(0);
1200 fh2FFZBgr->SetDirectory(0);
1201 fh2FFXiBgr->SetDirectory(0);
1207 for(Int_t i=0; i<fNJetPtSlices; i++){
1209 Float_t jetPtLoLim = fJetPtSlices->At(i);
1210 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
1212 Int_t binLo = static_cast<Int_t>(fh1FFJetPtBgr->FindBin(jetPtLoLim));
1213 Int_t binUp = static_cast<Int_t>(fh1FFJetPtBgr->FindBin(jetPtUpLim)) - 1;
1215 Float_t nJetsBin = fh1FFJetPtBgr->Integral(binLo,binUp);
1216 Double_t scaleF = 1;
1218 fNJetsBgr->SetAt(nJetsBin*scaleF,i);
1220 if(fDebug>0) Printf("bgr jet pt %d to %d: nJets %f, scaleF %.2f",
1221 static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim),nJetsBin,scaleF);
1227 for(Int_t i=0; i<fNJetPtSlices; i++){
1229 Float_t jetPtLoLim = fJetPtSlices->At(i);
1230 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
1232 Int_t binLo = static_cast<Int_t>(fh2FFTrackPtBgr->GetXaxis()->FindBin(jetPtLoLim));
1233 Int_t binUp = static_cast<Int_t>(fh2FFTrackPtBgr->GetXaxis()->FindBin(jetPtUpLim))-1;
1235 if(binUp > fh2FFTrackPtBgr->GetNbinsX()){
1236 Printf("%s:%d -- jet pt range %0.3f exceeds histo limits",(char*)__FILE__,__LINE__,jetPtUpLim);
1240 TString strNameBgrPt(Form("fh1BgrTrackPt%s_%02d_%02d",strID.Data(),static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
1241 TString strNameBgrZ(Form("fh1BgrZ%s_%02d_%02d",strID.Data(),static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
1242 TString strNameBgrXi(Form("fh1BgrXi%s_%02d_%02d",strID.Data(),static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
1244 // appendix 'unbinned' to avoid histos with same name after rebinning
1245 TH1F* projPt = (TH1F*) fh2FFTrackPtBgr->ProjectionY(strNameBgrPt+"_unBinned",binLo,binUp,"o"); // option "o": original axis range
1246 TH1F* projZ = (TH1F*) fh2FFZBgr->ProjectionY(strNameBgrZ+"_unBinned",binLo,binUp,"o");
1247 TH1F* projXi = (TH1F*) fh2FFXiBgr->ProjectionY(strNameBgrXi+"_unBinned",binLo,binUp,"o");
1249 if(fNHistoBinsPt[i]) projPt = (TH1F*) projPt->Rebin(fNHistoBinsPt[i],strNameBgrPt,fHistoBinsPt[i]->GetArray());
1250 if(fNHistoBinsZ[i]) projZ = (TH1F*) projZ->Rebin(fNHistoBinsZ[i],strNameBgrZ,fHistoBinsZ[i]->GetArray());
1251 if(fNHistoBinsXi[i]) projXi = (TH1F*) projXi->Rebin(fNHistoBinsXi[i],strNameBgrXi,fHistoBinsXi[i]->GetArray());
1253 projPt->SetNameTitle(strNameBgrPt,"");
1254 projZ->SetNameTitle(strNameBgrZ,"");
1255 projXi->SetNameTitle(strNameBgrXi,"");
1257 // raw bgr = corr level 0
1258 fCorrBgr[0]->AddCorrHistos(i,projPt,projZ,projXi);
1263 //__________________________________________________________________________________________________________
1264 void AliFragmentationFunctionCorrections::WriteOutput(TString strfile, TString strdir, Bool_t updateOutfile)
1266 // write histos to file
1267 // skip histos with 0 entries
1269 TString outfileOption = "RECREATE";
1270 if(updateOutfile) outfileOption = "UPDATE";
1272 TFile f(strfile,outfileOption);
1275 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
1279 if(fDebug>0) Printf("%s:%d -- write FF to file %s ",(char*)__FILE__,__LINE__,strfile.Data());
1281 if(strdir && strdir.Length()){
1282 TDirectory* dir = f.mkdir(strdir);
1286 for(Int_t i=0; i<fNJetPtSlices; i++){
1288 for(Int_t c=0; c<fNCorrectionLevels; c++) if(fCorrFF[c]->GetTrackPt(i)->GetEntries()) fCorrFF[c]->GetTrackPt(i)->Write();
1289 for(Int_t c=0; c<fNCorrectionLevels; c++) if(fCorrFF[c]->GetZ(i)->GetEntries()) fCorrFF[c]->GetZ(i)->Write();
1290 for(Int_t c=0; c<fNCorrectionLevels; c++) if(fCorrFF[c]->GetXi(i)->GetEntries()) fCorrFF[c]->GetXi(i)->Write();
1292 if(fh1FFXiShift[i]->GetEntries()) fh1FFXiShift[i]->Write();
1294 for(Int_t c=0; c<fNCorrectionLevelsBgr; c++) if(fCorrBgr[c]->GetTrackPt(i)->GetEntries()) fCorrBgr[c]->GetTrackPt(i)->Write();
1295 for(Int_t c=0; c<fNCorrectionLevelsBgr; c++) if(fCorrBgr[c]->GetZ(i)->GetEntries()) fCorrBgr[c]->GetZ(i)->Write();
1296 for(Int_t c=0; c<fNCorrectionLevelsBgr; c++) if(fCorrBgr[c]->GetXi(i)->GetEntries()) fCorrBgr[c]->GetXi(i)->Write();
1299 if(fh1FFTrackPtBackFolded[i] && fh1FFTrackPtBackFolded[i]->GetEntries()) fh1FFTrackPtBackFolded[i]->Write();
1300 if(fh1FFZBackFolded[i] && fh1FFZBackFolded[i]->GetEntries()) fh1FFZBackFolded[i]->Write();
1301 if(fh1FFXiBackFolded[i] && fh1FFXiBackFolded[i]->GetEntries()) fh1FFXiBackFolded[i]->Write();
1304 if(fh1FFRatioTrackPtFolded[i] && fh1FFRatioTrackPtFolded[i]->GetEntries()) fh1FFRatioTrackPtFolded[i]->Write();
1305 if(fh1FFRatioZFolded[i] && fh1FFRatioZFolded[i]->GetEntries()) fh1FFRatioZFolded[i]->Write();
1306 if(fh1FFRatioXiFolded[i] && fh1FFRatioXiFolded[i]->GetEntries()) fh1FFRatioXiFolded[i]->Write();
1308 if(fh1FFRatioTrackPtBackFolded[i] && fh1FFRatioTrackPtBackFolded[i]->GetEntries()) fh1FFRatioTrackPtBackFolded[i]->Write();
1309 if(fh1FFRatioZBackFolded[i] && fh1FFRatioZBackFolded[i]->GetEntries()) fh1FFRatioZBackFolded[i]->Write();
1310 if(fh1FFRatioXiBackFolded[i] &&fh1FFRatioXiBackFolded[i]->GetEntries()) fh1FFRatioXiBackFolded[i]->Write();
1314 // inclusive track pt
1316 for(Int_t c=0; c<fNCorrectionLevelsSinglePt; c++) if(fCorrSinglePt[c]->GetTrackPt(0)->GetEntries()) fCorrSinglePt[c]->GetTrackPt(0)->Write();
1317 if(fh1SingleTrackPtBackFolded) fh1SingleTrackPtBackFolded->Write();
1318 if(fh1RatioSingleTrackPtFolded) fh1RatioSingleTrackPtFolded->Write();
1319 if(fh1RatioSingleTrackPtBackFolded) fh1RatioSingleTrackPtBackFolded->Write();
1324 //____________________________________________________________________________________________________________________________________
1325 THnSparse* AliFragmentationFunctionCorrections::TH1toSparse(const TH1F* hist, TString strName, TString strTit, const Bool_t fillConst)
1327 // copy 1-dimensional histo to THnSparse
1328 // if fillConst TRUE, create THnSparse with same binning as hist but all entries = 1
1329 // histos with variable bin size are supported
1331 // note: function returns pointer to 'new' THnSparse on heap, object needs to be deleted by user
1333 THnSparseF* fhnHist;
1335 Int_t nBins = hist->GetXaxis()->GetNbins();
1336 Int_t nBinsVec[1] = { nBins };
1338 const Double_t* binsVec = hist->GetXaxis()->GetXbins()->GetArray();
1340 if(binsVec){ // binsVec only neq NULL if histo was rebinned before
1342 fhnHist = new THnSparseF(strName,strTit,1,nBinsVec/*,binMinVec,binMaxVec*/);
1343 fhnHist->SetBinEdges(0,binsVec);
1345 else{ // uniform bin size
1347 Double_t xMin = hist->GetXaxis()->GetXmin();
1348 Double_t xMax = hist->GetXaxis()->GetXmax();
1350 Double_t binMinVec[1] = { xMin };
1351 Double_t binMaxVec[1] = { xMax };
1353 fhnHist = new THnSparseF(strName,strTit,1,nBinsVec,binMinVec,binMaxVec);
1357 for(Int_t bin=1; bin<=nBins; bin++){
1359 Double_t binCenter = fhnHist->GetAxis(0)->GetBinCenter(bin);
1361 Double_t binCoord[] = {binCenter};
1362 fhnHist->Fill(binCoord,1); // initially need to create the bin
1364 Long64_t binIndex = fhnHist->GetBin(binCoord);
1366 Double_t cont = hist->GetBinContent(bin);
1367 Double_t err = hist->GetBinError(bin);
1374 fhnHist->SetBinContent(binIndex,cont);
1375 fhnHist->SetBinError(binIndex,err);
1381 //______________________________________________________________________________________________________________________________________________
1382 THnSparse* AliFragmentationFunctionCorrections::Unfold(THnSparse* hnHist, const THnSparse* hnResponse, const THnSparse* hnEff, const Int_t nIter,
1383 const Bool_t useCorrelatedErrors, const THnSparse* hnPrior)
1385 // unfold input histo
1387 AliCFUnfolding unfolding("unfolding","",1,hnResponse,hnEff,hnHist,hnPrior); // arg3: nVar; hnEff required, hnPrior not (defaults to 0x0)
1388 unfolding.SetMaxNumberOfIterations(nIter);
1389 // unfolding.SetMaxChi2PerDOF(1.e-07); // OBSOLETE !!!
1390 // if(useSmoothing) unfolding.UseSmoothing();
1392 if(useCorrelatedErrors) unfolding.SetUseCorrelatedErrors();
1395 THnSparse* unfolded = unfolding.GetUnfolded();
1397 TString hnameUnf = hnHist->GetName();
1398 hnameUnf.Append("_unf");
1399 unfolded->SetNameTitle(hnameUnf,hnHist->GetTitle());
1404 //___________________________________________________________________________________________________________________________
1405 void AliFragmentationFunctionCorrections::UnfoldHistos(const Int_t nIter, const Bool_t useCorrelatedErrors, const Int_t type)
1407 // loop over jet pt slices and unfold dN/dpt spectra
1409 TString labelCorr = fCorrFF[fNCorrectionLevels-1]->GetLabel();
1410 if(!labelCorr.Contains("unfold")) AddCorrectionLevel("unfold");
1412 for(Int_t i=0; i<fNJetPtSlices; i++){
1415 if(type == kFlagPt) hist = fCorrFF[fNCorrectionLevels-2]->GetTrackPt(i); // level -2: before unfolding, level -1: unfolded
1416 else if(type == kFlagZ) hist = fCorrFF[fNCorrectionLevels-2]->GetZ(i); // level -2: before unfolding, level -1: unfolded
1417 else if(type == kFlagXi) hist = fCorrFF[fNCorrectionLevels-2]->GetXi(i); // level -2: before unfolding, level -1: unfolded
1419 THnSparse* hnResponse = 0;
1420 if(type == kFlagPt) hnResponse = fhnResponsePt[i];
1421 else if(type == kFlagZ) hnResponse = fhnResponseZ[i];
1422 else if(type == kFlagXi) hnResponse = fhnResponseXi[i];
1426 if(type == kFlagPt && fh1FFTrackPtPrior[i] && ((TString(fh1FFTrackPtPrior[i]->GetName())).Length() > 0) ) hPrior = fh1FFTrackPtPrior[i];
1427 else if(type == kFlagZ && fh1FFZPrior[i] && ((TString(fh1FFZPrior[i]->GetName())).Length() > 0) ) hPrior = fh1FFZPrior[i];
1428 else if(type == kFlagXi && fh1FFXiPrior[i] && ((TString(fh1FFXiPrior[i]->GetName())).Length() > 0) ) hPrior = fh1FFXiPrior[i];
1431 TString histNameTHn = hist->GetName();
1432 histNameTHn.ReplaceAll("TH1","THn");
1434 TString priorNameTHn;
1436 priorNameTHn = hPrior->GetName();
1437 priorNameTHn.ReplaceAll("TH1","THn");
1440 TString histNameBackFolded = hist->GetName();
1441 histNameBackFolded.Append("_backfold");
1443 TString histNameRatioFolded = hist->GetName();
1444 histNameRatioFolded.ReplaceAll("fh1FF","hRatioFF");
1445 histNameRatioFolded.Append("_unfold");
1447 TString histNameRatioBackFolded = hist->GetName();
1448 histNameRatioBackFolded.ReplaceAll("fh1FF","hRatioFF");
1449 histNameRatioBackFolded.Append("_backfold");
1451 THnSparse* hnHist = TH1toSparse(hist,histNameTHn,hist->GetTitle());
1452 THnSparse* hnFlatEfficiency = TH1toSparse(hist,"fhnEfficiency","eff",kTRUE); // could optionally also use real eff
1453 THnSparse* hnPrior = 0;
1454 if(hPrior) hnPrior = TH1toSparse(hPrior,priorNameTHn,hPrior->GetTitle());
1456 THnSparse* hnUnfolded
1457 = Unfold(hnHist,hnResponse,hnFlatEfficiency,nIter,useCorrelatedErrors,hnPrior);
1459 TH1F* hUnfolded = (TH1F*) hnUnfolded->Projection(0);
1460 hUnfolded->SetNameTitle(hist->GetName(),hist->GetTitle());
1462 if(type == kFlagPt) fCorrFF[fNCorrectionLevels-1]->AddCorrHistos(i,hUnfolded,0,0);
1463 if(type == kFlagZ) fCorrFF[fNCorrectionLevels-1]->AddCorrHistos(i,0,hUnfolded,0);
1464 if(type == kFlagXi) fCorrFF[fNCorrectionLevels-1]->AddCorrHistos(i,0,0,hUnfolded);
1466 // backfolding: apply response matrix to unfolded spectrum
1467 TH1F* hBackFolded = ApplyResponse(hUnfolded,hnResponse);
1468 hBackFolded->SetNameTitle(histNameBackFolded,hist->GetTitle());
1470 if(type == kFlagPt) fh1FFTrackPtBackFolded[i] = hBackFolded;
1471 if(type == kFlagZ) fh1FFZBackFolded[i] = hBackFolded;
1472 if(type == kFlagXi) fh1FFXiBackFolded[i] = hBackFolded;
1474 // ratio unfolded to original histo
1475 TH1F* hRatioUnfolded = (TH1F*) hUnfolded->Clone(histNameRatioFolded);
1476 hRatioUnfolded->Reset();
1477 hRatioUnfolded->Divide(hUnfolded,hist,1,1,"B");
1479 if(type == kFlagPt) fh1FFRatioTrackPtFolded[i] = hRatioUnfolded;
1480 if(type == kFlagZ) fh1FFRatioZFolded[i] = hRatioUnfolded;
1481 if(type == kFlagXi) fh1FFRatioXiFolded[i] = hRatioUnfolded;
1484 // ratio backfolded to original histo
1485 TH1F* hRatioBackFolded = (TH1F*) hBackFolded->Clone(histNameRatioBackFolded);
1486 hRatioBackFolded->Reset();
1487 hRatioBackFolded->Divide(hBackFolded,hist,1,1,"B");
1489 if(type == kFlagPt) fh1FFRatioTrackPtBackFolded[i] = hRatioBackFolded;
1490 if(type == kFlagZ) fh1FFRatioZBackFolded[i] = hRatioBackFolded;
1491 if(type == kFlagXi) fh1FFRatioXiBackFolded[i] = hRatioBackFolded;
1494 delete hnFlatEfficiency;
1499 //_____________________________________________________________________________________________________
1500 void AliFragmentationFunctionCorrections::UnfoldPt(const Int_t nIter, const Bool_t useCorrelatedErrors)
1503 Int_t type = kFlagPt;
1504 UnfoldHistos(nIter, useCorrelatedErrors, type);
1507 //_____________________________________________________________________________________________________
1508 void AliFragmentationFunctionCorrections::UnfoldZ(const Int_t nIter, const Bool_t useCorrelatedErrors)
1511 Int_t type = kFlagZ;
1512 UnfoldHistos(nIter, useCorrelatedErrors, type);
1515 //_____________________________________________________________________________________________________
1516 void AliFragmentationFunctionCorrections::UnfoldXi(const Int_t nIter, const Bool_t useCorrelatedErrors)
1519 Int_t type = kFlagXi;
1520 UnfoldHistos(nIter, useCorrelatedErrors, type);
1523 //______________________________________________________________________________________________
1524 TH1F* AliFragmentationFunctionCorrections::ApplyResponse(const TH1F* hist, THnSparse* hnResponse)
1526 // apply (multiply) response matrix to hist
1528 TH1F* hOut = new TH1F(*hist);
1531 const Int_t axisM = 0;
1532 const Int_t axisT = 1;
1534 Int_t nBinsM = hnResponse->GetAxis(axisM)->GetNbins();
1535 Int_t nBinsT = hnResponse->GetAxis(axisT)->GetNbins();
1537 // response matrix normalization
1538 // do it in this function and not when reading response, since for 'proper' normalization errors are difficult to assign
1539 // so for unfolding proper we leave it to CORRFW ...
1541 Double_t normFacResponse[nBinsT];
1543 for(Int_t iT=1; iT<=nBinsT; iT++){
1545 Double_t sumResp = 0;
1547 for(Int_t iM=1; iM<=nBinsM; iM++){
1549 Double_t coordM = hnResponse->GetAxis(axisM)->GetBinCenter(iM);
1550 Double_t coordT = hnResponse->GetAxis(axisT)->GetBinCenter(iT);
1552 Double_t binCoord[] = {coordM,coordT};
1554 Long64_t binIndex = hnResponse->GetBin(binCoord);
1556 Double_t resp = hnResponse->GetBinContent(binIndex);
1561 normFacResponse[iT] = 0;
1562 if(sumResp) normFacResponse[iT] = 1/sumResp;
1567 for(Int_t iM=1; iM<=nBinsM; iM++){
1571 for(Int_t iT=1; iT<=nBinsT; iT++){
1573 Double_t contT = hist->GetBinContent(iT);
1575 Double_t coordM = hnResponse->GetAxis(axisM)->GetBinCenter(iM);
1576 Double_t coordT = hnResponse->GetAxis(axisT)->GetBinCenter(iT);
1578 Double_t binCoord[] = {coordM,coordT};
1580 Long64_t binIndex = hnResponse->GetBin(binCoord);
1582 Double_t resp = hnResponse->GetBinContent(binIndex);
1584 contM += resp*normFacResponse[iT]*contT;
1587 hOut->SetBinContent(iM,contM);
1593 //_______________________________________________________________________________________________________
1594 void AliFragmentationFunctionCorrections::ReadEfficiency(TString strfile, TString strdir, TString strlist)
1596 // read reconstruction efficiency from file
1597 // argument strlist optional - read from directory strdir if not specified
1599 // temporary histos to hold histos from file
1600 TH1F* hEffPt[fNJetPtSlices];
1601 TH1F* hEffZ[fNJetPtSlices];
1602 TH1F* hEffXi[fNJetPtSlices];
1604 for(Int_t i=0; i<fNJetPtSlices; i++) hEffPt[i] = 0;
1605 for(Int_t i=0; i<fNJetPtSlices; i++) hEffZ[i] = 0;
1606 for(Int_t i=0; i<fNJetPtSlices; i++) hEffXi[i] = 0;
1608 TFile f(strfile,"READ");
1611 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
1615 if(fDebug>0) Printf("%s:%d -- read efficiencies from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
1617 if(strdir && strdir.Length()) gDirectory->cd(strdir);
1621 if(strlist && strlist.Length()){
1623 if(!(list = (TList*) gDirectory->Get(strlist))){
1624 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
1629 for(Int_t i=0; i<fNJetPtSlices; i++){
1631 Int_t jetPtLoLim = static_cast<Int_t> (fJetPtSlices->At(i));
1632 Int_t jetPtUpLim = static_cast<Int_t> (fJetPtSlices->At(i+1));
1634 TString strNameEffPt(Form("hEffPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
1635 TString strNameEffZ(Form("hEffZ_%02d_%02d",jetPtLoLim,jetPtUpLim));
1636 TString strNameEffXi(Form("hEffXi_%02d_%02d",jetPtLoLim,jetPtUpLim));
1640 hEffPt[i] = (TH1F*) list->FindObject(strNameEffPt);
1641 hEffZ[i] = (TH1F*) list->FindObject(strNameEffZ);
1642 hEffXi[i] = (TH1F*) list->FindObject(strNameEffXi);
1645 hEffPt[i] = (TH1F*) gDirectory->Get(strNameEffPt);
1646 hEffZ[i] = (TH1F*) gDirectory->Get(strNameEffZ);
1647 hEffXi[i] = (TH1F*) gDirectory->Get(strNameEffXi);
1651 Printf("%s:%d -- error retrieving efficiency %s", (char*)__FILE__,__LINE__,strNameEffPt.Data());
1655 Printf("%s:%d -- error retrieving efficiency %s", (char*)__FILE__,__LINE__,strNameEffZ.Data());
1659 Printf("%s:%d -- error retrieving efficiency %s", (char*)__FILE__,__LINE__,strNameEffXi.Data());
1663 if(fNHistoBinsPt[i]) hEffPt[i] = (TH1F*) hEffPt[i]->Rebin(fNHistoBinsPt[i],strNameEffPt+"_rebin",fHistoBinsPt[i]->GetArray());
1664 if(fNHistoBinsZ[i]) hEffZ[i] = (TH1F*) hEffZ[i]->Rebin(fNHistoBinsZ[i],strNameEffZ+"_rebin",fHistoBinsZ[i]->GetArray());
1665 if(fNHistoBinsXi[i]) hEffXi[i] = (TH1F*) hEffXi[i]->Rebin(fNHistoBinsXi[i],strNameEffXi+"_rebin",fHistoBinsXi[i]->GetArray());
1667 if(hEffPt[i]) hEffPt[i]->SetDirectory(0);
1668 if(hEffZ[i]) hEffZ[i]->SetDirectory(0);
1669 if(hEffXi[i]) hEffXi[i]->SetDirectory(0);
1671 } // jet slices loop
1675 for(Int_t i=0; i<fNJetPtSlices; i++){ // 2nd loop: need to close input file before placing histos
1676 if(hEffPt[i]) new(fh1EffPt[i]) TH1F(*hEffPt[i]);
1677 if(hEffZ[i]) new(fh1EffZ[i]) TH1F(*hEffZ[i]);
1678 if(hEffXi[i]) new(fh1EffXi[i]) TH1F(*hEffXi[i]);
1682 //___________________________________________________________________________________________________________
1683 void AliFragmentationFunctionCorrections::ReadBgrEfficiency(TString strfile, TString strdir, TString strlist)
1685 // read bgr eff from file
1686 // argument strlist optional - read from directory strdir if not specified
1688 TH1F* hEffPtBgr[fNJetPtSlices];
1689 TH1F* hEffZBgr [fNJetPtSlices];
1690 TH1F* hEffXiBgr[fNJetPtSlices];
1692 for(Int_t i=0; i<fNJetPtSlices; i++) hEffPtBgr[i] = 0;
1693 for(Int_t i=0; i<fNJetPtSlices; i++) hEffZBgr[i] = 0;
1694 for(Int_t i=0; i<fNJetPtSlices; i++) hEffXiBgr[i] = 0;
1697 TFile f(strfile,"READ");
1700 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
1704 if(fDebug>0) Printf("%s:%d -- read bgr efficiencies from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
1706 if(strdir && strdir.Length()) gDirectory->cd(strdir);
1710 if(strlist && strlist.Length()){
1712 if(!(list = (TList*) gDirectory->Get(strlist))){
1713 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
1718 for(Int_t i=0; i<fNJetPtSlices; i++){
1720 Int_t jetPtLoLim = static_cast<Int_t> (fJetPtSlices->At(i));
1721 Int_t jetPtUpLim = static_cast<Int_t> (fJetPtSlices->At(i+1));
1723 TString strNameEffPtBgr(Form("hEffPtBgr%02dto%02d",jetPtLoLim,jetPtUpLim));
1724 TString strNameEffZBgr(Form("hEffZBgr%02dto%02d",jetPtLoLim,jetPtUpLim));
1725 TString strNameEffXiBgr(Form("hEffXiBgr%02dto%02d",jetPtLoLim,jetPtUpLim));
1729 hEffPtBgr[i] = (TH1F*) list->FindObject(strNameEffPtBgr);
1730 hEffZBgr[i] = (TH1F*) list->FindObject(strNameEffZBgr);
1731 hEffXiBgr[i] = (TH1F*) list->FindObject(strNameEffXiBgr);
1734 hEffPtBgr[i] = (TH1F*) gDirectory->Get(strNameEffPtBgr);
1735 hEffZBgr[i] = (TH1F*) gDirectory->Get(strNameEffZBgr);
1736 hEffXiBgr[i] = (TH1F*) gDirectory->Get(strNameEffXiBgr);
1740 Printf("%s:%d -- error retrieving efficiency %s", (char*)__FILE__,__LINE__,strNameEffPtBgr.Data());
1744 Printf("%s:%d -- error retrieving efficiency %s", (char*)__FILE__,__LINE__,strNameEffZBgr.Data());
1748 Printf("%s:%d -- error retrieving efficiency %s", (char*)__FILE__,__LINE__,strNameEffXiBgr.Data());
1752 if(fNHistoBinsPt[i]) hEffPtBgr[i] = (TH1F*) hEffPtBgr[i]->Rebin(fNHistoBinsPt[i],strNameEffPtBgr+"_rebin",fHistoBinsPt[i]->GetArray());
1753 if(fNHistoBinsZ[i]) hEffZBgr[i] = (TH1F*) hEffZBgr[i]->Rebin(fNHistoBinsZ[i],strNameEffZBgr+"_rebin",fHistoBinsZ[i]->GetArray());
1754 if(fNHistoBinsXi[i]) hEffXiBgr[i] = (TH1F*) hEffXiBgr[i]->Rebin(fNHistoBinsXi[i],strNameEffXiBgr+"_rebin",fHistoBinsXi[i]->GetArray());
1756 if(hEffPtBgr[i]) hEffPtBgr[i]->SetDirectory(0);
1757 if(hEffZBgr[i]) hEffZBgr[i]->SetDirectory(0);
1758 if(hEffXiBgr[i]) hEffXiBgr[i]->SetDirectory(0);
1760 } // jet slices loop
1764 for(Int_t i=0; i<fNJetPtSlices; i++){ // 2nd loop: need to close input file before placing histos
1765 if(hEffPtBgr[i]) new(fh1EffBgrPt[i]) TH1F(*hEffPtBgr[i]);
1766 if(hEffZBgr[i]) new(fh1EffBgrZ[i]) TH1F(*hEffZBgr[i]);
1767 if(hEffXiBgr[i]) new(fh1EffBgrXi[i]) TH1F(*hEffXiBgr[i]);
1771 // ________________________________________________
1772 void AliFragmentationFunctionCorrections::EffCorr()
1774 // apply efficiency correction
1776 AddCorrectionLevel("eff");
1778 for(Int_t i=0; i<fNJetPtSlices; i++){
1780 TH1F* histPt = fCorrFF[fNCorrectionLevels-2]->GetTrackPt(i);
1781 TH1F* histZ = fCorrFF[fNCorrectionLevels-2]->GetZ(i);
1782 TH1F* histXi = fCorrFF[fNCorrectionLevels-2]->GetXi(i);
1784 TString histNamePt = histPt->GetName();
1785 TString histNameZ = histZ->GetName();
1786 TString histNameXi = histXi->GetName();
1789 TH1F* hFFTrackPtEffCorr = (TH1F*) histPt->Clone(histNamePt);
1790 hFFTrackPtEffCorr->Divide(histPt,fh1EffPt[i],1,1,"");
1792 TH1F* hFFZEffCorr = (TH1F*) histZ->Clone(histNameZ);
1793 hFFZEffCorr->Divide(histZ,fh1EffZ[i],1,1,"");
1795 TH1F* hFFXiEffCorr = (TH1F*) histXi->Clone(histNameXi);
1796 hFFXiEffCorr->Divide(histXi,fh1EffXi[i],1,1,"");
1798 fCorrFF[fNCorrectionLevels-1]->AddCorrHistos(i,hFFTrackPtEffCorr,hFFZEffCorr,hFFXiEffCorr);
1802 //___________________________________________________
1803 void AliFragmentationFunctionCorrections::EffCorrBgr()
1805 // apply efficiency correction to bgr distributions
1807 AddCorrectionLevelBgr("eff");
1809 Printf("%s:%d -- apply efficiency correction, corrLevel %d",(char*)__FILE__,__LINE__,fNCorrectionLevels-1);
1811 for(Int_t i=0; i<fNJetPtSlices; i++){
1813 TH1F* histPt = fCorrBgr[fNCorrectionLevelsBgr-2]->GetTrackPt(i);
1814 TH1F* histZ = fCorrBgr[fNCorrectionLevelsBgr-2]->GetZ(i);
1815 TH1F* histXi = fCorrBgr[fNCorrectionLevelsBgr-2]->GetXi(i);
1817 TString histNamePt = histPt->GetName();
1818 TString histNameZ = histZ->GetName();
1819 TString histNameXi = histXi->GetName();
1822 TH1F* hFFTrackPtEffCorr = (TH1F*) histPt->Clone(histNamePt);
1823 hFFTrackPtEffCorr->Divide(histPt,fh1EffPt[i],1,1,"");
1825 TH1F* hFFZEffCorr = (TH1F*) histZ->Clone(histNameZ);
1826 hFFZEffCorr->Divide(histZ,fh1EffZ[i],1,1,"");
1828 TH1F* hFFXiEffCorr = (TH1F*) histXi->Clone(histNameXi);
1829 hFFXiEffCorr->Divide(histXi,fh1EffXi[i],1,1,"");
1831 fCorrBgr[fNCorrectionLevelsBgr-1]->AddCorrHistos(i,hFFTrackPtEffCorr,hFFZEffCorr,hFFXiEffCorr);
1835 //______________________________________________________________________
1836 void AliFragmentationFunctionCorrections::XiShift(const Int_t corrLevel)
1838 // re-evaluate jet energy after FF corrections from dN/dpt distribution
1839 // apply correction (shift) to dN/dxi distribution: xi = ln (pt/E) -> xi' = ln (pt/E') = ln (pt/E x E/E') = xi + ln E/E'
1840 // argument corrlevel: which level of correction to be corrected/shifted to
1842 if(corrLevel>=fNCorrectionLevels){
1843 Printf(" calc xi shift: corrLevel exceeded - do nothing");
1847 Double_t* jetPtUncorr = new Double_t[fNJetPtSlices];
1848 Double_t* jetPtCorr = new Double_t[fNJetPtSlices];
1849 Double_t* deltaXi = new Double_t[fNJetPtSlices];
1851 for(Int_t i=0; i<fNJetPtSlices; i++){
1853 TH1F* histPtRaw = fCorrFF[0]->GetTrackPt(i);
1854 TH1F* histPt = fCorrFF[corrLevel]->GetTrackPt(i);
1856 Double_t ptUncorr = 0;
1857 Double_t ptCorr = 0;
1859 for(Int_t bin = 1; bin<=histPtRaw->GetNbinsX(); bin++){
1861 Double_t cont = histPtRaw->GetBinContent(bin);
1862 Double_t width = histPtRaw->GetBinWidth(bin);
1863 Double_t meanPt = histPtRaw->GetBinCenter(bin);
1865 ptUncorr += meanPt*cont*width;
1868 for(Int_t bin = 1; bin<=histPt->GetNbinsX(); bin++){
1870 Double_t cont = histPt->GetBinContent(bin);
1871 Double_t width = histPt->GetBinWidth(bin);
1872 Double_t meanPt = histPt->GetBinCenter(bin);
1874 ptCorr += meanPt*cont*width;
1877 jetPtUncorr[i] = ptUncorr;
1878 jetPtCorr[i] = ptCorr;
1881 // calc dXi from dN/dpt distribution :
1882 // sum over track pt for raw and corrected FF is equivalent to raw/corrected jet pt
1884 for(Int_t i=0; i<fNJetPtSlices; i++){
1886 Float_t jetPtLoLim = fJetPtSlices->At(i);
1887 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
1889 Double_t meanJetPt = 0.5*(jetPtUpLim+jetPtLoLim);
1891 Double_t ptUncorr = jetPtUncorr[i];
1892 Double_t ptCorr = jetPtCorr[i];
1894 Double_t dXi = TMath::Log(ptCorr/ptUncorr);
1896 Printf(" calc xi shift: jet pt slice %d, mean jet pt %f, ptUncorr %f, ptCorr %f, ratio corr/uncorr %f, dXi %f "
1897 ,i,meanJetPt,ptUncorr,ptCorr,ptCorr/ptUncorr,dXi);
1902 // book & fill new dN/dxi histos
1904 for(Int_t i=0; i<fNJetPtSlices; i++){
1906 TH1F* histXi = fCorrFF[corrLevel]->GetXi(i);
1908 Double_t dXi = deltaXi[i];
1910 Int_t nBins = histXi->GetNbinsX();
1911 const Double_t* binsVec = histXi->GetXaxis()->GetXbins()->GetArray();
1912 Float_t binsVecNew[nBins+1];
1914 TString strName = histXi->GetName();
1915 strName.Append("_shift");
1916 TString strTit = histXi->GetTitle();
1920 // create shifted histo ...
1922 if(binsVec){ // binsVec only neq NULL if histo was rebinned before
1924 for(Int_t bin=0; bin<nBins+1; bin++) binsVecNew[bin] = binsVec[bin] + dXi;
1925 hXiCorr = new TH1F(strName,strTit,nBins,binsVecNew);
1927 else{ // uniform bin size
1929 Double_t xMin = histXi->GetXaxis()->GetXmin();
1930 Double_t xMax = histXi->GetXaxis()->GetXmax();
1935 hXiCorr = new TH1F(strName,strTit,nBins,xMin,xMax);
1940 for(Int_t bin=1; bin<nBins+1; bin++){
1941 Double_t cont = histXi->GetBinContent(bin);
1942 Double_t err = histXi->GetBinError(bin);
1944 hXiCorr->SetBinContent(bin,cont);
1945 hXiCorr->SetBinError(bin,err);
1948 new(fh1FFXiShift[i]) TH1F(*hXiCorr);
1952 delete[] jetPtUncorr;
1957 //_____________________________________________________
1958 void AliFragmentationFunctionCorrections::SubtractBgr()
1960 // subtract bgr distribution from FF
1961 // the current corr level is used for both
1963 AddCorrectionLevel("bgrSub");
1965 for(Int_t i=0; i<fNJetPtSlices; i++){
1967 TH1F* histPt = fCorrFF[fNCorrectionLevels-2]->GetTrackPt(i);
1968 TH1F* histZ = fCorrFF[fNCorrectionLevels-2]->GetZ(i);
1969 TH1F* histXi = fCorrFF[fNCorrectionLevels-2]->GetXi(i);
1971 TH1F* histPtBgr = fCorrBgr[fNCorrectionLevelsBgr-1]->GetTrackPt(i);
1972 TH1F* histZBgr = fCorrBgr[fNCorrectionLevelsBgr-1]->GetZ(i);
1973 TH1F* histXiBgr = fCorrBgr[fNCorrectionLevelsBgr-1]->GetXi(i);
1975 TString histNamePt = histPt->GetName();
1976 TString histNameZ = histZ->GetName();
1977 TString histNameXi = histXi->GetName();
1980 TH1F* hFFTrackPtBgrSub = (TH1F*) histPt->Clone(histNamePt);
1981 hFFTrackPtBgrSub->Add(histPtBgr,-1);
1983 TH1F* hFFZBgrSub = (TH1F*) histZ->Clone(histNameZ);
1984 hFFZBgrSub->Add(histZBgr,-1);
1986 TH1F* hFFXiBgrSub = (TH1F*) histXi->Clone(histNameXi);
1987 hFFXiBgrSub->Add(histXiBgr,-1);
1989 fCorrFF[fNCorrectionLevels-1]->AddCorrHistos(i,hFFTrackPtBgrSub,hFFZBgrSub,hFFXiBgrSub);
1993 //________________________________________________________________________________________________________________
1994 void AliFragmentationFunctionCorrections::WriteSingleTrackEff(TString strInfile, TString strID, TString strOutfile,
1995 Bool_t updateOutfile, TString strOutDir,TString strPostfix)
1997 // read task ouput from MC and write single track eff - standard dir/list
1999 TString strdir = "PWG4_FragmentationFunction_" + strID;
2000 TString strlist = "fracfunc_" + strID;
2002 WriteSingleTrackEff(strInfile,strdir,strlist,strOutfile,updateOutfile,strOutDir,strPostfix);
2005 //___________________________________________________________________________________________________________________________________
2006 void AliFragmentationFunctionCorrections::WriteSingleTrackEff(TString strInfile, TString strdir, TString strlist,
2007 TString strOutfile, Bool_t updateOutfile, TString strOutDir,TString strPostfix)
2009 // read task output from MC and write single track eff as function of pt, eta, phi
2010 // argument strlist optional - read from directory strdir if not specified
2011 // write eff to file stroutfile - by default only 'update' file (don't overwrite)
2014 TH1D* hdNdptTracksMCPrimGen;
2015 TH2D* hdNdetadphiTracksMCPrimGen;
2017 TH1D* hdNdptTracksMCPrimRec;
2018 TH2D* hdNdetadphiTracksMCPrimRec;
2021 TFile f(strInfile,"READ");
2024 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strInfile.Data());
2028 if(fDebug>0) Printf("%s:%d -- writeSingleTrackEff: open task ouput file %s ",(char*)__FILE__,__LINE__,strInfile.Data());
2030 if(strdir && strdir.Length()){
2031 if(fDebug>0) Printf("%s:%d -- writeSingleTrackEff: change dir to %s",(char*)__FILE__,__LINE__,strdir.Data());
2032 gDirectory->cd(strdir);
2037 if(strlist && strlist.Length()){
2039 if(!(list = (TList*) gDirectory->Get(strlist))){
2040 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
2046 TString hnamePtRecEffGen = "fh1TrackQAPtRecEffGen";
2047 if(strPostfix.Length()) hnamePtRecEffGen.Form("fh1TrackQAPtRecEffGen_%s",strPostfix.Data());
2049 TString hnamePtRecEffRec = "fh1TrackQAPtRecEffRec";
2050 if(strPostfix.Length()) hnamePtRecEffRec.Form("fh1TrackQAPtRecEffRec_%s",strPostfix.Data());
2052 TString hnameEtaPhiRecEffGen = "fh2TrackQAEtaPhiRecEffGen";
2053 if(strPostfix.Length()) hnameEtaPhiRecEffGen.Form("fh2TrackQAEtaPhiRecEffGen_%s",strPostfix.Data());
2055 TString hnameEtaPhiRecEffRec = "fh2TrackQAEtaPhiRecEffRec";
2056 if(strPostfix.Length()) hnameEtaPhiRecEffRec.Form("fh2TrackQAEtaPhiRecEffRec_%s",strPostfix.Data());
2060 hdNdptTracksMCPrimGen = (TH1D*) list->FindObject(hnamePtRecEffGen);
2061 hdNdetadphiTracksMCPrimGen = (TH2D*) list->FindObject(hnameEtaPhiRecEffGen);
2063 hdNdptTracksMCPrimRec = (TH1D*) list->FindObject(hnamePtRecEffRec);
2064 hdNdetadphiTracksMCPrimRec = (TH2D*) list->FindObject(hnameEtaPhiRecEffRec);
2067 hdNdptTracksMCPrimGen = (TH1D*) gDirectory->Get(hnamePtRecEffGen);
2068 hdNdetadphiTracksMCPrimGen = (TH2D*) gDirectory->Get(hnameEtaPhiRecEffGen);
2070 hdNdptTracksMCPrimRec = (TH1D*) gDirectory->Get(hnamePtRecEffRec);
2071 hdNdetadphiTracksMCPrimRec = (TH2D*) gDirectory->Get(hnameEtaPhiRecEffRec);
2074 hdNdptTracksMCPrimGen->SetDirectory(0);
2075 hdNdetadphiTracksMCPrimGen->SetDirectory(0);
2076 hdNdptTracksMCPrimRec->SetDirectory(0);
2077 hdNdetadphiTracksMCPrimRec->SetDirectory(0);
2081 // projections: dN/deta, dN/dphi
2083 TH1D* hdNdetaTracksMCPrimGen = (TH1D*) hdNdetadphiTracksMCPrimGen->ProjectionX("hdNdetaTracksMcPrimGen");
2084 TH1D* hdNdphiTracksMCPrimGen = (TH1D*) hdNdetadphiTracksMCPrimGen->ProjectionY("hdNdphiTracksMcPrimGen");
2086 TH1D* hdNdetaTracksMCPrimRec = (TH1D*) hdNdetadphiTracksMCPrimRec->ProjectionX("hdNdetaTracksMcPrimRec");
2087 TH1D* hdNdphiTracksMCPrimRec = (TH1D*) hdNdetadphiTracksMCPrimRec->ProjectionY("hdNdphiTracksMcPrimRec");
2091 TString strNamePtGen = "hTrackPtGenPrim";
2092 TString strNamePtRec = "hTrackPtRecPrim";
2094 if(fNHistoBinsSinglePt) hdNdptTracksMCPrimGen = (TH1D*) hdNdptTracksMCPrimGen->Rebin(fNHistoBinsSinglePt,strNamePtGen,fHistoBinsSinglePt->GetArray());
2095 if(fNHistoBinsSinglePt) hdNdptTracksMCPrimRec = (TH1D*) hdNdptTracksMCPrimRec->Rebin(fNHistoBinsSinglePt,strNamePtRec,fHistoBinsSinglePt->GetArray());
2097 // efficiency: divide
2099 TString hNameTrackEffPt = "hSingleTrackEffPt";
2100 if(strPostfix.Length()) hNameTrackEffPt.Form("hSingleTrackEffPt_%s",strPostfix.Data());
2102 TString hNameTrackEffEta = "hSingleTrackEffEta";
2103 if(strPostfix.Length()) hNameTrackEffEta.Form("hSingleTrackEffEta_%s",strPostfix.Data());
2105 TString hNameTrackEffPhi = "hSingleTrackEffPhi";
2106 if(strPostfix.Length()) hNameTrackEffPhi.Form("hSingleTrackEffPhi_%s",strPostfix.Data());
2109 TH1F* hSingleTrackEffPt = (TH1F*) hdNdptTracksMCPrimRec->Clone(hNameTrackEffPt);
2110 hSingleTrackEffPt->Divide(hdNdptTracksMCPrimRec,hdNdptTracksMCPrimGen,1,1,"B"); // binominal errors
2112 TH1F* hSingleTrackEffEta = (TH1F*) hdNdetaTracksMCPrimRec->Clone(hNameTrackEffEta);
2113 hSingleTrackEffEta->Divide(hdNdetaTracksMCPrimRec,hdNdetaTracksMCPrimGen,1,1,"B"); // binominal errors
2115 TH1F* hSingleTrackEffPhi = (TH1F*) hdNdphiTracksMCPrimRec->Clone(hNameTrackEffPhi);
2116 hSingleTrackEffPhi->Divide(hdNdphiTracksMCPrimRec,hdNdphiTracksMCPrimGen,1,1,"B"); // binominal errors
2119 TString outfileOption = "RECREATE";
2120 if(updateOutfile) outfileOption = "UPDATE";
2122 TFile out(strOutfile,outfileOption);
2125 Printf("%s:%d -- error opening efficiency output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
2129 if(fDebug>0) Printf("%s:%d -- write efficiency to file %s ",(char*)__FILE__,__LINE__,strOutfile.Data());
2131 if(strOutDir && strOutDir.Length()){
2134 if((dir = ((TDirectory*) gDirectory->Get(strOutDir)))) dir->cd();
2136 dir = out.mkdir(strOutDir);
2141 hSingleTrackEffPt->Write();
2142 hSingleTrackEffEta->Write();
2143 hSingleTrackEffPhi->Write();
2148 //________________________________________________________________________________________________________________
2149 void AliFragmentationFunctionCorrections::WriteSingleTrackSecCorr(TString strInfile, TString strID, TString strOutfile,
2150 Bool_t updateOutfile, TString strOutDir)
2152 // read task ouput from MC and write single track eff - standard dir/list
2154 TString strdir = "PWG4_FragmentationFunction_" + strID;
2155 TString strlist = "fracfunc_" + strID;
2157 WriteSingleTrackSecCorr(strInfile,strdir,strlist,strOutfile,updateOutfile,strOutDir);
2160 //___________________________________________________________________________________________________________________________________
2161 void AliFragmentationFunctionCorrections::WriteSingleTrackSecCorr(TString strInfile, TString strdir, TString strlist,
2162 TString strOutfile, Bool_t updateOutfile, TString strOutDir)
2164 // read task output from MC and write single track secondaries contamination correction as function of pt, eta, phi
2165 // argument strlist optional - read from directory strdir if not specified
2166 // write corr factor to file stroutfile - by default only 'update' file (don't overwrite)
2168 TH1D* hdNdptTracksMCPrimRec;
2169 TH2D* hdNdetadphiTracksMCPrimRec;
2171 TH1D* hdNdptTracksMCSecRec;
2172 TH2D* hdNdetadphiTracksMCSecRec;
2174 TFile f(strInfile,"READ");
2177 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strInfile.Data());
2181 if(fDebug>0) Printf("%s:%d -- writeSingleTrackEff: open task ouput file %s",(char*)__FILE__,__LINE__,strInfile.Data());
2183 if(strdir && strdir.Length()) gDirectory->cd(strdir);
2187 if(strlist && strlist.Length()){
2189 if(!(list = (TList*) gDirectory->Get(strlist))){
2190 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
2197 hdNdptTracksMCPrimRec = (TH1D*) list->FindObject("fh1TrackQAPtRecEffGen");
2198 hdNdetadphiTracksMCPrimRec = (TH2D*) list->FindObject("fh2TrackQAEtaPhiRecEffGen");
2200 hdNdptTracksMCSecRec = (TH1D*) list->FindObject("fh1TrackQAPtSecRec");
2201 hdNdetadphiTracksMCSecRec = (TH2D*) list->FindObject("fh2TrackQAEtaPhiSecRec");
2204 hdNdptTracksMCPrimRec = (TH1D*) gDirectory->Get("fh1TrackQAPtRecEffGen");
2205 hdNdetadphiTracksMCPrimRec = (TH2D*) gDirectory->Get("fh2TrackQAEtaPhiRecEffGen");
2207 hdNdptTracksMCSecRec = (TH1D*) gDirectory->Get("fh1TrackQAPtSecRec");
2208 hdNdetadphiTracksMCSecRec = (TH2D*) gDirectory->Get("fh2TrackQAEtaPhiSecRec");
2211 hdNdptTracksMCPrimRec->SetDirectory(0);
2212 hdNdetadphiTracksMCPrimRec->SetDirectory(0);
2213 hdNdptTracksMCSecRec->SetDirectory(0);
2214 hdNdetadphiTracksMCSecRec->SetDirectory(0);
2218 // projections: dN/deta, dN/dphi
2220 TH1D* hdNdetaTracksMCPrimRec = (TH1D*) hdNdetadphiTracksMCPrimRec->ProjectionX("hdNdetaTracksMcPrimRec");
2221 TH1D* hdNdphiTracksMCPrimRec = (TH1D*) hdNdetadphiTracksMCPrimRec->ProjectionY("hdNdphiTracksMcPrimRec");
2223 TH1D* hdNdetaTracksMCSecRec = (TH1D*) hdNdetadphiTracksMCSecRec->ProjectionX("hdNdetaTracksMcSecRec");
2224 TH1D* hdNdphiTracksMCSecRec = (TH1D*) hdNdetadphiTracksMCSecRec->ProjectionY("hdNdphiTracksMcSecRec");
2229 TString strNamePtPrim = "hTrackPtPrim";
2230 TString strNamePtSec = "hTrackPtSec";
2232 if(fNHistoBinsSinglePt) hdNdptTracksMCPrimRec = (TH1D*) hdNdptTracksMCPrimRec->Rebin(fNHistoBinsSinglePt,strNamePtPrim,fHistoBinsSinglePt->GetArray());
2233 if(fNHistoBinsSinglePt) hdNdptTracksMCSecRec = (TH1D*) hdNdptTracksMCSecRec->Rebin(fNHistoBinsSinglePt,strNamePtSec,fHistoBinsSinglePt->GetArray());
2236 // secondary correction factor: divide prim/(prim+sec)
2238 TH1F* hSingleTrackSecCorrPt = (TH1F*) hdNdptTracksMCSecRec->Clone("hSingleTrackSecCorrPt");
2239 TH1F* hSumPrimSecPt = (TH1F*) hdNdptTracksMCSecRec->Clone("hSumPrimSecPt");
2240 hSumPrimSecPt->Add(hdNdptTracksMCPrimRec);
2241 hSingleTrackSecCorrPt->Divide(hdNdptTracksMCPrimRec,hSumPrimSecPt,1,1,"B"); // binominal errors
2243 TH1F* hSingleTrackSecCorrEta = (TH1F*) hdNdetaTracksMCSecRec->Clone("hSingleTrackSecCorrEta");
2244 TH1F* hSumPrimSecEta = (TH1F*) hdNdetaTracksMCSecRec->Clone("hSumPrimSecEta");
2245 hSumPrimSecEta->Add(hdNdetaTracksMCPrimRec);
2246 hSingleTrackSecCorrEta->Divide(hdNdetaTracksMCPrimRec,hSumPrimSecEta,1,1,"B"); // binominal errors
2248 TH1F* hSingleTrackSecCorrPhi = (TH1F*) hdNdphiTracksMCSecRec->Clone("hSingleTrackSecCorrPhi");
2249 TH1F* hSumPrimSecPhi = (TH1F*) hdNdphiTracksMCSecRec->Clone("hSumPrimSecPhi");
2250 hSumPrimSecPhi->Add(hdNdphiTracksMCPrimRec);
2251 hSingleTrackSecCorrPhi->Divide(hdNdphiTracksMCPrimRec,hSumPrimSecPhi,1,1,"B"); // binominal errors
2254 TString outfileOption = "RECREATE";
2255 if(updateOutfile) outfileOption = "UPDATE";
2257 TFile out(strOutfile,outfileOption);
2260 Printf("%s:%d -- error opening secCorr output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
2264 if(fDebug>0) Printf("%s:%d -- write secCorr to file %s ",(char*)__FILE__,__LINE__,strOutfile.Data());
2266 if(strOutDir && strOutDir.Length()){
2269 if((dir = ((TDirectory*) gDirectory->Get(strOutDir)))) dir->cd();
2271 dir = out.mkdir(strOutDir);
2276 hdNdptTracksMCSecRec->Write();
2277 hdNdetaTracksMCSecRec->Write();
2278 hdNdphiTracksMCSecRec->Write();
2280 hSingleTrackSecCorrPt->Write();
2281 hSingleTrackSecCorrEta->Write();
2282 hSingleTrackSecCorrPhi->Write();
2287 //________________________________________________________________________________________________________________
2288 void AliFragmentationFunctionCorrections::WriteSingleResponse(TString strInfile, TString strID, TString strOutfile,
2289 Bool_t updateOutfile, TString strOutDir)
2291 // read task ouput from MC and write single track eff - standard dir/list
2293 TString strdir = "PWG4_FragmentationFunction_" + strID;
2294 TString strlist = "fracfunc_" + strID;
2296 WriteSingleResponse(strInfile,strdir,strlist,strOutfile,updateOutfile,strOutDir);
2300 //_____________________________________________________________________________________________________________________________________
2301 void AliFragmentationFunctionCorrections::WriteSingleResponse(TString strInfile, TString strdir, TString strlist,
2302 TString strOutfile, Bool_t updateOutfile, TString strOutDir)
2304 // read 2d THnSparse response matrices in pt from file
2306 // write to strOutfile
2308 THnSparse* hnResponseSinglePt;
2309 TH2F* h2ResponseSinglePt;
2311 TFile f(strInfile,"READ");
2314 Printf("%s:%d -- error opening file %s", (char*)__FILE__,__LINE__,strInfile.Data());
2318 if(fDebug>0) Printf("%s:%d -- read response matrices from file %s ",(char*)__FILE__,__LINE__,strInfile.Data());
2320 if(strdir && strdir.Length()) gDirectory->cd(strdir);
2324 if(strlist && strlist.Length()){
2326 if(!(list = (TList*) gDirectory->Get(strlist))){
2327 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
2332 if(list) hnResponseSinglePt = (THnSparse*) list->FindObject("fhnResponseSinglePt");
2333 else hnResponseSinglePt = (THnSparse*) gDirectory->Get("fhnResponseSinglePt");
2336 if(!hnResponseSinglePt){
2337 Printf("%s:%d -- error retrieving response matrix fhnResponseSinglePt",(char*)__FILE__,__LINE__);
2345 h2ResponseSinglePt = (TH2F*) hnResponseSinglePt->Projection(1,0);// note convention: yDim,xDim
2346 h2ResponseSinglePt->SetNameTitle("h2ResponseSinglePt","");
2351 TString outfileOption = "RECREATE";
2352 if(updateOutfile) outfileOption = "UPDATE";
2354 TFile out(strOutfile,outfileOption);
2357 Printf("%s:%d -- error opening response matrix output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
2361 if(fDebug>0) Printf("%s:%d -- write response matrices to file %s ",(char*)__FILE__,__LINE__,strOutfile.Data());
2363 if(strOutDir && strOutDir.Length()){
2366 if((dir = ((TDirectory*) gDirectory->Get(strOutDir)))) dir->cd();
2368 dir = out.mkdir(strOutDir);
2373 hnResponseSinglePt->Write();
2374 h2ResponseSinglePt->Write();
2379 //________________________________________________________________________________________________________________
2380 void AliFragmentationFunctionCorrections::WriteJetTrackEff(TString strInfile, TString strID, TString strOutfile,
2381 Bool_t updateOutfile)
2383 // read task ouput from MC and write single track eff - standard dir/list
2385 TString strdir = "PWG4_FragmentationFunction_" + strID;
2386 TString strlist = "fracfunc_" + strID;
2388 WriteJetTrackEff(strInfile,strdir,strlist,strOutfile,updateOutfile);
2391 //___________________________________________________________________________________________________________________________________
2392 void AliFragmentationFunctionCorrections::WriteJetTrackEff(TString strInfile, TString strdir, TString strlist,
2393 TString strOutfile, Bool_t updateOutfile)
2395 // read task output from MC and write track eff in jet pt slices as function of pt, z, xi
2396 // argument strlist optional - read from directory strdir if not specified
2397 // write eff to file strOutfile - by default only 'update' file (don't overwrite)
2399 TH1F* hEffPt[fNJetPtSlices];
2400 TH1F* hEffXi[fNJetPtSlices];
2401 TH1F* hEffZ[fNJetPtSlices];
2403 TH1F* hdNdptTracksMCPrimGen[fNJetPtSlices];
2404 TH1F* hdNdxiMCPrimGen[fNJetPtSlices];
2405 TH1F* hdNdzMCPrimGen[fNJetPtSlices];
2407 TH1F* hdNdptTracksMCPrimRec[fNJetPtSlices];
2408 TH1F* hdNdxiMCPrimRec[fNJetPtSlices];
2409 TH1F* hdNdzMCPrimRec[fNJetPtSlices];
2412 TH1F* fh1FFJetPtRecEffGen;
2414 TH2F* fh2FFTrackPtRecEffGen;
2415 TH2F* fh2FFZRecEffGen;
2416 TH2F* fh2FFXiRecEffGen;
2418 TH2F* fh2FFTrackPtRecEffRec;
2419 TH2F* fh2FFZRecEffRec;
2420 TH2F* fh2FFXiRecEffRec;
2423 TFile f(strInfile,"READ");
2426 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strInfile.Data());
2430 if(fDebug>0) Printf("%s:%d -- writeJetTrackEff: open task ouput file %s",(char*)__FILE__,__LINE__,strInfile.Data());
2432 if(strdir && strdir.Length()) gDirectory->cd(strdir);
2436 if(strlist && strlist.Length()){
2438 if(!(list = (TList*) gDirectory->Get(strlist))){
2439 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
2445 fh1FFJetPtRecEffGen = (TH1F*) list->FindObject("fh1FFJetPtRecEffGen");
2447 fh2FFTrackPtRecEffGen = (TH2F*) list->FindObject("fh2FFTrackPtRecEffGen");
2448 fh2FFZRecEffGen = (TH2F*) list->FindObject("fh2FFZRecEffGen");
2449 fh2FFXiRecEffGen = (TH2F*) list->FindObject("fh2FFXiRecEffGen");
2451 fh2FFTrackPtRecEffRec = (TH2F*) list->FindObject("fh2FFTrackPtRecEffRec");
2452 fh2FFZRecEffRec = (TH2F*) list->FindObject("fh2FFZRecEffRec");
2453 fh2FFXiRecEffRec = (TH2F*) list->FindObject("fh2FFXiRecEffRec");
2456 fh1FFJetPtRecEffGen = (TH1F*) gDirectory->FindObject("fh1FFJetPtRecEffGen");
2458 fh2FFTrackPtRecEffGen = (TH2F*) gDirectory->FindObject("fh2FFTrackPtRecEffGen");
2459 fh2FFZRecEffGen = (TH2F*) gDirectory->FindObject("fh2FFZRecEffGen");
2460 fh2FFXiRecEffGen = (TH2F*) gDirectory->FindObject("fh2FFXiRecEffGen");
2462 fh2FFTrackPtRecEffRec = (TH2F*) gDirectory->FindObject("fh2FFTrackPtRecEffRec");
2463 fh2FFZRecEffRec = (TH2F*) gDirectory->FindObject("fh2FFZRecEffRec");
2464 fh2FFXiRecEffRec = (TH2F*) gDirectory->FindObject("fh2FFXiRecEffRec");
2467 fh1FFJetPtRecEffGen->SetDirectory(0);
2469 fh2FFTrackPtRecEffGen->SetDirectory(0);
2470 fh2FFZRecEffGen->SetDirectory(0);
2471 fh2FFXiRecEffGen->SetDirectory(0);
2473 fh2FFTrackPtRecEffRec->SetDirectory(0);
2474 fh2FFZRecEffRec->SetDirectory(0);
2475 fh2FFXiRecEffRec->SetDirectory(0);
2480 // projections: FF for generated and reconstructed primaries
2482 for(Int_t i=0; i<fNJetPtSlices; i++){
2484 Float_t jetPtLoLim = fJetPtSlices->At(i);
2485 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
2487 Int_t binLo = static_cast<Int_t>(fh2FFTrackPtRecEffGen->GetXaxis()->FindBin(jetPtLoLim));
2488 Int_t binUp = static_cast<Int_t>(fh2FFTrackPtRecEffGen->GetXaxis()->FindBin(jetPtUpLim))-1;
2490 if(binUp > fh2FFTrackPtRecEffGen->GetNbinsX()){
2491 Printf("%s:%d -- jet pt range %0.3f exceeds histo limits",(char*)__FILE__,__LINE__,jetPtUpLim);
2495 TString strNameFFPtGen(Form("fh1FFTrackPtGenPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2496 TString strNameFFZGen(Form("fh1FFZGenPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2497 TString strNameFFXiGen(Form("fh1FFXiGenPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2499 TString strNameFFPtRec(Form("fh1FFTrackPtRecPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2500 TString strNameFFZRec(Form("fh1FFZRecPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2501 TString strNameFFXiRec(Form("fh1FFXiRecPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2504 // appendix 'unbinned' to avoid histos with same name after rebinning
2506 hdNdptTracksMCPrimGen[i] = (TH1F*) fh2FFTrackPtRecEffGen->ProjectionY(strNameFFPtGen+"_unBinned",binLo,binUp,"o"); // option "o": original axis range
2507 hdNdzMCPrimGen[i] = (TH1F*) fh2FFZRecEffGen->ProjectionY(strNameFFZGen+"_unBinned",binLo,binUp,"o");
2508 hdNdxiMCPrimGen[i] = (TH1F*) fh2FFXiRecEffGen->ProjectionY(strNameFFXiGen+"_unBinned",binLo,binUp,"o");
2510 hdNdptTracksMCPrimRec[i] = (TH1F*) fh2FFTrackPtRecEffRec->ProjectionY(strNameFFPtRec+"_unBinned",binLo,binUp,"o"); // option "o": original axis range
2511 hdNdzMCPrimRec[i] = (TH1F*) fh2FFZRecEffRec->ProjectionY(strNameFFZRec+"_unBinned",binLo,binUp,"o");
2512 hdNdxiMCPrimRec[i] = (TH1F*) fh2FFXiRecEffRec->ProjectionY(strNameFFXiRec+"_unBinned",binLo,binUp,"o");
2516 if(fNHistoBinsPt[i]) hdNdptTracksMCPrimGen[i] = (TH1F*) hdNdptTracksMCPrimGen[i]->Rebin(fNHistoBinsPt[i],strNameFFPtGen,fHistoBinsPt[i]->GetArray());
2517 if(fNHistoBinsZ[i]) hdNdzMCPrimGen[i] = (TH1F*) hdNdzMCPrimGen[i]->Rebin(fNHistoBinsZ[i],strNameFFZGen,fHistoBinsZ[i]->GetArray());
2518 if(fNHistoBinsXi[i]) hdNdxiMCPrimGen[i] = (TH1F*) hdNdxiMCPrimGen[i]->Rebin(fNHistoBinsXi[i],strNameFFXiGen,fHistoBinsXi[i]->GetArray());
2520 if(fNHistoBinsPt[i]) hdNdptTracksMCPrimRec[i] = (TH1F*) hdNdptTracksMCPrimRec[i]->Rebin(fNHistoBinsPt[i],strNameFFPtRec,fHistoBinsPt[i]->GetArray());
2521 if(fNHistoBinsZ[i]) hdNdzMCPrimRec[i] = (TH1F*) hdNdzMCPrimRec[i]->Rebin(fNHistoBinsZ[i],strNameFFZRec,fHistoBinsZ[i]->GetArray());
2522 if(fNHistoBinsXi[i]) hdNdxiMCPrimRec[i] = (TH1F*) hdNdxiMCPrimRec[i]->Rebin(fNHistoBinsXi[i],strNameFFXiRec,fHistoBinsXi[i]->GetArray());
2524 hdNdptTracksMCPrimGen[i]->SetNameTitle(strNameFFPtGen,"");
2525 hdNdzMCPrimGen[i]->SetNameTitle(strNameFFZGen,"");
2526 hdNdxiMCPrimGen[i]->SetNameTitle(strNameFFXiGen,"");
2528 hdNdptTracksMCPrimRec[i]->SetNameTitle(strNameFFPtRec,"");
2529 hdNdzMCPrimRec[i]->SetNameTitle(strNameFFZRec,"");
2530 hdNdxiMCPrimRec[i]->SetNameTitle(strNameFFXiRec,"");
2534 Double_t nJetsBin = fh1FFJetPtRecEffGen->Integral(binLo,binUp);
2536 NormalizeTH1(hdNdptTracksMCPrimGen[i],nJetsBin);
2537 NormalizeTH1(hdNdzMCPrimGen[i],nJetsBin);
2538 NormalizeTH1(hdNdxiMCPrimGen[i],nJetsBin);
2540 NormalizeTH1(hdNdptTracksMCPrimRec[i],nJetsBin);
2541 NormalizeTH1(hdNdzMCPrimRec[i],nJetsBin);
2542 NormalizeTH1(hdNdxiMCPrimRec[i],nJetsBin);
2544 // divide rec/gen : efficiency
2546 TString strNameEffPt(Form("hEffPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2547 TString strNameEffZ(Form("hEffZ_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2548 TString strNameEffXi(Form("hEffXi_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2550 hEffPt[i] = (TH1F*) hdNdptTracksMCPrimRec[i]->Clone(strNameEffPt);
2551 hEffPt[i]->Divide(hdNdptTracksMCPrimRec[i],hdNdptTracksMCPrimGen[i],1,1,"B"); // binominal errors
2553 hEffXi[i] = (TH1F*) hdNdxiMCPrimRec[i]->Clone(strNameEffXi);
2554 hEffXi[i]->Divide(hdNdxiMCPrimRec[i],hdNdxiMCPrimGen[i],1,1,"B"); // binominal errors
2556 hEffZ[i] = (TH1F*) hdNdzMCPrimRec[i]->Clone(strNameEffZ);
2557 hEffZ[i]->Divide(hdNdzMCPrimRec[i],hdNdzMCPrimGen[i],1,1,"B"); // binominal errors
2562 TString outfileOption = "RECREATE";
2563 if(updateOutfile) outfileOption = "UPDATE";
2565 TFile out(strOutfile,outfileOption);
2568 Printf("%s:%d -- error opening efficiency output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
2572 if(fDebug>0) Printf("%s:%d -- write efficiency to file %s ",(char*)__FILE__,__LINE__,strOutfile.Data());
2574 // if(strdir && strdir.Length()){
2575 // TDirectory* dir = out.mkdir(strdir);
2579 for(Int_t i=0; i<fNJetPtSlices; i++){
2581 hdNdptTracksMCPrimGen[i]->Write();
2582 hdNdxiMCPrimGen[i]->Write();
2583 hdNdzMCPrimGen[i]->Write();
2585 hdNdptTracksMCPrimRec[i]->Write();
2586 hdNdxiMCPrimRec[i]->Write();
2587 hdNdzMCPrimRec[i]->Write();
2598 //________________________________________________________________________________________________________________
2599 void AliFragmentationFunctionCorrections::WriteJetSecCorr(TString strInfile, TString strID, TString strOutfile,
2600 Bool_t updateOutfile)
2602 // read task ouput from MC and write secondary correction - standard dir/list
2604 TString strdir = "PWG4_FragmentationFunction_" + strID;
2605 TString strlist = "fracfunc_" + strID;
2607 WriteJetSecCorr(strInfile,strdir,strlist,strOutfile,updateOutfile);
2610 //___________________________________________________________________________________________________________________________________
2611 void AliFragmentationFunctionCorrections::WriteJetSecCorr(TString strInfile, TString strdir, TString strlist,
2612 TString strOutfile, Bool_t updateOutfile)
2614 // read task output from MC and write secondary correction in jet pt slices as function of pt, z, xi
2615 // argument strlist optional - read from directory strdir if not specified
2616 // write eff to file strOutfile - by default only 'update' file (don't overwrite)
2618 TH1F* hSecCorrPt[fNJetPtSlices];
2619 TH1F* hSecCorrXi[fNJetPtSlices];
2620 TH1F* hSecCorrZ[fNJetPtSlices];
2622 TH1F* hdNdptTracksMCPrimRec[fNJetPtSlices];
2623 TH1F* hdNdxiMCPrimRec[fNJetPtSlices];
2624 TH1F* hdNdzMCPrimRec[fNJetPtSlices];
2626 TH1F* hdNdptTracksMCSecRec[fNJetPtSlices];
2627 TH1F* hdNdxiMCSecRec[fNJetPtSlices];
2628 TH1F* hdNdzMCSecRec[fNJetPtSlices];
2630 TH1F* fh1FFJetPtRecEffGen;
2632 TH2F* fh2FFTrackPtRecEffRec;
2633 TH2F* fh2FFZRecEffRec;
2634 TH2F* fh2FFXiRecEffRec;
2636 TH2F* fh2FFTrackPtSecRec;
2638 TH2F* fh2FFXiSecRec;
2640 TFile f(strInfile,"READ");
2643 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strInfile.Data());
2647 if(fDebug>0) Printf("%s:%d -- writeJetTrackEff: open task ouput file %s",(char*)__FILE__,__LINE__,strInfile.Data());
2649 if(strdir && strdir.Length()) gDirectory->cd(strdir);
2653 if(strlist && strlist.Length()){
2655 if(!(list = (TList*) gDirectory->Get(strlist))){
2656 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
2662 fh1FFJetPtRecEffGen = (TH1F*) list->FindObject("fh1FFJetPtRecEffGen");
2664 fh2FFTrackPtRecEffRec = (TH2F*) list->FindObject("fh2FFTrackPtRecEffRec");
2665 fh2FFZRecEffRec = (TH2F*) list->FindObject("fh2FFZRecEffRec");
2666 fh2FFXiRecEffRec = (TH2F*) list->FindObject("fh2FFXiRecEffRec");
2668 fh2FFTrackPtSecRec = (TH2F*) list->FindObject("fh2FFTrackPtSecRec");
2669 fh2FFZSecRec = (TH2F*) list->FindObject("fh2FFZSecRec");
2670 fh2FFXiSecRec = (TH2F*) list->FindObject("fh2FFXiSecRec");
2673 fh1FFJetPtRecEffGen = (TH1F*) gDirectory->FindObject("fh1FFJetPtRecEffGen");
2675 fh2FFTrackPtRecEffRec = (TH2F*) gDirectory->FindObject("fh2FFTrackPtRecEffRec");
2676 fh2FFZRecEffRec = (TH2F*) gDirectory->FindObject("fh2FFZRecEffRec");
2677 fh2FFXiRecEffRec = (TH2F*) gDirectory->FindObject("fh2FFXiRecEffRec");
2679 fh2FFTrackPtSecRec = (TH2F*) gDirectory->FindObject("fh2FFTrackPtSecRec");
2680 fh2FFZSecRec = (TH2F*) gDirectory->FindObject("fh2FFZSecRec");
2681 fh2FFXiSecRec = (TH2F*) gDirectory->FindObject("fh2FFXiSecRec");
2684 fh1FFJetPtRecEffGen->SetDirectory(0);
2686 fh2FFTrackPtRecEffRec->SetDirectory(0);
2687 fh2FFZRecEffRec->SetDirectory(0);
2688 fh2FFXiRecEffRec->SetDirectory(0);
2690 fh2FFTrackPtSecRec->SetDirectory(0);
2691 fh2FFZSecRec->SetDirectory(0);
2692 fh2FFXiSecRec->SetDirectory(0);
2697 // projections: FF for generated and reconstructed primaries
2699 for(Int_t i=0; i<fNJetPtSlices; i++){
2701 Float_t jetPtLoLim = fJetPtSlices->At(i);
2702 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
2704 Int_t binLo = static_cast<Int_t>(fh2FFTrackPtRecEffRec->GetXaxis()->FindBin(jetPtLoLim));
2705 Int_t binUp = static_cast<Int_t>(fh2FFTrackPtRecEffRec->GetXaxis()->FindBin(jetPtUpLim))-1;
2707 if(binUp > fh2FFTrackPtRecEffRec->GetNbinsX()){
2708 Printf("%s:%d -- jet pt range %0.3f exceeds histo limits",(char*)__FILE__,__LINE__,jetPtUpLim);
2712 TString strNameFFPtPrimRec(Form("fh1FFTrackPtRecPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2713 TString strNameFFZPrimRec(Form("fh1FFZRecPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2714 TString strNameFFXiPrimRec(Form("fh1FFXiRecPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2716 TString strNameFFPtSecRec(Form("fh1FFTrackPtRecSec_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2717 TString strNameFFZSecRec(Form("fh1FFZRecSec_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2718 TString strNameFFXiSecRec(Form("fh1FFXiRecSec_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2721 // appendix 'unbinned' to avoid histos with same name after rebinning
2723 hdNdptTracksMCPrimRec[i] = (TH1F*) fh2FFTrackPtRecEffRec->ProjectionY(strNameFFPtPrimRec+"_unBinned",binLo,binUp,"o"); // option "o": original axis range
2724 hdNdzMCPrimRec[i] = (TH1F*) fh2FFZRecEffRec->ProjectionY(strNameFFZPrimRec+"_unBinned",binLo,binUp,"o");
2725 hdNdxiMCPrimRec[i] = (TH1F*) fh2FFXiRecEffRec->ProjectionY(strNameFFXiPrimRec+"_unBinned",binLo,binUp,"o");
2727 hdNdptTracksMCSecRec[i] = (TH1F*) fh2FFTrackPtSecRec->ProjectionY(strNameFFPtSecRec+"_unBinned",binLo,binUp,"o"); // option "o": original axis range
2728 hdNdzMCSecRec[i] = (TH1F*) fh2FFZSecRec->ProjectionY(strNameFFZSecRec+"_unBinned",binLo,binUp,"o");
2729 hdNdxiMCSecRec[i] = (TH1F*) fh2FFXiSecRec->ProjectionY(strNameFFXiSecRec+"_unBinned",binLo,binUp,"o");
2733 if(fNHistoBinsPt[i]) hdNdptTracksMCPrimRec[i] = (TH1F*) hdNdptTracksMCPrimRec[i]->Rebin(fNHistoBinsPt[i],strNameFFPtPrimRec,fHistoBinsPt[i]->GetArray());
2734 if(fNHistoBinsZ[i]) hdNdzMCPrimRec[i] = (TH1F*) hdNdzMCPrimRec[i]->Rebin(fNHistoBinsZ[i],strNameFFZPrimRec,fHistoBinsZ[i]->GetArray());
2735 if(fNHistoBinsXi[i]) hdNdxiMCPrimRec[i] = (TH1F*) hdNdxiMCPrimRec[i]->Rebin(fNHistoBinsXi[i],strNameFFXiPrimRec,fHistoBinsXi[i]->GetArray());
2737 if(fNHistoBinsPt[i]) hdNdptTracksMCSecRec[i] = (TH1F*) hdNdptTracksMCSecRec[i]->Rebin(fNHistoBinsPt[i],strNameFFPtSecRec,fHistoBinsPt[i]->GetArray());
2738 if(fNHistoBinsZ[i]) hdNdzMCSecRec[i] = (TH1F*) hdNdzMCSecRec[i]->Rebin(fNHistoBinsZ[i],strNameFFZSecRec,fHistoBinsZ[i]->GetArray());
2739 if(fNHistoBinsXi[i]) hdNdxiMCSecRec[i] = (TH1F*) hdNdxiMCSecRec[i]->Rebin(fNHistoBinsXi[i],strNameFFXiSecRec,fHistoBinsXi[i]->GetArray());
2741 hdNdptTracksMCPrimRec[i]->SetNameTitle(strNameFFPtPrimRec,"");
2742 hdNdzMCPrimRec[i]->SetNameTitle(strNameFFZPrimRec,"");
2743 hdNdxiMCPrimRec[i]->SetNameTitle(strNameFFXiPrimRec,"");
2745 hdNdptTracksMCSecRec[i]->SetNameTitle(strNameFFPtSecRec,"");
2746 hdNdzMCSecRec[i]->SetNameTitle(strNameFFZSecRec,"");
2747 hdNdxiMCSecRec[i]->SetNameTitle(strNameFFXiSecRec,"");
2751 Double_t nJetsBin = fh1FFJetPtRecEffGen->Integral(binLo,binUp);
2753 NormalizeTH1(hdNdptTracksMCPrimRec[i],nJetsBin);
2754 NormalizeTH1(hdNdzMCPrimRec[i],nJetsBin);
2755 NormalizeTH1(hdNdxiMCPrimRec[i],nJetsBin);
2757 NormalizeTH1(hdNdptTracksMCSecRec[i],nJetsBin);
2758 NormalizeTH1(hdNdzMCSecRec[i],nJetsBin);
2759 NormalizeTH1(hdNdxiMCSecRec[i],nJetsBin);
2761 // divide rec/gen : efficiency
2763 TString strNameSecCorrPt(Form("hSecCorrPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2764 TString strNameSecCorrZ(Form("hSecCorrZ_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2765 TString strNameSecCorrXi(Form("hSecCorrXi_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2767 hSecCorrPt[i] = (TH1F*) hdNdptTracksMCSecRec[i]->Clone(strNameSecCorrPt);
2768 TH1F* hSumPrimSecPt = (TH1F*) hdNdptTracksMCSecRec[i]->Clone("hSumPrimSecPt");
2769 hSumPrimSecPt->Add(hdNdptTracksMCPrimRec[i]);
2770 hSecCorrPt[i]->Divide(hdNdptTracksMCPrimRec[i],hSumPrimSecPt,1,1,"B"); // binominal errors
2772 hSecCorrXi[i] = (TH1F*) hdNdxiMCSecRec[i]->Clone(strNameSecCorrXi);
2773 TH1F* hSumPrimSecXi = (TH1F*) hdNdxiMCSecRec[i]->Clone("hSumPrimSecXi");
2774 hSumPrimSecXi->Add(hdNdxiMCPrimRec[i]);
2775 hSecCorrXi[i]->Divide(hdNdxiMCPrimRec[i],hSumPrimSecXi,1,1,"B"); // binominal errors
2777 hSecCorrZ[i] = (TH1F*) hdNdzMCSecRec[i]->Clone(strNameSecCorrZ);
2778 TH1F* hSumPrimSecZ = (TH1F*) hdNdzMCSecRec[i]->Clone("hSumPrimSecZ");
2779 hSumPrimSecZ->Add(hdNdzMCPrimRec[i]);
2780 hSecCorrZ[i]->Divide(hdNdzMCPrimRec[i],hSumPrimSecZ,1,1,"B"); // binominal errors
2785 TString outfileOption = "RECREATE";
2786 if(updateOutfile) outfileOption = "UPDATE";
2788 TFile out(strOutfile,outfileOption);
2791 Printf("%s:%d -- error opening efficiency output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
2795 if(fDebug>0) Printf("%s:%d -- write efficiency to file %s ",(char*)__FILE__,__LINE__,strOutfile.Data());
2797 for(Int_t i=0; i<fNJetPtSlices; i++){
2799 // hdNdptTracksMCSecRec[i]->Write();
2800 // hdNdxiMCSecRec[i]->Write();
2801 // hdNdzMCSecRec[i]->Write();
2803 hSecCorrPt[i]->Write();
2804 hSecCorrXi[i]->Write();
2805 hSecCorrZ[i]->Write();
2811 //________________________________________________________________________________________________________________
2812 void AliFragmentationFunctionCorrections::WriteJetResponse(TString strInfile, TString strID, TString strOutfile,
2813 Bool_t updateOutfile)
2815 // read task ouput from MC and write single track eff - standard dir/list
2817 TString strdir = "PWG4_FragmentationFunction_" + strID;
2818 TString strlist = "fracfunc_" + strID;
2820 WriteJetResponse(strInfile,strdir,strlist,strOutfile,updateOutfile);
2823 //_____________________________________________________________________________________________________________________________________
2824 void AliFragmentationFunctionCorrections::WriteJetResponse(TString strInfile, TString strdir, TString strlist,
2825 TString strOutfile, Bool_t updateOutfile)
2827 // read 3d THnSparse response matrices in pt,z,xi vs jet pt from file
2828 // project THnSparse + TH2 in jet pt slices
2829 // write to strOutfile
2831 THnSparse* hn3ResponseJetPt;
2832 THnSparse* hn3ResponseJetZ;
2833 THnSparse* hn3ResponseJetXi;
2835 // 2D response matrices
2837 THnSparse* hnResponsePt[fNJetPtSlices];
2838 THnSparse* hnResponseZ[fNJetPtSlices];
2839 THnSparse* hnResponseXi[fNJetPtSlices];
2841 TH2F* h2ResponsePt[fNJetPtSlices];
2842 TH2F* h2ResponseZ[fNJetPtSlices];
2843 TH2F* h2ResponseXi[fNJetPtSlices];
2845 // 1D projections on gen pt / rec pt axes
2847 TH1F* h1FFPtRec[fNJetPtSlices];
2848 TH1F* h1FFZRec[fNJetPtSlices];
2849 TH1F* h1FFXiRec[fNJetPtSlices];
2851 TH1F* h1FFPtGen[fNJetPtSlices];
2852 TH1F* h1FFZGen[fNJetPtSlices];
2853 TH1F* h1FFXiGen[fNJetPtSlices];
2855 TH1F* h1RatioPt[fNJetPtSlices];
2856 TH1F* h1RatioZ[fNJetPtSlices];
2857 TH1F* h1RatioXi[fNJetPtSlices];
2861 TFile f(strInfile,"READ");
2864 Printf("%s:%d -- error opening file %s", (char*)__FILE__,__LINE__,strInfile.Data());
2868 if(fDebug>0) Printf("%s:%d -- read response matrices from file %s ",(char*)__FILE__,__LINE__,strInfile.Data());
2870 if(strdir && strdir.Length()) gDirectory->cd(strdir);
2874 if(strlist && strlist.Length()){
2876 if(!(list = (TList*) gDirectory->Get(strlist))){
2877 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
2883 hn3ResponseJetPt = (THnSparse*) list->FindObject("fhnResponseJetTrackPt");
2884 hn3ResponseJetZ = (THnSparse*) list->FindObject("fhnResponseJetZ");
2885 hn3ResponseJetXi = (THnSparse*) list->FindObject("fhnResponseJetXi");
2888 hn3ResponseJetPt = (THnSparse*) gDirectory->Get("fhnResponseJetTrackPt");
2889 hn3ResponseJetZ = (THnSparse*) gDirectory->Get("fhnResponseJetZ");
2890 hn3ResponseJetXi = (THnSparse*) gDirectory->Get("fhnResponseJetXi");
2894 if(!hn3ResponseJetPt){
2895 Printf("%s:%d -- error retrieving response matrix fhnResponseJetTrackPt",(char*)__FILE__,__LINE__);
2899 if(!hn3ResponseJetZ){
2900 Printf("%s:%d -- error retrieving response matrix fhnResponseJetZ",(char*)__FILE__,__LINE__);
2904 if(!hn3ResponseJetXi){
2905 Printf("%s:%d -- error retrieving response matrix fhnResponseJetXi",(char*)__FILE__,__LINE__);
2913 Int_t axisJetPtTHn3 = -1;
2914 Int_t axisGenPtTHn3 = -1;
2915 Int_t axisRecPtTHn3 = -1;
2917 for(Int_t i=0; i<hn3ResponseJetPt->GetNdimensions(); i++){
2919 TString title = hn3ResponseJetPt->GetAxis(i)->GetTitle();
2921 if(title.Contains("jet p_{T}")) axisJetPtTHn3 = i;
2922 if(title.Contains("gen p_{T}")) axisGenPtTHn3 = i;
2923 if(title.Contains("rec p_{T}")) axisRecPtTHn3 = i;
2926 if(axisJetPtTHn3 == -1){
2927 Printf("%s:%d -- error axisJetPtTHn3",(char*)__FILE__,__LINE__);
2931 if(axisGenPtTHn3 == -1){
2932 Printf("%s:%d -- error axisGenPtTHn3",(char*)__FILE__,__LINE__);
2936 if(axisRecPtTHn3 == -1){
2937 Printf("%s:%d -- error axisRecPtTHn3",(char*)__FILE__,__LINE__);
2941 for(Int_t i=0; i<fNJetPtSlices; i++){
2943 Float_t jetPtLoLim = fJetPtSlices->At(i);
2944 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
2946 Int_t binLo = static_cast<Int_t>(hn3ResponseJetPt->GetAxis(axisJetPtTHn3)->FindBin(jetPtLoLim));
2947 Int_t binUp = static_cast<Int_t>(hn3ResponseJetPt->GetAxis(axisJetPtTHn3)->FindBin(jetPtUpLim))-1;
2949 if(binUp > hn3ResponseJetPt->GetAxis(axisJetPtTHn3)->GetNbins()){
2950 Printf("%s:%d -- jet pt range %0.3f exceeds histo limits",(char*)__FILE__,__LINE__,jetPtUpLim);
2954 TString strNameRespPt(Form("hnResponsePt_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2955 TString strNameRespZ(Form("hnResponseZ_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2956 TString strNameRespXi(Form("hnResponseXi_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2958 TString strNameTH2RespPt(Form("h2ResponsePt_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2959 TString strNameTH2RespZ(Form("h2ResponseZ_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2960 TString strNameTH2RespXi(Form("h2ResponseXi_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2962 TString strNameRecPt(Form("h1FFTrackPtRecPrim_recPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2963 TString strNameRecZ(Form("h1FFZRecPrim_recPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2964 TString strNameRecXi(Form("h1FFXiRecPrim_recPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2966 TString strNameGenPt(Form("h1FFTrackPtRecPrim_genPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2967 TString strNameGenZ(Form("h1FFZRecPrim_genPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2968 TString strNameGenXi(Form("h1FFXiRecPrim_genPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2970 TString strNameRatioPt(Form("h1RatioTrackPtRecPrim_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2971 TString strNameRatioZ(Form("h1RatioZRecPrim_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2972 TString strNameRatioXi(Form("h1RatioXiRecPrim_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2975 // 2D projections in jet pt range
2977 hn3ResponseJetPt->GetAxis(axisJetPtTHn3)->SetRange(binLo,binUp);
2978 hn3ResponseJetZ->GetAxis(axisJetPtTHn3)->SetRange(binLo,binUp);
2979 hn3ResponseJetXi->GetAxis(axisJetPtTHn3)->SetRange(binLo,binUp);
2981 Int_t axesProj[2] = {axisRecPtTHn3,axisGenPtTHn3};
2983 hnResponsePt[i] = hn3ResponseJetPt->Projection(2,axesProj);
2984 hnResponseZ[i] = hn3ResponseJetZ->Projection(2,axesProj);
2985 hnResponseXi[i] = hn3ResponseJetXi->Projection(2,axesProj);
2987 hnResponsePt[i]->SetNameTitle(strNameRespPt,"");
2988 hnResponseZ[i]->SetNameTitle(strNameRespZ,"");
2989 hnResponseXi[i]->SetNameTitle(strNameRespXi,"");
2991 h2ResponsePt[i] = (TH2F*) hnResponsePt[i]->Projection(1,0);// note convention: yDim,xDim
2992 h2ResponseZ[i] = (TH2F*) hnResponseZ[i]->Projection(1,0); // note convention: yDim,xDim
2993 h2ResponseXi[i] = (TH2F*) hnResponseXi[i]->Projection(1,0);// note convention: yDim,xDim
2995 h2ResponsePt[i]->SetNameTitle(strNameTH2RespPt,"");
2996 h2ResponseZ[i]->SetNameTitle(strNameTH2RespZ,"");
2997 h2ResponseXi[i]->SetNameTitle(strNameTH2RespXi,"");
3002 Int_t axisGenPtTHn2 = -1;
3003 Int_t axisRecPtTHn2 = -1;
3005 for(Int_t d=0; d<hnResponsePt[i]->GetNdimensions(); d++){
3007 TString title = hnResponsePt[i]->GetAxis(d)->GetTitle();
3009 if(title.Contains("gen p_{T}")) axisGenPtTHn2 = d;
3010 if(title.Contains("rec p_{T}")) axisRecPtTHn2 = d;
3014 if(axisGenPtTHn2 == -1){
3015 Printf("%s:%d -- error axisGenPtTHn2",(char*)__FILE__,__LINE__);
3019 if(axisRecPtTHn2 == -1){
3020 Printf("%s:%d -- error axisRecPtTHn2",(char*)__FILE__,__LINE__);
3025 h1FFPtRec[i] = (TH1F*) hnResponsePt[i]->Projection(axisRecPtTHn2);// note convention: yDim,xDim
3026 h1FFZRec[i] = (TH1F*) hnResponseZ[i]->Projection(axisRecPtTHn2);// note convention: yDim,xDim
3027 h1FFXiRec[i] = (TH1F*) hnResponseXi[i]->Projection(axisRecPtTHn2);// note convention: yDim,xDim
3029 h1FFPtRec[i]->SetNameTitle(strNameRecPt,"");
3030 h1FFZRec[i]->SetNameTitle(strNameRecZ,"");
3031 h1FFXiRec[i]->SetNameTitle(strNameRecXi,"");
3033 h1FFPtGen[i] = (TH1F*) hnResponsePt[i]->Projection(axisGenPtTHn2);// note convention: yDim,xDim
3034 h1FFZGen[i] = (TH1F*) hnResponseZ[i]->Projection(axisGenPtTHn2);// note convention: yDim,xDim
3035 h1FFXiGen[i] = (TH1F*) hnResponseXi[i]->Projection(axisGenPtTHn2);// note convention: yDim,xDim
3037 h1FFPtGen[i]->SetNameTitle(strNameGenPt,"");
3038 h1FFZGen[i]->SetNameTitle(strNameGenZ,"");
3039 h1FFXiGen[i]->SetNameTitle(strNameGenXi,"");
3041 // normalize 1D projections
3043 if(fNHistoBinsPt[i]) h1FFPtRec[i] = (TH1F*) h1FFPtRec[i]->Rebin(fNHistoBinsPt[i],"",fHistoBinsPt[i]->GetArray());
3044 if(fNHistoBinsZ[i]) h1FFZRec[i] = (TH1F*) h1FFZRec[i]->Rebin(fNHistoBinsZ[i],"",fHistoBinsZ[i]->GetArray());
3045 if(fNHistoBinsXi[i]) h1FFXiRec[i] = (TH1F*) h1FFXiRec[i]->Rebin(fNHistoBinsXi[i],"",fHistoBinsXi[i]->GetArray());
3047 if(fNHistoBinsPt[i]) h1FFPtGen[i] = (TH1F*) h1FFPtGen[i]->Rebin(fNHistoBinsPt[i],"",fHistoBinsPt[i]->GetArray());
3048 if(fNHistoBinsZ[i]) h1FFZGen[i] = (TH1F*) h1FFZGen[i]->Rebin(fNHistoBinsZ[i],"",fHistoBinsZ[i]->GetArray());
3049 if(fNHistoBinsXi[i]) h1FFXiGen[i] = (TH1F*) h1FFXiGen[i]->Rebin(fNHistoBinsXi[i],"",fHistoBinsXi[i]->GetArray());
3051 NormalizeTH1(h1FFPtRec[i],fNJets->At(i));
3052 NormalizeTH1(h1FFZRec[i],fNJets->At(i));
3053 NormalizeTH1(h1FFXiRec[i],fNJets->At(i));
3055 NormalizeTH1(h1FFPtGen[i],fNJets->At(i));
3056 NormalizeTH1(h1FFZGen[i],fNJets->At(i));
3057 NormalizeTH1(h1FFXiGen[i],fNJets->At(i));
3059 // ratios 1D projections
3061 h1RatioPt[i] = (TH1F*) h1FFPtRec[i]->Clone(strNameRatioPt);
3062 h1RatioPt[i]->Reset();
3063 h1RatioPt[i]->Divide(h1FFPtRec[i],h1FFPtGen[i],1,1,"B");
3065 h1RatioZ[i] = (TH1F*) h1FFZRec[i]->Clone(strNameRatioZ);
3066 h1RatioZ[i]->Reset();
3067 h1RatioZ[i]->Divide(h1FFZRec[i],h1FFZGen[i],1,1,"B");
3069 h1RatioXi[i] = (TH1F*) h1FFXiRec[i]->Clone(strNameRatioXi);
3070 h1RatioXi[i]->Reset();
3071 h1RatioXi[i]->Divide(h1FFXiRec[i],h1FFXiGen[i],1,1,"B");
3077 TString outfileOption = "RECREATE";
3078 if(updateOutfile) outfileOption = "UPDATE";
3080 TFile out(strOutfile,outfileOption);
3083 Printf("%s:%d -- error opening response matrix output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
3087 if(fDebug>0) Printf("%s:%d -- write response matrices to file %s ",(char*)__FILE__,__LINE__,strOutfile.Data());
3089 //if(strdir && strdir.Length()){
3090 // TDirectory* dir = out.mkdir(strdir);
3094 for(Int_t i=0; i<fNJetPtSlices; i++){
3096 hnResponsePt[i]->Write();
3097 hnResponseXi[i]->Write();
3098 hnResponseZ[i]->Write();
3100 h2ResponsePt[i]->Write();
3101 h2ResponseXi[i]->Write();
3102 h2ResponseZ[i]->Write();
3104 h1FFPtRec[i]->Write();
3105 h1FFZRec[i]->Write();
3106 h1FFXiRec[i]->Write();
3108 h1FFPtGen[i]->Write();
3109 h1FFZGen[i]->Write();
3110 h1FFXiGen[i]->Write();
3112 h1RatioPt[i]->Write();
3113 h1RatioZ[i]->Write();
3114 h1RatioXi[i]->Write();
3121 //______________________________________________________________________________________________________
3122 void AliFragmentationFunctionCorrections::ReadResponse(TString strfile, TString strdir, TString strlist)
3124 // read response matrices from file
3125 // argument strlist optional - read from directory strdir if not specified
3126 // note: THnSparse are not rebinned
3128 THnSparse* hRespPt[fNJetPtSlices];
3129 THnSparse* hRespZ[fNJetPtSlices];
3130 THnSparse* hRespXi[fNJetPtSlices];
3132 for(Int_t i=0; i<fNJetPtSlices; i++) hRespPt[i] = 0;
3133 for(Int_t i=0; i<fNJetPtSlices; i++) hRespZ[i] = 0;
3134 for(Int_t i=0; i<fNJetPtSlices; i++) hRespXi[i] = 0;
3136 TFile f(strfile,"READ");
3139 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
3143 if(fDebug>0) Printf("%s:%d -- read response matrices from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3145 if(strdir && strdir.Length()) gDirectory->cd(strdir);
3149 if(strlist && strlist.Length()){
3151 if(!(list = (TList*) gDirectory->Get(strlist))){
3152 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
3157 for(Int_t i=0; i<fNJetPtSlices; i++){
3159 Int_t jetPtLoLim = static_cast<Int_t> (fJetPtSlices->At(i));
3160 Int_t jetPtUpLim = static_cast<Int_t> (fJetPtSlices->At(i+1));
3162 TString strNameRespPt(Form("hnResponsePt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3163 TString strNameRespZ(Form("hnResponseZ_%02d_%02d",jetPtLoLim,jetPtUpLim));
3164 TString strNameRespXi(Form("hnResponseXi_%02d_%02d",jetPtLoLim,jetPtUpLim));
3167 hRespPt[i] = (THnSparse*) list->FindObject(strNameRespPt);
3168 hRespZ[i] = (THnSparse*) list->FindObject(strNameRespZ);
3169 hRespXi[i] = (THnSparse*) list->FindObject(strNameRespXi);
3172 hRespPt[i] = (THnSparse*) gDirectory->Get(strNameRespPt);
3173 hRespZ[i] = (THnSparse*) gDirectory->Get(strNameRespZ);
3174 hRespXi[i] = (THnSparse*) gDirectory->Get(strNameRespXi);
3178 Printf("%s:%d -- error retrieving response %s", (char*)__FILE__,__LINE__,strNameRespPt.Data());
3182 Printf("%s:%d -- error retrieving response %s", (char*)__FILE__,__LINE__,strNameRespZ.Data());
3186 Printf("%s:%d -- error retrieving response %s", (char*)__FILE__,__LINE__,strNameRespXi.Data());
3189 // if(0){ // can't rebin THnSparse ...
3190 // if(fNHistoBinsPt[i]) hRespPt[i]->SetBinEdges(0,fHistoBinsPt[i]->GetArray());
3191 // if(fNHistoBinsPt[i]) hRespPt[i]->SetBinEdges(1,fHistoBinsPt[i]->GetArray());
3193 // if(fNHistoBinsZ[i]) hRespZ[i]->SetBinEdges(0,fHistoBinsZ[i]->GetArray());
3194 // if(fNHistoBinsZ[i]) hRespZ[i]->SetBinEdges(1,fHistoBinsZ[i]->GetArray());
3196 // if(fNHistoBinsXi[i]) hRespXi[i]->SetBinEdges(0,fHistoBinsXi[i]->GetArray());
3197 // if(fNHistoBinsXi[i]) hRespXi[i]->SetBinEdges(1,fHistoBinsXi[i]->GetArray());
3201 } // jet slices loop
3203 f.Close(); // THnSparse pointers still valid even if file closed
3205 // for(Int_t i=0; i<fNJetPtSlices; i++){ // no copy c'tor ...
3206 // if(hRespPt[i]) new(fhnResponsePt[i]) THnSparseF(*hRespPt[i]);
3207 // if(hRespZ[i]) new(fhnResponseZ[i]) THnSparseF(*hRespZ[i]);
3208 // if(hRespXi[i]) new(fhnResponseXi[i]) THnSparseF(*hRespXi[i]);
3211 for(Int_t i=0; i<fNJetPtSlices; i++){
3212 fhnResponsePt[i] = hRespPt[i];
3213 fhnResponseZ[i] = hRespZ[i];
3214 fhnResponseXi[i] = hRespXi[i];
3218 //______________________________________________________________________________________________________________________
3219 void AliFragmentationFunctionCorrections::ReadPriors(TString strfile,const Int_t type)
3221 // read priors from file: rec primaries, gen pt dist
3223 if(fDebug>0) Printf("%s:%d -- read priors from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3225 // temporary histos to store pointers from file
3226 TH1F* hist[fNJetPtSlices];
3228 for(Int_t i=0; i<fNJetPtSlices; i++) hist[i] = 0;
3230 TFile f(strfile,"READ");
3233 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
3237 for(Int_t i=0; i<fNJetPtSlices; i++){
3239 Int_t jetPtLoLim = static_cast<Int_t> (fJetPtSlices->At(i));
3240 Int_t jetPtUpLim = static_cast<Int_t> (fJetPtSlices->At(i+1));
3244 if(type == kFlagPt) strName.Form("h1FFTrackPtRecPrim_genPt_%02d_%02d",jetPtLoLim,jetPtUpLim);
3245 if(type == kFlagZ) strName.Form("h1FFZRecPrim_genPt_%02d_%02d",jetPtLoLim,jetPtUpLim);
3246 if(type == kFlagXi) strName.Form("h1FFXiRecPrim_genPt_%02d_%02d",jetPtLoLim,jetPtUpLim);
3248 hist[i] = (TH1F*) gDirectory->Get(strName);
3251 Printf("%s:%d -- error retrieving prior %s", (char*)__FILE__,__LINE__,strName.Data());
3255 //if(fNHistoBinsPt[i]) hist[i] = (TH1F*) hist[i]->Rebin(fNHistoBinsPt[i],hist[i]->GetName()+"_rebin",fHistoBinsPt[i]->GetArray());
3257 if(hist[i]) hist[i]->SetDirectory(0);
3259 } // jet slices loop
3264 for(Int_t i=0; i<fNJetPtSlices; i++){ // 2nd loop: need to close input file before placing histos
3265 if(hist[i] && type == kFlagPt) new(fh1FFTrackPtPrior[i]) TH1F(*hist[i]);
3266 if(hist[i] && type == kFlagZ) new(fh1FFZPrior[i]) TH1F(*hist[i]);
3267 if(hist[i] && type == kFlagXi) new(fh1FFXiPrior[i]) TH1F(*hist[i]);
3271 //_____________________________________________________
3272 // void AliFragmentationFunctionCorrections::RatioRecGen()
3274 // // create ratio reconstructed over generated FF
3275 // // use current highest corrLevel
3277 // Printf("%s:%d -- build ratio rec.gen, corrLevel %d",(char*)__FILE__,__LINE__,fNCorrectionLevels-1);
3279 // for(Int_t i=0; i<fNJetPtSlices; i++){
3281 // TH1F* histPtRec = fCorrFF[fNCorrectionLevels-1]->GetTrackPt(i); // levels -1: latest corr level
3282 // TH1F* histZRec = fCorrFF[fNCorrectionLevels-1]->GetZ(i); // levels -1: latest corr level
3283 // TH1F* histXiRec = fCorrFF[fNCorrectionLevels-1]->GetXi(i); // levels -1: latest corr level
3285 // TH1F* histPtGen = fh1FFTrackPtGenPrim[i];
3286 // TH1F* histZGen = fh1FFZGenPrim[i];
3287 // TH1F* histXiGen = fh1FFXiGenPrim[i];
3289 // TString histNamePt = histPtRec->GetName();
3290 // TString histNameZ = histZRec->GetName();
3291 // TString histNameXi = histXiRec->GetName();
3293 // histNamePt.ReplaceAll("fh1FF","fh1FFRatioRecGen");
3294 // histNameZ.ReplaceAll("fh1FF","fh1FFRatioRecGen");
3295 // histNameXi.ReplaceAll("fh1FF","fh1FFRatioRecGen");
3298 // TH1F* hRatioRecGenPt = (TH1F*) histPtRec->Clone(histNamePt);
3299 // hRatioRecGenPt->Reset();
3300 // hRatioRecGenPt->Divide(histPtRec,histPtGen,1,1,"B");
3302 // TH1F* hRatioRecGenZ = (TH1F*) histZRec->Clone(histNameZ);
3303 // hRatioRecGenZ->Reset();
3304 // hRatioRecGenZ->Divide(histZRec,histZGen,1,1,"B");
3306 // TH1F* hRatioRecGenXi = (TH1F*) histXiRec->Clone(histNameXi);
3307 // hRatioRecGenXi->Reset();
3308 // hRatioRecGenXi->Divide(histXiRec,histXiGen,1,1,"B");
3310 // new(fh1FFRatioRecGenPt[i]) TH1F(*hRatioRecGenPt);
3311 // new(fh1FFRatioRecGenZ[i]) TH1F(*hRatioRecGenZ);
3312 // new(fh1FFRatioRecGenXi[i]) TH1F(*hRatioRecGenXi);
3316 // //___________________________________________________________
3317 // void AliFragmentationFunctionCorrections::RatioRecPrimaries()
3319 // // create ratio reconstructed tracks over reconstructed primaries
3320 // // use raw FF (corrLevel 0)
3322 // Printf("%s:%d -- build ratio rec tracks /rec primaries",(char*)__FILE__,__LINE__);
3324 // for(Int_t i=0; i<fNJetPtSlices; i++){
3326 // const Int_t corrLevel = 0;
3328 // TH1F* histPtRec = fCorrFF[corrLevel]->GetTrackPt(i); // levels -1: latest corr level
3329 // TH1F* histZRec = fCorrFF[corrLevel]->GetZ(i); // levels -1: latest corr level
3330 // TH1F* histXiRec = fCorrFF[corrLevel]->GetXi(i); // levels -1: latest corr level
3332 // TH1F* histPtRecPrim = fh1FFTrackPtRecPrim[i];
3333 // TH1F* histZRecPrim = fh1FFZRecPrim[i];
3334 // TH1F* histXiRecPrim = fh1FFXiRecPrim[i];
3336 // TString histNamePt = histPtRec->GetName();
3337 // TString histNameZ = histZRec->GetName();
3338 // TString histNameXi = histXiRec->GetName();
3340 // histNamePt.ReplaceAll("fh1FF","fh1FFRatioRecPrim");
3341 // histNameZ.ReplaceAll("fh1FF","fh1FFRatioRecPrim");
3342 // histNameXi.ReplaceAll("fh1FF","fh1FFRatioRecPrim");
3345 // TH1F* hRatioRecPrimPt = (TH1F*) histPtRec->Clone(histNamePt);
3346 // hRatioRecPrimPt->Reset();
3347 // hRatioRecPrimPt->Divide(histPtRec,histPtRecPrim,1,1,"B");
3349 // TH1F* hRatioRecPrimZ = (TH1F*) histZRec->Clone(histNameZ);
3350 // hRatioRecPrimZ->Reset();
3351 // hRatioRecPrimZ->Divide(histZRec,histZRecPrim,1,1,"B");
3353 // TH1F* hRatioRecPrimXi = (TH1F*) histXiRec->Clone(histNameXi);
3354 // hRatioRecPrimXi->Reset();
3355 // hRatioRecPrimXi->Divide(histXiRec,histXiRecPrim,1,1,"B");
3358 // new(fh1FFRatioRecPrimPt[i]) TH1F(*hRatioRecPrimPt);
3359 // new(fh1FFRatioRecPrimZ[i]) TH1F(*hRatioRecPrimZ);
3360 // new(fh1FFRatioRecPrimXi[i]) TH1F(*hRatioRecPrimXi);
3364 // __________________________________________________________________________________
3365 void AliFragmentationFunctionCorrections::ProjectJetResponseMatrices(TString strOutfile)
3368 // project response matrices on both axes:
3369 // FF for rec primaries, in terms of generated and reconstructed momentum
3370 // write FF and ratios to outFile
3372 Printf("%s:%d -- project response matrices, write to %s",(char*)__FILE__,__LINE__,strOutfile.Data());
3374 TH1F* hFFPtRec[fNJetPtSlices];
3375 TH1F* hFFZRec[fNJetPtSlices];
3376 TH1F* hFFXiRec[fNJetPtSlices];
3378 TH1F* hFFPtGen[fNJetPtSlices];
3379 TH1F* hFFZGen[fNJetPtSlices];
3380 TH1F* hFFXiGen[fNJetPtSlices];
3382 TH1F* hRatioPt[fNJetPtSlices];
3383 TH1F* hRatioZ[fNJetPtSlices];
3384 TH1F* hRatioXi[fNJetPtSlices];
3387 Int_t axisGenPt = 1;
3388 Int_t axisRecPt = 0;
3390 for(Int_t i=0; i<fNJetPtSlices; i++){
3392 Int_t jetPtLoLim = static_cast<Int_t> (fJetPtSlices->At(i));
3393 Int_t jetPtUpLim = static_cast<Int_t> (fJetPtSlices->At(i+1));
3395 TString strNameRecPt(Form("h1FFTrackPtRecPrim_recPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3396 TString strNameRecZ(Form("h1FFZRecPrim_recPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3397 TString strNameRecXi(Form("h1FFXiRecPrim_recPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3399 TString strNameGenPt(Form("h1FFTrackPtRecPrim_genPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3400 TString strNameGenZ(Form("h1FFZRecPrim_genPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3401 TString strNameGenXi(Form("h1FFXiRecPrim_genPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3403 TString strNameRatioPt(Form("h1RatioTrackPtRecPrim_%02d_%02d",jetPtLoLim,jetPtUpLim));
3404 TString strNameRatioZ(Form("h1RatioZRecPrim_%02d_%02d",jetPtLoLim,jetPtUpLim));
3405 TString strNameRatioXi(Form("h1RatioXiRecPrim_%02d_%02d",jetPtLoLim,jetPtUpLim));
3408 hFFPtRec[i] = (TH1F*) fhnResponsePt[i]->Projection(axisRecPt);// note convention: yDim,xDim
3409 hFFZRec[i] = (TH1F*) fhnResponseZ[i]->Projection(axisRecPt);// note convention: yDim,xDim
3410 hFFXiRec[i] = (TH1F*) fhnResponseXi[i]->Projection(axisRecPt);// note convention: yDim,xDim
3412 hFFPtRec[i]->SetNameTitle(strNameRecPt,"");
3413 hFFZRec[i]->SetNameTitle(strNameRecZ,"");
3414 hFFXiRec[i]->SetNameTitle(strNameRecXi,"");
3417 hFFPtGen[i] = (TH1F*) fhnResponsePt[i]->Projection(axisGenPt);// note convention: yDim,xDim
3418 hFFZGen[i] = (TH1F*) fhnResponseZ[i]->Projection(axisGenPt);// note convention: yDim,xDim
3419 hFFXiGen[i] = (TH1F*) fhnResponseXi[i]->Projection(axisGenPt);// note convention: yDim,xDim
3421 hFFPtGen[i]->SetNameTitle(strNameGenPt,"");
3422 hFFZGen[i]->SetNameTitle(strNameGenZ,"");
3423 hFFXiGen[i]->SetNameTitle(strNameGenXi,"");
3426 if(fNHistoBinsPt[i]) hFFPtRec[i] = (TH1F*) hFFPtRec[i]->Rebin(fNHistoBinsPt[i],"",fHistoBinsPt[i]->GetArray());
3427 if(fNHistoBinsZ[i]) hFFZRec[i] = (TH1F*) hFFZRec[i]->Rebin(fNHistoBinsZ[i],"",fHistoBinsZ[i]->GetArray());
3428 if(fNHistoBinsXi[i]) hFFXiRec[i] = (TH1F*) hFFXiRec[i]->Rebin(fNHistoBinsXi[i],"",fHistoBinsXi[i]->GetArray());
3430 if(fNHistoBinsPt[i]) hFFPtGen[i] = (TH1F*) hFFPtGen[i]->Rebin(fNHistoBinsPt[i],"",fHistoBinsPt[i]->GetArray());
3431 if(fNHistoBinsZ[i]) hFFZGen[i] = (TH1F*) hFFZGen[i]->Rebin(fNHistoBinsZ[i],"",fHistoBinsZ[i]->GetArray());
3432 if(fNHistoBinsXi[i]) hFFXiGen[i] = (TH1F*) hFFXiGen[i]->Rebin(fNHistoBinsXi[i],"",fHistoBinsXi[i]->GetArray());
3434 NormalizeTH1(hFFPtGen[i],fNJets->At(i));
3435 NormalizeTH1(hFFZGen[i],fNJets->At(i));
3436 NormalizeTH1(hFFXiGen[i],fNJets->At(i));
3438 NormalizeTH1(hFFPtRec[i],fNJets->At(i));
3439 NormalizeTH1(hFFZRec[i],fNJets->At(i));
3440 NormalizeTH1(hFFXiRec[i],fNJets->At(i));
3443 hRatioPt[i] = (TH1F*) hFFPtRec[i]->Clone(strNameRatioPt);
3444 hRatioPt[i]->Reset();
3445 hRatioPt[i]->Divide(hFFPtRec[i],hFFPtGen[i],1,1,"B");
3447 hRatioZ[i] = (TH1F*) hFFZRec[i]->Clone(strNameRatioZ);
3448 hRatioZ[i]->Reset();
3449 hRatioZ[i]->Divide(hFFZRec[i],hFFZGen[i],1,1,"B");
3451 hRatioXi[i] = (TH1F*) hFFXiRec[i]->Clone(strNameRatioXi);
3452 hRatioXi[i]->Reset();
3453 hRatioXi[i]->Divide(hFFXiRec[i],hFFXiGen[i],1,1,"B");
3460 TFile out(strOutfile,"RECREATE");
3463 Printf("%s:%d -- error opening response matrix output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
3467 for(Int_t i=0; i<fNJetPtSlices; i++){
3469 hFFPtRec[i]->Write();
3470 hFFZRec[i]->Write();
3471 hFFXiRec[i]->Write();
3473 hFFPtGen[i]->Write();
3474 hFFZGen[i]->Write();
3475 hFFXiGen[i]->Write();
3477 hRatioPt[i]->Write();
3478 hRatioZ[i]->Write();
3479 hRatioXi[i]->Write();
3485 // ____________________________________________________________________________________________________________________________
3486 void AliFragmentationFunctionCorrections::ProjectSingleResponseMatrix(TString strOutfile, Bool_t updateOutfile, TString strOutDir )
3488 // project response matrix on both axes:
3489 // pt spec for rec primaries, in terms of generated and reconstructed momentum
3490 // write spec and ratios to outFile
3492 Printf("%s:%d -- project single pt response matrix, write to %s",(char*)__FILE__,__LINE__,strOutfile.Data());
3498 Int_t axisGenPt = 1;
3499 Int_t axisRecPt = 0;
3501 TString strNameRecPt = "h1SpecTrackPtRecPrim_recPt";
3502 TString strNameGenPt = "h1SpecTrackPtRecPrim_genPt";
3503 TString strNameRatioPt = "h1RatioTrackPtRecPrim";
3505 hSpecPtRec = (TH1F*) fhnResponseSinglePt->Projection(axisRecPt);// note convention: yDim,xDim
3506 hSpecPtRec->SetNameTitle(strNameRecPt,"");
3508 hSpecPtGen = (TH1F*) fhnResponseSinglePt->Projection(axisGenPt);// note convention: yDim,xDim
3509 hSpecPtGen->SetNameTitle(strNameGenPt,"");
3511 hRatioPt = (TH1F*) hSpecPtRec->Clone(strNameRatioPt);
3513 hRatioPt->Divide(hSpecPtRec,hSpecPtGen,1,1,"B");
3515 TString outfileOption = "RECREATE";
3516 if(updateOutfile) outfileOption = "UPDATE";
3518 TFile out(strOutfile,outfileOption);
3521 Printf("%s:%d -- error opening reponse matrix projections output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
3526 if(strOutDir && strOutDir.Length()){
3529 if((dir = ((TDirectory*) gDirectory->Get(strOutDir)))) dir->cd();
3531 dir = out.mkdir(strOutDir);
3536 hSpecPtRec->Write();
3537 hSpecPtGen->Write();
3544 //__________________________________________________________________________________________________________________________________________________________________
3545 void AliFragmentationFunctionCorrections::RebinHisto(const Int_t jetPtSlice, const Int_t nBinsLimits, Double_t* binsLimits, Double_t* binsWidth, const Int_t type)
3547 // rebin histo, rescale bins according to new width
3548 // only correct for input histos with equal bin size
3550 // args: jetPtSlice, type, use current corr level
3552 // function takes array of limits and widths (e.g. 1 GeV bins up to 10 GeV, 2 GeV width up to 20 GeV, ...)
3553 // array size of binsLimits: nBinsLimits
3554 // array size of binsWidth: nBinsLimits-1
3555 // binsLimits have to be in increasing order
3556 // if binning undefined for any slice, original binning will be kept
3559 Printf("%s:%d -- jetPtSlices not defined", (char*)__FILE__,__LINE__);
3563 if(jetPtSlice>=fNJetPtSlices){
3564 Printf("%s:%d -- jetPtSlice %d exceeds max",(char*)__FILE__,__LINE__,jetPtSlice);
3569 Double_t binLimitMin = binsLimits[0];
3570 Double_t binLimitMax = binsLimits[nBinsLimits-1];
3572 Double_t binLimit = binLimitMin; // start value
3574 Int_t sizeUpperLim = 1000; //static_cast<Int_t>(binLimitMax/binsWidth[0])+1; - only if first bin has smallest width, but not case for dN/dxi ...
3575 TArrayD binsArray(sizeUpperLim);
3577 binsArray.SetAt(binLimitMin,nBins++);
3579 while(binLimit<binLimitMax && nBins<sizeUpperLim){
3581 Int_t currentSlice = -1;
3582 for(Int_t i=0; i<nBinsLimits; i++){
3583 if(binLimit >= 0.999*binsLimits[i]) currentSlice = i; // 0.999 numerical saftey factor
3586 Double_t currentBinWidth = binsWidth[currentSlice];
3587 binLimit += currentBinWidth;
3589 binsArray.SetAt(binLimit,nBins++);
3594 if(type == kFlagPt) hist = fCorrFF[fNCorrectionLevels-1]->GetTrackPt(jetPtSlice);
3595 else if(type == kFlagZ) hist = fCorrFF[fNCorrectionLevels-1]->GetZ(jetPtSlice);
3596 else if(type == kFlagXi) hist = fCorrFF[fNCorrectionLevels-1]->GetXi(jetPtSlice);
3597 else if(type == kFlagSinglePt) hist = fCorrSinglePt[fNCorrectionLevelsSinglePt-1]->GetTrackPt(0);
3599 Printf("%s%d unknown type",(char*)__FILE__,__LINE__);
3603 Double_t binWidthNoRebin = hist->GetBinWidth(1);
3605 Double_t* bins = binsArray.GetArray();
3607 hist = (TH1F*) hist->Rebin(nBins-1,"",bins);
3609 for(Int_t bin=0; bin <= hist->GetNbinsX(); bin++){
3611 Double_t binWidthRebin = hist->GetBinWidth(bin);
3612 Double_t scaleF = binWidthNoRebin / binWidthRebin;
3614 Double_t binCont = hist->GetBinContent(bin);
3615 Double_t binErr = hist->GetBinError(bin);
3620 hist->SetBinContent(bin,binCont);
3621 hist->SetBinError(bin,binErr);
3626 TH1F* temp = new TH1F(*hist);
3628 if(type == kFlagPt) fCorrFF[fNCorrectionLevels-1]->ReplaceCorrHistos(jetPtSlice,temp,0,0);
3629 if(type == kFlagZ) fCorrFF[fNCorrectionLevels-1]->ReplaceCorrHistos(jetPtSlice,0,temp,0);
3630 if(type == kFlagXi) fCorrFF[fNCorrectionLevels-1]->ReplaceCorrHistos(jetPtSlice,0,0,temp);
3631 if(type == kFlagSinglePt) fCorrSinglePt[fNCorrectionLevelsSinglePt-1]->ReplaceCorrHistos(0,temp,0,0);
3636 //__________________________________________________________________________________________________________________________________________________________________
3637 void AliFragmentationFunctionCorrections::WriteJetSpecResponse(TString strInfile, TString strdir, TString strlist/*, TString strOutfile*/)
3640 if(fDebug>0) Printf("%s:%d -- read jet spectrum response matrix from file %s ",(char*)__FILE__,__LINE__,strInfile.Data());
3642 if(strdir && strdir.Length()) gDirectory->cd(strdir);
3646 if(strlist && strlist.Length()){
3648 if(!(list = (TList*) gDirectory->Get(strlist))){
3649 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
3654 THnSparse* hn6ResponseJetPt = (THnSparse*) list->FindObject("fhnCorrelation");
3656 Int_t axis6RecJetPt = 0;
3657 Int_t axis6GenJetPt = 3;
3659 hn6ResponseJetPt->GetAxis(axis6RecJetPt)->SetTitle("rec jet p_{T} (GeV/c)");
3660 hn6ResponseJetPt->GetAxis(axis6GenJetPt)->SetTitle("gen jet p_{T} (GeV/c)");
3662 Int_t nBinsRecPt = hn6ResponseJetPt->GetAxis(axis6RecJetPt)->GetNbins();
3663 Double_t loLimRecPt = hn6ResponseJetPt->GetAxis(axis6RecJetPt)->GetBinLowEdge(1);
3664 Double_t upLimRecPt = hn6ResponseJetPt->GetAxis(axis6RecJetPt)->GetBinUpEdge(nBinsRecPt);
3666 Int_t nBinsGenPt = hn6ResponseJetPt->GetAxis(axis6GenJetPt)->GetNbins();
3667 Double_t loLimGenPt = hn6ResponseJetPt->GetAxis(axis6GenJetPt)->GetBinLowEdge(1);
3668 Double_t upLimGenPt = hn6ResponseJetPt->GetAxis(axis6GenJetPt)->GetBinUpEdge(nBinsGenPt);
3670 Int_t nBinsTrackPt = 200;
3671 Int_t loLimTrackPt = 0;
3672 Int_t upLimTrackPt = 200;
3675 Int_t nBinsResponse[4] = {nBinsRecPt,nBinsTrackPt,nBinsGenPt,nBinsTrackPt};
3676 Double_t binMinResponse[4] = {loLimRecPt,loLimTrackPt,loLimGenPt,loLimTrackPt};
3677 Double_t binMaxResponse[4] = {upLimRecPt,upLimTrackPt,upLimGenPt,upLimTrackPt};
3679 const char* labelsResponseSinglePt[4] = {"rec jet p_{T} (GeV/c)", "rec track p_{T} (GeV/c)", "gen jet p_{T} (GeV/c)", "gen track p_{T} (GeV/c)"};
3681 THnSparseD* hn4ResponseTrackPtJetPt = new THnSparseD("hn4ResponseTrackPtJetPt","",4,nBinsResponse,binMinResponse,binMaxResponse);
3683 for(Int_t i=0; i<4; i++){
3684 hn4ResponseTrackPtJetPt->GetAxis(i)->SetTitle(labelsResponseSinglePt[i]);
3693 //_____________________________________________________________________________________________________________________________________
3694 void AliFragmentationFunctionCorrections::ReadSingleTrackEfficiency(TString strfile, TString strdir, TString strlist, TString strname)
3697 ReadSingleTrackCorrection(strfile,strdir,strlist,strname,kFlagEfficiency);
3701 //_____________________________________________________________________________________________________________________________________
3702 void AliFragmentationFunctionCorrections::ReadSingleTrackResponse(TString strfile, TString strdir, TString strlist, TString strname)
3705 ReadSingleTrackCorrection(strfile,strdir,strlist,strname,kFlagResponse);
3709 //_____________________________________________________________________________________________________________________________________
3710 void AliFragmentationFunctionCorrections::ReadSingleTrackSecCorr(TString strfile, TString strdir, TString strlist, TString strname)
3713 ReadSingleTrackCorrection(strfile,strdir,strlist,strname,kFlagSecondaries);
3717 //______________________________________________________________________________________________________________________________________________________
3718 void AliFragmentationFunctionCorrections::ReadSingleTrackCorrection(TString strfile, TString strdir, TString strlist, TString strname, const Int_t type)
3720 // read single track correction (pt) from file
3721 // type: efficiency / response / secondaries correction
3723 if(!((type == kFlagEfficiency) || (type == kFlagResponse) || (type == kFlagSecondaries))){
3724 Printf("%s:%d -- no such correction ",(char*)__FILE__,__LINE__);
3728 TFile f(strfile,"READ");
3731 Printf("%s:%d -- error opening file %s", (char*)__FILE__,__LINE__,strfile.Data());
3735 if(fDebug>0 && type==kFlagEfficiency) Printf("%s:%d -- read single track corr from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3736 if(fDebug>0 && type==kFlagResponse) Printf("%s:%d -- read single track response from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3737 if(fDebug>0 && type==kFlagSecondaries) Printf("%s:%d -- read single track secondaries corr from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3739 if(strdir && strdir.Length()) gDirectory->cd(strdir);
3743 if(strlist && strlist.Length()){
3745 if(!(list = (TList*) gDirectory->Get(strlist))){
3746 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
3751 TH1F* h1CorrHist = 0; // common TObject pointer not possible, need SetDirectory() later
3752 THnSparse* hnCorrHist = 0;
3754 if(type == kFlagEfficiency || type == kFlagSecondaries){
3756 if(list) h1CorrHist = (TH1F*) list->FindObject(strname);
3757 else h1CorrHist = (TH1F*) gDirectory->Get(strname);
3760 Printf("%s:%d -- error retrieving histo %s", (char*)__FILE__,__LINE__,strname.Data());
3765 else if(type == kFlagResponse){
3767 if(list) hnCorrHist = (THnSparse*) list->FindObject(strname);
3768 else hnCorrHist = (THnSparse*) gDirectory->Get(strname);
3771 Printf("%s:%d -- error retrieving histo %s", (char*)__FILE__,__LINE__,strname.Data());
3777 if(h1CorrHist) h1CorrHist->SetDirectory(0);
3778 //if(hnCorrHist) hnCorrHist->SetDirectory(0);
3782 if(type == kFlagEfficiency) fh1EffSinglePt = h1CorrHist;
3783 else if(type == kFlagResponse) fhnResponseSinglePt = hnCorrHist;
3784 else if(type == kFlagSecondaries) fh1SecCorrSinglePt = h1CorrHist;
3788 //________________________________________________________________________________________________________________
3789 void AliFragmentationFunctionCorrections::ReadRawPtSpec(TString strInfile, TString strID)
3791 // read track pt spec from task ouput - standard dir/list
3793 TString strdir = "PWG4_FragmentationFunction_" + strID;
3794 TString strlist = "fracfunc_" + strID;
3796 ReadRawPtSpec(strInfile,strdir,strlist);
3799 //_______________________________________________________________________________________________________
3800 void AliFragmentationFunctionCorrections::ReadRawPtSpec(TString strfile, TString strdir, TString strlist)
3802 // get raw pt spectra from file
3806 fNCorrectionLevelsSinglePt = 0;
3807 fCorrSinglePt = new AliFragFuncCorrHistos*[fgMaxNCorrectionLevels];
3808 AddCorrectionLevelSinglePt(); // first 'correction' level = raw spectrum
3810 // get raw pt spec from input file, normalize
3812 TFile f(strfile,"READ");
3815 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
3819 if(fDebug>0) Printf("%s:%d -- read raw spectra from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3821 gDirectory->cd(strdir);
3825 if(!(list = (TList*) gDirectory->Get(strlist))){
3826 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
3830 TString hnameTrackPt("fh1TrackQAPtRecCuts");
3831 TString hnameEvtSel("fh1EvtSelection");
3833 TH1F* fh1TrackPt = (TH1F*) list->FindObject(hnameTrackPt);
3834 TH1F* fh1EvtSel = (TH1F*) list->FindObject(hnameEvtSel);
3836 if(!fh1TrackPt){ Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameTrackPt.Data()); return; }
3837 if(!fh1EvtSel) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameEvtSel.Data()); return; }
3840 //Float_t nEvents = fh1EvtSel->GetBinContent(fh1EvtSel->FindBin(0));
3842 // evts after physics selection
3843 Float_t nEvents = fh1EvtSel->GetEntries()
3844 - fh1EvtSel->GetBinContent(fh1EvtSel->FindBin(1)) // evts rejected by trigger selection ( = PhysicsSelection
3845 - fh1EvtSel->GetBinContent(fh1EvtSel->FindBin(2)); // evts with wrong centrality class
3848 fh1TrackPt->SetDirectory(0);
3853 NormalizeTH1(fh1TrackPt,nEvents);
3855 // raw FF = corr level 0
3856 fCorrSinglePt[0]->AddCorrHistos(0,fh1TrackPt);
3860 //_______________________________________________________________________________________________________
3861 void AliFragmentationFunctionCorrections::ReadRawPtSpecQATask(TString strfile, TString strdir, TString strlist)
3863 // get raw pt spectra from file
3864 // for output from Martas QA task
3868 fNCorrectionLevelsSinglePt = 0;
3869 fCorrSinglePt = new AliFragFuncCorrHistos*[fgMaxNCorrectionLevels];
3870 AddCorrectionLevelSinglePt(); // first 'correction' level = raw spectrum
3872 // get raw pt spec from input file, normalize
3874 TFile f(strfile,"READ");
3877 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
3881 if(fDebug>0) Printf("%s:%d -- read raw pt spec from QA task output file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3883 gDirectory->cd(strdir);
3887 if(!(list = (TList*) gDirectory->Get(strlist))){
3888 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
3892 TString hnameTrackPt("fPtSel");
3893 TString hnameEvtSel("fNEventAll");
3895 TH1F* fh1TrackPt = (TH1F*) list->FindObject(hnameTrackPt);
3896 TH1F* fh1EvtSel = (TH1F*) list->FindObject(hnameEvtSel);
3898 if(!fh1TrackPt){ Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameTrackPt.Data()); return; }
3899 if(!fh1EvtSel) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameEvtSel.Data()); return; }
3902 // evts after physics selection
3903 Float_t nEvents = fh1EvtSel->GetEntries();
3905 fh1TrackPt->SetDirectory(0);
3910 NormalizeTH1(fh1TrackPt,nEvents);
3912 // raw FF = corr level 0
3913 fCorrSinglePt[0]->AddCorrHistos(0,fh1TrackPt);
3916 // ________________________________________________________
3917 void AliFragmentationFunctionCorrections::EffCorrSinglePt()
3919 // apply efficiency correction to inclusive track pt spec
3921 AddCorrectionLevelSinglePt("eff");
3923 TH1F* histPt = fCorrSinglePt[fNCorrectionLevelsSinglePt-2]->GetTrackPt(0);
3925 if(histPt->GetNbinsX() != fh1EffSinglePt->GetNbinsX()) Printf("%s:%d: inconsistency pt spec and eff corr bins - rebin effCorr ...", (char*)__FILE__,__LINE__);
3927 TString histNamePt = histPt->GetName();
3928 TH1F* hTrackPtEffCorr = (TH1F*) histPt->Clone(histNamePt);
3929 hTrackPtEffCorr->Divide(histPt,fh1EffSinglePt,1,1,"");
3931 fCorrSinglePt[fNCorrectionLevelsSinglePt-1]->AddCorrHistos(0,hTrackPtEffCorr);
3934 //___________________________________________________________________________________________________________________________
3935 void AliFragmentationFunctionCorrections::UnfoldSinglePt(const Int_t nIter, const Bool_t useCorrelatedErrors)
3937 // unfolde inclusive dN/dpt spectra
3939 AddCorrectionLevelSinglePt("unfold");
3941 TH1F* hist = fCorrSinglePt[fNCorrectionLevelsSinglePt-2]->GetTrackPt(0); // level -2: before unfolding, level -1: unfolded
3942 THnSparse* hnResponse = fhnResponseSinglePt;
3944 TString histNameTHn = hist->GetName();
3945 if(histNameTHn.Contains("TH1")) histNameTHn.ReplaceAll("TH1","THn");
3946 if(histNameTHn.Contains("fPt")) histNameTHn.ReplaceAll("fPt","fhnPt");
3949 TString histNameBackFolded = hist->GetName();
3950 histNameBackFolded.Append("_backfold");
3952 TString histNameRatioFolded = hist->GetName();
3953 if(histNameRatioFolded.Contains("fh1")) histNameRatioFolded.ReplaceAll("fh1","hRatio");
3954 if(histNameRatioFolded.Contains("fPt")) histNameRatioFolded.ReplaceAll("fPt","hRatioPt");
3955 histNameRatioFolded.Append("_unfold");
3957 TString histNameRatioBackFolded = hist->GetName();
3958 if(histNameRatioBackFolded.Contains("fh1")) histNameRatioBackFolded.ReplaceAll("fh1","hRatio");
3959 if(histNameRatioBackFolded.Contains("fPt")) histNameRatioBackFolded.ReplaceAll("fPt","hRatioPt");
3960 histNameRatioBackFolded.Append("_backfold");
3962 THnSparse* hnHist = TH1toSparse(hist,histNameTHn,hist->GetTitle());
3963 THnSparse* hnFlatEfficiency = TH1toSparse(hist,"fhnEfficiency","eff",kTRUE); // could optionally also use real eff
3965 THnSparse* hnUnfolded
3966 = Unfold(hnHist,hnResponse,hnFlatEfficiency,nIter,useCorrelatedErrors);
3968 TH1F* hUnfolded = (TH1F*) hnUnfolded->Projection(0);
3969 hUnfolded->SetNameTitle(hist->GetName(),hist->GetTitle());
3971 fCorrSinglePt[fNCorrectionLevelsSinglePt-1]->AddCorrHistos(0,hUnfolded);
3973 // backfolding: apply response matrix to unfolded spectrum
3974 TH1F* hBackFolded = ApplyResponse(hUnfolded,hnResponse);
3975 hBackFolded->SetNameTitle(histNameBackFolded,hist->GetTitle());
3977 fh1SingleTrackPtBackFolded = hBackFolded;
3980 // ratio unfolded to original histo
3981 TH1F* hRatioUnfolded = (TH1F*) hUnfolded->Clone(histNameRatioFolded);
3982 hRatioUnfolded->Reset();
3983 hRatioUnfolded->Divide(hUnfolded,hist,1,1,"B");
3985 fh1RatioSingleTrackPtFolded = hRatioUnfolded;
3988 // ratio backfolded to original histo
3989 TH1F* hRatioBackFolded = (TH1F*) hBackFolded->Clone(histNameRatioBackFolded);
3990 hRatioBackFolded->Reset();
3991 hRatioBackFolded->Divide(hBackFolded,hist,1,1,"B");
3993 fh1RatioSingleTrackPtBackFolded = hRatioBackFolded;
3996 delete hnFlatEfficiency;
4000 // ________________________________________________________
4001 void AliFragmentationFunctionCorrections::SecCorrSinglePt()
4003 // apply efficiency correction to inclusive track pt spec
4005 AddCorrectionLevelSinglePt("secCorr");
4007 TH1F* histPt = fCorrSinglePt[fNCorrectionLevelsSinglePt-2]->GetTrackPt(0);
4009 if(histPt->GetNbinsX() != fh1SecCorrSinglePt->GetNbinsX())
4010 Printf("%s:%d: inconsistency pt spec and secondaries corr bins - rebin effCorr ...", (char*)__FILE__,__LINE__);
4012 TString histNamePt = histPt->GetName();
4013 TH1F* hTrackPtSecCorr = (TH1F*) histPt->Clone(histNamePt);
4015 hTrackPtSecCorr->Multiply(histPt,fh1SecCorrSinglePt,1,1,"");
4017 fCorrSinglePt[fNCorrectionLevelsSinglePt-1]->AddCorrHistos(0,hTrackPtSecCorr);