Bug correction
[u/mrichter/AliRoot.git] / PHOS / AliPHOSEmcRecPoint.cxx
CommitLineData
d15a28e7 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
b2a60966 16/* $Id$ */
17
d15a28e7 18//_________________________________________________________________________
b2a60966 19// RecPoint implementation for PHOS-EMC
20// An EmcRecPoint is a cluster of digits
baef0810 21//*--
b2a60966 22//*-- Author: Dmitri Peressounko (RRC KI & SUBATECH)
23
d15a28e7 24
25// --- ROOT system ---
9f616d61 26#include "TH2.h"
d15a28e7 27#include "TMath.h"
9f616d61 28#include "TCanvas.h"
55fe9d13 29#include "TGraph.h"
d15a28e7 30
31// --- Standard library ---
32
d15a28e7 33// --- AliRoot header files ---
e957fea8 34#include "AliPHOSLoader.h"
88cb7938 35#include "AliGenerator.h"
d15a28e7 36#include "AliPHOSGeometry.h"
e957fea8 37#include "AliPHOSDigit.h"
d15a28e7 38#include "AliPHOSEmcRecPoint.h"
e957fea8 39
d15a28e7 40ClassImp(AliPHOSEmcRecPoint)
41
42//____________________________________________________________________________
7932f811 43AliPHOSEmcRecPoint::AliPHOSEmcRecPoint() : AliPHOSRecPoint()
d15a28e7 44{
45 // ctor
46
47 fMulDigit = 0 ;
48 fAmp = 0. ;
7932f811 49 fCoreEnergy = 0 ;
50 fEnergyList = 0 ;
94256c23 51 fNExMax = 0 ; //Not unfolded yet
9688c1dd 52 fTime = -1. ;
a6eedfad 53 fLocPos.SetX(1000000.) ; //Local position should be evaluated
ce2a9a95 54 fDebug=0;
7b7c1533 55
83974468 56}
57
58//____________________________________________________________________________
73a68ccb 59AliPHOSEmcRecPoint::AliPHOSEmcRecPoint(const char * opt) : AliPHOSRecPoint(opt)
60{
61 // ctor
62
63 fMulDigit = 0 ;
64 fAmp = 0. ;
94256c23 65 fNExMax = 0 ; //Not unfolded yet
73a68ccb 66 fCoreEnergy = 0 ;
67 fEnergyList = 0 ;
68 fTime = -1. ;
69 fLocPos.SetX(1000000.) ; //Local position should be evaluated
ce2a9a95 70 fDebug=0;
73a68ccb 71
72}
73
74//____________________________________________________________________________
55fe9d13 75AliPHOSEmcRecPoint::AliPHOSEmcRecPoint(const AliPHOSEmcRecPoint & rp) : AliPHOSRecPoint(rp)
76{
77 // cpy ctor
78
79 fMulDigit = rp.fMulDigit ;
80 fAmp = rp.fAmp ;
81 fCoreEnergy = rp.fCoreEnergy ;
82 fEnergyList = new Float_t[rp.fMulDigit] ;
83 Int_t index ;
84 for(index = 0 ; index < fMulDigit ; index++)
85 fEnergyList[index] = rp.fEnergyList[index] ;
86 fNExMax = rp.fNExMax ;
87 fTime = rp.fTime ;
88}
89
90//____________________________________________________________________________
83974468 91AliPHOSEmcRecPoint::~AliPHOSEmcRecPoint()
92{
88714635 93 // dtor
a4e98857 94
83974468 95 if ( fEnergyList )
96 delete[] fEnergyList ;
d15a28e7 97}
98
9f616d61 99//____________________________________________________________________________
83974468 100void AliPHOSEmcRecPoint::AddDigit(AliPHOSDigit & digit, Float_t Energy)
d15a28e7 101{
b2a60966 102 // Adds a digit to the RecPoint
a4e98857 103 // and accumulates the total amplitude and the multiplicity
d15a28e7 104
7932f811 105 if(fEnergyList == 0)
106 fEnergyList = new Float_t[fMaxDigit];
107
d15a28e7 108 if ( fMulDigit >= fMaxDigit ) { // increase the size of the lists
9f616d61 109 fMaxDigit*=2 ;
0fbb8738 110 Int_t * tempo = new Int_t[fMaxDigit];
111 Float_t * tempoE = new Float_t[fMaxDigit];
9f616d61 112
113 Int_t index ;
d15a28e7 114 for ( index = 0 ; index < fMulDigit ; index++ ){
83974468 115 tempo[index] = fDigitsList[index] ;
d15a28e7 116 tempoE[index] = fEnergyList[index] ;
117 }
118
9f616d61 119 delete [] fDigitsList ;
0fbb8738 120 fDigitsList = new Int_t[fMaxDigit];
9f616d61 121
122 delete [] fEnergyList ;
0fbb8738 123 fEnergyList = new Float_t[fMaxDigit];
9f616d61 124
125 for ( index = 0 ; index < fMulDigit ; index++ ){
126 fDigitsList[index] = tempo[index] ;
127 fEnergyList[index] = tempoE[index] ;
128 }
129
130 delete [] tempo ;
131 delete [] tempoE ;
132 } // if
d15a28e7 133
83974468 134 fDigitsList[fMulDigit] = digit.GetIndexInList() ;
135 fEnergyList[fMulDigit] = Energy ;
136 fMulDigit++ ;
d15a28e7 137 fAmp += Energy ;
7932f811 138
139 EvalPHOSMod(&digit) ;
d15a28e7 140}
141
142//____________________________________________________________________________
ad8cfaf4 143Bool_t AliPHOSEmcRecPoint::AreNeighbours(AliPHOSDigit * digit1, AliPHOSDigit * digit2 ) const
d15a28e7 144{
a4e98857 145 // Tells if (true) or not (false) two digits are neighbors
d15a28e7 146
147 Bool_t aren = kFALSE ;
148
686b771f 149 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
7b7c1533 150
d15a28e7 151 Int_t relid1[4] ;
92862013 152 phosgeom->AbsToRelNumbering(digit1->GetId(), relid1) ;
d15a28e7 153
154 Int_t relid2[4] ;
92862013 155 phosgeom->AbsToRelNumbering(digit2->GetId(), relid2) ;
d15a28e7 156
92862013 157 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
158 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
d15a28e7 159
92862013 160 if (( coldiff <= 1 ) && ( rowdiff <= 1 ) && (coldiff + rowdiff > 0))
d15a28e7 161 aren = kTRUE ;
162
163 return aren ;
164}
165
166//____________________________________________________________________________
2a941f4e 167Int_t AliPHOSEmcRecPoint::Compare(const TObject * obj) const
d15a28e7 168{
b2a60966 169 // Compares two RecPoints according to their position in the PHOS modules
686b771f 170
171 const Float_t delta = 1 ; //Width of "Sorting row". If you changibg this
7932f811 172 //value (what is senseless) change as vell delta in
173 //AliPHOSTrackSegmentMakerv* and other RecPoints...
d15a28e7 174 Int_t rv ;
175
176 AliPHOSEmcRecPoint * clu = (AliPHOSEmcRecPoint *)obj ;
177
178
ad8cfaf4 179 Int_t phosmod1 = GetPHOSMod() ;
92862013 180 Int_t phosmod2 = clu->GetPHOSMod() ;
d15a28e7 181
92862013 182 TVector3 locpos1;
7932f811 183 GetLocalPosition(locpos1) ;
92862013 184 TVector3 locpos2;
185 clu->GetLocalPosition(locpos2) ;
d15a28e7 186
92862013 187 if(phosmod1 == phosmod2 ) {
7932f811 188 Int_t rowdif = (Int_t)TMath::Ceil(locpos1.X()/delta)-(Int_t)TMath::Ceil(locpos2.X()/delta) ;
d15a28e7 189 if (rowdif> 0)
7932f811 190 rv = 1 ;
d15a28e7 191 else if(rowdif < 0)
7932f811 192 rv = -1 ;
92862013 193 else if(locpos1.Z()>locpos2.Z())
d15a28e7 194 rv = -1 ;
195 else
196 rv = 1 ;
197 }
198
199 else {
92862013 200 if(phosmod1 < phosmod2 )
d15a28e7 201 rv = -1 ;
202 else
203 rv = 1 ;
204 }
205
206 return rv ;
207}
9f616d61 208//______________________________________________________________________________
8f2a3661 209void AliPHOSEmcRecPoint::ExecuteEvent(Int_t event, Int_t, Int_t) const
9f616d61 210{
9f616d61 211
9688c1dd 212 // Execute action corresponding to one event
213 // This member function is called when a AliPHOSRecPoint is clicked with the locator
214 //
215 // If Left button is clicked on AliPHOSRecPoint, the digits are switched on
216 // and switched off when the mouse button is released.
217
88cb7938 218
686b771f 219 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance();
83974468 220
9688c1dd 221 static TGraph * digitgraph = 0 ;
83974468 222
9688c1dd 223 if (!gPad->IsEditable()) return;
83974468 224
9688c1dd 225 TH2F * histo = 0 ;
226 TCanvas * histocanvas ;
227
88cb7938 228
229 //try to get run loader from default event folder
e191bb57 230 AliRunLoader* rn = AliRunLoader::GetRunLoader(AliConfig::GetDefaultEventFolderName());
88cb7938 231 if (rn == 0x0)
232 {
233 Error("ExecuteEvent","Can not find Run Loader in Default Event Folder");
234 return;
235 }
236 AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(rn->GetLoader("PHOSLoader"));
237 if (gime == 0x0)
238 {
239 Error("ExecuteEvent","Can not find PHOS Loader from Run Loader");
240 return;
241 }
242
243
afa51c4e 244 const TClonesArray * digits = gime->Digits() ;
9688c1dd 245
246 switch (event) {
83974468 247
9688c1dd 248 case kButton1Down: {
249 AliPHOSDigit * digit ;
250 Int_t iDigit;
251 Int_t relid[4] ;
83974468 252
9688c1dd 253 const Int_t kMulDigit = AliPHOSEmcRecPoint::GetDigitsMultiplicity() ;
254 Float_t * xi = new Float_t[kMulDigit] ;
255 Float_t * zi = new Float_t[kMulDigit] ;
83974468 256
9688c1dd 257 // create the histogram for the single cluster
258 // 1. gets histogram boundaries
259 Float_t ximax = -999. ;
260 Float_t zimax = -999. ;
261 Float_t ximin = 999. ;
262 Float_t zimin = 999. ;
83974468 263
9688c1dd 264 for(iDigit=0; iDigit<kMulDigit; iDigit++) {
265 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
266 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
267 phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]);
268 if ( xi[iDigit] > ximax )
269 ximax = xi[iDigit] ;
270 if ( xi[iDigit] < ximin )
271 ximin = xi[iDigit] ;
272 if ( zi[iDigit] > zimax )
273 zimax = zi[iDigit] ;
274 if ( zi[iDigit] < zimin )
275 zimin = zi[iDigit] ;
276 }
277 ximax += phosgeom->GetCrystalSize(0) / 2. ;
278 zimax += phosgeom->GetCrystalSize(2) / 2. ;
279 ximin -= phosgeom->GetCrystalSize(0) / 2. ;
280 zimin -= phosgeom->GetCrystalSize(2) / 2. ;
281 Int_t xdim = (int)( (ximax - ximin ) / phosgeom->GetCrystalSize(0) + 0.5 ) ;
282 Int_t zdim = (int)( (zimax - zimin ) / phosgeom->GetCrystalSize(2) + 0.5 ) ;
83974468 283
9688c1dd 284 // 2. gets the histogram title
83974468 285
9688c1dd 286 Text_t title[100] ;
287 sprintf(title,"Energy=%1.2f GeV ; Digits ; %d ", GetEnergy(), GetDigitsMultiplicity()) ;
83974468 288
9688c1dd 289 if (!histo) {
290 delete histo ;
291 histo = 0 ;
292 }
293 histo = new TH2F("cluster3D", title, xdim, ximin, ximax, zdim, zimin, zimax) ;
83974468 294
9688c1dd 295 Float_t x, z ;
296 for(iDigit=0; iDigit<kMulDigit; iDigit++) {
297 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
298 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
299 phosgeom->RelPosInModule(relid, x, z);
300 histo->Fill(x, z, fEnergyList[iDigit] ) ;
301 }
83974468 302
9688c1dd 303 if (!digitgraph) {
304 digitgraph = new TGraph(kMulDigit,xi,zi);
305 digitgraph-> SetMarkerStyle(5) ;
306 digitgraph-> SetMarkerSize(1.) ;
307 digitgraph-> SetMarkerColor(1) ;
308 digitgraph-> Paint("P") ;
309 }
83974468 310
9688c1dd 311 // Print() ;
312 histocanvas = new TCanvas("cluster", "a single cluster", 600, 500) ;
313 histocanvas->Draw() ;
314 histo->Draw("lego1") ;
83974468 315
9688c1dd 316 delete[] xi ;
317 delete[] zi ;
83974468 318
9688c1dd 319 break;
320 }
83974468 321
9688c1dd 322 case kButton1Up:
323 if (digitgraph) {
324 delete digitgraph ;
325 digitgraph = 0 ;
326 }
327 break;
9f616d61 328
9688c1dd 329 }
9f616d61 330}
331
d15a28e7 332//____________________________________________________________________________
7932f811 333void AliPHOSEmcRecPoint::EvalDispersion(Float_t logWeight,TClonesArray * digits)
d15a28e7 334{
b2a60966 335 // Calculates the dispersion of the shower at the origine of the RecPoint
336
e5b16749 337 Float_t d = 0. ;
338 Float_t wtot = 0. ;
d15a28e7 339
d084d50d 340 Float_t x = 0.;
341 Float_t z = 0.;
d15a28e7 342
343 AliPHOSDigit * digit ;
7b7c1533 344
686b771f 345 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance();
e5b16749 346
347 // Calculates the center of gravity in the local PHOS-module coordinates
348
d15a28e7 349 Int_t iDigit;
e5b16749 350
351 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
352 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
353 Int_t relid[4] ;
354 Float_t xi ;
355 Float_t zi ;
356 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
357 phosgeom->RelPosInModule(relid, xi, zi);
358 Float_t w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ) ) ;
359 x += xi * w ;
360 z += zi * w ;
361 wtot += w ;
362 }
363 x /= wtot ;
364 z /= wtot ;
365
366
367// Calculates the dispersion in coordinates
368 wtot = 0.;
88714635 369 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
7932f811 370 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
d15a28e7 371 Int_t relid[4] ;
372 Float_t xi ;
373 Float_t zi ;
92862013 374 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
375 phosgeom->RelPosInModule(relid, xi, zi);
7932f811 376 Float_t w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
92862013 377 d += w*((xi-x)*(xi-x) + (zi-z)*(zi-z) ) ;
d15a28e7 378 wtot+=w ;
d084d50d 379
380
d15a28e7 381 }
e5b16749 382
7932f811 383
92862013 384 d /= wtot ;
d15a28e7 385
7932f811 386 fDispersion = TMath::Sqrt(d) ;
c63c49e9 387
d15a28e7 388}
fad3e5b9 389//______________________________________________________________________________
e5b16749 390void AliPHOSEmcRecPoint::EvalCoreEnergy(Float_t logWeight, TClonesArray * digits)
fad3e5b9 391{
a4e98857 392 // This function calculates energy in the core,
393 // i.e. within a radius rad = 3cm around the center. Beyond this radius
394 // in accordance with shower profile the energy deposition
fad3e5b9 395 // should be less than 2%
396
fad3e5b9 397 Float_t coreRadius = 3 ;
398
e5b16749 399 Float_t x = 0 ;
400 Float_t z = 0 ;
fad3e5b9 401
402 AliPHOSDigit * digit ;
7b7c1533 403
686b771f 404 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance();
88cb7938 405
fad3e5b9 406 Int_t iDigit;
e5b16749 407
408// Calculates the center of gravity in the local PHOS-module coordinates
409 Float_t wtot = 0;
410 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
411 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
412 Int_t relid[4] ;
413 Float_t xi ;
414 Float_t zi ;
415 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
416 phosgeom->RelPosInModule(relid, xi, zi);
417 Float_t w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ) ) ;
418 x += xi * w ;
419 z += zi * w ;
420 wtot += w ;
421 }
422 x /= wtot ;
423 z /= wtot ;
424
425
fad3e5b9 426 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
7932f811 427 digit = (AliPHOSDigit *) ( digits->At(fDigitsList[iDigit]) ) ;
fad3e5b9 428 Int_t relid[4] ;
429 Float_t xi ;
430 Float_t zi ;
431 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
432 phosgeom->RelPosInModule(relid, xi, zi);
433 Float_t distance = TMath::Sqrt((xi-x)*(xi-x)+(zi-z)*(zi-z)) ;
434 if(distance < coreRadius)
7932f811 435 fCoreEnergy += fEnergyList[iDigit] ;
fad3e5b9 436 }
437
fad3e5b9 438}
d15a28e7 439
440//____________________________________________________________________________
7932f811 441void AliPHOSEmcRecPoint::EvalElipsAxis(Float_t logWeight,TClonesArray * digits)
d15a28e7 442{
b2a60966 443 // Calculates the axis of the shower ellipsoid
83974468 444
e8dbb96e 445 Double_t wtot = 0. ;
446 Double_t x = 0.;
447 Double_t z = 0.;
448 Double_t dxx = 0.;
449 Double_t dzz = 0.;
450 Double_t dxz = 0.;
d15a28e7 451
452 AliPHOSDigit * digit ;
7b7c1533 453
686b771f 454 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance();
7b7c1533 455
d15a28e7 456 Int_t iDigit;
457
e5b16749 458
d15a28e7 459 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
7932f811 460 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
d15a28e7 461 Int_t relid[4] ;
462 Float_t xi ;
463 Float_t zi ;
92862013 464 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
465 phosgeom->RelPosInModule(relid, xi, zi);
7932f811 466 Double_t w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
92862013 467 dxx += w * xi * xi ;
d15a28e7 468 x += w * xi ;
92862013 469 dzz += w * zi * zi ;
d15a28e7 470 z += w * zi ;
92862013 471 dxz += w * xi * zi ;
d15a28e7 472 wtot += w ;
473 }
92862013 474 dxx /= wtot ;
d15a28e7 475 x /= wtot ;
92862013 476 dxx -= x * x ;
477 dzz /= wtot ;
d15a28e7 478 z /= wtot ;
92862013 479 dzz -= z * z ;
480 dxz /= wtot ;
481 dxz -= x * z ;
d15a28e7 482
69183710 483// //Apply correction due to non-perpendicular incidence
484// Double_t CosX ;
485// Double_t CosZ ;
88cb7938 486// AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
7b7c1533 487// AliPHOSGeometry * phosgeom = (AliPHOSGeometry*)gime->PHOSGeometry();
488 // Double_t DistanceToIP= (Double_t ) phosgeom->GetIPtoCrystalSurface() ;
69183710 489
490// CosX = DistanceToIP/TMath::Sqrt(DistanceToIP*DistanceToIP+x*x) ;
491// CosZ = DistanceToIP/TMath::Sqrt(DistanceToIP*DistanceToIP+z*z) ;
492
493// dxx = dxx/(CosX*CosX) ;
494// dzz = dzz/(CosZ*CosZ) ;
495// dxz = dxz/(CosX*CosZ) ;
496
497
7932f811 498 fLambda[0] = 0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
499 if(fLambda[0] > 0)
500 fLambda[0] = TMath::Sqrt(fLambda[0]) ;
e8dbb96e 501
7932f811 502 fLambda[1] = 0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
503 if(fLambda[1] > 0) //To avoid exception if numerical errors lead to negative lambda.
504 fLambda[1] = TMath::Sqrt(fLambda[1]) ;
e8dbb96e 505 else
7932f811 506 fLambda[1]= 0. ;
d15a28e7 507}
508
509//____________________________________________________________________________
ce2a9a95 510void AliPHOSEmcRecPoint::EvalMoments(Float_t logWeight,TClonesArray * digits)
511{
512 // Calculate the shower moments in the eigen reference system
513 // M2x, M2z, M3x, M4z
514 // Calculate the angle between the shower position vector and the eigen vector
515
516 Double_t wtot = 0. ;
517 Double_t x = 0.;
518 Double_t z = 0.;
519 Double_t dxx = 0.;
520 Double_t dzz = 0.;
521 Double_t dxz = 0.;
522 Double_t lambda0=0, lambda1=0;
523
524 AliPHOSDigit * digit ;
525
686b771f 526 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
ce2a9a95 527
528 Int_t iDigit;
529
530 // 1) Find covariance matrix elements:
531 // || dxx dxz ||
532 // || dxz dzz ||
533
534 Float_t xi ;
535 Float_t zi ;
536 Int_t relid[4] ;
537 Double_t w;
538 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
539 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
540 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
541 phosgeom->RelPosInModule(relid, xi, zi);
542 w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
543 x += w * xi ;
544 z += w * zi ;
545 dxx += w * xi * xi ;
546 dzz += w * zi * zi ;
547 dxz += w * xi * zi ;
548 wtot += w ;
549 }
550 x /= wtot ;
551 z /= wtot ;
552 dxx /= wtot ;
553 dzz /= wtot ;
554 dxz /= wtot ;
555 dxx -= x * x ;
556 dzz -= z * z ;
557 dxz -= x * z ;
558
559 // 2) Find covariance matrix eigen values lambda0 and lambda1
560
561 lambda0 = 0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
562 lambda1 = 0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
563
564 // 3) Find covariance matrix eigen vectors e0 and e1
565
566 TVector2 e0,e1;
567 if (dxz != 0)
568 e0.Set(1.,(lambda0-dxx)/dxz);
569 else
570 e0.Set(0.,1.);
571
572 e0 = e0.Unit();
573 e1.Set(-e0.Y(),e0.X());
574
575 // 4) Rotate cluster tensor from (x,z) to (e0,e1) system
576 // and calculate moments M3x and M4z
577
578 Float_t cosPhi = e0.X();
579 Float_t sinPhi = e0.Y();
580
581 Float_t xiPHOS ;
582 Float_t ziPHOS ;
583 Double_t dx3, dz3, dz4;
584 wtot = 0.;
585 x = 0.;
586 z = 0.;
587 dxx = 0.;
588 dzz = 0.;
589 dxz = 0.;
590 dx3 = 0.;
591 dz3 = 0.;
592 dz4 = 0.;
593 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
594 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
595 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
596 phosgeom->RelPosInModule(relid, xiPHOS, ziPHOS);
597 xi = xiPHOS*cosPhi + ziPHOS*sinPhi;
598 zi = ziPHOS*cosPhi - xiPHOS*sinPhi;
599 w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
600 x += w * xi ;
601 z += w * zi ;
602 dxx += w * xi * xi ;
603 dzz += w * zi * zi ;
604 dxz += w * xi * zi ;
605 dx3 += w * xi * xi * xi;
606 dz3 += w * zi * zi * zi ;
607 dz4 += w * zi * zi * zi * zi ;
608 wtot += w ;
609 }
610 x /= wtot ;
611 z /= wtot ;
612 dxx /= wtot ;
613 dzz /= wtot ;
614 dxz /= wtot ;
615 dx3 /= wtot ;
616 dz3 /= wtot ;
617 dz4 /= wtot ;
618 dx3 += -3*dxx*x + 2*x*x*x;
619 dz4 += -4*dz3*z + 6*dzz*z*z -3*z*z*z*z;
620 dxx -= x * x ;
621 dzz -= z * z ;
622 dxz -= x * z ;
623
624 // 5) Find an angle between cluster center vector and eigen vector e0
625
626 Float_t phi = TMath::ACos ((x*e0.X() + z*e0.Y()) / sqrt(x*x + z*z));
627
628 fM2x = lambda0;
629 fM2z = lambda1;
630 fM3x = dx3;
631 fM4z = dz4;
632 fPhixe = phi;
633
634}
635//____________________________________________________________________________
7932f811 636void AliPHOSEmcRecPoint::EvalAll(Float_t logWeight, TClonesArray * digits )
ad8cfaf4 637{
baef0810 638 // Evaluates all shower parameters
7932f811 639 EvalLocalPosition(logWeight, digits) ;
640 EvalElipsAxis(logWeight, digits) ;
ce2a9a95 641 EvalMoments(logWeight, digits) ;
7932f811 642 EvalDispersion(logWeight, digits) ;
e5b16749 643 EvalCoreEnergy(logWeight, digits);
a6eedfad 644 EvalTime(digits) ;
e957fea8 645 AliPHOSRecPoint::EvalAll(digits) ;
ad8cfaf4 646}
647//____________________________________________________________________________
7932f811 648void AliPHOSEmcRecPoint::EvalLocalPosition(Float_t logWeight, TClonesArray * digits)
b2a60966 649{
650 // Calculates the center of gravity in the local PHOS-module coordinates
b2a60966 651 Float_t wtot = 0. ;
652
653 Int_t relid[4] ;
654
655 Float_t x = 0. ;
656 Float_t z = 0. ;
657
658 AliPHOSDigit * digit ;
659
686b771f 660 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
b2a60966 661
662 Int_t iDigit;
663
b2a60966 664 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
7932f811 665 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
b2a60966 666
667 Float_t xi ;
668 Float_t zi ;
669 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
670 phosgeom->RelPosInModule(relid, xi, zi);
7932f811 671 Float_t w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ) ) ;
b2a60966 672 x += xi * w ;
673 z += zi * w ;
674 wtot += w ;
b2a60966 675
9ce1a8d9 676 }
69183710 677 x /= wtot ;
678 z /= wtot ;
ad8cfaf4 679
680 // Correction for the depth of the shower starting point (TDR p 127)
681 Float_t para = 0.925 ;
682 Float_t parb = 6.52 ;
683
1b799736 684 Float_t xo,yo,zo ; //Coordinates of the origin
686b771f 685 //We should check all 3 possibilities to avoid seg.v.
686 if(gAlice && gAlice->GetMCApp() && gAlice->Generator())
687 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
688 else{
689 xo=yo=zo=0.;
690 }
5830e1d9 691 Float_t phi = phosgeom->GetPHOSAngle(relid[0]) ;
1b799736 692
693 //Transform to the local ref.frame
694 Float_t xoL,yoL ;
695 xoL = xo*TMath::Cos(phi)-yo*TMath::Sin(phi) ;
696 yoL = xo*TMath::Sin(phi)+yo*TMath::Cos(phi) ;
697
fd84cb73 698 Float_t radius = phosgeom->GetIPtoCrystalSurface()-yoL;
1b799736 699
700 Float_t incidencephi = TMath::ATan((x-xoL ) / radius) ;
701 Float_t incidencetheta = TMath::ATan((z-zo) / radius) ;
ad8cfaf4 702
703 Float_t depthx = ( para * TMath::Log(fAmp) + parb ) * TMath::Sin(incidencephi) ;
704 Float_t depthz = ( para * TMath::Log(fAmp) + parb ) * TMath::Sin(incidencetheta) ;
ad8cfaf4 705
706 fLocPos.SetX(x - depthx) ;
b2a60966 707 fLocPos.SetY(0.) ;
ad8cfaf4 708 fLocPos.SetZ(z - depthz) ;
b2a60966 709
a6eedfad 710 fLocPosM = 0 ;
b2a60966 711}
712
713//____________________________________________________________________________
ad8cfaf4 714Float_t AliPHOSEmcRecPoint::GetMaximalEnergy(void) const
d15a28e7 715{
b2a60966 716 // Finds the maximum energy in the cluster
717
d15a28e7 718 Float_t menergy = 0. ;
719
720 Int_t iDigit;
721
722 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
723
724 if(fEnergyList[iDigit] > menergy)
725 menergy = fEnergyList[iDigit] ;
726 }
727 return menergy ;
728}
729
730//____________________________________________________________________________
fc7e2f43 731Int_t AliPHOSEmcRecPoint::GetMultiplicityAtLevel(Float_t H) const
d15a28e7 732{
b2a60966 733 // Calculates the multiplicity of digits with energy larger than H*energy
734
d15a28e7 735 Int_t multipl = 0 ;
736 Int_t iDigit ;
737 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
738
739 if(fEnergyList[iDigit] > H * fAmp)
740 multipl++ ;
741 }
742 return multipl ;
743}
744
745//____________________________________________________________________________
a0636361 746Int_t AliPHOSEmcRecPoint::GetNumberOfLocalMax( AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
7932f811 747 Float_t locMaxCut,TClonesArray * digits) const
d15a28e7 748{
b2a60966 749 // Calculates the number of local maxima in the cluster using fLocalMaxCut as the minimum
a4e98857 750 // energy difference between two local maxima
b2a60966 751
d15a28e7 752 AliPHOSDigit * digit ;
753 AliPHOSDigit * digitN ;
754
755
756 Int_t iDigitN ;
757 Int_t iDigit ;
758
7932f811 759 for(iDigit = 0; iDigit < fMulDigit; iDigit++)
a0636361 760 maxAt[iDigit] = (AliPHOSDigit*) digits->At(fDigitsList[iDigit]) ;
7932f811 761
d15a28e7 762
6ad0bfa0 763 for(iDigit = 0 ; iDigit < fMulDigit; iDigit++) {
a0636361 764 if(maxAt[iDigit]) {
765 digit = maxAt[iDigit] ;
83974468 766
6ad0bfa0 767 for(iDigitN = 0; iDigitN < fMulDigit; iDigitN++) {
686b771f 768 if(iDigit == iDigitN)
769 continue ;
770
7932f811 771 digitN = (AliPHOSDigit *) digits->At(fDigitsList[iDigitN]) ;
d15a28e7 772
9f616d61 773 if ( AreNeighbours(digit, digitN) ) {
d15a28e7 774 if (fEnergyList[iDigit] > fEnergyList[iDigitN] ) {
a0636361 775 maxAt[iDigitN] = 0 ;
6ad0bfa0 776 // but may be digit too is not local max ?
7932f811 777 if(fEnergyList[iDigit] < fEnergyList[iDigitN] + locMaxCut)
a0636361 778 maxAt[iDigit] = 0 ;
d15a28e7 779 }
780 else {
a0636361 781 maxAt[iDigit] = 0 ;
6ad0bfa0 782 // but may be digitN too is not local max ?
7932f811 783 if(fEnergyList[iDigit] > fEnergyList[iDigitN] - locMaxCut)
a0636361 784 maxAt[iDigitN] = 0 ;
d15a28e7 785 }
786 } // if Areneighbours
787 } // while digitN
788 } // slot not empty
789 } // while digit
790
791 iDigitN = 0 ;
6ad0bfa0 792 for(iDigit = 0; iDigit < fMulDigit; iDigit++) {
a0636361 793 if(maxAt[iDigit]){
d15a28e7 794 maxAt[iDigitN] = maxAt[iDigit] ;
9f616d61 795 maxAtEnergy[iDigitN] = fEnergyList[iDigit] ;
796 iDigitN++ ;
d15a28e7 797 }
798 }
799 return iDigitN ;
800}
9688c1dd 801//____________________________________________________________________________
0bc3b8ed 802void AliPHOSEmcRecPoint::EvalTime(TClonesArray * digits)
803{
804 // Define a rec.point time as a time in the cell with the maximum energy
805
9688c1dd 806 Float_t maxE = 0;
807 Int_t maxAt = 0;
808 for(Int_t idig=0; idig < fMulDigit; idig++){
809 if(fEnergyList[idig] > maxE){
810 maxE = fEnergyList[idig] ;
811 maxAt = idig;
812 }
813 }
814 fTime = ((AliPHOSDigit*) digits->At(fDigitsList[maxAt]))->GetTime() ;
815
816}
d15a28e7 817//____________________________________________________________________________
092b50ba 818void AliPHOSEmcRecPoint::Purify(Float_t threshold){
819 //Removes digits below threshold
820
0fbb8738 821 Int_t * tempo = new Int_t[fMaxDigit];
822 Float_t * tempoE = new Float_t[fMaxDigit];
092b50ba 823
824 Int_t mult = 0 ;
825 for(Int_t iDigit=0;iDigit< fMulDigit ;iDigit++){
826 if(fEnergyList[iDigit] > threshold){
827 tempo[mult] = fDigitsList[iDigit] ;
828 tempoE[mult] = fEnergyList[iDigit] ;
829 mult++ ;
830 }
831 }
832
833 fMulDigit = mult ;
834 delete [] fDigitsList ;
835 delete [] fEnergyList ;
0fbb8738 836 fDigitsList = new Int_t[fMulDigit];
837 fEnergyList = new Float_t[fMulDigit];
092b50ba 838
0458aa58 839 fAmp = 0.; //Recalculate total energy
092b50ba 840 for(Int_t iDigit=0;iDigit< fMulDigit ;iDigit++){
0458aa58 841 fDigitsList[iDigit] = tempo[iDigit];
842 fEnergyList[iDigit] = tempoE[iDigit] ;
843 fAmp+=tempoE[iDigit];
092b50ba 844 }
845
846 delete [] tempo ;
847 delete [] tempoE ;
848
849}
850//____________________________________________________________________________
a8c47ab6 851void AliPHOSEmcRecPoint::Print(Option_t *) const
d15a28e7 852{
b2a60966 853 // Print the list of digits belonging to the cluster
854
21cd0c07 855 TString message ;
856 message = "AliPHOSEmcRecPoint:\n" ;
857 message += " digits # = " ;
858 Info("Print", message.Data()) ;
d15a28e7 859
d15a28e7 860 Int_t iDigit;
7932f811 861 for(iDigit=0; iDigit<fMulDigit; iDigit++)
53ad38d8 862 printf(" %d ", fDigitsList[iDigit] ) ;
7932f811 863
21cd0c07 864 Info("Print", " Energies = ") ;
7932f811 865 for(iDigit=0; iDigit<fMulDigit; iDigit++)
53ad38d8 866 printf(" %f ", fEnergyList[iDigit] ) ;
867 printf("\n") ;
21cd0c07 868 Info("Print", " Primaries ") ;
bc68d12c 869 for(iDigit = 0;iDigit < fMulTrack; iDigit++)
53ad38d8 870 printf(" %d ", fTracksList[iDigit]) ;
871 printf("\n") ;
21cd0c07 872 message = " Multiplicity = %d" ;
873 message += " Cluster Energy = %f" ;
874 message += " Number of primaries %d" ;
875 message += " Stored at position %d" ;
83974468 876
21cd0c07 877 Info("Print", message.Data(), fMulDigit, fAmp, fMulTrack,GetIndexInList() ) ;
d15a28e7 878}
88714635 879
7932f811 880