]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/qaRec/makeResults.C
added track covariance matrix (yz plane) to the tracklet
[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 <TPython.h>
43 #include <TString.h>
44 #include <TROOT.h>
45 #include <TSystem.h>
46 #include <TStyle.h>
47
48 #include "qaRec/AliTRDrecoTask.h"
49
50 #endif
51
52 #include "run.h"
53
54 Char_t *libs[] = {"libProofPlayer.so", "libANALYSIS.so", "libTRDqaRec.so", "libPyROOT"};
55
56 void makeResults(Char_t *args = "ALL")
57 {
58         // Load Libraries in interactive mode
59   Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
60   for(Int_t ilib=0; ilib<nlibs; ilib++){
61     if(gSystem->Load(libs[ilib]) >= 0) continue;
62     printf("Failed to load %s.\n", libs[ilib]);
63     return;
64   }
65
66
67   gStyle->SetOptStat(0);
68   Bool_t mc      = kTRUE;
69   Bool_t friends = kTRUE;
70
71   const Char_t *dir = 0x0;
72   TString tasks;
73   TObjArray *argsArray = TString(args).Tokenize("?");
74   switch(argsArray->GetEntriesFast()){
75   case 1:
76     tasks = ((TObjString*)(*argsArray)[0])->String();
77     dir=0x0;
78     break;
79   case 2:
80     tasks = ((TObjString*)(*argsArray)[0])->String();
81     dir = ((TObjString*)(*argsArray)[1])->GetName();
82     break;
83   default:
84     printf("Macro accepts 2 arguments separated by a '?'.\n");
85     printf("arg #1 : list of tasks/options\n");
86     printf("arg #2 : list of files to be processed\n");
87     return;
88   }
89
90   // select tasks to process; we should move it to an 
91   // individual function and move the task identifiers 
92   // outside the const space
93   TObjArray *tasksArray = tasks.Tokenize(" ");
94   Int_t fSteerTask = 0;
95   for(Int_t isel = 0; isel < tasksArray->GetEntriesFast(); isel++){
96     TString s = (dynamic_cast<TObjString *>(tasksArray->UncheckedAt(isel)))->String();
97     if(s.CompareTo("ALL") == 0){
98       for(Int_t itask = 1; itask < NTRDTASKS; itask++) SETBIT(fSteerTask, itask - 1);
99       continue;
100     } else if(s.CompareTo("NOFR") == 0){ 
101       friends = kFALSE;
102     } else if(s.CompareTo("NOMC") == 0){ 
103       mc = kFALSE;
104     } else { 
105       Bool_t foundOpt = kFALSE;  
106       for(Int_t itask = 1; itask < NTRDTASKS; itask++){
107         if(s.CompareTo(fgkTRDtaskOpt[itask]) != 0) continue;
108         SETBIT(fSteerTask, itask - 1);
109         foundOpt = kTRUE;
110         break;
111       }
112       if(!foundOpt) Info("makeResults.C", Form("Task %s not implemented (yet).", s.Data()));
113     }
114   }
115
116   // file merger object
117   TFileMerger *fFM = new TFileMerger();
118   TClass *ctask = 0x0;
119   AliTRDrecoTask *task = 0x0;
120   Int_t nFiles;
121
122   if(gSystem->AccessPathName(Form("%s/merge",  gSystem->ExpandPathName("$PWD")))) gSystem->Exec(Form("mkdir -v %s/merge",  gSystem->ExpandPathName("$PWD")));
123
124   printf("\n\tPROCESSING DATA FOR TASKS [%b]:\n", fSteerTask);
125   for(Int_t itask = 0; itask <NTRDTASKS; itask++){
126     if(!TSTBIT(fSteerTask, itask)) continue;
127
128     ctask = new TClass(fgkTRDtaskClassName[itask]);
129     task = (AliTRDrecoTask*)ctask->New();
130     task->SetDebugLevel(0);
131     task->SetMCdata(mc);
132     task->SetFriends(friends);
133
134      // setup filelist
135     string filename;
136     nFiles = 0;
137     ifstream filestream(dir);
138     while(getline(filestream, filename)){
139       if(Int_t(filename.find(task->GetName())) < 0) continue;
140       if(Int_t(filename.find("merge")) >= 0) continue;
141       nFiles++;
142     }
143     if(!nFiles){
144       printf("No Files found for Task %s\n", task->GetName());
145       delete task;
146       delete ctask;
147       continue;
148     }
149     printf("Processing %d files for task %s ...\n", nFiles, task->GetName());
150
151     ifstream file(dir);
152     if(nFiles>1){
153       fFM = new(fFM) TFileMerger(kTRUE);
154       fFM->OutputFile(Form("%s/merge/TRD.Task%s.root",  gSystem->ExpandPathName("$PWD"), task->GetName()));
155
156       while(getline(file, filename)){
157         if(Int_t(filename.find(task->GetName())) < 0) continue;
158         if(Int_t(filename.find("merge")) >= 0) continue;
159         fFM->AddFile(filename.c_str());
160       }
161       fFM->Merge();
162       fFM->~TFileMerger();
163       task->Load(Form("%s/merge/TRD.Task%s.root", gSystem->ExpandPathName("$PWD"), task->GetName()));
164     } else{
165       getline(file, filename);
166       task->Load(filename.c_str());
167     }
168
169     task->PostProcess();
170     TCanvas *c=new TCanvas();
171     for(Int_t ipic=0; ipic<task->GetNRefFigures(); ipic++){
172       task->GetRefFigure(ipic);
173       c->SaveAs(Form("%s_fig%d.gif", task->GetName(), ipic));
174       c->Clear();
175     }
176     delete c;
177     delete task;
178     delete ctask;
179   }
180 }
181