]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/AliSelector.cxx
new way of creating the corrections: 3d as function of eta, vtx_z and pt
[u/mrichter/AliRoot.git] / PWG0 / AliSelector.cxx
1 /* $Id$ */
2
3 // The class definition in esdV0.h has been generated automatically
4 // by the ROOT utility TTree::MakeSelector(). This class is derived
5 // from the ROOT class TSelector. For more information on the TSelector
6 // framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
7
8 // The following methods are defined in this file:
9 //    Begin():        called everytime a loop on the tree starts,
10 //                    a convenient place to create your histograms.
11 //    SlaveBegin():   called after Begin(), when on PROOF called only on the
12 //                    slave servers.
13 //    Process():      called for each event, in this function you decide what
14 //                    to read and fill your histograms.
15 //    SlaveTerminate: called at the end of the loop on the tree, when on PROOF
16 //                    called only on the slave servers.
17 //    Terminate():    called at the end of the loop on the tree,
18 //                    a convenient place to draw/fit your histograms.
19 //
20 // To use this file, try the following session on your Tree T:
21 //
22 // Root > T->Process("AliSelector.C")
23 // Root > T->Process("AliSelector.C","some options")
24 // Root > T->Process("AliSelector.C+")
25 //
26
27 #include "AliSelector.h"
28
29 #include <TStyle.h>
30 #include <TSystem.h>
31 #include <TCanvas.h>
32 #include <TRegexp.h>
33 #include <TTime.h>
34 #include <TFriendElement.h>
35 #include <TTree.h>
36 #include <TChain.h>
37 #include <TFile.h>
38
39 #include <AliLog.h>
40 #include <AliESD.h>
41
42 ClassImp(AliSelector)
43
44 AliSelector::AliSelector() :
45   TSelector(),
46   fTree(0),
47   fESD(0),
48   fCountFiles(0),
49   fKineFile(0)
50 {
51   //
52   // Constructor. Initialization of pointers
53   //
54
55   AliLog::SetClassDebugLevel("AliSelector", AliLog::kDebug);
56 }
57
58 AliSelector::~AliSelector()
59 {
60   //
61   // Destructor
62   //
63
64   // histograms are in the output list and deleted when the output
65   // list is deleted by the TSelector dtor
66 }
67
68 void AliSelector::Begin(TTree*)
69 {
70   // The Begin() function is called at the start of the query.
71   // When running with PROOF Begin() is only called on the client.
72   // The tree argument is deprecated (on PROOF 0 is passed).
73 }
74
75 void AliSelector::SlaveBegin(TTree* tree)
76 {
77   // The SlaveBegin() function is called after the Begin() function.
78   // When running with PROOF SlaveBegin() is called on each slave server.
79   // The tree argument is deprecated (on PROOF 0 is passed).
80
81   AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
82   AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
83   AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
84
85   if (tree != 0)
86     Init(tree);
87 }
88
89 void AliSelector::Init(TTree *tree)
90 {
91   // The Init() function is called when the selector needs to initialize
92   // a new tree or chain. Typically here the branch addresses of the tree
93   // will be set. It is normaly not necessary to make changes to the
94   // generated code, but the routine can be extended by the user if needed.
95   // Init() will be called many times when running with PROOF.
96
97   AliDebug(AliLog::kDebug, "=========Init==========");
98
99   fTree = tree;
100
101   if (fTree == 0)
102   {
103     AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
104     return;
105   }
106
107   // Set branch address
108   fTree->SetBranchAddress("ESD", &fESD);
109   if (fESD != 0)
110     AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
111 }
112
113 Bool_t AliSelector::Notify()
114 {
115   // The Notify() function is called when a new file is opened. This
116   // can be either for a new TTree in a TChain or when when a new TTree
117   // is started when using PROOF. Typically here the branch pointers
118   // will be retrieved. It is normaly not necessary to make changes
119   // to the generated code, but the routine can be extended by the
120   // user if needed.
121
122   AliDebug(AliLog::kDebug, "=========NOTIFY==========");
123   AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
124   AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
125
126   ++fCountFiles;
127   if (fTree)
128   {
129     TFile *f = fTree->GetCurrentFile();
130     AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
131   }
132   else
133   {
134     AliDebug(AliLog::kError, "fTree not available");
135   }
136
137   DeleteKinematicsFile();
138
139   return kTRUE;
140 }
141
142 Bool_t AliSelector::Process(Long64_t entry)
143 {
144   // The Process() function is called for each entry in the tree (or possibly
145   // keyed object in the case of PROOF) to be processed. The entry argument
146   // specifies which entry in the currently loaded tree is to be processed.
147   // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
148   // to read either all or the required parts of the data. When processing
149   // keyed objects with PROOF, the object is already loaded and is available
150   // via the fObject pointer.
151   //
152   // This function should contain the "body" of the analysis. It can contain
153   // simple or elaborate selection criteria, run algorithms on the data
154   // of the event and typically fill histograms.
155
156   // WARNING when a selector is used with a TChain, you must use
157   //  the pointer to the current TTree to call GetEntry(entry).
158   //  The entry is always the local entry number in the current tree.
159   //  Assuming that fTree is the pointer to the TChain being processed,
160   //  use fTree->GetTree()->GetEntry(entry).
161
162   AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
163
164   if (!fTree)
165   {
166     AliDebug(AliLog::kError, "ERROR: fTree is 0.");
167     return kFALSE;
168   }
169
170   fTree->GetTree()->GetEntry(entry);
171
172   /*
173   // debugging
174   if (fESD)
175     AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
176
177   if (fHeader)
178     AliDebug(AliLog::kDebug, Form("Header: We have %d primaries.", fHeader->GetNprimary()));
179
180   TTree* kinematics = GetKinematics();
181   if (kinematics)
182     AliDebug(AliLog::kDebug, Form("Kinematics: We have %lld particles.", kinematics->GetEntries()));
183   */
184
185   return kTRUE;
186 }
187
188 void AliSelector::SlaveTerminate()
189 {
190   // The SlaveTerminate() function is called after all entries or objects
191   // have been processed. When running with PROOF SlaveTerminate() is called
192   // on each slave server.
193
194   DeleteKinematicsFile();
195 }
196
197 void AliSelector::Terminate()
198 {
199   // The Terminate() function is the last function to be called during
200   // a query. It always runs on the client, it can be used to present
201   // the results graphically or save the results to file.
202
203   AliDebug(AliLog::kDebug, "=========TERMINATE==========");
204 }
205
206 TTree* AliSelector::GetKinematics()
207 {
208   // Returns kinematics tree corresponding to current ESD active in fTree
209   // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
210   // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
211
212   if (!fKineFile)
213   {
214     if (!fTree->GetCurrentFile())
215       return 0;
216
217     TString fileName(fTree->GetCurrentFile()->GetName());
218     fileName.ReplaceAll("AliESDs", "Kinematics");
219
220     AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
221
222     fKineFile = TFile::Open(fileName);
223     if (!fKineFile)
224       return 0;
225   }
226
227   return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fTree->GetTree()->GetReadEntry())));
228 }
229
230 void AliSelector::DeleteKinematicsFile()
231 {
232   //
233   // Closes the kinematics file and deletes the pointer.
234   //
235
236   if (fKineFile)
237   {
238     fKineFile->Close();
239     delete fKineFile;
240     fKineFile = 0;
241   }
242 }