]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/FLOW/Tasks/AliJetFlowTools.cxx
prepare the jet flow mc task to run the thermal model
[u/mrichter/AliRoot.git] / PWG / FLOW / Tasks / AliJetFlowTools.cxx
CommitLineData
dc1455ee 1/*************************************************************************
2 * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// Author: Redmer Alexander Bertens, Utrecht University, Utrecht, Netherlands
17// (rbertens@cern.ch, rbertens@nikhef.nl, r.a.bertens@uu.nl)
53547ff2 18//
dc1455ee 19// Tools class for Jet Flow Analysis, replaces 'extractJetFlow.C' macro
4292ca60 20//
21// The task uses input from two analysis tasks:
22// - $ALICE_ROOT/PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskRhoVnModulation.cxx
23// used to retrieve jet spectra and delta pt distributions
24// - $ALICE_ROOT/PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskJetMatching.cxx
25// used to construct the detector response function
26// and unfolds jet spectra with respect to the event plane. The user can choose
27// different alrogithms for unfolding which are available in (ali)root. RooUnfold
5e11c41c 28// libraries must be present on the system
29// ( see http://hepunx.rl.ac.uk/~adye/software/unfold/RooUnfold.html ).
4292ca60 30//
31// The weak spot of this class is the function PrepareForUnfolding, which will read
32// output from two output files and expects histograms with certain names and binning.
33// Unfolding methods itself are general and should be able to handle any input, therefore one
34// can forgo the PrepareForUnfolding method, and supply necessary input information via the
35// SetRawInput() method
36//
37// to see an example of how to use this class, see $ALICE_ROOT/PWGCF/FLOW/macros/jetFlowTools.C
dc1455ee 38
39// root includes
40#include "TF1.h"
41#include "TH1D.h"
42#include "TH2D.h"
53547ff2 43#include "TGraph.h"
4292ca60 44#include "TGraphErrors.h"
a39e4b2b 45#include "TGraphAsymmErrors.h"
18698978 46#include "TLine.h"
d7ec324f 47#include "TCanvas.h"
48#include "TLegend.h"
dc1455ee 49#include "TArrayD.h"
50#include "TList.h"
51#include "TMinuit.h"
52#include "TVirtualFitter.h"
53#include "TLegend.h"
54#include "TCanvas.h"
55#include "TStyle.h"
dc1455ee 56#include "TLine.h"
ad04a83c 57#include "TMath.h"
4292ca60 58#include "TVirtualFitter.h"
ef12d5a5 59#include "TFitResultPtr.h"
4292ca60 60// aliroot includes
dc1455ee 61#include "AliUnfolding.h"
62#include "AliAnaChargedJetResponseMaker.h"
4292ca60 63// class includes
dc1455ee 64#include "AliJetFlowTools.h"
51e6bc5a 65// roo unfold includes (make sure you have these available on your system)
66#include "RooUnfold.h"
67#include "RooUnfoldResponse.h"
68#include "RooUnfoldSvd.h"
549b5f40 69#include "RooUnfoldBayes.h"
51e6bc5a 70#include "TSVDUnfold.h"
dc1455ee 71
72using namespace std;
dc1455ee 73//_____________________________________________________________________________
74AliJetFlowTools::AliJetFlowTools() :
4292ca60 75 fResponseMaker (new AliAnaChargedJetResponseMaker()),
3e698d27 76 fRMS (kTRUE),
77 fSymmRMS (kTRUE),
ef12d5a5 78 fPower (new TF1("fPower","[0]*TMath::Power(x,-([1]))",0.,300.)),
9f892925 79 fSaveFull (kTRUE),
dc1455ee 80 fActiveString (""),
ad04a83c 81 fActiveDir (0x0),
dc1455ee 82 fInputList (0x0),
4292ca60 83 fRefreshInput (kTRUE),
dc1455ee 84 fOutputFileName ("UnfoldedSpectra.root"),
ad04a83c 85 fOutputFile (0x0),
67d11165 86 fCentralityArray (0x0),
c03f7598 87 fCentralityWeights (0x0),
dc1455ee 88 fDetectorResponse (0x0),
53547ff2 89 fJetFindingEff (0x0),
4292ca60 90 fBetaIn (.1),
91 fBetaOut (.1),
549b5f40
RAB
92 fBayesianIterIn (4),
93 fBayesianIterOut (4),
94 fBayesianSmoothIn (0.),
95 fBayesianSmoothOut (0.),
ef12d5a5 96 fAvoidRoundingError (kFALSE),
51e6bc5a 97 fUnfoldingAlgorithm (kChi2),
98 fPrior (kPriorMeasured),
18698978 99 fPriorUser (0x0),
dc1455ee 100 fBinsTrue (0x0),
101 fBinsRec (0x0),
ef12d5a5 102 fBinsTruePrior (0x0),
103 fBinsRecPrior (0x0),
4292ca60 104 fSVDRegIn (5),
105 fSVDRegOut (5),
51e6bc5a 106 fSVDToy (kTRUE),
107 fJetRadius (0.3),
20abfcc4 108 fEventCount (-1),
549b5f40
RAB
109 fNormalizeSpectra (kFALSE),
110 fSmoothenPrior (kFALSE),
4292ca60 111 fFitMin (60.),
549b5f40 112 fFitMax (300.),
4292ca60 113 fFitStart (75.),
549b5f40 114 fSmoothenCounts (kTRUE),
ef12d5a5 115 fTestMode (kFALSE),
4292ca60 116 fRawInputProvided (kFALSE),
ef12d5a5 117 fEventPlaneRes (.63),
118 fUseDetectorResponse(kTRUE),
549b5f40 119 fUseDptResponse (kTRUE),
ef12d5a5 120 fTrainPower (kTRUE),
486fb24e 121 fDphiUnfolding (kTRUE),
122 fDphiDptUnfolding (kFALSE),
123 fExLJDpt (kTRUE),
18698978 124 fTitleFontSize (-999.),
4292ca60 125 fRMSSpectrumIn (0x0),
126 fRMSSpectrumOut (0x0),
127 fRMSRatio (0x0),
ef12d5a5 128 fRMSV2 (0x0),
ad04a83c 129 fDeltaPtDeltaPhi (0x0),
130 fJetPtDeltaPhi (0x0),
dc1455ee 131 fSpectrumIn (0x0),
132 fSpectrumOut (0x0),
133 fDptInDist (0x0),
134 fDptOutDist (0x0),
135 fDptIn (0x0),
136 fDptOut (0x0),
137 fFullResponseIn (0x0),
549b5f40 138 fFullResponseOut (0x0) { // class constructor
486fb24e 139 // create response maker weight function (tuned to PYTHIA spectrum)
140 fResponseMaker->SetRMMergeWeightFunction(new TF1("weightFunction", "x*TMath::Power(1.+(1./(8.*0.9))*x, -8.)", 0, 200));
141 for(Int_t i(0); i < fPower->GetNpar(); i++) fPower->SetParameter(i, 0.);
4292ca60 142}
dc1455ee 143//_____________________________________________________________________________
144void AliJetFlowTools::Make() {
ad04a83c 145 // core function of the class
486fb24e 146 if(fDphiDptUnfolding) {
147 // to extract the yield as function of Dphi, Dpt - experimental
148 MakeAU();
149 return;
150 }
4292ca60 151 // 1) rebin the raw output of the jet task to the desired binnings
ad04a83c 152 // 2) calls the unfolding routine
153 // 3) writes output to file
4292ca60 154 // can be repeated multiple times with different configurations
155
ad04a83c 156 // 1) manipulation of input histograms
dc1455ee 157 // check if the input variables are present
4292ca60 158 if(fRefreshInput) {
159 if(!PrepareForUnfolding()) {
160 printf(" AliJetFlowTools::Make() Fatal error \n - couldn't prepare for unfolding ! \n");
161 return;
162 }
dc1455ee 163 }
4292ca60 164 // 1a) resize the jet spectrum according to the binning scheme in fBinsTrue
165 // parts of the spectrum can end up in over or underflow bins
549b5f40 166 TH1D* measuredJetSpectrumIn = RebinTH1D(fSpectrumIn, fBinsRec, TString("resized_in_"), kFALSE);
f3ba6c8e 167 TH1D* measuredJetSpectrumOut = RebinTH1D(fSpectrumOut, fBinsRec, TString("resized_out_"), kFALSE);
168
549b5f40 169 // 1b) resize the jet spectrum to 'true' bins. can serve as a prior and as a template for unfolding
4292ca60 170 // the template will be used as a prior for the chi2 unfolding
549b5f40
RAB
171 TH1D* measuredJetSpectrumTrueBinsIn = RebinTH1D(fSpectrumIn, fBinsTrue, TString("in"), kFALSE);
172 TH1D* measuredJetSpectrumTrueBinsOut = RebinTH1D(fSpectrumOut, fBinsTrue, TString("out"), kFALSE);
4292ca60 173 // get the full response matrix from the dpt and the detector response
dc1455ee 174 fDetectorResponse = NormalizeTH2D(fDetectorResponse);
ef12d5a5 175 // get the full response matrix. if test mode is chosen, the full response is replace by a unity matrix
176 // so that unfolding should return the initial spectrum
177 if(!fTestMode) {
549b5f40
RAB
178 if(fUseDptResponse && fUseDetectorResponse) {
179 fFullResponseIn = MatrixMultiplication(fDptIn, fDetectorResponse);
180 fFullResponseOut = MatrixMultiplication(fDptOut, fDetectorResponse);
181 } else if (fUseDptResponse && !fUseDetectorResponse) {
182 fFullResponseIn = fDptIn;
183 fFullResponseOut = fDptOut;
184 } else if (!fUseDptResponse && fUseDetectorResponse) {
185 fFullResponseIn = fDetectorResponse;
186 fFullResponseOut = fDetectorResponse;
187 } else if (!fUseDptResponse && !fUseDetectorResponse && !fUnfoldingAlgorithm == AliJetFlowTools::kNone) {
188 printf(" > No response, exiting ! < \n" );
189 return;
190 }
ef12d5a5 191 } else {
192 fFullResponseIn = GetUnityResponse(fBinsTrue, fBinsRec, TString("in"));
193 fFullResponseOut = GetUnityResponse(fBinsTrue, fBinsRec, TString("out"));
194 }
4292ca60 195 // normalize each slide of the response to one
dc1455ee 196 NormalizeTH2D(fFullResponseIn);
197 NormalizeTH2D(fFullResponseOut);
4292ca60 198 // resize to desired binning scheme
549b5f40
RAB
199 TH2D* resizedResponseIn = RebinTH2D(fFullResponseIn, fBinsTrue, fBinsRec, TString("in"));
200 TH2D* resizedResponseOut = RebinTH2D(fFullResponseOut, fBinsTrue, fBinsRec, TString("out"));
4292ca60 201 // get the kinematic efficiency
549b5f40 202 TH1D* kinematicEfficiencyIn = resizedResponseIn->ProjectionX();
4292ca60 203 kinematicEfficiencyIn->SetNameTitle("kin_eff_IN","kin_eff_IN");
549b5f40 204 TH1D* kinematicEfficiencyOut = resizedResponseOut->ProjectionX();
4292ca60 205 kinematicEfficiencyOut->SetNameTitle("kin_eff_OUT", "kin_eff_OUT");
206 // suppress the errors
51e6bc5a 207 for(Int_t i(0); i < kinematicEfficiencyOut->GetXaxis()->GetNbins(); i++) {
208 kinematicEfficiencyIn->SetBinError(1+i, 0.);
4292ca60 209 kinematicEfficiencyOut->SetBinError(1+i, 0.);
51e6bc5a 210 }
53547ff2
RAB
211 TH1D* jetFindingEfficiency(0x0);
212 if(fJetFindingEff) {
213 jetFindingEfficiency = ProtectHeap(fJetFindingEff);
214 jetFindingEfficiency->SetNameTitle(Form("%s_coarse", jetFindingEfficiency->GetName()), Form("%s_coarse", jetFindingEfficiency->GetName()));
215 jetFindingEfficiency = RebinTH1D(jetFindingEfficiency, fBinsTrue);
216 }
ad04a83c 217 // 2, 3) call the actual unfolding. results and transient objects are stored in a dedicated TDirectoryFile
549b5f40
RAB
218 TH1D* unfoldedJetSpectrumIn(0x0);
219 TH1D* unfoldedJetSpectrumOut(0x0);
ad04a83c 220 fActiveDir->cd(); // select active dir
221 TDirectoryFile* dirIn = new TDirectoryFile(Form("InPlane___%s", fActiveString.Data()), Form("InPlane___%s", fActiveString.Data()));
222 dirIn->cd(); // select inplane subdir
486fb24e 223 // do the inplane unfolding
224 unfoldedJetSpectrumIn = UnfoldWrapper(
225 measuredJetSpectrumIn,
226 resizedResponseIn,
227 kinematicEfficiencyIn,
228 measuredJetSpectrumTrueBinsIn,
229 TString("in"),
230 jetFindingEfficiency);
549b5f40 231 resizedResponseIn->SetNameTitle("ResponseMatrixIn", "response matrix in plane");
f3ba6c8e 232 resizedResponseIn->SetXTitle("p_{T, jet}^{true} [GeV/c]");
233 resizedResponseIn->SetYTitle("p_{T, jet}^{rec} [GeV/c]");
549b5f40
RAB
234 resizedResponseIn = ProtectHeap(resizedResponseIn);
235 resizedResponseIn->Write();
4292ca60 236 kinematicEfficiencyIn->SetNameTitle("KinematicEfficiencyIn","Kinematic efficiency, in plane");
237 kinematicEfficiencyIn = ProtectHeap(kinematicEfficiencyIn);
ad04a83c 238 kinematicEfficiencyIn->Write();
239 fDetectorResponse->SetNameTitle("DetectorResponse", "Detector response matrix");
4292ca60 240 fDetectorResponse = ProtectHeap(fDetectorResponse, kFALSE);
ad04a83c 241 fDetectorResponse->Write();
4292ca60 242 // optional histograms
243 if(fSaveFull) {
244 fSpectrumIn->SetNameTitle("[ORIG]JetSpectrum", "[INPUT] Jet spectrum, in plane");
245 fSpectrumIn->Write();
246 fDptInDist->SetNameTitle("[ORIG]DeltaPt", "#delta p_{T} distribution, in plane");
247 fDptInDist->Write();
248 fDptIn->SetNameTitle("[ORIG]DeltaPtMatrix","#delta p_{T} matrix, in plane");
249 fDptIn->Write();
250 fFullResponseIn->SetNameTitle("ResponseMatrix", "Response matrix, in plane");
251 fFullResponseIn->Write();
252 }
ad04a83c 253 fActiveDir->cd();
486fb24e 254 if(fDphiUnfolding) {
5e11c41c 255 TDirectoryFile* dirOut = new TDirectoryFile(Form("OutOfPlane___%s", fActiveString.Data()), Form("OutOfPlane___%s", fActiveString.Data()));
256 dirOut->cd();
486fb24e 257 // do the out of plane unfolding
258 unfoldedJetSpectrumOut = UnfoldWrapper(
5e11c41c 259 measuredJetSpectrumOut,
260 resizedResponseOut,
261 kinematicEfficiencyOut,
262 measuredJetSpectrumTrueBinsOut,
263 TString("out"),
264 jetFindingEfficiency);
5e11c41c 265 resizedResponseOut->SetNameTitle("ResponseMatrixOut", "response matrix in plane");
f3ba6c8e 266 resizedResponseOut->SetXTitle("p_{T, jet}^{true} [GeV/c]");
267 resizedResponseOut->SetYTitle("p_{T, jet}^{rec} [GeV/c]");
5e11c41c 268 resizedResponseOut = ProtectHeap(resizedResponseOut);
269 resizedResponseOut->Write();
270 kinematicEfficiencyOut->SetNameTitle("KinematicEfficiencyOut","Kinematic efficiency, Out plane");
271 kinematicEfficiencyOut = ProtectHeap(kinematicEfficiencyOut);
272 kinematicEfficiencyOut->Write();
273 fDetectorResponse->SetNameTitle("DetectorResponse", "Detector response matrix");
274 fDetectorResponse = ProtectHeap(fDetectorResponse, kFALSE);
275 fDetectorResponse->Write();
276 if(jetFindingEfficiency) jetFindingEfficiency->Write();
277 // optional histograms
278 if(fSaveFull) {
279 fSpectrumOut->SetNameTitle("[ORIG]JetSpectrum", "[INPUT]Jet spectrum, Out plane");
280 fSpectrumOut->Write();
281 fDptOutDist->SetNameTitle("[ORIG]DeltaPt", "#delta p_{T} distribution, Out plane");
282 fDptOutDist->Write();
283 fDptOut->SetNameTitle("[ORIG]DeltaPtMatrix","#delta p_{T} matrix, Out plane");
284 fDptOut->Write();
285 fFullResponseOut->SetNameTitle("[ORIG]ResponseMatrix", "Response matrix, Out plane");
286 fFullResponseOut->Write();
ef12d5a5 287 }
5e11c41c 288
289 // write general output histograms to file
290 fActiveDir->cd();
291 if(unfoldedJetSpectrumIn && unfoldedJetSpectrumOut && unfoldedJetSpectrumIn && unfoldedJetSpectrumOut) {
292 TGraphErrors* ratio(GetRatio((TH1D*)unfoldedJetSpectrumIn->Clone("unfoldedLocal_in"), (TH1D*)unfoldedJetSpectrumOut->Clone("unfoldedLocal_out")));
293 if(ratio) {
294 ratio->SetNameTitle("RatioInOutPlane", "Ratio in plane, out of plane jet spectrum");
f3ba6c8e 295 ratio->GetXaxis()->SetTitle("p_{T, jet} [GeV/c]");
5e11c41c 296 ratio->GetYaxis()->SetTitle("yield IN / yield OUT");
297 ratio = ProtectHeap(ratio);
298 ratio->Write();
299 // write histo values to RMS files if both routines converged
300 // input values are weighted by their uncertainty
301 for(Int_t i(0); i < ratio->GetXaxis()->GetNbins(); i++) {
302 if(unfoldedJetSpectrumIn->GetBinError(i+1) > 0) fRMSSpectrumIn->Fill(fRMSSpectrumIn->GetBinCenter(i+1), unfoldedJetSpectrumIn->GetBinContent(i+1), 1./TMath::Power(unfoldedJetSpectrumIn->GetBinError(i+1), 2.));
303 if(unfoldedJetSpectrumOut->GetBinError(i+1) > 0) fRMSSpectrumOut->Fill(fRMSSpectrumOut->GetBinCenter(i+1), unfoldedJetSpectrumOut->GetBinContent(i+1), 1./TMath::Power(unfoldedJetSpectrumOut->GetBinError(i+1), 2.));
304 if(unfoldedJetSpectrumOut->GetBinContent(i+1) > 0) fRMSRatio->Fill(fRMSSpectrumIn->GetBinCenter(i+1), unfoldedJetSpectrumIn->GetBinContent(i+1) / unfoldedJetSpectrumOut->GetBinContent(i+1));
305 }
306 }
35c03ef1 307 TGraphErrors* v2(GetV2((TH1D*)unfoldedJetSpectrumIn->Clone("unfoldedLocal_inv2"), (TH1D*)unfoldedJetSpectrumOut->Clone("unfoldedLocal_outv2"), fEventPlaneRes));
5e11c41c 308 if(v2) {
309 v2->SetNameTitle("v2", "v_{2} from different in, out of plane yield");
f3ba6c8e 310 v2->GetXaxis()->SetTitle("p_{T, jet} [GeV/c]");
5e11c41c 311 v2->GetYaxis()->SetTitle("v_{2}");
312 v2 = ProtectHeap(v2);
313 v2->Write();
314 }
315 } else if (unfoldedJetSpectrumOut && unfoldedJetSpectrumIn) {
316 TGraphErrors* ratio(GetRatio((TH1D*)unfoldedJetSpectrumIn->Clone("unfoldedLocal_in"), (TH1D*)unfoldedJetSpectrumOut->Clone("unfoldedLocal_out"), TString(""), kTRUE, fBinsRec->At(fBinsRec->GetSize()-1)));
317 if(ratio) {
318 ratio->SetNameTitle("[NC]RatioInOutPlane", "[NC]Ratio in plane, out of plane jet spectrum");
f3ba6c8e 319 ratio->GetXaxis()->SetTitle("p_{T, jet} [GeV/c]");
5e11c41c 320 ratio->GetYaxis()->SetTitle("yield IN / yield OUT");
321 ratio = ProtectHeap(ratio);
322 ratio->Write();
323 }
35c03ef1 324 TGraphErrors* v2(GetV2((TH1D*)unfoldedJetSpectrumIn->Clone("unfoldedLocal_inv2"), (TH1D*)unfoldedJetSpectrumOut->Clone("unfoldedLocal_outv2"), fEventPlaneRes));
5e11c41c 325 if(v2) {
326 v2->SetNameTitle("v2", "v_{2} from different in, out of plane yield");
f3ba6c8e 327 v2->GetXaxis()->SetTitle("p_{T, jet} [GeV/c]");
5e11c41c 328 v2->GetYaxis()->SetTitle("v_{2}");
329 v2 = ProtectHeap(v2);
330 v2->Write();
331 }
4292ca60 332 }
486fb24e 333 } // end of if(fDphiUnfolding)
ad04a83c 334 fDeltaPtDeltaPhi->Write();
9f892925 335 unfoldedJetSpectrumIn->Sumw2();
336 ProtectHeap(unfoldedJetSpectrumIn, kFALSE);
337 unfoldedJetSpectrumIn->Write();
338 unfoldedJetSpectrumOut->Sumw2();
339 ProtectHeap(unfoldedJetSpectrumOut, kFALSE);
340 unfoldedJetSpectrumOut->Write();
ad04a83c 341 fJetPtDeltaPhi->Write();
549b5f40
RAB
342 // save the current state of the unfolding object
343 SaveConfiguration(unfoldedJetSpectrumIn ? kTRUE : kFALSE, unfoldedJetSpectrumOut ? kTRUE : kFALSE);
f3ba6c8e 344 TH1D* unfoldedJetSpectrumInForSub((TH1D*)unfoldedJetSpectrumIn->Clone("forSubIn"));
345 TH1D* unfoldedJetSpectrumOutForSub((TH1D*)unfoldedJetSpectrumOut->Clone("forSubOut"));
346 unfoldedJetSpectrumInForSub->Add(unfoldedJetSpectrumOutForSub, -1.);
347 unfoldedJetSpectrumInForSub= ProtectHeap(unfoldedJetSpectrumInForSub);
348 unfoldedJetSpectrumInForSub->Write();
349
dc1455ee 350}
351//_____________________________________________________________________________
486fb24e 352TH1D* AliJetFlowTools::UnfoldWrapper(
353 const TH1D* measuredJetSpectrum, // truncated raw jets (same binning as pt rec of response)
354 const TH2D* resizedResponse, // response matrix
355 const TH1D* kinematicEfficiency, // kinematic efficiency
356 const TH1D* measuredJetSpectrumTrueBins, // unfolding template: same binning is pt gen of response
357 const TString suffix, // suffix (in or out of plane)
358 const TH1D* jetFindingEfficiency) // jet finding efficiency
359{
360 // wrapper function to call specific unfolding routine
361 TH1D* (AliJetFlowTools::*myFunction)(const TH1D*, const TH2D*, const TH1D*, const TH1D*, const TString, const TH1D*);
362 // initialize functon pointer
87233f72 363 if(fUnfoldingAlgorithm == kChi2) myFunction = &AliJetFlowTools::UnfoldSpectrumChi2;
364 else if(fUnfoldingAlgorithm == kBayesian) myFunction = &AliJetFlowTools::UnfoldSpectrumBayesian;
365 else if(fUnfoldingAlgorithm == kBayesianAli) myFunction = &AliJetFlowTools::UnfoldSpectrumBayesianAli;
366 else if(fUnfoldingAlgorithm == kSVD) myFunction = &AliJetFlowTools::UnfoldSpectrumSVD;
367 else if(fUnfoldingAlgorithm == kNone) {
368 TH1D* clone((TH1D*)measuredJetSpectrum->Clone("clone"));
369 clone->SetNameTitle(Form("MeasuredJetSpectrum%s", suffix.Data()), Form("measuredJetSpectrum %s", suffix.Data()));
c03f7598 370 return clone;//RebinTH1D(clone, fBinsTrue, clone->GetName(), kFALSE);
486fb24e 371 }
87233f72 372 else return 0x0;
486fb24e 373 // do the actual unfolding with the selected function
374 return (this->*myFunction)( measuredJetSpectrum, resizedResponse, kinematicEfficiency, measuredJetSpectrumTrueBins, suffix, jetFindingEfficiency);
375}
376//_____________________________________________________________________________
549b5f40
RAB
377TH1D* AliJetFlowTools::UnfoldSpectrumChi2(
378 const TH1D* measuredJetSpectrum, // truncated raw jets (same binning as pt rec of response)
486fb24e 379 const TH2D* resizedResponse, // response matrix
549b5f40
RAB
380 const TH1D* kinematicEfficiency, // kinematic efficiency
381 const TH1D* measuredJetSpectrumTrueBins, // unfolding template: same binning is pt gen of response
382 const TString suffix, // suffix (in or out of plane)
383 const TH1D* jetFindingEfficiency) // jet finding efficiency (optional)
dc1455ee 384{
51e6bc5a 385 // unfold the spectrum using chi2 minimization
386
4292ca60 387 // step 0) setup the static members of AliUnfolding
388 ResetAliUnfolding(); // reset from previous iteration
389 // also deletes and re-creates the global TVirtualFitter
390 AliUnfolding::SetUnfoldingMethod(AliUnfolding::kChi2Minimization);
391 if(!strcmp("in", suffix.Data())) AliUnfolding::SetChi2Regularization(AliUnfolding::kLogLog, fBetaIn);
392 else if(!strcmp("out", suffix.Data())) AliUnfolding::SetChi2Regularization(AliUnfolding::kLogLog, fBetaOut);
393 if(!strcmp("prior_in", suffix.Data())) AliUnfolding::SetChi2Regularization(AliUnfolding::kLogLog, fBetaIn);
394 else if(!strcmp("prior_out", suffix.Data())) AliUnfolding::SetChi2Regularization(AliUnfolding::kLogLog, fBetaOut);
395 AliUnfolding::SetNbins(fBinsRec->GetSize()-1, fBinsTrue->GetSize()-1);
dc1455ee 396
549b5f40
RAB
397 // step 1) clone all input histograms. the histograms are cloned to make sure that the original histograms
398 // stay intact. a local copy of a histogram (which only exists in the scope of this function) is
399 // denoted by the suffix 'Local'
4292ca60 400
549b5f40
RAB
401 // measuredJetSpectrumLocal holds the spectrum that needs to be unfolded
402 TH1D *measuredJetSpectrumLocal = (TH1D*)measuredJetSpectrum->Clone(Form("measuredJetSpectrumLocal_%s", suffix.Data()));
4292ca60 403 // unfolded local will be filled with the result of the unfolding
404 TH1D *unfoldedLocal(new TH1D(Form("unfoldedLocal_%s", suffix.Data()), Form("unfoldedLocal_%s", suffix.Data()), fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
405
dc1455ee 406 // full response matrix and kinematic efficiency
549b5f40 407 TH2D* resizedResponseLocal = (TH2D*)resizedResponse->Clone(Form("resizedResponseLocal_%s", suffix.Data()));
51e6bc5a 408 TH1D* kinematicEfficiencyLocal = (TH1D*)kinematicEfficiency->Clone(Form("kinematicEfficiencyLocal_%s", suffix.Data()));
d7ec324f 409
4292ca60 410 // the initial guess for the unfolded pt spectrum, equal to the folded spectrum, but in 'true' bins
549b5f40
RAB
411 TH1D *priorLocal = (TH1D*)measuredJetSpectrumTrueBins->Clone(Form("priorLocal_%s", suffix.Data()));
412 // optionally, the prior can be smoothened by extrapolating the spectrum using a power law fit
413 if(fSmoothenPrior) priorLocal = SmoothenPrior(priorLocal, fPower, fFitMin, fFitMax, fFitStart, kTRUE, fSmoothenCounts);
ef12d5a5 414
4292ca60 415 // step 2) start the unfolding
51e6bc5a 416 Int_t status(-1), i(0);
417 while(status < 0 && i < 100) {
4292ca60 418 // i > 0 means that the first iteration didn't converge. in that case, the result of the first
419 // iteration (stored in unfoldedLocal) is cloned and used as a starting point for the
420 if (i > 0) priorLocal = (TH1D*)unfoldedLocal->Clone(Form("priorLocal_%s_%i", suffix.Data(), i));
421 status = AliUnfolding::Unfold(
422 resizedResponseLocal, // response matrix
423 kinematicEfficiencyLocal, // efficiency applied on the unfolded spectrum (can be NULL)
549b5f40 424 measuredJetSpectrumLocal, // measured spectrum
4292ca60 425 priorLocal, // initial conditions (set NULL to use measured spectrum)
426 unfoldedLocal); // results
427 // status holds the minuit fit status (where 0 means convergence)
51e6bc5a 428 i++;
429 }
4292ca60 430 // get the status of TMinuit::mnhess(), fISW[1] == 3 means the hessian matrix was calculated succesfully
431 if(status == 0 && gMinuit->fISW[1] == 3) {
432 // if the unfolding converged and the hessian matrix is reliable, plot the pearson coefficients
ad04a83c 433 TVirtualFitter *fitter(TVirtualFitter::GetFitter());
4292ca60 434 if(gMinuit) gMinuit->Command("SET COV");
435 TMatrixD covarianceMatrix(fBinsTrue->GetSize()-1, fBinsTrue->GetSize()-1, fitter->GetCovarianceMatrix());
436 TMatrixD *pearson((TMatrixD*)CalculatePearsonCoefficients(&covarianceMatrix));
437 pearson->Print();
ad04a83c 438 TH2D *hPearson(new TH2D(*pearson));
4292ca60 439 hPearson->SetNameTitle(Form("PearsonCoefficients_%s", suffix.Data()), Form("Pearson coefficients, %s plane", suffix.Data()));
440 hPearson = ProtectHeap(hPearson);
ad04a83c 441 hPearson->Write();
4292ca60 442 } else status = -1;
d7ec324f 443
4292ca60 444 // step 3) refold the unfolded spectrum and save the ratio measured / refolded
445 TH1D *foldedLocal(fResponseMaker->MultiplyResponseGenerated(unfoldedLocal, resizedResponseLocal,kinematicEfficiencyLocal));
446 foldedLocal->SetNameTitle(Form("RefoldedSpectrum_%s", suffix.Data()), Form("Refolded jet spectrum, %s plane", suffix.Data()));
447 unfoldedLocal->SetNameTitle(Form("UnfoldedSpectrum_%s", suffix.Data()), Form("Unfolded jet spectrum, %s plane", suffix.Data()));
549b5f40 448 TGraphErrors* ratio(GetRatio(foldedLocal, measuredJetSpectrumLocal, TString(""), kTRUE, fBinsTrue->At(fBinsTrue->GetSize()-1)));
4292ca60 449 if(ratio) {
53547ff2
RAB
450 ratio->SetNameTitle("RatioRefoldedMeasured", Form("Ratio measured, re-folded %s ", suffix.Data()));
451 ratio->GetYaxis()->SetTitle("ratio measured / re-folded");
4292ca60 452 ratio = ProtectHeap(ratio);
453 ratio->Write();
454 }
d7ec324f 455
456 // step 4) write histograms to file. to ensure that these have unique identifiers on the heap,
457 // objects are cloned using 'ProtectHeap()'
549b5f40
RAB
458 measuredJetSpectrumLocal->SetNameTitle(Form("InputSpectrum_%s", suffix.Data()), Form("InputSpectrum_%s", suffix.Data()));
459 measuredJetSpectrumLocal = ProtectHeap(measuredJetSpectrumLocal);
460 measuredJetSpectrumLocal->Write();
d7ec324f 461
4292ca60 462 resizedResponseLocal = ProtectHeap(resizedResponseLocal);
463 resizedResponseLocal->Write();
d7ec324f 464
4292ca60 465 unfoldedLocal = ProtectHeap(unfoldedLocal);
53547ff2 466 if(jetFindingEfficiency) unfoldedLocal->Divide(jetFindingEfficiency);
51e6bc5a 467 unfoldedLocal->Write();
d7ec324f 468
4292ca60 469 foldedLocal = ProtectHeap(foldedLocal);
470 foldedLocal->Write();
d7ec324f 471
ef12d5a5 472 priorLocal = ProtectHeap(priorLocal);
473 priorLocal->Write();
d7ec324f 474
475 // step 5) save the fit status (penalty value, degrees of freedom, chi^2 value)
53547ff2 476 TH1F* fitStatus(new TH1F(Form("fitStatus_%s_%s", fActiveString.Data(), suffix.Data()), Form("fitStatus_%s_%s", fActiveString.Data(), suffix.Data()), 4, -0.5, 3.5));
d7ec324f 477 fitStatus->SetBinContent(1, AliUnfolding::fChi2FromFit);
478 fitStatus->GetXaxis()->SetBinLabel(1, "fChi2FromFit");
479 fitStatus->SetBinContent(2, AliUnfolding::fPenaltyVal);
480 fitStatus->GetXaxis()->SetBinLabel(2, "fPenaltyVal");
481 fitStatus->SetBinContent(3, fBinsRec->GetSize()-fBinsTrue->GetSize());
482 fitStatus->GetXaxis()->SetBinLabel(3, "DOF");
53547ff2
RAB
483 fitStatus->SetBinContent(4, (!strcmp(suffix.Data(), "in")) ? fBetaIn : fBetaOut);
484 fitStatus->GetXaxis()->SetBinLabel(4, (!strcmp(suffix.Data(), "in")) ? "fBetaIn" : "fBetaOut");
d7ec324f 485 fitStatus->Write();
549b5f40 486 return unfoldedLocal;
dc1455ee 487}
488//_____________________________________________________________________________
549b5f40
RAB
489TH1D* AliJetFlowTools::UnfoldSpectrumSVD(
490 const TH1D* measuredJetSpectrum, // jet pt in pt rec bins
491 const TH2D* resizedResponse, // full response matrix, normalized in slides of pt true
492 const TH1D* kinematicEfficiency, // kinematic efficiency
493 const TH1D* measuredJetSpectrumTrueBins, // jet pt in pt true bins, also the prior when measured is chosen as prior
494 const TString suffix, // suffix (in, out)
495 const TH1D* jetFindingEfficiency) // jet finding efficiency (optional)
51e6bc5a 496{
549b5f40
RAB
497
498 TH1D* priorLocal( GetPrior(
499 measuredJetSpectrum, // jet pt in pt rec bins
500 resizedResponse, // full response matrix, normalized in slides of pt true
501 kinematicEfficiency, // kinematic efficiency
502 measuredJetSpectrumTrueBins, // jet pt in pt true bins, also the prior when measured is chosen as prior
503 suffix, // suffix (in, out)
504 jetFindingEfficiency)); // jet finding efficiency (optional)
505 if(!priorLocal) {
506 printf(" > couldn't find prior ! < \n");
507 return 0x0;
508 } else printf(" 1) retrieved prior \n");
509
510 // go back to the 'root' directory of this instance of the SVD unfolding routine
20abfcc4 511 (!strcmp(suffix.Data(), "in")) ? fActiveDir->cd(Form("InPlane___%s", fActiveString.Data())) : fActiveDir->cd(Form("OutOfPlane___%s", fActiveString.Data()));
512
4292ca60 513 // 2) setup all the necessary input for the unfolding routine. all input histograms are copied locally
549b5f40
RAB
514 // measured jets in pt rec binning
515 TH1D *measuredJetSpectrumLocal((TH1D*)measuredJetSpectrum->Clone(Form("jets_%s", suffix.Data())));
516 // local copie of the response matrix
517 TH2D *resizedResponseLocal((TH2D*)resizedResponse->Clone(Form("resizedResponseLocal_%s", suffix.Data())));
518 // local copy of response matrix, all true slides normalized to 1
519 // this response matrix will eventually be used in the re-folding routine
520 TH2D *resizedResponseLocalNorm((TH2D*)resizedResponse->Clone(Form("resizedResponseLocalNorm_%s", suffix.Data())));
521 resizedResponseLocalNorm = NormalizeTH2D(resizedResponseLocalNorm);
ef12d5a5 522 // kinematic efficiency
51e6bc5a 523 TH1D *kinematicEfficiencyLocal((TH1D*)kinematicEfficiency->Clone(Form("kinematicEfficiency_%s", suffix.Data())));
ef12d5a5 524 // place holder histos
d7ec324f 525 TH1D *unfoldedLocalSVD(0x0);
526 TH1D *foldedLocalSVD(0x0);
4292ca60 527 cout << " 2) setup necessary input " << endl;
51e6bc5a 528 // 3) configure routine
529 RooUnfold::ErrorTreatment errorTreatment = (fSVDToy) ? RooUnfold::kCovToy : RooUnfold::kCovariance;
d7ec324f 530 cout << " step 3) configured routine " << endl;
531
4292ca60 532 // 4) get transpose matrices
549b5f40
RAB
533 // a) get the transpose of the full response matrix
534 TH2* responseMatrixLocalTransposePrior(fResponseMaker->GetTransposeResponsMatrix(resizedResponseLocal));
4292ca60 535 responseMatrixLocalTransposePrior->SetNameTitle(Form("prior_%s_%s", responseMatrixLocalTransposePrior->GetName(), suffix.Data()),Form("prior_%s_%s", responseMatrixLocalTransposePrior->GetName(), suffix.Data()));
549b5f40
RAB
536 // normalize it with the prior. this will ensure that high statistics bins will constrain the
537 // end result most strenuously than bins with limited number of counts
538 responseMatrixLocalTransposePrior = fResponseMaker->NormalizeResponsMatrixYaxisWithPrior(responseMatrixLocalTransposePrior, priorLocal);
539 cout << " 4) retrieved first transpose matrix " << endl;
4292ca60 540
541 // 5) get response for SVD unfolding
542 RooUnfoldResponse responseSVD(0, 0, responseMatrixLocalTransposePrior, Form("respCombinedSVD_%s", suffix.Data()), Form("respCombinedSVD_%s", suffix.Data()));
4292ca60 543 cout << " 5) retrieved roo unfold response object " << endl;
549b5f40 544
4292ca60 545 // 6) actualy unfolding loop
549b5f40 546 RooUnfoldSvd unfoldSVD(&responseSVD, measuredJetSpectrumLocal, (!strcmp(suffix.Data(), "in")) ? fSVDRegIn : fSVDRegOut);
20abfcc4 547 unfoldedLocalSVD = (TH1D*)unfoldSVD.Hreco(errorTreatment);
549b5f40
RAB
548 // correct the spectrum for the kinematic efficiency
549 unfoldedLocalSVD->Divide(kinematicEfficiencyLocal);
550
551 // get the pearson coefficients from the covariance matrix
20abfcc4 552 TMatrixD covarianceMatrix = unfoldSVD.Ereco(errorTreatment);
553 TMatrixD *pearson = (TMatrixD*)CalculatePearsonCoefficients(&covarianceMatrix);
4292ca60 554 if(pearson) {
549b5f40 555 TH2D* hPearson(new TH2D(*pearson));
4292ca60 556 pearson->Print();
d7ec324f 557 hPearson->SetNameTitle(Form("PearsonCoefficients_%s", suffix.Data()), Form("Pearson coefficients_%s", suffix.Data()));
558 hPearson = ProtectHeap(hPearson);
4292ca60 559 hPearson->Write();
549b5f40 560 } else return 0x0; // return if unfolding didn't converge
4292ca60 561
562 // plot singular values and d_i vector
20abfcc4 563 TSVDUnfold* svdUnfold(unfoldSVD.Impl());
51e6bc5a 564 TH1* hSVal(svdUnfold->GetSV());
565 TH1D* hdi(svdUnfold->GetD());
4292ca60 566 hSVal->SetNameTitle("SingularValuesOfAC", "Singular values of AC^{-1}");
51e6bc5a 567 hSVal->SetXTitle("singular values");
568 hSVal->Write();
4292ca60 569 hdi->SetNameTitle("dVector", "d vector after orthogonal transformation");
51e6bc5a 570 hdi->SetXTitle("|d_{i}^{kreg}|");
571 hdi->Write();
4292ca60 572 cout << " plotted singular values and d_i vector " << endl;
573
574 // 7) refold the unfolded spectrum
549b5f40
RAB
575 foldedLocalSVD = fResponseMaker->MultiplyResponseGenerated(unfoldedLocalSVD, resizedResponseLocalNorm, kinematicEfficiencyLocal);
576 TGraphErrors* ratio(GetRatio(measuredJetSpectrumLocal, foldedLocalSVD, "ratio measured / re-folded", kTRUE));
53547ff2 577 ratio->SetNameTitle(Form("RatioRefoldedMeasured_%s", fActiveString.Data()), Form("Ratio measured / re-folded %s", fActiveString.Data()));
4292ca60 578 ratio->GetXaxis()->SetTitle("p_{t}^{rec, rec} [GeV/ c]");
579 ratio->GetYaxis()->SetTitle("ratio measured / re-folded");
580 ratio->Write();
581 cout << " 7) refolded the unfolded spectrum " << endl;
582
549b5f40
RAB
583 // write the measured, unfolded and re-folded spectra to the output directory
584 measuredJetSpectrumLocal->SetNameTitle(Form("InputSpectrum_%s", suffix.Data()), Form("input spectrum (measured) %s", suffix.Data()));
585 measuredJetSpectrumLocal = ProtectHeap(measuredJetSpectrumLocal);
586 measuredJetSpectrumLocal->SetXTitle("p_{t}^{rec} [GeV/c]");
587 measuredJetSpectrumLocal->Write(); // input spectrum
d7ec324f 588 unfoldedLocalSVD->SetNameTitle(Form("UnfoldedSpectrum_%s",suffix.Data()), Form("unfolded spectrum %s", suffix.Data()));
589 unfoldedLocalSVD = ProtectHeap(unfoldedLocalSVD);
53547ff2 590 if(jetFindingEfficiency) unfoldedLocalSVD->Divide(jetFindingEfficiency);
4292ca60 591 unfoldedLocalSVD->Write(); // unfolded spectrum
d7ec324f 592 foldedLocalSVD->SetNameTitle(Form("RefoldedSpectrum_%s", suffix.Data()), Form("refoldedSpectrum_%s", suffix.Data()));
593 foldedLocalSVD = ProtectHeap(foldedLocalSVD);
4292ca60 594 foldedLocalSVD->Write(); // re-folded spectrum
d7ec324f 595
549b5f40
RAB
596 // save more general bookkeeeping histograms to the output directory
597 responseMatrixLocalTransposePrior->SetNameTitle("TransposeResponseMatrix", "Transpose of response matrix, normalize with prior");
f3ba6c8e 598 responseMatrixLocalTransposePrior->SetXTitle("p_{T, jet}^{true} [GeV/c]");
599 responseMatrixLocalTransposePrior->SetYTitle("p_{T, jet}^{rec} [GeV/c]");
4292ca60 600 responseMatrixLocalTransposePrior->Write();
549b5f40
RAB
601 priorLocal->SetNameTitle("PriorOriginal", "Prior, original");
602 priorLocal->SetXTitle("p_{t} [GeV/c]");
603 priorLocal = ProtectHeap(priorLocal);
604 priorLocal->Write();
605 resizedResponseLocalNorm = ProtectHeap(resizedResponseLocalNorm);
606 resizedResponseLocalNorm->Write();
53547ff2
RAB
607
608 // save some info
609 TH1F* fitStatus(new TH1F(Form("fitStatus_%s_%s", fActiveString.Data(), suffix.Data()), Form("fitStatus_%s_%s", fActiveString.Data(), suffix.Data()), 1, -0.5, 0.5));
610 fitStatus->SetBinContent(1, (!strcmp(suffix.Data(), "in")) ? fSVDRegIn : fSVDRegOut);
611 fitStatus->GetXaxis()->SetBinLabel(1, (!strcmp(suffix.Data(), "in")) ? "fSVDRegIn" : "fSVDRegOut");
612 fitStatus->Write();
613
549b5f40 614 return unfoldedLocalSVD;
51e6bc5a 615}
616//_____________________________________________________________________________
549b5f40
RAB
617TH1D* AliJetFlowTools::UnfoldSpectrumBayesianAli(
618 const TH1D* measuredJetSpectrum, // jet pt in pt rec bins
619 const TH2D* resizedResponse, // full response matrix, normalized in slides of pt true
620 const TH1D* kinematicEfficiency, // kinematic efficiency
621 const TH1D* measuredJetSpectrumTrueBins, // jet pt in pt true bins, also the prior when measured is chosen as prior
622 const TString suffix, // suffix (in, out)
623 const TH1D* jetFindingEfficiency) // jet finding efficiency (optional)
d7ec324f 624{
549b5f40
RAB
625 // unfold the spectrum using the bayesian unfolding impelmented in AliUnfolding
626 // FIXME careful, not tested yet ! (06122013) FIXME
627
628 // step 0) setup the static members of AliUnfolding
629 ResetAliUnfolding(); // reset from previous iteration
630 // also deletes and re-creates the global TVirtualFitter
631 AliUnfolding::SetUnfoldingMethod(AliUnfolding::kBayesian);
632 if(!strcmp("in", suffix.Data())) AliUnfolding::SetBayesianParameters(fBayesianSmoothIn, fBayesianIterIn);
633 else if(!strcmp("out", suffix.Data())) AliUnfolding::SetBayesianParameters(fBayesianSmoothOut, fBayesianIterOut);
634 else if(!strcmp("prior_in", suffix.Data())) AliUnfolding::SetBayesianParameters(fBayesianSmoothIn, fBayesianIterIn);
635 else if(!strcmp("prior_out", suffix.Data())) AliUnfolding::SetBayesianParameters(fBayesianSmoothOut, fBayesianIterOut);
4e4f12b6
RAB
636 AliUnfolding::SetNbins(fBinsRec->GetSize()-1, fBinsTrue->GetSize()-1);
637
549b5f40
RAB
638 // 1) get a prior for unfolding and clone all the input histograms
639 TH1D* priorLocal( GetPrior(
640 measuredJetSpectrum, // jet pt in pt rec bins
641 resizedResponse, // full response matrix, normalized in slides of pt true
642 kinematicEfficiency, // kinematic efficiency
643 measuredJetSpectrumTrueBins, // jet pt in pt true bins, also the prior when measured is chosen as prior
644 suffix, // suffix (in, out)
645 jetFindingEfficiency)); // jet finding efficiency (optional)
646 if(!priorLocal) {
647 printf(" > couldn't find prior ! < \n");
648 return 0x0;
649 } else printf(" 1) retrieved prior \n");
650 // switch back to root dir of this unfolding procedure
651 (!strcmp(suffix.Data(), "in")) ? fActiveDir->cd(Form("InPlane___%s", fActiveString.Data())) : fActiveDir->cd(Form("OutOfPlane___%s", fActiveString.Data()));
652
653 // measuredJetSpectrumLocal holds the spectrum that needs to be unfolded
654 TH1D *measuredJetSpectrumLocal = (TH1D*)measuredJetSpectrum->Clone(Form("measuredJetSpectrumLocal_%s", suffix.Data()));
655 // unfolded local will be filled with the result of the unfolding
656 TH1D *unfoldedLocal(new TH1D(Form("unfoldedLocal_%s", suffix.Data()), Form("unfoldedLocal_%s", suffix.Data()), fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
657
658 // full response matrix and kinematic efficiency
659 TH2D* resizedResponseLocal = (TH2D*)resizedResponse->Clone(Form("resizedResponseLocal_%s", suffix.Data()));
660 TH1D* kinematicEfficiencyLocal = (TH1D*)kinematicEfficiency->Clone(Form("kinematicEfficiencyLocal_%s", suffix.Data()));
661
662 // step 2) start the unfolding
663 Int_t status(-1), i(0);
664 while(status < 0 && i < 100) {
665 // i > 0 means that the first iteration didn't converge. in that case, the result of the first
666 // iteration (stored in unfoldedLocal) is cloned and used as a starting point for the
667 if (i > 0) priorLocal = (TH1D*)unfoldedLocal->Clone(Form("priorLocal_%s_%i", suffix.Data(), i));
668 status = AliUnfolding::Unfold(
669 resizedResponseLocal, // response matrix
670 kinematicEfficiencyLocal, // efficiency applied on the unfolded spectrum (can be NULL)
671 measuredJetSpectrumLocal, // measured spectrum
672 priorLocal, // initial conditions (set NULL to use measured spectrum)
673 unfoldedLocal); // results
674 // status holds the minuit fit status (where 0 means convergence)
675 i++;
676 }
677 // get the status of TMinuit::mnhess(), fISW[1] == 3 means the hessian matrix was calculated succesfully
678 if(status == 0 && gMinuit->fISW[1] == 3) {
679 // if the unfolding converged and the hessian matrix is reliable, plot the pearson coefficients
680 TVirtualFitter *fitter(TVirtualFitter::GetFitter());
681 if(gMinuit) gMinuit->Command("SET COV");
682 TMatrixD covarianceMatrix(fBinsTrue->GetSize()-1, fBinsTrue->GetSize()-1, fitter->GetCovarianceMatrix());
683 TMatrixD *pearson((TMatrixD*)CalculatePearsonCoefficients(&covarianceMatrix));
684 pearson->Print();
685 TH2D *hPearson(new TH2D(*pearson));
686 hPearson->SetNameTitle(Form("PearsonCoefficients_%s", suffix.Data()), Form("Pearson coefficients, %s plane", suffix.Data()));
687 hPearson = ProtectHeap(hPearson);
688 hPearson->Write();
689 } else status = -1;
690
691 // step 3) refold the unfolded spectrum and save the ratio measured / refolded
692 TH1D *foldedLocal(fResponseMaker->MultiplyResponseGenerated(unfoldedLocal, resizedResponseLocal,kinematicEfficiencyLocal));
693 foldedLocal->SetNameTitle(Form("RefoldedSpectrum_%s", suffix.Data()), Form("Refolded jet spectrum, %s plane", suffix.Data()));
694 unfoldedLocal->SetNameTitle(Form("UnfoldedSpectrum_%s", suffix.Data()), Form("Unfolded jet spectrum, %s plane", suffix.Data()));
695 TGraphErrors* ratio(GetRatio(foldedLocal, measuredJetSpectrumLocal, TString(""), kTRUE, fBinsTrue->At(fBinsTrue->GetSize()-1)));
696 if(ratio) {
697 ratio->SetNameTitle("RatioRefoldedMeasured", Form("Ratio measured, re-folded %s ", suffix.Data()));
698 ratio->GetYaxis()->SetTitle("ratio measured / re-folded");
699 ratio = ProtectHeap(ratio);
700 ratio->Write();
d7ec324f 701 }
549b5f40
RAB
702
703 // step 4) write histograms to file. to ensure that these have unique identifiers on the heap,
704 // objects are cloned using 'ProtectHeap()'
705 measuredJetSpectrumLocal->SetNameTitle(Form("InputSpectrum_%s", suffix.Data()), Form("InputSpectrum_%s", suffix.Data()));
706 measuredJetSpectrumLocal = ProtectHeap(measuredJetSpectrumLocal);
707 measuredJetSpectrumLocal->Write();
708
709 resizedResponseLocal = ProtectHeap(resizedResponseLocal);
710 resizedResponseLocal->Write();
711
712 unfoldedLocal = ProtectHeap(unfoldedLocal);
713 if(jetFindingEfficiency) unfoldedLocal->Divide(jetFindingEfficiency);
714 unfoldedLocal->Write();
715
716 foldedLocal = ProtectHeap(foldedLocal);
717 foldedLocal->Write();
718
719 priorLocal = ProtectHeap(priorLocal);
720 priorLocal->Write();
721
722 // step 5) save the fit status (penalty value, degrees of freedom, chi^2 value)
723 TH1F* fitStatus(new TH1F(Form("fitStatus_%s_%s", fActiveString.Data(), suffix.Data()), Form("fitStatus_%s_%s", fActiveString.Data(), suffix.Data()), 4, -0.5, 3.5));
724 fitStatus->SetBinContent(1, AliUnfolding::fChi2FromFit);
725 fitStatus->GetXaxis()->SetBinLabel(1, "fChi2FromFit");
726 fitStatus->SetBinContent(2, AliUnfolding::fPenaltyVal);
727 fitStatus->GetXaxis()->SetBinLabel(2, "fPenaltyVal");
728 fitStatus->SetBinContent(3, fBinsRec->GetSize()-fBinsTrue->GetSize());
729 fitStatus->GetXaxis()->SetBinLabel(3, "DOF");
730 fitStatus->SetBinContent(4, (!strcmp(suffix.Data(), "in")) ? fBetaIn : fBetaOut);
731 fitStatus->GetXaxis()->SetBinLabel(4, (!strcmp(suffix.Data(), "in")) ? "fBetaIn" : "fBetaOut");
732 fitStatus->Write();
733 return unfoldedLocal;
734}
735//_____________________________________________________________________________
736TH1D* AliJetFlowTools::UnfoldSpectrumBayesian(
737 const TH1D* measuredJetSpectrum, // jet pt in pt rec bins
738 const TH2D* resizedResponse, // full response matrix, normalized in slides of pt true
739 const TH1D* kinematicEfficiency, // kinematic efficiency
740 const TH1D* measuredJetSpectrumTrueBins, // jet pt in pt true bins, also the prior when measured is chosen as prior
741 const TString suffix, // suffix (in, out)
742 const TH1D* jetFindingEfficiency) // jet finding efficiency (optional)
743{
744 // use bayesian unfolding from the RooUnfold package to unfold jet spectra
745
746 // 1) get a prior for unfolding.
747 TH1D* priorLocal( GetPrior(
748 measuredJetSpectrum, // jet pt in pt rec bins
749 resizedResponse, // full response matrix, normalized in slides of pt true
750 kinematicEfficiency, // kinematic efficiency
751 measuredJetSpectrumTrueBins, // jet pt in pt true bins, also the prior when measured is chosen as prior
752 suffix, // suffix (in, out)
753 jetFindingEfficiency)); // jet finding efficiency (optional)
754 if(!priorLocal) {
755 printf(" > couldn't find prior ! < \n");
756 return 0x0;
757 } else printf(" 1) retrieved prior \n");
d7ec324f 758 (!strcmp(suffix.Data(), "in")) ? fActiveDir->cd(Form("InPlane___%s", fActiveString.Data())) : fActiveDir->cd(Form("OutOfPlane___%s", fActiveString.Data()));
d7ec324f 759
760 // 2) setup all the necessary input for the unfolding routine. all input histograms are copied locally
549b5f40
RAB
761 // measured jets in pt rec binning
762 TH1D *measuredJetSpectrumLocal((TH1D*)measuredJetSpectrum->Clone(Form("jets_%s", suffix.Data())));
763 // local copie of the response matrix
764 TH2D *resizedResponseLocal((TH2D*)resizedResponse->Clone(Form("resizedResponseLocal_%s", suffix.Data())));
765 // local copy of response matrix, all true slides normalized to 1
766 // this response matrix will eventually be used in the re-folding routine
767 TH2D *resizedResponseLocalNorm((TH2D*)resizedResponse->Clone(Form("resizedResponseLocalNorm_%s", suffix.Data())));
768 resizedResponseLocalNorm = NormalizeTH2D(resizedResponseLocalNorm);
d7ec324f 769 // kinematic efficiency
770 TH1D *kinematicEfficiencyLocal((TH1D*)kinematicEfficiency->Clone(Form("kinematicEfficiency_%s", suffix.Data())));
771 // place holder histos
549b5f40
RAB
772 TH1D *unfoldedLocalBayes(0x0);
773 TH1D *foldedLocalBayes(0x0);
d7ec324f 774 cout << " 2) setup necessary input " << endl;
549b5f40
RAB
775 // 4) get transpose matrices
776 // a) get the transpose of the full response matrix
777 TH2* responseMatrixLocalTransposePrior(fResponseMaker->GetTransposeResponsMatrix(resizedResponseLocal));
d7ec324f 778 responseMatrixLocalTransposePrior->SetNameTitle(Form("prior_%s_%s", responseMatrixLocalTransposePrior->GetName(), suffix.Data()),Form("prior_%s_%s", responseMatrixLocalTransposePrior->GetName(), suffix.Data()));
549b5f40
RAB
779 // normalize it with the prior. this will ensure that high statistics bins will constrain the
780 // end result most strenuously than bins with limited number of counts
781 responseMatrixLocalTransposePrior = fResponseMaker->NormalizeResponsMatrixYaxisWithPrior(responseMatrixLocalTransposePrior, priorLocal);
782 // 3) get response for Bayesian unfolding
783 RooUnfoldResponse responseBayes(0, 0, responseMatrixLocalTransposePrior, Form("respCombinedBayes_%s", suffix.Data()), Form("respCombinedBayes_%s", suffix.Data()));
d7ec324f 784
549b5f40
RAB
785 // 4) actualy unfolding loop
786 RooUnfoldBayes unfoldBayes(&responseBayes, measuredJetSpectrumLocal, (!strcmp("in", suffix.Data())) ? fBayesianIterIn : fBayesianIterOut);
787 RooUnfold::ErrorTreatment errorTreatment = (fSVDToy) ? RooUnfold::kCovToy : RooUnfold::kCovariance;
788 unfoldedLocalBayes = (TH1D*)unfoldBayes.Hreco(errorTreatment);
789 // correct the spectrum for the kinematic efficiency
790 unfoldedLocalBayes->Divide(kinematicEfficiencyLocal);
791 // get the pearson coefficients from the covariance matrix
792 TMatrixD covarianceMatrix = unfoldBayes.Ereco(errorTreatment);
d7ec324f 793 TMatrixD *pearson = (TMatrixD*)CalculatePearsonCoefficients(&covarianceMatrix);
d7ec324f 794 if(pearson) {
549b5f40 795 TH2D* hPearson(new TH2D(*pearson));
d7ec324f 796 pearson->Print();
797 hPearson->SetNameTitle(Form("PearsonCoefficients_%s", suffix.Data()), Form("Pearson coefficients_%s", suffix.Data()));
798 hPearson = ProtectHeap(hPearson);
799 hPearson->Write();
549b5f40 800 } else return 0x0; // return if unfolding didn't converge
d7ec324f 801
549b5f40
RAB
802 // 5) refold the unfolded spectrum
803 foldedLocalBayes = fResponseMaker->MultiplyResponseGenerated(unfoldedLocalBayes, resizedResponseLocalNorm, kinematicEfficiencyLocal);
804 TGraphErrors* ratio(GetRatio(measuredJetSpectrumLocal, foldedLocalBayes, "ratio measured / re-folded", kTRUE));
805 ratio->SetNameTitle(Form("RatioRefoldedMeasured_%s", fActiveString.Data()), Form("Ratio measured / re-folded %s", fActiveString.Data()));
d7ec324f 806 ratio->GetXaxis()->SetTitle("p_{t}^{rec, rec} [GeV/ c]");
807 ratio->GetYaxis()->SetTitle("ratio measured / re-folded");
808 ratio->Write();
809 cout << " 7) refolded the unfolded spectrum " << endl;
810
549b5f40
RAB
811 // write the measured, unfolded and re-folded spectra to the output directory
812 measuredJetSpectrumLocal->SetNameTitle(Form("InputSpectrum_%s", suffix.Data()), Form("input spectrum (measured) %s", suffix.Data()));
813 measuredJetSpectrumLocal = ProtectHeap(measuredJetSpectrumLocal);
814 measuredJetSpectrumLocal->SetXTitle("p_{t}^{rec} [GeV/c]");
815 measuredJetSpectrumLocal->Write(); // input spectrum
816 unfoldedLocalBayes->SetNameTitle(Form("UnfoldedSpectrum_%s",suffix.Data()), Form("unfolded spectrum %s", suffix.Data()));
817 unfoldedLocalBayes = ProtectHeap(unfoldedLocalBayes);
818 if(jetFindingEfficiency) unfoldedLocalBayes->Divide(jetFindingEfficiency);
819 unfoldedLocalBayes->Write(); // unfolded spectrum
820 foldedLocalBayes->SetNameTitle(Form("RefoldedSpectrum_%s", suffix.Data()), Form("refoldedSpectrum_%s", suffix.Data()));
821 foldedLocalBayes = ProtectHeap(foldedLocalBayes);
822 foldedLocalBayes->Write(); // re-folded spectrum
823
824 // save more general bookkeeeping histograms to the output directory
825 responseMatrixLocalTransposePrior->SetNameTitle("TransposeResponseMatrix", "Transpose of response matrix, normalize with prior");
f3ba6c8e 826 responseMatrixLocalTransposePrior->SetXTitle("p_{T, jet}^{true} [GeV/c]");
827 responseMatrixLocalTransposePrior->SetYTitle("p_{T, jet}^{rec} [GeV/c]");
d7ec324f 828 responseMatrixLocalTransposePrior->Write();
549b5f40
RAB
829 priorLocal->SetNameTitle("PriorOriginal", "Prior, original");
830 priorLocal->SetXTitle("p_{t} [GeV/c]");
831 priorLocal = ProtectHeap(priorLocal);
832 priorLocal->Write();
833 resizedResponseLocalNorm = ProtectHeap(resizedResponseLocalNorm);
834 resizedResponseLocalNorm->Write();
53547ff2
RAB
835
836 // save some info
837 TH1F* fitStatus(new TH1F(Form("fitStatus_%s_%s", fActiveString.Data(), suffix.Data()), Form("fitStatus_%s_%s", fActiveString.Data(), suffix.Data()), 1, -0.5, 0.5));
549b5f40
RAB
838 fitStatus->SetBinContent(1, (!strcmp(suffix.Data(), "in")) ? fBayesianIterIn : fBayesianIterOut);
839 fitStatus->GetXaxis()->SetBinLabel(1, (!strcmp(suffix.Data(), "in")) ? "fBayesianIterIn" : "fBayesianIterOut");
53547ff2
RAB
840 fitStatus->Write();
841
549b5f40 842 return unfoldedLocalBayes;
d7ec324f 843}
844//_____________________________________________________________________________
dc1455ee 845Bool_t AliJetFlowTools::PrepareForUnfolding()
846{
847 // prepare for unfolding
4292ca60 848 if(fRawInputProvided) return kTRUE;
dc1455ee 849 if(!fInputList) {
850 printf(" AliJetFlowTools::PrepareForUnfolding() fInputList not found \n - Set a list using AliJetFlowTools::SetInputList() \n");
851 return kFALSE;
852 }
549b5f40 853 if(!fDetectorResponse) printf(" WARNING, no detector response supplied ! May be ok (depending on what you want to do) \n ");
4292ca60 854 // check if the pt bin for true and rec have been set
855 if(!fBinsTrue || !fBinsRec) {
856 printf(" AliJetFlowTools::PrepareForUnfolding() no true or rec bins set, aborting ! \n");
857 return kFALSE;
dc1455ee 858 }
486fb24e 859 if(!fRMSSpectrumIn && fDphiUnfolding) { // initialie the profiles which will hold the RMS values. if binning changes in between unfolding
4292ca60 860 // procedures, these profiles will be nonsensical, user is responsible
861 fRMSSpectrumIn = new TProfile("fRMSSpectrumIn", "fRMSSpectrumIn", fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
862 fRMSSpectrumOut = new TProfile("fRMSSpectrumOut", "fRMSSpectrumOut", fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
863 fRMSRatio = new TProfile("fRMSRatio", "fRMSRatio", fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
dc1455ee 864 }
ef12d5a5 865 if(!fTrainPower) {
549b5f40 866 // clear minuit state to avoid constraining the fit with the results of the previous iteration
ef12d5a5 867 for(Int_t i(0); i < fPower->GetNpar(); i++) fPower->SetParameter(i, 0.);
868 }
c03f7598 869 // extract the spectra
870 TString spectrumName(Form("fHistJetPsi2Pt_%i", fCentralityArray->At(0)));
871 if(!fInputList->FindObject(spectrumName.Data())) {
dc1455ee 872 printf(" Couldn't find spectrum %s ! \n", spectrumName.Data());
873 return kFALSE;
874 }
67d11165 875
c03f7598 876 // get the first scaled spectrum
877 fJetPtDeltaPhi = (TH2D*)fInputList->FindObject(spectrumName.Data());
878 // clone the spectrum on the heap. this is necessary since scale or add change the
879 // contents of the original histogram
4292ca60 880 fJetPtDeltaPhi = ProtectHeap(fJetPtDeltaPhi, kFALSE);
c03f7598 881 fJetPtDeltaPhi->Scale(fCentralityWeights->At(0));
24005d85 882 printf("Extracted %s wight weight %.2f \n", spectrumName.Data(), fCentralityWeights->At(0));
c03f7598 883 // merge subsequent bins (if any)
884 for(Int_t i(1); i < fCentralityArray->GetSize(); i++) {
885 spectrumName = Form("fHistJetPsi2Pt_%i", fCentralityArray->At(i));
886 printf( " Merging with %s with weight %.4f \n", spectrumName.Data(), fCentralityWeights->At(i));
887 fJetPtDeltaPhi->Add(((TH2D*)fInputList->FindObject(spectrumName.Data())), fCentralityWeights->At(i));
888 }
889
dc1455ee 890 // in plane spectrum
486fb24e 891 if(!fDphiUnfolding) {
5e11c41c 892 fSpectrumIn = fJetPtDeltaPhi->ProjectionY(Form("_py_in_%s", spectrumName.Data()), 1, 40, "e");
893 fSpectrumOut = fJetPtDeltaPhi->ProjectionY(Form("_py_out_%s", spectrumName.Data()), 1, 40, "e");
ef12d5a5 894 } else {
5e11c41c 895 fSpectrumIn = fJetPtDeltaPhi->ProjectionY(Form("_py_ina_%s", spectrumName.Data()), 1, 10, "e");
896 fSpectrumIn->Add(fJetPtDeltaPhi->ProjectionY(Form("_py_inb_%s", spectrumName.Data()), 31, 40, "e"));
ef12d5a5 897 fSpectrumIn = ProtectHeap(fSpectrumIn);
898 // out of plane spectrum
5e11c41c 899 fSpectrumOut = fJetPtDeltaPhi->ProjectionY(Form("_py_out_%s", spectrumName.Data()), 11, 30, "e");
ef12d5a5 900 fSpectrumOut = ProtectHeap(fSpectrumOut);
901 }
20abfcc4 902 // normalize spectra to event count if requested
903 if(fNormalizeSpectra) {
c03f7598 904 TH1* rho((TH1*)fInputList->FindObject(Form("fHistRho_%i", fCentralityArray->At(0))));
905 rho->Scale(fCentralityWeights->At(0));
906 for(Int_t i(1); i < fCentralityArray->GetSize(); i++) {
907 rho->Add((TH1*)fInputList->FindObject(Form("fHistRho_%i", fCentralityArray->At(i))), fCentralityWeights->At(i));
67d11165 908 }
ef12d5a5 909 if(!rho) return 0x0;
910 Bool_t normalizeToFullSpectrum = (fEventCount < 0) ? kTRUE : kFALSE;
911 if (normalizeToFullSpectrum) fEventCount = rho->GetEntries();
20abfcc4 912 if(fEventCount > 0) {
4292ca60 913 fSpectrumIn->Sumw2(); // necessary for correct error propagation of scale
914 fSpectrumOut->Sumw2();
ef12d5a5 915 Double_t pt(0);
d7ec324f 916 Double_t error(0); // lots of issues with the errors here ...
ef12d5a5 917 for(Int_t i(0); i < fSpectrumIn->GetXaxis()->GetNbins(); i++) {
4292ca60 918 pt = fSpectrumIn->GetBinContent(1+i)/fEventCount; // normalized count
d7ec324f 919 error = 1./((double)(fEventCount*fEventCount))*fSpectrumIn->GetBinError(1+i)*fSpectrumIn->GetBinError(1+i);
4292ca60 920 fSpectrumIn->SetBinContent(1+i, pt);
ef12d5a5 921 if(pt <= 0 ) fSpectrumIn->SetBinError(1+i, 0.);
d7ec324f 922 if(error > 0) fSpectrumIn->SetBinError(1+i, error);
ef12d5a5 923 else fSpectrumIn->SetBinError(1+i, TMath::Sqrt(pt));
4292ca60 924 }
ef12d5a5 925 for(Int_t i(0); i < fSpectrumOut->GetXaxis()->GetNbins(); i++) {
926 pt = fSpectrumOut->GetBinContent(1+i)/fEventCount; // normalized count
d7ec324f 927 error = 1./((double)(fEventCount*fEventCount))*fSpectrumOut->GetBinError(1+i)*fSpectrumOut->GetBinError(1+i);
ef12d5a5 928 fSpectrumOut->SetBinContent(1+i, pt);
929 if( pt <= 0) fSpectrumOut->SetBinError(1+i, 0.);
d7ec324f 930 if(error > 0) fSpectrumOut->SetBinError(1+i, error);
ef12d5a5 931 else fSpectrumOut->SetBinError(1+i, TMath::Sqrt(pt));
4292ca60 932 }
20abfcc4 933 }
ef12d5a5 934 if(normalizeToFullSpectrum) fEventCount = -1;
20abfcc4 935 }
dc1455ee 936 // extract the delta pt matrices
486fb24e 937 TString deltaptName("");
c03f7598 938 deltaptName += (fExLJDpt) ? Form("fHistDeltaPtDeltaPhi2ExLJ_%i", fCentralityArray->At(0)) : Form("fHistDeltaPtDeltaPhi2_%i", fCentralityArray->At(0));
ad04a83c 939 fDeltaPtDeltaPhi = ((TH2D*)fInputList->FindObject(deltaptName.Data()));
940 if(!fDeltaPtDeltaPhi) {
dc1455ee 941 printf(" Couldn't find delta pt matrix %s ! \n", deltaptName.Data());
549b5f40
RAB
942 printf(" > may be ok, depending no what you want to do < \n");
943 fRefreshInput = kTRUE;
944 return kTRUE;
dc1455ee 945 }
67d11165 946
c03f7598 947 // clone the distribution on the heap and if requested merge with other centralities
4292ca60 948 fDeltaPtDeltaPhi = ProtectHeap(fDeltaPtDeltaPhi, kFALSE);
c03f7598 949 fDeltaPtDeltaPhi->Scale(fCentralityWeights->At(0));
950 printf("Extracted %s with weight %.2f \n", deltaptName.Data(), fCentralityWeights->At(0));
951 for(Int_t i(1); i < fCentralityArray->GetSize(); i++) {
952 deltaptName = (fExLJDpt) ? Form("fHistDeltaPtDeltaPhi2ExLJ_%i", fCentralityArray->At(i)) : Form("fHistDeltaPtDeltaPhi2_%i", fCentralityArray->At(i));
953 printf(" Merging with %s with weight %.4f \n", deltaptName.Data(), fCentralityWeights->At(i));
954 fDeltaPtDeltaPhi->Add((TH2D*)fInputList->FindObject(deltaptName.Data()), fCentralityWeights->At(i));
955 }
956
4292ca60 957 // in plane delta pt distribution
486fb24e 958 if(!fDphiUnfolding) {
5e11c41c 959 fDptInDist = fDeltaPtDeltaPhi->ProjectionY(Form("_py_in_%s", deltaptName.Data()), 1, 40, "e");
960 fDptOutDist = fDeltaPtDeltaPhi->ProjectionY(Form("_py_out_%s", deltaptName.Data()), 1, 40, "e");
ef12d5a5 961 } else {
5e11c41c 962 fDptInDist = fDeltaPtDeltaPhi->ProjectionY(Form("_py_ina_%s", deltaptName.Data()), 1, 10, "e");
963 fDptInDist->Add(fDeltaPtDeltaPhi->ProjectionY(Form("_py_inb_%s", deltaptName.Data()), 31, 40, "e"));
ef12d5a5 964 // out of plane delta pt distribution
5e11c41c 965 fDptOutDist = fDeltaPtDeltaPhi->ProjectionY(Form("_py_out_%s", deltaptName.Data()), 11, 30, "e");
ef12d5a5 966 fDptInDist = ProtectHeap(fDptInDist);
967 fDptOutDist = ProtectHeap(fDptOutDist);
968 // TODO get dpt response matrix from ConstructDPtResponseFromTH1D
969 }
4292ca60 970
dc1455ee 971 // create a rec - true smeared response matrix
972 TMatrixD* rfIn = new TMatrixD(-50, 249, -50, 249);
973 for(Int_t j(-50); j < 250; j++) { // loop on pt true slices j
ad04a83c 974 Bool_t skip = kFALSE;
dc1455ee 975 for(Int_t k(-50); k < 250; k++) { // loop on pt gen slices k
ad04a83c 976 (*rfIn)(k, j) = (skip) ? 0. : fDptInDist->GetBinContent(fDptInDist->GetXaxis()->FindBin(k-j));
977 if(fAvoidRoundingError && k > j && TMath::AreEqualAbs(fDptInDist->GetBinContent(fDptInDist->GetXaxis()->FindBin(k-j)), 0, 1e-8)) skip = kTRUE;
dc1455ee 978 }
979 }
980 TMatrixD* rfOut = new TMatrixD(-50, 249, -50, 249);
981 for(Int_t j(-50); j < 250; j++) { // loop on pt true slices j
ad04a83c 982 Bool_t skip = kFALSE;
dc1455ee 983 for(Int_t k(-50); k < 250; k++) { // loop on pt gen slices k
ad04a83c 984 (*rfOut)(k, j) = (skip) ? 0. : fDptOutDist->GetBinContent(fDptOutDist->GetXaxis()->FindBin(k-j));
985 if(fAvoidRoundingError && k > j && TMath::AreEqualAbs(fDptOutDist->GetBinContent(fDptOutDist->GetXaxis()->FindBin(k-j)), 0, 1e-8)) skip = kTRUE;
dc1455ee 986 }
987 }
988 fDptIn = new TH2D(*rfIn);
c03f7598 989 fDptIn->SetNameTitle(Form("dpt_response_INPLANE_%i", fCentralityArray->At(0)), Form("dpt_response_INPLANE_%i", fCentralityArray->At(0)));
f3ba6c8e 990 fDptIn->GetXaxis()->SetTitle("p_{T, jet}^{gen} [GeV/c]");
991 fDptIn->GetYaxis()->SetTitle("p_{T, jet}^{rec} [GeV/c]");
4292ca60 992 fDptIn = ProtectHeap(fDptIn);
dc1455ee 993 fDptOut = new TH2D(*rfOut);
c03f7598 994 fDptOut->SetNameTitle(Form("dpt_response_OUTOFPLANE_%i", fCentralityArray->At(0)), Form("dpt_response_OUTOFPLANE_%i", fCentralityArray->At(0)));
f3ba6c8e 995 fDptOut->GetXaxis()->SetTitle("p_{T, jet}^{gen} [GeV/c]");
996 fDptOut->GetYaxis()->SetTitle("p_{T, jet}^{rec} [GeV/c]");
4292ca60 997 fDptOut = ProtectHeap(fDptOut);
998
999 fRefreshInput = kTRUE; // force cloning of the input
dc1455ee 1000 return kTRUE;
1001}
1002//_____________________________________________________________________________
486fb24e 1003Bool_t AliJetFlowTools::PrepareForUnfolding(Int_t low, Int_t up) {
1004 // prepare for unfoldingUA - more robust method to extract input spectra from file
1005 // will replace PrepareForUnfolding eventually (09012014)
1006 if(!fInputList) {
1007 printf(" AliJetFlowTools::PrepareForUnfolding() fInputList not found \n - Set a list using AliJetFlowTools::SetInputList() \n");
1008 return kFALSE;
1009 }
1010 if(!fDetectorResponse) printf(" WARNING, no detector response supplied ! May be ok (depending on what you want to do) \n ");
1011 // check if the pt bin for true and rec have been set
1012 if(!fBinsTrue || !fBinsRec) {
1013 printf(" AliJetFlowTools::PrepareForUnfolding() no true or rec bins set, aborting ! \n");
1014 return kFALSE;
1015 }
1016 if(!fTrainPower) {
1017 // clear minuit state to avoid constraining the fit with the results of the previous iteration
1018 for(Int_t i(0); i < fPower->GetNpar(); i++) fPower->SetParameter(i, 0.);
1019 }
1020 // extract the spectra
c03f7598 1021 TString spectrumName(Form("fHistJetPsi2Pt_%i", fCentralityArray->At(0)));
486fb24e 1022 fJetPtDeltaPhi = ((TH2D*)fInputList->FindObject(spectrumName.Data()));
1023 if(!fJetPtDeltaPhi) {
1024 printf(" Couldn't find spectrum %s ! \n", spectrumName.Data());
1025 return kFALSE;
1026 }
67d11165 1027 if(fCentralityArray) {
1028 for(Int_t i(1); i < fCentralityArray->GetSize(); i++) {
1029 spectrumName = Form("fHistJetPsi2Pt_%i", fCentralityArray->At(i));
1030 fJetPtDeltaPhi->Add(((TH2D*)fInputList->FindObject(spectrumName.Data())));
1031 }
1032 }
486fb24e 1033 fJetPtDeltaPhi = ProtectHeap(fJetPtDeltaPhi, kFALSE);
1034 // in plane spectrum
1035 fSpectrumIn = fJetPtDeltaPhi->ProjectionY(Form("_py_in_%s", spectrumName.Data()), low, up, "e");
1036 // extract the delta pt matrices
1037 TString deltaptName("");
c03f7598 1038 deltaptName += (fExLJDpt) ? Form("fHistDeltaPtDeltaPhi2ExLJ_%i", fCentralityArray->At(0)) : Form("fHistDeltaPtDeltaPhi2_%i", fCentralityArray->At(0));
486fb24e 1039 fDeltaPtDeltaPhi = ((TH2D*)fInputList->FindObject(deltaptName.Data()));
1040 if(!fDeltaPtDeltaPhi) {
1041 printf(" Couldn't find delta pt matrix %s ! \n", deltaptName.Data());
1042 printf(" > may be ok, depending no what you want to do < \n");
1043 fRefreshInput = kTRUE;
1044 return kTRUE;
1045 }
67d11165 1046 if(fCentralityArray) {
1047 for(Int_t i(1); i < fCentralityArray->GetSize(); i++) {
1048 deltaptName += (fExLJDpt) ? Form("fHistDeltaPtDeltaPhi2ExLJ_%i", fCentralityArray->At(i)) : Form("fHistDeltaPtDeltaPhi2_%i", fCentralityArray->At(i));
1049 fDeltaPtDeltaPhi->Add(((TH2D*)fInputList->FindObject(deltaptName.Data())));
1050 }
1051 }
1052
486fb24e 1053 fDeltaPtDeltaPhi = ProtectHeap(fDeltaPtDeltaPhi, kFALSE);
1054 // in plane delta pt distribution
1055 fDptInDist = fDeltaPtDeltaPhi->ProjectionY(Form("_py_in_%s", deltaptName.Data()), low, up, "e");
1056 // create a rec - true smeared response matrix
1057 TMatrixD* rfIn = new TMatrixD(-50, 249, -50, 249);
1058 for(Int_t j(-50); j < 250; j++) { // loop on pt true slices j
1059 Bool_t skip = kFALSE;
1060 for(Int_t k(-50); k < 250; k++) { // loop on pt gen slices k
1061 (*rfIn)(k, j) = (skip) ? 0. : fDptInDist->GetBinContent(fDptInDist->GetXaxis()->FindBin(k-j));
1062 if(fAvoidRoundingError && k > j && TMath::AreEqualAbs(fDptInDist->GetBinContent(fDptInDist->GetXaxis()->FindBin(k-j)), 0, 1e-8)) skip = kTRUE;
1063 }
1064 }
1065 fDptIn = new TH2D(*rfIn);
c03f7598 1066 fDptIn->SetNameTitle(Form("dpt_response_INPLANE_%i", fCentralityArray->At(0)), Form("dpt_response_INPLANE_%i", fCentralityArray->At(0)));
f3ba6c8e 1067 fDptIn->GetXaxis()->SetTitle("p_{T, jet}^{gen} [GeV/c]");
1068 fDptIn->GetYaxis()->SetTitle("p_{T, jet}^{rec} [GeV/c]");
486fb24e 1069 fDptIn = ProtectHeap(fDptIn);
1070
1071 return kTRUE;
1072}
1073//_____________________________________________________________________________
549b5f40
RAB
1074TH1D* AliJetFlowTools::GetPrior(
1075 const TH1D* measuredJetSpectrum, // jet pt in pt rec bins
1076 const TH2D* resizedResponse, // full response matrix, normalized in slides of pt true
1077 const TH1D* kinematicEfficiency, // kinematic efficiency
1078 const TH1D* measuredJetSpectrumTrueBins, // jet pt in pt true bins, also the prior when measured is chosen as prior
1079 const TString suffix, // suffix (in, out)
1080 const TH1D* jetFindingEfficiency) // jet finding efficiency (optional)
1081{
1082 // 1) get a prior for unfolding.
1083 // this can be either an unfolded spectrum from e.g. chi2 unfolding or the measured spectrum
1084 TH1D* unfolded(0x0);
1085 TDirectoryFile* dirOut = new TDirectoryFile(Form("Prior_%s___%s", suffix.Data(), fActiveString.Data()), Form("Prior_%s___%s", suffix.Data(), fActiveString.Data()));
1086 dirOut->cd();
1087 switch (fPrior) { // select the prior for unfolding
18698978 1088 case kPriorPythia : {
1089 if(!fPriorUser) {
1090 printf("> GetPrior:: FATAL ERROR! pythia prior requested but prior has not been set ! < \n");
1091 return 0x0;
1092 }
1093 // rebin the given prior to the true spectrum (creates a new histo)
1094 return RebinTH1D(fPriorUser, fBinsTrue, Form("kPriorPythia_%s", suffix.Data()), kFALSE);
1095 } break;
549b5f40
RAB
1096 case kPriorChi2 : {
1097 if(fBinsTruePrior && fBinsRecPrior) { // if set, use different binning for the prior
1098 TArrayD* tempArrayTrue(fBinsTrue); // temporarily cache the original binning
1099 fBinsTrue = fBinsTruePrior; // switch binning schemes (will be used in UnfoldSpectrumChi2())
1100 TArrayD* tempArrayRec(fBinsRec);
1101 fBinsRec = fBinsRecPrior;
1102 TH1D* measuredJetSpectrumChi2 = RebinTH1D((!strcmp("in", suffix.Data())) ? fSpectrumIn : fSpectrumOut, fBinsRec, TString("resized_chi2"), kFALSE);
1103 TH1D* measuredJetSpectrumTrueBinsChi2 = RebinTH1D((!strcmp("in", suffix.Data())) ? fSpectrumIn : fSpectrumOut, fBinsTruePrior, TString("out"), kFALSE);
1104 TH2D* resizedResponseChi2(RebinTH2D((!strcmp("in", suffix.Data())) ? fFullResponseIn : fFullResponseOut,fBinsTruePrior, fBinsRec, TString("chi2")));
1105 TH1D* kinematicEfficiencyChi2(resizedResponseChi2->ProjectionX());
1106 kinematicEfficiencyChi2->SetNameTitle("kin_eff_chi2","kin_eff_chi2");
1107 for(Int_t i(0); i < kinematicEfficiencyChi2->GetXaxis()->GetNbins(); i++) kinematicEfficiencyChi2->SetBinError(1+i, 0.);
1108 unfolded= UnfoldSpectrumChi2(
1109 measuredJetSpectrumChi2,
1110 resizedResponseChi2,
1111 kinematicEfficiencyChi2,
1112 measuredJetSpectrumTrueBinsChi2, // prior for chi2 unfolding (measured)
1113 TString(Form("prior_%s", suffix.Data())));
1114 if(!unfolded) {
1115 printf(" > GetPrior:: panic, couldn't get prior from Chi2 unfolding! \n");
1116 printf(" probably Chi2 unfolding did not converge < \n");
1117 return 0x0;
1118 }
1119 fBinsTrue = tempArrayTrue; // reset bins borders
1120 fBinsRec = tempArrayRec;
1121 // if the chi2 prior has a different binning, rebin to the true binning for the unfolding
1122 unfolded = RebinTH1D(unfolded, fBinsTrue, TString(Form("unfoldedChi2Prior_%s", suffix.Data()))); // rebin unfolded
1123 } else {
1124 unfolded = UnfoldSpectrumChi2(
1125 measuredJetSpectrum,
1126 resizedResponse,
1127 kinematicEfficiency,
1128 measuredJetSpectrumTrueBins, // prior for chi2 unfolding (measured)
1129 TString(Form("prior_%s", suffix.Data())));
1130 if(!unfolded) {
1131 printf(" > GetPrior:: panic, couldn't get prior from Chi2 unfolding! \n");
1132 printf(" probably Chi2 unfolding did not converge < \n");
1133 return 0x0;
1134 }
1135 }
1136 break;
1137 }
1138 case kPriorMeasured : {
1139 unfolded = (TH1D*)measuredJetSpectrumTrueBins->Clone(Form("kPriorMeasured_%s", suffix.Data())); // copy template to unfolded to use as prior
1140 }
1141 default : break;
1142 }
1143 // it can be important that the prior is smooth, this can be achieved by
1144 // extrapolating the spectrum with a fitted power law when bins are sparsely filed
1145 if(jetFindingEfficiency) unfolded->Divide(jetFindingEfficiency);
1146 TH1D *priorLocal((TH1D*)unfolded->Clone(Form("priorUnfolded_%s", suffix.Data())));
1147 if(fSmoothenPrior) priorLocal = SmoothenPrior(priorLocal, fPower, fFitMin, fFitMax, fFitStart, kTRUE, fSmoothenCounts);
1148 return priorLocal;
1149}
1150//_____________________________________________________________________________
dc1455ee 1151TH1D* AliJetFlowTools::ResizeXaxisTH1D(TH1D* histo, Int_t low, Int_t up, TString suffix) {
1152 // resize the x-axis of a th1d
1153 if(!histo) {
1154 printf(" > ResizeXaxisTH!D:: fatal error, NULL pointer passed < \n");
1155 return NULL;
1156 }
1157 // see how many bins we need to copy
1158 TH1D* resized = new TH1D(Form("%s_resized_%s", histo->GetName(), suffix.Data()), Form("%s_resized_%s", histo->GetName(), suffix.Data()), up-low, (double)low, (double)up);
1159 // low is the bin number of the first new bin
1160 Int_t l = histo->GetXaxis()->FindBin(low);
1161 // set the values
1162 Double_t _x(0), _xx(0);
1163 for(Int_t i(0); i < up-low; i++) {
1164 _x = histo->GetBinContent(l+i);
1165 _xx=histo->GetBinError(l+i);
1166 resized->SetBinContent(i+1, _x);
1167 resized->SetBinError(i+1, _xx);
1168 }
1169 return resized;
1170}
1171//_____________________________________________________________________________
1172TH2D* AliJetFlowTools::ResizeYaxisTH2D(TH2D* histo, TArrayD* x, TArrayD* y, TString suffix) {
1173 // resize the y-axis of a th2d
1174 if(!histo) {
1175 printf(" > ResizeYaxisTH2D:: fatal error, NULL pointer passed < \n");
1176 return NULL;
1177 }
1178 // see how many bins we need to copy
1179 TH2D* resized = new TH2D(Form("%s_resized_%s", histo->GetName(), suffix.Data()), Form("%s_resized_%s", histo->GetName(), suffix.Data()), x->GetSize()-1, x->GetArray(), y->GetSize()-1, y->GetArray());
1180 // assume only the y-axis has changed
1181 // low is the bin number of the first new bin
1182 Int_t low = histo->GetYaxis()->FindBin(y->At(0));
1183 // set the values
1184 Double_t _x(0), _xx(0);
1185 for(Int_t i(0); i < x->GetSize(); i++) {
1186 for(Int_t j(0); j < y->GetSize(); j++) {
1187 _x = histo->GetBinContent(i, low+j);
1188 _xx=histo->GetBinError(i, low+1+j);
1189 resized->SetBinContent(i, j, _x);
1190 resized->SetBinError(i, j, _xx);
1191 }
1192 }
1193 return resized;
1194}
1195//_____________________________________________________________________________
512ced40 1196TH2D* AliJetFlowTools::NormalizeTH2D(TH2D* histo, Bool_t noError) {
dc1455ee 1197 // general method to normalize all vertical slices of a th2 to unity
1198 // i.e. get a probability matrix
1199 if(!histo) {
1200 printf(" > NormalizeTH2D:: fatal error, NULL pointer passed < \n");
1201 return NULL;
1202 }
1203 Int_t binsX = histo->GetXaxis()->GetNbins();
1204 Int_t binsY = histo->GetYaxis()->GetNbins();
1205
1206 // normalize all slices in x
1207 for(Int_t i(0); i < binsX; i++) { // for each vertical slice
1208 Double_t weight = 0;
1209 for(Int_t j(0); j < binsY; j++) { // loop over all the horizontal components
1210 weight+=histo->GetBinContent(i+1, j+1);
1211 } // now we know the total weight
1212 for(Int_t j(0); j < binsY; j++) {
1213 if (weight <= 0 ) continue;
1214 histo->SetBinContent(1+i, j+1, histo->GetBinContent(1+i, j+1)/weight);
512ced40
RAB
1215 if(noError) histo->SetBinError( 1+i, j+1, 0.);
1216 else histo->SetBinError( 1+i, j+1, histo->GetBinError( 1+i, j+1)/weight);
dc1455ee 1217 }
1218 }
1219 return histo;
1220}
1221//_____________________________________________________________________________
53547ff2 1222TH1D* AliJetFlowTools::RebinTH1D(TH1D* histo, TArrayD* bins, TString suffix, Bool_t kill) {
dc1455ee 1223 // return a TH1D with the supplied histogram rebinned to the supplied bins
53547ff2 1224 // the returned histogram is new, the original is deleted from the heap if kill is true
dc1455ee 1225 if(!histo || !bins) {
53547ff2 1226 printf(" > RebinTH1D:: fatal error, NULL pointer passed < \n");
dc1455ee 1227 return NULL;
1228 }
1229 // create the output histo
1230 TString name = histo->GetName();
1231 name+="_template";
1232 name+=suffix;
1233 TH1D* rebinned = new TH1D(name.Data(), name.Data(), bins->GetSize()-1, bins->GetArray());
1234 for(Int_t i(0); i < histo->GetXaxis()->GetNbins(); i++) {
4292ca60 1235 // loop over the bins of the old histo and fill the new one with its data
1236 rebinned->Fill(histo->GetBinCenter(i+1), histo->GetBinContent(i+1));
dc1455ee 1237 }
53547ff2 1238 if(kill) delete histo;
dc1455ee 1239 return rebinned;
1240}
1241//_____________________________________________________________________________
4292ca60 1242TH2D* AliJetFlowTools::RebinTH2D(TH2D* rebinMe, TArrayD* binsTrue, TArrayD* binsRec, TString suffix) {
53547ff2 1243 // weighted rebinning of a th2d, implementation for function call to AliAnaChargedJetResponseMaker
4292ca60 1244 if(!fResponseMaker || !binsTrue || !binsRec) {
1245 printf(" > RebinTH2D:: function called with NULL arguments < \n");
1246 return 0x0;
dc1455ee 1247 }
4292ca60 1248 TString name(Form("%s_%s", rebinMe->GetName(), suffix.Data()));
1249 return (TH2D*)fResponseMaker->MakeResponseMatrixRebin(rebinMe, (TH2*)(new TH2D(name.Data(), name.Data(), binsTrue->GetSize()-1, binsTrue->GetArray(), binsRec->GetSize()-1, binsRec->GetArray())), kTRUE);
dc1455ee 1250}
1251//_____________________________________________________________________________
d7ec324f 1252TH2D* AliJetFlowTools::MatrixMultiplication(TH2D* a, TH2D* b, TString name)
1253{
1254 // multiply two matrices
1255 if (a->GetNbinsX() != b->GetNbinsY()) return 0x0;
1256 TH2D* c = (TH2D*)a->Clone("c");
1257 for (Int_t y1 = 1; y1 <= a->GetNbinsY(); y1++) {
1258 for (Int_t x2 = 1; x2 <= b->GetNbinsX(); x2++) {
1259 Double_t val = 0;
1260 for (Int_t x1 = 1; x1 <= a->GetNbinsX(); x1++) {
1261 Int_t y2 = x1;
1262 val += a->GetBinContent(x1, y1) * b->GetBinContent(x2, y2);
1263 }
1264 c->SetBinContent(x2, y1, val);
512ced40 1265 c->SetBinError(x2, y1, 0.);
dc1455ee 1266 }
1267 }
d7ec324f 1268 if(strcmp(name.Data(), "")) c->SetNameTitle(name.Data(), name.Data());
1269 return c;
dc1455ee 1270}
1271//_____________________________________________________________________________
d7ec324f 1272TH1D* AliJetFlowTools::NormalizeTH1D(TH1D* histo, Double_t scale)
1273{
dc1455ee 1274 // normalize a th1d to a certain scale
4292ca60 1275 histo->Sumw2();
1276 Double_t integral = histo->Integral()*scale;
1277 if (integral > 0 && scale == 1.) histo->Scale(1./integral, "width");
1278 else if (scale != 1.) histo->Scale(1./scale, "width");
1279 else printf(" > Histogram integral < 0, cannot normalize \n");
1280 return histo;
dc1455ee 1281}
1282//_____________________________________________________________________________
51e6bc5a 1283TMatrixD* AliJetFlowTools::CalculatePearsonCoefficients(TMatrixD* covarianceMatrix)
dc1455ee 1284{
1285 // Calculate pearson coefficients from covariance matrix
51e6bc5a 1286 TMatrixD *pearsonCoefficients((TMatrixD*)covarianceMatrix->Clone("pearsonCoefficients"));
1287 Int_t nrows(covarianceMatrix->GetNrows()), ncols(covarianceMatrix->GetNcols());
ad04a83c 1288 Double_t pearson(0.);
dc1455ee 1289 if(nrows==0 && ncols==0) return 0x0;
ef12d5a5 1290 for(Int_t row = 0; row < nrows; row++) {
1291 for(Int_t col = 0; col<ncols; col++) {
51e6bc5a 1292 if((*covarianceMatrix)(row,row)!=0. && (*covarianceMatrix)(col,col)!=0.) pearson = (*covarianceMatrix)(row,col)/TMath::Sqrt((*covarianceMatrix)(row,row)*(*covarianceMatrix)(col,col));
1293 (*pearsonCoefficients)(row,col) = pearson;
dc1455ee 1294 }
1295 }
51e6bc5a 1296 return pearsonCoefficients;
dc1455ee 1297}
1298//_____________________________________________________________________________
549b5f40 1299TH1D* AliJetFlowTools::SmoothenPrior(TH1D* spectrum, TF1* function, Double_t min, Double_t max, Double_t start, Bool_t kill, Bool_t counts) {
d7ec324f 1300 // smoothen the spectrum using a user defined function
1301 // returns a clone of the original spectrum if fitting failed
1302 // if kill is kTRUE the input spectrum will be deleted from the heap
1303 // if 'count' is selected, bins are filled with integers (necessary if the
1304 // histogram is interpreted in a routine which accepts only counts)
549b5f40
RAB
1305 if(!spectrum || !function) return 0x0;
1306 if(start > max) printf(" > cannot extrapolate fit beyond fit range ! < " );
d7ec324f 1307 TH1D* temp = (TH1D*)spectrum->Clone(Form("%s_smoothened", spectrum->GetName()));
1308 temp->Sumw2(); // if already called on the original, this will give off a warning but do nothing
87233f72 1309 TFitResultPtr r = temp->Fit(function, "", "", min, max);
d7ec324f 1310 if((int)r == 0) { // MINUIT status
1311 for(Int_t i(0); i < temp->GetNbinsX() + 1; i++) {
1312 if(temp->GetBinCenter(i) > start) { // from this pt value use extrapolation
486fb24e 1313 (counts) ? temp->SetBinContent(i, (int)(function->Integral(temp->GetXaxis()->GetBinLowEdge(i),temp->GetXaxis()->GetBinUpEdge(i))/temp->GetXaxis()->GetBinWidth(i))) : temp->SetBinContent(i, function->Integral(temp->GetXaxis()->GetBinLowEdge(i),temp->GetXaxis()->GetBinUpEdge(i))/temp->GetXaxis()->GetBinWidth(i));
d7ec324f 1314 if(temp->GetBinContent(i) > 0) temp->SetBinError(i, TMath::Sqrt(temp->GetBinContent(i)));
1315 }
1316 }
1317 }
1318 if(kill) delete spectrum;
1319 return temp;
1320}
1321//_____________________________________________________________________________
18698978 1322void AliJetFlowTools::Style()
1323{
1324 // set global style for your current aliroot session
1325 if(!gStyle) return;
1326 gStyle->SetCanvasColor(-1);
1327 gStyle->SetPadColor(-1);
1328 gStyle->SetFrameFillColor(-1);
1329 gStyle->SetHistFillColor(-1);
1330 gStyle->SetTitleFillColor(-1);
1331 gStyle->SetFillColor(-1);
1332 gStyle->SetFillStyle(4000);
1333 gStyle->SetStatStyle(0);
1334 gStyle->SetTitleStyle(0);
1335 gStyle->SetCanvasBorderSize(0);
1336 gStyle->SetFrameBorderSize(0);
1337 gStyle->SetLegendBorderSize(0);
1338 gStyle->SetStatBorderSize(0);
1339 gStyle->SetTitleBorderSize(0);
1340}
1341//_____________________________________________________________________________
d7ec324f 1342void AliJetFlowTools::Style(TCanvas* c, TString style)
1343{
1344 // set a default style for a canvas
1345 if(!strcmp(style.Data(), "PEARSON")) {
1346 printf(" > style PEARSON canvas < \n");
1347 gStyle->SetOptStat(0);
1348 c->SetGridx();
1349 c->SetGridy();
1350 c->SetTicks();
1351 return;
1352 } else if(!strcmp(style.Data(), "SPECTRUM")) {
1353 printf(" > style SPECTRUM canvas < \n");
1354 gStyle->SetOptStat(0);
1355 c->SetLogy();
1356 c->SetGridx();
1357 c->SetGridy();
1358 c->SetTicks();
1359 return;
1360 } else printf(" > Style called with unknown option %s \n returning < \n", style.Data());
1361}
1362//_____________________________________________________________________________
1363void AliJetFlowTools::Style(TVirtualPad* c, TString style)
1364{
1365 // set a default style for a canvas
18698978 1366 c->SetLeftMargin(.25);
1367 c->SetBottomMargin(.25);
d7ec324f 1368 if(!strcmp(style.Data(), "PEARSON")) {
1369 printf(" > style PEARSON pad < \n");
1370 gStyle->SetOptStat(0);
1371 c->SetGridx();
1372 c->SetGridy();
1373 c->SetTicks();
1374 return;
1375 } else if(!strcmp(style.Data(), "SPECTRUM")) {
1376 printf(" > style SPECTRUM pad < \n");
1377 gStyle->SetOptStat(0);
1378 c->SetLogy();
1379 c->SetGridx();
1380 c->SetGridy();
1381 c->SetTicks();
1382 return;
18698978 1383 } else if (!strcmp(style.Data(), "GRID")) {
1384 printf(" > style GRID pad < \n");
1385 gStyle->SetOptStat(0);
1386 c->SetGridx();
1387 c->SetGridy();
1388 c->SetTicks();
d7ec324f 1389 } else printf(" > Style called with unknown option %s \n returning < \n", style.Data());
1390}
1391//_____________________________________________________________________________
53547ff2
RAB
1392void AliJetFlowTools::Style(TLegend* l)
1393{
1394 // set a default style for a legend
18698978 1395// l->SetTextSize(.06);
53547ff2 1396 l->SetFillColor(0);
18698978 1397// l->SetFillStyle(4050);
1398 l->SetBorderSize(0);
53547ff2
RAB
1399}
1400//_____________________________________________________________________________
1401void AliJetFlowTools::Style(TH1* h, EColor col, histoType type)
1402{
1403 // style a histo
1404 h->SetLineColor(col);
1405 h->SetMarkerColor(col);
1406 h->SetLineWidth(2.);
c03f7598 1407 h->SetMarkerSize(1.);
18698978 1408 h->SetTitle("");
1409 h->GetYaxis()->SetLabelSize(0.05);
1410 h->GetXaxis()->SetLabelSize(0.05);
1411 h->GetYaxis()->SetTitleOffset(1.5);
1412 h->GetXaxis()->SetTitleOffset(1.5);
1413 h->GetYaxis()->SetTitleSize(.05);
1414 h->GetXaxis()->SetTitleSize(.05);
53547ff2
RAB
1415 switch (type) {
1416 case kInPlaneSpectrum : {
1417 h->SetTitle("IN PLANE");
c03f7598 1418 h->GetXaxis()->SetTitle("#it{p}_{T}^{ch, jet} [GeV/#it{c}]");
18698978 1419 h->GetYaxis()->SetTitle("#frac{d#it{N}}{d#it{p}_{T}}");
53547ff2
RAB
1420 } break;
1421 case kOutPlaneSpectrum : {
1422 h->SetTitle("OUT OF PLANE");
18698978 1423 h->GetYaxis()->SetTitle("#frac{d#it{N}}{d#it{p}_{T}}");
c03f7598 1424 h->GetXaxis()->SetTitle("#it{p}_{T}^{ch, jet} [GeV/#it{c}]");
53547ff2
RAB
1425 } break;
1426 case kUnfoldedSpectrum : {
1427 h->SetTitle("UNFOLDED");
18698978 1428 h->GetYaxis()->SetTitle("#frac{d#it{N}}{d#it{p}_{T}}");
c03f7598 1429 h->GetXaxis()->SetTitle("#it{p}_{T}^{ch, jet} [GeV/#it{c}]");
53547ff2
RAB
1430 } break;
1431 case kFoldedSpectrum : {
1432 h->SetTitle("FOLDED");
18698978 1433 h->GetYaxis()->SetTitle("#frac{d#it{N}}{d#it{p}_{T}}");
c03f7598 1434 h->GetXaxis()->SetTitle("#it{p}_{T}^{ch, jet} [GeV/#it{c}]");
53547ff2
RAB
1435 } break;
1436 case kMeasuredSpectrum : {
1437 h->SetTitle("MEASURED");
18698978 1438 h->GetYaxis()->SetTitle("#frac{d#it{N}}{d#it{p}_{T}}");
c03f7598 1439 h->GetXaxis()->SetTitle("#it{p}_{T}^{ch, jet} [GeV/#it{c}]");
53547ff2 1440 } break;
18698978 1441 case kBar : {
1442 h->SetFillColor(col);
1443 h->SetBarWidth(.6);
c03f7598 1444 h->GetXaxis()->SetTitle("#it{p}_{T}^{ch, jet} [GeV/#it{c}]");
18698978 1445 h->SetBarOffset(0.2);
1446 }
53547ff2
RAB
1447 default : break;
1448 }
1449}
1450//_____________________________________________________________________________
1451void AliJetFlowTools::Style(TGraph* h, EColor col, histoType type)
1452{
1453 // style a histo
1454 h->SetLineColor(col);
1455 h->SetMarkerColor(col);
1456 h->SetLineWidth(2.);
c03f7598 1457 h->SetMarkerSize(1.);
18698978 1458 h->SetTitle("");
d06dbffe 1459 h->SetFillColor(kCyan);
a39e4b2b 1460 h->GetYaxis()->SetLabelSize(0.05);
1461 h->GetXaxis()->SetLabelSize(0.05);
1462 h->GetYaxis()->SetTitleOffset(1.6);
1463 h->GetXaxis()->SetTitleOffset(1.6);
1464 h->GetYaxis()->SetTitleSize(.05);
1465 h->GetXaxis()->SetTitleSize(.05);
1466 h->GetXaxis()->SetTitle("#it{p}_{T}^{ch, jet} [GeV/#it{c}]");
53547ff2
RAB
1467 switch (type) {
1468 case kInPlaneSpectrum : {
1469 h->SetTitle("IN PLANE");
18698978 1470 h->GetYaxis()->SetTitle("#frac{d#it{N}}{d#it{p}_{T}}");
53547ff2
RAB
1471 } break;
1472 case kOutPlaneSpectrum : {
1473 h->SetTitle("OUT OF PLANE");
18698978 1474 h->GetYaxis()->SetTitle("#frac{d#it{N}}{d#it{p}_{T}}");
53547ff2
RAB
1475 } break;
1476 case kUnfoldedSpectrum : {
1477 h->SetTitle("UNFOLDED");
18698978 1478 h->GetYaxis()->SetTitle("#frac{d#it{N}}{d#it{p}_{T}}");
53547ff2
RAB
1479 } break;
1480 case kFoldedSpectrum : {
1481 h->SetTitle("FOLDED");
18698978 1482 h->GetYaxis()->SetTitle("#frac{d#it{N}}{d#it{p}_{T}}");
53547ff2
RAB
1483 } break;
1484 case kMeasuredSpectrum : {
1485 h->SetTitle("MEASURED");
18698978 1486 h->GetYaxis()->SetTitle("#frac{d#it{N}}{d#it{p}_{T}}");
53547ff2 1487 } break;
a39e4b2b 1488 case kRatio : {
1489 h->GetYaxis()->SetTitle("#frac{d#it{N_{in plane}^{jet}}}{d#it{p}_{T}} / #frac{d#it{N_{out of plane}^{jet}}}{d#it{p}_{T}}");
1490 } break;
1491 case kV2 : {
1492 h->GetYaxis()->SetTitle("#it{v}_{2} = #frac{1}{#it{R}} #frac{#pi}{4} #frac{#it{N_{in plane}} - #it{N_{out of plane}}}{#it{N_{in plane}} + #it{N_{out of plane}}}");
1493 h->GetYaxis()->SetRangeUser(-.5, 1.);
1494 } break;
53547ff2
RAB
1495 default : break;
1496 }
1497}
1498//_____________________________________________________________________________
a39e4b2b 1499void AliJetFlowTools::GetNominalValues(
1500 TH1D*& ratio, // pointer reference, output of this function
1501 TGraphErrors*& v2, // pointer reference, as output of this function
1502 TArrayI* in,
1503 TArrayI* out,
1504 TString inFile,
1505 TString outFile) const
1506{
1507 // pass clones of the nominal points and nominal v2 values
1508 if(fOutputFile && !fOutputFile->IsZombie()) fOutputFile->Close(); // if for some weird reason the unfolding output is still mutable
1509 TFile* readMe(new TFile(inFile.Data(), "READ")); // open unfolding output read-only
1510 if(readMe->IsZombie()) {
1511 printf(" > Fatal error, couldn't read %s for post processing ! < \n", inFile.Data());
1512 return;
1513 }
1514 printf("\n\n\n\t\t GetNominalValues \n > Recovered the following file structure : \n <");
1515 readMe->ls();
1516 TFile* output(new TFile(outFile.Data(), "RECREATE")); // create new output file
a39e4b2b 1517 // get some placeholders, have to be initialized but will be deleted
1518 ratio = new TH1D("nominal", "nominal", fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
1519 TH1D* nominalIn(new TH1D("nominal in", "nominal in", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
1520 TH1D* nominalOut(new TH1D("nominal out", "nominal out", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
1521 Int_t iIn[] = {in->At(0), in->At(0)}; // first value is the nominal point
1522 Int_t iOut[] = {out->At(0), out->At(0)};
1523
1524 // call the functions and set the relevant pointer references
1525 TH1D* dud(0x0);
1526 DoIntermediateSystematics(
1527 new TArrayI(2, iIn),
1528 new TArrayI(2, iOut),
1529 dud, dud, dud, dud, dud, dud,
1530 ratio, // pointer reference, output of this function
1531 nominalIn,
1532 nominalOut,
1533 1,
1534 fBinsTrue->At(0),
24005d85 1535 fBinsTrue->At(fBinsTrue->GetSize()-1),
a39e4b2b 1536 readMe,
1537 "nominal_values");
35c03ef1 1538 v2 = GetV2(nominalIn, nominalOut, fEventPlaneRes, "nominal v_{2}");
a39e4b2b 1539
1540 // close the open files, reclaim ownership of histograms which are necessary outside of the file scope
1541 ratio->SetDirectory(0); // disassociate from current gDirectory
1542 readMe->Close();
a39e4b2b 1543}
1544//_____________________________________________________________________________
18698978 1545void AliJetFlowTools::GetCorrelatedUncertainty(
a39e4b2b 1546 TGraphAsymmErrors*& corrRatio, // correlated uncertainty function pointer
1547 TGraphAsymmErrors*& corrV2, // correlated uncertainty function pointer
1548 TArrayI* variationsIn, // variantions in plnae
1549 TArrayI* variationsOut, // variantions out of plane
7b88bd32 1550 Bool_t sym, // treat as symmmetric
1551 TArrayI* variations2ndIn, // second source of variations
1552 TArrayI* variations2ndOut, // second source of variations
1553 Bool_t sym2nd, // treat as symmetric
18698978 1554 TString type, // type of uncertaitny
24005d85 1555 TString type2,
18698978 1556 Int_t columns, // divide the output canvasses in this many columns
1557 Float_t rangeLow, // lower pt range
1558 Float_t rangeUp, // upper pt range
5159ed9e 1559 Float_t corr, // correlation strength
18698978 1560 TString in, // input file name (created by this unfolding class)
1561 TString out // output file name (which will hold results of the systematic test)
1562 ) const
f3ba6c8e 1563{
18698978 1564 // do full systematics
1565 if(fOutputFile && !fOutputFile->IsZombie()) fOutputFile->Close(); // if for some weird reason the unfolding output is still mutable
1566 TFile* readMe(new TFile(in.Data(), "READ")); // open unfolding output read-only
1567 if(readMe->IsZombie()) {
1568 printf(" > Fatal error, couldn't read %s for post processing ! < \n", in.Data());
1569 return;
1570 }
1571 printf("\n\n\n\t\t GetCorrelatedUncertainty \n > Recovered the following file structure : \n <");
1572 readMe->ls();
1573 TFile* output(new TFile(out.Data(), "RECREATE")); // create new output file
1574
1575 // create some null placeholder pointers
1576 TH1D* relativeErrorVariationInLow(0x0);
1577 TH1D* relativeErrorVariationInUp(0x0);
1578 TH1D* relativeErrorVariationOutLow(0x0);
1579 TH1D* relativeErrorVariationOutUp(0x0);
98d5b614 1580 TH1D* relativeError2ndVariationInLow(0x0);
1581 TH1D* relativeError2ndVariationInUp(0x0);
1582 TH1D* relativeError2ndVariationOutLow(0x0);
1583 TH1D* relativeError2ndVariationOutUp(0x0);
18698978 1584 TH1D* relativeStatisticalErrorIn(0x0);
1585 TH1D* relativeStatisticalErrorOut(0x0);
a39e4b2b 1586 // histo for the nominal ratio in / out
1587 TH1D* nominal(new TH1D("ratio in plane, out of plane", "ratio in plane, out of plane", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
1588 TH1D* nominalIn(new TH1D("in plane jet yield", "in plane jet yield", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
1589 TH1D* nominalOut(new TH1D("out of plane jet yield", "out of plane jet yield", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
18698978 1590
1591 // call the functions
1592 if(variationsIn && variationsOut) {
1593 DoIntermediateSystematics(
1594 variationsIn,
1595 variationsOut,
1596 relativeErrorVariationInUp, // pointer reference
1597 relativeErrorVariationInLow, // pointer reference
1598 relativeErrorVariationOutUp, // pointer reference
1599 relativeErrorVariationOutLow, // pointer reference
a39e4b2b 1600 relativeStatisticalErrorIn, // pointer reference
1601 relativeStatisticalErrorOut, // pointer reference
1602 nominal,
1603 nominalIn,
1604 nominalOut,
18698978 1605 columns,
1606 rangeLow,
1607 rangeUp,
1608 readMe,
1609 type);
1610 if(relativeErrorVariationInUp) {
1611 // canvas with the error from variation strength
1612 TCanvas* relativeErrorVariation(new TCanvas(Form("relativeError_%s", type.Data()), Form("relativeError_%s", type.Data())));
1613 relativeErrorVariation->Divide(2);
1614 relativeErrorVariation->cd(1);
1615 Style(gPad, "GRID");
1616 relativeErrorVariationInUp->DrawCopy("b");
1617 relativeErrorVariationInLow->DrawCopy("same b");
1618 Style(AddLegend(gPad));
1619 relativeErrorVariation->cd(2);
1620 Style(gPad, "GRID");
1621 relativeErrorVariationOutUp->DrawCopy("b");
1622 relativeErrorVariationOutLow->DrawCopy("same b");
1623 SavePadToPDF(relativeErrorVariation);
1624 Style(AddLegend(gPad));
1625 relativeErrorVariation->Write();
1626 }
98d5b614 1627 }
1628 // call the functions for a second set of systematic sources
1629 if(variations2ndIn && variations2ndOut) {
1630 DoIntermediateSystematics(
1631 variations2ndIn,
1632 variations2ndOut,
1633 relativeError2ndVariationInUp, // pointer reference
1634 relativeError2ndVariationInLow, // pointer reference
1635 relativeError2ndVariationOutUp, // pointer reference
1636 relativeError2ndVariationOutLow, // pointer reference
1637 relativeStatisticalErrorIn, // pointer reference
1638 relativeStatisticalErrorOut, // pointer reference
1639 nominal,
1640 nominalIn,
1641 nominalOut,
1642 columns,
1643 rangeLow,
1644 rangeUp,
1645 readMe,
24005d85 1646 type2);
98d5b614 1647 if(relativeError2ndVariationInUp) {
1648 // canvas with the error from variation strength
24005d85 1649 TCanvas* relativeError2ndVariation(new TCanvas(Form("relativeError2nd_%s", type2.Data()), Form("relativeError2nd_%s", type2.Data())));
98d5b614 1650 relativeError2ndVariation->Divide(2);
1651 relativeError2ndVariation->cd(1);
1652 Style(gPad, "GRID");
1653 relativeError2ndVariationInUp->DrawCopy("b");
1654 relativeError2ndVariationInLow->DrawCopy("same b");
1655 Style(AddLegend(gPad));
1656 relativeError2ndVariation->cd(2);
1657 Style(gPad, "GRID");
1658 relativeError2ndVariationOutUp->DrawCopy("b");
1659 relativeError2ndVariationOutLow->DrawCopy("same b");
1660 SavePadToPDF(relativeError2ndVariation);
1661 Style(AddLegend(gPad));
1662 relativeError2ndVariation->Write();
1663 }
1664
18698978 1665 }
1666
1667 // and the placeholder for the final systematic
1668 TH1D* relativeErrorInUp(new TH1D("max correlated uncertainty in plane", "max correlated uncertainty in plane", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
1669 TH1D* relativeErrorOutUp(new TH1D("max correlated uncertainty out of plane", "max correlated uncertainty out of plane", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
1670 TH1D* relativeErrorInLow(new TH1D("min correlated uncertainty in plane", "min correlated uncertainty in plane", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
1671 TH1D* relativeErrorOutLow(new TH1D("min correlated uncertainty out of plane", "min correlated uncertainty out of plane", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
1672 relativeErrorInUp->SetYTitle("relative uncertainty");
1673 relativeErrorOutUp->SetYTitle("relative uncertainty");
1674 relativeErrorInLow->SetYTitle("relative uncertainty");
1675 relativeErrorOutLow->SetYTitle("relative uncertainty");
1676
a39e4b2b 1677 // merge the correlated errors (FIXME) trivial for one set
1678 Double_t aInUp(0.), bInUp(0.), cInUp(0.), dInUp(0.);
1679 Double_t aOutUp(0.), bOutUp(0.), cOutUp(0.), dOutUp(0.);
1680 Double_t aInLow(0.), bInLow(0.), cInLow(0.), dInLow(0.);
1681 Double_t aOutLow(0.), bOutLow(0.), cOutLow(0.), dOutLow(0.);
1682
1683 for(Int_t b(0); b < fBinsTrue->GetSize()-1; b++) {
1684 // for the upper bound
1685 if(relativeErrorVariationInUp) aInUp = relativeErrorVariationInUp->GetBinContent(b+1);
1686 if(relativeErrorVariationOutUp) aOutUp = relativeErrorVariationOutUp->GetBinContent(b+1);
98d5b614 1687 if(relativeError2ndVariationInUp) bInUp = relativeError2ndVariationInUp->GetBinContent(b+1);
1688 if(relativeError2ndVariationOutUp) bInLow = relativeError2ndVariationOutUp->GetBinContent(b+1);
a39e4b2b 1689 dInUp = aInUp*aInUp + bInUp*bInUp + cInUp*cInUp;
7b88bd32 1690 // for a symmetric first variation
1691 if(sym) dInUp += aInLow*aInLow;
a39e4b2b 1692 if(dInUp > 0) relativeErrorInUp->SetBinContent(b+1, TMath::Sqrt(dInUp));
1693 dOutUp = aOutUp*aOutUp + bOutUp*bOutUp + cOutUp*cOutUp;
d06dbffe 1694 if(sym) dOutUp += aOutLow*aOutLow;
a39e4b2b 1695 if(dOutUp > 0) relativeErrorOutUp->SetBinContent(b+1, TMath::Sqrt(dOutUp));
1696 // for the lower bound
1697 if(relativeErrorVariationInLow) aInLow = relativeErrorVariationInLow->GetBinContent(b+1);
1698 if(relativeErrorVariationOutLow) aOutLow = relativeErrorVariationOutLow->GetBinContent(b+1);
98d5b614 1699 if(relativeError2ndVariationInLow) bInLow = relativeError2ndVariationInLow->GetBinContent(b+1);
1700 if(relativeError2ndVariationOutLow) bOutLow = relativeError2ndVariationOutLow->GetBinContent(b+1);
a39e4b2b 1701 dInLow = aInLow*aInLow + bInLow*bInLow + cInLow*cInLow;
7b88bd32 1702 if(sym) dInLow += aInUp*aInUp;
5159ed9e 1703 if(dInLow > 0) relativeErrorInLow->SetBinContent(b+1, -1*TMath::Sqrt(dInLow));
a39e4b2b 1704 dOutLow = aOutLow*aOutLow + bOutLow*bOutLow + cOutLow*cOutLow;
d06dbffe 1705 if(sym) dOutLow += aOutUp*aOutUp;
a39e4b2b 1706 if(dOutLow > 0) relativeErrorOutLow->SetBinContent(b+1, -1.*TMath::Sqrt(dOutLow));
1707 }
1708 // project the estimated errors on the nominal ratio
1709 if(nominal) {
1710 Double_t* ax = new Double_t[fBinsTrue->GetSize()-1];
1711 Double_t* ay = new Double_t[fBinsTrue->GetSize()-1];
1712 Double_t* axh = new Double_t[fBinsTrue->GetSize()-1];
1713 Double_t* axl = new Double_t[fBinsTrue->GetSize()-1];
1714 Double_t* ayh = new Double_t[fBinsTrue->GetSize()-1];
1715 Double_t* ayl = new Double_t[fBinsTrue->GetSize()-1];
1716 Double_t lowErr(0.), upErr(0.);
1717 for(Int_t i(0); i < fBinsTrue->GetSize()-1; i++) {
1718 // add the in and out of plane errors in quadrature
b3b03df7 1719 // propagation is tricky because we should consider two cases:
1720 // [1] the error is uncorrelated, and we propagate upper 1 with lower 2 and vice versa
1721 // [2] the error is correlated - in this case upper 1 should be propagated with upper 2
1722 // as the fluctuations are bound to always to of same sign
1723 if(corr <= 0) {
1724 lowErr = relativeErrorInLow->GetBinContent(i+1)*relativeErrorInLow->GetBinContent(i+1)+relativeErrorOutUp->GetBinContent(1+i)*relativeErrorOutUp->GetBinContent(i+1);
1725 upErr = relativeErrorInUp->GetBinContent(i+1)*relativeErrorInUp->GetBinContent(i+1)+relativeErrorOutLow->GetBinContent(i+1)*relativeErrorOutLow->GetBinContent(i+1);
1726 } else {
1727 lowErr = relativeErrorInLow->GetBinContent(i+1)*relativeErrorInLow->GetBinContent(i+1)+relativeErrorOutLow->GetBinContent(1+i)*relativeErrorOutLow->GetBinContent(i+1) -2.*corr*relativeErrorInLow->GetBinContent(i+1)*relativeErrorOutLow->GetBinContent(i+1);
1728 upErr = relativeErrorInUp->GetBinContent(i+1)*relativeErrorInUp->GetBinContent(i+1)+relativeErrorOutUp->GetBinContent(i+1)*relativeErrorOutUp->GetBinContent(i+1) - 2.*corr*relativeErrorInUp->GetBinContent(i+1)*relativeErrorOutUp->GetBinContent(i+1);
1729 }
5159ed9e 1730 ayl[i] = TMath::Sqrt(TMath::Abs(lowErr))*nominal->GetBinContent(i+1);
1731 ayh[i] = TMath::Sqrt(TMath::Abs(upErr))*nominal->GetBinContent(i+1);
a39e4b2b 1732 // get the bin width (which is the 'error' on x
1733 Double_t binWidth(nominal->GetBinWidth(i+1));
1734 axl[i] = binWidth/2.;
1735 axh[i] = binWidth/2.;
1736 // now get the coordinate for the point
1737 ax[i] = nominal->GetBinCenter(i+1);
1738 ay[i] = nominal->GetBinContent(i+1);
1739 }
1740 // save the nominal ratio
1741 TGraphAsymmErrors* nominalError(new TGraphAsymmErrors(fBinsTrue->GetSize()-1, ax, ay, axl, axh, ayl, ayh));
1742 corrRatio = (TGraphAsymmErrors*)nominalError->Clone();
1743 nominalError->SetName("correlated uncertainty");
1744 TCanvas* nominalCanvas(new TCanvas("nominalCanvas", "nominalCanvas"));
1745 nominalCanvas->Divide(2);
1746 nominalCanvas->cd(1);
1747 Style(nominal, kBlack);
d06dbffe 1748 Style(nominalError, kCyan, kRatio);
1749 nominalError->SetLineColor(kCyan);
1750 nominalError->SetMarkerColor(kCyan);
a39e4b2b 1751 nominalError->GetXaxis()->SetRangeUser(rangeLow, rangeUp);
1752 nominalError->GetYaxis()->SetRangeUser(.7, 2.2);
1753 nominalError->DrawClone("a2");
1754 nominal->DrawCopy("same E1");
1755 Style(AddLegend(gPad));
1756 Style(gPad, "GRID");
1757 Style(nominalCanvas);
1758 // save nominal v2 and systematic errors
1759 TGraphAsymmErrors* nominalV2Error(GetV2WithSystematicErrors(
1760 nominalIn,
1761 nominalOut,
35c03ef1 1762 fEventPlaneRes,
5159ed9e 1763 "v_{2} with shape uncertainty",
a39e4b2b 1764 relativeErrorInUp,
1765 relativeErrorInLow,
24005d85 1766 relativeErrorOutUp,
5159ed9e 1767 relativeErrorOutLow,
1768 corr));
a39e4b2b 1769 // pass the nominal values to the pointer references
1770 corrV2 = (TGraphAsymmErrors*)nominalV2Error->Clone();
35c03ef1 1771 TGraphErrors* nominalV2(GetV2(nominalIn, nominalOut, fEventPlaneRes, "v_{2}"));
a39e4b2b 1772 nominalCanvas->cd(2);
1773 Style(nominalV2, kBlack);
d06dbffe 1774 Style(nominalV2Error, kCyan, kV2);
1775 nominalV2Error->SetLineColor(kCyan);
1776 nominalV2Error->SetMarkerColor(kCyan);
a39e4b2b 1777 nominalV2Error->GetXaxis()->SetRangeUser(rangeLow, rangeUp);
1778 nominalV2Error->DrawClone("a2");
1779 nominalV2->DrawClone("same E1");
1780 Style(AddLegend(gPad));
1781 Style(gPad, "GRID");
1782 Style(nominalCanvas);
1783 SavePadToPDF(nominalCanvas);
1784 nominalCanvas->Write();
1785 }
1786
18698978 1787 TCanvas* relativeError(new TCanvas("relativeCorrelatedError"," relativeCorrelatedError"));
1788 relativeError->Divide(2);
1789 relativeError->cd(1);
1790 Style(gPad, "GRID");
1791 relativeErrorInUp->GetYaxis()->SetRangeUser(-1.5, 3.);
1792 Style(relativeErrorInUp, kBlue, kBar);
1793 Style(relativeErrorInLow, kGreen, kBar);
1794 relativeErrorInUp->DrawCopy("b");
1795 relativeErrorInLow->DrawCopy("same b");
1796 Style(relativeStatisticalErrorIn, kRed);
1797 relativeStatisticalErrorIn->DrawCopy("same");
1798 Style(AddLegend(gPad));
1799 relativeError->cd(2);
1800 Style(gPad, "GRID");
1801 relativeErrorOutUp->GetYaxis()->SetRangeUser(-1.5, 3.);
1802 Style(relativeErrorOutUp, kBlue, kBar);
1803 Style(relativeErrorOutLow, kGreen, kBar);
1804 relativeErrorOutUp->DrawCopy("b");
1805 relativeErrorOutLow->DrawCopy("same b");
1806 Style(relativeStatisticalErrorOut, kRed);
1807 relativeStatisticalErrorOut->DrawCopy("same");
1808 Style(AddLegend(gPad));
1809
1810 // write the buffered file to disk and close the file
1811 SavePadToPDF(relativeError);
1812 relativeError->Write();
1813 output->Write();
a39e4b2b 1814// output->Close();
18698978 1815}
1816//_____________________________________________________________________________
1817void AliJetFlowTools::GetShapeUncertainty(
a39e4b2b 1818 TGraphAsymmErrors*& shapeRatio, // pointer reference to final shape uncertainty of ratio
1819 TGraphAsymmErrors*& shapeV2, // pointer reference to final shape uncertainty of v2
18698978 1820 TArrayI* regularizationIn, // regularization strength systematics, in plane
1821 TArrayI* regularizationOut, // regularization strenght systematics, out of plane
1822 TArrayI* trueBinIn, // true bin ranges, in plane
1823 TArrayI* trueBinOut, // true bin ranges, out of plane
1824 TArrayI* recBinIn, // rec bin ranges, in plane
1825 TArrayI* recBinOut, // rec bin ranges, out of plane
b2150106 1826 TArrayI* methodIn, // method in
1827 TArrayI* methodOut, // method out
18698978 1828 Int_t columns, // divide the output canvasses in this many columns
1829 Float_t rangeLow, // lower pt range
1830 Float_t rangeUp, // upper pt range
1831 TString in, // input file name (created by this unfolding class)
1832 TString out // output file name (which will hold results of the systematic test)
1833 ) const
1834{
1835 // do full systematics
1836 if(fOutputFile && !fOutputFile->IsZombie()) fOutputFile->Close(); // if for some weird reason the unfolding output is still mutable
1837 TFile* readMe(new TFile(in.Data(), "READ")); // open unfolding output read-only
1838 if(readMe->IsZombie()) {
1839 printf(" > Fatal error, couldn't read %s for post processing ! < \n", in.Data());
1840 return;
1841 }
1842 printf("\n\n\n\t\t DOSYSTEMATICS \n > Recovered the following file structure : \n <");
1843 readMe->ls();
1844 TFile* output(new TFile(out.Data(), "RECREATE")); // create new output file
1845
1846 // create some null placeholder pointers
1847 TH1D* relativeErrorRegularizationInLow(0x0);
1848 TH1D* relativeErrorRegularizationInUp(0x0);
1849 TH1D* relativeErrorTrueBinInLow(0x0);
1850 TH1D* relativeErrorTrueBinInUp(0x0);
1851 TH1D* relativeErrorRecBinInLow(0x0);
1852 TH1D* relativeErrorRecBinInUp(0x0);
b2150106 1853 TH1D* relativeErrorMethodInLow(0x0);
1854 TH1D* relativeErrorMethodInUp(0x0);
18698978 1855 TH1D* relativeErrorRegularizationOutLow(0x0);
1856 TH1D* relativeErrorRegularizationOutUp(0x0);
1857 TH1D* relativeErrorTrueBinOutLow(0x0);
1858 TH1D* relativeErrorTrueBinOutUp(0x0);
1859 TH1D* relativeErrorRecBinOutLow(0x0);
1860 TH1D* relativeErrorRecBinOutUp(0x0);
1861 TH1D* relativeStatisticalErrorIn(0x0);
1862 TH1D* relativeStatisticalErrorOut(0x0);
b2150106 1863 TH1D* relativeErrorMethodOutLow(0x0);
1864 TH1D* relativeErrorMethodOutUp(0x0);
a39e4b2b 1865 // histo for the nominal ratio in / out
1866 TH1D* nominal(new TH1D("ratio in plane, out of plane", "ratio in plane, out of plane", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
1867 TH1D* nominalIn(new TH1D("in plane jet yield", "in plane jet yield", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
1868 TH1D* nominalOut(new TH1D("out of plane jet yield", "out of plane jet yield", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
18698978 1869
1870 // call the functions
1871 if(regularizationIn && regularizationOut) {
1872 DoIntermediateSystematics(
1873 regularizationIn,
1874 regularizationOut,
1875 relativeErrorRegularizationInUp, // pointer reference
1876 relativeErrorRegularizationInLow, // pointer reference
1877 relativeErrorRegularizationOutUp, // pointer reference
1878 relativeErrorRegularizationOutLow, // pointer reference
1879 relativeStatisticalErrorIn, // pointer reference
1880 relativeStatisticalErrorOut, // pointer reference
a39e4b2b 1881 nominal,
1882 nominalIn,
1883 nominalOut,
18698978 1884 columns,
1885 rangeLow,
1886 rangeUp,
1887 readMe,
d06dbffe 1888 "regularization",
3e698d27 1889 fRMS);
18698978 1890 if(relativeErrorRegularizationInUp) {
1891 // canvas with the error from regularization strength
1892 TCanvas* relativeErrorRegularization(new TCanvas("relativeErrorRegularization", "relativeErrorRegularization"));
1893 relativeErrorRegularization->Divide(2);
1894 relativeErrorRegularization->cd(1);
1895 Style(gPad, "GRID");
1896 relativeErrorRegularizationInUp->DrawCopy("b");
1897 relativeErrorRegularizationInLow->DrawCopy("same b");
1898 Style(AddLegend(gPad));
1899 relativeErrorRegularization->cd(2);
1900 Style(gPad, "GRID");
1901 relativeErrorRegularizationOutUp->DrawCopy("b");
1902 relativeErrorRegularizationOutLow->DrawCopy("same b");
1903 SavePadToPDF(relativeErrorRegularization);
1904 Style(AddLegend(gPad));
1905 relativeErrorRegularization->Write();
1906 }
1907 }
1908 if(trueBinIn && trueBinOut) {
1909 DoIntermediateSystematics(
1910 trueBinIn,
1911 trueBinOut,
1912 relativeErrorTrueBinInUp, // pointer reference
1913 relativeErrorTrueBinInLow, // pointer reference
1914 relativeErrorTrueBinOutUp, // pointer reference
1915 relativeErrorTrueBinOutLow, // pointer reference
1916 relativeStatisticalErrorIn,
1917 relativeStatisticalErrorOut,
a39e4b2b 1918 nominal,
1919 nominalIn,
1920 nominalOut,
18698978 1921 columns,
1922 rangeLow,
1923 rangeUp,
1924 readMe,
1925 "trueBin");
1926 if(relativeErrorTrueBinInUp) {
1927 TCanvas* relativeErrorTrueBin(new TCanvas("relativeErrorTrueBin", "relativeErrorTrueBin"));
1928 relativeErrorTrueBin->Divide(2);
1929 relativeErrorTrueBin->cd(1);
1930 Style(gPad, "GRID");
1931 relativeErrorTrueBinInUp->DrawCopy("b");
1932 relativeErrorTrueBinInLow->DrawCopy("same b");
1933 Style(AddLegend(gPad));
1934 relativeErrorTrueBin->cd(2);
1935 Style(gPad, "GRID");
1936 relativeErrorTrueBinOutUp->DrawCopy("b");
1937 relativeErrorTrueBinOutLow->DrawCopy("same b");
1938 SavePadToPDF(relativeErrorTrueBin);
1939 Style(AddLegend(gPad));
1940 relativeErrorTrueBin->Write();
1941 }
1942 }
1943 if(recBinIn && recBinOut) {
1944 DoIntermediateSystematics(
1945 recBinIn,
1946 recBinOut,
24005d85 1947 relativeErrorRecBinInUp, // pointer reference
1948 relativeErrorRecBinInLow, // pointer reference
1949 relativeErrorRecBinOutUp, // pointer reference
1950 relativeErrorRecBinOutLow, // pointer reference
18698978 1951 relativeStatisticalErrorIn,
1952 relativeStatisticalErrorOut,
a39e4b2b 1953 nominal,
1954 nominalIn,
1955 nominalOut,
18698978 1956 columns,
1957 rangeLow,
1958 rangeUp,
1959 readMe,
1960 "recBin");
1961 if(relativeErrorRecBinOutUp) {
1962 // canvas with the error from regularization strength
1963 TCanvas* relativeErrorRecBin(new TCanvas("relativeErrorRecBin"," relativeErrorRecBin"));
1964 relativeErrorRecBin->Divide(2);
1965 relativeErrorRecBin->cd(1);
1966 Style(gPad, "GRID");
1967 relativeErrorRecBinInUp->DrawCopy("b");
1968 relativeErrorRecBinInLow->DrawCopy("same b");
1969 Style(AddLegend(gPad));
1970 relativeErrorRecBin->cd(2);
1971 Style(gPad, "GRID");
1972 relativeErrorRecBinOutUp->DrawCopy("b");
1973 relativeErrorRecBinOutLow->DrawCopy("same b");
1974 SavePadToPDF(relativeErrorRecBin);
1975 Style(AddLegend(gPad));
1976 relativeErrorRecBin->Write();
1977 }
1978 }
b2150106 1979 if(methodIn && methodOut) {
1980 DoIntermediateSystematics(
1981 methodIn,
1982 methodOut,
1983 relativeErrorMethodInUp, // pointer reference
1984 relativeErrorMethodInLow, // pointer reference
1985 relativeErrorMethodOutUp, // pointer reference
1986 relativeErrorMethodOutLow, // pointer reference
1987 relativeStatisticalErrorIn,
1988 relativeStatisticalErrorOut,
1989 nominal,
1990 nominalIn,
1991 nominalOut,
1992 columns,
1993 rangeLow,
1994 rangeUp,
1995 readMe,
db02017e 1996 "method"
1997 );
b2150106 1998 if(relativeErrorMethodInUp) {
1999 TCanvas* relativeErrorMethod(new TCanvas("relativeErrorMethod", "relativeErrorMethod"));
2000 relativeErrorMethod->Divide(2);
2001 relativeErrorMethod->cd(1);
2002 Style(gPad, "GRID");
2003 relativeErrorMethodInUp->DrawCopy("b");
2004 relativeErrorMethodInLow->DrawCopy("same b");
2005 Style(AddLegend(gPad));
2006 relativeErrorMethod->cd(2);
2007 Style(gPad, "GRID");
2008 relativeErrorMethodOutUp->DrawCopy("b");
2009 relativeErrorMethodOutLow->DrawCopy("same b");
2010 SavePadToPDF(relativeErrorMethod);
2011 Style(AddLegend(gPad));
2012 relativeErrorMethod->Write();
2013 }
2014 }
18698978 2015
2016 // and the placeholder for the final systematic
2017 TH1D* relativeErrorInUp(new TH1D("max shape uncertainty in plane", "max shape uncertainty in plane", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
2018 TH1D* relativeErrorOutUp(new TH1D("max shape uncertainty out of plane", "max shape uncertainty out of plane", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
2019 TH1D* relativeErrorInLow(new TH1D("min shape uncertainty in plane", "min shape uncertainty in plane", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
2020 TH1D* relativeErrorOutLow(new TH1D("min shape uncertainty out of plane", "min shape uncertainty out of plane", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
2021 relativeErrorInUp->SetYTitle("relative uncertainty");
2022 relativeErrorOutUp->SetYTitle("relative uncertainty");
2023 relativeErrorInLow->SetYTitle("relative uncertainty");
2024 relativeErrorOutLow->SetYTitle("relative uncertainty");
2025
2026 // sum of squares for the total systematic error
b2150106 2027 Double_t aInUp(0.), bInUp(0.), cInUp(0.), dInUp(0.), eInUp(0.);
2028 Double_t aOutUp(0.), bOutUp(0.), cOutUp(0.), dOutUp(0.), eOutUp(0.);
2029 Double_t aInLow(0.), bInLow(0.), cInLow(0.), dInLow(0.), eInLow(0.);
2030 Double_t aOutLow(0.), bOutLow(0.), cOutLow(0.), dOutLow(0.), eOutLow(0.);
18698978 2031
2032 for(Int_t b(0); b < fBinsTrue->GetSize()-1; b++) {
2033 // for the upper bound
2034 if(relativeErrorRegularizationInUp) aInUp = relativeErrorRegularizationInUp->GetBinContent(b+1);
2035 if(relativeErrorRegularizationOutUp) aOutUp = relativeErrorRegularizationOutUp->GetBinContent(b+1);
2036 if(relativeErrorTrueBinInUp) bInUp = relativeErrorTrueBinInUp->GetBinContent(b+1);
2037 if(relativeErrorTrueBinOutUp) bOutUp = relativeErrorTrueBinOutUp->GetBinContent(b+1);
2038 if(relativeErrorRecBinInUp) cInUp = relativeErrorRecBinInUp->GetBinContent(b+1);
2039 if(relativeErrorRecBinOutUp) cOutUp = relativeErrorRecBinOutUp->GetBinContent(b+1);
b2150106 2040 if(relativeErrorMethodInUp) dInUp = relativeErrorMethodInUp->GetBinContent(b+1);
2041 if(relativeErrorMethodOutUp) dOutUp = relativeErrorMethodOutUp->GetBinContent(b+1);
2042 eInUp = aInUp*aInUp + bInUp*bInUp + cInUp*cInUp + dInUp*dInUp;
2043 if(eInUp > 0) relativeErrorInUp->SetBinContent(b+1, 1.*TMath::Sqrt(eInUp));
2044 eOutUp = aOutUp*aOutUp + bOutUp*bOutUp + cOutUp*cOutUp + dOutUp*dOutUp;
2045 if(eOutUp > 0) relativeErrorOutUp->SetBinContent(b+1, 1.*TMath::Sqrt(eOutUp));
18698978 2046 // for the lower bound
2047 if(relativeErrorRegularizationInLow) aInLow = relativeErrorRegularizationInLow->GetBinContent(b+1);
2048 if(relativeErrorRegularizationOutLow) aOutLow = relativeErrorRegularizationOutLow->GetBinContent(b+1);
2049 if(relativeErrorTrueBinInLow) bInLow = relativeErrorTrueBinInLow->GetBinContent(b+1);
2050 if(relativeErrorTrueBinOutLow) bOutLow = relativeErrorTrueBinOutLow->GetBinContent(b+1);
2051 if(relativeErrorRecBinInLow) cInLow = relativeErrorRecBinInLow->GetBinContent(b+1);
2052 if(relativeErrorRecBinOutLow) cOutLow = relativeErrorRecBinOutLow->GetBinContent(b+1);
b2150106 2053 if(relativeErrorMethodInLow) dInLow = relativeErrorMethodInLow->GetBinContent(b+1);
2054 if(relativeErrorMethodOutLow) dOutLow = relativeErrorMethodOutLow->GetBinContent(b+1);
db02017e 2055 if(fSymmRMS) { // take first category as symmetric
2056 aInLow = aInUp*1.5;
2057 aOutLow = aOutUp*1.5;
2058 if(dInLow < dInUp) dInLow = dInUp;
2059 if(dOutLow < dOutUp) dOutLow = dOutUp;
2060 }
2061
b2150106 2062 eInLow = aInLow*aInLow + bInLow*bInLow + cInLow*cInLow + dInLow*dInLow;
2063 if(eInLow > 0) relativeErrorInLow->SetBinContent(b+1, -1.*TMath::Sqrt(eInLow));
2064 eOutLow = aOutLow*aOutLow + bOutLow*bOutLow + cOutLow*cOutLow + dOutLow*dOutLow;
2065 if(eOutLow > 0) relativeErrorOutLow->SetBinContent(b+1, -1.*TMath::Sqrt(eOutLow));
18698978 2066 }
a39e4b2b 2067 // project the estimated errors on the nominal ratio
2068 if(nominal) {
2069 Double_t* ax = new Double_t[fBinsTrue->GetSize()-1];
2070 Double_t* ay = new Double_t[fBinsTrue->GetSize()-1];
2071 Double_t* axh = new Double_t[fBinsTrue->GetSize()-1];
2072 Double_t* axl = new Double_t[fBinsTrue->GetSize()-1];
2073 Double_t* ayh = new Double_t[fBinsTrue->GetSize()-1];
2074 Double_t* ayl = new Double_t[fBinsTrue->GetSize()-1];
2075 Double_t lowErr(0.), upErr(0.);
2076 for(Int_t i(0); i < fBinsTrue->GetSize()-1; i++) {
2077 // add the in and out of plane errors in quadrature
24005d85 2078 // take special care here: to propagate the assymetric error, we need to correlate the
2079 // InLow with OutUp (minimum value of ratio) and InUp with OutLow (maximum value of ratio)
2080 lowErr = relativeErrorInLow->GetBinContent(i+1)*relativeErrorInLow->GetBinContent(i+1)+relativeErrorOutUp->GetBinContent(1+i)*relativeErrorOutUp->GetBinContent(i+1);
2081 upErr = relativeErrorInUp->GetBinContent(i+1)*relativeErrorInUp->GetBinContent(i+1)+relativeErrorOutLow->GetBinContent(i+1)*relativeErrorOutLow->GetBinContent(i+1);
a39e4b2b 2082 // set the errors
2083 ayl[i] = TMath::Sqrt(lowErr)*nominal->GetBinContent(i+1);
2084 ayh[i] = TMath::Sqrt(upErr)*nominal->GetBinContent(i+1);
2085 // get the bin width (which is the 'error' on x
2086 Double_t binWidth(nominal->GetBinWidth(i+1));
2087 axl[i] = binWidth/2.;
2088 axh[i] = binWidth/2.;
2089 // now get the coordinate for the point
2090 ax[i] = nominal->GetBinCenter(i+1);
2091 ay[i] = nominal->GetBinContent(i+1);
2092 }
2093 // save the nominal ratio
2094 TGraphAsymmErrors* nominalError(new TGraphAsymmErrors(fBinsTrue->GetSize()-1, ax, ay, axl, axh, ayl, ayh));
2095 shapeRatio = (TGraphAsymmErrors*)nominalError->Clone();
2096 nominalError->SetName("shape uncertainty");
2097 TCanvas* nominalCanvas(new TCanvas("nominalCanvas", "nominalCanvas"));
2098 nominalCanvas->Divide(2);
2099 nominalCanvas->cd(1);
2100 Style(nominal, kBlack);
d06dbffe 2101 Style(nominalError, kCyan, kRatio);
2102 nominalError->SetLineColor(kCyan);
2103 nominalError->SetMarkerColor(kCyan);
a39e4b2b 2104 nominalError->GetXaxis()->SetRangeUser(rangeLow, rangeUp);
2105 nominalError->GetYaxis()->SetRangeUser(.7, 2.2);
2106 nominalError->DrawClone("a2");
2107 nominal->DrawCopy("same E1");
2108 Style(AddLegend(gPad));
2109 Style(gPad, "GRID");
2110 Style(nominalCanvas);
2111 // save nominal v2 and systematic errors
2112 TGraphAsymmErrors* nominalV2Error(GetV2WithSystematicErrors(
2113 nominalIn,
2114 nominalOut,
35c03ef1 2115 fEventPlaneRes,
a39e4b2b 2116 "v_{2} with shape uncertainty",
2117 relativeErrorInUp,
2118 relativeErrorInLow,
2119 relativeErrorOutUp,
2120 relativeErrorOutLow));
2121 shapeV2 = (TGraphAsymmErrors*)nominalV2Error->Clone();
35c03ef1 2122 TGraphErrors* nominalV2(GetV2(nominalIn, nominalOut, fEventPlaneRes, "v_{2}"));
a39e4b2b 2123 nominalCanvas->cd(2);
2124 Style(nominalV2, kBlack);
d06dbffe 2125 Style(nominalV2Error, kCyan, kV2);
2126 nominalV2Error->SetLineColor(kCyan);
2127 nominalV2Error->SetMarkerColor(kCyan);
a39e4b2b 2128 nominalV2Error->GetXaxis()->SetRangeUser(rangeLow, rangeUp);
2129 nominalV2Error->DrawClone("a2");
2130 nominalV2->DrawClone("same E1");
2131 Style(AddLegend(gPad));
2132 Style(gPad, "GRID");
2133 Style(nominalCanvas);
2134 SavePadToPDF(nominalCanvas);
2135 nominalCanvas->Write();
2136 }
2137
18698978 2138 TCanvas* relativeError(new TCanvas("relativeError"," relativeError"));
2139 relativeError->Divide(2);
2140 relativeError->cd(1);
2141 Style(gPad, "GRID");
2142 relativeErrorInUp->GetYaxis()->SetRangeUser(-1.5, 3.);
2143 Style(relativeErrorInUp, kBlue, kBar);
2144 Style(relativeErrorInLow, kGreen, kBar);
2145 relativeErrorInUp->DrawCopy("b");
2146 relativeErrorInLow->DrawCopy("same b");
2147 Style(relativeStatisticalErrorIn, kRed);
2148 relativeStatisticalErrorIn->DrawCopy("same");
2149 Style(AddLegend(gPad));
2150 relativeError->cd(2);
2151 Style(gPad, "GRID");
2152 relativeErrorOutUp->GetYaxis()->SetRangeUser(-1.5, 3.);
2153 Style(relativeErrorOutUp, kBlue, kBar);
2154 Style(relativeErrorOutLow, kGreen, kBar);
2155 relativeErrorOutUp->DrawCopy("b");
2156 relativeErrorOutLow->DrawCopy("same b");
2157 Style(relativeStatisticalErrorOut, kRed);
2158 relativeStatisticalErrorOut->DrawCopy("same");
2159 Style(AddLegend(gPad));
2160
2161 // write the buffered file to disk and close the file
2162 SavePadToPDF(relativeError);
2163 relativeError->Write();
2164 output->Write();
a39e4b2b 2165// output->Close();
18698978 2166}
2167//_____________________________________________________________________________
a39e4b2b 2168 void AliJetFlowTools::DoIntermediateSystematics(
2169 TArrayI* variationsIn, // variantions in plane
2170 TArrayI* variationsOut, // variantions out of plane
2171 TH1D*& relativeErrorInUp, // pointer reference to minimum relative error histogram in plane
2172 TH1D*& relativeErrorInLow, // pointer reference to maximum relative error histogram in plane
2173 TH1D*& relativeErrorOutUp, // pointer reference to minimum relative error histogram out of plane
2174 TH1D*& relativeErrorOutLow, // pointer reference to maximum relative error histogram out of plane
2175 TH1D*& relativeStatisticalErrorIn, // relative systematic error on ratio
2176 TH1D*& relativeStatisticalErrorOut, // relative systematic error on ratio
2177 TH1D*& nominal, // clone of the nominal ratio in / out of plane
2178 TH1D*& nominalIn, // clone of the nominal in plane yield
2179 TH1D*& nominalOut, // clone of the nominal out of plane yield
2180 Int_t columns, // divide the output canvasses in this many columns
2181 Float_t rangeLow, // lower pt range
2182 Float_t rangeUp, // upper pt range
2183 TFile* readMe, // input file name (created by this unfolding class)
d06dbffe 2184 TString source, // source of the variation
2185 Bool_t RMS // return RMS of distribution of variations as error
a39e4b2b 2186 ) const
18698978 2187{
2188 // intermediate systematic check function. first index of supplied array is nominal value
18698978 2189 TList* listOfKeys((TList*)readMe->GetListOfKeys());
f3ba6c8e 2190 if(!listOfKeys) {
2191 printf(" > Fatal error, couldn't retrieve list of keys. Input file might have been corrupted ! < \n");
2192 return;
2193 }
2194 // check input params
2195 if(variationsIn->GetSize() != variationsOut->GetSize()) {
2196 printf(" > DoSystematics: fatal error, input arrays have different sizes ! < \n ");
2197 return;
2198 }
18698978 2199 TDirectoryFile* defRootDirIn(dynamic_cast<TDirectoryFile*>(readMe->Get(listOfKeys->At(variationsIn->At(0))->GetName())));
2200 TDirectoryFile* defRootDirOut(dynamic_cast<TDirectoryFile*>(readMe->Get(listOfKeys->At(variationsOut->At(0))->GetName())));
f3ba6c8e 2201 if(!(defRootDirIn && defRootDirOut)) {
2202 printf(" > DoSystematics: fatal error, couldn't retrieve nominal values ! < \n ");
2203 return;
2204 }
2205 TString defIn(defRootDirIn->GetName());
2206 TString defOut(defRootDirOut->GetName());
18698978 2207
2208 // define lines to make the output prettier
2209 TLine* lineLow(new TLine(rangeLow, 0., rangeLow, 2.));
2210 TLine* lineUp(new TLine(rangeUp, 0., rangeUp, 2.));
2211 lineLow->SetLineColor(11);
2212 lineUp->SetLineColor(11);
2213 lineLow->SetLineWidth(3);
2214 lineUp->SetLineWidth(3);
2215
2216 // define an output histogram with the maximum relative error from this systematic constribution
d06dbffe 2217 // if the option RMS is set to false, sigma is not really a standard deviation but holds the maximum (or minimum) relative value that the data has
2218 // reached in this function call.
2219 // if the option RMS is set to true, sigma holds the RMS value (equal to sigma as the mean is zero for relative errors) of the distribution of variations
2220 // which should correspond to a 68% confidence level
18698978 2221 relativeErrorInUp = new TH1D(Form("max #sigma/|x| from %s", source.Data()), Form("max #sigma/|x| from %s", source.Data()), fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
2222 relativeErrorInLow = new TH1D(Form("min #sigma/|x| from %s", source.Data()), Form("min #sigma/|x| from %s", source.Data()), fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
2223 relativeErrorOutUp = new TH1D(Form("max #sigma/|x| from %s", source.Data()), Form("max #sigma/|x| from %s", source.Data()), fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
2224 relativeErrorOutLow = new TH1D(Form("min #sigma/|x| from %s", source.Data()), Form("min #sigma/|x| from %s", source.Data()), fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
2225 for(Int_t b(0); b < fBinsTrue->GetSize()-1; b++) {
3e698d27 2226 if(!RMS) {
2227 relativeErrorInUp->SetBinContent(b+1, 1.);
2228 relativeErrorInUp->SetBinError(b+1, 0.);
2229 relativeErrorOutUp->SetBinContent(b+1, 1.);
2230 relativeErrorOutUp->SetBinError(b+1, .0);
2231 relativeErrorInLow->SetBinContent(b+1, 1.);
2232 relativeErrorInLow->SetBinError(b+1, 0.);
2233 relativeErrorOutLow->SetBinContent(b+1, 1.);
2234 relativeErrorOutLow->SetBinError(b+1, .0);
2235 } else if(RMS) {
2236 relativeErrorInUp->SetBinContent(b+1, 0.);
2237 relativeErrorInUp->SetBinError(b+1, 0.);
2238 relativeErrorOutUp->SetBinContent(b+1, 0.);
2239 relativeErrorOutUp->SetBinError(b+1, 0.);
2240 relativeErrorInLow->SetBinContent(b+1, 0.);
2241 relativeErrorInLow->SetBinError(b+1, 0.);
2242 relativeErrorOutLow->SetBinContent(b+1, 0.);
2243 relativeErrorOutLow->SetBinError(b+1, 0.);
2244 }
18698978 2245 }
3e698d27 2246 Int_t relativeErrorInUpN[100] = {0};
2247 Int_t relativeErrorOutUpN[100] = {0};
2248 Int_t relativeErrorInLowN[100] = {0};
2249 Int_t relativeErrorOutLowN[100] = {0};
2250
18698978 2251 // define an output histogram with the systematic error from this systematic constribution
2252 if(!relativeStatisticalErrorIn && !relativeStatisticalErrorOut) {
2253 relativeStatisticalErrorIn = new TH1D("relative statistical error, in plane", "#sigma/|x|, statistical, in plane", fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
2254 relativeStatisticalErrorOut = new TH1D("relative statistical error, out of plane", "#sigma/|x|, statistical, out of plane", fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
2255 }
2256
f3ba6c8e 2257 // prepare necessary canvasses
18698978 2258 TCanvas* canvasIn(new TCanvas(Form("SYST_%s_PearsonIn", source.Data()), Form("SYST_%s_PearsonIn", source.Data())));
f3ba6c8e 2259 TCanvas* canvasOut(0x0);
18698978 2260 if(fDphiUnfolding) canvasOut = new TCanvas(Form("SYST_%s_PearsonOut", source.Data()), Form("SYST_%s_PearsonOut", source.Data()));
2261 TCanvas* canvasRatioMeasuredRefoldedIn(new TCanvas(Form("SYST_%s_RefoldedIn", source.Data()), Form("SYST_%s_RefoldedIn", source.Data())));
f3ba6c8e 2262 TCanvas* canvasRatioMeasuredRefoldedOut(0x0);
18698978 2263 if(fDphiUnfolding) canvasRatioMeasuredRefoldedOut = new TCanvas(Form("SYST_%s_RefoldedOut", source.Data()), Form("SYST_%s_RefoldedOut", source.Data()));
2264 TCanvas* canvasSpectraIn(new TCanvas(Form("SYST_%s_SpectraIn", source.Data()), Form("SYST_%s_SpectraIn", source.Data())));
f3ba6c8e 2265 TCanvas* canvasSpectraOut(0x0);
18698978 2266 if(fDphiUnfolding) canvasSpectraOut = new TCanvas(Form("SYST_%s_SpectraOut", source.Data()), Form("SYST_%s_SpectraOut", source.Data()));
f3ba6c8e 2267 TCanvas* canvasRatio(0x0);
18698978 2268 if(fDphiUnfolding) canvasRatio = new TCanvas(Form("SYST_%s_Ratio", source.Data()), Form("SYST_%s_Ratio", source.Data()));
f3ba6c8e 2269 TCanvas* canvasV2(0x0);
18698978 2270 if(fDphiUnfolding) canvasV2 = new TCanvas(Form("SYST_%s_V2", source.Data()), Form("SYST_%s_V2", source.Data()));
2271 TCanvas* canvasMISC(new TCanvas(Form("SYST_%s_MISC", source.Data()), Form("SYST_%s_MISC", source.Data())));
2272 TCanvas* canvasMasterIn(new TCanvas(Form("SYST_%s_defaultIn", source.Data()), Form("SYST_%s_defaultIn", source.Data())));
f3ba6c8e 2273 TCanvas* canvasMasterOut(0x0);
18698978 2274 if(fDphiUnfolding) canvasMasterOut = new TCanvas(Form("SYST_%s_defaultOut", source.Data()), Form("SYST_%s_defaultOut", source.Data()));
f3ba6c8e 2275 (fDphiUnfolding) ? canvasMISC->Divide(4, 2) : canvasMISC->Divide(4, 1);
a39e4b2b 2276
18698978 2277 TCanvas* canvasProfiles(new TCanvas(Form("SYST_%s_canvasProfiles", source.Data()), Form("SYST_%s_canvasProfiles", source.Data())));
f3ba6c8e 2278 canvasProfiles->Divide(2);
18698978 2279 TProfile* ratioProfile(new TProfile(Form("SYST_%s_ratioProfile", source.Data()), Form("SYST_%s_ratioProfile", source.Data()), fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
2280 TProfile* v2Profile(new TProfile(Form("SYST_%s_v2Profile", source.Data()), Form("SYST_%s_v2Profile", source.Data()),fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
f3ba6c8e 2281 // get an estimate of the number of outputs and find the default set
5c636e0d 2282
2283 Int_t rows = 1;
2284 columns = variationsIn->GetSize()-1;
2285 (TMath::Floor(variationsIn->GetSize()/(float)columns)+((variationsIn->GetSize()%columns)>0));
f3ba6c8e 2286 canvasIn->Divide(columns, rows);
2287 if(canvasOut) canvasOut->Divide(columns, rows);
2288 canvasRatioMeasuredRefoldedIn->Divide(columns, rows);
2289 if(canvasRatioMeasuredRefoldedOut) canvasRatioMeasuredRefoldedOut->Divide(columns, rows);
2290 canvasSpectraIn->Divide(columns, rows);
2291 if(canvasSpectraOut) canvasSpectraOut->Divide(columns, rows);
2292 if(canvasRatio) canvasRatio->Divide(columns, rows);
2293 if(canvasV2) canvasV2->Divide(columns, rows);
2294 canvasMasterIn->Divide(columns, rows);
2295 if(canvasMasterOut) canvasMasterOut->Divide(columns, rows);
2296
2297 // prepare a separate set of canvases to hold the nominal points
18698978 2298 TCanvas* canvasNominalIn(new TCanvas(Form("Nominal_%s_PearsonIn", source.Data()), Form("Nominal_%s_PearsonIn", source.Data())));
f3ba6c8e 2299 TCanvas* canvasNominalOut(0x0);
18698978 2300 if(fDphiUnfolding) canvasNominalOut = new TCanvas(Form("Nominal_%s_PearsonOut", source.Data()), Form("Nominal_%s_PearsonOut", source.Data()));
2301 TCanvas* canvasNominalRatioMeasuredRefoldedIn(new TCanvas(Form("Nominal_%s_RefoldedIn", source.Data()), Form("Nominal_%s_RefoldedIn", source.Data())));
f3ba6c8e 2302 TCanvas* canvasNominalRatioMeasuredRefoldedOut(0x0);
18698978 2303 if(fDphiUnfolding) canvasNominalRatioMeasuredRefoldedOut = new TCanvas(Form("Nominal_%s_RefoldedOut", source.Data()), Form("Nominal_%s_RefoldedOut", source.Data()));
2304 TCanvas* canvasNominalSpectraIn(new TCanvas(Form("Nominal_%s_SpectraIn", source.Data()), Form("Nominal_%s_SpectraIn", source.Data())));
f3ba6c8e 2305 TCanvas* canvasNominalSpectraOut(0x0);
18698978 2306 if(fDphiUnfolding) canvasNominalSpectraOut = new TCanvas(Form("Nominal_%s_SpectraOut", source.Data()), Form("Nominal_%s_SpectraOut", source.Data()));
f3ba6c8e 2307 TCanvas* canvasNominalRatio(0x0);
18698978 2308 if(fDphiUnfolding) canvasNominalRatio = new TCanvas(Form("Nominal_%s_Ratio", source.Data()), Form("Nominal_%s_Ratio", source.Data()));
f3ba6c8e 2309 TCanvas* canvasNominalV2(0x0);
18698978 2310 if(fDphiUnfolding) canvasNominalV2 = new TCanvas(Form("Nominal_%s_V2", source.Data()), Form("Nominal_%s_V2", source.Data()));
2311 TCanvas* canvasNominalMISC(new TCanvas(Form("Nominal_%s_MISC", source.Data()), Form("Nominal_%s_MISC", source.Data())));
2312 TCanvas* canvasNominalMasterIn(new TCanvas(Form("Nominal_%s_defaultIn", source.Data()), Form("Nominal_%s_defaultIn", source.Data())));
f3ba6c8e 2313 TCanvas* canvasNominalMasterOut(0x0);
18698978 2314 if(fDphiUnfolding) canvasNominalMasterOut = new TCanvas(Form("Nominal_%s_defaultOut", source.Data()), Form("Nominal_%s_defaultOut", source.Data()));
f3ba6c8e 2315 (fDphiUnfolding) ? canvasNominalMISC->Divide(4, 2) : canvasNominalMISC->Divide(4, 1);
18698978 2316
2317 canvasNominalSpectraIn->Divide(2);
2318 if(canvasNominalSpectraOut) canvasNominalSpectraOut->Divide(2);
2319
2320 canvasNominalMasterIn->Divide(2);
2321 if(canvasNominalMasterOut) canvasNominalMasterOut->Divide(2);
f3ba6c8e 2322
2323 // extract the default output
2324 TH1D* defaultUnfoldedJetSpectrumIn(0x0);
2325 TH1D* defaultUnfoldedJetSpectrumOut(0x0);
2326 TDirectoryFile* defDirIn = (TDirectoryFile*)defRootDirIn->Get(Form("InPlane___%s", defIn.Data()));
2327 TDirectoryFile* defDirOut = (TDirectoryFile*)defRootDirOut->Get(Form("OutOfPlane___%s", defOut.Data()));
2328 if(defDirIn) defaultUnfoldedJetSpectrumIn = (TH1D*)defDirIn->Get(Form("UnfoldedSpectrum_in_%s", defIn.Data()));
2329 if(defDirOut) defaultUnfoldedJetSpectrumOut = (TH1D*)defDirOut->Get(Form("UnfoldedSpectrum_out_%s", defOut.Data()));
2330 printf(" > succesfully extracted default results < \n");
a39e4b2b 2331
f3ba6c8e 2332 // loop through the directories, only plot the graphs if the deconvolution converged
2333 TDirectoryFile* tempDirIn(0x0);
2334 TDirectoryFile* tempDirOut(0x0);
2335 TDirectoryFile* tempIn(0x0);
2336 TDirectoryFile* tempOut(0x0);
2337 TH1D* unfoldedSpectrumInForRatio(0x0);
2338 TH1D* unfoldedSpectrumOutForRatio(0x0);
2339 for(Int_t i(0), j(-1); i < variationsIn->GetSize(); i++) {
18698978 2340 tempDirIn = (dynamic_cast<TDirectoryFile*>(readMe->Get(listOfKeys->At(variationsIn->At(i))->GetName())));
2341 tempDirOut = (dynamic_cast<TDirectoryFile*>(readMe->Get(listOfKeys->At(variationsOut->At(i))->GetName())));
f3ba6c8e 2342 if(!(tempDirIn && tempDirOut)) {
2343 printf(" > DoSystematics: couldn't get a set of variations < \n");
2344 continue;
2345 }
2346 TString dirNameIn(tempDirIn->GetName());
2347 TString dirNameOut(tempDirOut->GetName());
2348 // try to read the in- and out of plane subdirs
2349 tempIn = (TDirectoryFile*)tempDirIn->Get(Form("InPlane___%s", dirNameIn.Data()));
2350 tempOut = (TDirectoryFile*)tempDirOut->Get(Form("OutOfPlane___%s", dirNameOut.Data()));
2351 j++;
2352 if(tempIn) {
2353 // to see if the unfolding converged try to extract the pearson coefficients
2354 TH2D* pIn((TH2D*)tempIn->Get(Form("PearsonCoefficients_in_%s", dirNameIn.Data())));
2355 if(pIn) {
2356 printf(" - %s in plane converged \n", dirNameIn.Data());
2357 canvasIn->cd(j);
2358 if(i==0) canvasNominalIn->cd(j);
2359 Style(gPad, "PEARSON");
2360 pIn->DrawCopy("colz");
2361 TGraphErrors* rIn((TGraphErrors*)tempIn->Get(Form("RatioRefoldedMeasured_%s", dirNameIn.Data())));
2362 if(rIn) {
2363 Style(rIn);
2364 printf(" > found RatioRefoldedMeasured < \n");
2365 canvasRatioMeasuredRefoldedIn->cd(j);
2366 if(i==0) canvasNominalRatioMeasuredRefoldedIn->cd(j);
18698978 2367 Style(gPad, "GRID");
f3ba6c8e 2368 rIn->SetFillColor(kRed);
2369 rIn->Draw("ap");
2370 }
2371 TH1D* dvector((TH1D*)tempIn->Get("dVector"));
2372 TH1D* avalue((TH1D*)tempIn->Get("SingularValuesOfAC"));
2373 TH2D* rm((TH2D*)tempIn->Get(Form("ResponseMatrixIn_%s", dirNameIn.Data())));
2374 TH1D* eff((TH1D*)tempIn->Get(Form("KinematicEfficiencyIn_%s", dirNameIn.Data())));
2375 if(dvector && avalue && rm && eff) {
2376 Style(dvector);
2377 Style(avalue);
2378 Style(rm);
2379 Style(eff);
2380 canvasMISC->cd(1);
2381 if(i==0) canvasNominalMISC->cd(1);
2382 Style(gPad, "SPECTRUM");
2383 dvector->DrawCopy();
2384 canvasMISC->cd(2);
2385 if(i==0) canvasNominalMISC->cd(2);
2386 Style(gPad, "SPECTRUM");
2387 avalue->DrawCopy();
2388 canvasMISC->cd(3);
2389 if(i==0) canvasNominalMISC->cd(3);
2390 Style(gPad, "PEARSON");
2391 rm->DrawCopy("colz");
2392 canvasMISC->cd(4);
2393 if(i==0) canvasNominalMISC->cd(4);
2835b296 2394 Style(gPad, "GRID");
f3ba6c8e 2395 eff->DrawCopy();
2396 } else if(rm && eff) {
2397 Style(rm);
2398 Style(eff);
2399 canvasMISC->cd(3);
2400 if(i==0) canvasNominalMISC->cd(3);
2401 Style(gPad, "PEARSON");
2402 rm->DrawCopy("colz");
2403 canvasMISC->cd(4);
2404 if(i==0) canvasNominalMISC->cd(4);
2835b296 2405 Style(gPad, "GRID");
f3ba6c8e 2406 eff->DrawCopy();
2407 }
2408 }
2409 TH1D* inputSpectrum((TH1D*)tempIn->Get(Form("InputSpectrum_in_%s", dirNameIn.Data())));
2410 TH1D* unfoldedSpectrum((TH1D*)tempIn->Get(Form("UnfoldedSpectrum_in_%s", dirNameIn.Data())));
2411 unfoldedSpectrumInForRatio = ProtectHeap(unfoldedSpectrum, kFALSE, TString("ForRatio"));
2412 TH1D* refoldedSpectrum((TH1D*)tempIn->Get(Form("RefoldedSpectrum_in_%s", dirNameIn.Data())));
2413 if(inputSpectrum && unfoldedSpectrum && refoldedSpectrum) {
2414 if(defaultUnfoldedJetSpectrumIn) {
2415 Style(defaultUnfoldedJetSpectrumIn, kBlue, kUnfoldedSpectrum);
2416 TH1D* temp((TH1D*)defaultUnfoldedJetSpectrumIn->Clone(Form("defaultUnfoldedJetSpectrumIn_%s", dirNameIn.Data())));
2417 temp->Divide(unfoldedSpectrum);
18698978 2418 // get the absolute relative error
2419 for(Int_t b(0); b < fBinsTrue->GetSize()-1; b++) {
d06dbffe 2420 if(!RMS) { // save the maximum deviation that a variation can cause
2421 // the variation is HIGHER than the nominal point, so the bar goes UP
2422 if( temp->GetBinContent(b+1) < 1 && temp->GetBinContent(b+1) < relativeErrorInUp->GetBinContent(b+1)) {
2423 relativeErrorInUp->SetBinContent(b+1, temp->GetBinContent(b+1));
2424 relativeErrorInUp->SetBinError(b+1, 0.);
2425 }
2426 // the variation is LOWER than the nominal point, so the bar goes DOWN
2427 else if(temp->GetBinContent(b+1) > 1 && temp->GetBinContent(b+1) > relativeErrorInLow->GetBinContent(b+1)) {
2428 relativeErrorInLow->SetBinContent(b+1, temp->GetBinContent(b+1));
2429 relativeErrorInLow->SetBinError(b+1, 0.);
2430 }
3e698d27 2431 } else if (RMS && !fSymmRMS) { // save info necessary for evaluating the RMS of a distribution of variations
2432 printf(" oops shouldnt be here \n " );
2433 if(temp->GetBinContent(b+1) < 1) {
d06dbffe 2434 relativeErrorInUp->SetBinContent(b+1, relativeErrorInUp->GetBinContent(b+1)+TMath::Power(1.-temp->GetBinContent(b+1), 2));
3e698d27 2435 relativeErrorInUpN[b]++;
d06dbffe 2436 }
2437 // the variation is LOWER than the nominal point, so the bar goes DOWN
2438 else if(temp->GetBinContent(b+1) > 1) {
2439 relativeErrorInLow->SetBinContent(b+1, relativeErrorInLow->GetBinContent(b+1)+TMath::Power(1.-temp->GetBinContent(b+1), 2));
3e698d27 2440 relativeErrorInLowN[b]++;
d06dbffe 2441 }
3e698d27 2442 } else if (fSymmRMS) {
2443 // save symmetric sum of square to get a symmetric rms
2444 relativeErrorInUp->SetBinContent(b+1, relativeErrorInUp->GetBinContent(b+1)+TMath::Power(temp->GetBinContent(b+1)-1., 2));
2445 relativeErrorInUpN[b]++;
18698978 2446 }
2447 if(temp->GetBinError(b+1) > 0) relativeStatisticalErrorIn->SetBinContent(b+1, temp->GetBinError(b+1)/temp->GetBinContent(b+1));
2448 }
f3ba6c8e 2449 temp->SetTitle(Form("[%s] / [%s]", defIn.Data(), dirNameIn.Data()));
2450 temp->GetXaxis()->SetTitle("p_{T, jet} [GeV/c]");
2451 temp->GetYaxis()->SetTitle("ratio");
2452 canvasMasterIn->cd(j);
f3ba6c8e 2453 temp->GetYaxis()->SetRangeUser(0., 2);
18698978 2454 Style(gPad, "GRID");
f3ba6c8e 2455 temp->DrawCopy();
18698978 2456 canvasNominalMasterIn->cd(1);
2457 Style(gPad, "GRID");
2458 if(i > 0 ) {
2459 TH1D* tempSyst((TH1D*)temp->Clone(Form("%s_syst", temp->GetName())));
2460 tempSyst->SetTitle(Form("[%s] / [%s]", defIn.Data(), dirNameIn.Data()));
2461 Style(tempSyst, (EColor)(i+2));
2462 if(i==1) tempSyst->DrawCopy();
2463 else tempSyst->DrawCopy("same");
2464 }
f3ba6c8e 2465 }
2466 TH1F* fitStatus((TH1F*)tempIn->Get(Form("fitStatus_%s_in", dirNameIn.Data())));
2467 canvasSpectraIn->cd(j);
18698978 2468 if(i==0) canvasNominalSpectraIn->cd(1);
f3ba6c8e 2469 Style(gPad);
2470 Style(unfoldedSpectrum, kRed, kUnfoldedSpectrum);
2471 unfoldedSpectrum->DrawCopy();
2472 Style(inputSpectrum, kGreen, kMeasuredSpectrum);
2473 inputSpectrum->DrawCopy("same");
2474 Style(refoldedSpectrum, kBlue, kFoldedSpectrum);
2475 refoldedSpectrum->DrawCopy("same");
2476 TLegend* l(AddLegend(gPad));
2477 Style(l);
2478 if(fitStatus && fitStatus->GetNbinsX() == 4) { // only available in chi2 fit
2479 Float_t chi(fitStatus->GetBinContent(1));
2480 Float_t pen(fitStatus->GetBinContent(2));
2481 Int_t dof((int)fitStatus->GetBinContent(3));
2482 Float_t beta(fitStatus->GetBinContent(4));
2483 l->AddEntry((TObject*)0, Form("#chi %.2f \tP %.2f \tDOF %i, #beta %.2f", chi, pen, dof, beta), "");
2484 } else if (fitStatus) { // only available in SVD fit
2485 Int_t reg((int)fitStatus->GetBinContent(1));
2486 l->AddEntry((TObject*)0, Form("REG %i", reg), "");
2487 }
18698978 2488 canvasNominalSpectraIn->cd(2);
2489 TH1D* tempSyst((TH1D*)unfoldedSpectrum->Clone(Form("%s_syst", unfoldedSpectrum->GetName())));
2490 tempSyst->SetTitle(Form("[%s]", dirNameIn.Data()));
2491 Style(tempSyst, (EColor)(i+2));
2492 Style(gPad, "SPECTRUM");
2493 if(i==0) tempSyst->DrawCopy();
2494 else tempSyst->DrawCopy("same");
f3ba6c8e 2495 }
2496 }
2497 if(tempOut) {
2498 TH2D* pOut((TH2D*)tempOut->Get(Form("PearsonCoefficients_out_%s", dirNameOut.Data())));
2499 if(pOut) {
2500 printf(" - %s out of plane converged \n", dirNameOut.Data());
2501 canvasOut->cd(j);
2502 if(i==0) canvasNominalOut->cd(j);
2503 Style(gPad, "PEARSON");
2504 pOut->DrawCopy("colz");
2505 TGraphErrors* rOut((TGraphErrors*)tempOut->Get(Form("RatioRefoldedMeasured_%s", dirNameOut.Data())));
2506 if(rOut) {
2507 Style(rOut);
2508 printf(" > found RatioRefoldedMeasured < \n");
2509 canvasRatioMeasuredRefoldedOut->cd(j);
2510 if(i==0) canvasNominalRatioMeasuredRefoldedOut->cd(j);
18698978 2511 Style(gPad, "GRID");
f3ba6c8e 2512 rOut->SetFillColor(kRed);
2513 rOut->Draw("ap");
2514 }
2515 TH1D* dvector((TH1D*)tempOut->Get("dVector"));
2516 TH1D* avalue((TH1D*)tempOut->Get("SingularValuesOfAC"));
2517 TH2D* rm((TH2D*)tempOut->Get(Form("ResponseMatrixOut_%s", dirNameOut.Data())));
2518 TH1D* eff((TH1D*)tempOut->Get(Form("KinematicEfficiencyOut_%s", dirNameOut.Data())));
2519 if(dvector && avalue && rm && eff) {
2520 Style(dvector);
2521 Style(avalue);
2522 Style(rm);
2523 Style(eff);
2524 canvasMISC->cd(5);
2525 if(i==0) canvasNominalMISC->cd(5);
2526 Style(gPad, "SPECTRUM");
2527 dvector->DrawCopy();
2528 canvasMISC->cd(6);
2529 if(i==0) canvasNominalMISC->cd(6);
2530 Style(gPad, "SPECTRUM");
2531 avalue->DrawCopy();
2532 canvasMISC->cd(7);
2533 if(i==0) canvasNominalMISC->cd(7);
2534 Style(gPad, "PEARSON");
2535 rm->DrawCopy("colz");
2536 canvasMISC->cd(8);
2537 if(i==0) canvasNominalMISC->cd(8);
2835b296 2538 Style(gPad, "GRID");
f3ba6c8e 2539 eff->DrawCopy();
2540 } else if(rm && eff) {
2541 Style(rm);
2542 Style(eff);
2543 canvasMISC->cd(7);
2544 if(i==0) canvasNominalMISC->cd(7);
2545 Style(gPad, "PEARSON");
2546 rm->DrawCopy("colz");
2547 canvasMISC->cd(8);
2548 if(i==0) canvasNominalMISC->cd(8);
2835b296 2549 Style(gPad, "GRID");
f3ba6c8e 2550 eff->DrawCopy();
2551 }
2552 }
2553 TH1D* inputSpectrum((TH1D*)tempOut->Get(Form("InputSpectrum_out_%s", dirNameOut.Data())));
2554 TH1D* unfoldedSpectrum((TH1D*)tempOut->Get(Form("UnfoldedSpectrum_out_%s", dirNameOut.Data())));
2555 unfoldedSpectrumOutForRatio = ProtectHeap(unfoldedSpectrum, kFALSE, TString("ForRatio"));
2556 TH1D* refoldedSpectrum((TH1D*)tempOut->Get(Form("RefoldedSpectrum_out_%s", dirNameOut.Data())));
2557 if(inputSpectrum && unfoldedSpectrum && refoldedSpectrum) {
2558 if(defaultUnfoldedJetSpectrumOut) {
2559 Style(defaultUnfoldedJetSpectrumOut, kBlue, kUnfoldedSpectrum);
2560 TH1D* temp((TH1D*)defaultUnfoldedJetSpectrumOut->Clone(Form("defaultUnfoldedJetSpectrumOut_%s", dirNameOut.Data())));
2561 temp->Divide(unfoldedSpectrum);
18698978 2562 // get the absolute relative error
2563 for(Int_t b(0); b < fBinsTrue->GetSize()-1; b++) {
d06dbffe 2564 if(!RMS) {
2565 // check if the error is larger than the current maximum
2566 if(temp->GetBinContent(b+1) < 1 && temp->GetBinContent(b+1) < relativeErrorOutUp->GetBinContent(b+1)) {
2567 relativeErrorOutUp->SetBinContent(b+1, temp->GetBinContent(b+1));
2568 relativeErrorOutUp->SetBinError(b+1, 0.);
2569 }
2570 // check if the error is smaller than the current minimum
2571 else if(temp->GetBinContent(b+1) > 1 && temp->GetBinContent(b+1) > relativeErrorOutLow->GetBinContent(b+1)) {
2572 relativeErrorOutLow->SetBinContent(b+1, temp->GetBinContent(b+1));
2573 relativeErrorOutLow->SetBinError(b+1, 0.);
2574 }
3e698d27 2575 } else if (RMS && !fSymmRMS) {
2576 printf(" OOps \n ");
d06dbffe 2577 if(temp->GetBinContent(b+1) < 1) {
2578 relativeErrorOutUp->SetBinContent(b+1, relativeErrorOutUp->GetBinContent(b+1)+TMath::Power(1.-temp->GetBinContent(b+1), 2));
3e698d27 2579 relativeErrorOutUpN[b]++;
d06dbffe 2580 }
2581 else if(temp->GetBinContent(b+1) > 1) {
2582 relativeErrorOutLow->SetBinContent(b+1, relativeErrorOutLow->GetBinContent(b+1)+TMath::Power(1.-temp->GetBinContent(b+1), 2));
3e698d27 2583 relativeErrorOutLowN[b]++;
d06dbffe 2584 }
3e698d27 2585 } else if (fSymmRMS) {
2586 // save symmetric rms value
2587 relativeErrorOutUp->SetBinContent(b+1, relativeErrorOutUp->GetBinContent(b+1)+TMath::Power(temp->GetBinContent(b+1)-1., 2));
2588 relativeErrorOutUpN[b]++;
18698978 2589 }
2590 if(temp->GetBinError(b+1) > 0) relativeStatisticalErrorOut->SetBinContent(b+1, temp->GetBinError(b+1)/temp->GetBinContent(b+1));
d06dbffe 2591 }
18698978 2592 temp->SetTitle(Form("[%s] / [%s]", defOut.Data(), dirNameOut.Data()));
f3ba6c8e 2593 temp->GetXaxis()->SetTitle("p_{T, jet} [GeV/c]");
2594 temp->GetYaxis()->SetTitle("ratio");
2595 canvasMasterOut->cd(j);
18698978 2596 temp->GetYaxis()->SetRangeUser(0., 2);
2597 Style(gPad, "GRID");
f3ba6c8e 2598 temp->DrawCopy();
18698978 2599 canvasNominalMasterOut->cd(1);
2600 Style(gPad, "GRID");
2601 if(i > 0 ) {
2602 TH1D* tempSyst((TH1D*)temp->Clone(Form("%s_syst", temp->GetName())));
2603 tempSyst->SetTitle(Form("[%s] / [%s]", defOut.Data(), dirNameOut.Data()));
2604 Style(tempSyst, (EColor)(i+2));
2605 if(i==1) tempSyst->DrawCopy();
2606 else tempSyst->DrawCopy("same");
2607 }
f3ba6c8e 2608 }
2609 TH1F* fitStatus((TH1F*)tempOut->Get(Form("fitStatus_%s_out", dirNameOut.Data())));
2610 canvasSpectraOut->cd(j);
18698978 2611 if(i==0) canvasNominalSpectraOut->cd(1);
f3ba6c8e 2612 Style(gPad);
2613 Style(unfoldedSpectrum, kRed, kUnfoldedSpectrum);
2614 unfoldedSpectrum->DrawCopy();
2615 Style(inputSpectrum, kGreen, kMeasuredSpectrum);
2616 inputSpectrum->DrawCopy("same");
2617 Style(refoldedSpectrum, kBlue, kFoldedSpectrum);
2618 refoldedSpectrum->DrawCopy("same");
2619 TLegend* l(AddLegend(gPad));
2620 Style(l);
2621 if(fitStatus && fitStatus->GetNbinsX() == 4) { // only available in chi2 fit
2622 Float_t chi(fitStatus->GetBinContent(1));
2623 Float_t pen(fitStatus->GetBinContent(2));
2624 Int_t dof((int)fitStatus->GetBinContent(3));
2625 Float_t beta(fitStatus->GetBinContent(4));
2626 l->AddEntry((TObject*)0, Form("#chi %.2f \tP %.2f \tDOF %i, #beta %.2f", chi, pen, dof, beta), "");
2627 } else if (fitStatus) { // only available in SVD fit
2628 Int_t reg((int)fitStatus->GetBinContent(1));
2629 l->AddEntry((TObject*)0, Form("REG %i", reg), "");
2630 }
18698978 2631 canvasNominalSpectraOut->cd(2);
2632 TH1D* tempSyst((TH1D*)unfoldedSpectrum->Clone(Form("%s_syst", unfoldedSpectrum->GetName())));
2633 tempSyst->SetTitle(Form("[%s]", dirNameOut.Data()));
2634 Style(tempSyst, (EColor)(i+2));
2635 Style(gPad, "SPECTRUM");
2636 if(i==0) tempSyst->DrawCopy();
2637 else tempSyst->DrawCopy("same");
f3ba6c8e 2638 }
2639 }
2640 if(canvasRatio && canvasV2) {
2641 canvasRatio->cd(j);
a39e4b2b 2642 if(i==0) {
2643 canvasNominalRatio->cd(j);
2644 if(nominal && nominalIn && nominalOut) {
2645 // if a nominal ratio is requested, delete the placeholder and update the nominal point
2646 delete nominal;
2647 delete nominalIn;
2648 delete nominalOut;
2649 nominalIn = (TH1D*)unfoldedSpectrumInForRatio->Clone("in plane jet yield");
2650 nominalOut = (TH1D*)unfoldedSpectrumOutForRatio->Clone("out of plane jet yield");
2651 nominal = (TH1D*)unfoldedSpectrumInForRatio->Clone("ratio in plane out of plane");
2652 nominal->Divide(nominal, unfoldedSpectrumOutForRatio); // standard root divide for uncorrelated histos
2653 }
2654 }
f3ba6c8e 2655 TGraphErrors* ratioYield(GetRatio(unfoldedSpectrumInForRatio, unfoldedSpectrumOutForRatio, TString(Form("ratio [in=%s, out=%s]", dirNameIn.Data(), dirNameOut.Data()))));
2656 Double_t _tempx(0), _tempy(0);
2657 if(ratioYield) {
2658 Style(ratioYield);
2659 for(Int_t b(0); b < fBinsTrue->GetSize(); b++) {
a39e4b2b 2660 ratioYield->GetPoint(b, _tempx, _tempy);
f3ba6c8e 2661 ratioProfile->Fill(_tempx, _tempy);
2662 }
2663 ratioProfile->GetYaxis()->SetRangeUser(-0., 2.);
2664 ratioProfile->GetXaxis()->SetRangeUser(rangeLow, rangeUp);
2665 ratioYield->GetYaxis()->SetRangeUser(-0., 2.);
2666 ratioYield->GetXaxis()->SetRangeUser(rangeLow, rangeUp);
2667 ratioYield->SetFillColor(kRed);
2668 ratioYield->Draw("ap");
2669 }
2670 canvasV2->cd(j);
2671 if(i==0) canvasNominalV2->cd(j);
35c03ef1 2672 TGraphErrors* ratioV2(GetV2(unfoldedSpectrumInForRatio,unfoldedSpectrumOutForRatio, fEventPlaneRes, TString(Form("v_{2} [in=%s, out=%s]", dirNameIn.Data(), dirNameOut.Data()))));
f3ba6c8e 2673 if(ratioV2) {
2674 Style(ratioV2);
2675 for(Int_t b(0); b < fBinsTrue->GetSize(); b++) {
a39e4b2b 2676 ratioV2->GetPoint(b, _tempx, _tempy);
f3ba6c8e 2677 v2Profile->Fill(_tempx, _tempy);
2678
2679 }
2680 v2Profile->GetYaxis()->SetRangeUser(-0., 2.);
2681 v2Profile->GetXaxis()->SetRangeUser(rangeLow, rangeUp);
2682 ratioV2->GetYaxis()->SetRangeUser(-.25, .75);
2683 ratioV2->GetXaxis()->SetRangeUser(rangeLow, rangeUp);
2684 ratioV2->SetFillColor(kRed);
2685 ratioV2->Draw("ap");
2686 }
2687 }
2688 delete unfoldedSpectrumInForRatio;
2689 delete unfoldedSpectrumOutForRatio;
2690 }
f3ba6c8e 2691 // save the canvasses
2692 canvasProfiles->cd(1);
2693 Style(ratioProfile);
2694 ratioProfile->DrawCopy();
2695 canvasProfiles->cd(2);
2696 Style(v2Profile);
2697 v2Profile->DrawCopy();
2698 SavePadToPDF(canvasProfiles);
2699 canvasProfiles->Write();
2700 SavePadToPDF(canvasIn);
2701 canvasIn->Write();
2702 if(canvasOut) {
2703 SavePadToPDF(canvasOut);
2704 canvasOut->Write();
2705 }
2706 SavePadToPDF(canvasRatioMeasuredRefoldedIn);
2707 canvasRatioMeasuredRefoldedIn->Write();
2708 if(canvasRatioMeasuredRefoldedOut) {
2709 SavePadToPDF(canvasRatioMeasuredRefoldedOut);
2710 canvasRatioMeasuredRefoldedOut->Write();
2711 }
2712 SavePadToPDF(canvasSpectraIn);
2713 canvasSpectraIn->Write();
2714 if(canvasSpectraOut) {
2715 SavePadToPDF(canvasSpectraOut);
2716 canvasSpectraOut->Write();
2717 SavePadToPDF(canvasRatio);
2718 canvasRatio->Write();
2719 SavePadToPDF(canvasV2);
2720 canvasV2->Write();
2721 }
2722 SavePadToPDF(canvasMasterIn);
2723 canvasMasterIn->Write();
2724 if(canvasMasterOut) {
2725 SavePadToPDF(canvasMasterOut);
2726 canvasMasterOut->Write();
2727 }
2728 SavePadToPDF(canvasMISC);
2729 canvasMISC->Write();
2730 // save the nomial canvasses
2731 SavePadToPDF(canvasNominalIn);
2732 canvasNominalIn->Write();
2733 if(canvasNominalOut) {
2734 SavePadToPDF(canvasNominalOut);
2735 canvasNominalOut->Write();
2736 }
2737 SavePadToPDF(canvasNominalRatioMeasuredRefoldedIn);
2738 canvasNominalRatioMeasuredRefoldedIn->Write();
2739 if(canvasNominalRatioMeasuredRefoldedOut) {
2740 SavePadToPDF(canvasNominalRatioMeasuredRefoldedOut);
2741 canvasNominalRatioMeasuredRefoldedOut->Write();
2742 }
18698978 2743 canvasNominalSpectraIn->cd(2);
2744 Style(AddLegend(gPad));
f3ba6c8e 2745 SavePadToPDF(canvasNominalSpectraIn);
2746 canvasNominalSpectraIn->Write();
2747 if(canvasNominalSpectraOut) {
18698978 2748 canvasNominalSpectraOut->cd(2);
2749 Style(AddLegend(gPad));
f3ba6c8e 2750 SavePadToPDF(canvasNominalSpectraOut);
2751 canvasNominalSpectraOut->Write();
2752 SavePadToPDF(canvasNominalRatio);
2753 canvasNominalRatio->Write();
2754 SavePadToPDF(canvasNominalV2);
2755 canvasNominalV2->Write();
2756 }
18698978 2757 canvasNominalMasterIn->cd(1);
2758 Style(AddLegend(gPad));
2759 lineUp->DrawClone("same");
2760 lineLow->DrawClone("same");
f3ba6c8e 2761 SavePadToPDF(canvasNominalMasterIn);
2762 canvasNominalMasterIn->Write();
2763 if(canvasNominalMasterOut) {
18698978 2764 canvasNominalMasterOut->cd(1);
2765 Style(AddLegend(gPad));
2766 lineUp->DrawClone("same");
2767 lineLow->DrawClone("same");
f3ba6c8e 2768 SavePadToPDF(canvasNominalMasterOut);
2769 canvasNominalMasterOut->Write();
2770 }
2771 SavePadToPDF(canvasNominalMISC);
2772 canvasNominalMISC->Write();
2773
18698978 2774 // save the relative errors
2775 for(Int_t b(0); b < fBinsTrue->GetSize()-1; b++) {
24005d85 2776 // to arrive at a min and max from here, combine in up and out low
d06dbffe 2777 if(!RMS) {
2778 relativeErrorInUp->SetBinContent(b+1, -1.*(relativeErrorInUp->GetBinContent(b+1)-1));
2779 relativeErrorInUp->SetBinError(b+1, 0.);
2780 relativeErrorOutUp->SetBinContent(b+1, -1.*(relativeErrorOutUp->GetBinContent(b+1)-1));
2781 relativeErrorOutUp->SetBinError(b+1, .0);
2782 relativeErrorInLow->SetBinContent(b+1, -1.*(relativeErrorInLow->GetBinContent(b+1)-1));
2783 relativeErrorInLow->SetBinError(b+1, 0.);
2784 relativeErrorOutLow->SetBinContent(b+1, -1.*(relativeErrorOutLow->GetBinContent(b+1)-1));
2785 relativeErrorOutLow->SetBinError(b+1, .0);
2786 } else if (RMS) {
2787 // these guys are already stored as percentages, so no need to remove the offset of 1
2788 // RMS is defined as sqrt(sum(squared))/N
2789 // min is defined as negative, max is defined as positive
3e698d27 2790 if(!fSymmRMS) {
2791 if(relativeErrorInUpN[b] < 1) relativeErrorInUpN[b] = 1;
2792 if(relativeErrorInLowN[b] < 1) relativeErrorInLowN[b] = 1;
2793 if(relativeErrorOutUpN[b] < 1) relativeErrorOutUpN[b] = 1;
2794 if(relativeErrorOutLowN[b] < 1) relativeErrorOutLowN[b] = 1;
2795 relativeErrorInUp->SetBinContent(b+1, TMath::Sqrt(relativeErrorInUp->GetBinContent(b+1)/relativeErrorInUpN[b]));
2796 relativeErrorInUp->SetBinError(b+1, 0.);
2797 relativeErrorOutUp->SetBinContent(b+1, TMath::Sqrt(relativeErrorOutUp->GetBinContent(b+1)/relativeErrorOutUpN[b]));
2798 relativeErrorOutUp->SetBinError(b+1, .0);
2799 relativeErrorInLow->SetBinContent(b+1, -1.*TMath::Sqrt(relativeErrorInLow->GetBinContent(b+1)/relativeErrorInLowN[b]));
2800 relativeErrorInLow->SetBinError(b+1, 0.);
2801 relativeErrorOutLow->SetBinContent(b+1, -1.*TMath::Sqrt(relativeErrorOutLow->GetBinContent(b+1)/relativeErrorOutLowN[b]));
2802 relativeErrorOutLow->SetBinError(b+1, .0);
2803 } else if (fSymmRMS) {
2804 if(relativeErrorInUpN[b] < 1) relativeErrorInUpN[b] = 1;
2805 if(relativeErrorOutUpN[b] < 1) relativeErrorOutUpN[b] = 1;
2806 relativeErrorInUp->SetBinContent(b+1, TMath::Sqrt(relativeErrorInUp->GetBinContent(b+1)/relativeErrorInUpN[b]));
2807 relativeErrorOutUp->SetBinContent(b+1, TMath::Sqrt(relativeErrorOutUp->GetBinContent(b+1)/relativeErrorOutUpN[b]));
2808 }
d06dbffe 2809 }
18698978 2810 }
2811 relativeErrorInUp->SetYTitle("relative uncertainty");
2812 relativeErrorOutUp->SetYTitle("relative uncertainty");
2813 relativeErrorInLow->SetYTitle("relative uncertainty");
2814 relativeErrorOutLow->SetYTitle("relative uncertainty");
2815 relativeErrorInUp->GetYaxis()->SetRangeUser(-1.5, 3.);
2816 relativeErrorInLow->GetYaxis()->SetRangeUser(-1.5, 3.);
2817 relativeErrorOutUp->GetYaxis()->SetRangeUser(-1.5, 3.);
2818 relativeErrorOutLow->GetYaxis()->SetRangeUser(-1.5, 3.);
2819
2820 canvasNominalMasterIn->cd(2);
2821 Style(gPad, "GRID");
2822 Style(relativeErrorInUp, kBlue, kBar);
2823 Style(relativeErrorInLow, kGreen, kBar);
2824 relativeErrorInUp->DrawCopy("b");
2825 relativeErrorInLow->DrawCopy("same b");
2826 Style(AddLegend(gPad));
2827 SavePadToPDF(canvasNominalMasterIn);
2828 canvasNominalMasterIn->Write();
2829 canvasNominalMasterOut->cd(2);
2830 Style(gPad, "GRID");
2831 Style(relativeErrorOutUp, kBlue, kBar);
2832 Style(relativeErrorOutLow, kGreen, kBar);
2833 relativeErrorOutUp->DrawCopy("b");
2834 relativeErrorOutLow->DrawCopy("same b");
2835 Style(AddLegend(gPad));
2836 SavePadToPDF(canvasNominalMasterOut);
2837 canvasNominalMasterOut->Write();
f3ba6c8e 2838}
2839//_____________________________________________________________________________
87233f72 2840void AliJetFlowTools::PostProcess(TString def, Int_t columns, Float_t rangeLow, Float_t rangeUp, TString in, TString out) const
d7ec324f 2841{
2842 // go through the output file and perform post processing routines
2843 // can either be performed in one go with the unfolding, or at a later stage
53547ff2 2844 if(fOutputFile && !fOutputFile->IsZombie()) fOutputFile->Close();
d7ec324f 2845 TFile readMe(in.Data(), "READ"); // open file read-only
2846 if(readMe.IsZombie()) {
2847 printf(" > Fatal error, couldn't read %s for post processing ! < \n", in.Data());
2848 return;
2849 }
2850 printf("\n\n\n\t\t POSTPROCESSING \n > Recovered the following file structure : \n <");
2851 readMe.ls();
2852 TList* listOfKeys((TList*)readMe.GetListOfKeys());
2853 if(!listOfKeys) {
2854 printf(" > Fatal error, couldn't retrieve list of keys. Input file might have been corrupted ! < \n");
2855 return;
2856 }
2857 // prepare necessary canvasses
53547ff2 2858 TCanvas* canvasIn(new TCanvas("PearsonIn", "PearsonIn"));
5e11c41c 2859 TCanvas* canvasOut(0x0);
486fb24e 2860 if(fDphiUnfolding) canvasOut = new TCanvas("PearsonOut", "PearsonOut");
53547ff2 2861 TCanvas* canvasRatioMeasuredRefoldedIn(new TCanvas("RefoldedIn", "RefoldedIn"));
5e11c41c 2862 TCanvas* canvasRatioMeasuredRefoldedOut(0x0);
486fb24e 2863 if(fDphiUnfolding) canvasRatioMeasuredRefoldedOut = new TCanvas("RefoldedOut", "RefoldedOut");
53547ff2 2864 TCanvas* canvasSpectraIn(new TCanvas("SpectraIn", "SpectraIn"));
5e11c41c 2865 TCanvas* canvasSpectraOut(0x0);
486fb24e 2866 if(fDphiUnfolding) canvasSpectraOut = new TCanvas("SpectraOut", "SpectraOut");
5e11c41c 2867 TCanvas* canvasRatio(0x0);
486fb24e 2868 if(fDphiUnfolding) canvasRatio = new TCanvas("Ratio", "Ratio");
5e11c41c 2869 TCanvas* canvasV2(0x0);
486fb24e 2870 if(fDphiUnfolding) canvasV2 = new TCanvas("V2", "V2");
53547ff2
RAB
2871 TCanvas* canvasMISC(new TCanvas("MISC", "MISC"));
2872 TCanvas* canvasMasterIn(new TCanvas("defaultIn", "defaultIn"));
5e11c41c 2873 TCanvas* canvasMasterOut(0x0);
486fb24e 2874 if(fDphiUnfolding) canvasMasterOut = new TCanvas("defaultOut", "defaultOut");
2875 (fDphiUnfolding) ? canvasMISC->Divide(4, 2) : canvasMISC->Divide(4, 1);
d7ec324f 2876 TDirectoryFile* defDir(0x0);
87233f72 2877 TCanvas* canvasProfiles(new TCanvas("canvasProfiles", "canvasProfiles"));
2878 canvasProfiles->Divide(2);
2879 TProfile* ratioProfile(new TProfile("ratioProfile", "ratioProfile", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
2880 TProfile* v2Profile(new TProfile("v2Profile", "v2Profile", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
d7ec324f 2881 // get an estimate of the number of outputs and find the default set
2882 Int_t cacheMe(0);
2883 for(Int_t i(0); i < listOfKeys->GetSize(); i++) {
2884 if(dynamic_cast<TDirectoryFile*>(readMe.Get(listOfKeys->At(i)->GetName()))) {
2885 if(!strcmp(listOfKeys->At(i)->GetName(), def.Data())) defDir = dynamic_cast<TDirectoryFile*>(readMe.Get(listOfKeys->At(i)->GetName()));
2886 cacheMe++;
2887 }
2888 }
f3ba6c8e 2889 Int_t rows(TMath::Floor(cacheMe/(float)columns)+((cacheMe%columns)>0));
53547ff2 2890 canvasIn->Divide(columns, rows);
5e11c41c 2891 if(canvasOut) canvasOut->Divide(columns, rows);
53547ff2 2892 canvasRatioMeasuredRefoldedIn->Divide(columns, rows);
5e11c41c 2893 if(canvasRatioMeasuredRefoldedOut) canvasRatioMeasuredRefoldedOut->Divide(columns, rows);
53547ff2 2894 canvasSpectraIn->Divide(columns, rows);
5e11c41c 2895 if(canvasSpectraOut) canvasSpectraOut->Divide(columns, rows);
2896 if(canvasRatio) canvasRatio->Divide(columns, rows);
2897 if(canvasV2) canvasV2->Divide(columns, rows);
d7ec324f 2898
53547ff2 2899 canvasMasterIn->Divide(columns, rows);
5e11c41c 2900 if(canvasMasterOut) canvasMasterOut->Divide(columns, rows);
d7ec324f 2901 // extract the default output
ab474fb0 2902 TH1D* defaultUnfoldedJetSpectrumIn(0x0);
2903 TH1D* defaultUnfoldedJetSpectrumOut(0x0);
d7ec324f 2904 if(defDir) {
2905 TDirectoryFile* defDirIn = (TDirectoryFile*)defDir->Get(Form("InPlane___%s", def.Data()));
2906 TDirectoryFile* defDirOut = (TDirectoryFile*)defDir->Get(Form("OutOfPlane___%s", def.Data()));
ab474fb0 2907 if(defDirIn) defaultUnfoldedJetSpectrumIn = (TH1D*)defDirIn->Get(Form("UnfoldedSpectrum_in_%s", def.Data()));
2908 if(defDirOut) defaultUnfoldedJetSpectrumOut = (TH1D*)defDirOut->Get(Form("UnfoldedSpectrum_out_%s", def.Data()));
d7ec324f 2909 printf(" > succesfully extracted default results < \n");
2910 }
a39e4b2b 2911
d7ec324f 2912 // loop through the directories, only plot the graphs if the deconvolution converged
2913 TDirectoryFile* tempDir(0x0);
2914 TDirectoryFile* tempIn(0x0);
2915 TDirectoryFile* tempOut(0x0);
2916 for(Int_t i(0), j(0); i < listOfKeys->GetSize(); i++) {
ab474fb0 2917 // read the directory by its name
d7ec324f 2918 tempDir = dynamic_cast<TDirectoryFile*>(readMe.Get(listOfKeys->At(i)->GetName()));
2919 if(!tempDir) continue;
2920 TString dirName(tempDir->GetName());
ab474fb0 2921 // try to read the in- and out of plane subdirs
d7ec324f 2922 tempIn = (TDirectoryFile*)tempDir->Get(Form("InPlane___%s", dirName.Data()));
2923 tempOut = (TDirectoryFile*)tempDir->Get(Form("OutOfPlane___%s", dirName.Data()));
2924 j++;
486fb24e 2925 if(!tempIn) { // attempt to get MakeAU output
2926 TString stringArray[] = {"a", "b", "c", "d", "e", "f", "g", "h"};
2927 TCanvas* tempPearson(new TCanvas(Form("pearson_%s", dirName.Data()), Form("pearson_%s", dirName.Data())));
2928 tempPearson->Divide(4,2);
2929 TCanvas* tempRatio(new TCanvas(Form("ratio_%s", dirName.Data()), Form("ratio_%s", dirName.Data())));
2930 tempRatio->Divide(4,2);
2931 TCanvas* tempResult(new TCanvas(Form("result_%s", dirName.Data()), Form("result_%s", dirName.Data())));
2932 tempResult->Divide(4,2);
2933 for(Int_t q(0); q < 8; q++) {
2934 tempIn = (TDirectoryFile*)tempDir->Get(Form("%s___%s", stringArray[q].Data(), dirName.Data()));
2935 if(tempIn) {
a39e4b2b 2936 // to see if the unfolding converged try to extract the pearson coefficients
2937 TH2D* pIn((TH2D*)tempIn->Get(Form("PearsonCoefficients_in_%s", dirName.Data())));
2938 if(pIn) {
486fb24e 2939 printf(" - %s in plane converged \n", dirName.Data());
a39e4b2b 2940 tempPearson->cd(1+q);
486fb24e 2941 Style(gPad, "PEARSON");
a39e4b2b 2942 pIn->DrawCopy("colz");
2943 TGraphErrors* rIn((TGraphErrors*)tempIn->Get(Form("RatioRefoldedMeasured_%s", dirName.Data())));
2944 if(rIn) {
2945 Style(rIn);
2946 printf(" > found RatioRefoldedMeasured < \n");
2947 tempRatio->cd(q+1);
2948 rIn->SetFillColor(kRed);
2949 rIn->Draw("ap");
2950 }
2951 TH1D* dvector((TH1D*)tempIn->Get("dVector"));
2952 TH1D* avalue((TH1D*)tempIn->Get("SingularValuesOfAC"));
2953 TH2D* rm((TH2D*)tempIn->Get(Form("ResponseMatrixIn_%s", dirName.Data())));
2954 TH1D* eff((TH1D*)tempIn->Get(Form("KinematicEfficiencyIn_%s", dirName.Data())));
2955 if(dvector && avalue && rm && eff) {
2956 Style(dvector);
2957 Style(avalue);
2958 Style(rm);
2959 Style(eff);
2960 canvasMISC->cd(1);
2961 Style(gPad, "SPECTRUM");
2962 dvector->DrawCopy();
2963 canvasMISC->cd(2);
2964 Style(gPad, "SPECTRUM");
2965 avalue->DrawCopy();
2966 canvasMISC->cd(3);
2967 Style(gPad, "PEARSON");
2968 rm->DrawCopy("colz");
2969 canvasMISC->cd(4);
2835b296 2970 Style(gPad, "GRID");
a39e4b2b 2971 eff->DrawCopy();
2972 } else if(rm && eff) {
2973 Style(rm);
2974 Style(eff);
2975 canvasMISC->cd(3);
2976 Style(gPad, "PEARSON");
2977 rm->DrawCopy("colz");
2978 canvasMISC->cd(4);
2835b296 2979 Style(gPad, "GRID");
a39e4b2b 2980 eff->DrawCopy();
2981 }
486fb24e 2982 }
a39e4b2b 2983 TH1D* inputSpectrum((TH1D*)tempIn->Get(Form("InputSpectrum_in_%s", dirName.Data())));
2984 TH1D* unfoldedSpectrum((TH1D*)tempIn->Get(Form("UnfoldedSpectrum_in_%s", dirName.Data())));
2985 TH1D* refoldedSpectrum((TH1D*)tempIn->Get(Form("RefoldedSpectrum_in_%s", dirName.Data())));
2986 if(inputSpectrum && unfoldedSpectrum && refoldedSpectrum) {
2987 if(defaultUnfoldedJetSpectrumIn) {
2988 Style(defaultUnfoldedJetSpectrumIn, kBlue, kUnfoldedSpectrum);
2989 TH1D* temp((TH1D*)defaultUnfoldedJetSpectrumIn->Clone(Form("defaultUnfoldedJetSpectrumIn_%s", dirName.Data())));
2990 temp->Divide(unfoldedSpectrum);
2991 temp->SetTitle(Form("ratio default unfolded / %s", dirName.Data()));
2992 temp->GetXaxis()->SetTitle("p_{T, jet} [GeV/c]");
2993 temp->GetYaxis()->SetTitle(Form("%s / %s", def.Data(), dirName.Data()));
2994 canvasMasterIn->cd(j);
2995 temp->GetYaxis()->SetRangeUser(0., 2);
2996 temp->DrawCopy();
2997 }
2998 TH1F* fitStatus((TH1F*)tempIn->Get(Form("fitStatus_%s_in", dirName.Data())));
2999 tempResult->cd(q+1);
3000 Style(gPad);
3001 Style(unfoldedSpectrum, kRed, kUnfoldedSpectrum);
3002 unfoldedSpectrum->DrawCopy();
3003 Style(inputSpectrum, kGreen, kMeasuredSpectrum);
3004 inputSpectrum->DrawCopy("same");
3005 Style(refoldedSpectrum, kBlue, kFoldedSpectrum);
3006 refoldedSpectrum->DrawCopy("same");
3007 TLegend* l(AddLegend(gPad));
3008 Style(l);
3009 if(fitStatus && fitStatus->GetNbinsX() == 4) { // only available in chi2 fit
3010 Float_t chi(fitStatus->GetBinContent(1));
3011 Float_t pen(fitStatus->GetBinContent(2));
3012 Int_t dof((int)fitStatus->GetBinContent(3));
3013 Float_t beta(fitStatus->GetBinContent(4));
3014 l->AddEntry((TObject*)0, Form("#chi %.2f \tP %.2f \tDOF %i, #beta %.2f", chi, pen, dof, beta), "");
3015 } else if (fitStatus) { // only available in SVD fit
3016 Int_t reg((int)fitStatus->GetBinContent(1));
3017 l->AddEntry((TObject*)0, Form("REG %i", reg), "");
3018 }
3019 }
486fb24e 3020 }
3021 }
3022 }
d7ec324f 3023 if(tempIn) {
3024 // to see if the unfolding converged try to extract the pearson coefficients
3025 TH2D* pIn((TH2D*)tempIn->Get(Form("PearsonCoefficients_in_%s", dirName.Data())));
3026 if(pIn) {
3027 printf(" - %s in plane converged \n", dirName.Data());
3028 canvasIn->cd(j);
3029 Style(gPad, "PEARSON");
3030 pIn->DrawCopy("colz");
3031 TGraphErrors* rIn((TGraphErrors*)tempIn->Get(Form("RatioRefoldedMeasured_%s", dirName.Data())));
3032 if(rIn) {
53547ff2 3033 Style(rIn);
d7ec324f 3034 printf(" > found RatioRefoldedMeasured < \n");
3035 canvasRatioMeasuredRefoldedIn->cd(j);
ab474fb0 3036 rIn->SetFillColor(kRed);
3037 rIn->Draw("ap");
d7ec324f 3038 }
3039 TH1D* dvector((TH1D*)tempIn->Get("dVector"));
3040 TH1D* avalue((TH1D*)tempIn->Get("SingularValuesOfAC"));
3041 TH2D* rm((TH2D*)tempIn->Get(Form("ResponseMatrixIn_%s", dirName.Data())));
3042 TH1D* eff((TH1D*)tempIn->Get(Form("KinematicEfficiencyIn_%s", dirName.Data())));
3043 if(dvector && avalue && rm && eff) {
53547ff2
RAB
3044 Style(dvector);
3045 Style(avalue);
3046 Style(rm);
3047 Style(eff);
d7ec324f 3048 canvasMISC->cd(1);
3049 Style(gPad, "SPECTRUM");
3050 dvector->DrawCopy();
3051 canvasMISC->cd(2);
3052 Style(gPad, "SPECTRUM");
3053 avalue->DrawCopy();
3054 canvasMISC->cd(3);
3055 Style(gPad, "PEARSON");
3056 rm->DrawCopy("colz");
3057 canvasMISC->cd(4);
2835b296 3058 Style(gPad, "GRID");
d7ec324f 3059 eff->DrawCopy();
53547ff2
RAB
3060 } else if(rm && eff) {
3061 Style(rm);
3062 Style(eff);
3063 canvasMISC->cd(3);
3064 Style(gPad, "PEARSON");
3065 rm->DrawCopy("colz");
3066 canvasMISC->cd(4);
2835b296 3067 Style(gPad, "GRID");
53547ff2 3068 eff->DrawCopy();
d7ec324f 3069 }
3070 }
3071 TH1D* inputSpectrum((TH1D*)tempIn->Get(Form("InputSpectrum_in_%s", dirName.Data())));
3072 TH1D* unfoldedSpectrum((TH1D*)tempIn->Get(Form("UnfoldedSpectrum_in_%s", dirName.Data())));
3073 TH1D* refoldedSpectrum((TH1D*)tempIn->Get(Form("RefoldedSpectrum_in_%s", dirName.Data())));
3074 if(inputSpectrum && unfoldedSpectrum && refoldedSpectrum) {
ab474fb0 3075 if(defaultUnfoldedJetSpectrumIn) {
3076 Style(defaultUnfoldedJetSpectrumIn, kBlue, kUnfoldedSpectrum);
3077 TH1D* temp((TH1D*)defaultUnfoldedJetSpectrumIn->Clone(Form("defaultUnfoldedJetSpectrumIn_%s", dirName.Data())));
d7ec324f 3078 temp->Divide(unfoldedSpectrum);
3079 temp->SetTitle(Form("ratio default unfolded / %s", dirName.Data()));
f3ba6c8e 3080 temp->GetXaxis()->SetTitle("p_{T, jet} [GeV/c]");
d7ec324f 3081 temp->GetYaxis()->SetTitle(Form("%s / %s", def.Data(), dirName.Data()));
3082 canvasMasterIn->cd(j);
ab474fb0 3083 temp->GetYaxis()->SetRangeUser(0., 2);
d7ec324f 3084 temp->DrawCopy();
3085 }
3086 TH1F* fitStatus((TH1F*)tempIn->Get(Form("fitStatus_%s_in", dirName.Data())));
3087 canvasSpectraIn->cd(j);
3088 Style(gPad);
53547ff2 3089 Style(unfoldedSpectrum, kRed, kUnfoldedSpectrum);
d7ec324f 3090 unfoldedSpectrum->DrawCopy();
53547ff2 3091 Style(inputSpectrum, kGreen, kMeasuredSpectrum);
d7ec324f 3092 inputSpectrum->DrawCopy("same");
53547ff2 3093 Style(refoldedSpectrum, kBlue, kFoldedSpectrum);
d7ec324f 3094 refoldedSpectrum->DrawCopy("same");
3095 TLegend* l(AddLegend(gPad));
53547ff2
RAB
3096 Style(l);
3097 if(fitStatus && fitStatus->GetNbinsX() == 4) { // only available in chi2 fit
3098 Float_t chi(fitStatus->GetBinContent(1));
3099 Float_t pen(fitStatus->GetBinContent(2));
d7ec324f 3100 Int_t dof((int)fitStatus->GetBinContent(3));
53547ff2
RAB
3101 Float_t beta(fitStatus->GetBinContent(4));
3102 l->AddEntry((TObject*)0, Form("#chi %.2f \tP %.2f \tDOF %i, #beta %.2f", chi, pen, dof, beta), "");
3103 } else if (fitStatus) { // only available in SVD fit
3104 Int_t reg((int)fitStatus->GetBinContent(1));
3105 l->AddEntry((TObject*)0, Form("REG %i", reg), "");
d7ec324f 3106 }
3107 }
3108 }
3109 if(tempOut) {
3110 TH2D* pOut((TH2D*)tempOut->Get(Form("PearsonCoefficients_out_%s", dirName.Data())));
3111 if(pOut) {
3112 printf(" - %s out of plane converged \n", dirName.Data());
3113 canvasOut->cd(j);
3114 Style(gPad, "PEARSON");
3115 pOut->DrawCopy("colz");
3116 TGraphErrors* rOut((TGraphErrors*)tempOut->Get(Form("RatioRefoldedMeasured_%s", dirName.Data())));
3117 if(rOut) {
53547ff2 3118 Style(rOut);
d7ec324f 3119 printf(" > found RatioRefoldedMeasured < \n");
3120 canvasRatioMeasuredRefoldedOut->cd(j);
ab474fb0 3121 rOut->SetFillColor(kRed);
3122 rOut->Draw("ap");
d7ec324f 3123 }
3124 TH1D* dvector((TH1D*)tempOut->Get("dVector"));
3125 TH1D* avalue((TH1D*)tempOut->Get("SingularValuesOfAC"));
3126 TH2D* rm((TH2D*)tempOut->Get(Form("ResponseMatrixOut_%s", dirName.Data())));
3127 TH1D* eff((TH1D*)tempOut->Get(Form("KinematicEfficiencyOut_%s", dirName.Data())));
3128 if(dvector && avalue && rm && eff) {
53547ff2
RAB
3129 Style(dvector);
3130 Style(avalue);
3131 Style(rm);
3132 Style(eff);
d7ec324f 3133 canvasMISC->cd(5);
3134 Style(gPad, "SPECTRUM");
3135 dvector->DrawCopy();
3136 canvasMISC->cd(6);
3137 Style(gPad, "SPECTRUM");
3138 avalue->DrawCopy();
3139 canvasMISC->cd(7);
3140 Style(gPad, "PEARSON");
3141 rm->DrawCopy("colz");
3142 canvasMISC->cd(8);
2835b296 3143 Style(gPad, "GRID");
d7ec324f 3144 eff->DrawCopy();
53547ff2
RAB
3145 } else if(rm && eff) {
3146 Style(rm);
3147 Style(eff);
549b5f40 3148 canvasMISC->cd(7);
53547ff2
RAB
3149 Style(gPad, "PEARSON");
3150 rm->DrawCopy("colz");
549b5f40 3151 canvasMISC->cd(8);
2835b296 3152 Style(gPad, "GRID");
53547ff2 3153 eff->DrawCopy();
d7ec324f 3154 }
3155 }
3156 TH1D* inputSpectrum((TH1D*)tempOut->Get(Form("InputSpectrum_out_%s", dirName.Data())));
3157 TH1D* unfoldedSpectrum((TH1D*)tempOut->Get(Form("UnfoldedSpectrum_out_%s", dirName.Data())));
3158 TH1D* refoldedSpectrum((TH1D*)tempOut->Get(Form("RefoldedSpectrum_out_%s", dirName.Data())));
3159 if(inputSpectrum && unfoldedSpectrum && refoldedSpectrum) {
ab474fb0 3160 if(defaultUnfoldedJetSpectrumOut) {
3161 Style(defaultUnfoldedJetSpectrumOut, kBlue, kUnfoldedSpectrum);
3162 TH1D* temp((TH1D*)defaultUnfoldedJetSpectrumOut->Clone(Form("defaultUnfoldedJetSpectrumOut_%s", dirName.Data())));
d7ec324f 3163 temp->Divide(unfoldedSpectrum);
3164 temp->SetTitle(Form("ratio default unfolded / %s", dirName.Data()));
f3ba6c8e 3165 temp->GetXaxis()->SetTitle("p_{T, jet} [GeV/c]");
d7ec324f 3166 temp->GetYaxis()->SetTitle(Form("%s / %s", def.Data(), dirName.Data()));
3167 canvasMasterOut->cd(j);
ab474fb0 3168 temp->GetYaxis()->SetRangeUser(0., 2.);
d7ec324f 3169 temp->DrawCopy();
3170 }
3171 TH1F* fitStatus((TH1F*)tempOut->Get(Form("fitStatus_%s_out", dirName.Data())));
3172 canvasSpectraOut->cd(j);
3173 Style(gPad);
53547ff2 3174 Style(unfoldedSpectrum, kRed, kUnfoldedSpectrum);
d7ec324f 3175 unfoldedSpectrum->DrawCopy();
53547ff2 3176 Style(inputSpectrum, kGreen, kMeasuredSpectrum);
d7ec324f 3177 inputSpectrum->DrawCopy("same");
53547ff2 3178 Style(refoldedSpectrum, kBlue, kFoldedSpectrum);
d7ec324f 3179 refoldedSpectrum->DrawCopy("same");
3180 TLegend* l(AddLegend(gPad));
53547ff2
RAB
3181 Style(l);
3182 if(fitStatus && fitStatus->GetNbinsX() == 4) { // only available in chi2 fit
3183 Float_t chi(fitStatus->GetBinContent(1));
3184 Float_t pen(fitStatus->GetBinContent(2));
3185 Int_t dof((int)fitStatus->GetBinContent(3));
3186 Float_t beta(fitStatus->GetBinContent(4));
3187 l->AddEntry((TObject*)0, Form("#chi %.2f \tP %.2f \tDOF %i, #beta %.2f", chi, pen, dof, beta), "");
3188 } else if (fitStatus) { // only available in SVD fit
3189 Int_t reg((int)fitStatus->GetBinContent(1));
3190 l->AddEntry((TObject*)0, Form("REG %i", reg), "");
d7ec324f 3191 }
3192 }
3193 }
5e11c41c 3194 if(canvasRatio && canvasV2) {
3195 canvasRatio->cd(j);
3196 TGraphErrors* ratioYield((TGraphErrors*)tempDir->Get(Form("RatioInOutPlane_%s", dirName.Data())));
87233f72 3197 Double_t _tempx(0), _tempy(0);
5e11c41c 3198 if(ratioYield) {
3199 Style(ratioYield);
87233f72 3200 for(Int_t b(0); b < fBinsTrue->GetSize(); b++) {
a39e4b2b 3201 ratioYield->GetPoint(b, _tempx, _tempy);
87233f72 3202 ratioProfile->Fill(_tempx, _tempy);
3203 }
9f892925 3204 ratioProfile->GetYaxis()->SetRangeUser(-0., 2.);
87233f72 3205 ratioProfile->GetXaxis()->SetRangeUser(rangeLow, rangeUp);
9f892925 3206 ratioYield->GetYaxis()->SetRangeUser(-0., 2.);
87233f72 3207 ratioYield->GetXaxis()->SetRangeUser(rangeLow, rangeUp);
ab474fb0 3208 ratioYield->SetFillColor(kRed);
3209 ratioYield->Draw("ap");
5e11c41c 3210 }
3211 canvasV2->cd(j);
3212 TGraphErrors* ratioV2((TGraphErrors*)tempDir->Get(Form("v2_%s", dirName.Data())));
3213 if(ratioV2) {
3214 Style(ratioV2);
87233f72 3215 for(Int_t b(0); b < fBinsTrue->GetSize(); b++) {
a39e4b2b 3216 ratioV2->GetPoint(b, _tempx, _tempy);
87233f72 3217 v2Profile->Fill(_tempx, _tempy);
3218
3219 }
9f892925 3220 v2Profile->GetYaxis()->SetRangeUser(-0., 2.);
87233f72 3221 v2Profile->GetXaxis()->SetRangeUser(rangeLow, rangeUp);
5e11c41c 3222 ratioV2->GetYaxis()->SetRangeUser(-.25, .75);
87233f72 3223 ratioV2->GetXaxis()->SetRangeUser(rangeLow, rangeUp);
ab474fb0 3224 ratioV2->SetFillColor(kRed);
3225 ratioV2->Draw("ap");
5e11c41c 3226 }
d7ec324f 3227 }
3228 }
3229 TFile output(out.Data(), "RECREATE");
87233f72 3230 canvasProfiles->cd(1);
3231 Style(ratioProfile);
3232 ratioProfile->DrawCopy();
3233 canvasProfiles->cd(2);
3234 Style(v2Profile);
3235 v2Profile->DrawCopy();
3236 SavePadToPDF(canvasProfiles);
3237 canvasProfiles->Write();
512ced40 3238 SavePadToPDF(canvasIn);
d7ec324f 3239 canvasIn->Write();
5e11c41c 3240 if(canvasOut) {
3241 SavePadToPDF(canvasOut);
3242 canvasOut->Write();
3243 }
512ced40 3244 SavePadToPDF(canvasRatioMeasuredRefoldedIn);
d7ec324f 3245 canvasRatioMeasuredRefoldedIn->Write();
5e11c41c 3246 if(canvasRatioMeasuredRefoldedOut) {
3247 SavePadToPDF(canvasRatioMeasuredRefoldedOut);
3248 canvasRatioMeasuredRefoldedOut->Write();
3249 }
512ced40 3250 SavePadToPDF(canvasSpectraIn);
d7ec324f 3251 canvasSpectraIn->Write();
5e11c41c 3252 if(canvasSpectraOut) {
3253 SavePadToPDF(canvasSpectraOut);
3254 canvasSpectraOut->Write();
3255 SavePadToPDF(canvasRatio);
3256 canvasRatio->Write();
3257 SavePadToPDF(canvasV2);
3258 canvasV2->Write();
3259 }
512ced40 3260 SavePadToPDF(canvasMasterIn);
d7ec324f 3261 canvasMasterIn->Write();
5e11c41c 3262 if(canvasMasterOut) {
3263 SavePadToPDF(canvasMasterOut);
3264 canvasMasterOut->Write();
3265 }
512ced40 3266 SavePadToPDF(canvasMISC);
d7ec324f 3267 canvasMISC->Write();
3268 output.Write();
3269 output.Close();
3270}
3271//_____________________________________________________________________________
4292ca60 3272Bool_t AliJetFlowTools::SetRawInput (
3273 TH2D* detectorResponse, // detector response matrix
3274 TH1D* jetPtIn, // in plane jet spectrum
3275 TH1D* jetPtOut, // out of plane jet spectrum
3276 TH1D* dptIn, // in plane delta pt distribution
3277 TH1D* dptOut, // out of plane delta pt distribution
3278 Int_t eventCount) {
3279 // set input histograms manually
3280 fDetectorResponse = detectorResponse;
3281 fSpectrumIn = jetPtIn;
3282 fSpectrumOut = jetPtOut;
3283 fDptInDist = dptIn;
3284 fDptOutDist = dptOut;
3285 fRawInputProvided = kTRUE;
3286 // check if all data is provided
3287 if(!fDetectorResponse) {
3288 printf(" fDetectorResponse not found \n ");
3289 return kFALSE;
3290 }
3291 // check if the pt bin for true and rec have been set
3292 if(!fBinsTrue || !fBinsRec) {
3293 printf(" No true or rec bins set, please set binning ! \n");
3294 return kFALSE;
3295 }
3296 if(!fRMSSpectrumIn) { // initialie the profiles which will hold the RMS values. if binning changes in between unfolding
a39e4b2b 3297 // procedures, these profiles will be nonsensical, user is responsible
4292ca60 3298 fRMSSpectrumIn = new TProfile("fRMSSpectrumIn", "fRMSSpectrumIn", fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
3299 fRMSSpectrumOut = new TProfile("fRMSSpectrumOut", "fRMSSpectrumOut", fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
3300 fRMSRatio = new TProfile("fRMSRatio", "fRMSRatio", fBinsTrue->GetSize()-1, fBinsTrue->GetArray());
3301 }
3302 // normalize spectra to event count if requested
3303 if(fNormalizeSpectra) {
3304 fEventCount = eventCount;
3305 if(fEventCount > 0) {
3306 fSpectrumIn->Sumw2(); // necessary for correct error propagation of scale
3307 fSpectrumOut->Sumw2();
3308 fSpectrumIn->Scale(1./((double)fEventCount));
3309 fSpectrumOut->Scale(1./((double)fEventCount));
3310 }
3311 }
3312 if(!fNormalizeSpectra && fEventCount > 0) {
3313 fSpectrumIn->Sumw2(); // necessary for correct error propagation of scale
3314 fSpectrumOut->Sumw2();
3315 fSpectrumIn->Scale(1./((double)fEventCount));
3316 fSpectrumOut->Scale(1./((double)fEventCount));
3317 }
3318 fDptIn = ConstructDPtResponseFromTH1D(fDptInDist, fAvoidRoundingError);
c03f7598 3319 fDptIn->SetNameTitle(Form("dpt_response_INPLANE_%i", fCentralityArray->At(0)), Form("dpt_response_INPLANE_%i", fCentralityArray->At(0)));
f3ba6c8e 3320 fDptIn->GetXaxis()->SetTitle("p_{T, jet}^{gen} [GeV/c]");
3321 fDptIn->GetYaxis()->SetTitle("p_{T, jet}^{rec} [GeV/c]");
4292ca60 3322 fDptOut = ConstructDPtResponseFromTH1D(fDptOutDist, fAvoidRoundingError);
c03f7598 3323 fDptOut->SetNameTitle(Form("dpt_response_OUTOFPLANE_%i", fCentralityArray->At(0)), Form("dpt_response_OUTOFPLANE_%i", fCentralityArray->At(0)));
f3ba6c8e 3324 fDptOut->GetXaxis()->SetTitle("p_{T, jet}^{gen} [GeV/c]");
3325 fDptOut->GetYaxis()->SetTitle("p_{T, jet}^{rec} [GeV/c]");
4292ca60 3326
3327 return kTRUE;
3328}
3329//_____________________________________________________________________________
3330TGraphErrors* AliJetFlowTools::GetRatio(TH1 *h1, TH1* h2, TString name, Bool_t appendFit, Int_t xmax)
dc1455ee 3331{
ef12d5a5 3332 // return ratio of h1 / h2
3333 // histograms can have different binning. errors are propagated as uncorrelated
20abfcc4 3334 if(!(h1 && h2) ) {
3335 printf(" GetRatio called with NULL argument(s) \n ");
3336 return 0x0;
3337 }
ad04a83c 3338 Int_t j(0);
4292ca60 3339 TGraphErrors *gr = new TGraphErrors();
f3ba6c8e 3340 gr->GetXaxis()->SetTitle("p_{T, jet} [GeV/c]");
ef12d5a5 3341 Double_t binCent(0.), ratio(0.), error2(0.), binWidth(0.);
7bf39895 3342 TH1* dud((TH1*)h1->Clone("dud"));
486fb24e 3343 dud->Sumw2();
3344 h1->Sumw2();
3345 h2->Sumw2();
3346 if(!dud->Divide(h1, h2)) {
3347 printf(" > ROOT failed to divide two histogams, dividing manually \n < ");
7bf39895 3348 for(Int_t i(1); i <= h1->GetNbinsX(); i++) {
3349 binCent = h1->GetXaxis()->GetBinCenter(i);
3350 if(xmax > 0. && binCent > xmax) continue;
3351 j = h2->FindBin(binCent);
3352 binWidth = h1->GetXaxis()->GetBinWidth(i);
3353 if(h2->GetBinContent(j) > 0.) {
3354 ratio = h1->GetBinContent(i)/h2->GetBinContent(j);
7bf39895 3355 Double_t A = h1->GetBinError(i)/h1->GetBinContent(i);
3356 Double_t B = h2->GetBinError(i)/h2->GetBinContent(i);
3357 error2 = ratio*ratio*A*A+ratio*ratio*B*B;
3358 if(error2 > 0 ) error2 = TMath::Sqrt(error2);
35c03ef1 3359 gr->SetPoint(i-1, binCent, ratio);
3360 gr->SetPointError(i-1, 0.5*binWidth, error2);
7bf39895 3361 }
3362 }
3363 } else {
486fb24e 3364 printf( " > using ROOT to divide two histograms < \n");
7bf39895 3365 for(Int_t i(1); i <= h1->GetNbinsX(); i++) {
3366 binCent = dud->GetXaxis()->GetBinCenter(i);
3367 if(xmax > 0. && binCent > xmax) continue;
3368 binWidth = dud->GetXaxis()->GetBinWidth(i);
35c03ef1 3369 gr->SetPoint(i-1,binCent,dud->GetBinContent(i));
3370 gr->SetPointError(i-1, 0.5*binWidth,dud->GetBinError(i));
dc1455ee 3371 }
3372 }
7bf39895 3373
ad04a83c 3374 if(appendFit) {
4292ca60 3375 TF1* fit(new TF1("lin", "pol0", 10, 100));
ad04a83c 3376 gr->Fit(fit);
3377 }
4292ca60 3378 if(strcmp(name, "")) gr->SetNameTitle(name.Data(), name.Data());
7bf39895 3379 if(dud) delete dud;
dc1455ee 3380 return gr;
3381}
3382//_____________________________________________________________________________
ef12d5a5 3383TGraphErrors* AliJetFlowTools::GetV2(TH1 *h1, TH1* h2, Double_t r, TString name)
3384{
3385 // get v2 from difference of in plane, out of plane yield
3386 // h1 must hold the in-plane yield, h2 holds the out of plane yield
549b5f40
RAB
3387 // different binning is allowed but will mean that the error
3388 // propagation is unreliable
ef12d5a5 3389 // r is the event plane resolution for the chosen centrality
3390 if(!(h1 && h2) ) {
3391 printf(" GetV2 called with NULL argument(s) \n ");
3392 return 0x0;
3393 }
ef12d5a5 3394 TGraphErrors *gr = new TGraphErrors();
f3ba6c8e 3395 gr->GetXaxis()->SetTitle("p_{T, jet} [GeV/c]");
ef12d5a5 3396 Float_t binCent(0.), ratio(0.), error2(0.), binWidth(0.);
3397 Double_t pre(TMath::Pi()/(4.*r)), in(0.), out(0.), ein(0.), eout(0.);
35c03ef1 3398
ef12d5a5 3399 for(Int_t i(1); i <= h1->GetNbinsX(); i++) {
3400 binCent = h1->GetXaxis()->GetBinCenter(i);
ef12d5a5 3401 binWidth = h1->GetXaxis()->GetBinWidth(i);
35c03ef1 3402 if(h2->GetBinContent(i) > 0.) {
ef12d5a5 3403 in = h1->GetBinContent(i);
3404 ein = h1->GetBinError(i);
35c03ef1 3405 out = h2->GetBinContent(i);
35c03ef1 3406 eout = h2->GetBinError(i);
ef12d5a5 3407 ratio = pre*((in-out)/(in+out));
35c03ef1 3408 error2 = (4.*out*out/(TMath::Power(in+out, 4)))*ein*ein+(4.*in*in/(TMath::Power(in+out, 4)))*eout*eout;
3409 error2 = error2*pre*pre;
ef12d5a5 3410 if(error2 > 0) error2 = TMath::Sqrt(error2);
35c03ef1 3411 gr->SetPoint(i-1,binCent,ratio);
3412 gr->SetPointError(i-1,0.5*binWidth,error2);
ef12d5a5 3413 }
3414 }
3415 if(strcmp(name, "")) gr->SetNameTitle(name.Data(), name.Data());
3416 return gr;
3417}
3418//_____________________________________________________________________________
a39e4b2b 3419TGraphAsymmErrors* AliJetFlowTools::GetV2WithSystematicErrors(
3420 TH1* h1, TH1* h2, Double_t r, TString name,
3421 TH1* relativeErrorInUp,
3422 TH1* relativeErrorInLow,
3423 TH1* relativeErrorOutUp,
24af86e7 3424 TH1* relativeErrorOutLow,
3425 Float_t rho) const
a39e4b2b 3426{
3427 // get v2 with asymmetric systematic error
3428 // note that this is ONLY the systematic error, no statistical error!
24af86e7 3429 // rho is the pearson correlation coefficient
a39e4b2b 3430 TGraphErrors* tempV2(GetV2(h1, h2, r, name));
3431 Double_t* ax = new Double_t[fBinsTrue->GetSize()-1];
3432 Double_t* ay = new Double_t[fBinsTrue->GetSize()-1];
3433 Double_t* axh = new Double_t[fBinsTrue->GetSize()-1];
3434 Double_t* axl = new Double_t[fBinsTrue->GetSize()-1];
3435 Double_t* ayh = new Double_t[fBinsTrue->GetSize()-1];
3436 Double_t* ayl = new Double_t[fBinsTrue->GetSize()-1];
3437 Double_t in(0.), out(0.), einUp(0.), einLow(0.), eoutUp(0.), eoutLow(0.), error2Up(0.), error2Low(0.);
3438 // loop through the bins and do error propagation
3439 for(Int_t i(0); i < fBinsTrue->GetSize()-1; i++) {
3440 // extract the absolute errors
3441 in = h1->GetBinContent(i+1);
5159ed9e 3442 einUp = TMath::Abs(in*relativeErrorInUp->GetBinContent(i+1));
3443 einLow = TMath::Abs(in*relativeErrorInLow->GetBinContent(1+i));
a39e4b2b 3444 out = h2->GetBinContent(i+1);
5159ed9e 3445 eoutUp = TMath::Abs(out*relativeErrorOutUp->GetBinContent(1+i));
3446 eoutLow = TMath::Abs(out*relativeErrorOutLow->GetBinContent(1+i));
a39e4b2b 3447 // get the error squared
b3b03df7 3448 if(rho <= 0) {
3449 error2Up = TMath::Power(((r*4.)/(TMath::Pi())),-2.)*((4.*out*out/(TMath::Power(in+out, 4)))*einUp*einUp+(4.*in*in/(TMath::Power(in+out, 4)))*eoutLow*eoutLow);
3450 error2Low =TMath::Power(((r*4.)/(TMath::Pi())),-2.)*((4.*out*out/(TMath::Power(in+out, 4)))*einLow*einLow+(4.*in*in/(TMath::Power(in+out, 4)))*eoutUp*eoutUp);
3451 } else {
3452 error2Up = TMath::Power(((r*4.)/(TMath::Pi())),-2.)*((4.*out*out/(TMath::Power(in+out, 4)))*einUp*einUp+(4.*in*in/(TMath::Power(in+out, 4)))*eoutUp*eoutUp-((8.*out*in)/(TMath::Power(in+out, 4)))*rho*einUp*eoutUp);
3453 error2Low =TMath::Power(((r*4.)/(TMath::Pi())),-2.)*((4.*out*out/(TMath::Power(in+out, 4)))*einLow*einLow+(4.*in*in/(TMath::Power(in+out, 4)))*eoutLow*eoutLow-((8.*out*in)/(TMath::Power(in+out, 4)))*rho*einLow*eoutLow);
3454 }
a39e4b2b 3455 if(error2Up > 0) error2Up = TMath::Sqrt(error2Up);
3456 if(error2Low > 0) error2Low = TMath::Sqrt(error2Low);
3457 // set the errors
3458 ayh[i] = error2Up;
3459 ayl[i] = error2Low;
3460 // get the bin width (which is the 'error' on x)
3461 Double_t binWidth(h1->GetBinWidth(i+1));
3462 axl[i] = binWidth/2.;
3463 axh[i] = binWidth/2.;
3464 // now get the coordinate for the poin
3465 tempV2->GetPoint(i, ax[i], ay[i]);
3466 }
3467 // save the nominal ratio
3468 TGraphAsymmErrors* nominalError(new TGraphAsymmErrors(fBinsTrue->GetSize()-1, ax, ay, axl, axh, ayl, ayh));
3469 nominalError->SetName("v_{2} with shape uncertainty");
3470 // do some memory management
3471 delete tempV2;
3472 delete[] ax;
3473 delete[] ay;
3474 delete[] axh;
3475 delete[] axl;
3476 delete[] ayh;
3477 delete[] ayl;
3478
3479 return nominalError;
3480}
3481//_____________________________________________________________________________
549b5f40
RAB
3482void AliJetFlowTools::WriteObject(TObject* object, TString suffix, Bool_t kill) {
3483 // write object, if a unique identifier is given the object is cloned
3484 // and the clone is saved. setting kill to true will delete the original obect from the heap
4292ca60 3485 if(!object) {
3486 printf(" > WriteObject:: called with NULL arguments \n ");
3487 return;
549b5f40
RAB
3488 } else if(!strcmp("", suffix.Data())) object->Write();
3489 else {
3490 TObject* newObject(object->Clone(Form("%s_%s", object->GetName(), suffix.Data())));
3491 newObject->Write();
3492 }
3493 if(kill) delete object;
4292ca60 3494}
3495//_____________________________________________________________________________
3496TH2D* AliJetFlowTools::ConstructDPtResponseFromTH1D(TH1D* dpt, Bool_t AvoidRoundingError) {
3497 // construt a delta pt response matrix from supplied dpt distribution
3498 // binning is fine, set fBinsTrue and fBinsRec and call 'RebinTH2D' to
3499 // do a weighted rebinning to a (coarser) dpt distribution
3500 // be careful with the binning of the dpt response: it should be equal to that
3501 // of the response matrix, otherwise dpt and response matrices cannot be multiplied
3502 //
3503 // the response matrix will be square and have the same binning
3504 // (min, max and granularity) of the input histogram
3505 Int_t bins(dpt->GetXaxis()->GetNbins()); // number of bins, will also be no of rows, columns
3506 Double_t _bins[bins+1]; // prepare array with bin borders
3507 for(Int_t i(0); i < bins; i++) _bins[i] = dpt->GetBinLowEdge(i+1);
3508 _bins[bins] = dpt->GetBinLowEdge(bins)+dpt->GetBinWidth(bins+1); // get upper edge
3509 TH2D* res(new TH2D(Form("Response_from_%s", dpt->GetName()), Form("Response_from_%s", dpt->GetName()), bins, _bins, bins, _bins));
3510 for(Int_t j(0); j < bins+1; j++) { // loop on pt true slices j
3511 Bool_t skip = kFALSE;
3512 for(Int_t k(0); k < bins+1; k++) { // loop on pt gen slices k
3513 (skip) ? res->SetBinContent(j, k, 0.) : res->SetBinContent(j, k, dpt->GetBinContent(dpt->GetXaxis()->FindBin(k-j)));
3514 if(AvoidRoundingError && k > j && TMath::AreEqualAbs(dpt->GetBinContent(dpt->GetBinContent(k-j)), 0, 1e-8)) skip = kTRUE;
3515 }
3516 }
3517 return res;
3518}
ef12d5a5 3519//_____________________________________________________________________________
3520TH2D* AliJetFlowTools::GetUnityResponse(TArrayD* binsTrue, TArrayD* binsRec, TString suffix) {
3521 if(!binsTrue || !binsRec) {
3522 printf(" > GetUnityResponse:: function called with NULL arguments < \n");
3523 return 0x0;
3524 }
3525 TString name(Form("unityResponse_%s", suffix.Data()));
3526 TH2D* unity(new TH2D(name.Data(), name.Data(), binsTrue->GetSize()-1, binsTrue->GetArray(), binsRec->GetSize()-1, binsRec->GetArray()));
3527 for(Int_t i(0); i < binsTrue->GetSize(); i++) {
3528 for(Int_t j(0); j < binsRec->GetSize(); j++) {
3529 if(i==j) unity->SetBinContent(1+i, 1+j, 1.);
3530 }
3531 }
3532 return unity;
3533}
4292ca60 3534//_____________________________________________________________________________
549b5f40 3535void AliJetFlowTools::SaveConfiguration(Bool_t convergedIn, Bool_t convergedOut) const {
4292ca60 3536 // save configuration parameters to histogram
549b5f40 3537 TH1F* summary = new TH1F("UnfoldingConfiguration","UnfoldingConfiguration", 20, -.5, 19.5);
ef12d5a5 3538 summary->SetBinContent(1, fBetaIn);
3539 summary->GetXaxis()->SetBinLabel(1, "fBetaIn");
3540 summary->SetBinContent(2, fBetaOut);
3541 summary->GetXaxis()->SetBinLabel(2, "fBetaOut");
c03f7598 3542 summary->SetBinContent(3, fCentralityArray->At(0));
3543 summary->GetXaxis()->SetBinLabel(3, "fCentralityArray[0]");
ef12d5a5 3544 summary->SetBinContent(4, (int)convergedIn);
3545 summary->GetXaxis()->SetBinLabel(4, "convergedIn");
3546 summary->SetBinContent(5, (int)convergedOut);
3547 summary->GetXaxis()->SetBinLabel(5, "convergedOut");
3548 summary->SetBinContent(6, (int)fAvoidRoundingError);
3549 summary->GetXaxis()->SetBinLabel(6, "fAvoidRoundingError");
3550 summary->SetBinContent(7, (int)fUnfoldingAlgorithm);
3551 summary->GetXaxis()->SetBinLabel(7, "fUnfoldingAlgorithm");
3552 summary->SetBinContent(8, (int)fPrior);
3553 summary->GetXaxis()->SetBinLabel(8, "fPrior");
3554 summary->SetBinContent(9, fSVDRegIn);
3555 summary->GetXaxis()->SetBinLabel(9, "fSVDRegIn");
3556 summary->SetBinContent(10, fSVDRegOut);
3557 summary->GetXaxis()->SetBinLabel(10, "fSVDRegOut");
3558 summary->SetBinContent(11, (int)fSVDToy);
3559 summary->GetXaxis()->SetBinLabel(11, "fSVDToy");
3560 summary->SetBinContent(12, fJetRadius);
3561 summary->GetXaxis()->SetBinLabel(12, "fJetRadius");
3562 summary->SetBinContent(13, (int)fNormalizeSpectra);
3563 summary->GetXaxis()->SetBinLabel(13, "fNormalizeSpectra");
549b5f40
RAB
3564 summary->SetBinContent(14, (int)fSmoothenPrior);
3565 summary->GetXaxis()->SetBinLabel(14, "fSmoothenPrior");
ef12d5a5 3566 summary->SetBinContent(15, (int)fTestMode);
3567 summary->GetXaxis()->SetBinLabel(15, "fTestMode");
3568 summary->SetBinContent(16, (int)fUseDetectorResponse);
3569 summary->GetXaxis()->SetBinLabel(16, "fUseDetectorResponse");
549b5f40
RAB
3570 summary->SetBinContent(17, fBayesianIterIn);
3571 summary->GetXaxis()->SetBinLabel(17, "fBayesianIterIn");
3572 summary->SetBinContent(18, fBayesianIterOut);
3573 summary->GetXaxis()->SetBinLabel(18, "fBayesianIterOut");
3574 summary->SetBinContent(19, fBayesianSmoothIn);
3575 summary->GetXaxis()->SetBinLabel(19, "fBayesianSmoothIn");
3576 summary->SetBinContent(20, fBayesianSmoothOut);
3577 summary->GetXaxis()->SetBinLabel(20, "fBayesianSmoothOut");
4292ca60 3578}
3579//_____________________________________________________________________________
3580void AliJetFlowTools::ResetAliUnfolding() {
3581 // ugly function: reset all unfolding parameters
3582 TVirtualFitter* fitter(TVirtualFitter::GetFitter());
3583 if(fitter) {
3584 printf(" > Found fitter, will delete it < \n");
3585 delete fitter;
3586 }
d7ec324f 3587 if(gMinuit) {
3588 printf(" > Found gMinuit, will re-create it < \n");
3589 delete gMinuit;
3590 gMinuit = new TMinuit;
3591 }
4292ca60 3592 AliUnfolding::fgCorrelationMatrix = 0;
3593 AliUnfolding::fgCorrelationMatrixSquared = 0;
3594 AliUnfolding::fgCorrelationCovarianceMatrix = 0;
3595 AliUnfolding::fgCurrentESDVector = 0;
3596 AliUnfolding::fgEntropyAPriori = 0;
3597 AliUnfolding::fgEfficiency = 0;
3598 AliUnfolding::fgUnfoldedAxis = 0;
3599 AliUnfolding::fgMeasuredAxis = 0;
3600 AliUnfolding::fgFitFunction = 0;
3601 AliUnfolding::fgMaxInput = -1;
3602 AliUnfolding::fgMaxParams = -1;
3603 AliUnfolding::fgOverflowBinLimit = -1;
3604 AliUnfolding::fgRegularizationWeight = 10000;
3605 AliUnfolding::fgSkipBinsBegin = 0;
3606 AliUnfolding::fgMinuitStepSize = 0.1;
3607 AliUnfolding::fgMinuitPrecision = 1e-6;
3608 AliUnfolding::fgMinuitMaxIterations = 1000000;
3609 AliUnfolding::fgMinuitStrategy = 1.;
3610 AliUnfolding::fgMinimumInitialValue = kFALSE;
3611 AliUnfolding::fgMinimumInitialValueFix = -1;
3612 AliUnfolding::fgNormalizeInput = kFALSE;
3613 AliUnfolding::fgNotFoundEvents = 0;
3614 AliUnfolding::fgSkipBin0InChi2 = kFALSE;
3615 AliUnfolding::fgBayesianSmoothing = 1;
3616 AliUnfolding::fgBayesianIterations = 10;
3617 AliUnfolding::fgDebug = kFALSE;
3618 AliUnfolding::fgCallCount = 0;
3619 AliUnfolding::fgPowern = 5;
3620 AliUnfolding::fChi2FromFit = 0.;
3621 AliUnfolding::fPenaltyVal = 0.;
3622 AliUnfolding::fAvgResidual = 0.;
3623 AliUnfolding::fgPrintChi2Details = 0;
3624 AliUnfolding::fgCanvas = 0;
3625 AliUnfolding::fghUnfolded = 0;
3626 AliUnfolding::fghCorrelation = 0;
3627 AliUnfolding::fghEfficiency = 0;
3628 AliUnfolding::fghMeasured = 0;
3629 AliUnfolding::SetMinuitStepSize(1.);
3630 AliUnfolding::SetMinuitPrecision(1e-6);
3631 AliUnfolding::SetMinuitMaxIterations(100000);
3632 AliUnfolding::SetMinuitStrategy(2.);
3633 AliUnfolding::SetDebug(1);
3634}
3635//_____________________________________________________________________________
f3ba6c8e 3636TH1D* AliJetFlowTools::ProtectHeap(TH1D* protect, Bool_t kill, TString suffix) const {
4292ca60 3637 // protect heap by adding unique qualifier to name
3638 if(!protect) return 0x0;
3639 TH1D* p = (TH1D*)protect->Clone();
ef12d5a5 3640 TString tempString(fActiveString);
3641 tempString+=suffix;
3642 p->SetName(Form("%s_%s", protect->GetName(), tempString.Data()));
3643 p->SetTitle(Form("%s_%s", protect->GetTitle(), tempString.Data()));
4292ca60 3644 if(kill) delete protect;
3645 return p;
3646}
3647//_____________________________________________________________________________
f3ba6c8e 3648TH2D* AliJetFlowTools::ProtectHeap(TH2D* protect, Bool_t kill, TString suffix) const {
4292ca60 3649 // protect heap by adding unique qualifier to name
3650 if(!protect) return 0x0;
3651 TH2D* p = (TH2D*)protect->Clone();
ef12d5a5 3652 TString tempString(fActiveString);
3653 tempString+=suffix;
3654 p->SetName(Form("%s_%s", protect->GetName(), tempString.Data()));
3655 p->SetTitle(Form("%s_%s", protect->GetTitle(), tempString.Data()));
4292ca60 3656 if(kill) delete protect;
3657 return p;
3658}
3659//_____________________________________________________________________________
f3ba6c8e 3660TGraphErrors* AliJetFlowTools::ProtectHeap(TGraphErrors* protect, Bool_t kill, TString suffix) const {
4292ca60 3661 // protect heap by adding unique qualifier to name
3662 if(!protect) return 0x0;
3663 TGraphErrors* p = (TGraphErrors*)protect->Clone();
ef12d5a5 3664 TString tempString(fActiveString);
3665 tempString+=suffix;
3666 p->SetName(Form("%s_%s", protect->GetName(), tempString.Data()));
3667 p->SetTitle(Form("%s_%s", protect->GetTitle(), tempString.Data()));
4292ca60 3668 if(kill) delete protect;
3669 return p;
3670}
3671//_____________________________________________________________________________
486fb24e 3672void AliJetFlowTools::MakeAU() {
3673 // === azimuthal unfolding ===
3674 //
3675 // unfolds the spectrum in delta phi bins, extracts the yield per bin, and does a fit
3676 // in transverse momentum and azimuthal correlation space to extract v2 params
3677 // settings are equal to the ones used for 'Make()'
3678 //
3679 // basic steps that are followed:
3680 // 1) rebin the raw output of the jet task to the desired binnings
3681 // 2) calls the unfolding routine
3682 // 3) writes output to file
3683 // can be repeated multiple times with different configurations
3684
3685 Int_t low[] = {1, 6, 11, 16, 21, 26, 31, 36};
3686 Int_t up[] = {5, 10, 15, 20, 25, 30, 35, 40};
3687 TString stringArray[] = {"a", "b", "c", "d", "e", "f", "g", "h"};
35c03ef1 3688 TH1D* dPtdPhi[8];
3689 for(Int_t i(0); i < 8; i++) dPtdPhi[i] = new TH1D(Form("dPtdPhi_%i", i), Form("dPtdPhi_%i", i), 8, 0, TMath::Pi());
486fb24e 3690
3691 for(Int_t i(0); i < 8; i++) {
3692 // 1) manipulation of input histograms
3693 // check if the input variables are present
3694 if(!PrepareForUnfolding(low[i], up[i])) return;
3695 // 1a) resize the jet spectrum according to the binning scheme in fBinsTrue
3696 // parts of the spectrum can end up in over or underflow bins
3697 TH1D* measuredJetSpectrumIn = RebinTH1D(fSpectrumIn, fBinsRec, Form("resized_%s", stringArray[i].Data()), kFALSE);
3698
3699 // 1b) resize the jet spectrum to 'true' bins. can serve as a prior and as a template for unfolding
3700 // the template will be used as a prior for the chi2 unfolding
3701 TH1D* measuredJetSpectrumTrueBinsIn = RebinTH1D(fSpectrumIn, fBinsTrue, stringArray[i], kFALSE);
3702
3703 // get the full response matrix from the dpt and the detector response
3704 fDetectorResponse = NormalizeTH2D(fDetectorResponse);
3705 // get the full response matrix. if test mode is chosen, the full response is replace by a unity matrix
3706 // so that unfolding should return the initial spectrum
3707 if(fUseDptResponse && fUseDetectorResponse) fFullResponseIn = MatrixMultiplication(fDptIn, fDetectorResponse);
3708 else if (fUseDptResponse && !fUseDetectorResponse) fFullResponseIn = fDptIn;
3709 else if (!fUseDptResponse && fUseDetectorResponse) fFullResponseIn = fDetectorResponse;
3710 else if (!fUseDptResponse && !fUseDetectorResponse && !fUnfoldingAlgorithm == AliJetFlowTools::kNone) return;
3711 // normalize each slide of the response to one
3712 NormalizeTH2D(fFullResponseIn);
3713 // resize to desired binning scheme
3714 TH2D* resizedResponseIn = RebinTH2D(fFullResponseIn, fBinsTrue, fBinsRec, stringArray[i]);
3715 // get the kinematic efficiency
3716 TH1D* kinematicEfficiencyIn = resizedResponseIn->ProjectionX();
3717 kinematicEfficiencyIn->SetNameTitle(Form("kin_eff_%s", stringArray[i].Data()), Form("kin_eff_%s", stringArray[i].Data()));
3718 // suppress the errors
3719 for(Int_t j(0); j < kinematicEfficiencyIn->GetXaxis()->GetNbins(); j++) kinematicEfficiencyIn->SetBinError(1+j, 0.);
3720 TH1D* jetFindingEfficiency(0x0);
3721 if(fJetFindingEff) {
3722 jetFindingEfficiency = ProtectHeap(fJetFindingEff);
3723 jetFindingEfficiency->SetNameTitle(Form("%s_coarse", jetFindingEfficiency->GetName()), Form("%s_coarse", jetFindingEfficiency->GetName()));
3724 jetFindingEfficiency = RebinTH1D(jetFindingEfficiency, fBinsTrue);
3725 }
3726 // 2, 3) call the actual unfolding. results and transient objects are stored in a dedicated TDirectoryFile
3727 TH1D* unfoldedJetSpectrumIn(0x0);
3728 fActiveDir->cd(); // select active dir
3729 TDirectoryFile* dirIn = new TDirectoryFile(Form("%s___%s", stringArray[i].Data(), fActiveString.Data()), Form("%s___%s", stringArray[i].Data(), fActiveString.Data()));
3730 dirIn->cd(); // select inplane subdir
3731 // select the unfolding method
3732 unfoldedJetSpectrumIn = UnfoldWrapper(
3733 measuredJetSpectrumIn,
3734 resizedResponseIn,
3735 kinematicEfficiencyIn,
3736 measuredJetSpectrumTrueBinsIn,
3737 TString("dPtdPhiUnfolding"),
3738 jetFindingEfficiency);
3739 if(i==5) {
3740 resizedResponseIn->SetNameTitle(Form("ResponseMatrix_%s", stringArray[i].Data()), Form("response matrix %s", stringArray[i].Data()));
f3ba6c8e 3741 resizedResponseIn->SetXTitle("p_{T, jet}^{true} [GeV/c]");
3742 resizedResponseIn->SetYTitle("p_{T, jet}^{rec} [GeV/c]");
486fb24e 3743 resizedResponseIn = ProtectHeap(resizedResponseIn);
3744 resizedResponseIn->Write();
3745 kinematicEfficiencyIn->SetNameTitle(Form("KinematicEfficiency_%s", stringArray[i].Data()), Form("Kinematic efficiency, %s", stringArray[i].Data()));
3746 kinematicEfficiencyIn = ProtectHeap(kinematicEfficiencyIn);
3747 kinematicEfficiencyIn->Write();
3748 fDetectorResponse->SetNameTitle("DetectorResponse", "Detector response matrix");
3749 fDetectorResponse = ProtectHeap(fDetectorResponse, kFALSE);
3750 fDetectorResponse->Write();
3751 // optional histograms
3752 if(fSaveFull) {
3753 fSpectrumIn->SetNameTitle("[ORIG]JetSpectrum", Form("[INPUT] Jet spectrum, %s", stringArray[i].Data()));
3754 fSpectrumIn->Write();
3755 fDptInDist->SetNameTitle("[ORIG]DeltaPt", Form("#delta p_{T} distribution, %s", stringArray[i].Data()));
3756 fDptInDist->Write();
3757 fDptIn->SetNameTitle("[ORIG]DeltaPtMatrix", Form("#delta p_{T} matrix, %s", stringArray[i].Data()));
3758 fDptIn->Write();
3759 fFullResponseIn->SetNameTitle("ResponseMatrix", Form("Response matrix, %s", stringArray[i].Data()));
3760 fFullResponseIn->Write();
3761 }
3762 }
3763 fActiveDir->cd();
3764 fDeltaPtDeltaPhi->Write();
3765 fJetPtDeltaPhi->Write();
3766
3767 TH1D* dud(ProtectHeap(unfoldedJetSpectrumIn, kTRUE, stringArray[i]));;
3768 Double_t integralError(0);
3769 for(Int_t j(0); j < 6; j++) {
3770 // get the integrated
a39e4b2b 3771 Double_t integral(dud->IntegralAndError(2*j+1, 2*j+3, integralError));
3772 dPtdPhi[j]->SetBinContent(i+1, integral);
3773 dPtdPhi[j]->SetBinError(i+1, integralError);
486fb24e 3774 }
3775 dud->Write();
3776 // save the current state of the unfolding object
3777 SaveConfiguration(unfoldedJetSpectrumIn ? kTRUE : kFALSE, kFALSE);
3778 }
3779 TF1* fourier = new TF1("fourier", "[0]*(1.+0.5*[1]*(TMath::Cos(2.*x)))", 0, TMath::Pi());
3780 TH1D* v2(new TH1D("v2FromFit", "v2FromFit", fBinsTrue->GetSize()-1, fBinsTrue->GetArray()));
3781 for(Int_t i(0); i < 6; i++) {
3782 dPtdPhi[i]->Fit(fourier, "VI");
3783 v2->SetBinContent(1+i, fourier->GetParameter(1));
3784 v2->SetBinError(1+i, fourier->GetParError(1));
3785 dPtdPhi[i]->Write();
3786 }
3787 v2->Write();
3788}
3789//_____________________________________________________________________________