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 | |
37 | ClassImp(AliSelector) |
38 | |
39 | AliSelector::AliSelector(TTree *) : |
40 | TSelector(), |
41 | fChain(0), |
42 | fESD(0), |
43 | fHeader(0), |
79ab56b9 |
44 | fKineFile(0), |
45 | fRunLoader(0) |
539b6cb4 |
46 | { |
79ab56b9 |
47 | // |
539b6cb4 |
48 | // Constructor. Initialization of pointers |
79ab56b9 |
49 | // |
539b6cb4 |
50 | } |
51 | |
52 | AliSelector::~AliSelector() |
53 | { |
79ab56b9 |
54 | // |
55 | // Destructor |
56 | // |
539b6cb4 |
57 | |
58 | // histograms are in the output list and deleted when the output |
59 | // list is deleted by the TSelector dtor |
60 | } |
61 | |
62 | void AliSelector::Begin(TTree *) |
63 | { |
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). |
539b6cb4 |
67 | } |
68 | |
69 | void AliSelector::SlaveBegin(TTree * tree) |
70 | { |
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). |
74 | |
75 | Init(tree); |
76 | |
b8e8168f |
77 | AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========"); |
78 | AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName())); |
79 | AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString())); |
539b6cb4 |
80 | TFile *f = fChain->GetCurrentFile(); |
b8e8168f |
81 | AliDebug(AliLog::kDebug, f->GetName()); |
539b6cb4 |
82 | |
83 | TString option = GetOption(); |
84 | } |
85 | |
86 | void AliSelector::Init(TTree *tree) |
87 | { |
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. |
93 | |
b8e8168f |
94 | AliDebug(AliLog::kDebug, "=========Init=========="); |
539b6cb4 |
95 | |
96 | // Set branch addresses |
97 | if (tree == 0) |
98 | { |
b8e8168f |
99 | AliDebug(AliLog::kError, "ERROR: tree argument is 0."); |
539b6cb4 |
100 | return; |
101 | } |
102 | |
103 | fChain = dynamic_cast<TChain*> (tree); |
104 | if (fChain == 0) |
105 | { |
b8e8168f |
106 | AliDebug(AliLog::kDebug, "ERROR: tree argument could not be casted to TChain."); |
539b6cb4 |
107 | return; |
108 | } |
109 | |
110 | fChain->SetBranchAddress("ESD", &fESD); |
111 | if (fESD != 0) |
b8e8168f |
112 | AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain."); |
539b6cb4 |
113 | |
114 | fChain->SetBranchAddress("Header", &fHeader); |
115 | if (fHeader != 0) |
b8e8168f |
116 | AliDebug(AliLog::kInfo, "INFO: Found event header branch in chain."); |
539b6cb4 |
117 | } |
118 | |
119 | Bool_t AliSelector::Notify() |
120 | { |
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 |
126 | // user if needed. |
127 | |
b8e8168f |
128 | AliDebug(AliLog::kDebug, "=========NOTIFY=========="); |
129 | AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName())); |
130 | AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString())); |
131 | |
539b6cb4 |
132 | TFile *f = fChain->GetCurrentFile(); |
4dd2ad81 |
133 | AliDebug(AliLog::kInfo, Form("Processing file %s", f->GetName())); |
539b6cb4 |
134 | |
135 | DeleteKinematicsFile(); |
136 | DeleteRunLoader(); |
137 | |
138 | return kTRUE; |
139 | } |
140 | |
141 | Bool_t AliSelector::Process(Long64_t entry) |
142 | { |
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. |
150 | // |
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. |
154 | |
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). |
160 | |
b8e8168f |
161 | AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry)); |
539b6cb4 |
162 | |
163 | if (!fChain) |
164 | { |
b8e8168f |
165 | AliDebug(AliLog::kError, "ERROR: fChain is 0."); |
539b6cb4 |
166 | return kFALSE; |
167 | } |
168 | |
169 | fChain->GetTree()->GetEntry(entry); |
170 | |
171 | if (fESD) |
b8e8168f |
172 | AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks())); |
539b6cb4 |
173 | |
174 | if (fHeader) |
b8e8168f |
175 | AliDebug(AliLog::kDebug, Form("Header: We have %d primaries.", fHeader->GetNprimary())); |
539b6cb4 |
176 | |
177 | TTree* kinematics = GetKinematics(); |
178 | if (kinematics) |
b8e8168f |
179 | AliDebug(AliLog::kDebug, Form("Kinematics: We have %lld particles.", kinematics->GetEntries())); |
539b6cb4 |
180 | |
181 | return kTRUE; |
182 | } |
183 | |
184 | void AliSelector::SlaveTerminate() |
185 | { |
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. |
189 | |
190 | DeleteKinematicsFile(); |
191 | DeleteRunLoader(); |
192 | } |
193 | |
194 | void AliSelector::Terminate() |
195 | { |
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. |
199 | |
b8e8168f |
200 | AliDebug(AliLog::kDebug, "=========TERMINATE=========="); |
539b6cb4 |
201 | } |
202 | |
203 | TTree* AliSelector::GetKinematics() |
204 | { |
79ab56b9 |
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! |
208 | |
539b6cb4 |
209 | if (!fKineFile) |
210 | { |
211 | if (!fChain->GetCurrentFile()) |
212 | return 0; |
213 | |
214 | TString fileName(fChain->GetCurrentFile()->GetName()); |
215 | fileName.ReplaceAll("AliESDs", "Kinematics"); |
216 | |
217 | fKineFile = TFile::Open(fileName); |
218 | if (!fKineFile) |
219 | return 0; |
220 | } |
221 | |
222 | return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fChain->GetTree()->GetReadEntry()))); |
223 | |
224 | /* this is if we want to get it from a TChain |
225 | |
226 | define it in the header: |
227 | |
228 | TChain* fKineChain; |
229 | |
230 | this creates the chain: |
231 | |
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)); |
237 | |
238 | <mainChain>->GetUserInfo()->Add(chainKine); |
239 | |
240 | we retrieve it in init: |
241 | |
242 | fKineChain = dynamic_cast<TChain*> (fChain->GetUserInfo()->FindObject("TreeK")); |
243 | |
244 | and use it in process: |
245 | |
246 | if (fKineChain) |
247 | { |
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(); |
252 | |
253 | printf("Kinematics from tree friend: We have %lld particles.\n", kineTree->GetEntries()); |
254 | } |
255 | */ |
256 | } |
257 | |
258 | void AliSelector::DeleteKinematicsFile() |
259 | { |
79ab56b9 |
260 | // |
261 | // Closes the kinematics file and deletes the pointer. |
262 | // |
263 | |
539b6cb4 |
264 | if (fKineFile) |
265 | { |
266 | fKineFile->Close(); |
267 | delete fKineFile; |
268 | fKineFile = 0; |
269 | } |
270 | } |
271 | |
272 | AliRun* AliSelector::GetAliRun() |
273 | { |
79ab56b9 |
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! |
277 | |
539b6cb4 |
278 | if (!fRunLoader) |
279 | { |
280 | if (!fChain->GetCurrentFile()) |
281 | return 0; |
282 | |
283 | TString fileName(fChain->GetCurrentFile()->GetName()); |
284 | fileName.ReplaceAll("AliESDs", "galice"); |
285 | |
286 | fRunLoader = AliRunLoader::Open(fileName); |
287 | if (!fRunLoader) |
288 | return 0; |
289 | |
290 | fRunLoader->LoadgAlice(); |
291 | } |
292 | |
293 | return fRunLoader->GetAliRun(); |
294 | } |
295 | |
296 | void AliSelector::DeleteRunLoader() |
297 | { |
79ab56b9 |
298 | // |
299 | // deletes the runloader |
300 | // |
b8e8168f |
301 | |
539b6cb4 |
302 | if (fRunLoader) |
303 | { |
304 | fRunLoader->Delete(); |
305 | fRunLoader = 0; |
306 | } |
307 | } |
b8e8168f |
308 | |
4dd2ad81 |
309 | Bool_t AliSelector::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries) const |
310 | { |
311 | // |
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 |
314 | // |
315 | |
316 | // if the particle has a daughter primary, we do not want to count it |
317 | if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries) |
318 | return kFALSE; |
319 | |
320 | Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode()); |
321 | |
322 | // skip quarks and gluon |
323 | if (pdgCode <= 10 || pdgCode == 21) |
324 | return kFALSE; |
325 | |
326 | if (strcmp(aParticle->GetName(),"XXX") == 0) |
327 | { |
328 | AliDebug(AliLog::kDebug, Form("WARNING: There is a particle named XXX.")); |
329 | return kFALSE; |
330 | } |
331 | |
332 | TParticlePDG* pdgPart = aParticle->GetPDG(); |
333 | |
334 | if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0) |
335 | { |
336 | AliDebug(AliLog::kDebug, Form("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode)); |
337 | return kFALSE; |
338 | } |
339 | |
340 | if (pdgPart->Charge() == 0) |
341 | return kFALSE; |
342 | |
343 | return kTRUE; |
344 | } |