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 **************************************************************************/
18 //-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
19 // August 2002 Yves Schutz: clone PHOS as closely as possible and intoduction
20 // of new IO (à la PHOS)
21 // Mar 2007, Aleksei Pavlinov - new algoritmh of pseudo clusters
22 //////////////////////////////////////////////////////////////////////////////
23 // Clusterization class. Performs clusterization (collects neighbouring active cells) and
24 // unfolds the clusters having several local maxima.
25 // Results are stored in TreeR#, branches EMCALTowerRP (EMC recPoints),
26 // EMCALPreShoRP (CPV RecPoints) and AliEMCALClusterizer (Clusterizer with all
27 // parameters including input digits branch title, thresholds etc.)
28 // This TTask is normally called from Reconstructioner, but can as well be used in
31 // root [0] AliEMCALClusterizerv1 * cl = new AliEMCALClusterizerv1("galice.root")
32 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
33 // //reads gAlice from header file "..."
34 // root [1] cl->ExecuteTask()
35 // //finds RecPoints in all events stored in galice.root
36 // root [2] cl->SetDigitsBranch("digits2")
37 // //sets another title for Digitis (input) branch
38 // root [3] cl->SetRecPointsBranch("recp2")
39 // //sets another title four output branches
40 // root [4] cl->SetTowerLocalMaxCut(0.03)
41 // //set clusterization parameters
42 // root [5] cl->ExecuteTask("deb all time")
43 // //once more finds RecPoints options are
44 // // deb - print number of found rec points
45 // // deb all - print number of found RecPoints and some their characteristics
46 // // time - print benchmarking results
48 // --- ROOT system ---
59 #include <TBenchmark.h>
63 // --- Standard library ---
66 // --- AliRoot header files ---
67 #include "AliRunLoader.h"
70 #include "AliEMCALClusterizerv1.h"
71 #include "AliEMCALRecPoint.h"
72 #include "AliEMCALDigit.h"
73 #include "AliEMCALDigitizer.h"
75 #include "AliEMCALGeometry.h"
76 #include "AliEMCALRecParam.h"
77 #include "AliEMCALReconstructor.h"
78 #include "AliCDBManager.h"
81 #include "AliCDBEntry.h"
83 ClassImp(AliEMCALClusterizerv1)
85 //____________________________________________________________________________
86 AliEMCALClusterizerv1::AliEMCALClusterizerv1()
87 : AliEMCALClusterizer(),
91 fNumberOfECAClusters(0),fCalibData(0),
92 fADCchannelECA(0.),fADCpedestalECA(0.),fECAClusteringThreshold(0.),fECALocMaxCut(0.),
93 fECAW0(0.),fTimeCut(0.),fMinECut(0.)
95 // ctor with the indication of the file where header Tree and digits Tree are stored
100 //____________________________________________________________________________
101 AliEMCALClusterizerv1::AliEMCALClusterizerv1(AliEMCALGeometry* geometry)
102 : AliEMCALClusterizer(),
104 fDefaultInit(kFALSE),
106 fNumberOfECAClusters(0),fCalibData(0),
107 fADCchannelECA(0.),fADCpedestalECA(0.),fECAClusteringThreshold(0.),fECALocMaxCut(0.),
108 fECAW0(0.),fTimeCut(0.),fMinECut(0.)
110 // ctor with the indication of the file where header Tree and digits Tree are stored
111 // use this contructor to avoid usage of Init() which uses runloader
112 // change needed by HLT - MP
114 // Note for the future: the use on runloader should be avoided or optional at least
115 // another way is to make Init virtual and protected at least such that the deriving classes can overload
121 AliFatal("Geometry not initialized.");
125 gMinuit = new TMinuit(100) ;
129 //____________________________________________________________________________
130 AliEMCALClusterizerv1::~AliEMCALClusterizerv1()
135 //____________________________________________________________________________
136 Float_t AliEMCALClusterizerv1::Calibrate(Int_t amp, Int_t AbsId)
139 // Convert digitized amplitude into energy.
140 // Calibration parameters are taken from calibration data base for raw data,
141 // or from digitizer parameters for simulated data.
146 AliFatal("Did not get geometry from EMCALLoader") ;
155 Bool_t bCell = fGeom->GetCellIndex(AbsId, iSupMod, nModule, nIphi, nIeta) ;
157 fGeom->PrintGeometry();
158 Error("Calibrate()"," Wrong cell id number : %i", AbsId);
162 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,nModule,nIphi, nIeta,iphi,ieta);
164 fADCchannelECA = fCalibData->GetADCchannel (iSupMod,ieta,iphi);
165 fADCpedestalECA = fCalibData->GetADCpedestal(iSupMod,ieta,iphi);
167 return -fADCpedestalECA + amp * fADCchannelECA ;
170 else //Return energy with default parameters if calibration is not available
171 return -fADCpedestalECA + amp * fADCchannelECA ;
175 //____________________________________________________________________________
176 void AliEMCALClusterizerv1::Digits2Clusters(Option_t * option)
178 // Steering method to perform clusterization for the current event
181 if(strstr(option,"tim"))
182 gBenchmark->Start("EMCALClusterizer");
184 if(strstr(option,"print"))
187 //Get calibration parameters from file or digitizer default values.
188 GetCalibrationParameters() ;
191 fNumberOfECAClusters = 0;
193 MakeClusters() ; //only the real clusters
200 //Evaluate position, dispersion and other RecPoint properties for EC section
201 for(index = 0; index < fRecPoints->GetEntries(); index++) {
202 dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index))->EvalAll(fECAW0,fDigitsArr) ;
207 for(index = 0; index < fRecPoints->GetEntries(); index++) {
208 (dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index)))->SetIndexInList(index) ;
209 (dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index)))->Print();
214 if(strstr(option,"deb") || strstr(option,"all"))
215 PrintRecPoints(option) ;
217 AliDebug(1,Form("EMCAL Clusterizer found %d Rec Points",fRecPoints->GetEntriesFast()));
219 if(strstr(option,"tim")){
220 gBenchmark->Stop("EMCALClusterizer");
221 printf("Exec took %f seconds for Clusterizing",
222 gBenchmark->GetCpuTime("EMCALClusterizer"));
226 //____________________________________________________________________________
227 Bool_t AliEMCALClusterizerv1::FindFit(AliEMCALRecPoint * RecPoint, AliEMCALDigit ** maxAt,
228 Float_t* maxAtEnergy,
229 Int_t nPar, Float_t * fitparameters) const
231 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
232 // The initial values for fitting procedure are set equal to the
233 // positions of local maxima.
234 // Cluster will be fitted as a superposition of nPar/3
235 // electromagnetic showers
237 if (fGeom==0) AliFatal("Did not get geometry from EMCALLoader");
239 gMinuit->mncler(); // Reset Minuit's list of paramters
240 gMinuit->SetPrintLevel(-1) ; // No Printout
241 gMinuit->SetFCN(AliEMCALClusterizerv1::UnfoldingChiSquare) ;
242 // To set the address of the minimization function
243 TList * toMinuit = new TList();
244 toMinuit->AddAt(RecPoint,0) ;
245 toMinuit->AddAt(fDigitsArr,1) ;
246 toMinuit->AddAt(fGeom,2) ;
248 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
250 // filling initial values for fit parameters
251 AliEMCALDigit * digit ;
255 Int_t nDigits = (Int_t) nPar / 3 ;
259 for(iDigit = 0; iDigit < nDigits; iDigit++){
260 digit = maxAt[iDigit];
265 fGeom->RelPosCellInSModule(digit->GetId(), y, x, z);
267 Float_t energy = maxAtEnergy[iDigit] ;
269 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
272 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : x = %f", x ) ;
275 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
278 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : z = %f", z) ;
281 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
284 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : energy = %f", energy) ;
289 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ;
290 // The number of function call slightly depends on it.
291 //Double_t p1 = 1.0 ;
294 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
295 // gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
296 gMinuit->SetMaxIterations(5);
297 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
298 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
300 if(ierflg == 4){ // Minimum not found
301 Error("FindFit", "EMCAL Unfolding Fit not converged, cluster abandoned " ) ;
304 for(index = 0; index < nPar; index++){
307 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
308 fitparameters[index] = val ;
316 //____________________________________________________________________________
317 void AliEMCALClusterizerv1::GetCalibrationParameters()
319 // Set calibration parameters:
320 // if calibration database exists, they are read from database,
321 // otherwise, they are taken from digitizer.
323 // It is a user responsilibity to open CDB before reconstruction,
325 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
327 //Check if calibration is stored in data base
329 if(!fCalibData && (AliCDBManager::Instance()->IsDefaultStorageSet()))
331 AliCDBEntry *entry = (AliCDBEntry*)
332 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
333 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
337 AliFatal("Calibration parameters not found in CDB!");
341 //____________________________________________________________________________
342 void AliEMCALClusterizerv1::Init()
344 // Make all memory allocations which can not be done in default constructor.
345 // Attach the Clusterizer task to the list of EMCAL tasks
347 AliRunLoader *rl = AliRunLoader::Instance();
348 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL"))
349 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
351 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
353 AliDebug(1,Form("geom 0x%x",fGeom));
356 gMinuit = new TMinuit(100) ;
360 //____________________________________________________________________________
361 void AliEMCALClusterizerv1::InitParameters()
363 // Initializes the parameters for the Clusterizer
364 fNumberOfECAClusters = 0;
365 fTimeCut = 300e-9 ; // 300 ns time cut (to be tuned)
369 const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
371 AliFatal("Reconstruction parameters for EMCAL not set!");
373 fECAClusteringThreshold = recParam->GetClusteringThreshold();
374 fECAW0 = recParam->GetW0();
375 fMinECut = recParam->GetMinECut();
376 fToUnfold = recParam->GetUnfold();
377 if(fToUnfold) AliWarning("Cluster Unfolding ON. Implementing only for eta=0 case!!!");
378 fECALocMaxCut = recParam->GetLocMaxCut();
380 AliDebug(1,Form("Reconstruction parameters: fECAClusteringThreshold=%.3f, fECAW=%.3f, fMinECut=%.3f, fToUnfold=%d, fECALocMaxCut=%.3f",
381 fECAClusteringThreshold,fECAW0,fMinECut,fToUnfold,fECALocMaxCut));
386 //____________________________________________________________________________
387 Int_t AliEMCALClusterizerv1::AreNeighbours(AliEMCALDigit * d1, AliEMCALDigit * d2) const
389 // Gives the neighbourness of two digits = 0 are not neighbour ; continue searching
391 // = 2 is in different SM; continue searching
392 // neighbours are defined as digits having at least a common vertex
393 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
394 // which is compared to a digit (d2) not yet in a cluster
397 static Int_t nSupMod1=0, nModule1=0, nIphi1=0, nIeta1=0, iphi1=0, ieta1=0;
398 static Int_t nSupMod2=0, nModule2=0, nIphi2=0, nIeta2=0, iphi2=0, ieta2=0;
399 static Int_t rowdiff, coldiff;
402 fGeom->GetCellIndex(d1->GetId(), nSupMod1,nModule1,nIphi1,nIeta1);
403 fGeom->GetCellIndex(d2->GetId(), nSupMod2,nModule2,nIphi2,nIeta2);
404 if(nSupMod1 != nSupMod2) return 2; // different SM
406 fGeom->GetCellPhiEtaIndexInSModule(nSupMod1,nModule1,nIphi1,nIeta1, iphi1,ieta1);
407 fGeom->GetCellPhiEtaIndexInSModule(nSupMod2,nModule2,nIphi2,nIeta2, iphi2,ieta2);
409 rowdiff = TMath::Abs(iphi1 - iphi2);
410 coldiff = TMath::Abs(ieta1 - ieta2) ;
412 // neighbours with at least commom side; May 11, 2007
413 if ((coldiff==0 && abs(rowdiff)==1) || (rowdiff==0 && abs(coldiff)==1)) rv = 1;
415 if (gDebug == 2 && rv==1)
416 printf("AreNeighbours: neighbours=%d, id1=%d, relid1=%d,%d \n id2=%d, relid2=%d,%d \n",
417 rv, d1->GetId(), iphi1,ieta1, d2->GetId(), iphi2,ieta2);
422 //____________________________________________________________________________
423 void AliEMCALClusterizerv1::MakeClusters()
425 // Steering method to construct the clusters stored in a list of Reconstructed Points
426 // A cluster is defined as a list of neighbour digits
427 // Mar 03, 2007 by PAI
429 if (fGeom==0) AliFatal("Did not get geometry from EMCALLoader");
433 // Set up TObjArray with pointers to digits to work on
434 TObjArray *digitsC = new TObjArray();
435 TIter nextdigit(fDigitsArr);
436 AliEMCALDigit *digit;
437 while ( (digit = dynamic_cast<AliEMCALDigit*>(nextdigit())) ) {
438 digitsC->AddLast(digit);
441 double e = 0.0, ehs = 0.0;
442 TIter nextdigitC(digitsC);
444 while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigitC())) ) { // clean up digits
445 e = Calibrate(digit->GetAmp(), digit->GetId());
446 if ( e < fMinECut || digit->GetTimeR() > fTimeCut )
447 digitsC->Remove(digit);
451 AliDebug(1,Form("MakeClusters: Number of digits %d -> (e %f), ehs %d\n",
452 fDigitsArr->GetEntries(),fMinECut,ehs));
456 while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigitC())) ) { // scan over the list of digitsC
457 TArrayI clusterECAdigitslist(fDigitsArr->GetEntries());
459 if(fGeom->CheckAbsCellId(digit->GetId()) && (Calibrate(digit->GetAmp(), digit->GetId()) > fECAClusteringThreshold ) ){
460 // start a new Tower RecPoint
461 if(fNumberOfECAClusters >= fRecPoints->GetSize()) fRecPoints->Expand(2*fNumberOfECAClusters+1) ;
463 AliEMCALRecPoint *recPoint = new AliEMCALRecPoint("") ;
464 fRecPoints->AddAt(recPoint, fNumberOfECAClusters) ;
465 recPoint = dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(fNumberOfECAClusters)) ;
466 fNumberOfECAClusters++ ;
468 recPoint->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
470 recPoint->AddDigit(*digit, Calibrate(digit->GetAmp(), digit->GetId())) ;
471 TObjArray clusterDigits;
472 clusterDigits.AddLast(digit);
473 digitsC->Remove(digit) ;
475 AliDebug(1,Form("MakeClusters: OK id = %d, ene = %f , cell.th. = %f \n", digit->GetId(),
476 Calibrate(digit->GetAmp(),digit->GetId()), fECAClusteringThreshold));
478 // Grow cluster by finding neighbours
479 TIter nextClusterDigit(&clusterDigits);
480 while ( (digit = dynamic_cast<AliEMCALDigit*>(nextClusterDigit())) ) { // scan over digits in cluster
481 TIter nextdigitN(digitsC);
482 AliEMCALDigit *digitN = 0; // digi neighbor
483 while ( (digitN = (AliEMCALDigit *)nextdigitN()) ) { // scan over all digits to look for neighbours
484 if (AreNeighbours(digit, digitN)==1) { // call (digit,digitN) in THAT oder !!!!!
485 recPoint->AddDigit(*digitN, Calibrate(digitN->GetAmp(),digitN->GetId()) ) ;
486 clusterDigits.AddLast(digitN) ;
487 digitsC->Remove(digitN) ;
489 } // scan over digits
490 } // scan over digits already in cluster
492 AliDebug(2,Form("MakeClusters: %d digitd, energy %f \n", clusterDigits.GetEntries(), recPoint->GetEnergy()));
498 AliDebug(1,Form("total no of clusters %d from %d digits",fNumberOfECAClusters,fDigitsArr->GetEntriesFast()));
501 //____________________________________________________________________________
502 void AliEMCALClusterizerv1::MakeUnfolding()
504 // Unfolds clusters using the shape of an ElectroMagnetic shower
505 // Performs unfolding of all clusters
507 if(fNumberOfECAClusters > 0){
509 AliFatal("Did not get geometry from EMCALLoader") ;
510 Int_t nModulesToUnfold = fGeom->GetNCells();
512 Int_t numberofNotUnfolded = fNumberOfECAClusters ;
514 for(index = 0 ; index < numberofNotUnfolded ; index++){
516 AliEMCALRecPoint * RecPoint = dynamic_cast<AliEMCALRecPoint *>( fRecPoints->At(index) ) ;
520 RecPoint->GetGlobalPosition(gpos);
521 fGeom->GetAbsCellIdFromEtaPhi(gpos.Eta(),gpos.Phi(),absId);
522 if(absId > nModulesToUnfold)
525 Int_t nMultipl = RecPoint->GetMultiplicity() ;
526 AliEMCALDigit ** maxAt = new AliEMCALDigit*[nMultipl] ;
527 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
528 Int_t nMax = RecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fECALocMaxCut,fDigitsArr) ;
530 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
531 UnfoldCluster(RecPoint, nMax, maxAt, maxAtEnergy) ;
532 fRecPoints->Remove(RecPoint);
533 fRecPoints->Compress() ;
535 fNumberOfECAClusters-- ;
536 numberofNotUnfolded-- ;
539 RecPoint->SetNExMax(1) ; //Only one local maximum
543 delete[] maxAtEnergy ;
546 // End of Unfolding of clusters
549 //____________________________________________________________________________
550 Double_t AliEMCALClusterizerv1::ShowerShape(Double_t x, Double_t y)
552 // Shape of the shower
553 // If you change this function, change also the gradient evaluation in ChiSquare()
555 Double_t r = sqrt(x*x+y*y);
556 Double_t r133 = TMath::Power(r, 1.33) ;
557 Double_t r669 = TMath::Power(r, 6.69) ;
558 Double_t shape = TMath::Exp( -r133 * (1. / (1.57 + 0.0860 * r133) - 0.55 / (1 + 0.000563 * r669) ) ) ;
562 //____________________________________________________________________________
563 void AliEMCALClusterizerv1::UnfoldCluster(AliEMCALRecPoint * iniTower,
565 AliEMCALDigit ** maxAt,
566 Float_t * maxAtEnergy)
568 // Performs the unfolding of a cluster with nMax overlapping showers
569 Int_t nPar = 3 * nMax ;
570 Float_t * fitparameters = new Float_t[nPar] ;
573 AliFatal("Did not get geometry from EMCALLoader") ;
575 Bool_t rv = FindFit(iniTower, maxAt, maxAtEnergy, nPar, fitparameters) ;
577 // Fit failed, return and remove cluster
578 iniTower->SetNExMax(-1) ;
579 delete[] fitparameters ;
583 // create unfolded rec points and fill them with new energy lists
584 // First calculate energy deposited in each sell in accordance with
585 // fit (without fluctuations): efit[]
586 // and later correct this number in acordance with actual energy
589 Int_t nDigits = iniTower->GetMultiplicity() ;
590 Float_t * efit = new Float_t[nDigits] ;
591 Double_t xDigit=0.,yDigit=0.,zDigit=0. ;
592 Float_t xpar=0.,zpar=0.,epar=0. ;
594 AliEMCALDigit * digit = 0 ;
595 Int_t * Digits = iniTower->GetDigitsList() ;
599 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
600 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At(Digits[iDigit] ) ) ;
601 fGeom->RelPosCellInSModule(digit->GetId(), yDigit, xDigit, zDigit);
605 while(iparam < nPar ){
606 xpar = fitparameters[iparam] ;
607 zpar = fitparameters[iparam+1] ;
608 epar = fitparameters[iparam+2] ;
610 efit[iDigit] += epar * ShowerShape(xDigit - xpar,zDigit - zpar) ;
615 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
616 // so that energy deposited in each cell is distributed between new clusters proportionally
617 // to its contribution to efit
619 Float_t * Energies = iniTower->GetEnergiesList() ;
623 while(iparam < nPar ){
624 xpar = fitparameters[iparam] ;
625 zpar = fitparameters[iparam+1] ;
626 epar = fitparameters[iparam+2] ;
629 AliEMCALRecPoint * RecPoint = 0 ;
631 if(fNumberOfECAClusters >= fRecPoints->GetSize())
632 fRecPoints->Expand(2*fNumberOfECAClusters) ;
634 (*fRecPoints)[fNumberOfECAClusters] = new AliEMCALRecPoint("") ;
635 RecPoint = dynamic_cast<AliEMCALRecPoint *>( fRecPoints->At(fNumberOfECAClusters) ) ;
636 fNumberOfECAClusters++ ;
637 RecPoint->SetNExMax((Int_t)nPar/3) ;
640 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
641 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At( Digits[iDigit] ) ) ;
642 fGeom->RelPosCellInSModule(digit->GetId(), yDigit, xDigit, zDigit);
644 ratio = epar * ShowerShape(xDigit - xpar,zDigit - zpar) / efit[iDigit] ;
645 eDigit = Energies[iDigit] * ratio ;
646 RecPoint->AddDigit( *digit, eDigit ) ;
650 delete[] fitparameters ;
655 //_____________________________________________________________________________
656 void AliEMCALClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad,
658 Double_t * x, Int_t iflag)
660 // Calculates the Chi square for the cluster unfolding minimization
661 // Number of parameters, Gradient, Chi squared, parameters, what to do
663 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
665 AliEMCALRecPoint * RecPoint = dynamic_cast<AliEMCALRecPoint*>( toMinuit->At(0) ) ;
666 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
667 // A bit buggy way to get an access to the geometry
669 AliEMCALGeometry *geom = dynamic_cast<AliEMCALGeometry *>(toMinuit->At(2));
671 Int_t * Digits = RecPoint->GetDigitsList() ;
673 Int_t nOdigits = RecPoint->GetDigitsMultiplicity() ;
675 Float_t * Energies = RecPoint->GetEnergiesList() ;
681 for(iparam = 0 ; iparam < nPar ; iparam++)
682 Grad[iparam] = 0 ; // Will evaluate gradient
686 AliEMCALDigit * digit ;
689 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
691 digit = dynamic_cast<AliEMCALDigit*>( digits->At( Digits[iDigit] ) );
695 Double_t yDigit=0 ;//not used yet, assumed to be 0
697 geom->RelPosCellInSModule(digit->GetId(), yDigit, xDigit, zDigit);
699 if(iflag == 2){ // calculate gradient
702 while(iParam < nPar ){
703 Double_t dx = (xDigit - x[iParam]) ;
705 Double_t dz = (zDigit - x[iParam]) ;
707 efit += x[iParam] * ShowerShape(dx,dz) ;
710 Double_t sum = 2. * (efit - Energies[iDigit]) / Energies[iDigit] ; // Here we assume, that sigma = sqrt(E)
712 while(iParam < nPar ){
713 Double_t xpar = x[iParam] ;
714 Double_t zpar = x[iParam+1] ;
715 Double_t epar = x[iParam+2] ;
716 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
717 Double_t shape = sum * ShowerShape(xDigit - xpar,zDigit - zpar) ;
718 Double_t r133 = TMath::Power(dr, 1.33);
719 Double_t r669 = TMath::Power(dr,6.69);
720 Double_t deriv =-1.33 * TMath::Power(dr,0.33)*dr * ( 1.57 / ( (1.57 + 0.0860 * r133) * (1.57 + 0.0860 * r133) )
721 - 0.55 / (1 + 0.000563 * r669) / ( (1 + 0.000563 * r669) * (1 + 0.000563 * r669) ) ) ;
723 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
725 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
727 Grad[iParam] += shape ; // Derivative over energy
735 while(iparam < nPar ){
736 Double_t xpar = x[iparam] ;
737 Double_t zpar = x[iparam+1] ;
738 Double_t epar = x[iparam+2] ;
740 efit += epar * ShowerShape(xDigit - xpar,zDigit - zpar) ;
743 fret += (efit-Energies[iDigit])*(efit-Energies[iDigit])/Energies[iDigit] ;
744 // Here we assume, that sigma = sqrt(E)
747 //____________________________________________________________________________
748 void AliEMCALClusterizerv1::Print(Option_t * /*option*/)const
750 // Print clusterizer parameters
752 TString message("\n") ;
754 if( strcmp(GetName(), "") !=0 ){
758 TString taskName(Version()) ;
760 printf("--------------- ");
761 printf(taskName.Data()) ;
763 printf("Clusterizing digits: ");
764 printf("\n ECA Local Maximum cut = %f", fECALocMaxCut);
765 printf("\n ECA Logarithmic weight = %f", fECAW0);
767 printf("\nUnfolding on\n");
769 printf("\nUnfolding off\n");
771 printf("------------------------------------------------------------------");
774 printf("AliEMCALClusterizerv1 not initialized ") ;
777 //____________________________________________________________________________
778 void AliEMCALClusterizerv1::PrintRecPoints(Option_t * option)
780 // Prints list of RecPoints produced at the current pass of AliEMCALClusterizer
781 if(strstr(option,"deb")) {
782 printf("PrintRecPoints: Clusterization result:") ;
784 printf(" Found %d ECA Rec Points\n ",
785 fRecPoints->GetEntriesFast()) ;
788 if(strstr(option,"all")) {
789 if(strstr(option,"deb")) {
790 printf("\n-----------------------------------------------------------------------\n") ;
791 printf("Clusters in ECAL section\n") ;
792 printf("Index Ene(GeV) Multi Module GX GY GZ lX lY lZ Dispersion Lambda 1 Lambda 2 # of prim Primaries list\n") ;
796 for (index = 0 ; index < fRecPoints->GetEntries() ; index++) {
797 AliEMCALRecPoint * rp = dynamic_cast<AliEMCALRecPoint * >(fRecPoints->At(index)) ;
799 //rp->GetGlobalPosition(globalpos);
801 rp->GetLocalPosition(localpos);
803 rp->GetElipsAxis(lambda);
806 primaries = rp->GetPrimaries(nprimaries);
807 if(strstr(option,"deb"))
808 printf("\n%6d %8.4f %3d %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4f %4f %2d : ",
809 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(),
810 globalpos.X(), globalpos.Y(), globalpos.Z(), localpos.X(), localpos.Y(), localpos.Z(),
811 rp->GetDispersion(), lambda[0], lambda[1], nprimaries) ;
812 if(strstr(option,"deb")){
813 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
814 printf("%d ", primaries[iprimary] ) ;
819 if(strstr(option,"deb"))
820 printf("\n-----------------------------------------------------------------------\n");
824 //___________________________________________________________________
825 void AliEMCALClusterizerv1::PrintRecoInfo()
827 printf(" AliEMCALClusterizerv1::PrintRecoInfo() : version %s \n", Version() );