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