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) ;
57 //____________________________________________________________________________
58 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
63 //____________________________________________________________________________
64 Bool_t AliPHOSTrackSegmentMakerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
65 Int_t NPar, Float_t * FitParameters)
67 // Calls TMinuit for fitting cluster with several maxima
69 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
71 gMinuit->SetPrintLevel(-1) ; // No Printout
72 gMinuit->SetFCN(UnfoldingChiSquare) ; // To set the address of the minimization function
73 gMinuit->SetObjectFit(emcRP) ; // To tranfer pointer to UnfoldingChiSquare
75 // filling initial values for fit parameters
76 AliPHOSDigit * digit ;
80 Int_t NDigits = (Int_t) NPar / 3 ;
85 for(iDigit = 0; iDigit < NDigits; iDigit++){
86 digit = (AliPHOSDigit *) maxAt[iDigit];
91 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
92 geom->RelPosInModule(RelId, x, z) ;
94 Float_t Energy = maxAtEnergy[iDigit] ;
96 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
99 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
102 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
105 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
108 gMinuit->mnparm(index, "Energy", Energy , 0.05*Energy, 0., 4.*Energy, ierflg) ;
111 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : Energy = " << Energy << endl ;
116 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
121 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TgMinuit to reduce function calls
122 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
123 gMinuit->SetMaxIterations(5);
124 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
125 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
126 if(ierflg == 4){ // Minimum not found
127 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
130 for(index = 0; index < NPar; index++){
133 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
134 FitParameters[index] = val ;
140 //____________________________________________________________________________
141 void AliPHOSTrackSegmentMakerv1::FillOneModule(DigitsList * Dl, RecPointsList * emcIn, TObjArray * emcOut,
142 RecPointsList * ppsdIn, TObjArray * ppsdOutUp,
143 TObjArray * ppsdOutLow, Int_t & PHOSMod, Int_t & emcStopedAt,
144 Int_t & ppsdStopedAt)
146 // Unfold clusters and fill xxxOut arrays with clusters from one PHOS module
148 AliPHOSEmcRecPoint * emcRecPoint ;
149 AliPHOSPpsdRecPoint * ppsdRecPoint ;
152 Int_t NemcUnfolded = emcIn->GetEntries() ;
153 for(index = emcStopedAt; index < NemcUnfolded; index++){
154 emcRecPoint = (AliPHOSEmcRecPoint *) (*emcIn)[index] ;
156 if(emcRecPoint->GetPHOSMod() != PHOSMod )
159 Int_t NMultipl = emcRecPoint->GetMultiplicity() ;
160 Int_t maxAt[NMultipl] ;
161 Float_t maxAtEnergy[NMultipl] ;
162 Int_t Nmax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ;
164 if(Nmax <= 1) // if cluster is very flat (no pronounced maximum) then Nmax = 0
165 emcOut->Add(emcRecPoint) ;
167 UnfoldClusters(Dl, emcIn, emcRecPoint, Nmax, maxAt, maxAtEnergy, emcOut) ;
168 emcIn->Remove(emcRecPoint);
174 emcStopedAt = index ;
176 for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){
177 ppsdRecPoint = (AliPHOSPpsdRecPoint *) (*ppsdIn)[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)
199 EmcClu->GetLocalPosition(vecEmc) ;
200 PpsdClu->GetLocalPosition(vecPpsd) ;
201 if(EmcClu->GetPHOSMod() == PpsdClu->GetPHOSMod()){
202 if(vecPpsd.X() >= vecEmc.X() - fDelta ){
203 if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){
204 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
205 // Correct to difference in CPV and EMC position due to different distance to center.
206 // we assume, that particle moves from center
207 Float_t DCPV = geom->GetIPtoOuterCoverDistance();
208 Float_t DEMC = geom->GetIPtoCrystalSurface() ;
210 vecPpsd = DEMC * vecPpsd - vecEmc ;
212 } // if zPpsd >= zEmc - fDelta
214 } // if xPpsd >= xEmc - fDelta
224 //____________________________________________________________________________
225 void AliPHOSTrackSegmentMakerv1::MakeLinks(TObjArray * EmcRecPoints, TObjArray * PpsdRecPointsUp,
226 TObjArray * PpsdRecPointsLow, TClonesArray * LinkLowArray,
227 TClonesArray *LinkUpArray)
229 //Finds distanses (links) between all EMC and PPSD clusters, which are not further from each other than fR0
231 TIter nextEmc(EmcRecPoints) ;
234 AliPHOSPpsdRecPoint * PpsdLow ;
235 AliPHOSPpsdRecPoint * PpsdUp ;
236 AliPHOSEmcRecPoint * EmcClu ;
241 while( (EmcClu = (AliPHOSEmcRecPoint*)nextEmc() ) ) {
243 TIter nextPpsdLow(PpsdRecPointsLow ) ;
246 while( (PpsdLow = (AliPHOSPpsdRecPoint*)nextPpsdLow() ) ) {
247 Float_t R = GetDistanceInPHOSPlane(EmcClu, PpsdLow, TooFar) ;
252 new( (*LinkLowArray)[iLinkLow++]) AliPHOSLink(R, iEmcClu, iPpsdLow) ;
258 TIter nextPpsdUp(PpsdRecPointsUp ) ;
261 while( (PpsdUp = (AliPHOSPpsdRecPoint*)nextPpsdUp() ) ) {
262 Float_t R = GetDistanceInPHOSPlane(EmcClu, PpsdUp, TooFar) ;
267 new( (*LinkUpArray)[iLinkUp++]) AliPHOSLink(R, iEmcClu, iPpsdUp) ;
277 LinkLowArray->Sort() ; //first links with smallest distances
278 LinkUpArray->Sort() ;
281 //____________________________________________________________________________
282 void AliPHOSTrackSegmentMakerv1::MakePairs(TObjArray * EmcRecPoints, TObjArray * PpsdRecPointsUp,
283 TObjArray * PpsdRecPointsLow, TClonesArray * LinkLowArray,
284 TClonesArray * LinkUpArray, TrackSegmentsList * trsl)
287 // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance
289 TIter nextLow(LinkLowArray) ;
290 TIter nextUp(LinkUpArray) ;
292 AliPHOSLink * linkLow ;
293 AliPHOSLink * linkUp ;
295 AliPHOSEmcRecPoint * emc ;
296 AliPHOSPpsdRecPoint * ppsdLow ;
297 AliPHOSPpsdRecPoint * ppsdUp ;
299 AliPHOSRecPoint * NullPointer = 0 ;
301 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
302 emc = (AliPHOSEmcRecPoint *) EmcRecPoints->At(linkLow->GetEmc()) ;
303 ppsdLow = (AliPHOSPpsdRecPoint *) PpsdRecPointsLow->At(linkLow->GetPpsd()) ;
304 if( (emc) && (ppsdLow) ){ // RecPoints not removed yet
307 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
308 if(linkLow->GetEmc() == linkUp->GetEmc() ){
309 ppsdUp = (AliPHOSPpsdRecPoint *) PpsdRecPointsUp->At(linkUp->GetPpsd()) ;
316 AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
318 EmcRecPoints->AddAt(NullPointer,linkLow->GetEmc()) ;
319 PpsdRecPointsLow->AddAt(NullPointer,linkLow->GetPpsd()) ;
322 PpsdRecPointsUp->AddAt(NullPointer,linkUp->GetPpsd()) ;
327 TIter nextEmc(EmcRecPoints) ;
330 while( (emc = (AliPHOSEmcRecPoint*)nextEmc()) ){ //to create pairs if no PpsdLow
334 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
336 if(EmcRecPoints->IndexOf(emc) == linkUp->GetEmc() ){
337 ppsdUp = (AliPHOSPpsdRecPoint *) PpsdRecPointsUp->At(linkUp->GetPpsd()) ;
342 AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
346 PpsdRecPointsUp->AddAt(NullPointer,linkUp->GetPpsd()) ;
351 //____________________________________________________________________________
352 void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * DL, RecPointsList * emcl,
353 RecPointsList * ppsdl, TrackSegmentsList * trsl)
355 // main function, does the job
358 Int_t emcStopedAt = 0 ;
359 Int_t ppsdStopedAt = 0 ;
361 TObjArray * EmcRecPoints = new TObjArray(100) ; // these arrays keep pointers
362 TObjArray * PpsdRecPointsUp = new TObjArray(100) ; // to RecPoints, which are
363 TObjArray * PpsdRecPointsLow = new TObjArray(100) ; // kept in TClonesArray's emcl and ppsdl
366 TClonesArray * LinkLowArray = new TClonesArray("AliPHOSLink", 100);
367 TClonesArray * LinkUpArray = new TClonesArray("AliPHOSLink", 100);
369 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
371 while(PHOSMod <= geom->GetNModules() ){
373 FillOneModule(DL, emcl, EmcRecPoints, ppsdl, PpsdRecPointsUp, PpsdRecPointsLow, PHOSMod, emcStopedAt, ppsdStopedAt) ;
375 MakeLinks(EmcRecPoints, PpsdRecPointsUp, PpsdRecPointsLow, LinkLowArray, LinkUpArray) ;
377 MakePairs(EmcRecPoints, PpsdRecPointsUp, PpsdRecPointsLow, LinkLowArray, LinkUpArray, trsl) ;
379 EmcRecPoints->Clear() ;
381 PpsdRecPointsUp->Clear() ;
383 PpsdRecPointsLow->Clear() ;
385 LinkUpArray->Clear() ;
387 LinkLowArray->Clear() ;
391 delete EmcRecPoints ;
394 delete PpsdRecPointsUp ;
395 PpsdRecPointsUp = 0 ;
397 delete PpsdRecPointsLow ;
398 PpsdRecPointsLow = 0 ;
403 delete LinkLowArray ;
407 //____________________________________________________________________________
408 Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r)
410 // If you change this function, change also gradiend evaluation in ChiSquare()
411 Double_t r4 = r*r*r*r ;
412 Double_t r295 = TMath::Power(r, 2.95) ;
413 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
417 //____________________________________________________________________________
418 void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * DL, RecPointsList * emcIn, AliPHOSEmcRecPoint * iniEmc,
419 Int_t Nmax, int * maxAt, Float_t * maxAtEnergy, TObjArray * emcList)
421 // fits cluster with Nmax overlapping showers
423 Int_t NPar = 3 * Nmax ;
424 Float_t FitParameters[NPar] ;
425 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
427 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, NPar, FitParameters) ;
428 if( !rv ) // Fit failed, return and remove cluster
435 Int_t Ndigits = iniEmc->GetMultiplicity() ;
441 Float_t Efit[Ndigits] ;
445 AliPHOSDigit * digit ;
446 AliPHOSEmcRecPoint * emcRP ;
447 Int_t * emcDigits = iniEmc->GetDigitsList() ;
448 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
450 Int_t iRecPoint = emcIn->GetEntries() ;
452 for(iDigit = 0 ; iDigit < Ndigits ; iDigit ++){
453 digit = (AliPHOSDigit *) emcDigits[iDigit];
454 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
455 geom->RelPosInModule(RelId, xDigit, zDigit) ;
459 while(iparam < NPar ){
460 xpar = FitParameters[iparam] ;
461 zpar = FitParameters[iparam+1] ;
462 Epar = FitParameters[iparam+2] ;
464 Distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
465 Distance = TMath::Sqrt(Distance) ;
466 Efit[iDigit] += Epar * ShowerShape(Distance) ;
473 while(iparam < NPar ){
474 xpar = FitParameters[iparam] ;
475 zpar = FitParameters[iparam+1] ;
476 Epar = FitParameters[iparam+2] ;
478 new ((*emcIn)[iRecPoint]) AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
479 emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint++);
481 for(iDigit = 0 ; iDigit < Ndigits ; iDigit ++){
482 digit = (AliPHOSDigit *) emcDigits[iDigit];
483 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
484 geom->RelPosInModule(RelId, xDigit, zDigit) ;
485 Distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
486 Distance = TMath::Sqrt(Distance) ;
487 Ratio = Epar * ShowerShape(Distance) / Efit[iDigit] ;
488 eDigit = emcEnergies[iDigit] * Ratio ;
489 emcRP->AddDigit( *digit, eDigit ) ;
492 emcList->Add(emcRP) ;
497 //______________________________________________________________________________
498 void UnfoldingChiSquare(Int_t & NPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
501 // Number of parameters, Gradient, Chi squared, parameters, what to do
503 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
505 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
506 Int_t * emcDigits = emcRP->GetDigitsList() ;
507 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
512 for(iparam = 0 ; iparam < NPar ; iparam++)
513 Grad[iparam] = 0 ; // Will evaluate gradient
517 AliPHOSDigit * digit ;
520 while ( (digit = (AliPHOSDigit *)emcDigits[iDigit] )){
524 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
525 geom->RelPosInModule(RelId, xDigit, zDigit) ;
527 if(iflag == 2){ // calculate gradient
530 while(iParam < NPar ){
531 Double_t Distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
533 Distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
534 Distance = TMath::Sqrt( Distance ) ;
536 Efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(Distance) ;
539 Double_t sum = 2. * (Efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
541 while(iParam < NPar ){
542 Double_t xpar = x[iParam] ;
543 Double_t zpar = x[iParam+1] ;
544 Double_t Epar = x[iParam+2] ;
545 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
546 Double_t shape = sum * AliPHOSTrackSegmentMakerv1::ShowerShape(dr) ;
547 Double_t r4 = dr*dr*dr*dr ;
548 Double_t r295 = TMath::Power(dr,2.95) ;
549 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
550 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
552 Grad[iParam] += Epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
554 Grad[iParam] += Epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
556 Grad[iParam] += shape ; // Derivative over energy
562 while(iparam < NPar ){
563 Double_t xpar = x[iparam] ;
564 Double_t zpar = x[iparam+1] ;
565 Double_t Epar = x[iparam+2] ;
567 Double_t Distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
568 Distance = TMath::Sqrt(Distance) ;
569 Efit += Epar * AliPHOSTrackSegmentMakerv1::ShowerShape(Distance) ;
571 fret += (Efit-emcEnergies[iDigit])*(Efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
572 // Here we assume, that sigma = sqrt(E)