]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/TRD/macros/makeResults.C
add global monitor histo in task infoGen
[u/mrichter/AliRoot.git] / PWG1 / TRD / macros / makeResults.C
1 // Usage:
2 //   makeResults.C("tasks", "file_list", ""task_id, 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 //     "PID"  : TRD PID - pion efficiency 
8 //     "DET"  : Basic TRD Detector checks
9 //     "NOFR" : Data set does not have AliESDfriends.root 
10 //     "NOMC" : Data set does not have Monte Carlo Informations (real data), so all tasks which rely
11 //              on MC information are switched off
12 //   file_list : is the list of the files to be processed. 
13 //     They should contain the full path. Here is an example:
14 // /lustre/alice/local/TRDdata/SIM/P-Flat/TRUNK/RUN0/TRD.Performance.root
15 // or for GRID alien:///alice/cern.ch/user/m/mfasel/MinBiasProd/results/ppMinBias80000/1/TRD.Performance.root
16 //   task_id : identifier of task speciality as defined by the AddMacro.C. 
17 //             (e.g. AddTRDresolution.C defines "" for barrel tracks, "K" for kink tracks and "SA" for stand alone tracks)
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/RUN*/TRD.Performance.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.Performance.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 <TCanvas.h>
52 #include <TH1.h>
53 #include <TGraph.h>
54 #include <TObjArray.h>
55 #include <TObjString.h>
56 #include <TString.h>
57 #include <TROOT.h>
58 #include <TStyle.h>
59 #include <TGrid.h>
60 #include <TGridResult.h>
61 #include <TGridCollection.h>
62
63 #include "AliLog.h"
64
65 #include "PWG1/TRD/AliTRDrecoTask.h"
66 #include "PWG1/TRD/AliTRDcheckESD.h"
67
68 #endif
69
70 #include "AliTRDperformanceTrain.h"
71 #include "helper.C"
72 //#include "../../PWG1/macros/AddPerformanceTask.h"
73
74 Char_t *libs[] = {"libProofPlayer.so", "libANALYSIS.so", "libANALYSISalice.so", "libTENDER.so", "libPWG1.so"};
75 // define setup
76 TCanvas *c = 0x0;
77 Bool_t mc(kFALSE), friends(kFALSE);
78 Bool_t summary(kTRUE);
79
80 void processTRD(TNamed* task, const Char_t *filename);
81 void processESD(TNamed* task, const Char_t *filename);
82 void makeResults(Char_t *opt = "ALL", const Char_t *files="QAResults.root", Char_t *cid = "", Bool_t kGRID=kFALSE, Bool_t dosummary = kTRUE)
83 {
84   if(kGRID){
85     if(!gSystem->Getenv("GSHELL_ROOT")){
86       Error("makeResults.C", "AliEn not initialized.");
87       return;
88     }
89     TGrid::Connect("alien://");
90   }
91
92         // Load Libraries in interactive mode
93   Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
94   for(Int_t ilib=0; ilib<nlibs; ilib++){
95     if(gSystem->Load(libs[ilib]) >= 0) continue;
96     Error("makeResults.C", Form("Failed to load %s.", libs[ilib]));
97     return;
98   }
99
100   mc = HasReadMCData(opt);
101   friends = HasReadFriendData(opt);
102
103   gStyle->SetOptStat(0);
104   gStyle->SetOptFit(0);
105   TString outputFile;
106   if(!TString(files).EndsWith(".root")){ 
107     outputFile = Form("%s/QAResults.root", gSystem->ExpandPathName("$PWD"));
108     mergeProd("QAResults.root", files);
109   } else {
110     outputFile = files;
111   }
112   Int_t fSteerTask = ParseOptions(opt);
113
114   if(!dosummary){
115     summary = kFALSE;
116     if(!c) c=new TCanvas("c", "Performance", 10, 10, 800, 500);
117   }
118
119   TClass *ctask = new TClass;
120   AliAnalysisTask *task = 0x0;
121   for(Int_t itask = NTRDQATASKS; itask--;){
122     if(!TSTBIT(fSteerTask, itask)) continue;
123     new(ctask) TClass(fgkTRDtaskClassName[itask]);
124     task = (AliAnalysisTask*)ctask->New();
125     task->SetName(Form("%s%s", task->GetName(), cid));
126     printf(" *** task %s, output file %s\n", task->GetName(), outputFile.Data());
127     if(task->IsA()->InheritsFrom("AliTRDrecoTask")) processTRD(task, outputFile.Data());
128     else if(strcmp(task->IsA()->GetName(), "AliTRDcheckESD")==0) processESD(task, outputFile.Data());
129     else if(strcmp(task->IsA()->GetName(), "AliTRDinfoGen")==0)processGEN(task, outputFile.Data());
130     else{
131       Error("makeResults.C", Form("Handling of class task \"%s\" not implemented.", task->IsA()->GetName()));
132       delete task;
133     }
134   }
135   delete ctask;
136   delete c;
137 }
138
139
140 //______________________________________________________
141 void processTRD(TNamed *otask, const Char_t *filename)
142 {
143   printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
144   Int_t debug(0);
145   AliTRDrecoTask *task = dynamic_cast<AliTRDrecoTask*>(otask);
146   task->SetDebugLevel(debug);
147   AliLog::SetClassDebugLevel(otask->IsA()->GetName(), debug);
148   task->SetMCdata(mc);
149   task->SetFriends(friends);
150
151   //if(!task->Load(Form("%s/AnalysisResults.root", gSystem->ExpandPathName("$PWD")))){
152   if(!task->Load(filename)){
153     Error("makeResults.C", Form("Load data container for task %s failed.", task->GetName()));
154     delete task;
155     return;
156   }
157
158   if(!task->PostProcess()){
159     Error("makeResults.C", Form("Processing data container for task %s failed.", task->GetName()));
160     delete task;
161     return;
162   }
163   if(summary) task->MakeSummary();
164   else{
165     for(Int_t ipic=0; ipic<task->GetNRefFigures(); ipic++){
166       c->Clear();
167       if(!task->GetRefFigure(ipic)) continue;
168       c->SaveAs(Form("%s_Fig%02d.gif", task->GetName(), ipic), "gif");
169     }
170   }
171   delete task;
172 }
173
174 //______________________________________________________
175 void processESD(TNamed *otask, const Char_t *filename)
176 {
177   printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
178
179   AliTRDcheckESD *esd = dynamic_cast<AliTRDcheckESD*>(otask);
180   if(!esd){
181     Info("makeResults.C", Form("Processing of task %s failed.", otask->GetName()));
182     delete otask;
183     return;
184   }
185   //if(!esd->Load(Form("%s/AnalysisResults.root", gSystem->ExpandPathName("$PWD")), "TRD_Performance")){
186   if(!esd->Load(filename, "TRD_Performance")){
187     Error("makeResults.C", Form("Load data container for task %s failed.", esd->GetName()));
188     delete esd;
189     return;
190   }
191   esd->Terminate(NULL);
192   
193   if(summary) esd->MakeSummary();
194   else{
195     for(Int_t ipic(0); ipic<esd->GetNRefFigures(); ipic++){
196       c->Clear(); 
197       if(!esd->GetRefFigure(ipic)) continue;
198       c->SaveAs(Form("%s_Fig%02d.gif", esd->GetName(), ipic));
199     }
200   }
201   delete esd;
202 }
203
204 //______________________________________________________
205 void processGEN(TNamed *otask, const Char_t *filename)
206 {
207   printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
208
209   AliTRDinfoGen *info = dynamic_cast<AliTRDinfoGen*>(otask);
210
211   if(!info->Load(filename, "TRD_Performance")){
212     Error("makeResults.C", Form("Load data container for task %s failed.", info->GetName()));
213     delete info;
214     return;
215   }
216   if(!summary){
217     for(Int_t ipic(0); ipic<info->GetNRefFigures(); ipic++){
218       c->Clear(); 
219       if(!info->GetRefFigure(ipic)) continue;
220       c->SaveAs(Form("%s_Fig%02d.gif", info->GetName(), ipic));
221     }
222   }
223
224   delete info;
225 }