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