1 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
2 * See cxx source for full Copyright notice */
5 /* Author: Redmer Alexander Bertens, rbertens@cern.ch, rbertens@nikhef.nl, r.a.bertens@uu.nl
6 * see implementation for additional information */
8 #ifndef AliJetFlowTools_H
9 #define AliJetFlowTools_H
11 // root forward declarations
21 // aliroot forward declarations
22 class AliAnaChargedJetResponseMaker;
27 #include "TDirectoryFile.h"
30 #include "TVirtualPad.h"
31 #include "TPaveText.h"
34 //_____________________________________________________________________________
35 class AliJetFlowTools {
39 ~AliJetFlowTools(); // not implemented (deliberately). object ownership is a bit messy in this class
40 // since most (or all) of the objects are owned by the input and output files
43 enum unfoldingAlgorithm { // type of unfolding alrogithm
44 kChi2, // chi^2 unfolding, implemented in AliUnfolding
45 kBayesian, // Bayesian unfolding, implemented in RooUnfold
46 kBayesianAli, // Bayesian unfolding, implemented in AliUnfolding
47 kSVD, // SVD unfolding, implemented in RooUnfold
48 kNone }; // no unfolding
49 enum prior { // prior that is used for unfolding
50 kPriorChi2, // prior from chi^2 method
51 kPriorMeasured, // use measured spectrum as prior
52 kPriorPythia }; // use pythia spectrum as prior
53 enum histoType { // histogram identifier, only used internally
54 kInPlaneSpectrum, // default style for spectrum
59 kBar, // default style for bar histogram
60 kRatio, // default style for ratio
61 kV2, // default style for v2
62 kEmpty }; // default style
63 // setters, interface to the class
64 void SetSaveFull(Bool_t b) {fSaveFull = b;}
65 void SetInputList(TList* list) {
67 fRefreshInput = kTRUE;
69 void SetOutputFileName(TString name) {fOutputFileName = name;}
70 void CreateOutputList(TString name) {
71 // create a new output list and add it to the full output
72 if(!fOutputFile) fOutputFile = new TFile(fOutputFileName.Data(), "RECREATE");
73 fOutputFile->cd(); // avoid nested dirs
74 if(name.EqualTo(fActiveString)) {
75 printf(Form(" > Warning, duplicate output list, renaming %s to %s_2 ! < \n", name.Data(), name.Data()));
79 fActiveDir = new TDirectoryFile(fActiveString.Data(), fActiveString.Data());
82 void SetCentralityBin(Int_t bin) {
83 // in case of one centraltiy
84 fCentralityArray = new TArrayI(1);
85 fCentralityArray->AddAt(bin, 0);
86 // for one centrality there's no need for weights
87 fCentralityWeights = new TArrayD(1);
88 fCentralityWeights->AddAt(1., 0);
90 void SetCentralityBin(TArrayI* bins) {
91 fCentralityArray = bins;
93 void SetCentralityWeight(TArrayD* weights) {
94 fCentralityWeights = weights;
95 if(!fCentralityArray) printf(" > Warning: centrality weights set, but bins are not defined! \n");
97 void SetDetectorResponse(TH2D* dr) {fDetectorResponse = dr;}
98 void SetJetFindingEfficiency(TH1D* e) {fJetFindingEff = e;}
99 void SetBinsTrue(TArrayD* bins) {fBinsTrue = bins;}
100 void SetBinsRec(TArrayD* bins) {fBinsRec = bins;}
101 void SetBinsTruePrior(TArrayD* bins) {fBinsTruePrior = bins;}
102 void SetBinsRecPrior(TArrayD* bins) {fBinsRecPrior = bins;}
103 void SetSVDReg(Int_t r) {fSVDRegIn = r; fSVDRegOut = r;}
104 void SetSVDReg(Int_t in, Int_t out) {fSVDRegIn = in; fSVDRegOut = out;}
105 void SetSVDToy(Bool_t b, Float_t r) {fSVDToy = b; fJetRadius = r;}
106 void SetBeta(Double_t b) {fBetaIn = b; fBetaOut = b;}
107 void SetBeta(Double_t i, Double_t o) {fBetaIn = i; fBetaOut = o;}
108 void SetBayesianIter(Int_t i) {fBayesianIterIn = i; fBayesianIterOut = i;}
109 void SetBayesianIter(Int_t i, Int_t o) {fBayesianIterIn = i; fBayesianIterOut = o;}
110 void SetBayesianSmooth(Float_t s) {fBayesianSmoothIn = s; fBayesianSmoothOut = s;}
111 void SetBayesianSmooth(Float_t i, Float_t o) {fBayesianSmoothIn = i; fBayesianSmoothOut = o;}
112 void SetAvoidRoundingError(Bool_t r) {fAvoidRoundingError = r;}
113 void SetUnfoldingAlgorithm(unfoldingAlgorithm ua) {fUnfoldingAlgorithm = ua;}
114 void SetPrior(prior p) {fPrior = p;}
115 void SetPrior(prior p, TH1D* spectrum) {fPrior = p; fPriorUser = spectrum;}
116 void SetNormalizeSpectra(Bool_t b) {fNormalizeSpectra = b;}
117 void SetNormalizeSpectra(Int_t e) { // use to normalize to this no of events
119 fNormalizeSpectra = kFALSE;
121 void SetSmoothenPrior(Bool_t b, Float_t min = 50., Float_t max = 100., Float_t start= 75., Bool_t counts = kTRUE) {
126 fSmoothenCounts = counts;
128 void SetTestMode(Bool_t t) {fTestMode = t;}
129 void SetEventPlaneResolution(Double_t r) {fEventPlaneRes = r;}
130 void SetUseDetectorResponse(Bool_t r) {fUseDetectorResponse = r;}
131 void SetUseDptResponse(Bool_t r) {fUseDptResponse = r;}
132 void SetTrainPowerFit(Bool_t t) {fTrainPower = t;}
133 void SetDphiUnfolding(Bool_t i) {fDphiUnfolding = i;}
134 void SetDphiDptUnfolding(Bool_t i) {fDphiDptUnfolding = i;}
135 void SetExLJDpt(Bool_t i) {fExLJDpt = i;}
136 void SetWeightFunction(TF1* w) {fResponseMaker->SetRMMergeWeightFunction(w);}
137 void SetRMS(Bool_t r) {fRMS = r;}
138 void SetSymmRMS(Bool_t r) {fSymmRMS = r; fRMS = r;}
140 void MakeAU(); // test function, use with caution (09012014)
143 if(fRMSSpectrumIn) fRMSSpectrumIn->Write();
144 if(fRMSSpectrumOut) fRMSSpectrumOut->Write();
145 if(fRMSRatio) fRMSRatio->Write();
146 fOutputFile->Close();}
150 Float_t rangeLow = 20,
151 Float_t rangeUp = 80,
152 TString in = "UnfoldedSpectra.root",
153 TString out = "ProcessedSpectra.root") const;
154 void GetNominalValues(
159 TString inFile = "UnfoldedSpectra.root",
160 TString outFile = "Nominal.root") const;
161 void GetCorrelatedUncertainty(
162 TGraphAsymmErrors*& corrRatio,
163 TGraphAsymmErrors*& corrV2,
164 TArrayI* variationsIn,
165 TArrayI* variationsOut,
167 TArrayI* variantions2ndIn,
168 TArrayI* variantions2ndOut,
173 Float_t rangeLow = 20,
174 Float_t rangeUp = 80,
176 TString in = "UnfoldedSpectra.root",
177 TString out = "CorrelatedUncertainty.root") const;
178 void GetShapeUncertainty(
179 TGraphAsymmErrors*& shapeRatio,
180 TGraphAsymmErrors*& shapeV2,
181 TArrayI* regularizationIn,
182 TArrayI* regularizationOut,
183 TArrayI* trueBinIn = 0x0,
184 TArrayI* trueBinOut = 0x0,
185 TArrayI* recBinIn = 0x0,
186 TArrayI* recBinOut = 0x0,
187 TArrayI* methodIn = 0x0,
188 TArrayI* methodOut = 0x0,
190 Float_t rangeLow = 20,
191 Float_t rangeUp = 80,
192 TString in = "UnfoldedSpectra.root",
193 TString out = "ShapeUncertainty.root") const;
195 TH2D* detectorResponse, // detector response matrix
196 TH1D* jetPtIn, // in plane jet spectrum
197 TH1D* jetPtOut, // out of plane jet spectrum
198 TH1D* dptIn, // in plane delta pt distribution
199 TH1D* dptOut, // out of plane delta pt distribution
200 Int_t eventCount = 0); // event count (optional)
201 // static const helper functions, mainly histogram manipulation
202 static TH1D* ResizeXaxisTH1D(TH1D* histo, Int_t low, Int_t up, TString suffix = "");
203 static TH2D* ResizeYaxisTH2D(TH2D* histo, TArrayD* x, TArrayD* y, TString suffix = "");
204 static TH2D* NormalizeTH2D(TH2D* histo, Bool_t noError = kTRUE);
205 static TH1D* RebinTH1D(TH1D* histo, TArrayD* bins, TString suffix = "", Bool_t kill = kTRUE);
206 TH2D* RebinTH2D(TH2D* histo, TArrayD* binsTrue, TArrayD* binsRec, TString suffix = "");
207 static TH2D* MatrixMultiplication(TH2D* a, TH2D* b, TString name = "CombinedResponse");
208 static TH1D* NormalizeTH1D(TH1D* histo, Double_t scale = 1.);
209 static TGraphErrors* GetRatio(TH1 *h1 = 0x0, TH1* h2 = 0x0, TString name = "", Bool_t appendFit = kFALSE, Int_t xmax = -1);
210 static TGraphErrors* GetV2(TH1* h1 = 0x0, TH1* h2 = 0x0, Double_t r = 0., TString name = "");
211 TGraphAsymmErrors* GetV2WithSystematicErrors(
212 TH1* h1, TH1* h2, Double_t r, TString name,
213 TH1* relativeErrorInUp,
214 TH1* relativeErrorInLow,
215 TH1* relativeErrorOutUp,
216 TH1* relativeErrorOutLow,
217 Float_t rho = 0.) const;
218 static void WriteObject(TObject* object, TString suffix = "", Bool_t kill = kTRUE);
219 static TH2D* ConstructDPtResponseFromTH1D(TH1D* dpt, Bool_t AvoidRoundingError);
220 static TH2D* GetUnityResponse(TArrayD* binsTrue, TArrayD* binsRec, TString suffix = "");
221 void SaveConfiguration(Bool_t convergedIn, Bool_t convergedOut) const;
222 static TMatrixD* CalculatePearsonCoefficients(TMatrixD* covmat);
223 static TH1D* SmoothenPrior(TH1D* spectrum, TF1* function, Double_t min, Double_t max, Double_t start, Bool_t kill = kTRUE, Bool_t counts = kTRUE);
225 void SetTitleFontSize(Double_t s) {fTitleFontSize = s;}
226 static void Style(Bool_t legacy = kFALSE);
227 static void Style(TCanvas* c, TString style = "PEARSON");
228 static void Style(TVirtualPad* c, TString style = "SPECTRUM", Bool_t legacy = kFALSE);
229 static void Style(TLegend* l);
230 static void Style(TH1* h, EColor col = kBlue, histoType = kEmpty, Bool_t legacy = kFALSE);
231 static void Style(TGraph* h, EColor col = kBlue, histoType = kEmpty, Bool_t legacy = kFALSE);
232 static TLegend* AddLegend(TVirtualPad* p, Bool_t style = kFALSE) {
233 if(!style) return p->BuildLegend(.565, .663, .882, .883);
235 TLegend* l = AddLegend(p, kFALSE);
240 static TPaveText* AddTPaveText(TString text, Int_t r = 2) {
241 TPaveText* t(new TPaveText(.35, .27, .76, .33,"NDC"));
244 t->AddText(0.,0.,text.Data());
245 t->AddText(0., 0., Form("#it{R} = 0.%i anti-#it{k} charged jets, |#eta_{jet}|<%.1f", r, .9-r/10.));
246 t->SetTextColor(kBlack);
251 static TPaveText* AddText(TString text, EColor col) {
252 TPaveText* t(new TPaveText(.35, .27, .76, .33,"NDC"));
255 t->AddText(0.,0.,text.Data());
256 t->SetTextColor(col);
261 static TLatex* AddLogo(Bool_t logo, Double_t xmin = .59, Double_t ymax = .81) {
262 return AddTLatex(xmin, ymax, logo ? "ALICE Preliminary" : "ALICE");
264 static TLatex* AddSystem() {
265 return AddTLatex(0.55, 87, "Pb-Pb #sqrt{#it{s}}}_{NN} = 2.76 TeV");
267 static TLatex* AddTLatex(Double_t xmin, Double_t ymax, TString string) {
268 TLatex* tex = new TLatex(xmin, ymax, string.Data());
270 tex->SetTextFont(42);
275 static void SavePadToPDF(TVirtualPad* pad) {pad->SaveAs(Form("%s.pdf", pad->GetName()));}
276 // interface to AliUnfolding, not necessary but nice to have all parameters in one place
277 static void SetMinuitStepSize(Float_t s) {AliUnfolding::SetMinuitStepSize(s);}
278 static void SetMinuitPrecision(Float_t s) {AliUnfolding::SetMinuitPrecision(s);}
279 static void SetMinuitPrecision(Int_t i) {AliUnfolding::SetMinuitMaxIterations(i);}
280 static void SetMinuitStrategy(Double_t s) {AliUnfolding::SetMinuitStrategy(s);}
281 static void SetDebug(Int_t d) {AliUnfolding::SetDebug(d);}
283 Bool_t PrepareForUnfolding();
284 Bool_t PrepareForUnfolding(Int_t low, Int_t up);
285 TH1D* GetPrior( const TH1D* measuredJetSpectrum,
286 const TH2D* resizedResponse,
287 const TH1D* kinematicEfficiency,
288 const TH1D* measuredJetSpectrumTrueBins,
289 const TString suffix,
290 const TH1D* jetFindingEfficiency);
291 TH1D* UnfoldWrapper( const TH1D* measuredJetSpectrum,
292 const TH2D* resizedResponse,
293 const TH1D* kinematicEfficiency,
294 const TH1D* measuredJetSpectrumTrueBins,
295 const TString suffix,
296 const TH1D* jetFindingEfficiency = 0x0);
297 TH1D* UnfoldSpectrumChi2( const TH1D* measuredJetSpectrum,
298 const TH2D* resizedResponse,
299 const TH1D* kinematicEfficiency,
300 const TH1D* measuredJetSpectrumTrueBins,
301 const TString suffix,
302 const TH1D* jetFindingEfficiency = 0x0);
303 TH1D* UnfoldSpectrumSVD( const TH1D* measuredJetSpectrum,
304 const TH2D* resizedResponse,
305 const TH1D* kinematicEfficiency,
306 const TH1D* measuredJetSpectrumTrueBins,
307 const TString suffix,
308 const TH1D* jetFindingEfficiency = 0x0);
309 TH1D* UnfoldSpectrumBayesianAli( const TH1D* measuredJetSpectrum,
310 const TH2D* resizedResponse,
311 const TH1D* kinematicEfficiency,
312 const TH1D* measuredJetSpectrumTrueBins,
313 const TString suffix,
314 const TH1D* jetFindingEfficiency = 0x0);
315 TH1D* UnfoldSpectrumBayesian( const TH1D* measuredJetSpectrum,
316 const TH2D* resizedResponse,
317 const TH1D* kinematicEfficiency,
318 const TH1D* measuredJetSpectrumTrueBins,
319 const TString suffix,
320 const TH1D* jetFindingEfficiency = 0x0);
321 void DoIntermediateSystematics(
322 TArrayI* variationsIn,
323 TArrayI* variationsOut,
324 TH1D*& relativeErrorInUp,
325 TH1D*& relativeErrorInLow,
326 TH1D*& relativeErrorOutUp,
327 TH1D*& relativeErrorOutLow,
328 TH1D*& relativeSystematicIn,
329 TH1D*& relativeSystematicOut,
338 Bool_t RMS = kFALSE) const;
339 static void ResetAliUnfolding();
340 // give object a unique name via the 'protect heap' functions.
341 // may seem redundant, but some internal functions of root (e.g.
342 // ProjectionY()) check for existing objects by name and re-use them
343 TH1D* ProtectHeap(TH1D* protect, Bool_t kill = kTRUE, TString suffix = "") const;
344 TH2D* ProtectHeap(TH2D* protect, Bool_t kill = kTRUE, TString suffix = "") const;
345 TGraphErrors* ProtectHeap(TGraphErrors* protect, Bool_t kill = kTRUE, TString suffix = "") const;
346 // members, accessible via setters
347 AliAnaChargedJetResponseMaker* fResponseMaker; // utility object
348 Bool_t fRMS; // systematic method
349 Bool_t fSymmRMS; // symmetric systematic method
350 TF1* fPower; // smoothening fit
351 Bool_t fSaveFull; // save all generated histograms to file
352 TString fActiveString; // identifier of active output
353 TDirectoryFile* fActiveDir; // active directory
354 TList* fInputList; // input list
355 Bool_t fRefreshInput; // re-read the input (called automatically if input list changes)
356 TString fOutputFileName; // output file name
357 TFile* fOutputFile; // output file
358 TArrayI* fCentralityArray; // array of bins that are merged
359 TArrayD* fCentralityWeights; // array of centrality weights
360 TH2D* fDetectorResponse; // detector response
361 TH1D* fJetFindingEff; // jet finding efficiency
362 Double_t fBetaIn; // regularization strength, in plane unfolding
363 Double_t fBetaOut; // regularization strength, out of plane unfoldign
364 Int_t fBayesianIterIn; // bayesian regularization parameter, in plane unfolding
365 Int_t fBayesianIterOut; // bayesian regularization parameter, out plane unfolding
366 Float_t fBayesianSmoothIn; // bayesian smoothening parameter (AliUnfolding)
367 Float_t fBayesianSmoothOut; // bayesian smoothening parameter (AliUnfolding)
368 Bool_t fAvoidRoundingError; // set dpt to zero for small values far from the diagonal
369 unfoldingAlgorithm fUnfoldingAlgorithm; // algorithm used for unfolding
370 prior fPrior; // prior for unfolding
371 TH1D* fPriorUser; // user supplied prior (e.g. pythia spectrum)
372 TArrayD* fBinsTrue; // pt true bins
373 TArrayD* fBinsRec; // pt rec bins
374 TArrayD* fBinsTruePrior; // holds true bins for the chi2 prior for SVD. setting this is optional
375 TArrayD* fBinsRecPrior; // holds rec bins for the chi2 prior for SVD. setting this is optional
376 Int_t fSVDRegIn; // svd regularization (a good starting point is half of the number of bins)
377 Int_t fSVDRegOut; // svd regularization out of plane
378 Bool_t fSVDToy; // use toy to estimate coveriance matrix for SVD method
379 Float_t fJetRadius; // jet radius (for SVD toy)
380 Int_t fEventCount; // number of events
381 Bool_t fNormalizeSpectra; // normalize spectra to event count
382 Bool_t fSmoothenPrior; // smoothen the tail of the measured spectrum using a powerlaw fit
383 Float_t fFitMin; // lower bound of smoothening fit
384 Float_t fFitMax; // upper bound of smoothening fit
385 Float_t fFitStart; // from this value, use smoothening
386 Bool_t fSmoothenCounts; // fill smoothened spectrum with counts
387 Bool_t fTestMode; // unfold with unity response for testing
388 Bool_t fRawInputProvided; // input histograms provided, not read from file
389 Double_t fEventPlaneRes; // event plane resolution for current centrality
390 Bool_t fUseDetectorResponse; // add detector response to unfolding
391 Bool_t fUseDptResponse; // add dpt response to unfolding
392 Bool_t fTrainPower; // don't clear the params of fPower for call to Make
393 // might give more stable results, but possibly introduces
394 // a bias / dependency on previous iterations
395 Bool_t fDphiUnfolding; // do the unfolding in in and out of plane orientation
396 Bool_t fDphiDptUnfolding; // do the unfolding in dphi and dpt bins (to fit v2)
397 Bool_t fExLJDpt; // exclude randon cones with leading jet
398 Double_t fTitleFontSize; // title font size
399 // members, set internally
400 TProfile* fRMSSpectrumIn; // rms of in plane spectra of converged unfoldings
401 TProfile* fRMSSpectrumOut; // rms of out of plane spectra of converged unfoldings
402 TProfile* fRMSRatio; // rms of ratio of converged unfolded spectra
403 TProfile* fRMSV2; // rms of v2 of converged unfolded spectra
404 TH2D* fDeltaPtDeltaPhi; // delta pt delta phi distribution
405 TH2D* fJetPtDeltaPhi; // jet pt delta phi distribution
406 TH1D* fSpectrumIn; // in plane jet pt spectrum
407 TH1D* fSpectrumOut; // out of plane jet pt spectrum
408 TH1D* fDptInDist; // in plane dpt distribution
409 TH1D* fDptOutDist; // out of plane dpt distribution
410 TH2D* fDptIn; // in plane dpt matrix
411 TH2D* fDptOut; // out plane dpt matrix
412 TH2D* fFullResponseIn; // full response matrix, in plane
413 TH2D* fFullResponseOut; // full response matrix, out of plane
414 // copy and assignment
415 AliJetFlowTools(const AliJetFlowTools&); // not implemented
416 AliJetFlowTools& operator=(const AliJetFlowTools&); // not implemented
419 //_____________________________________________________________________________