]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSEvalRecPoint.cxx
fADCValuesHigh4x4 is not persistent
[u/mrichter/AliRoot.git] / PHOS / AliPHOSEvalRecPoint.cxx
CommitLineData
89308175 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
17/* $Log:
18 */
19//*-- Author: Boris Polichtchouk, IHEP
20//////////////////////////////////////////////////////////////////////////////
21// Reconstructed point operations for the Clusterization class for IHEP reconstruction.
22// Performs clusterization (collects neighbouring active cells)
23// It differs from AliPHOSClusterizerv1 in neighbour definition only
24
cbd576a6 25// ---- ROOT system ---
26#include "TDirectory.h"
27#include "TBranch.h"
28#include "TTree.h"
29#include "TROOT.h"
30#include "TFolder.h"
31
32// --- AliRoot header files ---
351dd634 33#include "AliLog.h"
88cb7938 34#include "AliConfig.h"
e957fea8 35#include "AliPHOSDigit.h"
88cb7938 36#include "AliPHOSClusterizer.h"
cbd576a6 37#include "AliPHOSEvalRecPoint.h"
38#include "AliRun.h"
88cb7938 39#include "AliPHOSLoader.h"
cbd576a6 40#include "AliPHOSRecCpvManager.h"
41#include "AliPHOSRecEmcManager.h"
42#include "AliPHOSDigitizer.h"
e957fea8 43#include "AliPHOSGeometry.h"
cbd576a6 44
45// --- Standard library ---
cbd576a6 46
47
48ClassImp(AliPHOSEvalRecPoint)
49
e191bb57 50 AliPHOSEvalRecPoint::AliPHOSEvalRecPoint(): fEventFolderName(AliConfig::GetDefaultEventFolderName())
cbd576a6 51{
89308175 52 // default ctor
cbd576a6 53 fParent=-333;
54 fChi2Dof=-111;
55 fIsCpv = kTRUE;
56 fIsEmc = kFALSE;
57}
58
89308175 59AliPHOSEvalRecPoint::AliPHOSEvalRecPoint(Bool_t cpv, AliPHOSEvalRecPoint* parent) : AliPHOSCpvRecPoint()
cbd576a6 60{
89308175 61 // ctor
cbd576a6 62 fParent=-333;
63 fChi2Dof=-111;
64
65// fParent=parent;
66 TObjArray* wPool = (TObjArray*)GetWorkingPool();
67 if(!wPool) {
e957fea8 68 Fatal("ctor", "Couldn't find working pool") ;
cbd576a6 69 }
70
71 fParent = wPool->IndexOf((TObject*)parent);
72 fChi2Dof = parent->Chi2Dof();
73
74 if(cpv) {
75 fIsEmc = kFALSE;
76 fIsCpv = kTRUE;
77 }
78 else {
79 fIsEmc = kTRUE;
80 fIsCpv = kFALSE;
81 }
82
83 // Add itself to working pool
84 AddToWorkingPool((TObject*)this);
85
86}
87
e191bb57 88AliPHOSEvalRecPoint::AliPHOSEvalRecPoint(Int_t i, Bool_t cpv) : fEventFolderName(AliConfig::GetDefaultEventFolderName())
cbd576a6 89{
89308175 90 // ctor
cbd576a6 91 fChi2Dof=-111;
92 fParent=-333;
93
94 AliPHOSEmcRecPoint* rp=0;
95
88cb7938 96 AliPHOSLoader* fLoader = AliPHOSLoader::GetPHOSLoader(fEventFolderName);
cbd576a6 97
98 if(cpv) {
88cb7938 99 rp = (AliPHOSCpvRecPoint*)fLoader->CpvRecPoints()->At(i);
cbd576a6 100 fIsEmc = kFALSE;
101 fIsCpv = kTRUE;
102 }
103 else {
88cb7938 104 rp = (AliPHOSEmcRecPoint*)fLoader->EmcRecPoints()->At(i);
cbd576a6 105 fIsEmc = kTRUE;
106 fIsCpv = kFALSE;
107 }
108
89308175 109 Int_t* digits = rp->GetDigitsList();
110 Float_t* energies = rp->GetEnergiesList();
cbd576a6 111 Int_t nDigits = rp->GetMultiplicity();
112
113 for(Int_t iDigit=0; iDigit<nDigits; iDigit++) {
89308175 114 AliPHOSDigit* digit = (AliPHOSDigit*)fLoader->Digits()->At( digits[iDigit] );
115 Float_t eDigit = energies[iDigit];
cbd576a6 116 this->AddDigit(*digit,eDigit);
117 }
118
119 TVector3 locpos;
120 rp->GetLocalPosition(locpos);
121 fLocPos = locpos;
122
123 // Add itself to working pool
124 AddToWorkingPool((TObject*)this);
125
126}
127
128AliPHOSClusterizer* AliPHOSEvalRecPoint::GetClusterizer()
129{
89308175 130 // returns clusterizer task
cbd576a6 131 TFolder* aliceF = (TFolder*)gROOT->FindObjectAny("YSAlice");
132 TFolder* wPoolF = (TFolder*)aliceF->FindObject("WhiteBoard/RecPoints/PHOS/SmP");
133 AliPHOSClusterizer* clu = (AliPHOSClusterizer*)wPoolF->FindObject("PHOS:clu-v1");
134 if(!clu) {
e957fea8 135 Fatal("GetClusterizer", "Couldn't find Clusterizer") ;
cbd576a6 136 }
137
138 return clu;
139}
140
141Bool_t AliPHOSEvalRecPoint::TooClose(AliPHOSRecPoint* pt) const
142{
89308175 143 // check if a rec.point pt is too close to this one
144 TVector3 herPos;
145 TVector3 myPos;
146 pt->GetLocalPosition(herPos);
147 this->GetLocalPosition(myPos);
148 Float_t dx = herPos.X() - myPos.X();
149 Float_t dz = herPos.Z() - myPos.Z();
cbd576a6 150 Float_t dr = TMath::Sqrt(dx*dx + dz*dz);
151
152 if(dr<GetReconstructionManager()->MergeGammasMinDistanceCut())
153 return kTRUE;
154 else
155 return kFALSE;
156
157}
158
159Bool_t AliPHOSEvalRecPoint::NeedToSplit() const
160{
89308175 161 // rec.point needs to be split
cbd576a6 162 return kFALSE;
163}
164
165void AliPHOSEvalRecPoint::DeleteParent()
166{
89308175 167 // delete parent
cbd576a6 168 fParent=-333;
169}
170
171void AliPHOSEvalRecPoint::UpdateWorkingPool()
172{
89308175 173 // update pool of rec.points
c9eeb00e 174 Int_t i; //loop variable
cbd576a6 175
c9eeb00e 176 for(i=0; i<this->InWorkingPool(); i++) {
cbd576a6 177 AliPHOSEvalRecPoint* parent = (AliPHOSEvalRecPoint*)GetFromWorkingPool(i);
178 TObjArray children;
179 Int_t nChild = parent->HasChild(children);
180 for(Int_t iChild=0; iChild<nChild; iChild++)
181 {
89308175 182 ((AliPHOSEvalRecPoint*)children.At(iChild))->DeleteParent();
cbd576a6 183 }
184
185 if(nChild) {
186 RemoveFromWorkingPool(parent);
187 delete parent;
188 }
189
190 }
191
c9eeb00e 192 for(i=0; i<this->InWorkingPool(); i++) {
cbd576a6 193 AliPHOSEvalRecPoint* weak = (AliPHOSEvalRecPoint*)GetFromWorkingPool(i);
194 if (weak->KillWeakPoint()) delete weak;
195 }
196
c9eeb00e 197 for(i=0; i<this->InWorkingPool(); i++) {
cbd576a6 198 AliPHOSEvalRecPoint* close = (AliPHOSEvalRecPoint*)GetFromWorkingPool(i);
199 close->MergeClosePoint();
200 }
201
c9eeb00e 202 for(i=0; i<this->InWorkingPool(); i++)
cbd576a6 203 ((AliPHOSEvalRecPoint*)AliPHOSEvalRecPoint::GetFromWorkingPool(i))->SetIndexInList(i);
204
205}
206
207Int_t AliPHOSEvalRecPoint::HasChild(TObjArray& children)
208{
89308175 209 // returns the number of children
cbd576a6 210 for(Int_t iChild=0; iChild<InWorkingPool(); iChild++)
211 {
212 AliPHOSEvalRecPoint* child = (AliPHOSEvalRecPoint*)GetFromWorkingPool(iChild);
213 TObject* parent = (TObject*)child->Parent();
214 TObject* me = (TObject*)this;
215 if(parent==me) children.Add(child);
216 }
217
218 return children.GetEntries();
219}
220
221void AliPHOSEvalRecPoint::Init()
222{
89308175 223 // initialization
cbd576a6 224 AliPHOSClusterizer* clusterizer = GetClusterizer();
225 if(!clusterizer) {
e957fea8 226 Fatal("Init", "Cannot get clusterizer") ;
cbd576a6 227 }
228
88cb7938 229 TClonesArray* digits = AliPHOSLoader::GetPHOSLoader(fEventFolderName)->Digits();
89308175 230 Float_t logWeight=0;
cbd576a6 231
232 if(this->IsEmc()) {
89308175 233 logWeight = clusterizer->GetEmcLogWeight();
cbd576a6 234 }
235 else {
89308175 236 logWeight = clusterizer->GetCpvLogWeight();
cbd576a6 237 }
238
89308175 239 EvalLocalPosition(logWeight,digits); // evaluate initial position
cbd576a6 240}
241
242
243void AliPHOSEvalRecPoint::MakeJob()
244{
245 // Reconstruction algoritm implementation.
246
247 AliPHOSRecManager* recMng = GetReconstructionManager();
248
249 Init();
250
251 UnfoldLocalMaxima();
252
253 TObjArray children;
254 Int_t nChild = HasChild(children);
255
256 if(!nChild) {
257 EvaluatePosition();
258 if(Chi2Dof()>recMng->OneGamChisqCut()) SplitMergedShowers();
259 }
260
261 for(Int_t iChild=0; iChild<nChild; iChild++) {
262 AliPHOSEvalRecPoint* child = (AliPHOSEvalRecPoint*)children.At(iChild);
263 child->EvaluatePosition();
264
265 if(child->Chi2Dof()>recMng->OneGamChisqCut())
266 child->SplitMergedShowers();
267 }
268
269}
270
271void AliPHOSEvalRecPoint::InitTwoGam(Float_t* gamma1, Float_t* gamma2)
272{
273 //Compute start values for two gamma fit algorithm.
274 // gamma1[0], gamma1[1], gamma1[2] are Energy,x,z of the reconstructed "gammas".
275
276
277 TVector3 lpos; // start point choosing.
278 GetLocalPosition(lpos);
279 Float_t xx = lpos.Z();
280 Float_t yy = lpos.X();
89308175 281 Float_t e = GetEnergy();
cbd576a6 282
351dd634 283 AliInfo(Form("(x,z,e)[old] = (%f, %f, %f)", yy, xx, e)) ;
cbd576a6 284
89308175 285// xx = XY(xx/e);
286// yy = XY(yy/e);
cbd576a6 287
288
289 Float_t eDigit ;
290 AliPHOSDigit * digit ;
291 Int_t nDigits = GetMultiplicity();
89308175 292 Int_t * digits = GetDigitsList();
293 Float_t * energies = GetEnergiesList();
cbd576a6 294
295 Float_t ix ;
296 Float_t iy ;
297 Int_t relid[4] ;
298
299 Float_t exx = 0;
300 Float_t eyy = 0;
301 Float_t exy = 0;
302 Float_t sqr;
303 Float_t cos2fi = 1.;
304
88cb7938 305 AliPHOSLoader* fLoader = AliPHOSLoader::GetPHOSLoader(fEventFolderName);
306 const AliPHOSGeometry* fGeom = fLoader->PHOSGeometry();
cbd576a6 307
c9eeb00e 308 Int_t iDigit; //loop variable
309
310 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++)
cbd576a6 311 {
89308175 312 digit = (AliPHOSDigit*)fLoader->Digits()->At( digits[iDigit] );
313 eDigit = energies[iDigit];
cbd576a6 314 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
315 fGeom->RelPosInModule(relid, iy, ix);
316
317 Float_t dx = ix - xx;
318 Float_t dy = iy - yy;
319 exx += eDigit*dx*dx;
320 eyy += eDigit*dy*dy;
321 exy += eDigit*dx*dy;
322
323 }
324
325 sqr = TMath::Sqrt(4.*exy*exy + (exx-eyy)*(exx-eyy));
326 Float_t euu = (exx+eyy+sqr)/2.;
327 if(sqr>1.e-10) cos2fi = (exx - eyy)/sqr;
328 Float_t cosfi = TMath::Sqrt((1.+cos2fi)/2.);
329 Float_t sinfi = TMath::Sqrt((1.-cos2fi)/2.);
330 if(exy<0) sinfi = -sinfi;
331
332 Float_t eu3 = 0;
c9eeb00e 333 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++)
cbd576a6 334 {
89308175 335 digit = (AliPHOSDigit*)fLoader->Digits()->At( digits[iDigit] );
336 eDigit = energies[iDigit];
cbd576a6 337 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
338 fGeom->RelPosInModule(relid, iy, ix);
339
340 Float_t dx = ix - xx;
341 Float_t dy = iy - yy;
342 Float_t du = dx*cosfi + dy*sinfi;
343 eu3 += eDigit*du*du*du;
344 }
345
89308175 346 Float_t c = e*eu3*eu3/(euu*euu*euu)/2.;
cbd576a6 347 Float_t sign = 1.;
348 if(eu3<0) sign = -1.;
349 Float_t r = 1.+ c + sign*TMath::Sqrt(2.*c + c*c);
350 Float_t u = 0;
351 if(TMath::Abs(r-1.)>0.1) u = eu3/euu*(r+1.)/(r-1.);
89308175 352 if(TMath::Abs(r-1.)<0.1) u = TMath::Sqrt(sqr/e/r)*(1.+r);
cbd576a6 353
89308175 354 Float_t e2c = e/(1.+r);
355 Float_t e1c = e-e2c;
cbd576a6 356 Float_t u1 = -u/(1.+r);
357 Float_t u2 = u+u1;
358
359 Float_t x1c = xx+u1*cosfi;
360 Float_t y1c = yy+u1*sinfi;
361 Float_t x2c = xx+u2*cosfi;
362 Float_t y2c = yy+u2*sinfi;
363
364// printf("e1c -> %f\n",e1c);
365// printf("x1c -> %f\n",x1c);
366// printf("y1c -> %f\n",y1c);
367// printf("e2c -> %f\n",e2c);
368// printf("x2c -> %f\n",x2c);
369// printf("y2c -> %f\n",y2c);
370
371 gamma1[0] = e1c;
372 gamma1[1] = y1c;
373 gamma1[2] = x1c;
374
375 gamma2[0] = e2c;
376 gamma2[1] = y2c;
377 gamma2[2] = x2c;
378
379}
380
381void AliPHOSEvalRecPoint::TwoGam(Float_t* gamma1, Float_t* gamma2)
382{
383 //Fitting algorithm for the two very closed gammas
384 //that merged into the cluster with one maximum.
385 // Starting points gamma1 and gamma2 must be provided before ( see InitTwoGam)
386 //Set chisquare of the fit.
387
388
389 Float_t st0 = GetReconstructionManager()->TwoGamInitialStep();
390 Float_t chmin = GetReconstructionManager()->TwoGamChisqMin();
391 Float_t emin = GetReconstructionManager()->TwoGamEmin();
392 Float_t stpmin = GetReconstructionManager()->TwoGamStepMin();
89308175 393 Int_t nIter = GetReconstructionManager()->TwoGamNumOfIterations(); // Number of iterations.
cbd576a6 394
395 Float_t chisq = 100.; //Initial chisquare.
396
397 Int_t nadc = GetMultiplicity();
398 if(nadc<3)
399 fChi2Dof= -111.;
400
401 Int_t dof = nadc - 5;
402 if(dof<1) dof=1;
403 Float_t chstop = chmin*dof;
404
405 Float_t ch = 1.e+20;
406 Float_t st = st0;
407 Float_t grx1 = 0.;
408 Float_t gry1 = 0.;
409 Float_t grx2 = 0.;
410 Float_t gry2 = 0.;
411 Float_t gre = 0.;
412 Float_t gr = 1.;
413 Float_t ee1=0,xx1=0,yy1=0,ee2=0,xx2=0,yy2=0,cosi;
414
415 Float_t e1c = gamma1[0];
416 Float_t y1c = gamma1[1];
417 Float_t x1c = gamma1[2];
418
419 Float_t e2c = gamma2[0];
420 Float_t y2c = gamma2[1];
421 Float_t x2c = gamma2[2];
422
89308175 423 Float_t e = GetEnergy();
cbd576a6 424
425 Float_t eDigit ;
426 AliPHOSDigit * digit ;
427 Int_t nDigits = GetMultiplicity();
89308175 428 Int_t * digits = GetDigitsList();
429 Float_t * energies = GetEnergiesList();
cbd576a6 430
431 Float_t ix ;
432 Float_t iy ;
433 Int_t relid[4] ;
434
88cb7938 435 AliPHOSLoader* fLoader = AliPHOSLoader::GetPHOSLoader(fEventFolderName);
436 const AliPHOSGeometry* fGeom = fLoader->PHOSGeometry();
cbd576a6 437
89308175 438 for(Int_t iter=0; iter<nIter; iter++)
cbd576a6 439 {
440 Float_t chisqc = 0.;
441 Float_t grx1c = 0.;
442 Float_t gry1c = 0.;
443 Float_t grx2c = 0.;
444 Float_t gry2c = 0.;
445 Float_t grec = 0.;
446
447 for(Int_t iDigit = 0 ; iDigit < nDigits ; iDigit ++)
448 {
89308175 449 digit = (AliPHOSDigit*)fLoader->Digits()->At( digits[iDigit] );
450 eDigit = energies[iDigit];
cbd576a6 451 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
452 fGeom->RelPosInModule(relid, iy, ix);
453
454 Float_t a1,gx1,gy1;
455 Float_t a2,gx2,gy2;
456
457 Float_t dx1 = x1c - ix;
458 Float_t dy1 = y1c - iy;
351dd634 459
cbd576a6 460 GetReconstructionManager()->AG(e1c,dx1,dy1,a1,gx1,gy1);
461
462 Float_t dx2 = x2c - ix;
463 Float_t dy2 = y2c - iy;
351dd634 464
cbd576a6 465 GetReconstructionManager()->AG(e2c,dx2,dy2,a2,gx2,gy2);
466
89308175 467 Float_t a = a1+a2;
468// Float_t D = Const*a*(1. - a/e);
cbd576a6 469// if(D<0) D=0;
470
471// // D = 9.; // ????
472
89308175 473// Float_t da = a - eDigit;
cbd576a6 474// chisqc += da*da/D;
475// Float_t dd = da/D;
89308175 476// dd = dd*(2.-dd*Const*(1.-2.*a/e));
cbd576a6 477
478 Float_t dd;
89308175 479 chisqc += GetReconstructionManager()->TwoGamChi2(a,eDigit,e,dd);
cbd576a6 480
481 grx1c += gx1*dd;
482 gry1c += gy1*dd;
483 grx2c += gx2*dd;
484 gry2c += gy2*dd;
89308175 485 grec += (a1/e1c - a2/e2c)*e*dd;
cbd576a6 486
487 }
488
489 Float_t grc = TMath::Sqrt(grx1c*grx1c + gry1c*gry1c + grx2c*grx2c + gry2c*gry2c);
490 if(grc<1.e-10) grc=1.e-10;
491
492 Float_t sc = 1. + chisqc/ch;
493 st = st/sc;
494
495 if(chisqc>ch)
496 goto loop20;
497 cosi = (grx1*grx1c + gry1*gry1c + grx2*grx2c + gry2*gry2c + gre*grec)/gr/grc;
498 st = st*sc/(1.4 - cosi);
499
500 ee1 = e1c;
501 xx1 = x1c;
502 yy1 = y1c;
503 ee2 = e2c;
504 xx2 = x2c;
505 yy2 = y2c;
506
507 ch = chisqc;
508
509 if(ch<chstop)
510 goto loop101;
511
512 grx1 = grx1c;
513 gry1 = gry1c;
514 grx2 = grx2c;
515 gry2 = gry2c;
516 gre = grec;
517 gr = grc;
518
519 loop20: ;
520 Float_t step = st*gr;
521
351dd634 522 AliInfo(Form("Iteration %d dof %d chisq/dof %f chstop/dof %f step %d stpmin %d",
523 iter, dof, ch/dof, chstop/dof, step, stpmin)) ;
cbd576a6 524
525
526 if(step<stpmin)
527 goto loop101;
528
89308175 529 Float_t de = st*gre*e;
cbd576a6 530 e1c = ee1 - de;
531 e2c = ee2 + de;
532
533 if( (e1c>emin) && (e2c>emin) )
534 goto loop25;
535 st = st/2.;
536 goto loop20;
537
538 loop25: ;
539 x1c = xx1 - st*grx1;
540 y1c = yy1 - st*gry1;
541 x2c = xx2 - st*grx2;
542 y2c = yy2 - st*gry2;
543
544
545 }
546
547 loop101:
548
549// if(ch>chisq*(nadc-2)-delch)
550// return ch/dof;
551
552 chisq = ch/dof;
553 gamma1[0] = ee1;
554 gamma1[1] = yy1;
555 gamma1[2] = xx1;
556
557 gamma2[0] = ee2;
558 gamma2[1] = yy2;
559 gamma2[2] = xx2;
560
89308175 561 Float_t x1New = yy1;
562 Float_t z1New = xx1;
563 Float_t e1New = ee1;
564 Float_t x2New = yy2;
565 Float_t z2New = xx2;
566 Float_t e2New = ee2;
cbd576a6 567
21cd0c07 568 TString message ;
89308175 569 message = " (x,z,e)[1 fit] = (%f, %f, %f)\n" ;
570 message = " (x,z,e)[2 fit] = (%f, %f, %f)\n" ;
351dd634 571 AliInfo(Form(message.Data(),
89308175 572 x1New, z1New, e1New,
351dd634 573 x2New, z2New, e2New)) ;
cbd576a6 574
575 fChi2Dof = chisq;
576
577}
578
579void AliPHOSEvalRecPoint::UnfoldTwoMergedPoints(Float_t* gamma1, Float_t* gamma2)
580{
581 //Unfold TWO merged rec. points in the case when cluster has only one maximum,
582 //but it's fitting to the one gamma shower is too bad.
583 // Use TwoGam() to estimate the positions and energies of merged points.
584
585
89308175 586 Int_t nMax = 2;
cbd576a6 587 Float_t* gamma;
588
89308175 589 Int_t* digits = GetDigitsList();
cbd576a6 590 Int_t nDigits = GetMultiplicity();
89308175 591 Float_t* energies = GetEnergiesList();
cbd576a6 592 Float_t* eFit = new Float_t[nDigits];
593
88cb7938 594 AliPHOSLoader* fLoader = AliPHOSLoader::GetPHOSLoader(fEventFolderName);
595 const AliPHOSGeometry* fGeom = fLoader->PHOSGeometry();
cbd576a6 596
597 for(Int_t iDigit=0; iDigit<nDigits; iDigit++)
598 {
89308175 599 AliPHOSDigit* digit = (AliPHOSDigit*)fLoader->Digits()->At( digits[iDigit] );
cbd576a6 600 Int_t relid[4] ;
601 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
602 Float_t x,z;
603 fGeom->RelPosInModule(relid, x, z);
604
605 Float_t gain = 0.;
89308175 606 for(Int_t iMax=0; iMax<nMax; iMax++)
cbd576a6 607 {
608 if(iMax==0)
609 gamma = gamma1;
610 else
611 gamma = gamma2;
612
613 Float_t eMax = gamma[0];
614 Float_t xMax = gamma[1];
615 Float_t zMax = gamma[2];
616
617 Float_t dx = xMax - x;
618 Float_t dz = zMax - z;
89308175 619 Float_t amp,gx,gy;
620 GetReconstructionManager()->AG(eMax,dz,dx,amp,gx,gy);
621 gain += amp;
cbd576a6 622 }
623
624 eFit[iDigit] = gain;
625 }
626
627
89308175 628 for( Int_t iMax=0; iMax<nMax; iMax++)
cbd576a6 629 {
630 if(iMax==0)
631 gamma = gamma1;
632 else
633 gamma = gamma2;
634
635 Float_t eMax = gamma[0];
636 Float_t xMax = gamma[1];
637 Float_t zMax = gamma[2];
638
639 AliPHOSEvalRecPoint* newRP = new AliPHOSEvalRecPoint(IsCPV(),this);
640 TVector3 newpos(xMax,0,zMax);
641 newRP->SetLocalPosition(newpos);
642
643 for( Int_t iDigit = 0 ; iDigit < nDigits ; iDigit ++)
644 {
89308175 645 AliPHOSDigit* digit = (AliPHOSDigit*)fLoader->Digits()->At( digits[iDigit] );
646 Float_t eDigit = energies[iDigit];
cbd576a6 647 Int_t relid[4] ;
648 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
649 Float_t ix,iz;
650 fGeom->RelPosInModule(relid, ix, iz);
651
652 Float_t dx = xMax - ix;
653 Float_t dz = zMax - iz;
89308175 654 Float_t singleShowerGain,gxMax,gyMax;
655 GetReconstructionManager()->AG(eMax,dz,dx,singleShowerGain,gxMax,gyMax);
656 Float_t totalGain = eFit[iDigit];
657 Float_t ratio = singleShowerGain/totalGain;
cbd576a6 658 eDigit = eDigit*ratio;
659 newRP->AddDigit(*digit,eDigit);
660 }
351dd634 661 AliInfo(Form("======= Split: daughter rec point %d =================",
662 iMax)) ;
e957fea8 663 newRP->Print();
cbd576a6 664
665 }
666
667 delete[] eFit;
cbd576a6 668
669
670}
671
672
673void AliPHOSEvalRecPoint::EvaluatePosition()
674{
675 // One gamma fit algorithm.
676 // Set chisq/dof of the fit.
677 // gamma1[0], gamma1[1], gamma1[2] are Energy,x,z of the reconstructed gamma, respectively.
678
679 Int_t nDigits = GetMultiplicity();
680 if(nDigits<2)
681 return;
682
89308175 683 Int_t nIter = GetReconstructionManager()->OneGamNumOfIterations(); // number of iterations
684 Float_t st0 = GetReconstructionManager()->OneGamInitialStep(); // initial step
685// const Float_t stpMin = 0.005;
686 Float_t stpMin = GetReconstructionManager()->OneGamStepMin();
cbd576a6 687 Float_t chmin = GetReconstructionManager()->OneGamChisqMin();
688
689 TVector3 locpos;
690 AliPHOSDigit* digit;
691 Float_t eDigit;
692 Int_t relid[4] ;
693 Float_t ix, iy;
694
695 GetLocalPosition(locpos);
89308175 696 Float_t e = GetEnergy();
cbd576a6 697 Float_t xc = locpos.Z();
698 Float_t yc = locpos.X();
699 Float_t dx,dy,gx,gy,grxc,gryc;
89308175 700 Float_t st = st0;
cbd576a6 701 Float_t chisq = 1.e+20;
702 Float_t gr = 1.;
703 Float_t grx = 0.;
704 Float_t gry = 0.;
705 Int_t dof = GetMultiplicity() - 2;
706 if(dof<1)
707 dof = 1;
708 Float_t chstop = chmin*dof;
709 Float_t cosi,x1=0,y1=0;
710 Float_t chisqc;
711
88cb7938 712 AliPHOSLoader* fLoader = AliPHOSLoader::GetPHOSLoader(fEventFolderName);
713 const AliPHOSGeometry* fGeom = fLoader->PHOSGeometry();
cbd576a6 714
89308175 715 for(Int_t iter=0; iter<nIter; iter++)
cbd576a6 716 {
717
718 chisqc = 0.;
719 grxc = 0.;
720 gryc = 0.;
721 for(Int_t iDigit = 0 ; iDigit < nDigits ; iDigit ++)
722 {
723
89308175 724 Float_t* energies = GetEnergiesList();
725 Int_t* digits = GetDigitsList();
726 digit = (AliPHOSDigit*)fLoader->Digits()->At( digits[iDigit] );
727 eDigit = energies[iDigit];
cbd576a6 728 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
729 fGeom->RelPosInModule(relid, iy, ix);
730
731 dx = xc - ix;
732 dy = yc - iy;
733
734 if(!dx) dx=dy;
735 if(!dy) dy=dx;
736
89308175 737 Float_t a;
738 GetReconstructionManager()->AG(e,dx,dy,a,gx,gy);
cbd576a6 739 Float_t dd;
351dd634 740 AliInfo(Form(" (ix iy xc yc dx dy) %f %f %f %f %f %f",
741 ix, iy, xc, yc, dx, dy)) ;
89308175 742 Float_t chi2dg = GetReconstructionManager()->OneGamChi2(a,eDigit,e,dd);
cbd576a6 743
744 // Exclude digit with too large chisquare.
745 if(chi2dg > 10) { continue; }
746
747 chisqc += chi2dg;
748 grxc += gx*dd;
749 gryc += gy*dd;
750
751 }
752
753 Float_t grc = TMath::Sqrt(grxc*grxc + gryc*gryc);
754 if(grc<1.e-10) grc=1.e-10;
755 Float_t sc = 1. + chisqc/chisq;
351dd634 756 AliInfo(Form(" chisq: %f", chisq)) ;
cbd576a6 757 st = st/sc;
758 if(chisqc>chisq)
759 goto loop20;
760 cosi = (grx*grxc + gry*gryc)/gr/grc;
761 st = st*sc/(1.4 - cosi);
762 x1 = xc;
763 y1 = yc;
764 grx = grxc;
765 gry = gryc;
766 gr = grc;
767 chisq = chisqc;
768
769 if(chisq<chstop)
770 goto loop101;
771
772 loop20: ;
773 Float_t step = st*gr;
774
351dd634 775 AliInfo(Form(" Iteration %d dof %d chisq/dof %f chstop/dof %f step %d stpMin %d",
776 iter, dof, chisq/dof, chisq/dof, chstop/dof, step, stpMin)) ;
cbd576a6 777
778
89308175 779 if(step<stpMin)
cbd576a6 780 goto loop101;
781
782 if(step>1.)
783 st = 1./gr;
784 xc = x1 - st*grx;
785 yc = y1 - st*gry;
786 }
787
788
789 loop101:
790 chisq = chisq/dof;
791// if(chisq>Chsqcut)
792// {
793// // TwoGam();
794// }
795
796 Float_t gamma1[3];
89308175 797 gamma1[0] = e;
cbd576a6 798 gamma1[1] = y1;
799 gamma1[2] = x1;
800
801 TVector3 newpos(gamma1[1],0,gamma1[2]);
802 //SetLocalPosition(newpos);
803
804 fLocPos=newpos;
89308175 805 fAmp=e;
cbd576a6 806
807// TVector3 pos;
808// RP->GetLocalPosition(pos);
cbd576a6 809
810
cbd576a6 811
812 fChi2Dof = chisq;
813
814}
815
816
817Bool_t AliPHOSEvalRecPoint::KillWeakPoint()
818{
819 // Remove this point from further procession
820 // if it's energy is too small.
821
89308175 822 Float_t thr0 = GetReconstructionManager()->KillGamMinEnergy();
cbd576a6 823
89308175 824 if(GetEnergy()<thr0) {
351dd634 825 AliInfo(Form("+++++++ Killing this rec point ++++++++++")) ;
cbd576a6 826 RemoveFromWorkingPool(this);
827 return kTRUE;
828 }
829
830 return kFALSE;
831}
832
833
834void AliPHOSEvalRecPoint::SplitMergedShowers()
835{
836 // Split two very close rec. points.
837
838 if(GetMultiplicity()<2)
839 return;
840
841 Float_t gamma1[3];
842 Float_t gamma2[3];
843
844 InitTwoGam(gamma1,gamma2); // start points for fit
845 TwoGam(gamma1,gamma2); // evaluate the positions and energies
846 UnfoldTwoMergedPoints(gamma1,gamma2); // make the job
847
848}
849
850
851void AliPHOSEvalRecPoint::MergeClosePoint()
852{
89308175 853 // merge rec.points if they are too close
88cb7938 854 AliPHOSLoader* fLoader = AliPHOSLoader::GetPHOSLoader(fEventFolderName);
855// AliPHOSDigitizer* digitizer = fLoader->Digitizer();
cbd576a6 856// Float_t fPedestal = digitizer->GetPedestal(); // YVK 30.09.2001
857// Float_t fSlope = digitizer->GetSlope();
858
859 for (Int_t i=0;i<InWorkingPool(); i++)
860 {
861 TObject* obj = GetFromWorkingPool(i);
366ed113 862 if(!((TObject*)this)->IsEqual(obj))
cbd576a6 863 {
864 AliPHOSRecPoint* rp = (AliPHOSRecPoint*)obj;
865 if(GetPHOSMod() == rp->GetPHOSMod())
866 {
867 if(TooClose(rp))
868 {
351dd634 869 AliInfo(Form("+++++++ Merging point 1: ++++++")) ;
e957fea8 870 this->Print();
351dd634 871 AliInfo(Form("+++++++ and point 2: ++++++++++")) ;
e957fea8 872 ((AliPHOSEvalRecPoint*)rp)->Print();
cbd576a6 873
874 //merge two rec. points
875 TVector3 lpos1;
876 TVector3 lpos2;
877 this->GetLocalPosition(lpos1);
878 rp->GetLocalPosition(lpos2);
879
89308175 880 Int_t* digits = rp->GetDigitsList();
cbd576a6 881 Float_t dE = rp->GetEnergy()/(rp->GetEnergy()+this->GetEnergy());
89308175 882 Float_t newX = lpos1.X()*dE + lpos2.X()*(1.-dE);
883 Float_t newZ = lpos1.Z()*dE + lpos2.Z()*(1.-dE);
884 Float_t newE = rp->GetEnergy()+this->GetEnergy();
885 Float_t* energies = ((AliPHOSEmcRecPoint*)rp)->GetEnergiesList();
cbd576a6 886
887 for(Int_t iDigit=0; iDigit<rp->GetDigitsMultiplicity(); iDigit++)
888 {
89308175 889 AliPHOSDigit* digit = (AliPHOSDigit*)fLoader->Digits()->At(digits[iDigit]);
890 Float_t eDigit = energies[iDigit];
cbd576a6 891 this->AddDigit(*digit,eDigit);
892 }
893
89308175 894 TVector3 newpos(newX,0,newZ);
cbd576a6 895 fLocPos = newpos;
89308175 896 fAmp = newE;
cbd576a6 897 RemoveFromWorkingPool(rp);
898 delete rp;
899
351dd634 900 AliInfo(Form("++++++ Resulting point: ++++++++")) ;
e957fea8 901 this->Print();
cbd576a6 902
903 break;
904 }
905 }
906 }
907 }
908
909}
910
911Int_t AliPHOSEvalRecPoint::UnfoldLocalMaxima()
912{
913 // Make unfolding in the reconstruction point with several local maxima.
914 // Return the number of local maxima.
915
916 // if multiplicity less then 2 - nothing to unfold
917 if(GetMultiplicity()<2) return 1;
918
a0636361 919 AliPHOSDigit * maxAt[1000];
cbd576a6 920 Float_t maxAtEnergy[1000];
89308175 921 Float_t locMaxCut, logWeight;
cbd576a6 922 Int_t relid[4] ;
923 Float_t xMax;
924 Float_t zMax;
925
cbd576a6 926 AliPHOSClusterizer* clusterizer = GetClusterizer();
927 if(!clusterizer) {
351dd634 928 AliFatal(Form("Cannot get clusterizer")) ;
cbd576a6 929 }
930
931 if(this->IsEmc()) {
89308175 932 locMaxCut = clusterizer->GetEmcLocalMaxCut();
933 logWeight = clusterizer->GetEmcLogWeight();
cbd576a6 934 }
935 else {
89308175 936 locMaxCut = clusterizer->GetCpvLocalMaxCut();
937 logWeight = clusterizer->GetCpvLogWeight();
cbd576a6 938 }
939
88cb7938 940 AliPHOSLoader* fLoader = AliPHOSLoader::GetPHOSLoader(fEventFolderName);
941 const AliPHOSGeometry* fGeom = fLoader->PHOSGeometry();
942 TClonesArray* digits = fLoader->Digits();
cbd576a6 943
944 // if number of local maxima less then 2 - nothing to unfold
89308175 945 Int_t nMax = GetNumberOfLocalMax(maxAt,maxAtEnergy,locMaxCut,digits);
946 if(nMax<2) return nMax;
cbd576a6 947
89308175 948 Int_t* digitsList = GetDigitsList();
cbd576a6 949 Int_t nDigits = GetMultiplicity();
89308175 950 Float_t* energies = GetEnergiesList();
cbd576a6 951 Float_t* eFit = new Float_t[nDigits];
952
c9eeb00e 953 Int_t iDigit; //loop variable
954
955 for(iDigit=0; iDigit<nDigits; iDigit++)
cbd576a6 956 {
957 eFit[iDigit] = 0.;
958 }
959
c9eeb00e 960 for(iDigit=0; iDigit<nDigits; iDigit++)
cbd576a6 961 {
962
89308175 963 AliPHOSDigit* digit = (AliPHOSDigit*)fLoader->Digits()->At( digitsList[iDigit] );
cbd576a6 964 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
965 Float_t x,z;
966 fGeom->RelPosInModule(relid, x, z);
967
89308175 968 for(Int_t iMax=0; iMax<nMax; iMax++)
cbd576a6 969 {
a0636361 970 AliPHOSDigit* digitMax = maxAt[iMax];
cbd576a6 971 Float_t eMax = maxAtEnergy[iMax];
972 fGeom->AbsToRelNumbering(digitMax->GetId(), relid) ;
973 fGeom->RelPosInModule(relid, xMax, zMax);
974 Float_t dx = xMax - x;
975 Float_t dz = zMax - z;
89308175 976 Float_t amp,gx,gy;
977 GetReconstructionManager()->AG(eMax,dz,dx,amp,gx,gy);
978// amp = amp + 0.5;
979 eFit[iDigit] += amp;
cbd576a6 980 }
981 }
982
983
89308175 984 for(Int_t iMax=0; iMax<nMax; iMax++)
cbd576a6 985 {
a0636361 986 AliPHOSDigit* digitMax = maxAt[iMax];
cbd576a6 987 fGeom->AbsToRelNumbering(digitMax->GetId(), relid) ;
988 fGeom->RelPosInModule(relid, xMax, zMax);
989 Float_t eMax = maxAtEnergy[iMax];
990
991 AliPHOSEvalRecPoint* newRP = new AliPHOSEvalRecPoint(IsCPV(),this);
992 newRP->AddDigit(*digitMax,maxAtEnergy[iMax]);
993
994 //Neighbous ( matrix 3x3 around the local maximum)
995 for(Int_t iDigit=0; iDigit<nDigits; iDigit++)
996 {
89308175 997 AliPHOSDigit* digit = (AliPHOSDigit*)fLoader->Digits()->At( digitsList[iDigit] );
998 Float_t eDigit = energies[iDigit];
cbd576a6 999 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
1000 Float_t ix,iz;
1001 fGeom->RelPosInModule(relid, ix, iz);
1002
1003 if(AreNeighbours(digitMax,digit))
1004 {
1005 Float_t dx = xMax - ix;
1006 Float_t dz = zMax - iz;
89308175 1007 Float_t singleShowerGain,gxMax,gyMax;
1008 GetReconstructionManager()->AG(eMax,dz,dx,singleShowerGain,gxMax,gyMax);
1009 Float_t totalGain = eFit[iDigit];
1010 Float_t ratio = singleShowerGain/totalGain;
351dd634 1011 AliInfo(Form(" ratio -> %f", ratio)) ;
cbd576a6 1012 eDigit = eDigit*ratio;
1013 newRP->AddDigit(*digit,eDigit);
1014 }
1015 }
1016
89308175 1017 newRP->EvalLocalPosition(logWeight,digits);
351dd634 1018 AliInfo(Form("======= Unfold: daughter rec point %d =================",
1019 iMax)) ;
e957fea8 1020 newRP->Print();
cbd576a6 1021 }
1022
1023// RemoveFromWorkingPool(this);
1024
1025 delete[] eFit;
cbd576a6 1026
89308175 1027 return nMax;
cbd576a6 1028
1029}
1030
e957fea8 1031void AliPHOSEvalRecPoint::PrintPoint()
cbd576a6 1032{
89308175 1033 // print rec.point to stdout
e957fea8 1034 AliPHOSCpvRecPoint::Print();
cbd576a6 1035
1036 TVector3 lpos;
1037 GetLocalPosition(lpos);
1038
21cd0c07 1039 TString message ;
1040 message = " Chi2/dof = %f" ;
1041 message += " Local (x,z) = (%f, %f) in module %d" ;
351dd634 1042 AliInfo(Form(message.Data(), Chi2Dof(), lpos.X(), lpos.Z(), GetPHOSMod())) ;
21cd0c07 1043
cbd576a6 1044}
1045
1046AliPHOSRecManager* AliPHOSEvalRecPoint::GetReconstructionManager() const
1047{
89308175 1048 // returns reconstruction manager
cbd576a6 1049 TFolder* aliceF = (TFolder*)gROOT->FindObjectAny("YSAlice");
1050 TFolder* wPoolF = (TFolder*)aliceF->FindObject("WhiteBoard/RecPoints/PHOS/SmP");
1051 AliPHOSRecManager* recMng = (AliPHOSRecManager*)wPoolF->FindObject("AliPHOSRecManager");
1052 if(!recMng) {
351dd634 1053 AliFatal(Form("Couldn't find Reconstruction Manager")) ;
cbd576a6 1054 }
1055
1056 return recMng;
1057}
1058
1059
1060AliPHOSRecPoint* AliPHOSEvalRecPoint::Parent()
1061{
89308175 1062 // returns a parent
cbd576a6 1063 if(fParent<0) return NULL;
1064 else
1065 return (AliPHOSRecPoint*)GetFromWorkingPool(fParent);
1066// return fParent;
1067}
1068
1069Float_t AliPHOSEvalRecPoint::Chi2Dof() const
1070{
89308175 1071 // returns a chi^2 per degree of freedom
cbd576a6 1072 return fChi2Dof;
1073}
1074
1075const TObject* AliPHOSEvalRecPoint::GetWorkingPool()
1076{
89308175 1077 // returns a pool of rec.points
cbd576a6 1078 TFolder* aliceF = (TFolder*)gROOT->FindObjectAny("YSAlice");
1079 TFolder* wPoolF = (TFolder*)aliceF->FindObject("WhiteBoard/RecPoints/PHOS/SmP");
1080 TObject* wPool = wPoolF->FindObject("SmartPoints");
1081 if(!wPool) {
351dd634 1082 AliFatal(Form("Couldn't find Working Pool")) ;
cbd576a6 1083 }
1084
1085 return wPool;
1086}
1087
1088void AliPHOSEvalRecPoint::AddToWorkingPool(TObject* obj)
1089{
89308175 1090 // add a rec.point to a pool
cbd576a6 1091 ((TObjArray*)GetWorkingPool())->Add(obj);
1092}
1093
1094TObject* AliPHOSEvalRecPoint::GetFromWorkingPool(Int_t i)
1095{
89308175 1096 // return a rec.point from a pool at an index i
cbd576a6 1097// return fWorkingPool->At(i);
1098 return ((TObjArray*)GetWorkingPool())->At(i);
1099}
1100
1101Int_t AliPHOSEvalRecPoint::InWorkingPool()
1102{
89308175 1103 // return the number of rec.points in a pool
cbd576a6 1104 return ((TObjArray*)GetWorkingPool())->GetEntries();
1105}
1106
1107void AliPHOSEvalRecPoint::RemoveFromWorkingPool(TObject* obj)
1108{
89308175 1109 // remove a rec.point from a pool
cbd576a6 1110 ((TObjArray*)GetWorkingPool())->Remove(obj);
1111 ((TObjArray*)GetWorkingPool())->Compress();
1112}
1113
1114void AliPHOSEvalRecPoint::PrintWorkingPool()
1115{
89308175 1116 // print pool of rec.points to stdout
e957fea8 1117 ((TObjArray*)GetWorkingPool())->Print();
cbd576a6 1118}