Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 92 additions & 13 deletions PWGUD/TableProducer/upcCandProducerGlobalMuon.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include "PWGUD/Core/UPCHelpers.h"
#include "PWGUD/DataModel/UDTables.h"

#include "Common/CCDB/RCTSelectionFlags.h"
#include "Common/Core/fwdtrackUtilities.h"
#include "Common/DataModel/EventSelection.h"

#include <CCDB/BasicCCDBManager.h>
#include <CCDB/CcdbApi.h>
Expand All @@ -37,6 +39,7 @@
#include <Framework/HistogramRegistry.h>
#include <Framework/HistogramSpec.h>
#include <Framework/InitContext.h>
#include <Framework/Logger.h>
#include <Framework/OutputObjHeader.h>
#include <Framework/runDataProcessing.h>
#include <GlobalTracking/MatchGlobalFwd.h>
Expand Down Expand Up @@ -104,6 +107,13 @@ struct UpcCandProducerGlobalMuon {
Configurable<int> fBcWindowMCHMFT{"fBcWindowMCHMFT", 20, "BC window for searching MCH-MFT tracks around MCH-MID-MFT anchors"};
Configurable<bool> fKeepBestMuonMatch{"fKeepBestMuonMatch", true, "Keep only the best MCH-MFT match per MCH track (lowest chi2)"};

// Same detector masks as UPCCandidateProducer; RCT is used only for selection.
Configurable<std::string> rctLabel{"rctLabel", "muon", "RCT selection label; muon = FV0 + MCH + MID, muon_glo adds MFT, none disables selection"};
Configurable<bool> checkZDC{"checkZDC", true, "Consider ZDC quality"};
Configurable<bool> useLAasBad{"useLAasBad", true, "Consider limited acceptance as bad"};
o2::aod::rctsel::RCTFlagsChecker myRCTChecker;

using BCsWithBcSels = o2::soa::Join<o2::aod::BCs, o2::aod::BcSels>;
using ForwardTracks = o2::soa::Join<o2::aod::FwdTracks, o2::aod::FwdTracksCov>;

HistogramRegistry histRegistry{"HistRegistry", {}, OutputObjHandlingPolicy::AnalysisObject};
Expand All @@ -125,6 +135,34 @@ struct UpcCandProducerGlobalMuon {
void init(InitContext&)
{
fUpcCuts = UPCCutparHolder(fUpcCutsConf);
using namespace o2::aod::rctsel;
// initialize RCT flag checker
if (rctLabel.value != "none" && rctLabel.value != "muon" && rctLabel.value != "muon_glo") {
myRCTChecker.init(rctLabel.value, checkZDC.value, useLAasBad.value);
} else if (rctLabel.value == "none") {
myRCTChecker.init("CBT_muon");
} else if (rctLabel.value == "muon") {
if (checkZDC.value && useLAasBad.value) {
myRCTChecker.init({kFV0Bad, kMCHBad, kMIDBad, kZDCBad, kMCHLimAccMCRepr, kMIDLimAccMCRepr});
} else if (checkZDC.value) {
myRCTChecker.init({kFV0Bad, kMCHBad, kMIDBad, kZDCBad});
} else if (useLAasBad.value) {
myRCTChecker.init({kFV0Bad, kMCHBad, kMIDBad, kMCHLimAccMCRepr, kMIDLimAccMCRepr});
} else {
myRCTChecker.init({kFV0Bad, kMCHBad, kMIDBad});
}
} else if (rctLabel.value == "muon_glo") {
if (checkZDC.value && useLAasBad.value) {
myRCTChecker.init({kFV0Bad, kMCHBad, kMIDBad, kMFTBad, kZDCBad, kMCHLimAccMCRepr, kMIDLimAccMCRepr, kMFTLimAccMCRepr});
} else if (checkZDC.value) {
myRCTChecker.init({kFV0Bad, kMCHBad, kMIDBad, kMFTBad, kZDCBad});
} else if (useLAasBad.value) {
myRCTChecker.init({kFV0Bad, kMCHBad, kMIDBad, kMFTBad, kMCHLimAccMCRepr, kMIDLimAccMCRepr, kMFTLimAccMCRepr});
} else {
myRCTChecker.init({kFV0Bad, kMCHBad, kMIDBad, kMFTBad});
}
}

if (fUpcCuts.getUseFwdCuts() || fEnableMFT) {
fCCDB->setURL("http://alice-ccdb.cern.ch");
fCCDB->setCaching(true);
Expand All @@ -140,6 +178,11 @@ struct UpcCandProducerGlobalMuon {
histRegistry.get<TH1>(HIST("MuonsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kFwdSelpDCA + 1, "pDCA");
histRegistry.get<TH1>(HIST("MuonsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kFwdSelChi2 + 1, "Chi2");

histRegistry.add("RCTSelCounter", "Track-level RCT selection (data and MC)", kTH1F, {{3, 0.5, 3.5}});
histRegistry.get<TH1>(HIST("RCTSelCounter"))->GetXaxis()->SetBinLabel(1, "Before RCT sel");
histRegistry.get<TH1>(HIST("RCTSelCounter"))->GetXaxis()->SetBinLabel(2, "After RCT sel");
histRegistry.get<TH1>(HIST("RCTSelCounter"))->GetXaxis()->SetBinLabel(3, "RCT rejected");

// NEW: Add histograms for global track monitoring
const AxisSpec axisTrackType{5, -0.5, 4.5, "Track Type"};
histRegistry.add("hTrackTypes", "Track type distribution", kTH1F, {axisTrackType});
Expand Down Expand Up @@ -194,7 +237,7 @@ struct UpcCandProducerGlobalMuon {
std::vector<int32_t> newEventIDs(mcCollisions.size(), -1);

int32_t newPartID = 0;
int32_t newEventID = 0;
int32_t nextEventID = 0;
int32_t nMCParticles = mcParticles.size();
// loop over MC particles to select only the ones from signal events
// and calculate new MC table IDs
Expand All @@ -211,8 +254,8 @@ struct UpcCandProducerGlobalMuon {
fNewPartIDs[mcPartID] = newPartID;
newPartID++;
if (newEventIDs[mcEventID] == -1) {
newEventIDs[mcEventID] = newEventID;
newEventID++;
newEventIDs[mcEventID] = nextEventID;
nextEventID++;
}
}

Expand Down Expand Up @@ -341,8 +384,8 @@ struct UpcCandProducerGlobalMuon {
void getMchTrackIds(uint64_t inGbc, std::map<uint64_t, std::vector<int64_t>>& mchTracksPerBC,
uint64_t maxDbc, std::map<int64_t, uint64_t>& outMchTrkIds)
{
auto fillMchIds = [&outMchTrkIds](std::map<uint64_t, std::vector<int64_t>>::iterator& inIt, uint64_t gbc) {
std::vector<int64_t>& ids = inIt->second;
auto fillMchIds = [&outMchTrkIds](std::map<uint64_t, std::vector<int64_t>>::iterator const& inIt, uint64_t gbc) {
const std::vector<int64_t>& ids = inIt->second;
for (const auto& id : ids)
outMchTrkIds[id] = gbc;
};
Expand All @@ -353,7 +396,7 @@ struct UpcCandProducerGlobalMuon {
std::map<uint64_t, int64_t>& mapBcs, std::vector<float>& amps, std::vector<int8_t>& relBcs)
{

auto fillAmps = [this, &fv0s, &amps, &relBcs, inGbc](std::map<uint64_t, int64_t>::iterator& inIt, uint64_t gbc) {
auto fillAmps = [this, &fv0s, &amps, &relBcs, inGbc](std::map<uint64_t, int64_t>::iterator const& inIt, uint64_t gbc) {
int64_t fv0Id = inIt->second;
const auto& fv0 = fv0s.iteratorAt(fv0Id);
const auto& amplitudes = fv0.amplitude();
Expand Down Expand Up @@ -583,7 +626,7 @@ struct UpcCandProducerGlobalMuon {
o2::aod::MFTTracks const& mftTracks,
o2::aod::FwdTrkCls const& fwdTrkCls,
o2::aod::AmbiguousFwdTracks const& ambFwdTracks,
o2::aod::BCs const& bcs,
BCsWithBcSels const& bcs,
o2::aod::Collisions const& collisions,
o2::aod::FV0As const& fv0s,
o2::aod::Zdcs const& zdcs,
Expand All @@ -594,6 +637,18 @@ struct UpcCandProducerGlobalMuon {
using o2::aod::fwdtrack::ForwardTrackTypeEnum::MCHStandaloneTrack;
using o2::aod::fwdtrack::ForwardTrackTypeEnum::MuonStandaloneTrack;

if (bcs.size() == 0) {
return;
}

if (rctLabel.value != "none") {
for (const auto& bc : bcs) {
if (!myRCTChecker.isTableValid(bc)) {
LOGP(fatal, "Missing RCT CCDB object for run {} at input global BC {}; stopping processing", bc.runNumber(), bc.globalBC());
}
}
}

int32_t runNumber = bcs.iteratorAt(0).runNumber();
if (fUpcCuts.getUseFwdCuts() || fEnableMFT) {
if (runNumber != fRun) {
Expand Down Expand Up @@ -661,8 +716,11 @@ struct UpcCandProducerGlobalMuon {
std::vector<int64_t> vAmbFwdTrackIndex(nFwdTracks, -1);
std::vector<int64_t> vAmbFwdTrackIndexBCs(nAmbFwdTracks, -1);
for (const auto& ambTr : ambFwdTracks) {
vAmbFwdTrackIndex[ambTr.fwdtrackId()] = ambTr.globalIndex();
vAmbFwdTrackIndexBCs[ambTr.globalIndex()] = ambTr.bcIds()[0];
if (ambTr.bcIds().empty()) {
LOGP(fatal, "Ambiguous forward track {} has no source BC", ambTr.fwdtrackId());
}
vAmbFwdTrackIndex.at(ambTr.fwdtrackId()) = ambTr.globalIndex();
vAmbFwdTrackIndexBCs.at(ambTr.globalIndex()) = ambTr.bcIds()[0];
}

// Select best MCH-MFT match per MCH track before sorting into BC maps
Expand Down Expand Up @@ -693,7 +751,28 @@ struct UpcCandProducerGlobalMuon {
}

auto trackId = fwdTrack.globalIndex();
int64_t indexBC = vAmbFwdTrackIndex[trackId] < 0 ? vColIndexBCs[fwdTrack.collisionId()] : vAmbFwdTrackIndexBCs[vAmbFwdTrackIndex[trackId]];
const auto ambIndex = vAmbFwdTrackIndex.at(trackId);
int64_t indexBC = -1;
if (ambIndex >= 0) {
indexBC = vAmbFwdTrackIndexBCs.at(ambIndex);
} else if (fwdTrack.has_collision()) {
indexBC = vColIndexBCs.at(fwdTrack.collisionId());
}
if (indexBC < 0 || indexBC >= nBcs) {
LOGP(fatal, "Forward track {} has no valid source BC (index {})", trackId, indexBC);
}

// For data and MC, check the input BC before the track-time shift,
// including the first listed BC for ambiguous tracks.
if (rctLabel.value != "none") {
const auto bcRCT = bcs.iteratorAt(indexBC);
histRegistry.fill(HIST("RCTSelCounter"), 1.);
if (!myRCTChecker(bcRCT)) {
histRegistry.fill(HIST("RCTSelCounter"), 3.);
continue;
}
histRegistry.fill(HIST("RCTSelCounter"), 2.);
}
auto globalBC = vGlobalBCs[indexBC] + TMath::FloorNint(fwdTrack.trackTime() / o2::constants::lhc::LHCBunchSpacingNS + kBcTimeRoundingOffset);

if (trackType == MuonStandaloneTrack) { // MCH-MID
Expand Down Expand Up @@ -852,7 +931,7 @@ struct UpcCandProducerGlobalMuon {
continue;
}
uint16_t numContrib = 0;
auto& vMuonIds = gbc_muids.second;
const auto& vMuonIds = gbc_muids.second;
// writing MCH-MID tracks
for (const auto& imuon : vMuonIds) {
if (!addToFwdTable(candId, imuon, globalBcMid, 0., fwdTracks, mftTracks, mcFwdTrackLabels))
Expand Down Expand Up @@ -916,7 +995,7 @@ struct UpcCandProducerGlobalMuon {
o2::aod::MFTTracks const& mftTracks,
o2::aod::FwdTrkCls const& fwdTrkCls,
o2::aod::AmbiguousFwdTracks const& ambFwdTracks,
o2::aod::BCs const& bcs,
BCsWithBcSels const& bcs,
o2::aod::Collisions const& collisions,
o2::aod::FV0As const& fv0s,
o2::aod::Zdcs const& zdcs)
Expand All @@ -929,7 +1008,7 @@ struct UpcCandProducerGlobalMuon {
o2::aod::MFTTracks const& mftTracks,
o2::aod::FwdTrkCls const& fwdTrkCls,
o2::aod::AmbiguousFwdTracks const& ambFwdTracks,
o2::aod::BCs const& bcs,
BCsWithBcSels const& bcs,
o2::aod::Collisions const& collisions,
o2::aod::FV0As const& fv0s,
o2::aod::Zdcs const& zdcs,
Expand Down
Loading