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