]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/AliSelector.cxx
Default changed: SPD chips thickness is 150 microns
[u/mrichter/AliRoot.git] / PWG0 / AliSelector.cxx
CommitLineData
539b6cb4 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.
5
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
10// slave servers.
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.
17//
18// To use this file, try the following session on your Tree T:
19//
20// Root > T->Process("AliSelector.C")
21// Root > T->Process("AliSelector.C","some options")
22// Root > T->Process("AliSelector.C+")
23//
24
25#include "AliSelector.h"
b8e8168f 26
539b6cb4 27#include <TStyle.h>
28#include <TSystem.h>
29#include <TCanvas.h>
30#include <TRegexp.h>
b8e8168f 31#include <TTime.h>
4dd2ad81 32#include <TParticle.h>
33#include <TParticlePDG.h>
539b6cb4 34
b8e8168f 35#include <AliLog.h>
539b6cb4 36
37ClassImp(AliSelector)
38
ee998961 39AliSelector::AliSelector() :
539b6cb4 40 TSelector(),
41 fChain(0),
42 fESD(0),
43 fHeader(0),
ee998961 44 fKineFile(0)
539b6cb4 45{
79ab56b9 46 //
539b6cb4 47 // Constructor. Initialization of pointers
79ab56b9 48 //
539b6cb4 49}
50
51AliSelector::~AliSelector()
52{
79ab56b9 53 //
54 // Destructor
55 //
539b6cb4 56
57 // histograms are in the output list and deleted when the output
58 // list is deleted by the TSelector dtor
59}
60
61void AliSelector::Begin(TTree *)
62{
63 // The Begin() function is called at the start of the query.
64 // When running with PROOF Begin() is only called on the client.
65 // The tree argument is deprecated (on PROOF 0 is passed).
539b6cb4 66}
67
68void AliSelector::SlaveBegin(TTree * tree)
69{
70 // The SlaveBegin() function is called after the Begin() function.
71 // When running with PROOF SlaveBegin() is called on each slave server.
72 // The tree argument is deprecated (on PROOF 0 is passed).
73
74 Init(tree);
75
b8e8168f 76 AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
77 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
78 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
539b6cb4 79 TFile *f = fChain->GetCurrentFile();
b8e8168f 80 AliDebug(AliLog::kDebug, f->GetName());
539b6cb4 81
82 TString option = GetOption();
83}
84
85void AliSelector::Init(TTree *tree)
86{
87 // The Init() function is called when the selector needs to initialize
88 // a new tree or chain. Typically here the branch addresses of the tree
89 // will be set. It is normaly not necessary to make changes to the
90 // generated code, but the routine can be extended by the user if needed.
91 // Init() will be called many times when running with PROOF.
92
b8e8168f 93 AliDebug(AliLog::kDebug, "=========Init==========");
539b6cb4 94
95 // Set branch addresses
96 if (tree == 0)
97 {
b8e8168f 98 AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
539b6cb4 99 return;
100 }
101
102 fChain = dynamic_cast<TChain*> (tree);
103 if (fChain == 0)
104 {
b8e8168f 105 AliDebug(AliLog::kDebug, "ERROR: tree argument could not be casted to TChain.");
539b6cb4 106 return;
107 }
108
109 fChain->SetBranchAddress("ESD", &fESD);
110 if (fESD != 0)
b8e8168f 111 AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
539b6cb4 112
113 fChain->SetBranchAddress("Header", &fHeader);
114 if (fHeader != 0)
b8e8168f 115 AliDebug(AliLog::kInfo, "INFO: Found event header branch in chain.");
539b6cb4 116}
117
118Bool_t AliSelector::Notify()
119{
120 // The Notify() function is called when a new file is opened. This
121 // can be either for a new TTree in a TChain or when when a new TTree
122 // is started when using PROOF. Typically here the branch pointers
123 // will be retrieved. It is normaly not necessary to make changes
124 // to the generated code, but the routine can be extended by the
125 // user if needed.
126
b8e8168f 127 AliDebug(AliLog::kDebug, "=========NOTIFY==========");
128 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
129 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
ee998961 130
539b6cb4 131 TFile *f = fChain->GetCurrentFile();
4dd2ad81 132 AliDebug(AliLog::kInfo, Form("Processing file %s", f->GetName()));
539b6cb4 133
134 DeleteKinematicsFile();
539b6cb4 135
136 return kTRUE;
137}
138
139Bool_t AliSelector::Process(Long64_t entry)
140{
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.
148 //
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.
152
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).
158
b8e8168f 159 AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
539b6cb4 160
161 if (!fChain)
162 {
b8e8168f 163 AliDebug(AliLog::kError, "ERROR: fChain is 0.");
539b6cb4 164 return kFALSE;
165 }
166
167 fChain->GetTree()->GetEntry(entry);
168
169 if (fESD)
b8e8168f 170 AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
539b6cb4 171
172 if (fHeader)
b8e8168f 173 AliDebug(AliLog::kDebug, Form("Header: We have %d primaries.", fHeader->GetNprimary()));
539b6cb4 174
175 TTree* kinematics = GetKinematics();
176 if (kinematics)
b8e8168f 177 AliDebug(AliLog::kDebug, Form("Kinematics: We have %lld particles.", kinematics->GetEntries()));
539b6cb4 178
179 return kTRUE;
180}
181
182void AliSelector::SlaveTerminate()
183{
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.
187
188 DeleteKinematicsFile();
539b6cb4 189}
190
191void AliSelector::Terminate()
192{
193 // The Terminate() function is the last function to be called during
194 // a query. It always runs on the client, it can be used to present
195 // the results graphically or save the results to file.
196
b8e8168f 197 AliDebug(AliLog::kDebug, "=========TERMINATE==========");
539b6cb4 198}
199
200TTree* AliSelector::GetKinematics()
201{
79ab56b9 202 // Returns kinematics tree corresponding to current ESD active in fChain
203 // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
204 // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
205
539b6cb4 206 if (!fKineFile)
207 {
208 if (!fChain->GetCurrentFile())
209 return 0;
210
211 TString fileName(fChain->GetCurrentFile()->GetName());
212 fileName.ReplaceAll("AliESDs", "Kinematics");
213
214 fKineFile = TFile::Open(fileName);
215 if (!fKineFile)
216 return 0;
217 }
218
219 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fChain->GetTree()->GetReadEntry())));
220
221 /* this is if we want to get it from a TChain
222
223 define it in the header:
224
225 TChain* fKineChain;
226
227 this creates the chain:
228
229 TChain* chainKine = new TChain("TreeK");
230 for (Int_t i=0; i<20; ++i)
231 chainKine->Add(Form("test/Kinematics.root/Event%d/TreeK", i));
232 for (Int_t i=0; i<20; ++i)
233 chainKine->Add(Form("test2/Kinematics.root/Event%d/TreeK", i));
234
235 <mainChain>->GetUserInfo()->Add(chainKine);
236
237 we retrieve it in init:
238
239 fKineChain = dynamic_cast<TChain*> (fChain->GetUserInfo()->FindObject("TreeK"));
240
241 and use it in process:
242
243 if (fKineChain)
244 {
245 Long64_t entryK = fKineChain->GetTreeOffset()[fChain->GetChainEntryNumber(entry)];
246 cout << "Entry in fKineChain: " << entryK << endl;
247 fKineChain->LoadTree(entryK);
248 TTree* kineTree = fKineChain->GetTree();
249
250 printf("Kinematics from tree friend: We have %lld particles.\n", kineTree->GetEntries());
251 }
252 */
253}
254
255void AliSelector::DeleteKinematicsFile()
256{
79ab56b9 257 //
258 // Closes the kinematics file and deletes the pointer.
259 //
260
539b6cb4 261 if (fKineFile)
262 {
263 fKineFile->Close();
264 delete fKineFile;
265 fKineFile = 0;
266 }
267}
268
4dd2ad81 269Bool_t AliSelector::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries) const
270{
271 //
272 // Returns if the given particle is a primary particle
273 // This function or a equivalent should be available in some common place of AliRoot
274 //
275
276 // if the particle has a daughter primary, we do not want to count it
277 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
278 return kFALSE;
279
280 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
281
282 // skip quarks and gluon
283 if (pdgCode <= 10 || pdgCode == 21)
284 return kFALSE;
285
286 if (strcmp(aParticle->GetName(),"XXX") == 0)
287 {
288 AliDebug(AliLog::kDebug, Form("WARNING: There is a particle named XXX."));
289 return kFALSE;
290 }
291
292 TParticlePDG* pdgPart = aParticle->GetPDG();
293
294 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
295 {
296 AliDebug(AliLog::kDebug, Form("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode));
297 return kFALSE;
298 }
299
300 if (pdgPart->Charge() == 0)
301 return kFALSE;
302
303 return kTRUE;
304}