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 **************************************************************************/
18 //_________________________________________________________________________
19 // Implementation version 1 of algorithm class to construct PHOS track segments
20 // Associates EMC and PPSD clusters
21 // Unfolds the EMC cluster
23 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH)
26 // --- ROOT system ---
28 #include "TObjArray.h"
29 #include "TClonesArray.h"
30 #include "TObjectTable.h"
32 // --- Standard library ---
37 // --- AliRoot header files ---
39 #include "AliPHOSTrackSegmentMakerv1.h"
40 #include "AliPHOSTrackSegment.h"
41 #include "AliPHOSLink.h"
42 #include "AliPHOSv0.h"
45 extern void UnfoldingChiSquare(Int_t &nPar, Double_t *Grad, Double_t & fret, Double_t *x, Int_t iflag) ;
47 ClassImp( AliPHOSTrackSegmentMakerv1)
50 //____________________________________________________________________________
51 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
56 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
57 //clusters are sorted in "rows" and "columns" of width geom->GetCrystalSize(0),
58 fDelta = fR0 + geom->GetCrystalSize(0) ;
59 fMinuit = new TMinuit(100) ;
63 //____________________________________________________________________________
64 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
71 //____________________________________________________________________________
72 Bool_t AliPHOSTrackSegmentMakerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
73 Int_t nPar, Float_t * fitparameters)
75 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
77 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
79 gMinuit->SetPrintLevel(-1) ; // No Printout
80 gMinuit->SetFCN(UnfoldingChiSquare) ; // To set the address of the minimization function
81 gMinuit->SetObjectFit(emcRP) ; // To tranfer pointer to UnfoldingChiSquare
83 // filling initial values for fit parameters
84 AliPHOSDigit * digit ;
88 Int_t nDigits = (Int_t) nPar / 3 ;
93 for(iDigit = 0; iDigit < nDigits; iDigit++){
94 digit = (AliPHOSDigit *) maxAt[iDigit];
99 geom->AbsToRelNumbering(digit->GetId(), relid) ;
100 geom->RelPosInModule(relid, x, z) ;
102 Float_t energy = maxAtEnergy[iDigit] ;
104 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
107 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
110 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
113 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
116 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
119 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
124 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
129 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TgMinuit to reduce function calls
130 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
131 gMinuit->SetMaxIterations(5);
132 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
133 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
134 if(ierflg == 4){ // Minimum not found
135 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
138 for(index = 0; index < nPar; index++){
141 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
142 fitparameters[index] = val ;
148 //____________________________________________________________________________
149 void AliPHOSTrackSegmentMakerv1::FillOneModule(DigitsList * dl, RecPointsList * emcIn, TObjArray * emcOut,
150 RecPointsList * ppsdIn, TObjArray * ppsdOutUp,
151 TObjArray * ppsdOutLow, Int_t & phosmod, Int_t & emcStopedAt,
152 Int_t & ppsdStopedAt)
154 // Unfold clusters and fill xxxOut arrays with clusters from one PHOS module
156 AliPHOSEmcRecPoint * emcRecPoint ;
157 AliPHOSPpsdRecPoint * ppsdRecPoint ;
160 Int_t nEmcUnfolded = emcIn->GetEntries() ;
161 for(index = emcStopedAt; index < nEmcUnfolded; index++){
162 emcRecPoint = (AliPHOSEmcRecPoint *) (*emcIn)[index] ;
164 if(emcRecPoint->GetPHOSMod() != phosmod )
167 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
168 Int_t maxAt[nMultipl] ;
169 Float_t maxAtEnergy[nMultipl] ;
170 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ;
172 if(nMax <= 1 ) // if cluster is very flat (no pronounced maximum) then nMax = 0
173 emcOut->Add(emcRecPoint) ;
174 else if (fUnfoldFlag) {
175 UnfoldClusters(dl, emcIn, emcRecPoint, nMax, maxAt, maxAtEnergy, emcOut) ;
176 emcIn->Remove(emcRecPoint);
182 emcStopedAt = index ;
184 for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){
185 ppsdRecPoint = (AliPHOSPpsdRecPoint *) (*ppsdIn)[index] ;
186 if(ppsdRecPoint->GetPHOSMod() != phosmod )
188 if(ppsdRecPoint->GetUp() )
189 ppsdOutUp->Add(ppsdRecPoint) ;
191 ppsdOutLow->Add(ppsdRecPoint) ;
193 ppsdStopedAt = index ;
199 //____________________________________________________________________________
200 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcclu,AliPHOSPpsdRecPoint * PpsdClu, Bool_t &toofar)
202 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
209 emcclu->GetLocalPosition(vecEmc) ;
210 PpsdClu->GetLocalPosition(vecPpsd) ;
211 if(emcclu->GetPHOSMod() == PpsdClu->GetPHOSMod()){
212 if(vecPpsd.X() >= vecEmc.X() - fDelta ){
213 if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){
214 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
215 // Correct to difference in CPV and EMC position due to different distance to center.
216 // we assume, that particle moves from center
217 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
218 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
220 vecPpsd = dEMC * vecPpsd - vecEmc ;
222 } // if zPpsd >= zEmc - fDelta
224 } // if xPpsd >= xEmc - fDelta
234 //____________________________________________________________________________
235 void AliPHOSTrackSegmentMakerv1::MakeLinks(TObjArray * emcRecPoints, TObjArray * ppsdRecPointsUp,
236 TObjArray * ppsdRecPointsLow, TClonesArray * linklowArray,
237 TClonesArray *linkupArray)
239 // Finds distances (links) between all EMC and PPSD clusters, which are not further apart from each other than fR0
241 TIter nextEmc(emcRecPoints) ;
244 AliPHOSPpsdRecPoint * ppsdlow ;
245 AliPHOSPpsdRecPoint * ppsdup ;
246 AliPHOSEmcRecPoint * emcclu ;
251 while( (emcclu = (AliPHOSEmcRecPoint*)nextEmc() ) ) {
253 TIter nextPpsdLow(ppsdRecPointsLow ) ;
256 while( (ppsdlow = (AliPHOSPpsdRecPoint*)nextPpsdLow() ) ) {
257 Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdlow, toofar) ;
262 new( (*linklowArray)[iLinkLow++]) AliPHOSLink(r, iEmcClu, iPpsdLow) ;
268 TIter nextPpsdUp(ppsdRecPointsUp ) ;
271 while( (ppsdup = (AliPHOSPpsdRecPoint*)nextPpsdUp() ) ) {
272 Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdup, toofar) ;
277 new( (*linkupArray)[iLinkUp++]) AliPHOSLink(r, iEmcClu, iPpsdUp) ;
287 linklowArray->Sort() ; //first links with smallest distances
288 linkupArray->Sort() ;
291 //____________________________________________________________________________
292 void AliPHOSTrackSegmentMakerv1::MakePairs(TObjArray * emcRecPoints, TObjArray * ppsdRecPointsUp,
293 TObjArray * ppsdRecPointsLow, TClonesArray * linklowArray,
294 TClonesArray * linkupArray, TrackSegmentsList * trsl)
297 // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance
299 TIter nextLow(linklowArray) ;
300 TIter nextUp(linkupArray) ;
302 AliPHOSLink * linkLow ;
303 AliPHOSLink * linkUp ;
305 AliPHOSEmcRecPoint * emc ;
306 AliPHOSPpsdRecPoint * ppsdLow ;
307 AliPHOSPpsdRecPoint * ppsdUp ;
309 AliPHOSRecPoint * nullpointer = 0 ;
311 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
312 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(linkLow->GetEmc()) ;
313 ppsdLow = (AliPHOSPpsdRecPoint *) ppsdRecPointsLow->At(linkLow->GetPpsd()) ;
314 if( (emc) && (ppsdLow) ){ // RecPoints not removed yet
317 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
318 if(linkLow->GetEmc() == linkUp->GetEmc() ){
319 ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
326 // AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
327 // trsl->Add(subtr) ;
328 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
330 emcRecPoints->AddAt(nullpointer,linkLow->GetEmc()) ;
331 ppsdRecPointsLow->AddAt(nullpointer,linkLow->GetPpsd()) ;
334 ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ;
339 TIter nextEmc(emcRecPoints) ;
342 while( (emc = (AliPHOSEmcRecPoint*)nextEmc()) ){ //to create pairs if no ppsdlow
346 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
348 if(emcRecPoints->IndexOf(emc) == linkUp->GetEmc() ){
349 ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
354 // AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
355 // trsl->Add(subtr) ;
356 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
361 ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ;
366 //____________________________________________________________________________
367 void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * dl, RecPointsList * emcl,
368 RecPointsList * ppsdl, TrackSegmentsList * trsl)
370 // Makes the track segments out of the list of EMC and PPSD Recpoints and stores them in a list
373 Int_t emcStopedAt = 0 ;
374 Int_t ppsdStopedAt = 0 ;
376 TObjArray * emcRecPoints = new TObjArray(100) ; // these arrays keep pointers
377 TObjArray * ppsdRecPointsUp = new TObjArray(100) ; // to RecPoints, which are
378 TObjArray * ppsdRecPointsLow = new TObjArray(100) ; // kept in TClonesArray's emcl and ppsdl
381 TClonesArray * linklowArray = new TClonesArray("AliPHOSLink", 100);
382 TClonesArray * linkupArray = new TClonesArray("AliPHOSLink", 100);
384 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
386 while(phosmod <= geom->GetNModules() ){
388 FillOneModule(dl, emcl, emcRecPoints, ppsdl, ppsdRecPointsUp, ppsdRecPointsLow, phosmod, emcStopedAt, ppsdStopedAt) ;
390 MakeLinks(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray) ;
392 MakePairs(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray, trsl) ;
394 emcRecPoints->Clear() ;
396 ppsdRecPointsUp->Clear() ;
398 ppsdRecPointsLow->Clear() ;
400 linkupArray->Clear() ;
402 linklowArray->Clear() ;
406 delete emcRecPoints ;
409 delete ppsdRecPointsUp ;
410 ppsdRecPointsUp = 0 ;
412 delete ppsdRecPointsLow ;
413 ppsdRecPointsLow = 0 ;
418 delete linklowArray ;
422 //____________________________________________________________________________
423 Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r)
425 // Shape of the shower (see PHOS TDR)
426 // If you change this function, change also the gradien evaluation in ChiSquare()
428 Double_t r4 = r*r*r*r ;
429 Double_t r295 = TMath::Power(r, 2.95) ;
430 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
434 //____________________________________________________________________________
435 void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * dl, RecPointsList * emcIn, AliPHOSEmcRecPoint * iniEmc,
436 Int_t nMax, int * maxAt, Float_t * maxAtEnergy, TObjArray * emcList)
438 // Performs the unfolding of a cluster with nMax overlapping showers
439 // This is time consuming (use the (Un)SetUnfolFlag() )
441 Int_t nPar = 3 * nMax ;
442 Float_t fitparameters[nPar] ;
443 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
445 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
446 if( !rv ) // Fit failed, return and remove cluster
453 Int_t nDigits = iniEmc->GetMultiplicity() ;
459 Float_t efit[nDigits] ;
463 AliPHOSDigit * digit ;
464 AliPHOSEmcRecPoint * emcRP ;
465 Int_t * emcDigits = iniEmc->GetDigitsList() ;
466 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
468 Int_t iRecPoint = emcIn->GetEntries() ;
470 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
471 digit = (AliPHOSDigit *) emcDigits[iDigit];
472 geom->AbsToRelNumbering(digit->GetId(), relid) ;
473 geom->RelPosInModule(relid, xDigit, zDigit) ;
477 while(iparam < nPar ){
478 xpar = fitparameters[iparam] ;
479 zpar = fitparameters[iparam+1] ;
480 epar = fitparameters[iparam+2] ;
482 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
483 distance = TMath::Sqrt(distance) ;
484 efit[iDigit] += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
491 while(iparam < nPar ){
492 xpar = fitparameters[iparam] ;
493 zpar = fitparameters[iparam+1] ;
494 epar = fitparameters[iparam+2] ;
496 new ((*emcIn)[iRecPoint]) AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
497 emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint++);
499 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
500 digit = (AliPHOSDigit *) emcDigits[iDigit];
501 geom->AbsToRelNumbering(digit->GetId(), relid) ;
502 geom->RelPosInModule(relid, xDigit, zDigit) ;
503 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
504 distance = TMath::Sqrt(distance) ;
505 ratio = epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) / efit[iDigit] ;
506 eDigit = emcEnergies[iDigit] * ratio ;
507 emcRP->AddDigit( *digit, eDigit ) ;
510 emcList->Add(emcRP) ;
515 //______________________________________________________________________________
516 void UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
518 // Calculates th Chi square for the cluster unfolding minimization
519 // Number of parameters, Gradient, Chi squared, parameters, what to do
521 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
523 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
524 Int_t * emcDigits = emcRP->GetDigitsList() ;
525 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
530 for(iparam = 0 ; iparam < nPar ; iparam++)
531 Grad[iparam] = 0 ; // Will evaluate gradient
535 AliPHOSDigit * digit ;
538 while ( (digit = (AliPHOSDigit *)emcDigits[iDigit] )){
542 geom->AbsToRelNumbering(digit->GetId(), relid) ;
543 geom->RelPosInModule(relid, xDigit, zDigit) ;
545 if(iflag == 2){ // calculate gradient
548 while(iParam < nPar ){
549 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
551 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
552 distance = TMath::Sqrt( distance ) ;
554 efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
557 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
559 while(iParam < nPar ){
560 Double_t xpar = x[iParam] ;
561 Double_t zpar = x[iParam+1] ;
562 Double_t epar = x[iParam+2] ;
563 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
564 Double_t shape = sum * AliPHOSTrackSegmentMakerv1::ShowerShape(dr) ;
565 Double_t r4 = dr*dr*dr*dr ;
566 Double_t r295 = TMath::Power(dr,2.95) ;
567 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
568 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
570 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
572 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
574 Grad[iParam] += shape ; // Derivative over energy
580 while(iparam < nPar ){
581 Double_t xpar = x[iparam] ;
582 Double_t zpar = x[iparam+1] ;
583 Double_t epar = x[iparam+2] ;
585 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
586 distance = TMath::Sqrt(distance) ;
587 efit += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
589 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
590 // Here we assume, that sigma = sqrt(E)