AliPhysics  cc1c0ba (cc1c0ba)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DrawDeltas3.C
Go to the documentation of this file.
1 
2 
3 THStack* GetDeltas(const char* filename, Double_t c1, Double_t c2,
4  Bool_t& k)
5 {
6  TFile* file = TFile::Open(filename, "READ");
7  if (!file) {
8  Warning("DrawDeltas2", "File %s couldn't be opened", filename);
9  return;
10  }
11 
12  TString dname; dname.Form("cent%06.2f_%06.2f", c1, c2);
13  dname.ReplaceAll(".", "d");
14  TDirectory* d = file->GetDirectory(dname);
15  if (!d) {
16  Warning("DrawDeltas2", "Directory %s not found in %s",
17  dname.Data(), file->GetName());
18  return;
19  }
20 
21  TDirectory* det = d->GetDirectory("details");
22  if (!det) {
23  Warning("DrawDeltas2", "Directory details not found in %s",
24  d->GetName());
25  d->ls();
26  return;
27  }
28  k = (det->Get("scalar") != 0);
29 
30  TObject* o = det->Get("deltas");
32  if (!o) {
33  Warning("DrawDeltas2", "Object deltas not found in %s",
34  det->GetName());
35  return;
36  }
37 
38  if (!o->IsA()->InheritsFrom(THStack::Class())) {
39  Warning("DrawDeltas2", "Object %s is not a THStack, but a %s",
40  o->GetName(), o->ClassName());
41  return;
42  }
43  THStack* s = static_cast<THStack*>(o);
44 
45  return s;
46 }
47 
48 void DrawStack(TVirtualPad* p, THStack* s, Double_t min, Double_t max)
49 {
50  p->SetLogx();
51  p->SetLogy();
52  p->SetGridx();
53  p->SetGridy();
54  p->SetTicks();
55 
56  s->SetMaximum(max);
57  s->SetMinimum(min);
58  s->Draw("nostack");
59 
60  TH1* h = s->GetHistogram();
61  h->SetXTitle("#Delta");
62  h->SetYTitle("Tracklets/event");
63 
64  TLine* ll = new TLine(1.5, min, 1.5, max);
65  ll->SetLineColor(kGreen+2);
66  ll->SetLineWidth(3);
67  ll->Draw();
68 
69  TLine* lh = new TLine(5, min, 5, max);
70  lh->SetLineColor(kRed+2);
71  lh->SetLineWidth(3);
72  lh->Draw();
73 
74  // TLegend* l = p->BuildLegend(.6,.75,.99,.99);
75  TLegend* l = p->BuildLegend(p->GetLeftMargin(),
76  p->GetBottomMargin(),
77  .7,
78  p->GetBottomMargin()+.35);
79  l->SetNColumns(2);
80  Int_t n = l->GetListOfPrimitives()->GetEntries();
81  ((TNamed*)(l->GetListOfPrimitives()->At(n-2)))->SetTitle("Signal cut");
82  ((TNamed*)(l->GetListOfPrimitives()->At(n-1)))->SetTitle("Background cut");
83  // l->SetBorderSize(0);
84  // l->SetFillStyle(0);
85  p->Modified();
86 
87  // s->GetHists()->Print();
88 
89 }
90 void DrawRatios(TVirtualPad* p, THStack* s, Double_t min=0.8, Double_t max=1.22)
91 {
92  p->SetLogx();
93  // p->SetLogy();
94  p->SetGridx();
95  p->SetGridy();
96  p->SetTicks();
97 
98  TH1* realMeas = static_cast<TH1*>(s->GetHists()->At(0));
99  TH1* simMeas = static_cast<TH1*>(s->GetHists()->At(1));
100  TH1* realInj = static_cast<TH1*>(s->GetHists()->At(2));
101  TH1* simInj = static_cast<TH1*>(s->GetHists()->At(3));
102 
103  TH1* ratioMeas = static_cast<TH1*>(simMeas->Clone("ratioMeas"));
104  TH1* ratioInj = static_cast<TH1*>(simInj ->Clone("ratioInj"));
105  ratioMeas->SetDirectory(0);
106  ratioInj ->SetDirectory(0);
107  ratioMeas->SetTitle(Form("%s/%s",simMeas->GetTitle(),realMeas->GetTitle()));
108  ratioInj ->SetTitle(Form("%s/%s",simInj ->GetTitle(),realInj ->GetTitle()));
109  ratioMeas->SetTitle("Measured");
110  ratioInj ->SetTitle("Injection");
111  ratioInj ->SetMarkerColor(realMeas->GetMarkerColor());
112  ratioMeas->Divide(realMeas);
113  ratioInj ->Divide(realInj );
114  ratioMeas->SetYTitle("Sim./Real");
115  ratioInj ->SetYTitle("Sim./Real");
116 
117  THStack* r = new THStack("ratios", "");
118  r->Add(ratioMeas);
119  r->Add(ratioInj);
120  r->SetMinimum(min);
121  r->SetMaximum(max);
122 
123  r->Draw("nostack");
124  TH1* h = r->GetHistogram();
125  h->SetXTitle(ratioMeas->GetXaxis()->GetTitle());
126  h->SetYTitle(ratioMeas->GetYaxis()->GetTitle());
127 
128  TLegend* l = p->BuildLegend(p->GetLeftMargin(),
129  p->GetBottomMargin(),
130  1-p->GetRightMargin(),
131  p->GetBottomMargin()+.15);
132  l->SetNColumns(2);
133 
134  p->Modified();
135 }
136 
137 void DrawTitle(TVirtualPad* c,
138  TVirtualPad* p,
139  const char* file,
140  Double_t c1,
141  Double_t c2,
142  Bool_t k)
143 {
144  TString t(file);
145  t.ReplaceAll("results/", "");
146  t.ReplaceAll("combine_","");
147  t.ReplaceAll("_0x3.root", "");
148  t.Prepend("Weights: ");
149  if (k) t.Append(", #it{k}(#eta),");
150  else t.Append(", #it{k}#equiv1,");
151  t.Append(Form(" %4.1f - %4.1f%%", c1, c2));
152 
153  c->cd();
154  Double_t xm = p->GetXlowNDC() + p->GetWNDC()/2;
155  TLatex* tit = new TLatex(xm, 0.99, t);
156  tit->SetTextFont(42);
157  tit->SetTextAlign(23);
158  tit->SetTextSize(0.03);
159  tit->Draw();
160 
161  c->Modified();
162 }
163 
164 
165 
166 TCanvas* DrawDeltas3(const char* file1, const char* file2,
167  Double_t c1=0, Double_t c2=5)
168 {
169  Bool_t k1 = false;
170  Bool_t k2 = false;
171  THStack* s1 = GetDeltas(file1, c1, c2, k1);
172  THStack* s2 = GetDeltas(file2, c1, c2, k2);
173  Double_t min = TMath::Min(s1->GetMinimum("nostack"),
174  s2->GetMinimum("nostack"));
175  Double_t max = TMath::Max(s1->GetMaximum("nostack"),
176  s2->GetMaximum("nostack"));
177 
178  Int_t cW = 1200;
179  Int_t cH = 900;
180  TCanvas* c = new TCanvas("c", "C", cW, cH);
181  c->SetTopMargin(0.1);
182  c->SetRightMargin(0.01);
183  c->Divide(2,2,0,0);
184 
185  TVirtualPad* p = c->cd(1);
186  DrawStack(p, s1, min, max);
187 
188  p = c->cd(2);
189  p->SetRightMargin(0.01);
190  DrawStack(p, s2, min, max);
191 
192  p = c->cd(3);
193  DrawRatios(p, s1);
194 
195  p = c->cd(4);
196  p->SetRightMargin(0.01);
197  DrawRatios(p, s2);
198 
199  DrawTitle(c, c->GetPad(1), file1, c1, c2, k1);
200  DrawTitle(c, c->GetPad(2), file2, c1, c2, k2);
201 
202  return c;
203 }
204 
206  const char* var,
207  Double_t c1=0,
208  Double_t c2=5)
209 {
210  TCanvas* c = DrawDeltas3(Form("results/combine_none_0x%x.root",flags),
211  Form("results/combine_%s_0x%x.root",var,flags),
212  c1, c2);
213  c->Modified();
214  c->Update();
215  c->cd();
216  c->SaveAs(Form("plots/deltas2_%s_0x%x.png", var, flags));
217 }
const char * filename
Definition: TestFCM.C:1
double Double_t
Definition: External.C:58
TCanvas * c
Definition: TestFitELoss.C:172
void DrawStack(TVirtualPad *p, THStack *s, Double_t min, Double_t max)
Definition: DrawDeltas3.C:48
TCanvas * DrawDeltas3(const char *file1, const char *file2, Double_t c1=0, Double_t c2=5)
Definition: DrawDeltas3.C:166
THStack * GetDeltas(const char *filename, Double_t c1, Double_t c2, Bool_t &k)
Definition: DrawDeltas3.C:3
Int_t cH
Definition: Combine.C:26
int Int_t
Definition: External.C:63
void DrawRatios(TVirtualPad *p, THStack *s, Double_t min=0.8, Double_t max=1.22)
Definition: DrawDeltas3.C:90
void DrawTitle(TVirtualPad *c, TVirtualPad *p, const char *file, Double_t c1, Double_t c2, Bool_t k)
Definition: DrawDeltas3.C:137
Int_t cW
Definition: Combine.C:25
TFile * file
TList with histograms for a given trigger.
unsigned short UShort_t
Definition: External.C:28
bool Bool_t
Definition: External.C:53
Definition: External.C:196