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 "AliEMCALClusterizerFixedWindow.h"
33 #include "AliEMCALDigit.h"
34 #include "AliEMCALGeometry.h"
35 #include "AliEMCALRecParam.h"
36 #include "AliEMCALRecPoint.h"
37 #include "AliInputEventHandler.h"
39 #include "AliAODMCParticle.h"
40 #include "AliEMCALRecoUtils.h"
41 #include "AliAODEvent.h"
42 #include "AliESDEvent.h"
43 #include "AliAnalysisManager.h"
55 {
"kClusterizerv1", AliEMCALRecParam::kClusterizerv1 },
56 {
"kClusterizerNxN", AliEMCALRecParam::kClusterizerNxN },
57 {
"kClusterizerv2", AliEMCALRecParam::kClusterizerv2 },
58 {
"kClusterizerFW", AliEMCALRecParam::kClusterizerFW }
71 fRecParam(new AliEMCALRecParam),
76 fGeomMatrixSet(kFALSE),
77 fLoadGeomMatrices(kFALSE),
83 fSubBackground(kFALSE),
89 fTestPatternInput(kFALSE),
90 fSetCellMCLabelFromCluster(0),
91 fSetCellMCLabelFromEdepFrac(0),
92 fRemapMCLabelForAODs(0),
93 fRecalDistToBadChannels(kFALSE),
94 fRecalShowerShape(kFALSE),
99 for(
Int_t i = 0; i < AliEMCALGeoParams::fgkEMCALModules; i++)
fGeomMatrix[i] = 0 ;
122 std::string clusterizerTypeStr =
"";
140 Bool_t enableFracEMCRecalc = kFALSE;
141 GetProperty(
"enableFracEMCRecalc", enableFracEMCRecalc);
147 Int_t removeNMCGenerators = 0;
148 GetProperty(
"removeNMCGenerators", removeNMCGenerators);
149 Bool_t enableMCGenRemovTrack = 1;
150 GetProperty(
"enableMCGenRemovTrack", enableMCGenRemovTrack);
151 std::string removeMcGen1 =
"";
153 TString removeMCGen1 = removeMcGen1.c_str();
154 std::string removeMcGen2 =
"";
156 TString removeMCGen2 = removeMcGen2.c_str();
158 fRecParam->SetClusterizerFlag(clusterizerType);
160 fRecParam->SetClusteringThreshold(seedE);
165 fRecParam->SetLocMaxCut(diffEAggregation);
167 if (clusterizerType == AliEMCALRecParam::kClusterizerNxN)
174 if(enableFracEMCRecalc){
178 printf(
"Enable frac MC recalc, remove generators %d \n",removeNMCGenerators);
179 if(removeNMCGenerators > 0)
181 printf(
"\t gen1 <%s>, gen2 <%s>, remove tracks %d\n",removeMCGen1.Data(),removeMCGen2.Data(),enableMCGenRemovTrack);
182 fRecoUtils->SetNumberOfMCGeneratorsToAccept(removeNMCGenerators) ;
183 fRecoUtils->SetNameOfMCGeneratorsToAccept(0,removeMCGen1);
184 fRecoUtils->SetNameOfMCGeneratorsToAccept(1,removeMCGen2);
186 if(!enableMCGenRemovTrack)
fRecoUtils->SwitchOffMCGeneratorToAcceptForTrackMatching();
192 AliFatal(
"Passed more than one cluster container to the clusterizer, but the clusterizer only supports one cluster container!");
206 fHistCPUTime =
new TH1F(
"hCPUTime",
"hCPUTime;CPU Time (ms)", 2000, 0, 1000);
209 fHistRealTime =
new TH1F(
"hRealTime",
"hRealTime;Real Time (ms)", 2000, 0, 1000);
234 AliFatal(
"Could not retrieve cluster container!");
242 AliWarning(Form(
"Number of EMCAL cells = %d, returning",
fCaloCells->GetNumberOfCells()));
249 UInt_t mask1 =
fEsd->GetESDRun()->GetDetectorsInDAQ();
250 UInt_t mask2 =
fEsd->GetESDRun()->GetDetectorsInReco();
251 Bool_t desc1 = (mask1 >> 18) & 0x1;
252 Bool_t desc2 = (mask2 >> 18) & 0x1;
253 if (desc1==0 || desc2==0) {
254 AliError(Form(
"EMCAL not in DAQ/RECO: %u (%u)/%u (%u)",
255 mask1,
fEsd->GetESDRun()->GetDetectorsInReco(),
256 mask2,
fEsd->GetESDRun()->GetDetectorsInDAQ()));
260 offtrigger = ((AliInputEventHandler*)(am->GetInputEventHandler()))->IsEventSelected();
262 offtrigger = ((AliVAODHeader*)
fAod->GetHeader())->GetOfflineTrigger();
266 if (offtrigger & AliVEvent::kFastOnly) {
267 AliError(Form(
"EMCAL not in fast only partition"));
275 AliWarning(
"Unfolding not implemented");
326 for (
Int_t idigit = 0; idigit < maxd; idigit++){
327 if (idigit % 24 == 12) idigit += 12;
328 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->New(idigit));
329 digit->SetId(idigit * 4);
331 digit->SetTimeR(600);
332 digit->SetIndexInList(idigit);
333 digit->SetType(AliEMCALDigit::kHG);
334 digit->SetAmplitude(0.1);
352 for (
Int_t i = 0; i < nClusters; i++)
358 if (!clus->IsEMCAL())
continue ;
360 Int_t label = clus->GetLabel();
361 UShort_t * index = clus->GetCellsAbsId() ;
363 for(
Int_t icell=0; icell < clus->GetNCells(); icell++)
375 for (
Int_t icell = 0, idigit = 0; icell < ncells; ++icell)
378 Double_t cellTime=0, amp = 0, cellEFrac = 0;
380 Int_t cellMCLabel=-1;
381 if (
fCaloCells->GetCell(icell, cellNumber, amp, cellTime, cellMCLabel, cellEFrac) != kTRUE)
393 if (cellMCLabel > 0 && cellEFrac < 1e-6)
396 if (cellAmplitude < 1e-6 || cellNumber < 0)
416 AliInfo(
"Negative original cluster index, skip \n");
422 for(
Int_t icluscell=0; icluscell < clus->GetNCells(); icluscell++ )
424 if(cellNumber != clus->GetCellAbsId(icluscell))
continue ;
427 fRecoUtils->RecalculateCellLabelsRemoveAddedGenerator(cellNumber, clus,
fMCEvent, cellAmplitude, labeArr, eDepArr);
428 nLabels = labeArr.GetSize();
432 AliEMCALDigit *digit =
new((*fDigitsArr)[idigit]) AliEMCALDigit(cellMCLabel, cellMCLabel, cellNumber,
433 cellAmplitude, (
Float_t)cellTime,
434 AliEMCALDigit::kHG,idigit, 0, 0, cellEFrac*cellAmplitude);
438 digit->SetListOfParents(nLabels,labeArr.GetArray(),eDepArr.GetArray());
446 digit->SetAmplitude(energy);
454 avgE /=
fGeom->GetNumberOfSuperModules()*48*24;
456 for (
Int_t i = 0; i < ndigis; ++i) {
457 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(i));
460 digit->SetAmplitude(0);
462 digit->SetAmplitude(energy);
476 AliDebug(1, Form(
"total no of clusters %d", Ncls));
478 for(
Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i)
480 AliEMCALRecPoint *recpoint =
static_cast<AliEMCALRecPoint*
>(
fClusterArr->At(i));
482 Int_t ncellsTrue = 0;
483 const Int_t ncells = recpoint->GetMultiplicity();
485 Double32_t ratios[ncells];
486 Int_t *dlist = recpoint->GetDigitsList();
487 Float_t *elist = recpoint->GetEnergiesList();
492 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(dlist[
c]));
493 absIds[ncellsTrue] = digit->GetId();
494 ratios[ncellsTrue] = elist[
c]/digit->GetAmplitude();
496 if (digit->GetIparent(1) > 0)
497 mcEnergy += digit->GetDEParent(1)/recpoint->GetEnergy();
504 AliWarning(
"Skipping cluster with no cells");
510 recpoint->GetGlobalPosition(gpos);
514 AliDebug(1, Form(
"energy %f", recpoint->GetEnergy()));
516 AliVCluster *
c =
static_cast<AliVCluster*
>(clus->New(nout++));
517 c->SetType(AliVCluster::kEMCALClusterv1);
518 c->SetE(recpoint->GetEnergy());
520 c->SetNCells(ncellsTrue);
521 c->SetCellsAbsId(absIds);
522 c->SetCellsAmplitudeFraction(ratios);
524 c->SetDispersion(recpoint->GetDispersion());
525 c->SetEmcCpvDistance(-1);
527 c->SetTOF(recpoint->GetTime()) ;
528 c->SetNExMax(recpoint->GetNExMax());
530 recpoint->GetElipsAxis(elipAxis);
531 c->SetM02(elipAxis[0]*elipAxis[0]);
532 c->SetM20(elipAxis[1]*elipAxis[1]);
533 c->SetMCEnergyFraction(mcEnergy);
538 Int_t parentMult = 0;
539 Int_t *parentList = recpoint->GetParents(parentMult);
540 Float_t *parentListDE = recpoint->GetParentsDE();
542 c->SetLabel(parentList, parentMult);
544 c->SetClusterMCEdepFractionFromEdepArray(parentListDE);
557 for(
Int_t icell = 0; icell < ncellsTrue ; icell++)
561 const AliEMCALDigit * dig = (
const AliEMCALDigit*)
fDigitsArr->At(idigit);
566 mcEdepFracPerCell[icell] = 0;
568 Int_t nparents = dig->GetNiparent();
574 Float_t mcEDepFrac[4] = {0,0,0,0};
577 for (
Int_t jndex = 0 ; jndex < nparents ; jndex++ )
579 digLabel = dig->GetIparent (jndex+1);
580 edep = dig->GetDEParent(jndex+1);
583 if ( digLabel == parentList[0] ) mcEDepFrac[0] = edep;
584 else if ( digLabel == parentList[1] ) mcEDepFrac[1] = edep;
585 else if ( digLabel == parentList[2] ) mcEDepFrac[2] = edep;
586 else if ( digLabel == parentList[3] ) mcEDepFrac[3] = edep;
593 mcEdepFracPerCell[icell] = c->PackMCEdepFraction(mcEDepFrac);
598 c->SetCellsMCEdepFractionMap(mcEdepFracPerCell);
600 delete [] mcEdepFracPerCell;
629 for (
Int_t icluster=0; icluster < nclusters; ++icluster) {
630 AliVCluster *clust =
static_cast<AliVCluster*
>(
fCaloClusters->At(icluster));
634 if (!clust->IsEMCAL()) {
656 if (label < 0)
return;
658 TClonesArray * arr =
dynamic_cast<TClonesArray*
>(
fAod->FindListObject(
"mcparticles")) ;
661 if (label < arr->GetEntriesFast())
663 AliAODMCParticle * particle =
dynamic_cast<AliAODMCParticle *
>(arr->At(label));
664 if (!particle) return ;
666 if (label == particle->Label())
return ;
670 for (
Int_t ind = 0; ind < arr->GetEntriesFast(); ind++)
672 AliAODMCParticle * particle =
dynamic_cast<AliAODMCParticle *
>(arr->At(ind));
673 if (!particle) continue ;
675 if (label == particle->Label())
696 for(
Int_t irp=0; irp < ncls; ++irp)
701 Int_t nLabTotOrg = 0;
705 AliEMCALRecPoint *clus =
static_cast<AliEMCALRecPoint*
>(
fClusterArr->At(irp));
708 const Int_t ncells = clus->GetMultiplicity();
709 Int_t *digList = clus->GetDigitsList();
711 for (
Int_t iLoopCell = 0 ; iLoopCell < ncells ; iLoopCell++)
713 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(digList[iLoopCell]));
714 Int_t idCell = digit->GetId();
720 for (
Int_t icl =0; icl < nClu; icl++)
722 if (((
Int_t)clArray.GetAt(icl))==-1)
continue;
723 if (idCluster == ((
Int_t)clArray.GetAt(icl))) set = kFALSE;
725 if (set && idCluster >= 0)
727 clArray.SetAt(idCluster,nClu++);
732 if (emax < clOrg->E())
742 if (idMax != ((
Int_t)clArray.GetAt(0)))
745 Int_t firstCluster = ((
Int_t)clArray.GetAt(0));
746 for (
Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++)
748 if (idMax == ((
Int_t)clArray.GetAt(iLoopCluster))) maxIndex = iLoopCluster;
751 if (firstCluster >=0 && idMax >=0)
753 clArray.SetAt(idMax,0);
754 clArray.SetAt(firstCluster,maxIndex);
759 TArrayI clMCArray(nLabTotOrg) ;
763 for (
Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++)
765 Int_t idCluster = (
Int_t) clArray.GetAt(iLoopCluster);
767 Int_t nLab = clOrg->GetNLabels();
769 for (
Int_t iLab = 0 ; iLab < nLab ; iLab++)
771 Int_t lab = clOrg->GetLabelAt(iLab) ;
775 for(
Int_t iLabTot =0; iLabTot < nLabTot; iLabTot++)
777 if (lab == ((
Int_t)clMCArray.GetAt(iLabTot))) set = kFALSE;
779 if (set) clMCArray.SetAt(lab,nLabTot++);
787 for(
Int_t il = 0; il < nLabTot; il++) labels[il] = clMCArray.GetArray()[il];
788 clus->SetParents(nLabTot,labels);
802 fRecoUtils->SwitchOnDistToBadChannelRecalculation();
804 fRecoUtils->SwitchOffDistToBadChannelRecalculation();
817 for(
Int_t mod=0; mod <
fGeom->GetNumberOfSuperModules(); ++mod) {
819 if (AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() > 2)
825 for(
Int_t mod=0; mod <
fGeom->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
826 const TGeoHMatrix *gm = 0;
828 gm =
fEsd->GetEMCALMatrix(mod);
830 AliAODHeader *aodheader =
dynamic_cast<AliAODHeader*
>(
fAod->GetHeader());
831 if(!aodheader) AliFatal(
"Not a standard AOD");
833 gm = aodheader->GetEMCALMatrix(mod);
837 if (AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() > 2)
839 fGeom->SetMisalMatrix(gm,mod);
848 fDigitsArr =
new TClonesArray(
"AliEMCALDigit", 1000);
858 if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
860 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN) {
861 AliEMCALClusterizerNxN *clusterizer =
new AliEMCALClusterizerNxN(
fGeom);
862 clusterizer->SetNRowDiff(
fRecParam->GetNRowDiff());
863 clusterizer->SetNColDiff(
fRecParam->GetNColDiff());
866 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
868 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerFW) {
869 AliEMCALClusterizerFixedWindow *clusterizer =
new AliEMCALClusterizerFixedWindow(
fGeom);
870 clusterizer->SetNphi(
fNPhi);
871 clusterizer->SetNeta(
fNEta);
878 AliFatal(Form(
"Clusterizer < %d > not available",
fRecParam->GetClusterizerFlag()));
883 AliCDBManager *cdb = AliCDBManager::Instance();
884 if (!cdb->IsDefaultStorageSet() && !
fOCDBpath.IsNull())
886 if (
fRun!=cdb->GetRun())
890 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Data"));
892 fCalibData =
static_cast<AliEMCALCalibData*
>(entry->GetObject());
894 AliFatal(
"Calibration parameters not found in CDB!");
897 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Pedestals"));
899 fPedestalData =
static_cast<AliCaloCalibPedestal*
>(entry->GetObject());
927 AliError(
"InitBadChannels returned false, returning");
930 AliWarning(
"InitBadChannels OK");
945 for (
Int_t i=0;i<nents;++i) {
Bool_t fTestPatternInput
Use test pattern as input instead of cells.
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
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) ...
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
Bool_t fLoadCalib
access calib object from OCDB (def=off)
AliEMCALRecoUtils * fRecoUtils
Pointer to RecoUtils.
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()
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
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
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()
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()
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.