19 #include <TObjArray.h> 21 #include <TStopwatch.h> 24 #include "AliCDBEntry.h" 25 #include "AliCDBManager.h" 26 #include "AliCaloCalibPedestal.h" 27 #include "AliEMCALAfterBurnerUF.h" 28 #include "AliEMCALCalibData.h" 29 #include "AliEMCALClusterizerNxN.h" 30 #include "AliEMCALClusterizerv1.h" 31 #include "AliEMCALClusterizerv2.h" 32 #include "AliEMCALClusterizerv3.h" 33 #include "AliEMCALClusterizerFixedWindow.h" 34 #include "AliEMCALDigit.h" 35 #include "AliEMCALGeometry.h" 36 #include "AliEMCALRecParam.h" 37 #include "AliEMCALRecPoint.h" 38 #include "AliInputEventHandler.h" 40 #include "AliAODMCParticle.h" 42 #include "AliAODEvent.h" 43 #include "AliESDEvent.h" 44 #include "AliAnalysisManager.h" 56 {
"kClusterizerv1", AliEMCALRecParam::kClusterizerv1 },
57 {
"kClusterizerNxN", AliEMCALRecParam::kClusterizerNxN },
58 {
"kClusterizerv2", AliEMCALRecParam::kClusterizerv2 },
59 {
"kClusterizerv3", AliEMCALRecParam::kClusterizerv3 },
60 {
"kClusterizerFW", AliEMCALRecParam::kClusterizerFW }
73 fRecParam(new AliEMCALRecParam),
78 fUnfoldCellMinEFrac(0),
80 fGeomMatrixSet(kFALSE),
81 fLoadGeomMatrices(kFALSE),
87 fSubBackground(kFALSE),
93 fTestPatternInput(kFALSE),
94 fSetCellMCLabelFromCluster(0),
95 fSetCellMCLabelFromEdepFrac(0),
96 fRemapMCLabelForAODs(0),
97 fRecalDistToBadChannels(kFALSE),
98 fRecalShowerShape(kFALSE),
103 for(
Int_t i = 0; i < AliEMCALGeoParams::fgkEMCALModules; i++)
fGeomMatrix[i] = 0 ;
126 std::string clusterizerTypeStr =
"";
132 Bool_t unfoldRejectBelowThreshold = kFALSE;
133 GetProperty(
"unfoldRejectBelowThreshold", unfoldRejectBelowThreshold);
152 Bool_t enableFracEMCRecalc = kFALSE;
153 GetProperty(
"enableFracEMCRecalc", enableFracEMCRecalc);
159 Int_t removeNMCGenerators = 0;
160 GetProperty(
"removeNMCGenerators", removeNMCGenerators);
161 Bool_t enableMCGenRemovTrack = 1;
162 GetProperty(
"enableMCGenRemovTrack", enableMCGenRemovTrack);
163 std::string removeMcGen1 =
"";
165 TString removeMCGen1 = removeMcGen1.c_str();
166 std::string removeMcGen2 =
"";
168 TString removeMCGen2 = removeMcGen2.c_str();
170 fRecParam->SetClusterizerFlag(clusterizerType);
172 fRecParam->SetRejectBelowThreshold(unfoldRejectBelowThreshold);
174 fRecParam->SetClusteringThreshold(seedE);
179 fRecParam->SetLocMaxCut(diffEAggregation);
181 if (clusterizerType == AliEMCALRecParam::kClusterizerNxN)
188 if(enableFracEMCRecalc){
192 printf(
"Enable frac MC recalc, remove generators %d \n",removeNMCGenerators);
193 if(removeNMCGenerators > 0)
195 printf(
"\t gen1 <%s>, gen2 <%s>, remove tracks %d\n",removeMCGen1.Data(),removeMCGen2.Data(),enableMCGenRemovTrack);
206 AliFatal(
"Passed more than one cluster container to the clusterizer, but the clusterizer only supports one cluster container!");
220 fHistCPUTime =
new TH1F(
"hCPUTime",
"hCPUTime;CPU Time (ms)", 2000, 0, 1000);
223 fHistRealTime =
new TH1F(
"hRealTime",
"hRealTime;Real Time (ms)", 2000, 0, 1000);
248 AliFatal(
"Could not retrieve cluster container!");
256 AliWarning(Form(
"Number of EMCAL cells = %d, returning",
fCaloCells->GetNumberOfCells()));
263 UInt_t mask1 =
fEsd->GetESDRun()->GetDetectorsInDAQ();
264 UInt_t mask2 =
fEsd->GetESDRun()->GetDetectorsInReco();
265 Bool_t desc1 = (mask1 >> 18) & 0x1;
266 Bool_t desc2 = (mask2 >> 18) & 0x1;
267 if (desc1==0 || desc2==0) {
268 AliError(Form(
"EMCAL not in DAQ/RECO: %u (%u)/%u (%u)",
269 mask1,
fEsd->GetESDRun()->GetDetectorsInReco(),
270 mask2,
fEsd->GetESDRun()->GetDetectorsInDAQ()));
274 offtrigger = ((AliInputEventHandler*)(am->GetInputEventHandler()))->IsEventSelected();
276 offtrigger = ((AliVAODHeader*)
fAod->GetHeader())->GetOfflineTrigger();
280 if (offtrigger & AliVEvent::kFastOnly) {
281 AliError(Form(
"EMCAL not in fast only partition"));
289 AliWarning(
"Unfolding not implemented");
340 for (
Int_t idigit = 0; idigit < maxd; idigit++){
341 if (idigit % 24 == 12) idigit += 12;
342 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->New(idigit));
343 digit->SetId(idigit * 4);
345 digit->SetTimeR(600);
346 digit->SetIndexInList(idigit);
347 digit->SetType(AliEMCALDigit::kHG);
348 digit->SetAmplitude(0.1);
366 for (
Int_t i = 0; i < nClusters; i++)
372 if (!clus->IsEMCAL())
continue ;
374 Int_t label = clus->GetLabel();
375 UShort_t * index = clus->GetCellsAbsId() ;
377 for(
Int_t icell=0; icell < clus->GetNCells(); icell++)
389 for (
Int_t icell = 0, idigit = 0; icell < ncells; ++icell)
392 Double_t cellTime=0, amp = 0, cellEFrac = 0;
394 Int_t cellMCLabel=-1;
395 if (
fCaloCells->GetCell(icell, cellNumber, amp, cellTime, cellMCLabel, cellEFrac) != kTRUE)
407 if (cellMCLabel > 0 && cellEFrac < 1e-6)
410 if (cellAmplitude < 1e-6 || cellNumber < 0)
430 AliInfo(
"Negative original cluster index, skip \n");
436 for(
Int_t icluscell=0; icluscell < clus->GetNCells(); icluscell++ )
438 if(cellNumber != clus->GetCellAbsId(icluscell))
continue ;
442 nLabels = labeArr.GetSize();
446 AliEMCALDigit *digit =
new((*fDigitsArr)[idigit]) AliEMCALDigit(cellMCLabel, cellMCLabel, cellNumber,
447 cellAmplitude, (
Float_t)cellTime,
448 AliEMCALDigit::kHG,idigit, 0, 0, cellEFrac*cellAmplitude);
452 digit->SetListOfParents(nLabels,labeArr.GetArray(),eDepArr.GetArray());
460 digit->SetAmplitude(energy);
468 avgE /=
fGeom->GetNumberOfSuperModules()*48*24;
470 for (
Int_t i = 0; i < ndigis; ++i) {
471 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(i));
474 digit->SetAmplitude(0);
476 digit->SetAmplitude(energy);
490 AliDebug(1, Form(
"total no of clusters %d", Ncls));
492 for(
Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i)
494 AliEMCALRecPoint *recpoint =
static_cast<AliEMCALRecPoint*
>(
fClusterArr->At(i));
496 Int_t ncellsTrue = 0;
497 const Int_t ncells = recpoint->GetMultiplicity();
499 Double32_t ratios[ncells];
500 Int_t *dlist = recpoint->GetDigitsList();
501 Float_t *elist = recpoint->GetEnergiesList();
507 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(dlist[
c]));
508 absIds[ncellsTrue] = digit->GetId();
509 ratios[ncellsTrue] = elist[
c]/digit->GetAmplitude();
511 if ( !
fRecParam->GetUnfold() && (ratios[ncellsTrue] > 1 || ratios[ncellsTrue] < 1) )
512 AliWarning(Form(
"recpoint cell E %2.3f but digit E %2.3f and no unfolding",
513 recpoint->GetEnergiesList()[
c], digit->GetAmplitude()));
522 AliDebug(2,Form(
"Too small energy in cell of cluster: cluster cell %f, digit %f",
523 recpoint->GetEnergiesList()[
c],digit->GetAmplitude()));
529 clusterE += recpoint->GetEnergiesList()[
c];
531 if (digit->GetIparent(1) > 0)
532 mcEnergy += digit->GetDEParent(1)/recpoint->GetEnergy();
539 AliWarning(
"Skipping cluster with no cells");
545 recpoint->GetGlobalPosition(gpos);
549 AliDebug(1, Form(
"energy %f", recpoint->GetEnergy()));
551 AliVCluster *
c =
static_cast<AliVCluster*
>(clus->New(nout++));
552 c->SetType(AliVCluster::kEMCALClusterv1);
555 c->SetNCells(ncellsTrue);
556 c->SetCellsAbsId(absIds);
557 c->SetCellsAmplitudeFraction(ratios);
559 c->SetDispersion(recpoint->GetDispersion());
560 c->SetEmcCpvDistance(-1);
562 c->SetTOF(recpoint->GetTime()) ;
563 c->SetNExMax(recpoint->GetNExMax());
564 c->SetMCEnergyFraction(mcEnergy);
566 if ( ncells == ncellsTrue )
569 recpoint->GetElipsAxis(elipAxis);
570 c->SetM02(elipAxis[0]*elipAxis[0]);
571 c->SetM20(elipAxis[1]*elipAxis[1]);
577 AliDebug(2,Form(
"Cells removed from cluster (ncells %d, ncellsTrue %d), recalculate Shower Shape",ncells,ncellsTrue));
587 Int_t parentMult = 0;
588 Int_t *parentList = recpoint->GetParents(parentMult);
589 Float_t *parentListDE = recpoint->GetParentsDE();
591 c->SetLabel(parentList, parentMult);
593 c->SetClusterMCEdepFractionFromEdepArray(parentListDE);
606 for(
Int_t icell = 0; icell < ncellsTrue ; icell++)
610 const AliEMCALDigit * dig = (
const AliEMCALDigit*)
fDigitsArr->At(idigit);
615 mcEdepFracPerCell[icell] = 0;
617 Int_t nparents = dig->GetNiparent();
623 Float_t mcEDepFrac[4] = {0,0,0,0};
626 for (
Int_t jndex = 0 ; jndex < nparents ; jndex++ )
628 digLabel = dig->GetIparent (jndex+1);
629 edep = dig->GetDEParent(jndex+1);
632 if ( digLabel == parentList[0] ) mcEDepFrac[0] = edep;
633 else if ( digLabel == parentList[1] ) mcEDepFrac[1] = edep;
634 else if ( digLabel == parentList[2] ) mcEDepFrac[2] = edep;
635 else if ( digLabel == parentList[3] ) mcEDepFrac[3] = edep;
642 mcEdepFracPerCell[icell] = c->PackMCEdepFraction(mcEDepFrac);
647 c->SetCellsMCEdepFractionMap(mcEdepFracPerCell);
649 delete [] mcEdepFracPerCell;
678 for (
Int_t icluster=0; icluster < nclusters; ++icluster) {
679 AliVCluster *clust =
static_cast<AliVCluster*
>(
fCaloClusters->At(icluster));
683 if (!clust->IsEMCAL()) {
705 if (label < 0)
return;
707 TClonesArray * arr =
dynamic_cast<TClonesArray*
>(
fAod->FindListObject(
"mcparticles")) ;
710 if (label < arr->GetEntriesFast())
712 AliAODMCParticle * particle =
dynamic_cast<AliAODMCParticle *
>(arr->At(label));
713 if (!particle) return ;
715 if (label == particle->Label())
return ;
719 for (
Int_t ind = 0; ind < arr->GetEntriesFast(); ind++)
721 AliAODMCParticle * particle =
dynamic_cast<AliAODMCParticle *
>(arr->At(ind));
722 if (!particle) continue ;
724 if (label == particle->Label())
745 for(
Int_t irp=0; irp < ncls; ++irp)
750 Int_t nLabTotOrg = 0;
754 AliEMCALRecPoint *clus =
static_cast<AliEMCALRecPoint*
>(
fClusterArr->At(irp));
757 const Int_t ncells = clus->GetMultiplicity();
758 Int_t *digList = clus->GetDigitsList();
760 for (
Int_t iLoopCell = 0 ; iLoopCell < ncells ; iLoopCell++)
762 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(digList[iLoopCell]));
763 Int_t idCell = digit->GetId();
769 for (
Int_t icl =0; icl < nClu; icl++)
771 if (((
Int_t)clArray.GetAt(icl))==-1)
continue;
772 if (idCluster == ((
Int_t)clArray.GetAt(icl)))
set = kFALSE;
774 if (
set && idCluster >= 0)
776 clArray.SetAt(idCluster,nClu++);
781 if (emax < clOrg->E())
791 if (idMax != ((
Int_t)clArray.GetAt(0)))
794 Int_t firstCluster = ((
Int_t)clArray.GetAt(0));
795 for (
Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++)
797 if (idMax == ((
Int_t)clArray.GetAt(iLoopCluster))) maxIndex = iLoopCluster;
800 if (firstCluster >=0 && idMax >=0)
802 clArray.SetAt(idMax,0);
803 clArray.SetAt(firstCluster,maxIndex);
808 TArrayI clMCArray(nLabTotOrg) ;
812 for (
Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++)
814 Int_t idCluster = (
Int_t) clArray.GetAt(iLoopCluster);
816 Int_t nLab = clOrg->GetNLabels();
818 for (
Int_t iLab = 0 ; iLab < nLab ; iLab++)
820 Int_t lab = clOrg->GetLabelAt(iLab) ;
824 for(
Int_t iLabTot =0; iLabTot < nLabTot; iLabTot++)
826 if (lab == ((
Int_t)clMCArray.GetAt(iLabTot)))
set = kFALSE;
828 if (
set) clMCArray.SetAt(lab,nLabTot++);
836 for(
Int_t il = 0; il < nLabTot; il++) labels[il] = clMCArray.GetArray()[il];
837 clus->SetParents(nLabTot,labels);
866 for(
Int_t mod=0; mod <
fGeom->GetNumberOfSuperModules(); ++mod) {
868 if (AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() > 2)
874 for(
Int_t mod=0; mod <
fGeom->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
875 const TGeoHMatrix *gm = 0;
877 gm =
fEsd->GetEMCALMatrix(mod);
879 AliAODHeader *aodheader =
dynamic_cast<AliAODHeader*
>(
fAod->GetHeader());
880 if(!aodheader) AliFatal(
"Not a standard AOD");
882 gm = aodheader->GetEMCALMatrix(mod);
886 if (AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() > 2)
888 fGeom->SetMisalMatrix(gm,mod);
897 fDigitsArr =
new TClonesArray(
"AliEMCALDigit", 1000);
907 if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
909 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN) {
910 AliEMCALClusterizerNxN *clusterizer =
new AliEMCALClusterizerNxN(
fGeom);
911 clusterizer->SetNRowDiff(
fRecParam->GetNRowDiff());
912 clusterizer->SetNColDiff(
fRecParam->GetNColDiff());
915 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
917 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv3)
919 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerFW) {
920 AliEMCALClusterizerFixedWindow *clusterizer =
new AliEMCALClusterizerFixedWindow(
fGeom);
921 clusterizer->SetNphi(
fNPhi);
922 clusterizer->SetNeta(
fNEta);
929 AliFatal(Form(
"Clusterizer < %d > not available",
fRecParam->GetClusterizerFlag()));
934 AliCDBManager *cdb = AliCDBManager::Instance();
935 if (!cdb->IsDefaultStorageSet() && !
fOCDBpath.IsNull())
937 if (
fRun!=cdb->GetRun())
941 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Data"));
943 fCalibData =
static_cast<AliEMCALCalibData*
>(entry->GetObject());
945 AliFatal(
"Calibration parameters not found in CDB!");
948 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Pedestals"));
950 fPedestalData =
static_cast<AliCaloCalibPedestal*
>(entry->GetObject());
979 AliError(
"InitBadChannels returned false, returning");
982 AliWarning(
"InitBadChannels OK");
997 for (
Int_t i=0;i<nents;++i) {
Bool_t fTestPatternInput
Use test pattern as input instead of cells.
void RecalculateCellLabelsRemoveAddedGenerator(Int_t absID, AliVCluster *clus, AliMCEvent *mc, Float_t &, TArrayI &labeArr, TArrayF &eDepArr) const
TStopwatch * fTimer
! Timer for the Run() function (event loop)
Bool_t fRemapMCLabelForAODs
Remap AOD cells MC label.
Int_t fShiftPhi
shift in phi (for FixedWindowsClusterizer)
void Print(std::ostream &o, const char *name, Double_t dT, Double_t dVM, Double_t alldT, Double_t alldVM)
AliEMCALGeometry * fGeom
! Geometry object
static const Int_t fgkTotalCellNumber
Maximum number of cells in EMCAL/DCAL: (48*24)*(10+4/3.+6*2/3.)
virtual ~AliEmcalCorrectionClusterizer()
TClonesArray * fCaloClusters
!calo clusters array
AliEMCALRecParam * fRecParam
reconstruction parameters container
Bool_t fSetCellMCLabelFromEdepFrac
For MC generated with aliroot > v5-07-21, check the EDep information.
Int_t fCellLabels[fgkTotalCellNumber]
Array with MC label/map.
AliAODEvent * fAod
!aod event
void SwitchOffDistToBadChannelRecalculation()
AliEMCALAfterBurnerUF * fUnfolder
!unfolding procedure
Bool_t fLoadPed
access ped object from OCDB (def=off)
Bool_t fTRUShift
shifting inside a TRU (true) or through the whole calorimeter (false) (for FixedWindowsClusterizer) ...
void SetNumberOfMCGeneratorsToAccept(Int_t nGen)
Int_t fShiftEta
shift in eta (for FixedWindowsClusterizer)
TObjArray * fClusterArr
!recpoints array
virtual void UserCreateOutputObjects()
Int_t fNPhi
nPhi (for FixedWindowsClusterizer)
AliVEvent * InputEvent() const
AliVCaloCells * fCaloCells
! Pointer to CaloCells
Some utilities for cluster and cell treatment.
void SwitchOffMCGeneratorToAcceptForTrackMatching()
Bool_t fLoadCalib
access calib object from OCDB (def=off)
AliEMCALRecoUtils * fRecoUtils
Pointer to RecoUtils.
void RecalculateClusterDistanceToBadChannel(const AliEMCALGeometry *geom, AliVCaloCells *cells, AliVCluster *cluster)
TObjArray fClusterCollArray
Cluster collection array.
AliCaloCalibPedestal * fPedestalData
EMCAL pedestal.
void RemapMCLabelForAODs(Int_t &label)
TGeoHMatrix * fGeomMatrix[AliEMCALGeoParams::fgkEMCALModules]
geometry matrices with alignments
AliEMCALClusterizer * fClusterizer
!clusterizer
AliESDEvent * fEsd
!esd event
AliEmcalCorrectionClusterizer()
void RecalculateClusterShowerShapeParameters(const AliEMCALGeometry *geom, AliVCaloCells *cells, AliVCluster *cluster)
Base class for correction components in the EMCal correction framework.
EMCal clusterizer component in the EMCal correction framework.
Int_t fSetCellMCLabelFromCluster
Use cluster MC label as cell label:
Bool_t fRecalShowerShape
switch for recalculation of the shower shape
AliMCEvent * fMCEvent
! MC
Bool_t fSubBackground
subtract background if true (def=off)
Int_t fNEta
nEta (for FixedWinoswsClusterizer)
TList * fOutput
! List of output histograms
void SwitchOnDistToBadChannelRecalculation()
Bool_t fGeomMatrixSet
set geometry matrices only once, for the first event.
Bool_t fCreateHisto
Flag to make some basic histograms.
Bool_t CheckIfRunChanged()
TString fOCDBpath
path with OCDB location
Float_t fUnfoldCellMinE
min energy cell threshold, after unfolding
static RegisterCorrectionComponent< AliEmcalCorrectionClusterizer > reg
Bool_t fRecalDistToBadChannels
recalculate distance to bad channel
static const std::map< std::string, AliEMCALRecParam::AliEMCALClusterizerFlag > fgkClusterizerTypeMap
Relates string to the clusterizer type enumeration for YAML configuration.
virtual Bool_t Initialize()
void RecalculateClusterPosition(const AliEMCALGeometry *geom, AliVCaloCells *cells, AliVCluster *clu)
TH1F * fHistCPUTime
! CPU time for the Run() function (event loop)
AliEMCALCalibData * fCalibData
EMCAL calib data.
Int_t fOrgClusterCellId[fgkTotalCellNumber]
Array ID of cluster to which the cell belongs in unmodified clusters.
AliEmcalCorrectionEventManager fEventManager
Minimal task which inherits from AliAnalysisTaskSE and manages access to the event.
void UserCreateOutputObjects()
Float_t fUnfoldCellMinEFrac
min fraction of cell energy after unfolding
virtual Bool_t CheckIfRunChanged()
void SetClustersMCLabelFromOriginalClusters()
Bool_t fJustUnfold
just unfold, do not recluster
void RecPoints2Clusters(TClonesArray *clus)
Bool_t fLoadGeomMatrices
matrices from configuration, not geometry.root nor ESDs/AODs
void ClearEMCalClusters()
AliClusterContainer * GetClusterContainer(Int_t i=0) const
TH1F * fHistRealTime
! Real time for the Run() function (event loop)
Container structure for EMCAL clusters.
TClonesArray * fDigitsArr
!digits array
TString fFilepass
Input data pass number.
bool GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.
void SetNameOfMCGeneratorsToAccept(Int_t ig, TString name)