]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAOD.cxx
First version of writing aod files. Reader for aod files. AliAOD::fParticles chnged...
[u/mrichter/AliRoot.git] / ANALYSIS / AliAOD.cxx
1 #include "AliAOD.h"
2 /**************************************************************************
3  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  *                                                                        *
5  * Author: The ALICE Off-line Project.                                    *
6  * Contributors are mentioned in the code where appropriate.              *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 /* $Id$ */
18
19 /////////////////////////////////////////////////////////////
20 //
21 // base class for AOD containers
22 //
23 /////////////////////////////////////////////////////////////
24
25 #include <TParticle.h>
26 #include <TClass.h>
27 #include <TString.h>
28 #include "AliAODParticle.h"
29 #include "AliTrackPoints.h"
30
31 ClassImp(AliAOD)
32
33 AliAOD::AliAOD():
34  fParticles(0x0),
35  fIsRandomized(kFALSE),
36  fPrimaryVertexX(0.0),
37  fPrimaryVertexY(0.0),
38  fPrimaryVertexZ(0.0),
39  fParticleClass(0x0)
40 {
41  //ctor
42 // Info("AliAOD()","Entered");
43 // SetOwner(kTRUE);
44 // Info("AliAOD()","Exited");
45 }
46 /**************************************************************************/
47
48 AliAOD::~AliAOD()
49 {
50   //Destructor
51   //fParticleClass does not belong to AliAOD -> Do not delete it
52   delete fParticles;
53   
54 }
55 /**************************************************************************/
56
57 void AliAOD::SetParticleClassName(const char* classname)
58 {
59 //Sets type of particle that is going to be stored 
60   if (gROOT == 0x0) Fatal("SetParticleClassName","ROOT System not initialized");
61   TClass* pclass = gROOT->GetClass(classname);
62   if ( pclass == 0x0 )
63    {
64      Error("SetParticleClass","Can not get TClass for class named %s",classname);
65      return;
66    }
67   SetParticleClass(pclass);
68 }
69 /**************************************************************************/
70
71 void AliAOD::SetParticleClass(TClass* pclass)
72 {
73 //Sets type of particle that is going to be stored 
74
75   if ( pclass == 0x0 )
76    {
77      Error("SetParticleClass","Parameter is NULL.");
78      return;
79    }
80    
81   if ( pclass->InheritsFrom("AliVAODParticle") == kFALSE )
82    {
83      Error("SetParticleClass","Class named %s does not inherit from AliVAODParticle",pclass->GetName());
84      return;
85    }
86   if (pclass != fParticleClass)
87    {
88      fParticleClass = pclass;
89      if (fParticleClass) delete fParticles;
90      fParticles = new TClonesArray(fParticleClass);
91    }
92 }
93
94 /**************************************************************************/
95
96 void  AliAOD::AddParticle(TParticle* part, Int_t idx)
97 {
98   //Adds TParticle to event
99   if (part == 0x0) 
100    {
101      Error("AddParticle(TParticle*,Int_t)","pointer to particle is NULL");
102      return;
103    }
104
105   if (fParticles == 0x0) SetParticleClassName("AliAODParticle");
106   AddParticle( new AliAODParticle(*part,idx) );
107 }
108 /**************************************************************************/
109
110 void  AliAOD::AddParticle(AliVAODParticle* particle)
111 {
112  //add particle to AOD
113  //MAKES ITS OWN COPY OF THE PARTICLE!!! (AOD is not going to keep and delete input pointer)
114  
115   if (fParticles == 0x0) SetParticleClassName("AliAODParticle");
116
117   Int_t idx = fParticles->GetLast() + 1;
118   TClonesArray& arr = *fParticles;
119   
120   AliVAODParticle* pp = (AliVAODParticle*)fParticleClass->New(arr[idx]);
121   pp->operator=(*particle);
122   
123 }
124 /**************************************************************************/
125
126 void  AliAOD::AddParticle(Int_t pdg, Int_t idx,
127                           Double_t px, Double_t py, Double_t pz, Double_t etot,
128                           Double_t vx, Double_t vy, Double_t vz, Double_t time)
129 {
130   //adds particle to event (standard AOD class)
131
132   if (fParticles == 0x0) SetParticleClassName("AliAODParticle");
133
134   Int_t newpartidx = fParticles->GetLast() + 1;
135   TClonesArray& arr = *fParticles;
136   
137   AliVAODParticle* p =  (AliVAODParticle*)fParticleClass->New(arr[newpartidx]);
138   
139   p->SetPdgCode(pdg);
140   p->SetUID(idx);
141   p->SetMomentum(px,py,pz,etot);
142   p->SetProductionVertex(vx,vy,vz,time);
143   
144 }
145 /**************************************************************************/
146
147 void AliAOD::SwapParticles(Int_t i, Int_t j)
148 {
149 //swaps particles positions; used by AliHBTEvent::Blend
150   if ( (i<0) || (i>=GetNumberOfParticles()) ) return;
151   if ( (j<0) || (j>=GetNumberOfParticles()) ) return;
152   
153   AliVAODParticle* tmpobj = (AliVAODParticle*)fParticleClass->New();
154   AliVAODParticle& tmp = *tmpobj;
155   AliVAODParticle& first = *(GetParticle(i));
156   AliVAODParticle& second = *(GetParticle(j));
157   
158   tmp = first;
159   first = second;
160   second = tmp;
161   
162 }
163 /**************************************************************************/
164
165 void  AliAOD::Reset()
166 {
167   //deletes all particles from the event
168    if (fParticles) fParticles->Clear("C");
169    
170    fIsRandomized = kFALSE;
171 }
172 /**************************************************************************/
173
174 void AliAOD::GetPrimaryVertex(Double_t&x, Double_t&y, Double_t&z)
175 {
176 //returns positions of the primary vertex
177   x = fPrimaryVertexX;
178   y = fPrimaryVertexY;
179   z = fPrimaryVertexZ;
180 }
181 /**************************************************************************/
182
183 void AliAOD::SetPrimaryVertex(Double_t x, Double_t y, Double_t z)
184 {
185 //Sets positions of the primary vertex 
186   fPrimaryVertexX = x;
187   fPrimaryVertexY = y;
188   fPrimaryVertexZ = z;
189 }
190 /**************************************************************************/
191
192 Int_t AliAOD::GetNumberOfCharged(Double_t etamin, Double_t etamax) const
193 {
194   //reurns number of charged particles within given pseudorapidity range
195   Int_t n = 0;
196   Int_t npart = GetNumberOfParticles();
197   for (Int_t i = 0; i < npart; i++)
198    {
199      AliVAODParticle* p = GetParticle(i);
200      Double_t eta = p->Eta();
201      if ( (eta < etamin) || (eta > etamax) ) continue;
202      if (p->Charge() != 0.0) n++;
203    }
204   return n;
205 }
206 /**************************************************************************/
207
208 void AliAOD::Move(Double_t x, Double_t y, Double_t z)
209 {
210  //moves all spacial coordinates about this vector
211  // vertex
212  // track points
213  // and whatever will be added to AOD and AOD particles that is a space coordinate
214
215   fPrimaryVertexX += x;
216   fPrimaryVertexY += y;
217   fPrimaryVertexZ += z;
218
219   Int_t npart = GetNumberOfParticles();
220   for (Int_t i = 0; i < npart; i++)
221    {
222      AliVAODParticle* p = GetParticle(i);
223      AliTrackPoints* tp  = p->GetTPCTrackPoints();
224      if (tp) tp->Move(x,y,z);
225      tp  = p->GetITSTrackPoints();
226      if (tp) tp->Move(x,y,z);
227    }
228 }
229
230 void AliAOD::Print(Option_t* /*option*/)
231 {
232   //Prints AOD
233   TString ts;
234   TString msg("\n");
235   msg+="Particle Class: ";
236   if (fParticleClass)
237    {
238      msg+=fParticleClass->GetName();
239    }
240   else
241    {
242      msg+="Not specified yet";
243    } 
244   msg += "\n";
245   msg += "Vertex position X: ";
246   msg += fPrimaryVertexX;
247   msg += " Y:" ;
248   msg += fPrimaryVertexY;
249   msg += " Z:";
250   msg += fPrimaryVertexZ;
251   msg += "\n";
252   
253   msg += "Randomized: ";
254   msg += fIsRandomized;
255   msg += "\n";
256   
257   Info("Print","%s",msg.Data());
258   
259   Int_t npart = GetNumberOfParticles();
260   Info("Print","Npart: %d",npart);
261   for (Int_t i = 0; i < npart; i++)
262    {
263      Info("Print","Getting particle %d",i);
264      AliVAODParticle* p = GetParticle(i);
265      Info("Print","Printing particle %d, address %#x",i,p);
266      p->Dump();
267      p->Print();
268      Info("Print","particle %d printed",i);
269    }
270 }
271
272 void AliAOD::SetOwner(Bool_t /*owner*/)
273 {
274 //Sets the ownership of particles: if particles should be also deleted if AOD is deleted/reseted
275 //Since fParticles is Clones and not Object Array, it is always the owner and this method does not have sense
276  
277  MayNotUse("SetOwner");
278  //if fParticles->SetOwner(owner);
279  
280 }