Split: fix refs to AddTaskPhysicsSelection.C
[u/mrichter/AliRoot.git] / PWGPP / macros / RunAnalysisITS.C
CommitLineData
76bd0732 1class AliAnalysisGrid;
2
b7fb742d 3void RunAnalysisITS(TString pluginmode="",Int_t firstrun=177173,Int_t lastrun=177173,
d20d53fc 4 Bool_t readMC=kFALSE,
b7fb742d 5 Bool_t runAlign=kFALSE,
6 Bool_t runITS=kFALSE,
d20d53fc 7 Bool_t runImpPar=kTRUE,
8 Bool_t runVtx=kFALSE,
9 Bool_t runSPD=kFALSE)
10{
76bd0732 11 //
12 // Macro to analyze ESDs from raw data reconstruction
13 // A.Dainese, andrea.dainese@pd.infn.it
14 //
15
16 gSystem->SetIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT -I$ALICE_ROOT/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TPC -I$ALICE_ROOT/CONTAINERS -I$ALICE_ROOT/STEER -I$ALICE_ROOT/TRD -I$ALICE_ROOT/macros -I$ALICE_ROOT/ANALYSIS -g");
17
18 //
d20d53fc 19 TString analysisMode = "grid"; // "local", "grid", or "proof" (not yet)
76bd0732 20
21 Long64_t nentries=1000000000000000,firstentry=0;
b7fb742d 22 Bool_t useAlienPlugin=kFALSE;
23 Bool_t uselibPWGPP=kTRUE;
24 TString loadMacroPath="./";
76bd0732 25 Bool_t readHLT=kFALSE;
26 //
27
28 if(analysisMode=="grid") {
29 // Connect to AliEn
30 TGrid::Connect("alien://");
31 } else if(analysisMode=="proof") {
32 // Connect to the PROOF cluster
33 printf("PROOF mode not yet functional..\n");
34 return;
35 TProof::Open("alicecaf");
36 //TProof::Reset("alicecaf");
37 }
38
39 // Load analysis libraries
4070f709 40 gSystem->Load("libANALYSIS");
41 gSystem->Load("libANALYSISalice");
b0635849 42 if(uselibPWGPP) {gSystem->Load("libTender");gSystem->Load("libPWGPP");}
62b52cbf 43
76bd0732 44 // Create Alien plugin, if requested
45 if(useAlienPlugin) {
2bfe5463 46 AliAnalysisGrid *alienHandler = CreateAlienHandler(pluginmode,uselibPWGPP,firstrun,lastrun);
76bd0732 47 if(!alienHandler) return;
48 }
49
50 TChain *chainESD = 0;
51 if(!useAlienPlugin) {
52 // Prepare input chain
d20d53fc 53 // chainESD = CreateESDChain("/home/dainesea/alignData/RAWdata_CosmicsSum09/RecoSPD/chunk.",13,13);
54 chainESD=new TChain("esdTree");
62b52cbf 55 //chainESD->Add("alien:///alice/cern.ch/user/s/sitta/output/000088361/ESDs/pass1/09000088361017.10/AliESDs.root");
d20d53fc 56 chainESD->Add("AliESDs.root");
76bd0732 57 }
58
59 // Create the analysis manager
60 AliAnalysisManager *mgr = new AliAnalysisManager("My Manager","My Manager");
61 // Enable debug printouts
62 mgr->SetDebugLevel(10);
63 // Connect plug-in to the analysis manager
64 if(useAlienPlugin) mgr->SetGridHandler(alienHandler);
65
66 // Add ESD handler
d20d53fc 67 Bool_t readRP=kFALSE;
4f8ced9e 68 AliESDInputHandler *esdH = 0;
69 if(readRP) {
70 esdH = new AliESDInputHandlerRP();
71 } else {
72 esdH = new AliESDInputHandler();
73 }
b900a060 74 esdH->SetActiveBranches("ESDfriend");
cde6f9ef 75 esdH->SetReadFriends(1);
76bd0732 76 if(readHLT) esdH->SetReadHLT();
77 mgr->SetInputEventHandler(esdH);
d20d53fc 78 if(readMC) {
79 AliMCEventHandler *mcH = new AliMCEventHandler();
80 mgr->SetMCtruthEventHandler(mcH);
81 }
82 //-------------------------------------------------------------------
83
76bd0732 84
85 //-------------------------------------------------------------------
86 // Analysis tasks (wagons of the train)
87 //
88 TString taskName;
d20d53fc 89
90 if(runAlign) {
2bfe5463 91 if(!uselibPWGPP) gROOT->LoadMacro("AliAlignmentDataFilterITS.cxx++g");
d20d53fc 92 taskName="AddTaskAlignmentDataFilterITS.C";
93 taskName.Prepend(loadMacroPath.Data());
94 gROOT->LoadMacro(taskName.Data());
95 AliAlignmentDataFilterITS *alignTask = AddTaskAlignmentDataFilterITS();
96 }
97 if(runITS) {
2bfe5463 98 if(!uselibPWGPP) gROOT->LoadMacro("AliAnalysisTaskITSTrackingCheck.cxx++g");
d20d53fc 99 taskName="AddTaskPerformanceITS.C";
100 taskName.Prepend(loadMacroPath.Data());
101 gROOT->LoadMacro(taskName.Data());
b7fb742d 102 AliAnalysisTaskITSTrackingCheck *itsTask = AddTaskPerformanceITS(readMC,kFALSE,kFALSE,0,1000000,1);
d20d53fc 103 }
104 if(runImpPar) {
2bfe5463 105 if(!uselibPWGPP) gROOT->LoadMacro("AliAnalysisTaskSEImpParRes.cxx++g");
d20d53fc 106 taskName="AddTaskImpParRes.C";
107 taskName.Prepend(loadMacroPath.Data());
108 gROOT->LoadMacro(taskName.Data());
b7fb742d 109 AliAnalysisTaskSEImpParRes *d0Task = AddTaskImpParRes(readMC,-1,kFALSE,kFALSE,0,1000000,0);
d20d53fc 110 }
111 if(runVtx) {
2bfe5463 112 if(!uselibPWGPP) gROOT->LoadMacro("AliAnalysisTaskVertexESD.cxx++g");
d20d53fc 113 taskName="AddTaskVertexESD.C";
114 taskName.Prepend(loadMacroPath.Data());
115 gROOT->LoadMacro(taskName.Data());
116 AliAnalysisTaskVertexESD *vtxTask = AddTaskVertexESD(readMC);
117 }
118 if(runSPD) {
2bfe5463 119 if(!uselibPWGPP) gROOT->LoadMacro("AliAnalysisTaskSPD.cxx++g");
d20d53fc 120 taskName="AddTaskSPDQA.C";
2bfe5463 121 taskName.Prepend("$ALICE_ROOT/PWGPP/PilotTrain/");
d20d53fc 122 gROOT->LoadMacro(taskName.Data());
123 AliAnalysisTaskSPD *spdTask = AddTaskSPDQA();
124 }
125 /*
2bfe5463 126 if(!uselibPWGPP) gROOT->LoadMacro("AliTrackMatchingTPCITSCosmics.cxx++g");
76bd0732 127 taskName="AddTaskTrackMatchingTPCITS.C";
128 taskName.Prepend(loadMacroPath.Data());
129 gROOT->LoadMacro(taskName.Data());
130 AliTrackMatchingTPCITSCosmics *tpcitsTask = AddTaskTrackMatchingTPCITS();
131 if(readHLT) tpcitsTask->SetReadHLTESD(kTRUE);
4f8ced9e 132 */
1b65f728 133
4f8ced9e 134
d20d53fc 135 // Apply the event selection
63b6cbd0 136 gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskPhysicsSelection.C");
d20d53fc 137 Bool_t bkgRej=kTRUE;
b7fb742d 138 //AliPhysicsSelectionTask *physSelTask = AddTaskPhysicsSelection(readMC,bkgRej);
d20d53fc 139
140
76bd0732 141 //
142 // Run the analysis
143 //
144 if(chainESD) printf("CHAIN HAS %d ENTRIES\n",(Int_t)chainESD->GetEntries());
145
146 if(!mgr->InitAnalysis()) return;
147 mgr->PrintStatus();
148 if(analysisMode=="grid" && !useAlienPlugin) analysisMode="local";
149 mgr->StartAnalysis(analysisMode.Data(),chainESD,nentries,firstentry);
150
151 return;
152}
153//_____________________________________________________________________________
154//
62b52cbf 155AliAnalysisGrid* CreateAlienHandler(TString pluginmode="test",
2bfe5463 156 Bool_t uselibPWGPP=kFALSE,
d20d53fc 157 Int_t firstrun,Int_t lastrun)
76bd0732 158{
159 // Check if user has a valid token, otherwise make one. This has limitations.
160 // One can always follow the standard procedure of calling alien-token-init then
161 // source /tmp/gclient_env_$UID in the current shell.
162 if (!AliAnalysisGrid::CreateToken()) return NULL;
163 AliAnalysisAlien *plugin = new AliAnalysisAlien();
164 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
165 plugin->SetRunMode(pluginmode.Data());
166 plugin->SetUser("dainesea");
167 plugin->SetNtestFiles(1);
168 // Set versions of used packages
d20d53fc 169 plugin->SetAPIVersion("V1.1x");
170 plugin->SetROOTVersion("v5-26-00b-6");
171 plugin->SetAliROOTVersion("v4-19-15-AN");
172 // Define alien work directory where all files will be copied. Relative to alien $HOME.
173 TString wdname="analysisITS_Runs_";
174 wdname+=firstrun;
175 wdname.Append("_");
176 wdname+=lastrun;
177 plugin->SetGridWorkingDir(wdname.Data());
178 // Declare alien output directory. Relative to working directory.
179 plugin->SetGridOutputDir("output"); // In this case will be $HOME/work/output
76bd0732 180 // Declare input data to be processed.
181 // Method 1: Create automatically XML collections using alien 'find' command.
182 // Define production directory LFN
d20d53fc 183 plugin->SetGridDataDir("/alice/data/2010/LHC10b");
76bd0732 184 // Set data search pattern
d20d53fc 185 plugin->SetDataPattern("pass2/*AliESDs.root");
186 //plugin->SetDataPattern("ESD.tag.root");
62b52cbf 187 Int_t n=0;
d20d53fc 188 FILE *in = fopen("/home/dainesea/alignData/RAWdata_pp10/goodruns_pp10.txt","r");
189 if(!in) printf("run file not found\n");
190 Int_t lines=0;
191 Float_t runnumber;
192 while(1) {
193 Int_t ncol = fscanf(in,"%f",&runnumber);
194 if(ncol<1) break;
195 if(runnumber<firstrun || runnumber>lastrun) continue;
196 TString runnumberstring="000";
197 Int_t runnumberint=(Int_t)runnumber;
198 runnumberstring+=runnumberint;
199 n++; plugin->AddRunNumber(runnumberstring.Data());
200 }
201 fclose(in);
62b52cbf 202 plugin->SetNrunsPerMaster(n);
76bd0732 203 // Method 2: Declare existing data files (raw collections, xml collections, root file)
204 // If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
205 // XML collections added via this method can be combined with the first method if
206 // the content is compatible (using or not tags)
207 // e.g.: find -z -x 80015 /alice/data/2009/LHC09c/000080015/ESDs/ ESD.tag.root > 80015.xml
208 //plugin->AddDataFile("79876.xml");
62b52cbf 209 //plugin->AddDataFile("80015.xml");
76bd0732 210 //plugin->AddDataFile("80261.xml");
211 // plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
76bd0732 212 // Declare the analysis source files names separated by blancs. To be compiled runtime
213 // using ACLiC on the worker nodes.
2bfe5463 214 if(!uselibPWGPP) {
d20d53fc 215 plugin->SetAnalysisSource("AliAnalysisTaskITSTrackingCheck.cxx AliAlignmentDataFilterITS.cxx AliAnalysisTaskSEImpParRes.cxx AliAnalysisTaskVertexESD.cxx");
216 //plugin->SetAnalysisSource("AliAnalysisTaskVertexESD.cxx");
217 //plugin->SetAnalysisSource("AliAlignmentDataFilterITS.cxx");
218 //plugin->SetAnalysisSource("AliTrackMatchingTPCITSCosmics.cxx");
62b52cbf 219 }
76bd0732 220 // Declare all libraries (other than the default ones for the framework. These will be
221 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
222 //plugin->SetAdditionalLibs("AliAlignmentDataFilterITS.h AliAlignmentDataFilterITS.cxx libProof.so libRAWDatabase.so libRAWDatarec.so libCDB.so libSTEER.so libITSbase.so libITSrec.so");
76bd0732 223 plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT -I$ALICE_ROOT/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TPC -I$ALICE_ROOT/CONTAINERS -I$ALICE_ROOT/STEER -I$ALICE_ROOT/TRD -I$ALICE_ROOT/macros -I$ALICE_ROOT/ANALYSIS -g");
2bfe5463 224 if(!uselibPWGPP) {
d20d53fc 225 //plugin->SetAdditionalLibs("AliAlignmentDataFilterITS.h AliAlignmentDataFilterITS.cxx libProof.so libRAWDatabase.so libRAWDatarec.so libCDB.so libSTEER.so libITSbase.so libITSrec.so");
226 plugin->SetAdditionalLibs("AliAlignmentDataFilterITS.h AliAlignmentDataFilterITS.cxx AliAnalysisTaskITSTrackingCheck.h AliAnalysisTaskITSTrackingCheck.cxx AliAnalysisTaskSEImpParRes.h AliAnalysisTaskSEImpParRes.cxx AliAnalysisTaskVertexESD.h AliAnalysisTaskVertexESD.cxx libGui.so libProof.so libRAWDatabase.so libRAWDatarec.so libCDB.so libSTEER.so libITSbase.so libITSrec.so");
227 //plugin->SetAdditionalLibs("AliAnalysisTaskVertexESD.h AliAnalysisTaskVertexESD.cxx libProof.so libRAWDatabase.so libRAWDatarec.so libCDB.so libSTEER.so libITSbase.so libITSrec.so");
62b52cbf 228 } else {
af472fff 229 plugin->SetAdditionalLibs("libGui.so libProof.so libMinuit.so libRAWDatabase.so libRAWDatarec.so libCDB.so libSTEER.so libITSbase.so libITSrec.so libTPCbase.so libTPCrec.so libTRDbase.so libTRDrec.so libTender.so libPWGPP.so");
62b52cbf 230 }
76bd0732 231 // Declare the output file names separated by blancs.
232 // (can be like: file.root or file.root@ALICE::Niham::File)
233 plugin->SetDefaultOutputs(kTRUE);
234 // Optionally define the files to be archived.
235 // plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:*.root@ALICE::NIHAM::File");
236 plugin->SetOutputArchive("log_archive.zip:stdout,stderr");
237 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
238 plugin->SetAnalysisMacro("AnalysisITS.C");
d20d53fc 239 plugin->SetExecutable("analysisITS.sh");
240 plugin->SetExecutableCommand("root.exe -b -q");
76bd0732 241 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
d20d53fc 242 plugin->SetSplitMaxInputFileNumber(5);
76bd0732 243 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
244 //plugin->SetMaxInitFailed(5);
245 // Optionally resubmit threshold.
246 //plugin->SetMasterResubmitThreshold(90);
247 // Optionally set time to live (default 30000 sec)
d20d53fc 248 plugin->SetTTL(80000);
76bd0732 249 // Optionally set input format (default xml-single)
250 plugin->SetInputFormat("xml-single");
251 // Optionally modify the name of the generated JDL (default analysis.jdl)
252 plugin->SetJDLName("TaskAnalysisITS.jdl");
253 // Optionally modify job price (default 1)
254 //plugin->SetPrice(1);
255 // Optionally modify split mode (default 'se')
256 plugin->SetSplitMode("se");
257 // Optionally set the preferred SE
258 plugin->SetPreferedSE("ALICE::CNAF::SE");
259
260 return plugin;
261}
262//-----------------------------------------------------------------------------
263TChain *CreateESDChain(TString esdpath=".",Int_t ifirst=-1,Int_t ilast=-1) {
264
265
266 TChain *chainESD = new TChain("esdTree");
267
268 if(ifirst<0) {
269 chainESD->Add("AliESDs.root");
270 } else {
271 for(Int_t i=ifirst; i<=ilast; i++) {
272 TString esdfile=esdpath; esdfile+=i; esdfile.Append("/AliESDs.root");
273 chainESD->Add(esdfile.Data());
274 }
275 }
276
277 return chainESD;
278}