]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/PilotTrain/PilotAnalysis.C
new PilotTrain.C containing centrality
[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   = 1;
10 Bool_t doEventStat    = 1;
11 Bool_t doCentrality   = 1;
12 Bool_t doQAsym        = 1;
13 Bool_t doVZERO        = 1;   // there is a 2nd file
14 Bool_t doVertex       = 1;
15 Bool_t doSPD          = 1;   // needs RP   
16 Bool_t doTPC          = 1;
17 Bool_t doSDD          = 1;   // needs RP
18 Bool_t doSSDdEdx      = 1;
19 // new 
20 Bool_t doTRD          = 1;
21 Bool_t doITS          = 1;
22 Bool_t doCALO         = 1;
23 Bool_t doMUONTrig     = 1;
24 Bool_t doImpParRes    = 1;
25 Bool_t doMUON         = 1;
26 Bool_t doTOF          = 1;
27 Bool_t doHMPID        = 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/ANALYSIS/macros/AddTaskCentrality.C");
189      AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
190      gROOT->LoadMacro("$ALICE_ROOT/PWG1/Centrality/AddTaskHIMultCorr.C");
191      AliAnalysisTaskHIMultCorr *taskHIcentrality = AddTaskHIMultCorr();
192   }   
193   
194   // Vertexing (A. Dainese)
195   // 
196   if (doVertex) {
197     gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskVertexESD.C");
198     AliAnalysisTaskVertexESD* taskvertexesd =  AddTaskVertexESD();
199     taskvertexesd->SelectCollisionCandidates();
200   }  
201
202   // TPC QA (E. Sicking)
203   //
204   if (doQAsym) {
205     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskQAsym.C");
206     AliAnalysisTaskSE * taskqasim = AddTaskQAsym(0);
207     taskqasim->SelectCollisionCandidates();
208   }  
209   //
210   // VZERO QA  (C. Cheshkov)
211   //
212   if (doVZERO) {
213     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskVZEROQA.C");
214     AliAnalysisTaskSE * taskv0qa = AddTaskVZEROQA(0);
215 //  taskv0qa->SelectCollisionCandidates();
216   }
217   //
218   // TPC (Jacek Otwinowski & Michael Knichel)
219   //
220   if (doTPC) {
221     gROOT->LoadMacro("$ALICE_ROOT/PWG1/TPC/macros/AddTaskPerformanceTPCdEdxQA.C");
222     AliPerformanceTask *tpcQA = AddTaskPerformanceTPCdEdxQA(kFALSE, kTRUE);
223     tpcQA->SelectCollisionCandidates();
224   }  
225   //
226   // SPD (A. Mastroserio)
227   //
228   if (doSPD) {
229     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskSPDQA.C");
230     AliAnalysisTaskSE* taskspdqa = AddTaskSPDQA();
231     taskspdqa->SelectCollisionCandidates();
232   }  
233   //
234   // SDD (F. Prino)
235   //
236   if (doSDD) {
237     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddSDDPoints.C");
238     AliAnalysisTaskSE* tasksdd = AddSDDPoints();
239     tasksdd->SelectCollisionCandidates();
240   }
241   //
242   // SSD dEdx (Marek Chojnacki)
243   //
244   if (doSSDdEdx) {
245     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskdEdxSSDQA.C");
246     AliAnalysisTaskSE* taskssddedx = AddTaskdEdxSSDQA();
247     taskssddedx->SelectCollisionCandidates();
248   }
249
250   //
251   // ITS
252   //
253   if (doITS) {
254       gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskPerformanceITS.C");
255       AliAnalysisTaskITSTrackingCheck *itsQA = AddTaskPerformanceITS(kFALSE);
256   }
257   //
258   // TRD (Alex Bercuci, M. Fasel) 
259   //
260   if(doTRD) {
261       gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTrainPerformanceTRD.C");
262       // steer individual TRD tasks
263       Bool_t 
264       doCheckESD(kTRUE),  // AliTRDcheckESD
265       doCheckDET(kTRUE),  // AliTRDcheckDET
266       doEffic(kTRUE),     // AliTRDefficiency
267       doResolution(kTRUE),// AliTRDresolution
268       doCheckPID(kTRUE),  // AliTRDcheckPID
269       doV0Monitor(kFALSE);// AliTRDv0Monitor
270       AddTrainPerformanceTRD(Translate(doCheckESD, doCheckDET, doEffic, doResolution, doCheckPID, doV0Monitor));
271   }
272
273   //
274   // Calorimetry (Gustavo Conesa)
275   //
276
277   if(doCALO) {
278       gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/QA/AddTaskCalorimeterQA.C");
279       AliAnalysisTaskParticleCorrelation *taskCaloQA = AddTaskCalorimeterQA("ESD", kTRUE, kFALSE);
280       taskCaloQA->SetDebugLevel(0);
281   }
282
283   //
284   // Muon Trigger
285   //
286   
287   if(doMUONTrig) {
288       gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskMTRchamberEfficiency.C");
289       AliAnalysisTaskTrigChEff *taskMuonTrig = AddTaskMTRchamberEfficiency();
290   }
291
292   //
293   // Muon Efficiency
294   //
295
296   if(doMUONEff) {
297       gROOT->LoadMacro("$ALICE_ROOT/PWG3/muondep/AddTaskMUONTrackingEfficiency.C");
298       AliAnalysisTaskMuonTrackingEff *taskMuonTrackEff = AddTaskMUONTrackingEfficiency();
299   }
300   
301   //
302   // V0-Decay Reconstruction (Ana Marin)
303   // 
304
305   if (doV0) {
306       gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskV0QA.C");
307       AliAnalysisTaskV0QA *taskv0QA = AddTaskV0QA(kFALSE);
308   }
309   //
310   // Impact parameter resolution (xianbao.yuan@pd.infn.it, andrea.dainese@pd.infn.it)
311   //
312   if (doImpParRes) {
313     gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskImpParRes.C");
314  //   AliAnalysisTaskSE* taskimpparres= AddTaskImpParRes();
315     AliAnalysisTaskSE* taskimpparres= AddTaskImpParRes(kFALSE,-1,kFALSE,kFALSE);
316     taskimpparres->SelectCollisionCandidates();
317   }  
318   //
319   // MUON QA (Philippe Pillot)
320   //
321   if (doMUON) {
322     gROOT->LoadMacro("$ALICE_ROOT/PWG3/muon/AddTaskMuonQA.C");
323     AliAnalysisTaskSE* taskmuonqa= AddTaskMuonQA();
324   }  
325   //
326   // TOF (Francesca Bellini)
327   //
328   if (doTOF) {
329     gROOT->LoadMacro("$ALICE_ROOT/PWG1/TOF/AddTaskTOFQA.C");
330     AliAnalysisTaskTOFqa *tofQA = AddTaskTOFQA();
331     tofQA->SelectCollisionCandidates();
332   }  
333   //
334   // HMPID QA (Giacomo Volpe)
335   //
336   if (doHMPID) {
337     gROOT->LoadMacro("$ALICE_ROOT/PWG1/HMPID/AddTaskHmpidQA.C");
338     AliAnalysisTaskSE* taskhmpidqa= AddTaskHmpidQA(kFALSE);
339   }      
340 }
341
342 //______________________________________________________________________________
343 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
344 {
345 // Check if user has a valid token, otherwise make one. This has limitations.
346 // One can always follow the standard procedure of calling alien-token-init then
347 //   source /tmp/gclient_env_$UID in the current shell.
348    if (!AliAnalysisGrid::CreateToken()) return NULL;
349    AliAnalysisAlien *plugin = new AliAnalysisAlien();
350 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
351    plugin->SetRunMode(plugin_mode);
352    if (useProductionMode) {
353       plugin->SetProductionMode();
354       plugin->AddDataFile(data_collection);
355    }   
356    plugin->SetJobTag(job_tag);
357    plugin->SetNtestFiles(5);
358    plugin->SetCheckCopy(kFALSE);
359 //   plugin->SetOneStageMerging(kTRUE);
360 // Set versions of used packages
361    plugin->SetAPIVersion("V1.1x");
362    plugin->SetROOTVersion(root_version);
363    plugin->SetAliROOTVersion(aliroot_version);
364 // Declare input data to be processed.
365 // Method 1: Create automatically XML collections using alien 'find' command.
366 // Define production directory LFN
367    plugin->SetGridDataDir(grid_datadir);
368 // Set data search pattern
369    plugin->SetDataPattern(data_pattern);
370 // ...then add run numbers to be considered
371 //   if (!iAODanalysis) plugin->SetRunRange(run_range[0], run_range[1]);
372 //   plugin->SetOutputSingleFolder("output");
373    if (!useProductionMode) {
374       plugin->SetRunPrefix("000");
375       plugin->SetOutputToRunNo();
376       for (Int_t i=0; i<2; i++) {
377          if (!runNumbers[i]) break;
378          plugin->AddRunNumber(runNumbers[i]);
379       }   
380    }
381 // Define alien work directory where all files will be copied. Relative to alien $HOME.
382    plugin->SetGridWorkingDir(grid_workdir);
383 // Declare alien output directory. Relative to working directory.
384    if (alien_outdir.IsNull()) alien_outdir = Form("output_%s",train_name.Data());
385    plugin->SetGridOutputDir(alien_outdir);
386
387    if (useDevelopmentVersion) {
388      plugin->EnablePackage("STEERBase");
389      plugin->EnablePackage("ESD");
390      plugin->EnablePackage("AOD");
391      plugin->EnablePackage("ANALYSIS");
392      plugin->EnablePackage("ANALYSISalice");
393    }
394
395 // Declare the analysis source files names separated by blancs. To be compiled runtime
396 // using ACLiC on the worker nodes.
397 // Declare all libraries (other than the default ones for the framework. These will be
398 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
399    plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TRD");
400    
401    plugin->SetAdditionalLibs("libCORRFW.so libTENDER.so libPWG0base.so libPWG0dep.so libPWG0selectors.so libPWG1.so libPWG2.so \
402                               libPWG2forward.so libEMCALUtils.so libPWG4PartCorrBase.so libPWG4PartCorrDep.so \
403                               libPWG3base.so libPWG3muon.so libPWG3muondep.so");
404      
405 // Declare the output file names separated by blancs.
406 // (can be like: file.root or file.root@ALICE::Niham::File)
407    plugin->SetDefaultOutputs();
408    plugin->SetMaxMergeFiles(20);
409    plugin->SetNrunsPerMaster(1);
410    
411    // Put default output files to archive
412    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
413    TIter next(mgr->GetOutputs());
414    AliAnalysisDataContainer *output;
415    if (!mergeExcludes.IsNull()) plugin->SetMergeExcludes(mergeExcludes);
416    if (!terminateFiles.IsNull()) plugin->SetTerminateFiles(terminateFiles);
417 // Set friends
418 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
419    plugin->SetAnalysisMacro(Form("%s.C", train_name.Data()));
420 // Optionally set a name for the generated validation script
421    plugin->SetValidationScript("validation.sh");
422 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
423    plugin->SetSplitMaxInputFileNumber(grid_split);
424 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
425 //   plugin->SetMaxInitFailed(5);
426 // Optionally modify the number of replicas
427    plugin->SetNumberOfReplicas(4);
428 // Optionally resubmit threshold.
429 //   plugin->SetMasterResubmitThreshold(90);
430 // Optionally set time to live (default 30000 sec)
431    plugin->SetTTL(70000);
432 // Optionally set input format (default xml-single)
433    plugin->SetInputFormat("xml-single");
434 // Optionally modify the name of the generated JDL (default analysis.jdl)
435    plugin->SetJDLName(Form("%s.jdl", train_name.Data()));
436 // Optionally modify the executable name (default analysis.sh)
437    plugin->SetExecutable(Form("%s.sh", train_name.Data()));
438 // Optionally modify job price (default 1)
439    plugin->SetPrice(1);      
440 // Optionally modify split mode (default 'se')    
441    plugin->SetSplitMode("se");
442    plugin->SetExecutableCommand("aliroot -b -q");
443 // Merge via JDL
444    plugin->SetMergeViaJDL(useMergeViaJDL);
445 // Use fastread option
446    plugin->SetFastReadOption(useFastReadOption);
447 // UseOverwrite mode
448    plugin->SetOverwriteMode(useOverwriteMode);   
449 /*********************************************************
450  ***     PROOF MODE SPECIFIC SETTINGS         ************
451  *********************************************************/
452 // Proof cluster
453 //   plugin->SetProofCluster("alice-caf");
454    plugin->SetProofCluster("skaf.saske.sk");
455 // Dataset to be used   
456    plugin->SetProofDataSet("/alice/data/LHC10e_000128175_p1#esdTree");
457 // May need to reset proof. Supported modes: 0-no reset, 1-soft, 2-hard
458    plugin->SetProofReset(0);
459 // May limit number of workers
460    plugin->SetNproofWorkers(20);   
461 // May use a specific version of root installed in proof
462    plugin->SetRootVersionForProof("current_dbg");
463 // May set the aliroot mode. Check http://aaf.cern.ch/node/83 
464    plugin->SetAliRootMode("ALIROOT"); // Loads AF libs by default
465 // May request ClearPackages (individual ClearPackage not supported)
466    plugin->SetClearPackages(kFALSE);
467 // Plugin test mode works only providing a file containing test file locations
468    plugin->SetFileForTestMode(gSystem->ExpandPathName("$ALICE_ROOT/PWG1/PilotTrain/files.txt"));
469    return plugin;
470 }