]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/qaRec/makeResults.C
! MAJOR ! update in the TRD tracking
[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 <fstream>
34 #include "TError.h"
35 #include <TClass.h>
36 #include <TFileMerger.h>
37 #include <TCanvas.h>
38 #include <TH1.h>
39 #include <TGraph.h>
40 #include <TObjArray.h>
41 #include <TObjString.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"};
54
55 void makeResults(Char_t *opt = "ALL", const Char_t *files=0x0)
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   // select tasks to process; we should move it to an 
71   // individual function and move the task identifiers 
72   // outside the const space
73   TString tasks(opt);
74   TObjArray *tasksArray = tasks.Tokenize(" ");
75   Int_t fSteerTask = 0;
76   for(Int_t isel = 0; isel < tasksArray->GetEntriesFast(); isel++){
77     TString s = (dynamic_cast<TObjString *>(tasksArray->UncheckedAt(isel)))->String();
78     if(s.CompareTo("ALL") == 0){
79       for(Int_t itask = 1; itask < NQATASKS; itask++) SETBIT(fSteerTask, itask);
80       continue;
81     } else if(s.CompareTo("NOFR") == 0){ 
82       friends = kFALSE;
83     } else if(s.CompareTo("NOMC") == 0){ 
84       mc = kFALSE;
85     } else { 
86       Bool_t foundOpt = kFALSE;  
87       for(Int_t itask = 1; itask < NTRDTASKS; itask++){
88         if(s.CompareTo(fgkTRDtaskOpt[itask]) != 0) continue;
89         SETBIT(fSteerTask, itask);
90         foundOpt = kTRUE;
91         break;
92       }
93       if(!foundOpt) Info("makeResults.C", Form("Task %s not implemented (yet).", s.Data()));
94     }
95   }
96   // extra rules for calibration tasks
97   if(TSTBIT(fSteerTask, kClErrParam)) SETBIT(fSteerTask, kResolution);
98   if(TSTBIT(fSteerTask, kPIDRefMaker)) SETBIT(fSteerTask, kPIDChecker);
99   if(TSTBIT(fSteerTask, kAlignment)) SETBIT(fSteerTask, kResolution);
100
101   // file merger object
102   TFileMerger *fFM = 0x0;
103   TClass *ctask = new TClass;
104   AliTRDrecoTask *task = 0x0;
105   Int_t nFiles;
106
107   if(gSystem->AccessPathName(Form("%s/merge",  gSystem->ExpandPathName("$PWD")))) gSystem->Exec(Form("mkdir -v %s/merge",  gSystem->ExpandPathName("$PWD")));
108
109   for(Int_t itask = 1; itask<NTRDTASKS; itask++){
110     if(!TSTBIT(fSteerTask, itask)) continue;
111
112     new(ctask) TClass(fgkTRDtaskClassName[itask]);
113     task = (AliTRDrecoTask*)ctask->New();
114     task->SetDebugLevel(0);
115     task->SetMCdata(mc);
116     task->SetFriends(friends);
117
118      // setup filelist
119     nFiles = 0;
120     TString mark(Form("%s.root", task->GetName()));
121     string filename;
122     if(files){
123       ifstream filestream(files);
124       while(getline(filestream, filename)){
125         if(Int_t(filename.find(mark.Data())) < 0) continue;
126         nFiles++;
127       }
128     } else {
129       nFiles = !gSystem->AccessPathName(Form("TRD.Task%s.root", task->GetName()));
130     }
131
132     if(!nFiles){
133       Info("makeResults.C", Form("No Files found for Task %s", task->GetName()));
134       delete task;
135       continue;
136     }
137     Info("makeResults.C", Form("  Processing %d files for task %s ...", nFiles, task->GetName()));
138
139     if(files){
140       fFM = new TFileMerger(kTRUE);
141       fFM->OutputFile(Form("%s/merge/TRD.Task%s.root",  gSystem->ExpandPathName("$PWD"), task->GetName()));
142
143       ifstream file(files);
144       while(getline(file, filename)){
145         if(Int_t(filename.find(mark.Data())) < 0) continue;
146         fFM->AddFile(filename.c_str());
147       }
148       fFM->Merge();
149       delete fFM;
150       if(!task->Load(Form("%s/merge/TRD.Task%s.root", gSystem->ExpandPathName("$PWD"), task->GetName()))){
151         delete task;
152         break;
153       }
154     } else{
155       if(!task->Load(Form("%s/TRD.Task%s.root", gSystem->ExpandPathName("$PWD"), task->GetName()))){
156         delete task;
157         break;
158       }
159     }
160
161     printf("Processing ...\n");
162     task->PostProcess();
163     TCanvas *c=new TCanvas();
164     for(Int_t ipic=0; ipic<task->GetNRefFigures(); ipic++){
165       if(!task->GetRefFigure(ipic)) continue;
166       c->SaveAs(Form("%s_fig%d.gif", task->GetName(), ipic));
167       c->Clear();
168     }
169     delete c;
170     delete task;
171   }
172   delete ctask;
173 }
174