]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/EMCAL/AliEmcalParticle.cxx
Make the EMCal trigger 1024 adc bug rejection optional (now *disabled* by default...
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliEmcalParticle.cxx
1 // $Id$
2 //
3 // Emcal particle class, which can contain either an AliVTrack or an AliVCluster
4 //
5 // Author: S.Aiola
6
7 #include "AliEmcalParticle.h"
8 #include "AliVCluster.h"
9 #include "AliLog.h"
10
11 //_________________________________________________________________________________________________
12 AliEmcalParticle::AliEmcalParticle() :
13   AliVParticle(),
14   fTrack(0), 
15   fCluster(0),
16   fNMatched(0),
17   fId(-1),
18   fPhi(0),
19   fEta(0),
20   fPt(0),
21   fMatchedPtr(0)
22 {
23   // Default constructor.
24
25   ResetMatchedObjects();
26 }
27
28 //_________________________________________________________________________________________________
29 AliEmcalParticle::AliEmcalParticle(TObject *particle, Int_t id, Double_t vx, Double_t vy, Double_t vz) :
30   AliVParticle(),
31   fTrack(0), 
32   fCluster(0),
33   fNMatched(0),
34   fId(id),
35   fPhi(0),
36   fEta(0),
37   fPt(0),
38   fMatchedPtr(0)
39 {
40   // Constructor.
41
42   if (!particle) {
43     AliWarning("Null pointer passed as particle.");
44     return;
45   }
46
47   fTrack = dynamic_cast<AliVTrack*>(particle);
48   if (fTrack) {
49     fEta = fTrack->Eta();
50     fPhi = fTrack->Phi();
51     fPt = fTrack->Pt();
52   } else {
53     fCluster = dynamic_cast<AliVCluster*>(particle);
54     if (fCluster) {
55       Double_t vtx[3]; vtx[0]=vx;vtx[1]=vy;vtx[2]=vz;
56       TLorentzVector vect;
57       fCluster->GetMomentum(vect, vtx);
58       fEta = vect.Eta();
59       fPhi = vect.Phi();
60       fPt  = vect.Pt();
61     }
62   }
63
64   if (!fTrack && !fCluster) {
65     AliWarning("Particle type not recognized (not AliVTrack nor AliVCluster).");
66     return;
67   }
68
69   ResetMatchedObjects();
70 }
71   
72 //_________________________________________________________________________________________________
73 AliEmcalParticle::AliEmcalParticle(const AliEmcalParticle &p) :
74   AliVParticle(p),
75   fTrack(p.fTrack),
76   fCluster(p.fCluster), 
77   fNMatched(p.fNMatched),
78   fId(p.fId),
79   fPhi(p.fPhi),
80   fEta(p.fEta),
81   fPt(p.fPt),
82   fMatchedPtr(p.fMatchedPtr)
83 {
84   // Copy constructor.
85
86   ResetMatchedObjects();
87
88   memcpy(fMatchedIds, p.fMatchedIds, sizeof(UShort_t) * fSizeMatched);
89   memcpy(fMatchedDist, p.fMatchedDist, sizeof(Double_t) * fSizeMatched);
90 }
91
92 //_________________________________________________________________________________________________
93 AliEmcalParticle::~AliEmcalParticle()
94 {
95   // Destructor.
96 }
97
98 //_________________________________________________________________________________________________
99 AliEmcalParticle &AliEmcalParticle::operator=(const AliEmcalParticle &p)
100 {
101   // Assignment operator.
102
103   if (this != &p) {
104     fTrack      = p.fTrack;
105     fCluster    = p.fCluster;
106     fNMatched   = p.fNMatched;
107     fId         = p.fId;
108     fPhi        = p.fPhi;
109     fEta        = p.fEta;
110     fPt         = p.fPt;
111     fMatchedPtr = p.fMatchedPtr;
112
113     ResetMatchedObjects();
114     memcpy(fMatchedIds,  p.fMatchedIds,  sizeof(UShort_t) * fSizeMatched);
115     memcpy(fMatchedDist, p.fMatchedDist, sizeof(Double_t) * fSizeMatched);
116   }
117
118   return *this;
119 }
120
121 //_________________________________________________________________________________________________
122 void AliEmcalParticle::ResetMatchedObjects()
123 {
124   // Reset matched objects.
125
126   for (Int_t i = 0; i < fSizeMatched; i++) {
127     fMatchedIds[i] = -1;
128     fMatchedDist[i] = 999;
129   }
130 }
131
132 //_________________________________________________________________________________________________
133 void AliEmcalParticle::AddMatchedObj(Int_t id, Double_t d)
134 {
135   // Add a matched object.
136
137   Int_t i = 0;
138   while (i < fNMatched && d > fMatchedDist[i])
139     ++i;
140   
141   if (i < fNMatched) {
142     memmove(fMatchedIds  + i + 1, fMatchedIds  + i, sizeof(UShort_t) * (fNMatched - i));
143     memmove(fMatchedDist + i + 1, fMatchedDist + i, sizeof(Double_t) * (fNMatched - i));
144   }
145   
146   fMatchedIds[i]  = id;
147   fMatchedDist[i] = d;
148   ++fNMatched;
149
150   if (fNMatched >= fSizeMatched)
151     fNMatched = fSizeMatched - 1;
152 }
153
154 //_________________________________________________________________________________________________
155 TLorentzVector &AliEmcalParticle::GetLorentzVector(const Double_t *vertex) const
156 {
157   // Make a TLorentzVector and return it.
158
159   static TLorentzVector vect;
160
161   if (fTrack) {
162     vect.SetPtEtaPhiM(fTrack->Pt(), fTrack->Eta(), fTrack->Phi(), M());
163   }
164   else if (fCluster && vertex) {
165     fCluster->GetMomentum(vect, const_cast<Double_t*>(vertex));
166   }
167
168   return vect;
169 }