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