Removing unused class AliMUONPixel
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALClusterizerv1.cxx
... / ...
CommitLineData
1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
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
29// standalone mode.
30// Use Case:
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
47
48// --- ROOT system ---
49#include <cassert>
50
51class TROOT;
52#include <TH1.h>
53#include <TFile.h>
54class TFolder;
55#include <TMath.h>
56#include <TMinuit.h>
57#include <TTree.h>
58class TSystem;
59#include <TBenchmark.h>
60#include <TBrowser.h>
61#include <TROOT.h>
62
63// --- Standard library ---
64
65
66// --- AliRoot header files ---
67#include "AliRunLoader.h"
68#include "AliRun.h"
69#include "AliESD.h"
70#include "AliEMCALClusterizerv1.h"
71#include "AliEMCALRecPoint.h"
72#include "AliEMCALDigit.h"
73#include "AliEMCALDigitizer.h"
74#include "AliEMCAL.h"
75#include "AliEMCALGeometry.h"
76#include "AliEMCALHistoUtilities.h"
77#include "AliEMCALRecParam.h"
78#include "AliEMCALReconstructor.h"
79#include "AliCDBManager.h"
80
81class AliCDBStorage;
82#include "AliCDBEntry.h"
83
84ClassImp(AliEMCALClusterizerv1)
85
86//____________________________________________________________________________
87AliEMCALClusterizerv1::AliEMCALClusterizerv1()
88 : AliEMCALClusterizer(),
89 fHists(0),fPointE(0),fPointL1(0),fPointL2(0),
90 fPointDis(0),fPointMult(0),fDigitAmp(0),fMaxE(0),
91 fMaxL1(0),fMaxL2(0),fMaxDis(0),fGeom(0),
92 fDefaultInit(kFALSE),
93 fToUnfold(kFALSE),
94 fNumberOfECAClusters(0),fNTowerInGroup(0),fCalibData(0),
95 fADCchannelECA(0.),fADCpedestalECA(0.),fECAClusteringThreshold(0.),fECALocMaxCut(0.),
96 fECAW0(0.),fTimeCut(0.),fMinECut(0.)
97{
98 // ctor with the indication of the file where header Tree and digits Tree are stored
99
100 InitParameters() ;
101 Init() ;
102}
103
104//____________________________________________________________________________
105 AliEMCALClusterizerv1::~AliEMCALClusterizerv1()
106{
107 // dtor
108}
109
110//____________________________________________________________________________
111Float_t AliEMCALClusterizerv1::Calibrate(Int_t amp, Int_t AbsId)
112{
113
114 // Convert digitized amplitude into energy.
115 // Calibration parameters are taken from calibration data base for raw data,
116 // or from digitizer parameters for simulated data.
117
118 if(fCalibData){
119
120 if (fGeom==0)
121 AliFatal("Did not get geometry from EMCALLoader") ;
122
123 Int_t iSupMod = -1;
124 Int_t nModule = -1;
125 Int_t nIphi = -1;
126 Int_t nIeta = -1;
127 Int_t iphi = -1;
128 Int_t ieta = -1;
129
130 Bool_t bCell = fGeom->GetCellIndex(AbsId, iSupMod, nModule, nIphi, nIeta) ;
131 if(!bCell) {
132 fGeom->PrintGeometry();
133 Error("Calibrate()"," Wrong cell id number : %i", AbsId);
134 assert(0);
135 }
136
137 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,nModule,nIphi, nIeta,iphi,ieta);
138
139 fADCchannelECA = fCalibData->GetADCchannel (iSupMod,ieta,iphi);
140 fADCpedestalECA = fCalibData->GetADCpedestal(iSupMod,ieta,iphi);
141
142 return -fADCpedestalECA + amp * fADCchannelECA ;
143
144 }
145 else //Return energy with default parameters if calibration is not available
146 return -fADCpedestalECA + amp * fADCchannelECA ;
147
148}
149
150//____________________________________________________________________________
151void AliEMCALClusterizerv1::Digits2Clusters(Option_t * option)
152{
153 // Steering method to perform clusterization for the current event
154 // in AliEMCALLoader
155
156 if(strstr(option,"tim"))
157 gBenchmark->Start("EMCALClusterizer");
158
159 if(strstr(option,"print"))
160 Print("") ;
161
162 //Get calibration parameters from file or digitizer default values.
163 GetCalibrationParameters() ;
164
165
166 fNumberOfECAClusters = 0;
167
168 if(strstr(option,"pseudo"))
169 MakeClusters("pseudo") ; //both types
170 else
171 MakeClusters("") ; //only the real clusters
172
173 if(fToUnfold)
174 MakeUnfolding() ;
175
176 Int_t index ;
177
178 //Evaluate position, dispersion and other RecPoint properties for EC section
179 for(index = 0; index < fRecPoints->GetEntries(); index++) {
180 if (dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index))->GetClusterType() != AliESDCaloCluster::kEMCALPseudoCluster)
181 dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index))->EvalAll(fECAW0,fDigitsArr) ;
182 }
183
184 fRecPoints->Sort() ;
185
186 for(index = 0; index < fRecPoints->GetEntries(); index++) {
187 (dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index)))->SetIndexInList(index) ;
188 (dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index)))->Print();
189 }
190
191 fTreeR->Fill();
192
193 if(strstr(option,"deb") || strstr(option,"all"))
194 PrintRecPoints(option) ;
195
196 AliDebug(1,Form("EMCAL Clusterizer found %d Rec Points",fRecPoints->GetEntriesFast()));
197
198 if(strstr(option,"tim")){
199 gBenchmark->Stop("EMCALClusterizer");
200 printf("Exec took %f seconds for Clusterizing",
201 gBenchmark->GetCpuTime("EMCALClusterizer"));
202 }
203}
204
205//____________________________________________________________________________
206Bool_t AliEMCALClusterizerv1::FindFit(AliEMCALRecPoint * emcRP, AliEMCALDigit ** maxAt, Float_t * maxAtEnergy,
207 Int_t nPar, Float_t * fitparameters) const
208{
209 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
210 // The initial values for fitting procedure are set equal to the positions of local maxima.
211 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
212
213 gMinuit->mncler(); // Reset Minuit's list of paramters
214 gMinuit->SetPrintLevel(-1) ; // No Printout
215 gMinuit->SetFCN(AliEMCALClusterizerv1::UnfoldingChiSquare) ;
216 // To set the address of the minimization function
217 TList * toMinuit = new TList();
218 toMinuit->AddAt(emcRP,0) ;
219 toMinuit->AddAt(fDigitsArr,1) ;
220
221 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
222
223 // filling initial values for fit parameters
224 AliEMCALDigit * digit ;
225
226 Int_t ierflg = 0;
227 Int_t index = 0 ;
228 Int_t nDigits = (Int_t) nPar / 3 ;
229
230 Int_t iDigit ;
231
232 for(iDigit = 0; iDigit < nDigits; iDigit++){
233 digit = maxAt[iDigit];
234
235 Float_t x = 0.;
236 Float_t z = 0.;
237 // have to be tune for TRD1; May 31,06
238 // Int_t relid[2] ;
239 // fGeom->AbsToRelNumbering(digit->GetId(), relid) ; // obsolete method
240 // fGeom->PosInAlice(relid, x, z) ; // obsolete method
241
242 Float_t energy = maxAtEnergy[iDigit] ;
243
244 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
245 index++ ;
246 if(ierflg != 0){
247 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : x = %f", x ) ;
248 return kFALSE;
249 }
250 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
251 index++ ;
252 if(ierflg != 0){
253 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : z = %f", z) ;
254 return kFALSE;
255 }
256 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
257 index++ ;
258 if(ierflg != 0){
259 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : energy = %f", energy) ;
260 return kFALSE;
261 }
262 }
263
264 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
265 // depends on it.
266 Double_t p1 = 1.0 ;
267 Double_t p2 = 0.0 ;
268
269 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
270 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
271 gMinuit->SetMaxIterations(5);
272 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
273
274 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
275
276 if(ierflg == 4){ // Minimum not found
277 Error("FindFit", "EMCAL Unfolding Fit not converged, cluster abandoned " ) ;
278 return kFALSE ;
279 }
280 for(index = 0; index < nPar; index++){
281 Double_t err ;
282 Double_t val ;
283 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
284 fitparameters[index] = val ;
285 }
286
287 delete toMinuit ;
288 return kTRUE;
289
290}
291
292//____________________________________________________________________________
293void AliEMCALClusterizerv1::GetCalibrationParameters()
294{
295 // Set calibration parameters:
296 // if calibration database exists, they are read from database,
297 // otherwise, they are taken from digitizer.
298 //
299 // It is a user responsilibity to open CDB before reconstruction,
300 // for example:
301 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
302
303 //Check if calibration is stored in data base
304
305 if(!fCalibData && (AliCDBManager::Instance()->IsDefaultStorageSet()))
306 {
307 AliCDBEntry *entry = (AliCDBEntry*)
308 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
309 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
310 }
311
312 if(!fCalibData)
313 AliFatal("Calibration parameters not found in CDB!");
314
315 // Please fix it!! Or better just remove it...
316// if(!fCalibData)
317// {
318// //If calibration is not available use default parameters
319// //Loader
320// if ( !emcalLoader->Digitizer() )
321// emcalLoader->LoadDigitizer();
322// AliEMCALDigitizer * dig = dynamic_cast<AliEMCALDigitizer*>(emcalLoader->Digitizer());
323
324// fADCchannelECA = dig->GetECAchannel() ;
325// fADCpedestalECA = dig->GetECApedestal();
326// }
327}
328
329//____________________________________________________________________________
330void AliEMCALClusterizerv1::Init()
331{
332 // Make all memory allocations which can not be done in default constructor.
333 // Attach the Clusterizer task to the list of EMCAL tasks
334
335 AliRunLoader *rl = AliRunLoader::GetRunLoader();
336 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL"))
337 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
338 else
339 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaulGeometryName());
340
341 AliDebug(1,Form("geom 0x%x",fGeom));
342
343 if(!gMinuit)
344 gMinuit = new TMinuit(100) ;
345
346 fHists = BookHists();
347}
348
349//____________________________________________________________________________
350void AliEMCALClusterizerv1::InitParameters()
351{
352 // Initializes the parameters for the Clusterizer
353 fNumberOfECAClusters = 0;
354
355 fNTowerInGroup = 36; //Produces maximum of 80 pseudoclusters per event
356
357 fECALocMaxCut = 0.03; // ??
358
359 fTimeCut = 300e-9 ; // 300 ns time cut (to be tuned)
360 fToUnfold = kFALSE ;
361
362 fCalibData = 0 ;
363
364 const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
365 if(!recParam) {
366 AliFatal("Reconstruction parameters for EMCAL not set!");
367 }
368 else {
369 fECAClusteringThreshold = recParam->GetClusteringThreshold();
370 fECAW0 = recParam->GetW0();
371 fMinECut = recParam->GetMinECut();
372 AliDebug(1,Form("Reconstruction parameters: fECAClusteringThreshold=%.3f, fECAW=%.3f, fMinECut=%.3f",
373 fECAClusteringThreshold,fECAW0,fMinECut));
374 }
375
376}
377
378//____________________________________________________________________________
379Int_t AliEMCALClusterizerv1::AreNeighbours(AliEMCALDigit * d1, AliEMCALDigit * d2) const
380{
381 // Gives the neighbourness of two digits = 0 are not neighbour ; continue searching
382 // = 1 are neighbour
383 // = 2 is in different SM; continue searching
384 // neighbours are defined as digits having at least a common vertex
385 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
386 // which is compared to a digit (d2) not yet in a cluster
387
388 static Int_t rv;
389 static Int_t nSupMod1=0, nModule1=0, nIphi1=0, nIeta1=0, iphi1=0, ieta1=0;
390 static Int_t nSupMod2=0, nModule2=0, nIphi2=0, nIeta2=0, iphi2=0, ieta2=0;
391 static Int_t rowdiff, coldiff;
392 rv = 0 ;
393
394 fGeom->GetCellIndex(d1->GetId(), nSupMod1,nModule1,nIphi1,nIeta1);
395 fGeom->GetCellIndex(d2->GetId(), nSupMod2,nModule2,nIphi2,nIeta2);
396 if(nSupMod1 != nSupMod2) return 2; // different SM
397
398 fGeom->GetCellPhiEtaIndexInSModule(nSupMod1,nModule1,nIphi1,nIeta1, iphi1,ieta1);
399 fGeom->GetCellPhiEtaIndexInSModule(nSupMod2,nModule2,nIphi2,nIeta2, iphi2,ieta2);
400
401 rowdiff = TMath::Abs(iphi1 - iphi2);
402 coldiff = TMath::Abs(ieta1 - ieta2) ;
403
404 // neighbours with at least commom side; May 11, 2007
405 if ((coldiff==0 && abs(rowdiff)==1) || (rowdiff==0 && abs(coldiff)==1)) rv = 1;
406
407 if (gDebug == 2 && rv==1)
408 printf("AreNeighbours: neighbours=%d, id1=%d, relid1=%d,%d \n id2=%d, relid2=%d,%d \n",
409 rv, d1->GetId(), iphi1,ieta1, d2->GetId(), iphi2,ieta2);
410
411 return rv ;
412}
413
414//____________________________________________________________________________
415Int_t AliEMCALClusterizerv1::AreInGroup(AliEMCALDigit * d1, AliEMCALDigit * d2) const
416{
417 // Tells whether two digits fall within the same supermodule and
418 // tower grouping. The number of towers in a group is controlled by
419 // the parameter nTowersInGroup
420 // = 0 are not in same group but continue searching
421 // = 1 same group
422 // = 2 is in different SM, quit from searching
423 // = 3 different tower group, quit from searching
424 //
425 // The order of d1 and d2 is important: first (d1) should be a digit
426 // already in a cluster which is compared to a digit (d2) not yet in a cluster
427
428 //JLK Question: does the quit from searching assume that the digits
429 //are ordered, so that once you are in a different SM, you'll not
430 //find another in the list that will match? How about my TowerGroup search?
431
432 static Int_t rv;
433 static Int_t nSupMod1=0, nModule1=0, nIphi1=0, nIeta1=0, iphi1=0, ieta1=0;
434 static Int_t nSupMod2=0, nModule2=0, nIphi2=0, nIeta2=0, iphi2=0, ieta2=0;
435 static Int_t towerGroup1 = -1, towerGroup2 = -1;
436 rv = 0 ;
437
438 fGeom->GetCellIndex(d1->GetId(), nSupMod1,nModule1,nIphi1,nIeta1);
439 fGeom->GetCellIndex(d2->GetId(), nSupMod2,nModule2,nIphi2,nIeta2);
440 if(nSupMod1 != nSupMod2) return 2; // different SM
441
442 static Int_t nTowerInSM = fGeom->GetNCellsInSupMod()/fGeom->GetNCellsInModule();
443
444 //figure out which tower grouping each digit belongs to
445 for(int it = 0; it < nTowerInSM/fNTowerInGroup; it++) {
446 if(nModule1 <= nTowerInSM - it*fNTowerInGroup) towerGroup1 = it;
447 if(nModule2 <= nTowerInSM - it*fNTowerInGroup) towerGroup2 = it;
448 }
449 if(towerGroup1 != towerGroup2) return 3; //different Towergroup
450
451 //same SM, same towergroup, we're happy
452 if(towerGroup1 == towerGroup2 && towerGroup2 >= 0)
453 rv = 1;
454
455 if (gDebug == 2 && rv==1)
456 printf("AreInGroup: neighbours=%d, id1=%d, relid1=%d,%d \n id2=%d, relid2=%d,%d \n",
457 rv, d1->GetId(), iphi1,ieta1, d2->GetId(), iphi2,ieta2);
458
459 return rv ;
460}
461
462//____________________________________________________________________________
463void AliEMCALClusterizerv1::MakeClusters(char* option)
464{
465 // Steering method to construct the clusters stored in a list of Reconstructed Points
466 // A cluster is defined as a list of neighbour digits
467 // Mar 03, 2007 by PAI
468
469 if (fGeom==0) AliFatal("Did not get geometry from EMCALLoader");
470
471 fRecPoints->Clear();
472
473 // Set up TObjArray with pointers to digits to work on
474 TObjArray *digitsC = new TObjArray();
475 TIter nextdigit(fDigitsArr);
476 AliEMCALDigit *digit;
477 while ( (digit = dynamic_cast<AliEMCALDigit*>(nextdigit())) ) {
478 digitsC->AddLast(digit);
479 }
480
481 //Start with pseudoclusters, if option
482 if(strstr(option,"pseudo")) {
483 //
484 // New algorithm : will be created one pseudo cluster per module
485 //
486 AliDebug(1,Form("Pseudo clustering #digits : %i ",fDigitsArr->GetEntries()));
487
488 AliEMCALRecPoint *recPoints[12]; // max size is 12 : see fGeom->GetNumberOfSuperModules();
489 for(int i=0; i<12; i++) recPoints[i] = 0;
490 TIter nextdigitC(digitsC) ;
491
492 // PseudoClusterization starts
493 int nSM = 0; // # of SM
494 while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigitC())) ) { // scan over the list of digitsC
495 if(fGeom->CheckAbsCellId(digit->GetId()) ) { //Is this an EMCAL digit? Just maing sure...
496 nSM = fGeom->GetSuperModuleNumber(digit->GetId());
497 if(recPoints[nSM] == 0) {
498 recPoints[nSM] = new AliEMCALRecPoint(Form("PC%2.2i", nSM));
499 recPoints[nSM]->SetClusterType(AliESDCaloCluster::kEMCALPseudoCluster);
500 }
501 recPoints[nSM]->AddDigit(*digit, Calibrate(digit->GetAmp(), digit->GetId()));
502 }
503 }
504 fNumberOfECAClusters = 0;
505 for(int i=0; i<fGeom->GetNumberOfSuperModules(); i++) { // put non empty rec.points to container
506 if(recPoints[i]) fRecPoints->AddAt(recPoints[i], fNumberOfECAClusters++);
507 }
508 AliDebug(1,Form(" Number of PC %d ", fNumberOfECAClusters));
509 }
510
511 //
512 // Now do real clusters
513 //
514
515 double e = 0.0, ehs = 0.0;
516 TIter nextdigitC(digitsC);
517
518 while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigitC())) ) { // clean up digits
519 e = Calibrate(digit->GetAmp(), digit->GetId());
520 AliEMCALHistoUtilities::FillH1(fHists, 10, digit->GetAmp());
521 AliEMCALHistoUtilities::FillH1(fHists, 11, e);
522 if ( e < fMinECut || digit->GetTimeR() > fTimeCut )
523 digitsC->Remove(digit);
524 else
525 ehs += e;
526 }
527 AliDebug(1,Form("MakeClusters: Number of digits %d -> (e %f), ehs %d\n",
528 fDigitsArr->GetEntries(),fMinECut,ehs));
529
530 nextdigitC.Reset();
531
532 while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigitC())) ) { // scan over the list of digitsC
533 TArrayI clusterECAdigitslist(fDigitsArr->GetEntries());
534
535 if(fGeom->CheckAbsCellId(digit->GetId()) && (Calibrate(digit->GetAmp(), digit->GetId()) > fECAClusteringThreshold ) ){
536 // start a new Tower RecPoint
537 if(fNumberOfECAClusters >= fRecPoints->GetSize()) fRecPoints->Expand(2*fNumberOfECAClusters+1) ;
538 AliEMCALRecPoint *recPoint = new AliEMCALRecPoint("") ;
539 fRecPoints->AddAt(recPoint, fNumberOfECAClusters) ;
540 recPoint = dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(fNumberOfECAClusters)) ;
541 fNumberOfECAClusters++ ;
542
543 recPoint->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
544
545 recPoint->AddDigit(*digit, Calibrate(digit->GetAmp(), digit->GetId())) ;
546 TObjArray clusterDigits;
547 clusterDigits.AddLast(digit);
548 digitsC->Remove(digit) ;
549
550 AliDebug(1,Form("MakeClusters: OK id = %d, ene = %f , cell.th. = %f \n", digit->GetId(),
551 Calibrate(digit->GetAmp(),digit->GetId()), fECAClusteringThreshold));
552
553 // Grow cluster by finding neighbours
554 TIter nextClusterDigit(&clusterDigits);
555 while ( (digit = dynamic_cast<AliEMCALDigit*>(nextClusterDigit())) ) { // scan over digits in cluster
556 TIter nextdigitN(digitsC);
557 AliEMCALDigit *digitN = 0; // digi neighbor
558 while ( (digitN = (AliEMCALDigit *)nextdigitN()) ) { // scan over all digits to look for neighbours
559 if (AreNeighbours(digit, digitN)==1) { // call (digit,digitN) in THAT oder !!!!!
560 recPoint->AddDigit(*digitN, Calibrate(digitN->GetAmp(),digitN->GetId()) ) ;
561 clusterDigits.AddLast(digitN) ;
562 digitsC->Remove(digitN) ;
563 } // if(ineb==1)
564 } // scan over digits
565 } // scan over digits already in cluster
566 if(recPoint)
567 AliDebug(2,Form("MakeClusters: %d digitd, energy %f \n", clusterDigits.GetEntries(), recPoint->GetEnergy()));
568 } // If seed found
569 } // while digit
570
571 delete digitsC ;
572
573 AliDebug(1,Form("total no of clusters %d from %d digits",fNumberOfECAClusters,fDigitsArr->GetEntriesFast()));
574}
575
576void AliEMCALClusterizerv1::MakeUnfolding() const
577{
578 Fatal("AliEMCALClusterizerv1::MakeUnfolding", "--> Unfolding not implemented") ;
579}
580
581//____________________________________________________________________________
582Double_t AliEMCALClusterizerv1::ShowerShape(Double_t r)
583{
584 // Shape of the shower (see EMCAL TDR)
585 // If you change this function, change also the gradient evaluation in ChiSquare()
586
587 Double_t r4 = r*r*r*r ;
588 Double_t r295 = TMath::Power(r, 2.95) ;
589 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
590 return shape ;
591}
592
593//____________________________________________________________________________
594void AliEMCALClusterizerv1::UnfoldCluster(AliEMCALRecPoint * /*iniTower*/,
595 Int_t /*nMax*/,
596 AliEMCALDigit ** /*maxAt*/,
597 Float_t * /*maxAtEnergy*/) const
598{
599 // Performs the unfolding of a cluster with nMax overlapping showers
600
601 Fatal("UnfoldCluster", "--> Unfolding not implemented") ;
602
603}
604
605//_____________________________________________________________________________
606void AliEMCALClusterizerv1::UnfoldingChiSquare(Int_t & /*nPar*/, Double_t * /*Grad*/,
607 Double_t & /*fret*/,
608 Double_t * /*x*/, Int_t /*iflag*/)
609{
610 // Calculates the Chi square for the cluster unfolding minimization
611 // Number of parameters, Gradient, Chi squared, parameters, what to do
612
613 ::Fatal("UnfoldingChiSquare","Unfolding not implemented") ;
614}
615//____________________________________________________________________________
616void AliEMCALClusterizerv1::Print(Option_t * /*option*/)const
617{
618 // Print clusterizer parameters
619
620 TString message("\n") ;
621
622 if( strcmp(GetName(), "") !=0 ){
623
624 // Print parameters
625
626 TString taskName(Version()) ;
627
628 printf("--------------- ");
629 printf(taskName.Data()) ;
630 printf(" ");
631 printf("Clusterizing digits: ");
632 printf("\n ECA Local Maximum cut = %f", fECALocMaxCut);
633 printf("\n ECA Logarithmic weight = %f", fECAW0);
634 if(fToUnfold)
635 printf("\nUnfolding on\n");
636 else
637 printf("\nUnfolding off\n");
638
639 printf("------------------------------------------------------------------");
640 }
641 else
642 printf("AliEMCALClusterizerv1 not initialized ") ;
643}
644
645//____________________________________________________________________________
646void AliEMCALClusterizerv1::PrintRecPoints(Option_t * option)
647{
648 // Prints list of RecPoints produced at the current pass of AliEMCALClusterizer
649 if(strstr(option,"deb")) {
650 printf("PrintRecPoints: Clusterization result:") ;
651
652 printf(" Found %d ECA Rec Points\n ",
653 fRecPoints->GetEntriesFast()) ;
654 }
655
656 if(strstr(option,"all")) {
657 if(strstr(option,"deb")) {
658 printf("\n-----------------------------------------------------------------------\n") ;
659 printf("Clusters in ECAL section\n") ;
660 printf("Index Ene(GeV) Multi Module GX GY GZ lX lY lZ Dispersion Lambda 1 Lambda 2 # of prim Primaries list\n") ;
661 }
662 Int_t index =0;
663 Float_t maxE=0;
664 Float_t maxL1=0;
665 Float_t maxL2=0;
666 Float_t maxDis=0;
667
668 AliEMCALHistoUtilities::FillH1(fHists, 12, double(fRecPoints->GetEntries()));
669
670 for (index = 0 ; index < fRecPoints->GetEntries() ; index++) {
671 AliEMCALRecPoint * rp = dynamic_cast<AliEMCALRecPoint * >(fRecPoints->At(index)) ;
672 TVector3 globalpos;
673 //rp->GetGlobalPosition(globalpos);
674 TVector3 localpos;
675 rp->GetLocalPosition(localpos);
676 Float_t lambda[2];
677 rp->GetElipsAxis(lambda);
678 Int_t * primaries;
679 Int_t nprimaries;
680 primaries = rp->GetPrimaries(nprimaries);
681 if(strstr(option,"deb"))
682 printf("\n%6d %8.4f %3d %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4f %4f %2d : ",
683 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(),
684 globalpos.X(), globalpos.Y(), globalpos.Z(), localpos.X(), localpos.Y(), localpos.Z(),
685 rp->GetDispersion(), lambda[0], lambda[1], nprimaries) ;
686 /////////////
687 if(rp->GetEnergy()>maxE){
688 maxE=rp->GetEnergy();
689 maxL1=lambda[0];
690 maxL2=lambda[1];
691 maxDis=rp->GetDispersion();
692 }
693 fPointE->Fill(rp->GetEnergy());
694 fPointL1->Fill(lambda[0]);
695 fPointL2->Fill(lambda[1]);
696 fPointDis->Fill(rp->GetDispersion());
697 fPointMult->Fill(rp->GetMultiplicity());
698 /////////////
699 if(strstr(option,"deb")){
700 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
701 printf("%d ", primaries[iprimary] ) ;
702 }
703 }
704 }
705
706 fMaxE->Fill(maxE);
707 fMaxL1->Fill(maxL1);
708 fMaxL2->Fill(maxL2);
709 fMaxDis->Fill(maxDis);
710
711 if(strstr(option,"deb"))
712 printf("\n-----------------------------------------------------------------------\n");
713 }
714}
715TList* AliEMCALClusterizerv1::BookHists()
716{
717 //set up histograms for monitoring clusterizer performance
718
719 gROOT->cd();
720
721 fPointE = new TH1F("00_pointE","point energy", 2000, 0.0, 150.);
722 fPointL1 = new TH1F("01_pointL1","point L1", 1000, 0.0, 3.);
723 fPointL2 = new TH1F("02_pointL2","point L2", 1000, 0.0, 3.);
724 fPointDis = new TH1F("03_pointDisp","point dispersion", 1000, 0.0, 10.);
725 fPointMult = new TH1F("04_pointMult","#cell in point(cluster)", 101, -0.5, 100.5);
726 fDigitAmp = new TH1F("05_digitAmp","Digit Amplitude", 2000, 0.0, 5000.);
727 fMaxE = new TH1F("06_maxE","Max point energy", 2000, 0.0, 150.);
728 fMaxL1 = new TH1F("07_maxL1","Largest (first) of eigenvalue of covariance matrix", 1000, 0.0, 3.);
729 fMaxL2 = new TH1F("08_maxL2","Smalest (second) of eigenvalue of covariace matrix", 1000, 0.0, 3.);
730 fMaxDis = new TH1F("09_maxDis","Point dispersion", 1000, 0.0, 10.); // 9
731 //
732 new TH1F("10_adcOfDigits","adc of digits(threshold control)", 1001, -0.5, 1000.5); // 10
733 new TH1F("11_energyOfDigits","energy of digits(threshold control)", 1000, 0.0, 1.); // 11
734 new TH1F("12_numberOfPoints","number of points(clusters)", 101, -0.5, 100.5); // 12
735
736 return AliEMCALHistoUtilities::MoveHistsToList("EmcalClusterizerv1ControlHists", kFALSE);
737}
738
739void AliEMCALClusterizerv1::SaveHists(const char *fn)
740{
741 AliEMCALHistoUtilities::SaveListOfHists(fHists, fn, kTRUE);
742}
743
744void AliEMCALClusterizerv1::PrintRecoInfo()
745{
746 printf(" AliEMCALClusterizerv1::PrintRecoInfo() : version %s \n", Version() );
747 TH1F *h = (TH1F*)fHists->At(12);
748 if(h) {
749 printf(" ## Multiplicity of RecPoints ## \n");
750 for(int i=1; i<=h->GetNbinsX(); i++) {
751 int nbin = int((*h)[i]);
752 int mult = int(h->GetBinCenter(i));
753 if(nbin > 0) printf(" %i : %5.5i %6.3f %% \n", mult, nbin, 100.*nbin/h->GetEntries());
754 }
755 }
756}
757
758void AliEMCALClusterizerv1::DrawLambdasHists()
759{
760 if(fMaxL1) {
761 fMaxL1->Draw();
762 if(fMaxL2) fMaxL2->Draw("same");
763 if(fMaxDis) {
764 fMaxDis->Draw("same");
765 }
766 }
767}