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"
79 #include "AliCaloCalibPedestal.h"
80 #include "AliEMCALCalibData.h"
82 #include "AliCDBEntry.h"
84 ClassImp(AliEMCALClusterizerv1)
86 //____________________________________________________________________________
87 AliEMCALClusterizerv1::AliEMCALClusterizerv1()
88 : AliEMCALClusterizer(),
92 fNumberOfECAClusters(0),fCalibData(0),fCaloPed(0),
93 fADCchannelECA(0.),fADCpedestalECA(0.),fECAClusteringThreshold(0.),fECALocMaxCut(0.),
94 fECAW0(0.),fTimeCut(1.),fMinECut(0.)
96 // ctor with the indication of the file where header Tree and digits Tree are stored
101 //____________________________________________________________________________
102 AliEMCALClusterizerv1::AliEMCALClusterizerv1(AliEMCALGeometry* geometry)
103 : AliEMCALClusterizer(),
105 fDefaultInit(kFALSE),
107 fNumberOfECAClusters(0),fCalibData(0), fCaloPed(0),
108 fADCchannelECA(0.),fADCpedestalECA(0.),fECAClusteringThreshold(0.),fECALocMaxCut(0.),
109 fECAW0(0.),fTimeCut(1.),fMinECut(0.)
111 // ctor with the indication of the file where header Tree and digits Tree are stored
112 // use this contructor to avoid usage of Init() which uses runloader
113 // change needed by HLT - MP
115 // Note for the future: the use on runloader should be avoided or optional at least
116 // another way is to make Init virtual and protected at least such that the deriving classes can overload
122 AliFatal("Geometry not initialized.");
126 gMinuit = new TMinuit(100) ;
130 //____________________________________________________________________________
131 AliEMCALClusterizerv1::AliEMCALClusterizerv1(AliEMCALGeometry* geometry, AliEMCALCalibData * calib, AliCaloCalibPedestal * caloped)
132 : AliEMCALClusterizer(),
134 fDefaultInit(kFALSE),
136 fNumberOfECAClusters(0),fCalibData(calib), fCaloPed(caloped),
137 fADCchannelECA(0.),fADCpedestalECA(0.),fECAClusteringThreshold(0.),fECALocMaxCut(0.),
138 fECAW0(0.),fTimeCut(1.),fMinECut(0.)
140 // ctor, geometry and calibration are initialized elsewhere.
143 AliFatal("Geometry not initialized.");
146 gMinuit = new TMinuit(100) ;
151 //____________________________________________________________________________
152 AliEMCALClusterizerv1::~AliEMCALClusterizerv1()
157 //____________________________________________________________________________
158 Float_t AliEMCALClusterizerv1::Calibrate(Int_t amp, Int_t absId)
161 // Convert digitized amplitude into energy.
162 // Calibration parameters are taken from calibration data base for raw data,
163 // or from digitizer parameters for simulated data.
168 AliFatal("Did not get geometry from EMCALLoader") ;
177 Bool_t bCell = fGeom->GetCellIndex(absId, iSupMod, nModule, nIphi, nIeta) ;
179 fGeom->PrintGeometry();
180 Error("Calibrate()"," Wrong cell id number : %i", absId);
184 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,nModule,nIphi, nIeta,iphi,ieta);
186 // Check if channel is bad (dead or hot), in this case return 0.
187 // Gustavo: 15-12-09 In case of RAW data this selection is already done, but not in simulation.
188 // for the moment keep it here but remember to do the selection at the sdigitizer level
189 // and remove it from here
190 Int_t channelStatus = (Int_t)(fCaloPed->GetDeadMap(iSupMod))->GetBinContent(ieta,iphi);
191 if(channelStatus == AliCaloCalibPedestal::kHot || channelStatus == AliCaloCalibPedestal::kDead) {
192 AliDebug(2,Form("Tower from SM %d, ieta %d, iphi %d is BAD : status %d !!!",iSupMod,ieta,iphi, channelStatus));
196 fADCchannelECA = fCalibData->GetADCchannel (iSupMod,ieta,iphi);
197 fADCpedestalECA = fCalibData->GetADCpedestal(iSupMod,ieta,iphi);
199 return -fADCpedestalECA + amp * fADCchannelECA ;
202 else //Return energy with default parameters if calibration is not available
203 return -fADCpedestalECA + amp * fADCchannelECA ;
207 //____________________________________________________________________________
208 void AliEMCALClusterizerv1::Digits2Clusters(Option_t * option)
210 // Steering method to perform clusterization for the current event
213 if(strstr(option,"tim"))
214 gBenchmark->Start("EMCALClusterizer");
216 if(strstr(option,"print"))
219 //Get calibration parameters from file or digitizer default values.
220 GetCalibrationParameters() ;
222 //Get dead channel map from file or digitizer default values.
223 GetCaloCalibPedestal() ;
225 fNumberOfECAClusters = 0;
227 MakeClusters() ; //only the real clusters
234 //Evaluate position, dispersion and other RecPoint properties for EC section
235 for(index = 0; index < fRecPoints->GetEntries(); index++) {
236 dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index))->EvalAll(fECAW0,fDigitsArr) ;
237 //For each rec.point set the distance to the nearest bad crystal
238 dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index))->EvalDistanceToBadChannels(fCaloPed);
243 for(index = 0; index < fRecPoints->GetEntries(); index++) {
244 (dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index)))->SetIndexInList(index) ;
245 (dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index)))->Print();
250 if(strstr(option,"deb") || strstr(option,"all"))
251 PrintRecPoints(option) ;
253 AliDebug(1,Form("EMCAL Clusterizer found %d Rec Points",fRecPoints->GetEntriesFast()));
255 fRecPoints->Delete();
257 if(strstr(option,"tim")){
258 gBenchmark->Stop("EMCALClusterizer");
259 printf("Exec took %f seconds for Clusterizing",
260 gBenchmark->GetCpuTime("EMCALClusterizer"));
264 //____________________________________________________________________________
265 Bool_t AliEMCALClusterizerv1::FindFit(AliEMCALRecPoint * recPoint, AliEMCALDigit ** maxAt,
266 const Float_t* maxAtEnergy,
267 Int_t nPar, Float_t * fitparameters) const
269 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
270 // The initial values for fitting procedure are set equal to the
271 // positions of local maxima.
272 // Cluster will be fitted as a superposition of nPar/3
273 // electromagnetic showers
275 if (fGeom==0) AliFatal("Did not get geometry from EMCALLoader");
277 gMinuit->mncler(); // Reset Minuit's list of paramters
278 gMinuit->SetPrintLevel(-1) ; // No Printout
279 gMinuit->SetFCN(AliEMCALClusterizerv1::UnfoldingChiSquare) ;
280 // To set the address of the minimization function
281 TList * toMinuit = new TList();
282 toMinuit->AddAt(recPoint,0) ;
283 toMinuit->AddAt(fDigitsArr,1) ;
284 toMinuit->AddAt(fGeom,2) ;
286 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
288 // filling initial values for fit parameters
289 AliEMCALDigit * digit ;
293 Int_t nDigits = (Int_t) nPar / 3 ;
297 for(iDigit = 0; iDigit < nDigits; iDigit++){
298 digit = maxAt[iDigit];
303 fGeom->RelPosCellInSModule(digit->GetId(), y, x, z);
305 Float_t energy = maxAtEnergy[iDigit] ;
307 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
310 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : x = %f", x ) ;
313 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
316 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : z = %f", z) ;
319 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
322 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : energy = %f", energy) ;
327 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ;
328 // The number of function call slightly depends on it.
329 //Double_t p1 = 1.0 ;
332 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
333 // gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
334 gMinuit->SetMaxIterations(5);
335 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
336 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
338 if(ierflg == 4){ // Minimum not found
339 Error("FindFit", "EMCAL Unfolding Fit not converged, cluster abandoned " ) ;
342 for(index = 0; index < nPar; index++){
345 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
346 fitparameters[index] = val ;
354 //____________________________________________________________________________
355 void AliEMCALClusterizerv1::GetCalibrationParameters()
357 // Set calibration parameters:
358 // if calibration database exists, they are read from database,
359 // otherwise, they are taken from digitizer.
361 // It is a user responsilibity to open CDB before reconstruction,
363 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
365 //Check if calibration is stored in data base
369 AliCDBEntry *entry = (AliCDBEntry*)
370 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
371 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
375 AliFatal("Calibration parameters not found in CDB!");
379 //____________________________________________________________________________
380 void AliEMCALClusterizerv1::GetCaloCalibPedestal()
382 // Set calibration parameters:
383 // if calibration database exists, they are read from database,
384 // otherwise, they are taken from digitizer.
386 // It is a user responsilibity to open CDB before reconstruction,
388 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
390 //Check if calibration is stored in data base
394 AliCDBEntry *entry = (AliCDBEntry*)
395 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
396 if (entry) fCaloPed = (AliCaloCalibPedestal*) entry->GetObject();
400 AliFatal("Pedestal info not found in CDB!");
405 //____________________________________________________________________________
406 void AliEMCALClusterizerv1::Init()
408 // Make all memory allocations which can not be done in default constructor.
409 // Attach the Clusterizer task to the list of EMCAL tasks
411 AliRunLoader *rl = AliRunLoader::Instance();
412 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL"))
413 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
415 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
417 AliDebug(1,Form("geom 0x%x",fGeom));
420 gMinuit = new TMinuit(100) ;
424 //____________________________________________________________________________
425 void AliEMCALClusterizerv1::InitParameters()
427 // Initializes the parameters for the Clusterizer
428 fNumberOfECAClusters = 0;
433 const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
435 AliFatal("Reconstruction parameters for EMCAL not set!");
437 fECAClusteringThreshold = recParam->GetClusteringThreshold();
438 fECAW0 = recParam->GetW0();
439 fMinECut = recParam->GetMinECut();
440 fToUnfold = recParam->GetUnfold();
441 if(fToUnfold) AliWarning("Cluster Unfolding ON. Implementing only for eta=0 case!!!");
442 fECALocMaxCut = recParam->GetLocMaxCut();
443 fTimeCut = recParam->GetTimeCut();// Originally 300 ns time cut, in data time found to be between 350 ns and 1500 ns, relax the cut for the moment, 1s.
445 AliDebug(1,Form("Reconstruction parameters: fECAClusteringThreshold=%.3f, fECAW=%.3f, fMinECut=%.3f, fToUnfold=%d, fECALocMaxCut=%.3f, fTimeCut=%f",
446 fECAClusteringThreshold,fECAW0,fMinECut,fToUnfold,fECALocMaxCut,fTimeCut));
451 //____________________________________________________________________________
452 Int_t AliEMCALClusterizerv1::AreNeighbours(AliEMCALDigit * d1, AliEMCALDigit * d2) const
454 // Gives the neighbourness of two digits = 0 are not neighbour ; continue searching
456 // = 2 is in different SM; continue searching
457 // neighbours are defined as digits having at least a common vertex
458 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
459 // which is compared to a digit (d2) not yet in a cluster
462 static Int_t nSupMod1=0, nModule1=0, nIphi1=0, nIeta1=0, iphi1=0, ieta1=0;
463 static Int_t nSupMod2=0, nModule2=0, nIphi2=0, nIeta2=0, iphi2=0, ieta2=0;
464 static Int_t rowdiff, coldiff;
467 fGeom->GetCellIndex(d1->GetId(), nSupMod1,nModule1,nIphi1,nIeta1);
468 fGeom->GetCellIndex(d2->GetId(), nSupMod2,nModule2,nIphi2,nIeta2);
469 if(nSupMod1 != nSupMod2) return 2; // different SM
471 fGeom->GetCellPhiEtaIndexInSModule(nSupMod1,nModule1,nIphi1,nIeta1, iphi1,ieta1);
472 fGeom->GetCellPhiEtaIndexInSModule(nSupMod2,nModule2,nIphi2,nIeta2, iphi2,ieta2);
474 rowdiff = TMath::Abs(iphi1 - iphi2);
475 coldiff = TMath::Abs(ieta1 - ieta2) ;
477 // neighbours with at least commom side; May 11, 2007
478 if ((coldiff==0 && abs(rowdiff)==1) || (rowdiff==0 && abs(coldiff)==1)) rv = 1;
480 if (gDebug == 2 && rv==1)
481 printf("AreNeighbours: neighbours=%d, id1=%d, relid1=%d,%d \n id2=%d, relid2=%d,%d \n",
482 rv, d1->GetId(), iphi1,ieta1, d2->GetId(), iphi2,ieta2);
487 //____________________________________________________________________________
488 void AliEMCALClusterizerv1::MakeClusters()
490 // Steering method to construct the clusters stored in a list of Reconstructed Points
491 // A cluster is defined as a list of neighbour digits
492 // Mar 03, 2007 by PAI
494 if (fGeom==0) AliFatal("Did not get geometry from EMCALLoader");
498 // Set up TObjArray with pointers to digits to work on
499 TObjArray *digitsC = new TObjArray();
500 TIter nextdigit(fDigitsArr);
501 AliEMCALDigit *digit;
502 while ( (digit = dynamic_cast<AliEMCALDigit*>(nextdigit())) ) {
503 digitsC->AddLast(digit);
506 double e = 0.0, ehs = 0.0;
507 TIter nextdigitC(digitsC);
508 while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigitC())) ) { // clean up digits
509 e = Calibrate(digit->GetAmp(), digit->GetId());
510 if ( e < fMinECut || digit->GetTimeR() > fTimeCut )
511 digitsC->Remove(digit);
515 AliDebug(1,Form("MakeClusters: Number of digits %d -> (e %f), ehs %d\n",
516 fDigitsArr->GetEntries(),fMinECut,ehs));
520 while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigitC())) ) { // scan over the list of digitsC
521 TArrayI clusterECAdigitslist(fDigitsArr->GetEntries());
523 if(fGeom->CheckAbsCellId(digit->GetId()) && (Calibrate(digit->GetAmp(), digit->GetId()) > fECAClusteringThreshold ) ){
524 // start a new Tower RecPoint
525 if(fNumberOfECAClusters >= fRecPoints->GetSize()) fRecPoints->Expand(2*fNumberOfECAClusters+1) ;
527 AliEMCALRecPoint *recPoint = new AliEMCALRecPoint("") ;
528 fRecPoints->AddAt(recPoint, fNumberOfECAClusters) ;
529 recPoint = dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(fNumberOfECAClusters)) ;
530 fNumberOfECAClusters++ ;
532 recPoint->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
534 recPoint->AddDigit(*digit, Calibrate(digit->GetAmp(), digit->GetId())) ;
535 TObjArray clusterDigits;
536 clusterDigits.AddLast(digit);
537 digitsC->Remove(digit) ;
539 AliDebug(1,Form("MakeClusters: OK id = %d, ene = %f , cell.th. = %f \n", digit->GetId(),
540 Calibrate(digit->GetAmp(),digit->GetId()), fECAClusteringThreshold));
542 // Grow cluster by finding neighbours
543 TIter nextClusterDigit(&clusterDigits);
544 while ( (digit = dynamic_cast<AliEMCALDigit*>(nextClusterDigit())) ) { // scan over digits in cluster
545 TIter nextdigitN(digitsC);
546 AliEMCALDigit *digitN = 0; // digi neighbor
547 while ( (digitN = (AliEMCALDigit *)nextdigitN()) ) { // scan over all digits to look for neighbours
548 if (AreNeighbours(digit, digitN)==1) { // call (digit,digitN) in THAT oder !!!!!
549 recPoint->AddDigit(*digitN, Calibrate(digitN->GetAmp(),digitN->GetId()) ) ;
550 clusterDigits.AddLast(digitN) ;
551 digitsC->Remove(digitN) ;
553 } // scan over digits
554 } // scan over digits already in cluster
556 AliDebug(2,Form("MakeClusters: %d digitd, energy %f \n", clusterDigits.GetEntries(), recPoint->GetEnergy()));
562 AliDebug(1,Form("total no of clusters %d from %d digits",fNumberOfECAClusters,fDigitsArr->GetEntriesFast()));
565 //____________________________________________________________________________
566 void AliEMCALClusterizerv1::MakeUnfolding()
568 // Unfolds clusters using the shape of an ElectroMagnetic shower
569 // Performs unfolding of all clusters
571 if(fNumberOfECAClusters > 0){
573 AliFatal("Did not get geometry from EMCALLoader") ;
574 Int_t nModulesToUnfold = fGeom->GetNCells();
576 Int_t numberofNotUnfolded = fNumberOfECAClusters ;
578 for(index = 0 ; index < numberofNotUnfolded ; index++){
580 AliEMCALRecPoint * recPoint = dynamic_cast<AliEMCALRecPoint *>( fRecPoints->At(index) ) ;
584 recPoint->GetGlobalPosition(gpos);
585 fGeom->GetAbsCellIdFromEtaPhi(gpos.Eta(),gpos.Phi(),absId);
586 if(absId > nModulesToUnfold)
589 Int_t nMultipl = recPoint->GetMultiplicity() ;
590 AliEMCALDigit ** maxAt = new AliEMCALDigit*[nMultipl] ;
591 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
592 Int_t nMax = recPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fECALocMaxCut,fDigitsArr) ;
594 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
595 UnfoldCluster(recPoint, nMax, maxAt, maxAtEnergy) ;
596 fRecPoints->Remove(recPoint);
597 fRecPoints->Compress() ;
599 fNumberOfECAClusters-- ;
600 numberofNotUnfolded-- ;
603 recPoint->SetNExMax(1) ; //Only one local maximum
607 delete[] maxAtEnergy ;
610 // End of Unfolding of clusters
613 //____________________________________________________________________________
614 Double_t AliEMCALClusterizerv1::ShowerShape(Double_t x, Double_t y)
616 // Shape of the shower
617 // If you change this function, change also the gradient evaluation in ChiSquare()
619 Double_t r = sqrt(x*x+y*y);
620 Double_t r133 = TMath::Power(r, 1.33) ;
621 Double_t r669 = TMath::Power(r, 6.69) ;
622 Double_t shape = TMath::Exp( -r133 * (1. / (1.57 + 0.0860 * r133) - 0.55 / (1 + 0.000563 * r669) ) ) ;
626 //____________________________________________________________________________
627 void AliEMCALClusterizerv1::UnfoldCluster(AliEMCALRecPoint * iniTower,
629 AliEMCALDigit ** maxAt,
630 Float_t * maxAtEnergy)
632 // Performs the unfolding of a cluster with nMax overlapping showers
633 Int_t nPar = 3 * nMax ;
634 Float_t * fitparameters = new Float_t[nPar] ;
637 AliFatal("Did not get geometry from EMCALLoader") ;
639 Bool_t rv = FindFit(iniTower, maxAt, maxAtEnergy, nPar, fitparameters) ;
641 // Fit failed, return and remove cluster
642 iniTower->SetNExMax(-1) ;
643 delete[] fitparameters ;
647 // create unfolded rec points and fill them with new energy lists
648 // First calculate energy deposited in each sell in accordance with
649 // fit (without fluctuations): efit[]
650 // and later correct this number in acordance with actual energy
653 Int_t nDigits = iniTower->GetMultiplicity() ;
654 Float_t * efit = new Float_t[nDigits] ;
655 Double_t xDigit=0.,yDigit=0.,zDigit=0. ;
656 Float_t xpar=0.,zpar=0.,epar=0. ;
658 AliEMCALDigit * digit = 0 ;
659 Int_t * digitsList = iniTower->GetDigitsList() ;
663 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
664 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At(digitsList[iDigit] ) ) ;
665 fGeom->RelPosCellInSModule(digit->GetId(), yDigit, xDigit, zDigit);
669 while(iparam < nPar ){
670 xpar = fitparameters[iparam] ;
671 zpar = fitparameters[iparam+1] ;
672 epar = fitparameters[iparam+2] ;
674 efit[iDigit] += epar * ShowerShape(xDigit - xpar,zDigit - zpar) ;
679 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
680 // so that energy deposited in each cell is distributed between new clusters proportionally
681 // to its contribution to efit
683 Float_t * energiesList = iniTower->GetEnergiesList() ;
687 while(iparam < nPar ){
688 xpar = fitparameters[iparam] ;
689 zpar = fitparameters[iparam+1] ;
690 epar = fitparameters[iparam+2] ;
693 AliEMCALRecPoint * recPoint = 0 ;
695 if(fNumberOfECAClusters >= fRecPoints->GetSize())
696 fRecPoints->Expand(2*fNumberOfECAClusters) ;
698 (*fRecPoints)[fNumberOfECAClusters] = new AliEMCALRecPoint("") ;
699 recPoint = dynamic_cast<AliEMCALRecPoint *>( fRecPoints->At(fNumberOfECAClusters) ) ;
700 fNumberOfECAClusters++ ;
701 recPoint->SetNExMax((Int_t)nPar/3) ;
704 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
705 digit = dynamic_cast<AliEMCALDigit*>( fDigitsArr->At( digitsList[iDigit] ) ) ;
706 fGeom->RelPosCellInSModule(digit->GetId(), yDigit, xDigit, zDigit);
708 ratio = epar * ShowerShape(xDigit - xpar,zDigit - zpar) / efit[iDigit] ;
709 eDigit = energiesList[iDigit] * ratio ;
710 recPoint->AddDigit( *digit, eDigit ) ;
714 delete[] fitparameters ;
719 //_____________________________________________________________________________
720 void AliEMCALClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad,
722 Double_t * x, Int_t iflag)
724 // Calculates the Chi square for the cluster unfolding minimization
725 // Number of parameters, Gradient, Chi squared, parameters, what to do
727 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
729 AliEMCALRecPoint * recPoint = dynamic_cast<AliEMCALRecPoint*>( toMinuit->At(0) ) ;
730 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
731 // A bit buggy way to get an access to the geometry
733 AliEMCALGeometry *geom = dynamic_cast<AliEMCALGeometry *>(toMinuit->At(2));
735 Int_t * digitsList = recPoint->GetDigitsList() ;
737 Int_t nOdigits = recPoint->GetDigitsMultiplicity() ;
739 Float_t * energiesList = recPoint->GetEnergiesList() ;
745 for(iparam = 0 ; iparam < nPar ; iparam++)
746 Grad[iparam] = 0 ; // Will evaluate gradient
750 AliEMCALDigit * digit ;
753 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
755 digit = dynamic_cast<AliEMCALDigit*>( digits->At( digitsList[iDigit] ) );
759 Double_t yDigit=0 ;//not used yet, assumed to be 0
761 geom->RelPosCellInSModule(digit->GetId(), yDigit, xDigit, zDigit);
763 if(iflag == 2){ // calculate gradient
766 while(iParam < nPar ){
767 Double_t dx = (xDigit - x[iParam]) ;
769 Double_t dz = (zDigit - x[iParam]) ;
771 efit += x[iParam] * ShowerShape(dx,dz) ;
774 Double_t sum = 2. * (efit - energiesList[iDigit]) / energiesList[iDigit] ; // Here we assume, that sigma = sqrt(E)
776 while(iParam < nPar ){
777 Double_t xpar = x[iParam] ;
778 Double_t zpar = x[iParam+1] ;
779 Double_t epar = x[iParam+2] ;
780 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
781 Double_t shape = sum * ShowerShape(xDigit - xpar,zDigit - zpar) ;
782 Double_t r133 = TMath::Power(dr, 1.33);
783 Double_t r669 = TMath::Power(dr,6.69);
784 Double_t deriv =-1.33 * TMath::Power(dr,0.33)*dr * ( 1.57 / ( (1.57 + 0.0860 * r133) * (1.57 + 0.0860 * r133) )
785 - 0.55 / (1 + 0.000563 * r669) / ( (1 + 0.000563 * r669) * (1 + 0.000563 * r669) ) ) ;
787 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
789 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
791 Grad[iParam] += shape ; // Derivative over energy
799 while(iparam < nPar ){
800 Double_t xpar = x[iparam] ;
801 Double_t zpar = x[iparam+1] ;
802 Double_t epar = x[iparam+2] ;
804 efit += epar * ShowerShape(xDigit - xpar,zDigit - zpar) ;
807 fret += (efit-energiesList[iDigit])*(efit-energiesList[iDigit])/energiesList[iDigit] ;
808 // Here we assume, that sigma = sqrt(E)
811 //____________________________________________________________________________
812 void AliEMCALClusterizerv1::Print(Option_t * /*option*/)const
814 // Print clusterizer parameters
816 TString message("\n") ;
818 if( strcmp(GetName(), "") !=0 ){
822 TString taskName(Version()) ;
824 printf("--------------- ");
825 printf("%s",taskName.Data()) ;
827 printf("Clusterizing digits: ");
828 printf("\n ECA Local Maximum cut = %f", fECALocMaxCut);
829 printf("\n ECA Logarithmic weight = %f", fECAW0);
831 printf("\nUnfolding on\n");
833 printf("\nUnfolding off\n");
835 printf("------------------------------------------------------------------");
838 printf("AliEMCALClusterizerv1 not initialized ") ;
841 //____________________________________________________________________________
842 void AliEMCALClusterizerv1::PrintRecPoints(Option_t * option)
844 // Prints list of RecPoints produced at the current pass of AliEMCALClusterizer
845 if(strstr(option,"deb")) {
846 printf("PrintRecPoints: Clusterization result:") ;
848 printf(" Found %d ECA Rec Points\n ",
849 fRecPoints->GetEntriesFast()) ;
852 if(strstr(option,"all")) {
853 if(strstr(option,"deb")) {
854 printf("\n-----------------------------------------------------------------------\n") ;
855 printf("Clusters in ECAL section\n") ;
856 printf("Index Ene(GeV) Multi Module GX GY GZ lX lY lZ Dispersion Lambda 1 Lambda 2 # of prim Primaries list\n") ;
860 for (index = 0 ; index < fRecPoints->GetEntries() ; index++) {
861 AliEMCALRecPoint * rp = dynamic_cast<AliEMCALRecPoint * >(fRecPoints->At(index)) ;
863 //rp->GetGlobalPosition(globalpos);
865 rp->GetLocalPosition(localpos);
867 rp->GetElipsAxis(lambda);
870 primaries = rp->GetPrimaries(nprimaries);
871 if(strstr(option,"deb"))
872 printf("\n%6d %8.4f %3d %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4f %4f %2d : ",
873 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(),
874 globalpos.X(), globalpos.Y(), globalpos.Z(), localpos.X(), localpos.Y(), localpos.Z(),
875 rp->GetDispersion(), lambda[0], lambda[1], nprimaries) ;
876 if(strstr(option,"deb")){
877 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
878 printf("%d ", primaries[iprimary] ) ;
883 if(strstr(option,"deb"))
884 printf("\n-----------------------------------------------------------------------\n");
888 //___________________________________________________________________
889 void AliEMCALClusterizerv1::PrintRecoInfo()
891 printf(" AliEMCALClusterizerv1::PrintRecoInfo() : version %s \n", Version() );