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"
32 #include <TParticle.h>
33 #include <TParticlePDG.h>
39 AliSelector::AliSelector(TTree *) :
48 // Constructor. Initialization of pointers
52 AliSelector::~AliSelector()
58 // histograms are in the output list and deleted when the output
59 // list is deleted by the TSelector dtor
62 void AliSelector::Begin(TTree *)
64 // The Begin() function is called at the start of the query.
65 // When running with PROOF Begin() is only called on the client.
66 // The tree argument is deprecated (on PROOF 0 is passed).
69 void AliSelector::SlaveBegin(TTree * tree)
71 // The SlaveBegin() function is called after the Begin() function.
72 // When running with PROOF SlaveBegin() is called on each slave server.
73 // The tree argument is deprecated (on PROOF 0 is passed).
77 AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
78 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
79 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
80 TFile *f = fChain->GetCurrentFile();
81 AliDebug(AliLog::kDebug, f->GetName());
83 TString option = GetOption();
86 void AliSelector::Init(TTree *tree)
88 // The Init() function is called when the selector needs to initialize
89 // a new tree or chain. Typically here the branch addresses of the tree
90 // will be set. It is normaly not necessary to make changes to the
91 // generated code, but the routine can be extended by the user if needed.
92 // Init() will be called many times when running with PROOF.
94 AliDebug(AliLog::kDebug, "=========Init==========");
96 // Set branch addresses
99 AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
103 fChain = dynamic_cast<TChain*> (tree);
106 AliDebug(AliLog::kDebug, "ERROR: tree argument could not be casted to TChain.");
110 fChain->SetBranchAddress("ESD", &fESD);
112 AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
114 fChain->SetBranchAddress("Header", &fHeader);
116 AliDebug(AliLog::kInfo, "INFO: Found event header branch in chain.");
119 Bool_t AliSelector::Notify()
121 // The Notify() function is called when a new file is opened. This
122 // can be either for a new TTree in a TChain or when when a new TTree
123 // is started when using PROOF. Typically here the branch pointers
124 // will be retrieved. It is normaly not necessary to make changes
125 // to the generated code, but the routine can be extended by the
128 AliDebug(AliLog::kDebug, "=========NOTIFY==========");
129 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
130 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
132 TFile *f = fChain->GetCurrentFile();
133 AliDebug(AliLog::kInfo, Form("Processing file %s", f->GetName()));
135 DeleteKinematicsFile();
141 Bool_t AliSelector::Process(Long64_t entry)
143 // The Process() function is called for each entry in the tree (or possibly
144 // keyed object in the case of PROOF) to be processed. The entry argument
145 // specifies which entry in the currently loaded tree is to be processed.
146 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
147 // to read either all or the required parts of the data. When processing
148 // keyed objects with PROOF, the object is already loaded and is available
149 // via the fObject pointer.
151 // This function should contain the "body" of the analysis. It can contain
152 // simple or elaborate selection criteria, run algorithms on the data
153 // of the event and typically fill histograms.
155 // WARNING when a selector is used with a TChain, you must use
156 // the pointer to the current TTree to call GetEntry(entry).
157 // The entry is always the local entry number in the current tree.
158 // Assuming that fChain is the pointer to the TChain being processed,
159 // use fChain->GetTree()->GetEntry(entry).
161 AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
165 AliDebug(AliLog::kError, "ERROR: fChain is 0.");
169 fChain->GetTree()->GetEntry(entry);
172 AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
175 AliDebug(AliLog::kDebug, Form("Header: We have %d primaries.", fHeader->GetNprimary()));
177 TTree* kinematics = GetKinematics();
179 AliDebug(AliLog::kDebug, Form("Kinematics: We have %lld particles.", 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 AliDebug(AliLog::kDebug, "=========TERMINATE==========");
203 TTree* AliSelector::GetKinematics()
205 // Returns kinematics tree corresponding to current ESD active in fChain
206 // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
207 // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
211 if (!fChain->GetCurrentFile())
214 TString fileName(fChain->GetCurrentFile()->GetName());
215 fileName.ReplaceAll("AliESDs", "Kinematics");
217 fKineFile = TFile::Open(fileName);
222 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fChain->GetTree()->GetReadEntry())));
224 /* this is if we want to get it from a TChain
226 define it in the header:
230 this creates the chain:
232 TChain* chainKine = new TChain("TreeK");
233 for (Int_t i=0; i<20; ++i)
234 chainKine->Add(Form("test/Kinematics.root/Event%d/TreeK", i));
235 for (Int_t i=0; i<20; ++i)
236 chainKine->Add(Form("test2/Kinematics.root/Event%d/TreeK", i));
238 <mainChain>->GetUserInfo()->Add(chainKine);
240 we retrieve it in init:
242 fKineChain = dynamic_cast<TChain*> (fChain->GetUserInfo()->FindObject("TreeK"));
244 and use it in process:
248 Long64_t entryK = fKineChain->GetTreeOffset()[fChain->GetChainEntryNumber(entry)];
249 cout << "Entry in fKineChain: " << entryK << endl;
250 fKineChain->LoadTree(entryK);
251 TTree* kineTree = fKineChain->GetTree();
253 printf("Kinematics from tree friend: We have %lld particles.\n", kineTree->GetEntries());
258 void AliSelector::DeleteKinematicsFile()
261 // Closes the kinematics file and deletes the pointer.
272 AliRun* AliSelector::GetAliRun()
274 // Returns AliRun instance corresponding to current ESD active in fChain
275 // Loads galice.root, the file is identified by replacing "AliESDs" to
276 // "galice" in the file path of the ESD file. This is a hack, to be changed!
280 if (!fChain->GetCurrentFile())
283 TString fileName(fChain->GetCurrentFile()->GetName());
284 fileName.ReplaceAll("AliESDs", "galice");
286 fRunLoader = AliRunLoader::Open(fileName);
290 fRunLoader->LoadgAlice();
293 return fRunLoader->GetAliRun();
296 void AliSelector::DeleteRunLoader()
299 // deletes the runloader
304 fRunLoader->Delete();
309 Bool_t AliSelector::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries) const
312 // Returns if the given particle is a primary particle
313 // This function or a equivalent should be available in some common place of AliRoot
316 // if the particle has a daughter primary, we do not want to count it
317 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
320 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
322 // skip quarks and gluon
323 if (pdgCode <= 10 || pdgCode == 21)
326 if (strcmp(aParticle->GetName(),"XXX") == 0)
328 AliDebug(AliLog::kDebug, Form("WARNING: There is a particle named XXX."));
332 TParticlePDG* pdgPart = aParticle->GetPDG();
334 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
336 AliDebug(AliLog::kDebug, Form("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode));
340 if (pdgPart->Charge() == 0)