TENDER becomes Tender, removing .so
[u/mrichter/AliRoot.git] / PWGCF / FLOW / macros / runFlowTaskCentralityPIDMHTrain.C
1 enum anaModes {mLocal,mPROOF,mGrid};
2 Int_t binfirst = 0;  //where do we start numbering bins
3 Int_t binlast = 8;  //where do we stop numbering bins
4 const Int_t numberOfCentralityBins = 9;
5 Float_t centralityArray[numberOfCentralityBins+1] = {0.,5.,10.,20.,30.,40.,50.,60.,70.,80.}; // in centrality percentile
6 //Int_t centralityArray[numberOfCentralityBins+1] = {41,80,146,245,384,576,835,1203,1471,10000}; // in terms of TPC only reference multiplicity
7
8 TString commonOutputFileName = "outputCentrality"; // e.g.: result for centrality bin 0 will be in the file "outputCentrality0.root", etc
9 Int_t centralitysel = AliVEvent::kMB | AliVEvent::kCentral | AliVEvent::kSemiCentral;
10
11 void runFlowTaskCentralityPIDMHTrain( Int_t mode = mLocal,
12                                       Bool_t useFlowParFiles = kFALSE,
13                                       Bool_t DATA = kTRUE,
14                                       const Char_t* dataDir="fileList",
15                                       Int_t nEvents = 1e4,
16                                       Int_t offset=0 ) {
17   // Time:
18   TStopwatch timer;
19   timer.Start();
20   
21   // Load needed libraries:
22   LoadLibraries(mode,useFlowParFiles);
23
24   // Create analysis manager:
25   AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
26
27   // Chains:
28   if(mode == mLocal) {
29     TChain *chain = new TChain("aodTree");
30     TString filename;
31     for(Int_t i = 1; i < 10; i++) {
32       filename = "/glusterfs/alice1/alice2/pchrist/HeavyIons/Data/2011/Set";
33       filename += i; filename += "/AliAOD.root";
34       chain->Add(filename.Data());
35     }
36   }
37
38   // Connect plug-in to the analysis manager:
39   if(mode == mGrid)
40   {
41     gROOT->LoadMacro("CreateAlienHandler.C");
42     AliAnalysisGrid *alienHandler = CreateAlienHandler(useFlowParFiles);
43     if(!alienHandler) return;
44     mgr->SetGridHandler(alienHandler);
45   }
46
47   // Event handlers:
48   AliVEventHandler* aodH = new AliAODInputHandler;
49   mgr->SetInputEventHandler(aodH);
50   if (!DATA)
51   {
52     AliMCEventHandler *mc = new AliMCEventHandler();
53     mgr->SetMCtruthEventHandler(mc);
54   }
55
56   // Task to check the offline trigger:
57   //gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
58   //AddTaskPhysicsSelection(!DATA);
59
60   //Add the centrality determination task
61   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
62   AliCentralitySelectionTask* centSelTask = AddTaskCentrality();
63   if (!DATA) centSelTask->SetMCInput();
64
65   //add the PID response task
66   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
67   AliAnalysisTaskPIDResponse* pidresponsetask = AddTaskPIDResponse(DATA);
68
69   //Add the TOF tender
70   //gROOT->LoadMacro("$ALICE_ROOT/PWGCF/FLOW/macros/AddTaskTenderTOF.C");
71   //AddTaskTenderTOF();
72
73   // Setup analysis per centrality bin:
74   //gROOT->LoadMacro("$ALICE_ROOT/PWGCF/FLOW/macros/AddTaskFlowCentralityPIDMH.C");
75   gROOT->LoadMacro("AddTaskFlowCentralityPIDMH.C");
76   for (Int_t i=binfirst; i<binlast+1; i++) {
77     Float_t lowCentralityBinEdge = centralityArray[i];
78     Float_t highCentralityBinEdge = centralityArray[i+1];
79     AddTaskFlowCentralityPIDMH(centralitysel,
80                                lowCentralityBinEdge,
81                                highCentralityBinEdge,
82                                kTRUE,
83                                AliPID::kPion,
84                                AliFlowTrackCuts::kTOFbayesian,
85                                0,1,768,
86                                2,kFALSE,
87                                "PbPb",
88                                commonOutputFileName);
89   } // end of for (Int_t i=0; i<numberOfCentralityBins; i++)
90
91   // Enable debug printouts:
92   mgr->SetDebugLevel(2);
93   // Run the analysis:
94   if(!mgr->InitAnalysis()) return;
95   mgr->PrintStatus();
96   if(mode == mLocal)
97   {
98     mgr->StartAnalysis("local",chain);
99   }
100   else if(mode == mPROOF)
101   {
102     mgr->StartAnalysis("proof",dataDir,nEvents,offset);
103   }
104   else if(mode == mGrid)
105   {
106     mgr->StartAnalysis("grid");
107   }
108
109   // Print real and CPU time used for analysis:
110   timer.Stop();
111   timer.Print();
112
113 } // end of void runFlowTaskCentralityPIDTrain(...)
114
115 //===============================================================================================
116 /*
117 void CrossCheckUserSettings(Bool_t bData)
118 {
119  // Check in this method if the user settings make sense.
120  if(LYZ1SUM && LYZ2SUM) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
121  if(LYZ1PROD && LYZ2PROD) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
122  if(LYZ2SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
123  if(LYZ1SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
124 } // end of void CrossCheckUserSettings()
125 */
126 //===============================================================================================
127
128 void LoadLibraries(const anaModes mode, Bool_t useFlowParFiles )
129 {
130   //--------------------------------------
131   // Load the needed libraries most of them already loaded by aliroot
132   //--------------------------------------
133
134   gSystem->Load("libCore");
135   gSystem->Load("libTree");
136   gSystem->Load("libGeom");
137   gSystem->Load("libVMC");
138   gSystem->Load("libXMLIO");
139   gSystem->Load("libPhysics");
140   gSystem->Load("libXMLParser");
141   gSystem->Load("libProof");
142   gSystem->Load("libMinuit");
143
144   if (mode==mLocal || mode==mGrid)
145   {
146     gSystem->Load("libSTEERBase");
147     gSystem->Load("libCDB");
148     gSystem->Load("libRAWDatabase");
149     gSystem->Load("libRAWDatarec");
150     gSystem->Load("libESD");
151     gSystem->Load("libAOD");
152     gSystem->Load("libSTEER");
153     gSystem->Load("libANALYSIS");
154     gSystem->Load("libANALYSISalice");
155     gSystem->Load("libTPCbase");
156     gSystem->Load("libTOFbase");
157     gSystem->Load("libTOFrec");
158     gSystem->Load("libTRDbase");
159     gSystem->Load("libVZERObase");
160     gSystem->Load("libVZEROrec");
161     gSystem->Load("libT0base");
162     gSystem->Load("libT0rec");
163     gSystem->Load("libTender");
164     gSystem->Load("libTenderSupplies");
165
166     if (useFlowParFiles)
167     {
168       AliAnalysisAlien::SetupPar("PWGflowBase");
169       AliAnalysisAlien::SetupPar("PWGflowTasks");
170     }
171     else
172     {
173       gSystem->Load("libPWGflowBase");
174       gSystem->Load("libPWGflowTasks");
175     }
176   }
177   else if (mode==mPROOF)
178   {
179     TList* list = new TList();
180     list->Add(new TNamed("ALIROOT_MODE", "ALIROOT"));
181     if (useFlowParFiles)
182       list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "ANALYSIS:ANALYSISalice:Tender:TenderSupplies"));
183     else
184       list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "ANALYSIS:ANALYSISalice:Tender:TenderSupplies:PWGflowBase:PWGflowTasks"));
185
186     //list->Add(new TNamed("ALIROOT_EXTRA_INCLUDES","PWG/FLOW/Base:PWG/FLOW/Tasks"));
187
188     // Connect to proof
189     printf("*** Connect to PROOF ***\n");
190     gEnv->SetValue("XSec.GSI.DelegProxy","2");
191     //TProof* proof = TProof::Open("alice-caf.cern.ch");
192     TProof* proof = TProof::Open("skaf.saske.sk");
193
194     // list the data available
195     //gProof->ShowDataSets("/*/*");
196     //gProof->ShowDataSets("/alice/sim/"); //for MC Data
197     //gProof->ShowDataSets("/alice/data/"); //for REAL Data
198
199     proof->ClearPackages();
200     proof->EnablePackage("VO_ALICE@AliRoot::v4-21-14-AN",list);
201
202     if (useFlowParFiles)
203     {
204       gProof->UploadPackage("PWGflowBase.par");
205       gProof->UploadPackage("PWGflowTasks.par");
206     }
207
208     // Show enables Packages
209     gProof->ShowEnabledPackages();
210   }
211 } // end of void LoadLibraries(const anaModes mode)
212
213 //===============================================================================================
214
215 TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
216 {
217   // creates chain of files in a given directory or file containing a list.
218   // In case of directory the structure is expected as:
219   // <aDataDir>/<dir0>/AliAOD.root
220   // <aDataDir>/<dir1>/AliAOD.root
221   // ...
222
223   if (!aDataDir)
224     return 0;
225
226   Long_t id, size, flags, modtime;
227   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
228   {
229     printf("%s not found.\n", aDataDir);
230     return 0;
231   }
232
233   TChain* chain = new TChain("aodTree");
234   TChain* chaingAlice = 0;
235
236   if (flags & 2)
237   {
238     TString execDir(gSystem->pwd());
239     TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
240     TList* dirList            = baseDir->GetListOfFiles();
241     Int_t nDirs               = dirList->GetEntries();
242     gSystem->cd(execDir);
243
244     Int_t count = 0;
245
246     for (Int_t iDir=0; iDir<nDirs; ++iDir)
247     {
248       TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
249       if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
250         continue;
251
252       if (offset > 0)
253       {
254         --offset;
255         continue;
256       }
257
258       if (count++ == aRuns)
259         break;
260
261       TString presentDirName(aDataDir);
262       presentDirName += "/";
263       presentDirName += presentDir->GetName();
264       chain->Add(presentDirName + "/AliAOD.root/aodTree");
265       // cerr<<presentDirName<<endl;
266     }
267
268   }
269   else
270   {
271     // Open the input stream
272     ifstream in;
273     in.open(aDataDir);
274
275     Int_t count = 0;
276
277     // Read the input list of files and add them to the chain
278     TString aodfile;
279     while(in.good())
280     {
281       in >> aodfile;
282       if (!aodfile.Contains("root")) continue; // protection
283
284       if (offset > 0)
285       {
286         --offset;
287         continue;
288       }
289
290       if (count++ == aRuns)
291         break;
292
293       // add aod file
294       chain->Add(aodfile);
295     }
296
297     in.close();
298   }
299
300   return chain;
301
302 } // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
303