]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AOD/AliAODCaloCluster.cxx
9471da8fa27fe4e283d6672cc31d95d3f3f6efac
[u/mrichter/AliRoot.git] / STEER / AOD / AliAODCaloCluster.cxx
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 //-------------------------------------------------------------------------
19 //     AOD calorimeter cluster class (for PHOS and EMCAL)
20 //     Author: Markus Oldenburg, CERN
21 //-------------------------------------------------------------------------
22
23 #include <TLorentzVector.h>
24 #include "AliAODCaloCluster.h"
25
26 ClassImp(AliAODCaloCluster)
27
28 //______________________________________________________________________________
29 AliAODCaloCluster::AliAODCaloCluster() : 
30   AliAODCluster(),
31   fDistToBadChannel(-999.),
32   fDispersion(-1),
33   fM20(0.),
34   fM02(0.),
35   fEmcCpvDistance(-999.),
36   fTrackDx(-999),
37   fTrackDz(-999),
38   fNExMax(0), 
39   fTOF(0.),
40   fCoreEnergy(0.),
41   fTracksMatched(),
42   fNCells(0),
43   fCellsAbsId(0x0),
44   fCellsAmpFraction(0x0)
45 {
46   // default constructor
47
48 }
49
50 //______________________________________________________________________________
51 AliAODCaloCluster::AliAODCaloCluster(Int_t id,
52                                      UInt_t nLabel,
53                                      Int_t *label, 
54                                      Double_t energy,
55                                      Double_t x[3],
56                                      Double_t pid[13],
57                                      Char_t ttype,
58                                      UInt_t selectInfo) :
59   AliAODCluster(id, nLabel, label, energy, x, pid, ttype, selectInfo),
60   fDistToBadChannel(-999.),
61   fDispersion(-1),
62   fM20(0.),
63   fM02(0.),
64   fEmcCpvDistance(-999.),
65   fTrackDx(-999),
66   fTrackDz(-999),
67   fNExMax(0),
68   fTOF(0.),
69   fCoreEnergy(0.),
70   fTracksMatched(),
71   fNCells(0),
72   fCellsAbsId(0x0),
73   fCellsAmpFraction(0x0)
74 {
75   // constructor
76
77 }
78
79 //______________________________________________________________________________
80 AliAODCaloCluster::AliAODCaloCluster(Int_t id,
81                                      UInt_t nLabel,
82                                      Int_t *label, 
83                                      Float_t energy,
84                                      Float_t x[3],
85                                      Float_t pid[13],
86                                      Char_t ttype,
87                                      UInt_t selectInfo) :
88   AliAODCluster(id, nLabel, label, energy, x, pid, ttype, selectInfo),
89   fDistToBadChannel(-999.),
90   fDispersion(-1),
91   fM20(0.),
92   fM02(0.),
93   fEmcCpvDistance(-999.),
94   fTrackDx(-999),
95   fTrackDz(-999),
96   fNExMax(0),
97   fTOF(0.),
98   fCoreEnergy(0.),
99   fTracksMatched(),
100   fNCells(0),
101   fCellsAbsId(0x0),
102   fCellsAmpFraction(0x0)
103 {
104   // constructor
105 }
106
107
108 //______________________________________________________________________________
109 AliAODCaloCluster::~AliAODCaloCluster() 
110 {
111   // destructor
112   if(fCellsAmpFraction) delete[] fCellsAmpFraction; fCellsAmpFraction=0;
113   if(fCellsAbsId)       delete[] fCellsAbsId;       fCellsAbsId = 0;
114 }
115
116 //______________________________________________________________________________
117 void AliAODCaloCluster::Clear(const Option_t*) 
118 {
119   // clear
120   RemoveLabel();
121   if(fCellsAmpFraction) delete[] fCellsAmpFraction; fCellsAmpFraction=0;
122   if(fCellsAbsId)       delete[] fCellsAbsId;       fCellsAbsId = 0;
123 }
124
125 //______________________________________________________________________________
126 AliAODCaloCluster::AliAODCaloCluster(const AliAODCaloCluster& clus) :
127   AliAODCluster(clus),
128   fDistToBadChannel(clus.fDistToBadChannel),
129   fDispersion(clus.fDispersion),
130   fM20(clus.fM20),
131   fM02(clus.fM02),
132   fEmcCpvDistance(clus.fEmcCpvDistance),
133   fTrackDx(clus.fTrackDx),
134   fTrackDz(clus.fTrackDz),
135   fNExMax(clus.fNExMax),
136   fTOF(clus.fTOF),
137   fCoreEnergy(clus.fCoreEnergy),
138   fTracksMatched(clus.fTracksMatched),
139   fNCells(clus.fNCells),
140   fCellsAbsId(0x0),
141   fCellsAmpFraction(0x0)
142 {
143   // Copy constructor
144
145   if (clus.fNCells > 0) {
146     
147     if(clus.fCellsAbsId){
148       fCellsAbsId = new UShort_t[clus.fNCells];
149       for (Int_t i=0; i<clus.fNCells; i++)
150         fCellsAbsId[i]=clus.fCellsAbsId[i];
151     }
152     
153     if(clus.fCellsAmpFraction){
154       fCellsAmpFraction = new Double32_t[clus.fNCells];
155       for (Int_t i=0; i<clus.fNCells; i++)
156         fCellsAmpFraction[i]=clus.fCellsAmpFraction[i];
157     }
158     
159   }
160   
161 }
162
163 //______________________________________________________________________________
164 AliAODCaloCluster& AliAODCaloCluster::operator=(const AliAODCaloCluster& clus)
165 {
166   // Assignment operator
167   if(this!=&clus) {
168
169     AliAODCluster::operator=(clus);
170
171     fDistToBadChannel = clus.fDistToBadChannel;
172     fDispersion = clus.fDispersion;
173     fM20 = clus.fM20;
174     fM02 = clus.fM02;
175     fEmcCpvDistance = clus.fEmcCpvDistance;
176     fTrackDx=clus.fTrackDx;
177     fTrackDz=clus.fTrackDz;
178     fNExMax = clus.fNExMax;
179     fTOF = clus.fTOF;
180     fCoreEnergy = clus.fCoreEnergy;
181     fTracksMatched = clus.fTracksMatched;
182
183     fNCells= clus. fNCells;
184     // delete anyway 
185     if(fCellsAbsId)delete [] fCellsAbsId;
186     if(fCellsAmpFraction)delete [] fCellsAmpFraction;
187
188     if (clus.fNCells > 0) {
189       
190       if(clus.fCellsAbsId){
191         fCellsAbsId = new UShort_t[clus.fNCells];
192         for (Int_t i=0; i<clus.fNCells; i++)
193           fCellsAbsId[i]=clus.fCellsAbsId[i];
194       }
195       
196       if(clus.fCellsAmpFraction){
197         fCellsAmpFraction = new Double32_t[clus.fNCells];
198         for (Int_t i=0; i<clus.fNCells; i++)
199           fCellsAmpFraction[i]=clus.fCellsAmpFraction[i];
200       }
201       
202     }
203
204   }
205
206   return *this;
207 }
208
209 //_______________________________________________________________________
210 Bool_t AliAODCaloCluster::HasTrackMatched(TObject *trk) const
211 {
212   // Checks if the given track contributed to this cluster.
213
214   TRefArrayIter iter(&fTracksMatched);
215   while (TObject *track = iter.Next()) {
216     if (trk == track) return kTRUE;
217   }
218   return kFALSE;
219 }
220
221 //_______________________________________________________________________
222 void AliAODCaloCluster::GetMomentum(TLorentzVector& p, Double_t *vertex ) const {
223   // Returns TLorentzVector with momentum of the cluster. Only valid for clusters 
224   // identified as photons or pi0 (overlapped gamma) produced on the vertex
225   //Vertex can be recovered with esd pointer doing:  
226   //" Double_t vertex[3] ; esd->GetVertex()->GetXYZ(vertex) ; "
227
228   Double32_t energy = E();
229   Float_t    pos[3];
230   GetPosition(pos);
231   
232   if(vertex){//calculate direction from vertex
233     pos[0]-=vertex[0];
234     pos[1]-=vertex[1];
235     pos[2]-=vertex[2];
236   }
237   
238   Double_t r = TMath::Sqrt(pos[0]*pos[0]+
239                            pos[1]*pos[1]+
240                            pos[2]*pos[2]   ) ; 
241   
242   p.SetPxPyPzE( energy*pos[0]/r,  energy*pos[1]/r,  energy*pos[2]/r,  energy) ; 
243   
244 }
245
246
247 void  AliAODCaloCluster::SetCellsAbsId(UShort_t *array)
248 {
249     //  Set the array of cell absId numbers 
250     if (fNCells) {
251       if(!fCellsAbsId)fCellsAbsId = new  UShort_t[fNCells];
252       for (Int_t i = 0; i < fNCells; i++) fCellsAbsId[i] = array[i];
253     }
254 }
255
256 void  AliAODCaloCluster::SetCellsAmplitudeFraction(Double32_t *array)
257 {
258     //  Set the array of cell amplitude fraction
259     if (fNCells) {
260       if(!fCellsAmpFraction)fCellsAmpFraction = new  Double32_t[fNCells];
261       for (Int_t i = 0; i < fNCells; i++) fCellsAmpFraction[i] = array[i];
262     }
263 }