]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/PilotTrain/PilotAnalysis_sim.C
update to AliTRDpwg1Helper class by Markus
[u/mrichter/AliRoot.git] / PWG1 / PilotTrain / PilotAnalysis_sim.C
1 #include "Riostream.h"
2 void LoadLibraries();
3 void AddAnalysisTasks(); 
4 class AliAnalysisAlien;                                                                                                                    
5 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode);
6
7 Int_t runNumbers[5] = {117222};
8
9 Bool_t doAOD          = 0;   
10 Bool_t doQAsym        = 1;   // output ok
11 Bool_t doVZERO        = 1;   // output ok but there is a 2nd file
12 Bool_t doVertex       = 1;   // output ok
13 Bool_t doSPD          = 1;   // output ok, needs RP   
14 Bool_t doFMD          = 1;   // output ok
15 Bool_t doTPC          = 1;   // output ok
16 Bool_t doEventStat    = 0;   // output ok
17 Bool_t doSDD          = 1;   // outout ok needs RP
18 Bool_t doSSDdEdx      = 1;   // testing
19 // new 
20 Bool_t doTRD          = 1;   // TRD 
21 Bool_t doITS          = 1;   // ITS
22 Bool_t doCALO         = 1;   // Calorimeter
23 Bool_t doMUONTrig     = 1;   // MUON trigger
24 Bool_t doImpParRes    = 1;   // Impact parameter resolution
25 Bool_t doMUON         = 1;   // MUON QA
26
27 Bool_t doMUONEff      = 0;   // MUON efficiency  NEEDS geometry
28 Bool_t doV0           = 0;   // V0 recosntruction performance NEEDS MCtruth 
29
30 TString     train_name         = "QA";
31 //TString     train_name         = "TR019_PASS6";
32 TString     job_tag            = "QA16sim_LHC10d: PWG1 QA train";
33 //TString     job_tag            = "TR019: LHC09d-Pass6 ESD filtering w. PhysSelection -> AOD (including muon deltas)";
34 TString     root_version       = "v5-26-00b-6";
35 TString     aliroot_version    = "v4-20-01-AN";
36 TString     grid_datadir       = " /alice/sim/LHC10c9";
37 //TString     grid_datadir       = "/alice/data/2009/LHC09d";
38 //TString     data_pattern       = "*ESDs/pass2/*ESDs.root";
39 TString     data_pattern       = "*ESDs.root";
40 TString     alien_outdir       = "";
41 //TString     alien_outdir       = "/alice/cern.ch/user/m/mgheata/analysisDATA/output_QA007_PASS1_7TeV/000114917";
42 //TString     alien_outdir       = "/alice/data/2009/LHC09d/analysis/PASS6/AOD";
43 TString     mergeExcludes;
44
45 Bool_t useProductionMode       = kTRUE;
46 Bool_t useMergeViaJDL          = kTRUE;
47 Bool_t useFastReadOption       = kTRUE;
48 Bool_t useOverwriteMode        = kTRUE;
49 Bool_t useDevelopmentVersion   = kFALSE;
50
51 void PilotAnalysis(const char *plugin_mode = "full")
52 {
53   TGrid::Connect("alien://");
54   if (!gGrid || !gGrid->IsConnected()) {
55     ::Error("PilotAnalysis", "No grid connection");
56     return;
57   }
58   // Write configuration
59   TString cdir = gSystem->WorkingDirectory();
60   gSystem->MakeDirectory(train_name);
61   gSystem->ChangeDirectory(train_name);
62   ofstream out;
63   out.open(Form("%sConfig.C",train_name.Data()), ios::out);
64   out << "{" << endl;
65   out << "   train_name      = " << "\"" << train_name.Data() << "\";" << endl;
66   out << "   root_version    = " << "\"" << root_version.Data() << "\";" << endl;
67   out << "   aliroot_version = " << "\"" << aliroot_version.Data() << "\";" << endl;
68   out << "   grid_datadir   = " << "\"" << grid_datadir.Data() << "\";" << endl;
69   if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
70   out << "   alien_outdir    = " << "\"" << alien_outdir.Data() << "\";" << endl;
71   out << "   doAOD           = " << doAOD << ";" << endl;
72   out << "   doQAsim         = " << doQAsym << ";" << endl;
73   out << "   doVZERO         = " << doVZERO << ";" << endl;
74   out << "   doVertex        = " << doVertex << ";" << endl;
75   out << "   doSPD           = " << doSPD << ";" << endl;
76   out << "   doSDD           = " << doSDD << ";" << endl;
77   out << "   doSSDdEdx       = " << doSSDdEdx << ";" << endl;
78   out << "   doFMD           = " << doFMD << ";" << endl;
79   out << "   doTPC           = " << doTPC << ";" << endl;
80   out << "   doTRD           = " << doTRD << ";" << endl;
81   out << "   doImpParRes     = " << doImpParRes << ";" << endl;
82   out << "   doMUON          = " << doMUON << ";" << endl;
83   out << "   doEventStat     = " << doEventStat << ";" << endl;
84   out << "}" << endl;
85   out.close();
86   
87   // Load libraries
88   gSystem->SetIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TRD");
89   LoadLibraries();
90   // Create manager
91   AliAnalysisManager *mgr  = new AliAnalysisManager("PilotAnalysis", "Production train");
92   mgr->SetNSysInfo(100);
93   // Input handler
94   AliESDInputHandlerRP *esdHandler = new AliESDInputHandlerRP();
95   esdHandler->SetReadFriends(kTRUE);
96   esdHandler->SetActiveBranches("ESDfriend");
97   mgr->SetInputEventHandler(esdHandler);
98   if (doAOD) {
99      // AOD output handler
100      AliAODHandler* aodHandler   = new AliAODHandler();
101      aodHandler->SetOutputFileName("AliAOD.root");
102      if (!mergeExcludes.IsNull()) mergeExcludes += " ";
103      mergeExcludes += "AliAOD.root";
104      mgr->SetOutputEventHandler(aodHandler);
105   }   
106
107   mgr->SetDebugLevel(0);
108   mgr->SetSaveCanvases(kTRUE);
109   
110   // AnalysisTasks
111   AddAnalysisTasks();
112   // Grid handler
113   AliAnalysisAlien *alienHandler = CreateAlienHandler(plugin_mode);
114   mgr->SetGridHandler(alienHandler);
115   if (mgr->InitAnalysis()) {                                                                                                              
116     mgr->PrintStatus(); 
117     mgr->StartAnalysis("grid");
118     TString alien_workdir = gGrid->GetHomeDirectory();
119     alien_workdir += "analysisDATA";
120     TString configName = Form("%s/%sConfig.C", alien_workdir.Data(), train_name.Data());
121     if (strcmp(plugin_mode, "test")) {
122       printf("=== Registering configuration file <%s>===\n", configName.Data());
123       if (AliAnalysisAlien::FileExists(configName.Data())) gGrid->Rm(configName.Data());                                                     
124       TFile::Cp(Form("file:%sConfig.C",train_name.Data()), Form("alien://%s", configName.Data()));  
125     }  
126   }
127 }
128
129 void LoadLibraries()
130 {
131   gSystem->Load("libANALYSIS");
132   gSystem->Load("libANALYSISalice");
133   gSystem->Load("libCORRFW");
134   gSystem->Load("libTENDER");
135   gSystem->Load("libPWG0base.so");
136   gSystem->Load("libPWG0dep.so");
137   gSystem->Load("libPWG0selectors.so");
138   gSystem->Load("libPWG1.so");
139   gSystem->Load("libPWG2.so");
140   gSystem->Load("libPWG2forward.so");
141
142   if (doCALO) {
143      gSystem->Load("libEMCALUtils");
144      gSystem->Load("libPWG4PartCorrBase");
145      gSystem->Load("libPWG4PartCorrDep");
146   }  
147   if(doMUONTrig || doAOD) {
148      gSystem->Load("libPWG3base");
149      gSystem->Load("libPWG3muon");
150      gSystem->Load("libPWG3muondep");
151   }   
152 }
153
154 void AddAnalysisTasks()
155 {
156   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
157   mgr->SetCommonFileName("QAresults.root");
158   // AOD creation with collision events
159   if (doAOD) {
160     gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
161     mgr->RegisterExtraFile("AliAOD.Muons.root");
162     mgr->RegisterExtraFile("AliAOD.Dimuons.root");
163     AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kFALSE, kTRUE, kTRUE, doEventStat);
164   }   
165   //
166   // Event Statistics (Jan Fiete)
167   //
168
169   if (doEventStat) {
170       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
171       AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
172 //      if (doMUON) physSelTask->GetPhysicsSelection()->SetUseMuonTriggers();
173       mgr->RegisterExtraFile("event_stat.root");
174   }
175   // Vertexing (A. Dainese)
176   // 
177   if (doVertex) {
178     gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskVertexESD.C");
179     AliAnalysisTaskVertexESD* taskvertexesd =  AddTaskVertexESD();
180     taskvertexesd->SelectCollisionCandidates();
181   }  
182
183   // TPC QA (E. Sicking)
184   //
185   if (doQAsym) {
186     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskQAsym.C");
187     AliAnalysisTaskSE * taskqasim = AddTaskQAsym(0);
188     taskqasim->SelectCollisionCandidates();
189   }  
190   //
191   // VZERO QA  (C. Cheshkov)
192   //
193   if (doVZERO) {
194     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskVZEROQA.C");
195     AliAnalysisTaskSE * taskv0qa = AddTaskVZEROQA(0);
196 //  taskv0qa->SelectCollisionCandidates();
197   }
198   //
199   // TPC (Jacek Otwinowski)
200   //
201   if (doTPC) {
202     gROOT->LoadMacro("$(ALICE_ROOT)/PWG1/TPC/macros/AddTaskPerformanceTPCQA.C");
203     AliPerformanceTask *tpcQA = AddTaskPerformanceTPCQA(kFALSE, kTRUE);
204   }  
205   //
206   // SPD (A. Mastroserio)
207   //
208   if (doSPD) {
209     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskSPDQA.C");
210     AliAnalysisTaskSE* taskspdqa = AddTaskSPDQA();
211     taskspdqa->SelectCollisionCandidates();
212   }  
213   //
214   // SDD (F. Prino)
215   //
216   if (doSDD) {
217     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddSDDPoints.C");
218     AliAnalysisTaskSE* tasksdd = AddSDDPoints();
219     tasksdd->SelectCollisionCandidates();
220   }
221   //
222   // SSD dEdx (Marek Chojnacki)
223   //
224   if (doSSDdEdx) {
225     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskdEdxSSDQA.C");
226     AliAnalysisTaskSE* taskssddedx = AddTaskdEdxSSDQA();
227     taskssddedx->SelectCollisionCandidates();
228   }
229
230   //
231   // ITS
232   //
233   if (doITS) {
234       gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskPerformanceITS.C");
235       AliAnalysisTaskITSTrackingCheck *itsQA = AddTaskPerformanceITS(kFALSE);
236   }
237   //
238   // TRD (Alex Bercuci, M. Fasel) 
239   //
240   if(doTRD) {
241       gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTrainPerformanceTRD.C");
242       // steer individual TRD tasks
243       Bool_t 
244       doCheckESD(kTRUE),  // AliTRDcheckESD
245       doCheckDET(kTRUE),  // AliTRDcheckDET
246       doEffic(kTRUE),     // AliTRDefficiency
247       doResolution(kTRUE),// AliTRDresolution
248       doCheckPID(kTRUE),  // AliTRDcheckPID
249       doV0Monitor(kFALSE);// AliTRDv0Monitor
250       AddTrainPerformanceTRD(Translate(doCheckESD, doCheckDET, doEffic, doResolution, doCheckPID, doV0Monitor));
251   }
252
253   //
254   // Calorimetry (Gustavo Conesa)
255   //
256
257   if(doCALO) {
258       gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/QA/AddTaskCalorimeterQA.C");
259       AliAnalysisTaskParticleCorrelation *taskCaloQA = AddTaskCalorimeterQA("ESD", kTRUE, kFALSE);
260       taskCaloQA->SetDebugLevel(0);
261   }
262
263   //
264   // Muon Trigger
265   //
266   
267   if(doMUONTrig) {
268       gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskMTRchamberEfficiency.C");
269       AliAnalysisTaskTrigChEff *taskMuonTrig = AddTaskMTRchamberEfficiency();
270   }
271
272   //
273   // Muon Efficiency
274   //
275
276   if(doMUONEff) {
277       gROOT->LoadMacro("$ALICE_ROOT/PWG3/muondep/AddTaskMUONTrackingEfficiency.C");
278       AliAnalysisTaskMuonTrackingEff *taskMuonTrackEff = AddTaskMUONTrackingEfficiency();
279   }
280   
281   //
282   // V0-Decay Reconstruction (Ana Marin)
283   // 
284
285   if (doV0) {
286       gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskV0QA.C");
287       AliAnalysisTaskV0QA *taskv0QA = AddTaskV0QA(kFALSE);
288   }
289   // FMD (Hans Hjersing Dalsgaard)
290   //
291   if (doFMD) {
292     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskFMD.C");
293     AliAnalysisTaskSE* taskfmd = AddTaskFMD();
294     taskfmd->SelectCollisionCandidates();
295   }  
296   // Impact parameter resolution (xianbao.yuan@pd.infn.it, andrea.dainese@pd.infn.it)
297   //
298   if (doImpParRes) {
299     gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskImpParRes.C");
300     AliAnalysisTaskSE* taskimpparres= AddTaskImpParRes();
301     taskimpparres->SelectCollisionCandidates();
302   }  
303   // MUON QA (Philippe Pillot)
304   //
305   if (doMUON) {
306     gROOT->LoadMacro("$ALICE_ROOT/PWG3/muon/AddTaskMuonQA.C");
307     AliAnalysisTaskSE* taskmuonqa= AddTaskMuonQA(kFALSE, kFALSE);
308   }  
309 }
310
311 //______________________________________________________________________________
312 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
313 {
314 // Check if user has a valid token, otherwise make one. This has limitations.
315 // One can always follow the standard procedure of calling alien-token-init then
316 //   source /tmp/gclient_env_$UID in the current shell.
317    if (!AliAnalysisGrid::CreateToken()) return NULL;
318    AliAnalysisAlien *plugin = new AliAnalysisAlien();
319 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
320    plugin->SetRunMode(plugin_mode);
321    if (useProductionMode) plugin->SetProductionMode();
322    plugin->SetJobTag(job_tag);
323    plugin->SetNtestFiles(1);
324 // Set versions of used packages
325    plugin->SetAPIVersion("V1.1x");
326    plugin->SetROOTVersion(root_version);
327    plugin->SetAliROOTVersion(aliroot_version);
328 // Declare input data to be processed.
329 // Method 1: Create automatically XML collections using alien 'find' command.
330 // Define production directory LFN
331    plugin->SetGridDataDir(grid_datadir);
332 // Set data search pattern
333    plugin->SetDataPattern(data_pattern);
334 // ...then add run numbers to be considered
335 //   if (!iAODanalysis) plugin->SetRunRange(run_range[0], run_range[1]);
336    //plugin->SetRunPrefix("000");
337 //   plugin->SetOutputSingleFolder("output");
338    plugin->SetOutputToRunNo();
339 //   Int_t run_numbers[30] = {104065, 104155, 104157, 104159, 104160, 104315, 104316, 104320, 104321, 104439, 
340 //                            104792, 104793, 104799, 104800, 104801, 104802, 104803, 104821, 104824, 104825,
341 //                            104841, 104845, 104849, 104852, 104865, 104867, 104876, 104892, 105143, 105160};
342 //   Int_t run_numbers[8] = {114785, 114778, 114757, 114753, 114745, 114744, 114743, 114737};
343 //   Int_t run_numbers[2] = {114785, 114917};
344    for (Int_t i=0; i<2; i++) {
345       if (!runNumbers[i]) break;
346       plugin->AddRunNumber(runNumbers[i]);
347    }   
348 // Define alien work directory where all files will be copied. Relative to alien $HOME.
349    plugin->SetGridWorkingDir(train_name);
350 // Declare alien output directory. Relative to working directory.
351    if (alien_outdir.IsNull()) alien_outdir = Form("output_%s",train_name.Data());
352    plugin->SetGridOutputDir(alien_outdir);
353
354    if (useDevelopmentVersion) {
355      plugin->EnablePackage("STEERBase");
356      plugin->EnablePackage("ESD");
357      plugin->EnablePackage("AOD");
358      plugin->EnablePackage("ANALYSIS");
359      plugin->EnablePackage("ANALYSISalice");
360    }
361
362 // Declare the analysis source files names separated by blancs. To be compiled runtime
363 // using ACLiC on the worker nodes.
364 // Declare all libraries (other than the default ones for the framework. These will be
365 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
366    plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TRD");
367    
368    plugin->SetAdditionalLibs("libTENDER.so libPWG0base.so libPWG0dep.so libPWG0selectors.so libPWG1.so libPWG2.so \
369                               libPWG2forward.so libEMCALUtils.so libPWG4PartCorrBase.so libPWG4PartCorrDep.so \
370                               libPWG3base.so libPWG3muon.so libPWG3muondep.so");
371      
372 // Declare the output file names separated by blancs.
373 // (can be like: file.root or file.root@ALICE::Niham::File)
374    plugin->SetDefaultOutputs();
375 //   plugin->SetMergeExcludes(mergeExclude);
376    plugin->SetMaxMergeFiles(20);
377    plugin->SetNrunsPerMaster(1);
378 // Optionally define the files to be archived.
379 //   plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
380    
381    // Put default output files to archive
382    TString listhists = "";
383    TString listaods  = "";
384    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
385    TIter next(mgr->GetOutputs());
386    AliAnalysisDataContainer *output;
387    while ((output=(AliAnalysisDataContainer*)next())) {
388       const char *filename = output->GetFileName();
389       if (!(strcmp(filename, "default"))) {
390          if (!mgr->GetOutputEventHandler()) continue;
391          filename = mgr->GetOutputEventHandler()->GetOutputFileName();
392          if (listaods.Length()) listaods += ",";
393          listaods += filename;
394       } else {   
395          if (listhists.Contains(filename)) continue;
396          if (listhists.Length()) listhists += ",";
397          listhists += filename;
398       }   
399    }
400    if (mgr->GetExtraFiles().Length()) {
401       if (listhists.Length()) listhists += ",";
402       listhists += mgr->GetExtraFiles();
403       listhists.ReplaceAll(" ", ",");
404    }
405    if (listhists.Length()) listhists = Form("hist_archive.zip:%s", listhists.Data());
406    if (listaods.Length())  listaods  = Form("aod_archive.zip:%s", listaods.Data());
407    if (!listhists.Length()) {
408       ::Fatal("AnalysisTrainNew", "No task output !");
409    }
410    TString outputArchive = "log_archive.zip:stdout,stderr@disk=4";
411    if (listaods.Length()) {
412       outputArchive += " ";
413       outputArchive += listaods;
414       outputArchive += "@disk=4";
415    }   
416    if (listhists.Length()) {
417       outputArchive += " ";
418       outputArchive += listhists;
419       outputArchive += "@disk=4";
420    }   
421    if (!mergeExcludes.IsNull()) plugin->SetMergeExcludes(mergeExcludes);
422 // Set friends
423 //   if (iAODanalysis && iPWG3d2h) 
424 //      plugin->SetFriendChainName("AliAOD.VertexingHF.root");
425 //   plugin->SetOutputArchive(outputArchive);
426 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
427    plugin->SetAnalysisMacro(Form("%s.C", train_name.Data()));
428 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
429    plugin->SetSplitMaxInputFileNumber(10);
430 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
431 //   plugin->SetMaxInitFailed(5);
432 // Optionally resubmit threshold.
433 //   plugin->SetMasterResubmitThreshold(90);
434 // Optionally set time to live (default 30000 sec)
435    plugin->SetTTL(70000);
436 // Optionally set input format (default xml-single)
437    plugin->SetInputFormat("xml-single");
438 // Optionally modify the name of the generated JDL (default analysis.jdl)
439    plugin->SetJDLName(Form("%s.jdl", train_name.Data()));
440 // Optionally modify the executable name (default analysis.sh)
441    plugin->SetExecutable(Form("%s.sh", train_name.Data()));
442 // Optionally modify job price (default 1)
443    plugin->SetPrice(1);      
444 // Optionally modify split mode (default 'se')    
445    plugin->SetSplitMode("se");
446    plugin->SetExecutableCommand("aliroot -b -q");
447 // Merge via JDL
448    plugin->SetMergeViaJDL(useMergeViaJDL);
449 // Use fastread option
450    plugin->SetFastReadOption(useFastReadOption);
451 // UseOverwrite mode
452    plugin->SetOverwriteMode(useOverwriteMode);   
453    return plugin;
454 }