1 //__________________________________________________________
2 ///////////////////////////////////////////////////////////////////
6 // This class is container for paticles coming from one event
8 // Piotr.Skowronski@cern.ch
10 ///////////////////////////////////////////////////////////////////
13 #include "AliHBTEvent.h"
14 #include "AliHBTParticle.h"
18 const UInt_t AliHBTEvent::fgkInitEventSize = 100;
20 /**************************************************************************/
22 AliHBTEvent::AliHBTEvent():
23 fSize(fgkInitEventSize),
24 fParticles(new AliHBTParticle* [fSize]),
30 if(fgkInitEventSize<1)
32 Fatal("AliHBTEvent::AliHBTEvent()",
33 "fgkInitEventSize has a stiupid value (%d). Change it to positive number and recompile",
38 /**************************************************************************/
40 AliHBTEvent::AliHBTEvent(const AliHBTEvent& source):
43 fParticles(new AliHBTParticle* [fSize]),
44 fNParticles(source.fNParticles),
45 fOwner(source.fNParticles),
46 fRandomized(source.fRandomized)
49 for(Int_t i =0; i<fNParticles; i++)
51 fParticles[i] = new AliHBTParticle( *(source.fParticles[i]) );
55 /**************************************************************************/
57 AliHBTEvent& AliHBTEvent::operator=(const AliHBTEvent& source)
61 if (fParticles) delete [] fParticles;
63 fParticles = new AliHBTParticle* [fSize];
64 fNParticles = source.fNParticles;
65 fOwner = source.fNParticles;
66 fRandomized = source.fRandomized;
68 for(Int_t i =0; i<fNParticles; i++)
70 fParticles[i] = new AliHBTParticle( *(source.fParticles[i]) );
74 /**************************************************************************/
75 AliHBTEvent::~AliHBTEvent()
78 this->Reset();//delete all particles
81 delete [] fParticles; //and delete array itself
85 /**************************************************************************/
86 void AliHBTEvent::Reset()
88 //deletes all particles from the event
89 if(fParticles && fOwner)
91 for(Int_t i =0; i<fNParticles; i++)
93 for (Int_t j = i+1; j<fNParticles; j++)
94 if (fParticles[j] == fParticles[i]) fParticles[j] = 0x0;
101 /**************************************************************************/
103 AliHBTParticle* AliHBTEvent::GetParticleSafely(Int_t n)
105 //returns nth particle with range check
106 if( (n<0) || (fNParticles<=n) ) return 0x0;
107 else return fParticles[n];
109 /**************************************************************************/
111 void AliHBTEvent:: AddParticle(AliHBTParticle* hbtpart)
113 //Adds new perticle to the event
114 if ( fNParticles+1 >= fSize) Expand(); //if there is no space in array, expand it
115 fParticles[fNParticles++] = hbtpart; //add a pointer
117 /**************************************************************************/
119 void AliHBTEvent::AddParticle(TParticle* part, Int_t idx)
121 //Adds TParticle to event
122 AddParticle( new AliHBTParticle(*part,idx) );
124 /**************************************************************************/
125 void AliHBTEvent::AddParticle(Int_t pdg, Int_t idx,
126 Double_t px, Double_t py, Double_t pz, Double_t etot,
127 Double_t vx, Double_t vy, Double_t vz, Double_t time)
129 //adds particle to event
130 AddParticle(new AliHBTParticle(pdg,idx,px,py,pz,etot,vx,vy,vz,time) );
132 /**************************************************************************/
134 void AliHBTEvent::Expand()
136 //expands the array with pointers to particles
137 //about the size defined in fgkInitEventSize
139 fSize+=fgkInitEventSize;
140 AliHBTParticle** tmpParticles = new AliHBTParticle* [fSize]; //create new array of pointers
141 //check if we got memory / if not Abort
142 if (!tmpParticles) Fatal("AliHBTEvent::Expand()","No more space in memory");
145 for(Int_t i = 0; i<fNParticles ;i++)
146 //copy pointers to the new array
148 tmpParticles[i] = fParticles[i];
150 delete [] fParticles; //delete old array
151 fParticles = tmpParticles; //copy new pointer to the array of pointers to particles
153 /**************************************************************************/
155 void AliHBTEvent::SwapParticles(Int_t i, Int_t j)
157 //swaps particles positions; used by AliHBTEvent::Blend
158 if ( (i<0) || (i>=fNParticles)) return;
159 if ( (j<0) || (j>=fNParticles)) return;
161 AliHBTParticle* tmp = fParticles[i];
162 fParticles[i] = fParticles[j];