Belle II Software development
TrackFindingCDCTestWithSimpleSimulation.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <tracking/trackFindingCDC/display/EventDataPlotter.h>
11#include <tracking/trackFindingCDC/sim/CDCSimpleSimulation.h>
12
13#include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
14#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment3D.h>
15#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
16#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory3D.h>
17
18#include <tracking/trackFindingCDC/topology/CDCWireTopology.h>
19
20#include <tracking/trackFindingCDC/geometry/Helix.h>
21
22#include <tracking/trackFindingCDC/testFixtures/TrackFindingCDCTestWithTopology.h>
23#include <tracking/trackFindingCDC/utilities/TimeIt.h>
24
25#include <array>
26
27namespace Belle2 {
32 namespace TrackFindingCDC {
33
37
38 public:
40 {
41 }
42
44
45 void SetUp() override
46 {
47
50 bool run_disabled = ::testing::GTEST_FLAG(also_run_disabled_tests);
51 if (run_disabled) {
54 }
55
57 m_mcAxialSegment2Ds.clear();
58 m_mcSegment2Ds.clear();
59 m_mcTracks.clear();
60 m_mcTrajectories.clear();
61 m_axialWireHits.clear();
62 m_wireHits.clear();
63 }
64
66 void simulate(const std::initializer_list<Helix>& helices)
67 {
68 simulate(std::vector<Helix>(helices));
69 }
70
71
73 void simulate(const std::vector<Helix>& helices)
74 {
75 std::vector<CDCTrajectory3D> trajectories;
76 trajectories.reserve(helices.size());
77 for (const Helix& helix : helices) {
78 // had to make the implicit convesion to an explicit conversion. Maybe there is a more elegant way to do it
79 trajectories.emplace_back(UncertainHelix(helix));
80 }
81 simulate(trajectories);
82 }
83
85 void simulate(const std::initializer_list<CDCTrajectory3D>& trajectories)
86 {
87 simulate(std::vector<CDCTrajectory3D>(trajectories));
88 }
89
91 void simulate(const std::vector<CDCTrajectory3D>& trajectories)
92 {
93 m_mcTrajectories = trajectories;
94
95 // Construct tracks. Wire hits are stored in the simple simulation
97
98 fillCaches();
99 }
100
103 {
104 // No trajectory information present
105 m_mcTrajectories.clear();
106
107 // Load prepared tracks wire hits are stored in the simple simulation
109
110 fillCaches();
111 }
112
115 {
116 for (size_t iTrack = 0; iTrack < m_mcTracks.size(); ++iTrack) {
117 B2INFO("Size mc track " << iTrack << " : " << m_mcTracks[iTrack].size());
118 }
119
120 // Prepare the monte carlo segments
121 for (const CDCTrack& mcTrack : m_mcTracks) {
122 std::vector<CDCSegment3D> segment3DsInTrack = mcTrack.splitIntoSegments();
123 for (const CDCSegment3D& segment3D : segment3DsInTrack) {
124 m_mcSegment2Ds.push_back(segment3D.stereoProjectToRef());
125 }
126 }
127
128 // Filter the axial segments
129 for (const CDCSegment2D& segment2D : m_mcSegment2Ds) {
130 if (segment2D.getStereoKind() == EStereoKind::c_Axial) {
131 m_mcAxialSegment2Ds.push_back(&segment2D);
132 }
133 }
134
135 // Filter for axial hits
136 for (const CDCWireHit& wireHit : m_simpleSimulation.getWireHits()) {
137 if (wireHit.isAxial()) {
138 m_axialWireHits.push_back(&wireHit);
139 }
140 }
141
142 // Pick up points for all hits
143 for (const CDCWireHit& wireHit : m_simpleSimulation.getWireHits()) {
144 m_wireHits.push_back(&wireHit);
145 }
146
148 for (const CDCWireHit& wireHit : m_simpleSimulation.getWireHits()) {
149 m_plotter.draw(wireHit);
150 }
151 }
152
155 { for (const CDCTrack& mcTrack : m_mcTracks) m_plotter.draw(mcTrack); }
156
159 {
160 for (const CDCTrajectory3D& mcTrajectory : m_mcTrajectories) {
161 m_plotter.draw(mcTrajectory.getTrajectory2D());
162 }
163 }
164
166 void saveDisplay(const std::string& svgFileName)
167 {
168 bool run_disabled = ::testing::GTEST_FLAG(also_run_disabled_tests);
169 if (run_disabled) {
170 m_plotter.save(svgFileName);
171 } else {
172 B2INFO("Not writing display file. To activate svg display output run with --gtest_also_run_disabled_tests");
173 }
174 }
175
181 template<class AFunction >
183 timeIt(size_t nExecutions,
184 bool activateCallgrind,
185 const AFunction& function,
186 const std::function<void()>& setUp = doNothing,
187 const std::function<void()>& tearDown = doNothing)
188 {
189 bool run_disabled = ::testing::GTEST_FLAG(also_run_disabled_tests);
190 if (not run_disabled) {
191 nExecutions = 1;
192 }
193 return Belle2::TrackFindingCDC::timeIt(nExecutions,
194 activateCallgrind,
195 function,
196 setUp,
197 tearDown);
198
199 }
200
202 template<class... Ts>
203 void draw(Ts&& ... args)
204 {
205 m_plotter.draw(std::forward<Ts>(args) ...);
206 }
207
209 void TearDown() override
210 {
213
215 m_mcAxialSegment2Ds.clear();
216 m_mcSegment2Ds.clear();
217 m_mcTracks.clear();
218 m_mcTrajectories.clear();
219 m_axialWireHits.clear();
220 m_wireHits.clear();
221 }
222
223 protected:
226
228 unsigned int m_savedDebugLogInfo = 100;
229
231 const std::array<std::string, 6> m_colors{{ "red", "blue", "green", "yellow", "violet", "cyan" }};
232
235
237 std::vector<CDCTrajectory3D> m_mcTrajectories;
238
240 std::vector<CDCTrack> m_mcTracks;
241
243 std::vector<CDCSegment2D> m_mcSegment2Ds;
244
246 std::vector<const CDCSegment2D*> m_mcAxialSegment2Ds;
247
249 std::vector<const CDCWireHit*> m_axialWireHits;
250
252 std::vector<const CDCWireHit*> m_wireHits;
253
254 private:
257
258 };
259
260 }
262}
ELogLevel getLogLevel() const
Returns the configured log level.
Definition: LogConfig.h:91
ELogLevel
Definition of the supported log levels.
Definition: LogConfig.h:26
@ c_Info
Info: for informational messages, e.g.
Definition: LogConfig.h:27
@ c_Debug
Debug: for code development.
Definition: LogConfig.h:26
unsigned int getLogInfo(ELogLevel logLevel) const
Returns the configured log information for the given level.
Definition: LogConfig.h:134
@ c_Level
Log level of the message.
Definition: LogConfig.h:36
@ c_Message
Log message text.
Definition: LogConfig.h:37
void setLogLevel(ELogLevel logLevel)
Configure the log level.
Definition: LogConfig.cc:25
void setLogInfo(ELogLevel logLevel, unsigned int logInfo)
Configure the printed log information for the given level.
Definition: LogConfig.h:127
LogConfig * getLogConfig()
Returns global log system configuration.
Definition: LogSystem.h:78
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
Definition: LogSystem.cc:31
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:39
A segment consisting of three dimensional reconstructed hits.
Definition: CDCSegment3D.h:26
Class providing a simple simulation of the CDC mainly for quick unit test checks.
ConstVectorRange< CDCWireHit > getWireHits() const
Getter for the wire hits created in the simulation.
std::vector< CDCTrack > simulate(const std::vector< CDCTrajectory3D > &trajectories3D)
Propagates the trajectories through the CDC as without energy loss until they first leave the CDC.
std::vector< CDCTrack > loadPreparedEvent()
Fills the wire hits with a hard coded event from the real simulation.
Class representing a sequence of three dimensional reconstructed hits.
Definition: CDCTrack.h:41
Particle full three dimensional trajectory.
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:55
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
A class that can plot event related data types.
const std::string save(const std::string &fileName)
Saves the current plot stead to a file.
void clear()
Clears all drawed elements from the plotter.
void draw(const Belle2::TrackFindingCDC::Circle2D &circle, AttributeMap attributeMap=AttributeMap())
Draws a filled circle.
Extension of the generalized circle also caching the perigee coordinates.
Definition: Helix.h:28
Class to capture the time a repeated execution took.
Definition: TimeIt.h:29
void simulate(const std::vector< CDCTrajectory3D > &trajectories)
Populate the event with hits generated from the given trajectories.
void simulate(const std::initializer_list< CDCTrajectory3D > &trajectories)
Populate the event with hits generated from the given trajectories.
void simulate(const std::initializer_list< Helix > &helices)
Populate the event with hits generated from the given helices.
void draw(Ts &&... args)
Forwarding draw class to the plotter instance.
void saveDisplay(const std::string &svgFileName)
Save content of the plotter to svg file only if running in unrestricted mode –gtest_also_run_disabled...
std::vector< CDCTrack > m_mcTracks
Memory for the Monte Carlo tracks of the current event.
std::vector< const CDCSegment2D * > m_mcAxialSegment2Ds
Memory for the axial Monte Carlo segments of the current event.
std::vector< CDCSegment2D > m_mcSegment2Ds
Memory for the Monte Carlo segments of the current event.
void loadPreparedEvent()
Populate the event with hits hard codes presimulated hits.
CDCSimpleSimulation m_simpleSimulation
Simple simulation generating the hits.
void simulate(const std::vector< Helix > &helices)
Populate the event with hits generated from the given helices.
TimeItResult timeIt(size_t nExecutions, bool activateCallgrind, const AFunction &function, const std::function< void()> &setUp=doNothing, const std::function< void()> &tearDown=doNothing)
Repeat a time critical simulation section a couple of times.
EventDataPlotter m_plotter
Plotter facility to generate visual representations.
std::vector< const CDCWireHit * > m_wireHits
Memory for the hits of the current event.
void plotMCTrajectories()
Add the Monte Carlo trajectories to the event plot.
LogConfig::ELogLevel m_savedLogLevel
Memory for the log level that was set before the test.
void fillCaches()
Prepare a set of hits, axial hits, segments, axial segments and track hits.
std::vector< const CDCWireHit * > m_axialWireHits
Memory for the axial hits of the current event.
unsigned int m_savedDebugLogInfo
Memory for the log info of debug that was set before the test.
std::vector< CDCTrajectory3D > m_mcTrajectories
Memory for the Monte Carlo trajectories of the current event.
const std::array< std::string, 6 > m_colors
Some colors to cycle for plotting.
This class provides the declaration of the common test fixture to all test of the track finding in th...
A general helix class including a covariance matrix.
Abstract base class for different kinds of events.