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 */
54 //__________________________________________________________________
67 //__________________________________________________________________
69 * Reset internal structures
72 void Clear(Option_t* )
74 if (fTree && fTree->GetCurrentFile()) {
75 fTree->GetCurrentFile()->Close();
82 if (fSum) delete fSum;
89 //__________________________________________________________________
93 * @param file Input file with AOD tree
94 * @param vzMin Minimum interaction point z coordinate
95 * @param vzMax Maximum interaction point z coordinate
96 * @param rebin How many times to re-bin the @f$ dN_{ch}/d\eta@f$
97 * @param mask Trigger mask
98 * @param energy Collision energy @f$ \sqrt{s}@f$ or @f$\sqrt{s_{NN}}@f$
99 * @param title Title to put on the plot
101 * @return True on success, false otherwise
103 Bool_t Run(const char* file="AliAODs.root",
104 Double_t vzMin=-10, Double_t vzMax=10, Int_t rebin=1,
105 Int_t mask=AliAODForwardMult::kInel, Int_t energy=900,
106 const char* title="")
109 if (mask & AliAODForwardMult::kInel) trgName.Append("inel-");
110 if (mask & AliAODForwardMult::kInelGt0) trgName.Append("inelgt0-");
111 if (mask & AliAODForwardMult::kNSD) trgName.Append("nsd-");
112 if (trgName.EndsWith("-")) trgName.Remove(trgName.Length()-1);
113 if (trgName.IsNull()) trgName = "unknown";
115 TString::Format("dndeta_%04dGeV_%c%02d-%c%02dcm_rb%02d_%s.root",
117 vzMin < 0 ? 'm' : 'p', Int_t(TMath::Abs(vzMin)+.5),
118 vzMax < 0 ? 'm' : 'p', Int_t(TMath::Abs(vzMax)+.5),
119 rebin, trgName.Data());
121 if (!Open(file, outName)) return kFALSE;
122 if (!Process(vzMin,vzMax,mask)) return kFALSE;
123 if (!Finish(rebin, mask, energy)) return kFALSE;
127 //__________________________________________________________________
129 * Open the files @a fname containg the tree with AliAODEvent objects,
130 * and also open the output file @a outname for writting.
132 * @param fname Input file name
133 * @param outname Output file name
135 * @return true on success, false otherwise
137 Bool_t Open(const char* fname, const char* outname)
141 TFile* file = TFile::Open(fname, "READ");
143 Error("Open", "Cannot open file %s", fname);
148 fTree = static_cast<TTree*>(file->Get("aodTree"));
150 Error("Init", "Couldn't get the tree");
154 // Set the branch pointer
155 fTree->SetBranchAddress("Forward", &fAOD);
157 fOut = TFile::Open(outname, "RECREATE");
159 Error("Open", "Couldn't open %s", outname);
164 //__________________________________________________________________
168 * @param vzMin Minimum interaction point z coordinate
169 * @param vzMax Maximum interaction point z coordinate
170 * @param mask Trigger mask
172 * @return true on success, false otherwise
174 Bool_t Process(Double_t vzMin, Double_t vzMax, Int_t mask)
176 Int_t nTriggered = 0; // # of triggered ev.
177 Int_t nWithVertex = 0; // # of ev. w/vertex
178 Int_t nAccepted = 0; // # of ev. used
179 Int_t nAvailable = fTree->GetEntries(); // How many entries
181 for (int i = 0; i < nAvailable; i++) {
183 if (((i+1) % 100) == 0) {
184 fprintf(stdout,"Event # %9d of %9d, %9d accepted so far\r",
185 i+1, nAvailable, nAccepted);
189 // Create sum histogram on first event - to match binning to input
191 fSum = static_cast<TH2D*>(fAOD->GetHistogram().Clone("d2ndetadphi"));
192 Info("Process", "Created sum histogram (%d,%f,%f)x(%d,%f,%f)",
194 fSum->GetXaxis()->GetXmin(),
195 fSum->GetXaxis()->GetXmax(),
197 fSum->GetYaxis()->GetXmin(),
198 fSum->GetYaxis()->GetXmax());
202 // Other trigger/event requirements could be defined
203 if (!fAOD->IsTriggerBits(mask)) continue;
206 // Check if there's a vertex
207 if (!fAOD->HasIpZ()) continue;
210 // Select vertex range (in centimeters)
211 if (!fAOD->InRange(vzMin, vzMax)) continue;
214 // Add contribution from this event
215 fSum->Add(&(fAOD->GetHistogram()));
218 fVtxEff = Double_t(nWithVertex)/nTriggered;
220 Info("Process", "Total of %9d events\n"
221 " %9d has a trigger\n"
222 " %9d has a vertex\n"
224 nAvailable, nTriggered, nWithVertex, nAccepted);
228 //__________________________________________________________________
230 * Finish the stuff and draw
232 * @param rebin How many times to rebin
233 * @param energy Collision energy
234 * @param mask Trigger mask
236 * @return true on success, false otherwise
238 Bool_t Finish(Int_t rebin, Int_t mask, Int_t energy)
242 // Get acceptance normalisation from underflow bins
243 TH1D* norm = fSum->ProjectionX("norm", 0, 1, "");
244 // Project onto eta axis - _ignoring_underflow_bins_!
245 TH1D* dndeta = fSum->ProjectionX("dndeta", 1, -1, "e");
246 dndeta->SetTitle("1/N dN_{ch}/d#eta|_{forward}");
247 // Normalize to the acceptance
248 dndeta->Divide(norm);
249 // Scale by the vertex efficiency
250 dndeta->Scale(fVtxEff, "width");
251 dndeta->SetMarkerColor(kRed+1);
252 dndeta->SetMarkerStyle(20);
253 dndeta->SetMarkerSize(1);
254 dndeta->SetFillStyle(0);
255 Rebin(dndeta, rebin);
256 DrawIt(dndeta, mask, energy);
260 //__________________________________________________________________
263 void DrawIt(TH1* dndeta, Int_t mask, Int_t energy)
265 // --- 1st part - prepare data -----------------------------------
266 TH1* sym = Symmetrice(dndeta);
267 // Rebin(sym, rebin);
269 THStack* stack = new THStack("results", "Results");
273 // Get the data from HHD's analysis - if available
274 TString hhdName(fOut->GetName());
275 hhdName.ReplaceAll("dndeta", "hhd");
276 TH1* hhd = GetHHD(hhdName.Data(), mask & AliAODForwardMult::kNSD);
279 // Symmetrice and add to stack
280 hhdsym = Symmetrice(hhd);
285 // Get graph of 'other' data - e.g., UA5, CMS, ... - and check if
286 // there's any graphs. Set the pad division based on that.
287 TMultiGraph* other = GetData(energy, mask);
288 THStack* ratios = MakeRatios(dndeta, sym, hhd, hhdsym, other);
290 // Check if we have ratios
292 // --- 2nd part - Draw in canvas ---------------------------------
294 gStyle->SetOptTitle(0);
295 TCanvas* c = new TCanvas("c", "C", 900, 800);
301 Double_t yd = (ratios ? 0.3 : 0);
303 // Make a sub-pad for the result itself
304 TPad* p1 = new TPad("p1", "p1", 0, yd, 1.0, 1.0, 0, 0);
305 p1->SetTopMargin(0.05);
306 p1->SetBottomMargin(ratios ? 0.001 : 0.1);
307 p1->SetRightMargin(0.05);
313 // Fix the apperance of the stack and redraw.
314 stack->SetMinimum(ratios ? -0.1 : 0);
315 FixAxis(stack, 1/(1-yd)/1.5, "#frac{1}{N} #frac{dN_{ch}}{#eta}");
317 stack->DrawClone("nostack e1");
321 TGraphAsymmErrors* o = 0;
322 TIter nextG(other->GetListOfGraphs());
323 while ((o = static_cast<TGraphAsymmErrors*>(nextG())))
328 // Make a legend in the main result pad
329 TString trigs(AliAODForwardMult::GetTriggerString(mask));
330 TLegend* l = p1->BuildLegend(.15,p1->GetBottomMargin()+.01,.90,.35);
337 // Put a title on top
338 TLatex* tit = new TLatex(0.10, 0.95, fTitle.Data());
340 tit->SetTextSize(0.05);
343 // Put a nice label in the plot
344 TLatex* tt = new TLatex(.5, .50,
345 Form("#sqrt{s}=%dGeV, %s", energy,
346 AliAODForwardMult::GetTriggerString(mask)));
348 tt->SetTextAlign(22);
351 // Mark the plot as preliminary
352 TLatex* pt = new TLatex(.5, .42, "Preliminary");
354 pt->SetTextSize(0.07);
355 pt->SetTextColor(kRed+1);
356 pt->SetTextAlign(22);
360 // If we do not have the ratios, fix up the display
361 // p1->SetPad(0, 0, 1, 1);
362 // p1->SetBottomMargin(0.1);
364 // stack->SetMinimum(0);
365 // FixAxis(stack, (1-yd)/1, "#frac{1}{N} #frac{dN_{ch}}{#eta}",10,false);
367 // If we do have the ratios, then make a new pad and draw the
370 TPad* p2 = new TPad("p2", "p2", 0, 0.0, 1.0, yd, 0, 0);
371 p2->SetTopMargin(0.001);
372 p2->SetRightMargin(0.05);
373 p2->SetBottomMargin(1/yd * 0.07);
380 FixAxis(ratios, 1/yd/1.5, "Ratios", 5);
382 // Fix up y range and redraw
383 ratios->SetMinimum(.58);
384 ratios->SetMaximum(1.22);
386 ratios->DrawClone("nostack e1");
389 TLegend* l2 = p2->BuildLegend(.15,p2->GetBottomMargin()+.01,.9,.6);
393 l2->SetBorderSize(0);
395 // Make a nice band from 0.9 to 1.1
396 TGraphErrors* band = new TGraphErrors(2);
397 band->SetPoint(0, sym->GetXaxis()->GetXmin(), 1);
398 band->SetPoint(1, dndeta->GetXaxis()->GetXmax(), 1);
399 band->SetPointError(0, 0, .1);
400 band->SetPointError(1, 0, .1);
401 band->SetFillColor(kYellow+2);
402 band->SetFillStyle(3002);
403 band->Draw("3 same");
405 // Replot the ratios on top
406 ratios->DrawClone("nostack e1 same");
412 TString imgName(fOut->GetName());
413 imgName.ReplaceAll(".root", ".png");
414 c->SaveAs(imgName.Data());
417 if (other) other->Write();
418 if (ratios) ratios->Write();
423 //__________________________________________________________________
425 * Get the result from previous analysis code
427 * @param fn File to open
429 * @return null or result of previous analysis code
431 TH1* GetHHD(const char* fn="fmd_dNdeta_mult.root", bool nsd=false)
433 TDirectory* savdir = gDirectory;
434 if (gSystem->AccessPathName(fn)) {
435 Warning("GetHHD", "Output of HHD analysis (%s) not available", fn);
438 TFile* file = TFile::Open(fn, "READ");
440 Warning("GetHHD", "couldn't open HHD file %s", fn);
444 TString hist(Form("dNdeta_dNdeta%s", (nsd ? "NSD" : "")));
445 TH1* h = static_cast<TH1*>(file->Get(hist.Data()));
447 Warning("GetHHD", "Couldn't find HHD histogram %s in %s",
453 TH1* r = static_cast<TH1*>(h->Clone("dndeta_hhd"));
454 r->SetTitle("1/N dN_{ch}/d#eta (HHD)");
457 r->SetMarkerStyle(21);
458 r->SetMarkerColor(kPink+1);
459 r->SetDirectory(savdir);
465 //__________________________________________________________________
468 THStack* MakeRatios(const TH1* dndeta, const TH1* sym,
469 const TH1* hhd, const TH1* hhdsym,
470 TMultiGraph* other) const
472 // If we have 'other' data, then do the ratio of the results to that
473 Bool_t hasOther = (other && other->GetListOfGraphs() &&
474 other->GetListOfGraphs()->GetEntries() > 0);
475 Bool_t hasHhd = (hhd && hhdsym);
476 if (!hasOther || !hasHhd) return 0;
478 THStack* ratios = new THStack("ratios", "Ratios");
480 TGraphAsymmErrors* o = 0;
481 TIter nextG(other->GetListOfGraphs());
482 while ((o = static_cast<TGraphAsymmErrors*>(nextG()))) {
483 ratios->Add(Ratio(dndeta, o));
484 ratios->Add(Ratio(sym, o));
485 ratios->Add(Ratio(hhd, o));
486 ratios->Add(Ratio(hhdsym, o));
490 // If we have data from HHD's analysis, then do the ratio of
491 // our result to that data.
493 TH1F* t1 = static_cast<TH1F*>(dndeta->Clone(Form("%s_%s",
496 t1->SetTitle(Form("%s / %s", dndeta->GetTitle(), hhd->GetTitle()));
497 TH1F* t2 = static_cast<TH1F*>(sym->Clone(Form("%s_%s",
499 hhdsym->GetName())));
500 t2->SetTitle(Form("%s / %s", sym->GetTitle(), hhdsym->GetTitle()));
507 // Check if we have ratios
508 Bool_t hasRatios = (ratios->GetHists() &&
509 (ratios->GetHists()->GetEntries() > 0));
510 Info("MakeRatios", "Got a total of %d ratios", !hasRatios ? 0 :
511 ratios->GetHists()->GetEntries());
513 if (!hasRatios) { delete ratios; ratios = 0; }
517 //__________________________________________________________________
519 * Fix the apperance of the axis in a stack
521 * @param stack stack of histogram
522 * @param s Scaling factor
523 * @param ytitle Y axis title
524 * @param force Whether to draw the stack first or not
526 void FixAxis(THStack* stack, Double_t s, const char* ytitle,
527 Int_t ynDiv=10, Bool_t force=true)
529 if (force) stack->Draw("nostack e1");
531 TH1* h = stack->GetHistogram();
534 h->SetXTitle("#eta");
535 h->SetYTitle(ytitle);
536 TAxis* xa = h->GetXaxis();
537 TAxis* ya = h->GetYaxis();
539 xa->SetTitle("#eta");
540 // xa->SetTicks("+-");
541 xa->SetTitleSize(s*xa->GetTitleSize());
542 xa->SetLabelSize(s*xa->GetLabelSize());
543 xa->SetTickLength(s*xa->GetTickLength());
546 ya->SetTitle(ytitle);
548 // ya->SetTicks("+-");
549 ya->SetNdivisions(ynDiv);
550 ya->SetTitleSize(s*ya->GetTitleSize());
551 ya->SetLabelSize(s*ya->GetLabelSize());
554 //__________________________________________________________________
556 * Compute the ratio of @a h to @a g. @a g is evaluated at the bin
564 TH1* Ratio(const TH1* h, const TGraph* g) const
566 if (!h || !g) return 0;
568 TH1* ret = static_cast<TH1*>(h->Clone("tmp"));
569 ret->SetName(Form("%s_over_%s", h->GetName(), g->GetName()));
570 ret->SetTitle(Form("%s / %s", h->GetTitle(), g->GetTitle()));
572 ret->SetMarkerStyle(h->GetMarkerStyle());
573 ret->SetMarkerColor(g->GetMarkerColor());
574 ret->SetMarkerSize(0.9*g->GetMarkerSize());
575 Double_t xlow = g->GetX()[0];
576 Double_t xhigh = g->GetX()[g->GetN()-1];
577 if (xlow > xhigh) { Double_t t = xhigh; xhigh = xlow; xlow = t; }
579 for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
580 Double_t c = h->GetBinContent(i);
581 if (c <= 0) continue;
583 Double_t x = h->GetBinCenter(i);
584 if (x < xlow || x > xhigh) continue;
586 Double_t f = g->Eval(x);
587 if (f <= 0) continue;
589 ret->SetBinContent(i, c / f);
590 ret->SetBinError(i, h->GetBinError(i) / f);
592 if (ret->GetEntries() <= 0) { delete ret; ret = 0; }
596 //__________________________________________________________________
598 * Make an extension of @a h to make it symmetric about 0
600 * @param h Histogram to symmertrice
602 * @return Symmetric extension of @a h
604 TH1* Symmetrice(const TH1* h) const
606 Int_t nBins = h->GetNbinsX();
607 TH1* s = new TH1D(Form("%s_mirror", h->GetName()),
608 Form("%s (mirrored)", h->GetTitle()),
610 -h->GetXaxis()->GetXmax(),
611 -h->GetXaxis()->GetXmin());
612 s->SetMarkerColor(h->GetMarkerColor());
613 s->SetMarkerSize(h->GetMarkerSize());
614 s->SetMarkerStyle(h->GetMarkerStyle()+4);
615 s->SetFillColor(h->GetFillColor());
616 s->SetFillStyle(h->GetFillStyle());
618 // Find the first and last bin with data
619 Int_t first = nBins+1;
621 for (Int_t i = 1; i <= nBins; i++) {
622 if (h->GetBinContent(i) <= 0) continue;
623 first = TMath::Min(first, i);
624 last = TMath::Max(last, i);
627 Double_t xfirst = h->GetBinCenter(first-1);
628 Int_t f1 = h->GetXaxis()->FindBin(-xfirst);
629 Int_t l2 = s->GetXaxis()->FindBin(xfirst);
630 for (Int_t i = f1, j=l2; i <= last; i++,j--) {
631 s->SetBinContent(j, h->GetBinContent(i));
632 s->SetBinError(j, h->GetBinError(i));
636 //__________________________________________________________________
640 * @param h Histogram to rebin
641 * @param rebin Rebinning factor
645 virtual void Rebin(TH1* h, Int_t rebin) const
647 if (rebin <= 1) return;
649 Int_t nBins = h->GetNbinsX();
650 if(nBins % rebin != 0) {
651 Warning("Rebin", "Rebin factor %d is not a devisor of current number "
652 "of bins %d in the histogram %s", rebin, nBins, h->GetName());
657 TH1* tmp = static_cast<TH1*>(h->Clone("tmp"));
659 tmp->SetDirectory(0);
661 // The new number of bins
662 Int_t nBinsNew = nBins / rebin;
663 for(Int_t i = 1;i<= nBinsNew; i++) {
664 Double_t content = 0;
668 for(Int_t j = 1; j<=rebin;j++) {
669 Int_t bin = (i-1)*rebin + j;
670 if(h->GetBinContent(bin) <= 0) continue;
671 Double_t c = h->GetBinContent(bin);
672 Double_t w = 1 / TMath::Power(c,2);
680 tmp->SetBinContent(i, wsum / sumw);
681 tmp->SetBinError(i,TMath::Sqrt(sumw));
685 // Finally, rebin the histogram, and set new content
687 for(Int_t i =1;i<=nBinsNew; i++) {
688 h->SetBinContent(i,tmp->GetBinContent(i));
689 // h->SetBinError(i,tmp->GetBinError(i));
696 //____________________________________________________________________