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 // gObjectTable->Print() ;
68 // Calls TMinuit for fitting cluster with several maxima
69 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
70 assert( NPar < 100 ) ;
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 ;
152 cout << "Fill 1" << endl ;
153 Int_t NemcUnfolded = emcIn->GetEntries() ;
154 for(index = emcStopedAt; index < NemcUnfolded; index++){
155 emcRecPoint = (AliPHOSEmcRecPoint *) (*emcIn)[index] ;
156 cout << "Fill 2" << endl ;
158 if(emcRecPoint->GetPHOSMod() != PHOSMod )
162 Int_t NMultipl = emcRecPoint->GetMultiplicity() ;
163 int maxAt[NMultipl] ;
164 Float_t maxAtEnergy[NMultipl] ;
165 Int_t Nmax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ;
169 if(Nmax <= 1) // if cluster is very flat, so that no prononsed maximum, then Nmax = 0
170 emcOut->Add(emcRecPoint) ;
172 UnfoldClusters(Dl, emcIn, emcRecPoint, Nmax, maxAt, maxAtEnergy, emcOut) ;
173 emcIn->Remove(emcRecPoint);
174 cout << "Fill 3" << endl ;
180 emcStopedAt = index ;
182 for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){
183 ppsdRecPoint = (AliPHOSPpsdRecPoint *) (*ppsdIn)[index] ;
184 if(ppsdRecPoint->GetPHOSMod() != PHOSMod )
186 if(ppsdRecPoint->GetUp() )
187 ppsdOutUp->Add(ppsdRecPoint) ;
189 ppsdOutLow->Add(ppsdRecPoint) ;
191 ppsdStopedAt = index ;
200 //____________________________________________________________________________
201 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * EmcClu,AliPHOSPpsdRecPoint * PpsdClu, Bool_t &TooFar)
208 EmcClu->GetLocalPosition(vecEmc) ;
209 PpsdClu->GetLocalPosition(vecPpsd) ;
210 if(EmcClu->GetPHOSMod() == PpsdClu->GetPHOSMod()){
211 if(vecPpsd.X() >= vecEmc.X() - fDelta ){
212 if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){
213 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
214 //Correct to difference in CPV and EMC position due to different distance to center.
215 //we assume, that particle moves from center
216 Float_t DCPV = geom->GetIPtoOuterCoverDistance();
217 Float_t DEMC = geom->GetIPtoCrystalSurface() ;
219 vecPpsd = DEMC * vecPpsd - vecEmc ;
221 } // if zPpsd >= zEmc - fDelta
223 } // if xPpsd >= xEmc - fDelta
233 //____________________________________________________________________________
234 void AliPHOSTrackSegmentMakerv1::MakeLinks(TObjArray * EmcRecPoints, TObjArray * PpsdRecPointsUp,
235 TObjArray * PpsdRecPointsLow, TClonesArray * LinkLowArray,
236 TClonesArray *LinkUpArray)
238 //Finds distanses (links) between all EMC and PPSD clusters, which are not further from each other than fR0
240 TIter nextEmc(EmcRecPoints) ;
243 AliPHOSPpsdRecPoint * PpsdLow ;
244 AliPHOSPpsdRecPoint * PpsdUp ;
245 AliPHOSEmcRecPoint * EmcClu ;
250 while( (EmcClu = (AliPHOSEmcRecPoint*)nextEmc() ) ) {
252 TIter nextPpsdLow(PpsdRecPointsLow ) ;
255 while( (PpsdLow = (AliPHOSPpsdRecPoint*)nextPpsdLow() ) ) {
256 Float_t R = GetDistanceInPHOSPlane(EmcClu, PpsdLow, TooFar) ;
261 new( (*LinkLowArray)[iLinkLow++]) AliPHOSLink(R, iEmcClu, iPpsdLow) ;
267 TIter nextPpsdUp(PpsdRecPointsUp ) ;
270 while( (PpsdUp = (AliPHOSPpsdRecPoint*)nextPpsdUp() ) ) {
271 Float_t R = GetDistanceInPHOSPlane(EmcClu, PpsdUp, TooFar) ;
276 new( (*LinkUpArray)[iLinkUp++]) AliPHOSLink(R, iEmcClu, iPpsdUp) ;
286 LinkLowArray->Sort() ; //first links with smallest distances
287 LinkUpArray->Sort() ;
290 //____________________________________________________________________________
291 void AliPHOSTrackSegmentMakerv1::MakePairs(TObjArray * EmcRecPoints, TObjArray * PpsdRecPointsUp,
292 TObjArray * PpsdRecPointsLow, TClonesArray * LinkLowArray,
293 TClonesArray * LinkUpArray, TrackSegmentsList * trsl)
294 { // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance
295 TIter nextLow(LinkLowArray) ;
296 TIter nextUp(LinkUpArray) ;
298 AliPHOSLink * linkLow ;
299 AliPHOSLink * linkUp ;
301 AliPHOSEmcRecPoint * emc ;
302 AliPHOSPpsdRecPoint * ppsdLow ;
303 AliPHOSPpsdRecPoint * ppsdUp ;
305 AliPHOSRecPoint * NullPointer = 0 ;
307 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
308 emc = (AliPHOSEmcRecPoint *) EmcRecPoints->At(linkLow->GetEmc()) ;
309 ppsdLow = (AliPHOSPpsdRecPoint *) PpsdRecPointsLow->At(linkLow->GetPpsd()) ;
310 if((emc)&&(ppsdLow)){ // RecPoints not removed yet
313 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
314 if(linkLow->GetEmc() == linkUp->GetEmc() ){
315 ppsdUp = (AliPHOSPpsdRecPoint *) PpsdRecPointsUp->At(linkUp->GetPpsd()) ;
322 AliPHOSTrackSegment * subtr = new 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()) ;
348 AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
352 PpsdRecPointsUp->AddAt(NullPointer,linkUp->GetPpsd()) ;
357 //____________________________________________________________________________
358 void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * DL, RecPointsList * emcl,
359 RecPointsList * ppsdl, TrackSegmentsList * trsl)
361 // main function, does the job
364 Int_t emcStopedAt = 0 ;
365 Int_t ppsdStopedAt = 0 ;
367 TObjArray * EmcRecPoints = new TObjArray(100) ; // these arrays keep pointers
368 TObjArray * PpsdRecPointsUp = new TObjArray(100) ; // to RecPoints, which are
369 TObjArray * PpsdRecPointsLow = new TObjArray(100) ; // kept in TClonesArray's emcl and ppsdl
372 TClonesArray * LinkLowArray = new TClonesArray("AliPHOSLink", 100);
373 TClonesArray * LinkUpArray = new TClonesArray("AliPHOSLink", 100);
375 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
377 while(PHOSMod <= geom->GetNModules() ){
379 cout << PHOSMod << " Track1 " << endl ;
381 FillOneModule(DL, emcl, EmcRecPoints, ppsdl, PpsdRecPointsUp, PpsdRecPointsLow, PHOSMod , emcStopedAt, ppsdStopedAt) ;
382 cout << PHOSMod << " Track2 " << endl ;
383 MakeLinks(EmcRecPoints, PpsdRecPointsUp, PpsdRecPointsLow, LinkLowArray, LinkUpArray) ;
385 cout << PHOSMod << " Track3 " << endl ;
386 MakePairs(EmcRecPoints, PpsdRecPointsUp, PpsdRecPointsLow, LinkLowArray, LinkUpArray, trsl) ;
388 EmcRecPoints->Clear() ;
390 PpsdRecPointsUp->Clear() ;
392 PpsdRecPointsLow->Clear() ;
394 LinkUpArray->Clear();
396 LinkLowArray->Clear();
399 delete EmcRecPoints ;
402 delete PpsdRecPointsUp ;
403 PpsdRecPointsUp = 0 ;
405 delete PpsdRecPointsLow ;
406 PpsdRecPointsLow = 0 ;
411 delete LinkLowArray ;
415 //____________________________________________________________________________
416 Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r)
418 // If you change this function, change also gradiend evaluation in ChiSquare()
419 Double_t r4 = r*r*r*r ;
420 Double_t r295 = TMath::Power(r, 2.95) ;
421 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
425 //____________________________________________________________________________
426 void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * DL, RecPointsList * emcIn, AliPHOSEmcRecPoint * iniEmc,
427 Int_t Nmax, int * maxAt, Float_t * maxAtEnergy, TObjArray * emcList)
429 // fits cluster with Nmax overlapping showers
431 Int_t NPar = 3 * Nmax ;
432 Float_t FitParameters[NPar] ;
433 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
435 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, NPar, FitParameters) ;
436 if( !rv ) // Fit failed, return and remove cluster
443 Int_t Ndigits = iniEmc->GetMultiplicity() ;
449 Float_t Efit[Ndigits] ;
453 AliPHOSDigit * digit ;
454 AliPHOSEmcRecPoint * emcRP ;
455 int * emcDigits = iniEmc->GetDigitsList() ;
456 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
458 Int_t iRecPoint = emcIn->GetEntries() ;
460 for(iDigit = 0 ; iDigit < Ndigits ; iDigit ++){
461 digit = (AliPHOSDigit *) emcDigits[iDigit];
462 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
463 geom->RelPosInModule(RelId, xDigit, zDigit) ;
467 while(iparam < NPar ){
468 xpar = FitParameters[iparam] ;
469 zpar = FitParameters[iparam+1] ;
470 Epar = FitParameters[iparam+2] ;
472 Distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
473 Distance = TMath::Sqrt(Distance) ;
474 Efit[iDigit] += Epar * ShowerShape(Distance) ;
482 while(iparam < NPar ){
483 xpar = FitParameters[iparam] ;
484 zpar = FitParameters[iparam+1] ;
485 Epar = FitParameters[iparam+2] ;
487 new ((*emcIn)[iRecPoint]) AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
488 emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint++);
490 for(iDigit = 0 ; iDigit < Ndigits ; iDigit ++){
491 digit = (AliPHOSDigit *) emcDigits[iDigit];
492 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
493 geom->RelPosInModule(RelId, xDigit, zDigit) ;
494 Distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
495 Distance = TMath::Sqrt(Distance) ;
496 Ratio = Epar * ShowerShape(Distance) / Efit[iDigit] ;
497 eDigit = emcEnergies[iDigit] * Ratio ;
498 emcRP->AddDigit( *digit, eDigit ) ;
501 emcList->Add(emcRP) ;
505 //______________________________________________________________________________
506 void UnfoldingChiSquare(Int_t &NPar, Double_t *Grad, Double_t & fret, Double_t *x, Int_t iflag)
509 // Number of paramters, Gradient , Chi squared, parameters, what to do
511 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
513 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
514 int * emcDigits = emcRP->GetDigitsList() ;
515 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
520 for(iparam = 0 ; iparam < NPar ; iparam++)
521 Grad[iparam] = 0 ; // Will evaluate gradient
525 AliPHOSDigit * digit ;
528 while ( (digit = (AliPHOSDigit *)emcDigits[iDigit] )){
532 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
533 geom->RelPosInModule(RelId, xDigit, zDigit) ;
535 if(iflag == 2){ // calculate gradient
538 while(iParam < NPar ){
539 Double_t Distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
541 Distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
542 Distance = TMath::Sqrt( Distance ) ;
544 Efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(Distance) ;
547 Double_t sum = 2. * (Efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
549 while(iParam < NPar ){
550 Double_t xpar = x[iParam] ;
551 Double_t zpar = x[iParam+1] ;
552 Double_t Epar = x[iParam+2] ;
553 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
554 Double_t shape = sum * AliPHOSTrackSegmentMakerv1::ShowerShape(dr) ;
555 Double_t r4 = dr*dr*dr*dr ;
556 Double_t r295 = TMath::Power(dr,2.95) ;
557 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
558 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
560 Grad[iParam] += Epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
562 Grad[iParam] += Epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
564 Grad[iParam] += shape ; // Derivative over energy
570 while(iparam < NPar ){
571 Double_t xpar = x[iparam] ;
572 Double_t zpar = x[iparam+1] ;
573 Double_t Epar = x[iparam+2] ;
575 Double_t Distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
576 Distance = TMath::Sqrt(Distance) ;
577 Efit += Epar * AliPHOSTrackSegmentMakerv1::ShowerShape(Distance) ;
579 fret += (Efit-emcEnergies[iDigit])*(Efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
580 // Here we assume, that sigma = sqrt(E)