]>
Commit | Line | Data |
---|---|---|
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 | ||
b055c99d | 16 | // $Id: AliEvent.cxx,v 1.22 2004/06/29 11:29:37 nick 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 |
7a086578 | 22 | // and/or devices like AliCalorimeters or AliDevice (derived) objects. |
23 | // | |
1c01b4f8 | 24 | // All objects which are derived from TObject can be regarded as a device. |
7a086578 | 25 | // However, AliDevice (or derived) objects profit from additional hit |
26 | // handling facilities. | |
27 | // A "hit" is a generic name indicating an AliSignal (or derived) object. | |
28 | // Note that AliEvent does NOT own hits; it only provides references to hits | |
29 | // obtained from the various devices. | |
30 | // This implies that hits should be owned by the devices themselves. | |
d16062ac | 31 | // |
32 | // The basic functionality of AliEvent is identical to the one of AliVertex. | |
35044448 | 33 | // So, an AliEvent may be used as the primary vertex with some additional |
34 | // functionality compared to AliVertex. | |
d16062ac | 35 | // |
7849a8ab | 36 | // To provide maximal flexibility to the user, the two modes of track/jet/vertex |
37 | // storage as described in AliJet and AliVertex can be used. | |
1c01b4f8 | 38 | // In addition an identical structure is provided for the storage of devices like |
39 | // AliCalorimeter objects, which can be selected by means of the memberfunction | |
40 | // SetDevCopy(). | |
41 | // | |
42 | // a) SetDevCopy(0) (which is the default). | |
43 | // Only the pointers of the 'added' devices are stored. | |
44 | // This mode is typically used by making studies based on a fixed set | |
45 | // of devices which stays under user control or is kept on an external | |
7849a8ab | 46 | // file/tree. |
47 | // In this way the AliEvent just represents a 'logical structure' for the | |
48 | // physics analysis. | |
35044448 | 49 | // |
50 | // Note : | |
1c01b4f8 | 51 | // Modifications made to the original devices also affect the device |
7849a8ab | 52 | // objects which are stored in the AliEvent. |
35044448 | 53 | // |
1c01b4f8 | 54 | // b) SetDevCopy(1). |
55 | // Of every 'added' device a private copy will be made of which the pointer | |
7849a8ab | 56 | // will be stored. |
57 | // In this way the AliEvent represents an entity on its own and modifications | |
58 | // made to the original calorimeters do not affect the AliCalorimeter objects | |
59 | // which are stored in the AliEvent. | |
1c01b4f8 | 60 | // This mode will allow 'adding' many different devices into an AliEvent by |
61 | // creating only one device instance in the main programme and using the | |
62 | // Reset() and parameter setting memberfunctions of the object representing the device. | |
63 | // | |
64 | // Note : | |
65 | // The copy is made using the Clone() memberfunction. | |
66 | // All devices (i.e. classes derived from TObject) have the default TObject::Clone() | |
67 | // memberfunction. | |
68 | // However, devices generally contain an internal (signal) data structure | |
69 | // which may include pointers to other objects. Therefore it is recommended to provide | |
70 | // for all devices a specific copy constructor and override the default Clone() | |
71 | // memberfunction using this copy constructor. | |
7a086578 | 72 | // Examples for this may be seen from AliCalorimeter, AliSignal and AliDevice. |
7849a8ab | 73 | // |
8e8e6c7f | 74 | // See also the documentation provided for the memberfunction SetOwner(). |
75 | // | |
7849a8ab | 76 | // Coding example to make an event consisting of a primary vertex, |
77 | // 2 secondary vertices and a calorimeter. | |
d16062ac | 78 | // -------------------------------------------------------------- |
7849a8ab | 79 | // vp contains the tracks 1,2,3 and 4 (primary vertex) |
80 | // v1 contains the tracks 5,6 and 7 (sec. vertex) | |
81 | // v2 contains the jets 1 and 2 (sec. vertex) | |
82 | // | |
7849a8ab | 83 | // AliEvent evt; |
84 | // | |
85 | // Specify the event object as the repository of all objects | |
86 | // for the event building and physics analysis. | |
87 | // | |
1c01b4f8 | 88 | // evt.SetDevCopy(1); |
7849a8ab | 89 | // evt.SetTrackCopy(1); |
90 | // | |
91 | // Fill the event structure with the basic objects | |
92 | // | |
b055c99d | 93 | // AliCalorimeter emcal1; |
94 | // AliCalorimeter emcal2; | |
35044448 | 95 | // ... |
b055c99d | 96 | // ... // code to fill the emcal1 and emcal2 calorimeter data |
35044448 | 97 | // ... |
98 | // | |
b055c99d | 99 | // evt.AddDevice(emcal1); |
100 | // evt.AddDevice(emcal2); | |
7849a8ab | 101 | // |
7a086578 | 102 | // // Assume AliTOF has been derived from AliDevice |
103 | // AliTOF tof1; | |
104 | // AliTOF tof2; | |
105 | // ... | |
106 | // ... // code to fill the tof1 and tof2 data | |
107 | // ... | |
108 | // | |
109 | // evt.AddDevice(tof1); | |
110 | // evt.AddDevice(tof2); | |
111 | // | |
35044448 | 112 | // AliTrack* tx=new AliTrack(); |
7849a8ab | 113 | // for (Int_t i=0; i<10; i++) |
114 | // { | |
d16062ac | 115 | // ... |
116 | // ... // code to fill the track data | |
117 | // ... | |
7849a8ab | 118 | // evt.AddTrack(tx); |
119 | // tx->Reset(); | |
120 | // } | |
121 | // | |
35044448 | 122 | // if (tx) |
123 | // { | |
124 | // delete tx; | |
125 | // tx=0; | |
126 | // } | |
127 | // | |
7a086578 | 128 | // Order and investigate all the hits of all the TOF devices |
129 | // | |
130 | // TObjArray* hits=evt.GetHits("AliTOF"); | |
b055c99d | 131 | // TObjArray orderedtofs=evt.SortHits(hits); |
132 | // Int_t nhits=orderedtofs.GetEntries(); | |
7a086578 | 133 | // for (Int_t i=0; i<nhits; i++) |
134 | // { | |
b055c99d | 135 | // AliSignal* sx=(AliSignal*)orderedtofs.At(i); |
136 | // if (sx) sx->Data(); | |
137 | // } | |
138 | // | |
139 | // Order and investigate all the hits of all the calorimeter devices | |
140 | // | |
141 | // TObjArray* hits=evt.GetHits("AliCalorimeter"); | |
142 | // TObjArray orderedcals=evt.SortHits(hits); | |
143 | // Int_t nhits=orderedcals.GetEntries(); | |
144 | // for (Int_t i=0; i<nhits; i++) | |
145 | // { | |
146 | // AliSignal* sx=(AliSignal*)orderedcals.At(i); | |
7a086578 | 147 | // if (sx) sx->Data(); |
148 | // } | |
149 | // | |
7849a8ab | 150 | // Build the event structure (vertices, jets, ...) for physics analysis |
151 | // based on the basic objects from the event repository. | |
d16062ac | 152 | // |
153 | // AliJet j1,j2; | |
7849a8ab | 154 | // for (Int_t i=0; i<evt.GetNtracks(); i++) |
155 | // { | |
156 | // tx=evt.GetTrack(i); | |
d16062ac | 157 | // ... |
158 | // ... // code to fill the jet data | |
159 | // ... | |
7849a8ab | 160 | // } |
d16062ac | 161 | // |
7849a8ab | 162 | // AliVertex vp; |
35044448 | 163 | // tx=evt.GetTrack(1); |
7849a8ab | 164 | // vp.AddTrack(tx); |
35044448 | 165 | // tx=evt.GetTrack(2); |
7849a8ab | 166 | // vp.AddTrack(tx); |
35044448 | 167 | // tx=evt.GetTrack(3); |
7849a8ab | 168 | // vp.AddTrack(tx); |
35044448 | 169 | // tx=evt.GetTrack(4); |
7849a8ab | 170 | // vp.AddTrack(tx); |
d16062ac | 171 | // |
7849a8ab | 172 | // Float_t rp[3]={2.4,0.1,-8.5}; |
173 | // vp.SetPosition(rp,"car"); | |
d16062ac | 174 | // |
7849a8ab | 175 | // AliVertex v1; |
35044448 | 176 | // tx=evt.GetTrack(5); |
7849a8ab | 177 | // v1.AddTrack(tx); |
35044448 | 178 | // tx=evt.GetTrack(6); |
7849a8ab | 179 | // v1.AddTrack(tx); |
35044448 | 180 | // tx=evt.GetTrack(7); |
7849a8ab | 181 | // v1.AddTrack(tx); |
d16062ac | 182 | // |
183 | // Float_t r1[3]={1.6,-3.2,5.7}; | |
184 | // v1.SetPosition(r1,"car"); | |
185 | // | |
d16062ac | 186 | // |
7849a8ab | 187 | // AliVertex v2; |
188 | // v2.SetJetCopy(1); | |
d16062ac | 189 | // v2.AddJet(j1); |
190 | // v2.AddJet(j2); | |
191 | // | |
192 | // Float_t r2[3]={6.2,4.8,1.3}; | |
193 | // v2.SetPosition(r2,"car"); | |
194 | // | |
7849a8ab | 195 | // Specify the vertices v1 and v2 as secondary vertices of the primary |
196 | // | |
197 | // vp.SetVertexCopy(1); | |
198 | // vp.AddVertex(v1); | |
199 | // vp.AddVertex(v2); | |
200 | // | |
201 | // Enter the physics structures into the event | |
202 | // evt.SetVertexCopy(1); | |
203 | // evt.AddVertex(vp,0); | |
204 | // | |
205 | // The jets j1 and j2 are already available via sec. vertex v2, | |
206 | // but can be made available also from the event itself if desired. | |
207 | // AliJet* jx; | |
208 | // jx=v2.GetJet(1); | |
209 | // evt.AddJet(jx,0); | |
210 | // jx=v2.GetJet(2); | |
211 | // evt.AddJet(jx,0); | |
212 | // | |
84bb7c66 | 213 | // evt.Data("sph"); |
d16062ac | 214 | // v1.ListAll(); |
215 | // v2.List("cyl"); | |
216 | // | |
217 | // Float_t etot=evt.GetEnergy(); | |
218 | // Ali3Vector ptot=evt.Get3Momentum(); | |
219 | // Float_t loc[3]; | |
220 | // evt.GetPosition(loc,"sph"); | |
221 | // AliPosition r=v1.GetPosition(); | |
84bb7c66 | 222 | // r.Data(); |
d16062ac | 223 | // Int_t nt=v2.GetNtracks(); |
224 | // AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2 | |
225 | // | |
d16062ac | 226 | // evt.List(); |
227 | // | |
228 | // Int_t nv=evt.GetNvtx(); | |
7849a8ab | 229 | // AliVertex* vx=evt.GetVertex(1); // Access primary vertex |
d16062ac | 230 | // Float_t e=vx->GetEnergy(); |
231 | // | |
232 | // Float_t M=evt.GetInvmass(); | |
233 | // | |
234 | // Reconstruct the event from scratch | |
235 | // | |
236 | // evt.Reset(); | |
237 | // evt.SetNvmax(25); // Increase initial no. of sec. vertices | |
7849a8ab | 238 | // ... |
239 | // ... // code to create tracks etc... | |
240 | // ... | |
d16062ac | 241 | // |
242 | // Note : All quantities are in GeV, GeV/c or GeV/c**2 | |
243 | // | |
244 | //--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht | |
b055c99d | 245 | //- Modified: NvE $Date: 2004/06/29 11:29:37 $ UU-SAP Utrecht |
d16062ac | 246 | /////////////////////////////////////////////////////////////////////////// |
247 | ||
248 | #include "AliEvent.h" | |
c72198f1 | 249 | #include "Riostream.h" |
d16062ac | 250 | |
251 | ClassImp(AliEvent) // Class implementation to enable ROOT I/O | |
252 | ||
c72198f1 | 253 | AliEvent::AliEvent() : AliVertex() |
d16062ac | 254 | { |
255 | // Default constructor. | |
256 | // All variables initialised to default values. | |
4bb13277 | 257 | fDaytime.Set(); |
d16062ac | 258 | fRun=0; |
259 | fEvent=0; | |
4575fcea | 260 | fAproj=0; |
261 | fZproj=0; | |
262 | fPnucProj=0; | |
da17f667 | 263 | fIdProj=0; |
4575fcea | 264 | fAtarg=0; |
265 | fZtarg=0; | |
266 | fPnucTarg=0; | |
da17f667 | 267 | fIdTarg=0; |
1c01b4f8 | 268 | fDevices=0; |
269 | fDevCopy=0; | |
7a086578 | 270 | fHits=0; |
d16062ac | 271 | } |
272 | /////////////////////////////////////////////////////////////////////////// | |
c72198f1 | 273 | AliEvent::AliEvent(Int_t n) : AliVertex(n) |
d16062ac | 274 | { |
275 | // Create an event to hold initially a maximum of n tracks | |
276 | // All variables initialised to default values | |
c72198f1 | 277 | if (n<=0) |
278 | { | |
279 | cout << " *** This AliVertex initialisation was invoked via the AliEvent ctor." << endl; | |
280 | } | |
4bb13277 | 281 | fDaytime.Set(); |
d16062ac | 282 | fRun=0; |
283 | fEvent=0; | |
4575fcea | 284 | fAproj=0; |
285 | fZproj=0; | |
286 | fPnucProj=0; | |
da17f667 | 287 | fIdProj=0; |
4575fcea | 288 | fAtarg=0; |
289 | fZtarg=0; | |
290 | fPnucTarg=0; | |
da17f667 | 291 | fIdTarg=0; |
1c01b4f8 | 292 | fDevices=0; |
293 | fDevCopy=0; | |
7a086578 | 294 | fHits=0; |
d16062ac | 295 | } |
296 | /////////////////////////////////////////////////////////////////////////// | |
297 | AliEvent::~AliEvent() | |
298 | { | |
299 | // Default destructor | |
1c01b4f8 | 300 | if (fDevices) |
7849a8ab | 301 | { |
1c01b4f8 | 302 | delete fDevices; |
303 | fDevices=0; | |
7849a8ab | 304 | } |
7a086578 | 305 | if (fHits) |
306 | { | |
307 | delete fHits; | |
308 | fHits=0; | |
309 | } | |
d16062ac | 310 | } |
311 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 312 | AliEvent::AliEvent(const AliEvent& evt) : AliVertex(evt) |
c72198f1 | 313 | { |
314 | // Copy constructor. | |
315 | fDaytime=evt.fDaytime; | |
316 | fRun=evt.fRun; | |
317 | fEvent=evt.fEvent; | |
318 | fAproj=evt.fAproj; | |
319 | fZproj=evt.fZproj; | |
320 | fPnucProj=evt.fPnucProj; | |
321 | fIdProj=evt.fIdProj; | |
322 | fAtarg=evt.fAtarg; | |
323 | fZtarg=evt.fZtarg; | |
324 | fPnucTarg=evt.fPnucTarg; | |
325 | fIdTarg=evt.fIdTarg; | |
1c01b4f8 | 326 | fDevCopy=evt.fDevCopy; |
c72198f1 | 327 | |
1c01b4f8 | 328 | fDevices=0; |
329 | Int_t ndevs=evt.GetNdevices(); | |
330 | if (ndevs) | |
c72198f1 | 331 | { |
1c01b4f8 | 332 | fDevices=new TObjArray(ndevs); |
333 | if (fDevCopy) fDevices->SetOwner(); | |
334 | for (Int_t i=1; i<=ndevs; i++) | |
c72198f1 | 335 | { |
1c01b4f8 | 336 | TObject* dev=evt.GetDevice(i); |
337 | if (dev) | |
c72198f1 | 338 | { |
1c01b4f8 | 339 | if (fDevCopy) |
c72198f1 | 340 | { |
1c01b4f8 | 341 | fDevices->Add(dev->Clone()); |
c72198f1 | 342 | } |
343 | else | |
344 | { | |
1c01b4f8 | 345 | fDevices->Add(dev); |
c72198f1 | 346 | } |
347 | } | |
348 | } | |
349 | } | |
7a086578 | 350 | |
351 | fHits=0; | |
352 | if (evt.fHits) | |
353 | { | |
354 | Int_t nhits=evt.fHits->GetEntries(); | |
355 | if (nhits) | |
356 | { | |
357 | fHits=new TObjArray(nhits); | |
358 | for (Int_t ih=0; ih<nhits; ih++) | |
359 | { | |
360 | AliSignal* sx=(AliSignal*)evt.fHits->At(ih); | |
361 | fHits->Add(sx); | |
362 | } | |
363 | } | |
364 | } | |
c72198f1 | 365 | } |
366 | /////////////////////////////////////////////////////////////////////////// | |
d16062ac | 367 | void AliEvent::Reset() |
368 | { | |
369 | // Reset all variables to default values | |
370 | // The max. number of tracks is set to the initial value again | |
371 | // The max. number of vertices is set to the default value again | |
8e8e6c7f | 372 | // Note : The CalCopy mode is maintained as it was set by the user before. |
c72198f1 | 373 | |
374 | AliVertex::Reset(); | |
375 | ||
4bb13277 | 376 | fDaytime.Set(); |
d16062ac | 377 | fRun=0; |
378 | fEvent=0; | |
4575fcea | 379 | fAproj=0; |
380 | fZproj=0; | |
381 | fPnucProj=0; | |
da17f667 | 382 | fIdProj=0; |
4575fcea | 383 | fAtarg=0; |
384 | fZtarg=0; | |
385 | fPnucTarg=0; | |
da17f667 | 386 | fIdTarg=0; |
d16062ac | 387 | |
1c01b4f8 | 388 | if (fDevices) |
7849a8ab | 389 | { |
1c01b4f8 | 390 | delete fDevices; |
391 | fDevices=0; | |
7849a8ab | 392 | } |
7a086578 | 393 | if (fHits) |
394 | { | |
395 | delete fHits; | |
396 | fHits=0; | |
397 | } | |
d16062ac | 398 | } |
399 | /////////////////////////////////////////////////////////////////////////// | |
8e8e6c7f | 400 | void AliEvent::SetOwner(Bool_t own) |
401 | { | |
402 | // Set ownership of all added objects. | |
403 | // The default parameter is own=kTRUE. | |
404 | // | |
405 | // Invokation of this memberfunction also sets all the copy modes | |
406 | // (e.g. TrackCopy & co.) according to the value of own. | |
407 | // | |
408 | // This function (with own=kTRUE) is particularly useful when reading data | |
409 | // from a tree/file, since Reset() will then actually remove all the | |
410 | // added objects from memory irrespective of the copy mode settings | |
411 | // during the tree/file creation process. In this way it provides a nice way | |
412 | // of preventing possible memory leaks in the reading/analysis process. | |
413 | // | |
414 | // In addition this memberfunction can also be used as a shortcut to set all | |
415 | // copy modes in one go during a tree/file creation process. | |
416 | // However, in this case the user has to take care to only set/change the | |
417 | // ownership (and copy mode) for empty objects (e.g. newly created objects | |
418 | // or after invokation of the Reset() memberfunction) otherwise it will | |
419 | // very likely result in inconsistent destructor behaviour. | |
420 | ||
421 | Int_t mode=1; | |
422 | if (!own) mode=0; | |
1c01b4f8 | 423 | if (fDevices) fDevices->SetOwner(own); |
424 | fDevCopy=mode; | |
8e8e6c7f | 425 | |
426 | AliVertex::SetOwner(own); | |
427 | } | |
428 | /////////////////////////////////////////////////////////////////////////// | |
387a745b | 429 | void AliEvent::SetDayTime(TTimeStamp& stamp) |
d16062ac | 430 | { |
387a745b | 431 | // Set the date and time stamp for this event. |
432 | // An exact copy of the entered date/time stamp will be saved with an | |
47dddbe4 | 433 | // accuracy of 1 nanosecond. |
d16062ac | 434 | fDaytime=stamp; |
435 | } | |
436 | /////////////////////////////////////////////////////////////////////////// | |
387a745b | 437 | void AliEvent::SetDayTime(TDatime& stamp) |
438 | { | |
439 | // Set the date and time stamp for this event. | |
440 | // The entered date/time will be interpreted as being the local date/time | |
441 | // and the accuracy is 1 second. | |
442 | // This function with the TDatime argument is mainly kept for backward | |
443 | // compatibility reasons. It is recommended to use the corresponding | |
444 | // function with the TTimeStamp argument. | |
445 | ||
4bb13277 | 446 | fDaytime.Set(stamp.GetDate(),stamp.GetTime(),0,kFALSE,0); |
387a745b | 447 | } |
448 | /////////////////////////////////////////////////////////////////////////// | |
d16062ac | 449 | void AliEvent::SetRunNumber(Int_t run) |
450 | { | |
451 | // Set the run number for this event | |
452 | fRun=run; | |
453 | } | |
454 | /////////////////////////////////////////////////////////////////////////// | |
455 | void AliEvent::SetEventNumber(Int_t evt) | |
456 | { | |
457 | // Set the event number for this event | |
458 | fEvent=evt; | |
459 | } | |
460 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 461 | TTimeStamp AliEvent::GetDayTime() const |
d16062ac | 462 | { |
463 | // Provide the date and time stamp for this event | |
464 | return fDaytime; | |
465 | } | |
466 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 467 | Int_t AliEvent::GetRunNumber() const |
d16062ac | 468 | { |
469 | // Provide the run number for this event | |
470 | return fRun; | |
471 | } | |
472 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 473 | Int_t AliEvent::GetEventNumber() const |
d16062ac | 474 | { |
475 | // Provide the event number for this event | |
476 | return fEvent; | |
477 | } | |
478 | /////////////////////////////////////////////////////////////////////////// | |
da17f667 | 479 | void AliEvent::SetProjectile(Int_t a,Int_t z,Double_t pnuc,Int_t id) |
4575fcea | 480 | { |
da17f667 | 481 | // Set the projectile A, Z, momentum per nucleon and user defined particle ID. |
482 | // By default the particle ID is set to zero. | |
4575fcea | 483 | fAproj=a; |
484 | fZproj=z; | |
485 | fPnucProj=pnuc; | |
da17f667 | 486 | fIdProj=id; |
4575fcea | 487 | } |
488 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 489 | Int_t AliEvent::GetProjectileA() const |
4575fcea | 490 | { |
491 | // Provide the projectile A value. | |
492 | return fAproj; | |
493 | } | |
494 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 495 | Int_t AliEvent::GetProjectileZ() const |
4575fcea | 496 | { |
497 | // Provide the projectile Z value. | |
498 | return fZproj; | |
499 | } | |
500 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 501 | Double_t AliEvent::GetProjectilePnuc() const |
4575fcea | 502 | { |
503 | // Provide the projectile momentum value per nucleon. | |
504 | return fPnucProj; | |
505 | } | |
506 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 507 | Int_t AliEvent::GetProjectileId() const |
4575fcea | 508 | { |
da17f667 | 509 | // Provide the user defined particle ID of the projectile. |
510 | return fIdProj; | |
511 | } | |
512 | /////////////////////////////////////////////////////////////////////////// | |
513 | void AliEvent::SetTarget(Int_t a,Int_t z,Double_t pnuc,Int_t id) | |
514 | { | |
515 | // Set the target A, Z, momentum per nucleon and user defined particle ID. | |
516 | // By default the particle ID is set to zero. | |
4575fcea | 517 | fAtarg=a; |
518 | fZtarg=z; | |
519 | fPnucTarg=pnuc; | |
da17f667 | 520 | fIdTarg=id; |
4575fcea | 521 | } |
522 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 523 | Int_t AliEvent::GetTargetA() const |
4575fcea | 524 | { |
525 | // Provide the target A value. | |
526 | return fAtarg; | |
527 | } | |
528 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 529 | Int_t AliEvent::GetTargetZ() const |
4575fcea | 530 | { |
531 | // Provide the target Z value. | |
532 | return fZtarg; | |
533 | } | |
534 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 535 | Double_t AliEvent::GetTargetPnuc() const |
4575fcea | 536 | { |
537 | // Provide the target momentum value per nucleon. | |
538 | return fPnucTarg; | |
539 | } | |
540 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 541 | Int_t AliEvent::GetTargetId() const |
da17f667 | 542 | { |
543 | // Provide the user defined particle ID of the target. | |
544 | return fIdTarg; | |
545 | } | |
546 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 547 | void AliEvent::HeaderData() const |
d16062ac | 548 | { |
549 | // Provide event header information | |
47dddbe4 | 550 | const char* name=GetName(); |
551 | const char* title=GetTitle(); | |
552 | Int_t ndevs=GetNdevices(); | |
553 | cout << " *" << ClassName() << "::Data*"; | |
554 | if (strlen(name)) cout << " Name : " << GetName(); | |
555 | if (strlen(title)) cout << " Title : " << GetTitle(); | |
556 | cout << endl; | |
387a745b | 557 | cout << " " << fDaytime.AsString() << endl; |
47dddbe4 | 558 | cout << " Run : " << fRun << " Event : " << fEvent |
559 | << " Number of devices : " << ndevs << endl; | |
d16062ac | 560 | |
47dddbe4 | 561 | if (ndevs) ShowDevices(); |
d16062ac | 562 | } |
563 | /////////////////////////////////////////////////////////////////////////// | |
84bb7c66 | 564 | void AliEvent::Data(TString f) |
d16062ac | 565 | { |
566 | // Provide event information within the coordinate frame f | |
84bb7c66 | 567 | HeaderData(); |
568 | AliVertex::Data(f); | |
d16062ac | 569 | } |
570 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 571 | Int_t AliEvent::GetNdevices() const |
7849a8ab | 572 | { |
1c01b4f8 | 573 | // Provide the number of stored devices |
574 | Int_t ndevs=0; | |
575 | if (fDevices) ndevs=fDevices->GetEntries(); | |
576 | return ndevs; | |
7849a8ab | 577 | } |
578 | /////////////////////////////////////////////////////////////////////////// | |
1c01b4f8 | 579 | void AliEvent::AddDevice(TObject& d) |
7849a8ab | 580 | { |
1c01b4f8 | 581 | // Add a device to the event. |
582 | // | |
583 | // Note : | |
584 | // In case a private copy is made, this is performed via the Clone() memberfunction. | |
585 | // All devices (i.e. classes derived from TObject) have the default TObject::Clone() | |
586 | // memberfunction. | |
587 | // However, devices generally contain an internal (signal) data structure | |
588 | // which may include pointers to other objects. Therefore it is recommended to provide | |
589 | // for all devices a specific copy constructor and override the default Clone() | |
590 | // memberfunction using this copy constructor. | |
591 | // An example for this may be seen from AliCalorimeter. | |
592 | ||
593 | if (!fDevices) | |
6516b62d | 594 | { |
1c01b4f8 | 595 | fDevices=new TObjArray(); |
596 | if (fDevCopy) fDevices->SetOwner(); | |
6516b62d | 597 | } |
7849a8ab | 598 | |
1c01b4f8 | 599 | // Add the device to this event |
600 | if (fDevCopy) | |
7849a8ab | 601 | { |
1c01b4f8 | 602 | fDevices->Add(d.Clone()); |
7849a8ab | 603 | } |
604 | else | |
605 | { | |
1c01b4f8 | 606 | fDevices->Add(&d); |
7849a8ab | 607 | } |
608 | } | |
609 | /////////////////////////////////////////////////////////////////////////// | |
1c01b4f8 | 610 | void AliEvent::SetDevCopy(Int_t j) |
7849a8ab | 611 | { |
1c01b4f8 | 612 | // (De)activate the creation of private copies of the added devices. |
613 | // j=0 ==> No private copies are made; pointers of original devices are stored. | |
614 | // j=1 ==> Private copies of the devices are made and these pointers are stored. | |
615 | // | |
616 | // | |
617 | // Notes : | |
618 | // In case a private copy is made, this is performed via the Clone() memberfunction. | |
619 | // All devices (i.e. classes derived from TObject) have the default TObject::Clone() | |
620 | // memberfunction. | |
621 | // However, devices generally contain an internal (signal) data structure | |
622 | // which may include pointers to other objects. Therefore it is recommended to provide | |
623 | // for all devices a specific copy constructor and override the default Clone() | |
624 | // memberfunction using this copy constructor. | |
625 | // An example for this may be seen from AliCalorimeter. | |
626 | // | |
627 | // Once the storage contains pointer(s) to device(s) one cannot | |
628 | // change the DevCopy mode anymore. | |
629 | // To change the DevCopy mode for an existing AliEvent containing | |
630 | // devices one first has to invoke Reset(). | |
631 | ||
632 | if (!fDevices) | |
7849a8ab | 633 | { |
634 | if (j==0 || j==1) | |
635 | { | |
1c01b4f8 | 636 | fDevCopy=j; |
7849a8ab | 637 | } |
638 | else | |
639 | { | |
1c01b4f8 | 640 | cout << " *" << ClassName() << "::SetDevCopy* Invalid argument : " << j << endl; |
7849a8ab | 641 | } |
642 | } | |
643 | else | |
644 | { | |
1c01b4f8 | 645 | cout << " *" << ClassName() << "::SetDevCopy* Storage already contained devices." |
646 | << " ==> DevCopy mode not changed." << endl; | |
7849a8ab | 647 | } |
648 | } | |
649 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 650 | Int_t AliEvent::GetDevCopy() const |
7849a8ab | 651 | { |
1c01b4f8 | 652 | // Provide value of the DevCopy mode. |
653 | // 0 ==> No private copies are made; pointers of original devices are stored. | |
654 | // 1 ==> Private copies of the devices are made and these pointers are stored. | |
655 | // | |
656 | // Note : | |
657 | // In case a private copy is made, this is performed via the Clone() memberfunction. | |
658 | // All devices (i.e. classes derived from TObject) have the default TObject::Clone() | |
659 | // memberfunction. | |
660 | // However, devices generally contain an internal (signal) data structure | |
661 | // which may include pointers to other objects. Therefore it is recommended to provide | |
662 | // for all devices a specific copy constructor and override the default Clone() | |
663 | // memberfunction using this copy constructor. | |
664 | // An example for this may be seen from AliCalorimeter. | |
665 | ||
666 | return fDevCopy; | |
7849a8ab | 667 | } |
668 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 669 | TObject* AliEvent::GetDevice(Int_t i) const |
7849a8ab | 670 | { |
1c01b4f8 | 671 | // Return the i-th device of this event. |
672 | // The first device corresponds to i=1. | |
673 | ||
674 | if (!fDevices) | |
7849a8ab | 675 | { |
7849a8ab | 676 | return 0; |
677 | } | |
678 | else | |
679 | { | |
1c01b4f8 | 680 | Int_t ndevs=GetNdevices(); |
681 | if (i<=0 || i>ndevs) | |
7849a8ab | 682 | { |
1c01b4f8 | 683 | cout << " *" << ClassName() << "::GetDevice* Invalid argument i : " << i |
684 | << " ndevs = " << ndevs << endl; | |
7849a8ab | 685 | return 0; |
686 | } | |
687 | else | |
688 | { | |
1c01b4f8 | 689 | return fDevices->At(i-1); |
7849a8ab | 690 | } |
691 | } | |
692 | } | |
693 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 694 | TObject* AliEvent::GetDevice(TString name) const |
7849a8ab | 695 | { |
1c01b4f8 | 696 | // Return the device with name tag "name" |
697 | if (!fDevices) | |
7849a8ab | 698 | { |
7849a8ab | 699 | return 0; |
700 | } | |
701 | else | |
702 | { | |
7849a8ab | 703 | TString s; |
1c01b4f8 | 704 | Int_t ndevs=GetNdevices(); |
705 | for (Int_t i=0; i<ndevs; i++) | |
7849a8ab | 706 | { |
1c01b4f8 | 707 | TObject* dev=fDevices->At(i); |
708 | if (dev) | |
35044448 | 709 | { |
1c01b4f8 | 710 | s=dev->GetName(); |
711 | if (s == name) return dev; | |
35044448 | 712 | } |
7849a8ab | 713 | } |
714 | ||
715 | return 0; // No matching name found | |
716 | } | |
717 | } | |
718 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 719 | void AliEvent::ShowDevices() const |
1ce8a857 | 720 | { |
1c01b4f8 | 721 | // Provide an overview of the available devices. |
722 | Int_t ndevs=GetNdevices(); | |
723 | if (ndevs) | |
1ce8a857 | 724 | { |
1c01b4f8 | 725 | cout << " The following " << ndevs << " devices are available :" << endl; |
726 | for (Int_t i=1; i<=ndevs; i++) | |
1ce8a857 | 727 | { |
1c01b4f8 | 728 | TObject* dev=GetDevice(i); |
729 | if (dev) | |
730 | { | |
731 | cout << " Device number : " << i | |
732 | << " Class : " << dev->ClassName() | |
733 | << " Name : " << dev->GetName() << endl; | |
734 | } | |
1ce8a857 | 735 | } |
736 | } | |
737 | else | |
738 | { | |
1c01b4f8 | 739 | cout << " No devices present for this event." << endl; |
1ce8a857 | 740 | } |
741 | } | |
742 | /////////////////////////////////////////////////////////////////////////// | |
7a086578 | 743 | Int_t AliEvent::GetNhits(const char* classname) |
744 | { | |
745 | // Provide the number of hits registered to the specified device class. | |
746 | // The specified device class has to be derived from AliDevice. | |
747 | // It is possible to indicate with the argument "classname" a specific | |
748 | // device instead of a whole class of devices. However, in such a case | |
749 | // it is more efficient to use the GetDevice() memberfunction directly. | |
750 | LoadHits(classname); | |
751 | Int_t nhits=0; | |
752 | if (fHits) nhits=fHits->GetEntries(); | |
753 | return nhits; | |
754 | } | |
755 | /////////////////////////////////////////////////////////////////////////// | |
756 | TObjArray* AliEvent::GetHits(const char* classname) | |
757 | { | |
758 | // Provide the references to all the hits registered to the specified | |
759 | // device class. | |
760 | // The specified device class has to be derived from AliDevice. | |
761 | // It is possible to indicate with the argument "classname" a specific | |
762 | // device instead of a whole class of devices. However, in such a case | |
763 | // it is more efficient to use the GetDevice() memberfunction directly. | |
764 | LoadHits(classname); | |
765 | return fHits; | |
766 | } | |
767 | /////////////////////////////////////////////////////////////////////////// | |
768 | void AliEvent::LoadHits(const char* classname) | |
769 | { | |
770 | // Load the references to the various hits registered to the specified | |
771 | // device class. | |
772 | // The specified device class has to be derived from AliDevice. | |
773 | if (fHits) fHits->Clear(); | |
774 | ||
775 | Int_t ndev=GetNdevices(); | |
776 | for (Int_t idev=1; idev<=ndev; idev++) | |
777 | { | |
778 | TObject* obj=GetDevice(idev); | |
779 | if (!obj) continue; | |
780 | ||
781 | if (obj->InheritsFrom(classname) && obj->InheritsFrom("AliDevice")) | |
782 | { | |
783 | AliDevice* dev=(AliDevice*)GetDevice(idev); | |
784 | Int_t nhits=dev->GetNhits(); | |
785 | if (nhits) | |
786 | { | |
787 | if (!fHits) fHits=new TObjArray(); | |
788 | for (Int_t ih=1; ih<=nhits; ih++) | |
789 | { | |
790 | AliSignal* sx=dev->GetHit(ih); | |
791 | if (sx) fHits->Add(sx); | |
792 | } | |
793 | } | |
794 | } | |
795 | } | |
796 | } | |
797 | /////////////////////////////////////////////////////////////////////////// | |
798 | TObjArray AliEvent::SortHits(TObjArray* hits,Int_t idx,Int_t mode) const | |
799 | { | |
800 | // Order the references to an array of hits by looping over the input array "hits" | |
801 | // and checking the signal value. The ordered array is returned as a TObjArray. | |
802 | // Note that the input array is not modified. | |
803 | // A "hit" represents an abstract object which is derived from AliSignal. | |
804 | // The user can specify the index of the signal slot to perform the sorting on. | |
805 | // By default the slotindex will be 1. | |
806 | // Via the "mode" argument the user can specify ordering in decreasing | |
807 | // order (mode=-1) or ordering in increasing order (mode=1). | |
808 | // The default is mode=-1. | |
809 | // Signals which were declared as "Dead" will be rejected. | |
810 | // The gain etc... corrected signals will be used in the ordering process. | |
811 | ||
812 | if (idx<=0 || abs(mode)!=1 || !hits) | |
813 | { | |
814 | TObjArray ordered; | |
815 | return ordered; | |
816 | } | |
817 | else | |
818 | { | |
819 | AliDevice dev; | |
820 | TObjArray ordered=dev.SortHits(idx,mode,hits); | |
821 | return ordered; | |
822 | } | |
823 | } | |
824 | /////////////////////////////////////////////////////////////////////////// | |
825 | TObjArray AliEvent::SortHits(TObjArray* hits,TString name,Int_t mode) const | |
826 | { | |
827 | // Order the references to an array of hits by looping over the input array "hits" | |
828 | // and checking the signal value. The ordered array is returned as a TObjArray. | |
829 | // Note that the input array is not modified. | |
830 | // A "hit" represents an abstract object which is derived from AliSignal. | |
831 | // The user can specify the name of the signal slot to perform the sorting on. | |
832 | // In case no matching slotname is found, the signal will be skipped. | |
833 | // Via the "mode" argument the user can specify ordering in decreasing | |
834 | // order (mode=-1) or ordering in increasing order (mode=1). | |
835 | // The default is mode=-1. | |
836 | // Signals which were declared as "Dead" will be rejected. | |
837 | // The gain etc... corrected signals will be used in the ordering process. | |
838 | ||
839 | if (abs(mode)!=1 || !hits) | |
840 | { | |
841 | TObjArray ordered; | |
842 | return ordered; | |
843 | } | |
844 | else | |
845 | { | |
846 | AliDevice dev; | |
847 | TObjArray ordered=dev.SortHits(name,mode,hits); | |
848 | return ordered; | |
849 | } | |
850 | } | |
851 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 852 | TObject* AliEvent::Clone(const char* name) const |
5f25234b | 853 | { |
854 | // Make a deep copy of the current object and provide the pointer to the copy. | |
855 | // This memberfunction enables automatic creation of new objects of the | |
856 | // correct type depending on the object type, a feature which may be very useful | |
857 | // for containers when adding objects in case the container owns the objects. | |
858 | // This feature allows to store either AliEvent objects or objects derived from | |
859 | // AliEvent via some generic AddEvent memberfunction, provided these derived | |
860 | // classes also have a proper Clone memberfunction. | |
861 | ||
862 | AliEvent* evt=new AliEvent(*this); | |
863 | if (name) | |
864 | { | |
865 | if (strlen(name)) evt->SetName(name); | |
866 | } | |
867 | return evt; | |
868 | } | |
869 | /////////////////////////////////////////////////////////////////////////// | |
d16062ac | 870 |