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