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 ---
36 // --- AliRoot header files ---
38 #include "AliPHOSTrackSegmentMakerv1.h"
39 #include "AliPHOSIndexToObject.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 //clusters are sorted in "rows" and "columns" of width geom->GetCrystalSize(0),
57 fDelta = fR0 + fGeom->GetCrystalSize(0) ;
58 fMinuit = new TMinuit(100) ;
62 //____________________________________________________________________________
63 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
70 //____________________________________________________________________________
71 Bool_t AliPHOSTrackSegmentMakerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
72 Int_t nPar, Float_t * fitparameters)
74 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
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
80 // filling initial values for fit parameters
81 AliPHOSDigit * digit ;
85 Int_t nDigits = (Int_t) nPar / 3 ;
90 for(iDigit = 0; iDigit < nDigits; iDigit++){
91 digit = (AliPHOSDigit *) maxAt[iDigit];
96 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
97 fGeom->RelPosInModule(relid, x, z) ;
99 Float_t energy = maxAtEnergy[iDigit] ;
101 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
104 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
107 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
110 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
113 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
116 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
121 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
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
128 gMinuit->SetMaxIterations(5);
129 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
131 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
133 if(ierflg == 4){ // Minimum not found
134 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
137 for(index = 0; index < nPar; index++){
140 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
141 fitparameters[index] = val ;
148 //____________________________________________________________________________
149 void AliPHOSTrackSegmentMakerv1::FillOneModule(AliPHOSRecPoint::RecPointsList * emcIn,
151 AliPHOSRecPoint::RecPointsList * ppsdIn,
152 TObjArray * ppsdOutUp,
153 TObjArray * ppsdOutLow,
156 Int_t & ppsdStopedAt)
158 // Fill xxxOut arrays with clusters from one PHOS module
160 AliPHOSEmcRecPoint * emcRecPoint ;
161 AliPHOSPpsdRecPoint * ppsdRecPoint ;
164 Int_t nEmcUnfolded = emcIn->GetEntries() ;
165 for(index = emcStopedAt; index < nEmcUnfolded; index++){
167 emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
169 if(emcRecPoint->GetPHOSMod() != phosmod )
172 emcOut->Add(emcRecPoint) ;
174 emcStopedAt = index ;
176 for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){
177 ppsdRecPoint = (AliPHOSPpsdRecPoint *) ppsdIn->At(index) ;
178 if(ppsdRecPoint->GetPHOSMod() != phosmod )
180 if(ppsdRecPoint->GetUp() )
181 ppsdOutUp->Add(ppsdRecPoint) ;
183 ppsdOutLow->Add(ppsdRecPoint) ;
185 ppsdStopedAt = index ;
191 //____________________________________________________________________________
192 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcclu,AliPHOSPpsdRecPoint * PpsdClu, Bool_t &toofar)
194 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
201 emcclu->GetLocalPosition(vecEmc) ;
202 PpsdClu->GetLocalPosition(vecPpsd) ;
203 if(emcclu->GetPHOSMod() == PpsdClu->GetPHOSMod()){
204 if(vecPpsd.X() >= vecEmc.X() - fDelta ){
205 if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){
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 = fGeom->GetIPtoOuterCoverDistance();
209 Float_t dEMC = fGeom->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 distances (links) between all EMC and PPSD clusters, which are not further apart 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,
284 TObjArray * ppsdRecPointsUp,
285 TObjArray * ppsdRecPointsLow,
286 TClonesArray * linklowArray,
287 TClonesArray * linkupArray,
288 AliPHOSTrackSegment::TrackSegmentsList * trsl)
291 // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance
293 TIter nextLow(linklowArray) ;
294 TIter nextUp(linkupArray) ;
296 AliPHOSLink * linkLow ;
297 AliPHOSLink * linkUp ;
299 AliPHOSEmcRecPoint * emc ;
300 AliPHOSPpsdRecPoint * ppsdLow ;
301 AliPHOSPpsdRecPoint * ppsdUp ;
303 AliPHOSRecPoint * nullpointer = 0 ;
305 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
306 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(linkLow->GetEmc()) ;
307 ppsdLow = (AliPHOSPpsdRecPoint *) ppsdRecPointsLow->At(linkLow->GetPpsd()) ;
308 if( (emc) && (ppsdLow) ){ // RecPoints not removed yet
311 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
312 if(linkLow->GetEmc() == linkUp->GetEmc() ){
313 ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
320 // AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
321 // trsl->Add(subtr) ;
322 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
324 emcRecPoints->AddAt(nullpointer,linkLow->GetEmc()) ;
325 ppsdRecPointsLow->AddAt(nullpointer,linkLow->GetPpsd()) ;
328 ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ;
333 TIter nextEmc(emcRecPoints) ;
336 while( (emc = (AliPHOSEmcRecPoint*)nextEmc()) ){ //to create pairs if no ppsdlow
340 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
342 if(emcRecPoints->IndexOf(emc) == linkUp->GetEmc() ){
343 ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
349 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
354 ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ;
359 //____________________________________________________________________________
360 void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * dl,
361 AliPHOSRecPoint::RecPointsList * emcl,
362 AliPHOSRecPoint::RecPointsList * ppsdl,
363 AliPHOSTrackSegment::TrackSegmentsList * trsl)
365 // Makes the track segments out of the list of EMC and PPSD Recpoints and stores them in a list
368 Int_t emcStopedAt = 0 ;
369 Int_t ppsdStopedAt = 0 ;
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
376 TClonesArray * linklowArray = new TClonesArray("AliPHOSLink", 100);
377 TClonesArray * linkupArray = new TClonesArray("AliPHOSLink", 100);
380 UnfoldAll(dl, emcl) ; // Unfolds all EMC clusters
383 while(phosmod <= fGeom->GetNModules() ){
385 FillOneModule(emcl, emcRecPoints, ppsdl, ppsdRecPointsUp, ppsdRecPointsLow, phosmod, emcStopedAt, ppsdStopedAt) ;
387 MakeLinks(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray) ;
389 MakePairs(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray, trsl) ;
391 emcRecPoints->Clear() ;
393 ppsdRecPointsUp->Clear() ;
395 ppsdRecPointsLow->Clear() ;
397 linkupArray->Clear() ;
399 linklowArray->Clear() ;
403 delete emcRecPoints ;
406 delete ppsdRecPointsUp ;
407 ppsdRecPointsUp = 0 ;
409 delete ppsdRecPointsLow ;
410 ppsdRecPointsLow = 0 ;
415 delete linklowArray ;
419 //____________________________________________________________________________
420 Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r)
422 // Shape of the shower (see PHOS TDR)
423 // If you change this function, change also the gradien evaluation in ChiSquare()
425 Double_t r4 = r*r*r*r ;
426 Double_t r295 = TMath::Power(r, 2.95) ;
427 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
431 //____________________________________________________________________________
432 void AliPHOSTrackSegmentMakerv1::UnfoldAll(DigitsList * dl, AliPHOSRecPoint::RecPointsList * emcIn)
434 // Performs unfolding of all EMC clusters, sorts them and resets indexes in RecPoints
436 AliPHOSEmcRecPoint * emcRecPoint ;
438 Int_t nEmcUnfolded = emcIn->GetEntries() ;
440 for(index = 0 ; index < nEmcUnfolded; index++){
442 emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
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) ;
449 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
451 UnfoldClusters(dl, emcIn, emcRecPoint, nMax, maxAt, maxAtEnergy) ;
452 emcIn->Remove(emcRecPoint);
459 delete[] maxAtEnergy ;
460 } //Unfolding finished
464 // to set index to new and correct index of old RecPoints
465 for( index = 0 ; index < emcIn->GetEntriesFast() ; index++){
467 ((AliPHOSEmcRecPoint *) emcIn->At(index))->SetIndexInList(index) ;
472 //____________________________________________________________________________
473 void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * dl,
474 AliPHOSRecPoint::RecPointsList * emcIn,
475 AliPHOSEmcRecPoint * iniEmc,
478 Float_t * maxAtEnergy)
480 // Performs the unfolding of a cluster with nMax overlapping showers
481 // This is time consuming (use the (Un)SetUnfolFlag() )
483 Int_t nPar = 3 * nMax ;
484 Float_t * fitparameters = new Float_t[nPar] ;
487 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
489 // Fit failed, return and remove cluster
490 delete[] fitparameters ;
499 Int_t nDigits = iniEmc->GetMultiplicity() ;
505 Float_t * efit = new Float_t[nDigits] ;
509 AliPHOSDigit * digit ;
510 AliPHOSEmcRecPoint * emcRP ;
511 Int_t * emcDigits = iniEmc->GetDigitsList() ;
512 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
514 Int_t iRecPoint = emcIn->GetEntries() ;
516 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
517 digit = fPlease->GimeDigit( emcDigits[iDigit] ) ;
518 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
519 fGeom->RelPosInModule(relid, xDigit, zDigit) ;
523 while(iparam < nPar ){
524 xpar = fitparameters[iparam] ;
525 zpar = fitparameters[iparam+1] ;
526 epar = fitparameters[iparam+2] ;
528 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
529 distance = TMath::Sqrt(distance) ;
530 efit[iDigit] += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
538 while(iparam < nPar ){
539 xpar = fitparameters[iparam] ;
540 zpar = fitparameters[iparam+1] ;
541 epar = fitparameters[iparam+2] ;
544 (*emcIn)[iRecPoint] = new AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
546 emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint);
549 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
550 digit = fPlease->GimeDigit( emcDigits[iDigit] ) ;
551 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
552 fGeom->RelPosInModule(relid, xDigit, zDigit) ;
553 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
554 distance = TMath::Sqrt(distance) ;
555 ratio = epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) / efit[iDigit] ;
556 eDigit = emcEnergies[iDigit] * ratio ;
557 emcRP->AddDigit( *digit, eDigit ) ;
562 delete[] fitparameters ;
567 //______________________________________________________________________________
568 void UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
570 // Calculates th Chi square for the cluster unfolding minimization
571 // Number of parameters, Gradient, Chi squared, parameters, what to do
573 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
575 Int_t * emcDigits = emcRP->GetDigitsList() ;
577 Int_t nOfDigits = emcRP->GetDigitsMultiplicity() ;
579 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
581 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
583 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
589 for(iparam = 0 ; iparam < nPar ; iparam++)
590 Grad[iparam] = 0 ; // Will evaluate gradient
594 AliPHOSDigit * digit ;
597 for( iDigit = 0 ; iDigit < nOfDigits ; iDigit++) {
599 digit = please->GimeDigit( emcDigits[iDigit] ) ;
605 geom->AbsToRelNumbering(digit->GetId(), relid) ;
607 geom->RelPosInModule(relid, xDigit, zDigit) ;
609 if(iflag == 2){ // calculate gradient
612 while(iParam < nPar ){
613 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
615 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
616 distance = TMath::Sqrt( distance ) ;
618 efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
621 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
623 while(iParam < nPar ){
624 Double_t xpar = x[iParam] ;
625 Double_t zpar = x[iParam+1] ;
626 Double_t epar = x[iParam+2] ;
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) ) ) ;
634 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
636 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
638 Grad[iParam] += shape ; // Derivative over energy
645 while(iparam < nPar ){
646 Double_t xpar = x[iparam] ;
647 Double_t zpar = x[iparam+1] ;
648 Double_t epar = x[iparam+2] ;
650 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
651 distance = TMath::Sqrt(distance) ;
652 efit += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
655 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
656 // Here we assume, that sigma = sqrt(E)