Option to write only the heavy flavor chain.
[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 }
179c3e32 192
2ecad9b5 193 if (esdevent) {
179c3e32 194 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
195 Bool_t mcmode = 0;
196 if (am->GetMCtruthEventHandler())
197 mcmode = 1;
198 if (!mcmode) {
179c3e32 199 if (offtrigger & AliVEvent::kFastOnly) {
200 AliWarning(Form("EMCAL not in fast only partition"));
201 return;
202 }
203 }
6b7ed7bd 204 }
2f7259cf 205
206 Init();
207
208 if (fJustUnfold) {
209 AliWarning("Unfolding not implemented");
84ccad86 210 return;
211 }
212
95f69c66 213 FillDigitsArray();
84ccad86 214
95f69c66 215 if (fRecalibOnly) {
216 UpdateCells();
217 return; // not requested to run clusterizer
84ccad86 218 }
7099ec08 219
95f69c66 220 Clusterize();
221 UpdateCells();
222 UpdateClusters();
2431b20f 223
95f69c66 224 if (fOutputAODBranch)
225 RecPoints2Clusters(fOutputAODBranch);
2431b20f 226}
227
228//________________________________________________________________________
95f69c66 229void AliAnalysisTaskEMCALClusterizeFast::Clusterize()
2431b20f 230{
95f69c66 231 // Clusterize
7099ec08 232
95f69c66 233 if (fSubBackground) {
234 fClusterizer->SetInputCalibrated(kTRUE);
235 fClusterizer->SetCalibrationParameters(0);
2f7259cf 236 }
d3b5a5ec 237
95f69c66 238 fClusterizer->Digits2Clusters("");
239 if (fSubBackground) {
4889ed8b 240 if (fCalibData) {
241 fClusterizer->SetInputCalibrated(kFALSE);
242 fClusterizer->SetCalibrationParameters(fCalibData);
243 }
4cf9204b 244 }
4cf9204b 245}
246
247//________________________________________________________________________
95f69c66 248void AliAnalysisTaskEMCALClusterizeFast::FillDigitsArray()
2f7259cf 249{
6265e793 250 // Fill digits array
55a8e3e4 251
6265e793 252 fDigitsArr->Clear("C");
253
5133b922 254 if (fCreatePattern) { // Fill digits from a pattern
7a7d5a64 255 AliEMCALGeometry *fGeom = AliEMCALGeometry::GetInstance(fGeomName);
7a7d5a64 256 Int_t maxd = fGeom->GetNCells() / 4;
6265e793 257 for (Int_t idigit = 0; idigit < maxd; idigit++){
7a7d5a64 258 if (idigit % 24 == 12) idigit += 12;
259 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
260 digit->SetId(idigit * 4);
261 digit->SetTime(600);
262 digit->SetTimeR(600);
263 digit->SetIndexInList(idigit);
264 digit->SetType(AliEMCALDigit::kHG);
265 digit->SetAmplitude(0.1);
b0e354fe 266 }
06ca320f 267
5133b922 268 } else if (fClusterizeFastORs) { // Fill digits from FastORs
6265e793 269
270 AliEMCALGeometry *fGeom = AliEMCALGeometry::GetInstance(fGeomName);
06ca320f 271
6265e793 272 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
273 if (!esd){
274 AliError("Cannot get the ESD event");
275 return;
276 }
277
278 AliESDCaloTrigger *triggers = esd->GetCaloTrigger("EMCAL");
279
280 if (!triggers || !(triggers->GetEntries() > 0))
281 return;
282
283 Int_t idigit = 0;
284 triggers->Reset();
285
5133b922 286 while ((triggers->Next())) {
6265e793 287 Float_t triggerAmplitude = 0;
288 triggers->GetAmplitude(triggerAmplitude);
289 if (triggerAmplitude <= 0)
290 continue;
291
292 Int_t triggerTime = 0;
293 Int_t ntimes = 0;
294 triggers->GetNL0Times(ntimes);
5133b922 295 if (ntimes > 0) {
6265e793 296 Int_t trgtimes[25];
297 triggers->GetL0Times(trgtimes);
298 triggerTime = trgtimes[0];
299 }
300
301 Int_t triggerCol = 0, triggerRow = 0;
302 triggers->GetPosition(triggerCol, triggerRow);
303
304 Int_t find = -1;
305 fGeom->GetAbsFastORIndexFromPositionInEMCAL(triggerCol, triggerRow, find);
306
307 if (find<0)
308 continue;
309
310 Int_t cidx[4] = {-1};
311 Bool_t ret = fGeom->GetCellIndexFromFastORIndex(find, cidx);
312
313 if (!ret)
314 continue;
315
5133b922 316 for (Int_t idxpos = 0; idxpos < 4; idxpos++) {
6265e793 317 Int_t triggerNumber = cidx[idxpos];
318 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
319 digit->SetId(triggerNumber);
320 digit->SetTime(triggerTime);
321 digit->SetTimeR(triggerTime);
322 digit->SetIndexInList(idigit);
323 digit->SetType(AliEMCALDigit::kHG);
324 digit->SetAmplitude(triggerAmplitude);
325 idigit++;
326 }
327 }
06ca320f 328
329 } else { // Fill digits from cells.
7a7d5a64 330
7a7d5a64 331 AliVCaloCells *cells = InputEvent()->GetEMCALCells();
55a8e3e4 332 Double_t avgE = 0; // for background subtraction
333 const Int_t ncells = cells->GetNumberOfCells();
7a7d5a64 334 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) {
335 Double_t cellAmplitude=0, cellTime=0;
336 Short_t cellNumber=0;
337 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
338 break;
339 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
340 digit->SetId(cellNumber);
341 digit->SetTime(cellTime);
342 digit->SetTimeR(cellTime);
343 digit->SetIndexInList(idigit);
344 digit->SetType(AliEMCALDigit::kHG);
345 if (fRecalibOnly||fSubBackground) {
346 Float_t energy = cellAmplitude;
55a8e3e4 347 Float_t time = cellTime;
7a7d5a64 348 fClusterizer->Calibrate(energy,time,cellNumber);
95f69c66 349 digit->SetAmplitude(energy);
7a7d5a64 350 avgE += energy;
351 } else {
352 digit->SetAmplitude(cellAmplitude);
95f69c66 353 }
7a7d5a64 354 idigit++;
b0e354fe 355 }
7a7d5a64 356
55a8e3e4 357 fDigitsArr->Sort();
358
7a7d5a64 359 if (fSubBackground) {
360 avgE /= AliEMCALGeometry::GetInstance(fGeomName)->GetNumberOfSuperModules()*48*24;
361 Int_t ndigis = fDigitsArr->GetEntries();
362 for (Int_t i = 0; i < ndigis; ++i) {
363 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(i));
364 Double_t energy = digit->GetAmplitude() - avgE;
365 if (energy<=0.001) {
366 digit->SetAmplitude(0);
367 } else {
368 digit->SetAmplitude(energy);
369 }
370 }
371 }
06ca320f 372 }
2f7259cf 373}
374
375//________________________________________________________________________________________
95f69c66 376void AliAnalysisTaskEMCALClusterizeFast::RecPoints2Clusters(TClonesArray *clus)
4cf9204b 377{
378 // Cluster energy, global position, cells and their amplitude fractions are restored.
379
95f69c66 380 Bool_t esdobjects = 0;
381 if (strcmp(clus->GetClass()->GetName(),"AliESDCaloCluster")==0)
382 esdobjects = 1;
383
b98487bc 384 AliVCaloCells *cells = InputEvent()->GetEMCALCells();
385 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance(fGeomName);
386
e93ec1f7 387 AliDebug(1, Form("total no of clusters %d", fClusterArr->GetEntriesFast()));
388
55a8e3e4 389 const Int_t Ncls = fClusterArr->GetEntriesFast();
4cf9204b 390 for(Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i) {
391 AliEMCALRecPoint *recpoint = static_cast<AliEMCALRecPoint*>(fClusterArr->At(i));
392 Int_t ncells_true = 0;
393 const Int_t ncells = recpoint->GetMultiplicity();
394 UShort_t absIds[ncells];
395 Double32_t ratios[ncells];
396 Int_t *dlist = recpoint->GetDigitsList();
397 Float_t *elist = recpoint->GetEnergiesList();
398 for (Int_t c = 0; c < ncells; ++c) {
399 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(dlist[c]));
400 absIds[ncells_true] = digit->GetId();
401 ratios[ncells_true] = elist[c]/digit->GetAmplitude();
84ccad86 402 ++ncells_true;
4cf9204b 403 }
404
405 if (ncells_true < 1) {
406 AliWarning("Skipping cluster with no cells");
407 continue;
408 }
409
410 // calculate new cluster position
411 TVector3 gpos;
4cf9204b 412 recpoint->GetGlobalPosition(gpos);
84ccad86 413 Float_t g[3];
4cf9204b 414 gpos.GetXYZ(g);
415
e93ec1f7 416 AliDebug(1, Form("energy %f", recpoint->GetEnergy()));
417
95f69c66 418 AliVCluster *c = static_cast<AliVCluster*>(clus->New(nout++));
4cf9204b 419 c->SetType(AliVCluster::kEMCALClusterv1);
420 c->SetE(recpoint->GetEnergy());
421 c->SetPosition(g);
422 c->SetNCells(ncells_true);
4cf9204b 423 c->SetDispersion(recpoint->GetDispersion());
84ccad86 424 c->SetEmcCpvDistance(-1); //not yet implemented
4cf9204b 425 c->SetChi2(-1); //not yet implemented
426 c->SetTOF(recpoint->GetTime()) ; //time-of-flight
427 c->SetNExMax(recpoint->GetNExMax()); //number of local maxima
428 Float_t elipAxis[2];
429 recpoint->GetElipsAxis(elipAxis);
e93ec1f7 430 c->SetM02(elipAxis[0]*elipAxis[0]);
431 c->SetM20(elipAxis[1]*elipAxis[1]);
432 if (fPedestalData) {
b98487bc 433 c->SetDistanceToBadChannel(recpoint->GetDistanceToBadTower());
e93ec1f7 434 }
435 else {
436 if (fRecoUtils && fRecoUtils->IsBadChannelsRemovalSwitchedOn()) {
437 fRecoUtils->RecalculateClusterDistanceToBadChannel(geom, cells, c);
438 }
b98487bc 439 }
e93ec1f7 440
95f69c66 441 if (esdobjects) {
442 AliESDCaloCluster *cesd = static_cast<AliESDCaloCluster*>(c);
443 cesd->SetCellsAbsId(absIds);
444 cesd->SetCellsAmplitudeFraction(ratios);
06ca320f 445 cesd->SetID(recpoint->GetUniqueID());
95f69c66 446 } else {
447 AliAODCaloCluster *caod = static_cast<AliAODCaloCluster*>(c);
448 caod->SetCellsAbsId(absIds);
449 caod->SetCellsAmplitudeFraction(ratios);
450 }
84ccad86 451 }
452
453 AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(InputEvent());
454 if (!esdevent)
455 return;
456 if (!fRecoUtils)
457 return;
458
95f69c66 459 AliAnalysisManager::GetAnalysisManager()->LoadBranch("Tracks");
84ccad86 460 fRecoUtils->FindMatches(esdevent,clus);
461
95f69c66 462 if (!esdobjects) {
55a8e3e4 463 const Int_t Nclus = clus->GetEntries();
95f69c66 464 for(Int_t i=0; i < Nclus; ++i) {
465 AliAODCaloCluster *c = static_cast<AliAODCaloCluster*>(clus->At(i));
466 Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
06ca320f 467 if (trackIndex >= 0) {
95f69c66 468 Float_t dR, dZ;
469 fRecoUtils->GetMatchedResiduals(i,dR, dZ);
e93ec1f7 470 c->AddTrackMatched(0x0); //esdevent->GetTrack(trackIndex));
95f69c66 471 c->SetTrackDistance(dR,dZ); // not implemented
472 c->SetEmcCpvDistance(dR);
473 c->SetChi2(dZ);
06ca320f 474 if (DebugLevel() > 1)
95f69c66 475 AliInfo(Form("Matched Track index %d to new cluster %d\n",trackIndex,i));
476 }
2f7259cf 477 }
95f69c66 478 } else {
55a8e3e4 479 const Int_t Nclus = clus->GetEntries();
84ccad86 480 for(Int_t i=0; i < Nclus; ++i) {
481 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->At(i));
2f7259cf 482 Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
06ca320f 483 if (trackIndex >= 0) {
84ccad86 484 Float_t dR, dZ;
485 fRecoUtils->GetMatchedResiduals(i,dR, dZ);
486 c->SetTrackDistance(dR,dZ);
487 c->SetEmcCpvDistance(dR); //to be consistent with AODs
488 c->SetChi2(dZ); //to be consistent with AODs
4cf9204b 489 TArrayI tm(1,&trackIndex);
490 c->AddTracksMatched(tm);
06ca320f 491 if (DebugLevel() > 1)
2f7259cf 492 AliInfo(Form("Matched Track index %d to new cluster %d\n",trackIndex,i));
493 }
494 }
495 }
496}
497
95f69c66 498//________________________________________________________________________
499void AliAnalysisTaskEMCALClusterizeFast::UpdateCells()
500{
501 // Update cells in case re-calibration was done.
502
503 if (!fCalibData&&!fSubBackground)
504 return;
505
506 AliVCaloCells *cells = InputEvent()->GetEMCALCells();
55a8e3e4 507 const Int_t ncells = cells->GetNumberOfCells();
508 const Int_t ndigis = fDigitsArr->GetEntries();
95f69c66 509 if (ncells!=ndigis) {
510 cells->DeleteContainer();
511 cells->CreateContainer(ndigis);
512 }
513 for (Int_t idigit = 0; idigit < ndigis; ++idigit) {
514 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(idigit));
515 Double_t cellAmplitude = digit->GetCalibAmp();
55a8e3e4 516 Short_t cellNumber = digit->GetId();
517 Double_t cellTime = digit->GetTime();
95f69c66 518 cells->SetCell(idigit, cellNumber, cellAmplitude, cellTime);
519 }
520}
521
522//________________________________________________________________________
523void AliAnalysisTaskEMCALClusterizeFast::UpdateClusters()
524{
525 // Update cells in case re-calibration was done.
7a7d5a64 526
95f69c66 527 if (!fAttachClusters)
528 return;
7a7d5a64 529
06ca320f 530 TClonesArray *clus = 0;
7a7d5a64 531
e50a444f 532 if (fOverwrite) {
7a7d5a64 533 clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("caloClusters"));
534 if (!clus)
535 clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("CaloClusters"));
06ca320f 536 if (!clus)
7a7d5a64 537 return;
538
55a8e3e4 539 const Int_t nents = clus->GetEntries();
7a7d5a64 540 for (Int_t i=0;i<nents;++i) {
541 AliVCluster *c = static_cast<AliVCluster*>(clus->At(i));
542 if (!c)
543 continue;
544 if (c->IsEMCAL())
545 delete clus->RemoveAt(i);
546 }
06ca320f 547 } else {
7a7d5a64 548 clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fNewClusterArrayName));
06ca320f 549 if (!clus) {
7a7d5a64 550 clus = new TClonesArray("AliESDCaloCluster");
551 clus->SetName(fNewClusterArrayName);
552 InputEvent()->AddObject(clus);
06ca320f 553 } else {
0a7eb283 554 clus->Delete();
7a7d5a64 555 }
556 }
557
95f69c66 558 RecPoints2Clusters(clus);
559}
560
2f7259cf 561//________________________________________________________________________________________
562void AliAnalysisTaskEMCALClusterizeFast::Init()
563{
564 //Select clusterization/unfolding algorithm and set all the needed parameters
01bc1ce8 565
2f7259cf 566 AliVEvent * event = InputEvent();
567 if (!event) {
568 AliWarning("Event not available!!!");
569 return;
570 }
571
572 if (event->GetRunNumber()==fRun)
573 return;
574 fRun = event->GetRunNumber();
575
576 if (fJustUnfold){
577 // init the unfolding afterburner
578 delete fUnfolder;
1759f743 579 fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut(),fRecParam->GetMinECut());
2f7259cf 580 return;
581 }
582
2f7259cf 583 AliEMCALGeometry *geometry = AliEMCALGeometry::GetInstance(fGeomName);
584 if (!geometry) {
585 AliFatal("Geometry not available!!!");
586 return;
587 }
588
589 if (!fGeomMatrixSet) {
590 if (fLoadGeomMatrices) {
e51bc3f5 591 for(Int_t mod=0; mod < geometry->GetNumberOfSuperModules(); ++mod) {
06ca320f 592 if (fGeomMatrix[mod]){
593 if (DebugLevel() > 2)
2f7259cf 594 fGeomMatrix[mod]->Print();
595 geometry->SetMisalMatrix(fGeomMatrix[mod],mod);
596 }
597 }
29b496d5 598 } else { // get matrix from file (work around bug in aliroot)
2f7259cf 599 for(Int_t mod=0; mod < geometry->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
29b496d5 600 const TGeoHMatrix *gm = 0;
441c4d3c 601 AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(event);
29b496d5 602 if (esdevent) {
603 gm = esdevent->GetEMCALMatrix(mod);
604 } else {
605 AliAODHeader *aodheader = dynamic_cast<AliAODHeader*>(event->GetHeader());
606 if (aodheader) {
607 gm = aodheader->GetEMCALMatrix(mod);
608 }
609 }
610 if (gm) {
06ca320f 611 if (DebugLevel() > 2)
29b496d5 612 gm->Print();
613 geometry->SetMisalMatrix(gm,mod);
2f7259cf 614 }
615 }
616 }
617 fGeomMatrixSet=kTRUE;
618 }
619
620 // setup digit array if needed
621 if (!fDigitsArr) {
622 fDigitsArr = new TClonesArray("AliEMCALDigit", 1000);
623 fDigitsArr->SetOwner(1);
624 }
625
626 // then setup clusterizer
627 delete fClusterizer;
628 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
629 fClusterizer = new AliEMCALClusterizerv1(geometry);
06ca320f 630 else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN) {
2f7259cf 631 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(geometry);
3c56da8f 632 clusterizer->SetNRowDiff(fRecParam->GetNRowDiff());
633 clusterizer->SetNColDiff(fRecParam->GetNColDiff());
634 fClusterizer = clusterizer;
06ca320f 635 } else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
3c56da8f 636 fClusterizer = new AliEMCALClusterizerv2(geometry);
06ca320f 637 else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerFW){
7a7d5a64 638 AliEMCALClusterizerFixedWindow *clusterizer = new AliEMCALClusterizerFixedWindow(geometry);
0fda97fe 639 clusterizer->SetNphi(fNPhi);
640 clusterizer->SetNeta(fNEta);
641 clusterizer->SetShiftPhi(fShiftPhi);
642 clusterizer->SetShiftEta(fShiftEta);
3c56da8f 643 clusterizer->SetTRUshift(fTRUShift);
7a7d5a64 644 fClusterizer = clusterizer;
645 }
646 else{
2f7259cf 647 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
648 }
649 fClusterizer->InitParameters(fRecParam);
01bc1ce8 650
651 if ((!fCalibData&&fLoadCalib) || (!fPedestalData&&fLoadPed)) {
652 AliCDBManager *cdb = AliCDBManager::Instance();
653 if (!cdb->IsDefaultStorageSet() && !fOCDBpath.IsNull())
654 cdb->SetDefaultStorage(fOCDBpath);
655 if (fRun!=cdb->GetRun())
656 cdb->SetRun(fRun);
657 }
349bf69e 658 if (!fCalibData&&fLoadCalib&&fRun>0) {
2f7259cf 659 AliCDBEntry *entry = static_cast<AliCDBEntry*>(AliCDBManager::Instance()->Get("EMCAL/Calib/Data"));
660 if (entry)
661 fCalibData = static_cast<AliEMCALCalibData*>(entry->GetObject());
662 if (!fCalibData)
663 AliFatal("Calibration parameters not found in CDB!");
664 }
349bf69e 665 if (!fPedestalData&&fLoadPed&&fRun>0) {
2f7259cf 666 AliCDBEntry *entry = static_cast<AliCDBEntry*>(AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals"));
667 if (entry)
668 fPedestalData = static_cast<AliCaloCalibPedestal*>(entry->GetObject());
669 }
10d33986 670 if (fCalibData) {
671 fClusterizer->SetInputCalibrated(kFALSE);
672 fClusterizer->SetCalibrationParameters(fCalibData);
10d33986 673 } else {
674 fClusterizer->SetInputCalibrated(kTRUE);
675 }
e93ec1f7 676 fClusterizer->SetCaloCalibPedestal(fPedestalData);
10d33986 677 fClusterizer->SetJustClusters(kTRUE);
2f7259cf 678 fClusterizer->SetDigitsArr(fDigitsArr);
679 fClusterizer->SetOutput(0);
680 fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());
681}