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