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 Printf("%s%d unknown type",(char*)__FILE__,__LINE__);
1423 THnSparse* hnResponse = 0;
1424 if(type == kFlagPt) hnResponse = fhnResponsePt[i];
1425 else if(type == kFlagZ) hnResponse = fhnResponseZ[i];
1426 else if(type == kFlagXi) hnResponse = fhnResponseXi[i];
1428 Printf("%s%d unknown type",(char*)__FILE__,__LINE__);
1434 if(type == kFlagPt && fh1FFTrackPtPrior[i] && ((TString(fh1FFTrackPtPrior[i]->GetName())).Length() > 0) ) hPrior = fh1FFTrackPtPrior[i];
1435 else if(type == kFlagZ && fh1FFZPrior[i] && ((TString(fh1FFZPrior[i]->GetName())).Length() > 0) ) hPrior = fh1FFZPrior[i];
1436 else if(type == kFlagXi && fh1FFXiPrior[i] && ((TString(fh1FFXiPrior[i]->GetName())).Length() > 0) ) hPrior = fh1FFXiPrior[i];
1438 Printf("%s%d unknown type",(char*)__FILE__,__LINE__);
1443 TString histNameTHn = hist->GetName();
1444 histNameTHn.ReplaceAll("TH1","THn");
1446 TString priorNameTHn;
1448 priorNameTHn = hPrior->GetName();
1449 priorNameTHn.ReplaceAll("TH1","THn");
1452 TString histNameBackFolded = hist->GetName();
1453 histNameBackFolded.Append("_backfold");
1455 TString histNameRatioFolded = hist->GetName();
1456 histNameRatioFolded.ReplaceAll("fh1FF","hRatioFF");
1457 histNameRatioFolded.Append("_unfold");
1459 TString histNameRatioBackFolded = hist->GetName();
1460 histNameRatioBackFolded.ReplaceAll("fh1FF","hRatioFF");
1461 histNameRatioBackFolded.Append("_backfold");
1463 THnSparse* hnHist = TH1toSparse(hist,histNameTHn,hist->GetTitle());
1464 THnSparse* hnFlatEfficiency = TH1toSparse(hist,"fhnEfficiency","eff",kTRUE); // could optionally also use real eff
1465 THnSparse* hnPrior = 0;
1466 if(hPrior) hnPrior = TH1toSparse(hPrior,priorNameTHn,hPrior->GetTitle());
1468 THnSparse* hnUnfolded
1469 = Unfold(hnHist,hnResponse,hnFlatEfficiency,nIter,useCorrelatedErrors,hnPrior);
1471 TH1F* hUnfolded = (TH1F*) hnUnfolded->Projection(0);
1472 hUnfolded->SetNameTitle(hist->GetName(),hist->GetTitle());
1474 if(type == kFlagPt) fCorrFF[fNCorrectionLevels-1]->AddCorrHistos(i,hUnfolded,0,0);
1475 if(type == kFlagZ) fCorrFF[fNCorrectionLevels-1]->AddCorrHistos(i,0,hUnfolded,0);
1476 if(type == kFlagXi) fCorrFF[fNCorrectionLevels-1]->AddCorrHistos(i,0,0,hUnfolded);
1478 // backfolding: apply response matrix to unfolded spectrum
1479 TH1F* hBackFolded = ApplyResponse(hUnfolded,hnResponse);
1480 hBackFolded->SetNameTitle(histNameBackFolded,hist->GetTitle());
1482 if(type == kFlagPt) fh1FFTrackPtBackFolded[i] = hBackFolded;
1483 if(type == kFlagZ) fh1FFZBackFolded[i] = hBackFolded;
1484 if(type == kFlagXi) fh1FFXiBackFolded[i] = hBackFolded;
1486 // ratio unfolded to original histo
1487 TH1F* hRatioUnfolded = (TH1F*) hUnfolded->Clone(histNameRatioFolded);
1488 hRatioUnfolded->Reset();
1489 hRatioUnfolded->Divide(hUnfolded,hist,1,1,"B");
1491 if(type == kFlagPt) fh1FFRatioTrackPtFolded[i] = hRatioUnfolded;
1492 if(type == kFlagZ) fh1FFRatioZFolded[i] = hRatioUnfolded;
1493 if(type == kFlagXi) fh1FFRatioXiFolded[i] = hRatioUnfolded;
1496 // ratio backfolded to original histo
1497 TH1F* hRatioBackFolded = (TH1F*) hBackFolded->Clone(histNameRatioBackFolded);
1498 hRatioBackFolded->Reset();
1499 hRatioBackFolded->Divide(hBackFolded,hist,1,1,"B");
1501 if(type == kFlagPt) fh1FFRatioTrackPtBackFolded[i] = hRatioBackFolded;
1502 if(type == kFlagZ) fh1FFRatioZBackFolded[i] = hRatioBackFolded;
1503 if(type == kFlagXi) fh1FFRatioXiBackFolded[i] = hRatioBackFolded;
1506 delete hnFlatEfficiency;
1511 //_____________________________________________________________________________________________________
1512 void AliFragmentationFunctionCorrections::UnfoldPt(const Int_t nIter, const Bool_t useCorrelatedErrors)
1515 Int_t type = kFlagPt;
1516 UnfoldHistos(nIter, useCorrelatedErrors, type);
1519 //_____________________________________________________________________________________________________
1520 void AliFragmentationFunctionCorrections::UnfoldZ(const Int_t nIter, const Bool_t useCorrelatedErrors)
1523 Int_t type = kFlagZ;
1524 UnfoldHistos(nIter, useCorrelatedErrors, type);
1527 //_____________________________________________________________________________________________________
1528 void AliFragmentationFunctionCorrections::UnfoldXi(const Int_t nIter, const Bool_t useCorrelatedErrors)
1531 Int_t type = kFlagXi;
1532 UnfoldHistos(nIter, useCorrelatedErrors, type);
1535 //______________________________________________________________________________________________
1536 TH1F* AliFragmentationFunctionCorrections::ApplyResponse(const TH1F* hist, THnSparse* hnResponse)
1538 // apply (multiply) response matrix to hist
1540 TH1F* hOut = new TH1F(*hist);
1543 const Int_t axisM = 0;
1544 const Int_t axisT = 1;
1546 Int_t nBinsM = hnResponse->GetAxis(axisM)->GetNbins();
1547 Int_t nBinsT = hnResponse->GetAxis(axisT)->GetNbins();
1549 // response matrix normalization
1550 // do it in this function and not when reading response, since for 'proper' normalization errors are difficult to assign
1551 // so for unfolding proper we leave it to CORRFW ...
1553 Double_t normFacResponse[nBinsT];
1555 for(Int_t iT=1; iT<=nBinsT; iT++){
1557 Double_t sumResp = 0;
1559 for(Int_t iM=1; iM<=nBinsM; iM++){
1561 Double_t coordM = hnResponse->GetAxis(axisM)->GetBinCenter(iM);
1562 Double_t coordT = hnResponse->GetAxis(axisT)->GetBinCenter(iT);
1564 Double_t binCoord[] = {coordM,coordT};
1566 Long64_t binIndex = hnResponse->GetBin(binCoord);
1568 Double_t resp = hnResponse->GetBinContent(binIndex);
1573 normFacResponse[iT] = 0;
1574 if(sumResp) normFacResponse[iT] = 1/sumResp;
1579 for(Int_t iM=1; iM<=nBinsM; iM++){
1583 for(Int_t iT=1; iT<=nBinsT; iT++){
1585 Double_t contT = hist->GetBinContent(iT);
1587 Double_t coordM = hnResponse->GetAxis(axisM)->GetBinCenter(iM);
1588 Double_t coordT = hnResponse->GetAxis(axisT)->GetBinCenter(iT);
1590 Double_t binCoord[] = {coordM,coordT};
1592 Long64_t binIndex = hnResponse->GetBin(binCoord);
1594 Double_t resp = hnResponse->GetBinContent(binIndex);
1596 contM += resp*normFacResponse[iT]*contT;
1599 hOut->SetBinContent(iM,contM);
1605 //_______________________________________________________________________________________________________
1606 void AliFragmentationFunctionCorrections::ReadEfficiency(TString strfile, TString strdir, TString strlist)
1608 // read reconstruction efficiency from file
1609 // argument strlist optional - read from directory strdir if not specified
1611 // temporary histos to hold histos from file
1612 TH1F* hEffPt[fNJetPtSlices];
1613 TH1F* hEffZ[fNJetPtSlices];
1614 TH1F* hEffXi[fNJetPtSlices];
1616 for(Int_t i=0; i<fNJetPtSlices; i++) hEffPt[i] = 0;
1617 for(Int_t i=0; i<fNJetPtSlices; i++) hEffZ[i] = 0;
1618 for(Int_t i=0; i<fNJetPtSlices; i++) hEffXi[i] = 0;
1620 TFile f(strfile,"READ");
1623 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
1627 if(fDebug>0) Printf("%s:%d -- read efficiencies from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
1629 if(strdir && strdir.Length()) gDirectory->cd(strdir);
1633 if(strlist && strlist.Length()){
1635 if(!(list = (TList*) gDirectory->Get(strlist))){
1636 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
1641 for(Int_t i=0; i<fNJetPtSlices; i++){
1643 Int_t jetPtLoLim = static_cast<Int_t> (fJetPtSlices->At(i));
1644 Int_t jetPtUpLim = static_cast<Int_t> (fJetPtSlices->At(i+1));
1646 TString strNameEffPt(Form("hEffPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
1647 TString strNameEffZ(Form("hEffZ_%02d_%02d",jetPtLoLim,jetPtUpLim));
1648 TString strNameEffXi(Form("hEffXi_%02d_%02d",jetPtLoLim,jetPtUpLim));
1652 hEffPt[i] = (TH1F*) list->FindObject(strNameEffPt);
1653 hEffZ[i] = (TH1F*) list->FindObject(strNameEffZ);
1654 hEffXi[i] = (TH1F*) list->FindObject(strNameEffXi);
1657 hEffPt[i] = (TH1F*) gDirectory->Get(strNameEffPt);
1658 hEffZ[i] = (TH1F*) gDirectory->Get(strNameEffZ);
1659 hEffXi[i] = (TH1F*) gDirectory->Get(strNameEffXi);
1663 Printf("%s:%d -- error retrieving efficiency %s", (char*)__FILE__,__LINE__,strNameEffPt.Data());
1667 Printf("%s:%d -- error retrieving efficiency %s", (char*)__FILE__,__LINE__,strNameEffZ.Data());
1671 Printf("%s:%d -- error retrieving efficiency %s", (char*)__FILE__,__LINE__,strNameEffXi.Data());
1675 if(fNHistoBinsPt[i]) hEffPt[i] = (TH1F*) hEffPt[i]->Rebin(fNHistoBinsPt[i],strNameEffPt+"_rebin",fHistoBinsPt[i]->GetArray());
1676 if(fNHistoBinsZ[i]) hEffZ[i] = (TH1F*) hEffZ[i]->Rebin(fNHistoBinsZ[i],strNameEffZ+"_rebin",fHistoBinsZ[i]->GetArray());
1677 if(fNHistoBinsXi[i]) hEffXi[i] = (TH1F*) hEffXi[i]->Rebin(fNHistoBinsXi[i],strNameEffXi+"_rebin",fHistoBinsXi[i]->GetArray());
1679 if(hEffPt[i]) hEffPt[i]->SetDirectory(0);
1680 if(hEffZ[i]) hEffZ[i]->SetDirectory(0);
1681 if(hEffXi[i]) hEffXi[i]->SetDirectory(0);
1683 } // jet slices loop
1687 for(Int_t i=0; i<fNJetPtSlices; i++){ // 2nd loop: need to close input file before placing histos
1688 if(hEffPt[i]) new(fh1EffPt[i]) TH1F(*hEffPt[i]);
1689 if(hEffZ[i]) new(fh1EffZ[i]) TH1F(*hEffZ[i]);
1690 if(hEffXi[i]) new(fh1EffXi[i]) TH1F(*hEffXi[i]);
1694 //___________________________________________________________________________________________________________
1695 void AliFragmentationFunctionCorrections::ReadBgrEfficiency(TString strfile, TString strdir, TString strlist)
1697 // read bgr eff from file
1698 // argument strlist optional - read from directory strdir if not specified
1700 TH1F* hEffPtBgr[fNJetPtSlices];
1701 TH1F* hEffZBgr [fNJetPtSlices];
1702 TH1F* hEffXiBgr[fNJetPtSlices];
1704 for(Int_t i=0; i<fNJetPtSlices; i++) hEffPtBgr[i] = 0;
1705 for(Int_t i=0; i<fNJetPtSlices; i++) hEffZBgr[i] = 0;
1706 for(Int_t i=0; i<fNJetPtSlices; i++) hEffXiBgr[i] = 0;
1709 TFile f(strfile,"READ");
1712 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
1716 if(fDebug>0) Printf("%s:%d -- read bgr efficiencies from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
1718 if(strdir && strdir.Length()) gDirectory->cd(strdir);
1722 if(strlist && strlist.Length()){
1724 if(!(list = (TList*) gDirectory->Get(strlist))){
1725 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
1730 for(Int_t i=0; i<fNJetPtSlices; i++){
1732 Int_t jetPtLoLim = static_cast<Int_t> (fJetPtSlices->At(i));
1733 Int_t jetPtUpLim = static_cast<Int_t> (fJetPtSlices->At(i+1));
1735 TString strNameEffPtBgr(Form("hEffPtBgr%02dto%02d",jetPtLoLim,jetPtUpLim));
1736 TString strNameEffZBgr(Form("hEffZBgr%02dto%02d",jetPtLoLim,jetPtUpLim));
1737 TString strNameEffXiBgr(Form("hEffXiBgr%02dto%02d",jetPtLoLim,jetPtUpLim));
1741 hEffPtBgr[i] = (TH1F*) list->FindObject(strNameEffPtBgr);
1742 hEffZBgr[i] = (TH1F*) list->FindObject(strNameEffZBgr);
1743 hEffXiBgr[i] = (TH1F*) list->FindObject(strNameEffXiBgr);
1746 hEffPtBgr[i] = (TH1F*) gDirectory->Get(strNameEffPtBgr);
1747 hEffZBgr[i] = (TH1F*) gDirectory->Get(strNameEffZBgr);
1748 hEffXiBgr[i] = (TH1F*) gDirectory->Get(strNameEffXiBgr);
1752 Printf("%s:%d -- error retrieving efficiency %s", (char*)__FILE__,__LINE__,strNameEffPtBgr.Data());
1756 Printf("%s:%d -- error retrieving efficiency %s", (char*)__FILE__,__LINE__,strNameEffZBgr.Data());
1760 Printf("%s:%d -- error retrieving efficiency %s", (char*)__FILE__,__LINE__,strNameEffXiBgr.Data());
1764 if(fNHistoBinsPt[i]) hEffPtBgr[i] = (TH1F*) hEffPtBgr[i]->Rebin(fNHistoBinsPt[i],strNameEffPtBgr+"_rebin",fHistoBinsPt[i]->GetArray());
1765 if(fNHistoBinsZ[i]) hEffZBgr[i] = (TH1F*) hEffZBgr[i]->Rebin(fNHistoBinsZ[i],strNameEffZBgr+"_rebin",fHistoBinsZ[i]->GetArray());
1766 if(fNHistoBinsXi[i]) hEffXiBgr[i] = (TH1F*) hEffXiBgr[i]->Rebin(fNHistoBinsXi[i],strNameEffXiBgr+"_rebin",fHistoBinsXi[i]->GetArray());
1768 if(hEffPtBgr[i]) hEffPtBgr[i]->SetDirectory(0);
1769 if(hEffZBgr[i]) hEffZBgr[i]->SetDirectory(0);
1770 if(hEffXiBgr[i]) hEffXiBgr[i]->SetDirectory(0);
1772 } // jet slices loop
1776 for(Int_t i=0; i<fNJetPtSlices; i++){ // 2nd loop: need to close input file before placing histos
1777 if(hEffPtBgr[i]) new(fh1EffBgrPt[i]) TH1F(*hEffPtBgr[i]);
1778 if(hEffZBgr[i]) new(fh1EffBgrZ[i]) TH1F(*hEffZBgr[i]);
1779 if(hEffXiBgr[i]) new(fh1EffBgrXi[i]) TH1F(*hEffXiBgr[i]);
1783 // ________________________________________________
1784 void AliFragmentationFunctionCorrections::EffCorr()
1786 // apply efficiency correction
1788 AddCorrectionLevel("eff");
1790 for(Int_t i=0; i<fNJetPtSlices; i++){
1792 TH1F* histPt = fCorrFF[fNCorrectionLevels-2]->GetTrackPt(i);
1793 TH1F* histZ = fCorrFF[fNCorrectionLevels-2]->GetZ(i);
1794 TH1F* histXi = fCorrFF[fNCorrectionLevels-2]->GetXi(i);
1796 TString histNamePt = histPt->GetName();
1797 TString histNameZ = histZ->GetName();
1798 TString histNameXi = histXi->GetName();
1801 TH1F* hFFTrackPtEffCorr = (TH1F*) histPt->Clone(histNamePt);
1802 hFFTrackPtEffCorr->Divide(histPt,fh1EffPt[i],1,1,"");
1804 TH1F* hFFZEffCorr = (TH1F*) histZ->Clone(histNameZ);
1805 hFFZEffCorr->Divide(histZ,fh1EffZ[i],1,1,"");
1807 TH1F* hFFXiEffCorr = (TH1F*) histXi->Clone(histNameXi);
1808 hFFXiEffCorr->Divide(histXi,fh1EffXi[i],1,1,"");
1810 fCorrFF[fNCorrectionLevels-1]->AddCorrHistos(i,hFFTrackPtEffCorr,hFFZEffCorr,hFFXiEffCorr);
1814 //___________________________________________________
1815 void AliFragmentationFunctionCorrections::EffCorrBgr()
1817 // apply efficiency correction to bgr distributions
1819 AddCorrectionLevelBgr("eff");
1821 Printf("%s:%d -- apply efficiency correction, corrLevel %d",(char*)__FILE__,__LINE__,fNCorrectionLevels-1);
1823 for(Int_t i=0; i<fNJetPtSlices; i++){
1825 TH1F* histPt = fCorrBgr[fNCorrectionLevelsBgr-2]->GetTrackPt(i);
1826 TH1F* histZ = fCorrBgr[fNCorrectionLevelsBgr-2]->GetZ(i);
1827 TH1F* histXi = fCorrBgr[fNCorrectionLevelsBgr-2]->GetXi(i);
1829 TString histNamePt = histPt->GetName();
1830 TString histNameZ = histZ->GetName();
1831 TString histNameXi = histXi->GetName();
1834 TH1F* hFFTrackPtEffCorr = (TH1F*) histPt->Clone(histNamePt);
1835 hFFTrackPtEffCorr->Divide(histPt,fh1EffPt[i],1,1,"");
1837 TH1F* hFFZEffCorr = (TH1F*) histZ->Clone(histNameZ);
1838 hFFZEffCorr->Divide(histZ,fh1EffZ[i],1,1,"");
1840 TH1F* hFFXiEffCorr = (TH1F*) histXi->Clone(histNameXi);
1841 hFFXiEffCorr->Divide(histXi,fh1EffXi[i],1,1,"");
1843 fCorrBgr[fNCorrectionLevelsBgr-1]->AddCorrHistos(i,hFFTrackPtEffCorr,hFFZEffCorr,hFFXiEffCorr);
1847 //______________________________________________________________________
1848 void AliFragmentationFunctionCorrections::XiShift(const Int_t corrLevel)
1850 // re-evaluate jet energy after FF corrections from dN/dpt distribution
1851 // 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'
1852 // argument corrlevel: which level of correction to be corrected/shifted to
1854 if(corrLevel>=fNCorrectionLevels){
1855 Printf(" calc xi shift: corrLevel exceeded - do nothing");
1859 Double_t* jetPtUncorr = new Double_t[fNJetPtSlices];
1860 Double_t* jetPtCorr = new Double_t[fNJetPtSlices];
1861 Double_t* deltaXi = new Double_t[fNJetPtSlices];
1863 for(Int_t i=0; i<fNJetPtSlices; i++){
1865 TH1F* histPtRaw = fCorrFF[0]->GetTrackPt(i);
1866 TH1F* histPt = fCorrFF[corrLevel]->GetTrackPt(i);
1868 Double_t ptUncorr = 0;
1869 Double_t ptCorr = 0;
1871 for(Int_t bin = 1; bin<=histPtRaw->GetNbinsX(); bin++){
1873 Double_t cont = histPtRaw->GetBinContent(bin);
1874 Double_t width = histPtRaw->GetBinWidth(bin);
1875 Double_t meanPt = histPtRaw->GetBinCenter(bin);
1877 ptUncorr += meanPt*cont*width;
1880 for(Int_t bin = 1; bin<=histPt->GetNbinsX(); bin++){
1882 Double_t cont = histPt->GetBinContent(bin);
1883 Double_t width = histPt->GetBinWidth(bin);
1884 Double_t meanPt = histPt->GetBinCenter(bin);
1886 ptCorr += meanPt*cont*width;
1889 jetPtUncorr[i] = ptUncorr;
1890 jetPtCorr[i] = ptCorr;
1893 // calc dXi from dN/dpt distribution :
1894 // sum over track pt for raw and corrected FF is equivalent to raw/corrected jet pt
1896 for(Int_t i=0; i<fNJetPtSlices; i++){
1898 Float_t jetPtLoLim = fJetPtSlices->At(i);
1899 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
1901 Double_t meanJetPt = 0.5*(jetPtUpLim+jetPtLoLim);
1903 Double_t ptUncorr = jetPtUncorr[i];
1904 Double_t ptCorr = jetPtCorr[i];
1906 Double_t dXi = TMath::Log(ptCorr/ptUncorr);
1908 Printf(" calc xi shift: jet pt slice %d, mean jet pt %f, ptUncorr %f, ptCorr %f, ratio corr/uncorr %f, dXi %f "
1909 ,i,meanJetPt,ptUncorr,ptCorr,ptCorr/ptUncorr,dXi);
1914 // book & fill new dN/dxi histos
1916 for(Int_t i=0; i<fNJetPtSlices; i++){
1918 TH1F* histXi = fCorrFF[corrLevel]->GetXi(i);
1920 Double_t dXi = deltaXi[i];
1922 Int_t nBins = histXi->GetNbinsX();
1923 const Double_t* binsVec = histXi->GetXaxis()->GetXbins()->GetArray();
1924 Float_t binsVecNew[nBins+1];
1926 TString strName = histXi->GetName();
1927 strName.Append("_shift");
1928 TString strTit = histXi->GetTitle();
1932 // create shifted histo ...
1934 if(binsVec){ // binsVec only neq NULL if histo was rebinned before
1936 for(Int_t bin=0; bin<nBins+1; bin++) binsVecNew[bin] = binsVec[bin] + dXi;
1937 hXiCorr = new TH1F(strName,strTit,nBins,binsVecNew);
1939 else{ // uniform bin size
1941 Double_t xMin = histXi->GetXaxis()->GetXmin();
1942 Double_t xMax = histXi->GetXaxis()->GetXmax();
1947 hXiCorr = new TH1F(strName,strTit,nBins,xMin,xMax);
1952 for(Int_t bin=1; bin<nBins+1; bin++){
1953 Double_t cont = histXi->GetBinContent(bin);
1954 Double_t err = histXi->GetBinError(bin);
1956 hXiCorr->SetBinContent(bin,cont);
1957 hXiCorr->SetBinError(bin,err);
1960 new(fh1FFXiShift[i]) TH1F(*hXiCorr);
1964 delete[] jetPtUncorr;
1969 //_____________________________________________________
1970 void AliFragmentationFunctionCorrections::SubtractBgr()
1972 // subtract bgr distribution from FF
1973 // the current corr level is used for both
1975 AddCorrectionLevel("bgrSub");
1977 for(Int_t i=0; i<fNJetPtSlices; i++){
1979 TH1F* histPt = fCorrFF[fNCorrectionLevels-2]->GetTrackPt(i);
1980 TH1F* histZ = fCorrFF[fNCorrectionLevels-2]->GetZ(i);
1981 TH1F* histXi = fCorrFF[fNCorrectionLevels-2]->GetXi(i);
1983 TH1F* histPtBgr = fCorrBgr[fNCorrectionLevelsBgr-1]->GetTrackPt(i);
1984 TH1F* histZBgr = fCorrBgr[fNCorrectionLevelsBgr-1]->GetZ(i);
1985 TH1F* histXiBgr = fCorrBgr[fNCorrectionLevelsBgr-1]->GetXi(i);
1987 TString histNamePt = histPt->GetName();
1988 TString histNameZ = histZ->GetName();
1989 TString histNameXi = histXi->GetName();
1992 TH1F* hFFTrackPtBgrSub = (TH1F*) histPt->Clone(histNamePt);
1993 hFFTrackPtBgrSub->Add(histPtBgr,-1);
1995 TH1F* hFFZBgrSub = (TH1F*) histZ->Clone(histNameZ);
1996 hFFZBgrSub->Add(histZBgr,-1);
1998 TH1F* hFFXiBgrSub = (TH1F*) histXi->Clone(histNameXi);
1999 hFFXiBgrSub->Add(histXiBgr,-1);
2001 fCorrFF[fNCorrectionLevels-1]->AddCorrHistos(i,hFFTrackPtBgrSub,hFFZBgrSub,hFFXiBgrSub);
2005 //________________________________________________________________________________________________________________
2006 void AliFragmentationFunctionCorrections::WriteSingleTrackEff(TString strInfile, TString strID, TString strOutfile,
2007 Bool_t updateOutfile, TString strOutDir,TString strPostfix)
2009 // read task ouput from MC and write single track eff - standard dir/list
2011 TString strdir = "PWG4_FragmentationFunction_" + strID;
2012 TString strlist = "fracfunc_" + strID;
2014 WriteSingleTrackEff(strInfile,strdir,strlist,strOutfile,updateOutfile,strOutDir,strPostfix);
2017 //___________________________________________________________________________________________________________________________________
2018 void AliFragmentationFunctionCorrections::WriteSingleTrackEff(TString strInfile, TString strdir, TString strlist,
2019 TString strOutfile, Bool_t updateOutfile, TString strOutDir,TString strPostfix)
2021 // read task output from MC and write single track eff as function of pt, eta, phi
2022 // argument strlist optional - read from directory strdir if not specified
2023 // write eff to file stroutfile - by default only 'update' file (don't overwrite)
2026 TH1D* hdNdptTracksMCPrimGen;
2027 TH2D* hdNdetadphiTracksMCPrimGen;
2029 TH1D* hdNdptTracksMCPrimRec;
2030 TH2D* hdNdetadphiTracksMCPrimRec;
2033 TFile f(strInfile,"READ");
2036 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strInfile.Data());
2040 if(fDebug>0) Printf("%s:%d -- writeSingleTrackEff: open task ouput file %s ",(char*)__FILE__,__LINE__,strInfile.Data());
2042 if(strdir && strdir.Length()){
2043 if(fDebug>0) Printf("%s:%d -- writeSingleTrackEff: change dir to %s",(char*)__FILE__,__LINE__,strdir.Data());
2044 gDirectory->cd(strdir);
2049 if(strlist && strlist.Length()){
2051 if(!(list = (TList*) gDirectory->Get(strlist))){
2052 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
2058 TString hnamePtRecEffGen = "fh1TrackQAPtRecEffGen";
2059 if(strPostfix.Length()) hnamePtRecEffGen.Form("fh1TrackQAPtRecEffGen_%s",strPostfix.Data());
2061 TString hnamePtRecEffRec = "fh1TrackQAPtRecEffRec";
2062 if(strPostfix.Length()) hnamePtRecEffRec.Form("fh1TrackQAPtRecEffRec_%s",strPostfix.Data());
2064 TString hnameEtaPhiRecEffGen = "fh2TrackQAEtaPhiRecEffGen";
2065 if(strPostfix.Length()) hnameEtaPhiRecEffGen.Form("fh2TrackQAEtaPhiRecEffGen_%s",strPostfix.Data());
2067 TString hnameEtaPhiRecEffRec = "fh2TrackQAEtaPhiRecEffRec";
2068 if(strPostfix.Length()) hnameEtaPhiRecEffRec.Form("fh2TrackQAEtaPhiRecEffRec_%s",strPostfix.Data());
2072 hdNdptTracksMCPrimGen = (TH1D*) list->FindObject(hnamePtRecEffGen);
2073 hdNdetadphiTracksMCPrimGen = (TH2D*) list->FindObject(hnameEtaPhiRecEffGen);
2075 hdNdptTracksMCPrimRec = (TH1D*) list->FindObject(hnamePtRecEffRec);
2076 hdNdetadphiTracksMCPrimRec = (TH2D*) list->FindObject(hnameEtaPhiRecEffRec);
2079 hdNdptTracksMCPrimGen = (TH1D*) gDirectory->Get(hnamePtRecEffGen);
2080 hdNdetadphiTracksMCPrimGen = (TH2D*) gDirectory->Get(hnameEtaPhiRecEffGen);
2082 hdNdptTracksMCPrimRec = (TH1D*) gDirectory->Get(hnamePtRecEffRec);
2083 hdNdetadphiTracksMCPrimRec = (TH2D*) gDirectory->Get(hnameEtaPhiRecEffRec);
2086 hdNdptTracksMCPrimGen->SetDirectory(0);
2087 hdNdetadphiTracksMCPrimGen->SetDirectory(0);
2088 hdNdptTracksMCPrimRec->SetDirectory(0);
2089 hdNdetadphiTracksMCPrimRec->SetDirectory(0);
2093 // projections: dN/deta, dN/dphi
2095 TH1D* hdNdetaTracksMCPrimGen = (TH1D*) hdNdetadphiTracksMCPrimGen->ProjectionX("hdNdetaTracksMcPrimGen");
2096 TH1D* hdNdphiTracksMCPrimGen = (TH1D*) hdNdetadphiTracksMCPrimGen->ProjectionY("hdNdphiTracksMcPrimGen");
2098 TH1D* hdNdetaTracksMCPrimRec = (TH1D*) hdNdetadphiTracksMCPrimRec->ProjectionX("hdNdetaTracksMcPrimRec");
2099 TH1D* hdNdphiTracksMCPrimRec = (TH1D*) hdNdetadphiTracksMCPrimRec->ProjectionY("hdNdphiTracksMcPrimRec");
2103 TString strNamePtGen = "hTrackPtGenPrim";
2104 TString strNamePtRec = "hTrackPtRecPrim";
2106 if(fNHistoBinsSinglePt) hdNdptTracksMCPrimGen = (TH1D*) hdNdptTracksMCPrimGen->Rebin(fNHistoBinsSinglePt,strNamePtGen,fHistoBinsSinglePt->GetArray());
2107 if(fNHistoBinsSinglePt) hdNdptTracksMCPrimRec = (TH1D*) hdNdptTracksMCPrimRec->Rebin(fNHistoBinsSinglePt,strNamePtRec,fHistoBinsSinglePt->GetArray());
2109 // efficiency: divide
2111 TString hNameTrackEffPt = "hSingleTrackEffPt";
2112 if(strPostfix.Length()) hNameTrackEffPt.Form("hSingleTrackEffPt_%s",strPostfix.Data());
2114 TString hNameTrackEffEta = "hSingleTrackEffEta";
2115 if(strPostfix.Length()) hNameTrackEffEta.Form("hSingleTrackEffEta_%s",strPostfix.Data());
2117 TString hNameTrackEffPhi = "hSingleTrackEffPhi";
2118 if(strPostfix.Length()) hNameTrackEffPhi.Form("hSingleTrackEffPhi_%s",strPostfix.Data());
2121 TH1F* hSingleTrackEffPt = (TH1F*) hdNdptTracksMCPrimRec->Clone(hNameTrackEffPt);
2122 hSingleTrackEffPt->Divide(hdNdptTracksMCPrimRec,hdNdptTracksMCPrimGen,1,1,"B"); // binominal errors
2124 TH1F* hSingleTrackEffEta = (TH1F*) hdNdetaTracksMCPrimRec->Clone(hNameTrackEffEta);
2125 hSingleTrackEffEta->Divide(hdNdetaTracksMCPrimRec,hdNdetaTracksMCPrimGen,1,1,"B"); // binominal errors
2127 TH1F* hSingleTrackEffPhi = (TH1F*) hdNdphiTracksMCPrimRec->Clone(hNameTrackEffPhi);
2128 hSingleTrackEffPhi->Divide(hdNdphiTracksMCPrimRec,hdNdphiTracksMCPrimGen,1,1,"B"); // binominal errors
2131 TString outfileOption = "RECREATE";
2132 if(updateOutfile) outfileOption = "UPDATE";
2134 TFile out(strOutfile,outfileOption);
2137 Printf("%s:%d -- error opening efficiency output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
2141 if(fDebug>0) Printf("%s:%d -- write efficiency to file %s ",(char*)__FILE__,__LINE__,strOutfile.Data());
2143 if(strOutDir && strOutDir.Length()){
2146 if((dir = ((TDirectory*) gDirectory->Get(strOutDir)))) dir->cd();
2148 dir = out.mkdir(strOutDir);
2153 hSingleTrackEffPt->Write();
2154 hSingleTrackEffEta->Write();
2155 hSingleTrackEffPhi->Write();
2160 //________________________________________________________________________________________________________________
2161 void AliFragmentationFunctionCorrections::WriteSingleTrackSecCorr(TString strInfile, TString strID, TString strOutfile,
2162 Bool_t updateOutfile, TString strOutDir)
2164 // read task ouput from MC and write single track eff - standard dir/list
2166 TString strdir = "PWG4_FragmentationFunction_" + strID;
2167 TString strlist = "fracfunc_" + strID;
2169 WriteSingleTrackSecCorr(strInfile,strdir,strlist,strOutfile,updateOutfile,strOutDir);
2172 //___________________________________________________________________________________________________________________________________
2173 void AliFragmentationFunctionCorrections::WriteSingleTrackSecCorr(TString strInfile, TString strdir, TString strlist,
2174 TString strOutfile, Bool_t updateOutfile, TString strOutDir)
2176 // read task output from MC and write single track secondaries contamination correction as function of pt, eta, phi
2177 // argument strlist optional - read from directory strdir if not specified
2178 // write corr factor to file stroutfile - by default only 'update' file (don't overwrite)
2180 TH1D* hdNdptTracksMCPrimRec;
2181 TH2D* hdNdetadphiTracksMCPrimRec;
2183 TH1D* hdNdptTracksMCSecRec;
2184 TH2D* hdNdetadphiTracksMCSecRec;
2186 TFile f(strInfile,"READ");
2189 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strInfile.Data());
2193 if(fDebug>0) Printf("%s:%d -- writeSingleTrackEff: open task ouput file %s",(char*)__FILE__,__LINE__,strInfile.Data());
2195 if(strdir && strdir.Length()) gDirectory->cd(strdir);
2199 if(strlist && strlist.Length()){
2201 if(!(list = (TList*) gDirectory->Get(strlist))){
2202 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
2209 hdNdptTracksMCPrimRec = (TH1D*) list->FindObject("fh1TrackQAPtRecEffGen");
2210 hdNdetadphiTracksMCPrimRec = (TH2D*) list->FindObject("fh2TrackQAEtaPhiRecEffGen");
2212 hdNdptTracksMCSecRec = (TH1D*) list->FindObject("fh1TrackQAPtSecRec");
2213 hdNdetadphiTracksMCSecRec = (TH2D*) list->FindObject("fh2TrackQAEtaPhiSecRec");
2216 hdNdptTracksMCPrimRec = (TH1D*) gDirectory->Get("fh1TrackQAPtRecEffGen");
2217 hdNdetadphiTracksMCPrimRec = (TH2D*) gDirectory->Get("fh2TrackQAEtaPhiRecEffGen");
2219 hdNdptTracksMCSecRec = (TH1D*) gDirectory->Get("fh1TrackQAPtSecRec");
2220 hdNdetadphiTracksMCSecRec = (TH2D*) gDirectory->Get("fh2TrackQAEtaPhiSecRec");
2223 hdNdptTracksMCPrimRec->SetDirectory(0);
2224 hdNdetadphiTracksMCPrimRec->SetDirectory(0);
2225 hdNdptTracksMCSecRec->SetDirectory(0);
2226 hdNdetadphiTracksMCSecRec->SetDirectory(0);
2230 // projections: dN/deta, dN/dphi
2232 TH1D* hdNdetaTracksMCPrimRec = (TH1D*) hdNdetadphiTracksMCPrimRec->ProjectionX("hdNdetaTracksMcPrimRec");
2233 TH1D* hdNdphiTracksMCPrimRec = (TH1D*) hdNdetadphiTracksMCPrimRec->ProjectionY("hdNdphiTracksMcPrimRec");
2235 TH1D* hdNdetaTracksMCSecRec = (TH1D*) hdNdetadphiTracksMCSecRec->ProjectionX("hdNdetaTracksMcSecRec");
2236 TH1D* hdNdphiTracksMCSecRec = (TH1D*) hdNdetadphiTracksMCSecRec->ProjectionY("hdNdphiTracksMcSecRec");
2241 TString strNamePtPrim = "hTrackPtPrim";
2242 TString strNamePtSec = "hTrackPtSec";
2244 if(fNHistoBinsSinglePt) hdNdptTracksMCPrimRec = (TH1D*) hdNdptTracksMCPrimRec->Rebin(fNHistoBinsSinglePt,strNamePtPrim,fHistoBinsSinglePt->GetArray());
2245 if(fNHistoBinsSinglePt) hdNdptTracksMCSecRec = (TH1D*) hdNdptTracksMCSecRec->Rebin(fNHistoBinsSinglePt,strNamePtSec,fHistoBinsSinglePt->GetArray());
2248 // secondary correction factor: divide prim/(prim+sec)
2250 TH1F* hSingleTrackSecCorrPt = (TH1F*) hdNdptTracksMCSecRec->Clone("hSingleTrackSecCorrPt");
2251 TH1F* hSumPrimSecPt = (TH1F*) hdNdptTracksMCSecRec->Clone("hSumPrimSecPt");
2252 hSumPrimSecPt->Add(hdNdptTracksMCPrimRec);
2253 hSingleTrackSecCorrPt->Divide(hdNdptTracksMCPrimRec,hSumPrimSecPt,1,1,"B"); // binominal errors
2255 TH1F* hSingleTrackSecCorrEta = (TH1F*) hdNdetaTracksMCSecRec->Clone("hSingleTrackSecCorrEta");
2256 TH1F* hSumPrimSecEta = (TH1F*) hdNdetaTracksMCSecRec->Clone("hSumPrimSecEta");
2257 hSumPrimSecEta->Add(hdNdetaTracksMCPrimRec);
2258 hSingleTrackSecCorrEta->Divide(hdNdetaTracksMCPrimRec,hSumPrimSecEta,1,1,"B"); // binominal errors
2260 TH1F* hSingleTrackSecCorrPhi = (TH1F*) hdNdphiTracksMCSecRec->Clone("hSingleTrackSecCorrPhi");
2261 TH1F* hSumPrimSecPhi = (TH1F*) hdNdphiTracksMCSecRec->Clone("hSumPrimSecPhi");
2262 hSumPrimSecPhi->Add(hdNdphiTracksMCPrimRec);
2263 hSingleTrackSecCorrPhi->Divide(hdNdphiTracksMCPrimRec,hSumPrimSecPhi,1,1,"B"); // binominal errors
2266 TString outfileOption = "RECREATE";
2267 if(updateOutfile) outfileOption = "UPDATE";
2269 TFile out(strOutfile,outfileOption);
2272 Printf("%s:%d -- error opening secCorr output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
2276 if(fDebug>0) Printf("%s:%d -- write secCorr to file %s ",(char*)__FILE__,__LINE__,strOutfile.Data());
2278 if(strOutDir && strOutDir.Length()){
2281 if((dir = ((TDirectory*) gDirectory->Get(strOutDir)))) dir->cd();
2283 dir = out.mkdir(strOutDir);
2288 hdNdptTracksMCSecRec->Write();
2289 hdNdetaTracksMCSecRec->Write();
2290 hdNdphiTracksMCSecRec->Write();
2292 hSingleTrackSecCorrPt->Write();
2293 hSingleTrackSecCorrEta->Write();
2294 hSingleTrackSecCorrPhi->Write();
2299 //________________________________________________________________________________________________________________
2300 void AliFragmentationFunctionCorrections::WriteSingleResponse(TString strInfile, TString strID, TString strOutfile,
2301 Bool_t updateOutfile, TString strOutDir)
2303 // read task ouput from MC and write single track eff - standard dir/list
2305 TString strdir = "PWG4_FragmentationFunction_" + strID;
2306 TString strlist = "fracfunc_" + strID;
2308 WriteSingleResponse(strInfile,strdir,strlist,strOutfile,updateOutfile,strOutDir);
2312 //_____________________________________________________________________________________________________________________________________
2313 void AliFragmentationFunctionCorrections::WriteSingleResponse(TString strInfile, TString strdir, TString strlist,
2314 TString strOutfile, Bool_t updateOutfile, TString strOutDir)
2316 // read 2d THnSparse response matrices in pt from file
2318 // write to strOutfile
2320 THnSparse* hnResponseSinglePt;
2321 TH2F* h2ResponseSinglePt;
2323 TFile f(strInfile,"READ");
2326 Printf("%s:%d -- error opening file %s", (char*)__FILE__,__LINE__,strInfile.Data());
2330 if(fDebug>0) Printf("%s:%d -- read response matrices from file %s ",(char*)__FILE__,__LINE__,strInfile.Data());
2332 if(strdir && strdir.Length()) gDirectory->cd(strdir);
2336 if(strlist && strlist.Length()){
2338 if(!(list = (TList*) gDirectory->Get(strlist))){
2339 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
2344 if(list) hnResponseSinglePt = (THnSparse*) list->FindObject("fhnResponseSinglePt");
2345 else hnResponseSinglePt = (THnSparse*) gDirectory->Get("fhnResponseSinglePt");
2348 if(!hnResponseSinglePt){
2349 Printf("%s:%d -- error retrieving response matrix fhnResponseSinglePt",(char*)__FILE__,__LINE__);
2357 h2ResponseSinglePt = (TH2F*) hnResponseSinglePt->Projection(1,0);// note convention: yDim,xDim
2358 h2ResponseSinglePt->SetNameTitle("h2ResponseSinglePt","");
2363 TString outfileOption = "RECREATE";
2364 if(updateOutfile) outfileOption = "UPDATE";
2366 TFile out(strOutfile,outfileOption);
2369 Printf("%s:%d -- error opening response matrix output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
2373 if(fDebug>0) Printf("%s:%d -- write response matrices to file %s ",(char*)__FILE__,__LINE__,strOutfile.Data());
2375 if(strOutDir && strOutDir.Length()){
2378 if((dir = ((TDirectory*) gDirectory->Get(strOutDir)))) dir->cd();
2380 dir = out.mkdir(strOutDir);
2385 hnResponseSinglePt->Write();
2386 h2ResponseSinglePt->Write();
2391 //________________________________________________________________________________________________________________
2392 void AliFragmentationFunctionCorrections::WriteJetTrackEff(TString strInfile, TString strID, TString strOutfile,
2393 Bool_t updateOutfile)
2395 // read task ouput from MC and write single track eff - standard dir/list
2397 TString strdir = "PWG4_FragmentationFunction_" + strID;
2398 TString strlist = "fracfunc_" + strID;
2400 WriteJetTrackEff(strInfile,strdir,strlist,strOutfile,updateOutfile);
2403 //___________________________________________________________________________________________________________________________________
2404 void AliFragmentationFunctionCorrections::WriteJetTrackEff(TString strInfile, TString strdir, TString strlist,
2405 TString strOutfile, Bool_t updateOutfile)
2407 // read task output from MC and write track eff in jet pt slices as function of pt, z, xi
2408 // argument strlist optional - read from directory strdir if not specified
2409 // write eff to file strOutfile - by default only 'update' file (don't overwrite)
2411 TH1F* hEffPt[fNJetPtSlices];
2412 TH1F* hEffXi[fNJetPtSlices];
2413 TH1F* hEffZ[fNJetPtSlices];
2415 TH1F* hdNdptTracksMCPrimGen[fNJetPtSlices];
2416 TH1F* hdNdxiMCPrimGen[fNJetPtSlices];
2417 TH1F* hdNdzMCPrimGen[fNJetPtSlices];
2419 TH1F* hdNdptTracksMCPrimRec[fNJetPtSlices];
2420 TH1F* hdNdxiMCPrimRec[fNJetPtSlices];
2421 TH1F* hdNdzMCPrimRec[fNJetPtSlices];
2424 TH1F* fh1FFJetPtRecEffGen;
2426 TH2F* fh2FFTrackPtRecEffGen;
2427 TH2F* fh2FFZRecEffGen;
2428 TH2F* fh2FFXiRecEffGen;
2430 TH2F* fh2FFTrackPtRecEffRec;
2431 TH2F* fh2FFZRecEffRec;
2432 TH2F* fh2FFXiRecEffRec;
2435 TFile f(strInfile,"READ");
2438 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strInfile.Data());
2442 if(fDebug>0) Printf("%s:%d -- writeJetTrackEff: open task ouput file %s",(char*)__FILE__,__LINE__,strInfile.Data());
2444 if(strdir && strdir.Length()) gDirectory->cd(strdir);
2448 if(strlist && strlist.Length()){
2450 if(!(list = (TList*) gDirectory->Get(strlist))){
2451 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
2457 fh1FFJetPtRecEffGen = (TH1F*) list->FindObject("fh1FFJetPtRecEffGen");
2459 fh2FFTrackPtRecEffGen = (TH2F*) list->FindObject("fh2FFTrackPtRecEffGen");
2460 fh2FFZRecEffGen = (TH2F*) list->FindObject("fh2FFZRecEffGen");
2461 fh2FFXiRecEffGen = (TH2F*) list->FindObject("fh2FFXiRecEffGen");
2463 fh2FFTrackPtRecEffRec = (TH2F*) list->FindObject("fh2FFTrackPtRecEffRec");
2464 fh2FFZRecEffRec = (TH2F*) list->FindObject("fh2FFZRecEffRec");
2465 fh2FFXiRecEffRec = (TH2F*) list->FindObject("fh2FFXiRecEffRec");
2468 fh1FFJetPtRecEffGen = (TH1F*) gDirectory->FindObject("fh1FFJetPtRecEffGen");
2470 fh2FFTrackPtRecEffGen = (TH2F*) gDirectory->FindObject("fh2FFTrackPtRecEffGen");
2471 fh2FFZRecEffGen = (TH2F*) gDirectory->FindObject("fh2FFZRecEffGen");
2472 fh2FFXiRecEffGen = (TH2F*) gDirectory->FindObject("fh2FFXiRecEffGen");
2474 fh2FFTrackPtRecEffRec = (TH2F*) gDirectory->FindObject("fh2FFTrackPtRecEffRec");
2475 fh2FFZRecEffRec = (TH2F*) gDirectory->FindObject("fh2FFZRecEffRec");
2476 fh2FFXiRecEffRec = (TH2F*) gDirectory->FindObject("fh2FFXiRecEffRec");
2479 fh1FFJetPtRecEffGen->SetDirectory(0);
2481 fh2FFTrackPtRecEffGen->SetDirectory(0);
2482 fh2FFZRecEffGen->SetDirectory(0);
2483 fh2FFXiRecEffGen->SetDirectory(0);
2485 fh2FFTrackPtRecEffRec->SetDirectory(0);
2486 fh2FFZRecEffRec->SetDirectory(0);
2487 fh2FFXiRecEffRec->SetDirectory(0);
2492 // projections: FF for generated and reconstructed primaries
2494 for(Int_t i=0; i<fNJetPtSlices; i++){
2496 Float_t jetPtLoLim = fJetPtSlices->At(i);
2497 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
2499 Int_t binLo = static_cast<Int_t>(fh2FFTrackPtRecEffGen->GetXaxis()->FindBin(jetPtLoLim));
2500 Int_t binUp = static_cast<Int_t>(fh2FFTrackPtRecEffGen->GetXaxis()->FindBin(jetPtUpLim))-1;
2502 if(binUp > fh2FFTrackPtRecEffGen->GetNbinsX()){
2503 Printf("%s:%d -- jet pt range %0.3f exceeds histo limits",(char*)__FILE__,__LINE__,jetPtUpLim);
2507 TString strNameFFPtGen(Form("fh1FFTrackPtGenPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2508 TString strNameFFZGen(Form("fh1FFZGenPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2509 TString strNameFFXiGen(Form("fh1FFXiGenPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2511 TString strNameFFPtRec(Form("fh1FFTrackPtRecPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2512 TString strNameFFZRec(Form("fh1FFZRecPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2513 TString strNameFFXiRec(Form("fh1FFXiRecPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2516 // appendix 'unbinned' to avoid histos with same name after rebinning
2518 hdNdptTracksMCPrimGen[i] = (TH1F*) fh2FFTrackPtRecEffGen->ProjectionY(strNameFFPtGen+"_unBinned",binLo,binUp,"o"); // option "o": original axis range
2519 hdNdzMCPrimGen[i] = (TH1F*) fh2FFZRecEffGen->ProjectionY(strNameFFZGen+"_unBinned",binLo,binUp,"o");
2520 hdNdxiMCPrimGen[i] = (TH1F*) fh2FFXiRecEffGen->ProjectionY(strNameFFXiGen+"_unBinned",binLo,binUp,"o");
2522 hdNdptTracksMCPrimRec[i] = (TH1F*) fh2FFTrackPtRecEffRec->ProjectionY(strNameFFPtRec+"_unBinned",binLo,binUp,"o"); // option "o": original axis range
2523 hdNdzMCPrimRec[i] = (TH1F*) fh2FFZRecEffRec->ProjectionY(strNameFFZRec+"_unBinned",binLo,binUp,"o");
2524 hdNdxiMCPrimRec[i] = (TH1F*) fh2FFXiRecEffRec->ProjectionY(strNameFFXiRec+"_unBinned",binLo,binUp,"o");
2528 if(fNHistoBinsPt[i]) hdNdptTracksMCPrimGen[i] = (TH1F*) hdNdptTracksMCPrimGen[i]->Rebin(fNHistoBinsPt[i],strNameFFPtGen,fHistoBinsPt[i]->GetArray());
2529 if(fNHistoBinsZ[i]) hdNdzMCPrimGen[i] = (TH1F*) hdNdzMCPrimGen[i]->Rebin(fNHistoBinsZ[i],strNameFFZGen,fHistoBinsZ[i]->GetArray());
2530 if(fNHistoBinsXi[i]) hdNdxiMCPrimGen[i] = (TH1F*) hdNdxiMCPrimGen[i]->Rebin(fNHistoBinsXi[i],strNameFFXiGen,fHistoBinsXi[i]->GetArray());
2532 if(fNHistoBinsPt[i]) hdNdptTracksMCPrimRec[i] = (TH1F*) hdNdptTracksMCPrimRec[i]->Rebin(fNHistoBinsPt[i],strNameFFPtRec,fHistoBinsPt[i]->GetArray());
2533 if(fNHistoBinsZ[i]) hdNdzMCPrimRec[i] = (TH1F*) hdNdzMCPrimRec[i]->Rebin(fNHistoBinsZ[i],strNameFFZRec,fHistoBinsZ[i]->GetArray());
2534 if(fNHistoBinsXi[i]) hdNdxiMCPrimRec[i] = (TH1F*) hdNdxiMCPrimRec[i]->Rebin(fNHistoBinsXi[i],strNameFFXiRec,fHistoBinsXi[i]->GetArray());
2536 hdNdptTracksMCPrimGen[i]->SetNameTitle(strNameFFPtGen,"");
2537 hdNdzMCPrimGen[i]->SetNameTitle(strNameFFZGen,"");
2538 hdNdxiMCPrimGen[i]->SetNameTitle(strNameFFXiGen,"");
2540 hdNdptTracksMCPrimRec[i]->SetNameTitle(strNameFFPtRec,"");
2541 hdNdzMCPrimRec[i]->SetNameTitle(strNameFFZRec,"");
2542 hdNdxiMCPrimRec[i]->SetNameTitle(strNameFFXiRec,"");
2546 Double_t nJetsBin = fh1FFJetPtRecEffGen->Integral(binLo,binUp);
2548 NormalizeTH1(hdNdptTracksMCPrimGen[i],nJetsBin);
2549 NormalizeTH1(hdNdzMCPrimGen[i],nJetsBin);
2550 NormalizeTH1(hdNdxiMCPrimGen[i],nJetsBin);
2552 NormalizeTH1(hdNdptTracksMCPrimRec[i],nJetsBin);
2553 NormalizeTH1(hdNdzMCPrimRec[i],nJetsBin);
2554 NormalizeTH1(hdNdxiMCPrimRec[i],nJetsBin);
2556 // divide rec/gen : efficiency
2558 TString strNameEffPt(Form("hEffPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2559 TString strNameEffZ(Form("hEffZ_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2560 TString strNameEffXi(Form("hEffXi_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2562 hEffPt[i] = (TH1F*) hdNdptTracksMCPrimRec[i]->Clone(strNameEffPt);
2563 hEffPt[i]->Divide(hdNdptTracksMCPrimRec[i],hdNdptTracksMCPrimGen[i],1,1,"B"); // binominal errors
2565 hEffXi[i] = (TH1F*) hdNdxiMCPrimRec[i]->Clone(strNameEffXi);
2566 hEffXi[i]->Divide(hdNdxiMCPrimRec[i],hdNdxiMCPrimGen[i],1,1,"B"); // binominal errors
2568 hEffZ[i] = (TH1F*) hdNdzMCPrimRec[i]->Clone(strNameEffZ);
2569 hEffZ[i]->Divide(hdNdzMCPrimRec[i],hdNdzMCPrimGen[i],1,1,"B"); // binominal errors
2574 TString outfileOption = "RECREATE";
2575 if(updateOutfile) outfileOption = "UPDATE";
2577 TFile out(strOutfile,outfileOption);
2580 Printf("%s:%d -- error opening efficiency output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
2584 if(fDebug>0) Printf("%s:%d -- write efficiency to file %s ",(char*)__FILE__,__LINE__,strOutfile.Data());
2586 // if(strdir && strdir.Length()){
2587 // TDirectory* dir = out.mkdir(strdir);
2591 for(Int_t i=0; i<fNJetPtSlices; i++){
2593 hdNdptTracksMCPrimGen[i]->Write();
2594 hdNdxiMCPrimGen[i]->Write();
2595 hdNdzMCPrimGen[i]->Write();
2597 hdNdptTracksMCPrimRec[i]->Write();
2598 hdNdxiMCPrimRec[i]->Write();
2599 hdNdzMCPrimRec[i]->Write();
2610 //________________________________________________________________________________________________________________
2611 void AliFragmentationFunctionCorrections::WriteJetSecCorr(TString strInfile, TString strID, TString strOutfile,
2612 Bool_t updateOutfile)
2614 // read task ouput from MC and write secondary correction - standard dir/list
2616 TString strdir = "PWG4_FragmentationFunction_" + strID;
2617 TString strlist = "fracfunc_" + strID;
2619 WriteJetSecCorr(strInfile,strdir,strlist,strOutfile,updateOutfile);
2622 //___________________________________________________________________________________________________________________________________
2623 void AliFragmentationFunctionCorrections::WriteJetSecCorr(TString strInfile, TString strdir, TString strlist,
2624 TString strOutfile, Bool_t updateOutfile)
2626 // read task output from MC and write secondary correction in jet pt slices as function of pt, z, xi
2627 // argument strlist optional - read from directory strdir if not specified
2628 // write eff to file strOutfile - by default only 'update' file (don't overwrite)
2630 TH1F* hSecCorrPt[fNJetPtSlices];
2631 TH1F* hSecCorrXi[fNJetPtSlices];
2632 TH1F* hSecCorrZ[fNJetPtSlices];
2634 TH1F* hdNdptTracksMCPrimRec[fNJetPtSlices];
2635 TH1F* hdNdxiMCPrimRec[fNJetPtSlices];
2636 TH1F* hdNdzMCPrimRec[fNJetPtSlices];
2638 TH1F* hdNdptTracksMCSecRec[fNJetPtSlices];
2639 TH1F* hdNdxiMCSecRec[fNJetPtSlices];
2640 TH1F* hdNdzMCSecRec[fNJetPtSlices];
2642 TH1F* fh1FFJetPtRecEffGen;
2644 TH2F* fh2FFTrackPtRecEffRec;
2645 TH2F* fh2FFZRecEffRec;
2646 TH2F* fh2FFXiRecEffRec;
2648 TH2F* fh2FFTrackPtSecRec;
2650 TH2F* fh2FFXiSecRec;
2652 TFile f(strInfile,"READ");
2655 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strInfile.Data());
2659 if(fDebug>0) Printf("%s:%d -- writeJetTrackEff: open task ouput file %s",(char*)__FILE__,__LINE__,strInfile.Data());
2661 if(strdir && strdir.Length()) gDirectory->cd(strdir);
2665 if(strlist && strlist.Length()){
2667 if(!(list = (TList*) gDirectory->Get(strlist))){
2668 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
2674 fh1FFJetPtRecEffGen = (TH1F*) list->FindObject("fh1FFJetPtRecEffGen");
2676 fh2FFTrackPtRecEffRec = (TH2F*) list->FindObject("fh2FFTrackPtRecEffRec");
2677 fh2FFZRecEffRec = (TH2F*) list->FindObject("fh2FFZRecEffRec");
2678 fh2FFXiRecEffRec = (TH2F*) list->FindObject("fh2FFXiRecEffRec");
2680 fh2FFTrackPtSecRec = (TH2F*) list->FindObject("fh2FFTrackPtSecRec");
2681 fh2FFZSecRec = (TH2F*) list->FindObject("fh2FFZSecRec");
2682 fh2FFXiSecRec = (TH2F*) list->FindObject("fh2FFXiSecRec");
2685 fh1FFJetPtRecEffGen = (TH1F*) gDirectory->FindObject("fh1FFJetPtRecEffGen");
2687 fh2FFTrackPtRecEffRec = (TH2F*) gDirectory->FindObject("fh2FFTrackPtRecEffRec");
2688 fh2FFZRecEffRec = (TH2F*) gDirectory->FindObject("fh2FFZRecEffRec");
2689 fh2FFXiRecEffRec = (TH2F*) gDirectory->FindObject("fh2FFXiRecEffRec");
2691 fh2FFTrackPtSecRec = (TH2F*) gDirectory->FindObject("fh2FFTrackPtSecRec");
2692 fh2FFZSecRec = (TH2F*) gDirectory->FindObject("fh2FFZSecRec");
2693 fh2FFXiSecRec = (TH2F*) gDirectory->FindObject("fh2FFXiSecRec");
2696 fh1FFJetPtRecEffGen->SetDirectory(0);
2698 fh2FFTrackPtRecEffRec->SetDirectory(0);
2699 fh2FFZRecEffRec->SetDirectory(0);
2700 fh2FFXiRecEffRec->SetDirectory(0);
2702 fh2FFTrackPtSecRec->SetDirectory(0);
2703 fh2FFZSecRec->SetDirectory(0);
2704 fh2FFXiSecRec->SetDirectory(0);
2709 // projections: FF for generated and reconstructed primaries
2711 for(Int_t i=0; i<fNJetPtSlices; i++){
2713 Float_t jetPtLoLim = fJetPtSlices->At(i);
2714 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
2716 Int_t binLo = static_cast<Int_t>(fh2FFTrackPtRecEffRec->GetXaxis()->FindBin(jetPtLoLim));
2717 Int_t binUp = static_cast<Int_t>(fh2FFTrackPtRecEffRec->GetXaxis()->FindBin(jetPtUpLim))-1;
2719 if(binUp > fh2FFTrackPtRecEffRec->GetNbinsX()){
2720 Printf("%s:%d -- jet pt range %0.3f exceeds histo limits",(char*)__FILE__,__LINE__,jetPtUpLim);
2724 TString strNameFFPtPrimRec(Form("fh1FFTrackPtRecPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2725 TString strNameFFZPrimRec(Form("fh1FFZRecPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2726 TString strNameFFXiPrimRec(Form("fh1FFXiRecPrim_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2728 TString strNameFFPtSecRec(Form("fh1FFTrackPtRecSec_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2729 TString strNameFFZSecRec(Form("fh1FFZRecSec_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2730 TString strNameFFXiSecRec(Form("fh1FFXiRecSec_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2733 // appendix 'unbinned' to avoid histos with same name after rebinning
2735 hdNdptTracksMCPrimRec[i] = (TH1F*) fh2FFTrackPtRecEffRec->ProjectionY(strNameFFPtPrimRec+"_unBinned",binLo,binUp,"o"); // option "o": original axis range
2736 hdNdzMCPrimRec[i] = (TH1F*) fh2FFZRecEffRec->ProjectionY(strNameFFZPrimRec+"_unBinned",binLo,binUp,"o");
2737 hdNdxiMCPrimRec[i] = (TH1F*) fh2FFXiRecEffRec->ProjectionY(strNameFFXiPrimRec+"_unBinned",binLo,binUp,"o");
2739 hdNdptTracksMCSecRec[i] = (TH1F*) fh2FFTrackPtSecRec->ProjectionY(strNameFFPtSecRec+"_unBinned",binLo,binUp,"o"); // option "o": original axis range
2740 hdNdzMCSecRec[i] = (TH1F*) fh2FFZSecRec->ProjectionY(strNameFFZSecRec+"_unBinned",binLo,binUp,"o");
2741 hdNdxiMCSecRec[i] = (TH1F*) fh2FFXiSecRec->ProjectionY(strNameFFXiSecRec+"_unBinned",binLo,binUp,"o");
2745 if(fNHistoBinsPt[i]) hdNdptTracksMCPrimRec[i] = (TH1F*) hdNdptTracksMCPrimRec[i]->Rebin(fNHistoBinsPt[i],strNameFFPtPrimRec,fHistoBinsPt[i]->GetArray());
2746 if(fNHistoBinsZ[i]) hdNdzMCPrimRec[i] = (TH1F*) hdNdzMCPrimRec[i]->Rebin(fNHistoBinsZ[i],strNameFFZPrimRec,fHistoBinsZ[i]->GetArray());
2747 if(fNHistoBinsXi[i]) hdNdxiMCPrimRec[i] = (TH1F*) hdNdxiMCPrimRec[i]->Rebin(fNHistoBinsXi[i],strNameFFXiPrimRec,fHistoBinsXi[i]->GetArray());
2749 if(fNHistoBinsPt[i]) hdNdptTracksMCSecRec[i] = (TH1F*) hdNdptTracksMCSecRec[i]->Rebin(fNHistoBinsPt[i],strNameFFPtSecRec,fHistoBinsPt[i]->GetArray());
2750 if(fNHistoBinsZ[i]) hdNdzMCSecRec[i] = (TH1F*) hdNdzMCSecRec[i]->Rebin(fNHistoBinsZ[i],strNameFFZSecRec,fHistoBinsZ[i]->GetArray());
2751 if(fNHistoBinsXi[i]) hdNdxiMCSecRec[i] = (TH1F*) hdNdxiMCSecRec[i]->Rebin(fNHistoBinsXi[i],strNameFFXiSecRec,fHistoBinsXi[i]->GetArray());
2753 hdNdptTracksMCPrimRec[i]->SetNameTitle(strNameFFPtPrimRec,"");
2754 hdNdzMCPrimRec[i]->SetNameTitle(strNameFFZPrimRec,"");
2755 hdNdxiMCPrimRec[i]->SetNameTitle(strNameFFXiPrimRec,"");
2757 hdNdptTracksMCSecRec[i]->SetNameTitle(strNameFFPtSecRec,"");
2758 hdNdzMCSecRec[i]->SetNameTitle(strNameFFZSecRec,"");
2759 hdNdxiMCSecRec[i]->SetNameTitle(strNameFFXiSecRec,"");
2763 Double_t nJetsBin = fh1FFJetPtRecEffGen->Integral(binLo,binUp);
2765 NormalizeTH1(hdNdptTracksMCPrimRec[i],nJetsBin);
2766 NormalizeTH1(hdNdzMCPrimRec[i],nJetsBin);
2767 NormalizeTH1(hdNdxiMCPrimRec[i],nJetsBin);
2769 NormalizeTH1(hdNdptTracksMCSecRec[i],nJetsBin);
2770 NormalizeTH1(hdNdzMCSecRec[i],nJetsBin);
2771 NormalizeTH1(hdNdxiMCSecRec[i],nJetsBin);
2773 // divide rec/gen : efficiency
2775 TString strNameSecCorrPt(Form("hSecCorrPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2776 TString strNameSecCorrZ(Form("hSecCorrZ_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2777 TString strNameSecCorrXi(Form("hSecCorrXi_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2779 hSecCorrPt[i] = (TH1F*) hdNdptTracksMCSecRec[i]->Clone(strNameSecCorrPt);
2780 TH1F* hSumPrimSecPt = (TH1F*) hdNdptTracksMCSecRec[i]->Clone("hSumPrimSecPt");
2781 hSumPrimSecPt->Add(hdNdptTracksMCPrimRec[i]);
2782 hSecCorrPt[i]->Divide(hdNdptTracksMCPrimRec[i],hSumPrimSecPt,1,1,"B"); // binominal errors
2784 hSecCorrXi[i] = (TH1F*) hdNdxiMCSecRec[i]->Clone(strNameSecCorrXi);
2785 TH1F* hSumPrimSecXi = (TH1F*) hdNdxiMCSecRec[i]->Clone("hSumPrimSecXi");
2786 hSumPrimSecXi->Add(hdNdxiMCPrimRec[i]);
2787 hSecCorrXi[i]->Divide(hdNdxiMCPrimRec[i],hSumPrimSecXi,1,1,"B"); // binominal errors
2789 hSecCorrZ[i] = (TH1F*) hdNdzMCSecRec[i]->Clone(strNameSecCorrZ);
2790 TH1F* hSumPrimSecZ = (TH1F*) hdNdzMCSecRec[i]->Clone("hSumPrimSecZ");
2791 hSumPrimSecZ->Add(hdNdzMCPrimRec[i]);
2792 hSecCorrZ[i]->Divide(hdNdzMCPrimRec[i],hSumPrimSecZ,1,1,"B"); // binominal errors
2797 TString outfileOption = "RECREATE";
2798 if(updateOutfile) outfileOption = "UPDATE";
2800 TFile out(strOutfile,outfileOption);
2803 Printf("%s:%d -- error opening efficiency output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
2807 if(fDebug>0) Printf("%s:%d -- write efficiency to file %s ",(char*)__FILE__,__LINE__,strOutfile.Data());
2809 for(Int_t i=0; i<fNJetPtSlices; i++){
2811 // hdNdptTracksMCSecRec[i]->Write();
2812 // hdNdxiMCSecRec[i]->Write();
2813 // hdNdzMCSecRec[i]->Write();
2815 hSecCorrPt[i]->Write();
2816 hSecCorrXi[i]->Write();
2817 hSecCorrZ[i]->Write();
2823 //________________________________________________________________________________________________________________
2824 void AliFragmentationFunctionCorrections::WriteJetResponse(TString strInfile, TString strID, TString strOutfile,
2825 Bool_t updateOutfile)
2827 // read task ouput from MC and write single track eff - standard dir/list
2829 TString strdir = "PWG4_FragmentationFunction_" + strID;
2830 TString strlist = "fracfunc_" + strID;
2832 WriteJetResponse(strInfile,strdir,strlist,strOutfile,updateOutfile);
2835 //_____________________________________________________________________________________________________________________________________
2836 void AliFragmentationFunctionCorrections::WriteJetResponse(TString strInfile, TString strdir, TString strlist,
2837 TString strOutfile, Bool_t updateOutfile)
2839 // read 3d THnSparse response matrices in pt,z,xi vs jet pt from file
2840 // project THnSparse + TH2 in jet pt slices
2841 // write to strOutfile
2843 THnSparse* hn3ResponseJetPt;
2844 THnSparse* hn3ResponseJetZ;
2845 THnSparse* hn3ResponseJetXi;
2847 // 2D response matrices
2849 THnSparse* hnResponsePt[fNJetPtSlices];
2850 THnSparse* hnResponseZ[fNJetPtSlices];
2851 THnSparse* hnResponseXi[fNJetPtSlices];
2853 TH2F* h2ResponsePt[fNJetPtSlices];
2854 TH2F* h2ResponseZ[fNJetPtSlices];
2855 TH2F* h2ResponseXi[fNJetPtSlices];
2857 // 1D projections on gen pt / rec pt axes
2859 TH1F* h1FFPtRec[fNJetPtSlices];
2860 TH1F* h1FFZRec[fNJetPtSlices];
2861 TH1F* h1FFXiRec[fNJetPtSlices];
2863 TH1F* h1FFPtGen[fNJetPtSlices];
2864 TH1F* h1FFZGen[fNJetPtSlices];
2865 TH1F* h1FFXiGen[fNJetPtSlices];
2867 TH1F* h1RatioPt[fNJetPtSlices];
2868 TH1F* h1RatioZ[fNJetPtSlices];
2869 TH1F* h1RatioXi[fNJetPtSlices];
2873 TFile f(strInfile,"READ");
2876 Printf("%s:%d -- error opening file %s", (char*)__FILE__,__LINE__,strInfile.Data());
2880 if(fDebug>0) Printf("%s:%d -- read response matrices from file %s ",(char*)__FILE__,__LINE__,strInfile.Data());
2882 if(strdir && strdir.Length()) gDirectory->cd(strdir);
2886 if(strlist && strlist.Length()){
2888 if(!(list = (TList*) gDirectory->Get(strlist))){
2889 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
2895 hn3ResponseJetPt = (THnSparse*) list->FindObject("fhnResponseJetTrackPt");
2896 hn3ResponseJetZ = (THnSparse*) list->FindObject("fhnResponseJetZ");
2897 hn3ResponseJetXi = (THnSparse*) list->FindObject("fhnResponseJetXi");
2900 hn3ResponseJetPt = (THnSparse*) gDirectory->Get("fhnResponseJetTrackPt");
2901 hn3ResponseJetZ = (THnSparse*) gDirectory->Get("fhnResponseJetZ");
2902 hn3ResponseJetXi = (THnSparse*) gDirectory->Get("fhnResponseJetXi");
2906 if(!hn3ResponseJetPt){
2907 Printf("%s:%d -- error retrieving response matrix fhnResponseJetTrackPt",(char*)__FILE__,__LINE__);
2911 if(!hn3ResponseJetZ){
2912 Printf("%s:%d -- error retrieving response matrix fhnResponseJetZ",(char*)__FILE__,__LINE__);
2916 if(!hn3ResponseJetXi){
2917 Printf("%s:%d -- error retrieving response matrix fhnResponseJetXi",(char*)__FILE__,__LINE__);
2925 Int_t axisJetPtTHn3 = -1;
2926 Int_t axisGenPtTHn3 = -1;
2927 Int_t axisRecPtTHn3 = -1;
2929 for(Int_t i=0; i<hn3ResponseJetPt->GetNdimensions(); i++){
2931 TString title = hn3ResponseJetPt->GetAxis(i)->GetTitle();
2933 if(title.Contains("jet p_{T}")) axisJetPtTHn3 = i;
2934 if(title.Contains("gen p_{T}")) axisGenPtTHn3 = i;
2935 if(title.Contains("rec p_{T}")) axisRecPtTHn3 = i;
2938 if(axisJetPtTHn3 == -1){
2939 Printf("%s:%d -- error axisJetPtTHn3",(char*)__FILE__,__LINE__);
2943 if(axisGenPtTHn3 == -1){
2944 Printf("%s:%d -- error axisGenPtTHn3",(char*)__FILE__,__LINE__);
2948 if(axisRecPtTHn3 == -1){
2949 Printf("%s:%d -- error axisRecPtTHn3",(char*)__FILE__,__LINE__);
2953 for(Int_t i=0; i<fNJetPtSlices; i++){
2955 Float_t jetPtLoLim = fJetPtSlices->At(i);
2956 Float_t jetPtUpLim = fJetPtSlices->At(i+1);
2958 Int_t binLo = static_cast<Int_t>(hn3ResponseJetPt->GetAxis(axisJetPtTHn3)->FindBin(jetPtLoLim));
2959 Int_t binUp = static_cast<Int_t>(hn3ResponseJetPt->GetAxis(axisJetPtTHn3)->FindBin(jetPtUpLim))-1;
2961 if(binUp > hn3ResponseJetPt->GetAxis(axisJetPtTHn3)->GetNbins()){
2962 Printf("%s:%d -- jet pt range %0.3f exceeds histo limits",(char*)__FILE__,__LINE__,jetPtUpLim);
2966 TString strNameRespPt(Form("hnResponsePt_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2967 TString strNameRespZ(Form("hnResponseZ_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2968 TString strNameRespXi(Form("hnResponseXi_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2970 TString strNameTH2RespPt(Form("h2ResponsePt_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2971 TString strNameTH2RespZ(Form("h2ResponseZ_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2972 TString strNameTH2RespXi(Form("h2ResponseXi_%02d_%02d",static_cast<Int_t> (jetPtLoLim),static_cast<Int_t> (jetPtUpLim)));
2974 TString strNameRecPt(Form("h1FFTrackPtRecPrim_recPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2975 TString strNameRecZ(Form("h1FFZRecPrim_recPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2976 TString strNameRecXi(Form("h1FFXiRecPrim_recPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2978 TString strNameGenPt(Form("h1FFTrackPtRecPrim_genPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2979 TString strNameGenZ(Form("h1FFZRecPrim_genPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2980 TString strNameGenXi(Form("h1FFXiRecPrim_genPt_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2982 TString strNameRatioPt(Form("h1RatioTrackPtRecPrim_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2983 TString strNameRatioZ(Form("h1RatioZRecPrim_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2984 TString strNameRatioXi(Form("h1RatioXiRecPrim_%02d_%02d",static_cast<Int_t>(jetPtLoLim),static_cast<Int_t>(jetPtUpLim)));
2987 // 2D projections in jet pt range
2989 hn3ResponseJetPt->GetAxis(axisJetPtTHn3)->SetRange(binLo,binUp);
2990 hn3ResponseJetZ->GetAxis(axisJetPtTHn3)->SetRange(binLo,binUp);
2991 hn3ResponseJetXi->GetAxis(axisJetPtTHn3)->SetRange(binLo,binUp);
2993 Int_t axesProj[2] = {axisRecPtTHn3,axisGenPtTHn3};
2995 hnResponsePt[i] = hn3ResponseJetPt->Projection(2,axesProj);
2996 hnResponseZ[i] = hn3ResponseJetZ->Projection(2,axesProj);
2997 hnResponseXi[i] = hn3ResponseJetXi->Projection(2,axesProj);
2999 hnResponsePt[i]->SetNameTitle(strNameRespPt,"");
3000 hnResponseZ[i]->SetNameTitle(strNameRespZ,"");
3001 hnResponseXi[i]->SetNameTitle(strNameRespXi,"");
3003 h2ResponsePt[i] = (TH2F*) hnResponsePt[i]->Projection(1,0);// note convention: yDim,xDim
3004 h2ResponseZ[i] = (TH2F*) hnResponseZ[i]->Projection(1,0); // note convention: yDim,xDim
3005 h2ResponseXi[i] = (TH2F*) hnResponseXi[i]->Projection(1,0);// note convention: yDim,xDim
3007 h2ResponsePt[i]->SetNameTitle(strNameTH2RespPt,"");
3008 h2ResponseZ[i]->SetNameTitle(strNameTH2RespZ,"");
3009 h2ResponseXi[i]->SetNameTitle(strNameTH2RespXi,"");
3014 Int_t axisGenPtTHn2 = -1;
3015 Int_t axisRecPtTHn2 = -1;
3017 for(Int_t d=0; d<hnResponsePt[i]->GetNdimensions(); d++){
3019 TString title = hnResponsePt[i]->GetAxis(d)->GetTitle();
3021 if(title.Contains("gen p_{T}")) axisGenPtTHn2 = d;
3022 if(title.Contains("rec p_{T}")) axisRecPtTHn2 = d;
3026 if(axisGenPtTHn2 == -1){
3027 Printf("%s:%d -- error axisGenPtTHn2",(char*)__FILE__,__LINE__);
3031 if(axisRecPtTHn2 == -1){
3032 Printf("%s:%d -- error axisRecPtTHn2",(char*)__FILE__,__LINE__);
3037 h1FFPtRec[i] = (TH1F*) hnResponsePt[i]->Projection(axisRecPtTHn2);// note convention: yDim,xDim
3038 h1FFZRec[i] = (TH1F*) hnResponseZ[i]->Projection(axisRecPtTHn2);// note convention: yDim,xDim
3039 h1FFXiRec[i] = (TH1F*) hnResponseXi[i]->Projection(axisRecPtTHn2);// note convention: yDim,xDim
3041 h1FFPtRec[i]->SetNameTitle(strNameRecPt,"");
3042 h1FFZRec[i]->SetNameTitle(strNameRecZ,"");
3043 h1FFXiRec[i]->SetNameTitle(strNameRecXi,"");
3045 h1FFPtGen[i] = (TH1F*) hnResponsePt[i]->Projection(axisGenPtTHn2);// note convention: yDim,xDim
3046 h1FFZGen[i] = (TH1F*) hnResponseZ[i]->Projection(axisGenPtTHn2);// note convention: yDim,xDim
3047 h1FFXiGen[i] = (TH1F*) hnResponseXi[i]->Projection(axisGenPtTHn2);// note convention: yDim,xDim
3049 h1FFPtGen[i]->SetNameTitle(strNameGenPt,"");
3050 h1FFZGen[i]->SetNameTitle(strNameGenZ,"");
3051 h1FFXiGen[i]->SetNameTitle(strNameGenXi,"");
3053 // normalize 1D projections
3055 if(fNHistoBinsPt[i]) h1FFPtRec[i] = (TH1F*) h1FFPtRec[i]->Rebin(fNHistoBinsPt[i],"",fHistoBinsPt[i]->GetArray());
3056 if(fNHistoBinsZ[i]) h1FFZRec[i] = (TH1F*) h1FFZRec[i]->Rebin(fNHistoBinsZ[i],"",fHistoBinsZ[i]->GetArray());
3057 if(fNHistoBinsXi[i]) h1FFXiRec[i] = (TH1F*) h1FFXiRec[i]->Rebin(fNHistoBinsXi[i],"",fHistoBinsXi[i]->GetArray());
3059 if(fNHistoBinsPt[i]) h1FFPtGen[i] = (TH1F*) h1FFPtGen[i]->Rebin(fNHistoBinsPt[i],"",fHistoBinsPt[i]->GetArray());
3060 if(fNHistoBinsZ[i]) h1FFZGen[i] = (TH1F*) h1FFZGen[i]->Rebin(fNHistoBinsZ[i],"",fHistoBinsZ[i]->GetArray());
3061 if(fNHistoBinsXi[i]) h1FFXiGen[i] = (TH1F*) h1FFXiGen[i]->Rebin(fNHistoBinsXi[i],"",fHistoBinsXi[i]->GetArray());
3063 NormalizeTH1(h1FFPtRec[i],fNJets->At(i));
3064 NormalizeTH1(h1FFZRec[i],fNJets->At(i));
3065 NormalizeTH1(h1FFXiRec[i],fNJets->At(i));
3067 NormalizeTH1(h1FFPtGen[i],fNJets->At(i));
3068 NormalizeTH1(h1FFZGen[i],fNJets->At(i));
3069 NormalizeTH1(h1FFXiGen[i],fNJets->At(i));
3071 // ratios 1D projections
3073 h1RatioPt[i] = (TH1F*) h1FFPtRec[i]->Clone(strNameRatioPt);
3074 h1RatioPt[i]->Reset();
3075 h1RatioPt[i]->Divide(h1FFPtRec[i],h1FFPtGen[i],1,1,"B");
3077 h1RatioZ[i] = (TH1F*) h1FFZRec[i]->Clone(strNameRatioZ);
3078 h1RatioZ[i]->Reset();
3079 h1RatioZ[i]->Divide(h1FFZRec[i],h1FFZGen[i],1,1,"B");
3081 h1RatioXi[i] = (TH1F*) h1FFXiRec[i]->Clone(strNameRatioXi);
3082 h1RatioXi[i]->Reset();
3083 h1RatioXi[i]->Divide(h1FFXiRec[i],h1FFXiGen[i],1,1,"B");
3089 TString outfileOption = "RECREATE";
3090 if(updateOutfile) outfileOption = "UPDATE";
3092 TFile out(strOutfile,outfileOption);
3095 Printf("%s:%d -- error opening response matrix output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
3099 if(fDebug>0) Printf("%s:%d -- write response matrices to file %s ",(char*)__FILE__,__LINE__,strOutfile.Data());
3101 //if(strdir && strdir.Length()){
3102 // TDirectory* dir = out.mkdir(strdir);
3106 for(Int_t i=0; i<fNJetPtSlices; i++){
3108 hnResponsePt[i]->Write();
3109 hnResponseXi[i]->Write();
3110 hnResponseZ[i]->Write();
3112 h2ResponsePt[i]->Write();
3113 h2ResponseXi[i]->Write();
3114 h2ResponseZ[i]->Write();
3116 h1FFPtRec[i]->Write();
3117 h1FFZRec[i]->Write();
3118 h1FFXiRec[i]->Write();
3120 h1FFPtGen[i]->Write();
3121 h1FFZGen[i]->Write();
3122 h1FFXiGen[i]->Write();
3124 h1RatioPt[i]->Write();
3125 h1RatioZ[i]->Write();
3126 h1RatioXi[i]->Write();
3133 //______________________________________________________________________________________________________
3134 void AliFragmentationFunctionCorrections::ReadResponse(TString strfile, TString strdir, TString strlist)
3136 // read response matrices from file
3137 // argument strlist optional - read from directory strdir if not specified
3138 // note: THnSparse are not rebinned
3140 THnSparse* hRespPt[fNJetPtSlices];
3141 THnSparse* hRespZ[fNJetPtSlices];
3142 THnSparse* hRespXi[fNJetPtSlices];
3144 for(Int_t i=0; i<fNJetPtSlices; i++) hRespPt[i] = 0;
3145 for(Int_t i=0; i<fNJetPtSlices; i++) hRespZ[i] = 0;
3146 for(Int_t i=0; i<fNJetPtSlices; i++) hRespXi[i] = 0;
3148 TFile f(strfile,"READ");
3151 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
3155 if(fDebug>0) Printf("%s:%d -- read response matrices from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3157 if(strdir && strdir.Length()) gDirectory->cd(strdir);
3161 if(strlist && strlist.Length()){
3163 if(!(list = (TList*) gDirectory->Get(strlist))){
3164 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
3169 for(Int_t i=0; i<fNJetPtSlices; i++){
3171 Int_t jetPtLoLim = static_cast<Int_t> (fJetPtSlices->At(i));
3172 Int_t jetPtUpLim = static_cast<Int_t> (fJetPtSlices->At(i+1));
3174 TString strNameRespPt(Form("hnResponsePt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3175 TString strNameRespZ(Form("hnResponseZ_%02d_%02d",jetPtLoLim,jetPtUpLim));
3176 TString strNameRespXi(Form("hnResponseXi_%02d_%02d",jetPtLoLim,jetPtUpLim));
3179 hRespPt[i] = (THnSparse*) list->FindObject(strNameRespPt);
3180 hRespZ[i] = (THnSparse*) list->FindObject(strNameRespZ);
3181 hRespXi[i] = (THnSparse*) list->FindObject(strNameRespXi);
3184 hRespPt[i] = (THnSparse*) gDirectory->Get(strNameRespPt);
3185 hRespZ[i] = (THnSparse*) gDirectory->Get(strNameRespZ);
3186 hRespXi[i] = (THnSparse*) gDirectory->Get(strNameRespXi);
3190 Printf("%s:%d -- error retrieving response %s", (char*)__FILE__,__LINE__,strNameRespPt.Data());
3194 Printf("%s:%d -- error retrieving response %s", (char*)__FILE__,__LINE__,strNameRespZ.Data());
3198 Printf("%s:%d -- error retrieving response %s", (char*)__FILE__,__LINE__,strNameRespXi.Data());
3201 // if(0){ // can't rebin THnSparse ...
3202 // if(fNHistoBinsPt[i]) hRespPt[i]->SetBinEdges(0,fHistoBinsPt[i]->GetArray());
3203 // if(fNHistoBinsPt[i]) hRespPt[i]->SetBinEdges(1,fHistoBinsPt[i]->GetArray());
3205 // if(fNHistoBinsZ[i]) hRespZ[i]->SetBinEdges(0,fHistoBinsZ[i]->GetArray());
3206 // if(fNHistoBinsZ[i]) hRespZ[i]->SetBinEdges(1,fHistoBinsZ[i]->GetArray());
3208 // if(fNHistoBinsXi[i]) hRespXi[i]->SetBinEdges(0,fHistoBinsXi[i]->GetArray());
3209 // if(fNHistoBinsXi[i]) hRespXi[i]->SetBinEdges(1,fHistoBinsXi[i]->GetArray());
3213 } // jet slices loop
3215 f.Close(); // THnSparse pointers still valid even if file closed
3217 // for(Int_t i=0; i<fNJetPtSlices; i++){ // no copy c'tor ...
3218 // if(hRespPt[i]) new(fhnResponsePt[i]) THnSparseF(*hRespPt[i]);
3219 // if(hRespZ[i]) new(fhnResponseZ[i]) THnSparseF(*hRespZ[i]);
3220 // if(hRespXi[i]) new(fhnResponseXi[i]) THnSparseF(*hRespXi[i]);
3223 for(Int_t i=0; i<fNJetPtSlices; i++){
3224 fhnResponsePt[i] = hRespPt[i];
3225 fhnResponseZ[i] = hRespZ[i];
3226 fhnResponseXi[i] = hRespXi[i];
3230 //______________________________________________________________________________________________________________________
3231 void AliFragmentationFunctionCorrections::ReadPriors(TString strfile,const Int_t type)
3233 // read priors from file: rec primaries, gen pt dist
3235 if(fDebug>0) Printf("%s:%d -- read priors from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3237 // temporary histos to store pointers from file
3238 TH1F* hist[fNJetPtSlices];
3240 for(Int_t i=0; i<fNJetPtSlices; i++) hist[i] = 0;
3242 TFile f(strfile,"READ");
3245 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
3249 for(Int_t i=0; i<fNJetPtSlices; i++){
3251 Int_t jetPtLoLim = static_cast<Int_t> (fJetPtSlices->At(i));
3252 Int_t jetPtUpLim = static_cast<Int_t> (fJetPtSlices->At(i+1));
3256 if(type == kFlagPt) strName.Form("h1FFTrackPtRecPrim_genPt_%02d_%02d",jetPtLoLim,jetPtUpLim);
3257 if(type == kFlagZ) strName.Form("h1FFZRecPrim_genPt_%02d_%02d",jetPtLoLim,jetPtUpLim);
3258 if(type == kFlagXi) strName.Form("h1FFXiRecPrim_genPt_%02d_%02d",jetPtLoLim,jetPtUpLim);
3260 hist[i] = (TH1F*) gDirectory->Get(strName);
3263 Printf("%s:%d -- error retrieving prior %s", (char*)__FILE__,__LINE__,strName.Data());
3267 //if(fNHistoBinsPt[i]) hist[i] = (TH1F*) hist[i]->Rebin(fNHistoBinsPt[i],hist[i]->GetName()+"_rebin",fHistoBinsPt[i]->GetArray());
3269 if(hist[i]) hist[i]->SetDirectory(0);
3271 } // jet slices loop
3276 for(Int_t i=0; i<fNJetPtSlices; i++){ // 2nd loop: need to close input file before placing histos
3277 if(hist[i] && type == kFlagPt) new(fh1FFTrackPtPrior[i]) TH1F(*hist[i]);
3278 if(hist[i] && type == kFlagZ) new(fh1FFZPrior[i]) TH1F(*hist[i]);
3279 if(hist[i] && type == kFlagXi) new(fh1FFXiPrior[i]) TH1F(*hist[i]);
3283 //_____________________________________________________
3284 // void AliFragmentationFunctionCorrections::RatioRecGen()
3286 // // create ratio reconstructed over generated FF
3287 // // use current highest corrLevel
3289 // Printf("%s:%d -- build ratio rec.gen, corrLevel %d",(char*)__FILE__,__LINE__,fNCorrectionLevels-1);
3291 // for(Int_t i=0; i<fNJetPtSlices; i++){
3293 // TH1F* histPtRec = fCorrFF[fNCorrectionLevels-1]->GetTrackPt(i); // levels -1: latest corr level
3294 // TH1F* histZRec = fCorrFF[fNCorrectionLevels-1]->GetZ(i); // levels -1: latest corr level
3295 // TH1F* histXiRec = fCorrFF[fNCorrectionLevels-1]->GetXi(i); // levels -1: latest corr level
3297 // TH1F* histPtGen = fh1FFTrackPtGenPrim[i];
3298 // TH1F* histZGen = fh1FFZGenPrim[i];
3299 // TH1F* histXiGen = fh1FFXiGenPrim[i];
3301 // TString histNamePt = histPtRec->GetName();
3302 // TString histNameZ = histZRec->GetName();
3303 // TString histNameXi = histXiRec->GetName();
3305 // histNamePt.ReplaceAll("fh1FF","fh1FFRatioRecGen");
3306 // histNameZ.ReplaceAll("fh1FF","fh1FFRatioRecGen");
3307 // histNameXi.ReplaceAll("fh1FF","fh1FFRatioRecGen");
3310 // TH1F* hRatioRecGenPt = (TH1F*) histPtRec->Clone(histNamePt);
3311 // hRatioRecGenPt->Reset();
3312 // hRatioRecGenPt->Divide(histPtRec,histPtGen,1,1,"B");
3314 // TH1F* hRatioRecGenZ = (TH1F*) histZRec->Clone(histNameZ);
3315 // hRatioRecGenZ->Reset();
3316 // hRatioRecGenZ->Divide(histZRec,histZGen,1,1,"B");
3318 // TH1F* hRatioRecGenXi = (TH1F*) histXiRec->Clone(histNameXi);
3319 // hRatioRecGenXi->Reset();
3320 // hRatioRecGenXi->Divide(histXiRec,histXiGen,1,1,"B");
3322 // new(fh1FFRatioRecGenPt[i]) TH1F(*hRatioRecGenPt);
3323 // new(fh1FFRatioRecGenZ[i]) TH1F(*hRatioRecGenZ);
3324 // new(fh1FFRatioRecGenXi[i]) TH1F(*hRatioRecGenXi);
3328 // //___________________________________________________________
3329 // void AliFragmentationFunctionCorrections::RatioRecPrimaries()
3331 // // create ratio reconstructed tracks over reconstructed primaries
3332 // // use raw FF (corrLevel 0)
3334 // Printf("%s:%d -- build ratio rec tracks /rec primaries",(char*)__FILE__,__LINE__);
3336 // for(Int_t i=0; i<fNJetPtSlices; i++){
3338 // const Int_t corrLevel = 0;
3340 // TH1F* histPtRec = fCorrFF[corrLevel]->GetTrackPt(i); // levels -1: latest corr level
3341 // TH1F* histZRec = fCorrFF[corrLevel]->GetZ(i); // levels -1: latest corr level
3342 // TH1F* histXiRec = fCorrFF[corrLevel]->GetXi(i); // levels -1: latest corr level
3344 // TH1F* histPtRecPrim = fh1FFTrackPtRecPrim[i];
3345 // TH1F* histZRecPrim = fh1FFZRecPrim[i];
3346 // TH1F* histXiRecPrim = fh1FFXiRecPrim[i];
3348 // TString histNamePt = histPtRec->GetName();
3349 // TString histNameZ = histZRec->GetName();
3350 // TString histNameXi = histXiRec->GetName();
3352 // histNamePt.ReplaceAll("fh1FF","fh1FFRatioRecPrim");
3353 // histNameZ.ReplaceAll("fh1FF","fh1FFRatioRecPrim");
3354 // histNameXi.ReplaceAll("fh1FF","fh1FFRatioRecPrim");
3357 // TH1F* hRatioRecPrimPt = (TH1F*) histPtRec->Clone(histNamePt);
3358 // hRatioRecPrimPt->Reset();
3359 // hRatioRecPrimPt->Divide(histPtRec,histPtRecPrim,1,1,"B");
3361 // TH1F* hRatioRecPrimZ = (TH1F*) histZRec->Clone(histNameZ);
3362 // hRatioRecPrimZ->Reset();
3363 // hRatioRecPrimZ->Divide(histZRec,histZRecPrim,1,1,"B");
3365 // TH1F* hRatioRecPrimXi = (TH1F*) histXiRec->Clone(histNameXi);
3366 // hRatioRecPrimXi->Reset();
3367 // hRatioRecPrimXi->Divide(histXiRec,histXiRecPrim,1,1,"B");
3370 // new(fh1FFRatioRecPrimPt[i]) TH1F(*hRatioRecPrimPt);
3371 // new(fh1FFRatioRecPrimZ[i]) TH1F(*hRatioRecPrimZ);
3372 // new(fh1FFRatioRecPrimXi[i]) TH1F(*hRatioRecPrimXi);
3376 // __________________________________________________________________________________
3377 void AliFragmentationFunctionCorrections::ProjectJetResponseMatrices(TString strOutfile)
3380 // project response matrices on both axes:
3381 // FF for rec primaries, in terms of generated and reconstructed momentum
3382 // write FF and ratios to outFile
3384 Printf("%s:%d -- project response matrices, write to %s",(char*)__FILE__,__LINE__,strOutfile.Data());
3386 TH1F* hFFPtRec[fNJetPtSlices];
3387 TH1F* hFFZRec[fNJetPtSlices];
3388 TH1F* hFFXiRec[fNJetPtSlices];
3390 TH1F* hFFPtGen[fNJetPtSlices];
3391 TH1F* hFFZGen[fNJetPtSlices];
3392 TH1F* hFFXiGen[fNJetPtSlices];
3394 TH1F* hRatioPt[fNJetPtSlices];
3395 TH1F* hRatioZ[fNJetPtSlices];
3396 TH1F* hRatioXi[fNJetPtSlices];
3399 Int_t axisGenPt = 1;
3400 Int_t axisRecPt = 0;
3402 for(Int_t i=0; i<fNJetPtSlices; i++){
3404 Int_t jetPtLoLim = static_cast<Int_t> (fJetPtSlices->At(i));
3405 Int_t jetPtUpLim = static_cast<Int_t> (fJetPtSlices->At(i+1));
3407 TString strNameRecPt(Form("h1FFTrackPtRecPrim_recPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3408 TString strNameRecZ(Form("h1FFZRecPrim_recPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3409 TString strNameRecXi(Form("h1FFXiRecPrim_recPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3411 TString strNameGenPt(Form("h1FFTrackPtRecPrim_genPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3412 TString strNameGenZ(Form("h1FFZRecPrim_genPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3413 TString strNameGenXi(Form("h1FFXiRecPrim_genPt_%02d_%02d",jetPtLoLim,jetPtUpLim));
3415 TString strNameRatioPt(Form("h1RatioTrackPtRecPrim_%02d_%02d",jetPtLoLim,jetPtUpLim));
3416 TString strNameRatioZ(Form("h1RatioZRecPrim_%02d_%02d",jetPtLoLim,jetPtUpLim));
3417 TString strNameRatioXi(Form("h1RatioXiRecPrim_%02d_%02d",jetPtLoLim,jetPtUpLim));
3420 hFFPtRec[i] = (TH1F*) fhnResponsePt[i]->Projection(axisRecPt);// note convention: yDim,xDim
3421 hFFZRec[i] = (TH1F*) fhnResponseZ[i]->Projection(axisRecPt);// note convention: yDim,xDim
3422 hFFXiRec[i] = (TH1F*) fhnResponseXi[i]->Projection(axisRecPt);// note convention: yDim,xDim
3424 hFFPtRec[i]->SetNameTitle(strNameRecPt,"");
3425 hFFZRec[i]->SetNameTitle(strNameRecZ,"");
3426 hFFXiRec[i]->SetNameTitle(strNameRecXi,"");
3429 hFFPtGen[i] = (TH1F*) fhnResponsePt[i]->Projection(axisGenPt);// note convention: yDim,xDim
3430 hFFZGen[i] = (TH1F*) fhnResponseZ[i]->Projection(axisGenPt);// note convention: yDim,xDim
3431 hFFXiGen[i] = (TH1F*) fhnResponseXi[i]->Projection(axisGenPt);// note convention: yDim,xDim
3433 hFFPtGen[i]->SetNameTitle(strNameGenPt,"");
3434 hFFZGen[i]->SetNameTitle(strNameGenZ,"");
3435 hFFXiGen[i]->SetNameTitle(strNameGenXi,"");
3438 if(fNHistoBinsPt[i]) hFFPtRec[i] = (TH1F*) hFFPtRec[i]->Rebin(fNHistoBinsPt[i],"",fHistoBinsPt[i]->GetArray());
3439 if(fNHistoBinsZ[i]) hFFZRec[i] = (TH1F*) hFFZRec[i]->Rebin(fNHistoBinsZ[i],"",fHistoBinsZ[i]->GetArray());
3440 if(fNHistoBinsXi[i]) hFFXiRec[i] = (TH1F*) hFFXiRec[i]->Rebin(fNHistoBinsXi[i],"",fHistoBinsXi[i]->GetArray());
3442 if(fNHistoBinsPt[i]) hFFPtGen[i] = (TH1F*) hFFPtGen[i]->Rebin(fNHistoBinsPt[i],"",fHistoBinsPt[i]->GetArray());
3443 if(fNHistoBinsZ[i]) hFFZGen[i] = (TH1F*) hFFZGen[i]->Rebin(fNHistoBinsZ[i],"",fHistoBinsZ[i]->GetArray());
3444 if(fNHistoBinsXi[i]) hFFXiGen[i] = (TH1F*) hFFXiGen[i]->Rebin(fNHistoBinsXi[i],"",fHistoBinsXi[i]->GetArray());
3446 NormalizeTH1(hFFPtGen[i],fNJets->At(i));
3447 NormalizeTH1(hFFZGen[i],fNJets->At(i));
3448 NormalizeTH1(hFFXiGen[i],fNJets->At(i));
3450 NormalizeTH1(hFFPtRec[i],fNJets->At(i));
3451 NormalizeTH1(hFFZRec[i],fNJets->At(i));
3452 NormalizeTH1(hFFXiRec[i],fNJets->At(i));
3455 hRatioPt[i] = (TH1F*) hFFPtRec[i]->Clone(strNameRatioPt);
3456 hRatioPt[i]->Reset();
3457 hRatioPt[i]->Divide(hFFPtRec[i],hFFPtGen[i],1,1,"B");
3459 hRatioZ[i] = (TH1F*) hFFZRec[i]->Clone(strNameRatioZ);
3460 hRatioZ[i]->Reset();
3461 hRatioZ[i]->Divide(hFFZRec[i],hFFZGen[i],1,1,"B");
3463 hRatioXi[i] = (TH1F*) hFFXiRec[i]->Clone(strNameRatioXi);
3464 hRatioXi[i]->Reset();
3465 hRatioXi[i]->Divide(hFFXiRec[i],hFFXiGen[i],1,1,"B");
3472 TFile out(strOutfile,"RECREATE");
3475 Printf("%s:%d -- error opening response matrix output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
3479 for(Int_t i=0; i<fNJetPtSlices; i++){
3481 hFFPtRec[i]->Write();
3482 hFFZRec[i]->Write();
3483 hFFXiRec[i]->Write();
3485 hFFPtGen[i]->Write();
3486 hFFZGen[i]->Write();
3487 hFFXiGen[i]->Write();
3489 hRatioPt[i]->Write();
3490 hRatioZ[i]->Write();
3491 hRatioXi[i]->Write();
3497 // ____________________________________________________________________________________________________________________________
3498 void AliFragmentationFunctionCorrections::ProjectSingleResponseMatrix(TString strOutfile, Bool_t updateOutfile, TString strOutDir )
3500 // project response matrix on both axes:
3501 // pt spec for rec primaries, in terms of generated and reconstructed momentum
3502 // write spec and ratios to outFile
3504 Printf("%s:%d -- project single pt response matrix, write to %s",(char*)__FILE__,__LINE__,strOutfile.Data());
3510 Int_t axisGenPt = 1;
3511 Int_t axisRecPt = 0;
3513 TString strNameRecPt = "h1SpecTrackPtRecPrim_recPt";
3514 TString strNameGenPt = "h1SpecTrackPtRecPrim_genPt";
3515 TString strNameRatioPt = "h1RatioTrackPtRecPrim";
3517 hSpecPtRec = (TH1F*) fhnResponseSinglePt->Projection(axisRecPt);// note convention: yDim,xDim
3518 hSpecPtRec->SetNameTitle(strNameRecPt,"");
3520 hSpecPtGen = (TH1F*) fhnResponseSinglePt->Projection(axisGenPt);// note convention: yDim,xDim
3521 hSpecPtGen->SetNameTitle(strNameGenPt,"");
3523 hRatioPt = (TH1F*) hSpecPtRec->Clone(strNameRatioPt);
3525 hRatioPt->Divide(hSpecPtRec,hSpecPtGen,1,1,"B");
3527 TString outfileOption = "RECREATE";
3528 if(updateOutfile) outfileOption = "UPDATE";
3530 TFile out(strOutfile,outfileOption);
3533 Printf("%s:%d -- error opening reponse matrix projections output file %s", (char*)__FILE__,__LINE__,strOutfile.Data());
3538 if(strOutDir && strOutDir.Length()){
3541 if((dir = ((TDirectory*) gDirectory->Get(strOutDir)))) dir->cd();
3543 dir = out.mkdir(strOutDir);
3548 hSpecPtRec->Write();
3549 hSpecPtGen->Write();
3556 //__________________________________________________________________________________________________________________________________________________________________
3557 void AliFragmentationFunctionCorrections::RebinHisto(const Int_t jetPtSlice, const Int_t nBinsLimits, Double_t* binsLimits, Double_t* binsWidth, const Int_t type)
3559 // rebin histo, rescale bins according to new width
3560 // only correct for input histos with equal bin size
3562 // args: jetPtSlice, type, use current corr level
3564 // function takes array of limits and widths (e.g. 1 GeV bins up to 10 GeV, 2 GeV width up to 20 GeV, ...)
3565 // array size of binsLimits: nBinsLimits
3566 // array size of binsWidth: nBinsLimits-1
3567 // binsLimits have to be in increasing order
3568 // if binning undefined for any slice, original binning will be kept
3571 Printf("%s:%d -- jetPtSlices not defined", (char*)__FILE__,__LINE__);
3575 if(jetPtSlice>=fNJetPtSlices){
3576 Printf("%s:%d -- jetPtSlice %d exceeds max",(char*)__FILE__,__LINE__,jetPtSlice);
3581 Double_t binLimitMin = binsLimits[0];
3582 Double_t binLimitMax = binsLimits[nBinsLimits-1];
3584 Double_t binLimit = binLimitMin; // start value
3586 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 ...
3587 TArrayD binsArray(sizeUpperLim);
3589 binsArray.SetAt(binLimitMin,nBins++);
3591 while(binLimit<binLimitMax && nBins<sizeUpperLim){
3593 Int_t currentSlice = -1;
3594 for(Int_t i=0; i<nBinsLimits; i++){
3595 if(binLimit >= 0.999*binsLimits[i]) currentSlice = i; // 0.999 numerical saftey factor
3598 Double_t currentBinWidth = binsWidth[currentSlice];
3599 binLimit += currentBinWidth;
3601 binsArray.SetAt(binLimit,nBins++);
3606 if(type == kFlagPt) hist = fCorrFF[fNCorrectionLevels-1]->GetTrackPt(jetPtSlice);
3607 else if(type == kFlagZ) hist = fCorrFF[fNCorrectionLevels-1]->GetZ(jetPtSlice);
3608 else if(type == kFlagXi) hist = fCorrFF[fNCorrectionLevels-1]->GetXi(jetPtSlice);
3609 else if(type == kFlagSinglePt) hist = fCorrSinglePt[fNCorrectionLevelsSinglePt-1]->GetTrackPt(0);
3611 Printf("%s%d unknown type",(char*)__FILE__,__LINE__);
3615 Double_t binWidthNoRebin = hist->GetBinWidth(1);
3617 Double_t* bins = binsArray.GetArray();
3619 hist = (TH1F*) hist->Rebin(nBins-1,"",bins);
3621 for(Int_t bin=0; bin <= hist->GetNbinsX(); bin++){
3623 Double_t binWidthRebin = hist->GetBinWidth(bin);
3624 Double_t scaleF = binWidthNoRebin / binWidthRebin;
3626 Double_t binCont = hist->GetBinContent(bin);
3627 Double_t binErr = hist->GetBinError(bin);
3632 hist->SetBinContent(bin,binCont);
3633 hist->SetBinError(bin,binErr);
3638 TH1F* temp = new TH1F(*hist);
3640 if(type == kFlagPt) fCorrFF[fNCorrectionLevels-1]->ReplaceCorrHistos(jetPtSlice,temp,0,0);
3641 if(type == kFlagZ) fCorrFF[fNCorrectionLevels-1]->ReplaceCorrHistos(jetPtSlice,0,temp,0);
3642 if(type == kFlagXi) fCorrFF[fNCorrectionLevels-1]->ReplaceCorrHistos(jetPtSlice,0,0,temp);
3643 if(type == kFlagSinglePt) fCorrSinglePt[fNCorrectionLevelsSinglePt-1]->ReplaceCorrHistos(0,temp,0,0);
3648 //__________________________________________________________________________________________________________________________________________________________________
3649 void AliFragmentationFunctionCorrections::WriteJetSpecResponse(TString strInfile, TString strdir, TString strlist/*, TString strOutfile*/)
3652 if(fDebug>0) Printf("%s:%d -- read jet spectrum response matrix from file %s ",(char*)__FILE__,__LINE__,strInfile.Data());
3654 if(strdir && strdir.Length()) gDirectory->cd(strdir);
3658 if(strlist && strlist.Length()){
3660 if(!(list = (TList*) gDirectory->Get(strlist))){
3661 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
3666 THnSparse* hn6ResponseJetPt;
3669 hn6ResponseJetPt = (THnSparse*) list->FindObject("fhnCorrelation");
3672 hn6ResponseJetPt = (THnSparse*) list->FindObject("fhnCorrelation");
3675 Int_t axis6RecJetPt = 0;
3676 Int_t axis6GenJetPt = 3;
3678 hn6ResponseJetPt->GetAxis(axis6RecJetPt)->SetTitle("rec jet p_{T} (GeV/c)");
3679 hn6ResponseJetPt->GetAxis(axis6GenJetPt)->SetTitle("gen jet p_{T} (GeV/c)");
3681 Int_t nBinsRecPt = hn6ResponseJetPt->GetAxis(axis6RecJetPt)->GetNbins();
3682 Double_t loLimRecPt = hn6ResponseJetPt->GetAxis(axis6RecJetPt)->GetBinLowEdge(1);
3683 Double_t upLimRecPt = hn6ResponseJetPt->GetAxis(axis6RecJetPt)->GetBinUpEdge(nBinsRecPt);
3685 Int_t nBinsGenPt = hn6ResponseJetPt->GetAxis(axis6GenJetPt)->GetNbins();
3686 Double_t loLimGenPt = hn6ResponseJetPt->GetAxis(axis6GenJetPt)->GetBinLowEdge(1);
3687 Double_t upLimGenPt = hn6ResponseJetPt->GetAxis(axis6GenJetPt)->GetBinUpEdge(nBinsGenPt);
3689 Int_t nBinsTrackPt = 200;
3690 Int_t loLimTrackPt = 0;
3691 Int_t upLimTrackPt = 200;
3694 Int_t nBinsResponse[4] = {nBinsRecPt,nBinsTrackPt,nBinsGenPt,nBinsTrackPt};
3695 Double_t binMinResponse[4] = {loLimRecPt,loLimTrackPt,loLimGenPt,loLimTrackPt};
3696 Double_t binMaxResponse[4] = {upLimRecPt,upLimTrackPt,upLimGenPt,upLimTrackPt};
3698 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)"};
3700 THnSparseD* hn4ResponseTrackPtJetPt = new THnSparseD("hn4ResponseTrackPtJetPt","",4,nBinsResponse,binMinResponse,binMaxResponse);
3702 for(Int_t i=0; i<4; i++){
3703 hn4ResponseTrackPtJetPt->GetAxis(i)->SetTitle(labelsResponseSinglePt[i]);
3712 //_____________________________________________________________________________________________________________________________________
3713 void AliFragmentationFunctionCorrections::ReadSingleTrackEfficiency(TString strfile, TString strdir, TString strlist, TString strname)
3716 ReadSingleTrackCorrection(strfile,strdir,strlist,strname,kFlagEfficiency);
3720 //_____________________________________________________________________________________________________________________________________
3721 void AliFragmentationFunctionCorrections::ReadSingleTrackResponse(TString strfile, TString strdir, TString strlist, TString strname)
3724 ReadSingleTrackCorrection(strfile,strdir,strlist,strname,kFlagResponse);
3728 //_____________________________________________________________________________________________________________________________________
3729 void AliFragmentationFunctionCorrections::ReadSingleTrackSecCorr(TString strfile, TString strdir, TString strlist, TString strname)
3732 ReadSingleTrackCorrection(strfile,strdir,strlist,strname,kFlagSecondaries);
3736 //______________________________________________________________________________________________________________________________________________________
3737 void AliFragmentationFunctionCorrections::ReadSingleTrackCorrection(TString strfile, TString strdir, TString strlist, TString strname, const Int_t type)
3739 // read single track correction (pt) from file
3740 // type: efficiency / response / secondaries correction
3742 if(!((type == kFlagEfficiency) || (type == kFlagResponse) || (type == kFlagSecondaries))){
3743 Printf("%s:%d -- no such correction ",(char*)__FILE__,__LINE__);
3747 TFile f(strfile,"READ");
3750 Printf("%s:%d -- error opening file %s", (char*)__FILE__,__LINE__,strfile.Data());
3754 if(fDebug>0 && type==kFlagEfficiency) Printf("%s:%d -- read single track corr from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3755 if(fDebug>0 && type==kFlagResponse) Printf("%s:%d -- read single track response from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3756 if(fDebug>0 && type==kFlagSecondaries) Printf("%s:%d -- read single track secondaries corr from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3758 if(strdir && strdir.Length()) gDirectory->cd(strdir);
3762 if(strlist && strlist.Length()){
3764 if(!(list = (TList*) gDirectory->Get(strlist))){
3765 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
3770 TH1F* h1CorrHist = 0; // common TObject pointer not possible, need SetDirectory() later
3771 THnSparse* hnCorrHist = 0;
3773 if(type == kFlagEfficiency || type == kFlagSecondaries){
3775 if(list) h1CorrHist = (TH1F*) list->FindObject(strname);
3776 else h1CorrHist = (TH1F*) gDirectory->Get(strname);
3779 Printf("%s:%d -- error retrieving histo %s", (char*)__FILE__,__LINE__,strname.Data());
3784 else if(type == kFlagResponse){
3786 if(list) hnCorrHist = (THnSparse*) list->FindObject(strname);
3787 else hnCorrHist = (THnSparse*) gDirectory->Get(strname);
3790 Printf("%s:%d -- error retrieving histo %s", (char*)__FILE__,__LINE__,strname.Data());
3796 if(h1CorrHist) h1CorrHist->SetDirectory(0);
3797 //if(hnCorrHist) hnCorrHist->SetDirectory(0);
3801 if(type == kFlagEfficiency) fh1EffSinglePt = h1CorrHist;
3802 else if(type == kFlagResponse) fhnResponseSinglePt = hnCorrHist;
3803 else if(type == kFlagSecondaries) fh1SecCorrSinglePt = h1CorrHist;
3807 //________________________________________________________________________________________________________________
3808 void AliFragmentationFunctionCorrections::ReadRawPtSpec(TString strInfile, TString strID)
3810 // read track pt spec from task ouput - standard dir/list
3812 TString strdir = "PWG4_FragmentationFunction_" + strID;
3813 TString strlist = "fracfunc_" + strID;
3815 ReadRawPtSpec(strInfile,strdir,strlist);
3818 //_______________________________________________________________________________________________________
3819 void AliFragmentationFunctionCorrections::ReadRawPtSpec(TString strfile, TString strdir, TString strlist)
3821 // get raw pt spectra from file
3825 fNCorrectionLevelsSinglePt = 0;
3826 fCorrSinglePt = new AliFragFuncCorrHistos*[fgMaxNCorrectionLevels];
3827 AddCorrectionLevelSinglePt(); // first 'correction' level = raw spectrum
3829 // get raw pt spec from input file, normalize
3831 TFile f(strfile,"READ");
3834 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
3838 if(fDebug>0) Printf("%s:%d -- read raw spectra from file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3840 gDirectory->cd(strdir);
3844 if(!(list = (TList*) gDirectory->Get(strlist))){
3845 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
3849 TString hnameTrackPt("fh1TrackQAPtRecCuts");
3850 TString hnameEvtSel("fh1EvtSelection");
3852 TH1F* fh1TrackPt = (TH1F*) list->FindObject(hnameTrackPt);
3853 TH1F* fh1EvtSel = (TH1F*) list->FindObject(hnameEvtSel);
3855 if(!fh1TrackPt){ Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameTrackPt.Data()); return; }
3856 if(!fh1EvtSel) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameEvtSel.Data()); return; }
3859 //Float_t nEvents = fh1EvtSel->GetBinContent(fh1EvtSel->FindBin(0));
3861 // evts after physics selection
3862 Float_t nEvents = fh1EvtSel->GetEntries()
3863 - fh1EvtSel->GetBinContent(fh1EvtSel->FindBin(1)) // evts rejected by trigger selection ( = PhysicsSelection
3864 - fh1EvtSel->GetBinContent(fh1EvtSel->FindBin(2)); // evts with wrong centrality class
3867 fh1TrackPt->SetDirectory(0);
3872 NormalizeTH1(fh1TrackPt,nEvents);
3874 // raw FF = corr level 0
3875 fCorrSinglePt[0]->AddCorrHistos(0,fh1TrackPt);
3879 //_______________________________________________________________________________________________________
3880 void AliFragmentationFunctionCorrections::ReadRawPtSpecQATask(TString strfile, TString strdir, TString strlist)
3882 // get raw pt spectra from file
3883 // for output from Martas QA task
3887 fNCorrectionLevelsSinglePt = 0;
3888 fCorrSinglePt = new AliFragFuncCorrHistos*[fgMaxNCorrectionLevels];
3889 AddCorrectionLevelSinglePt(); // first 'correction' level = raw spectrum
3891 // get raw pt spec from input file, normalize
3893 TFile f(strfile,"READ");
3896 Printf("%s:%d -- error opening raw data file %s", (char*)__FILE__,__LINE__,strfile.Data());
3900 if(fDebug>0) Printf("%s:%d -- read raw pt spec from QA task output file %s ",(char*)__FILE__,__LINE__,strfile.Data());
3902 gDirectory->cd(strdir);
3906 if(!(list = (TList*) gDirectory->Get(strlist))){
3907 Printf("%s:%d -- error retrieving list %s from directory %s", (char*)__FILE__,__LINE__,strlist.Data(),strdir.Data());
3911 TString hnameTrackPt("fPtSel");
3912 TString hnameEvtSel("fNEventAll");
3914 TH1F* fh1TrackPt = (TH1F*) list->FindObject(hnameTrackPt);
3915 TH1F* fh1EvtSel = (TH1F*) list->FindObject(hnameEvtSel);
3917 if(!fh1TrackPt){ Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameTrackPt.Data()); return; }
3918 if(!fh1EvtSel) { Printf("%s:%d -- histo %s not found",(char*)__FILE__,__LINE__,hnameEvtSel.Data()); return; }
3921 // evts after physics selection
3922 Float_t nEvents = fh1EvtSel->GetEntries();
3924 fh1TrackPt->SetDirectory(0);
3929 NormalizeTH1(fh1TrackPt,nEvents);
3931 // raw FF = corr level 0
3932 fCorrSinglePt[0]->AddCorrHistos(0,fh1TrackPt);
3935 // ________________________________________________________
3936 void AliFragmentationFunctionCorrections::EffCorrSinglePt()
3938 // apply efficiency correction to inclusive track pt spec
3940 AddCorrectionLevelSinglePt("eff");
3942 TH1F* histPt = fCorrSinglePt[fNCorrectionLevelsSinglePt-2]->GetTrackPt(0);
3944 if(histPt->GetNbinsX() != fh1EffSinglePt->GetNbinsX()) Printf("%s:%d: inconsistency pt spec and eff corr bins - rebin effCorr ...", (char*)__FILE__,__LINE__);
3946 TString histNamePt = histPt->GetName();
3947 TH1F* hTrackPtEffCorr = (TH1F*) histPt->Clone(histNamePt);
3948 hTrackPtEffCorr->Divide(histPt,fh1EffSinglePt,1,1,"");
3950 fCorrSinglePt[fNCorrectionLevelsSinglePt-1]->AddCorrHistos(0,hTrackPtEffCorr);
3953 //___________________________________________________________________________________________________________________________
3954 void AliFragmentationFunctionCorrections::UnfoldSinglePt(const Int_t nIter, const Bool_t useCorrelatedErrors)
3956 // unfolde inclusive dN/dpt spectra
3958 AddCorrectionLevelSinglePt("unfold");
3960 TH1F* hist = fCorrSinglePt[fNCorrectionLevelsSinglePt-2]->GetTrackPt(0); // level -2: before unfolding, level -1: unfolded
3961 THnSparse* hnResponse = fhnResponseSinglePt;
3963 TString histNameTHn = hist->GetName();
3964 if(histNameTHn.Contains("TH1")) histNameTHn.ReplaceAll("TH1","THn");
3965 if(histNameTHn.Contains("fPt")) histNameTHn.ReplaceAll("fPt","fhnPt");
3968 TString histNameBackFolded = hist->GetName();
3969 histNameBackFolded.Append("_backfold");
3971 TString histNameRatioFolded = hist->GetName();
3972 if(histNameRatioFolded.Contains("fh1")) histNameRatioFolded.ReplaceAll("fh1","hRatio");
3973 if(histNameRatioFolded.Contains("fPt")) histNameRatioFolded.ReplaceAll("fPt","hRatioPt");
3974 histNameRatioFolded.Append("_unfold");
3976 TString histNameRatioBackFolded = hist->GetName();
3977 if(histNameRatioBackFolded.Contains("fh1")) histNameRatioBackFolded.ReplaceAll("fh1","hRatio");
3978 if(histNameRatioBackFolded.Contains("fPt")) histNameRatioBackFolded.ReplaceAll("fPt","hRatioPt");
3979 histNameRatioBackFolded.Append("_backfold");
3981 THnSparse* hnHist = TH1toSparse(hist,histNameTHn,hist->GetTitle());
3982 THnSparse* hnFlatEfficiency = TH1toSparse(hist,"fhnEfficiency","eff",kTRUE); // could optionally also use real eff
3984 THnSparse* hnUnfolded
3985 = Unfold(hnHist,hnResponse,hnFlatEfficiency,nIter,useCorrelatedErrors);
3987 TH1F* hUnfolded = (TH1F*) hnUnfolded->Projection(0);
3988 hUnfolded->SetNameTitle(hist->GetName(),hist->GetTitle());
3990 fCorrSinglePt[fNCorrectionLevelsSinglePt-1]->AddCorrHistos(0,hUnfolded);
3992 // backfolding: apply response matrix to unfolded spectrum
3993 TH1F* hBackFolded = ApplyResponse(hUnfolded,hnResponse);
3994 hBackFolded->SetNameTitle(histNameBackFolded,hist->GetTitle());
3996 fh1SingleTrackPtBackFolded = hBackFolded;
3999 // ratio unfolded to original histo
4000 TH1F* hRatioUnfolded = (TH1F*) hUnfolded->Clone(histNameRatioFolded);
4001 hRatioUnfolded->Reset();
4002 hRatioUnfolded->Divide(hUnfolded,hist,1,1,"B");
4004 fh1RatioSingleTrackPtFolded = hRatioUnfolded;
4007 // ratio backfolded to original histo
4008 TH1F* hRatioBackFolded = (TH1F*) hBackFolded->Clone(histNameRatioBackFolded);
4009 hRatioBackFolded->Reset();
4010 hRatioBackFolded->Divide(hBackFolded,hist,1,1,"B");
4012 fh1RatioSingleTrackPtBackFolded = hRatioBackFolded;
4015 delete hnFlatEfficiency;
4019 // ________________________________________________________
4020 void AliFragmentationFunctionCorrections::SecCorrSinglePt()
4022 // apply efficiency correction to inclusive track pt spec
4024 AddCorrectionLevelSinglePt("secCorr");
4026 TH1F* histPt = fCorrSinglePt[fNCorrectionLevelsSinglePt-2]->GetTrackPt(0);
4028 if(histPt->GetNbinsX() != fh1SecCorrSinglePt->GetNbinsX())
4029 Printf("%s:%d: inconsistency pt spec and secondaries corr bins - rebin effCorr ...", (char*)__FILE__,__LINE__);
4031 TString histNamePt = histPt->GetName();
4032 TH1F* hTrackPtSecCorr = (TH1F*) histPt->Clone(histNamePt);
4034 hTrackPtSecCorr->Multiply(histPt,fh1SecCorrSinglePt,1,1,"");
4036 fCorrSinglePt[fNCorrectionLevelsSinglePt-1]->AddCorrHistos(0,hTrackPtSecCorr);