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