Skip to content

Commit

Permalink
[PWGDQ] Fixes in dqEfficiency_withassoc and adding muon refit in tabl…
Browse files Browse the repository at this point in the history
…eMakerMC (AliceO2Group#6815)

* Fixes for dqEff

* Clang format

* Global muon refit in tableMakerMC

* Fixing typo

* Fixing comilation issue

* Fix typo

Co-authored-by: Sergio Garcia <[email protected]>

* Fix typo

Co-authored-by: Sergio Garcia <[email protected]>

* Fix typo

Co-authored-by: Sergio Garcia <[email protected]>

* Fix typo

Co-authored-by: Sergio Garcia <[email protected]>

* Merge

* Fixing logic of parameter recomputation

* Fix dca calculation for muons

---------

Co-authored-by: Sergio Garcia <[email protected]>
  • Loading branch information
mcoquet642 and singiamtel authored Jul 17, 2024
1 parent c3ae264 commit 4099de3
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 37 deletions.
12 changes: 1 addition & 11 deletions PWGDQ/Core/VarManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2164,15 +2164,12 @@ void VarManager::FillTrackCollision(T const& track, C const& collision, float* v
}
if constexpr ((fillMap & MuonCov) > 0 || (fillMap & ReducedMuonCov) > 0) {

o2::dataformats::GlobalFwdTrack propmuon = PropagateMuon(track, collision);
o2::dataformats::GlobalFwdTrack propmuonAtDCA = PropagateMuon(track, collision, kToDCA);

float dcaX = (propmuonAtDCA.getX() - collision.posX());
float dcaY = (propmuonAtDCA.getY() - collision.posY());
float dcaXY = std::sqrt(dcaX * dcaX + dcaY * dcaY);
values[kMuonPDca] = track.p() * dcaXY;
values[kMuonDCAx] = dcaX;
values[kMuonDCAy] = dcaY;
}
}

Expand Down Expand Up @@ -2703,14 +2700,7 @@ void VarManager::FillPairVertexing(C const& collision, T const& t1, T const& t2,
t2.c1PtX(), t2.c1PtY(), t2.c1PtPhi(), t2.c1PtTgl(), t2.c1Pt21Pt2()};
SMatrix55 t2covs(v2.begin(), v2.end());
o2::track::TrackParCovFwd pars2{t2.z(), t2pars, t2covs, chi22};
if (std::abs(t2.cXX()) < 1.0e-6) {
// TODO: Some rare fwd-tracks have very small covariances and the DCAFitter throws a fatal!
// This is a protection, but please check for the reason and eventually change the behaviour.
// At the moment, when these tracks are encountered, the vertexing quantities are initialized to default values (-999)
procCode = 0;
} else {
procCode = fgFitterTwoProngFwd.process(pars1, pars2);
}
procCode = fgFitterTwoProngFwd.process(pars1, pars2);
} else {
return;
}
Expand Down
51 changes: 39 additions & 12 deletions PWGDQ/TableProducer/tableMakerMC_withAssoc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,14 @@ struct TableMakerMC {

// CCDB connection configurables
Configurable<std::string> fConfigCcdbUrl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<bool> fPropMuon{"cfgPropMuon", false, "Propgate muon tracks through absorber"};
Configurable<std::string> geoPath{"geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"};
Configurable<std::string> grpmagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"};
Configurable<std::string> grpmagPathRun2{"grpmagPathRun2", "GLO/GRP/GRP", "CCDB path of the GRPObject (Usage for Run 2)"};

// Muon related options
Configurable<bool> fPropMuon{"cfgPropMuon", true, "Propagate muon tracks through absorber (do not use if applying pairing)"};
Configurable<bool> fRefitGlobalMuon{"cfgRefitGlobalMuon", true, "Correct global muon parameters"};

Service<o2::ccdb::BasicCCDBManager> fCCDB;

o2::parameters::GRPObject* grpmagrun2 = nullptr; // for run 2, we access the GRPObject from GLO/GRP/GRP
Expand Down Expand Up @@ -648,7 +651,7 @@ struct TableMakerMC {
}

template <uint32_t TMuonFillMap, typename TEvent, typename TMuons>
void skimMuons(TEvent const& collision, TMuons const& muons, FwdTrackAssoc const& muonAssocs, aod::McParticles const& mcTracks)
void skimMuons(TEvent const& collision, TMuons const& muons, FwdTrackAssoc const& muonAssocs, aod::McParticles const& mcTracks, MFTTracks const& /*mftTracks*/)
{
// Skim the fwd-tracks (muons)
// Loop over the collision-track associations, recompute track properties depending on the collision assigned, and apply track cuts for selection
Expand All @@ -670,7 +673,18 @@ struct TableMakerMC {
VarManager::FillTrack<TMuonFillMap>(muon);
// NOTE: If a muon is associated to multiple collisions, depending on the selections,
// it may be accepted for some associations and rejected for other
VarManager::FillPropagateMuon<TMuonFillMap>(muon, collision);
if (fPropMuon) {
VarManager::FillPropagateMuon<TMuonFillMap>(muon, collision);
}
// recalculte pDca and global muon kinematics
if (static_cast<int>(muon.trackType()) < 2 && fRefitGlobalMuon) {
auto muontrack = muon.template matchMCHTrack_as<TMuons>();
auto mfttrack = muon.template matchMFTTrack_as<MFTTracks>();
VarManager::FillTrackCollision<TMuonFillMap>(muontrack, collision);
VarManager::FillGlobalMuonRefit<TMuonFillMap>(muontrack, mfttrack, collision);
} else {
VarManager::FillTrackCollision<TMuonFillMap>(muon, collision);
}

if (fDoDetailedQA) {
fHistMan->FillHistClass("Muons_BeforeCuts", VarManager::fgValues);
Expand Down Expand Up @@ -770,18 +784,31 @@ struct TableMakerMC {
mftIdx = fMftIndexMap[muon.matchMFTTrackId()];
}
}
muonBasic(reducedEventIdx, mchIdx, mftIdx, fFwdTrackFilterMap[muon.globalIndex()], muon.pt(), muon.eta(), muon.phi(), muon.sign(), 0);
muonExtra(muon.nClusters(), muon.pDca(), muon.rAtAbsorberEnd(),
VarManager::FillTrack<TMuonFillMap>(muon);
if (fPropMuon) {
VarManager::FillPropagateMuon<TMuonFillMap>(muon, collision);
}
// recalculte pDca and global muon kinematics
if (static_cast<int>(muon.trackType()) < 2 && fRefitGlobalMuon) {
auto muontrack = muon.template matchMCHTrack_as<TMuons>();
auto mfttrack = muon.template matchMFTTrack_as<MFTTracks>();
VarManager::FillTrackCollision<TMuonFillMap>(muontrack, collision);
VarManager::FillGlobalMuonRefit<TMuonFillMap>(muontrack, mfttrack, collision);
} else {
VarManager::FillTrackCollision<TMuonFillMap>(muon, collision);
}
muonBasic(reducedEventIdx, mchIdx, mftIdx, fFwdTrackFilterMap[muon.globalIndex()], VarManager::fgValues[VarManager::kPt], VarManager::fgValues[VarManager::kEta], VarManager::fgValues[VarManager::kPhi], muon.sign(), 0);
muonExtra(muon.nClusters(), VarManager::fgValues[VarManager::kMuonPDca], VarManager::fgValues[VarManager::kMuonRAtAbsorberEnd],
muon.chi2(), muon.chi2MatchMCHMID(), muon.chi2MatchMCHMFT(),
muon.matchScoreMCHMFT(),
muon.mchBitMap(), muon.midBitMap(),
muon.midBoards(), muon.trackType(), muon.fwdDcaX(), muon.fwdDcaY(),
muon.midBoards(), muon.trackType(), VarManager::fgValues[VarManager::kMuonDCAx], VarManager::fgValues[VarManager::kMuonDCAy],
muon.trackTime(), muon.trackTimeRes());
if constexpr (static_cast<bool>(TMuonFillMap & VarManager::ObjTypes::MuonCov)) {
muonCov(muon.x(), muon.y(), muon.z(), muon.phi(), muon.tgl(), muon.sign() / muon.pt(),
muon.cXX(), muon.cXY(), muon.cYY(), muon.cPhiX(), muon.cPhiY(), muon.cPhiPhi(),
muon.cTglX(), muon.cTglY(), muon.cTglPhi(), muon.cTglTgl(), muon.c1PtX(), muon.c1PtY(),
muon.c1PtPhi(), muon.c1PtTgl(), muon.c1Pt21Pt2());
muonCov(VarManager::fgValues[VarManager::kX], VarManager::fgValues[VarManager::kY], VarManager::fgValues[VarManager::kZ], VarManager::fgValues[VarManager::kPhi], VarManager::fgValues[VarManager::kTgl], muon.sign() / VarManager::fgValues[VarManager::kPt],
VarManager::fgValues[VarManager::kMuonCXX], VarManager::fgValues[VarManager::kMuonCXY], VarManager::fgValues[VarManager::kMuonCYY], VarManager::fgValues[VarManager::kMuonCPhiX], VarManager::fgValues[VarManager::kMuonCPhiY], VarManager::fgValues[VarManager::kMuonCPhiPhi],
VarManager::fgValues[VarManager::kMuonCTglX], VarManager::fgValues[VarManager::kMuonCTglY], VarManager::fgValues[VarManager::kMuonCTglPhi], VarManager::fgValues[VarManager::kMuonCTglTgl], VarManager::fgValues[VarManager::kMuonC1Pt2X], VarManager::fgValues[VarManager::kMuonC1Pt2Y],
VarManager::fgValues[VarManager::kMuonC1Pt2Phi], VarManager::fgValues[VarManager::kMuonC1Pt2Tgl], VarManager::fgValues[VarManager::kMuonC1Pt21Pt2]);
}
if (muon.has_mcParticle()) {
auto mctrack = muon.template mcParticle_as<aod::McParticles>();
Expand Down Expand Up @@ -874,9 +901,9 @@ struct TableMakerMC {
auto groupedMFTIndices = mftAssocs.sliceBy(mfttrackIndicesPerCollision, origIdx);
skimMFT<TMFTFillMap>(collision, mftTracks, groupedMFTIndices);
}
if constexpr (static_cast<bool>(TMuonFillMap)) {
if constexpr (static_cast<bool>(TMuonFillMap) && static_cast<bool>(TMFTFillMap)) {
auto groupedMuonIndices = fwdTrackAssocs.sliceBy(fwdtrackIndicesPerCollision, origIdx);
skimMuons<TMuonFillMap>(collision, muons, groupedMuonIndices, mcParticles);
skimMuons<TMuonFillMap>(collision, muons, groupedMuonIndices, mcParticles, mftTracks);
}
} // end loop over skimmed collisions
}
Expand Down
18 changes: 16 additions & 2 deletions PWGDQ/TableProducer/tableMaker_withAssoc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ struct TableMaker {
Configurable<bool> fPropTrack{"cfgPropTrack", true, "Propgate tracks to associated collision to recalculate DCA and momentum vector"};

// Muon related options
Configurable<bool> fPropMuon{"cfgPropMuon", true, "Propgate muon tracks through absorber (do not use if applying pairing)"};
Configurable<bool> fPropMuon{"cfgPropMuon", true, "Propagate muon tracks through absorber (do not use if applying pairing)"};
Configurable<bool> fRefitGlobalMuon{"cfgRefitGlobalMuon", true, "Correct global muon parameters"};

Service<o2::ccdb::BasicCCDBManager> fCCDB;

Expand Down Expand Up @@ -763,7 +764,7 @@ struct TableMaker {
VarManager::FillPropagateMuon<TMuonFillMap>(muon, collision);
}
// recalculte pDca and global muon kinematics
if (static_cast<int>(muon.trackType()) < 2) {
if (static_cast<int>(muon.trackType()) < 2 && fRefitGlobalMuon) {
auto muontrack = muon.template matchMCHTrack_as<TMuons>();
auto mfttrack = muon.template matchMFTTrack_as<MFTTracks>();
VarManager::FillTrackCollision<TMuonFillMap>(muontrack, collision);
Expand Down Expand Up @@ -832,6 +833,19 @@ struct TableMaker {
mftIdx = fMftIndexMap[muon.matchMFTTrackId()];
}
}
VarManager::FillTrack<TMuonFillMap>(muon);
if (fPropMuon) {
VarManager::FillPropagateMuon<TMuonFillMap>(muon, collision);
}
// recalculte pDca and global muon kinematics
if (static_cast<int>(muon.trackType()) < 2 && fRefitGlobalMuon) {
auto muontrack = muon.template matchMCHTrack_as<TMuons>();
auto mfttrack = muon.template matchMFTTrack_as<MFTTracks>();
VarManager::FillTrackCollision<TMuonFillMap>(muontrack, collision);
VarManager::FillGlobalMuonRefit<TMuonFillMap>(muontrack, mfttrack, collision);
} else {
VarManager::FillTrackCollision<TMuonFillMap>(muon, collision);
}
muonBasic(reducedEventIdx, mchIdx, mftIdx, fFwdTrackFilterMap[muon.globalIndex()], VarManager::fgValues[VarManager::kPt], VarManager::fgValues[VarManager::kEta], VarManager::fgValues[VarManager::kPhi], muon.sign(), 0);
muonExtra(muon.nClusters(), VarManager::fgValues[VarManager::kMuonPDca], VarManager::fgValues[VarManager::kMuonRAtAbsorberEnd],
muon.chi2(), muon.chi2MatchMCHMID(), muon.chi2MatchMCHMFT(),
Expand Down
37 changes: 25 additions & 12 deletions PWGDQ/Tasks/dqEfficiency_withAssoc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,10 @@ struct AnalysisTrackSelection {
int isig = 0;
if (filterMap > 0) {
for (auto sig = fMCSignals.begin(); sig != fMCSignals.end(); sig++, isig++) {
if ((*sig).CheckSignal(false, track.reducedMCTrack())) {
mcDecision |= (uint32_t(1) << isig);
if (track.has_reducedMCTrack()) {
if ((*sig).CheckSignal(false, track.reducedMCTrack())) {
mcDecision |= (uint32_t(1) << isig);
}
}
}

Expand Down Expand Up @@ -771,8 +773,10 @@ struct AnalysisMuonSelection {
int isig = 0;
for (auto sig = fMCSignals.begin(); sig != fMCSignals.end(); sig++, isig++) {
if constexpr ((TMuonFillMap & VarManager::ObjTypes::ReducedMuon) > 0) {
if ((*sig).CheckSignal(false, track.reducedMCTrack())) {
mcDecision |= (uint32_t(1) << isig);
if (track.has_reducedMCTrack()) {
if ((*sig).CheckSignal(false, track.reducedMCTrack())) {
mcDecision |= (uint32_t(1) << isig);
}
}
}
}
Expand Down Expand Up @@ -1426,12 +1430,16 @@ struct AnalysisSameEventPairing {
int isig = 0;
mcDecision = 0;
for (auto sig = fRecMCSignals.begin(); sig != fRecMCSignals.end(); sig++, isig++) {
if ((*sig).CheckSignal(false, t1.reducedMCTrack(), t2.reducedMCTrack())) {
mcDecision |= (uint32_t(1) << isig);
if (t1.has_reducedMCTrack() && t2.has_reducedMCTrack()) {
if ((*sig).CheckSignal(false, t1.reducedMCTrack(), t2.reducedMCTrack())) {
mcDecision |= (uint32_t(1) << isig);
}
}
} // end loop over MC signals
isCorrectAssoc_leg1 = (t1.reducedMCTrack().reducedMCevent() == event.reducedMCevent());
isCorrectAssoc_leg2 = (t2.reducedMCTrack().reducedMCevent() == event.reducedMCevent());
if (t1.has_reducedMCTrack() && t2.has_reducedMCTrack()) {
isCorrectAssoc_leg1 = (t1.reducedMCTrack().reducedMCevent() == event.reducedMCevent());
isCorrectAssoc_leg2 = (t2.reducedMCTrack().reducedMCevent() == event.reducedMCevent());
}

VarManager::FillPair<TPairType, TTrackFillMap>(t1, t2);
if constexpr (TTwoProngFitter) {
Expand Down Expand Up @@ -1469,12 +1477,17 @@ struct AnalysisSameEventPairing {
int isig = 0;
mcDecision = 0;
for (auto sig = fRecMCSignals.begin(); sig != fRecMCSignals.end(); sig++, isig++) {
if ((*sig).CheckSignal(false, t1.reducedMCTrack(), t2.reducedMCTrack())) {
mcDecision |= (uint32_t(1) << isig);
if (t1.has_reducedMCTrack() && t2.has_reducedMCTrack()) {
if ((*sig).CheckSignal(false, t1.reducedMCTrack(), t2.reducedMCTrack())) {
mcDecision |= (uint32_t(1) << isig);
}
}
} // end loop over MC signals
isCorrectAssoc_leg1 = (t1.reducedMCTrack().reducedMCevent() == event.reducedMCevent());
isCorrectAssoc_leg2 = (t2.reducedMCTrack().reducedMCevent() == event.reducedMCevent());

if (t1.has_reducedMCTrack() && t2.has_reducedMCTrack()) {
isCorrectAssoc_leg1 = (t1.reducedMCTrack().reducedMCevent() == event.reducedMCevent());
isCorrectAssoc_leg2 = (t2.reducedMCTrack().reducedMCevent() == event.reducedMCevent());
}

VarManager::FillPair<TPairType, TTrackFillMap>(t1, t2);
if constexpr (TTwoProngFitter) {
Expand Down

0 comments on commit 4099de3

Please sign in to comment.