16 #include "GaudiKernel/ThreadLocalContext.h"
25 const IInterface*
p ) :
27 m_selectionString(
""),
31 m_npass_pix_states(0),
32 m_ntot_pix_measurements(0),
33 m_npass_pix_measurements(0),
35 m_npass_sct_states(0),
36 m_ntot_sct_measurements(0),
37 m_npass_sct_measurements(0),
39 m_npass_trt_states(0),
40 m_ntot_trt_measurements(0),
41 m_npass_trt_measurements(0),
42 m_thinHitsOnTrack(false)
56 if (m_selectionString.empty()) {
57 ATH_MSG_FATAL(
"No inner detector track selection string provided!");
58 return StatusCode::FAILURE;
59 }
else {
ATH_MSG_INFO(
"Track thinning selection string: " << m_selectionString);}
62 if (!m_selectionString.empty()) {
63 ATH_CHECK(initializeParser(m_selectionString));
67 ATH_CHECK( m_inDetSGKey.initialize (m_streamName) );
68 ATH_MSG_INFO(
"Using " << m_inDetSGKey <<
"as the source collection for inner detector track particles");
70 if (m_thinHitsOnTrack) {
71 ATH_MSG_INFO(
"Pixel states collection as source for thinning: " << m_statesPixSGKey.key());
72 ATH_MSG_INFO(
"Pixel measurements collection as source for thinning: " << m_measurementsPixSGKey.key());
73 ATH_MSG_INFO(
"SCT states collection as source for thinning: " << m_statesSctSGKey.key());
74 ATH_MSG_INFO(
"SCT measurements collection as source for thinning: " << m_measurementsSctSGKey.key());
75 ATH_MSG_INFO(
"TRT states collection as source for thinning: " << m_statesTrtSGKey.key());
76 ATH_MSG_INFO(
"TRT measurements collection as source for thinning: " << m_measurementsTrtSGKey.key());
78 ATH_CHECK( m_statesPixSGKey.initialize (m_streamName, m_thinHitsOnTrack && !m_statesPixSGKey.empty()) );
79 ATH_CHECK( m_measurementsPixSGKey.initialize (m_streamName, m_thinHitsOnTrack && !m_measurementsPixSGKey.empty()) );
80 ATH_CHECK( m_statesSctSGKey.initialize (m_streamName, m_thinHitsOnTrack && !m_statesSctSGKey.empty()) );
81 ATH_CHECK( m_measurementsSctSGKey.initialize (m_streamName, m_thinHitsOnTrack && !m_measurementsSctSGKey.empty()) );
82 ATH_CHECK( m_statesTrtSGKey.initialize (m_streamName, m_thinHitsOnTrack && !m_statesTrtSGKey.empty()) );
83 ATH_CHECK( m_measurementsTrtSGKey.initialize (m_streamName, m_thinHitsOnTrack && !m_measurementsTrtSGKey.empty()) );
85 ATH_CHECK(m_SCTDetEleCollKey.initialize( !m_SCTDetEleCollKey.key().empty() ));
87 return StatusCode::SUCCESS;
93 ATH_MSG_INFO(
"Processed "<< m_ntot <<
" tracks, "<< m_npass<<
" were retained ");
94 if (m_thinHitsOnTrack) {
95 ATH_MSG_INFO(
"Pixel state objects thinning, Total / Passed (Efficiency): "
96 << m_ntot_pix_states <<
" / " << m_npass_pix_states
97 <<
" (" << (m_ntot_pix_states == 0 ? 0 :
static_cast<float>(m_npass_pix_states) / m_ntot_pix_states) <<
")");
98 ATH_MSG_INFO(
"Pixel measurements objects thinning, Total / Passed (Efficiency): "
99 << m_ntot_pix_measurements <<
" / " << m_npass_pix_measurements
100 <<
" (" << (m_ntot_pix_measurements == 0 ? 0 :
static_cast<float>(m_npass_pix_measurements) / m_ntot_pix_measurements) <<
")");
101 ATH_MSG_INFO(
"SCT state objects thinning, Total / Passed (Efficiency): "
102 << m_ntot_sct_states <<
" / " << m_npass_sct_states
103 <<
" (" << (m_ntot_sct_states == 0 ? 0 :
static_cast<float>(m_npass_sct_states) / m_ntot_sct_states) <<
")");
104 ATH_MSG_INFO(
"SCT measurements objects thinning, Total / Passed (Efficiency): "
105 << m_ntot_sct_measurements <<
" / " << m_npass_sct_measurements
106 <<
" (" << (m_ntot_sct_measurements == 0 ? 0 :
static_cast<float>(m_npass_sct_measurements) / m_ntot_sct_measurements) <<
")");
107 ATH_MSG_INFO(
"TRT state objects thinning, Total / Passed (Efficiency): "
108 << m_ntot_trt_states <<
" / " << m_npass_trt_states
109 <<
" (" << (m_ntot_trt_states == 0 ? 0 :
static_cast<float>(m_npass_trt_states) / m_ntot_trt_states) <<
")");
110 ATH_MSG_INFO(
"TRT measurements objects thinning, Total / Passed (Efficiency): "
111 << m_ntot_trt_measurements <<
" / " << m_npass_trt_measurements
112 <<
" (" << (m_ntot_trt_measurements == 0 ? 0 :
static_cast<float>(m_npass_trt_measurements) / m_ntot_trt_measurements) <<
")");
115 return StatusCode::SUCCESS;
121 const EventContext& ctx = Gaudi::Hive::currentContext();
128 unsigned int nTracks = importedTrackParticles->size();
129 if (nTracks==0)
return StatusCode::SUCCESS;
132 std::vector<bool>
mask;
133 mask.assign(nTracks,
false);
138 std::vector<int>
entries = m_parser->evaluateAsVector();
142 ATH_MSG_ERROR(
"Sizes incompatible! Are you sure your selection string used ID TrackParticles?");
143 return StatusCode::FAILURE;
156 if (m_thinHitsOnTrack) {
157 filterTrackHits (ctx,
159 *importedTrackParticles,
162 m_measurementsPixSGKey,
164 m_ntot_pix_measurements,
166 m_npass_pix_measurements);
167 filterTrackHits (ctx,
169 *importedTrackParticles,
172 m_measurementsSctSGKey,
174 m_ntot_sct_measurements,
176 m_npass_sct_measurements);
177 filterTrackHits (ctx,
179 *importedTrackParticles,
182 m_measurementsTrtSGKey,
184 m_ntot_trt_measurements,
186 m_npass_trt_measurements);
189 return StatusCode::SUCCESS;
194 (
const EventContext& ctx,
197 const std::vector<bool>& inputMask,
200 std::atomic<unsigned int>& ntot_states,
201 std::atomic<unsigned int>& ntot_measurements,
202 std::atomic<unsigned int>& npass_states,
203 std::atomic<unsigned int>& npass_measurements)
const
205 std::vector<bool> maskStates;
206 std::vector<bool> maskMeasurements;
208 selectTrackHits (inputTrackParticles, inputMask, detTypeToSelect,
209 maskStates, maskMeasurements);
211 auto count = [] (
const std::vector<bool>&
m)
213 npass_states +=
count (maskStates);
214 npass_measurements +=
count (maskMeasurements);
216 if (!statesKey.
empty()) {
219 unsigned int size_states = importedStates->size();
220 if (size_states == 0) {
224 ntot_states += size_states;
225 if (maskStates.size() > size_states) {
226 ATH_MSG_ERROR(
"States mask size mismatch " << maskStates.size() <<
227 " > " << size_states);
229 maskStates.resize (size_states);
230 importedStates.
keep (maskStates);
234 if (!measurementsKey.
empty()) {
236 (measurementsKey, ctx);
237 unsigned int size_measurements = importedMeasurements->size();
238 if (size_measurements == 0) {
242 ntot_measurements += size_measurements;
243 if (maskMeasurements.size() > size_measurements) {
244 ATH_MSG_ERROR(
"Measurements mask size mismatch " << maskMeasurements.size() <<
245 " > " << size_measurements);
247 maskMeasurements.resize (size_measurements);
248 importedMeasurements.
keep (maskMeasurements);
255 const std::vector<bool>& inputMask,
257 std::vector<bool>& outputStatesMask, std::vector<bool>& outputMeasurementsMask)
const
263 if (not inputMask[trkIndex])
continue;
266 using StatesOnTrack = std::vector<ElementLink<xAOD::TrackStateValidationContainer>>;
269 ATH_MSG_DEBUG(
"Cannot find TrackState link from xAOD::TrackParticle. Skipping track.");
272 const StatesOnTrack& measurementsOnTrack = msosLinkAcc(*trkIt);
274 if (not trkState_el.isValid()) {
275 ATH_MSG_DEBUG(
"Cannot find a valid link to TrackStateValidation object for track index: " << trkIndex);
278 if ((*trkState_el)->detType() != detTypeToSelect) {
279 ATH_MSG_VERBOSE(
"Discarding TrackState as not of correct type " << detTypeToSelect);
282 if (trkState_el.index() >= outputStatesMask.size()) {
283 outputStatesMask.resize (trkState_el.index()+1);
285 outputStatesMask[trkState_el.index()] =
true;
289 if (not trkMeasurement_el.
isValid()) {
290 ATH_MSG_VERBOSE(
"Cannot find a valid link to TrackMeasurementValidation object from track state for track index: " << trkIndex
291 <<
", trackState index: " << trkState_el.index());
294 if (*trkMeasurement_el ==
nullptr) {
295 ATH_MSG_VERBOSE(
"Invalid pointer to TrackMeasurementValidation object from track state for track index: " << trkIndex
296 <<
", trackState index: " << trkState_el.index());
299 if (trkMeasurement_el.
index() >= outputMeasurementsMask.size()) {
300 outputMeasurementsMask.resize (trkMeasurement_el.
index()+1);
302 outputMeasurementsMask[trkMeasurement_el.
index()] =
true;