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