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