1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //_________________________________________________________________________
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
20 //////////////////////////////////////////////////////////////////////////////
22 // --- ROOT system ---
24 #include "TObjArray.h"
25 #include "TClonesArray.h"
26 #include "TObjectTable.h"
28 // --- Standard library ---
33 // --- AliRoot header files ---
35 #include "AliPHOSTrackSegmentMakerv1.h"
36 #include "AliPHOSTrackSegment.h"
37 #include "AliPHOSLink.h"
38 #include "AliPHOSv0.h"
41 extern void UnfoldingChiSquare(Int_t &nPar, Double_t *Grad, Double_t & fret, Double_t *x, Int_t iflag) ;
43 ClassImp( AliPHOSTrackSegmentMakerv1)
46 //____________________________________________________________________________
47 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1()
51 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
52 //clusters are sorted in "rows" and "columns" of width geom->GetCrystalSize(0),
53 fDelta = fR0 + geom->GetCrystalSize(0) ;
54 fMinuit = new TMinuit(100) ;
58 //____________________________________________________________________________
59 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
64 //____________________________________________________________________________
65 Bool_t AliPHOSTrackSegmentMakerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
66 Int_t nPar, Float_t * fitparameters)
68 // Calls TMinuit for fitting cluster with several maxima
70 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
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
76 // filling initial values for fit parameters
77 AliPHOSDigit * digit ;
81 Int_t nDigits = (Int_t) nPar / 3 ;
86 for(iDigit = 0; iDigit < nDigits; iDigit++){
87 digit = (AliPHOSDigit *) maxAt[iDigit];
92 geom->AbsToRelNumbering(digit->GetId(), relid) ;
93 geom->RelPosInModule(relid, x, z) ;
95 Float_t energy = maxAtEnergy[iDigit] ;
97 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
100 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
103 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
106 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
109 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
112 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
117 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
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
124 gMinuit->SetMaxIterations(5);
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 ;
131 for(index = 0; index < nPar; index++){
134 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
135 fitparameters[index] = val ;
141 //____________________________________________________________________________
142 void AliPHOSTrackSegmentMakerv1::FillOneModule(DigitsList * Dl, RecPointsList * emcIn, TObjArray * emcOut,
143 RecPointsList * ppsdIn, TObjArray * ppsdOutUp,
144 TObjArray * ppsdOutLow, Int_t & phosmod, Int_t & emcStopedAt,
145 Int_t & ppsdStopedAt)
147 // Unfold clusters and fill xxxOut arrays with clusters from one PHOS module
149 AliPHOSEmcRecPoint * emcRecPoint ;
150 AliPHOSPpsdRecPoint * ppsdRecPoint ;
153 Int_t nEmcUnfolded = emcIn->GetEntries() ;
154 for(index = emcStopedAt; index < nEmcUnfolded; index++){
155 emcRecPoint = (AliPHOSEmcRecPoint *) (*emcIn)[index] ;
157 if(emcRecPoint->GetPHOSMod() != phosmod )
160 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
161 Int_t maxAt[nMultipl] ;
162 Float_t maxAtEnergy[nMultipl] ;
163 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ;
165 if(nMax <= 1 ) // if cluster is very flat (no pronounced maximum) then nMax = 0
166 emcOut->Add(emcRecPoint) ;
167 else if (fUnfoldFlag) {
168 UnfoldClusters(Dl, emcIn, emcRecPoint, nMax, maxAt, maxAtEnergy, emcOut) ;
169 emcIn->Remove(emcRecPoint);
175 emcStopedAt = index ;
177 for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){
178 ppsdRecPoint = (AliPHOSPpsdRecPoint *) (*ppsdIn)[index] ;
179 if(ppsdRecPoint->GetPHOSMod() != phosmod )
181 if(ppsdRecPoint->GetUp() )
182 ppsdOutUp->Add(ppsdRecPoint) ;
184 ppsdOutLow->Add(ppsdRecPoint) ;
186 ppsdStopedAt = index ;
192 //____________________________________________________________________________
193 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcclu,AliPHOSPpsdRecPoint * PpsdClu, Bool_t &toofar)
200 emcclu->GetLocalPosition(vecEmc) ;
201 PpsdClu->GetLocalPosition(vecPpsd) ;
202 if(emcclu->GetPHOSMod() == PpsdClu->GetPHOSMod()){
203 if(vecPpsd.X() >= vecEmc.X() - fDelta ){
204 if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){
205 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
206 // Correct to difference in CPV and EMC position due to different distance to center.
207 // we assume, that particle moves from center
208 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
209 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
211 vecPpsd = dEMC * vecPpsd - vecEmc ;
213 } // if zPpsd >= zEmc - fDelta
215 } // if xPpsd >= xEmc - fDelta
225 //____________________________________________________________________________
226 void AliPHOSTrackSegmentMakerv1::MakeLinks(TObjArray * emcRecPoints, TObjArray * ppsdRecPointsUp,
227 TObjArray * ppsdRecPointsLow, TClonesArray * linklowArray,
228 TClonesArray *linkupArray)
230 //Finds distanses (links) between all EMC and PPSD clusters, which are not further from each other than fR0
232 TIter nextEmc(emcRecPoints) ;
235 AliPHOSPpsdRecPoint * ppsdlow ;
236 AliPHOSPpsdRecPoint * ppsdup ;
237 AliPHOSEmcRecPoint * emcclu ;
242 while( (emcclu = (AliPHOSEmcRecPoint*)nextEmc() ) ) {
244 TIter nextPpsdLow(ppsdRecPointsLow ) ;
247 while( (ppsdlow = (AliPHOSPpsdRecPoint*)nextPpsdLow() ) ) {
248 Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdlow, toofar) ;
253 new( (*linklowArray)[iLinkLow++]) AliPHOSLink(r, iEmcClu, iPpsdLow) ;
259 TIter nextPpsdUp(ppsdRecPointsUp ) ;
262 while( (ppsdup = (AliPHOSPpsdRecPoint*)nextPpsdUp() ) ) {
263 Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdup, toofar) ;
268 new( (*linkupArray)[iLinkUp++]) AliPHOSLink(r, iEmcClu, iPpsdUp) ;
278 linklowArray->Sort() ; //first links with smallest distances
279 linkupArray->Sort() ;
282 //____________________________________________________________________________
283 void AliPHOSTrackSegmentMakerv1::MakePairs(TObjArray * emcRecPoints, TObjArray * ppsdRecPointsUp,
284 TObjArray * ppsdRecPointsLow, TClonesArray * linklowArray,
285 TClonesArray * linkupArray, TrackSegmentsList * trsl)
288 // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance
290 TIter nextLow(linklowArray) ;
291 TIter nextUp(linkupArray) ;
293 AliPHOSLink * linkLow ;
294 AliPHOSLink * linkUp ;
296 AliPHOSEmcRecPoint * emc ;
297 AliPHOSPpsdRecPoint * ppsdLow ;
298 AliPHOSPpsdRecPoint * ppsdUp ;
300 AliPHOSRecPoint * nullpointer = 0 ;
302 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
303 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(linkLow->GetEmc()) ;
304 ppsdLow = (AliPHOSPpsdRecPoint *) ppsdRecPointsLow->At(linkLow->GetPpsd()) ;
305 if( (emc) && (ppsdLow) ){ // RecPoints not removed yet
308 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
309 if(linkLow->GetEmc() == linkUp->GetEmc() ){
310 ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
317 AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
319 emcRecPoints->AddAt(nullpointer,linkLow->GetEmc()) ;
320 ppsdRecPointsLow->AddAt(nullpointer,linkLow->GetPpsd()) ;
323 ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ;
328 TIter nextEmc(emcRecPoints) ;
331 while( (emc = (AliPHOSEmcRecPoint*)nextEmc()) ){ //to create pairs if no ppsdlow
335 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
337 if(emcRecPoints->IndexOf(emc) == linkUp->GetEmc() ){
338 ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
343 AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
347 ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ;
352 //____________________________________________________________________________
353 void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * DL, RecPointsList * emcl,
354 RecPointsList * ppsdl, TrackSegmentsList * trsl)
356 // main function, does the job
359 Int_t emcStopedAt = 0 ;
360 Int_t ppsdStopedAt = 0 ;
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
367 TClonesArray * linklowArray = new TClonesArray("AliPHOSLink", 100);
368 TClonesArray * linkupArray = new TClonesArray("AliPHOSLink", 100);
370 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
372 while(phosmod <= geom->GetNModules() ){
374 FillOneModule(DL, emcl, emcRecPoints, ppsdl, ppsdRecPointsUp, ppsdRecPointsLow, phosmod, emcStopedAt, ppsdStopedAt) ;
376 MakeLinks(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray) ;
378 MakePairs(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray, trsl) ;
380 emcRecPoints->Clear() ;
382 ppsdRecPointsUp->Clear() ;
384 ppsdRecPointsLow->Clear() ;
386 linkupArray->Clear() ;
388 linklowArray->Clear() ;
392 delete emcRecPoints ;
395 delete ppsdRecPointsUp ;
396 ppsdRecPointsUp = 0 ;
398 delete ppsdRecPointsLow ;
399 ppsdRecPointsLow = 0 ;
404 delete linklowArray ;
408 //____________________________________________________________________________
409 Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r)
411 // If you change this function, change also gradiend evaluation in ChiSquare()
412 Double_t r4 = r*r*r*r ;
413 Double_t r295 = TMath::Power(r, 2.95) ;
414 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
418 //____________________________________________________________________________
419 void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * DL, RecPointsList * emcIn, AliPHOSEmcRecPoint * iniEmc,
420 Int_t nMax, int * maxAt, Float_t * maxAtEnergy, TObjArray * emcList)
422 // fits cluster with nMax overlapping showers
424 Int_t nPar = 3 * nMax ;
425 Float_t fitparameters[nPar] ;
426 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
428 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
429 if( !rv ) // Fit failed, return and remove cluster
436 Int_t nDigits = iniEmc->GetMultiplicity() ;
442 Float_t efit[nDigits] ;
446 AliPHOSDigit * digit ;
447 AliPHOSEmcRecPoint * emcRP ;
448 Int_t * emcDigits = iniEmc->GetDigitsList() ;
449 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
451 Int_t iRecPoint = emcIn->GetEntries() ;
453 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
454 digit = (AliPHOSDigit *) emcDigits[iDigit];
455 geom->AbsToRelNumbering(digit->GetId(), relid) ;
456 geom->RelPosInModule(relid, xDigit, zDigit) ;
460 while(iparam < nPar ){
461 xpar = fitparameters[iparam] ;
462 zpar = fitparameters[iparam+1] ;
463 epar = fitparameters[iparam+2] ;
465 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
466 distance = TMath::Sqrt(distance) ;
467 efit[iDigit] += epar * ShowerShape(distance) ;
474 while(iparam < nPar ){
475 xpar = fitparameters[iparam] ;
476 zpar = fitparameters[iparam+1] ;
477 epar = fitparameters[iparam+2] ;
479 new ((*emcIn)[iRecPoint]) AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
480 emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint++);
482 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
483 digit = (AliPHOSDigit *) emcDigits[iDigit];
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 ;
490 emcRP->AddDigit( *digit, eDigit ) ;
493 emcList->Add(emcRP) ;
498 //______________________________________________________________________________
499 void UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
502 // Number of parameters, Gradient, Chi squared, parameters, what to do
504 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
506 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
507 Int_t * emcDigits = emcRP->GetDigitsList() ;
508 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
513 for(iparam = 0 ; iparam < nPar ; iparam++)
514 Grad[iparam] = 0 ; // Will evaluate gradient
518 AliPHOSDigit * digit ;
521 while ( (digit = (AliPHOSDigit *)emcDigits[iDigit] )){
525 geom->AbsToRelNumbering(digit->GetId(), relid) ;
526 geom->RelPosInModule(relid, xDigit, zDigit) ;
528 if(iflag == 2){ // calculate gradient
531 while(iParam < nPar ){
532 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
534 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
535 distance = TMath::Sqrt( distance ) ;
537 efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
540 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
542 while(iParam < nPar ){
543 Double_t xpar = x[iParam] ;
544 Double_t zpar = x[iParam+1] ;
545 Double_t epar = x[iParam+2] ;
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) ) ) ;
553 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
555 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
557 Grad[iParam] += shape ; // Derivative over energy
563 while(iparam < nPar ){
564 Double_t xpar = x[iparam] ;
565 Double_t zpar = x[iparam+1] ;
566 Double_t epar = x[iparam+2] ;
568 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
569 distance = TMath::Sqrt(distance) ;
570 efit += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
572 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
573 // Here we assume, that sigma = sqrt(E)