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