AliPhysics  fffcdf3 (fffcdf3)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Extract.C
Go to the documentation of this file.
1 #ifndef __CINT__
2 #include <TGraphAsymmErrors.h>
3 #include <TFile.h>
4 #include <TString.h>
5 #include <TError.h>
6 #include <TClass.h>
7 #include <fstream>
8 #include <iomanip>
9 #else
10 class TGraphAsymmErrors;
11 #endif
12 
14  TString fname(Form("%s_%04d.root", trig.Data(), sNN));
15  TFile* file = TFile::Open(fname.Data(), "READ");
16  if (!file) {
17  Error("", "Failed to open %s", fname.Data());
18  return 0;
19  }
20 
21  TString objName(trig);
22  if (objName == "INELGt0") objName = "INELg0";
23 
24  TObject* o = file->Get(objName);
25  if (!o) {
26  Error("", "Failed to find %s in %s", objName.Data(), fname.Data());
27  file->Close();
28  return 0;
29  }
30 
31  if (!o->IsA()->InheritsFrom(TGraphAsymmErrors::Class())) {
32  Error("", "%s is not a TGraphAsymmErrors, but a %s",
33  objName.Data(), o->ClassName());
34  file->Close();
35  return 0;
36  }
37  TGraphAsymmErrors* ret = static_cast<TGraphAsymmErrors*>(o);
38  file->Close();
39 
40  return ret;
41 }
42 void WriteArray(const char* name, Double_t* a, Int_t first, Int_t last, std::ostream& o)
43 {
44 
45  o << " Double_t " << name << "[] = {";
46  Int_t n = last-first+1;
47  for (Int_t i = 0; i < n; i++) {
48  if (i != 0) {
49  o << ",";
50  if (i % 5 == 0) o << "\n ";
51  }
52  o << a[first+i];
53  }
54  o << "};" << std::endl;
55 }
56 
57 void WriteGraph(UShort_t sNN, const TString& trig, const TString& date, std::ostream& o)
58 {
59  TGraphAsymmErrors* src = GetGraph(sNN, trig);
60  if (!src) return;
61 
62  o << "// sNN=" << sNN << " trig=" << trig << std::endl;
63 
64  Int_t maxN = src->GetN();
65  Double_t* px = src->GetX();
66  Double_t* pxel = src->GetEXlow();
67  Double_t* pxeh = src->GetEXhigh();
68  Double_t* py = src->GetY();
69  Double_t* pyel = src->GetEYlow();
70  Double_t* pyeh = src->GetEYhigh();
71  Int_t first = -1;
72  Int_t last = -1;
73  for (Int_t i = 0; i < maxN; i++) {
74  if (py[i] > 1e-9) {
75  last = i;
76  if (first < 0) first = i;
77  }
78  }
79  if (first < 0 || last < 0) {
80  Warning("", "No points found for %d/%s", sNN, trig.Data());
81  return;
82  }
83  Int_t n = last-first+1;
84  Printf("Got %d-%d+1=%d non-zero points for %s",
85  last,first,last-first+1, src->GetName());
86 
87  o << " if (sNN==" << sNN << " && trg.EqualTo(\"" << trig << "\",TString::kIgnoreCase)) {\n"
88  << std::scientific
89  << " const Int_t n = " << n << ";" << std::endl;
90  WriteArray("x", px, first, last, o);
91  WriteArray("xel", pxel, first, last, o);
92  WriteArray("xeh", pxeh, first, last, o);
93  WriteArray("y", py, first, last, o);
94  WriteArray("yel", pyel, first, last, o);
95  WriteArray("yeh", pyeh, first, last, o);
96 
97  TString otrg(trig);
98  if (otrg.EqualTo("INEL")) otrg = "Inel";
99  else if (otrg.EqualTo("NSD")) otrg = "Nsd";
100  else if (otrg.EqualTo("INELGt0")) otrg = "InelGt0";
101 
102  o << " TGraphAsymmErrors* g = new TGraphAsymmErrors(" << n << ",x,y,xel,xeh,yel,yeh);\n"
103  << " SetGraphAttributes(g," << trig << ",WIP,false,\n"
104  << " \"alice_pp" << sNN << otrg << "Work\",\n"
105  << " \"PWG-UD/MULT - " << date << "\");\n"
106  << " return g;\n"
107  << " }"
108  << std::endl;
109 }
110 
111 void Extract()
112 {
113  TString date("2014/05/01");
114  std::ofstream o("PWGUD.C");
115 
116  o << "Int_t INEL = kRed+2;\n"
117  << "Int_t NSD = kGreen+2;\n"
118  << "Int_t INELGt0 = kBlue+2;\n"
119  << "Int_t WIP = 20;\n"
120  << "void SetGraphAttributes(TGraph* g, Int_t t, Int_t exp, bool b, const char* name, const char* title) {\n"
121  << " g->SetMarkerColor(t);\n"
122  << " g->SetMarkerStyle(exp);\n"
123  << " g->SetLineColor(t);\n"
124  << " g->SetFillColor(t);\n"
125  << " g->SetName(name);\n"
126  << " g->SetTitle(title);\n"
127  << " g->SetFillStyle(0);\n"
128  << " g->GetHistogram()->SetStats(kFALSE);\n"
129  << " g->GetHistogram()->SetXTitle(\"#eta\");\n"
130  << " g->GetHistogram()->SetYTitle(\"#frac{1}{N} #frac{dN_{ch}}{#eta}\");\n"
131  << "}\n\n"
132  << "TGraphAsymmErrors* GetPWGUD(UShort_t sNN, const TString& trg)\n"
133  << "{\n";
134  UShort_t aSNN[] = { 900, 2760, 7000, 8000, 0 };
135  const Char_t* aTrig[] = { "INEL", "NSD", "INELGt0", 0 };
136  UShort_t* pSNN = aSNN;
137 
138  while ((*pSNN > 0)) {
139  const char** pTrig = aTrig;
140  while ((*pTrig)) {
141  WriteGraph(*pSNN, *pTrig, date, o);
142  pTrig++;
143  }
144  pSNN++;
145  }
146 
147  o << " Warning(\"\",\"No data for sNN=%d and trig=%s\",sNN,trg.Data());\n"
148  << " return 0;\n"
149  << "}\n"
150  << "\n"
151  << "TMultiGraph* PWGUD() {\n"
152  << " TMultiGraph* mg = new TMultiGraph();\n";
153  pSNN = aSNN;
154  while ((*pSNN > 0)) {
155  const char** pTrig = aTrig;
156  while ((*pTrig)) {
157  o << " mg->Add(GetPWGUD(" << *pSNN << ",\"" << *pTrig << "\"));\n";
158  pTrig++;
159  }
160  pSNN++;
161  }
162  o << "\n"
163  << " mg->Draw(\"APL\");\n"
164  << " return mg;\n"
165  << "}\n"
166  << std::endl;
167 }
double Double_t
Definition: External.C:58
void Extract()
Definition: Extract.C:111
char Char_t
Definition: External.C:18
int Int_t
Definition: External.C:63
void WriteGraph(UShort_t sNN, const TString &trig, const TString &date, std::ostream &o)
Definition: Extract.C:57
TGraphAsymmErrors * GetGraph(UShort_t sNN, const TString &trig)
Definition: Extract.C:13
TFile * file
TList with histograms for a given trigger.
unsigned short UShort_t
Definition: External.C:28
void WriteArray(const char *name, Double_t *a, Int_t first, Int_t last, std::ostream &o)
Definition: Extract.C:42