Skip to content

Commit

Permalink
ccccc
Browse files Browse the repository at this point in the history
  • Loading branch information
f3sch committed Nov 9, 2023
1 parent 3219243 commit f0fa9e4
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 81 deletions.
26 changes: 18 additions & 8 deletions Detectors/Vertexing/include/DetectorsVertexing/SVertexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,30 @@ class SVertexer

using key_t = std::tuple<int, int, int>;

static size_t make_hash(int src, int eve, int id)
{
size_t seed = 0;
boost::hash_combine(seed, src ^ (0xdeadbeef ^ id));
boost::hash_combine(seed, eve << id);
boost::hash_combine(seed, id);
return seed;
}

struct key_hash {
size_t operator()(const key_t& k) const
{
const auto& [eve, src, trkid] = k;
size_t seed = 0;
boost::hash_combine(seed, eve);
boost::hash_combine(seed, src);
boost::hash_combine(seed, trkid);
return seed;
const auto& [src, eve, trkid] = k;
return make_hash(src, eve, trkid);
}
};
using map_timing_t = std::unordered_map<key_t, std::tuple<GIndex, GIndex, bool, ULong64_t>, key_hash>;
using map_before_t = std::unordered_map<key_t, std::tuple<MCTrack, MCTrack, MCTrack, bool>, key_hash>;
using map_after_t = std::unordered_map<key_t, std::tuple<TrackCand, MCTrack, TrackCand, MCTrack, MCTrack>, key_hash>;
using map_mc_t = std::unordered_map<key_t, std::pair<key_t, key_t>, key_hash>;
using map_mc_particle_t = std::unordered_map<key_t, bool, key_hash>;
using map_discard_t = std::unordered_map<size_t, int>;

map_discard_t mDiscardMap;
map_mc_t mD0V0Map;
map_mc_t mD1V0Map;
map_mc_t mMotherV0Map;
Expand Down Expand Up @@ -832,13 +839,14 @@ class SVertexer
return i;
}

void inc(Enum e, GIndex const& gid, o2::MCCompLabel const& lbl, map_mc_t const& d0, map_mc_t const& d1, map_mc_particle_t const& mcparticles)
bool inc(Enum e, GIndex const& gid, o2::MCCompLabel const& lbl, map_mc_t const& d0, map_mc_t const& d1, map_mc_particle_t const& mcparticles)
{
auto c = static_cast<unsigned int>(e);
auto gidITS = gid.includesDet(o2::detectors::DetID::ITS);
auto gidTPC = gid.includesDet(o2::detectors::DetID::TPC);
auto gidTRD = gid.includesDet(o2::detectors::DetID::TRD);
auto gidTOF = gid.includesDet(o2::detectors::DetID::TOF);
bool isV0 = false;
int i = getType(gidITS, gidTPC, gidTRD, gidTOF);
++mCounters[i][c];
++mTotCounters[c];
Expand All @@ -849,14 +857,15 @@ class SVertexer
mDupMap[i][c][gid] = true;
}
if (lbl.isFake() || !lbl.isValid()) {
return;
return false;
}
auto idx = std::make_tuple(lbl.getSourceID(), lbl.getEventID(), lbl.getTrackID());
auto it0 = d0.find(idx);
auto it1 = d1.find(idx);
auto it0T = it0 != d0.end();
auto it1T = it1 != d1.end();
if (it0T || it1T) {
isV0 = true;
++mCountersV0[i][c];
if (dup) {
++mCountersV0Dup[i][c];
Expand All @@ -866,6 +875,7 @@ class SVertexer
if (mcgen) {
++mCountersMC[i][c];
}
return isV0;
}

void incAcceptTrack(Enum e, GIndex const& gid, o2::MCCompLabel const& lbl, map_mc_t const& d0, map_mc_t const& d1, map_mc_particle_t const& mcparticles, utils::TreeStreamRedirector& mDebugStream, o2::track::TrackPar const& trc, bool write = false)
Expand Down
3 changes: 3 additions & 0 deletions Detectors/Vertexing/src/DetectorsVertexingLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
#pragma link C++ class o2::vertexing::PVtxCompDump + ;
#pragma link C++ class std::vector < o2::vertexing::PVtxCompDump> + ;

#pragma link C++ class std::unorderd_map < size_t, int> + ;
#pragma link C++ class std::unorderd_map < int, int> + ;

#endif
52 changes: 51 additions & 1 deletion Detectors/Vertexing/src/SVertexer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ void SVertexer::process(const o2::globaltracking::RecoContainer& recoData, o2::f
mCascadesIdxTmp[ith].clear();
m3bodyIdxTmp[ith].clear();
}
mDebugStream << "discardMap"
<< "map=" << mDiscardMap
<< "\n";

extractPVReferences(v0sIdx, v0Refs, cascsIdx, cascRefs, body3Idx, vtx3bodyRefs);
if (mUseDebug) {
Expand Down Expand Up @@ -491,15 +494,20 @@ void SVertexer::buildT2V(const o2::globaltracking::RecoContainer& recoData) // a
for (; it < itLim; it++) {
auto tvid = trackIndex[it];
auto lbl = getLabel(tvid, recoData);
mCounterBuildT2V.inc(BUILDT2V::CALLED, tvid, lbl, mD0V0Map, mD1V0Map, mMCParticle);
bool check = mCounterBuildT2V.inc(BUILDT2V::CALLED, tvid, lbl, mD0V0Map, mD1V0Map, mMCParticle);
if (!recoData.isTrackSourceLoaded(tvid.getSource())) {
mCounterBuildT2V.inc(BUILDT2V::NOTLOADED, tvid, lbl, mD0V0Map, mD1V0Map, mMCParticle);
if (check) {
mDiscardMap[make_hash(lbl.getSourceID(), lbl.getEventID(), lbl.getTrackID())] = 1 * int(BUILDT2V::NOTLOADED);
}
continue;
}
if (tvid.getSource() == GIndex::TPC) {
mCounterBuildT2V.inc(BUILDT2V::TPCTRACK, tvid, lbl, mD0V0Map, mD1V0Map, mMCParticle);
if (mSVParams->mExcludeTPCtracks) {
mCounterBuildT2V.inc(BUILDT2V::TPCEXCLUDE, tvid, lbl, mD0V0Map, mD1V0Map, mMCParticle);
if (check)
mDiscardMap[make_hash(lbl.getSourceID(), lbl.getEventID(), lbl.getTrackID())] = 1 * int(BUILDT2V::TPCEXCLUDE);
continue;
}
// unconstrained TPC tracks require special treatment: there is no point in checking DCA to mean vertex since it is not precise,
Expand All @@ -509,6 +517,9 @@ void SVertexer::buildT2V(const o2::globaltracking::RecoContainer& recoData) // a
if (status) {
mCounterBuildT2V.inc(BUILDT2V::TPCSPROCESS, tvid, lbl, mD0V0Map, mD1V0Map, mMCParticle);
++cTPC;
} else {
if (check)
mDiscardMap[make_hash(lbl.getSourceID(), lbl.getEventID(), lbl.getTrackID())] = 1 * int(BUILDT2V::TPCSPROCESS);
}
continue;
}
Expand Down Expand Up @@ -615,8 +626,11 @@ bool SVertexer::checkV0(const TrackCand& seedP, const TrackCand& seedN, int iP,
// seedN.gid.print();
fitterV0.process(seedP, seedN);
fitterV0.unsetDebug();
mDiscardMap[make_hash(lbl0.getSourceID(), lbl0.getEventID(), lbl0.getTrackID())] = int(CHECKV0::FPROCESS) + 1000;
mDiscardMap[make_hash(lbl1.getSourceID(), lbl1.getEventID(), lbl1.getTrackID())] = int(CHECKV0::FPROCESS) + 1000;
}
mCounterV0.inc(CHECKV0::FPROCESS, {}, pVtx, pVtxLbl, {}, seedP, seedN, lbl0, lbl1, ok, mD0V0Map, mD1V0Map, mcReader, mDebugStream, check, true, fitterV0.isPropagationFailure(), fitterV0.getNIterations());

if (mSVParams->ret) {
return false;
}
Expand All @@ -627,6 +641,10 @@ bool SVertexer::checkV0(const TrackCand& seedP, const TrackCand& seedN, int iP,
const float dxv0 = v0XYZ[0] - mMeanVertex.getX(), dyv0 = v0XYZ[1] - mMeanVertex.getY(), r2v0 = dxv0 * dxv0 + dyv0 * dyv0;
if (r2v0 < mMinR2ToMeanVertex) {
mCounterV0.inc(CHECKV0::MINR2TOMEANVERTEX, {}, pVtx, pVtxLbl, v0XYZ, seedP, seedN, lbl0, lbl1, ok, mD0V0Map, mD1V0Map, mcReader, mDebugStream, true, check, fitterV0.isPropagationFailure());
if (check) {
mDiscardMap[make_hash(lbl0.getSourceID(), lbl0.getEventID(), lbl0.getTrackID())] = int(CHECKV0::MINR2TOMEANVERTEX) + 1000;
mDiscardMap[make_hash(lbl1.getSourceID(), lbl1.getEventID(), lbl1.getTrackID())] = int(CHECKV0::MINR2TOMEANVERTEX) + 1000;
}
if (mSVParams->ret) {
return false;
}
Expand All @@ -635,13 +653,21 @@ bool SVertexer::checkV0(const TrackCand& seedP, const TrackCand& seedN, int iP,
if (drv0P > mSVParams->causalityRTolerance || drv0P < -mSVParams->maxV0ToProngsRDiff ||
drv0N > mSVParams->causalityRTolerance || drv0N < -mSVParams->maxV0ToProngsRDiff) {
mCounterV0.inc(CHECKV0::REJCAUSALITY, {}, pVtx, pVtxLbl, v0XYZ, seedP, seedN, lbl0, lbl1, ok, mD0V0Map, mD1V0Map, mcReader, mDebugStream, true, check, fitterV0.isPropagationFailure());
if (check) {
mDiscardMap[make_hash(lbl0.getSourceID(), lbl0.getEventID(), lbl0.getTrackID())] = int(CHECKV0::REJCAUSALITY) + 1000;
mDiscardMap[make_hash(lbl1.getSourceID(), lbl1.getEventID(), lbl1.getTrackID())] = int(CHECKV0::REJCAUSALITY) + 1000;
}
if (mSVParams->ret) {
return false;
}
}
const int cand = 0;
if (!fitterV0.isPropagateTracksToVertexDone(cand) && !fitterV0.propagateTracksToVertex(cand)) {
mCounterV0.inc(CHECKV0::PROPVTX, {}, pVtx, pVtxLbl, v0XYZ, seedP, seedN, lbl0, lbl1, ok, mD0V0Map, mD1V0Map, mcReader, mDebugStream, true, check, fitterV0.isPropagationFailure());
if (check) {
mDiscardMap[make_hash(lbl0.getSourceID(), lbl0.getEventID(), lbl0.getTrackID())] = int(CHECKV0::PROPVTX) + 1000;
mDiscardMap[make_hash(lbl1.getSourceID(), lbl1.getEventID(), lbl1.getTrackID())] = int(CHECKV0::PROPVTX) + 1000;
}
if (mSVParams->ret) {
return false;
}
Expand All @@ -656,13 +682,21 @@ bool SVertexer::checkV0(const TrackCand& seedP, const TrackCand& seedN, int iP,
if (pt2V0 < mMinPt2V0) { // pt cut
LOG(debug) << "RejPt2 " << pt2V0;
mCounterV0.inc(CHECKV0::REJPT2, {}, pVtx, pVtxLbl, v0XYZ, seedP, seedN, lbl0, lbl1, ok, mD0V0Map, mD1V0Map, mcReader, mDebugStream, true, check, fitterV0.isPropagationFailure());
if (check) {
mDiscardMap[make_hash(lbl0.getSourceID(), lbl0.getEventID(), lbl0.getTrackID())] = int(CHECKV0::REJPT2) + 1000;
mDiscardMap[make_hash(lbl1.getSourceID(), lbl1.getEventID(), lbl1.getTrackID())] = int(CHECKV0::REJPT2) + 1000;
}
if (mSVParams->ret) {
return false;
}
}
if (pV0[2] * pV0[2] / pt2V0 > mMaxTgl2V0) { // tgLambda cut
LOG(debug) << "RejTgL " << pV0[2] * pV0[2] / pt2V0;
mCounterV0.inc(CHECKV0::REJTGL, {}, pVtx, pVtxLbl, v0XYZ, seedP, seedN, lbl0, lbl1, ok, mD0V0Map, mD1V0Map, mcReader, mDebugStream, true, check, fitterV0.isPropagationFailure());
if (check) {
mDiscardMap[make_hash(lbl0.getSourceID(), lbl0.getEventID(), lbl0.getTrackID())] = int(CHECKV0::REJTGL) + 1000;
mDiscardMap[make_hash(lbl1.getSourceID(), lbl1.getEventID(), lbl1.getTrackID())] = int(CHECKV0::REJTGL) + 1000;
}
if (mSVParams->ret) {
return false;
}
Expand Down Expand Up @@ -702,6 +736,11 @@ bool SVertexer::checkV0(const TrackCand& seedP, const TrackCand& seedN, int iP,
LOG(debug) << "RejHypo";
if (!checkFor3BodyDecays && !checkForCascade) {
mCounterV0.inc(CHECKV0::V0HYP, {}, pVtx, pVtxLbl, fitterV0.getPCACandidate(cand), seedP, seedN, lbl0, lbl1, ok, mD0V0Map, mD1V0Map, mcReader, mDebugStream, true, check, fitterV0.isPropagationFailure());
if (check) {
mDiscardMap[make_hash(lbl0.getSourceID(), lbl0.getEventID(), lbl0.getTrackID())] = int(CHECKV0::V0HYP) + 1000;
mDiscardMap[make_hash(lbl1.getSourceID(), lbl1.getEventID(), lbl1.getTrackID())] = int(CHECKV0::V0HYP) + 1000;
}

if (mSVParams->ret) {
return false;
}
Expand Down Expand Up @@ -752,9 +791,17 @@ bool SVertexer::checkV0(const TrackCand& seedP, const TrackCand& seedN, int iP,
} else {
if (cosPAXY < mSVParams->minCosPAXYMeanVertex) {
mCounterV0.inc(CHECKV0::COSPAXY, {}, pVtx, pVtxLbl, fitterV0.getPCACandidate(cand), seedP, seedN, lbl0, lbl1, ok, mD0V0Map, mD1V0Map, mcReader, mDebugStream, true, check, fitterV0.isPropagationFailure(), -1, cosPAXY, dca2);
if (check) {
mDiscardMap[make_hash(lbl0.getSourceID(), lbl0.getEventID(), lbl0.getTrackID())] = int(CHECKV0::COSPAXY) + 1000;
mDiscardMap[make_hash(lbl1.getSourceID(), lbl1.getEventID(), lbl1.getTrackID())] = int(CHECKV0::COSPAXY) + 1000;
}
}
if (dca2 > mMaxDCAXY2ToMeanVertex) {
mCounterV0.inc(CHECKV0::DCA2, {}, pVtx, pVtxLbl, fitterV0.getPCACandidate(cand), seedP, seedN, lbl0, lbl1, ok, mD0V0Map, mD1V0Map, mcReader, mDebugStream, true, check, fitterV0.isPropagationFailure(), -1, cosPAXY, dca2);
if (check) {
mDiscardMap[make_hash(lbl0.getSourceID(), lbl0.getEventID(), lbl0.getTrackID())] = int(CHECKV0::DCA2) + 1000;
mDiscardMap[make_hash(lbl1.getSourceID(), lbl1.getEventID(), lbl1.getTrackID())] = int(CHECKV0::DCA2) + 1000;
}
}
if (mSVParams->ret) {
return false;
Expand Down Expand Up @@ -1540,7 +1587,9 @@ void SVertexer::writeMCInfo()
if (!mcReader.initFromDigitContext("collisioncontext.root")) {
LOGP(fatal, "Initialization of MCKinematicsReader failed!");
}
int events{0};
for (int iSource{0}; iSource < mcReader.getNSources(); ++iSource) {
events += mcReader.getNEvents(iSource);
for (int iEvent{0}; iEvent < mcReader.getNEvents(iSource); ++iEvent) {
const auto& header = mcReader.getMCEventHeader(iSource, iEvent);
if (abs(header.GetZ()) > 30) {
Expand Down Expand Up @@ -1630,6 +1679,7 @@ void SVertexer::writeMCInfo()
}
}
}
LOGP(info, "+++ Sources: {} Events: {}", mcReader.getNSources(), events);
LOGP(info, "~~~~~~~~~~~~~~~~~~~MC GEN Stats~~~~~~~~~~~~~~~~");
mCounterMC.printMC();
LOGP(info, "~~~~~~~~~~~~~~~~~~~V0 pairs generated~~~~~~~~~~");
Expand Down
Loading

0 comments on commit f0fa9e4

Please sign in to comment.