1 // The class definition in esdV0.h has been generated automatically
2 // by the ROOT utility TTree::MakeSelector(). This class is derived
3 // from the ROOT class TSelector. For more information on the TSelector
4 // framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
6 // The following methods are defined in this file:
7 // Begin(): called everytime a loop on the tree starts,
8 // a convenient place to create your histograms.
9 // SlaveBegin(): called after Begin(), when on PROOF called only on the
11 // Process(): called for each event, in this function you decide what
12 // to read and fill your histograms.
13 // SlaveTerminate: called at the end of the loop on the tree, when on PROOF
14 // called only on the slave servers.
15 // Terminate(): called at the end of the loop on the tree,
16 // a convenient place to draw/fit your histograms.
18 // To use this file, try the following session on your Tree T:
20 // Root > T->Process("AliSelector.C")
21 // Root > T->Process("AliSelector.C","some options")
22 // Root > T->Process("AliSelector.C+")
25 #include "AliSelector.h"
37 AliSelector::AliSelector(TTree *) :
46 // Constructor. Initialization of pointers
50 AliSelector::~AliSelector()
56 // histograms are in the output list and deleted when the output
57 // list is deleted by the TSelector dtor
60 void AliSelector::Begin(TTree *)
62 // The Begin() function is called at the start of the query.
63 // When running with PROOF Begin() is only called on the client.
64 // The tree argument is deprecated (on PROOF 0 is passed).
67 void AliSelector::SlaveBegin(TTree * tree)
69 // The SlaveBegin() function is called after the Begin() function.
70 // When running with PROOF SlaveBegin() is called on each slave server.
71 // The tree argument is deprecated (on PROOF 0 is passed).
75 AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
76 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
77 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
78 TFile *f = fChain->GetCurrentFile();
79 AliDebug(AliLog::kDebug, f->GetName());
81 TString option = GetOption();
84 void AliSelector::Init(TTree *tree)
86 // The Init() function is called when the selector needs to initialize
87 // a new tree or chain. Typically here the branch addresses of the tree
88 // will be set. It is normaly not necessary to make changes to the
89 // generated code, but the routine can be extended by the user if needed.
90 // Init() will be called many times when running with PROOF.
92 AliDebug(AliLog::kDebug, "=========Init==========");
94 // Set branch addresses
97 AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
101 fChain = dynamic_cast<TChain*> (tree);
104 AliDebug(AliLog::kDebug, "ERROR: tree argument could not be casted to TChain.");
108 fChain->SetBranchAddress("ESD", &fESD);
110 AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
112 fChain->SetBranchAddress("Header", &fHeader);
114 AliDebug(AliLog::kInfo, "INFO: Found event header branch in chain.");
117 Bool_t AliSelector::Notify()
119 // The Notify() function is called when a new file is opened. This
120 // can be either for a new TTree in a TChain or when when a new TTree
121 // is started when using PROOF. Typically here the branch pointers
122 // will be retrieved. It is normaly not necessary to make changes
123 // to the generated code, but the routine can be extended by the
126 AliDebug(AliLog::kDebug, "=========NOTIFY==========");
127 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
128 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
130 TFile *f = fChain->GetCurrentFile();
131 AliDebug(AliLog::kDebug, f->GetName());
133 DeleteKinematicsFile();
139 Bool_t AliSelector::Process(Long64_t entry)
141 // The Process() function is called for each entry in the tree (or possibly
142 // keyed object in the case of PROOF) to be processed. The entry argument
143 // specifies which entry in the currently loaded tree is to be processed.
144 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
145 // to read either all or the required parts of the data. When processing
146 // keyed objects with PROOF, the object is already loaded and is available
147 // via the fObject pointer.
149 // This function should contain the "body" of the analysis. It can contain
150 // simple or elaborate selection criteria, run algorithms on the data
151 // of the event and typically fill histograms.
153 // WARNING when a selector is used with a TChain, you must use
154 // the pointer to the current TTree to call GetEntry(entry).
155 // The entry is always the local entry number in the current tree.
156 // Assuming that fChain is the pointer to the TChain being processed,
157 // use fChain->GetTree()->GetEntry(entry).
159 AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
163 AliDebug(AliLog::kError, "ERROR: fChain is 0.");
167 fChain->GetTree()->GetEntry(entry);
170 AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
173 AliDebug(AliLog::kDebug, Form("Header: We have %d primaries.", fHeader->GetNprimary()));
175 TTree* kinematics = GetKinematics();
177 AliDebug(AliLog::kDebug, Form("Kinematics: We have %lld particles.", kinematics->GetEntries()));
182 void AliSelector::SlaveTerminate()
184 // The SlaveTerminate() function is called after all entries or objects
185 // have been processed. When running with PROOF SlaveTerminate() is called
186 // on each slave server.
188 DeleteKinematicsFile();
192 void AliSelector::Terminate()
194 // The Terminate() function is the last function to be called during
195 // a query. It always runs on the client, it can be used to present
196 // the results graphically or save the results to file.
198 AliDebug(AliLog::kDebug, "=========TERMINATE==========");
201 TTree* AliSelector::GetKinematics()
203 // Returns kinematics tree corresponding to current ESD active in fChain
204 // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
205 // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
209 if (!fChain->GetCurrentFile())
212 TString fileName(fChain->GetCurrentFile()->GetName());
213 fileName.ReplaceAll("AliESDs", "Kinematics");
215 fKineFile = TFile::Open(fileName);
220 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fChain->GetTree()->GetReadEntry())));
222 /* this is if we want to get it from a TChain
224 define it in the header:
228 this creates the chain:
230 TChain* chainKine = new TChain("TreeK");
231 for (Int_t i=0; i<20; ++i)
232 chainKine->Add(Form("test/Kinematics.root/Event%d/TreeK", i));
233 for (Int_t i=0; i<20; ++i)
234 chainKine->Add(Form("test2/Kinematics.root/Event%d/TreeK", i));
236 <mainChain>->GetUserInfo()->Add(chainKine);
238 we retrieve it in init:
240 fKineChain = dynamic_cast<TChain*> (fChain->GetUserInfo()->FindObject("TreeK"));
242 and use it in process:
246 Long64_t entryK = fKineChain->GetTreeOffset()[fChain->GetChainEntryNumber(entry)];
247 cout << "Entry in fKineChain: " << entryK << endl;
248 fKineChain->LoadTree(entryK);
249 TTree* kineTree = fKineChain->GetTree();
251 printf("Kinematics from tree friend: We have %lld particles.\n", kineTree->GetEntries());
256 void AliSelector::DeleteKinematicsFile()
259 // Closes the kinematics file and deletes the pointer.
270 AliRun* AliSelector::GetAliRun()
272 // Returns AliRun instance corresponding to current ESD active in fChain
273 // Loads galice.root, the file is identified by replacing "AliESDs" to
274 // "galice" in the file path of the ESD file. This is a hack, to be changed!
278 if (!fChain->GetCurrentFile())
281 TString fileName(fChain->GetCurrentFile()->GetName());
282 fileName.ReplaceAll("AliESDs", "galice");
284 fRunLoader = AliRunLoader::Open(fileName);
288 fRunLoader->LoadgAlice();
291 return fRunLoader->GetAliRun();
294 void AliSelector::DeleteRunLoader()
297 // deletes the runloader
302 fRunLoader->Delete();