17 #include <TClonesArray.h>
18 #include <TGeoManager.h>
19 #include <TObjArray.h>
25 #include "AliAODCaloCluster.h"
26 #include "AliAODEvent.h"
27 #include "AliAnalysisManager.h"
28 #include "AliCDBEntry.h"
29 #include "AliCDBManager.h"
30 #include "AliCaloCalibPedestal.h"
31 #include "AliEMCALAfterBurnerUF.h"
32 #include "AliEMCALCalibData.h"
33 #include "AliEMCALClusterizerNxN.h"
34 #include "AliEMCALClusterizerv1.h"
35 #include "AliEMCALClusterizerv2.h"
36 #include "AliEMCALClusterizerFixedWindow.h"
37 #include "AliEMCALDigit.h"
38 #include "AliEMCALGeometry.h"
39 #include "AliEMCALRecParam.h"
40 #include "AliEMCALRecPoint.h"
41 #include "AliEMCALRecoUtils.h"
42 #include "AliESDEvent.h"
43 #include "AliInputEventHandler.h"
56 fRecParam(new AliEMCALRecParam),
61 fGeomMatrixSet(kFALSE),
62 fLoadGeomMatrices(kFALSE),
71 fAttachClusters(kTRUE),
72 fSubBackground(kFALSE),
78 fInputCellType(kFEEData),
81 fCaloClustersName("newCaloClusters"),
82 fDoUpdateCells(kFALSE),
84 fClusterBadChannelCheck(kFALSE),
85 fRejectExoticClusters(kFALSE),
86 fRejectExoticCells(kFALSE),
88 fDoNonLinearity(kFALSE),
89 fRecalDistToBadChannels(kFALSE),
90 fSetCellMCLabelFromCluster(0),
91 fSetCellMCLabelFromEdepFrac(0),
100 for(
Int_t i = 0; i < AliEMCALGeoParams::fgkEMCALModules; i++) fGeomMatrix[i] = 0 ;
101 for(
Int_t j = 0; j < fgkTotalCellNumber; j++)
102 { fOrgClusterCellId[j] =-1; fCellLabels[j] =-1 ; }
111 fRecParam(new AliEMCALRecParam),
116 fGeomMatrixSet(kFALSE),
117 fLoadGeomMatrices(kFALSE),
126 fAttachClusters(kTRUE),
127 fSubBackground(kFALSE),
133 fInputCellType(kFEEData),
136 fCaloClustersName(
"newCaloClusters"),
137 fDoUpdateCells(kFALSE),
138 fDoClusterize(kTRUE),
139 fClusterBadChannelCheck(kFALSE),
140 fRejectExoticClusters(kFALSE),
141 fRejectExoticCells(kFALSE),
143 fDoNonLinearity(kFALSE),
144 fRecalDistToBadChannels(kFALSE),
145 fSetCellMCLabelFromCluster(0),
146 fSetCellMCLabelFromEdepFrac(0),
155 fBranchNames =
"ESD:AliESDHeader.,AliESDRun.,EMCALCells.,EMCALTrigger. AOD:header,emcalCells";
157 for(
Int_t i = 0; i < AliEMCALGeoParams::fgkEMCALModules; i++)
fGeomMatrix[i] = 0 ;
203 Error(
"UserExec",
"Event not available");
211 UInt_t mask1 =
fEsd->GetESDRun()->GetDetectorsInDAQ();
212 UInt_t mask2 =
fEsd->GetESDRun()->GetDetectorsInReco();
213 Bool_t desc1 = (mask1 >> 18) & 0x1;
214 Bool_t desc2 = (mask2 >> 18) & 0x1;
215 if (desc1==0 || desc2==0) {
216 AliError(Form(
"EMCAL not in DAQ/RECO: %u (%u)/%u (%u)",
217 mask1,
fEsd->GetESDRun()->GetDetectorsInReco(),
218 mask2,
fEsd->GetESDRun()->GetDetectorsInDAQ()));
222 offtrigger = ((AliInputEventHandler*)(am->GetInputEventHandler()))->IsEventSelected();
224 offtrigger = ((AliVAODHeader*)
fAod->GetHeader())->GetOfflineTrigger();
228 if (offtrigger & AliVEvent::kFastOnly) {
229 AliError(Form(
"EMCAL not in fast only partition"));
237 AliWarning(
"Unfolding not implemented");
263 const Int_t Ncls = orig->GetEntries();
265 for(
Int_t i=0; i < Ncls; ++i) {
266 AliVCluster *oc =
static_cast<AliVCluster*
>(orig->At(i));
274 AliVCluster *dc =
static_cast<AliVCluster*
>(dest->New(i));
275 dc->SetType(AliVCluster::kEMCALClusterv1);
278 oc->GetPosition(pos);
279 dc->SetPosition(pos);
280 dc->SetNCells(oc->GetNCells());
281 dc->SetCellsAbsId(oc->GetCellsAbsId());
282 dc->SetCellsAmplitudeFraction(oc->GetCellsAmplitudeFraction());
283 dc->SetID(oc->GetID());
284 dc->SetDispersion(oc->GetDispersion());
285 dc->SetEmcCpvDistance(-1);
287 dc->SetTOF(oc->GetTOF());
288 dc->SetNExMax(oc->GetNExMax());
289 dc->SetM02(oc->GetM02());
290 dc->SetM20(oc->GetM20());
291 dc->SetDistanceToBadChannel(oc->GetDistanceToBadChannel());
292 dc->SetMCEnergyFraction(oc->GetMCEnergyFraction());
295 UInt_t nlabels = oc->GetNLabels();
296 Int_t *labels = oc->GetLabels();
298 if (nlabels == 0 || !labels)
301 AliESDCaloCluster *esdClus =
dynamic_cast<AliESDCaloCluster*
>(dc);
303 TArrayI parents(nlabels, labels);
304 esdClus->AddLabels(parents);
307 AliAODCaloCluster *aodClus =
dynamic_cast<AliAODCaloCluster*
>(dc);
309 aodClus->SetLabel(labels, nlabels);
358 Int_t nClusters = InputEvent()->GetNumberOfCaloClusters();
359 for (
Int_t i = 0; i < nClusters; i++)
361 AliVCluster *clus = InputEvent()->GetCaloCluster(i);
365 if (!clus->IsEMCAL())
continue ;
367 Int_t label = clus->GetLabel();
368 UShort_t * index = clus->GetCellsAbsId() ;
370 for(
Int_t icell=0; icell < clus->GetNCells(); icell++)
382 for (
Int_t icell = 0, idigit = 0; icell < ncells; ++icell)
385 Double_t cellTime=0, amp = 0, cellEFrac = 0;
387 Int_t cellMCLabel=-1;
388 if (
fCaloCells->GetCell(icell, cellNumber, amp, cellTime, cellMCLabel, cellEFrac) != kTRUE)
395 if (cellMCLabel > 0 && cellEFrac < 1e-6)
398 if (cellAmplitude < 1e-6 || cellNumber < 0)
402 if (cellMCLabel <= 0)
405 cellAmplitude *= cellEFrac;
413 cellAmplitude *= 1 - cellEFrac;
438 AliInfo(
"Negative original cluster index, skip \n");
442 AliVCluster *clus = InputEvent()->GetCaloCluster(iclus);
444 for(
Int_t icluscell=0; icluscell < clus->GetNCells(); icluscell++ )
446 if(cellNumber != clus->GetCellAbsId(icluscell))
continue ;
450 fRecoUtils->RecalculateCellLabelsRemoveAddedGenerator(cellNumber, clus, MCEvent(),cellAmplitude, labeArr, eDepArr);
451 nLabels = labeArr.GetSize();
455 AliEMCALDigit *digit =
new((*fDigitsArr)[idigit]) AliEMCALDigit(cellMCLabel, cellMCLabel, cellNumber,
456 cellAmplitude, (
Float_t)cellTime,
457 AliEMCALDigit::kHG,idigit, 0, 0, cellEFrac*cellAmplitude);
461 digit->SetListOfParents(nLabels,labeArr.GetArray(),eDepArr.GetArray());
470 digit->SetAmplitude(energy);
478 avgE /=
fGeom->GetNumberOfSuperModules()*48*24;
480 for (
Int_t i = 0; i < ndigis; ++i) {
481 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(i));
484 digit->SetAmplitude(0);
486 digit->SetAmplitude(energy);
497 for (
Int_t idigit = 0; idigit < maxd; idigit++){
498 if (idigit % 24 == 12) idigit += 12;
499 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->New(idigit));
500 digit->SetId(idigit * 4);
502 digit->SetTimeR(600);
503 digit->SetIndexInList(idigit);
504 digit->SetType(AliEMCALDigit::kHG);
505 digit->SetAmplitude(0.1);
516 AliVCaloTrigger *triggers = InputEvent()->GetCaloTrigger(
"EMCAL");
518 if (!triggers || !(triggers->GetEntries() > 0))
524 while ((triggers->Next())) {
526 triggers->GetAmplitude(L0Amplitude);
531 Int_t L1Amplitude = 0;
532 triggers->GetL1TimeSum(L1Amplitude);
537 Int_t triggerTime = 0;
539 triggers->GetNL0Times(ntimes);
546 triggers->GetL0Times(trgtimes);
547 triggerTime = trgtimes[0];
550 Int_t triggerCol = 0, triggerRow = 0;
551 triggers->GetPosition(triggerCol, triggerRow);
554 fGeom->GetAbsFastORIndexFromPositionInEMCAL(triggerCol, triggerRow, find);
559 Int_t cidx[4] = {-1};
560 Bool_t ret =
fGeom->GetCellIndexFromFastORIndex(find, cidx);
568 triggerAmplitude = 0.25 * L1Amplitude;
571 triggerAmplitude = L0Amplitude;
574 for (
Int_t idxpos = 0; idxpos < 4; idxpos++) {
575 Int_t triggerNumber = cidx[idxpos];
576 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->New(idigit));
577 digit->SetId(triggerNumber);
578 digit->SetTime(triggerTime);
579 digit->SetTimeR(triggerTime);
580 digit->SetIndexInList(idigit);
581 digit->SetType(AliEMCALDigit::kHG);
582 digit->SetAmplitude(triggerAmplitude);
599 Int_t bunchCrossNo = InputEvent()->GetBunchCrossNumber();
601 if(isEx) accept = kFALSE;
602 if(!exRemoval)
fRecoUtils->SwitchOffRejectExoticCell();
614 for (
Int_t icluster=0; icluster < nclusters; ++icluster) {
615 AliVCluster *clust =
static_cast<AliVCluster*
>(
fCaloClusters->At(icluster));
618 if (!clust->IsEMCAL())
629 Bool_t badResult =
fRecoUtils->ClusterContainsBadChannel(
fGeom, clust->GetCellsAbsId(), clust->GetNCells());
652 Int_t bunchCrossNo = InputEvent()->GetBunchCrossNumber();
679 clust->SetE(correctedEnergy);
702 const Int_t ntrks = tarr->GetEntries();
703 for(
Int_t t = 0; t<ntrks; ++t) {
704 AliVTrack *track =
static_cast<AliVTrack*
>(tarr->At(t));
707 const AliExternalTrackParam *outp = track->GetOuterParam();
711 if (!outp->GetXYZ(trkPos))
713 TVector3 vec(trkPos[0],trkPos[1],trkPos[2]);
717 vphi += 2*TMath::Pi();
718 if (TMath::Abs(veta)>0.75 || (vphi<70*TMath::DegToRad()) || (vphi>190*TMath::DegToRad()))
725 AliExternalTrackParam trkParTemp(*outp);
730 tmpEta = ceta - veta;
731 tmpPhi = cphi - vphi;
733 if (TMath::Abs(tmpEta)<TMath::Abs(dEtaMin) && TMath::Abs(tmpPhi)<TMath::Abs(dPhiMin)) {
739 c->SetEmcCpvDistance(imin);
740 c->SetTrackDistance(dPhiMin, dEtaMin);
749 TClonesArray *tarr = 0;
751 tarr =
dynamic_cast<TClonesArray*
>(InputEvent()->FindListObject(
fTrackName));
753 AliError(Form(
"Cannot get tracks named %s",
fTrackName.Data()));
758 AliDebug(1, Form(
"total no of clusters %d", Ncls));
760 for(
Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i)
762 AliEMCALRecPoint *recpoint =
static_cast<AliEMCALRecPoint*
>(
fClusterArr->At(i));
764 Int_t ncellsTrue = 0;
765 const Int_t ncells = recpoint->GetMultiplicity();
767 Double32_t ratios[ncells];
768 Int_t *dlist = recpoint->GetDigitsList();
769 Float_t *elist = recpoint->GetEnergiesList();
774 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(dlist[
c]));
775 absIds[ncellsTrue] = digit->GetId();
776 ratios[ncellsTrue] = elist[
c]/digit->GetAmplitude();
778 if (digit->GetIparent(1) > 0)
779 mcEnergy += digit->GetDEParent(1)/recpoint->GetEnergy();
786 AliWarning(
"Skipping cluster with no cells");
792 recpoint->GetGlobalPosition(gpos);
796 AliDebug(1, Form(
"energy %f", recpoint->GetEnergy()));
798 AliVCluster *
c =
static_cast<AliVCluster*
>(clus->New(nout++));
799 c->SetType(AliVCluster::kEMCALClusterv1);
800 c->SetE(recpoint->GetEnergy());
802 c->SetNCells(ncellsTrue);
803 c->SetCellsAbsId(absIds);
804 c->SetCellsAmplitudeFraction(ratios);
805 c->SetID(recpoint->GetUniqueID());
806 c->SetDispersion(recpoint->GetDispersion());
807 c->SetEmcCpvDistance(-1);
809 c->SetTOF(recpoint->GetTime()) ;
810 c->SetNExMax(recpoint->GetNExMax());
812 recpoint->GetElipsAxis(elipAxis);
813 c->SetM02(elipAxis[0]*elipAxis[0]);
814 c->SetM20(elipAxis[1]*elipAxis[1]);
815 c->SetMCEnergyFraction(mcEnergy);
820 Int_t parentMult = 0;
821 Int_t *parentList = recpoint->GetParents(parentMult);
822 Float_t *parentListDE = recpoint->GetParentsDE();
824 c->SetLabel(parentList, parentMult);
827 c->SetClusterMCEdepFractionFromEdepArray(parentListDE);
839 for(
Int_t icell = 0; icell < ncellsTrue ; icell++)
843 const AliEMCALDigit * dig = (
const AliEMCALDigit*)
fDigitsArr->At(idigit);
848 mcEdepFracPerCell[icell] = 0;
850 Int_t nparents = dig->GetNiparent();
856 Float_t mcEDepFrac[4] = {0,0,0,0};
859 for (
Int_t jndex = 0 ; jndex < nparents ; jndex++ )
861 digLabel = dig->GetIparent (jndex+1);
862 edep = dig->GetDEParent(jndex+1);
865 if ( digLabel == parentList[0] ) mcEDepFrac[0] = edep;
866 else if ( digLabel == parentList[1] ) mcEDepFrac[1] = edep;
867 else if ( digLabel == parentList[2] ) mcEDepFrac[2] = edep;
868 else if ( digLabel == parentList[3] ) mcEDepFrac[3] = edep;
875 mcEdepFracPerCell[icell] = c->PackMCEdepFraction(mcEDepFrac);
880 c->SetCellsMCEdepFractionMap(mcEdepFracPerCell);
882 delete [] mcEdepFracPerCell;
903 if (ncells!=ndigis) {
907 for (
Int_t idigit = 0; idigit < ndigis; ++idigit) {
908 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(idigit));
909 Double_t cellAmplitude = digit->GetCalibAmp();
910 Short_t cellNumber = digit->GetId();
911 Double_t cellTime = digit->GetTime();
912 fCaloCells->SetCell(idigit, cellNumber, cellAmplitude, cellTime);
922 for (
Int_t i=0;i<nents;++i) {
942 fRun = InputEvent()->GetRunNumber();
954 fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(InputEvent()->
GetRunNumber());
956 AliFatal(
"Geometry not available!!!");
962 for(
Int_t mod=0; mod <
fGeom->GetNumberOfSuperModules(); ++mod) {
964 if (DebugLevel() > 2)
970 for(
Int_t mod=0; mod <
fGeom->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
971 const TGeoHMatrix *gm = 0;
973 gm =
fEsd->GetEMCALMatrix(mod);
975 AliAODHeader *aodheader =
dynamic_cast<AliAODHeader*
>(
fAod->GetHeader());
976 if(!aodheader) AliFatal(
"Not a standard AOD");
978 gm = aodheader->GetEMCALMatrix(mod);
982 if (DebugLevel() > 2)
984 fGeom->SetMisalMatrix(gm,mod);
993 fDigitsArr =
new TClonesArray(
"AliEMCALDigit", 1000);
1003 if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
1005 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN) {
1006 AliEMCALClusterizerNxN *clusterizer =
new AliEMCALClusterizerNxN(
fGeom);
1007 clusterizer->SetNRowDiff(
fRecParam->GetNRowDiff());
1008 clusterizer->SetNColDiff(
fRecParam->GetNColDiff());
1011 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
1013 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerFW) {
1014 AliEMCALClusterizerFixedWindow *clusterizer =
new AliEMCALClusterizerFixedWindow(
fGeom);
1015 clusterizer->SetNphi(
fNPhi);
1016 clusterizer->SetNeta(
fNEta);
1023 AliFatal(Form(
"Clusterizer < %d > not available",
fRecParam->GetClusterizerFlag()));
1028 AliCDBManager *cdb = AliCDBManager::Instance();
1029 if (!cdb->IsDefaultStorageSet() && !
fOCDBpath.IsNull())
1031 if (
fRun!=cdb->GetRun())
1035 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Data"));
1037 fCalibData =
static_cast<AliEMCALCalibData*
>(entry->GetObject());
1039 AliFatal(
"Calibration parameters not found in CDB!");
1042 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Pedestals"));
1044 fPedestalData =
static_cast<AliCaloCalibPedestal*
>(entry->GetObject());
1066 AliError(Form(
"%s: Could not retrieve cells %s!", GetName(),
fCaloCellsName.Data()));
1069 AliFatal(
"Could not get EMCal cells!");
1081 fCaloClusters =
static_cast<TClonesArray*
>(InputEvent()->FindListObject(
"CaloClusters"));
1083 fCaloClusters =
static_cast<TClonesArray*
>(InputEvent()->FindListObject(
"caloClusters"));
1100 AliFatal(
"Could not get cluster collection!");
1103 if (!cl->GetBaseClass(
"AliVCluster")) {
1104 AliFatal(Form(
"%s: Collection %s does not contain AliVCluster objects!", GetName(),
fCaloClusters->GetName()));
virtual void UserExec(Option_t *option)
AliEMCALClusterizer * fClusterizer
void Print(std::ostream &o, const char *name, Double_t dT, Double_t dVM, Double_t alldT, Double_t alldVM)
TString fOutputAODBrName
AOD Branch with output clusters.
AliAODEvent * fAod
esd event
virtual ~AliAnalysisTaskEMCALClusterizeFast()
EMCal data reclusterization.
TObjArray * fClusterArr
digits array
AliEMCALCalibData * fCalibData
Bool_t fSetCellMCLabelFromEdepFrac
TClonesArray * fDigitsArr
run number
AliEMCALAfterBurnerUF * fUnfolder
clusterizer
static const Int_t fgkTotalCellNumber
Bool_t fRecalDistToBadChannels
AliESDEvent * fEsd
calo clusters array
virtual void UserCreateOutputObjects()
AliEMCALRecParam * fRecParam
recpoints array
virtual void TrackClusterMatching(AliVCluster *c, TClonesArray *tarr)
TClonesArray * fCaloClusters
calo cells object
virtual void Clusterize()
AliEMCALRecoUtils * fRecoUtils
virtual void FillDigitsArray()
TClonesArray * fOutputAODBranch
AliCaloCalibPedestal * fPedestalData
virtual void CopyClusters(TClonesArray *orig, TClonesArray *dest)
Int_t fOrgClusterCellId[fgkTotalCellNumber]
Bool_t fRejectExoticCells
Bool_t fJustUnfold
unfolding procedure
AliEMCALGeometry * fGeom
aod event
Int_t fSetCellMCLabelFromCluster
virtual void CalibrateClusters()
virtual void UpdateCells()
TGeoHMatrix * fGeomMatrix[AliEMCALGeoParams::fgkEMCALModules]
virtual void RecPoints2Clusters(TClonesArray *clus)
Int_t GetRunNumber(TString)
AliVCaloCells * fCaloCells
AliAnalysisTaskEMCALClusterizeFast()
Bool_t AcceptCell(Int_t cellNumber)
TString fCaloClustersName
Bool_t fClusterBadChannelCheck
Bool_t fRejectExoticClusters
InputCellType fInputCellType
virtual void UpdateClusters()
Int_t fCellLabels[fgkTotalCellNumber]