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.
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
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.
20 // To use this file, try the following session on your Tree T:
22 // Root > T->Process("AliSelector.C")
23 // Root > T->Process("AliSelector.C","some options")
24 // Root > T->Process("AliSelector.C+")
27 #include "AliSelector.h"
34 #include <TFriendElement.h>
44 AliSelector::AliSelector() :
52 // Constructor. Initialization of pointers
56 AliSelector::~AliSelector()
62 // histograms are in the output list and deleted when the output
63 // list is deleted by the TSelector dtor
66 void AliSelector::Begin(TTree*)
68 // The Begin() function is called at the start of the query.
69 // When running with PROOF Begin() is only called on the client.
70 // The tree argument is deprecated (on PROOF 0 is passed).
72 TString option = GetOption();
74 if (option.Contains("debug"))
76 AliLog::SetClassDebugLevel("AliSelector", AliLog::kDebug);
77 AliInfo(Form("Called with option %s.", option.Data()));
80 AliDebug(AliLog::kDebug, "============BEGIN===========");
83 void AliSelector::SlaveBegin(TTree* tree)
85 // The SlaveBegin() function is called after the Begin() function.
86 // When running with PROOF SlaveBegin() is called on each slave server.
87 // The tree argument is deprecated (on PROOF 0 is passed).
89 AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
90 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
91 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
97 void AliSelector::Init(TTree *tree)
99 // The Init() function is called when the selector needs to initialize
100 // a new tree or chain. Typically here the branch addresses of the tree
101 // will be set. It is normaly not necessary to make changes to the
102 // generated code, but the routine can be extended by the user if needed.
103 // Init() will be called many times when running with PROOF.
105 AliDebug(AliLog::kDebug, "=========Init==========");
111 AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
115 // Set branch address
116 fTree->SetBranchAddress("ESD", &fESD);
118 AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
121 Bool_t AliSelector::Notify()
123 // The Notify() function is called when a new file is opened. This
124 // can be either for a new TTree in a TChain or when when a new TTree
125 // is started when using PROOF. Typically here the branch pointers
126 // will be retrieved. It is normaly not necessary to make changes
127 // to the generated code, but the routine can be extended by the
130 AliDebug(AliLog::kDebug, "=========NOTIFY==========");
131 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
132 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
137 TFile *f = fTree->GetCurrentFile();
138 AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
142 AliDebug(AliLog::kError, "fTree not available");
145 DeleteKinematicsFile();
150 Bool_t AliSelector::Process(Long64_t entry)
152 // The Process() function is called for each entry in the tree (or possibly
153 // keyed object in the case of PROOF) to be processed. The entry argument
154 // specifies which entry in the currently loaded tree is to be processed.
155 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
156 // to read either all or the required parts of the data. When processing
157 // keyed objects with PROOF, the object is already loaded and is available
158 // via the fObject pointer.
160 // This function should contain the "body" of the analysis. It can contain
161 // simple or elaborate selection criteria, run algorithms on the data
162 // of the event and typically fill histograms.
164 // WARNING when a selector is used with a TChain, you must use
165 // the pointer to the current TTree to call GetEntry(entry).
166 // The entry is always the local entry number in the current tree.
167 // Assuming that fTree is the pointer to the TChain being processed,
168 // use fTree->GetTree()->GetEntry(entry).
170 AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
174 AliDebug(AliLog::kError, "ERROR: fTree is 0.");
178 fTree->GetTree()->GetEntry(entry);
181 AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
186 void AliSelector::SlaveTerminate()
188 // The SlaveTerminate() function is called after all entries or objects
189 // have been processed. When running with PROOF SlaveTerminate() is called
190 // on each slave server.
192 AliDebug(AliLog::kDebug, "=======SLAVETERMINATE=======");
194 DeleteKinematicsFile();
197 void AliSelector::Terminate()
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.
203 AliDebug(AliLog::kDebug, "=========TERMINATE==========");
206 TTree* AliSelector::GetKinematics()
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!
214 if (!fTree->GetCurrentFile())
217 TString fileName(fTree->GetCurrentFile()->GetName());
218 fileName.ReplaceAll("AliESDs", "Kinematics");
220 AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
222 fKineFile = TFile::Open(fileName);
227 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fTree->GetTree()->GetReadEntry())));
230 void AliSelector::DeleteKinematicsFile()
233 // Closes the kinematics file and deletes the pointer.