Adaption to new fluka common blocks (E. Futo)
[u/mrichter/AliRoot.git] / HBTAN / AliHBTEvent.cxx
CommitLineData
8089a083 1//__________________________________________________________
2///////////////////////////////////////////////////////////////////
3//
4// class AliHBTEvent
5//
6// This class is container for paticles coming from one event
7//
8// Piotr.Skowronski@cern.ch
9//
10///////////////////////////////////////////////////////////////////
11
12
1b446896 13#include "AliHBTEvent.h"
14#include "AliHBTParticle.h"
15
16ClassImp(AliHBTEvent)
17
8089a083 18const UInt_t AliHBTEvent::fgkInitEventSize = 100;
1b446896 19
1b446896 20/**************************************************************************/
21
8089a083 22AliHBTEvent::AliHBTEvent()
1b446896 23 {
d74e6a27 24//default constructor
25 if(fgkInitEventSize<1)
26 {
27 Fatal("AliHBTEvent::AliHBTEvent()",
28 "fgkInitEventSize has a stiupid value (%d). Change it to positive number and recompile",
29 fgkInitEventSize);
30
31 }
32 fSize=fgkInitEventSize;
33 fParticles = new AliHBTParticle* [fSize];
34 fNParticles = 0;
35 fOwner = kTRUE;
1b446896 36 }
37/**************************************************************************/
38
39AliHBTEvent::~AliHBTEvent()
40 {
d74e6a27 41//destructor
42 this->Reset();//delete all particles
43 if(fParticles)
44 {
45 delete [] fParticles; //and delete array itself
46 }
47 fParticles = 0x0;
1b446896 48 }
49/**************************************************************************/
50void AliHBTEvent::Reset()
51{
8089a083 52 //deletes all particles from the event
cea431b6 53 if(fParticles && fOwner)
1b446896 54 {
55 for(Int_t i =0; i<fNParticles; i++)
56 delete fParticles[i];
57 }
58 fNParticles = 0;
59}
d74e6a27 60/**************************************************************************/
1b446896 61
62AliHBTParticle* AliHBTEvent::GetParticleSafely(Int_t n)
d74e6a27 63{
64 //returns nth particle with range check
65 if( (n<0) || (fNParticles<=n) ) return 0x0;
66 else return fParticles[n];
67}
1b446896 68/**************************************************************************/
69
70void AliHBTEvent:: AddParticle(AliHBTParticle* hbtpart)
d74e6a27 71{
72 //Adds new perticle to the event
73 if ( fNParticles+1 >= fSize) Expand(); //if there is no space in array, expand it
74 fParticles[fNParticles++] = hbtpart; //add a pointer
75}
1b446896 76/**************************************************************************/
d74e6a27 77
8089a083 78void AliHBTEvent::AddParticle(TParticle* part, Int_t idx)
d74e6a27 79{
80 //Adds TParticle to event
81 AddParticle( new AliHBTParticle(*part,idx) );
82}
1b446896 83/**************************************************************************/
d74e6a27 84void AliHBTEvent::AddParticle(Int_t pdg, Int_t idx,
85 Double_t px, Double_t py, Double_t pz, Double_t etot,
86 Double_t vx, Double_t vy, Double_t vz, Double_t time)
87{
88 //adds particle to event
89 AddParticle(new AliHBTParticle(pdg,idx,px,py,pz,etot,vx,vy,vz,time) );
90}
1b446896 91/**************************************************************************/
92
93void AliHBTEvent::Expand()
d74e6a27 94{
95//expands the array with pointers to particles
96//about the size defined in fgkInitEventSize
97
98 fSize+=fgkInitEventSize;
99 AliHBTParticle** tmpParticles = new AliHBTParticle* [fSize]; //create new array of pointers
100 //check if we got memory / if not Abort
101 if (!tmpParticles) Fatal("AliHBTEvent::Expand()","No more space in memory");
102
103
104 for(Int_t i = 0; i<fNParticles ;i++)
105 //copy pointers to the new array
106 {
107 tmpParticles[i] = fParticles[i];
108 }
109 delete [] fParticles; //delete old array
110 fParticles = tmpParticles; //copy new pointer to the array of pointers to particles
111}