New ALIPHOSv1: includes the light transport in the Xtal
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrackSegmentMakerv1.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
16//_________________________________________________________________________
9f616d61 17// Algorithm class to construct track segments connection RecPoints in
18// EMCA and Ppsd. Unfolds also the clusters in EMCA.
19//*-- Author : D. Peressounko SUBATECH
d15a28e7 20//////////////////////////////////////////////////////////////////////////////
21
22// --- ROOT system ---
23
24#include "TObjArray.h"
25#include "TClonesArray.h"
9f616d61 26#include "TObjectTable.h"
d15a28e7 27
28// --- Standard library ---
29
9f616d61 30#include <iostream>
31#include <cassert>
d15a28e7 32
33// --- AliRoot header files ---
34
35#include "AliPHOSTrackSegmentMakerv1.h"
36#include "AliPHOSTrackSegment.h"
37#include "AliPHOSLink.h"
38#include "AliPHOSv0.h"
39#include "AliRun.h"
40
9f616d61 41extern void UnfoldingChiSquare(Int_t &NPar, Double_t *Grad, Double_t & fret, Double_t *x, Int_t iflag) ;
42
d15a28e7 43ClassImp( AliPHOSTrackSegmentMakerv1)
44
45
46//____________________________________________________________________________
9f616d61 47 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1()
d15a28e7 48{
9f616d61 49 // ctor
d15a28e7 50 fR0 = 4. ;
51 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
52 //clusters are sorted in "rows" and "columns" of width geom->GetCrystalSize(0),
53 fDelta = fR0 + geom->GetCrystalSize(0) ;
9f616d61 54 fMinuit = new TMinuit(100) ;
d15a28e7 55}
56
57//____________________________________________________________________________
9f616d61 58 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
59{
60 // dtor
61 delete fMinuit ;
62}
63//____________________________________________________________________________
d15a28e7 64Bool_t AliPHOSTrackSegmentMakerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
9f616d61 65 Int_t NPar, Float_t * FitParameters)
66{
9f616d61 67 // Calls TMinuit for fitting cluster with several maxima
6ad0bfa0 68
d15a28e7 69 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
d15a28e7 70
9f616d61 71 gMinuit->SetPrintLevel(-1) ; // No Printout
72 gMinuit->SetFCN(UnfoldingChiSquare) ; // To set the address of the minimization function
73 gMinuit->SetObjectFit(emcRP) ; // To tranfer pointer to UnfoldingChiSquare
74
75 // filling initial values for fit parameters
d15a28e7 76 AliPHOSDigit * digit ;
9f616d61 77
78 Int_t ierflg = 0;
79 Int_t index = 0 ;
d15a28e7 80 Int_t NDigits = (Int_t) NPar / 3 ;
9f616d61 81
d15a28e7 82 Int_t iDigit ;
9f616d61 83
84
6ad0bfa0 85 for(iDigit = 0; iDigit < NDigits; iDigit++){
d15a28e7 86 digit = (AliPHOSDigit *) maxAt[iDigit];
87
88 Int_t RelId[4] ;
89 Float_t x ;
90 Float_t z ;
9f616d61 91 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
92 geom->RelPosInModule(RelId, x, z) ;
d15a28e7 93
94 Float_t Energy = maxAtEnergy[iDigit] ;
95
9f616d61 96 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
97 index++ ;
d15a28e7 98 if(ierflg != 0){
99 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
100 return kFALSE;
101 }
9f616d61 102 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
103 index++ ;
d15a28e7 104 if(ierflg != 0){
105 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
106 return kFALSE;
107 }
9f616d61 108 gMinuit->mnparm(index, "Energy", Energy , 0.05*Energy, 0., 4.*Energy, ierflg) ;
109 index++ ;
d15a28e7 110 if(ierflg != 0){
111 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : Energy = " << Energy << endl ;
112 return kFALSE;
6ad0bfa0 113 }
d15a28e7 114 }
115
9f616d61 116 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
117 // depends on it.
118 Double_t p1 = 1.0 ;
119 Double_t p2 = 0.0 ;
120
121 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TgMinuit to reduce function calls
122 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
d15a28e7 123 gMinuit->SetMaxIterations(5);
9f616d61 124 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
125 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
126 if(ierflg == 4){ // Minimum not found
127 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
d15a28e7 128 return kFALSE ;
129 }
130 for(index = 0; index < NPar; index++){
131 Double_t err ;
132 Double_t val ;
9f616d61 133 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
134 FitParameters[index] = val ;
d15a28e7 135 }
d15a28e7 136 return kTRUE;
9f616d61 137
d15a28e7 138}
9f616d61 139
d15a28e7 140//____________________________________________________________________________
141void AliPHOSTrackSegmentMakerv1::FillOneModule(DigitsList * Dl, RecPointsList * emcIn, TObjArray * emcOut,
142 RecPointsList * ppsdIn, TObjArray * ppsdOutUp,
9f616d61 143 TObjArray * ppsdOutLow, Int_t & PHOSMod, Int_t & emcStopedAt,
d15a28e7 144 Int_t & ppsdStopedAt)
9f616d61 145{
146 // Unfold clusters and fill xxxOut arrays with clusters from one PHOS module
147
148 AliPHOSEmcRecPoint * emcRecPoint ;
d15a28e7 149 AliPHOSPpsdRecPoint * ppsdRecPoint ;
150 Int_t index ;
6ad0bfa0 151
d15a28e7 152 Int_t NemcUnfolded = emcIn->GetEntries() ;
153 for(index = emcStopedAt; index < NemcUnfolded; index++){
d15a28e7 154 emcRecPoint = (AliPHOSEmcRecPoint *) (*emcIn)[index] ;
6ad0bfa0 155
d15a28e7 156 if(emcRecPoint->GetPHOSMod() != PHOSMod )
9f616d61 157 break ;
158
d15a28e7 159 Int_t NMultipl = emcRecPoint->GetMultiplicity() ;
6ad0bfa0 160 Int_t maxAt[NMultipl] ;
d15a28e7 161 Float_t maxAtEnergy[NMultipl] ;
9f616d61 162 Int_t Nmax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ;
9f616d61 163
6ad0bfa0 164 if(Nmax <= 1) // if cluster is very flat (no pronounced maximum) then Nmax = 0
d15a28e7 165 emcOut->Add(emcRecPoint) ;
166 else {
167 UnfoldClusters(Dl, emcIn, emcRecPoint, Nmax, maxAt, maxAtEnergy, emcOut) ;
168 emcIn->Remove(emcRecPoint);
169 emcIn->Compress() ;
170 NemcUnfolded-- ;
171 index-- ;
172 }
173 }
174 emcStopedAt = index ;
175
176 for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){
177 ppsdRecPoint = (AliPHOSPpsdRecPoint *) (*ppsdIn)[index] ;
9f616d61 178 if(ppsdRecPoint->GetPHOSMod() != PHOSMod )
179 break ;
d15a28e7 180 if(ppsdRecPoint->GetUp() )
181 ppsdOutUp->Add(ppsdRecPoint) ;
182 else
183 ppsdOutLow->Add(ppsdRecPoint) ;
184 }
185 ppsdStopedAt = index ;
6ad0bfa0 186
d15a28e7 187 emcOut->Sort() ;
188 ppsdOutUp->Sort() ;
6ad0bfa0 189 ppsdOutLow->Sort() ;
d15a28e7 190}
191//____________________________________________________________________________
192Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * EmcClu,AliPHOSPpsdRecPoint * PpsdClu, Bool_t &TooFar)
193{
194 Float_t R = fR0 ;
195
196 TVector3 vecEmc ;
197 TVector3 vecPpsd ;
198
199 EmcClu->GetLocalPosition(vecEmc) ;
200 PpsdClu->GetLocalPosition(vecPpsd) ;
201 if(EmcClu->GetPHOSMod() == PpsdClu->GetPHOSMod()){
202 if(vecPpsd.X() >= vecEmc.X() - fDelta ){
203 if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){
204 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
6ad0bfa0 205 // Correct to difference in CPV and EMC position due to different distance to center.
206 // we assume, that particle moves from center
d15a28e7 207 Float_t DCPV = geom->GetIPtoOuterCoverDistance();
208 Float_t DEMC = geom->GetIPtoCrystalSurface() ;
209 DEMC = DEMC / DCPV ;
210 vecPpsd = DEMC * vecPpsd - vecEmc ;
211 R = vecPpsd.Mag() ;
212 } // if zPpsd >= zEmc - fDelta
213 TooFar = kFALSE ;
214 } // if xPpsd >= xEmc - fDelta
215 else
216 TooFar = kTRUE ;
217 }
218 else
219 TooFar = kTRUE ;
220
221 return R ;
222}
223
224//____________________________________________________________________________
225void AliPHOSTrackSegmentMakerv1::MakeLinks(TObjArray * EmcRecPoints, TObjArray * PpsdRecPointsUp,
226 TObjArray * PpsdRecPointsLow, TClonesArray * LinkLowArray,
227 TClonesArray *LinkUpArray)
228{
229 //Finds distanses (links) between all EMC and PPSD clusters, which are not further from each other than fR0
230
231 TIter nextEmc(EmcRecPoints) ;
232 Int_t iEmcClu = 0 ;
233
234 AliPHOSPpsdRecPoint * PpsdLow ;
235 AliPHOSPpsdRecPoint * PpsdUp ;
236 AliPHOSEmcRecPoint * EmcClu ;
237
238 Int_t iLinkLow = 0 ;
239 Int_t iLinkUp = 0 ;
240
241 while( (EmcClu = (AliPHOSEmcRecPoint*)nextEmc() ) ) {
242 Bool_t TooFar ;
243 TIter nextPpsdLow(PpsdRecPointsLow ) ;
244 Int_t iPpsdLow = 0 ;
245
246 while( (PpsdLow = (AliPHOSPpsdRecPoint*)nextPpsdLow() ) ) {
247 Float_t R = GetDistanceInPHOSPlane(EmcClu, PpsdLow, TooFar) ;
248
249 if(TooFar)
250 break ;
251 if(R < fR0)
252 new( (*LinkLowArray)[iLinkLow++]) AliPHOSLink(R, iEmcClu, iPpsdLow) ;
253
254 iPpsdLow++ ;
255
256 }
257
258 TIter nextPpsdUp(PpsdRecPointsUp ) ;
259 Int_t iPpsdUp = 0 ;
260
261 while( (PpsdUp = (AliPHOSPpsdRecPoint*)nextPpsdUp() ) ) {
262 Float_t R = GetDistanceInPHOSPlane(EmcClu, PpsdUp, TooFar) ;
263
264 if(TooFar)
265 break ;
266 if(R < fR0)
267 new( (*LinkUpArray)[iLinkUp++]) AliPHOSLink(R, iEmcClu, iPpsdUp) ;
268
269 iPpsdUp++ ;
270
271 }
272
273 iEmcClu++ ;
274
275 } // while nextEmC
276
277 LinkLowArray->Sort() ; //first links with smallest distances
278 LinkUpArray->Sort() ;
279}
280
281//____________________________________________________________________________
282void AliPHOSTrackSegmentMakerv1::MakePairs(TObjArray * EmcRecPoints, TObjArray * PpsdRecPointsUp,
283 TObjArray * PpsdRecPointsLow, TClonesArray * LinkLowArray,
284 TClonesArray * LinkUpArray, TrackSegmentsList * trsl)
6ad0bfa0 285{
286
287 // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance
288
d15a28e7 289 TIter nextLow(LinkLowArray) ;
290 TIter nextUp(LinkUpArray) ;
291
292 AliPHOSLink * linkLow ;
293 AliPHOSLink * linkUp ;
294
295 AliPHOSEmcRecPoint * emc ;
296 AliPHOSPpsdRecPoint * ppsdLow ;
297 AliPHOSPpsdRecPoint * ppsdUp ;
298
9f616d61 299 AliPHOSRecPoint * NullPointer = 0 ;
300
d15a28e7 301 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
302 emc = (AliPHOSEmcRecPoint *) EmcRecPoints->At(linkLow->GetEmc()) ;
303 ppsdLow = (AliPHOSPpsdRecPoint *) PpsdRecPointsLow->At(linkLow->GetPpsd()) ;
6ad0bfa0 304 if( (emc) && (ppsdLow) ){ // RecPoints not removed yet
d15a28e7 305 ppsdUp = 0 ;
306
307 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
308 if(linkLow->GetEmc() == linkUp->GetEmc() ){
309 ppsdUp = (AliPHOSPpsdRecPoint *) PpsdRecPointsUp->At(linkUp->GetPpsd()) ;
310 break ;
311 }
312
313 } // while nextUp
314
315 nextUp.Reset();
316 AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
317 trsl->Add(subtr) ;
9f616d61 318 EmcRecPoints->AddAt(NullPointer,linkLow->GetEmc()) ;
319 PpsdRecPointsLow->AddAt(NullPointer,linkLow->GetPpsd()) ;
d15a28e7 320
321 if(ppsdUp)
9f616d61 322 PpsdRecPointsUp->AddAt(NullPointer,linkUp->GetPpsd()) ;
d15a28e7 323
6ad0bfa0 324 }
d15a28e7 325 }
326
327 TIter nextEmc(EmcRecPoints) ;
328 nextEmc.Reset() ;
329
330 while( (emc = (AliPHOSEmcRecPoint*)nextEmc()) ){ //to create pairs if no PpsdLow
9f616d61 331 ppsdLow = 0 ;
332 ppsdUp = 0 ;
d15a28e7 333
334 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
335
336 if(EmcRecPoints->IndexOf(emc) == linkUp->GetEmc() ){
337 ppsdUp = (AliPHOSPpsdRecPoint *) PpsdRecPointsUp->At(linkUp->GetPpsd()) ;
338 break ;
339 }
340
341 }
342 AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
343 trsl->Add(subtr) ;
344
345 if(ppsdUp)
9f616d61 346 PpsdRecPointsUp->AddAt(NullPointer,linkUp->GetPpsd()) ;
d15a28e7 347 }
348
349}
350
351//____________________________________________________________________________
352void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * DL, RecPointsList * emcl,
353 RecPointsList * ppsdl, TrackSegmentsList * trsl)
354{
9f616d61 355 // main function, does the job
d15a28e7 356
9f616d61 357 Int_t PHOSMod = 1 ;
358 Int_t emcStopedAt = 0 ;
d15a28e7 359 Int_t ppsdStopedAt = 0 ;
360
9f616d61 361 TObjArray * EmcRecPoints = new TObjArray(100) ; // these arrays keep pointers
362 TObjArray * PpsdRecPointsUp = new TObjArray(100) ; // to RecPoints, which are
363 TObjArray * PpsdRecPointsLow = new TObjArray(100) ; // kept in TClonesArray's emcl and ppsdl
d15a28e7 364
365
366 TClonesArray * LinkLowArray = new TClonesArray("AliPHOSLink", 100);
367 TClonesArray * LinkUpArray = new TClonesArray("AliPHOSLink", 100);
368
369 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
370
371 while(PHOSMod <= geom->GetNModules() ){
372
6ad0bfa0 373 FillOneModule(DL, emcl, EmcRecPoints, ppsdl, PpsdRecPointsUp, PpsdRecPointsLow, PHOSMod, emcStopedAt, ppsdStopedAt) ;
374
9f616d61 375 MakeLinks(EmcRecPoints, PpsdRecPointsUp, PpsdRecPointsLow, LinkLowArray, LinkUpArray) ;
d15a28e7 376
9f616d61 377 MakePairs(EmcRecPoints, PpsdRecPointsUp, PpsdRecPointsLow, LinkLowArray, LinkUpArray, trsl) ;
d15a28e7 378
379 EmcRecPoints->Clear() ;
9f616d61 380
d15a28e7 381 PpsdRecPointsUp->Clear() ;
9f616d61 382
d15a28e7 383 PpsdRecPointsLow->Clear() ;
9f616d61 384
6ad0bfa0 385 LinkUpArray->Clear() ;
9f616d61 386
6ad0bfa0 387 LinkLowArray->Clear() ;
9f616d61 388
6ad0bfa0 389 PHOSMod++ ;
d15a28e7 390 }
9f616d61 391 delete EmcRecPoints ;
392 EmcRecPoints = 0 ;
393
394 delete PpsdRecPointsUp ;
395 PpsdRecPointsUp = 0 ;
396
397 delete PpsdRecPointsLow ;
398 PpsdRecPointsLow = 0 ;
399
400 delete LinkUpArray ;
401 LinkUpArray = 0 ;
402
403 delete LinkLowArray ;
404 LinkLowArray = 0 ;
d15a28e7 405}
406
407//____________________________________________________________________________
9f616d61 408Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r)
409{
d15a28e7 410// If you change this function, change also gradiend evaluation in ChiSquare()
6ad0bfa0 411 Double_t r4 = r*r*r*r ;
412 Double_t r295 = TMath::Power(r, 2.95) ;
d15a28e7 413 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
414 return shape ;
415}
416
417//____________________________________________________________________________
418void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * DL, RecPointsList * emcIn, AliPHOSEmcRecPoint * iniEmc,
419 Int_t Nmax, int * maxAt, Float_t * maxAtEnergy, TObjArray * emcList)
420{
9f616d61 421 // fits cluster with Nmax overlapping showers
d15a28e7 422
423 Int_t NPar = 3 * Nmax ;
424 Float_t FitParameters[NPar] ;
425 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
9f616d61 426
427 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, NPar, FitParameters) ;
428 if( !rv ) // Fit failed, return and remove cluster
d15a28e7 429 return ;
430
431 Float_t xDigit ;
432 Float_t zDigit ;
433 Int_t RelId[4] ;
434
435 Int_t Ndigits = iniEmc->GetMultiplicity() ;
436 Float_t xpar ;
437 Float_t zpar ;
438 Float_t Epar ;
439 Float_t Distance ;
440 Float_t Ratio ;
441 Float_t Efit[Ndigits] ;
442 Int_t iparam ;
443 Int_t iDigit ;
444
445 AliPHOSDigit * digit ;
446 AliPHOSEmcRecPoint * emcRP ;
6ad0bfa0 447 Int_t * emcDigits = iniEmc->GetDigitsList() ;
d15a28e7 448 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
449
450 Int_t iRecPoint = emcIn->GetEntries() ;
451
452 for(iDigit = 0 ; iDigit < Ndigits ; iDigit ++){
453 digit = (AliPHOSDigit *) emcDigits[iDigit];
454 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
455 geom->RelPosInModule(RelId, xDigit, zDigit) ;
456 Efit[iDigit] = 0;
457 iparam = 0 ;
458
459 while(iparam < NPar ){
460 xpar = FitParameters[iparam] ;
461 zpar = FitParameters[iparam+1] ;
462 Epar = FitParameters[iparam+2] ;
463 iparam += 3 ;
464 Distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
465 Distance = TMath::Sqrt(Distance) ;
466 Efit[iDigit] += Epar * ShowerShape(Distance) ;
467 }
d15a28e7 468 }
469
470 iparam = 0 ;
471 Float_t eDigit ;
472
473 while(iparam < NPar ){
474 xpar = FitParameters[iparam] ;
475 zpar = FitParameters[iparam+1] ;
476 Epar = FitParameters[iparam+2] ;
477 iparam += 3 ;
478 new ((*emcIn)[iRecPoint]) AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
479 emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint++);
480
481 for(iDigit = 0 ; iDigit < Ndigits ; iDigit ++){
482 digit = (AliPHOSDigit *) emcDigits[iDigit];
483 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
484 geom->RelPosInModule(RelId, xDigit, zDigit) ;
485 Distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
486 Distance = TMath::Sqrt(Distance) ;
487 Ratio = Epar * ShowerShape(Distance) / Efit[iDigit] ;
488 eDigit = emcEnergies[iDigit] * Ratio ;
9f616d61 489 emcRP->AddDigit( *digit, eDigit ) ;
d15a28e7 490 }
491
492 emcList->Add(emcRP) ;
493
494 }
495}
6ad0bfa0 496
d15a28e7 497//______________________________________________________________________________
6ad0bfa0 498void UnfoldingChiSquare(Int_t & NPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
d15a28e7 499{
9f616d61 500
6ad0bfa0 501// Number of parameters, Gradient, Chi squared, parameters, what to do
9f616d61 502
d15a28e7 503 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
d15a28e7 504
9f616d61 505 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
6ad0bfa0 506 Int_t * emcDigits = emcRP->GetDigitsList() ;
d15a28e7 507 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
508 fret = 0. ;
509 Int_t iparam ;
510
9f616d61 511 if(iflag == 2)
512 for(iparam = 0 ; iparam < NPar ; iparam++)
513 Grad[iparam] = 0 ; // Will evaluate gradient
514
d15a28e7 515 Double_t Efit ;
9f616d61 516
d15a28e7 517 AliPHOSDigit * digit ;
518 Int_t iDigit = 0 ;
9f616d61 519
d15a28e7 520 while ( (digit = (AliPHOSDigit *)emcDigits[iDigit] )){
521 Int_t RelId[4] ;
522 Float_t xDigit ;
523 Float_t zDigit ;
524 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
525 geom->RelPosInModule(RelId, xDigit, zDigit) ;
526
9f616d61 527 if(iflag == 2){ // calculate gradient
528 Int_t iParam = 0 ;
529 Efit = 0 ;
530 while(iParam < NPar ){
531 Double_t Distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
532 iParam++ ;
533 Distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
534 Distance = TMath::Sqrt( Distance ) ;
535 iParam++ ;
536 Efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(Distance) ;
537 iParam++ ;
538 }
539 Double_t sum = 2. * (Efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
540 iParam = 0 ;
541 while(iParam < NPar ){
542 Double_t xpar = x[iParam] ;
543 Double_t zpar = x[iParam+1] ;
544 Double_t Epar = x[iParam+2] ;
545 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
546 Double_t shape = sum * AliPHOSTrackSegmentMakerv1::ShowerShape(dr) ;
547 Double_t r4 = dr*dr*dr*dr ;
548 Double_t r295 = TMath::Power(dr,2.95) ;
549 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
550 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
551
552 Grad[iParam] += Epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
553 iParam++ ;
554 Grad[iParam] += Epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
555 iParam++ ;
556 Grad[iParam] += shape ; // Derivative over energy
557 iParam++ ;
558 }
559 }
560 Efit = 0;
561 iparam = 0 ;
562 while(iparam < NPar ){
563 Double_t xpar = x[iparam] ;
564 Double_t zpar = x[iparam+1] ;
565 Double_t Epar = x[iparam+2] ;
566 iparam += 3 ;
567 Double_t Distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
568 Distance = TMath::Sqrt(Distance) ;
569 Efit += Epar * AliPHOSTrackSegmentMakerv1::ShowerShape(Distance) ;
570 }
571 fret += (Efit-emcEnergies[iDigit])*(Efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
572 // Here we assume, that sigma = sqrt(E)
573 iDigit++ ;
d15a28e7 574 }
575}