]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/TRD/macros/makeResults.C
152d9a3cbfbb40a7656d3ff2bd34f9f52f54ac61
[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 Char_t *libs[] = {"libProofPlayer.so", "libANALYSIS.so", "libANALYSISalice.so", "libTENDER.so", "libPWG1.so"};
71 // define setup
72 TCanvas *c = 0x0;
73 Bool_t mc(kFALSE), friends(kFALSE);
74 Bool_t summary(kTRUE);
75
76 void processTRD(TNamed* task, const Char_t *filename);
77 void processESD(TNamed* task, const Char_t *filename);
78 void makeResults(Char_t *opt = "ALL", const Char_t *files="QAResults.root", Char_t *cid = "", Bool_t kGRID=kFALSE, Bool_t dosummary = kTRUE)
79 {
80   if(kGRID){
81     if(!gSystem->Getenv("GSHELL_ROOT")){
82       Error("makeResults.C", "AliEn not initialized.");
83       return;
84     }
85     TGrid::Connect("alien://");
86   }
87
88         // Load Libraries in interactive mode
89   Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
90   for(Int_t ilib=0; ilib<nlibs; ilib++){
91     if(gSystem->Load(libs[ilib]) >= 0) continue;
92     Error("makeResults.C", Form("Failed to load %s.", libs[ilib]));
93     return;
94   }
95
96   mc      = AliTRDpwg1Helper::HasReadMCData(opt);
97   friends = AliTRDpwg1Helper::HasReadFriendData(opt);
98
99   gStyle->SetOptStat(0);
100   gStyle->SetOptFit(0);
101   TString outputFile;
102   if(!TString(files).EndsWith(".root")){ 
103     outputFile = Form("%s/QAResults.root", gSystem->ExpandPathName("$PWD"));
104     AliTRDpwg1Helper::MergeProd("QAResults.root", files);
105   } else {
106     outputFile = files;
107   }
108   Int_t fSteerTask = AliTRDpwg1Helper::ParseOptions(opt);
109
110   if(!dosummary){
111     summary = kFALSE;
112     if(!c) c=new TCanvas("c", "Performance", 10, 10, 800, 500);
113   }
114
115   TClass *ctask = new TClass;
116   AliAnalysisTask *task = 0x0;
117   for(Int_t itask = AliTRDpwg1Helper::kNTRDQATASKS; itask--;){
118     if(!TESTBIT(fSteerTask, itask)) continue;
119     new(ctask) TClass(AliTRDpwg1Helper::fgkTRDtaskClassName[itask]);
120     task = (AliAnalysisTask*)ctask->New();
121     task->SetName(Form("%s%s", task->GetName(), cid));
122     printf(" *** task %s, output file %s\n", task->GetName(), outputFile.Data());
123     if(task->IsA()->InheritsFrom("AliTRDrecoTask")) processTRD(task, outputFile.Data());
124     else if(strcmp(task->IsA()->GetName(), "AliTRDcheckESD")==0) processESD(task, outputFile.Data());
125     else if(strcmp(task->IsA()->GetName(), "AliTRDinfoGen")==0)processGEN(task, outputFile.Data());
126     else{
127       Error("makeResults.C", Form("Handling of class task \"%s\" not implemented.", task->IsA()->GetName()));
128       delete task;
129     }
130   }
131   delete ctask;
132   delete c;
133 }
134
135
136 //______________________________________________________
137 void processTRD(TNamed *otask, const Char_t *filename)
138 {
139   printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
140   Int_t debug(0);
141   AliTRDrecoTask *task = dynamic_cast<AliTRDrecoTask*>(otask);
142   task->SetDebugLevel(debug);
143   AliLog::SetClassDebugLevel(otask->IsA()->GetName(), debug);
144   task->SetMCdata(mc);
145   task->SetFriends(friends);
146
147   //if(!task->Load(Form("%s/AnalysisResults.root", gSystem->ExpandPathName("$PWD")))){
148   if(!task->Load(filename)){
149     Error("makeResults.C", Form("Load data container for task %s failed.", task->GetName()));
150     delete task;
151     return;
152   }
153
154   if(!task->PostProcess()){
155     Error("makeResults.C", Form("Processing data container for task %s failed.", task->GetName()));
156     delete task;
157     return;
158   }
159   if(summary) task->MakeSummary();
160   else{
161     for(Int_t ipic=0; ipic<task->GetNRefFigures(); ipic++){
162       c->Clear();
163       if(!task->GetRefFigure(ipic)) continue;
164       c->SaveAs(Form("%s_Fig%02d.gif", task->GetName(), ipic), "gif");
165     }
166   }
167   delete task;
168 }
169
170 //______________________________________________________
171 void processESD(TNamed *otask, const Char_t *filename)
172 {
173   printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
174
175   AliTRDcheckESD *esd = dynamic_cast<AliTRDcheckESD*>(otask);
176   if(!esd){
177     Info("makeResults.C", Form("Processing of task %s failed.", otask->GetName()));
178     delete otask;
179     return;
180   }
181   //if(!esd->Load(Form("%s/AnalysisResults.root", gSystem->ExpandPathName("$PWD")), "TRD_Performance")){
182   if(!esd->Load(filename, "TRD_Performance")){
183     Error("makeResults.C", Form("Load data container for task %s failed.", esd->GetName()));
184     delete esd;
185     return;
186   }
187   esd->Terminate(NULL);
188   
189   if(summary) esd->MakeSummary();
190   else{
191     for(Int_t ipic(0); ipic<esd->GetNRefFigures(); ipic++){
192       c->Clear(); 
193       if(!esd->GetRefFigure(ipic)) continue;
194       c->SaveAs(Form("%s_Fig%02d.gif", esd->GetName(), ipic));
195     }
196   }
197   delete esd;
198 }
199
200 //______________________________________________________
201 void processGEN(TNamed *otask, const Char_t *filename)
202 {
203   printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
204
205   AliTRDinfoGen *info = dynamic_cast<AliTRDinfoGen*>(otask);
206
207   if(!info->Load(filename, "TRD_Performance")){
208     Error("makeResults.C", Form("Load data container for task %s failed.", info->GetName()));
209     delete info;
210     return;
211   }
212   if(!summary){
213     for(Int_t ipic(0); ipic<info->GetNRefFigures(); ipic++){
214       c->Clear(); 
215       if(!info->GetRefFigure(ipic)) continue;
216       c->SaveAs(Form("%s_Fig%02d.gif", info->GetName(), ipic));
217     }
218   }
219
220   delete info;
221 }