]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HBTAN/AliHBTEvent.cxx
reverting to prev.
[u/mrichter/AliRoot.git] / HBTAN / AliHBTEvent.cxx
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
13 #include "AliHBTEvent.h"
14 #include "AliHBTParticle.h"
15
16 ClassImp(AliHBTEvent)
17
18 const UInt_t AliHBTEvent::fgkInitEventSize = 100;
19
20 /**************************************************************************/ 
21  
22 AliHBTEvent::AliHBTEvent():
23  fSize(fgkInitEventSize),
24  fParticles(new AliHBTParticle* [fSize]),
25  fNParticles(0),
26  fOwner(kTRUE),
27  fRandomized(kFALSE)
28  {
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    }
37  }
38 /**************************************************************************/ 
39  
40 AliHBTEvent::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 /**************************************************************************/ 
56
57 AliHBTEvent& AliHBTEvent::operator=(const AliHBTEvent& source)
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 /**************************************************************************/ 
75 AliHBTEvent::~AliHBTEvent()
76  {
77 //destructor   
78   this->Reset();//delete all particles
79   if(fParticles)
80    { 
81     delete [] fParticles; //and delete array itself
82    }
83   fParticles = 0x0;
84  }
85 /**************************************************************************/ 
86 void  AliHBTEvent::Reset()
87 {
88   //deletes all particles from the event
89   if(fParticles && fOwner)
90     {
91       for(Int_t i =0; i<fNParticles; i++)
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        }
97     }
98    fNParticles = 0;
99    fRandomized = kFALSE;
100
101 /**************************************************************************/ 
102
103 AliHBTParticle* AliHBTEvent::GetParticleSafely(Int_t n)
104 {
105   //returns nth particle with range check
106   if( (n<0) || (fNParticles<=n) ) return 0x0;
107   else return fParticles[n];
108 }
109 /**************************************************************************/ 
110
111 void  AliHBTEvent:: AddParticle(AliHBTParticle* hbtpart)
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 }
117 /**************************************************************************/ 
118
119 void  AliHBTEvent::AddParticle(TParticle* part, Int_t idx)
120 {
121   //Adds TParticle to event
122   AddParticle( new AliHBTParticle(*part,idx) );
123 }
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)
128 {
129   //adds particle to event
130   AddParticle(new  AliHBTParticle(pdg,idx,px,py,pz,etot,vx,vy,vz,time) );
131 }
132 /**************************************************************************/ 
133
134 void AliHBTEvent::Expand()
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 }
153 /**************************************************************************/ 
154
155 void 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 }