]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAODParticle.cxx
Small mods by Andrei
[u/mrichter/AliRoot.git] / ANALYSIS / AliAODParticle.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //___________________________________________________________
19 /////////////////////////////////////////////////////////////
20 //
21 // class AliAODParticle
22 //
23 // Ali HBT Particle: simplified class TParticle
24 // Simplified in order to minimize the size of object
25 //  - we want to keep a lot of such a objects in memory
26 // Additionaly adjusted for HBT Analysies purposes
27 // + pointer to Track Points
28 // + pointer to Cluster Map(s)
29 //
30 // Piotr.Skowronski@cern.ch
31 //
32 /////////////////////////////////////////////////////////////
33 #include <TParticle.h>
34
35 #include "AliAODParticle.h"
36 #include "AliClusterMap.h"
37 #include "AliLog.h"
38 #include "AliTrackPoints.h"
39
40 ClassImp(AliAODParticle)
41
42 //______________________________________________________________________________
43 AliAODParticle::AliAODParticle():  
44  fPdgIdx(0), fIdxInEvent(0),fNPids(0),fPids(0x0),fPidProb(0x0),
45  fCalcMass(0),fPx(0), fPy(0),fPz(0),fE(0), fVx(0), fVy(0),fVz(0),fVt(0),
46  fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
47 {//empty particle
48 }
49 //______________________________________________________________________________
50
51 AliAODParticle::AliAODParticle(Int_t pdg, Int_t idx,
52                Double_t px, Double_t py, Double_t pz, Double_t etot,
53                Double_t vx, Double_t vy, Double_t vz, Double_t time):  
54   fPdgIdx(0), fIdxInEvent(idx),fNPids(0),fPids(0x0),fPidProb(0x0),
55   fCalcMass(0), 
56   fPx(px), fPy(py),fPz(pz),fE(etot), 
57   fVx(vx), fVy(vy),fVz(vz),fVt(time),
58   fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
59 {
60 //mormal constructor
61   SetPdgCode(pdg);
62   if (GetPDG()) {
63      fCalcMass    = GetPDG()->Mass();
64   } else {
65      Double_t a2 = fE*fE -fPx*fPx -fPy*fPy -fPz*fPz;
66      if (a2 >= 0) fCalcMass =  TMath::Sqrt(a2);
67      else         fCalcMass = -TMath::Sqrt(-a2);
68   }
69 }
70 //______________________________________________________________________________
71
72 AliAODParticle::AliAODParticle(Int_t pdg, Float_t prob, Int_t idx, 
73                                Double_t px, Double_t py, Double_t pz, Double_t etot,
74                                Double_t vx, Double_t vy, Double_t vz, Double_t time):
75   fPdgIdx(0), fIdxInEvent(idx),fNPids(0),fPids(0x0),fPidProb(0x0),
76   fCalcMass(0), 
77   fPx(px), fPy(py),fPz(pz),fE(etot), 
78   fVx(vx), fVy(vy),fVz(vz),fVt(time),
79   fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
80 {
81 //mormal constructor
82   SetPdgCode(pdg,prob);
83   if (GetPDG()) {
84      fCalcMass    = GetPDG()->Mass();
85   } else {
86      Double_t a2 = fE*fE -fPx*fPx -fPy*fPy -fPz*fPz;
87      if (a2 >= 0) fCalcMass =  TMath::Sqrt(a2);
88      else         fCalcMass = -TMath::Sqrt(-a2);
89   }
90 }
91 //______________________________________________________________________________
92
93 AliAODParticle::AliAODParticle(const AliAODParticle& in):
94    AliVAODParticle(in),
95    fPdgIdx(in.fPdgIdx), fIdxInEvent(in.fIdxInEvent),
96    fNPids(in.fNPids),fPids(new Int_t[fNPids]),fPidProb(new Float_t[fNPids]),
97    fCalcMass(in.GetCalcMass()),
98    fPx(in.Px()),fPy(in.Py()),fPz(in.Pz()),fE(in.E()), 
99    fVx(in.Vx()),fVy(in.Vy()),fVz(in.Vz()),fVt(in.T()),
100    fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
101 {
102  //Copy constructor
103 // Info("AliAODParticle(const AliAODParticle& in)","");
104  for(Int_t i = 0; i<fNPids; i++)
105   {
106     fPids[i] =  in.fPids[i];
107     fPidProb[i] = in.fPidProb[i];
108   }
109  
110  if (in.fTPCTrackPoints)
111    fTPCTrackPoints = (AliTrackPoints*)in.fTPCTrackPoints->Clone();
112  if (in.fITSTrackPoints)
113    fITSTrackPoints = (AliTrackPoints*)in.fITSTrackPoints->Clone();
114  if (in.fClusterMap)
115    fClusterMap = (AliClusterMap*)in.fClusterMap->Clone();
116 }
117 //______________________________________________________________________________
118
119 AliAODParticle::AliAODParticle(const AliVAODParticle& in):
120    AliVAODParticle(in),
121    fPdgIdx(0), fIdxInEvent(in.GetUID()),
122    fNPids(0),fPids(0x0),fPidProb(0x0),
123    fCalcMass(-1.0),
124    fPx(in.Px()),fPy(in.Py()),fPz(in.Pz()),fE(in.E()), 
125    fVx(in.Vx()),fVy(in.Vy()),fVz(in.Vz()),fVt(in.T()),
126    fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
127 {
128  //Copy constructor
129 // Info("AliAODParticle(const AliVAODParticle& in)","");
130  for(Int_t i = 0; i<in.GetNumberOfPids(); i++)
131   {
132     SetPIDprobability(in.GetNthPid(i),in.GetNthPidProb(i));
133   }
134  SetPdgCode(in.GetPdgCode(),in.GetPidProb());
135  
136  AliTrackPoints* tpts = in.GetTPCTrackPoints();
137  if (tpts)  SetTPCTrackPoints((AliTrackPoints*)tpts->Clone());
138  
139  tpts = in.GetITSTrackPoints();  
140  if (tpts) SetITSTrackPoints((AliTrackPoints*)tpts->Clone());
141    
142  AliClusterMap* clmap = in.GetClusterMap();
143  if (clmap) SetClusterMap((AliClusterMap*)clmap->Clone());
144 }
145 //______________________________________________________________________________
146
147 AliAODParticle::AliAODParticle(const TParticle &p,Int_t idx):
148    fPdgIdx(0), fIdxInEvent(idx),
149    fNPids(0),fPids(0x0),fPidProb(0x0),
150    fCalcMass(p.GetCalcMass()),
151    fPx(p.Px()),fPy(p.Py()),fPz(p.Pz()),fE(p.Energy()), 
152    fVx(p.Vx()),fVy(p.Vy()),fVz(p.Vz()),fVt(p.T()),
153    fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
154 {
155  //all copied in the initialization
156  SetPdgCode(p.GetPdgCode());
157 }
158 //______________________________________________________________________________
159
160 AliAODParticle::~AliAODParticle()
161 {
162 //dtor  
163   delete [] fPids;
164   delete [] fPidProb;
165   delete fTPCTrackPoints;
166   delete fITSTrackPoints;
167   delete fClusterMap;
168 }
169 //______________________________________________________________________________
170
171 void AliAODParticle::Clear(Option_t*)
172 {
173 //Must be implemented in order to store this object in Clones Array
174   delete [] fPids;
175   delete [] fPidProb;
176   delete fTPCTrackPoints;
177   delete fITSTrackPoints;
178   delete fClusterMap;
179   
180   fPids = 0x0;
181   fPidProb = 0x0;
182   fTPCTrackPoints = 0x0;
183   fITSTrackPoints = 0x0;
184   fClusterMap = 0x0;
185 }
186 //______________________________________________________________________________
187
188 AliVAODParticle& AliAODParticle::operator=(const AliVAODParticle& in)
189 {
190 //operator=
191 //  Info("operator=(const AliVAODParticle& in)","AliAODParticle");
192   
193   if (&in == this) return *this;
194
195   delete [] fPids;
196   delete [] fPidProb;
197   fPids = 0x0;
198   fPidProb = 0x0;
199   fNPids = 0;
200
201   Int_t npids = in.GetNumberOfPids();
202   for (Int_t i = 0; i < npids; i++)
203    {
204      SetPIDprobability(in.GetNthPid(i),in.GetNthPidProb(i));
205    }
206    
207   SetPdgCode(in.GetPdgCode(),in.GetPidProb());
208
209   SetUID(in.GetUID());
210
211   fCalcMass = in.Mass();
212   
213   fPx = in.Px();
214   fPy = in.Py();
215   fPz = in.Pz();
216   fE = in.E(); 
217   fVx = in.Vx();
218   fVy = in.Vy();
219   fVz = in.Vz();
220   fVt = in.T();
221   
222   delete fTPCTrackPoints;
223   AliTrackPoints* tpts = in.GetTPCTrackPoints();
224   fTPCTrackPoints = (tpts)?(AliTrackPoints*)tpts->Clone():0x0;
225
226   delete fITSTrackPoints;
227   tpts = in.GetITSTrackPoints();  
228   fITSTrackPoints = (tpts)?(AliTrackPoints*)tpts->Clone():0x0;
229   
230   delete fClusterMap;
231   AliClusterMap* incmap = in.GetClusterMap();
232   fClusterMap =  (incmap)?(AliClusterMap*)incmap->Clone():0x0;
233   
234   return *this;
235 }
236 //______________________________________________________________________________
237
238 AliAODParticle& AliAODParticle::operator=(const AliAODParticle& in)
239 {
240 //assigment operator
241 //  Info("operator=(const AliAODParticle& in)","AliAODParticle");
242   if (&in == this) return *this;
243   fNPids = in.fNPids;
244   delete [] fPids;
245   delete [] fPidProb;
246   fPids = new Int_t[fNPids];
247   fPidProb = new Float_t[fNPids];
248   for (Int_t i = 0; i < fNPids;i++)
249    {
250      fPids[i]    = in.fPids[i];
251      fPidProb[i] = in.fPidProb[i];
252    }
253    
254   fPdgIdx = in.fPdgIdx; 
255   fIdxInEvent = in.fIdxInEvent;  
256   fCalcMass = in.GetCalcMass();
257   fPx = in.Px();
258   fPy = in.Py();
259   fPz = in.Pz();
260   fE = in.E(); 
261   fVx = in.Vx();
262   fVy = in.Vy();
263   fVz = in.Vz();
264   fVt = in.T();
265   
266   delete fTPCTrackPoints;
267   fTPCTrackPoints = (in.fTPCTrackPoints)?(AliTrackPoints*)in.fTPCTrackPoints->Clone():0x0;
268
269   delete fITSTrackPoints;
270   fITSTrackPoints = (in.fITSTrackPoints)?(AliTrackPoints*)in.fITSTrackPoints->Clone():0x0;
271   
272   delete fClusterMap;
273   fClusterMap =  (in.fClusterMap)?(AliClusterMap*)in.fClusterMap->Clone():0x0;
274   
275   return *this;
276 }
277 //______________________________________________________________________________
278
279 void AliAODParticle::SetPdgCode(Int_t pdg,Float_t prob)
280 {
281 //Set PDG Code
282   SetPIDprobability(pdg,prob);
283   fPdgIdx = GetPidSlot(pdg);
284 }
285
286 //______________________________________________________________________________
287 void AliAODParticle::SetPIDprobability(Int_t pdg, Float_t prob)
288 {
289 //Sets another pdg code and corresponding probabilty
290 //Ids are set in decreasing order
291 //Check if total probability is not overcoming unity is performed
292 //in case, warning is printed
293   AliDebug(9,Form("SetPIDprobability","Setting PID %d prob %f",pdg,prob));
294
295   Float_t totprob = 0.0;//sums up probabilities
296   Int_t idx = GetPidSlot(pdg);
297   Int_t i;
298
299   if (idx > -1) 
300    {
301      fPidProb[idx] = prob;
302      for (i = 0; i < fNPids;i++) totprob+=fPidProb[i];
303      if (totprob > (1.0+0.000001))
304        {
305          Warning("SetPIDprobability","Total probability greater than unity (%f)",totprob);
306        }
307      AliDebug(9,Form("Current Total probability: %f",totprob));
308      return;
309    }
310     
311   Int_t currentpid = GetPdgCode();
312   fNPids++;
313   Float_t* aPidProbNew = new Float_t[fNPids];
314   Int_t* aPidsNew = new Int_t[fNPids];
315   
316   for (i = 0; i < fNPids-1;i++)//find a slot
317    {
318      if ( fPidProb[i] > prob)
319       {
320         AliDebug(9,Form("Copying entry %d",i));
321         aPidProbNew[i] = fPidProb[i];
322         aPidsNew[i] = fPids[i];
323         totprob+=fPidProb[i];
324       }
325      else break;
326    }
327
328   AliDebug(9,Form("SetPID","Setting new PID on entry %d",i));
329   aPidProbNew[i] = prob;
330   aPidsNew[i] = pdg;
331   totprob+=prob;
332   
333
334   for (Int_t j = fNPids-1; j > i ;j--)//copy rest of old arays 
335    {
336      AliDebug(9,Form("SetPID","Copying from old entry %d to new entry %d",j-1,j));
337      aPidProbNew[j] = fPidProb[j-1];
338      aPidsNew[j] = fPids[j-1];
339      totprob+=fPidProb[j-1];
340    }
341
342   delete [] fPidProb;
343   delete [] fPids;
344   
345   fPidProb = aPidProbNew;
346   fPids = aPidsNew;
347   
348   fPdgIdx = GetPidSlot(currentpid);
349   if (fPdgIdx == -1) fPdgIdx = 0;
350   
351   if (totprob > (1.0+0.000001))//space for numerical error
352    {
353      Warning("SetId","Total probability is greater than unity (%f)!!!",totprob);
354      Print();
355    }
356 }
357 //______________________________________________________________________________
358
359 Float_t AliAODParticle::GetPIDprobability(Int_t pdg) const
360 {
361 //Returns probability that this particle is the type of pdg
362   Int_t idx = GetPidSlot(pdg);
363   if (idx < 0) return 0.0;//such pid was not specified for this particle
364   return fPidProb[idx];
365 }
366 //______________________________________________________________________________
367
368 const Char_t* AliAODParticle::GetName() const 
369 {
370   //returns name of this particle 
371    static char def[4] = "XXX";
372    const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
373    if (ap) return ap->GetName();
374    else    return def;
375 }
376 //______________________________________________________________________________
377
378 Int_t AliAODParticle::GetPidSlot(Int_t pdg) const
379 {
380  //returns position of the given PID in fPids (and fPidProb) array.
381  if (fPids == 0x0) return -1;
382  for (Int_t i = 0; i< fNPids; i++)
383   {
384    if (fPids[i] == pdg) return i;
385   }
386  return -1;
387 }
388 //______________________________________________________________________________
389
390 Int_t AliAODParticle::GetNthPid(Int_t idx) const
391 {
392   //returns PID sitting on slot idx in fPids
393   if ( (idx < 0) || (idx >= fNPids) )
394    {
395      Error("GetNthPid","Out Of Bounds");
396      return 0;
397    }
398   return fPids[idx];
399 }
400 //______________________________________________________________________________
401
402 Float_t AliAODParticle::GetNthPidProb(Int_t idx) const
403 {
404   //returns PID sitting on slot idx in fPidProb
405   if ( (idx < 0) || (idx >= fNPids) )
406    {
407      Error("GetNthPid","Out Of Bounds");
408      return 0;
409    }
410   return fPidProb[idx];
411 }
412 //______________________________________________________________________________
413
414 void AliAODParticle::Print(const Option_t * /*opt*/) const
415 {
416 //prints information about particle
417   printf("____________________________________________________\n");
418   printf("Idx: %d  PID: %d  Name: ",fIdxInEvent,GetPdgCode());
419   TParticlePDG *pdgp = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
420   if (pdgp)
421    {
422      printf("%s Mass: %f\n",pdgp->GetName(),pdgp->Mass());
423    }
424   else
425    {
426      printf("Not known\n");
427    }
428   
429   printf("Px: %+f Py: %+f Pz: %+f E: %+f Calculated Mass: %f\nVx: %+f Vy: %+f Vz: %+f T: %+f\n",
430           Px(),Py(),Pz(),E(),GetCalcMass(),Vx(),Vy(),Vz(),T());
431
432   for (Int_t i = 0; i < fNPids; i++)
433    {
434      printf("# %d  PID: %d  Probability %f name ",i,fPids[i],fPidProb[i]);
435      const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPids[i]);
436      if (ap)
437       {
438         printf("%s Mass %f\n",ap->GetName(),ap->Mass());
439       }
440      else
441       {
442         printf("Not known\n");
443       }
444    }
445   
446   if (fITSTrackPoints) fITSTrackPoints->Print();
447   if (fTPCTrackPoints) fTPCTrackPoints->Print();
448    
449 }
450
451 //______________________________________________________________________________
452
453 //void AliAODParticle::Streamer(TBuffer &b)
454 //{
455 //     // Stream all objects in the array to or from the I/O buffer.
456 //   UInt_t R__s, R__c;
457 //   Int_t i;
458 //   if (b.IsReading()) 
459 //    {
460 //      delete [] fPids;
461 //      delete [] fPidProb;
462 //      
463 //      Version_t v = b.ReadVersion(&R__s, &R__c);
464 //      if (v == 1)
465 //       {
466 //         AliAODParticle::Class()->ReadBuffer(b, this);
467 //      }
468 //      else
469 //       {
470 //        TObject::Streamer(b);
471 //       b >> fPdgIdx;
472 //       b >> fIdxInEvent;
473 //       
474 //       b >> fNPids;
475 //       Int_t* fPids = new Int_t[fNPids];
476 //        Float_t* fPidProb = new Float_t[fNPids];
477 //        for (i = 0;i<fNPids;i++) 
478 //         {
479 //           b >> fPids[i];
480 //         }
481 //        for (i = 0;i<fNPids;i++) 
482 //        {
483 //          b >> fPidProb[i];
484 //         }
485 //        b >> fCalcMass;
486 //
487 //        b >> fPx;
488 //       b >> fPy;
489 //       b >> fPz;
490 //        b >> fE;
491 //
492 //       b >> fVx;
493 //        b >> fVy;
494 //        b >> fVz;
495 //       b >> fVt;
496 //       Info("Streamer","Read data");
497 //        Print();
498 //       }
499 //
500 //      b.CheckByteCount(R__s, R__c,AliAODParticle::IsA());
501 //    } 
502 //  else 
503 //   {
504 //     R__c = b.WriteVersion(AliAODParticle::IsA(), kTRUE);
505 //     TObject::Streamer(b);
506 //     Info("Streamer","Read data");
507 //     Print();
508 //
509 //     b << fPdgIdx;
510 //     b << fIdxInEvent;
511 //     b << fNPids;
512 //     for (i = 0;i<fNPids;i++) 
513 //      {
514 //        b << fPids[i];
515 //      }
516 //      {
517 //      {
518 //     for (i = 0;i<fNPids;i++) 
519 //     {
520 //        b << fPidProb[i];
521 //      }
522 //     b << fCalcMass;
523 //
524 //     b << fPx;
525 //     b << fPy;
526 //     b << fPz;
527 //     b << fE;
528 //
529 //     b << fVx;
530 //     b << fVy;
531 //     b << fVz;
532 //     b << fVt;
533 //
534 //    b.SetByteCount(R__c, kTRUE);
535 //   }
536 //}