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 "AliPHOSTrackSegment.h"
40 #include "AliPHOSLink.h"
41 #include "AliPHOSv0.h"
44 extern void UnfoldingChiSquare(Int_t &nPar, Double_t *Grad, Double_t & fret, Double_t *x, Int_t iflag) ;
46 ClassImp( AliPHOSTrackSegmentMakerv1)
49 //____________________________________________________________________________
50 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
55 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
56 //clusters are sorted in "rows" and "columns" of width geom->GetCrystalSize(0),
57 fDelta = fR0 + geom->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 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
78 gMinuit->SetPrintLevel(-1) ; // No Printout
79 gMinuit->SetFCN(UnfoldingChiSquare) ; // To set the address of the minimization function
80 gMinuit->SetObjectFit(emcRP) ; // To tranfer pointer to UnfoldingChiSquare
82 // filling initial values for fit parameters
83 AliPHOSDigit * digit ;
87 Int_t nDigits = (Int_t) nPar / 3 ;
92 for(iDigit = 0; iDigit < nDigits; iDigit++){
93 digit = (AliPHOSDigit *) maxAt[iDigit];
98 geom->AbsToRelNumbering(digit->GetId(), relid) ;
99 geom->RelPosInModule(relid, x, z) ;
101 Float_t energy = maxAtEnergy[iDigit] ;
103 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
106 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
109 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
112 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
115 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
118 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
123 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
128 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TgMinuit to reduce function calls
129 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
130 gMinuit->SetMaxIterations(5);
131 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
132 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 ;
147 //____________________________________________________________________________
148 void AliPHOSTrackSegmentMakerv1::FillOneModule(DigitsList * dl,
149 AliPHOSRecPoint::RecPointsList * emcIn,
151 AliPHOSRecPoint::RecPointsList * ppsdIn,
152 TObjArray * ppsdOutUp,
153 TObjArray * ppsdOutLow,
156 Int_t & ppsdStopedAt)
158 // Unfold clusters and 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++){
166 emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
168 if(emcRecPoint->GetPHOSMod() != phosmod )
171 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
172 Int_t * maxAt = new Int_t[nMultipl] ;
173 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
174 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ;
176 if(nMax <= 1 ) // if cluster is very flat (no pronounced maximum) then nMax = 0
177 emcOut->Add(emcRecPoint) ;
178 else if (fUnfoldFlag) {
179 UnfoldClusters(dl, emcIn, emcRecPoint, nMax, maxAt, maxAtEnergy, emcOut) ;
180 emcIn->Remove(emcRecPoint);
187 delete[] maxAtEnergy ;
189 emcStopedAt = index ;
191 for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){
192 ppsdRecPoint = (AliPHOSPpsdRecPoint *) ppsdIn->At(index) ;
193 if(ppsdRecPoint->GetPHOSMod() != phosmod )
195 if(ppsdRecPoint->GetUp() )
196 ppsdOutUp->Add(ppsdRecPoint) ;
198 ppsdOutLow->Add(ppsdRecPoint) ;
200 ppsdStopedAt = index ;
206 //____________________________________________________________________________
207 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcclu,AliPHOSPpsdRecPoint * PpsdClu, Bool_t &toofar)
209 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
216 emcclu->GetLocalPosition(vecEmc) ;
217 PpsdClu->GetLocalPosition(vecPpsd) ;
218 if(emcclu->GetPHOSMod() == PpsdClu->GetPHOSMod()){
219 if(vecPpsd.X() >= vecEmc.X() - fDelta ){
220 if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){
221 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
222 // Correct to difference in CPV and EMC position due to different distance to center.
223 // we assume, that particle moves from center
224 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
225 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
227 vecPpsd = dEMC * vecPpsd - vecEmc ;
229 } // if zPpsd >= zEmc - fDelta
231 } // if xPpsd >= xEmc - fDelta
241 //____________________________________________________________________________
242 void AliPHOSTrackSegmentMakerv1::MakeLinks(TObjArray * emcRecPoints, TObjArray * ppsdRecPointsUp,
243 TObjArray * ppsdRecPointsLow, TClonesArray * linklowArray,
244 TClonesArray *linkupArray)
246 // Finds distances (links) between all EMC and PPSD clusters, which are not further apart from each other than fR0
248 TIter nextEmc(emcRecPoints) ;
251 AliPHOSPpsdRecPoint * ppsdlow ;
252 AliPHOSPpsdRecPoint * ppsdup ;
253 AliPHOSEmcRecPoint * emcclu ;
258 while( (emcclu = (AliPHOSEmcRecPoint*)nextEmc() ) ) {
260 TIter nextPpsdLow(ppsdRecPointsLow ) ;
263 while( (ppsdlow = (AliPHOSPpsdRecPoint*)nextPpsdLow() ) ) {
264 Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdlow, toofar) ;
269 new( (*linklowArray)[iLinkLow++]) AliPHOSLink(r, iEmcClu, iPpsdLow) ;
275 TIter nextPpsdUp(ppsdRecPointsUp ) ;
278 while( (ppsdup = (AliPHOSPpsdRecPoint*)nextPpsdUp() ) ) {
279 Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdup, toofar) ;
284 new( (*linkupArray)[iLinkUp++]) AliPHOSLink(r, iEmcClu, iPpsdUp) ;
294 linklowArray->Sort() ; //first links with smallest distances
295 linkupArray->Sort() ;
298 //____________________________________________________________________________
299 void AliPHOSTrackSegmentMakerv1::MakePairs(TObjArray * emcRecPoints,
300 TObjArray * ppsdRecPointsUp,
301 TObjArray * ppsdRecPointsLow,
302 TClonesArray * linklowArray,
303 TClonesArray * linkupArray,
304 AliPHOSTrackSegment::TrackSegmentsList * trsl)
307 // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance
309 TIter nextLow(linklowArray) ;
310 TIter nextUp(linkupArray) ;
312 AliPHOSLink * linkLow ;
313 AliPHOSLink * linkUp ;
315 AliPHOSEmcRecPoint * emc ;
316 AliPHOSPpsdRecPoint * ppsdLow ;
317 AliPHOSPpsdRecPoint * ppsdUp ;
319 AliPHOSRecPoint * nullpointer = 0 ;
321 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
322 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(linkLow->GetEmc()) ;
323 ppsdLow = (AliPHOSPpsdRecPoint *) ppsdRecPointsLow->At(linkLow->GetPpsd()) ;
324 if( (emc) && (ppsdLow) ){ // RecPoints not removed yet
327 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
328 if(linkLow->GetEmc() == linkUp->GetEmc() ){
329 ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
336 // AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
337 // trsl->Add(subtr) ;
338 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
340 emcRecPoints->AddAt(nullpointer,linkLow->GetEmc()) ;
341 ppsdRecPointsLow->AddAt(nullpointer,linkLow->GetPpsd()) ;
344 ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ;
349 TIter nextEmc(emcRecPoints) ;
352 while( (emc = (AliPHOSEmcRecPoint*)nextEmc()) ){ //to create pairs if no ppsdlow
356 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
358 if(emcRecPoints->IndexOf(emc) == linkUp->GetEmc() ){
359 ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
364 // AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
365 // trsl->Add(subtr) ;
366 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
371 ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ;
376 //____________________________________________________________________________
377 void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * dl,
378 AliPHOSRecPoint::RecPointsList * emcl,
379 AliPHOSRecPoint::RecPointsList * ppsdl,
380 AliPHOSTrackSegment::TrackSegmentsList * trsl)
382 // Makes the track segments out of the list of EMC and PPSD Recpoints and stores them in a list
385 Int_t emcStopedAt = 0 ;
386 Int_t ppsdStopedAt = 0 ;
388 TObjArray * emcRecPoints = new TObjArray(100) ; // these arrays keep pointers
389 TObjArray * ppsdRecPointsUp = new TObjArray(100) ; // to RecPoints, which are
390 TObjArray * ppsdRecPointsLow = new TObjArray(100) ; // kept in TClonesArray's emcl and ppsdl
393 TClonesArray * linklowArray = new TClonesArray("AliPHOSLink", 100);
394 TClonesArray * linkupArray = new TClonesArray("AliPHOSLink", 100);
396 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
398 while(phosmod <= geom->GetNModules() ){
400 FillOneModule(dl, emcl, emcRecPoints, ppsdl, ppsdRecPointsUp, ppsdRecPointsLow, phosmod, emcStopedAt, ppsdStopedAt) ;
402 MakeLinks(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray) ;
404 MakePairs(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray, trsl) ;
406 emcRecPoints->Clear() ;
408 ppsdRecPointsUp->Clear() ;
410 ppsdRecPointsLow->Clear() ;
412 linkupArray->Clear() ;
414 linklowArray->Clear() ;
418 delete emcRecPoints ;
421 delete ppsdRecPointsUp ;
422 ppsdRecPointsUp = 0 ;
424 delete ppsdRecPointsLow ;
425 ppsdRecPointsLow = 0 ;
430 delete linklowArray ;
434 //____________________________________________________________________________
435 Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r)
437 // Shape of the shower (see PHOS TDR)
438 // If you change this function, change also the gradien evaluation in ChiSquare()
440 Double_t r4 = r*r*r*r ;
441 Double_t r295 = TMath::Power(r, 2.95) ;
442 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
446 //____________________________________________________________________________
447 void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * dl,
448 AliPHOSRecPoint::RecPointsList * emcIn,
449 AliPHOSEmcRecPoint * iniEmc,
452 Float_t * maxAtEnergy,
455 // Performs the unfolding of a cluster with nMax overlapping showers
456 // This is time consuming (use the (Un)SetUnfolFlag() )
458 Int_t nPar = 3 * nMax ;
459 Float_t * fitparameters = new Float_t[nPar] ;
460 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
462 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
464 // Fit failed, return and remove cluster
465 delete[] fitparameters ;
473 Int_t nDigits = iniEmc->GetMultiplicity() ;
479 Float_t * efit = new Float_t[nDigits] ;
483 AliPHOSDigit * digit ;
484 AliPHOSEmcRecPoint * emcRP ;
485 Int_t * emcDigits = iniEmc->GetDigitsList() ;
486 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
488 Int_t iRecPoint = emcIn->GetEntries() ;
490 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
491 digit = (AliPHOSDigit *) emcDigits[iDigit];
492 geom->AbsToRelNumbering(digit->GetId(), relid) ;
493 geom->RelPosInModule(relid, xDigit, zDigit) ;
497 while(iparam < nPar ){
498 xpar = fitparameters[iparam] ;
499 zpar = fitparameters[iparam+1] ;
500 epar = fitparameters[iparam+2] ;
502 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
503 distance = TMath::Sqrt(distance) ;
504 efit[iDigit] += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
511 while(iparam < nPar ){
512 xpar = fitparameters[iparam] ;
513 zpar = fitparameters[iparam+1] ;
514 epar = fitparameters[iparam+2] ;
516 new ((*emcIn)[iRecPoint]) AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
517 emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint++);
519 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
520 digit = (AliPHOSDigit *) emcDigits[iDigit];
521 geom->AbsToRelNumbering(digit->GetId(), relid) ;
522 geom->RelPosInModule(relid, xDigit, zDigit) ;
523 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
524 distance = TMath::Sqrt(distance) ;
525 ratio = epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) / efit[iDigit] ;
526 eDigit = emcEnergies[iDigit] * ratio ;
527 emcRP->AddDigit( *digit, eDigit ) ;
530 emcList->Add(emcRP) ;
534 delete[] fitparameters ;
539 //______________________________________________________________________________
540 void UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
542 // Calculates th Chi square for the cluster unfolding minimization
543 // Number of parameters, Gradient, Chi squared, parameters, what to do
545 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
547 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
548 Int_t * emcDigits = emcRP->GetDigitsList() ;
549 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
554 for(iparam = 0 ; iparam < nPar ; iparam++)
555 Grad[iparam] = 0 ; // Will evaluate gradient
559 AliPHOSDigit * digit ;
562 while ( (digit = (AliPHOSDigit *)emcDigits[iDigit] )){
566 geom->AbsToRelNumbering(digit->GetId(), relid) ;
567 geom->RelPosInModule(relid, xDigit, zDigit) ;
569 if(iflag == 2){ // calculate gradient
572 while(iParam < nPar ){
573 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
575 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
576 distance = TMath::Sqrt( distance ) ;
578 efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
581 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
583 while(iParam < nPar ){
584 Double_t xpar = x[iParam] ;
585 Double_t zpar = x[iParam+1] ;
586 Double_t epar = x[iParam+2] ;
587 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
588 Double_t shape = sum * AliPHOSTrackSegmentMakerv1::ShowerShape(dr) ;
589 Double_t r4 = dr*dr*dr*dr ;
590 Double_t r295 = TMath::Power(dr,2.95) ;
591 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
592 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
594 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
596 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
598 Grad[iParam] += shape ; // Derivative over energy
604 while(iparam < nPar ){
605 Double_t xpar = x[iparam] ;
606 Double_t zpar = x[iparam+1] ;
607 Double_t epar = x[iparam+2] ;
609 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
610 distance = TMath::Sqrt(distance) ;
611 efit += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
613 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
614 // Here we assume, that sigma = sqrt(E)