Correction of previous commit.
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALClusterizer.cxx
CommitLineData
483b0559 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//_________________________________________________________________________
19// Base class for the clusterization algorithm (pure abstract)
20//*--
21//*-- Author: Yves Schutz SUBATECH
ee08edde 22//
23// Clusterization mother class. Contains common methods/data members of different
24// clusterizers. GCB 2010
483b0559 25//////////////////////////////////////////////////////////////////////////////
26
27// --- ROOT system ---
c47157cd 28#include "TClonesArray.h"
29#include "TTree.h"
ee08edde 30#include <TFile.h>
31class TFolder;
32#include <TMath.h>
33#include <TMinuit.h>
34#include <TTree.h>
35class TSystem;
36#include <TBenchmark.h>
37#include <TBrowser.h>
38#include <TROOT.h>
483b0559 39
40// --- Standard library ---
ee08edde 41#include <cassert>
483b0559 42
43// --- AliRoot header files ---
483b0559 44#include "AliEMCALClusterizer.h"
ee08edde 45#include "AliEMCALReconstructor.h"
46#include "AliRunLoader.h"
47#include "AliRun.h"
c47157cd 48#include "AliLog.h"
ee08edde 49#include "AliEMCAL.h"
50#include "AliEMCALRecPoint.h"
51#include "AliEMCALRecParam.h"
52#include "AliEMCALGeometry.h"
53#include "AliEMCALRecParam.h"
54#include "AliCDBManager.h"
55#include "AliCaloCalibPedestal.h"
56#include "AliEMCALCalibData.h"
57class AliCDBStorage;
58#include "AliCDBEntry.h"
483b0559 59
60ClassImp(AliEMCALClusterizer)
61
62//____________________________________________________________________________
c47157cd 63AliEMCALClusterizer::AliEMCALClusterizer():
ac084be7 64 fIsInputCalibrated(kFALSE),
294553d1 65 fJustClusters(kFALSE),
c47157cd 66 fDigitsArr(NULL),
67 fTreeR(NULL),
ee08edde 68 fRecPoints(NULL),
69 fGeom(NULL),
70 fCalibData(NULL),
71 fCaloPed(NULL),
72 fADCchannelECA(0.),fADCpedestalECA(0.),
73 fTimeMin(-1.),fTimeMax(1.),fTimeCut(1.),
74 fDefaultInit(kFALSE),fToUnfold(kFALSE),
75 fNumberOfECAClusters(0), fECAClusteringThreshold(0.),
65bec413 76 fECALocMaxCut(0.),fECAW0(0.),fMinECut(0.),
77 fClusterUnfolding(NULL)
483b0559 78{
79 // ctor
ee08edde 80
81 Init();
ee08edde 82}
83
84//____________________________________________________________________________
85AliEMCALClusterizer::AliEMCALClusterizer(AliEMCALGeometry* geometry):
ac084be7 86 fIsInputCalibrated(kFALSE),
294553d1 87 fJustClusters(kFALSE),
ee08edde 88 fDigitsArr(NULL),
89 fTreeR(NULL),
90 fRecPoints(NULL),
91 fGeom(geometry),
92 fCalibData(NULL),
93 fCaloPed(NULL),
94 fADCchannelECA(0.),fADCpedestalECA(0.),
95 fTimeMin(-1.),fTimeMax(1.),fTimeCut(1.),
96 fDefaultInit(kFALSE),fToUnfold(kFALSE),
97 fNumberOfECAClusters(0), fECAClusteringThreshold(0.),
65bec413 98 fECALocMaxCut(0.),fECAW0(0.),fMinECut(0.),
99 fClusterUnfolding(NULL)
ee08edde 100{
ac084be7 101 // Ctor with the indication of the file where header Tree and digits Tree are stored.
102 // Use this contructor to avoid usage of Init() which uses runloader.
103 // Change needed by HLT - MP.
104 // Note for the future: the use on runloader should be avoided or optional at least.
105 // Another way is to make Init virtual and protected at least
106 // such that the deriving classes can overload Init();
ee08edde 107
108 if (!fGeom)
109 {
110 AliFatal("Geometry not initialized.");
111 }
65bec413 112 Int_t i=0;
113 for (i = 0; i < 8; i++)
114 fSSPars[i] = 0.;
115 for (i = 0; i < 3; i++) {
116 fPar5[i] = 0.;
117 fPar6[i] = 0.;
118 }
483b0559 119}
839828a6 120
ee08edde 121//____________________________________________________________________________
ac084be7 122AliEMCALClusterizer::AliEMCALClusterizer(AliEMCALGeometry *geometry,
123 AliEMCALCalibData *calib,
124 AliCaloCalibPedestal *caloped):
125 fIsInputCalibrated(kFALSE),
294553d1 126 fJustClusters(kFALSE),
ee08edde 127 fDigitsArr(NULL),
128 fTreeR(NULL),
129 fRecPoints(NULL),
130 fGeom(geometry),
131 fCalibData(calib),
132 fCaloPed(caloped),
133 fADCchannelECA(0.),fADCpedestalECA(0.),
134 fTimeMin(-1.),fTimeMax(1.),fTimeCut(1.),
135 fDefaultInit(kFALSE),fToUnfold(kFALSE),
136 fNumberOfECAClusters(0), fECAClusteringThreshold(0.),
65bec413 137 fECALocMaxCut(0.),fECAW0(0.),fMinECut(0.),
138 fClusterUnfolding(NULL)
ee08edde 139{
c526514b 140 // ctor, geometry and calibration are initialized elsewhere.
141
142 if (!fGeom)
143 AliFatal("Geometry not initialized.");
ee08edde 144
65bec413 145 Int_t i=0;
146 for (i = 0; i < 8; i++)
147 fSSPars[i] = 0.;
148 for (i = 0; i < 3; i++) {
149 fPar5[i] = 0.;
150 fPar6[i] = 0.;
151 }
ee08edde 152}
153
483b0559 154//____________________________________________________________________________
c47157cd 155AliEMCALClusterizer::~AliEMCALClusterizer()
483b0559 156{
c47157cd 157 // dtor
23ca956b 158 //Already deleted in AliEMCALReconstructor.
159
65bec413 160 if(fClusterUnfolding) delete fClusterUnfolding;
18a21c7c 161}
162
ee08edde 163//____________________________________________________________________________
ac084be7 164Float_t AliEMCALClusterizer::Calibrate(const Float_t amp, const Float_t time, const Int_t absId)
ee08edde 165{
ee08edde 166 // Convert digitized amplitude into energy.
167 // Calibration parameters are taken from calibration data base for raw data,
168 // or from digitizer parameters for simulated data.
ac084be7 169
170 //Return energy with default parameters if calibration is not available
924d921d 171 if (!fCalibData&&!fCaloPed) {
ac084be7 172 if (fIsInputCalibrated == kTRUE)
b1324a01 173 {
174 AliDebug(10, Form("Input already calibrated!"));
175 return amp;
ac084be7 176 }
ee08edde 177
ac084be7 178 return -fADCpedestalECA + amp * fADCchannelECA ;
179 }
180
181 if (fGeom==0)
182 AliFatal("Did not get geometry from EMCALLoader") ;
b1324a01 183
ac084be7 184 Int_t iSupMod = -1;
185 Int_t nModule = -1;
186 Int_t nIphi = -1;
187 Int_t nIeta = -1;
188 Int_t iphi = -1;
189 Int_t ieta = -1;
ee08edde 190
ac084be7 191 Bool_t bCell = fGeom->GetCellIndex(absId, iSupMod, nModule, nIphi, nIeta) ;
192 if(!bCell) {
193 fGeom->PrintGeometry();
194 AliError(Form("Wrong cell id number : %i", absId));
195 //assert(0); // GCB: This aborts reconstruction of raw simulations
196 //where simulation had more SM than default geometry,
197 //change to return 0, to avoid aborting good generations.
198 return 0;
ee08edde 199 }
b1324a01 200
ac084be7 201 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,nModule,nIphi, nIeta,iphi,ieta);
202
203 // Check if channel is bad (dead or hot), in this case return 0.
204 // Gustavo: 15-12-09 In case of RAW data this selection is already done, but not in simulation.
205 // for the moment keep it here but remember to do the selection at the sdigitizer level
206 // and remove it from here
294553d1 207 if (fCaloPed) {
208 Int_t channelStatus = (Int_t)(fCaloPed->GetDeadMap(iSupMod))->GetBinContent(ieta,iphi);
209 if(channelStatus == AliCaloCalibPedestal::kHot || channelStatus == AliCaloCalibPedestal::kDead) {
210 AliDebug(2,Form("Tower from SM %d, ieta %d, iphi %d is BAD : status %d !!!",iSupMod,ieta,iphi, channelStatus));
211 return 0;
212 }
ac084be7 213 }
214 //Check if time is too large or too small, indication of a noisy channel, remove in this case
215 if(time > fTimeMax || time < fTimeMin) return 0;
b1324a01 216
9c8525ff 217 if (fIsInputCalibrated||!fCalibData)
ac084be7 218 {
219 AliDebug(10, Form("Input already calibrated!"));
220 return amp;
b1324a01 221 }
ac084be7 222
223 fADCchannelECA = fCalibData->GetADCchannel (iSupMod,ieta,iphi);
224 fADCpedestalECA = fCalibData->GetADCpedestal(iSupMod,ieta,iphi);
225
226 return -fADCpedestalECA + amp * fADCchannelECA ;
ee08edde 227}
228
229//____________________________________________________________________________
230void AliEMCALClusterizer::GetCalibrationParameters()
231{
232 // Set calibration parameters:
ac084be7 233 // If calibration database exists, they are read from database,
ee08edde 234 // otherwise, they are taken from digitizer.
ee08edde 235 // It is a user responsilibity to open CDB before reconstruction,
236 // for example:
237 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
ac084be7 238
239 if (fIsInputCalibrated)
240 return;
ee08edde 241
242 //Check if calibration is stored in data base
ee08edde 243 if(!fCalibData)
244 {
245 AliCDBEntry *entry = (AliCDBEntry*)
246 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
247 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
248 }
249
250 if(!fCalibData)
251 AliFatal("Calibration parameters not found in CDB!");
ee08edde 252}
253
254//____________________________________________________________________________
255void AliEMCALClusterizer::GetCaloCalibPedestal()
256{
c526514b 257 // Set calibration parameters:
258 // if calibration database exists, they are read from database,
259 // otherwise, they are taken from digitizer.
260 //
261 // It is a user responsilibity to open CDB before reconstruction,
262 // for example:
263 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
ac084be7 264
265 if (fIsInputCalibrated)
266 return;
c526514b 267
ac084be7 268 // Check if calibration is stored in data base
c526514b 269 if(!fCaloPed)
270 {
271 AliCDBEntry *entry = (AliCDBEntry*)
272 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
273 if (entry) fCaloPed = (AliCaloCalibPedestal*) entry->GetObject();
274 }
275
276 if(!fCaloPed)
277 AliFatal("Pedestal info not found in CDB!");
ee08edde 278}
279
280//____________________________________________________________________________
281void AliEMCALClusterizer::Init()
282{
283 // Make all memory allocations which can not be done in default constructor.
284 // Attach the Clusterizer task to the list of EMCAL tasks
285
286 AliRunLoader *rl = AliRunLoader::Instance();
a51e676d 287 if (rl->GetAliRun()){
288 AliEMCAL* emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
289 if(emcal)fGeom = emcal->GetGeometry();
290 }
291
292 if(!fGeom){
ac084be7 293 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
a51e676d 294 }
ee08edde 295
296 AliDebug(1,Form("geom %p",fGeom));
297
298 if(!gMinuit)
299 gMinuit = new TMinuit(100) ;
300
65bec413 301 Int_t i=0;
302 for (i = 0; i < 8; i++)
303 fSSPars[i] = 0.;
304 for (i = 0; i < 3; i++) {
305 fPar5[i] = 0.;
306 fPar6[i] = 0.;
307 }
ee08edde 308}
309
310//____________________________________________________________________________
311void AliEMCALClusterizer::InitParameters()
ac084be7 312{
313 // Initializes the parameters for the Clusterizer from AliEMCALReconstructor::GetRecParam().
314
315 return InitParameters(AliEMCALReconstructor::GetRecParam());
316}
317
318//____________________________________________________________________________
319void AliEMCALClusterizer::InitParameters(const AliEMCALRecParam* recParam)
ee08edde 320{
321 // Initializes the parameters for the Clusterizer
ac084be7 322
ee08edde 323 fNumberOfECAClusters = 0 ;
324 fCalibData = 0 ;
325 fCaloPed = 0 ;
326
ee08edde 327 if(!recParam) {
328 AliFatal("Reconstruction parameters for EMCAL not set!");
ac084be7 329 }
330
331 fECAClusteringThreshold = recParam->GetClusteringThreshold();
332 fECAW0 = recParam->GetW0();
333 fMinECut = recParam->GetMinECut();
334 fToUnfold = recParam->GetUnfold();
335 fECALocMaxCut = recParam->GetLocMaxCut();
336 fTimeCut = recParam->GetTimeCut();
337 fTimeMin = recParam->GetTimeMin();
338 fTimeMax = recParam->GetTimeMax();
65bec413 339
ac084be7 340 AliDebug(1,Form("Reconstruction parameters: fECAClusteringThreshold=%.3f GeV, fECAW=%.3f, fMinECut=%.3f GeV, "
341 "fToUnfold=%d, fECALocMaxCut=%.3f GeV, fTimeCut=%e s,fTimeMin=%e s,fTimeMax=%e s",
342 fECAClusteringThreshold,fECAW0,fMinECut,fToUnfold,fECALocMaxCut,fTimeCut, fTimeMin, fTimeMax));
343
344 if (fToUnfold) {
345 Int_t i=0;
346 for (i = 0; i < 8; i++) {
347 fSSPars[i] = recParam->GetSSPars(i);
348 } //end of loop over parameters
349 for (i = 0; i < 3; i++) {
350 fPar5[i] = recParam->GetPar5(i);
351 fPar6[i] = recParam->GetPar6(i);
352 } //end of loop over parameters
622e10be 353
ac084be7 354 InitClusterUnfolding();
622e10be 355
ac084be7 356 for (i = 0; i < 8; i++) {
357 AliDebug(1,Form("unfolding shower shape parameters: fSSPars=%f \n",fSSPars[i]));
358 }
359 for (i = 0; i < 3; i++) {
360 AliDebug(1,Form("unfolding parameter 5: fPar5=%f \n",fPar5[i]));
361 AliDebug(1,Form("unfolding parameter 6: fPar6=%f \n",fPar6[i]));
362 }
363 } // to unfold
ee08edde 364}
365
ee08edde 366//____________________________________________________________________________
367void AliEMCALClusterizer::Print(Option_t * /*option*/)const
368{
369 // Print clusterizer parameters
370
371 TString message("\n") ;
372
ac084be7 373 if (strcmp(GetName(),"") == 0) {
374 printf("AliEMCALClusterizer not initialized\n");
375 return;
376 }
ee08edde 377
ac084be7 378 // Print parameters
379 TString taskName(Version()) ;
ee08edde 380
ac084be7 381 printf("--------------- ");
382 printf("%s",taskName.Data()) ;
383 printf(" ");
384 printf("Clusterizing digits: ");
385 printf("\n ECA Local Maximum cut = %f", fECALocMaxCut);
386 printf("\n ECA Logarithmic weight = %f", fECAW0);
387 if (fToUnfold) {
388 printf("\nUnfolding on\n");
389 printf("Unfolding parameters: fSSpars: \n");
390 Int_t i=0;
391 for (i = 0; i < 8; i++) {
392 printf("fSSPars[%d] = %f \n", i, fSSPars[i]);
393 }
394 printf("Unfolding parameter 5 and 6: fPar5 and fPar6: \n");
395 for (i = 0; i < 3; i++) {
396 printf("fPar5[%d] = %f \n", i, fPar5[i]);
397 printf("fPar6[%d] = %f \n", i, fPar6[i]);
c526514b 398 }
ee08edde 399 }
400 else
ac084be7 401 printf("\nUnfolding off\n");
402
403 printf("------------------------------------------------------------------");
ee08edde 404}
405
406//____________________________________________________________________________
407void AliEMCALClusterizer::PrintRecPoints(Option_t * option)
408{
409 // Prints list of RecPoints produced at the current pass of AliEMCALClusterizer
ac084be7 410
411 if (strstr(option,"deb")) {
ee08edde 412 printf("PrintRecPoints: Clusterization result:") ;
ee08edde 413 printf(" Found %d ECA Rec Points\n ",
414 fRecPoints->GetEntriesFast()) ;
415 }
416
ac084be7 417 if (strstr(option,"all")) {
418 if (strstr(option,"deb")) {
ee08edde 419 printf("\n-----------------------------------------------------------------------\n") ;
420 printf("Clusters in ECAL section\n") ;
421 printf("Index Ene(GeV) Multi Module GX GY GZ lX lY lZ Dispersion Lambda 1 Lambda 2 # of prim Primaries list\n") ;
422 }
423 Int_t index;
424 for (index = 0 ; index < fRecPoints->GetEntries() ; index++) {
425 AliEMCALRecPoint * rp = dynamic_cast<AliEMCALRecPoint * >(fRecPoints->At(index)) ;
ac084be7 426 if (!rp)
427 continue;
428
429 TVector3 globalpos;
430 //rp->GetGlobalPosition(globalpos);
431 TVector3 localpos;
432 rp->GetLocalPosition(localpos);
433 Float_t lambda[2];
434 rp->GetElipsAxis(lambda);
51e4198e 435
ac084be7 436 Int_t nprimaries=0;
437 Int_t * primaries = rp->GetPrimaries(nprimaries);
438 if(strstr(option,"deb"))
439 printf("\n%6d %8.4f %3d %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4f %4f %2d : ",
440 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(),
441 globalpos.X(), globalpos.Y(), globalpos.Z(), localpos.X(), localpos.Y(), localpos.Z(),
442 rp->GetDispersion(), lambda[0], lambda[1], nprimaries) ;
443 if(strstr(option,"deb")){
444 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
445 printf("%d ", primaries[iprimary] ) ;
ee08edde 446 }
447 }
448 }
449
450 if(strstr(option,"deb"))
451 printf("\n-----------------------------------------------------------------------\n");
452 }
453}
454
455//___________________________________________________________________
456void AliEMCALClusterizer::PrintRecoInfo()
457{
ac084be7 458 // Print reco version
459
ee08edde 460 printf(" AliEMCALClusterizer::PrintRecoInfo() : version %s \n", Version() );
ee08edde 461}
462
18a21c7c 463//____________________________________________________________________________
c47157cd 464void AliEMCALClusterizer::SetInput(TTree *digitsTree)
18a21c7c 465{
c47157cd 466 // Read the digits from the input tree
ac084be7 467
c47157cd 468 TBranch *branch = digitsTree->GetBranch("EMCAL");
469 if (!branch) {
470 AliError("can't get the branch with the EMCAL digits !");
471 return;
472 }
3f9ad99f 473 if (!fDigitsArr)
474 fDigitsArr = new TClonesArray("AliEMCALDigit",100);
c47157cd 475 branch->SetAddress(&fDigitsArr);
476 branch->GetEntry(0);
483b0559 477}
478
479//____________________________________________________________________________
c47157cd 480void AliEMCALClusterizer::SetOutput(TTree *clustersTree)
483b0559 481{
c47157cd 482 // Read the digits from the input tree
ac084be7 483
c47157cd 484 AliDebug(9, "Making array for EMCAL clusters");
ac084be7 485 fRecPoints = new TObjArray(1000);
486 if (clustersTree) {
487 fTreeR = clustersTree;
488 Int_t split = 0;
489 Int_t bufsize = 32000;
490 fTreeR->Branch("EMCALECARP", "TObjArray", &fRecPoints, bufsize, split);
491 }
88cb7938 492}
ee08edde 493
b1324a01 494//___________________________________________________________________
ac084be7 495void AliEMCALClusterizer::SetInputCalibrated(Bool_t val)
b1324a01 496{
ac084be7 497 // Flag to indicate that input is calibrated - the case when we run already on ESD
ee08edde 498
ac084be7 499 fIsInputCalibrated = val;
500}
294553d1 501
502//___________________________________________________________________
503void AliEMCALClusterizer::SetJustClusters(Bool_t val)
504{
505 // Flag to indicate that we are running on ESDs, when calling
506 // rp->EvalAll(fECAW0,fDigitsArr,fJustClusters); in derived classes
507
508 fJustClusters = val;
509}