]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HBTAN/AliHBTEvent.cxx
Few switches added
[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
88cb7938 22AliHBTEvent::AliHBTEvent():
23 fSize(fgkInitEventSize),
24 fParticles(new AliHBTParticle* [fSize]),
25 fNParticles(0),
26 fOwner(kTRUE),
27 fRandomized(kFALSE)
1b446896 28 {
d74e6a27 29//default constructor
30 if(fgkInitEventSize<1)
31 {
32 Fatal("AliHBTEvent::AliHBTEvent()",
33 "fgkInitEventSize has a stiupid value (%d). Change it to positive number and recompile",
34 fgkInitEventSize);
35
36 }
1b446896 37 }
38/**************************************************************************/
bed069a4 39
40AliHBTEvent::AliHBTEvent(const AliHBTEvent& source):
41 TObject(source),
42 fSize(source.fSize),
43 fParticles(new AliHBTParticle* [fSize]),
44 fNParticles(source.fNParticles),
45 fOwner(source.fNParticles),
46 fRandomized(source.fRandomized)
47{
48//copy constructor
49 for(Int_t i =0; i<fNParticles; i++)
50 {
51 fParticles[i] = new AliHBTParticle( *(source.fParticles[i]) );
52 }
53
54}
55/**************************************************************************/
1b446896 56
81877d10 57AliHBTEvent& AliHBTEvent::operator=(const AliHBTEvent& source)
bed069a4 58{
59 // assigment operator
60 Reset();
61 if (fParticles) delete [] fParticles;
62 fSize = source.fSize;
63 fParticles = new AliHBTParticle* [fSize];
64 fNParticles = source.fNParticles;
65 fOwner = source.fNParticles;
66 fRandomized = source.fRandomized;
67
68 for(Int_t i =0; i<fNParticles; i++)
69 {
70 fParticles[i] = new AliHBTParticle( *(source.fParticles[i]) );
71 }
72 return *this;
73}
74/**************************************************************************/
1b446896 75AliHBTEvent::~AliHBTEvent()
76 {
d74e6a27 77//destructor
78 this->Reset();//delete all particles
79 if(fParticles)
80 {
81 delete [] fParticles; //and delete array itself
82 }
83 fParticles = 0x0;
1b446896 84 }
85/**************************************************************************/
86void AliHBTEvent::Reset()
87{
8089a083 88 //deletes all particles from the event
cea431b6 89 if(fParticles && fOwner)
1b446896 90 {
91 for(Int_t i =0; i<fNParticles; i++)
bed069a4 92 {
93 for (Int_t j = i+1; j<fNParticles; j++)
94 if (fParticles[j] == fParticles[i]) fParticles[j] = 0x0;
95 delete fParticles[i];
96 }
1b446896 97 }
98 fNParticles = 0;
efaf00f8 99 fRandomized = kFALSE;
1b446896 100}
d74e6a27 101/**************************************************************************/
1b446896 102
103AliHBTParticle* AliHBTEvent::GetParticleSafely(Int_t n)
d74e6a27 104{
105 //returns nth particle with range check
106 if( (n<0) || (fNParticles<=n) ) return 0x0;
107 else return fParticles[n];
108}
1b446896 109/**************************************************************************/
110
111void AliHBTEvent:: AddParticle(AliHBTParticle* hbtpart)
d74e6a27 112{
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
116}
1b446896 117/**************************************************************************/
d74e6a27 118
8089a083 119void AliHBTEvent::AddParticle(TParticle* part, Int_t idx)
d74e6a27 120{
121 //Adds TParticle to event
122 AddParticle( new AliHBTParticle(*part,idx) );
123}
1b446896 124/**************************************************************************/
d74e6a27 125void 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)
128{
129 //adds particle to event
130 AddParticle(new AliHBTParticle(pdg,idx,px,py,pz,etot,vx,vy,vz,time) );
131}
1b446896 132/**************************************************************************/
133
134void AliHBTEvent::Expand()
d74e6a27 135{
136//expands the array with pointers to particles
137//about the size defined in fgkInitEventSize
138
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");
143
144
145 for(Int_t i = 0; i<fNParticles ;i++)
146 //copy pointers to the new array
147 {
148 tmpParticles[i] = fParticles[i];
149 }
150 delete [] fParticles; //delete old array
151 fParticles = tmpParticles; //copy new pointer to the array of pointers to particles
152}
fe1a3526 153/**************************************************************************/
154
155void AliHBTEvent::SwapParticles(Int_t i, Int_t j)
156{
157//swaps particles positions; used by AliHBTEvent::Blend
158 if ( (i<0) || (i>=fNParticles)) return;
159 if ( (j<0) || (j>=fNParticles)) return;
160
161 AliHBTParticle* tmp = fParticles[i];
162 fParticles[i] = fParticles[j];
163 fParticles[j] = tmp;
164}