19 #include <TObjArray.h>
23 #include "AliCDBEntry.h"
24 #include "AliCDBManager.h"
25 #include "AliCaloCalibPedestal.h"
26 #include "AliEMCALAfterBurnerUF.h"
27 #include "AliEMCALCalibData.h"
28 #include "AliEMCALClusterizerNxN.h"
29 #include "AliEMCALClusterizerv1.h"
30 #include "AliEMCALClusterizerv2.h"
31 #include "AliEMCALClusterizerFixedWindow.h"
32 #include "AliEMCALDigit.h"
33 #include "AliEMCALGeometry.h"
34 #include "AliEMCALRecParam.h"
35 #include "AliEMCALRecPoint.h"
36 #include "AliInputEventHandler.h"
38 #include "AliAODMCParticle.h"
39 #include "AliEMCALRecoUtils.h"
40 #include "AliAODEvent.h"
41 #include "AliESDEvent.h"
42 #include "AliAnalysisManager.h"
58 fRecParam(new AliEMCALRecParam),
63 fGeomMatrixSet(kFALSE),
64 fLoadGeomMatrices(kFALSE),
70 fSubBackground(kFALSE),
76 fInputCellType(kFEEData),
77 fSetCellMCLabelFromCluster(0),
78 fSetCellMCLabelFromEdepFrac(0),
79 fRemapMCLabelForAODs(0),
83 fRecalDistToBadChannels(kFALSE),
84 fRecalShowerShape(kFALSE)
87 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
89 for(
Int_t i = 0; i < AliEMCALGeoParams::fgkEMCALModules; i++)
fGeomMatrix[i] = 0 ;
108 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
114 std::string clusterizerTypeStr =
"";
132 Bool_t enableFracEMCRecalc = kFALSE;
133 GetProperty(
"enableFracEMCRecalc", enableFracEMCRecalc);
138 Int_t removeNMCGenerators = 0;
139 GetProperty(
"removeNMCGenerators", removeNMCGenerators);
140 Bool_t enableMCGenRemovTrack = 1;
141 GetProperty(
"enableMCGenRemovTrack", enableMCGenRemovTrack);
142 std::string removeMcGen1 =
"";
144 TString removeMCGen1 = removeMcGen1.c_str();
145 std::string removeMcGen2 =
"";
147 TString removeMCGen2 = removeMcGen2.c_str();
149 fRecParam->SetClusterizerFlag(clusterizerType);
151 fRecParam->SetClusteringThreshold(seedE);
156 fRecParam->SetLocMaxCut(diffEAggregation);
158 if (clusterizerType == AliEMCALRecParam::kClusterizerNxN)
161 if(enableFracEMCRecalc){
165 printf(
"Enable frac MC recalc, remove generators %d \n",removeNMCGenerators);
166 if(removeNMCGenerators > 0)
168 printf(
"\t gen1 <%s>, gen2 <%s>, remove tracks %d\n",removeMCGen1.Data(),removeMCGen2.Data(),enableMCGenRemovTrack);
169 fRecoUtils->SetNumberOfMCGeneratorsToAccept(removeNMCGenerators) ;
170 fRecoUtils->SetNameOfMCGeneratorsToAccept(0,removeMCGen1);
171 fRecoUtils->SetNameOfMCGeneratorsToAccept(1,removeMCGen2);
173 if(!enableMCGenRemovTrack)
fRecoUtils->SwitchOffMCGeneratorToAcceptForTrackMatching();
186 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
195 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
207 UInt_t mask1 =
fEsd->GetESDRun()->GetDetectorsInDAQ();
208 UInt_t mask2 =
fEsd->GetESDRun()->GetDetectorsInReco();
209 Bool_t desc1 = (mask1 >> 18) & 0x1;
210 Bool_t desc2 = (mask2 >> 18) & 0x1;
211 if (desc1==0 || desc2==0) {
212 AliError(Form(
"EMCAL not in DAQ/RECO: %u (%u)/%u (%u)",
213 mask1,
fEsd->GetESDRun()->GetDetectorsInReco(),
214 mask2,
fEsd->GetESDRun()->GetDetectorsInDAQ()));
218 offtrigger = ((AliInputEventHandler*)(am->GetInputEventHandler()))->IsEventSelected();
220 offtrigger = ((AliVAODHeader*)
fAod->GetHeader())->GetOfflineTrigger();
224 if (offtrigger & AliVEvent::kFastOnly) {
225 AliError(Form(
"EMCAL not in fast only partition"));
233 AliWarning(
"Unfolding not implemented");
292 Int_t nClusters =
fEvent->GetNumberOfCaloClusters();
293 for (
Int_t i = 0; i < nClusters; i++)
295 AliVCluster *clus =
fEvent->GetCaloCluster(i);
299 if (!clus->IsEMCAL())
continue ;
301 Int_t label = clus->GetLabel();
302 UShort_t * index = clus->GetCellsAbsId() ;
304 for(
Int_t icell=0; icell < clus->GetNCells(); icell++)
316 for (
Int_t icell = 0, idigit = 0; icell < ncells; ++icell)
319 Double_t cellTime=0, amp = 0, cellEFrac = 0;
321 Int_t cellMCLabel=-1;
322 if (
fCaloCells->GetCell(icell, cellNumber, amp, cellTime, cellMCLabel, cellEFrac) != kTRUE)
334 if (cellMCLabel > 0 && cellEFrac < 1e-6)
337 if (cellAmplitude < 1e-6 || cellNumber < 0)
341 if (cellMCLabel <= 0)
344 cellAmplitude *= cellEFrac;
352 cellAmplitude *= 1 - cellEFrac;
374 AliInfo(
"Negative original cluster index, skip \n");
378 AliVCluster* clus =
fEvent->GetCaloCluster(iclus);
380 for(
Int_t icluscell=0; icluscell < clus->GetNCells(); icluscell++ )
382 if(cellNumber != clus->GetCellAbsId(icluscell))
continue ;
385 fRecoUtils->RecalculateCellLabelsRemoveAddedGenerator(cellNumber, clus,
fMCEvent, cellAmplitude, labeArr, eDepArr);
386 nLabels = labeArr.GetSize();
390 AliEMCALDigit *digit =
new((*fDigitsArr)[idigit]) AliEMCALDigit(cellMCLabel, cellMCLabel, cellNumber,
391 cellAmplitude, (
Float_t)cellTime,
392 AliEMCALDigit::kHG,idigit, 0, 0, cellEFrac*cellAmplitude);
396 digit->SetListOfParents(nLabels,labeArr.GetArray(),eDepArr.GetArray());
404 digit->SetAmplitude(energy);
412 avgE /=
fGeom->GetNumberOfSuperModules()*48*24;
414 for (
Int_t i = 0; i < ndigis; ++i) {
415 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(i));
418 digit->SetAmplitude(0);
420 digit->SetAmplitude(energy);
431 for (
Int_t idigit = 0; idigit < maxd; idigit++){
432 if (idigit % 24 == 12) idigit += 12;
433 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->New(idigit));
434 digit->SetId(idigit * 4);
436 digit->SetTimeR(600);
437 digit->SetIndexInList(idigit);
438 digit->SetType(AliEMCALDigit::kHG);
439 digit->SetAmplitude(0.1);
450 AliVCaloTrigger *triggers =
fEvent->GetCaloTrigger(
"EMCAL");
452 if (!triggers || !(triggers->GetEntries() > 0))
458 while ((triggers->Next())) {
460 triggers->GetAmplitude(L0Amplitude);
465 Int_t L1Amplitude = 0;
466 triggers->GetL1TimeSum(L1Amplitude);
471 Int_t triggerTime = 0;
473 triggers->GetNL0Times(ntimes);
480 triggers->GetL0Times(trgtimes);
481 triggerTime = trgtimes[0];
484 Int_t triggerCol = 0, triggerRow = 0;
485 triggers->GetPosition(triggerCol, triggerRow);
488 fGeom->GetAbsFastORIndexFromPositionInEMCAL(triggerCol, triggerRow, find);
493 Int_t cidx[4] = {-1};
494 Bool_t ret =
fGeom->GetCellIndexFromFastORIndex(find, cidx);
502 triggerAmplitude = 0.25 * L1Amplitude;
505 triggerAmplitude = L0Amplitude;
508 for (
Int_t idxpos = 0; idxpos < 4; idxpos++) {
509 Int_t triggerNumber = cidx[idxpos];
510 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->New(idigit));
511 digit->SetId(triggerNumber);
512 digit->SetTime(triggerTime);
513 digit->SetTimeR(triggerTime);
514 digit->SetIndexInList(idigit);
515 digit->SetType(AliEMCALDigit::kHG);
516 digit->SetAmplitude(triggerAmplitude);
532 AliDebug(1, Form(
"total no of clusters %d", Ncls));
534 for(
Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i)
536 AliEMCALRecPoint *recpoint =
static_cast<AliEMCALRecPoint*
>(
fClusterArr->At(i));
538 Int_t ncellsTrue = 0;
539 const Int_t ncells = recpoint->GetMultiplicity();
541 Double32_t ratios[ncells];
542 Int_t *dlist = recpoint->GetDigitsList();
543 Float_t *elist = recpoint->GetEnergiesList();
548 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(dlist[
c]));
549 absIds[ncellsTrue] = digit->GetId();
550 ratios[ncellsTrue] = elist[
c]/digit->GetAmplitude();
552 if (digit->GetIparent(1) > 0)
553 mcEnergy += digit->GetDEParent(1)/recpoint->GetEnergy();
560 AliWarning(
"Skipping cluster with no cells");
566 recpoint->GetGlobalPosition(gpos);
570 AliDebug(1, Form(
"energy %f", recpoint->GetEnergy()));
572 AliVCluster *
c =
static_cast<AliVCluster*
>(clus->New(nout++));
573 c->SetType(AliVCluster::kEMCALClusterv1);
574 c->SetE(recpoint->GetEnergy());
576 c->SetNCells(ncellsTrue);
577 c->SetCellsAbsId(absIds);
578 c->SetCellsAmplitudeFraction(ratios);
579 c->SetID(recpoint->GetUniqueID());
580 c->SetDispersion(recpoint->GetDispersion());
581 c->SetEmcCpvDistance(-1);
583 c->SetTOF(recpoint->GetTime()) ;
584 c->SetNExMax(recpoint->GetNExMax());
586 recpoint->GetElipsAxis(elipAxis);
587 c->SetM02(elipAxis[0]*elipAxis[0]);
588 c->SetM20(elipAxis[1]*elipAxis[1]);
589 c->SetMCEnergyFraction(mcEnergy);
594 Int_t parentMult = 0;
595 Int_t *parentList = recpoint->GetParents(parentMult);
596 Float_t *parentListDE = recpoint->GetParentsDE();
598 c->SetLabel(parentList, parentMult);
600 c->SetClusterMCEdepFractionFromEdepArray(parentListDE);
613 for(
Int_t icell = 0; icell < ncellsTrue ; icell++)
617 const AliEMCALDigit * dig = (
const AliEMCALDigit*)
fDigitsArr->At(idigit);
622 mcEdepFracPerCell[icell] = 0;
624 Int_t nparents = dig->GetNiparent();
630 Float_t mcEDepFrac[4] = {0,0,0,0};
633 for (
Int_t jndex = 0 ; jndex < nparents ; jndex++ )
635 digLabel = dig->GetIparent (jndex+1);
636 edep = dig->GetDEParent(jndex+1);
639 if ( digLabel == parentList[0] ) mcEDepFrac[0] = edep;
640 else if ( digLabel == parentList[1] ) mcEDepFrac[1] = edep;
641 else if ( digLabel == parentList[2] ) mcEDepFrac[2] = edep;
642 else if ( digLabel == parentList[3] ) mcEDepFrac[3] = edep;
649 mcEdepFracPerCell[icell] = c->PackMCEdepFraction(mcEDepFrac);
654 c->SetCellsMCEdepFractionMap(mcEdepFracPerCell);
656 delete [] mcEdepFracPerCell;
673 for (
Int_t i=0;i<nents;++i) {
692 for (
Int_t icluster=0; icluster < nclusters; ++icluster) {
693 AliVCluster *clust =
static_cast<AliVCluster*
>(
fCaloClusters->At(icluster));
714 if (label < 0)
return;
716 TClonesArray * arr =
dynamic_cast<TClonesArray*
>(
fAod->FindListObject(
"mcparticles")) ;
719 if (label < arr->GetEntriesFast())
721 AliAODMCParticle * particle =
dynamic_cast<AliAODMCParticle *
>(arr->At(label));
722 if (!particle) return ;
724 if (label == particle->Label())
return ;
728 for (
Int_t ind = 0; ind < arr->GetEntriesFast(); ind++)
730 AliAODMCParticle * particle =
dynamic_cast<AliAODMCParticle *
>(arr->At(ind));
731 if (!particle) continue ;
733 if (label == particle->Label())
754 for(
Int_t irp=0; irp < ncls; ++irp)
759 Int_t nLabTotOrg = 0;
763 AliEMCALRecPoint *clus =
static_cast<AliEMCALRecPoint*
>(
fClusterArr->At(irp));
766 const Int_t ncells = clus->GetMultiplicity();
767 Int_t *digList = clus->GetDigitsList();
769 for (
Int_t iLoopCell = 0 ; iLoopCell < ncells ; iLoopCell++)
771 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(digList[iLoopCell]));
772 Int_t idCell = digit->GetId();
778 for (
Int_t icl =0; icl < nClu; icl++)
780 if (((
Int_t)clArray.GetAt(icl))==-1)
continue;
781 if (idCluster == ((
Int_t)clArray.GetAt(icl))) set = kFALSE;
783 if (set && idCluster >= 0)
785 clArray.SetAt(idCluster,nClu++);
786 nLabTotOrg+=(
fEvent->GetCaloCluster(idCluster))->GetNLabels();
789 AliVCluster * clOrg =
fEvent->GetCaloCluster(idCluster);
790 if (emax < clOrg->E())
800 if (idMax != ((
Int_t)clArray.GetAt(0)))
803 Int_t firstCluster = ((
Int_t)clArray.GetAt(0));
804 for (
Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++)
806 if (idMax == ((
Int_t)clArray.GetAt(iLoopCluster))) maxIndex = iLoopCluster;
809 if (firstCluster >=0 && idMax >=0)
811 clArray.SetAt(idMax,0);
812 clArray.SetAt(firstCluster,maxIndex);
817 TArrayI clMCArray(nLabTotOrg) ;
821 for (
Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++)
823 Int_t idCluster = (
Int_t) clArray.GetAt(iLoopCluster);
824 AliVCluster * clOrg =
fEvent->GetCaloCluster(idCluster);
825 Int_t nLab = clOrg->GetNLabels();
827 for (
Int_t iLab = 0 ; iLab < nLab ; iLab++)
829 Int_t lab = clOrg->GetLabelAt(iLab) ;
833 for(
Int_t iLabTot =0; iLabTot < nLabTot; iLabTot++)
835 if (lab == ((
Int_t)clMCArray.GetAt(iLabTot))) set = kFALSE;
837 if (set) clMCArray.SetAt(lab,nLabTot++);
845 for(
Int_t il = 0; il < nLabTot; il++) labels[il] = clMCArray.GetArray()[il];
846 clus->SetParents(nLabTot,labels);
870 fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(
fRun);
872 AliFatal(
"Geometry not available!!!");
878 for(
Int_t mod=0; mod <
fGeom->GetNumberOfSuperModules(); ++mod) {
880 if (AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() > 2)
886 for(
Int_t mod=0; mod <
fGeom->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
887 const TGeoHMatrix *gm = 0;
889 gm =
fEsd->GetEMCALMatrix(mod);
891 AliAODHeader *aodheader =
dynamic_cast<AliAODHeader*
>(
fAod->GetHeader());
892 if(!aodheader) AliFatal(
"Not a standard AOD");
894 gm = aodheader->GetEMCALMatrix(mod);
898 if (AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() > 2)
900 fGeom->SetMisalMatrix(gm,mod);
909 fDigitsArr =
new TClonesArray(
"AliEMCALDigit", 1000);
919 if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
921 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN) {
922 AliEMCALClusterizerNxN *clusterizer =
new AliEMCALClusterizerNxN(
fGeom);
923 clusterizer->SetNRowDiff(
fRecParam->GetNRowDiff());
924 clusterizer->SetNColDiff(
fRecParam->GetNColDiff());
927 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
929 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerFW) {
930 AliEMCALClusterizerFixedWindow *clusterizer =
new AliEMCALClusterizerFixedWindow(
fGeom);
931 clusterizer->SetNphi(
fNPhi);
932 clusterizer->SetNeta(
fNEta);
939 AliFatal(Form(
"Clusterizer < %d > not available",
fRecParam->GetClusterizerFlag()));
944 AliCDBManager *cdb = AliCDBManager::Instance();
945 if (!cdb->IsDefaultStorageSet() && !
fOCDBpath.IsNull())
947 if (
fRun!=cdb->GetRun())
951 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Data"));
953 fCalibData =
static_cast<AliEMCALCalibData*
>(entry->GetObject());
955 AliFatal(
"Calibration parameters not found in CDB!");
958 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Pedestals"));
960 fPedestalData =
static_cast<AliCaloCalibPedestal*
>(entry->GetObject());
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.
std::map< std::string, AliEMCALRecParam::AliEMCALClusterizerFlag > clusterizerTypeMap
TString fGeomName
name of geometry to use.
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.
AliCaloCalibPedestal * fPedestalData
EMCAL pedestal.
AliClusterContainer * fClusCont
Pointer to the cluster container.
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)
InputCellType fInputCellType
input cells type to make clusters
Int_t fNEta
nEta (for FixedWinoswsClusterizer)
AliVEvent * fEvent
! Pointer to event
Bool_t fGeomMatrixSet
set geometry matrices only once, for the first event.
TString fOCDBpath
path with OCDB location
static RegisterCorrectionComponent< AliEmcalCorrectionClusterizer > reg
Bool_t fRecalDistToBadChannels
recalculate distance to bad channel
virtual Bool_t Initialize()
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()
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
TClonesArray * fDigitsArr
!digits array
bool GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.