]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGGA/EMCALTasks/AliAnalysisTaskEMCALClusterizeFast.cxx
updates from Salvatore
[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
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),
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
2f7259cf 100//________________________________________________________________________
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
2f7259cf 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);
6265e793 281
35799643 282 AliVCaloTrigger *triggers = InputEvent()->GetCaloTrigger("EMCAL");
6265e793 283
284 if (!triggers || !(triggers->GetEntries() > 0))
285 return;
286
287 Int_t idigit = 0;
288 triggers->Reset();
289
5133b922 290 while ((triggers->Next())) {
6265e793 291 Float_t triggerAmplitude = 0;
292 triggers->GetAmplitude(triggerAmplitude);
293 if (triggerAmplitude <= 0)
294 continue;
295
296 Int_t triggerTime = 0;
297 Int_t ntimes = 0;
298 triggers->GetNL0Times(ntimes);
be268574 299 if (!(ntimes > 0) && fCutL0Times)
300 continue;
301
302 Int_t trgtimes[25];
303 triggers->GetL0Times(trgtimes);
304 triggerTime = trgtimes[0];
305
6265e793 306 Int_t triggerCol = 0, triggerRow = 0;
307 triggers->GetPosition(triggerCol, triggerRow);
308
309 Int_t find = -1;
310 fGeom->GetAbsFastORIndexFromPositionInEMCAL(triggerCol, triggerRow, find);
311
312 if (find<0)
313 continue;
314
315 Int_t cidx[4] = {-1};
316 Bool_t ret = fGeom->GetCellIndexFromFastORIndex(find, cidx);
317
318 if (!ret)
319 continue;
320
5133b922 321 for (Int_t idxpos = 0; idxpos < 4; idxpos++) {
6265e793 322 Int_t triggerNumber = cidx[idxpos];
323 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
324 digit->SetId(triggerNumber);
325 digit->SetTime(triggerTime);
326 digit->SetTimeR(triggerTime);
327 digit->SetIndexInList(idigit);
328 digit->SetType(AliEMCALDigit::kHG);
329 digit->SetAmplitude(triggerAmplitude);
330 idigit++;
331 }
332 }
06ca320f 333
334 } else { // Fill digits from cells.
7a7d5a64 335
7a7d5a64 336 AliVCaloCells *cells = InputEvent()->GetEMCALCells();
55a8e3e4 337 Double_t avgE = 0; // for background subtraction
338 const Int_t ncells = cells->GetNumberOfCells();
7a7d5a64 339 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) {
77e93dc2 340 Double_t cellAmplitude=0, cellTime=0, cellEFrac = 0;
341 Short_t cellNumber=0, cellMCLabel=-1;
342 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime, cellMCLabel, cellEFrac) != kTRUE)
7a7d5a64 343 break;
344 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
345 digit->SetId(cellNumber);
346 digit->SetTime(cellTime);
347 digit->SetTimeR(cellTime);
348 digit->SetIndexInList(idigit);
349 digit->SetType(AliEMCALDigit::kHG);
350 if (fRecalibOnly||fSubBackground) {
351 Float_t energy = cellAmplitude;
55a8e3e4 352 Float_t time = cellTime;
7a7d5a64 353 fClusterizer->Calibrate(energy,time,cellNumber);
95f69c66 354 digit->SetAmplitude(energy);
7a7d5a64 355 avgE += energy;
356 } else {
357 digit->SetAmplitude(cellAmplitude);
95f69c66 358 }
7a7d5a64 359 idigit++;
b0e354fe 360 }
7a7d5a64 361
55a8e3e4 362 fDigitsArr->Sort();
363
7a7d5a64 364 if (fSubBackground) {
365 avgE /= AliEMCALGeometry::GetInstance(fGeomName)->GetNumberOfSuperModules()*48*24;
366 Int_t ndigis = fDigitsArr->GetEntries();
367 for (Int_t i = 0; i < ndigis; ++i) {
368 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(i));
369 Double_t energy = digit->GetAmplitude() - avgE;
370 if (energy<=0.001) {
371 digit->SetAmplitude(0);
372 } else {
373 digit->SetAmplitude(energy);
374 }
375 }
376 }
06ca320f 377 }
2f7259cf 378}
379
380//________________________________________________________________________________________
95f69c66 381void AliAnalysisTaskEMCALClusterizeFast::RecPoints2Clusters(TClonesArray *clus)
4cf9204b 382{
383 // Cluster energy, global position, cells and their amplitude fractions are restored.
384
b98487bc 385 AliVCaloCells *cells = InputEvent()->GetEMCALCells();
386 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance(fGeomName);
e278a6e9 387 AliVEvent *event = InputEvent();
388 if (!event) {
389 AliError("Cannot get the event");
31f5b395 390 return;
391 }
0408f54f 392
393 // tracks array for track/cluster matching
394 TClonesArray *tarr = 0;
395 if (!fTrackName.IsNull()) {
e278a6e9 396 tarr = dynamic_cast<TClonesArray*>(event->FindListObject(fTrackName));
0408f54f 397 if (!tarr) {
398 AliError(Form("Cannot get tracks named %s", fTrackName.Data()));
399 }
400 }
e93ec1f7 401
eb33b7f8 402 const Int_t Ncls = fClusterArr->GetEntries();
0408f54f 403 AliDebug(1, Form("total no of clusters %d", Ncls));
4cf9204b 404 for(Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i) {
405 AliEMCALRecPoint *recpoint = static_cast<AliEMCALRecPoint*>(fClusterArr->At(i));
406 Int_t ncells_true = 0;
407 const Int_t ncells = recpoint->GetMultiplicity();
408 UShort_t absIds[ncells];
409 Double32_t ratios[ncells];
410 Int_t *dlist = recpoint->GetDigitsList();
411 Float_t *elist = recpoint->GetEnergiesList();
412 for (Int_t c = 0; c < ncells; ++c) {
413 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(dlist[c]));
414 absIds[ncells_true] = digit->GetId();
415 ratios[ncells_true] = elist[c]/digit->GetAmplitude();
84ccad86 416 ++ncells_true;
4cf9204b 417 }
418
419 if (ncells_true < 1) {
420 AliWarning("Skipping cluster with no cells");
421 continue;
422 }
423
424 // calculate new cluster position
425 TVector3 gpos;
4cf9204b 426 recpoint->GetGlobalPosition(gpos);
84ccad86 427 Float_t g[3];
4cf9204b 428 gpos.GetXYZ(g);
429
e93ec1f7 430 AliDebug(1, Form("energy %f", recpoint->GetEnergy()));
431
95f69c66 432 AliVCluster *c = static_cast<AliVCluster*>(clus->New(nout++));
4cf9204b 433 c->SetType(AliVCluster::kEMCALClusterv1);
434 c->SetE(recpoint->GetEnergy());
435 c->SetPosition(g);
436 c->SetNCells(ncells_true);
a55e4f1d 437 c->SetCellsAbsId(absIds);
438 c->SetCellsAmplitudeFraction(ratios);
439 c->SetID(recpoint->GetUniqueID());
4cf9204b 440 c->SetDispersion(recpoint->GetDispersion());
0408f54f 441 c->SetEmcCpvDistance(-1);
442 c->SetChi2(-1);
4cf9204b 443 c->SetTOF(recpoint->GetTime()) ; //time-of-flight
444 c->SetNExMax(recpoint->GetNExMax()); //number of local maxima
445 Float_t elipAxis[2];
446 recpoint->GetElipsAxis(elipAxis);
e93ec1f7 447 c->SetM02(elipAxis[0]*elipAxis[0]);
448 c->SetM20(elipAxis[1]*elipAxis[1]);
449 if (fPedestalData) {
b98487bc 450 c->SetDistanceToBadChannel(recpoint->GetDistanceToBadTower());
eb33b7f8 451 } else {
e93ec1f7 452 if (fRecoUtils && fRecoUtils->IsBadChannelsRemovalSwitchedOn()) {
453 fRecoUtils->RecalculateClusterDistanceToBadChannel(geom, cells, c);
454 }
b98487bc 455 }
84ccad86 456
0408f54f 457 if (tarr) {
458 Double_t dEtaMin = 1e9;
459 Double_t dPhiMin = 1e9;
460 Int_t imin = -1;
461 Double_t ceta = gpos.Eta();
462 Double_t cphi = gpos.Phi();
463 const Int_t ntrks = tarr->GetEntries();
464 for(Int_t t = 0; t<ntrks; ++t) {
465 AliVTrack *track = static_cast<AliVTrack*>(tarr->At(t));
466 if (!track)
467 continue;
468 const AliExternalTrackParam *outp = track->GetOuterParam();
469 if (!outp)
470 continue;
471 Double_t trkPos[3] = {0.,0.,0.};
472 if (!outp->GetXYZ(trkPos))
473 continue;
474 TVector3 vec(trkPos[0],trkPos[1],trkPos[2]);
475 Double_t veta = vec.Eta();
476 Double_t vphi = vec.Phi();
477 if(vphi<0)
478 vphi += 2*TMath::Pi();
479 if (TMath::Abs(veta)>0.75 || (vphi<70*TMath::DegToRad()) || (vphi>190*TMath::DegToRad()))
480 continue;
481 Double_t dR = vec.DeltaR(gpos);
482 if(dR > 25)
483 continue;
484 Float_t tmpEta=0, tmpPhi=0;
485 if (0) {
486 AliExternalTrackParam trkParTemp(*outp); // retrieve the starting point every time before the extrapolation
487 Bool_t ret = fRecoUtils->ExtrapolateTrackToCluster(&trkParTemp, c, fRecoUtils->GetMass(), fRecoUtils->GetStep(), tmpEta, tmpPhi);
488 if (!ret)
489 continue;
490 } else {
491 tmpEta = ceta - veta;
492 tmpPhi = cphi - vphi;
493 }
494 if (TMath::Abs(tmpEta)<TMath::Abs(dEtaMin) && TMath::Abs(tmpPhi)<TMath::Abs(dPhiMin)) {
495 dEtaMin = tmpEta;
496 dPhiMin = tmpPhi;
497 imin = t;
498 }
95f69c66 499 }
eb33b7f8 500 c->SetEmcCpvDistance(imin);
501 c->SetTrackDistance(dPhiMin, dEtaMin);
2f7259cf 502 }
503 }
504}
505
95f69c66 506//________________________________________________________________________
507void AliAnalysisTaskEMCALClusterizeFast::UpdateCells()
508{
509 // Update cells in case re-calibration was done.
510
511 if (!fCalibData&&!fSubBackground)
512 return;
513
514 AliVCaloCells *cells = InputEvent()->GetEMCALCells();
55a8e3e4 515 const Int_t ncells = cells->GetNumberOfCells();
516 const Int_t ndigis = fDigitsArr->GetEntries();
95f69c66 517 if (ncells!=ndigis) {
518 cells->DeleteContainer();
519 cells->CreateContainer(ndigis);
520 }
521 for (Int_t idigit = 0; idigit < ndigis; ++idigit) {
522 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(idigit));
523 Double_t cellAmplitude = digit->GetCalibAmp();
55a8e3e4 524 Short_t cellNumber = digit->GetId();
525 Double_t cellTime = digit->GetTime();
95f69c66 526 cells->SetCell(idigit, cellNumber, cellAmplitude, cellTime);
527 }
528}
529
530//________________________________________________________________________
531void AliAnalysisTaskEMCALClusterizeFast::UpdateClusters()
532{
533 // Update cells in case re-calibration was done.
7a7d5a64 534
95f69c66 535 if (!fAttachClusters)
536 return;
7a7d5a64 537
06ca320f 538 TClonesArray *clus = 0;
7a7d5a64 539
e50a444f 540 if (fOverwrite) {
7a7d5a64 541 clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("caloClusters"));
542 if (!clus)
543 clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("CaloClusters"));
06ca320f 544 if (!clus)
7a7d5a64 545 return;
546
55a8e3e4 547 const Int_t nents = clus->GetEntries();
7a7d5a64 548 for (Int_t i=0;i<nents;++i) {
549 AliVCluster *c = static_cast<AliVCluster*>(clus->At(i));
550 if (!c)
551 continue;
552 if (c->IsEMCAL())
553 delete clus->RemoveAt(i);
554 }
06ca320f 555 } else {
7a7d5a64 556 clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fNewClusterArrayName));
06ca320f 557 if (!clus) {
7a7d5a64 558 clus = new TClonesArray("AliESDCaloCluster");
559 clus->SetName(fNewClusterArrayName);
560 InputEvent()->AddObject(clus);
06ca320f 561 } else {
0a7eb283 562 clus->Delete();
7a7d5a64 563 }
564 }
565
95f69c66 566 RecPoints2Clusters(clus);
567}
568
2f7259cf 569//________________________________________________________________________________________
570void AliAnalysisTaskEMCALClusterizeFast::Init()
571{
572 //Select clusterization/unfolding algorithm and set all the needed parameters
01bc1ce8 573
2f7259cf 574 AliVEvent * event = InputEvent();
575 if (!event) {
576 AliWarning("Event not available!!!");
577 return;
578 }
579
580 if (event->GetRunNumber()==fRun)
581 return;
582 fRun = event->GetRunNumber();
583
584 if (fJustUnfold){
585 // init the unfolding afterburner
586 delete fUnfolder;
1759f743 587 fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut(),fRecParam->GetMinECut());
2f7259cf 588 return;
589 }
590
2f7259cf 591 AliEMCALGeometry *geometry = AliEMCALGeometry::GetInstance(fGeomName);
592 if (!geometry) {
593 AliFatal("Geometry not available!!!");
594 return;
595 }
596
597 if (!fGeomMatrixSet) {
598 if (fLoadGeomMatrices) {
e51bc3f5 599 for(Int_t mod=0; mod < geometry->GetNumberOfSuperModules(); ++mod) {
06ca320f 600 if (fGeomMatrix[mod]){
601 if (DebugLevel() > 2)
2f7259cf 602 fGeomMatrix[mod]->Print();
603 geometry->SetMisalMatrix(fGeomMatrix[mod],mod);
604 }
605 }
29b496d5 606 } else { // get matrix from file (work around bug in aliroot)
2f7259cf 607 for(Int_t mod=0; mod < geometry->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
29b496d5 608 const TGeoHMatrix *gm = 0;
441c4d3c 609 AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(event);
29b496d5 610 if (esdevent) {
611 gm = esdevent->GetEMCALMatrix(mod);
612 } else {
613 AliAODHeader *aodheader = dynamic_cast<AliAODHeader*>(event->GetHeader());
614 if (aodheader) {
615 gm = aodheader->GetEMCALMatrix(mod);
616 }
617 }
618 if (gm) {
06ca320f 619 if (DebugLevel() > 2)
29b496d5 620 gm->Print();
621 geometry->SetMisalMatrix(gm,mod);
2f7259cf 622 }
623 }
624 }
625 fGeomMatrixSet=kTRUE;
626 }
627
628 // setup digit array if needed
629 if (!fDigitsArr) {
630 fDigitsArr = new TClonesArray("AliEMCALDigit", 1000);
631 fDigitsArr->SetOwner(1);
632 }
633
634 // then setup clusterizer
635 delete fClusterizer;
636 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
637 fClusterizer = new AliEMCALClusterizerv1(geometry);
06ca320f 638 else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN) {
2f7259cf 639 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(geometry);
3c56da8f 640 clusterizer->SetNRowDiff(fRecParam->GetNRowDiff());
641 clusterizer->SetNColDiff(fRecParam->GetNColDiff());
642 fClusterizer = clusterizer;
06ca320f 643 } else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
3c56da8f 644 fClusterizer = new AliEMCALClusterizerv2(geometry);
06ca320f 645 else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerFW){
7a7d5a64 646 AliEMCALClusterizerFixedWindow *clusterizer = new AliEMCALClusterizerFixedWindow(geometry);
0fda97fe 647 clusterizer->SetNphi(fNPhi);
648 clusterizer->SetNeta(fNEta);
649 clusterizer->SetShiftPhi(fShiftPhi);
650 clusterizer->SetShiftEta(fShiftEta);
3c56da8f 651 clusterizer->SetTRUshift(fTRUShift);
7a7d5a64 652 fClusterizer = clusterizer;
653 }
654 else{
2f7259cf 655 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
656 }
657 fClusterizer->InitParameters(fRecParam);
01bc1ce8 658
659 if ((!fCalibData&&fLoadCalib) || (!fPedestalData&&fLoadPed)) {
660 AliCDBManager *cdb = AliCDBManager::Instance();
661 if (!cdb->IsDefaultStorageSet() && !fOCDBpath.IsNull())
662 cdb->SetDefaultStorage(fOCDBpath);
663 if (fRun!=cdb->GetRun())
664 cdb->SetRun(fRun);
665 }
349bf69e 666 if (!fCalibData&&fLoadCalib&&fRun>0) {
2f7259cf 667 AliCDBEntry *entry = static_cast<AliCDBEntry*>(AliCDBManager::Instance()->Get("EMCAL/Calib/Data"));
668 if (entry)
669 fCalibData = static_cast<AliEMCALCalibData*>(entry->GetObject());
670 if (!fCalibData)
671 AliFatal("Calibration parameters not found in CDB!");
672 }
349bf69e 673 if (!fPedestalData&&fLoadPed&&fRun>0) {
2f7259cf 674 AliCDBEntry *entry = static_cast<AliCDBEntry*>(AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals"));
675 if (entry)
676 fPedestalData = static_cast<AliCaloCalibPedestal*>(entry->GetObject());
677 }
10d33986 678 if (fCalibData) {
679 fClusterizer->SetInputCalibrated(kFALSE);
680 fClusterizer->SetCalibrationParameters(fCalibData);
10d33986 681 } else {
682 fClusterizer->SetInputCalibrated(kTRUE);
683 }
e93ec1f7 684 fClusterizer->SetCaloCalibPedestal(fPedestalData);
10d33986 685 fClusterizer->SetJustClusters(kTRUE);
2f7259cf 686 fClusterizer->SetDigitsArr(fDigitsArr);
687 fClusterizer->SetOutput(0);
688 fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());
689}