Skip to content

Commit 612f9ef

Browse files
authored
Add contributesToAHit flag to MCTrack (#15996)
* Add contributesToAHit flag to MCTrack This adds a per-track flag for tracks that deposit into a hit created by another track, and a unit test. - MCTrack uses the previously reserved bit in mProp for the flag, so the storage layout is unchanged. - Stack::modifiesHit(iDet) sets the flag on the current track without touching the hit mask, kHasHits or the hit counter. - Kinematics pruning and output size are therefore unchanged. - EMCAL, PHOS, FOCAL, ZDC, FT0 and ALICE 3 ECal call modifiesHit where a track adds to an existing hit. https://its.cern.ch/jira/browse/O2-7172
1 parent 561ba48 commit 612f9ef

10 files changed

Lines changed: 77 additions & 4 deletions

File tree

‎DataFormats/simulation/include/SimulationDataFormat/MCTrack.h‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ class MCTrackT
250250

251251
bool isTransported() const { return getToBeDone() && !getInhibited(); };
252252

253+
/// mark that this track deposited into a hit created by another track
254+
void setContributesToAHit(bool f = true)
255+
{
256+
auto prop = ((PropEncoding)mProp);
257+
prop.contributesToAHit = f;
258+
mProp = prop.i;
259+
}
260+
bool getContributesToAHit() const { return ((PropEncoding)mProp).contributesToAHit; }
261+
253262
/// get the string representation of the production process
254263
const char* getProdProcessAsString() const;
255264

@@ -286,7 +295,7 @@ class MCTrackT
286295
int storage : 1; // encoding whether to store this track to the output
287296
unsigned int process : 6; // encoding process that created this track (enough to store TMCProcess from ROOT)
288297
int hitmask : NHITBITS; // encoding hits per detector
289-
int reserved1 : 1; // bit reserved for possible future purposes
298+
int contributesToAHit : 1; // whether this track deposited into a hit created by another track
290299
int inhibited : 1; // whether tracking of this was inhibited
291300
int toBeDone : 1; // whether this (still) needs tracking --> we might more complete information to cover full ParticleStatus space
292301
};

‎Detectors/Base/include/DetectorsBase/Stack.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ class Stack : public FairGenericStack
172172
/// Increment number of hits for the current track in a given detector
173173
/// \param iDet Detector unique identifier
174174
void addHit(int iDet);
175+
/// Mark the current track as contributing to a hit created by another track
176+
/// \param iDet Detector unique identifier
177+
void modifiesHit(int iDet);
175178

176179
TClonesArray* GetListOfParticles() override;
177180

‎Detectors/Base/src/Stack.cxx‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ void Stack::PushTrack(Int_t toBeDone, Int_t parentId, Int_t pdgCode, Double_t px
193193
TMCProcess proc2)
194194
{
195195
// printf("Pushing %s toBeDone %5d parentId %5d pdgCode %5d is %5d entries %5d \n",
196-
// proc == kPPrimary ? "Primary: " : "Secondary: ",
197-
// toBeDone, parentId, pdgCode, is, mNumberOfEntriesInParticles);
196+
// proc == kPPrimary ? "Primary: " : "Secondary: ",
197+
// toBeDone, parentId, pdgCode, is, mNumberOfEntriesInParticles);
198198

199199
//
200200
// This method is called
@@ -653,6 +653,16 @@ void Stack::addHit(int iDet)
653653
mCurrentParticle.SetBit(ParticleStatus::kHasHits, 1);
654654
mHitCounter++;
655655
}
656+
void Stack::modifiesHit(int iDet)
657+
{
658+
// flag only; hit mask, kHasHits and hit counter stay untouched
659+
if (mIndexOfCurrentTrack < mNumberOfPrimaryParticles) {
660+
mTracks->at(mIndexOfCurrentTrack).setContributesToAHit();
661+
} else {
662+
Int_t iTrack = mTrackIDtoParticlesEntry[mIndexOfCurrentTrack];
663+
mParticles[iTrack].setContributesToAHit();
664+
}
665+
}
656666
void Stack::addHit(int iDet, Int_t iTrack)
657667
{
658668
mHitCounter++;

‎Detectors/Base/test/testStack.cxx‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,42 @@ BOOST_AUTO_TEST_CASE(Offsetting_keeps_an_invalid_index_invalid)
180180
BOOST_CHECK_EQUAL(o2::base::Detector::offsetTrackIndex(7, nprimaries, primaryOffset, secondaryOffset), 107);
181181
BOOST_CHECK_EQUAL(o2::base::Detector::offsetTrackIndex(-1, nprimaries, primaryOffset, secondaryOffset), -1);
182182
}
183+
184+
// modifiesHit flags the current track without touching hit mask or pruning
185+
BOOST_AUTO_TEST_CASE(Stack_modifiesHit_test)
186+
{
187+
const int iDet = o2::detectors::DetID::EMC;
188+
for (bool prune : {false, true}) {
189+
o2::data::Stack st;
190+
st.pruneKinematics(prune);
191+
const auto prim = pushTrack(st, -1, kPPrimary);
192+
st.SetCurrentTrack(prim);
193+
// use grandchildren, since direct daughters of primaries are always kept
194+
const auto sec = pushTrack(st, prim, kPHadronic);
195+
const auto flagged = pushTrack(st, sec, kPHadronic);
196+
const auto other = pushTrack(st, sec, kPHadronic);
197+
198+
st.modifiesHit(iDet);
199+
st.SetCurrentTrack(flagged);
200+
st.modifiesHit(iDet);
201+
BOOST_CHECK(!st.currentTrackLeftHit());
202+
st.SetCurrentTrack(other);
203+
st.FinishPrimary();
204+
205+
auto const& tracks = *st.getMCTracks();
206+
if (prune) {
207+
// a flagged track without hits is still pruned
208+
BOOST_CHECK_EQUAL(tracks.size(), 2);
209+
} else {
210+
BOOST_REQUIRE_EQUAL(tracks.size(), 4);
211+
BOOST_CHECK(!tracks[sec].getContributesToAHit());
212+
BOOST_CHECK(tracks[flagged].getContributesToAHit());
213+
BOOST_CHECK(!tracks[other].getContributesToAHit());
214+
}
215+
BOOST_CHECK(tracks[prim].getContributesToAHit());
216+
for (auto const& t : tracks) {
217+
BOOST_CHECK_EQUAL(t.getHitMask(), 0);
218+
BOOST_CHECK(!t.hasHits());
219+
}
220+
}
221+
}

‎Detectors/EMCAL/simulation/src/Detector.cxx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ Bool_t Detector::ProcessHits(FairVolume* v)
313313
} else {
314314
LOG(debug3) << "Adding energy to the current hit" << std::endl;
315315
currenthit->SetEnergyLoss(currenthit->GetEnergyLoss() + lightyield);
316+
o2stack->modifiesHit(GetDetId());
316317
}
317318
}
318319

‎Detectors/FIT/FT0/simulation/src/Detector.cxx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,9 +1180,12 @@ Bool_t Detector::ProcessHits(FairVolume* v)
11801180
o2::ft0::HitType* Detector::AddHit(float x, float y, float z, float time, float energy, Int_t trackId, Int_t detId)
11811181
{
11821182
mHits->emplace_back(x, y, z, time, energy, trackId, detId);
1183+
auto stack = (o2::data::Stack*)fMC->GetStack();
11831184
if (energy == 10) {
1184-
auto stack = (o2::data::Stack*)fMC->GetStack();
11851185
stack->addHit(GetDetId());
1186+
} else {
1187+
// optical photon contributing to a hit recorded for its parent
1188+
stack->modifiesHit(GetDetId());
11861189
}
11871190
return &(mHits->back());
11881191
}

‎Detectors/FOCAL/simulation/src/Detector.cxx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,7 @@ bool Detector::ProcessHitsEPad(FairVolume* v)
13351335
} else {
13361336
LOG(debug3) << "Adding energy to the current hit";
13371337
currenthit->SetEnergyLoss(currenthit->GetEnergyLoss() + eloss);
1338+
o2stack->modifiesHit(GetDetId());
13381339
}
13391340
return true;
13401341
}
@@ -1384,6 +1385,7 @@ bool Detector::ProcessHitsHCAL(FairVolume* v)
13841385
} else {
13851386
LOG(debug3) << "Adding energy to the current hit";
13861387
currenthit->SetEnergyLoss(currenthit->GetEnergyLoss() + eloss);
1388+
o2stack->modifiesHit(GetDetId());
13871389
}
13881390
return true;
13891391
}
@@ -1433,6 +1435,7 @@ bool Detector::ProcessHitsEPix(FairVolume* v)
14331435
} else {
14341436
LOG(debug3) << "Adding energy to the current hit";
14351437
currenthit->SetEnergyLoss(currenthit->GetEnergyLoss() + eloss);
1438+
o2stack->modifiesHit(GetDetId());
14361439
}
14371440
return true;
14381441
}

‎Detectors/PHOS/simulation/src/Detector.cxx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ Bool_t Detector::ProcessHits(FairVolume* v)
169169
if (lostenergy < DBL_EPSILON && !isNewPartile) {
170170
return false; // do not create hits with zero energy deposition
171171
}
172+
if (!isNewPartile) { // track deposits into a hit of its super-parent
173+
stack->modifiesHit(GetDetId());
174+
}
172175

173176
Int_t moduleNumber;
174177
fMC->CurrentVolOffID(

‎Detectors/Upgrades/ALICE3/ECal/simulation/src/Detector.cxx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ bool Detector::ProcessHits(FairVolume* vol)
383383
stack->addHit(GetDetId());
384384
} else {
385385
hit->SetEnergyLoss(hit->GetEnergyLoss() + eloss);
386+
stack->modifiesHit(GetDetId());
386387
}
387388
return true;
388389
}

‎Detectors/ZDC/simulation/src/Detector.cxx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ Bool_t Detector::ProcessHits(FairVolume* v)
527527
curHit.SetEnergyLoss(incenloss);
528528
curHit.setPMCLightYield(curHit.getPMCLightYield() + nPMC);
529529
curHit.setPMQLightYield(curHit.getPMQLightYield() + nPMQ);
530+
stack->modifiesHit(GetDetId());
530531
//printf(" >>> Hit updated in vol %d %d for track %d (mother: %d) \t light %1.0f %1.0f \n",
531532
//detector, sector, trackn, stack->GetCurrentTrack()->GetFirstMother(), curHit.getPMCLightYield(), curHit.getPMQLightYield());
532533
}

0 commit comments

Comments
 (0)