Bug fix in the constructor (thanks to A.Marin)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALRecPoint.cxx
CommitLineData
ab48128d 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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/* $Id$ */
16//_________________________________________________________________________
70a93198 17// Reconstructed Points for the EMCAL
18// A RecPoint is a cluster of digits
40164976 19//
20//
d64c959b 21//*-- Author: Yves Schutz (SUBATECH)
70a93198 22//*-- Author: Dmitri Peressounko (RRC KI & SUBATECH)
23//*-- Author: Heather Gray (LBL) merged AliEMCALRecPoint and AliEMCALTowerRecPoint 02/04
ab48128d 24
25// --- ROOT system ---
9aa6a5f6 26#include "TPad.h"
27#include "TGraph.h"
28#include "TPaveText.h"
29#include "TClonesArray.h"
30#include "TMath.h"
31#include "TGeoMatrix.h"
32#include "TGeoManager.h"
33#include "TGeoPhysicalNode.h"
25bb3dcb 34#include "TRandom.h"
ab48128d 35
36// --- Standard library ---
9aa6a5f6 37#include <Riostream.h>
ab48128d 38
39// --- AliRoot header files ---
1d59832c 40//#include "AliGenerator.h"
41class AliGenerator;
1d59832c 42class AliEMCAL;
9aa6a5f6 43#include "AliLog.h"
44#include "AliGeomManager.h"
ab48128d 45#include "AliEMCALGeometry.h"
4635df1f 46#include "AliEMCALHit.h"
ab48128d 47#include "AliEMCALDigit.h"
48#include "AliEMCALRecPoint.h"
40164976 49#include "AliCaloCalibPedestal.h"
50#include "AliEMCALGeoParams.h"
ab48128d 51
52ClassImp(AliEMCALRecPoint)
53
ab48128d 54//____________________________________________________________________________
55AliEMCALRecPoint::AliEMCALRecPoint()
9aa6a5f6 56 : AliCluster(), fGeomPtr(0),
57 fAmp(0), fIndexInList(-1), //to be set when the point is already stored
25bb3dcb 58 fGlobPos(0,0,0),fLocPos(0,0,0),
9aa6a5f6 59 fMaxDigit(100), fMulDigit(0), fMaxTrack(200),
60 fMulTrack(0), fDigitsList(0), fTracksList(0),
61 fClusterType(-1), fCoreEnergy(0), fDispersion(0),
62 fEnergyList(0), fTimeList(0), fAbsIdList(0),
0561e246 63 fTime(0.), fNExMax(0), fCoreRadius(10), //HG check this
9aa6a5f6 64 fDETracksList(0), fMulParent(0), fMaxParent(0),
65 fParentsList(0), fDEParentsList(0), fSuperModuleNumber(0),
25bb3dcb 66 fDigitIndMax(-1), fDistToBadTower(-1), fSharedCluster(kFALSE)
ab48128d 67{
68 // ctor
9aa6a5f6 69 fGeomPtr = AliEMCALGeometry::GetInstance();
70
706863b6 71 fLambda[0] = 0;
72 fLambda[1] = 0;
9aa6a5f6 73
ab48128d 74}
75
76//____________________________________________________________________________
9aa6a5f6 77AliEMCALRecPoint::AliEMCALRecPoint(const char *)
78 : AliCluster(), fGeomPtr(0),
79 fAmp(0), fIndexInList(-1), //to be set when the point is already stored
25bb3dcb 80 fGlobPos(0,0,0), fLocPos(0,0,0),
9aa6a5f6 81 fMaxDigit(100), fMulDigit(0), fMaxTrack(1000), fMulTrack(0),
82 fDigitsList(new Int_t[fMaxDigit]), fTracksList(new Int_t[fMaxTrack]),
83 fClusterType(-1), fCoreEnergy(0), fDispersion(0),
84 fEnergyList(new Float_t[fMaxDigit]), fTimeList(new Float_t[fMaxDigit]),
0561e246 85 fAbsIdList(new Int_t[fMaxDigit]), fTime(-1.), fNExMax(0), fCoreRadius(10),
9aa6a5f6 86 fDETracksList(new Float_t[fMaxTrack]), fMulParent(0), fMaxParent(1000),
87 fParentsList(new Int_t[fMaxParent]), fDEParentsList(new Float_t[fMaxParent]),
25bb3dcb 88 fSuperModuleNumber(0), fDigitIndMax(-1), fDistToBadTower(-1),fSharedCluster(kFALSE)
ab48128d 89{
90 // ctor
af5bdd85 91 for (Int_t i = 0; i < fMaxTrack; i++)
92 fDETracksList[i] = 0;
94478418 93 for (Int_t i = 0; i < fMaxParent; i++) {
94 fParentsList[i] = -1;
af5bdd85 95 fDEParentsList[i] = 0;
94478418 96 }
18a21c7c 97
9aa6a5f6 98 fGeomPtr = AliEMCALGeometry::GetInstance();
706863b6 99 fLambda[0] = 0;
100 fLambda[1] = 0;
70a93198 101}
18a21c7c 102
70a93198 103//____________________________________________________________________________
18a21c7c 104AliEMCALRecPoint::AliEMCALRecPoint(const AliEMCALRecPoint & rp)
9aa6a5f6 105 : AliCluster(rp), fGeomPtr(rp.fGeomPtr),
106 fAmp(rp.fAmp), fIndexInList(rp.fIndexInList),
25bb3dcb 107 fGlobPos(rp.fGlobPos),fLocPos(rp.fLocPos),
9aa6a5f6 108 fMaxDigit(rp.fMaxDigit), fMulDigit(rp.fMulDigit),
109 fMaxTrack(rp.fMaxTrack), fMulTrack(rp.fMaxTrack),
110 fDigitsList(new Int_t[rp.fMaxDigit]), fTracksList(new Int_t[rp.fMaxTrack]),
111 fClusterType(rp.fClusterType), fCoreEnergy(rp.fCoreEnergy),
18a21c7c 112 fDispersion(rp.fDispersion),
9aa6a5f6 113 fEnergyList(new Float_t[rp.fMaxDigit]), fTimeList(new Float_t[rp.fMaxDigit]),
0561e246 114 fAbsIdList(new Int_t[rp.fMaxDigit]), fTime(rp.fTime), fNExMax(rp.fNExMax),fCoreRadius(rp.fCoreRadius),
9aa6a5f6 115 fDETracksList(new Float_t[rp.fMaxTrack]), fMulParent(rp.fMulParent),
116 fMaxParent(rp.fMaxParent), fParentsList(new Int_t[rp.fMaxParent]),
117 fDEParentsList(new Float_t[rp.fMaxParent]),
40164976 118 fSuperModuleNumber(rp.fSuperModuleNumber), fDigitIndMax(rp.fDigitIndMax),
25bb3dcb 119 fDistToBadTower(rp.fDistToBadTower), fSharedCluster(rp.fSharedCluster)
0a4cb131 120{
121 //copy ctor
0a4cb131 122 fLambda[0] = rp.fLambda[0];
123 fLambda[1] = rp.fLambda[1];
18a21c7c 124
0a4cb131 125 for(Int_t i = 0; i < rp.fMulDigit; i++) {
126 fEnergyList[i] = rp.fEnergyList[i];
127 fTimeList[i] = rp.fTimeList[i];
128 fAbsIdList[i] = rp.fAbsIdList[i];
129 }
9aa6a5f6 130
af5bdd85 131 for(Int_t i = 0; i < rp.fMulTrack; i++) fDETracksList[i] = rp.fDETracksList[i];
9aa6a5f6 132
133 for(Int_t i = 0; i < rp.fMulParent; i++) {
134 fParentsList[i] = rp.fParentsList[i];
135 fDEParentsList[i] = rp.fDEParentsList[i];
136 }
0a4cb131 137
138}
139//____________________________________________________________________________
70a93198 140AliEMCALRecPoint::~AliEMCALRecPoint()
141{
142 // dtor
143 if ( fEnergyList )
144 delete[] fEnergyList ;
85c60a8e 145 if ( fTimeList )
146 delete[] fTimeList ;
e52475ed 147 if ( fAbsIdList )
148 delete[] fAbsIdList ;
af5bdd85 149 if ( fDETracksList)
150 delete[] fDETracksList;
87cdc3be 151 if ( fParentsList)
152 delete[] fParentsList;
af5bdd85 153 if ( fDEParentsList)
154 delete[] fDEParentsList;
25bb3dcb 155
9aa6a5f6 156 delete [] fDigitsList ;
157 delete [] fTracksList ;
158}
159
160//____________________________________________________________________________
161AliEMCALRecPoint& AliEMCALRecPoint::operator= (const AliEMCALRecPoint &rp)
162{
37890aaf 163 // assignment operator
164
9aa6a5f6 165 if(&rp == this) return *this;
166
167 fGeomPtr = rp.fGeomPtr;
168 fAmp = rp.fAmp;
169 fIndexInList = rp.fIndexInList;
25bb3dcb 170 fGlobPos = rp.fGlobPos;
171 fLocPos = rp.fLocPos;
9aa6a5f6 172 fMaxDigit = rp.fMaxDigit;
173 fMulDigit = rp.fMulDigit;
174 fMaxTrack = rp.fMaxTrack;
175 fMulTrack = rp.fMaxTrack;
176 for(Int_t i = 0; i<fMaxDigit; i++) fDigitsList[i] = rp.fDigitsList[i];
177 for(Int_t i = 0; i<fMaxTrack; i++) fTracksList[i] = rp.fTracksList[i];
178 fClusterType = rp.fClusterType;
6ce4e2ed 179 fCoreEnergy = rp.fCoreEnergy;
180 fDispersion = rp.fDispersion;
9aa6a5f6 181 for(Int_t i = 0; i<fMaxDigit; i++) {
182 fEnergyList[i] = rp.fEnergyList[i];
6ce4e2ed 183 fTimeList[i] = rp.fTimeList[i];
184 fAbsIdList[i] = rp.fAbsIdList[i];
9aa6a5f6 185 }
186 fTime = rp.fTime;
0561e246 187 fNExMax = rp.fNExMax;
9aa6a5f6 188 fCoreRadius = rp.fCoreRadius;
189 for(Int_t i = 0; i < fMaxTrack; i++) fDETracksList[i] = rp.fDETracksList[i];
190 fMulParent = rp.fMulParent;
191 fMaxParent = rp.fMaxParent;
192 for(Int_t i = 0; i < fMaxParent; i++) {
193 fParentsList[i] = rp.fParentsList[i];
194 fDEParentsList[i] = rp.fDEParentsList[i];
195 }
196 fSuperModuleNumber = rp.fSuperModuleNumber;
197 fDigitIndMax = rp.fDigitIndMax;
198
199 fLambda[0] = rp.fLambda[0];
200 fLambda[1] = rp.fLambda[1];
40164976 201
202 fDistToBadTower = rp.fDistToBadTower;
25bb3dcb 203 fSharedCluster = rp.fSharedCluster;
40164976 204
9aa6a5f6 205 return *this;
206
70a93198 207}
208
209//____________________________________________________________________________
783153ff 210void AliEMCALRecPoint::AddDigit(AliEMCALDigit & digit, const Float_t energy, const Bool_t shared)
70a93198 211{
212 // Adds a digit to the RecPoint
213 // and accumulates the total amplitude and the multiplicity
214
215 if(fEnergyList == 0)
216 fEnergyList = new Float_t[fMaxDigit];
85c60a8e 217 if(fTimeList == 0)
783153ff 218 fTimeList = new Float_t[fMaxDigit];
e52475ed 219 if(fAbsIdList == 0) {
783153ff 220 fAbsIdList = new Int_t [fMaxDigit];
e52475ed 221 }
70a93198 222
223 if ( fMulDigit >= fMaxDigit ) { // increase the size of the lists
224 fMaxDigit*=2 ;
783153ff 225 Int_t * tempo = new Int_t [fMaxDigit];
6ce4e2ed 226 Float_t * tempoE = new Float_t[fMaxDigit];
227 Float_t * tempoT = new Float_t[fMaxDigit];
783153ff 228 Int_t * tempoId = new Int_t [fMaxDigit];
70a93198 229
230 Int_t index ;
231 for ( index = 0 ; index < fMulDigit ; index++ ){
783153ff 232 tempo [index] = fDigitsList[index] ;
233 tempoE [index] = fEnergyList[index] ;
234 tempoT [index] = fTimeList [index] ;
235 tempoId[index] = fAbsIdList [index] ;
70a93198 236 }
237
94478418 238 delete [] fDigitsList ;
70a93198 239 delete [] fEnergyList ;
85c60a8e 240 delete [] fTimeList ;
e52475ed 241 delete [] fAbsIdList ;
e52475ed 242
94478418 243 fDigitsList = tempo;
244 fEnergyList = tempoE;
6ce4e2ed 245 fTimeList = tempoT;
246 fAbsIdList = tempoId;
70a93198 247 } // if
248
249 fDigitsList[fMulDigit] = digit.GetIndexInList() ;
6ce4e2ed 250 fEnergyList[fMulDigit] = energy ;
783153ff 251 fTimeList [fMulDigit] = digit.GetTime();
252 fAbsIdList [fMulDigit] = digit.GetId();
70a93198 253 fMulDigit++ ;
6ce4e2ed 254 fAmp += energy ;
25bb3dcb 255
256 if(shared) fSharedCluster = kTRUE;
70a93198 257}
258//____________________________________________________________________________
259Bool_t AliEMCALRecPoint::AreNeighbours(AliEMCALDigit * digit1, AliEMCALDigit * digit2 ) const
260{
261 // Tells if (true) or not (false) two digits are neighbours
262 // A neighbour is defined as being two digits which share a corner
25bb3dcb 263 // ONLY USED IN CASE OF UNFOLDING
264
47583f1b 265 Bool_t areNeighbours = kFALSE ;
266 Int_t nSupMod=0, nModule=0, nIphi=0, nIeta=0;
267 Int_t nSupMod1=0, nModule1=0, nIphi1=0, nIeta1=0;
268 Int_t relid1[2] , relid2[2] ; // ieta, iphi
269 Int_t rowdiff=0, coldiff=0;
70a93198 270
e52475ed 271 areNeighbours = kFALSE ;
272
2bb3725c 273 fGeomPtr->GetCellIndex(digit1->GetId(), nSupMod,nModule,nIphi,nIeta);
274 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, relid1[0],relid1[1]);
e52475ed 275
2bb3725c 276 fGeomPtr->GetCellIndex(digit2->GetId(), nSupMod1,nModule1,nIphi1,nIeta1);
277 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod1,nModule1,nIphi1,nIeta1, relid2[0],relid2[1]);
70a93198 278
25bb3dcb 279 // In case of a shared cluster, index of SM in C side, columns start at 48 and ends at 48*2-1
280 // C Side impair SM, nSupMod%2=1; A side pair SM nSupMod%2=0
281 if(fSharedCluster){
282 if(nSupMod1%2) relid1[1]+=AliEMCALGeoParams::fgkEMCALCols;
283 else relid2[1]+=AliEMCALGeoParams::fgkEMCALCols;
284 }
285
e52475ed 286 rowdiff = TMath::Abs( relid1[0] - relid2[0] ) ;
287 coldiff = TMath::Abs( relid1[1] - relid2[1] ) ;
70a93198 288
289 if (( coldiff <= 1 ) && ( rowdiff <= 1 ) && (coldiff + rowdiff > 0))
e52475ed 290 areNeighbours = kTRUE ;
ab48128d 291
70a93198 292 return areNeighbours;
293}
294
295//____________________________________________________________________________
296Int_t AliEMCALRecPoint::Compare(const TObject * obj) const
297{
298 // Compares two RecPoints according to their position in the EMCAL modules
299
25bb3dcb 300 Float_t delta = 1 ; //Width of "Sorting row".
301
53e430a3 302 Int_t rv = 2 ;
70a93198 303
304 AliEMCALRecPoint * clu = (AliEMCALRecPoint *)obj ;
305
306 TVector3 locpos1;
307 GetLocalPosition(locpos1);
308 TVector3 locpos2;
309 clu->GetLocalPosition(locpos2);
310
9848d950 311 Int_t rowdif = (Int_t)(TMath::Ceil(locpos1.X()/delta)-TMath::Ceil(locpos2.X()/delta)) ;
70a93198 312 if (rowdif> 0)
313 rv = 1 ;
314 else if(rowdif < 0)
315 rv = -1 ;
316 else if(locpos1.Y()>locpos2.Y())
317 rv = -1 ;
318 else
319 rv = 1 ;
320
321 return rv ;
ab48128d 322}
323
ab48128d 324//___________________________________________________________________________
325 void AliEMCALRecPoint::Draw(Option_t *option)
326 {
327 // Draw this AliEMCALRecPoint with its current attributes
328
329 AppendPad(option);
330 }
331
70a93198 332//____________________________________________________________________________
0d0d6b98 333void AliEMCALRecPoint::EvalAll(Float_t logWeight,TClonesArray * digits, const Bool_t justClusters)
70a93198 334{
25bb3dcb 335 // Evaluates cluster parameters
336
337 // First calculate the index of digit with maximum amplitude and get
338 // the supermodule number where it sits.
6ce4e2ed 339
25bb3dcb 340 fDigitIndMax = GetMaximalEnergyIndex();
341 fSuperModuleNumber = fGeomPtr->GetSuperModuleNumber(GetAbsIdMaxDigit());
342
343 //Evaluate global and local position
344 EvalGlobalPosition(logWeight, digits) ;
70a93198 345 EvalLocalPosition(logWeight, digits) ;
25bb3dcb 346
347 //Evaluate shower parameters
70a93198 348 EvalElipsAxis(logWeight, digits) ;
349 EvalDispersion(logWeight, digits) ;
25bb3dcb 350
4635df1f 351 //EvalCoreEnergy(logWeight, digits);
70a93198 352 EvalTime(digits) ;
87cdc3be 353 EvalPrimaries(digits) ;
354 EvalParents(digits);
40164976 355
9aa6a5f6 356 //Called last because it sets the global position of the cluster?
0d0d6b98 357 //Do not call it when recalculating clusters out of standard reconstruction
92d9f317 358 if(!justClusters){
92d9f317 359 EvalLocal2TrackingCSTransform();
360 }
9aa6a5f6 361
70a93198 362}
363
364//____________________________________________________________________________
365void AliEMCALRecPoint::EvalDispersion(Float_t logWeight, TClonesArray * digits)
366{
367 // Calculates the dispersion of the shower at the origin of the RecPoint
1d46d1f6 368 // in cell units - Nov 16,2006
70a93198 369
1d46d1f6 370 Double_t d = 0., wtot = 0., w = 0.;
af5bdd85 371 Int_t iDigit=0, nstat=0;
53e430a3 372 AliEMCALDigit * digit=0;
25bb3dcb 373
1d46d1f6 374 // Calculates the dispersion in cell units
375 Double_t etai, phii, etaMean=0.0, phiMean=0.0;
2bb3725c 376 int nSupMod=0, nModule=0, nIphi=0, nIeta=0;
1d46d1f6 377 int iphi=0, ieta=0;
378 // Calculate mean values
70a93198 379 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
380 digit = (AliEMCALDigit *) digits->At(fDigitsList[iDigit]) ;
1963b290 381
1d46d1f6 382 if (fAmp>0 && fEnergyList[iDigit]>0) {
2bb3725c 383 fGeomPtr->GetCellIndex(digit->GetId(), nSupMod,nModule,nIphi,nIeta);
384 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
25bb3dcb 385
386 // In case of a shared cluster, index of SM in C side, columns start at 48 and ends at 48*2
387 // C Side impair SM, nSupMod%2=1; A side pair SM nSupMod%2=0
388 if(fSharedCluster && nSupMod%2) ieta+=AliEMCALGeoParams::fgkEMCALCols;
389
1d46d1f6 390 etai=(Double_t)ieta;
391 phii=(Double_t)iphi;
392 w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
393
394 if(w>0.0) {
395 phiMean += phii*w;
396 etaMean += etai*w;
397 wtot += w;
398 }
399 }
400 }
401 if (wtot>0) {
402 phiMean /= wtot ;
403 etaMean /= wtot ;
404 } else AliError(Form("Wrong weight %f\n", wtot));
70a93198 405
1d46d1f6 406 // Calculate dispersion
407 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
408 digit = (AliEMCALDigit *) digits->At(fDigitsList[iDigit]) ;
409
410 if (fAmp>0 && fEnergyList[iDigit]>0) {
2bb3725c 411 fGeomPtr->GetCellIndex(digit->GetId(), nSupMod,nModule,nIphi,nIeta);
412 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
25bb3dcb 413
414 // In case of a shared cluster, index of SM in C side, columns start at 48 and ends at 48*2
415 // C Side impair SM, nSupMod%2=1; A side pair SM, nSupMod%2=0
416 if(fSharedCluster && nSupMod%2) ieta+=AliEMCALGeoParams::fgkEMCALCols;
417
1d46d1f6 418 etai=(Double_t)ieta;
419 phii=(Double_t)iphi;
420 w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
421
422 if(w>0.0) {
423 nstat++;
424 d += w*((etai-etaMean)*(etai-etaMean)+(phii-phiMean)*(phii-phiMean));
e52475ed 425 }
426 }
ab48128d 427 }
70a93198 428
e52475ed 429 if ( wtot > 0 && nstat>1) d /= wtot ;
430 else d = 0. ;
70a93198 431
432 fDispersion = TMath::Sqrt(d) ;
25bb3dcb 433 //printf("AliEMCALRecPoint::EvalDispersion() : Dispersion %f \n",fDispersion);
ab48128d 434}
70a93198 435
ab48128d 436//____________________________________________________________________________
40164976 437void AliEMCALRecPoint::EvalDistanceToBadChannels(AliCaloCalibPedestal* caloped)
438{
73a654fc 439 //For each EMC rec. point set the distance to the nearest bad channel.
440 //AliInfo(Form("%d bad channel(s) found.\n", caloped->GetDeadTowerCount()));
2ebdefe6 441 //It is done in cell units and not in global or local position as before (Sept 2010)
73a654fc 442
443 if(!caloped->GetDeadTowerCount()) return;
444
445 //Get channels map of the supermodule where the cluster is.
446 TH2D* hMap = caloped->GetDeadMap(fSuperModuleNumber);
447
2ebdefe6 448 Int_t dRrow, dReta;
73a654fc 449 Float_t minDist = 10000.;
450 Float_t dist = 0.;
2ebdefe6 451 Int_t nSupMod, nModule;
452 Int_t nIphi, nIeta;
453 Int_t iphi, ieta;
454 fDigitIndMax = GetMaximalEnergyIndex();
455 fGeomPtr->GetCellIndex(fAbsIdList[fDigitIndMax], nSupMod,nModule,nIphi,nIeta);
456 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
2ebdefe6 457
458 //Loop on tower status map
73a654fc 459 for(Int_t irow = 0; irow < AliEMCALGeoParams::fgkEMCALRows; irow++){
460 for(Int_t icol = 0; icol < AliEMCALGeoParams::fgkEMCALCols; icol++){
461 //Check if tower is bad.
462 if(hMap->GetBinContent(icol,irow)==AliCaloCalibPedestal::kAlive) continue;
2ebdefe6 463 //printf("AliEMCALRecPoint::EvalDistanceToBadChannels() - Bad channel in SM %d, col %d, row %d\n",iSM,icol, irow);
73a654fc 464
2ebdefe6 465 dRrow=TMath::Abs(irow-iphi);
466 dReta=TMath::Abs(icol-ieta);
467 dist=TMath::Sqrt(dRrow*dRrow+dReta*dReta);
73a654fc 468 if(dist < minDist) minDist = dist;
2ebdefe6 469
73a654fc 470 }
471 }
2ebdefe6 472
73a654fc 473 //In case the cluster is shared by 2 SuperModules, need to check the map of the second Super Module
474 if (fSharedCluster) {
475 TH2D* hMap2 = 0;
476 Int_t nSupMod2 = -1;
2ebdefe6 477
73a654fc 478 //The only possible combinations are (0,1), (2,3) ... (10,11)
479 if(fSuperModuleNumber%2) nSupMod2 = fSuperModuleNumber-1;
480 else nSupMod2 = fSuperModuleNumber+1;
481 hMap2 = caloped->GetDeadMap(nSupMod2);
482
483 //Loop on tower status map of second super module
484 for(Int_t irow = 0; irow < AliEMCALGeoParams::fgkEMCALRows; irow++){
485 for(Int_t icol = 0; icol < AliEMCALGeoParams::fgkEMCALCols; icol++){
486 //Check if tower is bad.
487 if(hMap2->GetBinContent(icol,irow)==AliCaloCalibPedestal::kAlive) continue;
488 //printf("AliEMCALRecPoint::EvalDistanceToBadChannels() - Bad channel in SM %d, col %d, row %d\n",iSM,icol, irow);
2ebdefe6 489 dRrow=TMath::Abs(irow-iphi);
73a654fc 490
2ebdefe6 491 if(fSuperModuleNumber%2) {
73a654fc 492 dReta=TMath::Abs(icol-(AliEMCALGeoParams::fgkEMCALCols+ieta));
493 }
494 else {
495 dReta=TMath::Abs(AliEMCALGeoParams::fgkEMCALCols+icol-ieta);
496 }
2ebdefe6 497
73a654fc 498 dist=TMath::Sqrt(dRrow*dRrow+dReta*dReta);
2ebdefe6 499 if(dist < minDist) minDist = dist;
e93968a8 500
73a654fc 501 }
502 }
503
504 }// shared cluster in 2 SuperModules
505
506 fDistToBadTower = minDist;
507 //printf("AliEMCALRecPoint::EvalDistanceToBadChannel() - Distance to Bad is %f cm, shared cluster? %d \n",fDistToBadTower,fSharedCluster);
40164976 508}
509
510
511//____________________________________________________________________________
70a93198 512void AliEMCALRecPoint::EvalLocalPosition(Float_t logWeight, TClonesArray * digits)
88cb7938 513{
73a654fc 514 // Calculates the center of gravity in the local EMCAL-module coordinates
515 // Info("Print", " logWeight %f : cluster energy %f ", logWeight, fAmp); // for testing
516
517 AliEMCALDigit * digit=0;
518 Int_t i=0, nstat=0;
519
520 Double_t dist = TmaxInCm(Double_t(fAmp));
521 //Int_t idMax = GetAbsIdMaxDigit();// idMax is not used at all in RelPosCellInSModule, why use it?
522
523 Double_t clXYZ[3]={0.,0.,0.}, clRmsXYZ[3]={0.,0.,0.}, xyzi[3], wtot=0., w=0.;
524
525 //printf(" dist : %f e : %f \n", dist, fAmp);
526 for(Int_t iDigit=0; iDigit<fMulDigit; iDigit++) {
527 digit = dynamic_cast<AliEMCALDigit *>(digits->At(fDigitsList[iDigit])) ;
528
2ebdefe6 529 if(!digit) {
530 AliError("No Digit!!");
531 continue;
532 }
533
73a654fc 534 fGeomPtr->RelPosCellInSModule(digit->GetId(), dist, xyzi[0], xyzi[1], xyzi[2]);
535
536 //Temporal patch, due to mapping problem, need to swap "y" in one of the 2 SM, although no effect in position calculation. GCB 05/2010
537 if(fSharedCluster && fSuperModuleNumber != fGeomPtr->GetSuperModuleNumber(digit->GetId())) xyzi[1]*=-1;
538
539 //printf("EvalLocalPosition Cell: Id %i, SM %i : dist %f Local x,y,z %f %f %f \n",
540 // digit->GetId(), fGeomPtr->GetSuperModuleNumber(digit->GetId()), dist, xyzi[0], xyzi[1], xyzi[2]);
541
542 if(logWeight > 0.0) w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ));
543 else w = fEnergyList[iDigit]; // just energy
544
545 if(w>0.0) {
546 wtot += w ;
547 nstat++;
548 for(i=0; i<3; i++ ) {
549 clXYZ[i] += (w*xyzi[i]);
550 clRmsXYZ[i] += (w*xyzi[i]*xyzi[i]);
551 }
552 }
553 }
554 // cout << " wtot " << wtot << endl;
555 if ( wtot > 0 ) {
556 // xRMS = TMath::Sqrt(x2m - xMean*xMean);
557 for(i=0; i<3; i++ ) {
558 clXYZ[i] /= wtot;
559 if(nstat>1) {
560 clRmsXYZ[i] /= (wtot*wtot);
561 clRmsXYZ[i] = clRmsXYZ[i] - clXYZ[i]*clXYZ[i];
562 if(clRmsXYZ[i] > 0.0) {
563 clRmsXYZ[i] = TMath::Sqrt(clRmsXYZ[i]);
564 } else clRmsXYZ[i] = 0;
565 } else clRmsXYZ[i] = 0;
566 }
567 } else {
568 for(i=0; i<3; i++ ) {
569 clXYZ[i] = clRmsXYZ[i] = -1.;
570 }
571 }
73a654fc 572
573 // // Cluster of one single digit, smear the position to avoid discrete position
574 // // smear x and z with +- 3 cm to uniform (avoid discrete effects). Tower size is approx 6 cm.
575 // // Rndm generates a number in ]0,1]
576 // if (fMulDigit==1) {
577 // clXYZ[0] += fGeomPtr->GetPhiTileSize()*(0.5 - gRandom->Rndm());
578 // clXYZ[2] += fGeomPtr->GetEtaTileSize()*(0.5 - gRandom->Rndm());
579 // }
580
581 //Set position in local vector
582 fLocPos.SetX(clXYZ[0]);
583 fLocPos.SetY(clXYZ[1]);
584 fLocPos.SetZ(clXYZ[2]);
585
586 if (gDebug==2)
587 printf("EvalLocalPosition Cluster: Local (x,y,z) = (%f,%f,%f) \n", fLocPos.X(), fLocPos.Y(), fLocPos.Z()) ;
588
25bb3dcb 589}
590
591
592//____________________________________________________________________________
593void AliEMCALRecPoint::EvalGlobalPosition(Float_t logWeight, TClonesArray * digits)
594{
595 // Calculates the center of gravity in the global ALICE coordinates
e52475ed 596 // Info("Print", " logWeight %f : cluster energy %f ", logWeight, fAmp); // for testing
70a93198 597
53e430a3 598 AliEMCALDigit * digit=0;
25bb3dcb 599 Int_t i=0, nstat=0;
600
47583f1b 601 Double_t dist = TmaxInCm(Double_t(fAmp));
25bb3dcb 602 //Int_t idMax = GetAbsIdMaxDigit();// idMax is not used at all in RelPosCellInSModule, why use it?
603
604 Double_t clXYZ[3]={0.,0.,0.}, clRmsXYZ[3]={0.,0.,0.}, lxyzi[3], xyzi[3], wtot=0., w=0.;
70a93198 605
1ae500a2 606 //printf(" dist : %f e : %f \n", dist, fAmp);
e52475ed 607 for(Int_t iDigit=0; iDigit<fMulDigit; iDigit++) {
70a93198 608 digit = dynamic_cast<AliEMCALDigit *>(digits->At(fDigitsList[iDigit])) ;
e52475ed 609
2ebdefe6 610 if(!digit) {
611 AliError("No Digit!!");
612 continue;
613 }
614
25bb3dcb 615 //Get the local coordinates of the cell
25bb3dcb 616 fGeomPtr->RelPosCellInSModule(digit->GetId(), dist, lxyzi[0], lxyzi[1], lxyzi[2]);
617
618 //Now get the global coordinate
619 fGeomPtr->GetGlobal(lxyzi,xyzi, fGeomPtr->GetSuperModuleNumber(digit->GetId()));
620 //TVector3 pos(xyzi[0], xyzi[1], xyzi[2]);
621 //printf("EvalGlobalPosition Cell: Id %i, SM %i : dist %f Local (x,y,z) = (%f %f %f), eta %f, phi%f \n",
622 // digit->GetId(), fGeomPtr->GetSuperModuleNumber(digit->GetId()),dist, xyzi[0], xyzi[1], xyzi[2],pos.Eta(),pos.Phi()*TMath::RadToDeg());
623
af5bdd85 624 if(logWeight > 0.0) w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ));
625 else w = fEnergyList[iDigit]; // just energy
ab48128d 626
e52475ed 627 if(w>0.0) {
628 wtot += w ;
629 nstat++;
630 for(i=0; i<3; i++ ) {
631 clXYZ[i] += (w*xyzi[i]);
632 clRmsXYZ[i] += (w*xyzi[i]*xyzi[i]);
633 }
634 }
635 }
636 // cout << " wtot " << wtot << endl;
70a93198 637 if ( wtot > 0 ) {
e52475ed 638 // xRMS = TMath::Sqrt(x2m - xMean*xMean);
639 for(i=0; i<3; i++ ) {
640 clXYZ[i] /= wtot;
641 if(nstat>1) {
642 clRmsXYZ[i] /= (wtot*wtot);
643 clRmsXYZ[i] = clRmsXYZ[i] - clXYZ[i]*clXYZ[i];
644 if(clRmsXYZ[i] > 0.0) {
645 clRmsXYZ[i] = TMath::Sqrt(clRmsXYZ[i]);
646 } else clRmsXYZ[i] = 0;
647 } else clRmsXYZ[i] = 0;
648 }
70a93198 649 } else {
e52475ed 650 for(i=0; i<3; i++ ) {
651 clXYZ[i] = clRmsXYZ[i] = -1.;
652 }
70a93198 653 }
25bb3dcb 654
655// // Cluster of one single digit, smear the position to avoid discrete position
656// // smear x and z with +- 3 cm to uniform (avoid discrete effects). Tower size is approx 6 cm.
657// // Rndm generates a number in ]0,1]
658// if (fMulDigit==1) {
659// clXYZ[0] += fGeomPtr->GetPhiTileSize()*(0.5 - gRandom->Rndm());
660// clXYZ[2] += fGeomPtr->GetEtaTileSize()*(0.5 - gRandom->Rndm());
661// }
662
663 //Set position in global vector
664 fGlobPos.SetX(clXYZ[0]);
665 fGlobPos.SetY(clXYZ[1]);
666 fGlobPos.SetZ(clXYZ[2]);
667
668 if (gDebug==2)
669 printf("EvalGlobalPosition Cluster: (x ,y ,z) = (%f,%f,%f), eta %f,phi %f\n",
670 fGlobPos.X(), fGlobPos.Y(), fGlobPos.Z(),fGlobPos.Eta(),fGlobPos.Phi()*TMath::RadToDeg()) ;
ab48128d 671}
672
1ae500a2 673//____________________________________________________________________________
674void AliEMCALRecPoint::EvalLocalPositionFit(Double_t deff, Double_t logWeight,
675Double_t phiSlope, TClonesArray * digits)
676{
47583f1b 677 // Evaluates local position of clusters in SM
678
679 Double_t ycorr=0;
680 AliEMCALDigit *digit=0;
25bb3dcb 681 Int_t i=0, nstat=0;
1ae500a2 682 Double_t clXYZ[3]={0.,0.,0.}, clRmsXYZ[3]={0.,0.,0.}, xyzi[3], wtot=0., w=0.;
683
47583f1b 684 Double_t dist = TmaxInCm(Double_t(fAmp));
25bb3dcb 685 //Int_t idMax = GetAbsIdMaxDigit();// idMax is not used at all in RelPosCellInSModule, why use it?
686
1ae500a2 687 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
688 digit = dynamic_cast<AliEMCALDigit *>(digits->At(fDigitsList[iDigit])) ;
a51e676d 689 if(digit){
690 dist = deff;
691 //fGeomPtr->RelPosCellInSModule(digit->GetId(), idMax, dist, xyzi[0], xyzi[1], xyzi[2]);
692 fGeomPtr->RelPosCellInSModule(digit->GetId(), dist, xyzi[0], xyzi[1], xyzi[2]);
693
694 if(logWeight > 0.0) w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ));
695 else w = fEnergyList[iDigit]; // just energy
696
697 if(w>0.0) {
698 wtot += w ;
699 nstat++;
700 for(i=0; i<3; i++ ) {
701 clXYZ[i] += (w*xyzi[i]);
702 clRmsXYZ[i] += (w*xyzi[i]*xyzi[i]);
703 }
1ae500a2 704 }
a51e676d 705 }else AliError("Digit null");
706 }//loop
1ae500a2 707 // cout << " wtot " << wtot << endl;
708 if ( wtot > 0 ) {
709 // xRMS = TMath::Sqrt(x2m - xMean*xMean);
710 for(i=0; i<3; i++ ) {
711 clXYZ[i] /= wtot;
712 if(nstat>1) {
713 clRmsXYZ[i] /= (wtot*wtot);
714 clRmsXYZ[i] = clRmsXYZ[i] - clXYZ[i]*clXYZ[i];
715 if(clRmsXYZ[i] > 0.0) {
716 clRmsXYZ[i] = TMath::Sqrt(clRmsXYZ[i]);
717 } else clRmsXYZ[i] = 0;
718 } else clRmsXYZ[i] = 0;
719 }
720 } else {
721 for(i=0; i<3; i++ ) {
722 clXYZ[i] = clRmsXYZ[i] = -1.;
723 }
724 }
725 // clRmsXYZ[i] ??
726 if(phiSlope != 0.0 && logWeight > 0.0 && wtot) {
727 // Correction in phi direction (y - coords here); Aug 16;
728 // May be put to global level or seperate method
729 ycorr = clXYZ[1] * (1. + phiSlope);
730 //printf(" y %f : ycorr %f : slope %f \n", clXYZ[1], ycorr, phiSlope);
731 clXYZ[1] = ycorr;
732 }
25bb3dcb 733
1ae500a2 734 fLocPos.SetX(clXYZ[0]);
735 fLocPos.SetY(clXYZ[1]);
736 fLocPos.SetZ(clXYZ[2]);
737
738// if (gDebug==2)
739// printf("EvalLocalPosition: eta,phi,r = %f,%f,%f", fLocPos.X(), fLocPos.Y(), fLocPos.Z()) ;
1ae500a2 740}
741
9aa6a5f6 742//_____________________________________________________________________________
1ae500a2 743Bool_t AliEMCALRecPoint::EvalLocalPosition2(TClonesArray * digits, TArrayD &ed)
744{
745 // Evaluated local position of rec.point using digits
746 // and parametrisation of w0 and deff
747 //printf(" <I> AliEMCALRecPoint::EvalLocalPosition2() \n");
748 return AliEMCALRecPoint::EvalLocalPositionFromDigits(digits, ed, fLocPos);
749}
750
9aa6a5f6 751//_____________________________________________________________________________
1ae500a2 752Bool_t AliEMCALRecPoint::EvalLocalPositionFromDigits(TClonesArray *digits, TArrayD &ed, TVector3 &locPos)
753{
754 // Used when digits should be recalibrated
47583f1b 755 Double_t deff=0, w0=0, esum=0;
756 Int_t iDigit=0;
757 // AliEMCALDigit *digit;
1ae500a2 758
759 if(ed.GetSize() && (digits->GetEntries()!=ed.GetSize())) return kFALSE;
760
761 // Calculate sum energy of digits
762 esum = 0.0;
763 for(iDigit=0; iDigit<ed.GetSize(); iDigit++) esum += ed[iDigit];
764
765 GetDeffW0(esum, deff, w0);
766
767 return EvalLocalPositionFromDigits(esum, deff, w0, digits, ed, locPos);
768}
769
9aa6a5f6 770//_____________________________________________________________________________
771Bool_t AliEMCALRecPoint::EvalLocalPositionFromDigits(const Double_t esum, const Double_t deff, const Double_t w0, TClonesArray *digits, TArrayD &ed, TVector3 &locPos)
1ae500a2 772{
40164976 773 //Evaluate position of digits in supermodule.
47583f1b 774 AliEMCALDigit *digit=0;
1ae500a2 775
25bb3dcb 776 Int_t i=0, nstat=0;
1ae500a2 777 Double_t clXYZ[3]={0.,0.,0.}, xyzi[3], wtot=0., w=0.;
25bb3dcb 778 //Int_t idMax = GetAbsIdMaxDigit();// idMax is not used at all in RelPosCellInSModule, why use it?
779
9aa6a5f6 780 // Get pointer to EMCAL geometry
781 // (can't use fGeomPtr in static method)
782 AliEMCALGeometry* geo = AliEMCALGeometry::GetInstance();
783
1ae500a2 784 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
785 digit = dynamic_cast<AliEMCALDigit *>(digits->At(iDigit));
a51e676d 786 if(digit){
787 //geo->RelPosCellInSModule(digit->GetId(), idMax, deff, xyzi[0], xyzi[1], xyzi[2]);
788 geo->RelPosCellInSModule(digit->GetId(), deff, xyzi[0], xyzi[1], xyzi[2]);
789
790 if(w0 > 0.0) w = TMath::Max( 0., w0 + TMath::Log(ed[iDigit] / esum));
791 else w = ed[iDigit]; // just energy
792
793 if(w>0.0) {
794 wtot += w ;
795 nstat++;
796 for(i=0; i<3; i++ ) {
797 clXYZ[i] += (w*xyzi[i]);
798 }
1ae500a2 799 }
a51e676d 800 }else AliError("Digit null");
801 }//loop
1ae500a2 802 // cout << " wtot " << wtot << endl;
803 if (wtot > 0) {
804 for(i=0; i<3; i++ ) {
805 clXYZ[i] /= wtot;
806 }
807 locPos.SetX(clXYZ[0]);
808 locPos.SetY(clXYZ[1]);
809 locPos.SetZ(clXYZ[2]);
810 return kTRUE;
811 } else {
812 return kFALSE;
813 }
814
815}
816
9aa6a5f6 817//_____________________________________________________________________________
1ae500a2 818void AliEMCALRecPoint::GetDeffW0(const Double_t esum , Double_t &deff, Double_t &w0)
819{
820 //
821 // Aug 31, 2001
822 // Applied for simulation data with threshold 3 adc
823 // Calculate efective distance (deff) and weigh parameter (w0)
824 // for coordinate calculation; 0.5 GeV < esum <100 GeV.
825 // Look to: http://rhic.physics.wayne.edu/~pavlinov/ALICE/SHISHKEBAB/RES/CALIB/GEOMCORR/deffandW0VaEgamma_2.gif
826 //
47583f1b 827 Double_t e=0.0;
37890aaf 828 const Double_t kdp0=9.25147, kdp1=1.16700; // Hard coded now
829 const Double_t kwp0=4.83713, kwp1=-2.77970e-01, kwp2 = 4.41116;
1ae500a2 830
831 // No extrapolation here
832 e = esum<0.5?0.5:esum;
833 e = e>100.?100.:e;
834
37890aaf 835 deff = kdp0 + kdp1*TMath::Log(e);
836 w0 = kwp0 / (1. + TMath::Exp(kwp1*(e+kwp2)));
1ae500a2 837 //printf("<I> AliEMCALRecPoint::GetDeffW0 esum %5.2f : deff %5.2f : w0 %5.2f \n", esum, deff, w0);
838}
e52475ed 839
70a93198 840//______________________________________________________________________________
841void AliEMCALRecPoint::EvalCoreEnergy(Float_t logWeight, TClonesArray * digits)
842{
843 // This function calculates energy in the core,
4635df1f 844 // i.e. within a radius rad = fCoreEnergy around the center. Beyond this radius
70a93198 845 // in accordance with shower profile the energy deposition
846 // should be less than 2%
1d46d1f6 847 // Unfinished - Nov 15,2006
848 // Distance is calculate in (phi,eta) units
70a93198 849
53e430a3 850 AliEMCALDigit * digit = 0 ;
5dee926e 851
53e430a3 852 Int_t iDigit=0;
70a93198 853
e52475ed 854 if (!fLocPos.Mag()) {
70a93198 855 EvalLocalPosition(logWeight, digits);
856 }
857
1d46d1f6 858 Double_t phiPoint = fLocPos.Phi(), etaPoint = fLocPos.Eta();
859 Double_t eta, phi, distance;
70a93198 860 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
861 digit = (AliEMCALDigit *) ( digits->At(fDigitsList[iDigit]) ) ;
4635df1f 862
1d46d1f6 863 eta = phi = 0.0;
864 fGeomPtr->EtaPhiFromIndex(digit->GetId(),eta, phi) ;
865 phi = phi * TMath::DegToRad();
70a93198 866
1d46d1f6 867 distance = TMath::Sqrt((eta-etaPoint)*(eta-etaPoint)+(phi-phiPoint)*(phi-phiPoint));
70a93198 868 if(distance < fCoreRadius)
869 fCoreEnergy += fEnergyList[iDigit] ;
870 }
871
872}
ab48128d 873//____________________________________________________________________________
70a93198 874void AliEMCALRecPoint::EvalElipsAxis(Float_t logWeight,TClonesArray * digits)
ab48128d 875{
70a93198 876 // Calculates the axis of the shower ellipsoid in eta and phi
1d46d1f6 877 // in cell units
ab48128d 878
47583f1b 879 TString gn(fGeomPtr->GetName());
1d46d1f6 880
881 Double_t wtot = 0.;
70a93198 882 Double_t x = 0.;
883 Double_t z = 0.;
884 Double_t dxx = 0.;
885 Double_t dzz = 0.;
886 Double_t dxz = 0.;
ab48128d 887
1d46d1f6 888 AliEMCALDigit * digit = 0;
25bb3dcb 889
53e430a3 890 Double_t etai =0, phii=0, w=0;
2bb3725c 891 int nSupMod=0, nModule=0, nIphi=0, nIeta=0;
1d46d1f6 892 int iphi=0, ieta=0;
893 for(Int_t iDigit=0; iDigit<fMulDigit; iDigit++) {
70a93198 894 digit = (AliEMCALDigit *) digits->At(fDigitsList[iDigit]) ;
1d46d1f6 895 etai = phii = 0.;
1d46d1f6 896 // Nov 15,2006 - use cell numbers as coordinates
897 // Copied for shish-kebab geometry, ieta,iphi is cast as double as eta,phi
898 // We can use the eta,phi(or coordinates) of cell
dc77cc84 899 nSupMod = nModule = nIphi = nIeta = iphi = ieta = 0;
1d46d1f6 900
dc77cc84 901 fGeomPtr->GetCellIndex(digit->GetId(), nSupMod,nModule,nIphi,nIeta);
902 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi,ieta);
25bb3dcb 903
904 // In case of a shared cluster, index of SM in C side, columns start at 48 and ends at 48*2
905 // C Side impair SM, nSupMod%2=1; A side pair SM, nSupMod%2=0
906 if(fSharedCluster && nSupMod%2) ieta+=AliEMCALGeoParams::fgkEMCALCols;
907
dc77cc84 908 etai=(Double_t)ieta;
909 phii=(Double_t)iphi;
25bb3dcb 910
1d46d1f6 911 w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
912 // fAmp summed amplitude of digits, i.e. energy of recpoint
913 // Gives smaller value of lambda than log weight
914 // w = fEnergyList[iDigit] / fAmp; // Nov 16, 2006 - try just energy
ff1e7e2f 915
70a93198 916 dxx += w * etai * etai ;
917 x += w * etai ;
918 dzz += w * phii * phii ;
919 z += w * phii ;
1963b290 920
ff1e7e2f 921 dxz += w * etai * phii ;
1963b290 922
70a93198 923 wtot += w ;
924 }
ff1e7e2f 925
70a93198 926 if ( wtot > 0 ) {
927 dxx /= wtot ;
928 x /= wtot ;
929 dxx -= x * x ;
930 dzz /= wtot ;
931 z /= wtot ;
932 dzz -= z * z ;
933 dxz /= wtot ;
934 dxz -= x * z ;
ab48128d 935
70a93198 936 fLambda[0] = 0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
937 if(fLambda[0] > 0)
938 fLambda[0] = TMath::Sqrt(fLambda[0]) ;
939 else
940 fLambda[0] = 0;
941
942 fLambda[1] = 0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
ff1e7e2f 943
70a93198 944 if(fLambda[1] > 0) //To avoid exception if numerical errors lead to negative lambda.
945 fLambda[1] = TMath::Sqrt(fLambda[1]) ;
946 else
947 fLambda[1]= 0. ;
948 } else {
949 fLambda[0]= 0. ;
950 fLambda[1]= 0. ;
ab48128d 951 }
ff1e7e2f 952
25bb3dcb 953 //printf("AliEMCALRecPoint::EvalElipsAxis() lambdas = %f,%f \n", fLambda[0],fLambda[1]) ;
ff1e7e2f 954
ab48128d 955}
956
957//______________________________________________________________________________
958void AliEMCALRecPoint::EvalPrimaries(TClonesArray * digits)
959{
af5bdd85 960 // Constructs the list of primary particles (tracks) which
961 // have contributed to this RecPoint and calculate deposited energy
962 // for each track
73a654fc 963
53e430a3 964 AliEMCALDigit * digit =0;
af5bdd85 965 Int_t * primArray = new Int_t[fMaxTrack] ;
7f3091e7 966 memset(primArray,-1,sizeof(Int_t)*fMaxTrack);
af5bdd85 967 Float_t * dEPrimArray = new Float_t[fMaxTrack] ;
7f3091e7 968 memset(dEPrimArray,-1,sizeof(Int_t)*fMaxTrack);
2ebdefe6 969
ab48128d 970 Int_t index ;
971 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
972 digit = dynamic_cast<AliEMCALDigit *>(digits->At( fDigitsList[index] )) ;
2ebdefe6 973 if(!digit) {
974 AliError("No Digit!!");
975 continue;
976 }
977
ab48128d 978 Int_t nprimaries = digit->GetNprimary() ;
5c0368b8 979 if ( nprimaries == 0 ) continue ;
ab48128d 980 Int_t jndex ;
981 for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
982 if ( fMulTrack > fMaxTrack ) {
2ebdefe6 983 fMulTrack = fMaxTrack ;
984 Error("EvalPrimaries", "increase fMaxTrack ") ;
985 break ;
ab48128d 986 }
af5bdd85 987 Int_t newPrimary = digit->GetPrimary(jndex+1);
988 Float_t dEPrimary = digit->GetDEPrimary(jndex+1);
ab48128d 989 Int_t kndex ;
990 Bool_t already = kFALSE ;
991 for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
2ebdefe6 992 if ( newPrimary == primArray[kndex] ){
993 already = kTRUE ;
994 dEPrimArray[kndex] += dEPrimary;
995 break ;
996 }
ab48128d 997 } // end of check
5c0368b8 998 if ( !already && (fMulTrack < fMaxTrack)) { // store it
2ebdefe6 999 primArray[fMulTrack] = newPrimary ;
1000 dEPrimArray[fMulTrack] = dEPrimary ;
1001 fMulTrack++ ;
ab48128d 1002 } // store it
1003 } // all primaries in digit
ab48128d 1004 } // all digits
2ebdefe6 1005
af5bdd85 1006 Int_t *sortIdx = new Int_t[fMulTrack];
1007 TMath::Sort(fMulTrack,dEPrimArray,sortIdx);
1008 for(index = 0; index < fMulTrack; index++) {
1009 fTracksList[index] = primArray[sortIdx[index]] ;
1010 fDETracksList[index] = dEPrimArray[sortIdx[index]] ;
1011 }
1012 delete [] sortIdx;
1013 delete [] primArray ;
1014 delete [] dEPrimArray ;
2ebdefe6 1015
ab48128d 1016}
7ee5c5be 1017
87cdc3be 1018//______________________________________________________________________________
1019void AliEMCALRecPoint::EvalParents(TClonesArray * digits)
1020{
1021 // Constructs the list of parent particles (tracks) which have contributed to this RecPoint
73a654fc 1022
53e430a3 1023 AliEMCALDigit * digit=0 ;
af5bdd85 1024 Int_t * parentArray = new Int_t[fMaxTrack] ;
7f3091e7 1025 memset(parentArray,-1,sizeof(Int_t)*fMaxTrack);
af5bdd85 1026 Float_t * dEParentArray = new Float_t[fMaxTrack] ;
7f3091e7 1027 memset(dEParentArray,-1,sizeof(Int_t)*fMaxTrack);
2ebdefe6 1028
87cdc3be 1029 Int_t index ;
1030 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
94478418 1031 if (fDigitsList[index] >= digits->GetEntries() || fDigitsList[index] < 0)
2ebdefe6 1032 AliError(Form("Trying to get invalid digit %d (idx in WriteRecPoint %d)",fDigitsList[index],index));
87cdc3be 1033 digit = dynamic_cast<AliEMCALDigit *>(digits->At( fDigitsList[index] )) ;
2ebdefe6 1034 if(!digit) {
1035 AliError("No Digit!!");
1036 continue;
1037 }
1038
87cdc3be 1039 Int_t nparents = digit->GetNiparent() ;
5c0368b8 1040 if ( nparents == 0 ) continue ;
2ebdefe6 1041
87cdc3be 1042 Int_t jndex ;
1043 for ( jndex = 0 ; jndex < nparents ; jndex++ ) { // all primaries in digit
1044 if ( fMulParent > fMaxParent ) {
2ebdefe6 1045 fMulTrack = - 1 ;
1046 Error("EvalParents", "increase fMaxParent") ;
1047 break ;
87cdc3be 1048 }
af5bdd85 1049 Int_t newParent = digit->GetIparent(jndex+1) ;
1050 Float_t newdEParent = digit->GetDEParent(jndex+1) ;
87cdc3be 1051 Int_t kndex ;
1052 Bool_t already = kFALSE ;
f1d429fd 1053 for ( kndex = 0 ; kndex < fMulParent ; kndex++ ) { //check if not already stored
2ebdefe6 1054 if ( newParent == parentArray[kndex] ){
1055 dEParentArray[kndex] += newdEParent;
1056 already = kTRUE ;
1057 break ;
1058 }
87cdc3be 1059 } // end of check
94478418 1060 if ( !already && (fMulParent < fMaxParent)) { // store it
2ebdefe6 1061 parentArray[fMulParent] = newParent ;
1062 dEParentArray[fMulParent] = newdEParent ;
1063 fMulParent++ ;
87cdc3be 1064 } // store it
1065 } // all parents in digit
87cdc3be 1066 } // all digits
2ebdefe6 1067
27e2a47c 1068 if (fMulParent>0) {
af5bdd85 1069 Int_t *sortIdx = new Int_t[fMulParent];
1070 TMath::Sort(fMulParent,dEParentArray,sortIdx);
1071 for(index = 0; index < fMulParent; index++) {
1072 fParentsList[index] = parentArray[sortIdx[index]] ;
1073 fDEParentsList[index] = dEParentArray[sortIdx[index]] ;
1074 }
1075 delete [] sortIdx;
27e2a47c 1076 }
2ebdefe6 1077
af5bdd85 1078 delete [] parentArray;
1079 delete [] dEParentArray;
87cdc3be 1080}
1081
ab48128d 1082//____________________________________________________________________________
70a93198 1083void AliEMCALRecPoint::GetLocalPosition(TVector3 & lpos) const
1084{
9aa6a5f6 1085 // returns the position of the cluster in the local reference system
1086 // of the sub-detector
70a93198 1087
9aa6a5f6 1088 lpos = fLocPos;
70a93198 1089}
1090
1091//____________________________________________________________________________
ab48128d 1092void AliEMCALRecPoint::GetGlobalPosition(TVector3 & gpos) const
1093{
1094 // returns the position of the cluster in the global reference system of ALICE
70a93198 1095 // These are now the Cartesian X, Y and Z
e52475ed 1096 // cout<<" geom "<<geom<<endl;
25bb3dcb 1097 // fGeomPtr->GetGlobal(fLocPos, gpos, fSuperModuleNumber);
1098 gpos = fGlobPos;
1099
9aa6a5f6 1100}
1101
1102//____________________________________________________________________________
7cfcebd3 1103//void AliEMCALRecPoint::GetGlobalPosition(TVector3 & gpos, TMatrixF & gmat) const
1104//{
1105// // returns the position of the cluster in the global reference system of ALICE
1106// // These are now the Cartesian X, Y and Z
1107// // cout<<" geom "<<geom<<endl;
1108//
1109// //To be implemented
1110// fGeomPtr->GetGlobalEMCAL(this, gpos, gmat);
1111//
1112//}
9aa6a5f6 1113
1114//_____________________________________________________________________________
1115void AliEMCALRecPoint::EvalLocal2TrackingCSTransform()
1116{
1117 //Evaluates local to "tracking" c.s. transformation (B.P.).
1118 //All evaluations should be completed before calling for this
1119 //function.
1120 //See ALICE PPR Chapter 5 p.18 for "tracking" c.s. definition,
1121 //or just ask Jouri Belikov. :)
1122
1123 SetVolumeId(AliGeomManager::LayerToVolUID(AliGeomManager::kEMCAL,GetSuperModuleNumber()));
1124
1125 const TGeoHMatrix* tr2loc = GetTracking2LocalMatrix();
1126 if(!tr2loc) AliFatal(Form("No Tracking2LocalMatrix found."));
1127
1128 Double_t lxyz[3] = {fLocPos.X(),fLocPos.Y(),fLocPos.Z()};
1129 Double_t txyz[3] = {0,0,0};
1130
1131 tr2loc->MasterToLocal(lxyz,txyz);
1132 SetX(txyz[0]); SetY(txyz[1]); SetZ(txyz[2]);
1133
1134 if(AliLog::GetGlobalDebugLevel()>0) {
73a654fc 1135 TVector3 gpos; //TMatrixF gmat;
7cfcebd3 1136 //GetGlobalPosition(gpos,gmat); //Not doing anythin special, replace by next line.
73a654fc 1137 fGeomPtr->GetGlobal(fLocPos, gpos, GetSuperModuleNumber());
1138
9aa6a5f6 1139 Float_t gxyz[3];
1140 GetGlobalXYZ(gxyz);
1141 AliInfo(Form("lCS-->(%.3f,%.3f,%.3f), tCS-->(%.3f,%.3f,%.3f), gCS-->(%.3f,%.3f,%.3f), gCScalc-\
1142->(%.3f,%.3f,%.3f), supermodule %d",
1143 fLocPos.X(),fLocPos.Y(),fLocPos.Z(),
1144 GetX(),GetY(),GetZ(),
1145 gpos.X(),gpos.Y(),gpos.Z(),
1146 gxyz[0],gxyz[1],gxyz[2],GetSuperModuleNumber()));
1147 }
1148
70a93198 1149}
1150
1151//____________________________________________________________________________
1152Float_t AliEMCALRecPoint::GetMaximalEnergy(void) const
1153{
1154 // Finds the maximum energy in the cluster
ab48128d 1155
70a93198 1156 Float_t menergy = 0. ;
1157
1158 Int_t iDigit;
70a93198 1159 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
1160
1161 if(fEnergyList[iDigit] > menergy)
1162 menergy = fEnergyList[iDigit] ;
1163 }
1164 return menergy ;
ab48128d 1165}
1166
aad8e277 1167//____________________________________________________________________________
25bb3dcb 1168Int_t AliEMCALRecPoint::GetMaximalEnergyIndex(void) const
1169{
1170 // Finds the maximum energy in the cluster
1171
1172 Float_t menergy = 0. ;
44fe3410 1173 Int_t mid = 0 ;
25bb3dcb 1174 Int_t iDigit;
1175
1176 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
1177
1178 if(fEnergyList[iDigit] > menergy){
1179 menergy = fEnergyList[iDigit] ;
1180 mid = iDigit ;
1181 }
1182 }//loop on cluster digits
1183
1184 return mid ;
1185}
1186
1187
1188//____________________________________________________________________________
70a93198 1189Int_t AliEMCALRecPoint::GetMultiplicityAtLevel(Float_t H) const
aad8e277 1190{
70a93198 1191 // Calculates the multiplicity of digits with energy larger than H*energy
1192
1193 Int_t multipl = 0 ;
1194 Int_t iDigit ;
1195 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
1196
1197 if(fEnergyList[iDigit] > H * fAmp)
1198 multipl++ ;
1199 }
1200 return multipl ;
1201}
1202
1203//____________________________________________________________________________
1204Int_t AliEMCALRecPoint::GetNumberOfLocalMax(AliEMCALDigit ** maxAt, Float_t * maxAtEnergy,
1205 Float_t locMaxCut,TClonesArray * digits) const
1206{
1207 // Calculates the number of local maxima in the cluster using fLocalMaxCut as the minimum
1208 // energy difference between two local maxima
1209
53e430a3 1210 AliEMCALDigit * digit = 0;
1211 AliEMCALDigit * digitN = 0;
70a93198 1212
53e430a3 1213 Int_t iDigitN = 0 ;
1214 Int_t iDigit = 0 ;
70a93198 1215
1216 for(iDigit = 0; iDigit < fMulDigit; iDigit++)
1217 maxAt[iDigit] = (AliEMCALDigit*) digits->At(fDigitsList[iDigit]) ;
1218
1219 for(iDigit = 0 ; iDigit < fMulDigit; iDigit++) {
1220 if(maxAt[iDigit]) {
1221 digit = maxAt[iDigit] ;
1222
1223 for(iDigitN = 0; iDigitN < fMulDigit; iDigitN++) {
53e430a3 1224 digitN = (AliEMCALDigit *) digits->At(fDigitsList[iDigitN]) ;
70a93198 1225
1226 if ( AreNeighbours(digit, digitN) ) {
1227 if (fEnergyList[iDigit] > fEnergyList[iDigitN] ) {
1228 maxAt[iDigitN] = 0 ;
1229 // but may be digit too is not local max ?
1230 if(fEnergyList[iDigit] < fEnergyList[iDigitN] + locMaxCut)
1231 maxAt[iDigit] = 0 ;
1232 }
1233 else {
1234 maxAt[iDigit] = 0 ;
1235 // but may be digitN too is not local max ?
1236 if(fEnergyList[iDigit] > fEnergyList[iDigitN] - locMaxCut)
1237 maxAt[iDigitN] = 0 ;
1238 }
1239 } // if Areneighbours
1240 } // while digitN
1241 } // slot not empty
1242 } // while digit
1243
1244 iDigitN = 0 ;
1245 for(iDigit = 0; iDigit < fMulDigit; iDigit++) {
1246 if(maxAt[iDigit] ){
1247 maxAt[iDigitN] = maxAt[iDigit] ;
1248 maxAtEnergy[iDigitN] = fEnergyList[iDigit] ;
1249 iDigitN++ ;
1250 }
1251 }
1252 return iDigitN ;
1253}
4635df1f 1254
1255//____________________________________________________________________________
1256Int_t AliEMCALRecPoint::GetPrimaryIndex() const
1257{
1258 // Get the primary track index in TreeK which deposits the most energy
af5bdd85 1259 // in Digits which forms RecPoint.
4635df1f 1260
af5bdd85 1261 if (fMulTrack)
1262 return fTracksList[0];
1263 return -12345;
4635df1f 1264}
1265
70a93198 1266//____________________________________________________________________________
1267void AliEMCALRecPoint::EvalTime(TClonesArray * digits){
1268 // time is set to the time of the digit with the maximum energy
1269
53e430a3 1270 Float_t maxE = 0;
1271 Int_t maxAt = 0;
70a93198 1272 for(Int_t idig=0; idig < fMulDigit; idig++){
1273 if(fEnergyList[idig] > maxE){
53e430a3 1274 maxE = fEnergyList[idig] ;
70a93198 1275 maxAt = idig;
1276 }
1277 }
1278 fTime = ((AliEMCALDigit*) digits->At(fDigitsList[maxAt]))->GetTime() ;
aad8e277 1279
aad8e277 1280}
ab48128d 1281
1282//______________________________________________________________________________
1283void AliEMCALRecPoint::Paint(Option_t *)
1284{
1285 // Paint this ALiRecPoint as a TMarker with its current attributes
1286
1287 TVector3 pos(0.,0.,0.) ;
1288 GetLocalPosition(pos) ;
1289 Coord_t x = pos.X() ;
1290 Coord_t y = pos.Z() ;
1291 Color_t markercolor = 1 ;
53e430a3 1292 Size_t markersize = 1.;
ab48128d 1293 Style_t markerstyle = 5 ;
1294
1295 if (!gPad->IsBatch()) {
1296 gVirtualX->SetMarkerColor(markercolor) ;
1297 gVirtualX->SetMarkerSize (markersize) ;
1298 gVirtualX->SetMarkerStyle(markerstyle) ;
1299 }
1300 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
1301 gPad->PaintPolyMarker(1,&x,&y,"") ;
1302}
70a93198 1303
9aa6a5f6 1304//_____________________________________________________________________
1ae500a2 1305Double_t AliEMCALRecPoint::TmaxInCm(const Double_t e , const Int_t key)
1306{
9aa6a5f6 1307 // e energy in GeV)
1ae500a2 1308 // key = 0(gamma, default)
1309 // != 0(electron)
47583f1b 1310 const Double_t ca = 4.82; // shower max parameter - first guess; ca=TMath::Log(1000./8.07)
47583f1b 1311 Double_t tmax = 0.; // position of electromagnetic shower max in cm
1ae500a2 1312
171d2441 1313 Double_t x0 = 1.31; // radiation lenght (cm)
1314 //If old geometry in use
1315 if(!((fGeomPtr->GetEMCGeometry()->GetGeoName()).Contains("V1"))) x0 = 1.28;
1316
1ae500a2 1317 if(e>0.1) {
1318 tmax = TMath::Log(e) + ca;
1319 if (key==0) tmax += 0.5;
1320 else tmax -= 0.5;
37890aaf 1321 tmax *= x0; // convert to cm
1ae500a2 1322 }
1323 return tmax;
1324}
1325
70a93198 1326//______________________________________________________________________________
1327Float_t AliEMCALRecPoint::EtaToTheta(Float_t arg) const
1328{
1329 //Converts Theta (Radians) to Eta(Radians)
1330 return (2.*TMath::ATan(TMath::Exp(-arg)));
1331}
1332
1333//______________________________________________________________________________
1334Float_t AliEMCALRecPoint::ThetaToEta(Float_t arg) const
1335{
1336 //Converts Eta (Radians) to Theta(Radians)
1337 return (-1 * TMath::Log(TMath::Tan(0.5 * arg)));
1338}
261b1065 1339
1340//____________________________________________________________________________
e1a51e6e 1341void AliEMCALRecPoint::Print(Option_t *opt) const
261b1065 1342{
1343 // Print the list of digits belonging to the cluster
e1a51e6e 1344 if(strlen(opt)==0) return;
261b1065 1345 TString message ;
4800667c 1346 message = "AliEMCALRecPoint:\n" ;
261b1065 1347 message += " digits # = " ;
d8c2bd69 1348 AliInfo(message.Data()) ;
261b1065 1349
1350 Int_t iDigit;
1351 for(iDigit=0; iDigit<fMulDigit; iDigit++)
1352 printf(" %d ", fDigitsList[iDigit] ) ;
e52475ed 1353 printf("\n");
1354
d8c2bd69 1355 AliInfo(" Energies = ") ;
261b1065 1356 for(iDigit=0; iDigit<fMulDigit; iDigit++)
1357 printf(" %f ", fEnergyList[iDigit] ) ;
e52475ed 1358 printf("\n");
1359
d8c2bd69 1360 AliInfo("\n Abs Ids = ") ;
e52475ed 1361 for(iDigit=0; iDigit<fMulDigit; iDigit++)
1362 printf(" %i ", fAbsIdList[iDigit] ) ;
1363 printf("\n");
1364
d8c2bd69 1365 AliInfo(" Primaries ") ;
261b1065 1366 for(iDigit = 0;iDigit < fMulTrack; iDigit++)
1367 printf(" %d ", fTracksList[iDigit]) ;
e52475ed 1368
1369 printf("\n Local x %6.2f y %7.2f z %7.1f \n", fLocPos[0], fLocPos[1], fLocPos[2]);
1370
85c60a8e 1371 message = " ClusterType = %d" ;
1372 message += " Multiplicity = %d" ;
261b1065 1373 message += " Cluster Energy = %f" ;
1374 message += " Core energy = %f" ;
1375 message += " Core radius = %f" ;
1376 message += " Number of primaries %d" ;
1377 message += " Stored at position %d" ;
d8c2bd69 1378 AliInfo(Form(message.Data(), fClusterType, fMulDigit, fAmp, fCoreEnergy, fCoreRadius, fMulTrack, GetIndexInList()) ) ;
261b1065 1379}
1d46d1f6 1380
9aa6a5f6 1381//___________________________________________________________
1d46d1f6 1382Double_t AliEMCALRecPoint::GetPointEnergy() const
1383{
37890aaf 1384 //Returns energy ....
47583f1b 1385 Double_t e=0.0;
1d46d1f6 1386 for(int ic=0; ic<GetMultiplicity(); ic++) e += double(fEnergyList[ic]);
1387 return e;
1388}