3 * @author Christian Holm Christensen <cholm@nbi.dk>
4 * @date Thu Nov 17 11:16:45 2011
6 * @brief Script to draw the energy loss fits from the output file of
7 * AliFMDELossFitter(Task).
9 * @ingroup pwglf_forward_scripts_corr
23 //____________________________________________________________________
25 /** List of fitters */
29 /** Name of output file */
30 const char* pdfName = "FitResults.pdf";
31 /** Produce plots in landscape mode */
32 bool landscape = true;
34 //____________________________________________________________________
36 * Open a file. The file is expected to contain the directory
54 * | +- FMD1I_edist (TH1)
59 * @param fname File to open
61 * @return Pointer to the list of objects
63 * @ingroup pwglf_forward_scripts_corr
65 TList* OpenFile(const char* fname)
67 TFile* file = TFile::Open(fname, "READ");
69 Error("DrawFits", "Couldn't open %s", fname);
73 TList* forward = static_cast<TList*>(file->Get("ForwardResults"));
74 // static_cast<TList*>(file->Get("PWGLFforwardDnDeta/Forward"));
76 Error("DrawFits", "Couldn't get forward list from %s", fname);
80 fitter = static_cast<TList*>(forward->FindObject("fmdEnergyFitter"));
82 Error("DrawFits", "Couldn't get fitter folder");
87 //____________________________________________________________________
89 * Open file if not done already
91 * @param fname File to open
93 * @return List of fits
95 * @ingroup pwglf_forward_scripts_corr
97 TList* CheckFitter(const char* fname="AnalysisResults.root")
99 if (!fitter) return OpenFile(fname);
103 //____________________________________________________________________
105 * Make canvas if not done already
110 * @ingroup pwglf_forward_scripts_corr
112 TCanvas* CheckCanvas()
114 if (canvas) return canvas;
116 gStyle->SetOptFit(111111);
117 gStyle->SetTitleFillColor(0);
118 gStyle->SetTitleBorderSize(0);
119 gStyle->SetTitleX(0);
120 gStyle->SetTitleY(.9);
121 gStyle->SetTitleW(.4);
122 gStyle->SetTitleH(.1);
123 gStyle->SetStatW(0.2);
124 gStyle->SetStatH(0.2);
125 gStyle->SetStatColor(0);
126 gStyle->SetStatBorderSize(1);
127 gStyle->SetOptTitle(0);
128 gStyle->SetOptFit(1111);
129 gStyle->SetStatW(0.3);
130 gStyle->SetStatH(0.15);
131 gStyle->SetStatColor(0);
132 gStyle->SetStatBorderSize(1);
134 Int_t w = Int_t(800 / TMath::Sqrt(2));
141 canvas = new TCanvas("c", "C", w, h);
142 canvas->SetFillColor(0);
143 canvas->SetBorderMode(0);
144 canvas->SetBorderSize(0);
145 canvas->SetBottomMargin(0.15);
149 //____________________________________________________________________
151 * Clean stack for full ring histograms
153 * @param stack Input stack
155 * @ingroup pwglf_forward_scripts_corr
157 void CleanStack(THStack* stack)
159 TIter next(stack->GetHists());
161 while ((o = next())) {
162 TString name(o->GetName());
163 if (name.Contains("_t_"))
164 stack->RecursiveRemove(o);
168 //____________________________________________________________________
170 * Add a stack to list
172 * @param stacks List to add to
173 * @param list Input list
174 * @param name Name of stack to add
176 * @return The found stack
178 * @ingroup pwglf_forward_scripts_corr
181 AddToStack(TList* stacks, TList* list, const char* name)
183 TObject* o = list->FindObject(name);
185 Warning("AddToStack", "Object %s not found in %s", name,
190 THStack* toAdd = static_cast<THStack*>(o);
192 Info("AddToStack", "Adding %s to stacks", name);
198 //____________________________________________________________________
202 * @param fname File name to read
203 * @param onlySummary Only plot summary pae
205 * @ingroup pwglf_forward_scripts_corr
207 void DrawSummary(const char* fname="forward_eloss.root",
208 bool onlySummary=true)
210 if (!CheckFitter(fname)) {
211 Error("DrawFits", "File not opened");
214 if (!CheckCanvas()) {
215 Error("DrawFits", "No canvas");
221 /* THStack* chi2nu = */ AddToStack(&stacks, fitter, "chi2");
222 /* THStack* c = */ AddToStack(&stacks, fitter, "c");
223 /* THStack* delta = */ AddToStack(&stacks, fitter, "delta");
224 /* THStack* xi = */ AddToStack(&stacks, fitter, "xi");
225 /* THStack* sigma = */ AddToStack(&stacks, fitter, "sigma");
226 /* THStack* sigman = */ AddToStack(&stacks, fitter, "sigman");
227 /* THStack* n = */ AddToStack(&stacks, fitter, "n");
228 Int_t baseA = stacks.GetEntries()+1;
231 if (!AddToStack(&stacks, fitter, Form("a%d",i++)))
235 Int_t nMax = stacks.GetEntries();
236 for (i = nMax-1; i >= baseA; i--) {
237 THStack* stack = static_cast<THStack*>(stacks.At(i));
238 TIter nextH(stack->GetHists());
240 Bool_t hasData = kFALSE;
241 while ((hist = static_cast<TH1*>(nextH())))
242 if (hist->Integral() > 0) hasData = kTRUE;
243 if (!hasData) nMax--;
246 canvas->SetRightMargin(0.01);
247 canvas->SetTopMargin(0.01);
248 Int_t nL = (nMax+1) / 2;
257 canvas->Divide(nX, nY, 0.1, 0, 0);
263 while ((stack = static_cast<THStack*>(next()))) {
265 Int_t ipad = 1+i/nL + 2 * (i % nL);
266 Info("DrawSummary", "cd'ing to canvas %d for %s", ipad,
268 TVirtualPad* p = canvas->cd(ipad);
269 p->SetLeftMargin(.6/nL);
270 p->SetTopMargin(.01);
271 p->SetRightMargin(.01);
275 stack->Draw("nostack");
276 stack->GetHistogram()->SetYTitle(stack->GetTitle());
277 stack->GetHistogram()->SetXTitle("#eta");
279 TAxis* yaxis = stack->GetHistogram()->GetYaxis();
280 if (i == 0) yaxis->SetRangeUser(0,20); // Chi2
281 if (i == 1) stack->SetMaximum(1); // c
282 if (i == 2) stack->SetMaximum(1); // delta
283 if (i == 3) stack->SetMaximum(0.1); // xi
284 if (i == 4 || i == 5) stack->SetMaximum(0.5); // sigma{,n}
285 if (i == 7) stack->SetMaximum(0.5); // a
286 if (i == 0) p->SetLogy();
287 yaxis->SetTitleSize(0.3/nL);
288 yaxis->SetLabelSize(0.08);
289 yaxis->SetTitleOffset(2.5/nL);
290 yaxis->SetNdivisions(5);
291 yaxis->SetTitleFont(42);
292 yaxis->SetLabelFont(42);
293 yaxis->SetDecimals();
295 TAxis* xaxis = stack->GetHistogram()->GetXaxis();
296 xaxis->SetTitleSize(0.3/nL);
297 xaxis->SetLabelSize(0.08);
298 xaxis->SetTitleOffset(2./nL);
299 xaxis->SetNdivisions(10);
300 xaxis->SetTitleFont(42);
301 xaxis->SetLabelFont(42);
302 xaxis->SetDecimals();
305 stack->Draw("nostack");
307 // if (i >= 5) b = 2;
310 canvas->SaveAs("fit_results.png");
312 canvas->Print(pdfName, "Title:Fit summary");
315 //____________________________________________________________________
321 * @ingroup pwglf_forward_scripts_corr
323 * @ingroup pwglf_forward_scripts_corr
325 void DrawRings(const char* fname="AnalysisResults.root")
327 if (!CheckFitter(fname)) {
328 Error("DrawFits", "File not opened");
331 if (!CheckCanvas()) {
332 Error("DrawFits", "No canvas");
338 canvas->Divide(1, 5,0,0);
340 const char* dets[] = { "FMD1I", "FMD2I", "FMD2O", "FMD3I", "FMD3O", 0 };
341 for (Int_t i = 0; i < 5; i++) {
342 TVirtualPad* p = canvas->cd(i+1);
347 TList* d = static_cast<TList*>(fitter->FindObject(dets[i]));
349 Warning("DrawFits", "List %s not found", dets[i]);
352 TH1* edist = static_cast<TH1*>(d->FindObject(Form("%s_edist", dets[i])));
354 Warning("DrawFits", "Histogram %s_edist not found", dets[i]);
359 TIter nextF(edist->GetListOfFunctions());
360 while ((f = static_cast<TF1*>(nextF()))) {
361 Double_t chi2 = f->GetChisquare();
362 Int_t ndf = f->GetNDF();
363 Printf("%s %s:\n Range: %f-%f\n"
364 "chi^2/ndf= %f / %d = %f",
365 edist->GetName(), f->GetName(),
366 f->GetXmin(), f->GetXmax(), chi2, ndf,
367 (ndf > 0) ? chi2/ndf : 0);
368 for (Int_t j = 0; j < f->GetNpar(); j++) {
369 Printf(" %-20s : %9.4f +/- %9.4f",
370 f->GetParName(j), f->GetParameter(j), f->GetParError(j));
376 canvas->Print(pdfName, "Title:Fit to rings");
379 //____________________________________________________________________
381 * Draw fits in eta bins
385 * @ingroup pwglf_forward_scripts_corr
387 * @ingroup pwglf_forward_scripts_corr
389 void DrawEtaBins(const char* fname="AnalysisResults.root")
391 if (!CheckFitter(fname)) {
392 Error("DrawFits", "File not opened");
395 if (!CheckCanvas()) {
396 Error("DrawFits", "No canvas");
400 canvas->Divide(2,2,0,0);
402 for (UShort_t d=1; d<=3; d++) {
403 UShort_t nQ = (d == 1 ? 1 : 2);
404 for (UShort_t q = 0; q < nQ; q++) {
405 Char_t r = (q == 0 ? 'I' : 'O');
408 static_cast<TList*>(fitter->FindObject(Form("FMD%d%c",d,r)));
410 Error("PrintFits", "Couldn't get ring FMD%d%c", d,r);
413 TList* edists = static_cast<TList*>(ring->FindObject("EDists"));
415 Error("PrintFits", "Couldn't get EDists list for FMD%d%c", d,r);
419 Info("DrawEtaBins", "Drawing for FMD%d%c", d, r);
424 while ((dist = static_cast<TH1*>(next()))) {
425 Info("DrawEtaBins", "FMD%d%c: %s", d, r, dist->GetName());
429 canvas->Print(pdfName, Form("Title:FMD%d%c page %2d", d,r,j));
431 TVirtualPad* p = canvas->cd(++i);
432 p->SetFillColor(kWhite);
436 dist->SetMaximum(15);
442 for (; i <= 4; i++) {
443 TVirtualPad* p = canvas->cd(i);
445 p->SetFillColor(kMagenta-3);
449 canvas->Print(pdfName, Form("FMD%d%c page %2d", d,r,j++));
455 //____________________________________________________________________
457 * Draw energy loss fits to a multi-page PDF
459 * The input file is the result of running AliFMDELossFitter -
460 * either directly via AliFMDELossFitterTask or as part of a larger
461 * train (AliForwardMultiplicityTask or AliForwardMCMultiplicityTask).
472 * +- sigman (THStack)
478 * | +- FMD1I_edist (TH1)
479 * | +- EDists (TList)
483 * @param fname File name to read
484 * @param onlySummary Only plot summary pae
486 * @ingroup pwglf_forward_scripts_corr
489 DrawAnaELoss(const char* fname="forward_eloss.root", bool onlySummary=true)
491 if (!CheckCanvas()) {
492 Error("DrawFits", "No canvas");
495 if (!onlySummary) canvas->Print(Form("%s[", pdfName));
496 DrawSummary(fname, onlySummary);
497 if (onlySummary) return;
500 canvas->Print(Form("%s]", pdfName));