Split: fix refs to AddTaskPhysicsSelection.C
[u/mrichter/AliRoot.git] / TOF / macrosQA / RunTOFqa.C
1 #include "Riostream.h"
2 class AliAnalysisAlien;
3
4 void LoadLibraries();
5 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode);
6
7 Int_t  iCollisionType = 0;
8 UInt_t kTriggerInt = AliVEvent::kAnyINT;
9 UInt_t kTriggerMuonAll = AliVEvent::kMUL7 | AliVEvent::kMUSH7 | AliVEvent::kMUU7 | AliVEvent::kMUS7;
10 UInt_t kTriggerMuonBarell = AliVEvent::kMUU7;
11 UInt_t kTriggerEMC = AliVEvent::kEMC7;
12 UInt_t kTriggerHM  = AliVEvent::kHighMult;
13 UInt_t kTriggerMask = kTriggerInt;
14 TString grid_datadir = "/alice/data/2011/LHC11h/";
15 TString data_pattern = "*ESDs/pass1_std/*ESDs.root";
16 Int_t runNumbers[5] = {166532};
17 Int_t debug_level = 1;        // Debugging
18
19 void RunTOFqa(const char* plugin_mode="full") {
20
21         // macro to run the TOF qa
22         gSystem->SetIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TRD -I$ALICE_ROOT/PWGPP");
23         //
24         TString trainName = "TOFqa";
25         TString analysisMode = "grid"; // "local", "grid", or "proof"
26         TString inputMode    = "list"; // "list", "xml", or "dataset"
27         Long64_t nentries=123567890,firstentry=0;
28         Bool_t saveProofToAlien=kFALSE;
29         TString proofOutdir = "";
30         if(analysisMode=="grid") {
31                 // Connect to AliEn
32                 TGrid::Connect("alien://");
33         } 
34         else if(analysisMode=="proof") {
35                 // Connect to the PROOF cluster
36                 if(inputMode!="dataset") {printf("Input mode must be dataset, for proof analysis\n"); return;}
37                 gEnv->SetValue("XSec.GSI.DelegProxy","2");
38                 TProof::Open("alicecaf");
39                 if(saveProofToAlien) {
40                         TGrid::Connect("alien://");
41                         if(gGrid) {
42                                 TString homedir = gGrid->GetHomeDirectory();
43                                 TString workdir = homedir + trainName;
44                                 if(!gGrid->Cd(workdir)) {
45                                         gGrid->Cd(homedir);
46                                         if(gGrid->Mkdir(workdir)) {
47                                                 gGrid->Cd(trainName);
48                                                 ::Info("TOFqa::Connect()", "Directory %s created", gGrid->Pwd());
49                                         }
50                                 }          
51                                 gGrid->Mkdir("proof_output");
52                                 gGrid->Cd("proof_output");
53                                 proofOutdir = Form("alien://%s", gGrid->Pwd());
54                         } 
55                 }
56         }
57         
58
59         // AliRoot libraries
60         if(analysisMode=="local" || analysisMode=="grid") {
61                 LoadLibraries();
62         } 
63         else if (analysisMode=="proof") {
64                 // do nothing now
65         }
66
67         if(analysisMode!="grid") {printf("Analysis mode must be grid, to use alien plugin\n"); return;}
68         AliAnalysisAlien *alienHandler = CreateAlienHandler(plugin_mode);  
69         if(!alienHandler) return;
70
71         // Create the analysis manager
72         AliAnalysisManager *mgr  = new AliAnalysisManager("My Manager","My Manager");
73         mgr->SetDebugLevel(10);
74
75         // Connect plug-in to the analysis manager
76         mgr->SetGridHandler(alienHandler);
77
78         // Handler
79         AliESDInputHandler *esdHandler = new AliESDInputHandler();
80         esdHandler->SetReadFriends(kFALSE);
81         mgr->SetInputEventHandler(esdHandler);
82         mgr->SetDebugLevel(debug_level);
83         if(saveProofToAlien) mgr->SetSpecialOutputLocation(proofOutdir);
84   
85         // Physics Selection
86         gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskPhysicsSelection.C");
87         AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kFALSE /*MC*/);
88
89         // TOF qa task
90         gROOT->LoadMacro("$ALICE_ROOT/PWGPP/TOF/AddTaskTOFQA.C");
91         AliAnalysisTaskTOFqa *tofQA = AddTaskTOFQA();
92         tofQA->SelectCollisionCandidates(kTriggerMask);
93
94         // run the analysis
95         if (mgr->InitAnalysis()) {                                                                                                              
96                 mgr->PrintStatus(); 
97                 if (!strcmp(analysisMode.Data(), "local")) {
98                         TChain* chain = new TChain("esdTree");
99                         chain->AddFile("/Users/Chiara/SOFT/MyAnalysis/TOF/QA_PbPb/OnGrid/AliESDs.root");
100                         Printf("The chain has %d entries",chain->GetEntries());
101                         mgr->StartAnalysis("local",chain);
102                 }
103                 else mgr->StartAnalysis("grid");
104         }
105   
106 }
107
108
109 void LoadLibraries()
110 {
111         Printf("Loading libs");
112         gSystem->Load("libANALYSIS");
113         gSystem->Load("libANALYSISalice");
114         gSystem->Load("libCORRFW");
115         gSystem->Load("libTender");
116         gSystem->Load("libPWG0base");
117         gSystem->Load("libPWG0dep");
118         gSystem->Load("libPWG0selectors");
119         gSystem->Load("libPWGPP");
120
121 }
122
123
124 //_____________________________________________________________________________
125 //
126 AliAnalysisAlien* CreateAlienHandler(const char* plugin_mode)
127 {
128
129         AliAnalysisAlien *plugin = new AliAnalysisAlien();
130         // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
131         plugin->SetRunMode(plugin_mode);
132         plugin->SetUser("zampolli");
133         plugin->SetNtestFiles(1);
134         // Set versions of used packages
135         plugin->SetAPIVersion("V1.1x");
136         plugin->SetROOTVersion("v5-30-03-1");
137         plugin->SetAliROOTVersion("v5-02-08-AN");
138         plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TRD");   
139         plugin->SetAdditionalLibs("libCORRFW.so libTender.so libPWG0base.so libPWG0dep.so libPWG0selectors.so libPWGPP.so");
140         // Declare input data to be processed.
141         plugin->SetGridDataDir(grid_datadir); // specify LHC period
142         plugin->SetDataPattern(data_pattern); // specify reco pass and AOD set
143         plugin->SetRunPrefix("000");
144         for (Int_t i=0; i<5; i++) {
145                 if (!runNumbers[i]) break;
146                 plugin->AddRunNumber(runNumbers[i]);
147         }   
148         plugin->SetNrunsPerMaster(1);
149         plugin->SetOutputToRunNo(1);
150    
151         plugin->SetGridWorkingDir("QATOF_1");
152         plugin->SetGridOutputDir("output"); // In this case will be $HOME/work/output
153         //plugin->SetAdditionalLibs();
154         plugin->SetDefaultOutputs(kTRUE);
155         plugin->SetAnalysisMacro("TOFqa_1.C");
156         plugin->SetExecutable("TOFqa_1.sh");
157         plugin->SetSplitMaxInputFileNumber(100);
158         plugin->SetInputFormat("xml-single");
159         plugin->SetJDLName("TOFqa_1.jdl");
160         plugin->SetSplitMode("se");
161         plugin->SetMergeViaJDL(kTRUE);
162         plugin->SetExecutableCommand("aliroot -b -q");
163         //plugin->SetOneStageMerging(kFALSE); // One can use this to force a single stage
164         plugin->SetMaxMergeStages(2); // adapt n to your expected number of files 
165         
166         return plugin;
167 }