]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGGA/EMCALTasks/AliEmcalParticle.cxx
make an emcal part (can be track/cluster) and holds other clusters/tracks in vicinity
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliEmcalParticle.cxx
CommitLineData
d11dc2a6 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//_________________________________________________________________________________________________
12AliEmcalParticle::AliEmcalParticle() :
13 TObject(),
14 fTrack(0),
15 fCluster(0),
16 fNMatched(0),
17 fId(-1)
18{
19 // Default constructor.
20
21 ResetMatchedObjects();
22}
23
24//_________________________________________________________________________________________________
25AliEmcalParticle::AliEmcalParticle(TObject *particle, Int_t id) :
26 TObject(),
27 fTrack(0),
28 fCluster(0),
29 fNMatched(0),
30 fId(id)
31{
32 // Constructor.
33
34 if (!particle)
35 AliWarning("Null pointer passed as particle.");
36
37
38 fTrack = dynamic_cast<AliVTrack*>(particle);
39 if (!fTrack)
40 fCluster = dynamic_cast<AliVCluster*>(particle);
41
42 if (!fTrack && !fCluster)
43 AliWarning("Particle type not recognized (not AliVTrack nor AliVCluster).");
44
45 ResetMatchedObjects();
46}
47
48//_________________________________________________________________________________________________
49AliEmcalParticle::AliEmcalParticle(const AliEmcalParticle &p) :
50 TObject(),
51 fTrack(p.fTrack),
52 fCluster(p.fCluster),
53 fNMatched(p.fNMatched),
54 fId(p.fId)
55{
56 // Copy constructor.
57
58 ResetMatchedObjects();
59
60 memcpy(fMatchedIds, p.fMatchedIds, sizeof(UShort_t) * fSizeMatched);
61 memcpy(fMatchedDist, p.fMatchedDist, sizeof(Double_t) * fSizeMatched);
62}
63
64//_________________________________________________________________________________________________
65AliEmcalParticle::~AliEmcalParticle()
66{
67 // Destructor.
68}
69
70//_________________________________________________________________________________________________
71AliEmcalParticle &AliEmcalParticle::operator=(const AliEmcalParticle &p)
72{
73 // Assignment operator.
74
75 if (this != &p) {
76 fTrack = p.fTrack;
77 fCluster = p.fCluster;
78 fNMatched = p.fNMatched;
79
80 ResetMatchedObjects();
81
82 memcpy(fMatchedIds, p.fMatchedIds, sizeof(UShort_t) * fSizeMatched);
83 memcpy(fMatchedDist, p.fMatchedDist, sizeof(Double_t) * fSizeMatched);
84 }
85
86 return *this;
87}
88
89//_________________________________________________________________________________________________
90void AliEmcalParticle::ResetMatchedObjects()
91{
92 // Reset matched objects.
93
94 for (Int_t i = 0; i < fSizeMatched; i++) {
95 fMatchedIds[i] = -1;
96 fMatchedDist[i] = 999;
97 }
98}
99
100//_________________________________________________________________________________________________
101void AliEmcalParticle::AddMatchedObj(Int_t id, Double_t d)
102{
103 // Add a matched object.
104
105 Int_t i = 0;
106 while (i < fNMatched && d > fMatchedDist[i])
107 i++;
108
109 if (i < fNMatched) {
110 memmove(fMatchedIds + i + 1, fMatchedIds + i, sizeof(UShort_t) * (fNMatched - i));
111 memmove(fMatchedDist + i + 1, fMatchedDist + i, sizeof(Double_t) * (fNMatched - i));
112 }
113
114 fMatchedIds[i] = id;
115 fMatchedDist[i] = d;
116 fNMatched++;
117
118 if (fNMatched >= fSizeMatched)
119 fNMatched = fSizeMatched - 1;
120}
121
122//_________________________________________________________________________________________________
123TLorentzVector &AliEmcalParticle::GetLorentzVector(const Double_t *vertex) const
124{
125 // Make a TLorentzVector and return it.
126
127 static TLorentzVector vect;
128
129 if (fTrack) {
130 vect.SetPtEtaPhiM(fTrack->Pt(), fTrack->Eta(), fTrack->Phi(), M());
131 }
132 else if (fCluster && vertex) {
133 fCluster->GetMomentum(vect, const_cast<Double_t*>(vertex));
134 }
135
136 return vect;
137}