Commit 8aad6124 authored by Daniel Charles Craik's avatar Daniel Charles Craik Committed by Dorothea Vom Bruch
Browse files

Monitoring of track features

parent f0108b1b
......@@ -519,6 +519,10 @@ the numbers of successfully monitored and skipped slices as well as the monitori
Monitor classes
---------------
Currently, monitoring is performed of the rate for each HLT line (`RateMonitor`) and for the momentum,
pT and chi^2(IP) of each track produced by the Kalman filter (`TrackMonitor`). Further monitoring histograms
can be either added to one of these classes or to a new monitoring class, as appropriate.
Additional monitors that produce histograms based on information in the `HostBuffers` should be added to
`integration/monitoring` and inherit from the `BufferMonitor` class. The `RateMonitor` class provides an
example of this. Furthermore, each histogram that is added must be given a unique key in MonitorBase::MonHistType.
......@@ -529,6 +533,14 @@ of the class in the vectors created in `MonitorManager::init`, e.g.
m_monitors.back().push_back(new RateMonitor(buffers_manager, time_step, offset));
```
To monitor a feature, either that feature or others from which it can be calculated must be present in the
`HostBuffers`. For example, the features recorded by `TrackMonitor` depend on the buffers `host_kf_tracks`
(for the track objects) and `host_atomics_scifi` (for the number of tracks in each event and the offset to the
start of each event). It is important that any buffers used by the monitoring are copied from the device to
the host memory and that they do not depend on `runtime_options.do_check` being set. Additionally, to avoid
a loss of performance, these buffers must be written to pinned memory, i.e. the memory must be allocated by
`cudaMallocHost` and not by `malloc` in `HostBuffers::reserve`.
Saving histograms
-----------------
......
......@@ -23,7 +23,10 @@ struct MonitorBase {
SingleMuonRate,
DispDimuonRate,
HighMassDimuonRate,
InclusiveRate
InclusiveRate,
KalmanTrackP,
KalmanTrackPt,
KalmanTrackIPChi2
};
MonitorBase(std::string name, int timeStep, int offset) : m_name(name), m_time_step(timeStep), m_offset(offset) {};
......
#pragma once
#include "BufferMonitor.h"
struct HostBuffersManager;
struct TrackMonitor : public BufferMonitor {
TrackMonitor(HostBuffersManager* buffers_manager, int timeStep = 30, int offset = 0) :
BufferMonitor("kalmanTracks", timeStep, offset), m_buffers_manager(buffers_manager)
{
init();
};
virtual ~TrackMonitor() = default;
void fill(uint i_buf, bool useWallTime = true) override;
private:
void init();
HostBuffersManager* m_buffers_manager;
};
#include "MonitorManager.h"
#include "RateMonitor.h"
#include "TrackMonitor.h"
#include "HostBuffersManager.cuh"
#include "Logger.h"
......@@ -66,6 +67,7 @@ void MonitorManager::init(uint n_mon_thread, HostBuffersManager* buffers_manager
for (uint i = 0; i < n_mon_thread; ++i) {
m_monitors.push_back(std::vector<BufferMonitor*>());
m_monitors.back().push_back(new RateMonitor(buffers_manager, time_step, offset));
m_monitors.back().push_back(new TrackMonitor(buffers_manager, time_step, offset));
free_monitors.push(i);
}
}
#include "TrackMonitor.h"
#include "HostBuffers.cuh"
#include "HostBuffersManager.cuh"
#include "Logger.h"
#include "HltDecReport.cuh"
#include "RawBanksDefinitions.cuh"
#include <cmath>
#ifdef WITH_ROOT
void TrackMonitor::fill(uint i_buf, bool)
{
HostBuffers* buf = m_buffers_manager->getBuffers(i_buf);
uint nevt = buf->host_number_of_selected_events[0];
int* trk_offsets = buf->host_atomics_scifi + nevt;
for (uint ievt = 0; ievt < nevt; ++ievt) {
int ntrk = buf->host_atomics_scifi[ievt];
uint trk_offset = trk_offsets[ievt];
for (int itrk = 0; itrk < ntrk; ++itrk) {
ParKalmanFilter::FittedTrack track = buf->host_kf_tracks[trk_offset + itrk];
m_histograms[MonHistType::KalmanTrackP]->Fill(track.p());
m_histograms[MonHistType::KalmanTrackPt]->Fill(track.pt());
m_histograms[MonHistType::KalmanTrackIPChi2]->Fill(log(track.ipChi2));
}
}
}
void TrackMonitor::init()
{
uint nBins = 1000;
m_histograms.emplace(MonHistType::KalmanTrackP, new TH1D("trackP", "", nBins, 0., 1e6));
m_histograms.emplace(MonHistType::KalmanTrackPt, new TH1D("trackPt", "", nBins, 0., 2e4));
m_histograms.emplace(MonHistType::KalmanTrackIPChi2, new TH1D("trackLogIPChi2", "", nBins, -10., 10.));
for (auto kv : m_histograms) {
kv.second->SetDirectory(nullptr);
kv.second->Sumw2();
}
}
#else
void TrackMonitor::fill(uint, bool) {}
void TrackMonitor::init() {}
#endif
......@@ -40,6 +40,10 @@ void HostBuffers::reserve(const uint max_number_of_events, const bool do_check)
host_allocated_prefix_sum_space = 10000000;
cudaCheck(cudaMallocHost((void**) &host_prefix_sum_buffer, host_allocated_prefix_sum_space * sizeof(uint)));
// Needed for track monitoring
cudaCheck(cudaMallocHost((void**) &host_atomics_scifi, max_number_of_events * SciFi::num_atomics * sizeof(int)));
cudaCheck(cudaMallocHost((void**) &host_kf_tracks, max_number_of_events * SciFi::Constants::max_tracks * sizeof(ParKalmanFilter::FittedTrack)));
if (do_check) {
// Datatypes to be reserved only if checking is on
// Note: These datatypes in principle do not require to be pinned
......@@ -71,8 +75,6 @@ void HostBuffers::reserve(const uint max_number_of_events, const bool do_check)
host_ut_track_velo_indices = reinterpret_cast<decltype(host_ut_track_velo_indices)>(
malloc(max_number_of_events * UT::Constants::max_num_tracks * sizeof(int)));
host_atomics_scifi = reinterpret_cast<decltype(host_atomics_scifi)>(malloc(
max_number_of_events * SciFi::num_atomics * sizeof(int)));
host_scifi_tracks = reinterpret_cast<decltype(host_scifi_tracks)>(malloc(
max_number_of_events * UT::Constants::max_num_tracks *
LookingForward::maximum_number_of_candidates_per_ut_track * sizeof(SciFi::TrackHits)));
......@@ -109,8 +111,6 @@ void HostBuffers::reserve(const uint max_number_of_events, const bool do_check)
host_number_of_multivertex =
reinterpret_cast<decltype(host_number_of_multivertex)>(malloc(max_number_of_events * sizeof(int)));
host_kf_tracks = reinterpret_cast<decltype(host_kf_tracks)>(
malloc(max_number_of_events * SciFi::Constants::max_tracks * sizeof(ParKalmanFilter::FittedTrack)));
host_muon_catboost_output = reinterpret_cast<decltype(host_muon_catboost_output)>(
malloc(max_number_of_events * SciFi::Constants::max_tracks * sizeof(float)));
host_is_muon = reinterpret_cast<decltype(host_is_muon)>(
......
......@@ -45,14 +45,14 @@ void SequenceVisitor::visit<consolidate_scifi_tracks_t>(
state.invoke();
// Transmission device to host of Scifi consolidated tracks
if (runtime_options.do_check) {
cudaCheck(cudaMemcpyAsync(
host_buffers.host_atomics_scifi,
arguments.offset<dev_atomics_scifi>(),
arguments.size<dev_atomics_scifi>(),
cudaMemcpyDeviceToHost,
cuda_stream));
cudaCheck(cudaMemcpyAsync(
host_buffers.host_atomics_scifi,
arguments.offset<dev_atomics_scifi>(),
arguments.size<dev_atomics_scifi>(),
cudaMemcpyDeviceToHost,
cuda_stream));
if (runtime_options.do_check) {
cudaCheck(cudaMemcpyAsync(
host_buffers.host_scifi_track_hit_number,
arguments.offset<dev_scifi_track_hit_number>(),
......
......@@ -37,12 +37,10 @@ void SequenceVisitor::visit<kalman_pv_ipchi2_t>(
arguments.offset<dev_is_muon>());
state.invoke();
if (runtime_options.do_check) {
cudaCheck(cudaMemcpyAsync(
host_buffers.host_kf_tracks,
arguments.offset<dev_kf_tracks>(),
arguments.size<dev_kf_tracks>(),
cudaMemcpyDeviceToHost,
cuda_stream));
}
cudaCheck(cudaMemcpyAsync(
host_buffers.host_kf_tracks,
arguments.offset<dev_kf_tracks>(),
arguments.size<dev_kf_tracks>(),
cudaMemcpyDeviceToHost,
cuda_stream));
}
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