Commit 3d980a26 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Merge branch 'cleanup_improve_reference_timestamp' into 'master'

Cleanup ImproveReferenceTimestamp

See merge request !407
parents cb115aec 25927b3f
Pipeline #2575954 passed with stages
in 24 minutes and 28 seconds
......@@ -17,18 +17,29 @@ using namespace std;
ImproveReferenceTimestamp::ImproveReferenceTimestamp(Configuration& config, std::vector<std::shared_ptr<Detector>> detectors)
: Module(config, std::move(detectors)) {
config_.setDefault<int>("improvement_method", 1);
config_.setDefault<std::string>("signal_source", "W0013_G02");
config_.setDefault<double>("trigger_latency", Units::get<double>(0, "ns"));
config_.setDefault<double>("search_window", Units::get<double>(100, "ns"));
m_method = config_.get<int>("improvement_method");
m_source = config_.get<std::string>("signal_source");
m_triggerLatency = config_.get<double>("trigger_latency");
m_searchWindow = config_.get<double>("search_window");
}
void ImproveReferenceTimestamp::initialize() {
// Initialise member variables
m_eventNumber = 0;
m_improvedTriggers = 0;
m_noTriggerOnClipboard = 0;
m_noTriggerInWindow = 0;
hTriggersPerEvent = new TH1D("hTriggersPerEvent", "hTriggersPerEvent;triggers per event;# entries", 20, -0.5, 19.5);
hTracksPerEvent = new TH1D("hTracksPerEvent", "hTracksPerEvent;tracks per event;# entries", 20, -0.5, 19.5);
hTrackTriggerTimeCorrelation = new TH1D("hTrackTriggerTimeCorrelation",
"hTrackTriggerTimeCorrelation;ts_{track} - ts_{trigger} [ns];# entries",
1000,
-500.5,
499.5);
}
StatusCode ImproveReferenceTimestamp::run(const std::shared_ptr<Clipboard>& clipboard) {
......@@ -49,15 +60,25 @@ StatusCode ImproveReferenceTimestamp::run(const std::shared_ptr<Clipboard>& clip
// Get the tracks from the clipboard
auto tracks = clipboard->getData<Track>();
LOG(DEBUG) << "Number of tracks found: " << tracks.size();
hTriggersPerEvent->Fill(static_cast<double>(trigger_times.size()));
hTracksPerEvent->Fill(static_cast<double>(tracks.size()));
for(auto& track : tracks) {
double improved_time = track->timestamp();
// Use trigger timestamp
if(m_method == 0) {
// Find trigger timestamp closest in time
double diff = std::numeric_limits<double>::max();
// Find trigger timestamp closest in time
double diff = std::numeric_limits<double>::max();
if(!trigger_times.size()) {
LOG(DEBUG) << "No triggers, removing track.";
clipboard->removeData(track);
m_noTriggerOnClipboard++;
} else {
for(auto& trigger_time : trigger_times) {
hTrackTriggerTimeCorrelation->Fill(track->timestamp() - trigger_time);
LOG(DEBUG) << " track: " << track->timestamp() << " trigger: " << trigger_time
<< " diff: " << Units::display(abs(trigger_time - track->timestamp()), {"ns", "us", "s"})
<< " diff stored: " << Units::display(diff, {"ns", "us", "s"});
......@@ -66,26 +87,16 @@ StatusCode ImproveReferenceTimestamp::run(const std::shared_ptr<Clipboard>& clip
diff = abs(trigger_time - track->timestamp());
}
}
}
// Use average track timestamp
else if(m_method == 1) {
int nhits = 0;
double avg_track_time = 0;
for(auto& cluster : track->getClusters()) {
avg_track_time += cluster->timestamp();
nhits++;
if(diff < m_searchWindow) {
LOG(DEBUG) << "Found trigger within search window, improving track timestamp.";
track->setTimestamp(improved_time);
m_improvedTriggers++;
} else {
LOG(DEBUG) << "No trigger within search window, removing track.";
clipboard->removeData(track);
m_noTriggerInWindow++;
}
improved_time = round(avg_track_time / nhits);
LOG(DEBUG) << setprecision(12) << "Reference track time "
<< Units::display(track->timestamp(), {"ns", "us", "s"});
LOG(DEBUG) << setprecision(12) << "Average track time " << Units::display(improved_time, {"ns", "us", "s"});
}
// Set improved reference timestamp
track->setTimestamp(improved_time);
LOG(DEBUG) << "End of track";
}
// Increment event counter
......@@ -98,5 +109,7 @@ StatusCode ImproveReferenceTimestamp::run(const std::shared_ptr<Clipboard>& clip
void ImproveReferenceTimestamp::finalize(const std::shared_ptr<ReadonlyClipboard>&) {
LOG(DEBUG) << "Analysed " << m_eventNumber << " events";
LOG(STATUS) << "Analysed " << m_eventNumber << " events, improved track timestamps: " << m_improvedTriggers
<< ", no trigger on clipboard: " << m_noTriggerOnClipboard
<< ", no trigger in search window: " << m_noTriggerInWindow;
}
......@@ -36,18 +36,18 @@ namespace corryvreckan {
StatusCode run(const std::shared_ptr<Clipboard>& clipboard) override;
void finalize(const std::shared_ptr<ReadonlyClipboard>& clipboard) override;
// Histograms for several devices
std::map<std::string, TH2F*> plotPerDevice;
// Single histograms
TH1F* singlePlot;
TH1D* hTriggersPerEvent;
TH1D* hTracksPerEvent;
TH1D* hTrackTriggerTimeCorrelation;
// Member variables
int m_eventNumber;
int m_method;
bool m_stop;
int m_noTriggerOnClipboard;
int m_noTriggerInWindow;
int m_improvedTriggers;
std::string m_source;
double m_triggerLatency;
double m_searchWindow;
};
} // namespace corryvreckan
#endif // ImproveReferenceTimestamp_H
# ImproveReferenceTimestamp
**Maintainer**: Florian Pitters (<florian.pitters@cern.ch>)
**Maintainer**: Florian Pitters (<florian.pitters@cern.ch>), Jens Kroeger (<jens.kroeger@cern.ch>)
**Module Type**: *GLOBAL*
**Status**: Work in progress
**Status**: Working
### Description
Replaces the existing reference timestamp (earliest hit on reference plane) by either the trigger timestamp (method 0) or the average track timestamp (method 1). For method 0 to work, a trigger timestamp has to be saved as SPIDR signal during data taking.
Replaces the existing track timestamp (set in the tracking module) by the closest trigger timestamp. For this, a trigger timestamp has to be saved as SPIDR signal during data taking.
If no suitable trigger is found for a track, the track is removed from the clipboard and thus not available any further.
### Parameters
* `improvement_method`: Determines which method to use. Trigger timestamp is 0, average track timestamp is 1. Default value is `1`.
* `signal_source`: Determines which detector plane carries the trigger signals. Only relevant for method 0. Default value is `"W0013_G02"`.
* `trigger_latency`: Adds a latency to the trigger timestamp to shift time histograms. Default value is `0`.
* `search_window`: Time window to search for SPIDR trigger signals around the track timestamp. Default value is `200ns`.
### Plots produced
The following plots are produced:
* number of triggers per event
* number of tracks per event
* time correlation between track and trigger timestamps
### Usage
```toml
[ImproveReferenceTimestamp]
improvement_method = 0
signal_source = "W0013_G02"
trigger_latency = 20ns
```
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