AliPhysics  b555aef (b555aef)
DrawKs.C
Go to the documentation of this file.
1 const Color_t cc[] = { kMagenta+2,
2  kBlue+2,
3  kAzure-1, // 10,
4  kCyan+2,
5  kGreen+1,
6  kSpring+5,//+10,
7  kYellow+1,
8  kOrange+5,//+10,
9  kRed+1,
10  kPink+5,//+10,
11  kBlack };
12 
13 TH1* GetCentK(TDirectory* top, Double_t c1, Double_t c2, Int_t s,
14  TLegend* l)
15 {
16  TString dname; dname.Form("cent%06.2f_%06.2f", c1, c2);
17  dname.ReplaceAll(".", "d");
18  TDirectory* d = top->GetDirectory(dname);
19  if (!d) {
20  Warning("GetCetnK", "Directory %s not found in %s",
21  dname.Data(), top->GetName());
22  return;
23  }
24 
25  TDirectory* det = d->GetDirectory("details");
26  if (!det) {
27  Warning("GetCetnK", "Directory details not found in %s",
28  d->GetName());
29  d->ls();
30  return;
31  }
32 
33  TObject* o = det->Get("scalar");
34  if (!o) {
35  Warning("GetCetnK", "Object scalar not found in %s",
36  det->GetName());
37  return;
38  }
39 
40  if (!o->IsA()->InheritsFrom(TH1::Class())) {
41  Warning("GetCetnK", "Object %s is not a TH1, but a %s",
42  o->GetName(), o->ClassName());
43  return;
44  }
45  TH1* h = static_cast<TH1*>(o->Clone());
46  Color_t col = cc[(s-1)%10];
47  h->SetLineColor(col);
48  h->SetMarkerColor(col);
49  h->SetFillColor(col);
50  h->SetFillStyle(1001);
51  // h->SetTitle(Form("%5.2f-%5.2f%% #times %d", c1, c2, s));
52  h->SetTitle(Form("%2.0f-%2.0f%% + %d", c1, c2, s-1));
53  TF1* f = new TF1("", "[0]",-2.2,2.2);
54  f->SetParameter(0,s-1);
55  f->SetLineColor(col);
56  f->SetLineStyle(7);
57  f->SetLineWidth(1);
58  // h->Scale(s);
59  h->Add(f);
60  h->GetListOfFunctions()->Add(f);
61  f->SetParameter(0,s);
62  for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
63  if (TMath::Abs(h->GetBinCenter(i)) > 2) {
64  h->SetBinContent(i,0);
65  h->SetBinError(i,0);
66  }
67  }
68 
69  TLegendEntry* e = l->AddEntry(h, h->GetTitle(), "f");
70  e->SetFillColor(col);
71  e->SetFillStyle(1001);
72  e->SetLineColor(col);
73 
74  return h;
75 }
76 
77 TCanvas* DrawKs(const char* filename)
78 {
79 
80  TFile* file = TFile::Open(filename, "READ");
81  if (!file) {
82  Warning("DrawKs", "File %s couldn't be opened", filename);
83  return 0;
84  }
85 
86  TH1* cent = static_cast<TH1*>(file->Get("cent"));
87  if (!cent) {
88  Warning("DrawKs", "Failed to find cent in %s", file->GetName());
89  return 0;
90  }
91 
92  TString t(filename);
93  t.ReplaceAll("results/", "");
94  t.ReplaceAll("combine_","");
95  t.ReplaceAll("_0x3.root", "");
96  TString nm(filename);
97  nm.ReplaceAll(".root", "");
98  nm.ReplaceAll("results/", "plots/");
99  nm.ReplaceAll("combine", "ks");
100  if (t.Contains("none"))
101  t.ReplaceAll("none", "No weights");
102  else
103  t.Append(" weights");
104 
105  Int_t cW = 1200;
106  Int_t cH = 800;
107  TCanvas* c = new TCanvas(nm,t,cW, cH);
108  c->SetTopMargin(0.07);
109  c->SetRightMargin(0.20);
110  c->SetTicks();
111 
112  TLegend* l = new TLegend(1-c->GetRightMargin(),
113  c->GetBottomMargin(),
114  .99,
115  1-c->GetTopMargin());
116  l->SetFillStyle(0);
117  l->SetBorderSize(0);
118 
119  THStack* s = new THStack("ks", "");
120  Int_t nCent = cent->GetXaxis()->GetNbins();
121  for (Int_t i = 1; i <= nCent; i++) {
122  Double_t c1 = cent->GetXaxis()->GetBinLowEdge(i);
123  Double_t c2 = cent->GetXaxis()->GetBinUpEdge(i);
124 
125  TH1* h = GetCentK(file, c1, c2, nCent-i+1-2, l);
126  if (!h) continue;
127 
128  s->Add(h);
129  }
130  s->Draw("nostack");
131  TH1* f = s->GetHistogram();
132  if (f) {
133  f->SetXTitle("#eta");
134  f->SetYTitle("#it{k}(#eta)");
135  }
136 
137  TLatex* tit = new TLatex(0.55, 0.99, t);
138  tit->SetTextFont(42);
139  tit->SetTextAlign(23);
140  tit->SetTextSize(0.03);
141  tit->SetNDC();
142  tit->Draw();
143  l->SetBorderSize(0);
144  l->Draw();
145 
146  c->Modified();
147  c->Update();
148  c->cd();
149 
150  return c;
151 }
152 
153 void DrawKs(UShort_t flags, const char* var)
154 {
155  TCanvas* c = DrawKs(Form("results/combine_%s_0x%x.root", var, flags));
156  c->SaveAs(Form("plots/ks_%s_0x%x.png", var, flags));
157 }
const char * filename
Definition: TestFCM.C:1
const Color_t cc[]
Definition: DrawKs.C:1
double Double_t
Definition: External.C:58
TCanvas * c
Definition: TestFitELoss.C:172
Int_t cH
Definition: Combine.C:26
int Int_t
Definition: External.C:63
TH1 * GetCentK(TDirectory *top, Double_t c1, Double_t c2, Int_t s, TLegend *l)
Definition: DrawKs.C:13
TCanvas * DrawKs(const char *filename)
Definition: DrawKs.C:77
Int_t cW
Definition: Combine.C:25
TFile * file
TList with histograms for a given trigger.
unsigned short UShort_t
Definition: External.C:28
Definition: External.C:196