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 // Base class for the cluster unfolding algorithm
18 //*-- Author: Adam Matyja (SUBATECH)
19 // Based on unfolding in clusterizerv1 done by Cynthia Hadjidakis
20 //-- Unfolding for eta~0: Cynthia Hadjidakis - still in AliEMCALCLusterizerv1
21 //-- Unfolding extension for whole EMCAL: Adam Matyja (SUBATECH & INP PAN)
23 // unfolds the clusters having several local maxima.
24 //////////////////////////////////////////////////////////////////////////////
26 // --- ROOT system ---
27 #include "TClonesArray.h"
31 // --- Standard library ---
34 // --- AliRoot header files ---
35 #include "AliEMCALUnfolding.h"
36 #include "AliEMCALGeometry.h"
37 #include "AliRunLoader.h"
40 #include "AliEMCALRecParam.h"
41 #include "AliEMCALRecPoint.h"
42 #include "AliEMCALDigit.h"
43 #include "AliEMCALReconstructor.h"
46 #include "AliCDBManager.h"
48 #include "AliCDBEntry.h"
50 Double_t AliEMCALUnfolding::fgSSPars[8]={0.9262,3.365,1.548,0.1625,-0.4195,0.,0.,2.332};
51 Double_t AliEMCALUnfolding::fgPar5[3]={12.31,-0.007381,-0.06936};
52 Double_t AliEMCALUnfolding::fgPar6[3]={0.05452,0.0001228,0.001361};
54 ClassImp(AliEMCALUnfolding)
56 //____________________________________________________________________________
57 AliEMCALUnfolding::AliEMCALUnfolding():
58 fNumberOfECAClusters(0),
60 fThreshold(0.01),//10 MeV
65 // ctor with the indication of the file where header Tree and digits Tree are stored
70 //____________________________________________________________________________
71 AliEMCALUnfolding::AliEMCALUnfolding(AliEMCALGeometry* geometry):
72 fNumberOfECAClusters(0),
74 fThreshold(0.01),//10 MeV
79 // ctor with the indication of the file where header Tree and digits Tree are stored
80 // use this contructor to avoid usage of Init() which uses runloader
81 // change needed by HLT - MP
84 AliFatal("AliEMCALUnfolding: Geometry not initialized.");
89 //____________________________________________________________________________
90 AliEMCALUnfolding::AliEMCALUnfolding(AliEMCALGeometry* geometry,Float_t ECALocMaxCut,Double_t *SSPars,Double_t *Par5,Double_t *Par6):
91 fNumberOfECAClusters(0),
92 fECALocMaxCut(ECALocMaxCut),
93 fThreshold(0.01),//10 MeV
98 // ctor with the indication of the file where header Tree and digits Tree are stored
99 // use this contructor to avoid usage of Init() which uses runloader
100 // change needed by HLT - MP
103 AliFatal("AliEMCALUnfolding: Geometry not initialized.");
106 for (i = 0; i < 8; i++) fgSSPars[i] = SSPars[i];
107 for (i = 0; i < 3; i++) {
114 //____________________________________________________________________________
115 void AliEMCALUnfolding::Init()
117 // Make all memory allocations which can not be done in default constructor.
118 // Attach the Clusterizer task to the list of EMCAL tasks
120 AliRunLoader *rl = AliRunLoader::Instance();
121 if (rl && rl->GetAliRun()){
122 AliEMCAL* emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
123 if(emcal)fGeom = emcal->GetGeometry();
127 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
129 AliDebug(1,Form("geom %p",fGeom));
132 gMinuit = new TMinuit(100) ;
136 //____________________________________________________________________________
137 AliEMCALUnfolding::~AliEMCALUnfolding()
142 //____________________________________________________________________________
143 void AliEMCALUnfolding::SetInput(Int_t numberOfECAClusters,TObjArray *recPoints,TClonesArray *digitsArr)
146 //Set input for unfolding purposes
147 SetNumberOfECAClusters(numberOfECAClusters);
148 SetRecPoints(recPoints);
149 SetDigitsArr(digitsArr);
152 //____________________________________________________________________________
153 void AliEMCALUnfolding::MakeUnfolding()
155 // Unfolds clusters using the shape of an ElectroMagnetic shower
156 // Performs unfolding of all clusters
158 if(fNumberOfECAClusters > 0){
160 AliFatal("Did not get geometry from EMCALLoader") ;
161 //Int_t nModulesToUnfold = fGeom->GetNCells();
163 Int_t numberofNotUnfolded = fNumberOfECAClusters ;
165 for(index = 0 ; index < numberofNotUnfolded ; index++){
166 AliEMCALRecPoint * recPoint = dynamic_cast<AliEMCALRecPoint *>( fRecPoints->At(index) ) ;
169 Int_t nMultipl = recPoint->GetMultiplicity() ;
170 AliEMCALDigit ** maxAt = new AliEMCALDigit*[nMultipl] ;
171 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
172 Int_t nMax = recPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fECALocMaxCut,fDigitsArr) ;
174 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
175 if(UnfoldClusterV2(recPoint, nMax, maxAt, maxAtEnergy) ){
176 fRecPoints->Remove(recPoint);
177 fRecPoints->Compress() ;//is it really needed
179 fNumberOfECAClusters-- ;
180 numberofNotUnfolded-- ;
184 recPoint->SetNExMax(1) ; //Only one local maximum
188 delete[] maxAtEnergy ;
189 } else AliError("RecPoint NULL");
192 // End of Unfolding of clusters
195 //____________________________________________________________________________
196 Bool_t AliEMCALUnfolding::UnfoldClusterV2(AliEMCALRecPoint * iniTower,
198 AliEMCALDigit ** maxAt,
199 Float_t * maxAtEnergy)
201 // Extended to whole EMCAL
203 //**************************** part 1 *******************************************
204 // Performs the unfolding of a cluster with nMax overlapping showers
206 //printf("Original cluster E %f\n",iniTower->GetEnergy());
208 Int_t nPar = 3 * nMax ;
209 Float_t * fitparameters = new Float_t[nPar] ;
212 AliFatal("Did not get geometry from EMCALLoader") ;
214 Bool_t rv = FindFitV2(iniTower, maxAt, maxAtEnergy, nPar, fitparameters) ;
217 // Fit failed, return (and remove cluster? - why? I leave the cluster)
218 iniTower->SetNExMax(-1) ;
219 delete[] fitparameters ;
223 //**************************** part 2 *******************************************
224 // create unfolded rec points and fill them with new energy lists
225 // First calculate energy deposited in each sell in accordance with
226 // fit (without fluctuations): efit[]
227 // and later correct this number in acordance with actual energy
230 Int_t nDigits = iniTower->GetMultiplicity() ;
231 Float_t * efit = new Float_t[nDigits] ;//new fitted energy in cells
232 Float_t xpar=0.,zpar=0.,epar=0. ;//center of gravity in cell units
234 AliEMCALDigit * digit = 0 ;
235 Int_t * digitsList = iniTower->GetDigitsList() ;
241 Int_t iphi = 0 ;//x direction
242 Int_t ieta = 0 ;//z direstion
247 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++)
249 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At(digitsList[iDigit] ) ) ;
252 fGeom->GetCellIndex(digit->GetId(),iSupMod,iTower,iIphi,iIeta);
253 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
254 iIphi, iIeta,iphi,ieta);
255 EvalParsPhiDependence(digit->GetId(),fGeom);
259 while(iparam < nPar )
261 xpar = fitparameters[iparam] ;
262 zpar = fitparameters[iparam+1] ;
263 epar = fitparameters[iparam+2] ;
266 efit[iDigit] += epar * ShowerShapeV2((Float_t)iphi - xpar,(Float_t)ieta - zpar) ;
268 } else AliDebug(1,"Digit NULL part 2!");
272 //**************************** part 3 *******************************************
273 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
274 // so that energy deposited in each cell is distributed between new clusters proportionally
275 // to its contribution to efit
277 Float_t * energiesList = iniTower->GetEnergiesList() ;
279 Float_t eDigit = 0. ;
280 Int_t nSplittedClusters=(Int_t)nPar/3;
282 Float_t * correctedEnergyList = new Float_t[nDigits*nSplittedClusters];
283 //above - temporary table with energies after unfolding.
284 //the orderis following:
285 //first cluster <first cell - last cell>,
286 //second cluster <first cell - last cell>, etc.
288 //**************************** sub-part 3.1 *************************************
289 //here we check if energy of the cell in the cluster after unfolding is above threshold.
290 //If not the energy from a given cell in the cluster is divided in correct proportions
291 //in accordance to the other clusters and added to them and set to 0.
294 while(iparam < nPar )
296 xpar = fitparameters[iparam] ;
297 zpar = fitparameters[iparam+1] ;
298 epar = fitparameters[iparam+2] ;
300 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++)
302 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At( digitsList[iDigit] ) ) ;
305 fGeom->GetCellIndex(digit->GetId(),iSupMod,iTower,iIphi,iIeta);
306 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
307 iIphi, iIeta,iphi,ieta);
309 EvalParsPhiDependence(digit->GetId(),fGeom);
313 correctedEnergyList[iparam/3+iDigit] = 0;
317 ratio = epar * ShowerShapeV2((Float_t)iphi - xpar,(Float_t)ieta - zpar) / efit[iDigit] ;
318 eDigit = energiesList[iDigit] * ratio ;
320 //add energy to temporary matrix
321 correctedEnergyList[iparam/3+iDigit] = eDigit;
323 } else AliDebug(1,"NULL digit part 3");
328 //**************************** sub-part 3.2 *************************************
329 //here we correct energy for each cell and cluster
330 Float_t maximumEne=0;
331 Int_t maximumIndex=0;
332 Bool_t isAnyBelowThreshold=kFALSE;
333 // Float_t Threshold=0.01;
334 Float_t * energyFraction = new Float_t[nSplittedClusters];
336 for(iDigit = 0 ; iDigit < nDigits ; iDigit++)
338 isAnyBelowThreshold=kFALSE;
340 for(iparam = 0 ; iparam < nPar ; iparam+=3)
343 if(correctedEnergyList[iparam/3+iDigit] < fThreshold ) isAnyBelowThreshold = kTRUE;
344 if(correctedEnergyList[iparam/3+iDigit] > maximumEne)
346 maximumEne = correctedEnergyList[iparam/3+iDigit];
347 maximumIndex = iparam;
349 }//end of loop over clusters after unfolding
351 if(!isAnyBelowThreshold) continue; //no cluster-cell below threshold
353 //printf("Correct E cell %f < %f, org Digit index %d, e = %f\n",correctedEnergyList[iparam/3+iDigit],fThreshold,iDigit, energiesList[iDigit]);
354 //if( energiesList[iDigit] < correctedEnergyList[iparam/3+iDigit]) printf("\t What? \n");
356 if(maximumEne < fThreshold)
357 {//add all cluster cells and put energy into max index, other set to 0
359 for(iparam = 0 ; iparam < nPar ; iparam+=3)
361 maximumEne+=correctedEnergyList[iparam/3+iDigit];
362 correctedEnergyList[iparam/3+iDigit]=0;
364 correctedEnergyList[maximumIndex/3+iDigit]=maximumEne;
368 //divide energy of cell below threshold in the correct proportion and add to other cells
369 maximumEne=0;//not used any more so use it for the energy sum
370 for(iparam = 0 ; iparam < nPar ; iparam+=3)
371 {//calculate energy sum
372 if(correctedEnergyList[iparam/3+iDigit] < fThreshold) energyFraction[iparam/3]=0;
375 energyFraction[iparam/3]=1;
376 maximumEne+=correctedEnergyList[iparam/3+iDigit];
378 }//end of loop over clusters after unfolding
381 for(iparam = 0 ; iparam < nPar ; iparam+=3){//calculate fraction
382 energyFraction[iparam/3] = energyFraction[iparam/3] * correctedEnergyList[iparam/3+iDigit] / maximumEne;
385 for(iparam = 0 ; iparam < nPar ; iparam+=3)
386 {//add energy from cells below threshold to others
387 if(energyFraction[iparam/3]>0) continue;
390 for(iparam2 = 0 ; iparam2 < nPar ; iparam2+=3)
392 correctedEnergyList[iparam2/3+iDigit] += (energyFraction[iparam2/3] *
393 correctedEnergyList[iparam/3+iDigit]) ;
395 correctedEnergyList[iparam/3+iDigit] = 0;
401 //digit energy to be set to 0
402 for(iparam = 0 ; iparam < nPar ; iparam+=3)
404 correctedEnergyList[iparam/3+iDigit] = 0;
406 }//new adam correction for is energy>0
408 }//end of loop over digits
409 delete[] energyFraction;
411 //**************************** sub-part 3.3 *************************************
412 //here we add digits to recpoints with corrected energy
414 while(iparam < nPar )
416 AliEMCALRecPoint * recPoint = 0 ;
418 if(fNumberOfECAClusters >= fRecPoints->GetSize())
419 fRecPoints->Expand(2*fNumberOfECAClusters) ;
422 (*fRecPoints)[fNumberOfECAClusters] = new AliEMCALRecPoint("") ;
423 recPoint = dynamic_cast<AliEMCALRecPoint *>( fRecPoints->At(fNumberOfECAClusters) ) ;
427 fNumberOfECAClusters++ ;
428 recPoint->SetNExMax(nSplittedClusters) ;
430 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++)
432 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At( digitsList[iDigit] ) ) ;
435 if(digit && correctedEnergyList[iparam/3+iDigit]>0. )
437 //if(correctedEnergyList[iparam/3+iDigit]<fThreshold) printf("Final E cell %f < %f\n",correctedEnergyList[iparam/3+iDigit],fThreshold);
438 recPoint->AddDigit( *digit, correctedEnergyList[iparam/3+iDigit], kFALSE ) ; //FIXME, need to study the shared case
441 AliDebug(1,Form("NULL digit part3.3 or NULL energy=%f",correctedEnergyList[iparam/3+iDigit]));
442 //cout<<"nDigits "<<nDigits<<" iParam/3 "<<iparam/3<< endl;
445 } else AliError("NULL RecPoint");
447 //protection from recpoint with no digits
448 //cout<<"multi rec "<<recPoint->GetMultiplicity()<<endl;
449 if(recPoint->GetMultiplicity()==0)
451 delete (*fRecPoints)[fNumberOfECAClusters];
452 //cout<<"size fRecPoints before "<<fRecPoints->GetSize()<<endl;
453 fRecPoints->RemoveAt(fNumberOfECAClusters);
454 //cout<<"size fRecPoints after "<<fRecPoints->GetSize()<<endl;
455 fNumberOfECAClusters--;
463 delete[] fitparameters ;
465 delete[] correctedEnergyList ;
471 //____________________________________________________________________________
472 Bool_t AliEMCALUnfolding::UnfoldClusterV2old(AliEMCALRecPoint * iniTower,
474 AliEMCALDigit ** maxAt,
475 Float_t * maxAtEnergy)
477 // Extended to whole EMCAL
478 // Performs the unfolding of a cluster with nMax overlapping showers
480 Int_t nPar = 3 * nMax ;
481 Float_t * fitparameters = new Float_t[nPar] ;
484 AliFatal("Did not get geometry from EMCALLoader") ;
486 Bool_t rv = FindFitV2(iniTower, maxAt, maxAtEnergy, nPar, fitparameters) ;
488 // Fit failed, return (and remove cluster? - why? I leave the cluster)
489 iniTower->SetNExMax(-1) ;
490 delete[] fitparameters ;
494 // create unfolded rec points and fill them with new energy lists
495 // First calculate energy deposited in each sell in accordance with
496 // fit (without fluctuations): efit[]
497 // and later correct this number in acordance with actual energy
500 Int_t nDigits = iniTower->GetMultiplicity() ;
501 Float_t * efit = new Float_t[nDigits] ;//new fitted energy in cells
502 Float_t xpar=0.,zpar=0.,epar=0. ;//center of gravity in cell units
504 AliEMCALDigit * digit = 0 ;
505 Int_t * digitsList = iniTower->GetDigitsList() ;
511 Int_t iphi = 0 ;//x direction
512 Int_t ieta = 0 ;//z direstion
517 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
518 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At(digitsList[iDigit] ) ) ;
520 fGeom->GetCellIndex(digit->GetId(),iSupMod,iTower,iIphi,iIeta);
521 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
522 iIphi, iIeta,iphi,ieta);
523 EvalParsPhiDependence(digit->GetId(),fGeom);
527 while(iparam < nPar ){
528 xpar = fitparameters[iparam] ;
529 zpar = fitparameters[iparam+1] ;
530 epar = fitparameters[iparam+2] ;
533 efit[iDigit] += epar * ShowerShapeV2((Float_t)iphi - xpar,(Float_t)ieta - zpar) ;
535 } else AliError("Digit NULL!");
539 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
540 // so that energy deposited in each cell is distributed between new clusters proportionally
541 // to its contribution to efit
543 Float_t * energiesList = iniTower->GetEnergiesList() ;
547 while(iparam < nPar ){
548 xpar = fitparameters[iparam] ;
549 zpar = fitparameters[iparam+1] ;
550 epar = fitparameters[iparam+2] ;
553 AliEMCALRecPoint * recPoint = 0 ;
555 if(fNumberOfECAClusters >= fRecPoints->GetSize())
556 fRecPoints->Expand(2*fNumberOfECAClusters) ;
559 (*fRecPoints)[fNumberOfECAClusters] = new AliEMCALRecPoint("") ;
560 recPoint = dynamic_cast<AliEMCALRecPoint *>( fRecPoints->At(fNumberOfECAClusters) ) ;
564 fNumberOfECAClusters++ ;
565 recPoint->SetNExMax((Int_t)nPar/3) ;
567 Float_t eDigit = 0. ;
568 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
569 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At( digitsList[iDigit] ) ) ;
571 fGeom->GetCellIndex(digit->GetId(),iSupMod,iTower,iIphi,iIeta);
572 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
573 iIphi, iIeta,iphi,ieta);
574 EvalParsPhiDependence(digit->GetId(),fGeom);
575 if(efit[iDigit]==0) continue;//just for sure
576 ratio = epar * ShowerShapeV2((Float_t)iphi - xpar,(Float_t)ieta - zpar) / efit[iDigit] ;
577 eDigit = energiesList[iDigit] * ratio ;
578 recPoint->AddDigit( *digit, eDigit, kFALSE ) ; //FIXME, need to study the shared case
579 } else AliError("NULL digit");
581 } else AliError("NULL RecPoint");
584 delete[] fitparameters ;
591 //____________________________________________________________________________
592 Bool_t AliEMCALUnfolding::FindFitV2(AliEMCALRecPoint * recPoint, AliEMCALDigit ** maxAt,
593 const Float_t* maxAtEnergy,
594 Int_t nPar, Float_t * fitparameters) const
596 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
597 // The initial values for fitting procedure are set equal to the
598 // positions of local maxima.
599 // Cluster will be fitted as a superposition of nPar/3
600 // electromagnetic showers
602 if (fGeom==0) AliFatal("Did not get geometry from EMCALLoader");
605 gMinuit = new TMinuit(100) ;//max 100 parameters
607 gMinuit->mncler(); // Reset Minuit's list of paramters
608 gMinuit->SetPrintLevel(-1) ; // No Printout
609 gMinuit->SetFCN(AliEMCALUnfolding::UnfoldingChiSquareV2) ;
610 // To set the address of the minimization function
611 TList * toMinuit = new TList();
612 toMinuit->AddAt(recPoint,0) ;
613 toMinuit->AddAt(fDigitsArr,1) ;
614 toMinuit->AddAt(fGeom,2) ;
616 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
618 // filling initial values for fit parameters
619 AliEMCALDigit * digit ;
623 Int_t nDigits = (Int_t) nPar / 3 ;
631 Int_t iphi = 0 ;//x direction
632 Int_t ieta = 0 ;//z direstion
634 for(iDigit = 0; iDigit < nDigits; iDigit++){
635 digit = maxAt[iDigit];
636 if(digit==0) AliError("energy of digit = 0!");
637 fGeom->GetCellIndex(digit->GetId(),iSupMod,iTower,iIphi,iIeta);
638 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
639 iIphi, iIeta,iphi,ieta);
641 Float_t energy = maxAtEnergy[iDigit] ;
643 //gMinuit->mnparm(index, "x", iphi, 0.1, 0, 0, ierflg) ;//original
644 gMinuit->mnparm(index, "x", iphi, 0.05, 0, 0, ierflg) ;
647 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : x = %d", iphi ) ;
652 //gMinuit->mnparm(index, "z", ieta, 0.1, 0, 0, ierflg) ;//original
653 gMinuit->mnparm(index, "z", ieta, 0.05, 0, 0, ierflg) ;
656 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : z = %d", ieta) ;
661 //gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;//original
662 gMinuit->mnparm(index, "Energy", energy , 0.001*energy, 0., 5.*energy, ierflg) ;//was 0.05
665 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : energy = %f", energy) ;
672 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ;
673 // The number of function call slightly depends on it.
674 // Double_t p1 = 1.0 ;// par to gradient
676 // Double_t p3 = 3.0 ;
677 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
678 // gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
679 gMinuit->SetMaxIterations(5);//was 5
680 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
681 //gMinuit->mnexcm("SET PRI", &p3 , 3, ierflg) ; // printouts
683 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
684 //gMinuit->mnexcm("MINI", &p0, 0, ierflg) ; // minimize
685 if(ierflg == 4){ // Minimum not found
686 AliDebug(1,"EMCAL Unfolding Fit not converged, cluster abandoned " ) ;
691 for(index = 0; index < nPar; index++){
694 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
695 fitparameters[index] = val ;
704 //____________________________________________________________________________
705 Double_t AliEMCALUnfolding::ShowerShapeV2(Double_t x, Double_t y)
707 // extended to whole EMCAL
708 // Shape of the shower
709 // If you change this function, change also the gradient evaluation in ChiSquare()
711 Double_t r = fgSSPars[7]*TMath::Sqrt(x*x+y*y);
712 Double_t rp1 = TMath::Power(r, fgSSPars[1]) ;
713 Double_t rp5 = TMath::Power(r, fgSSPars[5]) ;
714 Double_t shape = fgSSPars[0]*TMath::Exp( -rp1 * (1. / (fgSSPars[2] + fgSSPars[3] * rp1) + fgSSPars[4] / (1 + fgSSPars[6] * rp5) ) ) ;
718 //____________________________________________________________________________
719 void AliEMCALUnfolding::UnfoldingChiSquareV2(Int_t & nPar, Double_t * Grad,
721 Double_t * x, Int_t iflag)
723 // Calculates the Chi square for the cluster unfolding minimization
724 // Number of parameters, Gradient, Chi squared, parameters, what to do
726 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
728 AliEMCALRecPoint * recPoint = dynamic_cast<AliEMCALRecPoint*>( toMinuit->At(0) ) ;
729 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
730 // A bit buggy way to get an access to the geometry
732 AliEMCALGeometry *geom = dynamic_cast<AliEMCALGeometry *>(toMinuit->At(2));
734 if(recPoint && digits && geom){
736 Int_t * digitsList = recPoint->GetDigitsList() ;
738 Int_t nOdigits = recPoint->GetDigitsMultiplicity() ;
740 Float_t * energiesList = recPoint->GetEnergiesList() ;
746 for(iparam = 0 ; iparam < nPar ; iparam++)
747 Grad[iparam] = 0 ; // Will evaluate gradient
751 AliEMCALDigit * digit ;
758 Int_t iphi = 0 ;//x direction
759 Int_t ieta = 0 ;//z direstion
762 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
763 if(energiesList[iDigit]==0) continue;
765 digit = dynamic_cast<AliEMCALDigit*>( digits->At( digitsList[iDigit] ) );
768 geom->GetCellIndex(digit->GetId(),iSupMod,iTower,iIphi,iIeta);
769 geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
770 iIphi, iIeta,iphi,ieta);
771 EvalParsPhiDependence(digit->GetId(),geom);
773 if(iflag == 2){ // calculate gradient
776 while(iParam < nPar ){
777 Double_t dx = ((Float_t)iphi - x[iParam]) ;
779 Double_t dz = ((Float_t)ieta - x[iParam]) ;
781 efit += x[iParam] * ShowerShapeV2(dx,dz) ;
785 Double_t sum = 2. * (efit - energiesList[iDigit]) / energiesList[iDigit] ; // Here we assume, that sigma = sqrt(E)
787 while(iParam < nPar ){
788 Double_t xpar = x[iParam] ;
789 Double_t zpar = x[iParam+1] ;
790 Double_t epar = x[iParam+2] ;
792 Double_t dr = fgSSPars[7]*TMath::Sqrt( ((Float_t)iphi - xpar) * ((Float_t)iphi - xpar) + ((Float_t)ieta - zpar) * ((Float_t)ieta - zpar) );
793 Double_t shape = sum * ShowerShapeV2((Float_t)iphi - xpar,(Float_t)ieta - zpar) ;
794 Double_t rp1 = TMath::Power(dr, fgSSPars[1]) ;
795 Double_t rp5 = TMath::Power(dr, fgSSPars[5]) ;
797 Double_t deriv = -2 * TMath::Power(dr,fgSSPars[1]-2.) * fgSSPars[7] * fgSSPars[7] *
798 (fgSSPars[1] * ( 1/(fgSSPars[2]+fgSSPars[3]*rp1) + fgSSPars[4]/(1+fgSSPars[6]*rp5) ) -
799 (fgSSPars[1]*fgSSPars[3]*rp1/( (fgSSPars[2]+fgSSPars[3]*rp1)*(fgSSPars[2]+fgSSPars[3]*rp1) ) +
800 fgSSPars[4]*fgSSPars[5]*fgSSPars[6]*rp5/( (1+fgSSPars[6]*rp5)*(1+fgSSPars[6]*rp5) ) ) );
802 //Double_t deriv =-1.33 * TMath::Power(dr,0.33)*dr * ( 1.57 / ( (1.57 + 0.0860 * r133) * (1.57 + 0.0860 * r133) )
803 // - 0.55 / (1 + 0.000563 * r669) / ( (1 + 0.000563 * r669) * (1 + 0.000563 * r669) ) ) ;
805 Grad[iParam] += epar * shape * deriv * ((Float_t)iphi - xpar) ; // Derivative over x
807 Grad[iParam] += epar * shape * deriv * ((Float_t)ieta - zpar) ; // Derivative over z
809 Grad[iParam] += shape ; // Derivative over energy
816 while(iparam < nPar ){
817 Double_t xpar = x[iparam] ;
818 Double_t zpar = x[iparam+1] ;
819 Double_t epar = x[iparam+2] ;
821 efit += epar * ShowerShapeV2((Float_t)iphi - xpar,(Float_t)ieta - zpar) ;
824 fret += (efit-energiesList[iDigit])*(efit-energiesList[iDigit])/energiesList[iDigit] ;
825 // Here we assume, that sigma = sqrt(E)
826 } else printf("AliEMCALUnfoding::UnfoldingChiSquareV2 - NULL digit!, nPar %d \n", nPar); // put nPar here to cheat coverity and rule checker
828 } // recpoint, digits and geom not NULL
834 //____________________________________________________________________________
835 void AliEMCALUnfolding::SetShowerShapeParams(Double_t *pars){
836 for(UInt_t i=0;i<7;++i)
838 if(pars[2]==0. && pars[3]==0.) fgSSPars[2]=1.;//to avoid dividing by 0
841 //____________________________________________________________________________
842 void AliEMCALUnfolding::SetPar5(Double_t *pars){
843 for(UInt_t i=0;i<3;++i)
847 //____________________________________________________________________________
848 void AliEMCALUnfolding::SetPar6(Double_t *pars){
849 for(UInt_t i=0;i<3;++i)
853 //____________________________________________________________________________
854 void AliEMCALUnfolding::EvalPar5(Double_t phi){
856 //Evaluate the 5th parameter of the shower shape function
857 //phi in degrees range (-10,10)
859 //fSSPars[5] = 12.31 - phi*0.007381 - phi*phi*0.06936;
860 fgSSPars[5] = fgPar5[0] + phi * fgPar5[1] + phi*phi * fgPar5[2];
863 //____________________________________________________________________________
864 void AliEMCALUnfolding::EvalPar6(Double_t phi){
866 //Evaluate the 6th parameter of the shower shape function
867 //phi in degrees range (-10,10)
869 //fSSPars[6] = 0.05452 + phi*0.0001228 + phi*phi*0.001361;
870 fgSSPars[6] = fgPar6[0] + phi * fgPar6[1] + phi*phi * fgPar6[2];
873 //____________________________________________________________________________
874 void AliEMCALUnfolding::EvalParsPhiDependence(Int_t absId, const AliEMCALGeometry *geom){
876 // calculate params p5 and p6 depending on the phi angle in global coordinate
877 // for the cell with given absId index
879 Double_t etaGlob = 0.;//eta in global c.s. - unused
880 Double_t phiGlob = 0.;//phi in global c.s. in radians
881 geom->EtaPhiFromIndex(absId, etaGlob, phiGlob);
882 phiGlob*=180./TMath::Pi();
884 phiGlob-= (Double_t)((Int_t)geom->GetSuperModuleNumber(absId)/2 * 20);