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 // A brief description of the class
18 //*-- Author : Yves Schutz SUBATECH
19 //////////////////////////////////////////////////////////////////////////////
21 // --- ROOT system ---
23 #include "TObjArray.h"
24 #include "TClonesArray.h"
27 // --- Standard library ---
31 // --- AliRoot header files ---
33 #include "AliPHOSTrackSegmentMakerv1.h"
34 #include "AliPHOSTrackSegment.h"
35 #include "AliPHOSLink.h"
36 #include "AliPHOSv0.h"
39 ClassImp( AliPHOSTrackSegmentMakerv1)
42 //____________________________________________________________________________
43 AliPHOSTrackSegmentMakerv1:: AliPHOSTrackSegmentMakerv1() // ctor
46 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
47 //clusters are sorted in "rows" and "columns" of width geom->GetCrystalSize(0),
48 fDelta = fR0 + geom->GetCrystalSize(0) ;
51 //____________________________________________________________________________
52 Bool_t AliPHOSTrackSegmentMakerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
53 Int_t NPar, Float_t * FitParametres)
54 { //Calls TMinuit for fitting cluster with several maxima
56 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
57 TMinuit *gMinuit = new TMinuit(NPar); //initialize TMinuit with a maximum of 5 params
58 gMinuit->SetPrintLevel(-1) ; //No PRIntout
59 gMinuit->SetFCN(UnfoldingChiSquare ); //To set the address of the minimization function
60 gMinuit->SetObjectFit(emcRP) ; //To tranfer pointer to UnfoldingChiSquare
62 //filling initial values for fit parameters
63 AliPHOSDigit * digit ;
66 Int_t NDigits = (Int_t) NPar / 3 ;
68 for(iDigit = 0 ; iDigit < NDigits ; iDigit ++){
69 digit = (AliPHOSDigit *) maxAt[iDigit];
74 geom->AbsToRelNumbering(digit->GetId(),RelId) ;
75 geom->RelPosInModule(RelId,x,z) ;
77 Float_t Energy = maxAtEnergy[iDigit] ;
79 gMinuit->mnparm(index++, " ", x, 0.1, 0, 0, ierflg) ;
81 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
84 gMinuit->mnparm(index++, " ", z, 0.1, 0, 0, ierflg) ;
86 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
89 gMinuit->mnparm(index++, " ", Energy , 0.05*Energy, 0., 4.*Energy, ierflg) ;
91 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : Energy = " << Energy << endl ;
96 Double_t p0=0.1; //"Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
100 gMinuit->mnexcm("SET STR", 0, 0, ierflg) ; //force TMinuit to reduce function calls
101 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; //force TMinuit to use my gradient
102 gMinuit->SetMaxIterations(5);
103 gMinuit->mnexcm("SET NOW", 0 , 0, ierflg) ; //No Warnings
104 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg); // minimize
105 if(ierflg == 4){ //Minimum not found
106 cout << "PHOS Unfolding> Fit not converged, cluster abondoned "<< endl ;
109 for(index = 0; index < NPar; index++){
112 gMinuit->GetParameter(index, val, err) ; //Returns value and error of parameter index
113 FitParametres[index] = val ;
118 //____________________________________________________________________________
119 void AliPHOSTrackSegmentMakerv1::FillOneModule(DigitsList * Dl, RecPointsList * emcIn, TObjArray * emcOut,
120 RecPointsList * ppsdIn, TObjArray * ppsdOutUp,
121 TObjArray * ppsdOutLow, Int_t &PHOSMod, Int_t & emcStopedAt,
122 Int_t & ppsdStopedAt)
123 {// Unfold clusters and fill xxxOut arrais with clusters from ome PHOS modeule
124 AliPHOSEmcRecPoint * emcRecPoint ;
125 AliPHOSPpsdRecPoint * ppsdRecPoint ;
128 Int_t NemcUnfolded = emcIn->GetEntries() ;
129 for(index = emcStopedAt; index < NemcUnfolded; index++){
131 emcRecPoint = (AliPHOSEmcRecPoint *) (*emcIn)[index] ;
133 if(emcRecPoint->GetPHOSMod() != PHOSMod )
136 Int_t NMultipl = emcRecPoint->GetMultiplicity() ;
137 int maxAt[NMultipl] ;
138 Float_t maxAtEnergy[NMultipl] ;
139 Int_t Nmax = emcRecPoint->GetNumberOfLocalMax(maxAt,maxAtEnergy) ;
141 if(Nmax<=1) // if cluster is very flat, so that no prononsed maximum, then Nmax = 0
142 emcOut->Add(emcRecPoint) ;
144 UnfoldClusters(Dl, emcIn, emcRecPoint, Nmax, maxAt, maxAtEnergy, emcOut) ;
145 emcIn->Remove(emcRecPoint);
151 emcStopedAt = index ;
153 for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){
154 ppsdRecPoint = (AliPHOSPpsdRecPoint *) (*ppsdIn)[index] ;
155 if(ppsdRecPoint->GetPHOSMod() != PHOSMod ) break ;
156 if(ppsdRecPoint->GetUp() )
157 ppsdOutUp->Add(ppsdRecPoint) ;
159 ppsdOutLow->Add(ppsdRecPoint) ;
161 ppsdStopedAt = index ;
170 //____________________________________________________________________________
171 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * EmcClu,AliPHOSPpsdRecPoint * PpsdClu, Bool_t &TooFar)
178 EmcClu->GetLocalPosition(vecEmc) ;
179 PpsdClu->GetLocalPosition(vecPpsd) ;
180 if(EmcClu->GetPHOSMod() == PpsdClu->GetPHOSMod()){
181 if(vecPpsd.X() >= vecEmc.X() - fDelta ){
182 if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){
183 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
184 //Correct to difference in CPV and EMC position due to different distance to center.
185 //we assume, that particle moves from center
186 Float_t DCPV = geom->GetIPtoOuterCoverDistance();
187 Float_t DEMC = geom->GetIPtoCrystalSurface() ;
189 vecPpsd = DEMC * vecPpsd - vecEmc ;
191 } // if zPpsd >= zEmc - fDelta
193 } // if xPpsd >= xEmc - fDelta
203 //____________________________________________________________________________
204 void AliPHOSTrackSegmentMakerv1::MakeLinks(TObjArray * EmcRecPoints, TObjArray * PpsdRecPointsUp,
205 TObjArray * PpsdRecPointsLow, TClonesArray * LinkLowArray,
206 TClonesArray *LinkUpArray)
208 //Finds distanses (links) between all EMC and PPSD clusters, which are not further from each other than fR0
210 TIter nextEmc(EmcRecPoints) ;
213 AliPHOSPpsdRecPoint * PpsdLow ;
214 AliPHOSPpsdRecPoint * PpsdUp ;
215 AliPHOSEmcRecPoint * EmcClu ;
220 while( (EmcClu = (AliPHOSEmcRecPoint*)nextEmc() ) ) {
222 TIter nextPpsdLow(PpsdRecPointsLow ) ;
225 while( (PpsdLow = (AliPHOSPpsdRecPoint*)nextPpsdLow() ) ) {
226 Float_t R = GetDistanceInPHOSPlane(EmcClu, PpsdLow, TooFar) ;
231 new( (*LinkLowArray)[iLinkLow++]) AliPHOSLink(R, iEmcClu, iPpsdLow) ;
237 TIter nextPpsdUp(PpsdRecPointsUp ) ;
240 while( (PpsdUp = (AliPHOSPpsdRecPoint*)nextPpsdUp() ) ) {
241 Float_t R = GetDistanceInPHOSPlane(EmcClu, PpsdUp, TooFar) ;
246 new( (*LinkUpArray)[iLinkUp++]) AliPHOSLink(R, iEmcClu, iPpsdUp) ;
256 LinkLowArray->Sort() ; //first links with smallest distances
257 LinkUpArray->Sort() ;
260 //____________________________________________________________________________
261 void AliPHOSTrackSegmentMakerv1::MakePairs(TObjArray * EmcRecPoints, TObjArray * PpsdRecPointsUp,
262 TObjArray * PpsdRecPointsLow, TClonesArray * LinkLowArray,
263 TClonesArray * LinkUpArray, TrackSegmentsList * trsl)
264 { // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance
265 TIter nextLow(LinkLowArray) ;
266 TIter nextUp(LinkUpArray) ;
268 AliPHOSLink * linkLow ;
269 AliPHOSLink * linkUp ;
271 AliPHOSEmcRecPoint * emc ;
272 AliPHOSPpsdRecPoint * ppsdLow ;
273 AliPHOSPpsdRecPoint * ppsdUp ;
275 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
276 emc = (AliPHOSEmcRecPoint *) EmcRecPoints->At(linkLow->GetEmc()) ;
277 ppsdLow = (AliPHOSPpsdRecPoint *) PpsdRecPointsLow->At(linkLow->GetPpsd()) ;
278 if((emc)&&(ppsdLow)){ // RecPoints not removed yet
281 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
282 if(linkLow->GetEmc() == linkUp->GetEmc() ){
283 ppsdUp = (AliPHOSPpsdRecPoint *) PpsdRecPointsUp->At(linkUp->GetPpsd()) ;
290 AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
292 EmcRecPoints->RemoveAt(linkLow->GetEmc()) ;
293 PpsdRecPointsLow->RemoveAt(linkLow->GetPpsd()) ;
296 PpsdRecPointsUp->RemoveAt(linkUp->GetPpsd()) ;
301 TIter nextEmc(EmcRecPoints) ;
304 while( (emc = (AliPHOSEmcRecPoint*)nextEmc()) ){ //to create pairs if no PpsdLow
308 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
310 if(EmcRecPoints->IndexOf(emc) == linkUp->GetEmc() ){
311 ppsdUp = (AliPHOSPpsdRecPoint *) PpsdRecPointsUp->At(linkUp->GetPpsd()) ;
316 AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ;
320 PpsdRecPointsUp->RemoveAt(linkUp->GetPpsd()) ;
326 //____________________________________________________________________________
327 void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * DL, RecPointsList * emcl,
328 RecPointsList * ppsdl, TrackSegmentsList * trsl)
330 //main function, does the job
333 Int_t emcStopedAt = 0 ;
334 Int_t ppsdStopedAt = 0 ;
336 TObjArray * EmcRecPoints = new TObjArray(100) ; //these arrays keeps pointers
337 TObjArray * PpsdRecPointsUp = new TObjArray(100) ; //on RecPoints, which are
338 TObjArray * PpsdRecPointsLow = new TObjArray(100) ; //kept in TClonesArray's emcl and ppsdl
341 TClonesArray * LinkLowArray = new TClonesArray("AliPHOSLink", 100);
342 TClonesArray * LinkUpArray = new TClonesArray("AliPHOSLink", 100);
344 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
346 while(PHOSMod <= geom->GetNModules() ){
348 FillOneModule(DL, emcl, EmcRecPoints, ppsdl, PpsdRecPointsUp, PpsdRecPointsLow, PHOSMod , emcStopedAt, ppsdStopedAt) ;
350 MakeLinks(EmcRecPoints,PpsdRecPointsUp, PpsdRecPointsLow, LinkLowArray, LinkUpArray) ;
352 MakePairs(EmcRecPoints,PpsdRecPointsUp, PpsdRecPointsLow, LinkLowArray, LinkUpArray, trsl) ;
354 EmcRecPoints->Clear() ;
355 PpsdRecPointsUp->Clear() ;
356 PpsdRecPointsLow->Clear() ;
357 LinkUpArray->Delete();
358 LinkLowArray->Delete();
362 //____________________________________________________________________________
363 Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r){
364 // If you change this function, change also gradiend evaluation in ChiSquare()
365 Double_t r4 = r*r*r*r ;
366 Double_t r295 = TMath::Power(r, 2.95) ;
367 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
371 //____________________________________________________________________________
372 void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * DL, RecPointsList * emcIn, AliPHOSEmcRecPoint * iniEmc,
373 Int_t Nmax, int * maxAt, Float_t * maxAtEnergy, TObjArray * emcList)
375 //fits cluster with Nmax overlapping showers
377 Int_t NPar = 3 * Nmax ;
378 Float_t FitParameters[NPar] ;
379 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
381 if( !FindFit(iniEmc, maxAt, maxAtEnergy, NPar, FitParameters) ) //Fit failed, return and remove cluster
388 Int_t Ndigits = iniEmc->GetMultiplicity() ;
394 Float_t Efit[Ndigits] ;
398 AliPHOSDigit * digit ;
399 AliPHOSEmcRecPoint * emcRP ;
400 int * emcDigits = iniEmc->GetDigitsList() ;
401 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
403 Int_t iRecPoint = emcIn->GetEntries() ;
405 for(iDigit = 0 ; iDigit < Ndigits ; iDigit ++){
406 digit = (AliPHOSDigit *) emcDigits[iDigit];
407 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
408 geom->RelPosInModule(RelId, xDigit, zDigit) ;
412 while(iparam < NPar ){
413 xpar = FitParameters[iparam] ;
414 zpar = FitParameters[iparam+1] ;
415 Epar = FitParameters[iparam+2] ;
417 Distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
418 Distance = TMath::Sqrt(Distance) ;
419 Efit[iDigit] += Epar * ShowerShape(Distance) ;
427 while(iparam < NPar ){
428 xpar = FitParameters[iparam] ;
429 zpar = FitParameters[iparam+1] ;
430 Epar = FitParameters[iparam+2] ;
432 new ((*emcIn)[iRecPoint]) AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
433 emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint++);
435 for(iDigit = 0 ; iDigit < Ndigits ; iDigit ++){
436 digit = (AliPHOSDigit *) emcDigits[iDigit];
437 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
438 geom->RelPosInModule(RelId, xDigit, zDigit) ;
439 Distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
440 Distance = TMath::Sqrt(Distance) ;
441 Ratio = Epar * ShowerShape(Distance) / Efit[iDigit] ;
442 eDigit = emcEnergies[iDigit] * Ratio ;
443 emcRP->AddDigit( *digit,eDigit ) ;
446 emcList->Add(emcRP) ;
450 //______________________________________________________________________________
451 void AliPHOSTrackSegmentMakerv1::UnfoldingChiSquare(Int_t &NPar, Double_t *Grad, Double_t & fret, Double_t *x, Int_t iflag)
453 // NUmber of paramters, Gradient , Chi squared, parameters, what to do
454 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
455 AliPHOSTrackSegmentMakerv1 TrS ;
457 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; //EmcRecPoint to fit
458 int * emcDigits = emcRP->GetDigitsList() ;
459 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
464 for(iparam = 0 ; iparam < NPar ; iparam ++)
465 Grad[iparam] = 0 ; //Will evaluate gradient
469 AliPHOSDigit * digit ;
471 while ( (digit = (AliPHOSDigit *)emcDigits[iDigit] )){
475 geom->AbsToRelNumbering(digit->GetId(), RelId) ;
476 geom->RelPosInModule(RelId, xDigit, zDigit) ;
478 if(iflag == 2){ //calculate gradient
481 while(iParam < NPar ){
482 Double_t Distance = TMath::Sqrt( (xDigit - x[iParam]) * (xDigit - x[iParam]) +
483 (zDigit - x[++iParam]) * (zDigit - x[iParam]) ) ;
484 Efit += x[++iParam] * TrS.ShowerShape(Distance) ;
487 Double_t sum = 2. * (Efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; //Here we assume, that sigma = sqrt(E)
489 while(iParam < NPar ){
490 Double_t xpar = x[iParam] ;
491 Double_t zpar = x[iParam+1] ;
492 Double_t Epar = x[iParam+2] ;
493 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
494 Double_t shape = sum * TrS.ShowerShape(dr) ;
495 Double_t r4 = dr*dr*dr*dr ;
496 Double_t r295 = TMath::Power(dr,2.95) ;
497 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
498 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
500 Grad[iParam++] += Epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
501 Grad[iParam++] += Epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
502 Grad[iParam++] += shape ; // Derivative over energy
507 while(iparam < NPar ){
508 Double_t xpar = x[iparam] ;
509 Double_t zpar = x[iparam+1] ;
510 Double_t Epar = x[iparam+2] ;
512 Double_t Distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
513 Distance = TMath::Sqrt(Distance) ;
514 Efit += Epar * TrS.ShowerShape(Distance) ;
516 fret += (Efit-emcEnergies[iDigit])*(Efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
517 //Here we assume, that sigma = sqrt(E)