]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/testKiner.C
namespace added for constants
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / testKiner.C
1 /////////////////////////////////////////////////////////////
2 //
3 // $Id$
4 //
5 // Author: Emanuele Simili
6 //
7 /////////////////////////////////////////////////////////////
8 //
9 // Description: AliRoot macro to make AliFlowEvents from KineTree (new way) 
10 //
11 /////////////////////////////////////////////////////////////
12
13 #include <vector>
14 #include <iostream>
15 #include <fstream>
16 #include "TMath.h"
17 #include "TFile.h"
18 #include "TObjArray"
19 #include "TStopwatch.h"
20
21 using namespace std; //required for resolving the 'cout' symbol
22
23 const char* aDataDir = "./" ; Int_t aRuns = -1 ; Int_t offset = 0 ;
24
25 //////////////////////////////////////////////////////////////////////////////////////////////////////
26
27 int testKiner(int cen = -1)
28 {
29  cout << " . Here the new flow kinemaker (2007 noRL) ... " << endl ;
30  cout << endl ;
31
32  int limit = -1 ;
33  if(limit>0)
34  {
35   cout << " . limited to " << limit << "events . " << endl ;
36   cout << endl ;
37  }
38  
39  // flowEvents file (output) //
40
41  TString output = "flowKevts" ;
42  if(cen >= 0) { output += cen ; }
43  output += ".root" ;
44  
45  // start, load libs //
46
47  TStopwatch timer;
48  timer.Start();
49
50  //gSystem->Load("libPhysics.so");
51  gSystem->Load("libPWG2flow.so");
52
53  // open output file //
54
55  TFile * fFlowfile = new TFile(output.Data(),"RECREATE") ;
56  //fFlowfile->cd() ; 
57
58  // flow maker //
59
60  AliFlowKineMaker * flowKiner = new  AliFlowKineMaker() ;
61  // cuts, etc.
62  flowKiner->SetAbsEtaCut(10.) ;
63  flowKiner->SetECut(0.001,100.) ;
64  //flowKiner->SetLabelCut(..,..) ;
65  flowKiner->SetPrimaryCut(kTRUE) ;
66  flowKiner->PrintCutList() ;
67
68  AliFlowEvent * flowEvt = 0 ;
69  Int_t count = 0 ;
70
71  // loop (folders) //
72
73  TString execDir(gSystem->pwd());
74  TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
75  TList* dirList            = baseDir->GetListOfFiles();
76  Int_t nDirs               = dirList->GetEntries();
77  gSystem->cd(execDir);
78  
79  for(Int_t iDir=0; iDir<nDirs; ++iDir)
80  {
81   TSystemFile* presentDir = (TSystemFile*)dirList->At(iDir) ;
82   if(!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0) 
83   {
84    cout << endl ; 
85    cout << "Directory (" << iDir << "):  " << presentDir->GetName() << " - Skipping ... " << endl ;
86    continue ;   
87   }
88   if(offset > 0)  { --offset ; continue ; }
89   if((aRuns > 0) && (count >= aRuns)) { break ; }
90  
91   TString presentDirName(aDataDir);
92   presentDirName += presentDir->GetName();
93   presentDirName += "/";
94
95   TString fileName = presentDirName ; 
96   fileName += "galice.root" ;
97   Long_t *id, *size, *flags, *modtime ;
98   if(gSystem->GetPathInfo(fileName.Data(),id,size,flags,modtime)) 
99   { 
100    cout << " File : " << fileName << " does NOT exist ! - Skipping ... " << endl ; 
101    continue ; 
102   }
103   cout << endl ; cout << "Directory (" << iDir << "):  " << presentDirName << "  ... " << endl ;
104
105  // loop (simulations in the present dir) //
106
107   TSystemDirectory* evtsDir = new TSystemDirectory(".", presentDirName.Data());
108   TList* fileList           = evtsDir->GetListOfFiles();
109   Int_t nFiles              = fileList->GetEntries();
110   gSystem->cd(execDir);
111
112   for(Int_t iFiles=0; iFiles<nFiles; ++iFiles)
113   {
114    TSystemFile* presentFile = (TSystemFile*) fileList->At(iFiles);
115
116    TString presentFileName(presentDirName);
117    presentFileName += presentFile->GetName();
118
119    if(!(presentFileName.Contains("Kinematics") && presentFileName.Contains("root"))) { continue ; }
120
121    cout << " found: " << presentFileName.Data() << endl ; 
122   
123    TFile* kineFile = new TFile(presentFileName.Data(), "READ") ; 
124    // kineFile->ls() ;
125    Int_t nEvts = kineFile->GetNkeys() ; 
126    cout << "  . found: " << nEvts << " KineTree(s) in " << presentFileName.Data() << endl ;
127    TList* kineEventsList = (TList*)kineFile->GetListOfKeys() ; 
128    TTree* kTree ;
129    TIter next(kineEventsList); 
130    TKey* key ;
131
132    // Loop over the events
133    while( key=(TKey *)next() ) 
134    {
135     TDirectory* tDir = (TDirectory*)key->ReadObj() ;
136     if(!tDir) break;
137  
138     TString evtDir(tDir->GetName()) ; 
139     cout << "  . . found: " << tDir->GetName() << endl ;
140
141     kTree = (TTree *)tDir->Get("TreeK");
142     if(!kTree) break;
143
144     Int_t nPart = kTree->GetEntries() ;
145     cout << "  . . . kTree " << count << " has " << nPart << " particles " << endl ;
146     
147    // fill and save the flow event
148     flowEvt = flowKiner->FillFlowEvent(kTree) ;
149     cout << "  . . . flowEvent " << flowEvt << " filled from ttree " << kTree << " ... " << endl ; 
150     // flowEvt->Dump() ; cout << endl ;
151     TString evtID = "" ; evtID += iDir ; evtID += "-" ; evtID += evtDir ; 
152     fFlowfile->cd() ; flowEvt->Write(evtID.Data()) ;
153     cout <<  "  . . . flowEvent " << flowEvt << "  ( " << evtID.Data() << " )  -  written on disk (" << output << ") ... " << endl;
154     delete flowEvt ; cout << endl ;
155    // -
156
157     if(count == limit) { break ; }
158     count ++ ;
159     
160     delete kTree ;
161    }
162    delete kineFile ;
163   }
164   delete evtsDir ;
165  }
166  
167  fFlowfile->Close() ; 
168  
169  cout <<  endl ;
170  cout << " Finished ... " << endl ;
171  cout << "  nParticles:  " << (flowKiner->GetNgoodTracks() + flowKiner->GetNgoodV0s()) << " (" << flowKiner->GetNposiTracks() << "+ , " << flowKiner->GetNnegaTracks() << "- , " << flowKiner->GetNgoodV0s() << " neutral) " << endl ;   
172  cout << "  <nCharged> (|eta|<0.5):  " << (Int_t)(flowKiner->GetNgoodTracksEta()/count) << endl ; 
173  cout << "  Bayesian :  " ; 
174  for(int ii=0;ii<5;ii++) { cout << flowKiner->GetBayesianNorm(ii) << "   " ; } 
175  cout << " . " << endl ; 
176
177  timer.Stop() ;
178  cout << endl ;
179  timer.Print() ;
180  cout << " . here it was (kiner noRL) ... " << endl ;  //juice!
181  cout << endl ;
182
183  // cout << endl ; cout << " Memory Check (from Paul)" << endl ; 
184  // gObjectTable->Print();
185  // cout << endl ; cout << endl ;
186
187  return cen ;
188 }
189
190 //////////////////////////////////////////////////////////////////////////////////////////////////////
191