]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSTrackSegmentMakerv1.cxx
Check of bounds of RP arrays is added
[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
b2a60966 16/* $Id$ */
17
d15a28e7 18//_________________________________________________________________________
b2a60966 19// Implementation version 1 of algorithm class to construct PHOS track segments
20// Associates EMC and PPSD clusters
21// Unfolds the EMC cluster
22//
23//*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH)
24//
d15a28e7 25
26// --- ROOT system ---
27
28#include "TObjArray.h"
29#include "TClonesArray.h"
9f616d61 30#include "TObjectTable.h"
d15a28e7 31
32// --- Standard library ---
33
de9ec31b 34#include <iostream.h>
d15a28e7 35
36// --- AliRoot header files ---
37
38#include "AliPHOSTrackSegmentMakerv1.h"
98cbd830 39#include "AliPHOSIndexToObject.h"
d15a28e7 40#include "AliPHOSTrackSegment.h"
41#include "AliPHOSLink.h"
42#include "AliPHOSv0.h"
43#include "AliRun.h"
44
92862013 45extern void UnfoldingChiSquare(Int_t &nPar, Double_t *Grad, Double_t & fret, Double_t *x, Int_t iflag) ;
9f616d61 46
d15a28e7 47ClassImp( AliPHOSTrackSegmentMakerv1)
48
49
50//____________________________________________________________________________
b2a60966 51 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
d15a28e7 52{
9f616d61 53 // ctor
b2a60966 54
d15a28e7 55 fR0 = 4. ;
d15a28e7 56 //clusters are sorted in "rows" and "columns" of width geom->GetCrystalSize(0),
98cbd830 57 fDelta = fR0 + fGeom->GetCrystalSize(0) ;
6727be7e 58 fMinuit = new TMinuit(100) ;
59 fUnfoldFlag = kTRUE ;
d15a28e7 60}
61
9f616d61 62//____________________________________________________________________________
63 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
64{
65 // dtor
b2a60966 66
67 delete fMinuit ;
9f616d61 68}
b2a60966 69
d15a28e7 70//____________________________________________________________________________
71Bool_t AliPHOSTrackSegmentMakerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
92862013 72 Int_t nPar, Float_t * fitparameters)
9f616d61 73{
b2a60966 74 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
6ad0bfa0 75
9f616d61 76 gMinuit->SetPrintLevel(-1) ; // No Printout
77 gMinuit->SetFCN(UnfoldingChiSquare) ; // To set the address of the minimization function
78 gMinuit->SetObjectFit(emcRP) ; // To tranfer pointer to UnfoldingChiSquare
79
80 // filling initial values for fit parameters
d15a28e7 81 AliPHOSDigit * digit ;
9f616d61 82
83 Int_t ierflg = 0;
84 Int_t index = 0 ;
92862013 85 Int_t nDigits = (Int_t) nPar / 3 ;
9f616d61 86
d15a28e7 87 Int_t iDigit ;
9f616d61 88
89
92862013 90 for(iDigit = 0; iDigit < nDigits; iDigit++){
d15a28e7 91 digit = (AliPHOSDigit *) maxAt[iDigit];
92
92862013 93 Int_t relid[4] ;
d15a28e7 94 Float_t x ;
95 Float_t z ;
98cbd830 96 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
97 fGeom->RelPosInModule(relid, x, z) ;
d15a28e7 98
92862013 99 Float_t energy = maxAtEnergy[iDigit] ;
d15a28e7 100
9f616d61 101 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
102 index++ ;
d15a28e7 103 if(ierflg != 0){
104 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
105 return kFALSE;
106 }
9f616d61 107 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
108 index++ ;
d15a28e7 109 if(ierflg != 0){
110 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
111 return kFALSE;
112 }
92862013 113 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
9f616d61 114 index++ ;
d15a28e7 115 if(ierflg != 0){
92862013 116 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
d15a28e7 117 return kFALSE;
6ad0bfa0 118 }
d15a28e7 119 }
120
9f616d61 121 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
122 // depends on it.
123 Double_t p1 = 1.0 ;
124 Double_t p2 = 0.0 ;
125
126 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TgMinuit to reduce function calls
127 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
d15a28e7 128 gMinuit->SetMaxIterations(5);
9f616d61 129 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
98cbd830 130
9f616d61 131 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
98cbd830 132
9f616d61 133 if(ierflg == 4){ // Minimum not found
134 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
d15a28e7 135 return kFALSE ;
136 }
92862013 137 for(index = 0; index < nPar; index++){
d15a28e7 138 Double_t err ;
139 Double_t val ;
9f616d61 140 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
92862013 141 fitparameters[index] = val ;
d15a28e7 142 }
98cbd830 143
d15a28e7 144 return kTRUE;
9f616d61 145
d15a28e7 146}
9f616d61 147
d15a28e7 148//____________________________________________________________________________
98cbd830 149void AliPHOSTrackSegmentMakerv1::FillOneModule(AliPHOSRecPoint::RecPointsList * emcIn,
88714635 150 TObjArray * emcOut,
151 AliPHOSRecPoint::RecPointsList * ppsdIn,
152 TObjArray * ppsdOutUp,
153 TObjArray * ppsdOutLow,
154 Int_t & phosmod,
155 Int_t & emcStopedAt,
156 Int_t & ppsdStopedAt)
9f616d61 157{
98cbd830 158 // Fill xxxOut arrays with clusters from one PHOS module
9f616d61 159
160 AliPHOSEmcRecPoint * emcRecPoint ;
d15a28e7 161 AliPHOSPpsdRecPoint * ppsdRecPoint ;
162 Int_t index ;
6ad0bfa0 163
92862013 164 Int_t nEmcUnfolded = emcIn->GetEntries() ;
165 for(index = emcStopedAt; index < nEmcUnfolded; index++){
6ad0bfa0 166
98cbd830 167 emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
9f616d61 168
98cbd830 169 if(emcRecPoint->GetPHOSMod() != phosmod )
170 break ;
31aa6d6c 171
98cbd830 172 emcOut->Add(emcRecPoint) ;
d15a28e7 173 }
174 emcStopedAt = index ;
175
176 for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){
83974468 177 ppsdRecPoint = (AliPHOSPpsdRecPoint *) ppsdIn->At(index) ;
92862013 178 if(ppsdRecPoint->GetPHOSMod() != phosmod )
9f616d61 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//____________________________________________________________________________
92862013 192Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcclu,AliPHOSPpsdRecPoint * PpsdClu, Bool_t &toofar)
d15a28e7 193{
b2a60966 194 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
195
92862013 196 Float_t r = fR0 ;
d15a28e7 197
198 TVector3 vecEmc ;
199 TVector3 vecPpsd ;
200
92862013 201 emcclu->GetLocalPosition(vecEmc) ;
d15a28e7 202 PpsdClu->GetLocalPosition(vecPpsd) ;
92862013 203 if(emcclu->GetPHOSMod() == PpsdClu->GetPHOSMod()){
d15a28e7 204 if(vecPpsd.X() >= vecEmc.X() - fDelta ){
205 if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){
6ad0bfa0 206 // Correct to difference in CPV and EMC position due to different distance to center.
207 // we assume, that particle moves from center
98cbd830 208 Float_t dCPV = fGeom->GetIPtoOuterCoverDistance();
209 Float_t dEMC = fGeom->GetIPtoCrystalSurface() ;
92862013 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{
b2a60966 230 // Finds distances (links) between all EMC and PPSD clusters, which are not further apart 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 ;
83974468 252 if(r < fR0){
92862013 253 new( (*linklowArray)[iLinkLow++]) AliPHOSLink(r, iEmcClu, iPpsdLow) ;
83974468 254 }
d15a28e7 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 ;
83974468 267 if(r < fR0) {
92862013 268 new( (*linkupArray)[iLinkUp++]) AliPHOSLink(r, iEmcClu, iPpsdUp) ;
83974468 269 }
d15a28e7 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//____________________________________________________________________________
88714635 283void AliPHOSTrackSegmentMakerv1::MakePairs(TObjArray * emcRecPoints,
284 TObjArray * ppsdRecPointsUp,
285 TObjArray * ppsdRecPointsLow,
286 TClonesArray * linklowArray,
287 TClonesArray * linkupArray,
288 AliPHOSTrackSegment::TrackSegmentsList * trsl)
6ad0bfa0 289{
290
291 // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance
292
92862013 293 TIter nextLow(linklowArray) ;
294 TIter nextUp(linkupArray) ;
d15a28e7 295
296 AliPHOSLink * linkLow ;
297 AliPHOSLink * linkUp ;
298
299 AliPHOSEmcRecPoint * emc ;
300 AliPHOSPpsdRecPoint * ppsdLow ;
301 AliPHOSPpsdRecPoint * ppsdUp ;
302
92862013 303 AliPHOSRecPoint * nullpointer = 0 ;
9f616d61 304
d15a28e7 305 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
92862013 306 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(linkLow->GetEmc()) ;
307 ppsdLow = (AliPHOSPpsdRecPoint *) ppsdRecPointsLow->At(linkLow->GetPpsd()) ;
6ad0bfa0 308 if( (emc) && (ppsdLow) ){ // RecPoints not removed yet
d15a28e7 309 ppsdUp = 0 ;
310
311 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
312 if(linkLow->GetEmc() == linkUp->GetEmc() ){
92862013 313 ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
d15a28e7 314 break ;
315 }
316
317 } // while nextUp
318
319 nextUp.Reset();
b2a60966 320// AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
32d0941d 321// trsl->Add(subtr) ;
322 fNTrackSegments = trsl->GetEntries() ;
b2a60966 323 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
324 fNTrackSegments++ ;
92862013 325 emcRecPoints->AddAt(nullpointer,linkLow->GetEmc()) ;
326 ppsdRecPointsLow->AddAt(nullpointer,linkLow->GetPpsd()) ;
d15a28e7 327
328 if(ppsdUp)
92862013 329 ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ;
d15a28e7 330
6ad0bfa0 331 }
d15a28e7 332 }
333
92862013 334 TIter nextEmc(emcRecPoints) ;
d15a28e7 335 nextEmc.Reset() ;
336
92862013 337 while( (emc = (AliPHOSEmcRecPoint*)nextEmc()) ){ //to create pairs if no ppsdlow
9f616d61 338 ppsdLow = 0 ;
339 ppsdUp = 0 ;
d15a28e7 340
341 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
342
92862013 343 if(emcRecPoints->IndexOf(emc) == linkUp->GetEmc() ){
344 ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
d15a28e7 345 break ;
346 }
347
348 }
98cbd830 349
32d0941d 350 fNTrackSegments = trsl->GetEntries() ;
b2a60966 351 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
352 fNTrackSegments++ ;
353
354
d15a28e7 355 if(ppsdUp)
92862013 356 ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ;
d15a28e7 357 }
358
359}
360
361//____________________________________________________________________________
88714635 362void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * dl,
363 AliPHOSRecPoint::RecPointsList * emcl,
364 AliPHOSRecPoint::RecPointsList * ppsdl,
365 AliPHOSTrackSegment::TrackSegmentsList * trsl)
d15a28e7 366{
b2a60966 367 // Makes the track segments out of the list of EMC and PPSD Recpoints and stores them in a list
98cbd830 368
92862013 369 Int_t phosmod = 1 ;
9f616d61 370 Int_t emcStopedAt = 0 ;
d15a28e7 371 Int_t ppsdStopedAt = 0 ;
372
92862013 373 TObjArray * emcRecPoints = new TObjArray(100) ; // these arrays keep pointers
374 TObjArray * ppsdRecPointsUp = new TObjArray(100) ; // to RecPoints, which are
375 TObjArray * ppsdRecPointsLow = new TObjArray(100) ; // kept in TClonesArray's emcl and ppsdl
d15a28e7 376
377
92862013 378 TClonesArray * linklowArray = new TClonesArray("AliPHOSLink", 100);
379 TClonesArray * linkupArray = new TClonesArray("AliPHOSLink", 100);
6ad0bfa0 380
98cbd830 381 if(fUnfoldFlag){
382 UnfoldAll(dl, emcl) ; // Unfolds all EMC clusters
383 }
d15a28e7 384
98cbd830 385 while(phosmod <= fGeom->GetNModules() ){
386
387 FillOneModule(emcl, emcRecPoints, ppsdl, ppsdRecPointsUp, ppsdRecPointsLow, phosmod, emcStopedAt, ppsdStopedAt) ;
388
389 MakeLinks(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray) ;
390
92862013 391 MakePairs(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray, trsl) ;
98cbd830 392
92862013 393 emcRecPoints->Clear() ;
98cbd830 394
92862013 395 ppsdRecPointsUp->Clear() ;
98cbd830 396
92862013 397 ppsdRecPointsLow->Clear() ;
98cbd830 398
92862013 399 linkupArray->Clear() ;
98cbd830 400
92862013 401 linklowArray->Clear() ;
98cbd830 402
92862013 403 phosmod++ ;
d15a28e7 404 }
92862013 405 delete emcRecPoints ;
406 emcRecPoints = 0 ;
98cbd830 407
92862013 408 delete ppsdRecPointsUp ;
409 ppsdRecPointsUp = 0 ;
9f616d61 410
92862013 411 delete ppsdRecPointsLow ;
412 ppsdRecPointsLow = 0 ;
9f616d61 413
92862013 414 delete linkupArray ;
415 linkupArray = 0 ;
9f616d61 416
92862013 417 delete linklowArray ;
418 linklowArray = 0 ;
d15a28e7 419}
420
421//____________________________________________________________________________
9f616d61 422Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r)
423{
b2a60966 424 // Shape of the shower (see PHOS TDR)
425 // If you change this function, change also the gradien evaluation in ChiSquare()
426
6ad0bfa0 427 Double_t r4 = r*r*r*r ;
428 Double_t r295 = TMath::Power(r, 2.95) ;
d15a28e7 429 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
430 return shape ;
431}
432
98cbd830 433//____________________________________________________________________________
434void AliPHOSTrackSegmentMakerv1::UnfoldAll(DigitsList * dl, AliPHOSRecPoint::RecPointsList * emcIn)
435{
436 // Performs unfolding of all EMC clusters, sorts them and resets indexes in RecPoints
437
438 AliPHOSEmcRecPoint * emcRecPoint ;
439 Int_t index ;
440 Int_t nEmcUnfolded = emcIn->GetEntries() ;
441
442 for(index = 0 ; index < nEmcUnfolded; index++){
443
444 emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
445
446 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
447 Int_t * maxAt = new Int_t[nMultipl] ;
448 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
449 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ;
450
451 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
452
453 UnfoldClusters(dl, emcIn, emcRecPoint, nMax, maxAt, maxAtEnergy) ;
454 emcIn->Remove(emcRecPoint);
455 emcIn->Compress() ;
456 index-- ;
457 nEmcUnfolded-- ;
458 }
459
460 delete[] maxAt ;
461 delete[] maxAtEnergy ;
462 } //Unfolding finished
463
464 emcIn->Sort() ;
465
466 // to set index to new and correct index of old RecPoints
467 for( index = 0 ; index < emcIn->GetEntriesFast() ; index++){
468
469 ((AliPHOSEmcRecPoint *) emcIn->At(index))->SetIndexInList(index) ;
470
471 }
472
473}
d15a28e7 474//____________________________________________________________________________
88714635 475void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * dl,
476 AliPHOSRecPoint::RecPointsList * emcIn,
477 AliPHOSEmcRecPoint * iniEmc,
478 Int_t nMax,
479 int * maxAt,
98cbd830 480 Float_t * maxAtEnergy)
d15a28e7 481{
b2a60966 482 // Performs the unfolding of a cluster with nMax overlapping showers
483 // This is time consuming (use the (Un)SetUnfolFlag() )
484
92862013 485 Int_t nPar = 3 * nMax ;
31aa6d6c 486 Float_t * fitparameters = new Float_t[nPar] ;
98cbd830 487
9f616d61 488
92862013 489 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
31aa6d6c 490 if( !rv ) {
491 // Fit failed, return and remove cluster
492 delete[] fitparameters ;
d15a28e7 493 return ;
31aa6d6c 494 }
98cbd830 495
496
d15a28e7 497 Float_t xDigit ;
498 Float_t zDigit ;
92862013 499 Int_t relid[4] ;
d15a28e7 500
92862013 501 Int_t nDigits = iniEmc->GetMultiplicity() ;
d15a28e7 502 Float_t xpar ;
503 Float_t zpar ;
92862013 504 Float_t epar ;
505 Float_t distance ;
506 Float_t ratio ;
31aa6d6c 507 Float_t * efit = new Float_t[nDigits] ;
d15a28e7 508 Int_t iparam ;
509 Int_t iDigit ;
510
511 AliPHOSDigit * digit ;
512 AliPHOSEmcRecPoint * emcRP ;
6ad0bfa0 513 Int_t * emcDigits = iniEmc->GetDigitsList() ;
d15a28e7 514 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
515
516 Int_t iRecPoint = emcIn->GetEntries() ;
517
92862013 518 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
98cbd830 519 digit = fPlease->GimeDigit( emcDigits[iDigit] ) ;
520 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
521 fGeom->RelPosInModule(relid, xDigit, zDigit) ;
92862013 522 efit[iDigit] = 0;
d15a28e7 523 iparam = 0 ;
524
92862013 525 while(iparam < nPar ){
526 xpar = fitparameters[iparam] ;
527 zpar = fitparameters[iparam+1] ;
528 epar = fitparameters[iparam+2] ;
d15a28e7 529 iparam += 3 ;
92862013 530 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
531 distance = TMath::Sqrt(distance) ;
b2a60966 532 efit[iDigit] += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
d15a28e7 533 }
d15a28e7 534 }
535
536 iparam = 0 ;
537 Float_t eDigit ;
538
98cbd830 539
92862013 540 while(iparam < nPar ){
541 xpar = fitparameters[iparam] ;
542 zpar = fitparameters[iparam+1] ;
543 epar = fitparameters[iparam+2] ;
d15a28e7 544 iparam += 3 ;
98cbd830 545
546 (*emcIn)[iRecPoint] = new AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
547
548 emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint);
549 iRecPoint++ ;
d15a28e7 550
92862013 551 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
98cbd830 552 digit = fPlease->GimeDigit( emcDigits[iDigit] ) ;
553 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
554 fGeom->RelPosInModule(relid, xDigit, zDigit) ;
92862013 555 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
556 distance = TMath::Sqrt(distance) ;
b2a60966 557 ratio = epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) / efit[iDigit] ;
92862013 558 eDigit = emcEnergies[iDigit] * ratio ;
9f616d61 559 emcRP->AddDigit( *digit, eDigit ) ;
d15a28e7 560 }
561
d15a28e7 562 }
31aa6d6c 563
564 delete[] fitparameters ;
565 delete[] efit ;
566
d15a28e7 567}
6ad0bfa0 568
d15a28e7 569//______________________________________________________________________________
92862013 570void UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
d15a28e7 571{
b2a60966 572 // Calculates th Chi square for the cluster unfolding minimization
573 // Number of parameters, Gradient, Chi squared, parameters, what to do
98cbd830 574
9f616d61 575 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
98cbd830 576
6ad0bfa0 577 Int_t * emcDigits = emcRP->GetDigitsList() ;
98cbd830 578
579 Int_t nOfDigits = emcRP->GetDigitsMultiplicity() ;
580
d15a28e7 581 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
98cbd830 582
583 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
584
585 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
586
d15a28e7 587 fret = 0. ;
588 Int_t iparam ;
589
9f616d61 590 if(iflag == 2)
92862013 591 for(iparam = 0 ; iparam < nPar ; iparam++)
9f616d61 592 Grad[iparam] = 0 ; // Will evaluate gradient
593
98cbd830 594 Double_t efit ;
595
d15a28e7 596 AliPHOSDigit * digit ;
98cbd830 597 Int_t iDigit ;
598
599 for( iDigit = 0 ; iDigit < nOfDigits ; iDigit++) {
600
601 digit = please->GimeDigit( emcDigits[iDigit] ) ;
9f616d61 602
92862013 603 Int_t relid[4] ;
d15a28e7 604 Float_t xDigit ;
605 Float_t zDigit ;
98cbd830 606
92862013 607 geom->AbsToRelNumbering(digit->GetId(), relid) ;
98cbd830 608
92862013 609 geom->RelPosInModule(relid, xDigit, zDigit) ;
98cbd830 610
9f616d61 611 if(iflag == 2){ // calculate gradient
612 Int_t iParam = 0 ;
92862013 613 efit = 0 ;
614 while(iParam < nPar ){
615 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
9f616d61 616 iParam++ ;
92862013 617 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
618 distance = TMath::Sqrt( distance ) ;
9f616d61 619 iParam++ ;
92862013 620 efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
9f616d61 621 iParam++ ;
622 }
92862013 623 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
9f616d61 624 iParam = 0 ;
92862013 625 while(iParam < nPar ){
9f616d61 626 Double_t xpar = x[iParam] ;
627 Double_t zpar = x[iParam+1] ;
92862013 628 Double_t epar = x[iParam+2] ;
9f616d61 629 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
630 Double_t shape = sum * AliPHOSTrackSegmentMakerv1::ShowerShape(dr) ;
631 Double_t r4 = dr*dr*dr*dr ;
632 Double_t r295 = TMath::Power(dr,2.95) ;
633 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
634 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
635
92862013 636 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
9f616d61 637 iParam++ ;
92862013 638 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
9f616d61 639 iParam++ ;
640 Grad[iParam] += shape ; // Derivative over energy
641 iParam++ ;
642 }
643 }
92862013 644 efit = 0;
9f616d61 645 iparam = 0 ;
98cbd830 646
92862013 647 while(iparam < nPar ){
9f616d61 648 Double_t xpar = x[iparam] ;
649 Double_t zpar = x[iparam+1] ;
92862013 650 Double_t epar = x[iparam+2] ;
9f616d61 651 iparam += 3 ;
92862013 652 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
653 distance = TMath::Sqrt(distance) ;
654 efit += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
9f616d61 655 }
98cbd830 656
92862013 657 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
9f616d61 658 // Here we assume, that sigma = sqrt(E)
d15a28e7 659 }
98cbd830 660
d15a28e7 661}