12 #include <TMultiGraph.h>
14 #include <TGraphErrors.h>
17 #include "AliAODForwardMult.h"
18 #include "OtherData.C"
21 * Draw the data stored in the AOD
26 * Root> .L $ALICE_ROOT/PWG2/FORWARD/analysis2/Compile.C
27 * Root> Compile("$ALICE_ROOT/PWG2/FORWARD/analysis2/DrawRes.C")
29 * Root> dr.Run("AliAODs.root",-10,10,5,AliAODForwardMult::kInel,900)
32 * The output is stored in a ROOT file
34 * See also the script Pass2.C
36 * @ingroup pwg2_forward_analysis_scripts
44 AliAODForwardMult* fAOD;
47 /** Summed histogram */
49 /** Vertex efficiency */
51 /** Title to put on the plot */
53 /** Do HHD comparison */
56 //__________________________________________________________________
70 //__________________________________________________________________
72 * Reset internal structures
75 void Clear(Option_t* )
77 if (fTree && fTree->GetCurrentFile()) {
78 fTree->GetCurrentFile()->Close();
85 if (fSum) delete fSum;
92 //__________________________________________________________________
96 * @param file Input file with AOD tree
97 * @param vzMin Minimum interaction point z coordinate
98 * @param vzMax Maximum interaction point z coordinate
99 * @param rebin How many times to re-bin the @f$ dN_{ch}/d\eta@f$
100 * @param mask Trigger mask
101 * @param energy Collision energy @f$ \sqrt{s}@f$ or @f$\sqrt{s_{NN}}@f$
102 * @param title Title to put on the plot
104 * @return True on success, false otherwise
106 Bool_t Run(const char* file="AliAODs.root",
107 Double_t vzMin=-10, Double_t vzMax=10, Int_t rebin=1,
108 Int_t mask=AliAODForwardMult::kInel, Int_t energy=900,
109 const char* title="", Bool_t doHHD=false, Bool_t doComp=false)
112 if (mask & AliAODForwardMult::kInel) trgName.Append("inel-");
113 if (mask & AliAODForwardMult::kInelGt0) trgName.Append("inelgt0-");
114 if (mask & AliAODForwardMult::kNSD) trgName.Append("nsd-");
115 if (trgName.EndsWith("-")) trgName.Remove(trgName.Length()-1);
116 if (trgName.IsNull()) trgName = "unknown";
118 TString::Format("dndeta_%04dGeV_%c%02d-%c%02dcm_rb%02d_%s.root",
120 vzMin < 0 ? 'm' : 'p', Int_t(TMath::Abs(vzMin)+.5),
121 vzMax < 0 ? 'm' : 'p', Int_t(TMath::Abs(vzMax)+.5),
122 rebin, trgName.Data());
124 if (!Open(file, outName)) return kFALSE;
125 if (!Process(vzMin,vzMax,mask)) return kFALSE;
126 if (!Finish(rebin, mask, energy,doHHD,doComp)) return kFALSE;
130 //__________________________________________________________________
132 * Open the files @a fname containg the tree with AliAODEvent objects,
133 * and also open the output file @a outname for writting.
135 * @param fname Input file name
136 * @param outname Output file name
138 * @return true on success, false otherwise
140 Bool_t Open(const char* fname, const char* outname)
144 TFile* file = TFile::Open(fname, "READ");
146 Error("Open", "Cannot open file %s", fname);
151 fTree = static_cast<TTree*>(file->Get("aodTree"));
153 Error("Init", "Couldn't get the tree");
157 // Set the branch pointer
158 fTree->SetBranchAddress("Forward", &fAOD);
160 fOut = TFile::Open(outname, "RECREATE");
162 Error("Open", "Couldn't open %s", outname);
167 //__________________________________________________________________
171 * @param vzMin Minimum interaction point z coordinate
172 * @param vzMax Maximum interaction point z coordinate
173 * @param mask Trigger mask
175 * @return true on success, false otherwise
177 Bool_t Process(Double_t vzMin, Double_t vzMax, Int_t mask)
179 Int_t nTriggered = 0; // # of triggered ev.
180 Int_t nWithVertex = 0; // # of ev. w/vertex
181 Int_t nAccepted = 0; // # of ev. used
182 Int_t nAvailable = fTree->GetEntries(); // How many entries
184 for (int i = 0; i < nAvailable; i++) {
186 if (((i+1) % 100) == 0) {
187 fprintf(stdout,"Event # %9d of %9d, %9d accepted so far\r",
188 i+1, nAvailable, nAccepted);
192 // Create sum histogram on first event - to match binning to input
194 fSum = static_cast<TH2D*>(fAOD->GetHistogram().Clone("d2ndetadphi"));
195 Info("Process", "Created sum histogram (%d,%f,%f)x(%d,%f,%f)",
197 fSum->GetXaxis()->GetXmin(),
198 fSum->GetXaxis()->GetXmax(),
200 fSum->GetYaxis()->GetXmin(),
201 fSum->GetYaxis()->GetXmax());
205 // Other trigger/event requirements could be defined
206 if (!fAOD->IsTriggerBits(mask)) continue;
209 // Check if there's a vertex
210 if (!fAOD->HasIpZ()) continue;
213 // Select vertex range (in centimeters)
214 if (!fAOD->InRange(vzMin, vzMax)) continue;
217 // Add contribution from this event
218 fSum->Add(&(fAOD->GetHistogram()));
221 fVtxEff = Double_t(nWithVertex)/nTriggered;
223 Info("Process", "Total of %9d events\n"
224 " %9d has a trigger\n"
225 " %9d has a vertex\n"
227 nAvailable, nTriggered, nWithVertex, nAccepted);
231 //__________________________________________________________________
233 * Finish the stuff and draw
235 * @param rebin How many times to rebin
236 * @param energy Collision energy
237 * @param mask Trigger mask
239 * @return true on success, false otherwise
241 Bool_t Finish(Int_t rebin, Int_t mask, Int_t energy,
242 Bool_t doHHD, Bool_t doComp)
246 // Get acceptance normalisation from underflow bins
247 TH1D* norm = fSum->ProjectionX("norm", 0, 1, "");
248 // Project onto eta axis - _ignoring_underflow_bins_!
249 TH1D* dndeta = fSum->ProjectionX("dndeta", 1, -1, "e");
250 dndeta->SetTitle("1/N dN_{ch}/d#eta|_{forward}");
251 // Normalize to the acceptance
252 dndeta->Divide(norm);
253 // Scale by the vertex efficiency
254 dndeta->Scale(fVtxEff, "width");
255 dndeta->SetMarkerColor(kRed+1);
256 dndeta->SetMarkerStyle(20);
257 dndeta->SetMarkerSize(1);
258 dndeta->SetFillStyle(0);
259 Rebin(dndeta, rebin);
260 DrawIt(dndeta, mask, energy, doHHD, doComp);
264 //__________________________________________________________________
267 void DrawIt(TH1* dndeta, Int_t mask, Int_t energy,
268 Bool_t doHHD, Bool_t doComp)
270 // --- 1st part - prepare data -----------------------------------
271 TH1* sym = Symmetrice(dndeta);
272 // Rebin(sym, rebin);
274 THStack* stack = new THStack("results", "Results");
278 // Get the data from HHD's analysis - if available
281 Info("DrawIt", "Will %sdraw HHD results", (doHHD ? "" : "not "));
283 TString hhdName(fOut->GetName());
284 hhdName.ReplaceAll("dndeta", "hhd");
285 hhd = GetHHD(hhdName.Data(), mask & AliAODForwardMult::kNSD);
288 // Symmetrice and add to stack
289 hhdsym = Symmetrice(hhd);
294 Warning("DrawIt", "No HHD data found");
297 // Get graph of 'other' data - e.g., UA5, CMS, ... - and check if
298 // there's any graphs. Set the pad division based on that.
299 Info("DrawIt", "Will %sdraw other results", (doComp ? "" : "not "));
300 TMultiGraph* other = (doComp ? GetData(energy, mask) : 0);
301 THStack* ratios = MakeRatios(dndeta, sym, hhd, hhdsym, other);
303 // Check if we have ratios
305 // --- 2nd part - Draw in canvas ---------------------------------
307 gStyle->SetOptTitle(0);
308 gStyle->SetTitleFont(132, "xyz");
309 gStyle->SetLabelFont(132, "xyz");
310 TCanvas* c = new TCanvas("c", "C", 900, 800);
316 Double_t yd = (ratios ? 0.3 : 0);
318 // Make a sub-pad for the result itself
319 TPad* p1 = new TPad("p1", "p1", 0, yd, 1.0, 1.0, 0, 0);
320 p1->SetTopMargin(0.05);
321 p1->SetBottomMargin(ratios ? 0.001 : 0.1);
322 p1->SetRightMargin(0.05);
328 // Fix the apperance of the stack and redraw.
329 stack->SetMinimum(ratios ? -0.1 : 0);
330 FixAxis(stack, 1/(1-yd)/1.5, "#frac{1}{N} #frac{dN_{ch}}{#eta}");
332 stack->DrawClone("nostack e1");
336 TGraphAsymmErrors* o = 0;
337 TIter nextG(other->GetListOfGraphs());
338 while ((o = static_cast<TGraphAsymmErrors*>(nextG())))
343 // Make a legend in the main result pad
344 TString trigs(AliAODForwardMult::GetTriggerString(mask));
345 TLegend* l = p1->BuildLegend(.15,p1->GetBottomMargin()+.01,.90,.35);
353 // Put a title on top
354 TLatex* tit = new TLatex(0.10, 0.95, fTitle.Data());
356 tit->SetTextFont(132);
357 tit->SetTextSize(0.05);
360 // Put a nice label in the plot
361 TLatex* tt = new TLatex(.93, .93,
362 Form("#sqrt{s}=%dGeV, %s", energy,
363 AliAODForwardMult::GetTriggerString(mask)));
365 tt->SetTextFont(132);
366 tt->SetTextAlign(33);
369 // Mark the plot as preliminary
370 TLatex* pt = new TLatex(.93, .88, "Preliminary");
373 pt->SetTextSize(0.07);
374 pt->SetTextColor(kRed+1);
375 pt->SetTextAlign(33);
379 // If we do not have the ratios, fix up the display
380 // p1->SetPad(0, 0, 1, 1);
381 // p1->SetBottomMargin(0.1);
383 // stack->SetMinimum(0);
384 // FixAxis(stack, (1-yd)/1, "#frac{1}{N} #frac{dN_{ch}}{#eta}",10,false);
386 // If we do have the ratios, then make a new pad and draw the
389 TPad* p2 = new TPad("p2", "p2", 0, 0.0, 1.0, yd, 0, 0);
390 p2->SetTopMargin(0.001);
391 p2->SetRightMargin(0.05);
392 p2->SetBottomMargin(1/yd * 0.07);
399 FixAxis(ratios, 1/yd/1.5, "Ratios", 5);
401 // Fix up y range and redraw
402 ratios->SetMinimum(.58);
403 ratios->SetMaximum(1.22);
405 ratios->DrawClone("nostack e1");
408 TLegend* l2 = p2->BuildLegend(.15,p2->GetBottomMargin()+.01,.9,.6);
412 l2->SetBorderSize(0);
413 l2->SetTextFont(132);
415 // Make a nice band from 0.9 to 1.1
416 TGraphErrors* band = new TGraphErrors(2);
417 band->SetPoint(0, sym->GetXaxis()->GetXmin(), 1);
418 band->SetPoint(1, dndeta->GetXaxis()->GetXmax(), 1);
419 band->SetPointError(0, 0, .1);
420 band->SetPointError(1, 0, .1);
421 band->SetFillColor(kYellow+2);
422 band->SetFillStyle(3002);
423 band->Draw("3 same");
425 // Replot the ratios on top
426 ratios->DrawClone("nostack e1 same");
432 TString imgName(fOut->GetName());
433 imgName.ReplaceAll(".root", ".png");
434 c->SaveAs(imgName.Data());
435 imgName.ReplaceAll(".png", ".C");
436 c->SaveAs(imgName.Data());
439 if (other) other->Write();
440 if (ratios) ratios->Write();
445 //__________________________________________________________________
447 * Get the result from previous analysis code
449 * @param fn File to open
451 * @return null or result of previous analysis code
453 TH1* GetHHD(const char* fn="fmd_dNdeta_mult.root", bool nsd=false)
455 TDirectory* savdir = gDirectory;
456 if (gSystem->AccessPathName(fn)) {
457 Warning("GetHHD", "Output of HHD analysis (%s) not available", fn);
460 TFile* file = TFile::Open(fn, "READ");
462 Warning("GetHHD", "couldn't open HHD file %s", fn);
466 TString hist(Form("dNdeta_dNdeta%s", (nsd ? "NSD" : "")));
467 TH1* h = static_cast<TH1*>(file->Get(hist.Data()));
469 Warning("GetHHD", "Couldn't find HHD histogram %s in %s",
475 TH1* r = static_cast<TH1*>(h->Clone("dndeta_hhd"));
476 r->SetTitle("1/N dN_{ch}/d#eta (HHD)");
479 r->SetMarkerStyle(21);
480 r->SetMarkerColor(kPink+1);
481 r->SetDirectory(savdir);
487 //__________________________________________________________________
490 THStack* MakeRatios(const TH1* dndeta, const TH1* sym,
491 const TH1* hhd, const TH1* hhdsym,
492 TMultiGraph* other) const
494 // If we have 'other' data, then do the ratio of the results to that
495 Bool_t hasOther = (other && other->GetListOfGraphs() &&
496 other->GetListOfGraphs()->GetEntries() > 0);
497 Bool_t hasHhd = (hhd && hhdsym);
498 if (!hasOther || !hasHhd) return 0;
500 THStack* ratios = new THStack("ratios", "Ratios");
502 TGraphAsymmErrors* o = 0;
503 TIter nextG(other->GetListOfGraphs());
504 while ((o = static_cast<TGraphAsymmErrors*>(nextG()))) {
505 ratios->Add(Ratio(dndeta, o));
506 ratios->Add(Ratio(sym, o));
507 ratios->Add(Ratio(hhd, o));
508 ratios->Add(Ratio(hhdsym, o));
512 // If we have data from HHD's analysis, then do the ratio of
513 // our result to that data.
515 TH1F* t1 = static_cast<TH1F*>(dndeta->Clone(Form("%s_%s",
518 t1->SetTitle(Form("%s / %s", dndeta->GetTitle(), hhd->GetTitle()));
519 TH1F* t2 = static_cast<TH1F*>(sym->Clone(Form("%s_%s",
521 hhdsym->GetName())));
522 t2->SetTitle(Form("%s / %s", sym->GetTitle(), hhdsym->GetTitle()));
529 // Check if we have ratios
530 Bool_t hasRatios = (ratios->GetHists() &&
531 (ratios->GetHists()->GetEntries() > 0));
532 Info("MakeRatios", "Got a total of %d ratios", !hasRatios ? 0 :
533 ratios->GetHists()->GetEntries());
535 if (!hasRatios) { delete ratios; ratios = 0; }
539 //__________________________________________________________________
541 * Fix the apperance of the axis in a stack
543 * @param stack stack of histogram
544 * @param s Scaling factor
545 * @param ytitle Y axis title
546 * @param force Whether to draw the stack first or not
548 void FixAxis(THStack* stack, Double_t s, const char* ytitle,
549 Int_t ynDiv=10, Bool_t force=true)
551 if (force) stack->Draw("nostack e1");
553 TH1* h = stack->GetHistogram();
556 h->SetXTitle("#eta");
557 h->SetYTitle(ytitle);
558 TAxis* xa = h->GetXaxis();
559 TAxis* ya = h->GetYaxis();
561 xa->SetTitle("#eta");
562 // xa->SetTicks("+-");
563 xa->SetTitleSize(s*xa->GetTitleSize());
564 xa->SetLabelSize(s*xa->GetLabelSize());
565 xa->SetTickLength(s*xa->GetTickLength());
568 ya->SetTitle(ytitle);
570 // ya->SetTicks("+-");
571 ya->SetNdivisions(ynDiv);
572 ya->SetTitleSize(s*ya->GetTitleSize());
573 ya->SetLabelSize(s*ya->GetLabelSize());
576 //__________________________________________________________________
578 * Compute the ratio of @a h to @a g. @a g is evaluated at the bin
586 TH1* Ratio(const TH1* h, const TGraph* g) const
588 if (!h || !g) return 0;
590 TH1* ret = static_cast<TH1*>(h->Clone("tmp"));
591 ret->SetName(Form("%s_over_%s", h->GetName(), g->GetName()));
592 ret->SetTitle(Form("%s / %s", h->GetTitle(), g->GetTitle()));
594 ret->SetMarkerStyle(h->GetMarkerStyle());
595 ret->SetMarkerColor(g->GetMarkerColor());
596 ret->SetMarkerSize(0.9*g->GetMarkerSize());
597 Double_t xlow = g->GetX()[0];
598 Double_t xhigh = g->GetX()[g->GetN()-1];
599 if (xlow > xhigh) { Double_t t = xhigh; xhigh = xlow; xlow = t; }
601 for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
602 Double_t c = h->GetBinContent(i);
603 if (c <= 0) continue;
605 Double_t x = h->GetBinCenter(i);
606 if (x < xlow || x > xhigh) continue;
608 Double_t f = g->Eval(x);
609 if (f <= 0) continue;
611 ret->SetBinContent(i, c / f);
612 ret->SetBinError(i, h->GetBinError(i) / f);
614 if (ret->GetEntries() <= 0) { delete ret; ret = 0; }
618 //__________________________________________________________________
620 * Make an extension of @a h to make it symmetric about 0
622 * @param h Histogram to symmertrice
624 * @return Symmetric extension of @a h
626 TH1* Symmetrice(const TH1* h) const
628 Int_t nBins = h->GetNbinsX();
629 TH1* s = new TH1D(Form("%s_mirror", h->GetName()),
630 Form("%s (mirrored)", h->GetTitle()),
632 -h->GetXaxis()->GetXmax(),
633 -h->GetXaxis()->GetXmin());
634 s->SetMarkerColor(h->GetMarkerColor());
635 s->SetMarkerSize(h->GetMarkerSize());
636 s->SetMarkerStyle(h->GetMarkerStyle()+4);
637 s->SetFillColor(h->GetFillColor());
638 s->SetFillStyle(h->GetFillStyle());
640 // Find the first and last bin with data
641 Int_t first = nBins+1;
643 for (Int_t i = 1; i <= nBins; i++) {
644 if (h->GetBinContent(i) <= 0) continue;
645 first = TMath::Min(first, i);
646 last = TMath::Max(last, i);
649 Double_t xfirst = h->GetBinCenter(first-1);
650 Int_t f1 = h->GetXaxis()->FindBin(-xfirst);
651 Int_t l2 = s->GetXaxis()->FindBin(xfirst);
652 for (Int_t i = f1, j=l2; i <= last; i++,j--) {
653 s->SetBinContent(j, h->GetBinContent(i));
654 s->SetBinError(j, h->GetBinError(i));
658 //__________________________________________________________________
662 * @param h Histogram to rebin
663 * @param rebin Rebinning factor
667 virtual void Rebin(TH1* h, Int_t rebin) const
669 if (rebin <= 1) return;
671 Int_t nBins = h->GetNbinsX();
672 if(nBins % rebin != 0) {
673 Warning("Rebin", "Rebin factor %d is not a devisor of current number "
674 "of bins %d in the histogram %s", rebin, nBins, h->GetName());
679 TH1* tmp = static_cast<TH1*>(h->Clone("tmp"));
681 tmp->SetDirectory(0);
683 // The new number of bins
684 Int_t nBinsNew = nBins / rebin;
685 for(Int_t i = 1;i<= nBinsNew; i++) {
686 Double_t content = 0;
690 for(Int_t j = 1; j<=rebin;j++) {
691 Int_t bin = (i-1)*rebin + j;
692 if(h->GetBinContent(bin) <= 0) continue;
693 Double_t c = h->GetBinContent(bin);
694 Double_t w = 1 / TMath::Power(c,2);
702 tmp->SetBinContent(i, wsum / sumw);
703 tmp->SetBinError(i,TMath::Sqrt(sumw));
707 // Finally, rebin the histogram, and set new content
709 for(Int_t i =1;i<=nBinsNew; i++) {
710 h->SetBinContent(i,tmp->GetBinContent(i));
711 // h->SetBinError(i,tmp->GetBinError(i));
718 //____________________________________________________________________