AliPhysics  05c4c93 (05c4c93)
QuickDraw.C
Go to the documentation of this file.
1 #include <cstdarg>
2 #include <cstring>
3 #include <cstdio>
4 
5 void MyPrint(const char* msg)
6 {
7  gROOT->IndentLevel();
8  Printf(msg);
9 }
10 void MyIncr()
11 {
12  gROOT->IncreaseDirLevel();
13 }
14 void MyDecr()
15 {
16  gROOT->DecreaseDirLevel();
17 }
18 struct MyGuard
19 {
21  MyGuard(const char* msg)
22  : fMsg(msg)
23  {
24  MyPrint(msg);
25  MyIncr();
26  }
27  ~MyGuard() { MyDecr(); MyPrint(Form("End %s", fMsg.Data())); }
28 };
29 
30 
31 
32 void AddPath(const TString& dir, Bool_t pre=true)
33 {
34  TString mPath(gROOT->GetMacroPath());
35  if (pre) {
36  mPath.Prepend(":");
37  mPath.Prepend(dir);
38  }
39  else {
40  mPath.Append(":");
41  mPath.Append(dir);
42  }
43  gROOT->SetMacroPath(mPath);
44  gSystem->AddIncludePath(Form("-I%s", dir.Data()));
45 }
46 
47 
48 void ProcessCandidates(const TSeqCollection* inp, TList& toDraw)
49 {
50  TIter next(inp);
51  TObject* o = 0;
52  while ((o = next())) {
53  GraphSysErr* g = static_cast<GraphSysErr*>(o);
54  TString obsKey = g->GetKey("obskey");
55  TString det = g->GetKey("detector");
56  MyPrint(Form("ObsKey=%s Detector=%s", obsKey.Data(), det.Data()));
57  // g->Print("key");
58  TString opt("");
59  if (det.Contains("TRACKLET", TString::kIgnoreCase)) {
60  opt="XBASE=-4";
61  Color_t col = g->GetMarkerColor();
64  g->SetSumFillStyle(0);
65  g->SetSumFillColor(col);
66  g->SetSumLineColor(col);
68  g->SetCommonSumFillStyle(1001);
69  g->SetCommonSumFillColor(col);
70  g->SetCommonSumLineColor(col);
71  }
72  if (obsKey.EqualTo("DN/DETARAP", TString::kIgnoreCase))
73  toDraw.Add(g, opt);
74 
75  }
76 }
77 
78 void ProcessHEPData(const TString& filename, TList& toDraw)
79 {
80  MyGuard g(Form("HEPData %s", filename.Data()));
81  TSeqCollection* list = GraphSysErr::Import(filename);
82  ProcessCandidates(list,toDraw);
83 }
84 
85 void ProcessFile(const TString& filename, TList& toDraw)
86 {
87  MyGuard g(Form("File %s", filename.Data()));
88  TFile* file = TFile::Open(filename, "READ");
89  if (!file) return;
90 
91  TList candidates;
92  ProcessFileDirectory(file, candidates);
93  ProcessCandidates(&candidates, toDraw);
94  file->Close();
95 }
96 
97 void ProcessCollection(const TCollection* d, TList& toInspect)
98 {
99  MyGuard g(Form("Collection: %s", d->GetName()));
100  TIter next(d);
101  TObject* obj = 0;
102  while ((obj = next())) {
103  TClass* cls = obj->IsA();
104  if (!cls) {
105  MyPrint(Form("W: Object %s in %s has unknown class: %s",
106  obj->GetName(), d->GetName(), obj->ClassName()));
107  continue;
108  }
109  if (cls->InheritsFrom(TDirectory::Class())) {
110  ProcessFileDirectory(static_cast<TDirectory*>(obj),toInspect);
111  continue;
112  }
113  if (cls->InheritsFrom(TCollection::Class())) {
114  ProcessCollection(static_cast<TCollection*>(obj), toInspect);
115  continue;
116  }
117  if (cls->InheritsFrom(GraphSysErr::Class())) {
118  MyPrint(Form("Adding %s/%s to candidate list",
119  d->GetName(), obj->GetName()));
120  toInspect.Add(obj);
121  }
122  }
123 }
124 
125 void ProcessFileDirectory(const TDirectory* d, TList& toInspect)
126 {
127  MyGuard g(Form("File directory: %s", d->GetPath()));
128  TIter next(d->GetListOfKeys());
129  TKey* key = 0;
130  while ((key = static_cast<TKey*>(next()))) {
131  TClass* cls = gROOT->GetClass(key->GetClassName());
132  if (!cls) {
133  MyPrint(Form("W: Object %s in %s has unknown class: %s",
134  key->GetName(), d->GetPath(), key->GetClassName()));
135  continue;
136  }
137  if (cls->InheritsFrom(TDirectory::Class())) {
138  ProcessFileDirectory(static_cast<TDirectory*>(key->ReadObj()),toInspect);
139  continue;
140  }
141  if (cls->InheritsFrom(TCollection::Class())) {
142  ProcessCollection(static_cast<TCollection*>(key->ReadObj()), toInspect);
143  continue;
144  }
145  if (cls->InheritsFrom(GraphSysErr::Class())) {
146  MyPrint(Form("Adding %s/%s to candidate list",
147  d->GetPath(), key->GetName()));
148  toInspect.Add(key->ReadObj());
149  }
150  }
151 }
152 
153 void ProcessOne(const TString& filename, TList& toDraw)
154 {
155  if (filename.EndsWith(".input"))
156  ProcessHEPData(filename, toDraw);
157  else
158  ProcessFile(filename, toDraw);
159 }
160 
161 void QuickDraw()
162 {
163  QuickDraw(&(gApplication->Argv()[1]));
164 }
165 void QuickDraw(const char** args)
166 {
167  if (!gROOT->GetClass("GraphSysErr")) {
168  AddPath("$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/gse");
169  AddPath("$HOME/GraphSysErr");
170  gROOT->LoadMacro("GraphSysErr.C+g");
171  }
172  TList list;
173  {
174  // Int_t argc = gApplication->Argc();
175  // gApplication->ClearInputFiles();
176  MyGuard* g1 = new MyGuard("Processing arguments");
177  const char** ptr = args;
178  while (*ptr) {
179  TString argi = *ptr;
180  ptr++;
181  if (argi.BeginsWith("-")) continue;
182  if (argi.EndsWith("root.exe")) continue;
183  if (argi.EndsWith("QuickDraw.C")) continue;
184  if (!argi.EndsWith(".input") && !argi.EndsWith(".root")) continue;
185  gSystem->ExpandPathName(argi);
186  MyPrint(Form("Adding file %s", argi.Data()));
187  list.Add(new TObjString(argi));
188  // gApplication->Argv(i) = 0;
189  }
190  delete g1;
191  }
192 
193 
194  TList toDraw;
195  {
196  MyGuard* g2 = new MyGuard("Processing found files");
197  TIter next(&list);
198  TObject* obj = 0;
199  while ((obj = next())) {
200  ProcessOne(obj->GetName(), toDraw);
201  }
202  delete g2;
203  }
204 
205  // toDraw.ls();
206  TString opt("COMBINED QUAD");
207  Double_t ymin = 1e9, ymax = -1e9;
208  Double_t xmin = 1e9, xmax = -1e9;
209  {
210  MyGuard* g3 = new MyGuard("Figuring out min/max");
211  TIter next(&toDraw);
212  GraphSysErr* g = 0;
213  while ((g = static_cast<GraphSysErr*>(next()))) {
214  Double_t mn, mx;
215  g->GetMinMax(opt, mn, mx);
216  ymax = TMath::Max(mx,ymax);
217  ymin = TMath::Min(mn,ymin);
218  Int_t nx = g->GetN()-1;
219  Double_t x1 = g->GetX(0) -2*g->GetErrorXLeft(0);
220  Double_t x2 = g->GetX(nx)+2*g->GetErrorXRight(nx);
221  xmin = TMath::Min(x1,xmin);
222  xmax = TMath::Max(x2,xmax);
223 
224  }
225  MyPrint(Form("x-range: [%f,%f] y-range: [%f,%f]",xmin,xmax,ymin,ymax));
226  delete g3;
227  }
228 
229 
230  TCanvas* c = new TCanvas("c","c", 1000, 1000);
231  c->SetTopMargin(0.01);
232  c->SetRightMargin(0.01);
233  c->SetLeftMargin(ymax > 100 ? 0.14 : 0.1);
234  TH1* f = new TH2D("frame","",300,
235  (xmin < 0 ? 1.3 : 0.7)*xmin,
236  (xmax < 0 ? 0.7 : 1.3)*xmax,
237  300, 0.9*ymin, 1.1*ymax);
238  f->SetStats(0);
239  f->SetXTitle("\\eta");
240  f->SetYTitle("\\hbox{d}N_{\\hbox{ch}}/\\hbox{d}\\eta");
241  f->GetYaxis()->SetTitleOffset(ymax > 1000 ? 1.7 : 1.1);
242  f->GetYaxis()->SetNdivisions(210);
243  f->GetXaxis()->SetNdivisions(210);
244  f->Draw();
245  {
246  MyGuard* g4 = new MyGuard("Drawing stuff");
247  TIter next(&toDraw);
248  GraphSysErr* g = 0;
249  TH1* f = 0;
250  while ((g = static_cast<GraphSysErr*>(next()))) {
251  TString lOpt(opt); lOpt.Append(" "); lOpt.Append(next.GetOption());
252  MyPrint(Form("%s w/options \"%s\" (%d)",
253  g->GetName(),lOpt.Data(),
254  g->GetSumOption()));
255  g->Draw(lOpt);
256  }
257  delete g4;
258  }
259 
260  c->Modified();
261  c->Update();
262  c->cd();
263  c->SaveAs("QuickDraw.png");
264  gPad = c;
265 }
const char * filename
Definition: TestFCM.C:1
const Double_t ymax
Definition: AddTaskCFDStar.C:7
double Double_t
Definition: External.C:58
void Draw(Option_t *option="")
Definition: GraphSysErr.C:791
void MyDecr()
Definition: QuickDraw.C:14
TSystem * gSystem
Double_t GetErrorXRight(Int_t p) const
Definition: GraphSysErr.C:3627
void SetCommonSumLineColor(Color_t color)
Definition: GraphSysErr.C:4503
TCanvas * c
Definition: TestFitELoss.C:172
~MyGuard()
Definition: QuickDraw.C:27
UInt_t GetSumOption() const
Definition: GraphSysErr.C:3841
void SetCommonSumOption(EDrawOption_t opt)
Definition: GraphSysErr.C:4491
static TSeqCollection * Import(const TString &fileName)
Definition: GraphSysErr.C:2993
Double_t GetErrorXLeft(Int_t p) const
Definition: GraphSysErr.C:3621
int Int_t
Definition: External.C:63
void ProcessCandidates(const TSeqCollection *inp, TList &toDraw)
Definition: QuickDraw.C:48
MyGuard(const char *msg)
Definition: QuickDraw.C:21
void GetMinMax(Option_t *option, Double_t &ymin, Double_t &ymax) const
Definition: GraphSysErr.C:3985
void SetDataOption(EDrawOption_t opt)
Definition: GraphSysErr.C:3586
void AddPath(const TString &dir, Bool_t pre=true)
Definition: QuickDraw.C:32
Definition: External.C:228
void SetSumFillStyle(Style_t style)
Definition: GraphSysErr.C:4485
Int_t GetN() const
Definition: GraphSysErr.C:3609
const char * GetKey(const char *key) const
Definition: GraphSysErr.C:4641
void SetSumOption(EDrawOption_t opt)
Definition: GraphSysErr.C:4449
TString fMsg
Definition: QuickDraw.C:20
void ProcessOne(const TString &filename, TList &toDraw)
Definition: QuickDraw.C:153
TFile * file
TList with histograms for a given trigger.
void ProcessCollection(const TCollection *d, TList &toInspect)
Definition: QuickDraw.C:97
const Double_t ymin
Definition: AddTaskCFDStar.C:6
void ProcessFile(const TString &filename, TList &toDraw)
Definition: QuickDraw.C:85
void ProcessHEPData(const TString &filename, TList &toDraw)
Definition: QuickDraw.C:78
void SetSumFillColor(Color_t color)
Definition: GraphSysErr.C:4479
void QuickDraw()
Definition: QuickDraw.C:161
void SetCommonSumFillStyle(Style_t style)
Definition: GraphSysErr.C:4527
bool Bool_t
Definition: External.C:53
Double_t GetX(Int_t p) const
Definition: GraphSysErr.C:3615
void ProcessFileDirectory(const TDirectory *d, TList &toInspect)
Definition: QuickDraw.C:125
void SetSumLineColor(Color_t color)
Definition: GraphSysErr.C:4461
void SetCommonSumFillColor(Color_t color)
Definition: GraphSysErr.C:4521
void MyIncr()
Definition: QuickDraw.C:10
Definition: External.C:196
TDirectoryFile * dir
void MyPrint(const char *msg)
Definition: QuickDraw.C:5