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