d16062ac |
1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * |
3 | * * |
4 | * Author: The ALICE Off-line Project. * |
5 | * Contributors are mentioned in the code where appropriate. * |
6 | * * |
7 | * Permission to use, copy, modify and distribute this software and its * |
8 | * documentation strictly for non-commercial purposes is hereby granted * |
9 | * without fee, provided that the above copyright notice appears in all * |
10 | * copies and that both the copyright notice and this permission notice * |
11 | * appear in the supporting documentation. The authors make no claims * |
12 | * about the suitability of this software for any purpose. It is * |
13 | * provided "as is" without express or implied warranty. * |
14 | **************************************************************************/ |
15 | |
7849a8ab |
16 | // $Id: AliEvent.cxx,v 1.2 2001/06/25 09:37:23 hristov Exp $ |
d16062ac |
17 | |
18 | /////////////////////////////////////////////////////////////////////////// |
19 | // Class AliEvent |
20 | // Creation and investigation of an Alice physics event. |
7849a8ab |
21 | // An AliEvent can be constructed by adding AliTracks, Alivertices, AliJets |
22 | // and/or AliCalorimeters. |
d16062ac |
23 | // |
24 | // The basic functionality of AliEvent is identical to the one of AliVertex. |
25 | // So, an AliEvent may be regarded as the primary vertex with some |
26 | // additional functionality compared to AliVertex. |
27 | // |
7849a8ab |
28 | // To provide maximal flexibility to the user, the two modes of track/jet/vertex |
29 | // storage as described in AliJet and AliVertex can be used. |
30 | // In addition an identical structure is provided for the storage of AliCalorimeter |
31 | // objects, which can be selected by means of the memberfunction SetCalCopy(). |
32 | // |
33 | // a) SetCalCopy(0) (which is the default). |
34 | // Only the pointers of the 'added' calorimeters are stored. |
35 | // This mode is typically used by making cal. studies based on a fixed set |
36 | // of calorimeters which stays under user control or is kept on an external |
37 | // file/tree. |
38 | // In this way the AliEvent just represents a 'logical structure' for the |
39 | // physics analysis. |
40 | // Modifications made to the original calorimeters also affect the AliCalorimeter |
41 | // objects which are stored in the AliEvent. |
42 | // b) SetCalCopy(1). |
43 | // Of every 'added' calorimeter a private copy will be made of which the pointer |
44 | // will be stored. |
45 | // In this way the AliEvent represents an entity on its own and modifications |
46 | // made to the original calorimeters do not affect the AliCalorimeter objects |
47 | // which are stored in the AliEvent. |
48 | // This mode will allow 'adding' many different AliCalorimeters into an AliEvent by |
49 | // creating only one AliCalorimeter instance in the main programme and using the |
50 | // AliCalorimeter::Reset() and AliCalorimeter parameter setting memberfunctions. |
51 | // |
52 | // Coding example to make an event consisting of a primary vertex, |
53 | // 2 secondary vertices and a calorimeter. |
d16062ac |
54 | // -------------------------------------------------------------- |
7849a8ab |
55 | // vp contains the tracks 1,2,3 and 4 (primary vertex) |
56 | // v1 contains the tracks 5,6 and 7 (sec. vertex) |
57 | // v2 contains the jets 1 and 2 (sec. vertex) |
58 | // |
59 | // AliCalorimeter emcal; |
60 | // ... |
61 | // ... // code to fill the calorimeter data |
62 | // ... |
d16062ac |
63 | // |
7849a8ab |
64 | // AliEvent evt; |
65 | // |
66 | // Specify the event object as the repository of all objects |
67 | // for the event building and physics analysis. |
68 | // |
69 | // evt.SetCalCopy(1); |
70 | // evt.SetTrackCopy(1); |
71 | // |
72 | // Fill the event structure with the basic objects |
73 | // |
74 | // evt.AddCalorimeter(emcal); |
75 | // |
76 | // AliTrack* tx; |
77 | // for (Int_t i=0; i<10; i++) |
78 | // { |
d16062ac |
79 | // ... |
80 | // ... // code to fill the track data |
81 | // ... |
7849a8ab |
82 | // evt.AddTrack(tx); |
83 | // tx->Reset(); |
84 | // } |
85 | // |
86 | // Build the event structure (vertices, jets, ...) for physics analysis |
87 | // based on the basic objects from the event repository. |
d16062ac |
88 | // |
89 | // AliJet j1,j2; |
7849a8ab |
90 | // for (Int_t i=0; i<evt.GetNtracks(); i++) |
91 | // { |
92 | // tx=evt.GetTrack(i); |
d16062ac |
93 | // ... |
94 | // ... // code to fill the jet data |
95 | // ... |
7849a8ab |
96 | // } |
d16062ac |
97 | // |
7849a8ab |
98 | // AliVertex vp; |
99 | // tx=evt.GetTrack(1) |
100 | // vp.AddTrack(tx); |
101 | // tx=evt.GetTrack(2) |
102 | // vp.AddTrack(tx); |
103 | // tx=evt.GetTrack(3) |
104 | // vp.AddTrack(tx); |
105 | // tx=evt.GetTrack(4) |
106 | // vp.AddTrack(tx); |
d16062ac |
107 | // |
7849a8ab |
108 | // Float_t rp[3]={2.4,0.1,-8.5}; |
109 | // vp.SetPosition(rp,"car"); |
d16062ac |
110 | // |
7849a8ab |
111 | // AliVertex v1; |
112 | // tx=evt.GetTrack(5) |
113 | // v1.AddTrack(tx); |
114 | // tx=evt.GetTrack(6) |
115 | // v1.AddTrack(tx); |
116 | // tx=evt.GetTrack(7) |
117 | // v1.AddTrack(tx); |
d16062ac |
118 | // |
119 | // Float_t r1[3]={1.6,-3.2,5.7}; |
120 | // v1.SetPosition(r1,"car"); |
121 | // |
d16062ac |
122 | // |
7849a8ab |
123 | // AliVertex v2; |
124 | // v2.SetJetCopy(1); |
d16062ac |
125 | // v2.AddJet(j1); |
126 | // v2.AddJet(j2); |
127 | // |
128 | // Float_t r2[3]={6.2,4.8,1.3}; |
129 | // v2.SetPosition(r2,"car"); |
130 | // |
7849a8ab |
131 | // Specify the vertices v1 and v2 as secondary vertices of the primary |
132 | // |
133 | // vp.SetVertexCopy(1); |
134 | // vp.AddVertex(v1); |
135 | // vp.AddVertex(v2); |
136 | // |
137 | // Enter the physics structures into the event |
138 | // evt.SetVertexCopy(1); |
139 | // evt.AddVertex(vp,0); |
140 | // |
141 | // The jets j1 and j2 are already available via sec. vertex v2, |
142 | // but can be made available also from the event itself if desired. |
143 | // AliJet* jx; |
144 | // jx=v2.GetJet(1); |
145 | // evt.AddJet(jx,0); |
146 | // jx=v2.GetJet(2); |
147 | // evt.AddJet(jx,0); |
148 | // |
d16062ac |
149 | // evt.Info("sph"); |
150 | // v1.ListAll(); |
151 | // v2.List("cyl"); |
152 | // |
153 | // Float_t etot=evt.GetEnergy(); |
154 | // Ali3Vector ptot=evt.Get3Momentum(); |
155 | // Float_t loc[3]; |
156 | // evt.GetPosition(loc,"sph"); |
157 | // AliPosition r=v1.GetPosition(); |
158 | // r.Info(); |
159 | // Int_t nt=v2.GetNtracks(); |
160 | // AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2 |
161 | // |
d16062ac |
162 | // evt.List(); |
163 | // |
164 | // Int_t nv=evt.GetNvtx(); |
7849a8ab |
165 | // AliVertex* vx=evt.GetVertex(1); // Access primary vertex |
d16062ac |
166 | // Float_t e=vx->GetEnergy(); |
167 | // |
168 | // Float_t M=evt.GetInvmass(); |
169 | // |
170 | // Reconstruct the event from scratch |
171 | // |
172 | // evt.Reset(); |
173 | // evt.SetNvmax(25); // Increase initial no. of sec. vertices |
7849a8ab |
174 | // ... |
175 | // ... // code to create tracks etc... |
176 | // ... |
d16062ac |
177 | // |
178 | // Note : All quantities are in GeV, GeV/c or GeV/c**2 |
179 | // |
180 | //--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht |
7849a8ab |
181 | //- Modified: NvE $Date: 2001/06/25 09:37:23 $ UU-SAP Utrecht |
d16062ac |
182 | /////////////////////////////////////////////////////////////////////////// |
183 | |
184 | #include "AliEvent.h" |
185 | |
186 | ClassImp(AliEvent) // Class implementation to enable ROOT I/O |
187 | |
188 | AliEvent::AliEvent() |
189 | { |
190 | // Default constructor. |
191 | // All variables initialised to default values. |
192 | fDaytime.Set(); |
193 | fRun=0; |
194 | fEvent=0; |
7849a8ab |
195 | fNcals=0; |
196 | fCalorimeters=0; |
197 | fCalCopy=0; |
d16062ac |
198 | } |
199 | /////////////////////////////////////////////////////////////////////////// |
81508922 |
200 | AliEvent::AliEvent(Int_t n): AliVertex(n) |
d16062ac |
201 | { |
202 | // Create an event to hold initially a maximum of n tracks |
203 | // All variables initialised to default values |
204 | fDaytime.Set(); |
205 | fRun=0; |
206 | fEvent=0; |
7849a8ab |
207 | fNcals=0; |
208 | fCalorimeters=0; |
209 | fCalCopy=0; |
d16062ac |
210 | } |
211 | /////////////////////////////////////////////////////////////////////////// |
212 | AliEvent::~AliEvent() |
213 | { |
214 | // Default destructor |
7849a8ab |
215 | if (fCalorimeters) |
216 | { |
217 | if (fCalCopy) fCalorimeters->Delete(); |
218 | delete fCalorimeters; |
219 | fCalorimeters=0; |
220 | } |
d16062ac |
221 | } |
222 | /////////////////////////////////////////////////////////////////////////// |
223 | void AliEvent::Reset() |
224 | { |
225 | // Reset all variables to default values |
226 | // The max. number of tracks is set to the initial value again |
227 | // The max. number of vertices is set to the default value again |
228 | fDaytime.Set(); |
229 | fRun=0; |
230 | fEvent=0; |
231 | |
7849a8ab |
232 | fNcals=0; |
233 | if (fCalorimeters) |
234 | { |
235 | if (fCalCopy) fCalorimeters->Delete(); |
236 | delete fCalorimeters; |
237 | fCalorimeters=0; |
238 | } |
239 | |
d16062ac |
240 | AliVertex::Reset(); |
241 | } |
242 | /////////////////////////////////////////////////////////////////////////// |
243 | void AliEvent::SetDayTime(TDatime& stamp) |
244 | { |
245 | // Set the date and time stamp for this event |
246 | fDaytime=stamp; |
247 | } |
248 | /////////////////////////////////////////////////////////////////////////// |
249 | void AliEvent::SetRunNumber(Int_t run) |
250 | { |
251 | // Set the run number for this event |
252 | fRun=run; |
253 | } |
254 | /////////////////////////////////////////////////////////////////////////// |
255 | void AliEvent::SetEventNumber(Int_t evt) |
256 | { |
257 | // Set the event number for this event |
258 | fEvent=evt; |
259 | } |
260 | /////////////////////////////////////////////////////////////////////////// |
261 | TDatime AliEvent::GetDayTime() |
262 | { |
263 | // Provide the date and time stamp for this event |
264 | return fDaytime; |
265 | } |
266 | /////////////////////////////////////////////////////////////////////////// |
267 | Int_t AliEvent::GetRunNumber() |
268 | { |
269 | // Provide the run number for this event |
270 | return fRun; |
271 | } |
272 | /////////////////////////////////////////////////////////////////////////// |
273 | Int_t AliEvent::GetEventNumber() |
274 | { |
275 | // Provide the event number for this event |
276 | return fEvent; |
277 | } |
278 | /////////////////////////////////////////////////////////////////////////// |
279 | void AliEvent::HeaderInfo() |
280 | { |
281 | // Provide event header information |
282 | Int_t date=fDaytime.GetDate(); |
283 | Int_t time=fDaytime.GetTime(); |
284 | |
285 | Int_t year=date/10000; |
286 | Int_t month=(date%10000)/100; |
287 | Int_t day=date%100; |
288 | Int_t hh=time/10000; |
289 | Int_t mm=(time%10000)/100; |
290 | Int_t ss=time%100; |
291 | |
292 | char* c[12]={"jan","feb","mar","apr","may","jun", |
293 | "jul","aug","sep","oct","nov","dec"}; |
294 | |
295 | cout << " *AliEvent::Info* Run : " << fRun << " Event : " << fEvent; |
296 | cout.fill('0'); |
297 | cout << " Date : " << setw(2) << day << "-" << c[month-1] << "-" << year |
298 | << " Time : " << setw(2) << hh << ":" << setw(2) << mm << ":" << setw(2) << ss << endl; |
299 | cout.fill(' '); |
7849a8ab |
300 | cout << " Ncalorimeters : " << fNcals << endl; |
d16062ac |
301 | } |
302 | /////////////////////////////////////////////////////////////////////////// |
303 | void AliEvent::Info(TString f) |
304 | { |
305 | // Provide event information within the coordinate frame f |
306 | HeaderInfo(); |
307 | AliVertex::Info(f); |
308 | } |
309 | /////////////////////////////////////////////////////////////////////////// |
7849a8ab |
310 | Int_t AliEvent::GetNcalorimeters() |
311 | { |
312 | // Provide the number of stored calorimeter systems |
313 | return fNcals; |
314 | } |
315 | /////////////////////////////////////////////////////////////////////////// |
316 | void AliEvent::AddCalorimeter(AliCalorimeter& c) |
317 | { |
318 | // Add a calorimeter system to the event |
319 | if (!fCalorimeters) fCalorimeters=new TObjArray(); |
320 | |
321 | // Add the calorimeter system to this event |
322 | fNcals++; |
323 | if (fCalCopy) |
324 | { |
325 | AliCalorimeter* cx=new AliCalorimeter(c); |
326 | fCalorimeters->AddLast(cx); |
327 | } |
328 | else |
329 | { |
330 | fCalorimeters->AddLast(&c); |
331 | } |
332 | } |
333 | /////////////////////////////////////////////////////////////////////////// |
334 | void AliEvent::SetCalCopy(Int_t j) |
335 | { |
336 | // (De)activate the creation of private copies of the added calorimeters. |
337 | // j=0 ==> No private copies are made; pointers of original cals. are stored. |
338 | // j=1 ==> Private copies of the cals. are made and these pointers are stored. |
339 | // |
340 | // Note : Once the storage contains pointer(s) to AliCalorimeter(s) one cannot |
341 | // change the CalCopy mode anymore. |
342 | // To change the CalCopy mode for an existing AliEvent containing |
343 | // calorimeters one first has to invoke Reset(). |
344 | if (!fCalorimeters) |
345 | { |
346 | if (j==0 || j==1) |
347 | { |
348 | fCalCopy=j; |
349 | } |
350 | else |
351 | { |
352 | cout << "*AliEvent::SetCalCopy* Invalid argument : " << j << endl; |
353 | } |
354 | } |
355 | else |
356 | { |
357 | cout << "*AliEvent::SetCalCopy* Storage already contained calorimeters." |
358 | << " ==> CalCopy mode not changed." << endl; |
359 | } |
360 | } |
361 | /////////////////////////////////////////////////////////////////////////// |
362 | Int_t AliEvent::GetCalCopy() |
363 | { |
364 | // Provide value of the CalCopy mode. |
365 | // 0 ==> No private copies are made; pointers of original cals. are stored. |
366 | // 1 ==> Private copies of the cals. are made and these pointers are stored. |
367 | return fCalCopy; |
368 | } |
369 | /////////////////////////////////////////////////////////////////////////// |
370 | AliCalorimeter* AliEvent::GetCalorimeter(Int_t i) |
371 | { |
372 | // Return the i-th calorimeter of this event |
373 | if (!fCalorimeters) |
374 | { |
375 | cout << " *AliEvent::GetCalorimeter* No calorimeters present." << endl; |
376 | return 0; |
377 | } |
378 | else |
379 | { |
380 | if (i<=0 || i>fNcals) |
381 | { |
382 | cout << " *AliEvent::GetCalorimeter* Invalid argument i : " << i |
383 | << " Ncals = " << fNcals << endl; |
384 | return 0; |
385 | } |
386 | else |
387 | { |
388 | return (AliCalorimeter*)fCalorimeters->At(i-1); |
389 | } |
390 | } |
391 | } |
392 | /////////////////////////////////////////////////////////////////////////// |
393 | AliCalorimeter* AliEvent::GetCalorimeter(TString name) |
394 | { |
395 | // Return the calorimeter with name tag "name" |
396 | if (!fCalorimeters) |
397 | { |
398 | cout << " *AliEvent::GetCalorimeter* No calorimeters present." << endl; |
399 | return 0; |
400 | } |
401 | else |
402 | { |
403 | AliCalorimeter* cx; |
404 | TString s; |
405 | for (Int_t i=0; i<fNcals; i++) |
406 | { |
407 | cx=(AliCalorimeter*)fCalorimeters->At(i); |
408 | s=cx->GetName(); |
409 | if (s == name) return cx; |
410 | } |
411 | |
412 | return 0; // No matching name found |
413 | } |
414 | } |
415 | /////////////////////////////////////////////////////////////////////////// |
d16062ac |
416 | |