]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliEvent.cxx
Replacing array of objects by array of pointers
[u/mrichter/AliRoot.git] / RALICE / AliEvent.cxx
CommitLineData
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
4f368c8c 16// $Id: AliEvent.cxx,v 1.25 2004/10/20 10:49:44 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");
7b825f44 131// TObjArray* orderedtofs=evt.SortHits(hits);
132// Int_t nhits=0;
133// if (orderedtofs) nhits=orderedtofs->GetEntries();
7a086578 134// for (Int_t i=0; i<nhits; i++)
135// {
7b825f44 136// AliSignal* sx=(AliSignal*)orderedtofs->At(i);
b055c99d 137// if (sx) sx->Data();
138// }
139//
140// Order and investigate all the hits of all the calorimeter devices
141//
142// TObjArray* hits=evt.GetHits("AliCalorimeter");
7b825f44 143// TObjArray* orderedcals=evt.SortHits(hits);
144// Int_t nhits=0;
145// if (orderedcals) nhits=orderedcals->GetEntries();
b055c99d 146// for (Int_t i=0; i<nhits; i++)
147// {
7b825f44 148// AliSignal* sx=(AliSignal*)orderedcals->At(i);
7a086578 149// if (sx) sx->Data();
150// }
151//
7849a8ab 152// Build the event structure (vertices, jets, ...) for physics analysis
153// based on the basic objects from the event repository.
d16062ac 154//
155// AliJet j1,j2;
7849a8ab 156// for (Int_t i=0; i<evt.GetNtracks(); i++)
157// {
158// tx=evt.GetTrack(i);
d16062ac 159// ...
160// ... // code to fill the jet data
161// ...
7849a8ab 162// }
d16062ac 163//
7849a8ab 164// AliVertex vp;
35044448 165// tx=evt.GetTrack(1);
7849a8ab 166// vp.AddTrack(tx);
35044448 167// tx=evt.GetTrack(2);
7849a8ab 168// vp.AddTrack(tx);
35044448 169// tx=evt.GetTrack(3);
7849a8ab 170// vp.AddTrack(tx);
35044448 171// tx=evt.GetTrack(4);
7849a8ab 172// vp.AddTrack(tx);
d16062ac 173//
7849a8ab 174// Float_t rp[3]={2.4,0.1,-8.5};
175// vp.SetPosition(rp,"car");
d16062ac 176//
7849a8ab 177// AliVertex v1;
35044448 178// tx=evt.GetTrack(5);
7849a8ab 179// v1.AddTrack(tx);
35044448 180// tx=evt.GetTrack(6);
7849a8ab 181// v1.AddTrack(tx);
35044448 182// tx=evt.GetTrack(7);
7849a8ab 183// v1.AddTrack(tx);
d16062ac 184//
185// Float_t r1[3]={1.6,-3.2,5.7};
186// v1.SetPosition(r1,"car");
187//
d16062ac 188//
7849a8ab 189// AliVertex v2;
190// v2.SetJetCopy(1);
d16062ac 191// v2.AddJet(j1);
192// v2.AddJet(j2);
193//
194// Float_t r2[3]={6.2,4.8,1.3};
195// v2.SetPosition(r2,"car");
196//
7849a8ab 197// Specify the vertices v1 and v2 as secondary vertices of the primary
198//
199// vp.SetVertexCopy(1);
200// vp.AddVertex(v1);
201// vp.AddVertex(v2);
202//
203// Enter the physics structures into the event
204// evt.SetVertexCopy(1);
205// evt.AddVertex(vp,0);
206//
207// The jets j1 and j2 are already available via sec. vertex v2,
208// but can be made available also from the event itself if desired.
209// AliJet* jx;
210// jx=v2.GetJet(1);
211// evt.AddJet(jx,0);
212// jx=v2.GetJet(2);
213// evt.AddJet(jx,0);
214//
84bb7c66 215// evt.Data("sph");
d16062ac 216// v1.ListAll();
217// v2.List("cyl");
218//
219// Float_t etot=evt.GetEnergy();
220// Ali3Vector ptot=evt.Get3Momentum();
221// Float_t loc[3];
222// evt.GetPosition(loc,"sph");
223// AliPosition r=v1.GetPosition();
84bb7c66 224// r.Data();
d16062ac 225// Int_t nt=v2.GetNtracks();
226// AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
227//
d16062ac 228// evt.List();
229//
230// Int_t nv=evt.GetNvtx();
7849a8ab 231// AliVertex* vx=evt.GetVertex(1); // Access primary vertex
d16062ac 232// Float_t e=vx->GetEnergy();
233//
234// Float_t M=evt.GetInvmass();
235//
236// Reconstruct the event from scratch
237//
238// evt.Reset();
239// evt.SetNvmax(25); // Increase initial no. of sec. vertices
7849a8ab 240// ...
241// ... // code to create tracks etc...
242// ...
d16062ac 243//
244// Note : All quantities are in GeV, GeV/c or GeV/c**2
245//
246//--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht
4f368c8c 247//- Modified: NvE $Date: 2004/10/20 10:49:44 $ UU-SAP Utrecht
d16062ac 248///////////////////////////////////////////////////////////////////////////
249
250#include "AliEvent.h"
c72198f1 251#include "Riostream.h"
d16062ac 252
253ClassImp(AliEvent) // Class implementation to enable ROOT I/O
254
3ea81e9c 255AliEvent::AliEvent() : AliVertex(),AliTimestamp()
d16062ac 256{
257// Default constructor.
258// All variables initialised to default values.
d16062ac 259 fRun=0;
260 fEvent=0;
4575fcea 261 fAproj=0;
262 fZproj=0;
263 fPnucProj=0;
da17f667 264 fIdProj=0;
4575fcea 265 fAtarg=0;
266 fZtarg=0;
267 fPnucTarg=0;
da17f667 268 fIdTarg=0;
1c01b4f8 269 fDevices=0;
270 fDevCopy=0;
7a086578 271 fHits=0;
965bd237 272 fOrdered=0;
273 fDisplay=0;
d16062ac 274}
275///////////////////////////////////////////////////////////////////////////
3ea81e9c 276AliEvent::AliEvent(Int_t n) : AliVertex(n),AliTimestamp()
d16062ac 277{
278// Create an event to hold initially a maximum of n tracks
279// All variables initialised to default values
c72198f1 280 if (n<=0)
281 {
282 cout << " *** This AliVertex initialisation was invoked via the AliEvent ctor." << endl;
283 }
d16062ac 284 fRun=0;
285 fEvent=0;
4575fcea 286 fAproj=0;
287 fZproj=0;
288 fPnucProj=0;
da17f667 289 fIdProj=0;
4575fcea 290 fAtarg=0;
291 fZtarg=0;
292 fPnucTarg=0;
da17f667 293 fIdTarg=0;
1c01b4f8 294 fDevices=0;
295 fDevCopy=0;
7a086578 296 fHits=0;
965bd237 297 fOrdered=0;
298 fDisplay=0;
d16062ac 299}
300///////////////////////////////////////////////////////////////////////////
301AliEvent::~AliEvent()
302{
303// Default destructor
1c01b4f8 304 if (fDevices)
7849a8ab 305 {
1c01b4f8 306 delete fDevices;
307 fDevices=0;
7849a8ab 308 }
7a086578 309 if (fHits)
310 {
311 delete fHits;
312 fHits=0;
313 }
965bd237 314 if (fOrdered)
315 {
316 delete fOrdered;
317 fOrdered=0;
318 }
319 if (fDisplay)
320 {
321 delete fDisplay;
322 fDisplay=0;
323 }
d16062ac 324}
325///////////////////////////////////////////////////////////////////////////
3ea81e9c 326AliEvent::AliEvent(const AliEvent& evt) : AliVertex(evt),AliTimestamp(evt)
c72198f1 327{
328// Copy constructor.
c72198f1 329 fRun=evt.fRun;
330 fEvent=evt.fEvent;
331 fAproj=evt.fAproj;
332 fZproj=evt.fZproj;
333 fPnucProj=evt.fPnucProj;
334 fIdProj=evt.fIdProj;
335 fAtarg=evt.fAtarg;
336 fZtarg=evt.fZtarg;
337 fPnucTarg=evt.fPnucTarg;
338 fIdTarg=evt.fIdTarg;
1c01b4f8 339 fDevCopy=evt.fDevCopy;
c72198f1 340
965bd237 341 fHits=0;
342 fOrdered=0;
343 fDisplay=0;
344
1c01b4f8 345 fDevices=0;
346 Int_t ndevs=evt.GetNdevices();
347 if (ndevs)
c72198f1 348 {
1c01b4f8 349 fDevices=new TObjArray(ndevs);
350 if (fDevCopy) fDevices->SetOwner();
351 for (Int_t i=1; i<=ndevs; i++)
c72198f1 352 {
1c01b4f8 353 TObject* dev=evt.GetDevice(i);
354 if (dev)
c72198f1 355 {
1c01b4f8 356 if (fDevCopy)
c72198f1 357 {
1c01b4f8 358 fDevices->Add(dev->Clone());
c72198f1 359 }
360 else
361 {
1c01b4f8 362 fDevices->Add(dev);
c72198f1 363 }
364 }
365 }
366 }
367}
368///////////////////////////////////////////////////////////////////////////
d16062ac 369void AliEvent::Reset()
370{
371// Reset all variables to default values
372// The max. number of tracks is set to the initial value again
373// The max. number of vertices is set to the default value again
7b825f44 374// Note : The DevCopy mode is maintained as it was set by the user before.
c72198f1 375
376 AliVertex::Reset();
377
3ea81e9c 378 Set();
d16062ac 379 fRun=0;
380 fEvent=0;
4575fcea 381 fAproj=0;
382 fZproj=0;
383 fPnucProj=0;
da17f667 384 fIdProj=0;
4575fcea 385 fAtarg=0;
386 fZtarg=0;
387 fPnucTarg=0;
da17f667 388 fIdTarg=0;
d16062ac 389
1c01b4f8 390 if (fDevices)
7849a8ab 391 {
1c01b4f8 392 delete fDevices;
393 fDevices=0;
7849a8ab 394 }
7a086578 395 if (fHits)
396 {
397 delete fHits;
398 fHits=0;
399 }
965bd237 400 if (fOrdered)
401 {
402 delete fOrdered;
403 fOrdered=0;
404 }
405 if (fDisplay)
406 {
407 delete fDisplay;
408 fDisplay=0;
409 }
d16062ac 410}
411///////////////////////////////////////////////////////////////////////////
8e8e6c7f 412void AliEvent::SetOwner(Bool_t own)
413{
414// Set ownership of all added objects.
415// The default parameter is own=kTRUE.
416//
417// Invokation of this memberfunction also sets all the copy modes
418// (e.g. TrackCopy & co.) according to the value of own.
419//
420// This function (with own=kTRUE) is particularly useful when reading data
421// from a tree/file, since Reset() will then actually remove all the
422// added objects from memory irrespective of the copy mode settings
423// during the tree/file creation process. In this way it provides a nice way
424// of preventing possible memory leaks in the reading/analysis process.
425//
426// In addition this memberfunction can also be used as a shortcut to set all
427// copy modes in one go during a tree/file creation process.
428// However, in this case the user has to take care to only set/change the
429// ownership (and copy mode) for empty objects (e.g. newly created objects
430// or after invokation of the Reset() memberfunction) otherwise it will
431// very likely result in inconsistent destructor behaviour.
432
433 Int_t mode=1;
434 if (!own) mode=0;
1c01b4f8 435 if (fDevices) fDevices->SetOwner(own);
436 fDevCopy=mode;
8e8e6c7f 437
438 AliVertex::SetOwner(own);
439}
440///////////////////////////////////////////////////////////////////////////
387a745b 441void AliEvent::SetDayTime(TTimeStamp& stamp)
d16062ac 442{
387a745b 443// Set the date and time stamp for this event.
444// An exact copy of the entered date/time stamp will be saved with an
47dddbe4 445// accuracy of 1 nanosecond.
3ea81e9c 446//
447// Note : Since the introduction of the more versatile class AliTimestamp
448// and the fact that AliEvent has now been derived from it,
449// this memberfunction has become obsolete.
450// It is recommended to use the corresponding AliTimestamp
451// functionality directly for AliEvent instances.
452// This memberfunction is only kept for backward compatibility.
453
454 Set(stamp.GetDate(),stamp.GetTime(),0,kTRUE,0);
d16062ac 455}
456///////////////////////////////////////////////////////////////////////////
387a745b 457void AliEvent::SetDayTime(TDatime& stamp)
458{
459// Set the date and time stamp for this event.
460// The entered date/time will be interpreted as being the local date/time
461// and the accuracy is 1 second.
3ea81e9c 462//
387a745b 463// This function with the TDatime argument is mainly kept for backward
3ea81e9c 464// compatibility reasons.
465// It is recommended to use the corresponding AliTimestamp functionality
466// directly for AliEvent instances.
387a745b 467
3ea81e9c 468 Set(stamp.GetDate(),stamp.GetTime(),0,kFALSE,0);
387a745b 469}
470///////////////////////////////////////////////////////////////////////////
d16062ac 471void AliEvent::SetRunNumber(Int_t run)
472{
473// Set the run number for this event
474 fRun=run;
475}
476///////////////////////////////////////////////////////////////////////////
477void AliEvent::SetEventNumber(Int_t evt)
478{
479// Set the event number for this event
480 fEvent=evt;
481}
482///////////////////////////////////////////////////////////////////////////
261c0caf 483TTimeStamp AliEvent::GetDayTime() const
d16062ac 484{
485// Provide the date and time stamp for this event
3ea81e9c 486//
487// Note : Since the introduction of the more versatile class AliTimestamp
488// and the fact that AliEvent has now been derived from it,
489// this memberfunction has become obsolete.
490// It is recommended to use the corresponding AliTimestamp
491// functionality directly for AliEvent instances.
492// This memberfunction is only kept for backward compatibility.
493
494 return (TTimeStamp)(*this);
d16062ac 495}
496///////////////////////////////////////////////////////////////////////////
261c0caf 497Int_t AliEvent::GetRunNumber() const
d16062ac 498{
499// Provide the run number for this event
500 return fRun;
501}
502///////////////////////////////////////////////////////////////////////////
261c0caf 503Int_t AliEvent::GetEventNumber() const
d16062ac 504{
505// Provide the event number for this event
506 return fEvent;
507}
508///////////////////////////////////////////////////////////////////////////
da17f667 509void AliEvent::SetProjectile(Int_t a,Int_t z,Double_t pnuc,Int_t id)
4575fcea 510{
da17f667 511// Set the projectile A, Z, momentum per nucleon and user defined particle ID.
512// By default the particle ID is set to zero.
4575fcea 513 fAproj=a;
514 fZproj=z;
515 fPnucProj=pnuc;
da17f667 516 fIdProj=id;
4575fcea 517}
518///////////////////////////////////////////////////////////////////////////
261c0caf 519Int_t AliEvent::GetProjectileA() const
4575fcea 520{
521// Provide the projectile A value.
522 return fAproj;
523}
524///////////////////////////////////////////////////////////////////////////
261c0caf 525Int_t AliEvent::GetProjectileZ() const
4575fcea 526{
527// Provide the projectile Z value.
528 return fZproj;
529}
530///////////////////////////////////////////////////////////////////////////
261c0caf 531Double_t AliEvent::GetProjectilePnuc() const
4575fcea 532{
533// Provide the projectile momentum value per nucleon.
534 return fPnucProj;
535}
536///////////////////////////////////////////////////////////////////////////
261c0caf 537Int_t AliEvent::GetProjectileId() const
4575fcea 538{
da17f667 539// Provide the user defined particle ID of the projectile.
540 return fIdProj;
541}
542///////////////////////////////////////////////////////////////////////////
543void AliEvent::SetTarget(Int_t a,Int_t z,Double_t pnuc,Int_t id)
544{
545// Set the target A, Z, momentum per nucleon and user defined particle ID.
546// By default the particle ID is set to zero.
4575fcea 547 fAtarg=a;
548 fZtarg=z;
549 fPnucTarg=pnuc;
da17f667 550 fIdTarg=id;
4575fcea 551}
552///////////////////////////////////////////////////////////////////////////
261c0caf 553Int_t AliEvent::GetTargetA() const
4575fcea 554{
555// Provide the target A value.
556 return fAtarg;
557}
558///////////////////////////////////////////////////////////////////////////
261c0caf 559Int_t AliEvent::GetTargetZ() const
4575fcea 560{
561// Provide the target Z value.
562 return fZtarg;
563}
564///////////////////////////////////////////////////////////////////////////
261c0caf 565Double_t AliEvent::GetTargetPnuc() const
4575fcea 566{
567// Provide the target momentum value per nucleon.
568 return fPnucTarg;
569}
570///////////////////////////////////////////////////////////////////////////
261c0caf 571Int_t AliEvent::GetTargetId() const
da17f667 572{
573// Provide the user defined particle ID of the target.
574 return fIdTarg;
575}
576///////////////////////////////////////////////////////////////////////////
3ea81e9c 577void AliEvent::HeaderData()
d16062ac 578{
579// Provide event header information
47dddbe4 580 const char* name=GetName();
581 const char* title=GetTitle();
47dddbe4 582 cout << " *" << ClassName() << "::Data*";
583 if (strlen(name)) cout << " Name : " << GetName();
584 if (strlen(title)) cout << " Title : " << GetTitle();
585 cout << endl;
3ea81e9c 586 Date(1);
ea0b5b7f 587 cout << " Run : " << fRun << " Event : " << fEvent << endl;
588 ShowDevices(0);
589 ShowTracks(0);
d16062ac 590}
591///////////////////////////////////////////////////////////////////////////
84bb7c66 592void AliEvent::Data(TString f)
d16062ac 593{
594// Provide event information within the coordinate frame f
84bb7c66 595 HeaderData();
596 AliVertex::Data(f);
d16062ac 597}
598///////////////////////////////////////////////////////////////////////////
261c0caf 599Int_t AliEvent::GetNdevices() const
7849a8ab 600{
1c01b4f8 601// Provide the number of stored devices
602 Int_t ndevs=0;
603 if (fDevices) ndevs=fDevices->GetEntries();
604 return ndevs;
7849a8ab 605}
606///////////////////////////////////////////////////////////////////////////
1c01b4f8 607void AliEvent::AddDevice(TObject& d)
7849a8ab 608{
1c01b4f8 609// Add a device to the event.
610//
611// Note :
612// In case a private copy is made, this is performed via the Clone() memberfunction.
613// All devices (i.e. classes derived from TObject) have the default TObject::Clone()
614// memberfunction.
615// However, devices generally contain an internal (signal) data structure
616// which may include pointers to other objects. Therefore it is recommended to provide
617// for all devices a specific copy constructor and override the default Clone()
618// memberfunction using this copy constructor.
619// An example for this may be seen from AliCalorimeter.
620
621 if (!fDevices)
6516b62d 622 {
1c01b4f8 623 fDevices=new TObjArray();
624 if (fDevCopy) fDevices->SetOwner();
6516b62d 625 }
7849a8ab 626
1c01b4f8 627 // Add the device to this event
628 if (fDevCopy)
7849a8ab 629 {
1c01b4f8 630 fDevices->Add(d.Clone());
7849a8ab 631 }
632 else
633 {
1c01b4f8 634 fDevices->Add(&d);
7849a8ab 635 }
636}
637///////////////////////////////////////////////////////////////////////////
1c01b4f8 638void AliEvent::SetDevCopy(Int_t j)
7849a8ab 639{
1c01b4f8 640// (De)activate the creation of private copies of the added devices.
641// j=0 ==> No private copies are made; pointers of original devices are stored.
642// j=1 ==> Private copies of the devices are made and these pointers are stored.
643//
644//
645// Notes :
646// In case a private copy is made, this is performed via the Clone() memberfunction.
647// All devices (i.e. classes derived from TObject) have the default TObject::Clone()
648// memberfunction.
649// However, devices generally contain an internal (signal) data structure
650// which may include pointers to other objects. Therefore it is recommended to provide
651// for all devices a specific copy constructor and override the default Clone()
652// memberfunction using this copy constructor.
653// An example for this may be seen from AliCalorimeter.
654//
655// Once the storage contains pointer(s) to device(s) one cannot
656// change the DevCopy mode anymore.
657// To change the DevCopy mode for an existing AliEvent containing
658// devices one first has to invoke Reset().
659
660 if (!fDevices)
7849a8ab 661 {
662 if (j==0 || j==1)
663 {
1c01b4f8 664 fDevCopy=j;
7849a8ab 665 }
666 else
667 {
1c01b4f8 668 cout << " *" << ClassName() << "::SetDevCopy* Invalid argument : " << j << endl;
7849a8ab 669 }
670 }
671 else
672 {
1c01b4f8 673 cout << " *" << ClassName() << "::SetDevCopy* Storage already contained devices."
674 << " ==> DevCopy mode not changed." << endl;
7849a8ab 675 }
676}
677///////////////////////////////////////////////////////////////////////////
261c0caf 678Int_t AliEvent::GetDevCopy() const
7849a8ab 679{
1c01b4f8 680// Provide value of the DevCopy mode.
681// 0 ==> No private copies are made; pointers of original devices are stored.
682// 1 ==> Private copies of the devices are made and these pointers are stored.
683//
684// Note :
685// In case a private copy is made, this is performed via the Clone() memberfunction.
686// All devices (i.e. classes derived from TObject) have the default TObject::Clone()
687// memberfunction.
688// However, devices generally contain an internal (signal) data structure
689// which may include pointers to other objects. Therefore it is recommended to provide
690// for all devices a specific copy constructor and override the default Clone()
691// memberfunction using this copy constructor.
692// An example for this may be seen from AliCalorimeter.
693
694 return fDevCopy;
7849a8ab 695}
696///////////////////////////////////////////////////////////////////////////
261c0caf 697TObject* AliEvent::GetDevice(Int_t i) const
7849a8ab 698{
1c01b4f8 699// Return the i-th device of this event.
700// The first device corresponds to i=1.
701
702 if (!fDevices)
7849a8ab 703 {
7849a8ab 704 return 0;
705 }
706 else
707 {
1c01b4f8 708 Int_t ndevs=GetNdevices();
709 if (i<=0 || i>ndevs)
7849a8ab 710 {
1c01b4f8 711 cout << " *" << ClassName() << "::GetDevice* Invalid argument i : " << i
712 << " ndevs = " << ndevs << endl;
7849a8ab 713 return 0;
714 }
715 else
716 {
1c01b4f8 717 return fDevices->At(i-1);
7849a8ab 718 }
719 }
720}
721///////////////////////////////////////////////////////////////////////////
261c0caf 722TObject* AliEvent::GetDevice(TString name) const
7849a8ab 723{
1c01b4f8 724// Return the device with name tag "name"
725 if (!fDevices)
7849a8ab 726 {
7849a8ab 727 return 0;
728 }
729 else
730 {
7849a8ab 731 TString s;
1c01b4f8 732 Int_t ndevs=GetNdevices();
733 for (Int_t i=0; i<ndevs; i++)
7849a8ab 734 {
1c01b4f8 735 TObject* dev=fDevices->At(i);
736 if (dev)
35044448 737 {
1c01b4f8 738 s=dev->GetName();
739 if (s == name) return dev;
35044448 740 }
7849a8ab 741 }
742
743 return 0; // No matching name found
744 }
745}
746///////////////////////////////////////////////////////////////////////////
4f368c8c 747TObject* AliEvent::GetIdDevice(Int_t id) const
748{
749// Return the device with unique identifier "id".
750 if (!fDevices || id<0) return 0;
751
752 Int_t idx=0;
753 for (Int_t i=0; i<GetNdevices(); i++)
754 {
755 TObject* dev=fDevices->At(i);
756 if (dev)
757 {
758 idx=dev->GetUniqueID();
759 if (idx==id) return dev;
760 }
761 }
762 return 0; // No matching id found
763}
764///////////////////////////////////////////////////////////////////////////
ea0b5b7f 765void AliEvent::ShowDevices(Int_t mode) const
1ce8a857 766{
1c01b4f8 767// Provide an overview of the available devices.
ea0b5b7f 768// The argument mode determines the amount of information as follows :
769// mode = 0 ==> Only printout of the number of devices
770// 1 ==> Provide a listing with 1 line of info for each device
771//
772// The default is mode=1.
773//
1c01b4f8 774 Int_t ndevs=GetNdevices();
775 if (ndevs)
1ce8a857 776 {
ea0b5b7f 777 if (!mode)
1ce8a857 778 {
ea0b5b7f 779 cout << " There are " << ndevs << " devices available." << endl;
780 }
781 else
782 {
783 cout << " The following " << ndevs << " devices are available :" << endl;
784 for (Int_t i=1; i<=ndevs; i++)
1c01b4f8 785 {
ea0b5b7f 786 TObject* dev=GetDevice(i);
787 if (dev)
788 {
789 const char* name=dev->GetName();
790 cout << " Device number : " << i;
791 cout << " Class : " << dev->ClassName() << " Id : " << dev->GetUniqueID();
792 if (strlen(name)) cout << " Name : " << name;
793 if (dev->InheritsFrom("AliDevice")) cout << " Nhits : " << ((AliDevice*)dev)->GetNhits();
794 if (dev->InheritsFrom("AliSignal")) cout << " Nwaveforms : " << ((AliSignal*)dev)->GetNwaveforms();
795 cout << endl;
796 }
1c01b4f8 797 }
1ce8a857 798 }
799 }
800 else
801 {
1c01b4f8 802 cout << " No devices present for this event." << endl;
1ce8a857 803 }
804}
805///////////////////////////////////////////////////////////////////////////
7a086578 806Int_t AliEvent::GetNhits(const char* classname)
807{
808// Provide the number of hits registered to the specified device class.
809// The specified device class has to be derived from AliDevice.
810// It is possible to indicate with the argument "classname" a specific
811// device instead of a whole class of devices. However, in such a case
812// it is more efficient to use the GetDevice() memberfunction directly.
813 LoadHits(classname);
814 Int_t nhits=0;
815 if (fHits) nhits=fHits->GetEntries();
816 return nhits;
817}
818///////////////////////////////////////////////////////////////////////////
819TObjArray* AliEvent::GetHits(const char* classname)
820{
821// Provide the references to all the hits registered to the specified
822// device class.
823// The specified device class has to be derived from AliDevice.
824// It is possible to indicate with the argument "classname" a specific
825// device instead of a whole class of devices. However, in such a case
826// it is more efficient to use the GetDevice() memberfunction directly.
827 LoadHits(classname);
828 return fHits;
829}
830///////////////////////////////////////////////////////////////////////////
4f368c8c 831AliSignal* AliEvent::GetIdHit(Int_t id,const char* classname)
832{
833// Return the hit with unique identifier "id" for the specified device class.
834 if (id<0) return 0;
835
836 Int_t nhits=GetNhits(classname);
837 if (!nhits) return 0;
838
839 AliSignal* sx=0;
840 Int_t sid=0;
841 for (Int_t i=0; i<nhits; i++)
842 {
843 sx=(AliSignal*)fHits->At(i);
844 if (sx)
845 {
846 sid=sx->GetUniqueID();
847 if (id==sid) return sx;
848 }
849 }
850 return 0; // No matching id found
851}
852///////////////////////////////////////////////////////////////////////////
7a086578 853void AliEvent::LoadHits(const char* classname)
854{
855// Load the references to the various hits registered to the specified
856// device class.
857// The specified device class has to be derived from AliDevice.
858 if (fHits) fHits->Clear();
859
860 Int_t ndev=GetNdevices();
861 for (Int_t idev=1; idev<=ndev; idev++)
862 {
863 TObject* obj=GetDevice(idev);
864 if (!obj) continue;
865
866 if (obj->InheritsFrom(classname) && obj->InheritsFrom("AliDevice"))
867 {
868 AliDevice* dev=(AliDevice*)GetDevice(idev);
869 Int_t nhits=dev->GetNhits();
870 if (nhits)
871 {
872 if (!fHits) fHits=new TObjArray();
873 for (Int_t ih=1; ih<=nhits; ih++)
874 {
875 AliSignal* sx=dev->GetHit(ih);
876 if (sx) fHits->Add(sx);
877 }
878 }
879 }
880 }
881}
882///////////////////////////////////////////////////////////////////////////
965bd237 883TObjArray* AliEvent::SortHits(const char* classname,Int_t idx,Int_t mode)
7a086578 884{
965bd237 885// Order the references to the various hits registered to the specified
886// device class. The ordered array is returned as a TObjArray.
7a086578 887// A "hit" represents an abstract object which is derived from AliSignal.
888// The user can specify the index of the signal slot to perform the sorting on.
889// By default the slotindex will be 1.
890// Via the "mode" argument the user can specify ordering in decreasing
891// order (mode=-1) or ordering in increasing order (mode=1).
892// The default is mode=-1.
893// Signals which were declared as "Dead" will be rejected.
894// The gain etc... corrected signals will be used in the ordering process.
965bd237 895//
896// For more extended functionality see class AliDevice.
897
898 if (idx<=0 || abs(mode)!=1) return 0;
899
900 LoadHits(classname);
901
902 AliDevice dev;
903 TObjArray* ordered=dev.SortHits(idx,mode,fHits);
7b825f44 904
905 if (fHits)
7a086578 906 {
7b825f44 907 delete fHits;
908 fHits=0;
909 }
7b825f44 910 if (ordered) fHits=new TObjArray(*ordered);
911 return fHits;
7a086578 912}
913///////////////////////////////////////////////////////////////////////////
965bd237 914TObjArray* AliEvent::SortHits(const char* classname,TString name,Int_t mode)
7a086578 915{
965bd237 916// Order the references to the various hits registered to the specified
917// device class. The ordered array is returned as a TObjArray.
7a086578 918// A "hit" represents an abstract object which is derived from AliSignal.
919// The user can specify the name of the signal slot to perform the sorting on.
920// In case no matching slotname is found, the signal will be skipped.
921// Via the "mode" argument the user can specify ordering in decreasing
922// order (mode=-1) or ordering in increasing order (mode=1).
923// The default is mode=-1.
924// Signals which were declared as "Dead" will be rejected.
925// The gain etc... corrected signals will be used in the ordering process.
965bd237 926//
927// For more extended functionality see class AliDevice.
928
929 if (abs(mode)!=1) return 0;
930
931 LoadHits(classname);
932
933 AliDevice dev;
934 TObjArray* ordered=dev.SortHits(name,mode,fHits);
7b825f44 935
936 if (fHits)
7a086578 937 {
7b825f44 938 delete fHits;
939 fHits=0;
940 }
965bd237 941 if (ordered) fHits=new TObjArray(*ordered);
942 return fHits;
943}
944///////////////////////////////////////////////////////////////////////////
945void AliEvent::GetExtremes(const char* classname,Float_t& vmin,Float_t& vmax,Int_t idx)
946{
947// Provide the min. and max. signal values of the various hits registered
948// to the specified device class.
949// The input argument "idx" denotes the index of the signal slots to be investigated.
950// The default is idx=1;
951// Signals which were declared as "Dead" will be rejected.
952// The gain etc... corrected signals will be used in the process.
953//
954// For more extended functionality see class AliDevice.
955
956 if (idx<=0) return;
957
958 LoadHits(classname);
959
960 AliDevice dev;
961 dev.GetExtremes(vmin,vmax,idx,fHits);
962}
963///////////////////////////////////////////////////////////////////////////
964void AliEvent::GetExtremes(const char* classname,Float_t& vmin,Float_t& vmax,TString name)
965{
966// Provide the min. and max. signal values of the various hits registered
967// to the specified device class.
968// The input argument "name" denotes the name of the signal slots to be investigated.
969// Signals which were declared as "Dead" will be rejected.
970// The gain etc... corrected signals will be used in the process.
971//
972// For more extended functionality see class AliDevice.
973
974 LoadHits(classname);
975
976 AliDevice dev;
977 dev.GetExtremes(vmin,vmax,name,fHits);
978}
979///////////////////////////////////////////////////////////////////////////
980void AliEvent::DisplayHits(const char* classname,Int_t idx,Float_t scale,Int_t dp,Int_t mstyle,Int_t mcol)
981{
982// 3D color display of the various hits registered to the specified device class.
983// The user can specify the index (default=1) of the signal slot to perform the display for.
984// The marker size will indicate the absolute value of the signal (specified by the slotindex)
985// as a percentage of the input argument "scale".
986// In case scale<0 the maximum absolute signal value encountered in the hit array will be used
987// to define the 100% scale. The default is scale=-1.
988// In case dp=1 the owning device position will be used, otherwise the hit position will
989// be used in the display. The default is dp=0.
990// Via the "mstyle" and "mcol" arguments the user can specify the marker style
991// and color (see TPolyMarker3D) respectively.
992// The defaults are mstyle="large scalable dot" and mcol=blue.
993// Signals which were declared as "Dead" will not be displayed.
994// The gain etc... corrected signals will be used to determine the marker size.
995//
996// For more extended functionality see class AliDevice.
997//
998// Note :
999// ------
1000// Before any display activity, a TCanvas and a TView have to be initiated
1001// first by the user like for instance
1002//
1003// TCanvas* c1=new TCanvas("c1","c1");
1004// TView* view=new TView(1);
1005// view->SetRange(-1000,-1000,-1000,1000,1000,1000);
1006// view->ShowAxis();
1007
1008 if (idx<=0) return;
1009
1010 LoadHits(classname);
1011
1012 AliDevice* dev=new AliDevice();
1013 dev->DisplayHits(idx,scale,fHits,dp,mstyle,mcol);
1014
1015 if (fDisplay)
1016 {
1017 delete fDisplay;
1018 fDisplay=0;
1019 }
1020 fDisplay=dev;
1021}
1022///////////////////////////////////////////////////////////////////////////
1023void AliEvent::DisplayHits(const char* classname,TString name,Float_t scale,Int_t dp,Int_t mstyle,Int_t mcol)
1024{
1025// 3D color display of the various hits registered to the specified device class.
1026// The user can specify the name of the signal slot to perform the display for.
1027// The marker size will indicate the absolute value of the signal (specified by the slotname)
1028// as a percentage of the input argument "scale".
1029// In case scale<0 the maximum absolute signal value encountered in the hit array will be used
1030// to define the 100% scale. The default is scale=-1.
1031// In case dp=1 the owning device position will be used, otherwise the hit position will
1032// be used in the display. The default is dp=0.
1033// The marker size will indicate the percentage of the maximum encountered value
1034// of the absolute value of the name-specified input signal slots.
1035// Via the "mstyle" and "mcol" arguments the user can specify the marker style
1036// and color (see TPolyMarker3D) respectively.
1037// The defaults are mstyle="large scalable dot" and mcol=blue.
1038// Signals which were declared as "Dead" will not be displayed.
1039// The gain etc... corrected signals will be used to determine the marker size.
1040//
1041// For more extended functionality see class AliDevice.
1042//
1043// Note :
1044// ------
1045// Before any display activity, a TCanvas and a TView have to be initiated
1046// first by the user like for instance
1047//
1048// TCanvas* c1=new TCanvas("c1","c1");
1049// TView* view=new TView(1);
1050// view->SetRange(-1000,-1000,-1000,1000,1000,1000);
1051// view->ShowAxis();
1052
1053 LoadHits(classname);
1054
1055 AliDevice* dev=new AliDevice();
1056 dev->DisplayHits(name,scale,fHits,dp,mstyle,mcol);
1057
1058 if (fDisplay)
1059 {
1060 delete fDisplay;
1061 fDisplay=0;
1062 }
1063 fDisplay=dev;
1064}
1065///////////////////////////////////////////////////////////////////////////
1066TObjArray* AliEvent::SortDevices(const char* classname,TString name,Int_t mode)
1067{
1068// Order the references to the various devices based on hit signals registered
1069// to the specified device class. The ordered array is returned as a TObjArray.
1070// A "hit" represents an abstract object which is derived from AliSignal.
1071// The user can specify the name of the signal slot to perform the sorting on.
1072// In case no matching slotname is found, the signal will be skipped.
1073// Via the "mode" argument the user can specify ordering in decreasing
1074// order (mode=-1) or ordering in increasing order (mode=1).
1075// The default is mode=-1.
1076// Signals which were declared as "Dead" will be rejected.
1077// The gain etc... corrected signals will be used in the ordering process.
1078//
1079
1080 TObjArray* ordered=SortHits(classname,name,mode);
1081
1082 if (!ordered) return 0;
1083
1084 TObjArray* devs=SortDevices(ordered,"*",0);
1085 return devs;
1086}
1087///////////////////////////////////////////////////////////////////////////
1088TObjArray* AliEvent::SortDevices(const char* classname,Int_t idx,Int_t mode)
1089{
1090// Order the references to the various devices based on hit signals registered
1091// to the specified device class. The ordered array is returned as a TObjArray.
1092// A "hit" represents an abstract object which is derived from AliSignal.
1093// The user can specify the index of the signal slot to perform the sorting on.
1094// By default the slotindex will be 1.
1095// Via the "mode" argument the user can specify ordering in decreasing
1096// order (mode=-1) or ordering in increasing order (mode=1).
1097// The default is mode=-1.
1098// Signals which were declared as "Dead" will be rejected.
1099// The gain etc... corrected signals will be used in the ordering process.
1100//
1101
1102 TObjArray* ordered=SortHits(classname,idx,mode);
7b825f44 1103
965bd237 1104 if (!ordered) return 0;
7b825f44 1105
965bd237 1106 TObjArray* devs=SortDevices(ordered,0,0);
1107 return devs;
1108}
1109///////////////////////////////////////////////////////////////////////////
1110TObjArray* AliEvent::SortDevices(TObjArray* hits,TString name,Int_t mode)
1111{
1112// Order the references to the various devices based on hit signals contained
1113// in the input array. The ordered array is returned as a TObjArray.
1114// A "hit" represents an abstract object which is derived from AliSignal.
1115// The user can specify the name of the signal slot to perform the sorting on.
1116// In case no matching slotname is found, the signal will be skipped.
1117// Via the "mode" argument the user can specify ordering in decreasing
1118// order (mode=-1), ordering in increasing order (mode=1) or no ordering (mode=0).
1119// The latter option provides a means to quickly obtain an ordered devices list
1120// when the hits in the array were already ordered by the user. In this case
1121// the input argument "name" is irrelevant.
1122// The default is mode=-1.
1123// Signals which were declared as "Dead" will be rejected.
1124// The gain etc... corrected signals will be used in the ordering process.
1125//
1126
1127 if (!hits) return 0;
1128
1129 TObjArray* ordered=hits;
7b825f44 1130 AliDevice dev;
965bd237 1131 if (mode) ordered=dev.SortHits(name,mode,hits);
1132
1133 if (!ordered) return 0;
1134
1135 if (fOrdered)
1136 {
1137 fOrdered->Clear();
1138 }
1139 else
1140 {
1141 fOrdered=new TObjArray();
1142 }
1143
1144 Int_t nhits=ordered->GetEntries();
1145 Int_t exist=0;
1146 for (Int_t ih=0; ih<nhits; ih++)
1147 {
1148 AliSignal* sx=(AliSignal*)ordered->At(ih);
1149 if (!sx) continue;
1150 AliDevice* dx=sx->GetDevice();
1151 exist=0;
1152 for (Int_t id=0; id<fOrdered->GetEntries(); id++)
1153 {
1154 AliDevice* odx=(AliDevice*)fOrdered->At(id);
1155 if (dx==odx)
1156 {
1157 exist=1;
1158 break;
1159 }
1160 }
1161 if (!exist) fOrdered->Add(dx);
1162 }
1163 return fOrdered;
1164}
1165///////////////////////////////////////////////////////////////////////////
1166TObjArray* AliEvent::SortDevices(TObjArray* hits,Int_t idx,Int_t mode)
1167{
1168// Order the references to the various devices based on hit signals contained
1169// in the input array. The ordered array is returned as a TObjArray.
1170// A "hit" represents an abstract object which is derived from AliSignal.
1171// The user can specify the index of the signal slot to perform the sorting on.
1172// By default the slotindex will be 1.
1173// Via the "mode" argument the user can specify ordering in decreasing
1174// order (mode=-1), ordering in increasing order (mode=1) or no ordering (mode=0).
1175// The latter option provides a means to quickly obtain an ordered devices list
1176// when the hits in the array were already ordered by the user. In this case
1177// the input argument "idx" is irrelevant.
1178// The default is mode=-1.
1179// Signals which were declared as "Dead" will be rejected.
1180// The gain etc... corrected signals will be used in the ordering process.
1181//
1182
1183 if (!hits) return 0;
1184
1185 TObjArray* ordered=hits;
1186 AliDevice dev;
1187 if (mode) ordered=dev.SortHits(idx,mode,hits);
1188
1189 if (!ordered) return 0;
1190
1191 if (fOrdered)
1192 {
1193 fOrdered->Clear();
1194 }
1195 else
1196 {
1197 fOrdered=new TObjArray();
1198 }
1199
1200 Int_t nhits=ordered->GetEntries();
1201 Int_t exist=0;
1202 for (Int_t ih=0; ih<nhits; ih++)
1203 {
1204 AliSignal* sx=(AliSignal*)ordered->At(ih);
1205 if (!sx) continue;
1206 AliDevice* dx=sx->GetDevice();
1207 exist=0;
1208 for (Int_t id=0; id<fOrdered->GetEntries(); id++)
1209 {
1210 AliDevice* odx=(AliDevice*)fOrdered->At(id);
1211 if (dx==odx)
1212 {
1213 exist=1;
1214 break;
1215 }
1216 }
1217 if (!exist) fOrdered->Add(dx);
1218 }
1219 return fOrdered;
7a086578 1220}
1221///////////////////////////////////////////////////////////////////////////
261c0caf 1222TObject* AliEvent::Clone(const char* name) const
5f25234b 1223{
1224// Make a deep copy of the current object and provide the pointer to the copy.
1225// This memberfunction enables automatic creation of new objects of the
1226// correct type depending on the object type, a feature which may be very useful
1227// for containers when adding objects in case the container owns the objects.
1228// This feature allows to store either AliEvent objects or objects derived from
1229// AliEvent via some generic AddEvent memberfunction, provided these derived
1230// classes also have a proper Clone memberfunction.
1231
1232 AliEvent* evt=new AliEvent(*this);
1233 if (name)
1234 {
1235 if (strlen(name)) evt->SetName(name);
1236 }
1237 return evt;
1238}
1239///////////////////////////////////////////////////////////////////////////
d16062ac 1240