]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/PilotTrain/PilotAnalysis.C
Centrality task now compiled in PWG1 library
[u/mrichter/AliRoot.git] / PWG1 / PilotTrain / PilotAnalysis.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] = {137844};
8
9 Bool_t doCDBconnect   = 0;
10 Bool_t doQAsym        = 0;
11 Bool_t doVZERO        = 0;   // there is a 2nd file
12 Bool_t doVertex       = 0;
13 Bool_t doSPD          = 0;   // needs RP   
14 Bool_t doTPC          = 0;
15 Bool_t doEventStat    = 1;
16 Bool_t doSDD          = 0;   // needs RP
17 Bool_t doSSDdEdx      = 0;
18 // new 
19 Bool_t doTRD          = 0;
20 Bool_t doITS          = 0;
21 Bool_t doCALO         = 0;
22 Bool_t doMUONTrig     = 0;
23 Bool_t doImpParRes    = 0;
24 Bool_t doMUON         = 0;
25 Bool_t doTOF          = 0;
26 Bool_t doHMPID        = 0;
27 Bool_t doCentrality   = 1;
28
29 Bool_t doMUONEff      = 0;   // NEEDS geometry
30 Bool_t doV0           = 0;   // NEEDS MCtruth 
31
32 TString     train_name         = "QA";      // QA local folder name
33 TString     train_tag          = "";        // Train special tag appended to 
34                                             // visible name. ("sim", "pp", ...)
35                // Name in train page (DON'T CHANGE)
36 TString     visible_name       = Form("QA$2_$3%s", train_tag.Data()); //# FIXED #
37 TString     job_comment        = "PWG1 QA train"; // Can add observations here
38                // Job tag (DON'T CHANGE)
39 TString     job_tag            = Form("%s: %s", visible_name.Data(), job_comment.Data());
40                // Package versions - Modify as needed
41 TString     root_version       = "v5-27-06b";
42 TString     aliroot_version    = "v4-21-09-AN";
43                // Production directory - change as needed for test mode
44 TString     grid_datadir       = "/alice/data/2010/LHC10h";
45                // Work directory in GRID (DON'T CHANGE)
46 TString     grid_workdir       = "/alice/cern.ch/user/a/alidaq/QA/QA$2";
47                // Job splitting
48 Int_t       grid_split         = 10;       // Splitting
49                // Debug level
50 Int_t       debug_level        = 1;        // Debugging
51                // Data pattern - change as needed for test mode
52 TString     data_pattern       = "*ESDs/pass1/*ESDs.root";
53                // Output directory (DON'T CHANGE)
54 TString     alien_outdir       = "$1/QA$2";
55                // Input collection (production mode)
56 TString     data_collection    = "$1/qa1.xml";
57 TString     mergeExcludes      = ""; // Files to be excluded for merging
58 TString     terminateFiles     = "trending.root"; // Files produced during Terminate
59
60 Bool_t useProductionMode       = kTRUE;
61 Bool_t useMergeViaJDL          = kTRUE;
62 Bool_t useFastReadOption       = kTRUE;
63 Bool_t useOverwriteMode        = kTRUE;
64 Bool_t useDevelopmentVersion   = kFALSE;
65
66 void PilotAnalysis(const char *plugin_mode = "full")
67 {
68   TString smode(plugin_mode);
69   smode.ToLower();
70   if (smode == "test") useProductionMode = kFALSE;
71   if (!useProductionMode) {
72      TGrid::Connect("alien://");
73      if (!gGrid || !gGrid->IsConnected()) {
74        ::Error("PilotAnalysis", "No grid connection");
75        return;
76      }
77   }   
78   // Write configuration
79   TString cdir = gSystem->WorkingDirectory();
80   gSystem->MakeDirectory(train_name);
81   gSystem->ChangeDirectory(train_name);
82   ofstream out;
83   out.open(Form("%sConfig.C",train_name.Data()), ios::out);
84   out << "{" << endl;
85   out << "   train_name      = " << "\"" << train_name.Data() << "\";" << endl;
86   out << "   root_version    = " << "\"" << root_version.Data() << "\";" << endl;
87   out << "   aliroot_version = " << "\"" << aliroot_version.Data() << "\";" << endl;
88   out << "   grid_datadir   = " << "\"" << grid_datadir.Data() << "\";" << endl;
89   if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
90   out << "   alien_outdir    = " << "\"" << alien_outdir.Data() << "\";" << endl;
91   out << "   doQAsim         = " << doQAsym << ";" << endl;
92   out << "   doVZERO         = " << doVZERO << ";" << endl;
93   out << "   doVertex        = " << doVertex << ";" << endl;
94   out << "   doSPD           = " << doSPD << ";" << endl;
95   out << "   doSDD           = " << doSDD << ";" << endl;
96   out << "   doSSDdEdx       = " << doSSDdEdx << ";" << endl;
97   out << "   doTPC           = " << doTPC << ";" << endl;
98   out << "   doTRD           = " << doTRD << ";" << endl;
99   out << "   doImpParRes     = " << doImpParRes << ";" << endl;
100   out << "   doMUON          = " << doMUON << ";" << endl;
101   out << "   doTOF           = " << doTOF << ";" << endl;
102   out << "   doHMPID         = " << doHMPID << ";" << endl;
103   out << "   doEventStat     = " << doEventStat << ";" << endl;
104   out << "   doCentrality    = " << doCentrality << ";" << endl;
105   out << "}" << endl;
106   out.close();
107   
108   // Load libraries
109   gSystem->SetIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TRD -I$ALICE_ROOT/PWG1");
110   LoadLibraries();
111   // Create manager
112   AliAnalysisManager *mgr  = new AliAnalysisManager("PilotAnalysis", "Production train");
113   mgr->SetNSysInfo(100);
114   mgr->SetDebugLevel(1);
115   // Input handler
116   AliESDInputHandlerRP *esdHandler = new AliESDInputHandlerRP();
117   esdHandler->SetReadFriends(kTRUE);
118   esdHandler->SetActiveBranches("ESDfriend");
119   mgr->SetInputEventHandler(esdHandler);
120   mgr->SetDebugLevel(debug_level);
121   
122   // AnalysisTasks
123   AddAnalysisTasks();
124   // Grid handler
125   AliAnalysisAlien *alienHandler = CreateAlienHandler(plugin_mode);
126   mgr->SetGridHandler(alienHandler);
127   if (mgr->InitAnalysis()) {                                                                                                              
128     mgr->PrintStatus(); 
129     if (!strcmp(plugin_mode, "local")) mgr->StartAnalysis("local");
130     else mgr->StartAnalysis("grid");
131   }
132 }
133
134 void LoadLibraries()
135 {
136   gSystem->Load("libANALYSIS");
137   gSystem->Load("libANALYSISalice");
138   gSystem->Load("libCORRFW");
139   gSystem->Load("libTENDER");
140   gSystem->Load("libPWG0base.so");
141   gSystem->Load("libPWG0dep.so");
142   gSystem->Load("libPWG0selectors.so");
143   gSystem->Load("libPWG1.so");
144   gSystem->Load("libPWG2.so");
145   gSystem->Load("libPWG2forward.so");
146
147   if (doCALO) {
148      gSystem->Load("libEMCALUtils");
149      gSystem->Load("libPWG4PartCorrBase");
150      gSystem->Load("libPWG4PartCorrDep");
151   }  
152   if(doMUONTrig) {
153      gSystem->Load("libPWG3base");
154      gSystem->Load("libPWG3muon");
155      gSystem->Load("libPWG3muondep");
156   }   
157 }
158
159 void AddAnalysisTasks()
160 {
161   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
162   mgr->SetCommonFileName("QAresults.root");
163   //
164   // CDB connection
165   //
166   if (doCDBconnect) {
167     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskCDBconnect.C");
168     AliTaskCDBconnect *taskCDB = AddTaskCDBconnect();
169     if (!taskCDB) return;
170     taskCDB->SetRunNumber(runNumbers[0]);
171   }    
172   
173   //
174   // Event Statistics (Jan Fiete)
175   //
176   if (doEventStat) {
177       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
178       AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kFALSE /*MC*/);
179 //      mgr->RegisterExtraFile("event_stat.root");
180       if (!terminateFiles.IsNull()) terminateFiles += ",";
181       terminateFiles += "event_stat.root";
182   }
183   
184   //
185   // Centrality (J. Thaeder)
186   //
187   if (doCentrality) {
188      gROOT->LoadMacro("$ALICE_ROOT/PWG1/Centrality/AddTaskHIMultCorr.C");
189      AliAnalysisTaskHIMultCorr *taskHIcentrality = AddTaskHIMultCorr();
190   }   
191   
192   // Vertexing (A. Dainese)
193   // 
194   if (doVertex) {
195     gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskVertexESD.C");
196     AliAnalysisTaskVertexESD* taskvertexesd =  AddTaskVertexESD();
197     taskvertexesd->SelectCollisionCandidates();
198   }  
199
200   // TPC QA (E. Sicking)
201   //
202   if (doQAsym) {
203     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskQAsym.C");
204     AliAnalysisTaskSE * taskqasim = AddTaskQAsym(0);
205     taskqasim->SelectCollisionCandidates();
206   }  
207   //
208   // VZERO QA  (C. Cheshkov)
209   //
210   if (doVZERO) {
211     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskVZEROQA.C");
212     AliAnalysisTaskSE * taskv0qa = AddTaskVZEROQA(0);
213 //  taskv0qa->SelectCollisionCandidates();
214   }
215   //
216   // TPC (Jacek Otwinowski & Michael Knichel)
217   //
218   if (doTPC) {
219     gROOT->LoadMacro("$ALICE_ROOT/PWG1/TPC/macros/AddTaskPerformanceTPCdEdxQA.C");
220     AliPerformanceTask *tpcQA = AddTaskPerformanceTPCdEdxQA(kFALSE, kTRUE);
221     tpcQA->SelectCollisionCandidates();
222   }  
223   //
224   // SPD (A. Mastroserio)
225   //
226   if (doSPD) {
227     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskSPDQA.C");
228     AliAnalysisTaskSE* taskspdqa = AddTaskSPDQA();
229     taskspdqa->SelectCollisionCandidates();
230   }  
231   //
232   // SDD (F. Prino)
233   //
234   if (doSDD) {
235     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddSDDPoints.C");
236     AliAnalysisTaskSE* tasksdd = AddSDDPoints();
237     tasksdd->SelectCollisionCandidates();
238   }
239   //
240   // SSD dEdx (Marek Chojnacki)
241   //
242   if (doSSDdEdx) {
243     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskdEdxSSDQA.C");
244     AliAnalysisTaskSE* taskssddedx = AddTaskdEdxSSDQA();
245     taskssddedx->SelectCollisionCandidates();
246   }
247
248   //
249   // ITS
250   //
251   if (doITS) {
252       gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskPerformanceITS.C");
253       AliAnalysisTaskITSTrackingCheck *itsQA = AddTaskPerformanceITS(kFALSE);
254   }
255   //
256   // TRD (Alex Bercuci, M. Fasel) 
257   //
258   if(doTRD) {
259       gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTrainPerformanceTRD.C");
260       // steer individual TRD tasks
261       Bool_t 
262       doCheckESD(kTRUE),  // AliTRDcheckESD
263       doCheckDET(kTRUE),  // AliTRDcheckDET
264       doEffic(kTRUE),     // AliTRDefficiency
265       doResolution(kTRUE),// AliTRDresolution
266       doCheckPID(kTRUE),  // AliTRDcheckPID
267       doV0Monitor(kFALSE);// AliTRDv0Monitor
268       AddTrainPerformanceTRD(Translate(doCheckESD, doCheckDET, doEffic, doResolution, doCheckPID, doV0Monitor));
269   }
270
271   //
272   // Calorimetry (Gustavo Conesa)
273   //
274
275   if(doCALO) {
276       gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/QA/AddTaskCalorimeterQA.C");
277       AliAnalysisTaskParticleCorrelation *taskCaloQA = AddTaskCalorimeterQA("ESD", kTRUE, kFALSE);
278       taskCaloQA->SetDebugLevel(0);
279   }
280
281   //
282   // Muon Trigger
283   //
284   
285   if(doMUONTrig) {
286       gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskMTRchamberEfficiency.C");
287       AliAnalysisTaskTrigChEff *taskMuonTrig = AddTaskMTRchamberEfficiency();
288   }
289
290   //
291   // Muon Efficiency
292   //
293
294   if(doMUONEff) {
295       gROOT->LoadMacro("$ALICE_ROOT/PWG3/muondep/AddTaskMUONTrackingEfficiency.C");
296       AliAnalysisTaskMuonTrackingEff *taskMuonTrackEff = AddTaskMUONTrackingEfficiency();
297   }
298   
299   //
300   // V0-Decay Reconstruction (Ana Marin)
301   // 
302
303   if (doV0) {
304       gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskV0QA.C");
305       AliAnalysisTaskV0QA *taskv0QA = AddTaskV0QA(kFALSE);
306   }
307   //
308   // Impact parameter resolution (xianbao.yuan@pd.infn.it, andrea.dainese@pd.infn.it)
309   //
310   if (doImpParRes) {
311     gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskImpParRes.C");
312  //   AliAnalysisTaskSE* taskimpparres= AddTaskImpParRes();
313     AliAnalysisTaskSE* taskimpparres= AddTaskImpParRes(kFALSE,-1,kFALSE,kFALSE);
314     taskimpparres->SelectCollisionCandidates();
315   }  
316   //
317   // MUON QA (Philippe Pillot)
318   //
319   if (doMUON) {
320     gROOT->LoadMacro("$ALICE_ROOT/PWG3/muon/AddTaskMuonQA.C");
321     AliAnalysisTaskSE* taskmuonqa= AddTaskMuonQA();
322   }  
323   //
324   // TOF (Francesca Bellini)
325   //
326   if (doTOF) {
327     gROOT->LoadMacro("$ALICE_ROOT/PWG1/TOF/AddTaskTOFQA.C");
328     AliAnalysisTaskTOFqa *tofQA = AddTaskTOFQA();
329     tofQA->SelectCollisionCandidates();
330   }  
331   //
332   // HMPID QA (Giacomo Volpe)
333   //
334   if (doHMPID) {
335     gROOT->LoadMacro("$ALICE_ROOT/PWG1/HMPID/AddTaskHmpidQA.C");
336     AliAnalysisTaskSE* taskhmpidqa= AddTaskHmpidQA(kFALSE);
337   }      
338 }
339
340 //______________________________________________________________________________
341 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
342 {
343 // Check if user has a valid token, otherwise make one. This has limitations.
344 // One can always follow the standard procedure of calling alien-token-init then
345 //   source /tmp/gclient_env_$UID in the current shell.
346    if (!AliAnalysisGrid::CreateToken()) return NULL;
347    AliAnalysisAlien *plugin = new AliAnalysisAlien();
348 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
349    plugin->SetRunMode(plugin_mode);
350    if (useProductionMode) {
351       plugin->SetProductionMode();
352       plugin->AddDataFile(data_collection);
353    }   
354    plugin->SetJobTag(job_tag);
355    plugin->SetNtestFiles(5);
356    plugin->SetCheckCopy(kFALSE);
357 //   plugin->SetOneStageMerging(kTRUE);
358 // Set versions of used packages
359    plugin->SetAPIVersion("V1.1x");
360    plugin->SetROOTVersion(root_version);
361    plugin->SetAliROOTVersion(aliroot_version);
362 // Declare input data to be processed.
363 // Method 1: Create automatically XML collections using alien 'find' command.
364 // Define production directory LFN
365    plugin->SetGridDataDir(grid_datadir);
366 // Set data search pattern
367    plugin->SetDataPattern(data_pattern);
368 // ...then add run numbers to be considered
369 //   if (!iAODanalysis) plugin->SetRunRange(run_range[0], run_range[1]);
370 //   plugin->SetOutputSingleFolder("output");
371    if (!useProductionMode) {
372       plugin->SetRunPrefix("000");
373       plugin->SetOutputToRunNo();
374       for (Int_t i=0; i<2; i++) {
375          if (!runNumbers[i]) break;
376          plugin->AddRunNumber(runNumbers[i]);
377       }   
378    }
379 // Define alien work directory where all files will be copied. Relative to alien $HOME.
380    plugin->SetGridWorkingDir(grid_workdir);
381 // Declare alien output directory. Relative to working directory.
382    if (alien_outdir.IsNull()) alien_outdir = Form("output_%s",train_name.Data());
383    plugin->SetGridOutputDir(alien_outdir);
384
385    if (useDevelopmentVersion) {
386      plugin->EnablePackage("STEERBase");
387      plugin->EnablePackage("ESD");
388      plugin->EnablePackage("AOD");
389      plugin->EnablePackage("ANALYSIS");
390      plugin->EnablePackage("ANALYSISalice");
391    }
392
393 // Declare the analysis source files names separated by blancs. To be compiled runtime
394 // using ACLiC on the worker nodes.
395 // Declare all libraries (other than the default ones for the framework. These will be
396 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
397    plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TRD");
398    
399    plugin->SetAdditionalLibs("libCORRFW.so libTENDER.so libPWG0base.so libPWG0dep.so libPWG0selectors.so libPWG1.so libPWG2.so \
400                               libPWG2forward.so libEMCALUtils.so libPWG4PartCorrBase.so libPWG4PartCorrDep.so \
401                               libPWG3base.so libPWG3muon.so libPWG3muondep.so");
402      
403 // Declare the output file names separated by blancs.
404 // (can be like: file.root or file.root@ALICE::Niham::File)
405    plugin->SetDefaultOutputs();
406    plugin->SetMaxMergeFiles(20);
407    plugin->SetNrunsPerMaster(1);
408    
409    // Put default output files to archive
410    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
411    TIter next(mgr->GetOutputs());
412    AliAnalysisDataContainer *output;
413    if (!mergeExcludes.IsNull()) plugin->SetMergeExcludes(mergeExcludes);
414    if (!terminateFiles.IsNull()) plugin->SetTerminateFiles(terminateFiles);
415 // Set friends
416 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
417    plugin->SetAnalysisMacro(Form("%s.C", train_name.Data()));
418 // Optionally set a name for the generated validation script
419    plugin->SetValidationScript("validation.sh");
420 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
421    plugin->SetSplitMaxInputFileNumber(grid_split);
422 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
423 //   plugin->SetMaxInitFailed(5);
424 // Optionally modify the number of replicas
425    plugin->SetNumberOfReplicas(4);
426 // Optionally resubmit threshold.
427 //   plugin->SetMasterResubmitThreshold(90);
428 // Optionally set time to live (default 30000 sec)
429    plugin->SetTTL(70000);
430 // Optionally set input format (default xml-single)
431    plugin->SetInputFormat("xml-single");
432 // Optionally modify the name of the generated JDL (default analysis.jdl)
433    plugin->SetJDLName(Form("%s.jdl", train_name.Data()));
434 // Optionally modify the executable name (default analysis.sh)
435    plugin->SetExecutable(Form("%s.sh", train_name.Data()));
436 // Optionally modify job price (default 1)
437    plugin->SetPrice(1);      
438 // Optionally modify split mode (default 'se')    
439    plugin->SetSplitMode("se");
440    plugin->SetExecutableCommand("aliroot -b -q");
441 // Merge via JDL
442    plugin->SetMergeViaJDL(useMergeViaJDL);
443 // Use fastread option
444    plugin->SetFastReadOption(useFastReadOption);
445 // UseOverwrite mode
446    plugin->SetOverwriteMode(useOverwriteMode);   
447 /*********************************************************
448  ***     PROOF MODE SPECIFIC SETTINGS         ************
449  *********************************************************/
450 // Proof cluster
451 //   plugin->SetProofCluster("alice-caf");
452    plugin->SetProofCluster("skaf.saske.sk");
453 // Dataset to be used   
454    plugin->SetProofDataSet("/alice/data/LHC10e_000128175_p1#esdTree");
455 // May need to reset proof. Supported modes: 0-no reset, 1-soft, 2-hard
456    plugin->SetProofReset(0);
457 // May limit number of workers
458    plugin->SetNproofWorkers(20);   
459 // May use a specific version of root installed in proof
460    plugin->SetRootVersionForProof("current_dbg");
461 // May set the aliroot mode. Check http://aaf.cern.ch/node/83 
462    plugin->SetAliRootMode("ALIROOT"); // Loads AF libs by default
463 // May request ClearPackages (individual ClearPackage not supported)
464    plugin->SetClearPackages(kFALSE);
465 // Plugin test mode works only providing a file containing test file locations
466    plugin->SetFileForTestMode(gSystem->ExpandPathName("$ALICE_ROOT/PWG1/PilotTrain/files.txt"));
467    return plugin;
468 }