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"
33 //_____________________________________________________________________________
34 class AliJetFlowTools {
38 ~AliJetFlowTools(); // not implemented (deliberately). object ownership is a bit messy in this class
39 // since most (or all) of the objects are owned by the input and output files
42 enum unfoldingAlgorithm { // type of unfolding alrogithm
43 kChi2, // chi^2 unfolding, implemented in AliUnfolding
44 kBayesian, // Bayesian unfolding, implemented in RooUnfold
45 kBayesianAli, // Bayesian unfolding, implemented in AliUnfolding
46 kSVD, // SVD unfolding, implemented in RooUnfold
47 kNone }; // no unfolding
48 enum prior { // prior that is used for unfolding
49 kPriorChi2, // prior from chi^2 method
50 kPriorMeasured, // use measured spectrum as prior
51 kPriorPythia }; // use pythia spectrum as prior
52 enum histoType { // histogram identifier, only used internally
53 kInPlaneSpectrum, // default style for spectrum
58 kBar, // default style for bar histogram
59 kRatio, // default style for ratio
60 kV2, // default style for v2
61 kEmpty }; // default style
62 // setters, interface to the class
63 void SetSaveFull(Bool_t b) {fSaveFull = b;}
64 void SetInputList(TList* list) {
66 fRefreshInput = kTRUE;
68 void SetOutputFileName(TString name) {fOutputFileName = name;}
69 void CreateOutputList(TString name) {
70 // create a new output list and add it to the full output
71 if(!fOutputFile) fOutputFile = new TFile(fOutputFileName.Data(), "RECREATE");
72 fOutputFile->cd(); // avoid nested dirs
73 if(name.EqualTo(fActiveString)) {
74 printf(Form(" > Warning, duplicate output list, renaming %s to %s_2 ! < \n", name.Data(), name.Data()));
78 fActiveDir = new TDirectoryFile(fActiveString.Data(), fActiveString.Data());
81 void SetCentralityBin(Int_t bin) {fCentralityBin = bin;}
82 void SetDetectorResponse(TH2D* dr) {fDetectorResponse = dr;}
83 void SetJetFindingEfficiency(TH1D* e) {fJetFindingEff = e;}
84 void SetBinsTrue(TArrayD* bins) {fBinsTrue = bins;}
85 void SetBinsRec(TArrayD* bins) {fBinsRec = bins;}
86 void SetBinsTruePrior(TArrayD* bins) {fBinsTruePrior = bins;}
87 void SetBinsRecPrior(TArrayD* bins) {fBinsRecPrior = bins;}
88 void SetSVDReg(Int_t r) {fSVDRegIn = r; fSVDRegOut = r;}
89 void SetSVDReg(Int_t in, Int_t out) {fSVDRegIn = in; fSVDRegOut = out;}
90 void SetSVDToy(Bool_t b, Float_t r) {fSVDToy = b; fJetRadius = r;}
91 void SetBeta(Double_t b) {fBetaIn = b; fBetaOut = b;}
92 void SetBeta(Double_t i, Double_t o) {fBetaIn = i; fBetaOut = o;}
93 void SetBayesianIter(Int_t i) {fBayesianIterIn = i; fBayesianIterOut = i;}
94 void SetBayesianIter(Int_t i, Int_t o) {fBayesianIterIn = i; fBayesianIterOut = o;}
95 void SetBayesianSmooth(Float_t s) {fBayesianSmoothIn = s; fBayesianSmoothOut = s;}
96 void SetBayesianSmooth(Float_t i, Float_t o) {fBayesianSmoothIn = i; fBayesianSmoothOut = o;}
97 void SetAvoidRoundingError(Bool_t r) {fAvoidRoundingError = r;}
98 void SetUnfoldingAlgorithm(unfoldingAlgorithm ua) {fUnfoldingAlgorithm = ua;}
99 void SetPrior(prior p) {fPrior = p;}
100 void SetPrior(prior p, TH1D* spectrum) {fPrior = p; fPriorUser = spectrum;}
101 void SetNormalizeSpectra(Bool_t b) {fNormalizeSpectra = b;}
102 void SetNormalizeSpectra(Int_t e) { // use to normalize to this no of events
104 fNormalizeSpectra = kFALSE;
106 void SetSmoothenPrior(Bool_t b, Float_t min = 50., Float_t max = 100., Float_t start= 75., Bool_t counts = kTRUE) {
111 fSmoothenCounts = counts;
113 void SetTestMode(Bool_t t) {fTestMode = t;}
114 void SetEventPlaneResolution(Double_t r) {fEventPlaneRes = r;}
115 void SetUseDetectorResponse(Bool_t r) {fUseDetectorResponse = r;}
116 void SetUseDptResponse(Bool_t r) {fUseDptResponse = r;}
117 void SetTrainPowerFit(Bool_t t) {fTrainPower = t;}
118 void SetDphiUnfolding(Bool_t i) {fDphiUnfolding = i;}
119 void SetDphiDptUnfolding(Bool_t i) {fDphiDptUnfolding = i;}
120 void SetExLJDpt(Bool_t i) {fExLJDpt = i;}
121 void SetWeightFunction(TF1* w) {fResponseMaker->SetRMMergeWeightFunction(w);}
123 void MakeAU(); // test function, use with caution (09012014)
126 if(fRMSSpectrumIn) fRMSSpectrumIn->Write();
127 if(fRMSSpectrumOut) fRMSSpectrumOut->Write();
128 if(fRMSRatio) fRMSRatio->Write();
129 fOutputFile->Close();}
133 Float_t rangeLow = 20,
134 Float_t rangeUp = 80,
135 TString in = "UnfoldedSpectra.root",
136 TString out = "ProcessedSpectra.root") const;
137 void GetNominalValues(
142 TString inFile = "UnfoldedSpectra.root",
143 TString outFile = "Nominal.root") const;
144 void GetCorrelatedUncertainty(
145 TGraphAsymmErrors*& corrRatio,
146 TGraphAsymmErrors*& corrV2,
147 TArrayI* variationsIn,
148 TArrayI* variationsOut,
151 Float_t rangeLow = 20,
152 Float_t rangeUp = 80,
153 TString in = "UnfoldedSpectra.root",
154 TString out = "CorrelatedUncertainty.root") const;
155 void GetShapeUncertainty(
156 TGraphAsymmErrors*& shapeRatio,
157 TGraphAsymmErrors*& shapeV2,
158 TArrayI* regularizationIn,
159 TArrayI* regularizationOut,
160 TArrayI* trueBinIn = 0x0,
161 TArrayI* trueBinOut = 0x0,
162 TArrayI* recBinIn = 0x0,
163 TArrayI* recBinOut = 0x0,
165 Float_t rangeLow = 20,
166 Float_t rangeUp = 80,
167 TString in = "UnfoldedSpectra.root",
168 TString out = "ShapeUncertainty.root") const;
170 TH2D* detectorResponse, // detector response matrix
171 TH1D* jetPtIn, // in plane jet spectrum
172 TH1D* jetPtOut, // out of plane jet spectrum
173 TH1D* dptIn, // in plane delta pt distribution
174 TH1D* dptOut, // out of plane delta pt distribution
175 Int_t eventCount = 0); // event count (optional)
176 // static const helper functions, mainly histogram manipulation
177 static TH1D* ResizeXaxisTH1D(TH1D* histo, Int_t low, Int_t up, TString suffix = "");
178 static TH2D* ResizeYaxisTH2D(TH2D* histo, TArrayD* x, TArrayD* y, TString suffix = "");
179 static TH2D* NormalizeTH2D(TH2D* histo, Bool_t noError = kTRUE);
180 static TH1D* RebinTH1D(TH1D* histo, TArrayD* bins, TString suffix = "", Bool_t kill = kTRUE);
181 TH2D* RebinTH2D(TH2D* histo, TArrayD* binsTrue, TArrayD* binsRec, TString suffix = "");
182 static TH2D* MatrixMultiplication(TH2D* a, TH2D* b, TString name = "CombinedResponse");
183 static TH1D* NormalizeTH1D(TH1D* histo, Double_t scale = 1.);
184 static TGraphErrors* GetRatio(TH1 *h1 = 0x0, TH1* h2 = 0x0, TString name = "", Bool_t appendFit = kFALSE, Int_t xmax = -1);
185 static TGraphErrors* GetV2(TH1* h1 = 0x0, TH1* h2 = 0x0, Double_t r = .7, TString name = "");
186 TGraphAsymmErrors* GetV2WithSystematicErrors(
187 TH1* h1, TH1* h2, Double_t r, TString name,
188 TH1* relativeErrorInUp,
189 TH1* relativeErrorInLow,
190 TH1* relativeErrorOutUp,
191 TH1* relativeErrorOutLow) const;
192 static void WriteObject(TObject* object, TString suffix = "", Bool_t kill = kTRUE);
193 static TH2D* ConstructDPtResponseFromTH1D(TH1D* dpt, Bool_t AvoidRoundingError);
194 static TH2D* GetUnityResponse(TArrayD* binsTrue, TArrayD* binsRec, TString suffix = "");
195 void SaveConfiguration(Bool_t convergedIn, Bool_t convergedOut) const;
196 static TMatrixD* CalculatePearsonCoefficients(TMatrixD* covmat);
197 static TH1D* SmoothenPrior(TH1D* spectrum, TF1* function, Double_t min, Double_t max, Double_t start, Bool_t kill = kTRUE, Bool_t counts = kTRUE);
199 void SetTitleFontSize(Double_t s) {fTitleFontSize = s;}
201 static void Style(TCanvas* c, TString style = "PEARSON");
202 static void Style(TVirtualPad* c, TString style = "SPECTRUM");
203 static void Style(TLegend* l);
204 static void Style(TH1* h, EColor col = kBlue, histoType = kEmpty);
205 static void Style(TGraph* h, EColor col = kBlue, histoType = kEmpty);
206 static TLegend* AddLegend(TVirtualPad* p, Bool_t style = kFALSE) {
207 if(!style) return p->BuildLegend(.565, .663, .882, .883);
209 TLegend* l = AddLegend(p, kFALSE);
214 static TPaveText* AddTPaveText(TString text) {
215 TPaveText* t(new TPaveText(.35, .27, .76, .33,"NDC"));
216 // t->SetFillStyle(0);
219 t->AddText(0.,0.,text.Data());
220 t->AddText(0., 0., "#it{R} = 0.2 #it{k}_{T} charged jets");
221 t->SetTextColor(kBlack);
222 // t->SetTextSize(0.03);
227 static void SavePadToPDF(TVirtualPad* pad) {pad->SaveAs(Form("%s.pdf", pad->GetName()));}
228 // interface to AliUnfolding, not necessary but nice to have all parameters in one place
229 static void SetMinuitStepSize(Float_t s) {AliUnfolding::SetMinuitStepSize(s);}
230 static void SetMinuitPrecision(Float_t s) {AliUnfolding::SetMinuitPrecision(s);}
231 static void SetMinuitPrecision(Int_t i) {AliUnfolding::SetMinuitMaxIterations(i);}
232 static void SetMinuitStrategy(Double_t s) {AliUnfolding::SetMinuitStrategy(s);}
233 static void SetDebug(Int_t d) {AliUnfolding::SetDebug(d);}
235 Bool_t PrepareForUnfolding();
236 Bool_t PrepareForUnfolding(Int_t low, Int_t up);
237 TH1D* GetPrior( const TH1D* measuredJetSpectrum,
238 const TH2D* resizedResponse,
239 const TH1D* kinematicEfficiency,
240 const TH1D* measuredJetSpectrumTrueBins,
241 const TString suffix,
242 const TH1D* jetFindingEfficiency);
243 TH1D* UnfoldWrapper( const TH1D* measuredJetSpectrum,
244 const TH2D* resizedResponse,
245 const TH1D* kinematicEfficiency,
246 const TH1D* measuredJetSpectrumTrueBins,
247 const TString suffix,
248 const TH1D* jetFindingEfficiency = 0x0);
249 TH1D* UnfoldSpectrumChi2( const TH1D* measuredJetSpectrum,
250 const TH2D* resizedResponse,
251 const TH1D* kinematicEfficiency,
252 const TH1D* measuredJetSpectrumTrueBins,
253 const TString suffix,
254 const TH1D* jetFindingEfficiency = 0x0);
255 TH1D* UnfoldSpectrumSVD( const TH1D* measuredJetSpectrum,
256 const TH2D* resizedResponse,
257 const TH1D* kinematicEfficiency,
258 const TH1D* measuredJetSpectrumTrueBins,
259 const TString suffix,
260 const TH1D* jetFindingEfficiency = 0x0);
261 TH1D* UnfoldSpectrumBayesianAli( const TH1D* measuredJetSpectrum,
262 const TH2D* resizedResponse,
263 const TH1D* kinematicEfficiency,
264 const TH1D* measuredJetSpectrumTrueBins,
265 const TString suffix,
266 const TH1D* jetFindingEfficiency = 0x0);
267 TH1D* UnfoldSpectrumBayesian( const TH1D* measuredJetSpectrum,
268 const TH2D* resizedResponse,
269 const TH1D* kinematicEfficiency,
270 const TH1D* measuredJetSpectrumTrueBins,
271 const TString suffix,
272 const TH1D* jetFindingEfficiency = 0x0);
273 void DoIntermediateSystematics(
274 TArrayI* variationsIn,
275 TArrayI* variationsOut,
276 TH1D*& relativeErrorInUp,
277 TH1D*& relativeErrorInLow,
278 TH1D*& relativeErrorOutUp,
279 TH1D*& relativeErrorOutLow,
280 TH1D*& relativeSystematicIn,
281 TH1D*& relativeSystematicOut,
289 TString source = "") const;
290 static void ResetAliUnfolding();
291 // give object a unique name via the 'protect heap' functions.
292 // may seem redundant, but some internal functions of root (e.g.
293 // ProjectionY()) check for existing objects by name and re-use them
294 TH1D* ProtectHeap(TH1D* protect, Bool_t kill = kTRUE, TString suffix = "") const;
295 TH2D* ProtectHeap(TH2D* protect, Bool_t kill = kTRUE, TString suffix = "") const;
296 TGraphErrors* ProtectHeap(TGraphErrors* protect, Bool_t kill = kTRUE, TString suffix = "") const;
297 // members, accessible via setters
298 AliAnaChargedJetResponseMaker* fResponseMaker; // utility object
299 TF1* fPower; // smoothening fit
300 Bool_t fSaveFull; // save all generated histograms to file
301 TString fActiveString; // identifier of active output
302 TDirectoryFile* fActiveDir; // active directory
303 TList* fInputList; // input list
304 Bool_t fRefreshInput; // re-read the input (called automatically if input list changes)
305 TString fOutputFileName; // output file name
306 TFile* fOutputFile; // output file
307 Int_t fCentralityBin; // centrality bin
308 TH2D* fDetectorResponse; // detector response
309 TH1D* fJetFindingEff; // jet finding efficiency
310 Double_t fBetaIn; // regularization strength, in plane unfolding
311 Double_t fBetaOut; // regularization strength, out of plane unfoldign
312 Int_t fBayesianIterIn; // bayesian regularization parameter, in plane unfolding
313 Int_t fBayesianIterOut; // bayesian regularization parameter, out plane unfolding
314 Float_t fBayesianSmoothIn; // bayesian smoothening parameter (AliUnfolding)
315 Float_t fBayesianSmoothOut; // bayesian smoothening parameter (AliUnfolding)
316 Bool_t fAvoidRoundingError; // set dpt to zero for small values far from the diagonal
317 unfoldingAlgorithm fUnfoldingAlgorithm; // algorithm used for unfolding
318 prior fPrior; // prior for unfolding
319 TH1D* fPriorUser; // user supplied prior (e.g. pythia spectrum)
320 TArrayD* fBinsTrue; // pt true bins
321 TArrayD* fBinsRec; // pt rec bins
322 TArrayD* fBinsTruePrior; // holds true bins for the chi2 prior for SVD. setting this is optional
323 TArrayD* fBinsRecPrior; // holds rec bins for the chi2 prior for SVD. setting this is optional
324 Int_t fSVDRegIn; // svd regularization (a good starting point is half of the number of bins)
325 Int_t fSVDRegOut; // svd regularization out of plane
326 Bool_t fSVDToy; // use toy to estimate coveriance matrix for SVD method
327 Float_t fJetRadius; // jet radius (for SVD toy)
328 Int_t fEventCount; // number of events
329 Bool_t fNormalizeSpectra; // normalize spectra to event count
330 Bool_t fSmoothenPrior; // smoothen the tail of the measured spectrum using a powerlaw fit
331 Float_t fFitMin; // lower bound of smoothening fit
332 Float_t fFitMax; // upper bound of smoothening fit
333 Float_t fFitStart; // from this value, use smoothening
334 Bool_t fSmoothenCounts; // fill smoothened spectrum with counts
335 Bool_t fTestMode; // unfold with unity response for testing
336 Bool_t fRawInputProvided; // input histograms provided, not read from file
337 Double_t fEventPlaneRes; // event plane resolution for current centrality
338 Bool_t fUseDetectorResponse; // add detector response to unfolding
339 Bool_t fUseDptResponse; // add dpt response to unfolding
340 Bool_t fTrainPower; // don't clear the params of fPower for call to Make
341 // might give more stable results, but possibly introduces
342 // a bias / dependency on previous iterations
343 Bool_t fDphiUnfolding; // do the unfolding in in and out of plane orientation
344 Bool_t fDphiDptUnfolding; // do the unfolding in dphi and dpt bins (to fit v2)
345 Bool_t fExLJDpt; // exclude randon cones with leading jet
346 Double_t fTitleFontSize; // title font size
347 // members, set internally
348 TProfile* fRMSSpectrumIn; // rms of in plane spectra of converged unfoldings
349 TProfile* fRMSSpectrumOut; // rms of out of plane spectra of converged unfoldings
350 TProfile* fRMSRatio; // rms of ratio of converged unfolded spectra
351 TProfile* fRMSV2; // rms of v2 of converged unfolded spectra
352 TH2D* fDeltaPtDeltaPhi; // delta pt delta phi distribution
353 TH2D* fJetPtDeltaPhi; // jet pt delta phi distribution
354 TH1D* fSpectrumIn; // in plane jet pt spectrum
355 TH1D* fSpectrumOut; // out of plane jet pt spectrum
356 TH1D* fDptInDist; // in plane dpt distribution
357 TH1D* fDptOutDist; // out of plane dpt distribution
358 TH2D* fDptIn; // in plane dpt matrix
359 TH2D* fDptOut; // out plane dpt matrix
360 TH2D* fFullResponseIn; // full response matrix, in plane
361 TH2D* fFullResponseOut; // full response matrix, out of plane
362 // copy and assignment
363 AliJetFlowTools(const AliJetFlowTools&); // not implemented
364 AliJetFlowTools& operator=(const AliJetFlowTools&); // not implemented
367 //_____________________________________________________________________________