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