1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //_________________________________________________________________________
17 // This analysis provides a new list of clusters to be used in other analysis
19 // Author: Constantin Loizides, Salvatore Aiola
20 // Adapted from analysis class from Deepa Thomas
23 //_________________________________________________________________________
26 #include <TClonesArray.h>
27 #include <TGeoManager.h>
28 #include <TObjArray.h>
34 #include "AliAODCaloCluster.h"
35 #include "AliAODEvent.h"
36 #include "AliAnalysisManager.h"
37 #include "AliCDBEntry.h"
38 #include "AliCDBManager.h"
39 #include "AliCaloCalibPedestal.h"
40 #include "AliEMCALAfterBurnerUF.h"
41 #include "AliEMCALCalibData.h"
42 #include "AliEMCALClusterizerNxN.h"
43 #include "AliEMCALClusterizerv1.h"
44 #include "AliEMCALClusterizerv2.h"
45 #include "AliEMCALClusterizerFixedWindow.h"
46 #include "AliEMCALDigit.h"
47 #include "AliEMCALGeometry.h"
48 #include "AliEMCALRecParam.h"
49 #include "AliEMCALRecPoint.h"
50 #include "AliEMCALRecoUtils.h"
51 #include "AliESDEvent.h"
52 #include "AliInputEventHandler.h"
55 #include "AliAnalysisTaskEMCALClusterizeFast.h"
57 ClassImp(AliAnalysisTaskEMCALClusterizeFast)
59 //________________________________________________________________________
60 AliAnalysisTaskEMCALClusterizeFast::AliAnalysisTaskEMCALClusterizeFast() :
65 fRecParam(new AliEMCALRecParam),
70 fGeomMatrixSet(kFALSE),
71 fLoadGeomMatrices(kFALSE),
80 fAttachClusters(kTRUE),
81 fSubBackground(kFALSE),
87 fInputCellType(kFEEData),
90 fCaloClustersName("newCaloClusters"),
91 fDoUpdateCells(kFALSE),
93 fClusterBadChannelCheck(kFALSE),
94 fRejectExoticClusters(kFALSE),
95 fRejectExoticCells(kFALSE),
97 fDoNonLinearity(kFALSE),
98 fRecalDistToBadChannels(kFALSE),
107 for(Int_t i = 0; i < 12; ++i)
111 //________________________________________________________________________
112 AliAnalysisTaskEMCALClusterizeFast::AliAnalysisTaskEMCALClusterizeFast(const char *name) :
113 AliAnalysisTaskSE(name),
117 fRecParam(new AliEMCALRecParam),
122 fGeomMatrixSet(kFALSE),
123 fLoadGeomMatrices(kFALSE),
132 fAttachClusters(kTRUE),
133 fSubBackground(kFALSE),
139 fInputCellType(kFEEData),
142 fCaloClustersName("newCaloClusters"),
143 fDoUpdateCells(kFALSE),
144 fDoClusterize(kTRUE),
145 fClusterBadChannelCheck(kFALSE),
146 fRejectExoticClusters(kFALSE),
147 fRejectExoticCells(kFALSE),
149 fDoNonLinearity(kFALSE),
150 fRecalDistToBadChannels(kFALSE),
159 fBranchNames = "ESD:AliESDHeader.,AliESDRun.,EMCALCells.,EMCALTrigger. AOD:header,emcalCells";
160 for(Int_t i = 0; i < 12; ++i)
164 //________________________________________________________________________
165 AliAnalysisTaskEMCALClusterizeFast::~AliAnalysisTaskEMCALClusterizeFast()
175 //________________________________________________________________________
176 void AliAnalysisTaskEMCALClusterizeFast::UserCreateOutputObjects()
178 // Create output objects.
180 if (!fOutputAODBrName.IsNull()) {
181 fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
182 fOutputAODBranch->SetName(fOutputAODBrName);
183 AddAODBranch("TClonesArray", &fOutputAODBranch);
184 AliInfo(Form("Created Branch: %s",fOutputAODBrName.Data()));
188 //________________________________________________________________________
189 void AliAnalysisTaskEMCALClusterizeFast::UserExec(Option_t *)
191 // Main loop, called for each event
193 // if no operation is requested, return
194 if (!fDoClusterize && !fDoUpdateCells)
197 // remove the contents of output list set in the previous event
198 if (fOutputAODBranch)
199 fOutputAODBranch->Clear("C");
201 fEsd = dynamic_cast<AliESDEvent*>(InputEvent());
202 fAod = dynamic_cast<AliAODEvent*>(InputEvent());
205 Error("UserExec","Event not available");
211 UInt_t offtrigger = 0;
213 UInt_t mask1 = fEsd->GetESDRun()->GetDetectorsInDAQ();
214 UInt_t mask2 = fEsd->GetESDRun()->GetDetectorsInReco();
215 Bool_t desc1 = (mask1 >> 18) & 0x1;
216 Bool_t desc2 = (mask2 >> 18) & 0x1;
217 if (desc1==0 || desc2==0) { //AliDAQ::OfflineModuleName(180=="EMCAL"
218 AliError(Form("EMCAL not in DAQ/RECO: %u (%u)/%u (%u)",
219 mask1, fEsd->GetESDRun()->GetDetectorsInReco(),
220 mask2, fEsd->GetESDRun()->GetDetectorsInDAQ()));
223 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
224 offtrigger = ((AliInputEventHandler*)(am->GetInputEventHandler()))->IsEventSelected();
226 offtrigger = ((AliVAODHeader*)fAod->GetHeader())->GetOfflineTrigger();
230 if (offtrigger & AliVEvent::kFastOnly) {
231 AliError(Form("EMCAL not in fast only partition"));
239 AliWarning("Unfolding not implemented");
251 if (!fDoClusterize || (!fAttachClusters && !fOutputAODBranch) || !fCaloClusters)
257 if (fOutputAODBranch && fCaloClusters != fOutputAODBranch)
258 CopyClusters(fCaloClusters, fOutputAODBranch);
262 //________________________________________________________________________
263 void AliAnalysisTaskEMCALClusterizeFast::CopyClusters(TClonesArray *orig, TClonesArray *dest)
265 const Int_t Ncls = orig->GetEntries();
267 for(Int_t i=0; i < Ncls; ++i) {
268 AliVCluster *oc = static_cast<AliVCluster*>(orig->At(i));
276 AliVCluster *dc = static_cast<AliVCluster*>(dest->New(i));
277 dc->SetType(AliVCluster::kEMCALClusterv1);
279 Float_t pos[3] = {0};
280 oc->GetPosition(pos);
281 dc->SetPosition(pos);
282 dc->SetNCells(oc->GetNCells());
283 dc->SetCellsAbsId(oc->GetCellsAbsId());
284 dc->SetCellsAmplitudeFraction(oc->GetCellsAmplitudeFraction());
285 dc->SetID(oc->GetID());
286 dc->SetDispersion(oc->GetDispersion());
287 dc->SetEmcCpvDistance(-1);
289 dc->SetTOF(oc->GetTOF()); //time-of-flight
290 dc->SetNExMax(oc->GetNExMax()); //number of local maxima
291 dc->SetM02(oc->GetM02());
292 dc->SetM20(oc->GetM20());
293 dc->SetDistanceToBadChannel(oc->GetDistanceToBadChannel());
294 dc->SetMCEnergyFraction(oc->GetMCEnergyFraction());
297 UInt_t nlabels = oc->GetNLabels();
298 Int_t *labels = oc->GetLabels();
300 if (nlabels == 0 || !labels)
303 AliESDCaloCluster *esdClus = dynamic_cast<AliESDCaloCluster*>(dc);
305 TArrayI parents(nlabels, labels);
306 esdClus->AddLabels(parents);
309 AliAODCaloCluster *aodClus = dynamic_cast<AliAODCaloCluster*>(dc);
311 aodClus->SetLabel(labels, nlabels);
316 //________________________________________________________________________
317 void AliAnalysisTaskEMCALClusterizeFast::Clusterize()
321 if (fSubBackground) {
322 fClusterizer->SetInputCalibrated(kTRUE);
323 fClusterizer->SetCalibrationParameters(0);
326 fClusterizer->Digits2Clusters("");
328 if (fSubBackground) {
330 fClusterizer->SetInputCalibrated(kFALSE);
331 fClusterizer->SetCalibrationParameters(fCalibData);
336 //________________________________________________________________________
337 void AliAnalysisTaskEMCALClusterizeFast::FillDigitsArray()
341 fDigitsArr->Clear("C");
342 switch (fInputCellType) {
345 case kFEEDataMCOnly :
346 case kFEEDataExcludeMC :
348 Double_t avgE = 0; // for background subtraction
349 const Int_t ncells = fCaloCells->GetNumberOfCells();
350 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) {
351 Double_t cellAmplitude=0, cellTime=0, cellEFrac = 0;
352 Short_t cellNumber=0;
353 Int_t cellMCLabel=-1;
354 if (fCaloCells->GetCell(icell, cellNumber, cellAmplitude, cellTime, cellMCLabel, cellEFrac) != kTRUE)
357 if (cellMCLabel > 0 && cellEFrac < 1e-6)
360 if (cellAmplitude < 1e-6 || cellNumber < 0)
363 if (fInputCellType == kFEEDataMCOnly) {
364 if (cellMCLabel <= 0)
367 cellAmplitude *= cellEFrac;
371 else if (fInputCellType == kFEEDataExcludeMC) {
375 cellAmplitude *= 1 - cellEFrac;
380 if(!AcceptCell(cellNumber)) continue;
382 AliEMCALDigit *digit = new((*fDigitsArr)[idigit]) AliEMCALDigit(cellMCLabel, cellMCLabel, cellNumber,
383 (Float_t)cellAmplitude, (Float_t)cellTime,
384 AliEMCALDigit::kHG,idigit, 0, 0, cellEFrac*cellAmplitude);
386 if (!fDoClusterize||fSubBackground) {
387 Float_t energy = cellAmplitude;
388 Float_t time = cellTime;
389 fClusterizer->Calibrate(energy,time,cellNumber);
390 digit->SetAmplitude(energy);
396 if (fSubBackground) {
397 avgE /= fGeom->GetNumberOfSuperModules()*48*24;
398 Int_t ndigis = fDigitsArr->GetEntries();
399 for (Int_t i = 0; i < ndigis; ++i) {
400 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(i));
401 Double_t energy = digit->GetAmplitude() - avgE;
403 digit->SetAmplitude(0);
405 digit->SetAmplitude(energy);
414 // Fill digits from a pattern
415 Int_t maxd = fGeom->GetNCells() / 4;
416 for (Int_t idigit = 0; idigit < maxd; idigit++){
417 if (idigit % 24 == 12) idigit += 12;
418 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
419 digit->SetId(idigit * 4);
421 digit->SetTimeR(600);
422 digit->SetIndexInList(idigit);
423 digit->SetType(AliEMCALDigit::kHG);
424 digit->SetAmplitude(0.1);
433 // Fill digits from FastORs
435 AliVCaloTrigger *triggers = InputEvent()->GetCaloTrigger("EMCAL");
437 if (!triggers || !(triggers->GetEntries() > 0))
443 while ((triggers->Next())) {
444 Float_t L0Amplitude = 0;
445 triggers->GetAmplitude(L0Amplitude);
447 if (L0Amplitude <= 0 && fInputCellType != kL1FastORs)
450 Int_t L1Amplitude = 0;
451 triggers->GetL1TimeSum(L1Amplitude);
453 if (L1Amplitude <= 0 && fInputCellType == kL1FastORs)
456 Int_t triggerTime = 0;
458 triggers->GetNL0Times(ntimes);
460 if (ntimes < 1 && fInputCellType == kL0FastORsTC)
465 triggers->GetL0Times(trgtimes);
466 triggerTime = trgtimes[0];
469 Int_t triggerCol = 0, triggerRow = 0;
470 triggers->GetPosition(triggerCol, triggerRow);
473 fGeom->GetAbsFastORIndexFromPositionInEMCAL(triggerCol, triggerRow, find);
478 Int_t cidx[4] = {-1};
479 Bool_t ret = fGeom->GetCellIndexFromFastORIndex(find, cidx);
484 Float_t triggerAmplitude = 0;
486 if (fInputCellType == kL1FastORs) {
487 triggerAmplitude = 0.25 * L1Amplitude; // it will add 4 cells for 1 amplitude
490 triggerAmplitude = L0Amplitude; // 10 bit truncated, so it is already divided by 4
493 for (Int_t idxpos = 0; idxpos < 4; idxpos++) {
494 Int_t triggerNumber = cidx[idxpos];
495 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
496 digit->SetId(triggerNumber);
497 digit->SetTime(triggerTime);
498 digit->SetTimeR(triggerTime);
499 digit->SetIndexInList(idigit);
500 digit->SetType(AliEMCALDigit::kHG);
501 digit->SetAmplitude(triggerAmplitude);
510 //________________________________________________________________________________________
511 Bool_t AliAnalysisTaskEMCALClusterizeFast::AcceptCell(Int_t cellNumber) {
513 Bool_t accept = kTRUE;
514 if(fRejectExoticCells) {
515 //Remove exotic cells before making digits
516 Bool_t exRemoval = fRecoUtils->IsRejectExoticCell();
517 fRecoUtils->SwitchOnRejectExoticCell();//switch on and off
518 Int_t bunchCrossNo = InputEvent()->GetBunchCrossNumber();
519 Bool_t isEx = fRecoUtils->IsExoticCell(cellNumber, fCaloCells, bunchCrossNo);
520 if(isEx) accept = kFALSE;
521 if(!exRemoval) fRecoUtils->SwitchOffRejectExoticCell();//switch on and off
526 //________________________________________________________________________________________
527 void AliAnalysisTaskEMCALClusterizeFast::CalibrateClusters()
529 // Go through clusters one by one and process separate correction
530 // as those were defined or not
532 Int_t nclusters = fCaloClusters->GetEntriesFast();
533 for (Int_t icluster=0; icluster < nclusters; ++icluster) {
534 AliVCluster *clust = static_cast<AliVCluster*>(fCaloClusters->At(icluster));
537 if (!clust->IsEMCAL())
540 // REMOVE CLUSTERS WITH BAD CELLS -----------------------------
541 if (fClusterBadChannelCheck) {
542 // careful, the the ClusterContainsBadChannel is dependent on
543 // SwitchOnBadChannelsRemoval, switching it ON automatically
544 // and returning to original value after processing
545 Bool_t badRemoval = fRecoUtils->IsBadChannelsRemovalSwitchedOn();
546 fRecoUtils->SwitchOnBadChannelsRemoval();
548 Bool_t badResult = fRecoUtils->ClusterContainsBadChannel(fGeom, clust->GetCellsAbsId(), clust->GetNCells());
550 // switch the bad channels removal back
552 fRecoUtils->SwitchOffBadChannelsRemoval();
555 delete fCaloClusters->RemoveAt(icluster);
556 continue; //TODO is it really needed to remove it? Or should we flag it?
560 // REMOVE EXOTIC CLUSTERS -------------------------------------
561 // does process local cell recalibration energy and time without replacing
562 // the global cell values, in case of no cell recalib done yet
563 if (fRejectExoticClusters) {
564 // careful, the IsExoticCluster is dependent on
565 // SwitchOnRejectExoticCell, switching it ON automatically
566 // and returning to original value after processing
567 Bool_t exRemoval = fRecoUtils->IsRejectExoticCell();
568 fRecoUtils->SwitchOnRejectExoticCell();
570 // get bunch crossing
571 Int_t bunchCrossNo = InputEvent()->GetBunchCrossNumber();
573 Bool_t exResult = fRecoUtils->IsExoticCluster(clust, fCaloCells, bunchCrossNo);
575 // switch the exotic channels removal back
577 fRecoUtils->SwitchOffRejectExoticCell();
580 delete fCaloClusters->RemoveAt(icluster);
581 continue; //TODO is it really needed to remove it? Or should we flag it?
585 // FIDUCIAL CUT -----------------------------------------------
587 // depends on SetNumberOfCellsFromEMCALBorder
588 // SwitchOnNoFiducialBorderInEMCALEta0
589 if (!fRecoUtils->CheckCellFiducialRegion(fGeom, clust, fCaloCells)){
590 delete fCaloClusters->RemoveAt(icluster);
591 continue; //TODO it would be nice to store the distance
595 // NONLINEARITY -----------------------------------------------
596 if (fDoNonLinearity) {
597 Float_t correctedEnergy = fRecoUtils->CorrectClusterEnergyLinearity(clust);
598 clust->SetE(correctedEnergy);
601 // DISTANCE TO BAD CHANNELS -----------------------------------
602 if (fRecalDistToBadChannels)
603 fRecoUtils->RecalculateClusterDistanceToBadChannel(fGeom, fCaloCells, clust);
606 fCaloClusters->Compress();
609 //________________________________________________________________________________________
610 void AliAnalysisTaskEMCALClusterizeFast::TrackClusterMatching(AliVCluster *c, TClonesArray *tarr)
616 Double_t dEtaMin = 1e9;
617 Double_t dPhiMin = 1e9;
619 Double_t ceta = gpos.Eta();
620 Double_t cphi = gpos.Phi();
621 const Int_t ntrks = tarr->GetEntries();
622 for(Int_t t = 0; t<ntrks; ++t) {
623 AliVTrack *track = static_cast<AliVTrack*>(tarr->At(t));
626 const AliExternalTrackParam *outp = track->GetOuterParam();
629 Double_t trkPos[3] = {0.,0.,0.};
630 if (!outp->GetXYZ(trkPos))
632 TVector3 vec(trkPos[0],trkPos[1],trkPos[2]);
633 Double_t veta = vec.Eta();
634 Double_t vphi = vec.Phi();
636 vphi += 2*TMath::Pi();
637 if (TMath::Abs(veta)>0.75 || (vphi<70*TMath::DegToRad()) || (vphi>190*TMath::DegToRad()))
639 Double_t dR = vec.DeltaR(gpos);
642 Float_t tmpEta=0, tmpPhi=0;
644 AliExternalTrackParam trkParTemp(*outp); // retrieve the starting point every time before the extrapolation
645 Bool_t ret = fRecoUtils->ExtrapolateTrackToCluster(&trkParTemp, c, fRecoUtils->GetMass(), fRecoUtils->GetStep(), tmpEta, tmpPhi);
649 tmpEta = ceta - veta;
650 tmpPhi = cphi - vphi;
652 if (TMath::Abs(tmpEta)<TMath::Abs(dEtaMin) && TMath::Abs(tmpPhi)<TMath::Abs(dPhiMin)) {
658 c->SetEmcCpvDistance(imin);
659 c->SetTrackDistance(dPhiMin, dEtaMin);
662 //________________________________________________________________________________________
663 void AliAnalysisTaskEMCALClusterizeFast::RecPoints2Clusters(TClonesArray *clus)
665 // Cluster energy, global position, cells and their amplitude fractions are restored.
667 // tracks array for track/cluster matching
668 TClonesArray *tarr = 0;
669 if (!fTrackName.IsNull()) {
670 tarr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTrackName));
672 AliError(Form("Cannot get tracks named %s", fTrackName.Data()));
676 const Int_t Ncls = fClusterArr->GetEntries();
677 AliDebug(1, Form("total no of clusters %d", Ncls));
678 for(Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i) {
679 AliEMCALRecPoint *recpoint = static_cast<AliEMCALRecPoint*>(fClusterArr->At(i));
680 Int_t ncells_true = 0;
681 const Int_t ncells = recpoint->GetMultiplicity();
682 UShort_t absIds[ncells];
683 Double32_t ratios[ncells];
684 Int_t *dlist = recpoint->GetDigitsList();
685 Float_t *elist = recpoint->GetEnergiesList();
686 Double_t mcEnergy = 0;
687 for (Int_t c = 0; c < ncells; ++c) {
688 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(dlist[c]));
689 absIds[ncells_true] = digit->GetId();
690 ratios[ncells_true] = elist[c]/recpoint->GetEnergy();
691 if (digit->GetIparent(1) > 0)
692 mcEnergy += digit->GetDEParent(1)/recpoint->GetEnergy();
696 if (ncells_true < 1) {
697 AliWarning("Skipping cluster with no cells");
701 // calculate new cluster position
703 recpoint->GetGlobalPosition(gpos);
707 AliDebug(1, Form("energy %f", recpoint->GetEnergy()));
709 AliVCluster *c = static_cast<AliVCluster*>(clus->New(nout++));
710 c->SetType(AliVCluster::kEMCALClusterv1);
711 c->SetE(recpoint->GetEnergy());
713 c->SetNCells(ncells_true);
714 c->SetCellsAbsId(absIds);
715 c->SetCellsAmplitudeFraction(ratios);
716 c->SetID(recpoint->GetUniqueID());
717 c->SetDispersion(recpoint->GetDispersion());
718 c->SetEmcCpvDistance(-1);
720 c->SetTOF(recpoint->GetTime()) ; //time-of-flight
721 c->SetNExMax(recpoint->GetNExMax()); //number of local maxima
723 recpoint->GetElipsAxis(elipAxis);
724 c->SetM02(elipAxis[0]*elipAxis[0]);
725 c->SetM20(elipAxis[1]*elipAxis[1]);
726 c->SetMCEnergyFraction(mcEnergy);
729 AliESDCaloCluster *esdClus = dynamic_cast<AliESDCaloCluster*>(c);
731 Int_t parentMult = 0;
732 Int_t *parentList = recpoint->GetParents(parentMult);
733 if (parentMult > 0) {
734 TArrayI parents(parentMult, parentList);
735 esdClus->AddLabels(parents);
739 AliAODCaloCluster *aodClus = dynamic_cast<AliAODCaloCluster*>(c);
741 Int_t parentMult = 0;
742 Int_t *parentList = recpoint->GetParents(parentMult);
743 aodClus->SetLabel(parentList, parentMult);
748 TrackClusterMatching(c, tarr);
752 //________________________________________________________________________
753 void AliAnalysisTaskEMCALClusterizeFast::UpdateCells()
755 // Update cells in case re-calibration was done.
756 if (!fCalibData&&!fSubBackground)
759 const Int_t ncells = fCaloCells->GetNumberOfCells();
760 const Int_t ndigis = fDigitsArr->GetEntries();
761 if (ncells!=ndigis) {
762 fCaloCells->DeleteContainer();
763 fCaloCells->CreateContainer(ndigis);
765 for (Int_t idigit = 0; idigit < ndigis; ++idigit) {
766 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(idigit));
767 Double_t cellAmplitude = digit->GetCalibAmp();
768 Short_t cellNumber = digit->GetId();
769 Double_t cellTime = digit->GetTime();
770 fCaloCells->SetCell(idigit, cellNumber, cellAmplitude, cellTime);
774 //________________________________________________________________________
775 void AliAnalysisTaskEMCALClusterizeFast::UpdateClusters()
777 // Update cells in case re-calibration was done.
779 const Int_t nents = fCaloClusters->GetEntries();
780 for (Int_t i=0;i<nents;++i) {
781 AliVCluster *c = static_cast<AliVCluster*>(fCaloClusters->At(i));
785 delete fCaloClusters->RemoveAt(i);
788 fCaloClusters->Compress();
790 RecPoints2Clusters(fCaloClusters);
793 //________________________________________________________________________________________
794 void AliAnalysisTaskEMCALClusterizeFast::Init()
796 // Select clusterization/unfolding algorithm and set all the needed parameters.
798 if (InputEvent()->GetRunNumber()==fRun)
800 fRun = InputEvent()->GetRunNumber();
803 // init the unfolding afterburner
805 fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut(),fRecParam->GetMinECut());
809 if (fGeomName.Length()>0)
810 fGeom = AliEMCALGeometry::GetInstance(fGeomName);
812 fGeom = AliEMCALGeometry::GetInstance();
814 AliFatal("Geometry not available!!!");
818 if (!fGeomMatrixSet) {
819 if (fLoadGeomMatrices) {
820 for(Int_t mod=0; mod < fGeom->GetNumberOfSuperModules(); ++mod) {
821 if (fGeomMatrix[mod]){
822 if (DebugLevel() > 2)
823 fGeomMatrix[mod]->Print();
824 fGeom->SetMisalMatrix(fGeomMatrix[mod],mod);
827 } else { // get matrix from file (work around bug in aliroot)
828 for(Int_t mod=0; mod < fGeom->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
829 const TGeoHMatrix *gm = 0;
831 gm = fEsd->GetEMCALMatrix(mod);
833 AliAODHeader *aodheader = dynamic_cast<AliAODHeader*>(fAod->GetHeader());
834 if(!aodheader) AliFatal("Not a standard AOD");
836 gm = aodheader->GetEMCALMatrix(mod);
840 if (DebugLevel() > 2)
842 fGeom->SetMisalMatrix(gm,mod);
846 fGeomMatrixSet=kTRUE;
849 // setup digit array if needed
851 fDigitsArr = new TClonesArray("AliEMCALDigit", 1000);
852 fDigitsArr->SetOwner(1);
855 // then setup clusterizer
857 // avoid to delete digits array
858 fClusterizer->SetDigitsArr(0);
861 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
862 fClusterizer = new AliEMCALClusterizerv1(fGeom);
863 else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN) {
864 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(fGeom);
865 clusterizer->SetNRowDiff(fRecParam->GetNRowDiff()); //MV: already done in AliEMCALClusterizer::InitParameters
866 clusterizer->SetNColDiff(fRecParam->GetNColDiff()); //MV: already done in AliEMCALClusterizer::InitParameters
867 fClusterizer = clusterizer;
869 else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
870 fClusterizer = new AliEMCALClusterizerv2(fGeom);
871 else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerFW) {
872 AliEMCALClusterizerFixedWindow *clusterizer = new AliEMCALClusterizerFixedWindow(fGeom);
873 clusterizer->SetNphi(fNPhi);
874 clusterizer->SetNeta(fNEta);
875 clusterizer->SetShiftPhi(fShiftPhi);
876 clusterizer->SetShiftEta(fShiftEta);
877 clusterizer->SetTRUshift(fTRUShift);
878 fClusterizer = clusterizer;
881 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
883 fClusterizer->InitParameters(fRecParam);
885 if ((!fCalibData&&fLoadCalib) || (!fPedestalData&&fLoadPed)) {
886 AliCDBManager *cdb = AliCDBManager::Instance();
887 if (!cdb->IsDefaultStorageSet() && !fOCDBpath.IsNull())
888 cdb->SetDefaultStorage(fOCDBpath);
889 if (fRun!=cdb->GetRun())
892 if (!fCalibData&&fLoadCalib&&fRun>0) {
893 AliCDBEntry *entry = static_cast<AliCDBEntry*>(AliCDBManager::Instance()->Get("EMCAL/Calib/Data"));
895 fCalibData = static_cast<AliEMCALCalibData*>(entry->GetObject());
897 AliFatal("Calibration parameters not found in CDB!");
899 if (!fPedestalData&&fLoadPed&&fRun>0) {
900 AliCDBEntry *entry = static_cast<AliCDBEntry*>(AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals"));
902 fPedestalData = static_cast<AliCaloCalibPedestal*>(entry->GetObject());
905 fClusterizer->SetInputCalibrated(kFALSE);
906 fClusterizer->SetCalibrationParameters(fCalibData);
908 fClusterizer->SetInputCalibrated(kTRUE);
910 fClusterizer->SetCaloCalibPedestal(fPedestalData);
911 fClusterizer->SetJustClusters(kTRUE);
912 fClusterizer->SetDigitsArr(fDigitsArr);
913 fClusterizer->SetOutput(0);
914 fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());
916 // Get the emcal cells
917 if ((fInputCellType == kFEEData || fInputCellType == kFEEDataMCOnly || fInputCellType == kFEEDataExcludeMC) && !fCaloCells) {
918 if (fCaloCellsName.IsNull()) {
919 fCaloCells = InputEvent()->GetEMCALCells();
922 fCaloCells = dynamic_cast<AliVCaloCells*>(InputEvent()->FindListObject(fCaloCellsName));
924 AliError(Form("%s: Could not retrieve cells %s!", GetName(), fCaloCellsName.Data()));
927 AliFatal("Could not get EMCal cells!");
930 // Set output clusters collection
931 if (!fAttachClusters) {
932 fCaloClusters = fOutputAODBranch;
936 if (!fCaloClusters) {
937 if (fCaloClustersName.IsNull()) { //overwrite mode
939 fCaloClusters = static_cast<TClonesArray*>(InputEvent()->FindListObject("CaloClusters"));
941 fCaloClusters = static_cast<TClonesArray*>(InputEvent()->FindListObject("caloClusters"));
944 fCaloClusters = static_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloClustersName));
946 if (!fCaloClusters) {
948 fCaloClusters = new TClonesArray("AliESDCaloCluster");
950 fCaloClusters = new TClonesArray("AliAODCaloCluster");
952 fCaloClusters->SetName(fCaloClustersName);
953 InputEvent()->AddObject(fCaloClusters);
958 AliFatal("Could not get cluster collection!");
960 TClass *cl = fCaloClusters->GetClass();
961 if (!cl->GetBaseClass("AliVCluster")) {
962 AliFatal(Form("%s: Collection %s does not contain AliVCluster objects!", GetName(), fCaloClusters->GetName()));