]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALRecPoint.cxx
- added the PHOS library to the autotools configuration
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALRecPoint.cxx
CommitLineData
ab48128d 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/* $Id$ */
16//_________________________________________________________________________
70a93198 17// Reconstructed Points for the EMCAL
18// A RecPoint is a cluster of digits
d64c959b 19//*-- Author: Yves Schutz (SUBATECH)
70a93198 20//*-- Author: Dmitri Peressounko (RRC KI & SUBATECH)
21//*-- Author: Heather Gray (LBL) merged AliEMCALRecPoint and AliEMCALTowerRecPoint 02/04
ab48128d 22
23// --- ROOT system ---
1d59832c 24class Riostream;
e52475ed 25#include <TPad.h>
1d59832c 26class TGraph;
27class TPaveText;
e52475ed 28#include <TClonesArray.h>
29#include <TMath.h>
ab48128d 30
31// --- Standard library ---
ab48128d 32
33// --- AliRoot header files ---
1d59832c 34//#include "AliGenerator.h"
35class AliGenerator;
4635df1f 36#include "AliRunLoader.h"
37#include "AliRun.h"
1d59832c 38class AliEMCAL;
4635df1f 39#include "AliEMCALLoader.h"
ab48128d 40#include "AliEMCALGeometry.h"
4635df1f 41#include "AliEMCALHit.h"
ab48128d 42#include "AliEMCALDigit.h"
43#include "AliEMCALRecPoint.h"
ab48128d 44
45ClassImp(AliEMCALRecPoint)
46
ab48128d 47//____________________________________________________________________________
48AliEMCALRecPoint::AliEMCALRecPoint()
49 : AliRecPoint()
50{
51 // ctor
85c60a8e 52 fClusterType = -1;
692088ae 53 fMaxTrack = 0 ;
70a93198 54 fMulDigit = 0 ;
87cdc3be 55 fMaxParent = 0;
56 fMulParent = 0;
70a93198 57 fAmp = 0. ;
58 fCoreEnergy = 0 ;
59 fEnergyList = 0 ;
85c60a8e 60 fTimeList = 0 ;
e52475ed 61 fAbsIdList = 0;
87cdc3be 62 fParentsList = 0;
70a93198 63 fTime = 0. ;
e52475ed 64 // fLocPos.SetX(1.e+6) ; //Local position should be evaluated
70a93198 65 fCoreRadius = 10; //HG Check this
4635df1f 66
67 AliRunLoader *rl = AliRunLoader::GetRunLoader();
14ce0a6e 68 fGeomPtr = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
69 //fGeomPtr = AliEMCALGeometry::GetInstance();
70 fGeomPtr->GetTransformationForSM(); // Global <-> Local
ab48128d 71}
72
73//____________________________________________________________________________
74AliEMCALRecPoint::AliEMCALRecPoint(const char * opt) : AliRecPoint(opt)
75{
76 // ctor
85c60a8e 77 fClusterType = -1;
ff1e7e2f 78 fMaxTrack = 1000 ;
79 fMaxParent = 1000;
87cdc3be 80 fMulDigit = 0 ;
81 fMulParent = 0;
70a93198 82 fAmp = 0. ;
83 fCoreEnergy = 0 ;
84 fEnergyList = 0 ;
85c60a8e 85 fTimeList = 0 ;
e52475ed 86 fAbsIdList = 0;
87cdc3be 87 fParentsList = new Int_t[fMaxParent];
70a93198 88 fTime = -1. ;
e52475ed 89 //fLocPos.SetX(1.e+6) ; //Local position should be evaluated
70a93198 90 fCoreRadius = 10; //HG Check this
14ce0a6e 91 //fGeomPtr = AliEMCALGeometry::GetInstance();
4635df1f 92 AliRunLoader *rl = AliRunLoader::GetRunLoader();
14ce0a6e 93 fGeomPtr = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
94 fGeomPtr->GetTransformationForSM(); // Global <-> Local
70a93198 95}
96//____________________________________________________________________________
0a4cb131 97AliEMCALRecPoint::AliEMCALRecPoint(const AliEMCALRecPoint & rp) : AliRecPoint(rp)
98{
99 //copy ctor
100 fGeomPtr = rp.fGeomPtr;
101 fClusterType = rp.fClusterType;
102 fCoreEnergy = rp.fCoreEnergy;
103 fLambda[0] = rp.fLambda[0];
104 fLambda[1] = rp.fLambda[1];
105 fDispersion = rp.fDispersion;
106 fEnergyList = new Float_t[rp.fMulDigit];
107 fTimeList = new Float_t[rp.fMulDigit];
108 fAbsIdList = new Int_t[rp.fMulDigit];
109 for(Int_t i = 0; i < rp.fMulDigit; i++) {
110 fEnergyList[i] = rp.fEnergyList[i];
111 fTimeList[i] = rp.fTimeList[i];
112 fAbsIdList[i] = rp.fAbsIdList[i];
113 }
114 fTime = rp.fTime;
115 fCoreRadius = rp.fCoreRadius;
116 fMulParent = rp.fMulParent;
117 fMaxParent = rp.fMaxParent;
118 fParentsList = new Int_t[rp.fMulParent];
119 for(Int_t i = 0; i < rp.fMulParent; i++) fParentsList[i] = rp.fParentsList[i];
120 fSuperModuleNumber = rp.fSuperModuleNumber;
121
122}
123//____________________________________________________________________________
70a93198 124AliEMCALRecPoint::~AliEMCALRecPoint()
125{
126 // dtor
127 if ( fEnergyList )
128 delete[] fEnergyList ;
85c60a8e 129 if ( fTimeList )
130 delete[] fTimeList ;
e52475ed 131 if ( fAbsIdList )
132 delete[] fAbsIdList ;
87cdc3be 133 if ( fParentsList)
134 delete[] fParentsList;
70a93198 135}
136
137//____________________________________________________________________________
138void AliEMCALRecPoint::AddDigit(AliEMCALDigit & digit, Float_t Energy)
139{
140 // Adds a digit to the RecPoint
141 // and accumulates the total amplitude and the multiplicity
142
143 if(fEnergyList == 0)
144 fEnergyList = new Float_t[fMaxDigit];
85c60a8e 145 if(fTimeList == 0)
146 fTimeList = new Float_t[fMaxDigit];
e52475ed 147 if(fAbsIdList == 0) {
148 fAbsIdList = new Int_t[fMaxDigit];
14ce0a6e 149 fSuperModuleNumber = fGeomPtr->GetSuperModuleNumber(digit.GetId());
e52475ed 150 }
70a93198 151
152 if ( fMulDigit >= fMaxDigit ) { // increase the size of the lists
153 fMaxDigit*=2 ;
a64a06d6 154 Int_t * tempo = new Int_t[fMaxDigit];
155 Float_t * tempoE = new Float_t[fMaxDigit];
85c60a8e 156 Float_t * tempoT = new Float_t[fMaxDigit];
e52475ed 157 Int_t * tempoId = new Int_t[fMaxDigit];
70a93198 158
159 Int_t index ;
160 for ( index = 0 ; index < fMulDigit ; index++ ){
e52475ed 161 tempo[index] = fDigitsList[index] ;
162 tempoE[index] = fEnergyList[index] ;
85c60a8e 163 tempoT[index] = fTimeList[index] ;
e52475ed 164 tempoId[index] = fAbsIdList[index] ;
70a93198 165 }
166
167 delete [] fDigitsList ;
a64a06d6 168 fDigitsList = new Int_t[fMaxDigit];
70a93198 169
170 delete [] fEnergyList ;
a64a06d6 171 fEnergyList = new Float_t[fMaxDigit];
70a93198 172
85c60a8e 173 delete [] fTimeList ;
174 fTimeList = new Float_t[fMaxDigit];
175
e52475ed 176 delete [] fAbsIdList ;
177 fAbsIdList = new Int_t[fMaxDigit];
178
70a93198 179 for ( index = 0 ; index < fMulDigit ; index++ ){
180 fDigitsList[index] = tempo[index] ;
181 fEnergyList[index] = tempoE[index] ;
85c60a8e 182 fTimeList[index] = tempoT[index] ;
e52475ed 183 fAbsIdList[index] = tempoId[index] ;
70a93198 184 }
185
186 delete [] tempo ;
187 delete [] tempoE ;
85c60a8e 188 delete [] tempoT ;
e52475ed 189 delete [] tempoId ;
70a93198 190 } // if
191
192 fDigitsList[fMulDigit] = digit.GetIndexInList() ;
193 fEnergyList[fMulDigit] = Energy ;
85c60a8e 194 fTimeList[fMulDigit] = digit.GetTime() ;
e52475ed 195 fAbsIdList[fMulDigit] = digit.GetId();
70a93198 196 fMulDigit++ ;
197 fAmp += Energy ;
198
199}
200//____________________________________________________________________________
201Bool_t AliEMCALRecPoint::AreNeighbours(AliEMCALDigit * digit1, AliEMCALDigit * digit2 ) const
202{
203 // Tells if (true) or not (false) two digits are neighbours
204 // A neighbour is defined as being two digits which share a corner
205
e52475ed 206 static Bool_t areNeighbours = kFALSE ;
207 static Int_t nSupMod=0, nTower=0, nIphi=0, nIeta=0;
208 static int nSupMod1=0, nTower1=0, nIphi1=0, nIeta1=0;
209 static Int_t relid1[2] , relid2[2] ; // ieta, iphi
210 static Int_t rowdiff=0, coldiff=0;
70a93198 211
e52475ed 212 areNeighbours = kFALSE ;
213
14ce0a6e 214 fGeomPtr->GetCellIndex(digit1->GetId(), nSupMod,nTower,nIphi,nIeta);
215 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod,nTower,nIphi,nIeta, relid1[0],relid1[1]);
e52475ed 216
14ce0a6e 217 fGeomPtr->GetCellIndex(digit2->GetId(), nSupMod1,nTower1,nIphi1,nIeta1);
218 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod1,nTower1,nIphi1,nIeta1, relid2[0],relid2[1]);
70a93198 219
e52475ed 220 rowdiff = TMath::Abs( relid1[0] - relid2[0] ) ;
221 coldiff = TMath::Abs( relid1[1] - relid2[1] ) ;
70a93198 222
223 if (( coldiff <= 1 ) && ( rowdiff <= 1 ) && (coldiff + rowdiff > 0))
e52475ed 224 areNeighbours = kTRUE ;
ab48128d 225
70a93198 226 return areNeighbours;
227}
228
229//____________________________________________________________________________
230Int_t AliEMCALRecPoint::Compare(const TObject * obj) const
231{
232 // Compares two RecPoints according to their position in the EMCAL modules
233
234 Float_t delta = 1 ; //Width of "Sorting row". If you change this
235 //value (what is senseless) change as well delta in
236 //AliEMCALTrackSegmentMakerv* and other RecPoints...
237 Int_t rv ;
238
239 AliEMCALRecPoint * clu = (AliEMCALRecPoint *)obj ;
240
241 TVector3 locpos1;
242 GetLocalPosition(locpos1);
243 TVector3 locpos2;
244 clu->GetLocalPosition(locpos2);
245
9848d950 246 Int_t rowdif = (Int_t)(TMath::Ceil(locpos1.X()/delta)-TMath::Ceil(locpos2.X()/delta)) ;
70a93198 247 if (rowdif> 0)
248 rv = 1 ;
249 else if(rowdif < 0)
250 rv = -1 ;
251 else if(locpos1.Y()>locpos2.Y())
252 rv = -1 ;
253 else
254 rv = 1 ;
255
256 return rv ;
ab48128d 257}
258
259//____________________________________________________________________________
260Int_t AliEMCALRecPoint::DistancetoPrimitive(Int_t px, Int_t py)
261{
262 // Compute distance from point px,py to a AliEMCALRecPoint considered as a Tmarker
263 // Compute the closest distance of approach from point px,py to this marker.
264 // The distance is computed in pixels units.
70a93198 265 // HG Still need to update -> Not sure what this should achieve
ab48128d 266
267 TVector3 pos(0.,0.,0.) ;
70a93198 268 GetLocalPosition(pos) ;
ab48128d 269 Float_t x = pos.X() ;
70a93198 270 Float_t y = pos.Y() ;
ab48128d 271 const Int_t kMaxDiff = 10;
272 Int_t pxm = gPad->XtoAbsPixel(x);
273 Int_t pym = gPad->YtoAbsPixel(y);
274 Int_t dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
275
276 if (dist > kMaxDiff) return 9999;
277 return dist;
278}
279
280//___________________________________________________________________________
281 void AliEMCALRecPoint::Draw(Option_t *option)
282 {
283 // Draw this AliEMCALRecPoint with its current attributes
284
285 AppendPad(option);
286 }
287
288//______________________________________________________________________________
70a93198 289void AliEMCALRecPoint::ExecuteEvent(Int_t /*event*/, Int_t, Int_t)
ab48128d 290{
291 // Execute action corresponding to one event
292 // This member function is called when a AliEMCALRecPoint is clicked with the locator
293 //
294 // If Left button is clicked on AliEMCALRecPoint, the digits are switched on
295 // and switched off when the mouse button is released.
296
297 // static Int_t pxold, pyold;
298
70a93198 299 /* static TGraph * digitgraph = 0 ;
ab48128d 300 static TPaveText* clustertext = 0 ;
301
302 if (!gPad->IsEditable()) return;
303
304 switch (event) {
305
306
307 case kButton1Down:{
308 AliEMCALDigit * digit ;
88cb7938 309 AliEMCALGeometry * emcalgeom = (AliEMCALGetter::Instance())->EMCALGeometry() ;
ab48128d 310
311 Int_t iDigit;
70a93198 312 Int_t relid[2] ;
ab48128d 313
314 const Int_t kMulDigit=AliEMCALRecPoint::GetDigitsMultiplicity() ;
315 Float_t * xi = new Float_t [kMulDigit] ;
316 Float_t * zi = new Float_t [kMulDigit] ;
317
318 for(iDigit = 0; iDigit < kMulDigit; iDigit++) {
319 Fatal("AliEMCALRecPoint::ExecuteEvent", " -> Something wrong with the code");
320 digit = 0 ; //dynamic_cast<AliEMCALDigit *>((fDigitsList)[iDigit]);
321 emcalgeom->AbsToRelNumbering(digit->GetId(), relid) ;
322 emcalgeom->PosInAlice(relid, xi[iDigit], zi[iDigit]) ;
323 }
324
325 if (!digitgraph) {
326 digitgraph = new TGraph(fMulDigit,xi,zi);
327 digitgraph-> SetMarkerStyle(5) ;
328 digitgraph-> SetMarkerSize(1.) ;
329 digitgraph-> SetMarkerColor(1) ;
330 digitgraph-> Draw("P") ;
331 }
332 if (!clustertext) {
333
334 TVector3 pos(0.,0.,0.) ;
335 GetLocalPosition(pos) ;
336 clustertext = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+50,pos.Z()+35,"") ;
337 Text_t line1[40] ;
338 Text_t line2[40] ;
339 sprintf(line1,"Energy=%1.2f GeV",GetEnergy()) ;
340 sprintf(line2,"%d Digits",GetDigitsMultiplicity()) ;
341 clustertext ->AddText(line1) ;
342 clustertext ->AddText(line2) ;
343 clustertext ->Draw("");
344 }
345 gPad->Update() ;
9e5d2067 346 Print("") ;
ab48128d 347 delete[] xi ;
348 delete[] zi ;
349 }
350
351break;
352
353 case kButton1Up:
354 if (digitgraph) {
355 delete digitgraph ;
356 digitgraph = 0 ;
357 }
358 if (clustertext) {
359 delete clustertext ;
360 clustertext = 0 ;
361 }
362
363 break;
364
70a93198 365 }*/
366}
367//____________________________________________________________________________
368void AliEMCALRecPoint::EvalAll(Float_t logWeight,TClonesArray * digits)
369{
370 // Evaluates all shower parameters
371
372 EvalLocalPosition(logWeight, digits) ;
500aeccc 373 // printf("eval position done\n");
70a93198 374 EvalElipsAxis(logWeight, digits) ;
500aeccc 375 // printf("eval axis done\n");
70a93198 376 EvalDispersion(logWeight, digits) ;
500aeccc 377 // printf("eval dispersion done\n");
4635df1f 378 //EvalCoreEnergy(logWeight, digits);
1963b290 379 // printf("eval energy done\n");
70a93198 380 EvalTime(digits) ;
500aeccc 381 // printf("eval time done\n");
70a93198 382
87cdc3be 383 EvalPrimaries(digits) ;
500aeccc 384 // printf("eval pri done\n");
87cdc3be 385 EvalParents(digits);
500aeccc 386 // printf("eval parent done\n");
70a93198 387}
388
389//____________________________________________________________________________
390void AliEMCALRecPoint::EvalDispersion(Float_t logWeight, TClonesArray * digits)
391{
392 // Calculates the dispersion of the shower at the origin of the RecPoint
393
e52475ed 394 Double_t d = 0., wtot = 0., w = 0., xyzi[3], diff=0.;
395 Int_t iDigit=0, nstat=0, i=0;
70a93198 396 AliEMCALDigit * digit ;
5dee926e 397
70a93198 398 // Calculates the centre of gravity in the local EMCAL-module coordinates
e52475ed 399 if (!fLocPos.Mag())
70a93198 400 EvalLocalPosition(logWeight, digits) ;
401
70a93198 402 // Calculates the dispersion in coordinates
70a93198 403 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
404 digit = (AliEMCALDigit *) digits->At(fDigitsList[iDigit]) ;
1963b290 405
14ce0a6e 406 fGeomPtr->RelPosCellInSModule(digit->GetId(), xyzi[0], xyzi[1], xyzi[2]);
e52475ed 407 w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
70a93198 408
e52475ed 409 if(w>0.0) {
410 wtot += w;
411 nstat++;
412 for(i=0; i<3; i++ ) {
413 diff = xyzi[i] - double(fLocPos[i]);
414 d += w * diff*diff;
415 }
416 }
ab48128d 417 }
70a93198 418
e52475ed 419 if ( wtot > 0 && nstat>1) d /= wtot ;
420 else d = 0. ;
70a93198 421
422 fDispersion = TMath::Sqrt(d) ;
ab48128d 423}
70a93198 424
ab48128d 425//____________________________________________________________________________
70a93198 426void AliEMCALRecPoint::EvalLocalPosition(Float_t logWeight, TClonesArray * digits)
88cb7938 427{
70a93198 428 // Calculates the center of gravity in the local EMCAL-module coordinates
e52475ed 429 // Info("Print", " logWeight %f : cluster energy %f ", logWeight, fAmp); // for testing
70a93198 430
e52475ed 431 AliEMCALDigit * digit;
e52475ed 432 Int_t i=0, nstat=0;
433 Double_t clXYZ[3]={0.,0.,0.}, clRmsXYZ[3]={0.,0.,0.}, xyzi[3], wtot=0., w=0.;
70a93198 434
e52475ed 435 for(Int_t iDigit=0; iDigit<fMulDigit; iDigit++) {
70a93198 436 digit = dynamic_cast<AliEMCALDigit *>(digits->At(fDigitsList[iDigit])) ;
437
14ce0a6e 438 fGeomPtr->RelPosCellInSModule(digit->GetId(), xyzi[0], xyzi[1], xyzi[2]);
e52475ed 439 // printf(" Id %i : Local x,y,z %f %f %f \n", digit->GetId(), xyzi[0], xyzi[1], xyzi[2]);
440
441 if(logWeight > 0.0) w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ));
442 else w = fEnergyList[iDigit]; // just energy
ab48128d 443
e52475ed 444 if(w>0.0) {
445 wtot += w ;
446 nstat++;
447 for(i=0; i<3; i++ ) {
448 clXYZ[i] += (w*xyzi[i]);
449 clRmsXYZ[i] += (w*xyzi[i]*xyzi[i]);
450 }
451 }
452 }
453 // cout << " wtot " << wtot << endl;
70a93198 454 if ( wtot > 0 ) {
e52475ed 455 // xRMS = TMath::Sqrt(x2m - xMean*xMean);
456 for(i=0; i<3; i++ ) {
457 clXYZ[i] /= wtot;
458 if(nstat>1) {
459 clRmsXYZ[i] /= (wtot*wtot);
460 clRmsXYZ[i] = clRmsXYZ[i] - clXYZ[i]*clXYZ[i];
461 if(clRmsXYZ[i] > 0.0) {
462 clRmsXYZ[i] = TMath::Sqrt(clRmsXYZ[i]);
463 } else clRmsXYZ[i] = 0;
464 } else clRmsXYZ[i] = 0;
465 }
70a93198 466 } else {
e52475ed 467 for(i=0; i<3; i++ ) {
468 clXYZ[i] = clRmsXYZ[i] = -1.;
469 }
70a93198 470 }
e52475ed 471 // clRmsXYZ[i] ??
472 fLocPos.SetX(clXYZ[0]);
473 fLocPos.SetY(clXYZ[1]);
474 fLocPos.SetZ(clXYZ[2]);
70a93198 475
1963b290 476// if (gDebug==2)
500aeccc 477// printf("EvalLocalPosition: eta,phi,r = %f,%f,%f", fLocPos.X(), fLocPos.Y(), fLocPos.Z()) ;
e52475ed 478 fLocPosM = 0 ; // covariance matrix
ab48128d 479}
480
e52475ed 481//void AliEMCALRecPoint::EvalLocalPositionSimple()
482//{ // Weight is proportional of cell energy
483//}
484
70a93198 485//______________________________________________________________________________
486void AliEMCALRecPoint::EvalCoreEnergy(Float_t logWeight, TClonesArray * digits)
487{
488 // This function calculates energy in the core,
4635df1f 489 // i.e. within a radius rad = fCoreEnergy around the center. Beyond this radius
70a93198 490 // in accordance with shower profile the energy deposition
491 // should be less than 2%
492
493 AliEMCALDigit * digit ;
494 const Float_t kDeg2Rad = TMath::DegToRad() ;
5dee926e 495
70a93198 496 Int_t iDigit;
497
e52475ed 498 if (!fLocPos.Mag()) {
70a93198 499 EvalLocalPosition(logWeight, digits);
500 }
501
502 for(iDigit=0; iDigit < fMulDigit; iDigit++) {
503 digit = (AliEMCALDigit *) ( digits->At(fDigitsList[iDigit]) ) ;
4635df1f 504
505 Float_t ieta = 0.0;
506 Float_t iphi = 0.0;
14ce0a6e 507 //fGeomPtr->PosInAlice(digit->GetId(), ieta, iphi);
508 fGeomPtr->EtaPhiFromIndex(digit->GetId(),ieta, iphi) ;
4635df1f 509 iphi = iphi * kDeg2Rad;
70a93198 510
4635df1f 511 Float_t distance = TMath::Sqrt((ieta-fLocPos.X())*(ieta-fLocPos.X())+(iphi-fLocPos.Y())*(iphi-fLocPos.Y())) ;
70a93198 512 if(distance < fCoreRadius)
513 fCoreEnergy += fEnergyList[iDigit] ;
514 }
515
516}
ab48128d 517//____________________________________________________________________________
70a93198 518void AliEMCALRecPoint::EvalElipsAxis(Float_t logWeight,TClonesArray * digits)
ab48128d 519{
70a93198 520 // Calculates the axis of the shower ellipsoid in eta and phi
ab48128d 521
70a93198 522 Double_t wtot = 0. ;
523 Double_t x = 0.;
524 Double_t z = 0.;
525 Double_t dxx = 0.;
526 Double_t dzz = 0.;
527 Double_t dxz = 0.;
ab48128d 528
ff1e7e2f 529 const Float_t kDeg2Rad = TMath::DegToRad();
70a93198 530 AliEMCALDigit * digit ;
531
14ce0a6e 532 TString gn(fGeomPtr->GetName());
70a93198 533
534 Int_t iDigit;
ab48128d 535
70a93198 536 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
537 digit = (AliEMCALDigit *) digits->At(fDigitsList[iDigit]) ;
538 Float_t etai = 0. ;
539 Float_t phii = 0. ;
e52475ed 540 if(gn.Contains("SHISH")) { // have to be change - Feb 28, 2006
1963b290 541 //copied for shish-kebab geometry, ieta,iphi is cast as float as eta,phi conversion
542 // for this geometry does not exist
543 int nSupMod=0, nTower=0, nIphi=0, nIeta=0;
544 int iphi=0, ieta=0;
14ce0a6e 545 fGeomPtr->GetCellIndex(digit->GetId(), nSupMod,nTower,nIphi,nIeta);
546 fGeomPtr->GetCellPhiEtaIndexInSModule(nSupMod,nTower,nIphi,nIeta, iphi,ieta);
1963b290 547 etai=(Float_t)ieta;
548 phii=(Float_t)iphi;
549 } else {
14ce0a6e 550 fGeomPtr->EtaPhiFromIndex(digit->GetId(), etai, phii);
1963b290 551 phii = phii * kDeg2Rad;
552 }
553
70a93198 554 Double_t w = TMath::Max(0.,logWeight+TMath::Log(fEnergyList[iDigit]/fAmp ) ) ;
ff1e7e2f 555
70a93198 556 dxx += w * etai * etai ;
557 x += w * etai ;
558 dzz += w * phii * phii ;
559 z += w * phii ;
1963b290 560
ff1e7e2f 561 dxz += w * etai * phii ;
1963b290 562
70a93198 563 wtot += w ;
564 }
ff1e7e2f 565
70a93198 566 if ( wtot > 0 ) {
567 dxx /= wtot ;
568 x /= wtot ;
569 dxx -= x * x ;
570 dzz /= wtot ;
571 z /= wtot ;
572 dzz -= z * z ;
573 dxz /= wtot ;
574 dxz -= x * z ;
ab48128d 575
70a93198 576 fLambda[0] = 0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
577 if(fLambda[0] > 0)
578 fLambda[0] = TMath::Sqrt(fLambda[0]) ;
579 else
580 fLambda[0] = 0;
581
582 fLambda[1] = 0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
ff1e7e2f 583
70a93198 584 if(fLambda[1] > 0) //To avoid exception if numerical errors lead to negative lambda.
585 fLambda[1] = TMath::Sqrt(fLambda[1]) ;
586 else
587 fLambda[1]= 0. ;
588 } else {
589 fLambda[0]= 0. ;
590 fLambda[1]= 0. ;
ab48128d 591 }
ff1e7e2f 592
1963b290 593 // printf("Evalaxis: lambdas = %f,%f", fLambda[0],fLambda[1]) ;
ff1e7e2f 594
ab48128d 595}
596
597//______________________________________________________________________________
598void AliEMCALRecPoint::EvalPrimaries(TClonesArray * digits)
599{
600 // Constructs the list of primary particles (tracks) which have contributed to this RecPoint
601
602 AliEMCALDigit * digit ;
603 Int_t * tempo = new Int_t[fMaxTrack] ;
604
605 Int_t index ;
606 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
607 digit = dynamic_cast<AliEMCALDigit *>(digits->At( fDigitsList[index] )) ;
608 Int_t nprimaries = digit->GetNprimary() ;
5c0368b8 609 if ( nprimaries == 0 ) continue ;
ab48128d 610 Int_t * newprimaryarray = new Int_t[nprimaries] ;
611 Int_t ii ;
612 for ( ii = 0 ; ii < nprimaries ; ii++)
613 newprimaryarray[ii] = digit->GetPrimary(ii+1) ;
614
615 Int_t jndex ;
616 for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
617 if ( fMulTrack > fMaxTrack ) {
f792c312 618 fMulTrack = fMaxTrack ;
9859bfc0 619 Error("GetNprimaries", "increase fMaxTrack ") ;
ab48128d 620 break ;
621 }
622 Int_t newprimary = newprimaryarray[jndex] ;
623 Int_t kndex ;
624 Bool_t already = kFALSE ;
625 for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
626 if ( newprimary == tempo[kndex] ){
627 already = kTRUE ;
628 break ;
629 }
630 } // end of check
5c0368b8 631 if ( !already && (fMulTrack < fMaxTrack)) { // store it
ab48128d 632 tempo[fMulTrack] = newprimary ;
633 fMulTrack++ ;
634 } // store it
635 } // all primaries in digit
f792c312 636 delete [] newprimaryarray ;
ab48128d 637 } // all digits
638
639
640 fTracksList = new Int_t[fMulTrack] ;
641 for(index = 0; index < fMulTrack; index++)
642 fTracksList[index] = tempo[index] ;
643
f792c312 644 delete [] tempo ;
ab48128d 645
646}
7ee5c5be 647
87cdc3be 648//______________________________________________________________________________
649void AliEMCALRecPoint::EvalParents(TClonesArray * digits)
650{
651 // Constructs the list of parent particles (tracks) which have contributed to this RecPoint
652
653 AliEMCALDigit * digit ;
654 Int_t * tempo = new Int_t[fMaxParent] ;
655
656 Int_t index ;
657 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
658 digit = dynamic_cast<AliEMCALDigit *>(digits->At( fDigitsList[index] )) ;
659 Int_t nparents = digit->GetNiparent() ;
5c0368b8 660 if ( nparents == 0 ) continue ;
87cdc3be 661 Int_t * newparentarray = new Int_t[nparents] ;
662 Int_t ii ;
663 for ( ii = 0 ; ii < nparents ; ii++)
664 newparentarray[ii] = digit->GetIparent(ii+1) ;
665
666 Int_t jndex ;
667 for ( jndex = 0 ; jndex < nparents ; jndex++ ) { // all primaries in digit
668 if ( fMulParent > fMaxParent ) {
669 fMulTrack = - 1 ;
670 Error("GetNiparent", "increase fMaxParent") ;
671 break ;
672 }
673 Int_t newparent = newparentarray[jndex] ;
674 Int_t kndex ;
675 Bool_t already = kFALSE ;
f1d429fd 676 for ( kndex = 0 ; kndex < fMulParent ; kndex++ ) { //check if not already stored
87cdc3be 677 if ( newparent == tempo[kndex] ){
678 already = kTRUE ;
679 break ;
680 }
681 } // end of check
5c0368b8 682 if ( !already && (fMulTrack < fMaxTrack)) { // store it
87cdc3be 683 tempo[fMulParent] = newparent ;
684 fMulParent++ ;
685 } // store it
686 } // all parents in digit
27e2a47c 687 delete [] newparentarray ;
87cdc3be 688 } // all digits
689
27e2a47c 690 if (fMulParent>0) {
691 fParentsList = new Int_t[fMulParent] ;
692 for(index = 0; index < fMulParent; index++)
693 fParentsList[index] = tempo[index] ;
694 }
87cdc3be 695
27e2a47c 696 delete [] tempo ;
87cdc3be 697
698}
699
70a93198 700//____________________________________________________________________________
701void AliEMCALRecPoint::GetLocalPosition(TVector3 & lpos) const
702{
703 // returns the position of the cluster in the local reference system of ALICE
70a93198 704
705 lpos.SetX(fLocPos.X()) ;
706 lpos.SetY(fLocPos.Y()) ;
707 lpos.SetZ(fLocPos.Z()) ;
708}
709
ab48128d 710//____________________________________________________________________________
711void AliEMCALRecPoint::GetGlobalPosition(TVector3 & gpos) const
712{
713 // returns the position of the cluster in the global reference system of ALICE
70a93198 714 // These are now the Cartesian X, Y and Z
e52475ed 715 // cout<<" geom "<<geom<<endl;
14ce0a6e 716 fGeomPtr->GetGlobal(fLocPos, gpos, fSuperModuleNumber);
70a93198 717}
718
719//____________________________________________________________________________
720Float_t AliEMCALRecPoint::GetMaximalEnergy(void) const
721{
722 // Finds the maximum energy in the cluster
ab48128d 723
70a93198 724 Float_t menergy = 0. ;
725
726 Int_t iDigit;
727
728 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
729
730 if(fEnergyList[iDigit] > menergy)
731 menergy = fEnergyList[iDigit] ;
732 }
733 return menergy ;
ab48128d 734}
735
aad8e277 736//____________________________________________________________________________
70a93198 737Int_t AliEMCALRecPoint::GetMultiplicityAtLevel(Float_t H) const
aad8e277 738{
70a93198 739 // Calculates the multiplicity of digits with energy larger than H*energy
740
741 Int_t multipl = 0 ;
742 Int_t iDigit ;
743 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
744
745 if(fEnergyList[iDigit] > H * fAmp)
746 multipl++ ;
747 }
748 return multipl ;
749}
750
751//____________________________________________________________________________
752Int_t AliEMCALRecPoint::GetNumberOfLocalMax(AliEMCALDigit ** maxAt, Float_t * maxAtEnergy,
753 Float_t locMaxCut,TClonesArray * digits) const
754{
755 // Calculates the number of local maxima in the cluster using fLocalMaxCut as the minimum
756 // energy difference between two local maxima
757
758 AliEMCALDigit * digit ;
759 AliEMCALDigit * digitN ;
760
761 Int_t iDigitN ;
762 Int_t iDigit ;
763
764 for(iDigit = 0; iDigit < fMulDigit; iDigit++)
765 maxAt[iDigit] = (AliEMCALDigit*) digits->At(fDigitsList[iDigit]) ;
766
767 for(iDigit = 0 ; iDigit < fMulDigit; iDigit++) {
768 if(maxAt[iDigit]) {
769 digit = maxAt[iDigit] ;
770
771 for(iDigitN = 0; iDigitN < fMulDigit; iDigitN++) {
772 digitN = (AliEMCALDigit *) digits->At(fDigitsList[iDigitN]) ;
773
774 if ( AreNeighbours(digit, digitN) ) {
775 if (fEnergyList[iDigit] > fEnergyList[iDigitN] ) {
776 maxAt[iDigitN] = 0 ;
777 // but may be digit too is not local max ?
778 if(fEnergyList[iDigit] < fEnergyList[iDigitN] + locMaxCut)
779 maxAt[iDigit] = 0 ;
780 }
781 else {
782 maxAt[iDigit] = 0 ;
783 // but may be digitN too is not local max ?
784 if(fEnergyList[iDigit] > fEnergyList[iDigitN] - locMaxCut)
785 maxAt[iDigitN] = 0 ;
786 }
787 } // if Areneighbours
788 } // while digitN
789 } // slot not empty
790 } // while digit
791
792 iDigitN = 0 ;
793 for(iDigit = 0; iDigit < fMulDigit; iDigit++) {
794 if(maxAt[iDigit] ){
795 maxAt[iDigitN] = maxAt[iDigit] ;
796 maxAtEnergy[iDigitN] = fEnergyList[iDigit] ;
797 iDigitN++ ;
798 }
799 }
800 return iDigitN ;
801}
4635df1f 802
803//____________________________________________________________________________
804Int_t AliEMCALRecPoint::GetPrimaryIndex() const
805{
806 // Get the primary track index in TreeK which deposits the most energy
807 // in Digits which forms RecPoint. Kinematics, Hits and Digits must be
808 // loaded before the call of the method.
809
810 AliRunLoader *rl = AliRunLoader::GetRunLoader();
811 if (!rl)
812 AliError(Form(" No Runloader ")) ;
813
814 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>
815 (rl->GetDetectorLoader("EMCAL"));
816
817 // Get the list of digits forming this RecPoint
818 Int_t nDigits = fMulDigit ;
819 Int_t *digitList = fDigitsList ;
820
821 // Find the digit with maximum amplitude
822 AliEMCALDigit *digit = 0;
823 TClonesArray *digits = emcalLoader->Digits();
824 Int_t maxAmp = 0;
825 Int_t bestDigitIndex = -1;
826 for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {
827 digit = static_cast<AliEMCALDigit *>(digits->At(digitList[iDigit]));
828 if (digit->GetAmp() > maxAmp) {
829 maxAmp = digit->GetAmp();
830 bestDigitIndex = iDigit;
831 }
832 }
833
834 digit = static_cast<AliEMCALDigit *>(digits->At(digitList[bestDigitIndex]));
835
836 // Get the list of hits producing this digit,
837 // find which hit has deposited more energy
838 // and find the primary track.
839
840 AliEMCALHit *hit = 0;
841 TClonesArray *hits = emcalLoader->Hits();
842
843 Double_t maxedep = 0;
844 Int_t maxtrack = -1;
845 Int_t nHits = hits ->GetEntries();
846 Int_t id = digit->GetId();
847 for (Int_t iHit=0; iHit<nHits; iHit++) {
848 hit = static_cast<AliEMCALHit*> (hits->At(iHit)) ;
849 if(hit->GetId() == id){
850 Double_t edep = hit->GetEnergy();
851 Int_t track = hit->GetIparent();//Primary();
852 if(edep > maxedep){
853 maxedep = edep;
854 maxtrack = track;
855 }
856 }
857 }
858 if (maxtrack != -1) return maxtrack;
859 return -12345; // no track found :(
860}
861
70a93198 862//____________________________________________________________________________
863void AliEMCALRecPoint::EvalTime(TClonesArray * digits){
864 // time is set to the time of the digit with the maximum energy
865
866 Float_t maxE = 0;
867 Int_t maxAt = 0;
868 for(Int_t idig=0; idig < fMulDigit; idig++){
869 if(fEnergyList[idig] > maxE){
870 maxE = fEnergyList[idig] ;
871 maxAt = idig;
872 }
873 }
874 fTime = ((AliEMCALDigit*) digits->At(fDigitsList[maxAt]))->GetTime() ;
aad8e277 875
aad8e277 876}
ab48128d 877
878//______________________________________________________________________________
879void AliEMCALRecPoint::Paint(Option_t *)
880{
881 // Paint this ALiRecPoint as a TMarker with its current attributes
882
883 TVector3 pos(0.,0.,0.) ;
884 GetLocalPosition(pos) ;
885 Coord_t x = pos.X() ;
886 Coord_t y = pos.Z() ;
887 Color_t markercolor = 1 ;
888 Size_t markersize = 1. ;
889 Style_t markerstyle = 5 ;
890
891 if (!gPad->IsBatch()) {
892 gVirtualX->SetMarkerColor(markercolor) ;
893 gVirtualX->SetMarkerSize (markersize) ;
894 gVirtualX->SetMarkerStyle(markerstyle) ;
895 }
896 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
897 gPad->PaintPolyMarker(1,&x,&y,"") ;
898}
70a93198 899
900//______________________________________________________________________________
901Float_t AliEMCALRecPoint::EtaToTheta(Float_t arg) const
902{
903 //Converts Theta (Radians) to Eta(Radians)
904 return (2.*TMath::ATan(TMath::Exp(-arg)));
905}
906
907//______________________________________________________________________________
908Float_t AliEMCALRecPoint::ThetaToEta(Float_t arg) const
909{
910 //Converts Eta (Radians) to Theta(Radians)
911 return (-1 * TMath::Log(TMath::Tan(0.5 * arg)));
912}
261b1065 913
914//____________________________________________________________________________
915void AliEMCALRecPoint::Print(Option_t *) const
916{
917 // Print the list of digits belonging to the cluster
e52475ed 918 return;
261b1065 919 TString message ;
4800667c 920 message = "AliEMCALRecPoint:\n" ;
261b1065 921 message += " digits # = " ;
922 Info("Print", message.Data()) ;
923
924 Int_t iDigit;
925 for(iDigit=0; iDigit<fMulDigit; iDigit++)
926 printf(" %d ", fDigitsList[iDigit] ) ;
e52475ed 927 printf("\n");
928
261b1065 929 Info("Print", " Energies = ") ;
930 for(iDigit=0; iDigit<fMulDigit; iDigit++)
931 printf(" %f ", fEnergyList[iDigit] ) ;
e52475ed 932 printf("\n");
933
934 Info("Print", "\n Abs Ids = ") ;
935 for(iDigit=0; iDigit<fMulDigit; iDigit++)
936 printf(" %i ", fAbsIdList[iDigit] ) ;
937 printf("\n");
938
939 Info("Print", " Primaries ") ;
261b1065 940 for(iDigit = 0;iDigit < fMulTrack; iDigit++)
941 printf(" %d ", fTracksList[iDigit]) ;
e52475ed 942
943 printf("\n Local x %6.2f y %7.2f z %7.1f \n", fLocPos[0], fLocPos[1], fLocPos[2]);
944
85c60a8e 945 message = " ClusterType = %d" ;
946 message += " Multiplicity = %d" ;
261b1065 947 message += " Cluster Energy = %f" ;
948 message += " Core energy = %f" ;
949 message += " Core radius = %f" ;
950 message += " Number of primaries %d" ;
951 message += " Stored at position %d" ;
85c60a8e 952 Info("Print", message.Data(), fClusterType, fMulDigit, fAmp, fCoreEnergy, fCoreRadius, fMulTrack, GetIndexInList() ) ;
261b1065 953}