]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/qaRec/makeResults.C
fix problems in the efficiency plot (Markus)
[u/mrichter/AliRoot.git] / TRD / qaRec / makeResults.C
1 #if ! defined (__CINT__) || defined (__MAKECINT__)
2 #include "TError.h"
3 #include <TClass.h>
4 #include <TFileMerger.h>
5 #include <TCanvas.h>
6 #include <TH1.h>
7 #include <TGraph.h>
8 #include <TObjArray.h>
9 #include <TObjString.h>
10 #include <TPython.h>
11 #include <TString.h>
12 #include <TROOT.h>
13 #include <TSystem.h>
14 #include <TStyle.h>
15
16 #include "qaRec/AliTRDrecoTask.h"
17
18 #endif
19
20 #include "run.h"
21
22 Char_t *libs[] = {"libProofPlayer.so", "libANALYSIS.so", "libTRDqaRec.so", "libPyROOT"};
23
24 void makeResults(Char_t *tasks = "ALL", Char_t* dir=0x0)
25 {
26         // Load Libraries in interactive mode
27   Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
28   for(Int_t ilib=0; ilib<nlibs; ilib++){
29     if(gSystem->Load(libs[ilib]) >= 0) continue;
30     printf("Failed to load %s.\n", libs[ilib]);
31     return;
32   }
33
34
35   gStyle->SetOptStat(0);
36   Bool_t mc      = kTRUE;
37   Bool_t friends = kTRUE;
38
39   // select tasks to process; we should move it to an 
40   // individual function and move the task identifiers 
41   // outside the const space
42   TObjArray *tasksArray = TString(tasks).Tokenize(" ");
43   Int_t fSteerTask = 0;
44   for(Int_t isel = 0; isel < tasksArray->GetEntriesFast(); isel++){
45     TString s = (dynamic_cast<TObjString *>(tasksArray->UncheckedAt(isel)))->String();
46     if(s.CompareTo("ALL") == 0){
47       for(Int_t itask = 1; itask < fknTasks; itask++) SETBIT(fSteerTask, itask);
48       continue;
49     } else if(s.CompareTo("NOFR") == 0){ 
50       friends = kFALSE;
51     } else if(s.CompareTo("NOMC") == 0){ 
52       mc = kFALSE;
53     } else { 
54       Bool_t foundOpt = kFALSE;  
55       for(Int_t itask = 1; itask < fknTasks; itask++){
56         if(s.CompareTo(fTaskOpt[itask]) != 0) continue;
57         SETBIT(fSteerTask, itask);
58         foundOpt = kTRUE;
59         break;
60       }
61       if(!foundOpt) Info("makeResults.C", Form("Task %s not implemented (yet).", s.Data()));
62     }
63   }
64
65
66   // catch the list of files using the ROOT Python Interface
67   TPython *pyshell = new TPython();
68   pyshell->Exec("import commands");
69
70   // file merger object
71   TFileMerger *fFM = new TFileMerger();
72   TClass *ctask = 0x0;
73   TObject *o = 0x0;
74   TObjArray *fContainer = 0x0;
75   AliTRDrecoTask *task = 0x0;
76
77   printf("\n\tPROCESSING DATA FOR TASKS [%d]:\n", fSteerTask);
78   for(Int_t itask = 1; itask <fknTasks; itask++){
79     if(!TESTBIT(fSteerTask, itask)) continue;
80
81     ctask = new TClass(fTaskClass[itask]);
82     task = (AliTRDrecoTask*)ctask->New();
83     task->SetDebugLevel(0);
84     task->SetMCdata(mc);
85     task->SetFriends(friends);
86     printf("\t%s [%s]\n", task->GetTitle(), task->GetName());
87
88      // setup filelist
89     TString pathname(dir ? "." : gSystem->ExpandPathName("$PWD"));
90     TString filestring((const Char_t*) pyshell->Eval(Form("commands.getstatusoutput(\"find %s | grep TRD.Task%s.root\")[1]", pathname.Data(), task->GetName())));
91     TObjArray *filenames = filestring.Tokenize("\n");
92     Int_t nFiles = filenames->GetEntriesFast();
93     if(!nFiles){
94       printf("No Files found for Task %s\n", task->GetName());
95       delete task;
96       delete ctask;
97       continue;
98     }
99
100     if(nFiles>1){
101       fFM = new(fFM) TFileMerger(kTRUE);
102       fFM->OutputFile(Form("merge/TRD.Task%s.root",  task->GetName()));
103       for(Int_t ifile = 0; ifile < nFiles; ifile++){
104         TString filename = (dynamic_cast<TObjString *>(filenames->UncheckedAt(ifile)))->String();
105         if(filename.Contains("merge")) continue;
106         printf("\tProcessing %s ...\n", filename.Data());
107         fFM->AddFile(filename.Data());
108       }
109       fFM->Merge();
110       fFM->~TFileMerger();
111       task->Load(Form("%s/merge/TRD.Task%s.root",gSystem->ExpandPathName("$PWD"), task->GetName()));
112     } else task->Load((dynamic_cast<TObjString *>(filenames->UncheckedAt(0)))->String().Data());
113
114
115     if(!(fContainer = task->Container())) {
116       delete task;
117       delete ctask;
118       continue;
119     } 
120     
121     task->PostProcess();
122     for(Int_t ipic=0; ipic<task->GetNRefFigures(); ipic++){
123       TCanvas *c = new TCanvas("c", "", 500, 500);
124       Int_t ifirst, ilast; Option_t *opt;
125       TH1 *h = 0x0; TGraph *g = 0x0;
126       task->GetRefFigure(ipic, ifirst, ilast, opt);
127       if(!(o = fContainer->At(ifirst))) continue;
128       
129       if(o->InheritsFrom("TH1")){ 
130         h = dynamic_cast<TH1*>(o);
131         h->Draw(opt);
132       } else if(o->InheritsFrom("TGraph")){ 
133         g = dynamic_cast<TGraph*>(o);
134         g->Draw(opt);
135       } else{
136         printf("No idea how to plot object of type %s.\n", o->IsA()->GetName());
137         printf("Please teach me.\n");
138         continue;
139       }
140
141       for(Int_t ig=ifirst+1; ig<ilast; ig++){
142         if(!(o = fContainer->At(ig))) continue;
143         if(o->InheritsFrom("TH1")){
144           h = dynamic_cast<TH1*>(o);
145           h->Draw(Form("%ssame", opt));
146         } else if(o->InheritsFrom("TGraph")){
147           g = dynamic_cast<TGraph*>(o);
148           g->Draw(opt);
149         }
150       }
151       c->SaveAs(Form("%s_fig%d.gif", task->GetName(), ipic));
152       delete c;
153     }
154     delete task;
155     delete ctask;
156   }
157   delete pyshell;
158 }
159