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