]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/PWGPPmacros/runPWGPPTrain.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGPP / PWGPPmacros / runPWGPPTrain.C
1 /*
2   Macros to run PWGPP train:
3   
4   void runPWGPPTrain(const char *macros = "AddTask*.C", const char *fname="AliESDs.root");
5   //Parameters:
6   //    macros: run the train for selected tasks
7   //            tasks are expected to be in the working  directory
8   //    fname : name of the input file or input list
9
10
11   .L $ALICE_ROOT/PWGPP/PWGPPmacros/runPWGPPTrain.C
12
13
14 */
15
16 void LoadTrainLibs(){
17   //
18   // load libraries needed for train
19   //
20   gSystem->SetIncludePath("-I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT -I$ALICE_ROOT/TRD -I$ALICE_ROOT/PWGPP/TRD/macros/ ");
21   gSystem->Load("libANALYSIS");
22   gSystem->Load("libANALYSISalice");
23   gSystem->Load("libTender");
24   gSystem->Load("libCORRFW");
25   gSystem->Load("libPWG0base");
26   gSystem->Load("libPWG0dep");
27   gSystem->Load("libPWG0selectors");
28   gSystem->Load("libPWGPP");
29   gSystem->Load("libPWG2");
30   gSystem->Load("libPWGmuon");
31   gSystem->Load("libPWGmuondep");
32   gSystem->Load("libPWG2forward");
33   gSystem->Load("libPWG4PartCorrBase");
34   gSystem->Load("libPWG4PartCorrDep");
35 }
36
37 void TestConfig(){
38
39 }
40
41 void AddMacros(const char *addmacros){
42   //
43   // add tasks from selected macros - * convention can be used
44   // Macro expected to be in the working directory
45   // Macros has to be without arguments
46   //
47   //
48   TString  macroList = gSystem->GetFromPipe(Form("cat ConfigTask.txt |grep  %s",addmacros));  
49   TObjArray * array  = macroList.Tokenize("\n");
50
51   if (!array) { printf("No task specified"); return;}
52   if (array->GetEntries()==0) {
53     printf("Empty list of tasks"); 
54     return;
55   }
56   for (Int_t itask=0; itask<array->GetEntries(); itask++){
57     gROOT->Macro(array->At(itask)->GetName());    
58   }
59 }
60
61 void AddToChain(TChain * chain, TString inputList){
62   //
63   // add the files form inputList into chain
64   //
65   ifstream in;
66   in.open(inputList.Data());
67   Int_t counter=0; 
68   TString currentFile;
69   while(in.good()) {
70     in >> currentFile;
71     if (!currentFile.Contains(".root")) continue;
72     chain->Add(currentFile.Data());
73     printf("%d\t%s\n",counter,currentFile.Data()); 
74     counter++;
75   }
76 }
77
78 void PrintSysInfo(){
79   //
80   // print sysinfo
81   //
82   TF1 f1("f1","pol1");
83   TTree * tree = AliSysInfo::MakeTree("syswatch.log");
84   Int_t entries=0;
85   TGraph *gr = 0;
86   entries=tree->Draw("VM:id0","id0>10","goff");
87   gr=new TGraph(entries, tree->GetV2(),tree->GetV1());
88   gr->Fit(&f1);
89   gr->Draw("alp");
90   printf("SysInfoMem:\t%f\n",f1->GetParameter(1));
91   //
92   entries=tree->Draw("T:id0","id0>10","goff");
93   gr=new TGraph(entries, tree->GetV2(),tree->GetV1());
94   gr->Fit(&f1);
95   gr->Draw("alp");
96   printf("SysInfoTime:\t%f\n",f1->GetParameter(1));
97 }
98
99 void runPWGPPTrain(const char *macros = "AddTask*.C", TString inputList ="esd.list", Int_t debugLevel=0) {
100   //Parameters:
101   //    macros: run the train for selected tasks
102   //            tasks are expected to be in the working  directory
103   //    fname : name of the input file or input list
104   TStopwatch timer;
105   timer.Start();
106   LoadTrainLibs();
107
108   //____________________________________________
109   // Make the analysis manager
110   //
111   AliAnalysisManager *mgr = new AliAnalysisManager("TestManager");
112   mgr->SetDebugLevel(debugLevel);
113   
114   AliInputEventHandler* esdH = new AliESDInputHandlerRP();
115   esdH->SetActiveBranches("ESDfriend");
116   mgr->SetInputEventHandler(esdH);  
117   //
118   // make chain
119   //
120   TChain* chain = new TChain("esdTree");
121   if (inputList.Contains(".root")){
122     chain->AddFile(inputList);
123   }
124   if (inputList.Contains(".list")){
125     AddToChain(chain, inputList);
126   }
127   chain->Lookup();
128   //
129   //
130   // Init
131   AddMacros(macros);
132   mgr->SetNSysInfo(1000);
133   if (!mgr->InitAnalysis()) 
134     mgr->PrintStatus();
135   mgr->PrintStatus();
136   // Run on dataset
137   //
138   mgr->StartAnalysis("local", chain);
139   PrintSysInfo();
140
141   timer.Stop();
142   timer.Print();
143 }
144