]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/PilotTrain/PilotAnalysis.C
New working version of CDBconnect task. Has to be run in sync with the change in...
[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] = {121040};
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
26 Bool_t doMUONEff      = 0;   // NEEDS geometry
27 Bool_t doV0           = 0;   // NEEDS MCtruth 
28
29 TString     train_name         = "QA";      // QA local folder name
30 TString     train_tag          = "";        // Train special tag appended to 
31                                             // visible name. ("sim", "pp", ...)
32                // Name in train page (DON'T CHANGE)
33 TString     visible_name       = Form("QA$2_$3%s", train_tag.Data()); //# FIXED #
34 TString     job_comment        = "PWG1 QA train"; // Can add observations here
35                // Job tag (DON'T CHANGE)
36 TString     job_tag            = Form("%s: %s", visible_name.Data(), job_comment.Data());
37                // Package versions - Modify as needed
38 TString     root_version       = "v5-27-05";
39 TString     aliroot_version    = "v4-20-07-AN";
40                // Production directory - change as needed for test mode
41 TString     grid_datadir       = "/alice/data/2010/LHC10c";
42                // Work directory in GRID (DON'T CHANGE)
43 TString     grid_workdir       = "/alice/cern.ch/user/a/alidaq/QA/QA$2";
44                // Job splitting
45 Int_t       grid_split         = 20;       // Splitting
46                // Debug level
47 Int_t       debug_level        = 1;        // Debugging
48                // Data pattern - change as needed for test mode
49 TString     data_pattern       = "*ESDs/pass2/*ESDs.root";
50                // Output directory (DON'T CHANGE)
51 TString     alien_outdir       = "$1/QA$2";
52                // Input collection (production mode)
53 TString     data_collection    = "$1/qa1.xml";
54 TString     mergeExcludes      = ""; // Files to be excluded for merging
55 TString     terminateFiles     = ""; // Files produced during Terminate
56
57 Bool_t useProductionMode       = kTRUE;
58 Bool_t useMergeViaJDL          = kTRUE;
59 Bool_t useFastReadOption       = kTRUE;
60 Bool_t useOverwriteMode        = kFALSE;
61 Bool_t useDevelopmentVersion   = kFALSE;
62
63 void PilotAnalysis(const char *plugin_mode = "full")
64 {
65   TString smode(plugin_mode);
66   smode.ToLower();
67   if (smode == "test") useProductionMode = kFALSE;
68   if (!useProductionMode) {
69      TGrid::Connect("alien://");
70      if (!gGrid || !gGrid->IsConnected()) {
71        ::Error("PilotAnalysis", "No grid connection");
72        return;
73      }
74   }   
75   // Write configuration
76   TString cdir = gSystem->WorkingDirectory();
77   gSystem->MakeDirectory(train_name);
78   gSystem->ChangeDirectory(train_name);
79   ofstream out;
80   out.open(Form("%sConfig.C",train_name.Data()), ios::out);
81   out << "{" << endl;
82   out << "   train_name      = " << "\"" << train_name.Data() << "\";" << endl;
83   out << "   root_version    = " << "\"" << root_version.Data() << "\";" << endl;
84   out << "   aliroot_version = " << "\"" << aliroot_version.Data() << "\";" << endl;
85   out << "   grid_datadir   = " << "\"" << grid_datadir.Data() << "\";" << endl;
86   if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
87   out << "   alien_outdir    = " << "\"" << alien_outdir.Data() << "\";" << endl;
88   out << "   doQAsim         = " << doQAsym << ";" << endl;
89   out << "   doVZERO         = " << doVZERO << ";" << endl;
90   out << "   doVertex        = " << doVertex << ";" << endl;
91   out << "   doSPD           = " << doSPD << ";" << endl;
92   out << "   doSDD           = " << doSDD << ";" << endl;
93   out << "   doSSDdEdx       = " << doSSDdEdx << ";" << endl;
94   out << "   doTPC           = " << doTPC << ";" << endl;
95   out << "   doTRD           = " << doTRD << ";" << endl;
96   out << "   doImpParRes     = " << doImpParRes << ";" << endl;
97   out << "   doMUON          = " << doMUON << ";" << endl;
98   out << "   doEventStat     = " << doEventStat << ";" << endl;
99   out << "}" << endl;
100   out.close();
101   
102   // Load libraries
103   gSystem->SetIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TRD");
104   LoadLibraries();
105   // Create manager
106   AliAnalysisManager *mgr  = new AliAnalysisManager("PilotAnalysis", "Production train");
107   mgr->SetNSysInfo(100);
108   // Input handler
109   AliESDInputHandlerRP *esdHandler = new AliESDInputHandlerRP();
110   esdHandler->SetReadFriends(kTRUE);
111   esdHandler->SetActiveBranches("ESDfriend");
112   mgr->SetInputEventHandler(esdHandler);
113   mgr->SetDebugLevel(debug_level);
114   mgr->SetSaveCanvases(kFALSE);
115   
116   // AnalysisTasks
117   AddAnalysisTasks();
118   // Grid handler
119   AliAnalysisAlien *alienHandler = CreateAlienHandler(plugin_mode);
120   mgr->SetGridHandler(alienHandler);
121   if (mgr->InitAnalysis()) {                                                                                                              
122     mgr->PrintStatus(); 
123     mgr->StartAnalysis("grid");
124   }
125 }
126
127 void LoadLibraries()
128 {
129   gSystem->Load("libANALYSIS");
130   gSystem->Load("libANALYSISalice");
131   gSystem->Load("libCORRFW");
132   gSystem->Load("libTENDER");
133   gSystem->Load("libPWG0base.so");
134   gSystem->Load("libPWG0dep.so");
135   gSystem->Load("libPWG0selectors.so");
136   gSystem->Load("libPWG1.so");
137   gSystem->Load("libPWG2.so");
138   gSystem->Load("libPWG2forward.so");
139
140   if (doCALO) {
141      gSystem->Load("libEMCALUtils");
142      gSystem->Load("libPWG4PartCorrBase");
143      gSystem->Load("libPWG4PartCorrDep");
144   }  
145   if(doMUONTrig) {
146      gSystem->Load("libPWG3base");
147      gSystem->Load("libPWG3muon");
148      gSystem->Load("libPWG3muondep");
149   }   
150 }
151
152 void AddAnalysisTasks()
153 {
154   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
155   mgr->SetCommonFileName("QAresults.root");
156   //
157   // CDB connection
158   //
159   if (doCDBconnect) {
160     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskCDBconnect.C");
161     AliTaskCDBconnect *taskCDB = AddTaskCDBconnect();
162     if (!taskCDB) return;
163   }    
164   
165   //
166   // Event Statistics (Jan Fiete)
167   //
168   if (doEventStat) {
169       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
170       AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
171 //      mgr->RegisterExtraFile("event_stat.root");
172       if (!terminateFiles.IsNull()) terminateFiles += ",";
173       terminateFiles += "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   // Impact parameter resolution (xianbao.yuan@pd.infn.it, andrea.dainese@pd.infn.it)
290   //
291   if (doImpParRes) {
292     gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTaskImpParRes.C");
293     AliAnalysisTaskSE* taskimpparres= AddTaskImpParRes();
294     taskimpparres->SelectCollisionCandidates();
295   }  
296   // MUON QA (Philippe Pillot)
297   //
298   if (doMUON) {
299     gROOT->LoadMacro("$ALICE_ROOT/PWG3/muon/AddTaskMuonQA.C");
300     AliAnalysisTaskSE* taskmuonqa= AddTaskMuonQA();
301   }  
302 }
303
304 //______________________________________________________________________________
305 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
306 {
307 // Check if user has a valid token, otherwise make one. This has limitations.
308 // One can always follow the standard procedure of calling alien-token-init then
309 //   source /tmp/gclient_env_$UID in the current shell.
310    if (!AliAnalysisGrid::CreateToken()) return NULL;
311    AliAnalysisAlien *plugin = new AliAnalysisAlien();
312 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
313    plugin->SetRunMode(plugin_mode);
314    if (useProductionMode) {
315       plugin->SetProductionMode();
316       plugin->AddDataFile(data_collection);
317    }   
318    plugin->SetJobTag(job_tag);
319    plugin->SetNtestFiles(3);
320    plugin->SetCheckCopy(kFALSE);
321    plugin->SetOneStageMerging(kTRUE);
322 // Set versions of used packages
323    plugin->SetAPIVersion("V1.1x");
324    plugin->SetROOTVersion(root_version);
325    plugin->SetAliROOTVersion(aliroot_version);
326 // Declare input data to be processed.
327 // Method 1: Create automatically XML collections using alien 'find' command.
328 // Define production directory LFN
329    plugin->SetGridDataDir(grid_datadir);
330 // Set data search pattern
331    plugin->SetDataPattern(data_pattern);
332 // ...then add run numbers to be considered
333 //   if (!iAODanalysis) plugin->SetRunRange(run_range[0], run_range[1]);
334 //   plugin->SetOutputSingleFolder("output");
335    if (!useProductionMode) {
336       plugin->SetRunPrefix("000");
337       plugin->SetOutputToRunNo();
338       for (Int_t i=0; i<2; i++) {
339          if (!runNumbers[i]) break;
340          plugin->AddRunNumber(runNumbers[i]);
341       }   
342    }
343 // Define alien work directory where all files will be copied. Relative to alien $HOME.
344    plugin->SetGridWorkingDir(grid_workdir);
345 // Declare alien output directory. Relative to working directory.
346    if (alien_outdir.IsNull()) alien_outdir = Form("output_%s",train_name.Data());
347    plugin->SetGridOutputDir(alien_outdir);
348
349    if (useDevelopmentVersion) {
350      plugin->EnablePackage("STEERBase");
351      plugin->EnablePackage("ESD");
352      plugin->EnablePackage("AOD");
353      plugin->EnablePackage("ANALYSIS");
354      plugin->EnablePackage("ANALYSISalice");
355    }
356
357 // Declare the analysis source files names separated by blancs. To be compiled runtime
358 // using ACLiC on the worker nodes.
359 // Declare all libraries (other than the default ones for the framework. These will be
360 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
361    plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TRD");
362    
363    plugin->SetAdditionalLibs("libCORRFW.so libTENDER.so libPWG0base.so libPWG0dep.so libPWG0selectors.so libPWG1.so libPWG2.so \
364                               libPWG2forward.so libEMCALUtils.so libPWG4PartCorrBase.so libPWG4PartCorrDep.so \
365                               libPWG3base.so libPWG3muon.so libPWG3muondep.so");
366      
367 // Declare the output file names separated by blancs.
368 // (can be like: file.root or file.root@ALICE::Niham::File)
369    plugin->SetDefaultOutputs();
370    plugin->SetMaxMergeFiles(20);
371    plugin->SetNrunsPerMaster(1);
372    
373    // Put default output files to archive
374    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
375    TIter next(mgr->GetOutputs());
376    AliAnalysisDataContainer *output;
377    if (!mergeExcludes.IsNull()) plugin->SetMergeExcludes(mergeExcludes);
378    if (!terminateFiles.IsNull()) plugin->SetTerminateFiles(terminateFiles);
379 // Set friends
380 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
381    plugin->SetAnalysisMacro(Form("%s.C", train_name.Data()));
382 // Optionally set a name for the generated validation script
383    plugin->SetValidationScript("validation.sh");
384 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
385    plugin->SetSplitMaxInputFileNumber(grid_split);
386 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
387 //   plugin->SetMaxInitFailed(5);
388 // Optionally modify the number of replicas
389    plugin->SetNumberOfReplicas(4);
390 // Optionally resubmit threshold.
391 //   plugin->SetMasterResubmitThreshold(90);
392 // Optionally set time to live (default 30000 sec)
393    plugin->SetTTL(70000);
394 // Optionally set input format (default xml-single)
395    plugin->SetInputFormat("xml-single");
396 // Optionally modify the name of the generated JDL (default analysis.jdl)
397    plugin->SetJDLName(Form("%s.jdl", train_name.Data()));
398 // Optionally modify the executable name (default analysis.sh)
399    plugin->SetExecutable(Form("%s.sh", train_name.Data()));
400 // Optionally modify job price (default 1)
401    plugin->SetPrice(1);      
402 // Optionally modify split mode (default 'se')    
403    plugin->SetSplitMode("se");
404    plugin->SetExecutableCommand("aliroot -b -q");
405 // Merge via JDL
406    plugin->SetMergeViaJDL(useMergeViaJDL);
407 // Use fastread option
408    plugin->SetFastReadOption(useFastReadOption);
409 // UseOverwrite mode
410    plugin->SetOverwriteMode(useOverwriteMode);   
411 /*********************************************************
412  ***     PROOF MODE SPECIFIC SETTINGS         ************
413  *********************************************************/
414 // Proof cluster
415 //   plugin->SetProofCluster("alice-caf");
416    plugin->SetProofCluster("skaf.saske.sk");
417 // Dataset to be used   
418    plugin->SetProofDataSet("/alice/data/LHC10e_000128175_p1#esdTree");
419 // May need to reset proof. Supported modes: 0-no reset, 1-soft, 2-hard
420    plugin->SetProofReset(0);
421 // May limit number of workers
422    plugin->SetNproofWorkers(20);   
423 // May use a specific version of root installed in proof
424    plugin->SetRootVersionForProof("current_dbg");
425 // May set the aliroot mode. Check http://aaf.cern.ch/node/83 
426    plugin->SetAliRootMode("ALIROOT"); // Loads AF libs by default
427 // May request ClearPackages (individual ClearPackage not supported)
428    plugin->SetClearPackages(kFALSE);
429 // Plugin test mode works only providing a file containing test file locations
430    plugin->SetFileForTestMode(gSystem->ExpandPathName("$ALICE_ROOT/PWG1/PilotTrain/files.txt"));
431    return plugin;
432 }