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 <TParticle.h>
35 #include <TParticlePDG.h>
36 #include <TFriendElement.h>
43 #include <AliHeader.h>
47 AliSelector::AliSelector() :
58 // Constructor. Initialization of pointers
62 AliSelector::~AliSelector()
68 // histograms are in the output list and deleted when the output
69 // list is deleted by the TSelector dtor
72 void AliSelector::Begin(TTree *)
74 // The Begin() function is called at the start of the query.
75 // When running with PROOF Begin() is only called on the client.
76 // The tree argument is deprecated (on PROOF 0 is passed).
79 void AliSelector::SlaveBegin(TTree * tree)
81 // The SlaveBegin() function is called after the Begin() function.
82 // When running with PROOF SlaveBegin() is called on each slave server.
83 // The tree argument is deprecated (on PROOF 0 is passed).
87 AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
88 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
89 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
91 TString option = GetOption();
94 void AliSelector::Init(TTree *tree)
96 // The Init() function is called when the selector needs to initialize
97 // a new tree or chain. Typically here the branch addresses of the tree
98 // will be set. It is normaly not necessary to make changes to the
99 // generated code, but the routine can be extended by the user if needed.
100 // Init() will be called many times when running with PROOF.
102 AliDebug(AliLog::kDebug, "=========Init==========");
104 // Set branch addresses
107 AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
111 fChain = dynamic_cast<TChain*> (tree);
114 AliDebug(AliLog::kDebug, "ERROR: tree argument could not be casted to TChain.");
118 fChain->SetBranchAddress("ESD", &fESD);
120 AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
122 /*fChain->SetBranchAddress("Header", &fHeader);
124 AliDebug(AliLog::kInfo, "INFO: Found event header branch in chain.");*/
127 Bool_t AliSelector::Notify()
129 // The Notify() function is called when a new file is opened. This
130 // can be either for a new TTree in a TChain or when when a new TTree
131 // is started when using PROOF. Typically here the branch pointers
132 // will be retrieved. It is normaly not necessary to make changes
133 // to the generated code, but the routine can be extended by the
136 AliDebug(AliLog::kDebug, "=========NOTIFY==========");
137 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
138 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
141 TFile *f = fChain->GetCurrentFile();
142 AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
144 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 fChain is the pointer to the TChain being processed,
168 // use fChain->GetTree()->GetEntry(entry).
170 AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
174 AliDebug(AliLog::kError, "ERROR: fChain is 0.");
178 fChain->GetTree()->GetEntry(entry);
183 AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
186 AliDebug(AliLog::kDebug, Form("Header: We have %d primaries.", fHeader->GetNprimary()));
188 TTree* kinematics = GetKinematics();
190 AliDebug(AliLog::kDebug, Form("Kinematics: We have %lld particles.", kinematics->GetEntries()));
196 void AliSelector::SlaveTerminate()
198 // The SlaveTerminate() function is called after all entries or objects
199 // have been processed. When running with PROOF SlaveTerminate() is called
200 // on each slave server.
202 DeleteKinematicsFile();
206 void AliSelector::Terminate()
208 // The Terminate() function is the last function to be called during
209 // a query. It always runs on the client, it can be used to present
210 // the results graphically or save the results to file.
212 AliDebug(AliLog::kDebug, "=========TERMINATE==========");
215 TTree* AliSelector::GetKinematics()
217 // Returns kinematics tree corresponding to current ESD active in fChain
218 // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
219 // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
223 if (!fChain->GetCurrentFile())
226 TString fileName(fChain->GetCurrentFile()->GetName());
227 fileName.ReplaceAll("AliESDs", "Kinematics");
229 AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
231 fKineFile = TFile::Open(fileName);
236 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fChain->GetTree()->GetReadEntry())));
239 void AliSelector::DeleteKinematicsFile()
242 // Closes the kinematics file and deletes the pointer.
253 AliHeader* AliSelector::GetHeader()
255 // Returns header corresponding to current ESD active in fChain
256 // Loads the header from galice.root, the file is identified by replacing "AliESDs" to
257 // "galice" in the file path of the ESD file. This is a hack, to be changed!
259 if (!fHeaderFile || !fHeaderTree)
261 if (!fChain->GetCurrentFile())
264 TString fileName(fChain->GetCurrentFile()->GetName());
265 fileName.ReplaceAll("AliESDs", "galice");
267 AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
269 fHeaderFile = TFile::Open(fileName);
273 fHeaderTree = dynamic_cast<TTree*> (fHeaderFile->Get("TE"));
277 fHeaderTree->SetBranchAddress("Header", &fHeader);
280 fHeaderTree->GetEntry(fChain->GetTree()->GetReadEntry());
285 void AliSelector::DeleteHeaderFile()
288 // Closes the kinematics file and deletes the pointer.
293 fHeaderFile->Close();
300 Bool_t AliSelector::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries) const
303 // Returns if the given particle is a primary particle
304 // This function or a equivalent should be available in some common place of AliRoot
307 // if the particle has a daughter primary, we do not want to count it
308 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
310 AliDebug(AliLog::kDebug+1, "Dropping particle because it has a daughter among the primaries.");
314 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
316 // skip quarks and gluon
317 if (pdgCode <= 10 || pdgCode == 21)
319 AliDebug(AliLog::kDebug+1, "Dropping particle because it is a quark or gluon.");
323 if (strcmp(aParticle->GetName(),"XXX") == 0)
325 AliDebug(AliLog::kDebug, Form("WARNING: There is a particle named XXX."));
329 TParticlePDG* pdgPart = aParticle->GetPDG();
331 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
333 AliDebug(AliLog::kDebug, Form("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode));
337 if (pdgPart->Charge() == 0)
340 AliDebug(AliLog::kDebug+1, "Dropping particle because it is not charged.");