TENDER becomes Tender
[u/mrichter/AliRoot.git] / PWGPP / TRD / macros / makeResults.C
CommitLineData
1ee39b3a 1// Usage:
9e985d64 2// makeResults.C("tasks", "file_list", ""task_id, kGRID)
1ee39b3a 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
9e985d64 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)
1ee39b3a 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//
37ef945e 42//
43// In compiled mode :
44// Don't forget to load first the libraries
45// gSystem->Load("libANALYSIS.so")
46// gSystem->Load("libANALYSISalice.so")
af472fff 47// gSystem->Load("libTender.so");
2bfe5463 48// gSystem->Load("libPWGPP.so");
37ef945e 49// gSystem->Load("libCORRFW.so");
f1b821e6 50// gSystem->Load("libPWGmuon.so");
37ef945e 51// gSystem->Load("libNetx.so") ;
52// gSystem->Load("libRAliEn.so");
53
1ee39b3a 54// Authors:
37ef945e 55// Alex Bercuci (A.Bercuci@gsi.de)
56// Markus Fasel (m.Fasel@gsi.de)
1ee39b3a 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>
37ef945e 71#include <TSystem.h>
1ee39b3a 72#include <TGrid.h>
73#include <TGridResult.h>
74#include <TGridCollection.h>
75
02213fef 76#include "AliLog.h"
77
f01f8284 78#include "PWGPP/TRD/info/AliTRDtrendingManager.h"
2bfe5463 79#include "PWGPP/TRD/AliTRDpwgppHelper.h"
80#include "PWGPP/TRD/AliTRDrecoTask.h"
81#include "PWGPP/TRD/AliTRDcheckESD.h"
82#include "PWGPP/TRD/AliTRDinfoGen.h"
1ee39b3a 83#endif
84
af472fff 85const Char_t *libs[] = {"libProofPlayer.so", "libANALYSIS.so", "libANALYSISalice.so", "libCORRFW", "libTender.so", "libPWGPP.so", "libPWGmuon.so"};
1ee39b3a 86// define setup
37ef945e 87TCanvas *c(NULL);
1ee39b3a 88Bool_t mc(kFALSE), friends(kFALSE);
b795b480 89Bool_t summary(kTRUE);
1ee39b3a 90
02213fef 91void processTRD(TNamed* task, const Char_t *filename);
92void processESD(TNamed* task, const Char_t *filename);
37ef945e 93void processGEN(TNamed* task, const Char_t *filename);
c2c78193 94void 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);
37ef945e 101void 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)
1ee39b3a 105{
37ef945e 106 if(kGRID) TGrid::Connect("alien://");
1ee39b3a 107
566c3d46 108 // Load Libraries in interactive mode
1ee39b3a 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;
37ef945e 112 Error("makeResults.C", "Failed to load %s.", libs[ilib]);
1ee39b3a 113 return;
114 }
115
2bfe5463 116 mc = AliTRDpwgppHelper::HasReadMCData(opt);
117 friends = AliTRDpwgppHelper::HasReadFriendData(opt);
1ee39b3a 118
119 gStyle->SetOptStat(0);
120 gStyle->SetOptFit(0);
02213fef 121 TString outputFile;
37ef945e 122 if(!TString(files).EndsWith(".root")){
02213fef 123 outputFile = Form("%s/QAResults.root", gSystem->ExpandPathName("$PWD"));
2bfe5463 124 AliTRDpwgppHelper::MergeProd("QAResults.root", files);
02213fef 125 } else {
126 outputFile = files;
127 }
2bfe5463 128 Int_t fSteerTask = AliTRDpwgppHelper::ParseOptions(opt);
1ee39b3a 129
b795b480 130 if(!dosummary){
2ae60201 131 summary = kFALSE;
b795b480 132 if(!c) c=new TCanvas("c", "Performance", 10, 10, 800, 500);
133 }
1ee39b3a 134
135 TClass *ctask = new TClass;
847569f2 136 AliAnalysisTask *task = NULL;
2bfe5463 137 for(Int_t itask = AliTRDpwgppHelper::kNTRDQATASKS; itask--;){
138 if(!AliTRDpwgppHelper::DoTask(itask, fSteerTask)) continue;
139 new(ctask) TClass(AliTRDpwgppHelper::TaskClassName(itask));
1ee39b3a 140 task = (AliAnalysisTask*)ctask->New();
92d6d80c 141 task->SetName(Form("%s%s", task->GetName(), cid));
058c3053 142 printf(" *** task %s, output file %s\n", task->GetName(), outputFile.Data());
02213fef 143 if(task->IsA()->InheritsFrom("AliTRDrecoTask")) processTRD(task, outputFile.Data());
058c3053 144 else if(strcmp(task->IsA()->GetName(), "AliTRDcheckESD")==0) processESD(task, outputFile.Data());
566c3d46 145 else if(strcmp(task->IsA()->GetName(), "AliTRDinfoGen")==0) processGEN(task, outputFile.Data());
058c3053 146 else{
37ef945e 147 Error("makeResults.C", "Handling of class task \"%s\" not implemented.", task->IsA()->GetName());
058c3053 148 delete task;
149 }
1ee39b3a 150 }
151 delete ctask;
152 delete c;
847569f2 153 // write trending summary
154 AliTRDtrendingManager::Instance()->Terminate();
1ee39b3a 155}
156
157
158//______________________________________________________
02213fef 159void processTRD(TNamed *otask, const Char_t *filename)
1ee39b3a 160{
97d0ccba 161 printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
92d6d80c 162 Int_t debug(0);
1ee39b3a 163 AliTRDrecoTask *task = dynamic_cast<AliTRDrecoTask*>(otask);
92d6d80c 164 task->SetDebugLevel(debug);
165 AliLog::SetClassDebugLevel(otask->IsA()->GetName(), debug);
1ee39b3a 166 task->SetMCdata(mc);
167 task->SetFriends(friends);
168
02213fef 169 //if(!task->Load(Form("%s/AnalysisResults.root", gSystem->ExpandPathName("$PWD")))){
170 if(!task->Load(filename)){
37ef945e 171 Error("makeResults.C", "Load data container for task %s failed.", task->GetName());
1ee39b3a 172 delete task;
173 return;
174 }
8892a7f3 175 task->LoadDetectorMap(filename);
1ee39b3a 176 if(!task->PostProcess()){
37ef945e 177 Error("makeResults.C", "Processing data container for task %s failed.", task->GetName());
1ee39b3a 178 delete task;
179 return;
180 }
b795b480 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 }
1ee39b3a 188 }
189 delete task;
190}
191
192//______________________________________________________
02213fef 193void processESD(TNamed *otask, const Char_t *filename)
1ee39b3a 194{
97d0ccba 195 printf("process[%s] : %s\n", otask->GetName(), otask->GetTitle());
3d2a3dff 196
1ee39b3a 197 AliTRDcheckESD *esd = dynamic_cast<AliTRDcheckESD*>(otask);
198 if(!esd){
37ef945e 199 Info("makeResults.C", "Processing of task %s failed.", otask->GetName());
1ee39b3a 200 delete otask;
201 return;
202 }
02213fef 203 //if(!esd->Load(Form("%s/AnalysisResults.root", gSystem->ExpandPathName("$PWD")), "TRD_Performance")){
204 if(!esd->Load(filename, "TRD_Performance")){
37ef945e 205 Error("makeResults.C", "Load data container for task %s failed.", esd->GetName());
1ee39b3a 206 delete esd;
207 return;
208 }
02213fef 209 esd->Terminate(NULL);
37ef945e 210
5047978d 211 if(summary) esd->MakeSummaryFromCF(0, "", kFALSE, kFALSE);
694247e5 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 // }
1ee39b3a 219 delete esd;
220}
058c3053 221
222//______________________________________________________
223void 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")){
37ef945e 230 Error("makeResults.C", "Load data container for task %s failed.", info->GetName());
058c3053 231 delete info;
232 return;
233 }
dffc3357 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// }
058c3053 242
243 delete info;
810660cc 244}
566c3d46 245
246//______________________________________________________
247void 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 //
37ef945e 251 if(isGrid) TGrid::Connect("alien://");
252
566c3d46 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;
37ef945e 257 Error("makeResults.C", "Failed to load %s.", libs[ilib]);
566c3d46 258 return;
259 }
37ef945e 260
566c3d46 261 AliTRDcheckESD *esd=new AliTRDcheckESD();
262 if(!esd->Load(filename,dir)) return;
263 //esd->Terminate();
b93fa72f 264 if(useCF) esd->MakeSummaryFromCF(trendValues, "", useIsolatedBC, cutTOFbc);
694247e5 265 // else esd->MakeSummary(trendValues);
566c3d46 266}