]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/TRD/macros/makeResults.C
8f402344a59a45d2e707168eaf902dba11a04221
[u/mrichter/AliRoot.git] / PWGPP / 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 //
43 // In compiled mode :
44 // Don't forget to load first the libraries
45 // gSystem->Load("libANALYSIS")
46 // gSystem->Load("libANALYSISalice")
47 // gSystem->Load("libTender");
48 // gSystem->Load("libPWGPP");
49 // gSystem->Load("libCORRFW");
50 // gSystem->Load("libPWGmuon");
51 // gSystem->Load("libNetx") ;
52 // gSystem->Load("libRAliEn");
53
54 // Authors:
55 //   Alex Bercuci (A.Bercuci@gsi.de)
56 //   Markus Fasel (m.Fasel@gsi.de)
57 //
58
59 #if ! defined (__CINT__) || defined (__MAKECINT__)
60 #include <fstream>
61 #include "TError.h"
62 #include <TClass.h>
63 #include <TCanvas.h>
64 #include <TH1.h>
65 #include <TGraph.h>
66 #include <TObjArray.h>
67 #include <TObjString.h>
68 #include <TString.h>
69 #include <TROOT.h>
70 #include <TStyle.h>
71 #include <TSystem.h>
72 #include <TGrid.h>
73 #include <TGridResult.h>
74 #include <TGridCollection.h>
75
76 #include "AliLog.h"
77
78 #include "PWGPP/TRD/info/AliTRDtrendingManager.h"
79 #include "PWGPP/TRD/AliTRDpwgppHelper.h"
80 #include "PWGPP/TRD/AliTRDrecoTask.h"
81 #include "PWGPP/TRD/AliTRDcheckESD.h"
82 #include "PWGPP/TRD/AliTRDinfoGen.h"
83 #endif
84
85 const Char_t *libs[] = {"libProofPlayer", "libANALYSIS", "libANALYSISalice", "libCORRFW", "libTender", "libPWGPP", "libPWGmuon"};
86 // define setup
87 TCanvas *c(NULL);
88 Bool_t mc(kFALSE), friends(kFALSE);
89 Bool_t summary(kTRUE);
90
91 void processTRD(TNamed* task, const Char_t *filename);
92 void processESD(TNamed* task, const Char_t *filename);
93 void processGEN(TNamed* task, const Char_t *filename);
94 void makeSummaryESD(const Char_t* filename="QAresults.root", 
95                     Double_t* trendValues=0x0, 
96                     Bool_t useCF=kTRUE, 
97                     Bool_t useIsolatedBC=kFALSE, 
98                     Bool_t cutTOFbc=kFALSE, 
99                     const Char_t* dir="TRD_Performance", 
100                     Bool_t isGrid=kFALSE);
101 void makeResults(const Char_t *opt = "ALL",
102                  const Char_t *files="QAresults.root",
103                  const Char_t *cid = "",
104                  Bool_t kGRID=kFALSE, Bool_t dosummary = kTRUE)
105 {
106   if(kGRID) TGrid::Connect("alien://");
107
108   // Load Libraries in interactive mode
109   Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
110   for(Int_t ilib=0; ilib<nlibs; ilib++){
111     if(gSystem->Load(libs[ilib]) >= 0) continue;
112     Error("makeResults.C", "Failed to load %s.", libs[ilib]);
113     return;
114   }
115
116   mc      = AliTRDpwgppHelper::HasReadMCData(opt);
117   friends = AliTRDpwgppHelper::HasReadFriendData(opt);
118
119   gStyle->SetOptStat(0);
120   gStyle->SetOptFit(0);
121   TString outputFile;
122   if(!TString(files).EndsWith(".root")){
123     outputFile = Form("%s/QAResults.root", gSystem->ExpandPathName("$PWD"));
124     AliTRDpwgppHelper::MergeProd("QAResults.root", files);
125   } else {
126     outputFile = files;
127   }
128   Int_t fSteerTask = AliTRDpwgppHelper::ParseOptions(opt);
129
130   if(!dosummary){
131     summary = kFALSE;
132     if(!c) c=new TCanvas("c", "Performance", 10, 10, 800, 500);
133   }
134
135   TClass *ctask = new TClass;
136   AliAnalysisTask *task = NULL;
137   for(Int_t itask = AliTRDpwgppHelper::kNTRDQATASKS; itask--;){
138     if(!AliTRDpwgppHelper::DoTask(itask, fSteerTask)) continue;
139     new(ctask) TClass(AliTRDpwgppHelper::TaskClassName(itask));
140     task = (AliAnalysisTask*)ctask->New();
141     task->SetName(Form("%s%s", task->GetName(), cid));
142     printf(" *** task %s, output file %s\n", task->GetName(), outputFile.Data());
143     if(task->IsA()->InheritsFrom("AliTRDrecoTask")) processTRD(task, outputFile.Data());
144     else if(strcmp(task->IsA()->GetName(), "AliTRDcheckESD")==0) processESD(task, outputFile.Data());
145     else if(strcmp(task->IsA()->GetName(), "AliTRDinfoGen")==0) processGEN(task, outputFile.Data());
146     else{
147       Error("makeResults.C", "Handling of class task \"%s\" not implemented.", task->IsA()->GetName());
148       delete task;
149     }
150   }
151   delete ctask;
152   delete c;
153   // write trending summary
154   AliTRDtrendingManager::Instance()->Terminate();
155 }
156
157
158 //______________________________________________________
159 void processTRD(TNamed *otask, const Char_t *filename)
160 {
161   printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
162   Int_t debug(0);
163   AliTRDrecoTask *task = dynamic_cast<AliTRDrecoTask*>(otask);
164   task->SetDebugLevel(debug);
165   AliLog::SetClassDebugLevel(otask->IsA()->GetName(), debug);
166   task->SetMCdata(mc);
167   task->SetFriends(friends);
168
169   //if(!task->Load(Form("%s/AnalysisResults.root", gSystem->ExpandPathName("$PWD")))){
170   if(!task->Load(filename)){
171     Error("makeResults.C", "Load data container for task %s failed.", task->GetName());
172     delete task;
173     return;
174   }
175   task->LoadDetectorMap(filename);
176   if(!task->PostProcess()){
177     Error("makeResults.C", "Processing data container for task %s failed.", task->GetName());
178     delete task;
179     return;
180   }
181   if(summary) task->MakeSummary();
182   else{
183     for(Int_t ipic=0; ipic<task->GetNRefFigures(); ipic++){
184       c->Clear();
185       if(!task->GetRefFigure(ipic)) continue;
186       c->SaveAs(Form("%s_Fig%02d.gif", task->GetName(), ipic), "gif");
187     }
188   }
189   delete task;
190 }
191
192 //______________________________________________________
193 void processESD(TNamed *otask, const Char_t *filename)
194 {
195   printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
196
197   AliTRDcheckESD *esd = dynamic_cast<AliTRDcheckESD*>(otask);
198   if(!esd){
199     Info("makeResults.C", "Processing of task %s failed.", otask->GetName());
200     delete otask;
201     return;
202   }
203   //if(!esd->Load(Form("%s/AnalysisResults.root", gSystem->ExpandPathName("$PWD")), "TRD_Performance")){
204   if(!esd->Load(filename, "TRD_Performance")){
205     Error("makeResults.C", "Load data container for task %s failed.", esd->GetName());
206     delete esd;
207     return;
208   }
209   esd->Terminate(NULL);
210
211   if(summary) esd->MakeSummaryFromCF(0, "", kFALSE, kFALSE);
212   // else{
213   //   for(Int_t ipic(0); ipic<esd->GetNRefFigures(); ipic++){
214   //     c->Clear();
215   //     if(!esd->GetRefFigure(ipic)) continue;
216   //     c->SaveAs(Form("%s_Fig%02d.gif", esd->GetName(), ipic));
217   //   }
218   // }
219   delete esd;
220 }
221
222 //______________________________________________________
223 void processGEN(TNamed *otask, const Char_t *filename)
224 {
225   printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
226
227   AliTRDinfoGen *info = dynamic_cast<AliTRDinfoGen*>(otask);
228
229   if(!info->Load(filename, "TRD_Performance")){
230     Error("makeResults.C", "Load data container for task %s failed.", info->GetName());
231     delete info;
232     return;
233   }
234   info->MakeSummary();
235 //   else{
236 //     for(Int_t ipic(0); ipic<info->GetNRefFigures(); ipic++){
237 //       c->Clear();
238 //       if(!info->GetRefFigure(ipic)) continue;
239 //       c->SaveAs(Form("%s_Fig%02d.gif", info->GetName(), ipic));
240 //     }
241 //   }
242
243   delete info;
244 }
245
246 //______________________________________________________
247 void makeSummaryESD(const Char_t* filename, Double_t* trendValues, Bool_t useCF, Bool_t useIsolatedBC, Bool_t cutTOFbc, const Char_t* dir, Bool_t isGrid) {
248   //
249   //  Make the summary picture and get trending variables from the ESD task
250   //
251   if(isGrid) TGrid::Connect("alien://");
252
253   // Load Libraries in interactive mode
254   Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
255   for(Int_t ilib=0; ilib<nlibs; ilib++){
256     if(gSystem->Load(libs[ilib]) >= 0) continue;
257     Error("makeResults.C", "Failed to load %s.", libs[ilib]);
258     return;
259   }
260
261   AliTRDcheckESD *esd=new AliTRDcheckESD();
262   if(!esd->Load(filename,dir)) return;
263   //esd->Terminate();
264   if(useCF) esd->MakeSummaryFromCF(trendValues, "", useIsolatedBC, cutTOFbc);
265   //  else esd->MakeSummary(trendValues);
266 }