]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HBTAN/AliHBTEvent.cxx
Adaption to new fluka common blocks (E. Futo)
[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  {
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;
36  }
37 /**************************************************************************/ 
38
39 AliHBTEvent::~AliHBTEvent()
40  {
41 //destructor   
42   this->Reset();//delete all particles
43   if(fParticles)
44    { 
45     delete [] fParticles; //and delete array itself
46    }
47   fParticles = 0x0;
48  }
49 /**************************************************************************/ 
50 void  AliHBTEvent::Reset()
51 {
52   //deletes all particles from the event
53   if(fParticles && fOwner)
54     {
55       for(Int_t i =0; i<fNParticles; i++)
56         delete fParticles[i];
57     }
58    fNParticles = 0;
59
60 /**************************************************************************/ 
61
62 AliHBTParticle* AliHBTEvent::GetParticleSafely(Int_t n)
63 {
64   //returns nth particle with range check
65   if( (n<0) || (fNParticles<=n) ) return 0x0;
66   else return fParticles[n];
67 }
68 /**************************************************************************/ 
69
70 void  AliHBTEvent:: AddParticle(AliHBTParticle* hbtpart)
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 }
76 /**************************************************************************/ 
77
78 void  AliHBTEvent::AddParticle(TParticle* part, Int_t idx)
79 {
80   //Adds TParticle to event
81   AddParticle( new AliHBTParticle(*part,idx) );
82 }
83 /**************************************************************************/ 
84 void  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 }
91 /**************************************************************************/ 
92
93 void AliHBTEvent::Expand()
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 }