Commit 711c6f8b authored by Jens Kroeger's avatar Jens Kroeger
Browse files

Merge branch 'tracking4d_perf' into 'master'

Improve Performance of Tracking4D by Factor x2

See merge request corryvreckan/corryvreckan!291
parents da0b84a3 b25b7bbd
# Tracking4D
**Maintainer**: Simon Spannagel (<simon.spannagel@cern.ch>)
**Maintainer**: Simon Spannagel (<simon.spannagel@cern.ch>), Paul Schütze (<paul.schuetze@desy.de>)
**Module Type**: *GLOBAL*
**Status**: Functional
......
......@@ -161,33 +161,32 @@ StatusCode Tracking4D::run(std::shared_ptr<Clipboard> clipboard) {
LOG(DEBUG) << "Start of event";
// Container for all clusters, and detectors in tracking
map<string, KDTree*> trees;
map<std::shared_ptr<Detector>, KDTree*> trees;
std::string reference_first, reference_last;
std::shared_ptr<Detector> reference_first, reference_last;
for(auto& detector : get_detectors()) {
string detectorID = detector->getName();
if(excludeDUT && detector->isDUT()) {
LOG(DEBUG) << "Skipping DUT plane.";
continue;
}
// Get the clusters
auto tempClusters = clipboard->getData<Cluster>(detectorID);
auto tempClusters = clipboard->getData<Cluster>(detector->getName());
if(tempClusters == nullptr || tempClusters->size() == 0) {
LOG(DEBUG) << "Detector " << detectorID << " does not have any clusters on the clipboard";
LOG(DEBUG) << "Detector " << detector->getName() << " does not have any clusters on the clipboard";
} else {
// Store them
LOG(DEBUG) << "Picked up " << tempClusters->size() << " clusters from " << detectorID;
LOG(DEBUG) << "Picked up " << tempClusters->size() << " clusters from " << detector->getName();
KDTree* clusterTree = new KDTree();
clusterTree->buildTimeTree(*tempClusters);
trees[detectorID] = clusterTree;
trees[detector] = clusterTree;
if(reference_first.empty()) {
reference_first = detectorID;
// Get first and last detectors with clusters on them:
if(!reference_first) {
reference_first = detector;
}
reference_last = detectorID;
reference_last = detector;
}
}
......@@ -209,27 +208,28 @@ StatusCode Tracking4D::run(std::shared_ptr<Clipboard> clipboard) {
// Output track container
auto tracks = std::make_shared<TrackVector>();
// Time cut for combinations of reference clusters and for reference track with additional detector
auto time_cut_ref = std::max(time_cuts_[reference_first], time_cuts_[reference_last]);
auto time_cut_ref_track = std::min(time_cuts_[reference_first], time_cuts_[reference_last]);
for(auto& clusterFirst : trees[reference_first]->getAllClusters()) {
for(auto& clusterLast : trees[reference_last]->getAllClusters()) {
LOG(DEBUG) << "Looking at next reference cluster pair";
if(std::fabs(clusterFirst->timestamp() - clusterLast->timestamp()) > time_cut_ref) {
LOG(DEBUG) << "Reference clusters not within time cuts.";
continue;
}
// The track finding is based on a straight line. Therefore a refTrack to extrapolate to the next plane is used
// here
StraightLineTrack refTrack;
refTrack.addCluster(clusterFirst);
refTrack.addCluster(clusterLast);
if((clusterFirst->timestamp() - clusterLast->timestamp()) >
(time_cuts_[get_detector(reference_first)] + time_cuts_[get_detector(reference_last)])) {
LOG(DEBUG) << "Reference clusters not within time cuts.";
continue;
}
auto averageTimestamp = calculate_average_timestamp(&refTrack);
refTrack.setTimestamp(averageTimestamp);
// Make a new track
auto track = Track::Factory(trackModel);
track->addCluster(clusterFirst);
track->addCluster(clusterLast);
track->setTimestamp(averageTimestamp);
......@@ -243,13 +243,12 @@ StatusCode Tracking4D::run(std::shared_ptr<Clipboard> clipboard) {
if(detector->isAuxiliary()) {
continue;
}
auto detectorID = detector->getName();
// always add the material budget:
track->addMaterial(detectorID, detector->materialBudget(), detector->displacement().z());
LOG(TRACE) << "added material budget for " << detectorID << " at z = " << detector->displacement().z();
track->addMaterial(detector->getName(), detector->materialBudget(), detector->displacement().z());
LOG(TRACE) << "added material budget for " << detector->getName()
<< " at z = " << detector->displacement().z();
if(detectorID == reference_first || detectorID == reference_last) {
if(detector == reference_first || detector == reference_last) {
continue;
}
......@@ -267,13 +266,13 @@ StatusCode Tracking4D::run(std::shared_ptr<Clipboard> clipboard) {
continue;
}
if(trees.count(detectorID) == 0) {
LOG(TRACE) << "Skipping detector " << detectorID << " as it has 0 clusters.";
if(trees.count(detector) == 0) {
LOG(TRACE) << "Skipping detector " << detector->getName() << " as it has 0 clusters.";
continue;
}
// Get all neighbours within the timing cut
LOG(DEBUG) << "Searching for neighbouring cluster on device " << detectorID;
LOG(DEBUG) << "Searching for neighbouring cluster on device " << detector->getName();
LOG(DEBUG) << "- reference time is " << Units::display(refTrack.timestamp(), {"ns", "us", "s"});
Cluster* closestCluster = nullptr;
......@@ -281,12 +280,10 @@ StatusCode Tracking4D::run(std::shared_ptr<Clipboard> clipboard) {
double closestClusterDistance = sqrt(spatial_cuts_[detector].x() * spatial_cuts_[detector].x() +
spatial_cuts_[detector].y() * spatial_cuts_[detector].y());
double timeCut =
std::max(std::min(time_cuts_[get_detector(reference_first)], time_cuts_[get_detector(reference_last)]),
time_cuts_[detector]);
double timeCut = std::max(time_cut_ref_track, time_cuts_[detector]);
LOG(DEBUG) << "Using timing cut of " << Units::display(timeCut, {"ns", "us", "s"});
auto neighbours = trees[detectorID]->getAllClustersInTimeWindow(refTrack.timestamp(), timeCut);
auto neighbours = trees[detector]->getAllClustersInTimeWindow(refTrack.timestamp(), timeCut);
LOG(DEBUG) << "- found " << neighbours.size() << " neighbours within the correct time window";
......
......@@ -23,5 +23,4 @@ spatial_cut_abs = 200um, 200um
#DATASET timepix3tel_ebeam120
#PASS Ev: 18.8k Px: 6.23M Tr: 217.1k (11.5/ev) t = 3.76s
\ No newline at end of file
#PASS Ev: 18.8k Px: 6.23M Tr: 216.5k (11.5/ev) t = 3.76s
......@@ -24,4 +24,4 @@ volume_scattering_length=304m
#DATASET timepix3tel_ebeam120
#PASS Ev: 18.8k Px: 6.23M Tr: 205.4k (10.9/ev) t = 3.76s
#PASS Ev: 18.8k Px: 6.23M Tr: 205.1k (10.9/ev) t = 3.76s
......@@ -30,4 +30,4 @@ chi2ndof_cut = 8
time_cut_frameedge = 10ns
#DATASET timepix3tel_ebeam120
#PASS [F:FileWriter] Wrote 1716494 objects to 15 branches in file:
#PASS [F:FileWriter] Wrote 1716310 objects to 15 branches in file:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment