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
15 changes: 13 additions & 2 deletions python/SndlhcMuonReco.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ class MuonReco(ROOT.FairTask):

def Init(self):
"""Initialize the task."""
ROOT.gInterpreter.Declare(r"""
#include "TClonesArray.h"
#include "sndRecoTrack.h"

// Construct a *copy* of src inside arr at index i (placement new).
sndRecoTrack* EmplaceSndRecoTrack(TClonesArray* arr, int i, const sndRecoTrack& src) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're stuck with many TCAs, it might be worth making this a template function for any object inheriting from TObject and declare it somewhere centrally.

return new((*arr)[i]) sndRecoTrack(src);
}
""")
self.logger = ROOT.FairLogger.GetLogger()
if self.logger.IsLogNeeded(ROOT.fair.Severity.info):
print("Initializing muon reconstruction task!")
Expand Down Expand Up @@ -583,7 +592,7 @@ def SetStandalone(self):
def Exec(self, opt):
"""Core part of teh task."""
self.kalman_tracks.Clear("C")

nStored = 0
# Set scaling in case task is run seperately from other tracking tasks
if self.scale > 1 and self.standalone:
if ROOT.gRandom.Rndm() > 1.0 / self.scale:
Expand Down Expand Up @@ -1123,7 +1132,9 @@ def Exec(self, opt):
this_track.setRawMeasTimes(pointTimes)
this_track.setTrackType(self.track_type)
# Save the track in sndRecoTrack format
self.kalman_tracks[i_muon] = this_track
self.kalman_tracks.ExpandCreate(nStored + 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be avoided, as this might involve copying the entire array. It's probably better to only expand the array by a growth factor whenever we reach its capacity.

ROOT.EmplaceSndRecoTrack(self.kalman_tracks, int(nStored), this_track)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't want to define our own function, TClonesArray::ConstructedAt() followed by std::swap() can be used.

nStored += 1
# Delete the Kalman track object
theTrack.Delete()

Expand Down