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 }
68 fRecParam(new AliEMCALRecParam),
73 fGeomMatrixSet(kFALSE),
74 fLoadGeomMatrices(kFALSE),
80 fSubBackground(kFALSE),
86 fTestPatternInput(kFALSE),
87 fSetCellMCLabelFromCluster(0),
88 fSetCellMCLabelFromEdepFrac(0),
89 fRemapMCLabelForAODs(0),
93 fRecalDistToBadChannels(kFALSE),
94 fRecalShowerShape(kFALSE)
96 for(
Int_t i = 0; i < AliEMCALGeoParams::fgkEMCALModules; i++)
fGeomMatrix[i] = 0 ;
119 std::string clusterizerTypeStr =
"";
137 Bool_t enableFracEMCRecalc = kFALSE;
138 GetProperty(
"enableFracEMCRecalc", enableFracEMCRecalc);
144 Int_t removeNMCGenerators = 0;
145 GetProperty(
"removeNMCGenerators", removeNMCGenerators);
146 Bool_t enableMCGenRemovTrack = 1;
147 GetProperty(
"enableMCGenRemovTrack", enableMCGenRemovTrack);
148 std::string removeMcGen1 =
"";
150 TString removeMCGen1 = removeMcGen1.c_str();
151 std::string removeMcGen2 =
"";
153 TString removeMCGen2 = removeMcGen2.c_str();
155 fRecParam->SetClusterizerFlag(clusterizerType);
157 fRecParam->SetClusteringThreshold(seedE);
162 fRecParam->SetLocMaxCut(diffEAggregation);
164 if (clusterizerType == AliEMCALRecParam::kClusterizerNxN)
171 if(enableFracEMCRecalc){
175 printf(
"Enable frac MC recalc, remove generators %d \n",removeNMCGenerators);
176 if(removeNMCGenerators > 0)
178 printf(
"\t gen1 <%s>, gen2 <%s>, remove tracks %d\n",removeMCGen1.Data(),removeMCGen2.Data(),enableMCGenRemovTrack);
179 fRecoUtils->SetNumberOfMCGeneratorsToAccept(removeNMCGenerators) ;
180 fRecoUtils->SetNameOfMCGeneratorsToAccept(0,removeMCGen1);
181 fRecoUtils->SetNameOfMCGeneratorsToAccept(1,removeMCGen2);
183 if(!enableMCGenRemovTrack)
fRecoUtils->SwitchOffMCGeneratorToAcceptForTrackMatching();
189 AliFatal(
"Passed more than one cluster container to the clusterizer, but the clusterizer only supports one cluster container!");
203 fHistCPUTime =
new TH1F(
"hCPUTime",
"hCPUTime;CPU Time (ms)", 2000, 0, 1000);
206 fHistRealTime =
new TH1F(
"hRealTime",
"hRealTime;Real Time (ms)", 2000, 0, 1000);
231 AliFatal(
"Could not retrieve cluster container!");
239 AliWarning(Form(
"Number of EMCAL cells = %d, returning",
fCaloCells->GetNumberOfCells()));
246 UInt_t mask1 =
fEsd->GetESDRun()->GetDetectorsInDAQ();
247 UInt_t mask2 =
fEsd->GetESDRun()->GetDetectorsInReco();
248 Bool_t desc1 = (mask1 >> 18) & 0x1;
249 Bool_t desc2 = (mask2 >> 18) & 0x1;
250 if (desc1==0 || desc2==0) {
251 AliError(Form(
"EMCAL not in DAQ/RECO: %u (%u)/%u (%u)",
252 mask1,
fEsd->GetESDRun()->GetDetectorsInReco(),
253 mask2,
fEsd->GetESDRun()->GetDetectorsInDAQ()));
257 offtrigger = ((AliInputEventHandler*)(am->GetInputEventHandler()))->IsEventSelected();
259 offtrigger = ((AliVAODHeader*)
fAod->GetHeader())->GetOfflineTrigger();
263 if (offtrigger & AliVEvent::kFastOnly) {
264 AliError(Form(
"EMCAL not in fast only partition"));
272 AliWarning(
"Unfolding not implemented");
323 for (
Int_t idigit = 0; idigit < maxd; idigit++){
324 if (idigit % 24 == 12) idigit += 12;
325 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->New(idigit));
326 digit->SetId(idigit * 4);
328 digit->SetTimeR(600);
329 digit->SetIndexInList(idigit);
330 digit->SetType(AliEMCALDigit::kHG);
331 digit->SetAmplitude(0.1);
348 Int_t nClusters =
fEvent->GetNumberOfCaloClusters();
349 for (
Int_t i = 0; i < nClusters; i++)
351 AliVCluster *clus =
fEvent->GetCaloCluster(i);
355 if (!clus->IsEMCAL())
continue ;
357 Int_t label = clus->GetLabel();
358 UShort_t * index = clus->GetCellsAbsId() ;
360 for(
Int_t icell=0; icell < clus->GetNCells(); icell++)
372 for (
Int_t icell = 0, idigit = 0; icell < ncells; ++icell)
375 Double_t cellTime=0, amp = 0, cellEFrac = 0;
377 Int_t cellMCLabel=-1;
378 if (
fCaloCells->GetCell(icell, cellNumber, amp, cellTime, cellMCLabel, cellEFrac) != kTRUE)
390 if (cellMCLabel > 0 && cellEFrac < 1e-6)
393 if (cellAmplitude < 1e-6 || cellNumber < 0)
413 AliInfo(
"Negative original cluster index, skip \n");
417 AliVCluster* clus =
fEvent->GetCaloCluster(iclus);
419 for(
Int_t icluscell=0; icluscell < clus->GetNCells(); icluscell++ )
421 if(cellNumber != clus->GetCellAbsId(icluscell))
continue ;
424 fRecoUtils->RecalculateCellLabelsRemoveAddedGenerator(cellNumber, clus,
fMCEvent, cellAmplitude, labeArr, eDepArr);
425 nLabels = labeArr.GetSize();
429 AliEMCALDigit *digit =
new((*fDigitsArr)[idigit]) AliEMCALDigit(cellMCLabel, cellMCLabel, cellNumber,
430 cellAmplitude, (
Float_t)cellTime,
431 AliEMCALDigit::kHG,idigit, 0, 0, cellEFrac*cellAmplitude);
435 digit->SetListOfParents(nLabels,labeArr.GetArray(),eDepArr.GetArray());
443 digit->SetAmplitude(energy);
451 avgE /=
fGeom->GetNumberOfSuperModules()*48*24;
453 for (
Int_t i = 0; i < ndigis; ++i) {
454 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(i));
457 digit->SetAmplitude(0);
459 digit->SetAmplitude(energy);
473 AliDebug(1, Form(
"total no of clusters %d", Ncls));
475 for(
Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i)
477 AliEMCALRecPoint *recpoint =
static_cast<AliEMCALRecPoint*
>(
fClusterArr->At(i));
479 Int_t ncellsTrue = 0;
480 const Int_t ncells = recpoint->GetMultiplicity();
482 Double32_t ratios[ncells];
483 Int_t *dlist = recpoint->GetDigitsList();
484 Float_t *elist = recpoint->GetEnergiesList();
489 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(dlist[
c]));
490 absIds[ncellsTrue] = digit->GetId();
491 ratios[ncellsTrue] = elist[
c]/digit->GetAmplitude();
493 if (digit->GetIparent(1) > 0)
494 mcEnergy += digit->GetDEParent(1)/recpoint->GetEnergy();
501 AliWarning(
"Skipping cluster with no cells");
507 recpoint->GetGlobalPosition(gpos);
511 AliDebug(1, Form(
"energy %f", recpoint->GetEnergy()));
513 AliVCluster *
c =
static_cast<AliVCluster*
>(clus->New(nout++));
514 c->SetType(AliVCluster::kEMCALClusterv1);
515 c->SetE(recpoint->GetEnergy());
517 c->SetNCells(ncellsTrue);
518 c->SetCellsAbsId(absIds);
519 c->SetCellsAmplitudeFraction(ratios);
521 c->SetDispersion(recpoint->GetDispersion());
522 c->SetEmcCpvDistance(-1);
524 c->SetTOF(recpoint->GetTime()) ;
525 c->SetNExMax(recpoint->GetNExMax());
527 recpoint->GetElipsAxis(elipAxis);
528 c->SetM02(elipAxis[0]*elipAxis[0]);
529 c->SetM20(elipAxis[1]*elipAxis[1]);
530 c->SetMCEnergyFraction(mcEnergy);
535 Int_t parentMult = 0;
536 Int_t *parentList = recpoint->GetParents(parentMult);
537 Float_t *parentListDE = recpoint->GetParentsDE();
539 c->SetLabel(parentList, parentMult);
541 c->SetClusterMCEdepFractionFromEdepArray(parentListDE);
554 for(
Int_t icell = 0; icell < ncellsTrue ; icell++)
558 const AliEMCALDigit * dig = (
const AliEMCALDigit*)
fDigitsArr->At(idigit);
563 mcEdepFracPerCell[icell] = 0;
565 Int_t nparents = dig->GetNiparent();
571 Float_t mcEDepFrac[4] = {0,0,0,0};
574 for (
Int_t jndex = 0 ; jndex < nparents ; jndex++ )
576 digLabel = dig->GetIparent (jndex+1);
577 edep = dig->GetDEParent(jndex+1);
580 if ( digLabel == parentList[0] ) mcEDepFrac[0] = edep;
581 else if ( digLabel == parentList[1] ) mcEDepFrac[1] = edep;
582 else if ( digLabel == parentList[2] ) mcEDepFrac[2] = edep;
583 else if ( digLabel == parentList[3] ) mcEDepFrac[3] = edep;
590 mcEdepFracPerCell[icell] = c->PackMCEdepFraction(mcEDepFrac);
595 c->SetCellsMCEdepFractionMap(mcEdepFracPerCell);
597 delete [] mcEdepFracPerCell;
626 for (
Int_t icluster=0; icluster < nclusters; ++icluster) {
627 AliVCluster *clust =
static_cast<AliVCluster*
>(
fCaloClusters->At(icluster));
649 if (label < 0)
return;
651 TClonesArray * arr =
dynamic_cast<TClonesArray*
>(
fAod->FindListObject(
"mcparticles")) ;
654 if (label < arr->GetEntriesFast())
656 AliAODMCParticle * particle =
dynamic_cast<AliAODMCParticle *
>(arr->At(label));
657 if (!particle) return ;
659 if (label == particle->Label())
return ;
663 for (
Int_t ind = 0; ind < arr->GetEntriesFast(); ind++)
665 AliAODMCParticle * particle =
dynamic_cast<AliAODMCParticle *
>(arr->At(ind));
666 if (!particle) continue ;
668 if (label == particle->Label())
689 for(
Int_t irp=0; irp < ncls; ++irp)
694 Int_t nLabTotOrg = 0;
698 AliEMCALRecPoint *clus =
static_cast<AliEMCALRecPoint*
>(
fClusterArr->At(irp));
701 const Int_t ncells = clus->GetMultiplicity();
702 Int_t *digList = clus->GetDigitsList();
704 for (
Int_t iLoopCell = 0 ; iLoopCell < ncells ; iLoopCell++)
706 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(digList[iLoopCell]));
707 Int_t idCell = digit->GetId();
713 for (
Int_t icl =0; icl < nClu; icl++)
715 if (((
Int_t)clArray.GetAt(icl))==-1)
continue;
716 if (idCluster == ((
Int_t)clArray.GetAt(icl))) set = kFALSE;
718 if (set && idCluster >= 0)
720 clArray.SetAt(idCluster,nClu++);
721 nLabTotOrg+=(
fEvent->GetCaloCluster(idCluster))->GetNLabels();
724 AliVCluster * clOrg =
fEvent->GetCaloCluster(idCluster);
725 if (emax < clOrg->E())
735 if (idMax != ((
Int_t)clArray.GetAt(0)))
738 Int_t firstCluster = ((
Int_t)clArray.GetAt(0));
739 for (
Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++)
741 if (idMax == ((
Int_t)clArray.GetAt(iLoopCluster))) maxIndex = iLoopCluster;
744 if (firstCluster >=0 && idMax >=0)
746 clArray.SetAt(idMax,0);
747 clArray.SetAt(firstCluster,maxIndex);
752 TArrayI clMCArray(nLabTotOrg) ;
756 for (
Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++)
758 Int_t idCluster = (
Int_t) clArray.GetAt(iLoopCluster);
759 AliVCluster * clOrg =
fEvent->GetCaloCluster(idCluster);
760 Int_t nLab = clOrg->GetNLabels();
762 for (
Int_t iLab = 0 ; iLab < nLab ; iLab++)
764 Int_t lab = clOrg->GetLabelAt(iLab) ;
768 for(
Int_t iLabTot =0; iLabTot < nLabTot; iLabTot++)
770 if (lab == ((
Int_t)clMCArray.GetAt(iLabTot))) set = kFALSE;
772 if (set) clMCArray.SetAt(lab,nLabTot++);
780 for(
Int_t il = 0; il < nLabTot; il++) labels[il] = clMCArray.GetArray()[il];
781 clus->SetParents(nLabTot,labels);
795 fRecoUtils->SwitchOnDistToBadChannelRecalculation();
797 fRecoUtils->SwitchOffDistToBadChannelRecalculation();
810 for(
Int_t mod=0; mod <
fGeom->GetNumberOfSuperModules(); ++mod) {
812 if (AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() > 2)
818 for(
Int_t mod=0; mod <
fGeom->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
819 const TGeoHMatrix *gm = 0;
821 gm =
fEsd->GetEMCALMatrix(mod);
823 AliAODHeader *aodheader =
dynamic_cast<AliAODHeader*
>(
fAod->GetHeader());
824 if(!aodheader) AliFatal(
"Not a standard AOD");
826 gm = aodheader->GetEMCALMatrix(mod);
830 if (AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() > 2)
832 fGeom->SetMisalMatrix(gm,mod);
841 fDigitsArr =
new TClonesArray(
"AliEMCALDigit", 1000);
851 if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
853 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN) {
854 AliEMCALClusterizerNxN *clusterizer =
new AliEMCALClusterizerNxN(
fGeom);
855 clusterizer->SetNRowDiff(
fRecParam->GetNRowDiff());
856 clusterizer->SetNColDiff(
fRecParam->GetNColDiff());
859 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
861 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerFW) {
862 AliEMCALClusterizerFixedWindow *clusterizer =
new AliEMCALClusterizerFixedWindow(
fGeom);
863 clusterizer->SetNphi(
fNPhi);
864 clusterizer->SetNeta(
fNEta);
871 AliFatal(Form(
"Clusterizer < %d > not available",
fRecParam->GetClusterizerFlag()));
876 AliCDBManager *cdb = AliCDBManager::Instance();
877 if (!cdb->IsDefaultStorageSet() && !
fOCDBpath.IsNull())
879 if (
fRun!=cdb->GetRun())
883 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Data"));
885 fCalibData =
static_cast<AliEMCALCalibData*
>(entry->GetObject());
887 AliFatal(
"Calibration parameters not found in CDB!");
890 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Pedestals"));
892 fPedestalData =
static_cast<AliCaloCalibPedestal*
>(entry->GetObject());
920 AliError(
"InitBadChannels returned false, returning");
923 AliWarning(
"InitBadChannels OK");
926 AliWarning(Form(
"No external hot channel set: %d - %s",
fEvent->GetRunNumber(),
fFilepass.Data()));
938 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)
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)
AliVEvent * fEvent
! Pointer to event
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)
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
AliEMCALCalibData * fCalibData
EMCAL calib data.
Int_t fOrgClusterCellId[fgkTotalCellNumber]
Array ID of cluster to which the cell belongs in unmodified clusters.
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.