Fix against cleaning with deletion of fToFit in destructor
[u/mrichter/AliRoot.git] / PWG4 / UserTasks / EmcalTasks / AliAnalysisTaskEMCALClusterizeFast.cxx
CommitLineData
2f7259cf 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// --- Root ---
19#include <TClonesArray.h>
20#include <TGeoManager.h>
21#include <TObjArray.h>
22#include <TString.h>
23#include <TTree.h>
7a7d5a64 24
25// --- AliRoot ---
2f7259cf 26#include "AliAODCaloCluster.h"
27#include "AliAODEvent.h"
28#include "AliAnalysisManager.h"
29#include "AliCDBEntry.h"
30#include "AliCDBManager.h"
31#include "AliCaloCalibPedestal.h"
32#include "AliEMCALAfterBurnerUF.h"
33#include "AliEMCALCalibData.h"
34#include "AliEMCALClusterizerNxN.h"
35#include "AliEMCALClusterizerv1.h"
3786256f 36#include "AliEMCALClusterizerv2.h"
7a7d5a64 37#include "AliEMCALClusterizerFixedWindow.h"
2f7259cf 38#include "AliEMCALDigit.h"
39#include "AliEMCALGeometry.h"
40#include "AliEMCALRecParam.h"
41#include "AliEMCALRecPoint.h"
42#include "AliEMCALRecoUtils.h"
43#include "AliESDEvent.h"
6b7ed7bd 44#include "AliInputEventHandler.h"
2f7259cf 45#include "AliLog.h"
46
47#include "AliAnalysisTaskEMCALClusterizeFast.h"
48
49ClassImp(AliAnalysisTaskEMCALClusterizeFast)
50
51//________________________________________________________________________
2431b20f 52AliAnalysisTaskEMCALClusterizeFast::AliAnalysisTaskEMCALClusterizeFast()
53 : AliAnalysisTaskSE(),
349bf69e 54 fRun(-1),
2431b20f 55 fDigitsArr(0),
56 fClusterArr(0),
57 fRecParam(0),
58 fClusterizer(0),
59 fUnfolder(0),
60 fJustUnfold(kFALSE),
61 fGeomName(),
62 fGeomMatrixSet(kFALSE),
63 fLoadGeomMatrices(kFALSE),
64 fOCDBpath(),
65 fCalibData(0),
66 fPedestalData(0),
67 fOutputAODBranch(0),
68 fOutputAODBrName(),
69 fRecoUtils(0),
70 fLoadCalib(0),
4cf9204b 71 fLoadPed(0),
e50a444f 72 fAttachClusters(1),
95f69c66 73 fRecalibOnly(0),
7a7d5a64 74 fSubBackground(0),
75 fCreatePattern(0),
e50a444f 76 fOverwrite(0),
7a7d5a64 77 fNewClusterArrayName("newCaloClusters"),
78 fNPhi(4),
79 fNEta(4),
3c56da8f 80 fShiftPhi(2),
81 fShiftEta(2),
82 fTRUShift(0),
e93ec1f7 83 fClusterizeFastORs(0)
2431b20f 84{
85 // Constructor
c6d60de7 86
87 for(Int_t i = 0; i < 12; ++i)
88 fGeomMatrix[i] = 0;
2431b20f 89}
90
91//________________________________________________________________________
2f7259cf 92AliAnalysisTaskEMCALClusterizeFast::AliAnalysisTaskEMCALClusterizeFast(const char *name)
93 : AliAnalysisTaskSE(name),
349bf69e 94 fRun(-1),
2f7259cf 95 fDigitsArr(0),
96 fClusterArr(0),
97 fRecParam(new AliEMCALRecParam),
98 fClusterizer(0),
99 fUnfolder(0),
100 fJustUnfold(kFALSE),
101 fGeomName("EMCAL_FIRSTYEARV1"),
102 fGeomMatrixSet(kFALSE),
103 fLoadGeomMatrices(kFALSE),
104 fOCDBpath(),
105 fCalibData(0),
106 fPedestalData(0),
107 fOutputAODBranch(0),
108 fOutputAODBrName(),
10d33986 109 fRecoUtils(0),
110 fLoadCalib(0),
4cf9204b 111 fLoadPed(0),
e50a444f 112 fAttachClusters(1),
95f69c66 113 fRecalibOnly(0),
7a7d5a64 114 fSubBackground(0),
115 fCreatePattern(0),
e50a444f 116 fOverwrite(0),
7a7d5a64 117 fNewClusterArrayName("newCaloClusters"),
118 fNPhi(4),
119 fNEta(4),
3c56da8f 120 fShiftPhi(2),
121 fShiftEta(2),
122 fTRUShift(0),
e93ec1f7 123 fClusterizeFastORs(0)
2f7259cf 124{
125 // Constructor
126
0a7eb283 127 fBranchNames = "ESD:AliESDHeader.,AliESDRun.,EMCALCells.,EMCALTrigger. AOD:header,emcalCells";
95f69c66 128 for(Int_t i = 0; i < 12; ++i)
2f7259cf 129 fGeomMatrix[i] = 0;
130}
131
132//________________________________________________________________________
133AliAnalysisTaskEMCALClusterizeFast::~AliAnalysisTaskEMCALClusterizeFast()
134{
135 // Destructor.
136
536c7492 137 //delete fDigitsArr;
2f7259cf 138 delete fClusterizer;
139 delete fUnfolder;
140 delete fRecoUtils;
141}
142
143//-------------------------------------------------------------------
144void AliAnalysisTaskEMCALClusterizeFast::UserCreateOutputObjects()
145{
146 // Create output objects.
147
148 if (!fOutputAODBrName.IsNull()) {
149 fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
150 fOutputAODBranch->SetName(fOutputAODBrName);
151 AddAODBranch("TClonesArray", &fOutputAODBranch);
152 AliInfo(Form("Created Branch: %s",fOutputAODBrName.Data()));
153 }
154}
155
156//________________________________________________________________________
157void AliAnalysisTaskEMCALClusterizeFast::UserExec(Option_t *)
158{
159 // Main loop, called for each event
160
161 // remove the contents of output list set in the previous event
162 if (fOutputAODBranch)
163 fOutputAODBranch->Clear("C");
164
165 AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(InputEvent());
166 AliAODEvent *aodevent = dynamic_cast<AliAODEvent*>(InputEvent());
167
168 if (!esdevent&&!aodevent) {
169 Error("UserExec","Event not available");
170 return;
171 }
172
173 LoadBranches();
6b7ed7bd 174
175 UInt_t offtrigger = 0;
176 if (esdevent) {
9809ed8c 177 UInt_t mask1 = esdevent->GetESDRun()->GetDetectorsInDAQ();
178 UInt_t mask2 = esdevent->GetESDRun()->GetDetectorsInReco();
179 Bool_t desc1 = (mask1 >> 18) & 0x1;
180 Bool_t desc2 = (mask2 >> 18) & 0x1;
181 if (desc1==0 || desc2==0) { //AliDAQ::OfflineModuleName(180=="EMCAL"
182 AliError(Form("EMCAL not in DAQ/RECO: %u (%u)/%u (%u)",
183 mask1, esdevent->GetESDRun()->GetDetectorsInReco(),
184 mask2, esdevent->GetESDRun()->GetDetectorsInDAQ()));
6b7ed7bd 185 return;
186 }
187 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
188 offtrigger = ((AliInputEventHandler*)(am->GetInputEventHandler()))->IsEventSelected();
189 } else if (aodevent) {
190 offtrigger = aodevent->GetHeader()->GetOfflineTrigger();
191 }
192 if (offtrigger & AliVEvent::kFastOnly) {
193 AliWarning(Form("EMCAL not in fast only partition"));
194 return;
195 }
2f7259cf 196
197 Init();
198
199 if (fJustUnfold) {
200 AliWarning("Unfolding not implemented");
84ccad86 201 return;
202 }
203
95f69c66 204 FillDigitsArray();
84ccad86 205
95f69c66 206 if (fRecalibOnly) {
207 UpdateCells();
208 return; // not requested to run clusterizer
84ccad86 209 }
7099ec08 210
95f69c66 211 Clusterize();
212 UpdateCells();
213 UpdateClusters();
2431b20f 214
95f69c66 215 if (fOutputAODBranch)
216 RecPoints2Clusters(fOutputAODBranch);
2431b20f 217}
218
219//________________________________________________________________________
95f69c66 220void AliAnalysisTaskEMCALClusterizeFast::Clusterize()
2431b20f 221{
95f69c66 222 // Clusterize
7099ec08 223
95f69c66 224 if (fSubBackground) {
225 fClusterizer->SetInputCalibrated(kTRUE);
226 fClusterizer->SetCalibrationParameters(0);
2f7259cf 227 }
d3b5a5ec 228
95f69c66 229 fClusterizer->Digits2Clusters("");
230 if (fSubBackground) {
4889ed8b 231 if (fCalibData) {
232 fClusterizer->SetInputCalibrated(kFALSE);
233 fClusterizer->SetCalibrationParameters(fCalibData);
234 }
4cf9204b 235 }
4cf9204b 236}
237
238//________________________________________________________________________
95f69c66 239void AliAnalysisTaskEMCALClusterizeFast::FillDigitsArray()
2f7259cf 240{
6265e793 241 // Fill digits array
55a8e3e4 242
6265e793 243 fDigitsArr->Clear("C");
244
5133b922 245 if (fCreatePattern) { // Fill digits from a pattern
7a7d5a64 246 AliEMCALGeometry *fGeom = AliEMCALGeometry::GetInstance(fGeomName);
7a7d5a64 247 Int_t maxd = fGeom->GetNCells() / 4;
6265e793 248 for (Int_t idigit = 0; idigit < maxd; idigit++){
7a7d5a64 249 if (idigit % 24 == 12) idigit += 12;
250 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
251 digit->SetId(idigit * 4);
252 digit->SetTime(600);
253 digit->SetTimeR(600);
254 digit->SetIndexInList(idigit);
255 digit->SetType(AliEMCALDigit::kHG);
256 digit->SetAmplitude(0.1);
b0e354fe 257 }
06ca320f 258
5133b922 259 } else if (fClusterizeFastORs) { // Fill digits from FastORs
6265e793 260
261 AliEMCALGeometry *fGeom = AliEMCALGeometry::GetInstance(fGeomName);
06ca320f 262
6265e793 263 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
264 if (!esd){
265 AliError("Cannot get the ESD event");
266 return;
267 }
268
269 AliESDCaloTrigger *triggers = esd->GetCaloTrigger("EMCAL");
270
271 if (!triggers || !(triggers->GetEntries() > 0))
272 return;
273
274 Int_t idigit = 0;
275 triggers->Reset();
276
5133b922 277 while ((triggers->Next())) {
6265e793 278 Float_t triggerAmplitude = 0;
279 triggers->GetAmplitude(triggerAmplitude);
280 if (triggerAmplitude <= 0)
281 continue;
282
283 Int_t triggerTime = 0;
284 Int_t ntimes = 0;
285 triggers->GetNL0Times(ntimes);
5133b922 286 if (ntimes > 0) {
6265e793 287 Int_t trgtimes[25];
288 triggers->GetL0Times(trgtimes);
289 triggerTime = trgtimes[0];
290 }
291
292 Int_t triggerCol = 0, triggerRow = 0;
293 triggers->GetPosition(triggerCol, triggerRow);
294
295 Int_t find = -1;
296 fGeom->GetAbsFastORIndexFromPositionInEMCAL(triggerCol, triggerRow, find);
297
298 if (find<0)
299 continue;
300
301 Int_t cidx[4] = {-1};
302 Bool_t ret = fGeom->GetCellIndexFromFastORIndex(find, cidx);
303
304 if (!ret)
305 continue;
306
5133b922 307 for (Int_t idxpos = 0; idxpos < 4; idxpos++) {
6265e793 308 Int_t triggerNumber = cidx[idxpos];
309 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
310 digit->SetId(triggerNumber);
311 digit->SetTime(triggerTime);
312 digit->SetTimeR(triggerTime);
313 digit->SetIndexInList(idigit);
314 digit->SetType(AliEMCALDigit::kHG);
315 digit->SetAmplitude(triggerAmplitude);
316 idigit++;
317 }
318 }
06ca320f 319
320 } else { // Fill digits from cells.
7a7d5a64 321
7a7d5a64 322 AliVCaloCells *cells = InputEvent()->GetEMCALCells();
55a8e3e4 323 Double_t avgE = 0; // for background subtraction
324 const Int_t ncells = cells->GetNumberOfCells();
7a7d5a64 325 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) {
326 Double_t cellAmplitude=0, cellTime=0;
327 Short_t cellNumber=0;
328 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
329 break;
330 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
331 digit->SetId(cellNumber);
332 digit->SetTime(cellTime);
333 digit->SetTimeR(cellTime);
334 digit->SetIndexInList(idigit);
335 digit->SetType(AliEMCALDigit::kHG);
336 if (fRecalibOnly||fSubBackground) {
337 Float_t energy = cellAmplitude;
55a8e3e4 338 Float_t time = cellTime;
7a7d5a64 339 fClusterizer->Calibrate(energy,time,cellNumber);
95f69c66 340 digit->SetAmplitude(energy);
7a7d5a64 341 avgE += energy;
342 } else {
343 digit->SetAmplitude(cellAmplitude);
95f69c66 344 }
7a7d5a64 345 idigit++;
b0e354fe 346 }
7a7d5a64 347
55a8e3e4 348 fDigitsArr->Sort();
349
7a7d5a64 350 if (fSubBackground) {
351 avgE /= AliEMCALGeometry::GetInstance(fGeomName)->GetNumberOfSuperModules()*48*24;
352 Int_t ndigis = fDigitsArr->GetEntries();
353 for (Int_t i = 0; i < ndigis; ++i) {
354 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(i));
355 Double_t energy = digit->GetAmplitude() - avgE;
356 if (energy<=0.001) {
357 digit->SetAmplitude(0);
358 } else {
359 digit->SetAmplitude(energy);
360 }
361 }
362 }
06ca320f 363 }
2f7259cf 364}
365
366//________________________________________________________________________________________
95f69c66 367void AliAnalysisTaskEMCALClusterizeFast::RecPoints2Clusters(TClonesArray *clus)
4cf9204b 368{
369 // Cluster energy, global position, cells and their amplitude fractions are restored.
370
95f69c66 371 Bool_t esdobjects = 0;
372 if (strcmp(clus->GetClass()->GetName(),"AliESDCaloCluster")==0)
373 esdobjects = 1;
374
b98487bc 375 AliVCaloCells *cells = InputEvent()->GetEMCALCells();
376 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance(fGeomName);
377
e93ec1f7 378 AliDebug(1, Form("total no of clusters %d", fClusterArr->GetEntriesFast()));
379
55a8e3e4 380 const Int_t Ncls = fClusterArr->GetEntriesFast();
4cf9204b 381 for(Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i) {
382 AliEMCALRecPoint *recpoint = static_cast<AliEMCALRecPoint*>(fClusterArr->At(i));
383 Int_t ncells_true = 0;
384 const Int_t ncells = recpoint->GetMultiplicity();
385 UShort_t absIds[ncells];
386 Double32_t ratios[ncells];
387 Int_t *dlist = recpoint->GetDigitsList();
388 Float_t *elist = recpoint->GetEnergiesList();
389 for (Int_t c = 0; c < ncells; ++c) {
390 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(dlist[c]));
391 absIds[ncells_true] = digit->GetId();
392 ratios[ncells_true] = elist[c]/digit->GetAmplitude();
84ccad86 393 ++ncells_true;
4cf9204b 394 }
395
396 if (ncells_true < 1) {
397 AliWarning("Skipping cluster with no cells");
398 continue;
399 }
400
401 // calculate new cluster position
402 TVector3 gpos;
4cf9204b 403 recpoint->GetGlobalPosition(gpos);
84ccad86 404 Float_t g[3];
4cf9204b 405 gpos.GetXYZ(g);
406
e93ec1f7 407 AliDebug(1, Form("energy %f", recpoint->GetEnergy()));
408
95f69c66 409 AliVCluster *c = static_cast<AliVCluster*>(clus->New(nout++));
4cf9204b 410 c->SetType(AliVCluster::kEMCALClusterv1);
411 c->SetE(recpoint->GetEnergy());
412 c->SetPosition(g);
413 c->SetNCells(ncells_true);
4cf9204b 414 c->SetDispersion(recpoint->GetDispersion());
84ccad86 415 c->SetEmcCpvDistance(-1); //not yet implemented
4cf9204b 416 c->SetChi2(-1); //not yet implemented
417 c->SetTOF(recpoint->GetTime()) ; //time-of-flight
418 c->SetNExMax(recpoint->GetNExMax()); //number of local maxima
419 Float_t elipAxis[2];
420 recpoint->GetElipsAxis(elipAxis);
e93ec1f7 421 c->SetM02(elipAxis[0]*elipAxis[0]);
422 c->SetM20(elipAxis[1]*elipAxis[1]);
423 if (fPedestalData) {
b98487bc 424 c->SetDistanceToBadChannel(recpoint->GetDistanceToBadTower());
e93ec1f7 425 }
426 else {
427 if (fRecoUtils && fRecoUtils->IsBadChannelsRemovalSwitchedOn()) {
428 fRecoUtils->RecalculateClusterDistanceToBadChannel(geom, cells, c);
429 }
b98487bc 430 }
e93ec1f7 431
95f69c66 432 if (esdobjects) {
433 AliESDCaloCluster *cesd = static_cast<AliESDCaloCluster*>(c);
434 cesd->SetCellsAbsId(absIds);
435 cesd->SetCellsAmplitudeFraction(ratios);
06ca320f 436 cesd->SetID(recpoint->GetUniqueID());
95f69c66 437 } else {
438 AliAODCaloCluster *caod = static_cast<AliAODCaloCluster*>(c);
439 caod->SetCellsAbsId(absIds);
440 caod->SetCellsAmplitudeFraction(ratios);
441 }
84ccad86 442 }
443
444 AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(InputEvent());
445 if (!esdevent)
446 return;
447 if (!fRecoUtils)
448 return;
449
95f69c66 450 AliAnalysisManager::GetAnalysisManager()->LoadBranch("Tracks");
84ccad86 451 fRecoUtils->FindMatches(esdevent,clus);
452
95f69c66 453 if (!esdobjects) {
55a8e3e4 454 const Int_t Nclus = clus->GetEntries();
95f69c66 455 for(Int_t i=0; i < Nclus; ++i) {
456 AliAODCaloCluster *c = static_cast<AliAODCaloCluster*>(clus->At(i));
457 Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
06ca320f 458 if (trackIndex >= 0) {
95f69c66 459 Float_t dR, dZ;
460 fRecoUtils->GetMatchedResiduals(i,dR, dZ);
e93ec1f7 461 c->AddTrackMatched(0x0); //esdevent->GetTrack(trackIndex));
95f69c66 462 c->SetTrackDistance(dR,dZ); // not implemented
463 c->SetEmcCpvDistance(dR);
464 c->SetChi2(dZ);
06ca320f 465 if (DebugLevel() > 1)
95f69c66 466 AliInfo(Form("Matched Track index %d to new cluster %d\n",trackIndex,i));
467 }
2f7259cf 468 }
95f69c66 469 } else {
55a8e3e4 470 const Int_t Nclus = clus->GetEntries();
84ccad86 471 for(Int_t i=0; i < Nclus; ++i) {
472 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->At(i));
2f7259cf 473 Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
06ca320f 474 if (trackIndex >= 0) {
84ccad86 475 Float_t dR, dZ;
476 fRecoUtils->GetMatchedResiduals(i,dR, dZ);
477 c->SetTrackDistance(dR,dZ);
478 c->SetEmcCpvDistance(dR); //to be consistent with AODs
479 c->SetChi2(dZ); //to be consistent with AODs
4cf9204b 480 TArrayI tm(1,&trackIndex);
481 c->AddTracksMatched(tm);
06ca320f 482 if (DebugLevel() > 1)
2f7259cf 483 AliInfo(Form("Matched Track index %d to new cluster %d\n",trackIndex,i));
484 }
485 }
486 }
487}
488
95f69c66 489//________________________________________________________________________
490void AliAnalysisTaskEMCALClusterizeFast::UpdateCells()
491{
492 // Update cells in case re-calibration was done.
493
494 if (!fCalibData&&!fSubBackground)
495 return;
496
497 AliVCaloCells *cells = InputEvent()->GetEMCALCells();
55a8e3e4 498 const Int_t ncells = cells->GetNumberOfCells();
499 const Int_t ndigis = fDigitsArr->GetEntries();
95f69c66 500 if (ncells!=ndigis) {
501 cells->DeleteContainer();
502 cells->CreateContainer(ndigis);
503 }
504 for (Int_t idigit = 0; idigit < ndigis; ++idigit) {
505 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(idigit));
506 Double_t cellAmplitude = digit->GetCalibAmp();
55a8e3e4 507 Short_t cellNumber = digit->GetId();
508 Double_t cellTime = digit->GetTime();
95f69c66 509 cells->SetCell(idigit, cellNumber, cellAmplitude, cellTime);
510 }
511}
512
513//________________________________________________________________________
514void AliAnalysisTaskEMCALClusterizeFast::UpdateClusters()
515{
516 // Update cells in case re-calibration was done.
7a7d5a64 517
95f69c66 518 if (!fAttachClusters)
519 return;
7a7d5a64 520
06ca320f 521 TClonesArray *clus = 0;
7a7d5a64 522
e50a444f 523 if (fOverwrite) {
7a7d5a64 524 clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("caloClusters"));
525 if (!clus)
526 clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("CaloClusters"));
06ca320f 527 if (!clus)
7a7d5a64 528 return;
529
55a8e3e4 530 const Int_t nents = clus->GetEntries();
7a7d5a64 531 for (Int_t i=0;i<nents;++i) {
532 AliVCluster *c = static_cast<AliVCluster*>(clus->At(i));
533 if (!c)
534 continue;
535 if (c->IsEMCAL())
536 delete clus->RemoveAt(i);
537 }
06ca320f 538 } else {
7a7d5a64 539 clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fNewClusterArrayName));
06ca320f 540 if (!clus) {
7a7d5a64 541 clus = new TClonesArray("AliESDCaloCluster");
542 clus->SetName(fNewClusterArrayName);
543 InputEvent()->AddObject(clus);
06ca320f 544 } else {
0a7eb283 545 clus->Delete();
7a7d5a64 546 }
547 }
548
95f69c66 549 RecPoints2Clusters(clus);
550}
551
2f7259cf 552//________________________________________________________________________________________
553void AliAnalysisTaskEMCALClusterizeFast::Init()
554{
555 //Select clusterization/unfolding algorithm and set all the needed parameters
01bc1ce8 556
2f7259cf 557 AliVEvent * event = InputEvent();
558 if (!event) {
559 AliWarning("Event not available!!!");
560 return;
561 }
562
563 if (event->GetRunNumber()==fRun)
564 return;
565 fRun = event->GetRunNumber();
566
567 if (fJustUnfold){
568 // init the unfolding afterburner
569 delete fUnfolder;
1759f743 570 fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut(),fRecParam->GetMinECut());
2f7259cf 571 return;
572 }
573
2f7259cf 574 AliEMCALGeometry *geometry = AliEMCALGeometry::GetInstance(fGeomName);
575 if (!geometry) {
576 AliFatal("Geometry not available!!!");
577 return;
578 }
579
580 if (!fGeomMatrixSet) {
581 if (fLoadGeomMatrices) {
e51bc3f5 582 for(Int_t mod=0; mod < geometry->GetNumberOfSuperModules(); ++mod) {
06ca320f 583 if (fGeomMatrix[mod]){
584 if (DebugLevel() > 2)
2f7259cf 585 fGeomMatrix[mod]->Print();
586 geometry->SetMisalMatrix(fGeomMatrix[mod],mod);
587 }
588 }
29b496d5 589 } else { // get matrix from file (work around bug in aliroot)
2f7259cf 590 for(Int_t mod=0; mod < geometry->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
29b496d5 591 const TGeoHMatrix *gm = 0;
441c4d3c 592 AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(event);
29b496d5 593 if (esdevent) {
594 gm = esdevent->GetEMCALMatrix(mod);
595 } else {
596 AliAODHeader *aodheader = dynamic_cast<AliAODHeader*>(event->GetHeader());
597 if (aodheader) {
598 gm = aodheader->GetEMCALMatrix(mod);
599 }
600 }
601 if (gm) {
06ca320f 602 if (DebugLevel() > 2)
29b496d5 603 gm->Print();
604 geometry->SetMisalMatrix(gm,mod);
2f7259cf 605 }
606 }
607 }
608 fGeomMatrixSet=kTRUE;
609 }
610
611 // setup digit array if needed
612 if (!fDigitsArr) {
613 fDigitsArr = new TClonesArray("AliEMCALDigit", 1000);
614 fDigitsArr->SetOwner(1);
615 }
616
617 // then setup clusterizer
618 delete fClusterizer;
619 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
620 fClusterizer = new AliEMCALClusterizerv1(geometry);
06ca320f 621 else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN) {
2f7259cf 622 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(geometry);
3c56da8f 623 clusterizer->SetNRowDiff(fRecParam->GetNRowDiff());
624 clusterizer->SetNColDiff(fRecParam->GetNColDiff());
625 fClusterizer = clusterizer;
06ca320f 626 } else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
3c56da8f 627 fClusterizer = new AliEMCALClusterizerv2(geometry);
06ca320f 628 else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerFW){
7a7d5a64 629 AliEMCALClusterizerFixedWindow *clusterizer = new AliEMCALClusterizerFixedWindow(geometry);
0fda97fe 630 clusterizer->SetNphi(fNPhi);
631 clusterizer->SetNeta(fNEta);
632 clusterizer->SetShiftPhi(fShiftPhi);
633 clusterizer->SetShiftEta(fShiftEta);
3c56da8f 634 clusterizer->SetTRUshift(fTRUShift);
7a7d5a64 635 fClusterizer = clusterizer;
636 }
637 else{
2f7259cf 638 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
639 }
640 fClusterizer->InitParameters(fRecParam);
01bc1ce8 641
642 if ((!fCalibData&&fLoadCalib) || (!fPedestalData&&fLoadPed)) {
643 AliCDBManager *cdb = AliCDBManager::Instance();
644 if (!cdb->IsDefaultStorageSet() && !fOCDBpath.IsNull())
645 cdb->SetDefaultStorage(fOCDBpath);
646 if (fRun!=cdb->GetRun())
647 cdb->SetRun(fRun);
648 }
349bf69e 649 if (!fCalibData&&fLoadCalib&&fRun>0) {
2f7259cf 650 AliCDBEntry *entry = static_cast<AliCDBEntry*>(AliCDBManager::Instance()->Get("EMCAL/Calib/Data"));
651 if (entry)
652 fCalibData = static_cast<AliEMCALCalibData*>(entry->GetObject());
653 if (!fCalibData)
654 AliFatal("Calibration parameters not found in CDB!");
655 }
349bf69e 656 if (!fPedestalData&&fLoadPed&&fRun>0) {
2f7259cf 657 AliCDBEntry *entry = static_cast<AliCDBEntry*>(AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals"));
658 if (entry)
659 fPedestalData = static_cast<AliCaloCalibPedestal*>(entry->GetObject());
660 }
10d33986 661 if (fCalibData) {
662 fClusterizer->SetInputCalibrated(kFALSE);
663 fClusterizer->SetCalibrationParameters(fCalibData);
10d33986 664 } else {
665 fClusterizer->SetInputCalibrated(kTRUE);
666 }
e93ec1f7 667 fClusterizer->SetCaloCalibPedestal(fPedestalData);
10d33986 668 fClusterizer->SetJustClusters(kTRUE);
2f7259cf 669 fClusterizer->SetDigitsArr(fDigitsArr);
670 fClusterizer->SetOutput(0);
671 fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());
672}