]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/makeSelectorNMLYZ.C
Macros for Lee Yang Zeroes from Naomi van der Kolk
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / makeSelectorNMLYZ.C
1 ///////////////////////////////////////////////////////////////////////////////
2 // macro to run AliSelectorLYZNewMethod for LYZ analysis on ESDs             //
3 // Make sure that the input files are available:
4 // "fof_flowLYZAnal_firstrun.root" from the first run of AliSelectorLYZ.C and
5 // "fof_flowLYZAnal_secondrun.root" from the second run of AliSelectorLYZ.C(0)
6 //
7 // (this dependence on input files will change at some point)                //
8 ///////////////////////////////////////////////////////////////////////////////
9
10
11 // from CreateESDChain.C - instead of  #include "CreateESDChain.C"
12 TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20, Int_t offset = 0) ;
13 void LookupWrite(TChain* chain, const char* target) ;
14
15
16
17 void makeSelectorNMLYZ(const Char_t* dataDir="/data/alice1/simili/lcgHijing/4", Int_t nRuns = 1, Int_t offset = 0)
18
19
20
21 {
22  // include path (to find the .h files when compiling)
23  gSystem->AddIncludePath("-I$ALICE_ROOT/include") ;
24  gSystem->AddIncludePath("-I$ROOTSYS/include") ;
25  gSystem->AddIncludePath("-I$ALICE_ROOT/PWG2/FLOW") ;
26
27  // load needed libraries
28  gSystem->Load("libESD");
29   
30  // Flow libraries 
31  gSystem->Load("libPWG2flow.so");
32  gROOT->LoadMacro("AliFlowLYZConstants.cxx+");
33  gROOT->LoadMacro("AliSelectorLYZNewMethod.cxx+");
34  
35  // create the TChain. CreateESDChain() is defined in CreateESDChain.C
36  TChain* chain = CreateESDChain(dataDir, nRuns, offset);
37  cout << " * " << chain->GetEntries() << " * " << endl ;
38
39  // enable debugging
40  AliLog::SetClassDebugLevel("AliSelectorLYZ", AliLog::kInfo);
41
42  // run selector on chain
43  AliSelectorLYZNewMethod* selector = new AliSelectorLYZNewMethod; //create new selector object
44  Long64_t result = chain->Process(selector);    //proces the selector on the chain of data
45   
46  if (result != 0)  {
47    cout<<"ERROR: Executing process failed with "<<result<<endl;
48    return; }
49
50  cout<<"Execution complete."<<endl<<endl;
51  delete selector;
52 }
53
54 // Helper macros for creating chains
55 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
56
57 TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
58 {
59   // creates chain of files in a given directory or file containing a list.
60   // In case of directory the structure is expected as:
61   // <aDataDir>/<dir0>/AliESDs.root
62   // <aDataDir>/<dir1>/AliESDs.root
63   // ...
64
65   if (!aDataDir)
66     return 0;
67
68   Long_t id, size, flags, modtime;
69   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
70   {
71     printf("%s not found.\n", aDataDir);
72     return 0;
73   }
74
75   TChain* chain = new TChain("esdTree");
76   TChain* chaingAlice = 0;
77
78   if (flags & 2)
79   {
80     TString execDir(gSystem->pwd());
81     TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
82     TList* dirList            = baseDir->GetListOfFiles();
83     Int_t nDirs               = dirList->GetEntries();
84     gSystem->cd(execDir);
85
86     Int_t count = 0;
87
88     for (Int_t iDir=0; iDir<nDirs; ++iDir)
89     {
90       TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
91       if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
92         continue;
93
94       if (offset > 0)
95       {
96         --offset;
97         continue;
98       }
99
100       if (count++ == aRuns)
101         break;
102
103       TString presentDirName(aDataDir);
104       presentDirName += "/";
105       presentDirName += presentDir->GetName();
106
107       chain->Add(presentDirName + "/AliESDs.root/esdTree");
108     }
109   }
110   else
111   {
112     // Open the input stream
113     ifstream in;
114     in.open(aDataDir);
115
116     Int_t count = 0;
117
118     // Read the input list of files and add them to the chain
119     TString esdfile;
120     while(in.good()) {
121       in >> esdfile;
122       if (!esdfile.Contains("root")) continue; // protection
123
124       if (offset > 0)
125       {
126         --offset;
127         continue;
128       }
129
130       if (count++ == aRuns)
131         break;
132
133         // add esd file
134       chain->Add(esdfile);
135     }
136
137     in.close();
138   }
139
140   return chain;
141 }
142
143 void LookupWrite(TChain* chain, const char* target)
144 {
145   // looks up the chain and writes the remaining files to the text file target
146
147   chain->Lookup();
148
149   TObjArray* list = chain->GetListOfFiles();
150   TIterator* iter = list->MakeIterator();
151   TObject* obj = 0;
152
153   ofstream outfile;
154   outfile.open(target);
155
156   while ((obj = iter->Next()))
157     outfile << obj->GetTitle() << "#AliESDs.root" << endl;
158
159   outfile.close();
160
161   delete iter;
162 }