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"
31 #include <TFriendElement.h>
38 AliSelector::AliSelector(TTree *) :
46 // Constructor. Initialization of pointers
49 AliSelector::~AliSelector()
51 // Remove all pointers
53 // histograms are in the output list and deleted when the output
54 // list is deleted by the TSelector dtor
57 void AliSelector::Begin(TTree *)
59 // The Begin() function is called at the start of the query.
60 // When running with PROOF Begin() is only called on the client.
61 // The tree argument is deprecated (on PROOF 0 is passed).
63 //TString option = GetOption();
66 void AliSelector::SlaveBegin(TTree * tree)
68 // The SlaveBegin() function is called after the Begin() function.
69 // When running with PROOF SlaveBegin() is called on each slave server.
70 // The tree argument is deprecated (on PROOF 0 is passed).
74 printf("=======SLAVEBEGIN========\n");
75 gSystem->Exec("hostname");
76 gSystem->Exec("date");
77 TFile *f = fChain->GetCurrentFile();
78 printf("%s\n",f->GetName());
80 TString option = GetOption();
83 void AliSelector::Init(TTree *tree)
85 // The Init() function is called when the selector needs to initialize
86 // a new tree or chain. Typically here the branch addresses of the tree
87 // will be set. It is normaly not necessary to make changes to the
88 // generated code, but the routine can be extended by the user if needed.
89 // Init() will be called many times when running with PROOF.
91 printf("=========Init==========\n");
93 // Set branch addresses
96 printf("ERROR: tree argument is 0.\n");
100 fChain = dynamic_cast<TChain*> (tree);
103 printf("ERROR: tree argument could not be casted to TChain.\n");
107 fChain->SetBranchAddress("ESD", &fESD);
109 printf("INFO: Found ESD branch in chain.\n");
111 fChain->SetBranchAddress("Header", &fHeader);
113 printf("INFO: Found event header branch in chain.\n");
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 printf("=========NOTIFY==========\n");
127 gSystem->Exec("hostname");
128 gSystem->Exec("date");
129 TFile *f = fChain->GetCurrentFile();
130 TString fileName(f->GetName());
131 printf("%s\n",fileName.Data());
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 printf("=========PROCESS========== Entry %lld\n", entry);
163 printf("ERROR: fChain is 0.\n");
167 fChain->GetTree()->GetEntry(entry);
170 printf("ESD: We have %d tracks.\n", fESD->GetNumberOfTracks());
173 printf("Header: We have %d primaries.\n", fHeader->GetNprimary());
175 TTree* kinematics = GetKinematics();
177 printf("Kinematics from folder: We have %lld particles.\n", kinematics->GetEntries());
184 void AliSelector::SlaveTerminate()
186 // The SlaveTerminate() function is called after all entries or objects
187 // have been processed. When running with PROOF SlaveTerminate() is called
188 // on each slave server.
190 DeleteKinematicsFile();
194 void AliSelector::Terminate()
196 // The Terminate() function is the last function to be called during
197 // a query. It always runs on the client, it can be used to present
198 // the results graphically or save the results to file.
200 printf("=========TERMINATE==========\n");
203 TTree* AliSelector::GetKinematics()
207 if (!fChain->GetCurrentFile())
210 TString fileName(fChain->GetCurrentFile()->GetName());
211 fileName.ReplaceAll("AliESDs", "Kinematics");
213 fKineFile = TFile::Open(fileName);
218 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fChain->GetTree()->GetReadEntry())));
220 /* this is if we want to get it from a TChain
222 define it in the header:
226 this creates the chain:
228 TChain* chainKine = new TChain("TreeK");
229 for (Int_t i=0; i<20; ++i)
230 chainKine->Add(Form("test/Kinematics.root/Event%d/TreeK", i));
231 for (Int_t i=0; i<20; ++i)
232 chainKine->Add(Form("test2/Kinematics.root/Event%d/TreeK", i));
234 <mainChain>->GetUserInfo()->Add(chainKine);
236 we retrieve it in init:
238 fKineChain = dynamic_cast<TChain*> (fChain->GetUserInfo()->FindObject("TreeK"));
240 and use it in process:
244 Long64_t entryK = fKineChain->GetTreeOffset()[fChain->GetChainEntryNumber(entry)];
245 cout << "Entry in fKineChain: " << entryK << endl;
246 fKineChain->LoadTree(entryK);
247 TTree* kineTree = fKineChain->GetTree();
249 printf("Kinematics from tree friend: We have %lld particles.\n", kineTree->GetEntries());
254 void AliSelector::DeleteKinematicsFile()
264 AliRun* AliSelector::GetAliRun()
268 if (!fChain->GetCurrentFile())
271 TString fileName(fChain->GetCurrentFile()->GetName());
272 fileName.ReplaceAll("AliESDs", "galice");
274 fRunLoader = AliRunLoader::Open(fileName);
278 fRunLoader->LoadgAlice();
281 return fRunLoader->GetAliRun();
284 void AliSelector::DeleteRunLoader()
288 fRunLoader->Delete();