AliPhysics  a5cd6b6 (a5cd6b6)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Interpolate.C
Go to the documentation of this file.
1 #include <THStack.h>
2 #include <TROOT.h>
3 #include <TCanvas.h>
4 #include <TLegend.h>
5 #include <TList.h>
6 #include <TH1.h>
7 #include <TError.h>
8 #include <TMultiGraph.h>
9 #include <TNtuple.h>
10 #include <TFile.h>
11 #include <TGraph.h>
12 #include <TGraphErrors.h>
13 #include <TPrincipal.h>
14 
15 TH1* GetOne(UShort_t sNN, const TString& trigger)
16 {
17  Long_t p = gROOT->ProcessLine(Form("Drawer::GetStack(0, \"pp\", %d, "
18  "\"%s\", false, true)",
19  sNN, trigger.Data()));
20  THStack* s = (THStack*)p;
21  TList* l = s->GetHists();
22  TH1* h = 0;
23  TIter n(l);
24  l->ls();
25  while ((h = static_cast<TH1*>(n()))) {
26  TString m(h->GetName());
27  if (m.EqualTo("dndetaForward_all")) break;
28  }
29 
30  if (h) {
31  switch (sNN) {
32  case 900: h->SetTitle("900GeV"); h->SetMarkerColor(kRed+2); break;
33  case 2760: h->SetTitle("2.76TeV"); h->SetMarkerColor(kGreen+2); break;
34  case 7000: h->SetTitle("7TeV"); h->SetMarkerColor(kBlue+2); break;
35  case 8000: h->SetTitle("8TeV"); h->SetMarkerColor(kBlack); break;
36  }
37  }
38 
39  return h;
40 }
41 void OneBin(Int_t bin,
42  TH1* h0900,
43  TH1* h2760,
44  TH1* h7000,
45  TH1* h8000,
46  TMultiGraph* mg,
47  TNtuple* tuple,
48  Double_t sysErr=0.076)
49 {
50  Info("OneBin", "Getting one bin %d,%p,%p,%p,%p,%p",
51  bin, h0900,h2760,h7000,h8000,tuple);
52 
53  Double_t eta = h0900->GetXaxis()->GetBinCenter(bin);
54  Double_t w = h0900->GetXaxis()->GetBinWidth(bin);
55  Info("", "Eta=%f +/- %f", eta, w);
56  Double_t e[] = { 900., 2760., 7000., 8000., 0 };
57  TH1* h[] = { h0900, h2760, h7000, h8000, 0 };
58  Float_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
59  x[0] = eta;
60  x[1] = w;
61 
62  TGraphErrors* g = new TGraphErrors(0);
63  g->SetName(Form("eta%03d", bin));
64  g->SetTitle(Form("%f", eta));
65  g->SetMarkerStyle(bin % 10 + 20);
66  g->SetMarkerColor(bin % 6 + 2);
67 
68  Double_t* pe = e;
69  TH1** ph = h;
70  Int_t i = 0;
71  Int_t j = 1;
72  while (*pe && *ph) {
73  Double_t c = (*ph)->GetBinContent(bin);
74  Double_t v = sysErr*c;
75  if (c > 1e-6){
76  g->SetPoint(i, *pe, c);
77  g->SetPointError(i, w, v);
78  x[Int_t(2*j+0)] = c;
79  x[Int_t(2*j+1)] = v;
80  i++;
81  }
82  j++;
83  pe++;
84  ph++;
85  }
86  if (tuple) tuple->Fill(x);
87  if (i > 0) mg->Add(g);
88  else delete g;
89 }
90 
91 
92 void Interpolate(const TString& trigger="INEL")
93 {
94  if (gSystem->Getenv("FWD"))
95  fwd = gSystem->Getenv("FWD");
96  else
97  fwd = gSystem->ExpandPathName("$ALICE_PHYSICS/PWGLF/FORWARD/analysis2");
98  gROOT->SetMacroPath(Form("%s/dndeta:%s", gROOT->GetMacroPath(),fwd));
99 
100  if (!gROOT->GetClass("Drawer")) gROOT->LoadMacro("Drawer.C+");
101 
102  TH1* h0900 = GetOne( 900, trigger);
103  TH1* h2760 = GetOne(2760, trigger);
104  TH1* h7000 = GetOne(7000, trigger);
105  TH1* h8000 = GetOne(8000, trigger);
106  Info("","900: %p 2760: %p 7000: %p 8000: %p",
107  h0900, h2760, h7000, h8000);
108  Double_t e8000 = (trigger.EqualTo("INEL") ? 0.852 : 0.93);
109  h8000->Scale(e8000);
110 
111  TFile* out = TFile::Open("trends.root", "RECREATE");
112  THStack* sOrig = new THStack("orig", Form("pp - %s", trigger.Data()));
113  sOrig->Add(h8000);
114  sOrig->Add(h7000);
115  sOrig->Add(h2760);
116  sOrig->Add(h0900);
117 
118  TCanvas* cOrig = new TCanvas("cOrig", "Original", 1200, 1200);
119  cOrig->SetTopMargin(0.01);
120  cOrig->SetRightMargin(0.01);
121  sOrig->Draw("nostack");
122  sOrig->GetHistogram()->SetYTitle("1/#it{N} d#it{N}_{ch}/d#it{#eta}");
123  sOrig->GetHistogram()->SetXTitle("#it{#eta}");
124  sOrig->DrawClone("nostack");
125  sOrig->Write();
126 
127  TLegend* l = cOrig->BuildLegend(.35, .2, .55, .6, "#sqrt{s}");
128  l->SetFillColor(0);
129  l->SetFillStyle(0);
130  l->SetBorderSize(0);
131 
132  cOrig->Modified();
133  cOrig->Update();
134  cOrig->cd();
135  cOrig->Write();
136  Info("", "Wrote original");
137 
138  TCanvas* cG = new TCanvas("cG", "one", 1200, 1200);
139  cG->SetTopMargin(0.01);
140  cG->SetRightMargin(0.01);
141 
142  Info("","Creating tuple");
143  TNtuple* tuple = new TNtuple("tuple", "Tuple",
144  "eta:deta:"
145  "v0900:e0900:v2760:e2760:"
146  "v7000:e7000:v8000:e8000");
147  TMultiGraph* mg = new TMultiGraph;
148  Int_t n = h0900->GetNbinsX();
149  Info("","Loop over bins %d", n);
150 
151  for (Int_t i = 1; i <= n; i++) {
152  Info("", "Getting one bin %d,%p,%p,%p,%p,%p,%p",
153  i, h0900,h2760,h7000,h8000,mg,tuple);
154  OneBin(i, h0900, h2760, h7000, h8000, mg, tuple);
155  }
156  mg->Draw("alp");
157 
158  cG->Modified();
159  cG->Update();
160  cG->cd();
161 
162  TPrincipal* p =tuple->Principal("v0900:v2760:v7000:v8000","eta<0", "npdhc");
163 }
TH1 * GetOne(UShort_t sNN, const TString &trigger)
Definition: Interpolate.C:15
double Double_t
Definition: External.C:58
TSystem * gSystem
TCanvas * c
Definition: TestFitELoss.C:172
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
void Interpolate(const TString &trigger="INEL")
Definition: Interpolate.C:92
const char * fwd
unsigned short UShort_t
Definition: External.C:28
Definition: External.C:196
void OneBin(Int_t bin, TH1 *h0900, TH1 *h2760, TH1 *h7000, TH1 *h8000, TMultiGraph *mg, TNtuple *tuple, Double_t sysErr=0.076)
Definition: Interpolate.C:41