]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/qaRec/makeResults.C
continue Visualization-QA integration with the check Detector task
[u/mrichter/AliRoot.git] / TRD / qaRec / makeResults.C
1 // Usage:
2 //   makeResults.C("tasks?file_list")
3 //   tasks : "ALL" or one/more of the following separated by space:
4 //     "EFF"  : TRD Tracking Efficiency 
5 //     "EFFC" : TRD Tracking Efficiency Combined (barrel + stand alone) - only in case of simulations
6 //     "RES"  : TRD tracking Resolution
7 //     "CAL"  : TRD calibration
8 //     "PID"  : TRD PID - pion efficiency 
9 //     "PIDR" : TRD PID - reference data
10 //     "DET"  : Basic TRD Detector checks
11 //     "NOFR" : Data set does not have AliESDfriends.root 
12 //     "NOMC" : Data set does not have Monte Carlo Informations (real data), so all tasks which rely
13 //              on MC information are switched off
14 //   file_list : is the list of the files to be processed. 
15 //     They should contain the full path. Here is an example:
16 // /lustre_alpha/alice/TRDdata/HEAD/1.0GeV/RUN0/TRD.TaskResolution.root
17 // /lustre_alpha/alice/TRDdata/HEAD/2.0GeV/RUN1/TRD.TaskResolution.root
18 // /lustre_alpha/alice/TRDdata/HEAD/3.0GeV/RUN2/TRD.TaskResolution.root
19 // /lustre_alpha/alice/TRDdata/HEAD/2.0GeV/RUN0/TRD.TaskDetChecker.root
20 // /lustre_alpha/alice/TRDdata/HEAD/2.0GeV/RUN1/TRD.TaskDetChecker.root
21 // /lustre_alpha/alice/TRDdata/HEAD/2.0GeV/RUN2/TRD.TaskDetChecker.root
22 // /lustre_alpha/alice/TRDdata/HEAD/2.0GeV/RUN0/TRD.TaskTrackingEff.root
23 //
24 // The files which will be processed are the initersaction between the 
25 // condition on the tasks and the files iin the file list.  
26 //
27 // Authors:
28 //   Alex Bercuci (A.Bercuci@gsi.de) 
29 //   Markus Fasel (m.Fasel@gsi.de) 
30 //
31
32 #if ! defined (__CINT__) || defined (__MAKECINT__)
33 #include "TError.h"
34 #include <TClass.h>
35 #include <TFileMerger.h>
36 #include <TCanvas.h>
37 #include <TH1.h>
38 #include <TGraph.h>
39 #include <TObjArray.h>
40 #include <TObjString.h>
41 #include <TPython.h>
42 #include <TString.h>
43 #include <TROOT.h>
44 #include <TSystem.h>
45 #include <TStyle.h>
46
47 #include "qaRec/AliTRDrecoTask.h"
48
49 #endif
50
51 #include "run.h"
52
53 Char_t *libs[] = {"libProofPlayer.so", "libANALYSIS.so", "libTRDqaRec.so", "libPyROOT"};
54
55 void makeResults(Char_t *args = "ALL")
56 {
57         // Load Libraries in interactive mode
58   Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
59   for(Int_t ilib=0; ilib<nlibs; ilib++){
60     if(gSystem->Load(libs[ilib]) >= 0) continue;
61     printf("Failed to load %s.\n", libs[ilib]);
62     return;
63   }
64
65
66   gStyle->SetOptStat(0);
67   Bool_t mc      = kTRUE;
68   Bool_t friends = kTRUE;
69
70   Char_t *dir = 0x0;
71   TString tasks;
72   TObjArray *argsArray = TString(args).Tokenize("?");
73   switch(argsArray->GetEntriesFast()){
74   case 1:
75     tasks = ((TObjString*)(*argsArray)[0])->String();
76     dir=0x0;
77     break;
78   case 2:
79     tasks = ((TObjString*)(*argsArray)[0])->String();
80     dir = ((TObjString*)(*argsArray)[1])->GetName();
81     break;
82   default:
83     printf("Macro accepts 2 arguments separated by a '?'.\n");
84     printf("arg #1 : list of tasks/options\n");
85     printf("arg #2 : list of files to be processed\n");
86     return;
87   }
88
89   // select tasks to process; we should move it to an 
90   // individual function and move the task identifiers 
91   // outside the const space
92   TObjArray *tasksArray = tasks.Tokenize(" ");
93   Int_t fSteerTask = 0;
94   for(Int_t isel = 0; isel < tasksArray->GetEntriesFast(); isel++){
95     TString s = (dynamic_cast<TObjString *>(tasksArray->UncheckedAt(isel)))->String();
96     if(s.CompareTo("ALL") == 0){
97       for(Int_t itask = 1; itask < NTRDTASKS; itask++) SETBIT(fSteerTask, itask);
98       continue;
99     } else if(s.CompareTo("NOFR") == 0){ 
100       friends = kFALSE;
101     } else if(s.CompareTo("NOMC") == 0){ 
102       mc = kFALSE;
103     } else { 
104       Bool_t foundOpt = kFALSE;  
105       for(Int_t itask = 1; itask < NTRDTASKS; itask++){
106         if(s.CompareTo(fgkTRDtaskOpt[itask]) != 0) continue;
107         SETBIT(fSteerTask, itask);
108         foundOpt = kTRUE;
109         break;
110       }
111       if(!foundOpt) Info("makeResults.C", Form("Task %s not implemented (yet).", s.Data()));
112     }
113   }
114
115   // file merger object
116   TFileMerger *fFM = new TFileMerger();
117   TClass *ctask = 0x0;
118   TObject *o = 0x0;
119   TObjArray *fContainer = 0x0;
120   AliTRDrecoTask *task = 0x0;
121   Int_t nFiles;
122
123   if(gSystem->AccessPathName(Form("%s/merge",  gSystem->ExpandPathName("$PWD")))) gSystem->Exec(Form("mkdir -v %s/merge",  gSystem->ExpandPathName("$PWD")));
124
125   printf("\n\tPROCESSING DATA FOR TASKS [%b]:\n", fSteerTask);
126   for(Int_t itask = 1; itask <NTRDTASKS; itask++){
127     if(!TESTBIT(fSteerTask, itask)) continue;
128
129     ctask = new TClass(fgkTRDtaskClassName[itask]);
130     task = (AliTRDrecoTask*)ctask->New();
131     task->SetDebugLevel(0);
132     task->SetMCdata(mc);
133     task->SetFriends(friends);
134
135      // setup filelist
136     string filename;
137     nFiles = 0;
138     ifstream filestream(dir);
139     while(getline(filestream, filename)){
140       if(Int_t(filename.find(task->GetName())) < 0) continue;
141       if(Int_t(filename.find("merge")) >= 0) continue;
142       nFiles++;
143     }
144     if(!nFiles){
145       printf("No Files found for Task %s\n", task->GetName());
146       delete task;
147       delete ctask;
148       continue;
149     }
150     printf("Processing %d files for task %s ...\n", nFiles, task->GetName());
151
152     ifstream filestream(dir);
153     if(nFiles>1){
154       fFM = new(fFM) TFileMerger(kTRUE);
155       fFM->OutputFile(Form("%s/merge/TRD.Task%s.root",  gSystem->ExpandPathName("$PWD"), task->GetName()));
156
157       while(getline(filestream, filename)){
158         if(Int_t(filename.find(task->GetName())) < 0) continue;
159         if(Int_t(filename.find("merge")) >= 0) continue;
160         fFM->AddFile(filename.c_str());
161       }
162       fFM->Merge();
163       fFM->~TFileMerger();
164       task->Load(Form("%s/merge/TRD.Task%s.root", gSystem->ExpandPathName("$PWD"), task->GetName()));
165     } else{
166       getline(filestream, filename);
167       task->Load(filename.c_str());
168     }
169
170     task->PostProcess();
171     TCanvas *c=new TCanvas();
172     for(Int_t ipic=0; ipic<task->GetNRefFigures(); ipic++){
173       task->GetRefFigure(ipic);
174       c->SaveAs(Form("%s_fig%d.gif", task->GetName(), ipic));
175       c->Clear();
176     }
177     delete c;
178     delete task;
179     delete ctask;
180   }
181 }
182