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