]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/qaRec/macros/makeResults.C
57ec91b97b7cc6eb0843fc926de12bdb3b1d71c5
[u/mrichter/AliRoot.git] / TRD / qaRec / macros / makeResults.C
1 // Usage:
2 //   makeResults.C("tasks", "file_list", 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 //     "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/alice/local/TRDdata/SIM/P-Flat/TRUNK/RUN0/TRD.Performance.root
17 // or for GRID alien:///alice/cern.ch/user/m/mfasel/MinBiasProd/results/ppMinBias80000/1/TRD.Performance.root
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.Task%.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 <TFileMerger.h>
52 #include <TCanvas.h>
53 #include <TH1.h>
54 #include <TGraph.h>
55 #include <TObjArray.h>
56 #include <TObjString.h>
57 #include <TString.h>
58 #include <TROOT.h>
59 #include <TSystem.h>
60 #include <TStyle.h>
61
62 #include "qaRec/AliTRDrecoTask.h"
63
64 #endif
65
66 #include "AliTRDperformanceTrain.h"
67 //#include "../../PWG1/macros/AddPerformanceTask.h"
68
69 Char_t *libs[] = {"libProofPlayer.so", "libANALYSIS.so", "libTRDqaRec.so"};
70 // define setup
71 TCanvas *c = 0x0;
72 void mergeProd(const Char_t *mark="TRD.Performance.root", const Char_t *files=0);
73 void processTRD(TNamed* task);
74 void processAliTask(TNamed* task);
75 void makeResults(Char_t *opt = "ALL", const Char_t *files=0x0, Bool_t kGRID=kFALSE)
76 {
77   if(kGRID){
78     if(!gSystem->Getenv("GSHELL_ROOT")){
79       Error("makeResults.C", "AliEn not initialized.");
80       return;
81     }
82     TGrid::Connect("alien://");
83   }
84
85         // Load Libraries in interactive mode
86   Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
87   for(Int_t ilib=0; ilib<nlibs; ilib++){
88     if(gSystem->Load(libs[ilib]) >= 0) continue;
89     Error("makeResults.C", Form("Failed to load %s.", libs[ilib]));
90     return;
91   }
92
93   Bool_t mc = HasReadMCData(opt);
94   Bool_t friends = HasReadFriendData(opt);
95
96   gStyle->SetOptStat(0);
97   gStyle->SetOptFit(0);
98   if(files) mergeProd("TRD.Performance.root", files);
99   Int_t fSteerTask = ParseOptions(opt);
100
101   if(!c) c=new TCanvas("c", "Performance", 10, 10, 800, 500);
102
103   TClass *ctask = new TClass;
104   AliAnalysisTask *task = 0x0;
105   AliTRDrecoTask  *trd  = 0x0;
106   for(Int_t itask = NTRDQATASKS; itask--;){
107     if(!TSTBIT(fSteerTask, itask)) continue;
108     new(ctask) TClass(fgkTRDtaskClassName[itask]);
109     task = (AliAnalysisTask*)ctask->New();
110
111     if(task->IsA()->InheritsFrom("AliTRDrecoTask")) processTRD(task);
112     else processAliTask(task);
113   }
114   delete ctask;
115   delete c;
116 }
117
118 //______________________________________________________
119 void mergeProd(const Char_t *mark, const Char_t *files)
120 {
121   const Int_t kBatch = 20;
122
123   TFileMerger *fFM = new TFileMerger(1);
124   fFM->OutputFile(Form("%s/0_%s",  gSystem->ExpandPathName("$PWD"), mark));
125
126   Int_t jbatch = 0, nbatch = 0;
127   string filename;
128   ifstream file(files);
129   while(getline(file, filename)){
130     if(Int_t(filename.find(mark)) < 0) continue;
131     fFM->AddFile(filename.c_str()); nbatch++;
132     if(nbatch==kBatch){
133       //printf("MERGE BATCH %d [%d]\n", jbatch, nbatch);
134       fFM->Merge(); jbatch++;
135       new(fFM) TFileMerger(kTRUE);
136       fFM->OutputFile(Form("%s/%d_%s",  gSystem->ExpandPathName("$PWD"), jbatch, mark));
137       nbatch=0;
138     }
139   }
140   if(nbatch){
141     //printf("MERGE BATCH %d[%d]\n", jbatch, nbatch);
142     fFM->Merge();
143     jbatch++;
144   }
145   if(!jbatch){
146     delete fFM;
147     return;
148   }
149
150   new(fFM) TFileMerger(kTRUE);
151   fFM->OutputFile(Form("%s/%s",  gSystem->ExpandPathName("$PWD"), mark));
152   for(Int_t ib=jbatch; ib--;){
153     fFM->AddFile(Form("%s/%d_%s",  gSystem->ExpandPathName("$PWD"), ib, mark));
154     gSystem->Exec(Form("rm -f %s/%d_%s", gSystem->ExpandPathName("$PWD"), ib, mark));
155   }
156   fFM->Merge();
157   delete fFM;
158 }
159
160 //______________________________________________________
161 void processTRD(TNamed *otask)
162 {
163   AliTRDrecoTask *task = dynamic_cast<AliTRDrecoTask*>(otask);
164   task->SetDebugLevel(0);
165   task->SetMCdata(mc);
166   task->SetFriends(friends);
167
168   if(!task->Load(Form("%s/TRD.Performance.root", gSystem->ExpandPathName("$PWD")))){
169     Error("makeResults.C", Form("Load data container for task %s failed.", task->GetName()));
170     delete task;
171     return;
172   }
173
174   if(!task->PostProcess()){
175     Error("makeResults.C", Form("Processing data container for task %s failed.", task->GetName()));
176     delete task;
177     return;
178   }
179   for(Int_t ipic=0; ipic<task->GetNRefFigures(); ipic++){
180     c->Clear();
181     if(!task->GetRefFigure(ipic)) continue;
182     c->SaveAs(Form("%s_Fig%02d.gif", task->GetName(), ipic));
183   }
184   delete task;
185 }
186
187 //______________________________________________________
188 void processAliTask(TNamed *otask)
189 {
190   AliAnalysisTask *task = dynamic_cast<AliAnalysisTask*>(otask);
191   Info("makeResults.C", Form("Processing of task %s not implemented yet.", task->GetName()));
192   delete task;
193 }