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 Int_t nPar = 3 * nMax ;
207 Float_t * fitparameters = new Float_t[nPar] ;
210 AliFatal("Did not get geometry from EMCALLoader") ;
212 Bool_t rv = FindFitV2(iniTower, maxAt, maxAtEnergy, nPar, fitparameters) ;
214 // Fit failed, return (and remove cluster? - why? I leave the cluster)
215 iniTower->SetNExMax(-1) ;
216 delete[] fitparameters ;
220 //**************************** part 2 *******************************************
221 // create unfolded rec points and fill them with new energy lists
222 // First calculate energy deposited in each sell in accordance with
223 // fit (without fluctuations): efit[]
224 // and later correct this number in acordance with actual energy
227 Int_t nDigits = iniTower->GetMultiplicity() ;
228 Float_t * efit = new Float_t[nDigits] ;//new fitted energy in cells
229 Float_t xpar=0.,zpar=0.,epar=0. ;//center of gravity in cell units
231 AliEMCALDigit * digit = 0 ;
232 Int_t * digitsList = iniTower->GetDigitsList() ;
238 Int_t iphi = 0 ;//x direction
239 Int_t ieta = 0 ;//z direstion
244 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
245 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At(digitsList[iDigit] ) ) ;
247 fGeom->GetCellIndex(digit->GetId(),iSupMod,iTower,iIphi,iIeta);
248 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
249 iIphi, iIeta,iphi,ieta);
250 EvalParsPhiDependence(digit->GetId(),fGeom);
254 while(iparam < nPar ){
255 xpar = fitparameters[iparam] ;
256 zpar = fitparameters[iparam+1] ;
257 epar = fitparameters[iparam+2] ;
260 efit[iDigit] += epar * ShowerShapeV2((Float_t)iphi - xpar,(Float_t)ieta - zpar) ;
262 } else AliError("Digit NULL part 2!");
266 //**************************** part 3 *******************************************
267 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
268 // so that energy deposited in each cell is distributed between new clusters proportionally
269 // to its contribution to efit
271 Float_t * energiesList = iniTower->GetEnergiesList() ;
273 Float_t eDigit = 0. ;
274 Int_t nSplittedClusters=(Int_t)nPar/3;
276 Float_t * correctedEnergyList = new Float_t[nDigits*nSplittedClusters];
277 //above - temporary table with energies after unfolding.
278 //the orderis following:
279 //first cluster <first cell - last cell>,
280 //second cluster <first cell - last cell>, etc.
282 //**************************** sub-part 3.1 *************************************
283 //here we check if energy of the cell in the cluster after unfolding is above threshold.
284 //If not the energy from a given cell in the cluster is divided in correct proportions
285 //in accordance to the other clusters and added to them and set to 0.
288 while(iparam < nPar ){
289 xpar = fitparameters[iparam] ;
290 zpar = fitparameters[iparam+1] ;
291 epar = fitparameters[iparam+2] ;
294 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
295 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At( digitsList[iDigit] ) ) ;
297 fGeom->GetCellIndex(digit->GetId(),iSupMod,iTower,iIphi,iIeta);
298 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
299 iIphi, iIeta,iphi,ieta);
300 EvalParsPhiDependence(digit->GetId(),fGeom);
301 if(efit[iDigit]==0) {//just for sure
302 correctedEnergyList[iparam/3+iDigit] = 0;
305 ratio = epar * ShowerShapeV2((Float_t)iphi - xpar,(Float_t)ieta - zpar) / efit[iDigit] ;
306 eDigit = energiesList[iDigit] * ratio ;
308 //add energy to temporary matrix
309 correctedEnergyList[iparam/3+iDigit] = eDigit;
311 } else AliError("NULL digit part 3");
316 //**************************** sub-part 3.2 *************************************
317 //here we correct energy for each cell and cluster
318 Float_t maximumEne=0;
319 Int_t maximumIndex=0;
320 Bool_t isAnyBelowThreshold=kFALSE;
321 // Float_t Threshold=0.01;
322 Float_t * energyFraction = new Float_t[nSplittedClusters];
324 for(iDigit = 0 ; iDigit < nDigits ; iDigit++){
325 isAnyBelowThreshold=kFALSE;
327 for(iparam = 0 ; iparam < nPar ; iparam+=3){
329 if(correctedEnergyList[iparam/3+iDigit] < fThreshold ) isAnyBelowThreshold = kTRUE;
330 if(correctedEnergyList[iparam/3+iDigit] > maximumEne) {
331 maximumEne = correctedEnergyList[iparam/3+iDigit];
332 maximumIndex = iparam;
334 }//end of loop over clusters after unfolding
336 if(!isAnyBelowThreshold) continue; //no cluster-cell below threshold
337 if(maximumEne < fThreshold) {//add all cluster cells and put energy into max index, other set to 0
339 for(iparam = 0 ; iparam < nPar ; iparam+=3){
340 maximumEne+=correctedEnergyList[iparam/3+iDigit];
341 correctedEnergyList[iparam/3+iDigit]=0;
343 correctedEnergyList[maximumIndex/3+iDigit]=maximumEne;
347 //divide energy of cell below threshold in the correct proportion and add to other cells
348 maximumEne=0;//not used any more so use it for the energy sum
349 for(iparam = 0 ; iparam < nPar ; iparam+=3){//calculate energy sum
350 if(correctedEnergyList[iparam/3+iDigit] < fThreshold) energyFraction[iparam/3]=0;
352 energyFraction[iparam/3]=1;
353 maximumEne+=correctedEnergyList[iparam/3+iDigit];
355 }//end of loop over clusters after unfolding
357 for(iparam = 0 ; iparam < nPar ; iparam+=3){//calculate fraction
358 energyFraction[iparam/3] = energyFraction[iparam/3] * correctedEnergyList[iparam/3+iDigit] / maximumEne;
361 for(iparam = 0 ; iparam < nPar ; iparam+=3){//add energy from cells below threshold to others
362 if(energyFraction[iparam/3]>0) continue;
364 for(iparam2 = 0 ; iparam2 < nPar ; iparam2+=3){
365 correctedEnergyList[iparam2/3+iDigit] += (energyFraction[iparam2/3] *
366 correctedEnergyList[iparam/3+iDigit]) ;
368 correctedEnergyList[iparam/3+iDigit] = 0;
373 //digit energy to be set to 0
374 for(iparam = 0 ; iparam < nPar ; iparam+=3){
375 correctedEnergyList[iparam/3+iDigit] = 0;
377 }//new adam correction for is energy>0
379 }//end of loop over digits
380 delete[] energyFraction;
382 //**************************** sub-part 3.3 *************************************
383 //here we add digits to recpoints with corrected energy
385 while(iparam < nPar ){
386 AliEMCALRecPoint * recPoint = 0 ;
388 if(fNumberOfECAClusters >= fRecPoints->GetSize())
389 fRecPoints->Expand(2*fNumberOfECAClusters) ;
392 (*fRecPoints)[fNumberOfECAClusters] = new AliEMCALRecPoint("") ;
393 recPoint = dynamic_cast<AliEMCALRecPoint *>( fRecPoints->At(fNumberOfECAClusters) ) ;
397 fNumberOfECAClusters++ ;
398 recPoint->SetNExMax(nSplittedClusters) ;
400 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
401 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At( digitsList[iDigit] ) ) ;
403 if(digit && correctedEnergyList[iparam/3+iDigit]>0. ){
404 recPoint->AddDigit( *digit, correctedEnergyList[iparam/3+iDigit], kFALSE ) ; //FIXME, need to study the shared case
406 AliError("NULL digit part3.3 or energy=0");
407 //cout<<"nDigits "<<nDigits<<" iParam/3 "<<iparam/3<< endl;
410 } else AliError("NULL RecPoint");
411 //protection from recpoint with no digits
412 //cout<<"multi rec "<<recPoint->GetMultiplicity()<<endl;
413 if(recPoint->GetMultiplicity()==0){
414 delete (*fRecPoints)[fNumberOfECAClusters];
415 //cout<<"size fRecPoints before "<<fRecPoints->GetSize()<<endl;
416 fRecPoints->RemoveAt(fNumberOfECAClusters);
417 //cout<<"size fRecPoints after "<<fRecPoints->GetSize()<<endl;
418 fNumberOfECAClusters--;
426 delete[] fitparameters ;
428 delete[] correctedEnergyList ;
434 //____________________________________________________________________________
435 Bool_t AliEMCALUnfolding::UnfoldClusterV2old(AliEMCALRecPoint * iniTower,
437 AliEMCALDigit ** maxAt,
438 Float_t * maxAtEnergy)
440 // Extended to whole EMCAL
441 // Performs the unfolding of a cluster with nMax overlapping showers
443 Int_t nPar = 3 * nMax ;
444 Float_t * fitparameters = new Float_t[nPar] ;
447 AliFatal("Did not get geometry from EMCALLoader") ;
449 Bool_t rv = FindFitV2(iniTower, maxAt, maxAtEnergy, nPar, fitparameters) ;
451 // Fit failed, return (and remove cluster? - why? I leave the cluster)
452 iniTower->SetNExMax(-1) ;
453 delete[] fitparameters ;
457 // create unfolded rec points and fill them with new energy lists
458 // First calculate energy deposited in each sell in accordance with
459 // fit (without fluctuations): efit[]
460 // and later correct this number in acordance with actual energy
463 Int_t nDigits = iniTower->GetMultiplicity() ;
464 Float_t * efit = new Float_t[nDigits] ;//new fitted energy in cells
465 Float_t xpar=0.,zpar=0.,epar=0. ;//center of gravity in cell units
467 AliEMCALDigit * digit = 0 ;
468 Int_t * digitsList = iniTower->GetDigitsList() ;
474 Int_t iphi = 0 ;//x direction
475 Int_t ieta = 0 ;//z direstion
480 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
481 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At(digitsList[iDigit] ) ) ;
483 fGeom->GetCellIndex(digit->GetId(),iSupMod,iTower,iIphi,iIeta);
484 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
485 iIphi, iIeta,iphi,ieta);
486 EvalParsPhiDependence(digit->GetId(),fGeom);
490 while(iparam < nPar ){
491 xpar = fitparameters[iparam] ;
492 zpar = fitparameters[iparam+1] ;
493 epar = fitparameters[iparam+2] ;
496 efit[iDigit] += epar * ShowerShapeV2((Float_t)iphi - xpar,(Float_t)ieta - zpar) ;
498 } else AliError("Digit NULL!");
502 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
503 // so that energy deposited in each cell is distributed between new clusters proportionally
504 // to its contribution to efit
506 Float_t * energiesList = iniTower->GetEnergiesList() ;
510 while(iparam < nPar ){
511 xpar = fitparameters[iparam] ;
512 zpar = fitparameters[iparam+1] ;
513 epar = fitparameters[iparam+2] ;
516 AliEMCALRecPoint * recPoint = 0 ;
518 if(fNumberOfECAClusters >= fRecPoints->GetSize())
519 fRecPoints->Expand(2*fNumberOfECAClusters) ;
522 (*fRecPoints)[fNumberOfECAClusters] = new AliEMCALRecPoint("") ;
523 recPoint = dynamic_cast<AliEMCALRecPoint *>( fRecPoints->At(fNumberOfECAClusters) ) ;
527 fNumberOfECAClusters++ ;
528 recPoint->SetNExMax((Int_t)nPar/3) ;
530 Float_t eDigit = 0. ;
531 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
532 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At( digitsList[iDigit] ) ) ;
534 fGeom->GetCellIndex(digit->GetId(),iSupMod,iTower,iIphi,iIeta);
535 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
536 iIphi, iIeta,iphi,ieta);
537 EvalParsPhiDependence(digit->GetId(),fGeom);
538 if(efit[iDigit]==0) continue;//just for sure
539 ratio = epar * ShowerShapeV2((Float_t)iphi - xpar,(Float_t)ieta - zpar) / efit[iDigit] ;
540 eDigit = energiesList[iDigit] * ratio ;
541 recPoint->AddDigit( *digit, eDigit, kFALSE ) ; //FIXME, need to study the shared case
542 } else AliError("NULL digit");
544 } else AliError("NULL RecPoint");
547 delete[] fitparameters ;
554 //____________________________________________________________________________
555 Bool_t AliEMCALUnfolding::FindFitV2(AliEMCALRecPoint * recPoint, AliEMCALDigit ** maxAt,
556 const Float_t* maxAtEnergy,
557 Int_t nPar, Float_t * fitparameters) const
559 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
560 // The initial values for fitting procedure are set equal to the
561 // positions of local maxima.
562 // Cluster will be fitted as a superposition of nPar/3
563 // electromagnetic showers
565 if (fGeom==0) AliFatal("Did not get geometry from EMCALLoader");
568 gMinuit = new TMinuit(100) ;//max 100 parameters
570 gMinuit->mncler(); // Reset Minuit's list of paramters
571 gMinuit->SetPrintLevel(-1) ; // No Printout
572 gMinuit->SetFCN(AliEMCALUnfolding::UnfoldingChiSquareV2) ;
573 // To set the address of the minimization function
574 TList * toMinuit = new TList();
575 toMinuit->AddAt(recPoint,0) ;
576 toMinuit->AddAt(fDigitsArr,1) ;
577 toMinuit->AddAt(fGeom,2) ;
579 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
581 // filling initial values for fit parameters
582 AliEMCALDigit * digit ;
586 Int_t nDigits = (Int_t) nPar / 3 ;
594 Int_t iphi = 0 ;//x direction
595 Int_t ieta = 0 ;//z direstion
597 for(iDigit = 0; iDigit < nDigits; iDigit++){
598 digit = maxAt[iDigit];
599 if(digit==0) AliError("energy of digit = 0!");
600 fGeom->GetCellIndex(digit->GetId(),iSupMod,iTower,iIphi,iIeta);
601 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
602 iIphi, iIeta,iphi,ieta);
604 Float_t energy = maxAtEnergy[iDigit] ;
606 //gMinuit->mnparm(index, "x", iphi, 0.1, 0, 0, ierflg) ;//original
607 gMinuit->mnparm(index, "x", iphi, 0.05, 0, 0, ierflg) ;
610 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : x = %d", iphi ) ;
615 //gMinuit->mnparm(index, "z", ieta, 0.1, 0, 0, ierflg) ;//original
616 gMinuit->mnparm(index, "z", ieta, 0.05, 0, 0, ierflg) ;
619 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : z = %d", ieta) ;
624 //gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;//original
625 gMinuit->mnparm(index, "Energy", energy , 0.001*energy, 0., 5.*energy, ierflg) ;//was 0.05
628 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : energy = %f", energy) ;
635 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ;
636 // The number of function call slightly depends on it.
637 // Double_t p1 = 1.0 ;// par to gradient
639 // Double_t p3 = 3.0 ;
640 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
641 // gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
642 gMinuit->SetMaxIterations(5);//was 5
643 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
644 //gMinuit->mnexcm("SET PRI", &p3 , 3, ierflg) ; // printouts
646 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
647 //gMinuit->mnexcm("MINI", &p0, 0, ierflg) ; // minimize
648 if(ierflg == 4){ // Minimum not found
649 Error("FindFit", "EMCAL Unfolding Fit not converged, cluster abandoned " ) ;
654 for(index = 0; index < nPar; index++){
657 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
658 fitparameters[index] = val ;
667 //____________________________________________________________________________
668 Double_t AliEMCALUnfolding::ShowerShapeV2(Double_t x, Double_t y)
670 // extended to whole EMCAL
671 // Shape of the shower
672 // If you change this function, change also the gradient evaluation in ChiSquare()
674 Double_t r = fgSSPars[7]*TMath::Sqrt(x*x+y*y);
675 Double_t rp1 = TMath::Power(r, fgSSPars[1]) ;
676 Double_t rp5 = TMath::Power(r, fgSSPars[5]) ;
677 Double_t shape = fgSSPars[0]*TMath::Exp( -rp1 * (1. / (fgSSPars[2] + fgSSPars[3] * rp1) + fgSSPars[4] / (1 + fgSSPars[6] * rp5) ) ) ;
681 //____________________________________________________________________________
682 void AliEMCALUnfolding::UnfoldingChiSquareV2(Int_t & nPar, Double_t * Grad,
684 Double_t * x, Int_t iflag)
686 // Calculates the Chi square for the cluster unfolding minimization
687 // Number of parameters, Gradient, Chi squared, parameters, what to do
689 nPar=nPar;//to cheat rulechecker
691 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
693 AliEMCALRecPoint * recPoint = dynamic_cast<AliEMCALRecPoint*>( toMinuit->At(0) ) ;
694 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
695 // A bit buggy way to get an access to the geometry
697 AliEMCALGeometry *geom = dynamic_cast<AliEMCALGeometry *>(toMinuit->At(2));
699 if(recPoint && digits && geom){
701 Int_t * digitsList = recPoint->GetDigitsList() ;
703 Int_t nOdigits = recPoint->GetDigitsMultiplicity() ;
705 Float_t * energiesList = recPoint->GetEnergiesList() ;
711 for(iparam = 0 ; iparam < nPar ; iparam++)
712 Grad[iparam] = 0 ; // Will evaluate gradient
716 AliEMCALDigit * digit ;
723 Int_t iphi = 0 ;//x direction
724 Int_t ieta = 0 ;//z direstion
727 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
728 if(energiesList[iDigit]==0) continue;
730 digit = dynamic_cast<AliEMCALDigit*>( digits->At( digitsList[iDigit] ) );
733 geom->GetCellIndex(digit->GetId(),iSupMod,iTower,iIphi,iIeta);
734 geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
735 iIphi, iIeta,iphi,ieta);
736 EvalParsPhiDependence(digit->GetId(),geom);
738 if(iflag == 2){ // calculate gradient
741 while(iParam < nPar ){
742 Double_t dx = ((Float_t)iphi - x[iParam]) ;
744 Double_t dz = ((Float_t)ieta - x[iParam]) ;
746 efit += x[iParam] * ShowerShapeV2(dx,dz) ;
750 Double_t sum = 2. * (efit - energiesList[iDigit]) / energiesList[iDigit] ; // Here we assume, that sigma = sqrt(E)
752 while(iParam < nPar ){
753 Double_t xpar = x[iParam] ;
754 Double_t zpar = x[iParam+1] ;
755 Double_t epar = x[iParam+2] ;
757 Double_t dr = fgSSPars[7]*TMath::Sqrt( ((Float_t)iphi - xpar) * ((Float_t)iphi - xpar) + ((Float_t)ieta - zpar) * ((Float_t)ieta - zpar) );
758 Double_t shape = sum * ShowerShapeV2((Float_t)iphi - xpar,(Float_t)ieta - zpar) ;
759 Double_t rp1 = TMath::Power(dr, fgSSPars[1]) ;
760 Double_t rp5 = TMath::Power(dr, fgSSPars[5]) ;
762 Double_t deriv = -2 * TMath::Power(dr,fgSSPars[1]-2.) * fgSSPars[7] * fgSSPars[7] *
763 (fgSSPars[1] * ( 1/(fgSSPars[2]+fgSSPars[3]*rp1) + fgSSPars[4]/(1+fgSSPars[6]*rp5) ) -
764 (fgSSPars[1]*fgSSPars[3]*rp1/( (fgSSPars[2]+fgSSPars[3]*rp1)*(fgSSPars[2]+fgSSPars[3]*rp1) ) +
765 fgSSPars[4]*fgSSPars[5]*fgSSPars[6]*rp5/( (1+fgSSPars[6]*rp5)*(1+fgSSPars[6]*rp5) ) ) );
767 //Double_t deriv =-1.33 * TMath::Power(dr,0.33)*dr * ( 1.57 / ( (1.57 + 0.0860 * r133) * (1.57 + 0.0860 * r133) )
768 // - 0.55 / (1 + 0.000563 * r669) / ( (1 + 0.000563 * r669) * (1 + 0.000563 * r669) ) ) ;
770 Grad[iParam] += epar * shape * deriv * ((Float_t)iphi - xpar) ; // Derivative over x
772 Grad[iParam] += epar * shape * deriv * ((Float_t)ieta - zpar) ; // Derivative over z
774 Grad[iParam] += shape ; // Derivative over energy
781 while(iparam < nPar ){
782 Double_t xpar = x[iparam] ;
783 Double_t zpar = x[iparam+1] ;
784 Double_t epar = x[iparam+2] ;
786 efit += epar * ShowerShapeV2((Float_t)iphi - xpar,(Float_t)ieta - zpar) ;
789 fret += (efit-energiesList[iDigit])*(efit-energiesList[iDigit])/energiesList[iDigit] ;
790 // Here we assume, that sigma = sqrt(E)
791 } else printf("AliEMCALUnfoding::UnfoldingChiSquareV2 - NULL digit!\n");
793 } // recpoint, digits and geom not NULL
799 //____________________________________________________________________________
800 void AliEMCALUnfolding::SetShowerShapeParams(Double_t *pars){
801 for(UInt_t i=0;i<7;++i)
803 if(pars[2]==0. && pars[3]==0.) fgSSPars[2]=1.;//to avoid dividing by 0
806 //____________________________________________________________________________
807 void AliEMCALUnfolding::SetPar5(Double_t *pars){
808 for(UInt_t i=0;i<3;++i)
812 //____________________________________________________________________________
813 void AliEMCALUnfolding::SetPar6(Double_t *pars){
814 for(UInt_t i=0;i<3;++i)
818 //____________________________________________________________________________
819 void AliEMCALUnfolding::EvalPar5(Double_t phi){
821 //Evaluate the 5th parameter of the shower shape function
822 //phi in degrees range (-10,10)
824 //fSSPars[5] = 12.31 - phi*0.007381 - phi*phi*0.06936;
825 fgSSPars[5] = fgPar5[0] + phi * fgPar5[1] + phi*phi * fgPar5[2];
828 //____________________________________________________________________________
829 void AliEMCALUnfolding::EvalPar6(Double_t phi){
831 //Evaluate the 6th parameter of the shower shape function
832 //phi in degrees range (-10,10)
834 //fSSPars[6] = 0.05452 + phi*0.0001228 + phi*phi*0.001361;
835 fgSSPars[6] = fgPar6[0] + phi * fgPar6[1] + phi*phi * fgPar6[2];
838 //____________________________________________________________________________
839 void AliEMCALUnfolding::EvalParsPhiDependence(Int_t absId, const AliEMCALGeometry *geom){
841 // calculate params p5 and p6 depending on the phi angle in global coordinate
842 // for the cell with given absId index
844 Double_t etaGlob = 0.;//eta in global c.s. - unused
845 Double_t phiGlob = 0.;//phi in global c.s. in radians
846 geom->EtaPhiFromIndex(absId, etaGlob, phiGlob);
847 phiGlob*=180./TMath::Pi();
849 phiGlob-= (Double_t)((Int_t)geom->GetSuperModuleNumber(absId)/2 * 20);