1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 // $Id: AliEvent.cxx,v 1.23 2004/07/01 14:28:50 nick Exp $
18 ///////////////////////////////////////////////////////////////////////////
20 // Creation and investigation of an Alice physics event.
21 // An AliEvent can be constructed by adding AliTracks, Alivertices, AliJets
22 // and/or devices like AliCalorimeters or AliDevice (derived) objects.
24 // All objects which are derived from TObject can be regarded as a device.
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.
32 // The basic functionality of AliEvent is identical to the one of AliVertex.
33 // So, an AliEvent may be used as the primary vertex with some additional
34 // functionality compared to AliVertex.
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.
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
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
47 // In this way the AliEvent just represents a 'logical structure' for the
51 // Modifications made to the original devices also affect the device
52 // objects which are stored in the AliEvent.
55 // Of every 'added' device a private copy will be made of which the pointer
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.
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.
65 // The copy is made using the Clone() memberfunction.
66 // All devices (i.e. classes derived from TObject) have the default TObject::Clone()
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.
72 // Examples for this may be seen from AliCalorimeter, AliSignal and AliDevice.
74 // See also the documentation provided for the memberfunction SetOwner().
76 // Coding example to make an event consisting of a primary vertex,
77 // 2 secondary vertices and a calorimeter.
78 // --------------------------------------------------------------
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)
85 // Specify the event object as the repository of all objects
86 // for the event building and physics analysis.
89 // evt.SetTrackCopy(1);
91 // Fill the event structure with the basic objects
93 // AliCalorimeter emcal1;
94 // AliCalorimeter emcal2;
96 // ... // code to fill the emcal1 and emcal2 calorimeter data
99 // evt.AddDevice(emcal1);
100 // evt.AddDevice(emcal2);
102 // // Assume AliTOF has been derived from AliDevice
106 // ... // code to fill the tof1 and tof2 data
109 // evt.AddDevice(tof1);
110 // evt.AddDevice(tof2);
112 // AliTrack* tx=new AliTrack();
113 // for (Int_t i=0; i<10; i++)
116 // ... // code to fill the track data
128 // Order and investigate all the hits of all the TOF devices
130 // TObjArray* hits=evt.GetHits("AliTOF");
131 // TObjArray* orderedtofs=evt.SortHits(hits);
133 // if (orderedtofs) nhits=orderedtofs->GetEntries();
134 // for (Int_t i=0; i<nhits; i++)
136 // AliSignal* sx=(AliSignal*)orderedtofs->At(i);
137 // if (sx) sx->Data();
140 // Order and investigate all the hits of all the calorimeter devices
142 // TObjArray* hits=evt.GetHits("AliCalorimeter");
143 // TObjArray* orderedcals=evt.SortHits(hits);
145 // if (orderedcals) nhits=orderedcals->GetEntries();
146 // for (Int_t i=0; i<nhits; i++)
148 // AliSignal* sx=(AliSignal*)orderedcals->At(i);
149 // if (sx) sx->Data();
152 // Build the event structure (vertices, jets, ...) for physics analysis
153 // based on the basic objects from the event repository.
156 // for (Int_t i=0; i<evt.GetNtracks(); i++)
158 // tx=evt.GetTrack(i);
160 // ... // code to fill the jet data
165 // tx=evt.GetTrack(1);
167 // tx=evt.GetTrack(2);
169 // tx=evt.GetTrack(3);
171 // tx=evt.GetTrack(4);
174 // Float_t rp[3]={2.4,0.1,-8.5};
175 // vp.SetPosition(rp,"car");
178 // tx=evt.GetTrack(5);
180 // tx=evt.GetTrack(6);
182 // tx=evt.GetTrack(7);
185 // Float_t r1[3]={1.6,-3.2,5.7};
186 // v1.SetPosition(r1,"car");
194 // Float_t r2[3]={6.2,4.8,1.3};
195 // v2.SetPosition(r2,"car");
197 // Specify the vertices v1 and v2 as secondary vertices of the primary
199 // vp.SetVertexCopy(1);
203 // Enter the physics structures into the event
204 // evt.SetVertexCopy(1);
205 // evt.AddVertex(vp,0);
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.
219 // Float_t etot=evt.GetEnergy();
220 // Ali3Vector ptot=evt.Get3Momentum();
222 // evt.GetPosition(loc,"sph");
223 // AliPosition r=v1.GetPosition();
225 // Int_t nt=v2.GetNtracks();
226 // AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
230 // Int_t nv=evt.GetNvtx();
231 // AliVertex* vx=evt.GetVertex(1); // Access primary vertex
232 // Float_t e=vx->GetEnergy();
234 // Float_t M=evt.GetInvmass();
236 // Reconstruct the event from scratch
239 // evt.SetNvmax(25); // Increase initial no. of sec. vertices
241 // ... // code to create tracks etc...
244 // Note : All quantities are in GeV, GeV/c or GeV/c**2
246 //--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht
247 //- Modified: NvE $Date: 2004/07/01 14:28:50 $ UU-SAP Utrecht
248 ///////////////////////////////////////////////////////////////////////////
250 #include "AliEvent.h"
251 #include "Riostream.h"
253 ClassImp(AliEvent) // Class implementation to enable ROOT I/O
255 AliEvent::AliEvent() : AliVertex()
257 // Default constructor.
258 // All variables initialised to default values.
274 ///////////////////////////////////////////////////////////////////////////
275 AliEvent::AliEvent(Int_t n) : AliVertex(n)
277 // Create an event to hold initially a maximum of n tracks
278 // All variables initialised to default values
281 cout << " *** This AliVertex initialisation was invoked via the AliEvent ctor." << endl;
298 ///////////////////////////////////////////////////////////////////////////
299 AliEvent::~AliEvent()
301 // Default destructor
313 ///////////////////////////////////////////////////////////////////////////
314 AliEvent::AliEvent(const AliEvent& evt) : AliVertex(evt)
317 fDaytime=evt.fDaytime;
322 fPnucProj=evt.fPnucProj;
326 fPnucTarg=evt.fPnucTarg;
328 fDevCopy=evt.fDevCopy;
331 Int_t ndevs=evt.GetNdevices();
334 fDevices=new TObjArray(ndevs);
335 if (fDevCopy) fDevices->SetOwner();
336 for (Int_t i=1; i<=ndevs; i++)
338 TObject* dev=evt.GetDevice(i);
343 fDevices->Add(dev->Clone());
356 Int_t nhits=evt.fHits->GetEntries();
359 fHits=new TObjArray(nhits);
360 for (Int_t ih=0; ih<nhits; ih++)
362 AliSignal* sx=(AliSignal*)evt.fHits->At(ih);
368 ///////////////////////////////////////////////////////////////////////////
369 void AliEvent::Reset()
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
374 // Note : The DevCopy mode is maintained as it was set by the user before.
401 ///////////////////////////////////////////////////////////////////////////
402 void AliEvent::SetOwner(Bool_t own)
404 // Set ownership of all added objects.
405 // The default parameter is own=kTRUE.
407 // Invokation of this memberfunction also sets all the copy modes
408 // (e.g. TrackCopy & co.) according to the value of own.
410 // This function (with own=kTRUE) is particularly useful when reading data
411 // from a tree/file, since Reset() will then actually remove all the
412 // added objects from memory irrespective of the copy mode settings
413 // during the tree/file creation process. In this way it provides a nice way
414 // of preventing possible memory leaks in the reading/analysis process.
416 // In addition this memberfunction can also be used as a shortcut to set all
417 // copy modes in one go during a tree/file creation process.
418 // However, in this case the user has to take care to only set/change the
419 // ownership (and copy mode) for empty objects (e.g. newly created objects
420 // or after invokation of the Reset() memberfunction) otherwise it will
421 // very likely result in inconsistent destructor behaviour.
425 if (fDevices) fDevices->SetOwner(own);
428 AliVertex::SetOwner(own);
430 ///////////////////////////////////////////////////////////////////////////
431 void AliEvent::SetDayTime(TTimeStamp& stamp)
433 // Set the date and time stamp for this event.
434 // An exact copy of the entered date/time stamp will be saved with an
435 // accuracy of 1 nanosecond.
438 ///////////////////////////////////////////////////////////////////////////
439 void AliEvent::SetDayTime(TDatime& stamp)
441 // Set the date and time stamp for this event.
442 // The entered date/time will be interpreted as being the local date/time
443 // and the accuracy is 1 second.
444 // This function with the TDatime argument is mainly kept for backward
445 // compatibility reasons. It is recommended to use the corresponding
446 // function with the TTimeStamp argument.
448 fDaytime.Set(stamp.GetDate(),stamp.GetTime(),0,kFALSE,0);
450 ///////////////////////////////////////////////////////////////////////////
451 void AliEvent::SetRunNumber(Int_t run)
453 // Set the run number for this event
456 ///////////////////////////////////////////////////////////////////////////
457 void AliEvent::SetEventNumber(Int_t evt)
459 // Set the event number for this event
462 ///////////////////////////////////////////////////////////////////////////
463 TTimeStamp AliEvent::GetDayTime() const
465 // Provide the date and time stamp for this event
468 ///////////////////////////////////////////////////////////////////////////
469 Int_t AliEvent::GetRunNumber() const
471 // Provide the run number for this event
474 ///////////////////////////////////////////////////////////////////////////
475 Int_t AliEvent::GetEventNumber() const
477 // Provide the event number for this event
480 ///////////////////////////////////////////////////////////////////////////
481 void AliEvent::SetProjectile(Int_t a,Int_t z,Double_t pnuc,Int_t id)
483 // Set the projectile A, Z, momentum per nucleon and user defined particle ID.
484 // By default the particle ID is set to zero.
490 ///////////////////////////////////////////////////////////////////////////
491 Int_t AliEvent::GetProjectileA() const
493 // Provide the projectile A value.
496 ///////////////////////////////////////////////////////////////////////////
497 Int_t AliEvent::GetProjectileZ() const
499 // Provide the projectile Z value.
502 ///////////////////////////////////////////////////////////////////////////
503 Double_t AliEvent::GetProjectilePnuc() const
505 // Provide the projectile momentum value per nucleon.
508 ///////////////////////////////////////////////////////////////////////////
509 Int_t AliEvent::GetProjectileId() const
511 // Provide the user defined particle ID of the projectile.
514 ///////////////////////////////////////////////////////////////////////////
515 void AliEvent::SetTarget(Int_t a,Int_t z,Double_t pnuc,Int_t id)
517 // Set the target A, Z, momentum per nucleon and user defined particle ID.
518 // By default the particle ID is set to zero.
524 ///////////////////////////////////////////////////////////////////////////
525 Int_t AliEvent::GetTargetA() const
527 // Provide the target A value.
530 ///////////////////////////////////////////////////////////////////////////
531 Int_t AliEvent::GetTargetZ() const
533 // Provide the target Z value.
536 ///////////////////////////////////////////////////////////////////////////
537 Double_t AliEvent::GetTargetPnuc() const
539 // Provide the target momentum value per nucleon.
542 ///////////////////////////////////////////////////////////////////////////
543 Int_t AliEvent::GetTargetId() const
545 // Provide the user defined particle ID of the target.
548 ///////////////////////////////////////////////////////////////////////////
549 void AliEvent::HeaderData() const
551 // Provide event header information
552 const char* name=GetName();
553 const char* title=GetTitle();
554 Int_t ndevs=GetNdevices();
555 cout << " *" << ClassName() << "::Data*";
556 if (strlen(name)) cout << " Name : " << GetName();
557 if (strlen(title)) cout << " Title : " << GetTitle();
559 cout << " " << fDaytime.AsString() << endl;
560 cout << " Run : " << fRun << " Event : " << fEvent
561 << " Number of devices : " << ndevs << endl;
563 if (ndevs) ShowDevices();
565 ///////////////////////////////////////////////////////////////////////////
566 void AliEvent::Data(TString f)
568 // Provide event information within the coordinate frame f
572 ///////////////////////////////////////////////////////////////////////////
573 Int_t AliEvent::GetNdevices() const
575 // Provide the number of stored devices
577 if (fDevices) ndevs=fDevices->GetEntries();
580 ///////////////////////////////////////////////////////////////////////////
581 void AliEvent::AddDevice(TObject& d)
583 // Add a device to the event.
586 // In case a private copy is made, this is performed via the Clone() memberfunction.
587 // All devices (i.e. classes derived from TObject) have the default TObject::Clone()
589 // However, devices generally contain an internal (signal) data structure
590 // which may include pointers to other objects. Therefore it is recommended to provide
591 // for all devices a specific copy constructor and override the default Clone()
592 // memberfunction using this copy constructor.
593 // An example for this may be seen from AliCalorimeter.
597 fDevices=new TObjArray();
598 if (fDevCopy) fDevices->SetOwner();
601 // Add the device to this event
604 fDevices->Add(d.Clone());
611 ///////////////////////////////////////////////////////////////////////////
612 void AliEvent::SetDevCopy(Int_t j)
614 // (De)activate the creation of private copies of the added devices.
615 // j=0 ==> No private copies are made; pointers of original devices are stored.
616 // j=1 ==> Private copies of the devices are made and these pointers are stored.
620 // In case a private copy is made, this is performed via the Clone() memberfunction.
621 // All devices (i.e. classes derived from TObject) have the default TObject::Clone()
623 // However, devices generally contain an internal (signal) data structure
624 // which may include pointers to other objects. Therefore it is recommended to provide
625 // for all devices a specific copy constructor and override the default Clone()
626 // memberfunction using this copy constructor.
627 // An example for this may be seen from AliCalorimeter.
629 // Once the storage contains pointer(s) to device(s) one cannot
630 // change the DevCopy mode anymore.
631 // To change the DevCopy mode for an existing AliEvent containing
632 // devices one first has to invoke Reset().
642 cout << " *" << ClassName() << "::SetDevCopy* Invalid argument : " << j << endl;
647 cout << " *" << ClassName() << "::SetDevCopy* Storage already contained devices."
648 << " ==> DevCopy mode not changed." << endl;
651 ///////////////////////////////////////////////////////////////////////////
652 Int_t AliEvent::GetDevCopy() const
654 // Provide value of the DevCopy mode.
655 // 0 ==> No private copies are made; pointers of original devices are stored.
656 // 1 ==> Private copies of the devices are made and these pointers are stored.
659 // In case a private copy is made, this is performed via the Clone() memberfunction.
660 // All devices (i.e. classes derived from TObject) have the default TObject::Clone()
662 // However, devices generally contain an internal (signal) data structure
663 // which may include pointers to other objects. Therefore it is recommended to provide
664 // for all devices a specific copy constructor and override the default Clone()
665 // memberfunction using this copy constructor.
666 // An example for this may be seen from AliCalorimeter.
670 ///////////////////////////////////////////////////////////////////////////
671 TObject* AliEvent::GetDevice(Int_t i) const
673 // Return the i-th device of this event.
674 // The first device corresponds to i=1.
682 Int_t ndevs=GetNdevices();
685 cout << " *" << ClassName() << "::GetDevice* Invalid argument i : " << i
686 << " ndevs = " << ndevs << endl;
691 return fDevices->At(i-1);
695 ///////////////////////////////////////////////////////////////////////////
696 TObject* AliEvent::GetDevice(TString name) const
698 // Return the device with name tag "name"
706 Int_t ndevs=GetNdevices();
707 for (Int_t i=0; i<ndevs; i++)
709 TObject* dev=fDevices->At(i);
713 if (s == name) return dev;
717 return 0; // No matching name found
720 ///////////////////////////////////////////////////////////////////////////
721 void AliEvent::ShowDevices() const
723 // Provide an overview of the available devices.
724 Int_t ndevs=GetNdevices();
727 cout << " The following " << ndevs << " devices are available :" << endl;
728 for (Int_t i=1; i<=ndevs; i++)
730 TObject* dev=GetDevice(i);
733 const char* name=dev->GetName();
734 cout << " Device number : " << i;
735 cout << " Class : " << dev->ClassName();
736 if (strlen(name)) cout << " Name : " << name;
737 if (dev->InheritsFrom("AliDevice")) cout << " Nhits : " << ((AliDevice*)dev)->GetNhits();
744 cout << " No devices present for this event." << endl;
747 ///////////////////////////////////////////////////////////////////////////
748 Int_t AliEvent::GetNhits(const char* classname)
750 // Provide the number of hits registered to the specified device class.
751 // The specified device class has to be derived from AliDevice.
752 // It is possible to indicate with the argument "classname" a specific
753 // device instead of a whole class of devices. However, in such a case
754 // it is more efficient to use the GetDevice() memberfunction directly.
757 if (fHits) nhits=fHits->GetEntries();
760 ///////////////////////////////////////////////////////////////////////////
761 TObjArray* AliEvent::GetHits(const char* classname)
763 // Provide the references to all the hits registered to the specified
765 // The specified device class has to be derived from AliDevice.
766 // It is possible to indicate with the argument "classname" a specific
767 // device instead of a whole class of devices. However, in such a case
768 // it is more efficient to use the GetDevice() memberfunction directly.
772 ///////////////////////////////////////////////////////////////////////////
773 void AliEvent::LoadHits(const char* classname)
775 // Load the references to the various hits registered to the specified
777 // The specified device class has to be derived from AliDevice.
778 if (fHits) fHits->Clear();
780 Int_t ndev=GetNdevices();
781 for (Int_t idev=1; idev<=ndev; idev++)
783 TObject* obj=GetDevice(idev);
786 if (obj->InheritsFrom(classname) && obj->InheritsFrom("AliDevice"))
788 AliDevice* dev=(AliDevice*)GetDevice(idev);
789 Int_t nhits=dev->GetNhits();
792 if (!fHits) fHits=new TObjArray();
793 for (Int_t ih=1; ih<=nhits; ih++)
795 AliSignal* sx=dev->GetHit(ih);
796 if (sx) fHits->Add(sx);
802 ///////////////////////////////////////////////////////////////////////////
803 TObjArray* AliEvent::SortHits(TObjArray* hits,Int_t idx,Int_t mode)
805 // Order the references to an array of hits by looping over the input array "hits"
806 // and checking the signal value. The ordered array is returned as a TObjArray.
807 // Note that the input array is not modified.
808 // A "hit" represents an abstract object which is derived from AliSignal.
809 // The user can specify the index of the signal slot to perform the sorting on.
810 // By default the slotindex will be 1.
811 // Via the "mode" argument the user can specify ordering in decreasing
812 // order (mode=-1) or ordering in increasing order (mode=1).
813 // The default is mode=-1.
814 // Signals which were declared as "Dead" will be rejected.
815 // The gain etc... corrected signals will be used in the ordering process.
823 if (idx<=0 || abs(mode)!=1 || !hits) return fHits;
826 TObjArray* ordered=dev.SortHits(idx,mode,hits);
827 if (ordered) fHits=new TObjArray(*ordered);
830 ///////////////////////////////////////////////////////////////////////////
831 TObjArray* AliEvent::SortHits(TObjArray* hits,TString name,Int_t mode)
833 // Order the references to an array of hits by looping over the input array "hits"
834 // and checking the signal value. The ordered array is returned as a TObjArray.
835 // Note that the input array is not modified.
836 // A "hit" represents an abstract object which is derived from AliSignal.
837 // The user can specify the name of the signal slot to perform the sorting on.
838 // In case no matching slotname is found, the signal will be skipped.
839 // Via the "mode" argument the user can specify ordering in decreasing
840 // order (mode=-1) or ordering in increasing order (mode=1).
841 // The default is mode=-1.
842 // Signals which were declared as "Dead" will be rejected.
843 // The gain etc... corrected signals will be used in the ordering process.
851 if (abs(mode)!=1 || !hits) return fHits;
854 TObjArray* ordered=dev.SortHits(name,mode,hits);
855 if (ordered) fHits=new TObjArray(*ordered);
858 ///////////////////////////////////////////////////////////////////////////
859 TObject* AliEvent::Clone(const char* name) const
861 // Make a deep copy of the current object and provide the pointer to the copy.
862 // This memberfunction enables automatic creation of new objects of the
863 // correct type depending on the object type, a feature which may be very useful
864 // for containers when adding objects in case the container owns the objects.
865 // This feature allows to store either AliEvent objects or objects derived from
866 // AliEvent via some generic AddEvent memberfunction, provided these derived
867 // classes also have a proper Clone memberfunction.
869 AliEvent* evt=new AliEvent(*this);
872 if (strlen(name)) evt->SetName(name);
876 ///////////////////////////////////////////////////////////////////////////