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>
46 AliSelector::AliSelector() :
54 // Constructor. Initialization of pointers
57 AliLog::SetClassDebugLevel("AliSelector", AliLog::kDebug);
60 AliSelector::~AliSelector()
66 // histograms are in the output list and deleted when the output
67 // list is deleted by the TSelector dtor
70 void AliSelector::Begin(TTree*)
72 // The Begin() function is called at the start of the query.
73 // When running with PROOF Begin() is only called on the client.
74 // The tree argument is deprecated (on PROOF 0 is passed).
77 void AliSelector::SlaveBegin(TTree* tree)
79 // The SlaveBegin() function is called after the Begin() function.
80 // When running with PROOF SlaveBegin() is called on each slave server.
81 // The tree argument is deprecated (on PROOF 0 is passed).
83 AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
84 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
85 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
91 void AliSelector::Init(TTree *tree)
93 // The Init() function is called when the selector needs to initialize
94 // a new tree or chain. Typically here the branch addresses of the tree
95 // will be set. It is normaly not necessary to make changes to the
96 // generated code, but the routine can be extended by the user if needed.
97 // Init() will be called many times when running with PROOF.
99 AliDebug(AliLog::kDebug, "=========Init==========");
105 AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
109 // Set branch address
110 fTree->SetBranchAddress("ESD", &fESD);
112 AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
115 Bool_t AliSelector::Notify()
117 // The Notify() function is called when a new file is opened. This
118 // can be either for a new TTree in a TChain or when when a new TTree
119 // is started when using PROOF. Typically here the branch pointers
120 // will be retrieved. It is normaly not necessary to make changes
121 // to the generated code, but the routine can be extended by the
124 AliDebug(AliLog::kDebug, "=========NOTIFY==========");
125 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
126 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
131 TFile *f = fTree->GetCurrentFile();
132 AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
136 AliDebug(AliLog::kError, "fTree not available");
139 DeleteKinematicsFile();
144 Bool_t AliSelector::Process(Long64_t entry)
146 // The Process() function is called for each entry in the tree (or possibly
147 // keyed object in the case of PROOF) to be processed. The entry argument
148 // specifies which entry in the currently loaded tree is to be processed.
149 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
150 // to read either all or the required parts of the data. When processing
151 // keyed objects with PROOF, the object is already loaded and is available
152 // via the fObject pointer.
154 // This function should contain the "body" of the analysis. It can contain
155 // simple or elaborate selection criteria, run algorithms on the data
156 // of the event and typically fill histograms.
158 // WARNING when a selector is used with a TChain, you must use
159 // the pointer to the current TTree to call GetEntry(entry).
160 // The entry is always the local entry number in the current tree.
161 // Assuming that fTree is the pointer to the TChain being processed,
162 // use fTree->GetTree()->GetEntry(entry).
164 AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
168 AliDebug(AliLog::kError, "ERROR: fTree is 0.");
172 fTree->GetTree()->GetEntry(entry);
177 AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
180 AliDebug(AliLog::kDebug, Form("Header: We have %d primaries.", fHeader->GetNprimary()));
182 TTree* kinematics = GetKinematics();
184 AliDebug(AliLog::kDebug, Form("Kinematics: We have %lld particles.", kinematics->GetEntries()));
190 void AliSelector::SlaveTerminate()
192 // The SlaveTerminate() function is called after all entries or objects
193 // have been processed. When running with PROOF SlaveTerminate() is called
194 // on each slave server.
196 DeleteKinematicsFile();
199 void AliSelector::Terminate()
201 // The Terminate() function is the last function to be called during
202 // a query. It always runs on the client, it can be used to present
203 // the results graphically or save the results to file.
205 AliDebug(AliLog::kDebug, "=========TERMINATE==========");
208 TTree* AliSelector::GetKinematics()
210 // Returns kinematics tree corresponding to current ESD active in fTree
211 // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
212 // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
216 if (!fTree->GetCurrentFile())
219 TString fileName(fTree->GetCurrentFile()->GetName());
220 fileName.ReplaceAll("AliESDs", "Kinematics");
222 AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
224 fKineFile = TFile::Open(fileName);
229 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fTree->GetTree()->GetReadEntry())));
232 void AliSelector::DeleteKinematicsFile()
235 // Closes the kinematics file and deletes the pointer.
246 Bool_t AliSelector::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries) const
249 // Returns if the given particle is a primary particle
250 // This function or a equivalent should be available in some common place of AliRoot
253 // if the particle has a daughter primary, we do not want to count it
254 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
256 AliDebug(AliLog::kDebug+1, "Dropping particle because it has a daughter among the primaries.");
260 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
262 // skip quarks and gluon
263 if (pdgCode <= 10 || pdgCode == 21)
265 AliDebug(AliLog::kDebug+1, "Dropping particle because it is a quark or gluon.");
269 if (strcmp(aParticle->GetName(),"XXX") == 0)
271 AliDebug(AliLog::kDebug, Form("WARNING: There is a particle named XXX."));
275 TParticlePDG* pdgPart = aParticle->GetPDG();
277 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
279 AliDebug(AliLog::kDebug, Form("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode));
283 if (pdgPart->Charge() == 0)
286 AliDebug(AliLog::kDebug+1, "Dropping particle because it is not charged.");