]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/qaRec/makeResults.C
rename constant kNTimeBins to kNclusters to reflect its true meaning
[u/mrichter/AliRoot.git] / TRD / qaRec / makeResults.C
1 // Usage:
2 //   makeResults.C("tasks", "file_list", kGRID)
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 // or for GRID alien:///alice/cern.ch/user/m/mfasel/MinBiasProd/results/ppMinBias80000/1/TRD.TaskDetChecker.root
18 //   kGRID : specify if files are comming from a GRID collection [default kFALSE]
19 //
20 // HOW TO BUILD THE FILE LIST
21 //   1. locally
22 // ls -1 BaseDir/TRD.Task*.root > files.lst
23 // 
24 //   2. on Grid
25 // char *BaseDir="/alice/cern.ch/user/m/mfasel/MinBiasProd/results/ppMinBias80000/";
26 // TGrid::Connect("alien://");
27 // TGridResult *res = gGrid->Query(BaseDir, "%/TRD.Task%.root");
28 // TGridCollection *col = gGrid->OpenCollectionQuery(res);
29 // col->Reset();
30 // TMap *map = 0x0;
31 // while(map = (TMap*)col->Next()){
32 //   TIter it((TCollection*)map);
33 //   TObjString *info = 0x0;
34 //   while(info=(TObjString*)it()){
35 //     printf("alien://%s\n", col->GetLFN(info->GetString().Data()));
36 //   }
37 // }
38 //
39 // The files which will be processed are the intersection between the
40 // condition on the tasks and the files in the file list.
41 //
42 // Authors:
43 //   Alex Bercuci (A.Bercuci@gsi.de) 
44 //   Markus Fasel (m.Fasel@gsi.de) 
45 //
46
47 #if ! defined (__CINT__) || defined (__MAKECINT__)
48 #include <fstream>
49 #include "TError.h"
50 #include <TClass.h>
51 #include <TFileMerger.h>
52 #include <TCanvas.h>
53 #include <TH1.h>
54 #include <TGraph.h>
55 #include <TObjArray.h>
56 #include <TObjString.h>
57 #include <TString.h>
58 #include <TROOT.h>
59 #include <TSystem.h>
60 #include <TStyle.h>
61
62 #include "qaRec/AliTRDrecoTask.h"
63
64 #endif
65
66 #include "run.h"
67
68 Char_t *libs[] = {"libProofPlayer.so", "libANALYSIS.so", "libTRDqaRec.so"};
69
70 void makeResults(Char_t *opt = "ALL", const Char_t *files=0x0, Bool_t kGRID=kFALSE)
71 {
72   if(kGRID){
73     if(!gSystem->Getenv("GSHELL_ROOT")){
74       printf("alien not initialized.\n");
75       return;
76     }
77     TGrid::Connect("alien://");
78   }
79
80         // Load Libraries in interactive mode
81   Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
82   for(Int_t ilib=0; ilib<nlibs; ilib++){
83     if(gSystem->Load(libs[ilib]) >= 0) continue;
84     printf("Failed to load %s.\n", libs[ilib]);
85     return;
86   }
87
88
89   gStyle->SetOptStat(0);
90   Bool_t mc      = kTRUE;
91   Bool_t friends = kTRUE;
92
93   // select tasks to process; we should move it to an 
94   // individual function and move the task identifiers 
95   // outside the const space
96   TString tasks(opt);
97   TObjArray *tasksArray = tasks.Tokenize(" ");
98   Int_t fSteerTask = 0;
99   for(Int_t isel = 0; isel < tasksArray->GetEntriesFast(); isel++){
100     TString s = (dynamic_cast<TObjString *>(tasksArray->UncheckedAt(isel)))->String();
101     if(s.CompareTo("ALL") == 0){
102       for(Int_t itask = 1; itask < NQATASKS; itask++) SETBIT(fSteerTask, itask);
103       continue;
104     } else if(s.CompareTo("NOFR") == 0){ 
105       friends = kFALSE;
106     } else if(s.CompareTo("NOMC") == 0){ 
107       mc = kFALSE;
108     } else { 
109       Bool_t foundOpt = kFALSE;  
110       for(Int_t itask = 1; itask < NTRDTASKS; itask++){
111         if(s.CompareTo(fgkTRDtaskOpt[itask]) != 0) continue;
112         SETBIT(fSteerTask, itask);
113         foundOpt = kTRUE;
114         break;
115       }
116       if(!foundOpt) Info("makeResults.C", Form("Task %s not implemented (yet).", s.Data()));
117     }
118   }
119   // extra rules for calibration tasks
120   if(TSTBIT(fSteerTask, kClErrParam)) SETBIT(fSteerTask, kResolution);
121   if(TSTBIT(fSteerTask, kPIDRefMaker)) SETBIT(fSteerTask, kPIDChecker);
122   if(TSTBIT(fSteerTask, kAlignment)) SETBIT(fSteerTask, kResolution);
123
124   // file merger object
125   TFileMerger *fFM = 0x0;
126   TClass *ctask = new TClass;
127   AliTRDrecoTask *task = 0x0;
128   Int_t nFiles;
129
130   if(gSystem->AccessPathName(Form("%s/merge",  gSystem->ExpandPathName("$PWD")))) gSystem->Exec(Form("mkdir -v %s/merge",  gSystem->ExpandPathName("$PWD")));
131
132   for(Int_t itask = 1; itask<NTRDTASKS; itask++){
133     if(!TSTBIT(fSteerTask, itask)) continue;
134
135     new(ctask) TClass(fgkTRDtaskClassName[itask]);
136     task = (AliTRDrecoTask*)ctask->New();
137     task->SetDebugLevel(0);
138     task->SetMCdata(mc);
139     task->SetFriends(friends);
140
141      // setup filelist
142     nFiles = 0;
143     TString mark(Form("%s.root", task->GetName()));
144     string filename;
145     if(files){
146       ifstream filestream(files);
147       while(getline(filestream, filename)){
148         if(Int_t(filename.find(mark.Data())) < 0) continue;
149         nFiles++;
150       }
151     } else {
152       nFiles = !gSystem->AccessPathName(Form("TRD.Task%s.root", task->GetName()));
153     }
154
155     if(!nFiles){
156       Info("makeResults.C", Form("No Files found for Task %s", task->GetName()));
157       delete task;
158       continue;
159     }
160     Info("makeResults.C", Form("  Processing %d files for task %s ...", nFiles, task->GetName()));
161
162     if(files){
163       fFM = new TFileMerger(kTRUE);
164       fFM->OutputFile(Form("%s/merge/TRD.Task%s.root",  gSystem->ExpandPathName("$PWD"), task->GetName()));
165
166       ifstream file(files);
167       while(getline(file, filename)){
168         if(Int_t(filename.find(mark.Data())) < 0) continue;
169         fFM->AddFile(filename.c_str());
170       }
171       fFM->Merge();
172       delete fFM;
173       if(!task->Load(Form("%s/merge/TRD.Task%s.root", gSystem->ExpandPathName("$PWD"), task->GetName()))){
174         delete task;
175         break;
176       }
177     } else{
178       if(!task->Load(Form("%s/TRD.Task%s.root", gSystem->ExpandPathName("$PWD"), task->GetName()))){
179         delete task;
180         break;
181       }
182     }
183
184     printf("Processing ...\n");
185     task->PostProcess();
186     TCanvas *c=new TCanvas();
187     for(Int_t ipic=0; ipic<task->GetNRefFigures(); ipic++){
188       if(!task->GetRefFigure(ipic)) continue;
189       c->SaveAs(Form("%s_fig%d.gif", task->GetName(), ipic));
190       c->Clear();
191     }
192     delete c;
193     delete task;
194   }
195   delete ctask;
196 }
197