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