Commit c0e83502 authored by Jens Kroeger's avatar Jens Kroeger
Browse files

Merge branch 'unique' into 'master'

Tracking4D: Unique cluster usage

See merge request !436
parents cb277807 81fcda81
Pipeline #2700547 passed with stages
in 20 minutes and 3 seconds
......@@ -25,6 +25,7 @@ The DUT plane can be excluded from the track finding.
* `volume_scattering`: Select if volume scattering will be taken into account - defaults to false
* `volume_radiation_length`: Define the radiation length of the volume around the telescope. Defaults to dry air with a radiation length of`304.2 m`
* `reject_by_roi`: If true, tracks intercepting any detector outside its ROI will be rejected. Defaults to `false`.
* `uinque_cluster_usage`: Only use a cluster for one track - in the case of multiple assignments, the track with the best chi2/ndof is kept. Defaults to `false`
### Plots produced
......
......@@ -32,6 +32,7 @@ Tracking4D::Tracking4D(Configuration& config, std::vector<std::shared_ptr<Detect
config_.setDefault<double>("volume_radiation_length", Units::get<double>(304.2, "m"));
config_.setDefault<bool>("volume_scattering", false);
config_.setDefault<bool>("reject_by_roi", false);
config_.setDefault<bool>("unique_cluster_usage", false);
if(config_.count({"time_cut_rel", "time_cut_abs"}) == 0) {
config_.setDefault("time_cut_rel", 3.0);
......@@ -62,6 +63,7 @@ Tracking4D::Tracking4D(Configuration& config, std::vector<std::shared_ptr<Detect
volume_radiation_length_ = config_.get<double>("volume_radiation_length");
use_volume_scatterer_ = config_.get<bool>("volume_scattering");
reject_by_ROI_ = config_.get<bool>("reject_by_roi");
unique_cluster_usage_ = config_.get<bool>("unique_cluster_usage");
// print a warning if volumeScatterer are used as this causes fit failures
// that are still not understood
......@@ -402,7 +404,61 @@ StatusCode Tracking4D::run(const std::shared_ptr<Clipboard>& clipboard) {
LOG_N(WARNING, 100) << "Rejected a track due to failure in fitting";
continue;
}
// Fill histograms
if(timestamp_from_.empty()) {
// Improve the track timestamp by taking the average of all planes
auto timestamp = calculate_average_timestamp(track.get());
track->setTimestamp(timestamp);
LOG(DEBUG) << "Using average cluster timestamp of " << Units::display(timestamp, "us")
<< " as track timestamp.";
} else {
// use timestamp of required detector:
double track_timestamp = track->getClusterFromDetector(timestamp_from_)->timestamp();
LOG(DEBUG) << "Using timestamp of detector " << timestamp_from_
<< " as track timestamp: " << Units::display(track_timestamp, "us");
track->setTimestamp(track_timestamp);
}
}
}
auto duplicated_hit = [this](const Track* a, const Track* b) {
for(auto d : get_detectors()) {
if(a->getClusterFromDetector(d->getName()) == b->getClusterFromDetector(d->getName()) &&
!(b->getClusterFromDetector(d->getName()) == nullptr)) {
LOG(DEBUG) << "Duplicated hit on " << d->getName() << ": rejecting track";
return true;
}
}
return false;
};
// Save the tracks on the clipboard
if(tracks.size() > 0) {
// if requested ensure unique usage of clusters
if(unique_cluster_usage_ && tracks.size() > 1) {
// sort by chi2:
LOG_ONCE(WARNING) << "Rejecting tracks with same hits";
std::sort(tracks.begin(), tracks.end(), [](const shared_ptr<Track> a, const shared_ptr<Track> b) {
return (a->getChi2() / a->getNdof()) < (b->getChi2() / b->getNdof());
});
// remove tracks with hit that is used twice
auto track1 = tracks.begin();
while(track1 != tracks.end()) {
auto track2 = track1 + 1;
while(track2 != tracks.end()) {
// if hit is used twice delete the track
if(duplicated_hit(track2->get(), track1->get())) {
track2 = tracks.erase(track2);
} else {
track2++;
}
}
track1++;
}
}
clipboard->putData(tracks);
}
for(auto track : tracks) {
trackChi2->Fill(track->getChi2());
clustersPerTrack->Fill(static_cast<double>(track->getNClusters()));
trackChi2ndof->Fill(track->getChi2ndof());
......@@ -466,30 +522,9 @@ StatusCode Tracking4D::run(const std::shared_ptr<Clipboard>& clipboard) {
kinkX.at(det)->Fill(kink.x());
kinkY.at(det)->Fill(kink.y());
}
if(timestamp_from_.empty()) {
// Improve the track timestamp by taking the average of all planes
auto timestamp = calculate_average_timestamp(track.get());
track->setTimestamp(timestamp);
LOG(DEBUG) << "Using average cluster timestamp of " << Units::display(timestamp, "us")
<< " as track timestamp.";
} else {
// use timestamp of required detector:
double track_timestamp = track->getClusterFromDetector(timestamp_from_)->timestamp();
LOG(DEBUG) << "Using timestamp of detector " << timestamp_from_
<< " as track timestamp: " << Units::display(track_timestamp, "us");
track->setTimestamp(track_timestamp);
}
}
}
tracksPerEvent->Fill(static_cast<double>(tracks.size()));
// Save the tracks on the clipboard
if(tracks.size() > 0) {
clipboard->putData(tracks);
}
LOG(DEBUG) << "End of event";
return StatusCode::Success;
}
......@@ -74,6 +74,7 @@ namespace corryvreckan {
bool exclude_DUT_;
bool use_volume_scatterer_;
bool reject_by_ROI_;
bool unique_cluster_usage_;
std::vector<std::string> require_detectors_;
std::map<std::shared_ptr<Detector>, double> time_cuts_;
std::map<std::shared_ptr<Detector>, XYVector> spatial_cuts_;
......
Markdown is supported
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