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