25 #include <TClonesArray.h>
26 #include <TGeoManager.h>
27 #include <TObjArray.h>
33 #include "AliAODCaloCluster.h"
34 #include "AliAODEvent.h"
35 #include "AliAnalysisManager.h"
36 #include "AliCDBEntry.h"
37 #include "AliCDBManager.h"
38 #include "AliCaloCalibPedestal.h"
39 #include "AliEMCALAfterBurnerUF.h"
40 #include "AliEMCALCalibData.h"
41 #include "AliEMCALClusterizerNxN.h"
42 #include "AliEMCALClusterizerv1.h"
43 #include "AliEMCALClusterizerv2.h"
44 #include "AliEMCALClusterizerFixedWindow.h"
45 #include "AliEMCALDigit.h"
46 #include "AliEMCALGeometry.h"
47 #include "AliEMCALRecParam.h"
48 #include "AliEMCALRecPoint.h"
49 #include "AliEMCALRecoUtils.h"
50 #include "AliESDEvent.h"
51 #include "AliInputEventHandler.h"
64 fRecParam(new AliEMCALRecParam),
69 fGeomMatrixSet(kFALSE),
70 fLoadGeomMatrices(kFALSE),
79 fAttachClusters(kTRUE),
80 fSubBackground(kFALSE),
86 fInputCellType(kFEEData),
89 fCaloClustersName("newCaloClusters"),
90 fDoUpdateCells(kFALSE),
92 fClusterBadChannelCheck(kFALSE),
93 fRejectExoticClusters(kFALSE),
94 fRejectExoticCells(kFALSE),
96 fDoNonLinearity(kFALSE),
97 fRecalDistToBadChannels(kFALSE),
98 fSetCellMCLabelFromCluster(0),
107 for(Int_t i = 0; i < 12; ++i)
113 AliAnalysisTaskSE(name),
117 fRecParam(new AliEMCALRecParam),
122 fGeomMatrixSet(kFALSE),
123 fLoadGeomMatrices(kFALSE),
132 fAttachClusters(kTRUE),
133 fSubBackground(kFALSE),
139 fInputCellType(kFEEData),
142 fCaloClustersName(
"newCaloClusters"),
143 fDoUpdateCells(kFALSE),
144 fDoClusterize(kTRUE),
145 fClusterBadChannelCheck(kFALSE),
146 fRejectExoticClusters(kFALSE),
147 fRejectExoticCells(kFALSE),
149 fDoNonLinearity(kFALSE),
150 fRecalDistToBadChannels(kFALSE),
151 fSetCellMCLabelFromCluster(0),
160 fBranchNames =
"ESD:AliESDHeader.,AliESDRun.,EMCALCells.,EMCALTrigger. AOD:header,emcalCells";
161 for(Int_t i = 0; i < 12; ++i)
202 fEsd =
dynamic_cast<AliESDEvent*
>(InputEvent());
203 fAod =
dynamic_cast<AliAODEvent*
>(InputEvent());
206 Error(
"UserExec",
"Event not available");
212 UInt_t offtrigger = 0;
214 UInt_t mask1 =
fEsd->GetESDRun()->GetDetectorsInDAQ();
215 UInt_t mask2 =
fEsd->GetESDRun()->GetDetectorsInReco();
216 Bool_t desc1 = (mask1 >> 18) & 0x1;
217 Bool_t desc2 = (mask2 >> 18) & 0x1;
218 if (desc1==0 || desc2==0) {
219 AliError(Form(
"EMCAL not in DAQ/RECO: %u (%u)/%u (%u)",
220 mask1,
fEsd->GetESDRun()->GetDetectorsInReco(),
221 mask2,
fEsd->GetESDRun()->GetDetectorsInDAQ()));
224 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
225 offtrigger = ((AliInputEventHandler*)(am->GetInputEventHandler()))->IsEventSelected();
227 offtrigger = ((AliVAODHeader*)
fAod->GetHeader())->GetOfflineTrigger();
231 if (offtrigger & AliVEvent::kFastOnly) {
232 AliError(Form(
"EMCAL not in fast only partition"));
240 AliWarning(
"Unfolding not implemented");
266 const Int_t Ncls = orig->GetEntries();
268 for(Int_t i=0; i < Ncls; ++i) {
269 AliVCluster *oc =
static_cast<AliVCluster*
>(orig->At(i));
277 AliVCluster *dc =
static_cast<AliVCluster*
>(dest->New(i));
278 dc->SetType(AliVCluster::kEMCALClusterv1);
280 Float_t pos[3] = {0};
281 oc->GetPosition(pos);
282 dc->SetPosition(pos);
283 dc->SetNCells(oc->GetNCells());
284 dc->SetCellsAbsId(oc->GetCellsAbsId());
285 dc->SetCellsAmplitudeFraction(oc->GetCellsAmplitudeFraction());
286 dc->SetID(oc->GetID());
287 dc->SetDispersion(oc->GetDispersion());
288 dc->SetEmcCpvDistance(-1);
290 dc->SetTOF(oc->GetTOF());
291 dc->SetNExMax(oc->GetNExMax());
292 dc->SetM02(oc->GetM02());
293 dc->SetM20(oc->GetM20());
294 dc->SetDistanceToBadChannel(oc->GetDistanceToBadChannel());
295 dc->SetMCEnergyFraction(oc->GetMCEnergyFraction());
298 UInt_t nlabels = oc->GetNLabels();
299 Int_t *labels = oc->GetLabels();
301 if (nlabels == 0 || !labels)
304 AliESDCaloCluster *esdClus =
dynamic_cast<AliESDCaloCluster*
>(dc);
306 TArrayI parents(nlabels, labels);
307 esdClus->AddLabels(parents);
310 AliAODCaloCluster *aodClus =
dynamic_cast<AliAODCaloCluster*
>(dc);
312 aodClus->SetLabel(labels, nlabels);
353 Int_t cellLabels[12672]={-1};
355 Int_t nClusters = InputEvent()->GetNumberOfCaloClusters();
356 for (Int_t i = 0; i < nClusters; i++) {
357 AliVCluster *clus = InputEvent()->GetCaloCluster(i);
360 if (!clus->IsEMCAL())
continue ;
362 Int_t label = clus->GetLabel();
363 UShort_t * index = clus->GetCellsAbsId() ;
365 for (Int_t icell=0; icell < clus->GetNCells(); icell++) cellLabels[index[icell]] = label;
370 const Int_t ncells =
fCaloCells->GetNumberOfCells();
371 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) {
372 Double_t cellAmplitude=0, cellTime=0, cellEFrac = 0;
373 Short_t cellNumber=0;
374 Int_t cellMCLabel=-1;
375 if (
fCaloCells->GetCell(icell, cellNumber, cellAmplitude, cellTime, cellMCLabel, cellEFrac) != kTRUE)
380 if (cellMCLabel > 0 && cellEFrac < 1e-6)
383 if (cellAmplitude < 1e-6 || cellNumber < 0)
387 if (cellMCLabel <= 0)
390 cellAmplitude *= cellEFrac;
398 cellAmplitude *= 1 - cellEFrac;
405 AliEMCALDigit *digit =
new((*fDigitsArr)[idigit]) AliEMCALDigit(cellMCLabel, cellMCLabel, cellNumber,
406 (Float_t)cellAmplitude, (Float_t)cellTime,
407 AliEMCALDigit::kHG,idigit, 0, 0, cellEFrac*cellAmplitude);
410 Float_t
energy = cellAmplitude;
411 Float_t time = cellTime;
413 digit->SetAmplitude(energy);
420 avgE /=
fGeom->GetNumberOfSuperModules()*48*24;
422 for (Int_t i = 0; i < ndigis; ++i) {
423 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(i));
424 Double_t
energy = digit->GetAmplitude() - avgE;
426 digit->SetAmplitude(0);
428 digit->SetAmplitude(energy);
438 Int_t maxd =
fGeom->GetNCells() / 4;
439 for (Int_t idigit = 0; idigit < maxd; idigit++){
440 if (idigit % 24 == 12) idigit += 12;
441 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->New(idigit));
442 digit->SetId(idigit * 4);
444 digit->SetTimeR(600);
445 digit->SetIndexInList(idigit);
446 digit->SetType(AliEMCALDigit::kHG);
447 digit->SetAmplitude(0.1);
458 AliVCaloTrigger *triggers = InputEvent()->GetCaloTrigger(
"EMCAL");
460 if (!triggers || !(triggers->GetEntries() > 0))
466 while ((triggers->Next())) {
467 Float_t L0Amplitude = 0;
468 triggers->GetAmplitude(L0Amplitude);
473 Int_t L1Amplitude = 0;
474 triggers->GetL1TimeSum(L1Amplitude);
479 Int_t triggerTime = 0;
481 triggers->GetNL0Times(ntimes);
488 triggers->GetL0Times(trgtimes);
489 triggerTime = trgtimes[0];
492 Int_t triggerCol = 0, triggerRow = 0;
493 triggers->GetPosition(triggerCol, triggerRow);
496 fGeom->GetAbsFastORIndexFromPositionInEMCAL(triggerCol, triggerRow, find);
501 Int_t cidx[4] = {-1};
502 Bool_t ret =
fGeom->GetCellIndexFromFastORIndex(find, cidx);
507 Float_t triggerAmplitude = 0;
510 triggerAmplitude = 0.25 * L1Amplitude;
513 triggerAmplitude = L0Amplitude;
516 for (Int_t idxpos = 0; idxpos < 4; idxpos++) {
517 Int_t triggerNumber = cidx[idxpos];
518 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->New(idigit));
519 digit->SetId(triggerNumber);
520 digit->SetTime(triggerTime);
521 digit->SetTimeR(triggerTime);
522 digit->SetIndexInList(idigit);
523 digit->SetType(AliEMCALDigit::kHG);
524 digit->SetAmplitude(triggerAmplitude);
536 Bool_t accept = kTRUE;
539 Bool_t exRemoval =
fRecoUtils->IsRejectExoticCell();
541 Int_t bunchCrossNo = InputEvent()->GetBunchCrossNumber();
543 if(isEx) accept = kFALSE;
544 if(!exRemoval)
fRecoUtils->SwitchOffRejectExoticCell();
556 for (Int_t icluster=0; icluster < nclusters; ++icluster) {
557 AliVCluster *clust =
static_cast<AliVCluster*
>(
fCaloClusters->At(icluster));
560 if (!clust->IsEMCAL())
568 Bool_t badRemoval =
fRecoUtils->IsBadChannelsRemovalSwitchedOn();
571 Bool_t badResult =
fRecoUtils->ClusterContainsBadChannel(
fGeom, clust->GetCellsAbsId(), clust->GetNCells());
590 Bool_t exRemoval =
fRecoUtils->IsRejectExoticCell();
594 Int_t bunchCrossNo = InputEvent()->GetBunchCrossNumber();
620 Float_t correctedEnergy =
fRecoUtils->CorrectClusterEnergyLinearity(clust);
621 clust->SetE(correctedEnergy);
639 Double_t dEtaMin = 1e9;
640 Double_t dPhiMin = 1e9;
642 Double_t ceta = gpos.Eta();
643 Double_t cphi = gpos.Phi();
644 const Int_t ntrks = tarr->GetEntries();
645 for(Int_t t = 0; t<ntrks; ++t) {
646 AliVTrack *track =
static_cast<AliVTrack*
>(tarr->At(t));
649 const AliExternalTrackParam *outp = track->GetOuterParam();
652 Double_t trkPos[3] = {0.,0.,0.};
653 if (!outp->GetXYZ(trkPos))
655 TVector3 vec(trkPos[0],trkPos[1],trkPos[2]);
656 Double_t veta = vec.Eta();
657 Double_t vphi = vec.Phi();
659 vphi += 2*TMath::Pi();
660 if (TMath::Abs(veta)>0.75 || (vphi<70*TMath::DegToRad()) || (vphi>190*TMath::DegToRad()))
662 Double_t dR = vec.DeltaR(gpos);
665 Float_t tmpEta=0, tmpPhi=0;
667 AliExternalTrackParam trkParTemp(*outp);
672 tmpEta = ceta - veta;
673 tmpPhi = cphi - vphi;
675 if (TMath::Abs(tmpEta)<TMath::Abs(dEtaMin) && TMath::Abs(tmpPhi)<TMath::Abs(dPhiMin)) {
681 c->SetEmcCpvDistance(imin);
682 c->SetTrackDistance(dPhiMin, dEtaMin);
691 TClonesArray *tarr = 0;
693 tarr =
dynamic_cast<TClonesArray*
>(InputEvent()->FindListObject(
fTrackName));
695 AliError(Form(
"Cannot get tracks named %s",
fTrackName.Data()));
700 AliDebug(1, Form(
"total no of clusters %d", Ncls));
701 for(Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i) {
702 AliEMCALRecPoint *recpoint =
static_cast<AliEMCALRecPoint*
>(
fClusterArr->At(i));
703 Int_t ncells_true = 0;
704 const Int_t ncells = recpoint->GetMultiplicity();
705 UShort_t absIds[ncells];
706 Double32_t ratios[ncells];
707 Int_t *dlist = recpoint->GetDigitsList();
708 Float_t *elist = recpoint->GetEnergiesList();
709 Double_t mcEnergy = 0;
710 for (Int_t c = 0; c < ncells; ++c) {
711 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(dlist[c]));
712 absIds[ncells_true] = digit->GetId();
713 ratios[ncells_true] = elist[c]/recpoint->GetEnergy();
714 if (digit->GetIparent(1) > 0)
715 mcEnergy += digit->GetDEParent(1)/recpoint->GetEnergy();
719 if (ncells_true < 1) {
720 AliWarning(
"Skipping cluster with no cells");
726 recpoint->GetGlobalPosition(gpos);
730 AliDebug(1, Form(
"energy %f", recpoint->GetEnergy()));
732 AliVCluster *c =
static_cast<AliVCluster*
>(clus->New(nout++));
733 c->SetType(AliVCluster::kEMCALClusterv1);
734 c->SetE(recpoint->GetEnergy());
736 c->SetNCells(ncells_true);
737 c->SetCellsAbsId(absIds);
738 c->SetCellsAmplitudeFraction(ratios);
739 c->SetID(recpoint->GetUniqueID());
740 c->SetDispersion(recpoint->GetDispersion());
741 c->SetEmcCpvDistance(-1);
743 c->SetTOF(recpoint->GetTime()) ;
744 c->SetNExMax(recpoint->GetNExMax());
746 recpoint->GetElipsAxis(elipAxis);
747 c->SetM02(elipAxis[0]*elipAxis[0]);
748 c->SetM20(elipAxis[1]*elipAxis[1]);
749 c->SetMCEnergyFraction(mcEnergy);
752 AliESDCaloCluster *esdClus =
dynamic_cast<AliESDCaloCluster*
>(c);
754 Int_t parentMult = 0;
755 Int_t *parentList = recpoint->GetParents(parentMult);
756 if (parentMult > 0) {
757 TArrayI parents(parentMult, parentList);
758 esdClus->AddLabels(parents);
762 AliAODCaloCluster *aodClus =
dynamic_cast<AliAODCaloCluster*
>(c);
764 Int_t parentMult = 0;
765 Int_t *parentList = recpoint->GetParents(parentMult);
766 aodClus->SetLabel(parentList, parentMult);
782 const Int_t ncells =
fCaloCells->GetNumberOfCells();
783 const Int_t ndigis =
fDigitsArr->GetEntries();
784 if (ncells!=ndigis) {
788 for (Int_t idigit = 0; idigit < ndigis; ++idigit) {
789 AliEMCALDigit *digit =
static_cast<AliEMCALDigit*
>(
fDigitsArr->At(idigit));
790 Double_t cellAmplitude = digit->GetCalibAmp();
791 Short_t cellNumber = digit->GetId();
792 Double_t cellTime = digit->GetTime();
793 fCaloCells->SetCell(idigit, cellNumber, cellAmplitude, cellTime);
803 for (Int_t i=0;i<nents;++i) {
804 AliVCluster *c =
static_cast<AliVCluster*
>(
fCaloClusters->At(i));
823 fRun = InputEvent()->GetRunNumber();
835 fGeom = AliEMCALGeometry::GetInstance();
837 AliFatal(
"Geometry not available!!!");
843 for(Int_t mod=0; mod <
fGeom->GetNumberOfSuperModules(); ++mod) {
845 if (DebugLevel() > 2)
851 for(Int_t mod=0; mod <
fGeom->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
852 const TGeoHMatrix *gm = 0;
854 gm =
fEsd->GetEMCALMatrix(mod);
856 AliAODHeader *aodheader =
dynamic_cast<AliAODHeader*
>(
fAod->GetHeader());
857 if(!aodheader) AliFatal(
"Not a standard AOD");
859 gm = aodheader->GetEMCALMatrix(mod);
863 if (DebugLevel() > 2)
865 fGeom->SetMisalMatrix(gm,mod);
874 fDigitsArr =
new TClonesArray(
"AliEMCALDigit", 1000);
884 if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
886 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN) {
887 AliEMCALClusterizerNxN *clusterizer =
new AliEMCALClusterizerNxN(
fGeom);
888 clusterizer->SetNRowDiff(
fRecParam->GetNRowDiff());
889 clusterizer->SetNColDiff(
fRecParam->GetNColDiff());
892 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
894 else if (
fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerFW) {
895 AliEMCALClusterizerFixedWindow *clusterizer =
new AliEMCALClusterizerFixedWindow(
fGeom);
896 clusterizer->SetNphi(
fNPhi);
897 clusterizer->SetNeta(
fNEta);
904 AliFatal(Form(
"Clusterizer < %d > not available",
fRecParam->GetClusterizerFlag()));
909 AliCDBManager *cdb = AliCDBManager::Instance();
910 if (!cdb->IsDefaultStorageSet() && !
fOCDBpath.IsNull())
912 if (
fRun!=cdb->GetRun())
916 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Data"));
918 fCalibData =
static_cast<AliEMCALCalibData*
>(entry->GetObject());
920 AliFatal(
"Calibration parameters not found in CDB!");
923 AliCDBEntry *entry =
static_cast<AliCDBEntry*
>(AliCDBManager::Instance()->Get(
"EMCAL/Calib/Pedestals"));
925 fPedestalData =
static_cast<AliCaloCalibPedestal*
>(entry->GetObject());
947 AliError(Form(
"%s: Could not retrieve cells %s!", GetName(),
fCaloCellsName.Data()));
950 AliFatal(
"Could not get EMCal cells!");
962 fCaloClusters =
static_cast<TClonesArray*
>(InputEvent()->FindListObject(
"CaloClusters"));
964 fCaloClusters =
static_cast<TClonesArray*
>(InputEvent()->FindListObject(
"caloClusters"));
981 AliFatal(
"Could not get cluster collection!");
984 if (!cl->GetBaseClass(
"AliVCluster")) {
985 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()
TObjArray * fClusterArr
digits array
AliEMCALCalibData * fCalibData
TClonesArray * fDigitsArr
run number
AliEMCALAfterBurnerUF * fUnfolder
clusterizer
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)
Bool_t fRejectExoticCells
Bool_t fJustUnfold
unfolding procedure
AliEMCALGeometry * fGeom
aod event
Int_t fSetCellMCLabelFromCluster
virtual void CalibrateClusters()
virtual void UpdateCells()
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
TGeoHMatrix * fGeomMatrix[12]
virtual void UpdateClusters()