]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/TRD/macros/makeResults.C
186db2e9c2cf0811392a17998510feb14137865f
[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.so")
46 // gSystem->Load("libANALYSISalice.so")
47 // gSystem->Load("libTENDER.so");
48 // gSystem->Load("libPWGPP.so");
49 // gSystem->Load("libCORRFW.so");
50 // gSystem->Load("libPWGmuon.so");
51 // gSystem->Load("libNetx.so") ;
52 // gSystem->Load("libRAliEn.so");
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.so", "libANALYSIS.so", "libANALYSISalice.so", "libCORRFW", "libTENDER.so", "libPWGPP.so", "libPWGmuon.so"};
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", Double_t* trendValues=0x0, Bool_t useCF=kFALSE, Bool_t useIsolatedBC=kFALSE, Bool_t cutTOFbc=kFALSE, const Char_t* dir="TRD_Performance", Bool_t isGrid=kFALSE);
95 void makeResults(const Char_t *opt = "ALL",
96                  const Char_t *files="QAresults.root",
97                  const Char_t *cid = "",
98                  Bool_t kGRID=kFALSE, Bool_t dosummary = kTRUE)
99 {
100   if(kGRID) TGrid::Connect("alien://");
101
102   // Load Libraries in interactive mode
103   Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
104   for(Int_t ilib=0; ilib<nlibs; ilib++){
105     if(gSystem->Load(libs[ilib]) >= 0) continue;
106     Error("makeResults.C", "Failed to load %s.", libs[ilib]);
107     return;
108   }
109
110   mc      = AliTRDpwgppHelper::HasReadMCData(opt);
111   friends = AliTRDpwgppHelper::HasReadFriendData(opt);
112
113   gStyle->SetOptStat(0);
114   gStyle->SetOptFit(0);
115   TString outputFile;
116   if(!TString(files).EndsWith(".root")){
117     outputFile = Form("%s/QAResults.root", gSystem->ExpandPathName("$PWD"));
118     AliTRDpwgppHelper::MergeProd("QAResults.root", files);
119   } else {
120     outputFile = files;
121   }
122   Int_t fSteerTask = AliTRDpwgppHelper::ParseOptions(opt);
123
124   if(!dosummary){
125     summary = kFALSE;
126     if(!c) c=new TCanvas("c", "Performance", 10, 10, 800, 500);
127   }
128
129   TClass *ctask = new TClass;
130   AliAnalysisTask *task = NULL;
131   for(Int_t itask = AliTRDpwgppHelper::kNTRDQATASKS; itask--;){
132     if(!AliTRDpwgppHelper::DoTask(itask, fSteerTask)) continue;
133     new(ctask) TClass(AliTRDpwgppHelper::TaskClassName(itask));
134     task = (AliAnalysisTask*)ctask->New();
135     task->SetName(Form("%s%s", task->GetName(), cid));
136     printf(" *** task %s, output file %s\n", task->GetName(), outputFile.Data());
137     if(task->IsA()->InheritsFrom("AliTRDrecoTask")) processTRD(task, outputFile.Data());
138     else if(strcmp(task->IsA()->GetName(), "AliTRDcheckESD")==0) processESD(task, outputFile.Data());
139     else if(strcmp(task->IsA()->GetName(), "AliTRDinfoGen")==0) processGEN(task, outputFile.Data());
140     else{
141       Error("makeResults.C", "Handling of class task \"%s\" not implemented.", task->IsA()->GetName());
142       delete task;
143     }
144   }
145   delete ctask;
146   delete c;
147   // write trending summary
148   AliTRDtrendingManager::Instance()->Terminate();
149 }
150
151
152 //______________________________________________________
153 void processTRD(TNamed *otask, const Char_t *filename)
154 {
155   printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
156   Int_t debug(0);
157   AliTRDrecoTask *task = dynamic_cast<AliTRDrecoTask*>(otask);
158   task->SetDebugLevel(debug);
159   AliLog::SetClassDebugLevel(otask->IsA()->GetName(), debug);
160   task->SetMCdata(mc);
161   task->SetFriends(friends);
162
163   //if(!task->Load(Form("%s/AnalysisResults.root", gSystem->ExpandPathName("$PWD")))){
164   if(!task->Load(filename)){
165     Error("makeResults.C", "Load data container for task %s failed.", task->GetName());
166     delete task;
167     return;
168   }
169   task->LoadDetectorMap(filename);
170   if(!task->PostProcess()){
171     Error("makeResults.C", "Processing data container for task %s failed.", task->GetName());
172     delete task;
173     return;
174   }
175   if(summary) task->MakeSummary();
176   else{
177     for(Int_t ipic=0; ipic<task->GetNRefFigures(); ipic++){
178       c->Clear();
179       if(!task->GetRefFigure(ipic)) continue;
180       c->SaveAs(Form("%s_Fig%02d.gif", task->GetName(), ipic), "gif");
181     }
182   }
183   delete task;
184 }
185
186 //______________________________________________________
187 void processESD(TNamed *otask, const Char_t *filename)
188 {
189   printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
190
191   AliTRDcheckESD *esd = dynamic_cast<AliTRDcheckESD*>(otask);
192   if(!esd){
193     Info("makeResults.C", "Processing of task %s failed.", otask->GetName());
194     delete otask;
195     return;
196   }
197   //if(!esd->Load(Form("%s/AnalysisResults.root", gSystem->ExpandPathName("$PWD")), "TRD_Performance")){
198   if(!esd->Load(filename, "TRD_Performance")){
199     Error("makeResults.C", "Load data container for task %s failed.", esd->GetName());
200     delete esd;
201     return;
202   }
203   esd->Terminate(NULL);
204
205   if(summary) esd->MakeSummary();
206   else{
207     for(Int_t ipic(0); ipic<esd->GetNRefFigures(); ipic++){
208       c->Clear();
209       if(!esd->GetRefFigure(ipic)) continue;
210       c->SaveAs(Form("%s_Fig%02d.gif", esd->GetName(), ipic));
211     }
212   }
213   delete esd;
214 }
215
216 //______________________________________________________
217 void processGEN(TNamed *otask, const Char_t *filename)
218 {
219   printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
220
221   AliTRDinfoGen *info = dynamic_cast<AliTRDinfoGen*>(otask);
222
223   if(!info->Load(filename, "TRD_Performance")){
224     Error("makeResults.C", "Load data container for task %s failed.", info->GetName());
225     delete info;
226     return;
227   }
228   if(summary) Info("processGEN", "MakeSummary() not implemented yet");//info->MakeSummary();
229   else{
230     for(Int_t ipic(0); ipic<info->GetNRefFigures(); ipic++){
231       c->Clear();
232       if(!info->GetRefFigure(ipic)) continue;
233       c->SaveAs(Form("%s_Fig%02d.gif", info->GetName(), ipic));
234     }
235   }
236
237   delete info;
238 }
239
240 //______________________________________________________
241 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) {
242   //
243   //  Make the summary picture and get trending variables from the ESD task
244   //
245   if(isGrid) TGrid::Connect("alien://");
246
247   // Load Libraries in interactive mode
248   Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
249   for(Int_t ilib=0; ilib<nlibs; ilib++){
250     if(gSystem->Load(libs[ilib]) >= 0) continue;
251     Error("makeResults.C", "Failed to load %s.", libs[ilib]);
252     return;
253   }
254
255   AliTRDcheckESD *esd=new AliTRDcheckESD();
256   if(!esd->Load(filename,dir)) return;
257   //esd->Terminate();
258   if(useCF) esd->MakeSummaryFromCF(trendValues, "", useIsolatedBC, cutTOFbc);
259   else esd->MakeSummary(trendValues);
260 }