]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSTrackSegmentMakerv1.cxx
Unfolding slightly reorganized (added finction UnfoldAll) to be consistent with Index...
[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 ) ;
321// trsl->Add(subtr) ;
322 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
323 fNTrackSegments++ ;
92862013 324 emcRecPoints->AddAt(nullpointer,linkLow->GetEmc()) ;
325 ppsdRecPointsLow->AddAt(nullpointer,linkLow->GetPpsd()) ;
d15a28e7 326
327 if(ppsdUp)
92862013 328 ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ;
d15a28e7 329
6ad0bfa0 330 }
d15a28e7 331 }
332
92862013 333 TIter nextEmc(emcRecPoints) ;
d15a28e7 334 nextEmc.Reset() ;
335
92862013 336 while( (emc = (AliPHOSEmcRecPoint*)nextEmc()) ){ //to create pairs if no ppsdlow
9f616d61 337 ppsdLow = 0 ;
338 ppsdUp = 0 ;
d15a28e7 339
340 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
341
92862013 342 if(emcRecPoints->IndexOf(emc) == linkUp->GetEmc() ){
343 ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
d15a28e7 344 break ;
345 }
346
347 }
98cbd830 348
b2a60966 349 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
350 fNTrackSegments++ ;
351
352
d15a28e7 353 if(ppsdUp)
92862013 354 ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ;
d15a28e7 355 }
356
357}
358
359//____________________________________________________________________________
88714635 360void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * dl,
361 AliPHOSRecPoint::RecPointsList * emcl,
362 AliPHOSRecPoint::RecPointsList * ppsdl,
363 AliPHOSTrackSegment::TrackSegmentsList * trsl)
d15a28e7 364{
b2a60966 365 // Makes the track segments out of the list of EMC and PPSD Recpoints and stores them in a list
98cbd830 366
92862013 367 Int_t phosmod = 1 ;
9f616d61 368 Int_t emcStopedAt = 0 ;
d15a28e7 369 Int_t ppsdStopedAt = 0 ;
370
92862013 371 TObjArray * emcRecPoints = new TObjArray(100) ; // these arrays keep pointers
372 TObjArray * ppsdRecPointsUp = new TObjArray(100) ; // to RecPoints, which are
373 TObjArray * ppsdRecPointsLow = new TObjArray(100) ; // kept in TClonesArray's emcl and ppsdl
d15a28e7 374
375
92862013 376 TClonesArray * linklowArray = new TClonesArray("AliPHOSLink", 100);
377 TClonesArray * linkupArray = new TClonesArray("AliPHOSLink", 100);
6ad0bfa0 378
98cbd830 379 if(fUnfoldFlag){
380 UnfoldAll(dl, emcl) ; // Unfolds all EMC clusters
381 }
d15a28e7 382
98cbd830 383 while(phosmod <= fGeom->GetNModules() ){
384
385 FillOneModule(emcl, emcRecPoints, ppsdl, ppsdRecPointsUp, ppsdRecPointsLow, phosmod, emcStopedAt, ppsdStopedAt) ;
386
387 MakeLinks(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray) ;
388
92862013 389 MakePairs(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray, trsl) ;
98cbd830 390
92862013 391 emcRecPoints->Clear() ;
98cbd830 392
92862013 393 ppsdRecPointsUp->Clear() ;
98cbd830 394
92862013 395 ppsdRecPointsLow->Clear() ;
98cbd830 396
92862013 397 linkupArray->Clear() ;
98cbd830 398
92862013 399 linklowArray->Clear() ;
98cbd830 400
92862013 401 phosmod++ ;
d15a28e7 402 }
92862013 403 delete emcRecPoints ;
404 emcRecPoints = 0 ;
98cbd830 405
92862013 406 delete ppsdRecPointsUp ;
407 ppsdRecPointsUp = 0 ;
9f616d61 408
92862013 409 delete ppsdRecPointsLow ;
410 ppsdRecPointsLow = 0 ;
9f616d61 411
92862013 412 delete linkupArray ;
413 linkupArray = 0 ;
9f616d61 414
92862013 415 delete linklowArray ;
416 linklowArray = 0 ;
d15a28e7 417}
418
419//____________________________________________________________________________
9f616d61 420Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r)
421{
b2a60966 422 // Shape of the shower (see PHOS TDR)
423 // If you change this function, change also the gradien evaluation in ChiSquare()
424
6ad0bfa0 425 Double_t r4 = r*r*r*r ;
426 Double_t r295 = TMath::Power(r, 2.95) ;
d15a28e7 427 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
428 return shape ;
429}
430
98cbd830 431//____________________________________________________________________________
432void AliPHOSTrackSegmentMakerv1::UnfoldAll(DigitsList * dl, AliPHOSRecPoint::RecPointsList * emcIn)
433{
434 // Performs unfolding of all EMC clusters, sorts them and resets indexes in RecPoints
435
436 AliPHOSEmcRecPoint * emcRecPoint ;
437 Int_t index ;
438 Int_t nEmcUnfolded = emcIn->GetEntries() ;
439
440 for(index = 0 ; index < nEmcUnfolded; index++){
441
442 emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
443
444 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
445 Int_t * maxAt = new Int_t[nMultipl] ;
446 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
447 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ;
448
449 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
450
451 UnfoldClusters(dl, emcIn, emcRecPoint, nMax, maxAt, maxAtEnergy) ;
452 emcIn->Remove(emcRecPoint);
453 emcIn->Compress() ;
454 index-- ;
455 nEmcUnfolded-- ;
456 }
457
458 delete[] maxAt ;
459 delete[] maxAtEnergy ;
460 } //Unfolding finished
461
462 emcIn->Sort() ;
463
464 // to set index to new and correct index of old RecPoints
465 for( index = 0 ; index < emcIn->GetEntriesFast() ; index++){
466
467 ((AliPHOSEmcRecPoint *) emcIn->At(index))->SetIndexInList(index) ;
468
469 }
470
471}
d15a28e7 472//____________________________________________________________________________
88714635 473void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * dl,
474 AliPHOSRecPoint::RecPointsList * emcIn,
475 AliPHOSEmcRecPoint * iniEmc,
476 Int_t nMax,
477 int * maxAt,
98cbd830 478 Float_t * maxAtEnergy)
d15a28e7 479{
b2a60966 480 // Performs the unfolding of a cluster with nMax overlapping showers
481 // This is time consuming (use the (Un)SetUnfolFlag() )
482
92862013 483 Int_t nPar = 3 * nMax ;
31aa6d6c 484 Float_t * fitparameters = new Float_t[nPar] ;
98cbd830 485
9f616d61 486
92862013 487 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
31aa6d6c 488 if( !rv ) {
489 // Fit failed, return and remove cluster
490 delete[] fitparameters ;
d15a28e7 491 return ;
31aa6d6c 492 }
98cbd830 493
494
d15a28e7 495 Float_t xDigit ;
496 Float_t zDigit ;
92862013 497 Int_t relid[4] ;
d15a28e7 498
92862013 499 Int_t nDigits = iniEmc->GetMultiplicity() ;
d15a28e7 500 Float_t xpar ;
501 Float_t zpar ;
92862013 502 Float_t epar ;
503 Float_t distance ;
504 Float_t ratio ;
31aa6d6c 505 Float_t * efit = new Float_t[nDigits] ;
d15a28e7 506 Int_t iparam ;
507 Int_t iDigit ;
508
509 AliPHOSDigit * digit ;
510 AliPHOSEmcRecPoint * emcRP ;
6ad0bfa0 511 Int_t * emcDigits = iniEmc->GetDigitsList() ;
d15a28e7 512 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
513
514 Int_t iRecPoint = emcIn->GetEntries() ;
515
92862013 516 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
98cbd830 517 digit = fPlease->GimeDigit( emcDigits[iDigit] ) ;
518 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
519 fGeom->RelPosInModule(relid, xDigit, zDigit) ;
92862013 520 efit[iDigit] = 0;
d15a28e7 521 iparam = 0 ;
522
92862013 523 while(iparam < nPar ){
524 xpar = fitparameters[iparam] ;
525 zpar = fitparameters[iparam+1] ;
526 epar = fitparameters[iparam+2] ;
d15a28e7 527 iparam += 3 ;
92862013 528 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
529 distance = TMath::Sqrt(distance) ;
b2a60966 530 efit[iDigit] += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
d15a28e7 531 }
d15a28e7 532 }
533
534 iparam = 0 ;
535 Float_t eDigit ;
536
98cbd830 537
92862013 538 while(iparam < nPar ){
539 xpar = fitparameters[iparam] ;
540 zpar = fitparameters[iparam+1] ;
541 epar = fitparameters[iparam+2] ;
d15a28e7 542 iparam += 3 ;
98cbd830 543
544 (*emcIn)[iRecPoint] = new AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
545
546 emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint);
547 iRecPoint++ ;
d15a28e7 548
92862013 549 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
98cbd830 550 digit = fPlease->GimeDigit( emcDigits[iDigit] ) ;
551 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
552 fGeom->RelPosInModule(relid, xDigit, zDigit) ;
92862013 553 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
554 distance = TMath::Sqrt(distance) ;
b2a60966 555 ratio = epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) / efit[iDigit] ;
92862013 556 eDigit = emcEnergies[iDigit] * ratio ;
9f616d61 557 emcRP->AddDigit( *digit, eDigit ) ;
d15a28e7 558 }
559
d15a28e7 560 }
31aa6d6c 561
562 delete[] fitparameters ;
563 delete[] efit ;
564
d15a28e7 565}
6ad0bfa0 566
d15a28e7 567//______________________________________________________________________________
92862013 568void UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
d15a28e7 569{
b2a60966 570 // Calculates th Chi square for the cluster unfolding minimization
571 // Number of parameters, Gradient, Chi squared, parameters, what to do
98cbd830 572
9f616d61 573 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
98cbd830 574
6ad0bfa0 575 Int_t * emcDigits = emcRP->GetDigitsList() ;
98cbd830 576
577 Int_t nOfDigits = emcRP->GetDigitsMultiplicity() ;
578
d15a28e7 579 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
98cbd830 580
581 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
582
583 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
584
d15a28e7 585 fret = 0. ;
586 Int_t iparam ;
587
9f616d61 588 if(iflag == 2)
92862013 589 for(iparam = 0 ; iparam < nPar ; iparam++)
9f616d61 590 Grad[iparam] = 0 ; // Will evaluate gradient
591
98cbd830 592 Double_t efit ;
593
d15a28e7 594 AliPHOSDigit * digit ;
98cbd830 595 Int_t iDigit ;
596
597 for( iDigit = 0 ; iDigit < nOfDigits ; iDigit++) {
598
599 digit = please->GimeDigit( emcDigits[iDigit] ) ;
9f616d61 600
92862013 601 Int_t relid[4] ;
d15a28e7 602 Float_t xDigit ;
603 Float_t zDigit ;
98cbd830 604
92862013 605 geom->AbsToRelNumbering(digit->GetId(), relid) ;
98cbd830 606
92862013 607 geom->RelPosInModule(relid, xDigit, zDigit) ;
98cbd830 608
9f616d61 609 if(iflag == 2){ // calculate gradient
610 Int_t iParam = 0 ;
92862013 611 efit = 0 ;
612 while(iParam < nPar ){
613 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
9f616d61 614 iParam++ ;
92862013 615 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
616 distance = TMath::Sqrt( distance ) ;
9f616d61 617 iParam++ ;
92862013 618 efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
9f616d61 619 iParam++ ;
620 }
92862013 621 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
9f616d61 622 iParam = 0 ;
92862013 623 while(iParam < nPar ){
9f616d61 624 Double_t xpar = x[iParam] ;
625 Double_t zpar = x[iParam+1] ;
92862013 626 Double_t epar = x[iParam+2] ;
9f616d61 627 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
628 Double_t shape = sum * AliPHOSTrackSegmentMakerv1::ShowerShape(dr) ;
629 Double_t r4 = dr*dr*dr*dr ;
630 Double_t r295 = TMath::Power(dr,2.95) ;
631 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
632 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
633
92862013 634 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
9f616d61 635 iParam++ ;
92862013 636 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
9f616d61 637 iParam++ ;
638 Grad[iParam] += shape ; // Derivative over energy
639 iParam++ ;
640 }
641 }
92862013 642 efit = 0;
9f616d61 643 iparam = 0 ;
98cbd830 644
92862013 645 while(iparam < nPar ){
9f616d61 646 Double_t xpar = x[iparam] ;
647 Double_t zpar = x[iparam+1] ;
92862013 648 Double_t epar = x[iparam+2] ;
9f616d61 649 iparam += 3 ;
92862013 650 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
651 distance = TMath::Sqrt(distance) ;
652 efit += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
9f616d61 653 }
98cbd830 654
92862013 655 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
9f616d61 656 // Here we assume, that sigma = sqrt(E)
d15a28e7 657 }
98cbd830 658
d15a28e7 659}