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