]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODCluster.cxx
Fixing CONSTANT_EXPRESSION_RESULT Coverity defect
[u/mrichter/AliRoot.git] / STEER / AliAODCluster.cxx
CommitLineData
df9db588 1/**************************************************************************
2 * Copyright(c) 1998-2007, 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//-------------------------------------------------------------------------
a9255000 19// AOD cluster base class
df9db588 20// Author: Markus Oldenburg, CERN
21//-------------------------------------------------------------------------
22
a9255000 23#include "AliAODCluster.h"
df9db588 24
a9255000 25ClassImp(AliAODCluster)
df9db588 26
27//______________________________________________________________________________
c8fe2783 28AliAODCluster::AliAODCluster() :
29 AliVCluster(),
df9db588 30 fEnergy(0),
31 fChi2(-999.),
32 fID(-999),
4cfedff1 33 fNLabel(0),
34 fLabel(0x0),
35 fFilterMap(0),
36 fType(kUndef)
df9db588 37{
38 // default constructor
39
c8fe2783 40 SetPosition(NULL);
41 SetPID(NULL);
df9db588 42}
43
44//______________________________________________________________________________
a9255000 45AliAODCluster::AliAODCluster(Int_t id,
4cfedff1 46 UInt_t nLabel,
47 Int_t *label,
df9db588 48 Double_t energy,
49 Double_t x[3],
83dd7da3 50 Double_t pid[13],
4cfedff1 51 Char_t ttype,
52 UInt_t selectInfo) :
c8fe2783 53 AliVCluster(),
df9db588 54 fEnergy(energy),
55 fChi2(-999.),
56 fID(id),
4cfedff1 57 fNLabel(0),
58 fLabel(0x0),
59 fFilterMap(selectInfo),
60 fType(ttype)
df9db588 61{
62 // constructor
63
c8fe2783 64 if(x) {for (Int_t i = 0; i < 3 ; i++) SetPositionAt(x[i] ,i);}
65 if(pid) {for (Int_t i = 0; i < 13 ; i++) SetPIDAt (pid[i],i);}
4cfedff1 66 SetLabel(label, nLabel);
df9db588 67}
68
69//______________________________________________________________________________
a9255000 70AliAODCluster::AliAODCluster(Int_t id,
4cfedff1 71 UInt_t nLabel,
72 Int_t *label,
df9db588 73 Float_t energy,
74 Float_t x[3],
83dd7da3 75 Float_t pid[13],
4cfedff1 76 Char_t ttype,
77 UInt_t selectInfo) :
c8fe2783 78 AliVCluster(),
df9db588 79 fEnergy(energy),
80 fChi2(-999.),
81 fID(id),
4cfedff1 82 fNLabel(0),
83 fLabel(0x0),
84 fFilterMap(selectInfo),
85 fType(ttype)
df9db588 86{
87 // constructor
c8fe2783 88 if(x) {for (Int_t i = 0; i < 3 ; i++) SetPositionAt(x[i] ,i);}
89 if(pid) {for (Int_t i = 0; i < 13 ; i++) SetPIDAt (pid[i],i);}
4cfedff1 90 SetLabel(label, nLabel);
df9db588 91}
92
93
94//______________________________________________________________________________
a9255000 95AliAODCluster::~AliAODCluster()
df9db588 96{
97 // destructor
4cfedff1 98
99 RemoveLabel();
df9db588 100}
101
102
103//______________________________________________________________________________
14d55e62 104AliAODCluster::AliAODCluster(const AliAODCluster& clus) :
c8fe2783 105 AliVCluster(clus),
14d55e62 106 fEnergy(clus.fEnergy),
107 fChi2(clus.fChi2),
108 fID(clus.fID),
4cfedff1 109 fNLabel(0),
110 fLabel(0x0),
111 fFilterMap(clus.fFilterMap),
112 fType(clus.fType)
df9db588 113{
114 // Copy constructor
115
c8fe2783 116 if(fPosition) {for(Int_t i = 0; i < 3 ; i++) fPosition[i] = clus.fPosition[i];}
117 if(fPID) {for(Int_t i = 0; i < 13 ; i++) fPID[i] = clus.fPID[i];}
118
4cfedff1 119 SetLabel(clus.fLabel, clus.fNLabel);
df9db588 120}
121
122//______________________________________________________________________________
14d55e62 123AliAODCluster& AliAODCluster::operator=(const AliAODCluster& clus)
df9db588 124{
125 // Assignment operator
14d55e62 126 if(this!=&clus) {
c8fe2783 127
128 if(fPosition) {for(Int_t i = 0; i < 3 ; i++) fPosition[i] = clus.fPosition[i];}
129 if(fPID) {for(Int_t i = 0; i < 13 ; i++) fPID[i] = clus.fPID[i];}
130
14d55e62 131 fEnergy = clus.fEnergy;
132 fChi2 = clus.fChi2;
df9db588 133
14d55e62 134 fID = clus.fID;
4cfedff1 135 SetLabel(clus.fLabel, clus.fNLabel);
136 fFilterMap = clus.fFilterMap;
9333290e 137
138 fType = clus.fType;
df9db588 139 }
140
141 return *this;
142}
143
144//______________________________________________________________________________
c8fe2783 145void AliAODCluster::SetPosition(Float_t *x)
df9db588 146{
147 // set the position
c8fe2783 148
df9db588 149 if (x) {
c8fe2783 150 fPosition[0] = x[0];
151 fPosition[1] = x[1];
152 fPosition[2] = x[2];
df9db588 153 } else {
df9db588 154 fPosition[0] = -999.;
155 fPosition[1] = -999.;
156 fPosition[2] = -999.;
157 }
158}
159
14d55e62 160//______________________________________________________________________________
c8fe2783 161UShort_t AliAODCluster::GetMostProbablePID() const
14d55e62 162{
163 // Returns the most probable PID array element.
164
83dd7da3 165 Int_t nPID = 13;
c8fe2783 166 UShort_t unknown = AliVCluster::kUnknown;
167
14d55e62 168 if (fPID) {
c8fe2783 169 UShort_t loc = unknown;
14d55e62 170 Double_t max = 0.;
171 Bool_t allTheSame = kTRUE;
172
173 for (Int_t iPID = 0; iPID < nPID; iPID++) {
174 if (fPID[iPID] >= max) {
c8fe2783 175 if (fPID[iPID] > max) {
176 allTheSame = kFALSE;
177 max = fPID[iPID];
178 loc = (UShort_t)iPID;
179 } else {
180 allTheSame = kTRUE;
181 }
14d55e62 182 }
183 }
184
c8fe2783 185 return allTheSame ? unknown : loc;
14d55e62 186 } else {
c8fe2783 187 return unknown;
14d55e62 188 }
189}
190
4cfedff1 191//______________________________________________________________________________
192void AliAODCluster::SetLabel(Int_t *label, UInt_t size)
193{
194 if (label && size>0) {
195 if (size != (UInt_t)fNLabel) {
196 RemoveLabel();
197 fNLabel = size;
198 fLabel = new Int_t[fNLabel];
199 }
200
201 for (Int_t i = 0; i < fNLabel; i++) {
202 fLabel[i] = label[i];
203 }
204 } else {
205 RemoveLabel();
206 }
207
208 return;
209}
210
211//______________________________________________________________________________
c8fe2783 212Int_t AliAODCluster::GetLabelAt(UInt_t i) const
4cfedff1 213{
214 if (fLabel && i < (UInt_t)fNLabel) {
215 return fLabel[i];
216 } else {
217 return -999;
218 }
219}
220
221//______________________________________________________________________________
222void AliAODCluster::RemoveLabel()
223{
224 delete[] fLabel;
225 fLabel = 0x0;
226 fNLabel = 0;
227
228 return;
229}
230
df9db588 231//______________________________________________________________________________
a9255000 232void AliAODCluster::Print(Option_t* /* option */) const
df9db588 233{
a9255000 234 // prints information about AliAODCluster
df9db588 235
4cfedff1 236 printf("Cluster type: %d\n", GetType());
237 printf(" energy = %f\n", E());
238 printf(" chi2 = %f\n", Chi2());
c8fe2783 239 const Double_t *pid = GetPID();
240 printf("PID weights: photon %0.2f, pi0 %0.2f, electron %0.2f, conversion electron %0.2f\n, hadrons: pion %0.2f, kaon %0.2f, proton %0.2f , neutron %0.2f, kaon %0.2f \n",
241 pid[AliVCluster::kPhoton], pid[AliVCluster::kPi0],
242 pid[AliVCluster::kElectron], pid[AliVCluster::kEleCon],
243 pid[AliVCluster::kPion], pid[AliVCluster::kKaon], pid[AliVCluster::kProton],
244 pid[AliVCluster::kNeutron], pid[AliVCluster::kKaon0]);
df9db588 245}