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 ; }
107 AliAnalysisTaskSE(name),
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 ;
199 fEsd =
dynamic_cast<AliESDEvent*
>(InputEvent());
200 fAod =
dynamic_cast<AliAODEvent*
>(InputEvent());
203 Error(
"UserExec",
"Event not available");
209 UInt_t offtrigger = 0;
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()));
221 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
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);
277 Float_t pos[3] = {0};
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++)
381 const Int_t ncells =
fCaloCells->GetNumberOfCells();
382 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell)
384 Double_t cellAmplitude=0, cellTime=0, cellEFrac = 0;
385 Short_t cellNumber=0;
386 Int_t cellMCLabel=-1;
387 if (
fCaloCells->GetCell(icell, cellNumber, cellAmplitude, cellTime, cellMCLabel, cellEFrac) != kTRUE)
392 if (cellMCLabel > 0 && cellEFrac < 1e-6)
395 if (cellAmplitude < 1e-6 || cellNumber < 0)
399 if (cellMCLabel <= 0)
402 cellAmplitude *= cellEFrac;
410 cellAmplitude *= 1 - cellEFrac;
417 AliEMCALDigit *digit =
new((*fDigitsArr)[idigit]) AliEMCALDigit(cellMCLabel, cellMCLabel, cellNumber,
418 (Float_t)cellAmplitude, (Float_t)cellTime,
419 AliEMCALDigit::kHG,idigit, 0, 0, cellEFrac*cellAmplitude);
423 Float_t
energy = cellAmplitude;
424 Float_t time = cellTime;
426 digit->SetAmplitude(energy);
436 AliVCluster *clus = 0;
441 AliInfo(
"Negative original cluster index, skip \n");
445 clus = InputEvent()->GetCaloCluster(iclus);
447 for(Int_t icluscell=0; icluscell < clus->GetNCells(); icluscell++ )
449 if(cellNumber != clus->GetCellAbsId(icluscell))
continue ;
453 clus->GetCellMCEdepFractionArray(icluscell,eDepFrac);
459 for(Int_t imc = 0; imc < 4; imc++)
461 if(eDepFrac[imc] > 0 && clus->GetNLabels() > imc)
465 labeArr.Set(nLabels);
466 labeArr.AddAt(clus->GetLabelAt(imc), nLabels-1);
468 eDepArr.Set(nLabels);
469 eDepArr.AddAt(eDepFrac[imc]*cellAmplitude, nLabels-1);
476 digit->SetListOfParents(nLabels,labeArr.GetArray(),eDepArr.GetArray());
486 avgE /=
fGeom->GetNumberOfSuperModules()*48*24;
488 for (Int_t i = 0; i < ndigis; ++i) {
489 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(i));
490 Double_t
energy = digit->GetAmplitude() - avgE;
492 digit->SetAmplitude(0);
494 digit->SetAmplitude(energy);
504 Int_t maxd =
fGeom->GetNCells() / 4;
505 for (Int_t idigit = 0; idigit < maxd; idigit++){
506 if (idigit % 24 == 12) idigit += 12;
507 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->New(idigit));
508 digit->SetId(idigit * 4);
510 digit->SetTimeR(600);
511 digit->SetIndexInList(idigit);
512 digit->SetType(AliEMCALDigit::kHG);
513 digit->SetAmplitude(0.1);
524 AliVCaloTrigger *triggers = InputEvent()->GetCaloTrigger(
"EMCAL");
526 if (!triggers || !(triggers->GetEntries() > 0))
532 while ((triggers->Next())) {
533 Float_t L0Amplitude = 0;
534 triggers->GetAmplitude(L0Amplitude);
539 Int_t L1Amplitude = 0;
540 triggers->GetL1TimeSum(L1Amplitude);
545 Int_t triggerTime = 0;
547 triggers->GetNL0Times(ntimes);
554 triggers->GetL0Times(trgtimes);
555 triggerTime = trgtimes[0];
558 Int_t triggerCol = 0, triggerRow = 0;
559 triggers->GetPosition(triggerCol, triggerRow);
562 fGeom->GetAbsFastORIndexFromPositionInEMCAL(triggerCol, triggerRow, find);
567 Int_t cidx[4] = {-1};
568 Bool_t ret =
fGeom->GetCellIndexFromFastORIndex(find, cidx);
573 Float_t triggerAmplitude = 0;
576 triggerAmplitude = 0.25 * L1Amplitude;
579 triggerAmplitude = L0Amplitude;
582 for (Int_t idxpos = 0; idxpos < 4; idxpos++) {
583 Int_t triggerNumber = cidx[idxpos];
584 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->New(idigit));
585 digit->SetId(triggerNumber);
586 digit->SetTime(triggerTime);
587 digit->SetTimeR(triggerTime);
588 digit->SetIndexInList(idigit);
589 digit->SetType(AliEMCALDigit::kHG);
590 digit->SetAmplitude(triggerAmplitude);
602 Bool_t accept = kTRUE;
605 Bool_t exRemoval =
fRecoUtils->IsRejectExoticCell();
607 Int_t bunchCrossNo = InputEvent()->GetBunchCrossNumber();
609 if(isEx) accept = kFALSE;
610 if(!exRemoval)
fRecoUtils->SwitchOffRejectExoticCell();
622 for (Int_t icluster=0; icluster < nclusters; ++icluster) {
623 AliVCluster *clust =
static_cast<AliVCluster*
>(
fCaloClusters->At(icluster));
626 if (!clust->IsEMCAL())
634 Bool_t badRemoval =
fRecoUtils->IsBadChannelsRemovalSwitchedOn();
637 Bool_t badResult =
fRecoUtils->ClusterContainsBadChannel(
fGeom, clust->GetCellsAbsId(), clust->GetNCells());
656 Bool_t exRemoval =
fRecoUtils->IsRejectExoticCell();
660 Int_t bunchCrossNo = InputEvent()->GetBunchCrossNumber();
686 Float_t correctedEnergy =
fRecoUtils->CorrectClusterEnergyLinearity(clust);
687 clust->SetE(correctedEnergy);
705 Double_t dEtaMin = 1e9;
706 Double_t dPhiMin = 1e9;
708 Double_t ceta = gpos.Eta();
709 Double_t cphi = gpos.Phi();
710 const Int_t ntrks = tarr->GetEntries();
711 for(Int_t t = 0; t<ntrks; ++t) {
712 AliVTrack *track =
static_cast<AliVTrack*
>(tarr->At(t));
715 const AliExternalTrackParam *outp = track->GetOuterParam();
718 Double_t trkPos[3] = {0.,0.,0.};
719 if (!outp->GetXYZ(trkPos))
721 TVector3 vec(trkPos[0],trkPos[1],trkPos[2]);
722 Double_t veta = vec.Eta();
723 Double_t vphi = vec.Phi();
725 vphi += 2*TMath::Pi();
726 if (TMath::Abs(veta)>0.75 || (vphi<70*TMath::DegToRad()) || (vphi>190*TMath::DegToRad()))
728 Double_t dR = vec.DeltaR(gpos);
731 Float_t tmpEta=0, tmpPhi=0;
733 AliExternalTrackParam trkParTemp(*outp);
738 tmpEta = ceta - veta;
739 tmpPhi = cphi - vphi;
741 if (TMath::Abs(tmpEta)<TMath::Abs(dEtaMin) && TMath::Abs(tmpPhi)<TMath::Abs(dPhiMin)) {
747 c->SetEmcCpvDistance(imin);
748 c->SetTrackDistance(dPhiMin, dEtaMin);
757 TClonesArray *tarr = 0;
759 tarr =
dynamic_cast<TClonesArray*
>(InputEvent()->FindListObject(
fTrackName));
761 AliError(Form(
"Cannot get tracks named %s",
fTrackName.Data()));
766 AliDebug(1, Form(
"total no of clusters %d", Ncls));
768 for(Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i)
770 AliEMCALRecPoint *recpoint =
static_cast<AliEMCALRecPoint*
>(
fClusterArr->At(i));
772 Int_t ncellsTrue = 0;
773 const Int_t ncells = recpoint->GetMultiplicity();
774 UShort_t absIds[ncells];
775 Double32_t ratios[ncells];
776 Int_t *dlist = recpoint->GetDigitsList();
777 Float_t *elist = recpoint->GetEnergiesList();
778 Double_t mcEnergy = 0;
780 for (Int_t c = 0; c < ncells; ++c)
782 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(dlist[c]));
783 absIds[ncellsTrue] = digit->GetId();
784 ratios[ncellsTrue] = elist[c]/recpoint->GetEnergy();
786 if (digit->GetIparent(1) > 0)
787 mcEnergy += digit->GetDEParent(1)/recpoint->GetEnergy();
794 AliWarning(
"Skipping cluster with no cells");
800 recpoint->GetGlobalPosition(gpos);
804 AliDebug(1, Form(
"energy %f", recpoint->GetEnergy()));
806 AliVCluster *c =
static_cast<AliVCluster*
>(clus->New(nout++));
807 c->SetType(AliVCluster::kEMCALClusterv1);
808 c->SetE(recpoint->GetEnergy());
810 c->SetNCells(ncellsTrue);
811 c->SetCellsAbsId(absIds);
812 c->SetCellsAmplitudeFraction(ratios);
813 c->SetID(recpoint->GetUniqueID());
814 c->SetDispersion(recpoint->GetDispersion());
815 c->SetEmcCpvDistance(-1);
817 c->SetTOF(recpoint->GetTime()) ;
818 c->SetNExMax(recpoint->GetNExMax());
820 recpoint->GetElipsAxis(elipAxis);
821 c->SetM02(elipAxis[0]*elipAxis[0]);
822 c->SetM20(elipAxis[1]*elipAxis[1]);
823 c->SetMCEnergyFraction(mcEnergy);
828 Int_t parentMult = 0;
829 Int_t *parentList = recpoint->GetParents(parentMult);
830 Float_t *parentListDE = recpoint->GetParentsDE();
832 c->SetLabel(parentList, parentMult);
833 c->SetClusterMCEdepFractionFromEdepArray(parentListDE);
840 UInt_t * mcEdepFracPerCell =
new UInt_t[ncellsTrue];
845 for(Int_t icell = 0; icell < ncellsTrue ; icell++)
849 const AliEMCALDigit * dig = (
const AliEMCALDigit*)
fDigitsArr->At(idigit);
854 mcEdepFracPerCell[icell] = 0;
856 Int_t nparents = dig->GetNiparent();
861 Float_t edepTot = 0 ;
862 Float_t mcEDepFrac[4] = {0,0,0,0};
865 for ( Int_t jndex = 0 ; jndex < nparents ; jndex++ )
867 digLabel = dig->GetIparent (jndex+1);
868 edep = dig->GetDEParent(jndex+1);
871 if ( digLabel == parentList[0] ) mcEDepFrac[0] = edep;
872 else if ( digLabel == parentList[1] ) mcEDepFrac[1] = edep;
873 else if ( digLabel == parentList[2] ) mcEDepFrac[2] = edep;
874 else if ( digLabel == parentList[3] ) mcEDepFrac[3] = edep;
881 mcEdepFracPerCell[icell] = c->PackMCEdepFraction(mcEDepFrac);
886 c->SetCellsMCEdepFractionMap(mcEdepFracPerCell);
888 delete [] mcEdepFracPerCell;
907 const Int_t ncells =
fCaloCells->GetNumberOfCells();
908 const Int_t ndigis =
fDigitsArr->GetEntries();
909 if (ncells!=ndigis) {
913 for (Int_t idigit = 0; idigit < ndigis; ++idigit) {
914 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(idigit));
915 Double_t cellAmplitude = digit->GetCalibAmp();
916 Short_t cellNumber = digit->GetId();
917 Double_t cellTime = digit->GetTime();
918 fCaloCells->SetCell(idigit, cellNumber, cellAmplitude, cellTime);
928 for (Int_t i=0;i<nents;++i) {
929 AliVCluster *c =
static_cast<AliVCluster*
>(
fCaloClusters->At(i));
948 fRun = InputEvent()->GetRunNumber();
960 fGeom = AliEMCALGeometry::GetInstance();
962 AliFatal(
"Geometry not available!!!");
968 for(Int_t mod=0; mod <
fGeom->GetNumberOfSuperModules(); ++mod) {
970 if (DebugLevel() > 2)
976 for(Int_t mod=0; mod <
fGeom->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
977 const TGeoHMatrix *gm = 0;
979 gm =
fEsd->GetEMCALMatrix(mod);
981 AliAODHeader *aodheader =
dynamic_cast<AliAODHeader*
>(
fAod->GetHeader());
982 if(!aodheader) AliFatal(
"Not a standard AOD");
984 gm = aodheader->GetEMCALMatrix(mod);
988 if (DebugLevel() > 2)
990 fGeom->SetMisalMatrix(gm,mod);
999 fDigitsArr =
new TClonesArray(
"AliEMCALDigit", 1000);
1009 if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
1011 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN) {
1012 AliEMCALClusterizerNxN *clusterizer =
new AliEMCALClusterizerNxN(
fGeom);
1013 clusterizer->SetNRowDiff(
fRecParam->GetNRowDiff());
1014 clusterizer->SetNColDiff(
fRecParam->GetNColDiff());
1017 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
1019 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerFW) {
1020 AliEMCALClusterizerFixedWindow *clusterizer =
new AliEMCALClusterizerFixedWindow(
fGeom);
1021 clusterizer->SetNphi(
fNPhi);
1022 clusterizer->SetNeta(
fNEta);
1029 AliFatal(Form(
"Clusterizer < %d > not available",
fRecParam->GetClusterizerFlag()));
1034 AliCDBManager *cdb = AliCDBManager::Instance();
1035 if (!cdb->IsDefaultStorageSet() && !
fOCDBpath.IsNull())
1037 if (
fRun!=cdb->GetRun())
1041 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Data"));
1043 fCalibData =
static_cast<AliEMCALCalibData*
>(entry->GetObject());
1045 AliFatal(
"Calibration parameters not found in CDB!");
1048 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Pedestals"));
1050 fPedestalData =
static_cast<AliCaloCalibPedestal*
>(entry->GetObject());
1072 AliError(Form(
"%s: Could not retrieve cells %s!", GetName(),
fCaloCellsName.Data()));
1075 AliFatal(
"Could not get EMCal cells!");
1087 fCaloClusters =
static_cast<TClonesArray*
>(InputEvent()->FindListObject(
"CaloClusters"));
1089 fCaloClusters =
static_cast<TClonesArray*
>(InputEvent()->FindListObject(
"caloClusters"));
1106 AliFatal(
"Could not get cluster collection!");
1109 if (!cl->GetBaseClass(
"AliVCluster")) {
1110 AliFatal(Form(
"%s: Collection %s does not contain AliVCluster objects!", GetName(),
fCaloClusters->GetName()));
virtual void UserExec(Option_t *option)
AliEMCALClusterizer * fClusterizer
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]
ClassImp(AliAnalysisTaskEMCALClusterizeFast) AliAnalysisTaskEMCALClusterizeFast
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]