ATLAS Offline Software
Loading...
Searching...
No Matches
AFPToFSiTAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*
4*
5* AFPToFSiTAlgorithm
6*
7*
8*/
9
10#include "AFPToFSiTAlgorithm.h"
15
16#include <utility>
17#include <vector>
18
19
20namespace{
21 const std::string afpToFsiToolStr{"AFPToFSiTTool"};
22}
23
25
27
28 using namespace Monitored;
29
31
32 // We must declare to the framework in initialize what SG objects we are going to use
33 SG::ReadHandleKey<xAOD::AFPSiHitContainer> afpSiHitContainerKey( "AFPSiHits" );
34 ATH_CHECK( m_afpSiHitContainerKey.initialize() );
35 SG::ReadHandleKey<xAOD::AFPToFHitContainer> afpToFHitContainerKey( "AFPToFHits" );
36 ATH_CHECK( m_afpToFHitContainerKey.initialize() );
37 SG::ReadHandleKey<xAOD::AFPTrackContainer> afpTrackContainerKey( "AFPTracks" );
38 ATH_CHECK( m_afpTrackContainerKey.initialize() );
39
41}
42
43StatusCode AFPToFSiTAlgorithm::fillHistograms( const EventContext& ctx ) const {
45 if ( !afpSiHitContainer.isValid() ) {
46 ATH_MSG_WARNING( "evtStore() does not contain hits collection with name " << m_afpSiHitContainerKey );
47 return StatusCode::SUCCESS;
48 }
49 ATH_CHECK( afpSiHitContainer.initialize() );
50
52 if ( !afpTrackContainer.isValid() ) {
53 ATH_MSG_WARNING( "evtStore() does not contain hits collection with name " << m_afpTrackContainerKey );
54 return StatusCode::SUCCESS;
55 }
56 ATH_CHECK( afpTrackContainer.initialize() );
57
59 if ( !afpToFHitContainer.isValid() ) {
60 ATH_MSG_WARNING( "evtStore() does not contain hits collection with name " << m_afpToFHitContainerKey );
61 return StatusCode::SUCCESS;
62 }
63 ATH_CHECK( afpToFHitContainer.initialize() );
64
65 Monitored::Scalar<float> lqbar[ 2 ] = { Monitored::Scalar<float>( "lqBar_A", 0.0 ),
66 Monitored::Scalar<float>( "lqBar_C", 0.0 ) };
67
68 Monitored::Scalar<float> lqbar_tight[ 2 ] = { Monitored::Scalar<float>( "lqBar_tight_A", 0.0 ),
69 Monitored::Scalar<float>( "lqBar_tight_C", 0.0 ) };
70 Monitored::Scalar<float> fsp0_rows_tight[ 2 ] = { Monitored::Scalar<float>( "fsp0_rows_tight_A", 0.0 ),
71 Monitored::Scalar<float>( "fsp0_rows_tight_C", 0.0 ) };
72 Monitored::Scalar<float> fsp0_columns_tight[ 2 ] = { Monitored::Scalar<float>( "fsp0_columns_tight_A", 0.0 ),
73 Monitored::Scalar<float>( "fsp0_columns_tight_C", 0.0 ) };
74
75 Monitored::Scalar<float> trainHits[ 2 ] = { Monitored::Scalar<float>( "trainHits_A", 0.0 ),
76 Monitored::Scalar<float>( "trainHits_C", 0.0 ) };
77
78 Monitored::Scalar<float> tofHits[ 2 ] = { Monitored::Scalar<float>( "tofHits_A", 0.0 ),
79 Monitored::Scalar<float>( "tofHits_C", 0.0 ) };
80 Monitored::Scalar<float> fsp0Hits[ 2 ] = { Monitored::Scalar<float>( "fsp0Hits_A", 0.0 ),
81 Monitored::Scalar<float>( "fsp0Hits_C", 0.0 ) };
82
83 Monitored::Scalar<float> fs_rows_full[ 2 ] = { Monitored::Scalar<float>( "fs_rows_full_A", 0.0 ),
84 Monitored::Scalar<float>( "fs_rows_full_C", 0.0 ) };
85 Monitored::Scalar<float> fs_rows[ 2 ] = { Monitored::Scalar<float>( "fs_rows_A", 0.0 ),
86 Monitored::Scalar<float>( "fs_rows_C", 0.0 ) };
87 Monitored::Scalar<float> fs_columns[ 2 ] = { Monitored::Scalar<float>( "fs_columns_A", 0.0 ),
88 Monitored::Scalar<float>( "fs_columns_C", 0.0 ) };
89
90
91 std::vector<std::pair<int, int>> fsp[ 2 ][ 2 ] = {};
92 std::vector<std::pair<int, int>> fsp_full[ 4 ][ 2 ] = {};
93
94 for ( const xAOD::AFPSiHit* hitsItr : *afpSiHitContainer ) {
95 if ( hitsItr->stationID() != 0 && hitsItr->stationID() != 3 ) continue;
96 int side = hitsItr->stationID() / 2;
97 if ( hitsItr->pixelLayerID() >= 0 && hitsItr->pixelLayerID() < 4 )
98 {
99 int plane_full = hitsItr->pixelLayerID();
100 fsp_full[ plane_full ][ side ].emplace_back( hitsItr->pixelRowIDChip(), hitsItr->pixelColIDChip() );
101 }
102
103 if ( hitsItr->pixelLayerID() != 0 && hitsItr->pixelLayerID() != 2 ) continue;
104 int plane = hitsItr->pixelLayerID() / 2;
105
106 fsp[ plane ][ side ].emplace_back( hitsItr->pixelRowIDChip(), hitsItr->pixelColIDChip() );
107 }
108
109 int numToFHitsTrain[ 4 ][ 2 ] = {};
110 bool ToFHasHit = false;
111
112 for ( const xAOD::AFPToFHit* hitsItr : *afpToFHitContainer ) {
113 int side = hitsItr->stationID() / 2;
114 float bar = hitsItr->trainID() + hitsItr->barInTrainID() / 4.0;
115 for ( auto& coord : fsp[ 0 ][ side ] ) {
116 bool match = false;
117 if ( fsp[ 0 ][ side ].size() == 2 && fsp[ 1 ][ side ].size() == 2 ) {
118 for ( auto& coord2 : fsp[ 1 ][ side ] ) {
119 match |= std::abs( coord2.first - coord.first ) < 3 && std::abs( coord2.second - coord.second ) < 2;
120 }
121 }
122 if ( match ) {
123 lqbar_tight[ side ] = bar;
124 fsp0_rows_tight[ side ] = coord.first;
125 fsp0_columns_tight[ side ] = coord.second;
126
127 fill( afpToFsiToolStr, lqbar_tight[ side ], fsp0_rows_tight[ side ] );
128 fill( afpToFsiToolStr, lqbar_tight[ side ], fsp0_columns_tight[ side ] );
129
130 lqbar_tight[ side ] = -0.5;
131
132 fill( afpToFsiToolStr, lqbar_tight[ side ], fsp0_rows_tight[ side ] );
133 fill( afpToFsiToolStr, lqbar_tight[ side ], fsp0_columns_tight[ side ] );
134 }
135 }
136 //additional TofSitCorr hists
137 for (int j = 0; j < 4; j++)
138 for ( auto& coord : fsp_full[ j ][ side ] )
139 {
140 lqbar[ side ] = bar;
141 fs_rows[ side ] = coord.first;
142 fs_columns[ side ] = coord.second;
143 fs_rows_full[ side ] = coord.first;
144 fill(m_tools[m_GroupToFSiTCorr.at(m_planes.at(j))], lqbar[ side ], fs_rows[ side ]);
145 fill(m_tools[m_GroupToFSiTCorr.at(m_planes.at(j))], lqbar[ side ], fs_columns[ side ]);
146 fill( afpToFsiToolStr, lqbar[ side ], fs_rows_full[ side ] );
147 }
148
149 for (int j = 0; j < 4; j++)
150 {
151 if ( fsp_full[ j ][ side ].empty() )
152 {
153 lqbar[ side ] = bar;
154 fs_columns[ side ] = -5;
155 for ( int k = -10; k < -1; ++k )
156 {
157 fs_rows[ side ] = k;
158 fs_rows_full[ side ] = k;
159 fill(m_tools[m_GroupToFSiTCorr.at(m_planes.at(j))], lqbar[ side ], fs_rows[ side ]);
160 }
161 fill(m_tools[m_GroupToFSiTCorr.at(m_planes.at(j))], lqbar[ side ], fs_columns[ side ]);
162 }
163 }
164
165 ++numToFHitsTrain[ hitsItr->trainID() ][ side ];
166 ToFHasHit = true;
167
168 ++tofHits[ side ];
169 }
170
171 for ( auto side : { 0, 1 } ) {
172 bool wasMatch = false;
173 if ( fsp[ 0 ][ side ].size() == 2 && fsp[ 1 ][ side ].size() == 2 ) {
174 for ( auto& coord : fsp[ 0 ][ side ] ) {
175 bool match = false;
176 for ( auto& coord2 : fsp[ 1 ][ side ] ) {
177 match |= std::abs( coord2.first - coord.first ) < 3 && std::abs( coord2.second - coord.second ) < 2;
178 }
179 if ( match ) {
180 for ( int itrain = 0; itrain < 4; ++itrain ) {
181 trainHits[ side ] = itrain + numToFHitsTrain[ itrain ][ side ] / 5.0;
182 fsp0_rows_tight[ side ] = coord.first;
183 fsp0_columns_tight[ side ] = coord.second;
184
185 fill( afpToFsiToolStr, trainHits[ side ], fsp0_rows_tight[ side ] );
186 fill( afpToFsiToolStr, trainHits[ side ], fsp0_columns_tight[ side ] );
187 }
188 if ( numToFHitsTrain[ 0 ][ side ] > 4 || numToFHitsTrain[ 1 ][ side ] > 4
189 || numToFHitsTrain[ 2 ][ side ] > 4 || numToFHitsTrain[ 3 ][ side ] > 4 ) {
190 trainHits[ side ] = -1;
191 fsp0_rows_tight[ side ] = coord.first;
192 fsp0_columns_tight[ side ] = coord.second;
193
194 fill( afpToFsiToolStr, trainHits[ side ], fsp0_rows_tight[ side ] );
195 fill( afpToFsiToolStr, trainHits[ side ], fsp0_columns_tight[ side ] );
196 }
197 }
198 wasMatch |= match;
199 }
200 }
201
202 if ( !ToFHasHit ) {
203 for ( auto& coord : fsp[ 0 ][ side ] ) {
204 if ( wasMatch ) {
205 lqbar_tight[ side ] = -1;
206 fsp0_rows_tight[ side ] = coord.first;
207 fsp0_columns_tight[ side ] = coord.second;
208
209 fill( afpToFsiToolStr, lqbar_tight[ side ], fsp0_rows_tight[ side ] );
210 fill( afpToFsiToolStr, lqbar_tight[ side ], fsp0_columns_tight[ side ] );
211 }
212 }
213 for (int j = 0; j < 4; j++)
214 for ( auto& coord : fsp_full[ j ][ side ] )
215 {
216 lqbar[ side ] = -1;
217 fs_rows[ side ] = coord.first;
218 fs_columns[ side ] = coord.second;
219 fill(m_tools[m_GroupToFSiTCorr.at(m_planes.at(j))], lqbar[ side ], fs_rows[ side ]);
220 fill(m_tools[m_GroupToFSiTCorr.at(m_planes.at(j))], lqbar[ side ], fs_columns[ side ]);
221 }
222 }
223
224 fsp0Hits[ side ] = fsp[ 0 ][ side ].size();
225 fill( afpToFsiToolStr, tofHits[ side ], fsp0Hits[ side ] );
226 }
227
228 return fillHistograms_eff(*afpTrackContainer, *afpToFHitContainer);
229}
230
232 const xAOD::AFPTrackContainer& afpTrackContainer,
233 const xAOD::AFPToFHitContainer& afpToFHitContainer) const {
234 // Initialize monitored variables for histogram filling
235 Monitored::Scalar<bool> tof_eff_OFF_passed[2] = {
236 Monitored::Scalar<bool>( "tof_eff_OFF_passed_A", false ),
237 Monitored::Scalar<bool>( "tof_eff_OFF_passed_C", false )
238 };
239 Monitored::Scalar<uint8_t> tof_eff_OFF_trains[2] = {
240 Monitored::Scalar<uint8_t>( "tof_eff_OFF_trains_A", 0 ),
241 Monitored::Scalar<uint8_t>( "tof_eff_OFF_trains_C", 0 )
242 };
243 Monitored::Scalar<uint8_t> tof_eff_OFF_bars[2] = {
244 Monitored::Scalar<uint8_t>( "tof_eff_OFF_bars_A", 0 ),
245 Monitored::Scalar<uint8_t>( "tof_eff_OFF_bars_C", 0 )
246 };
247
248 bool bar_hit[2][5] = {};
249 bool channel_present[2][16] = {};
250 bool multihit[2] = {};
251 uint8_t track_train[2] = {};
252 std::size_t track_count[2] = {};
253
254 // Load the necessary information
255 for (const xAOD::AFPTrack* tracksItr : afpTrackContainer) {
256 const auto side = tracksItr->stationID() == 3;
257
258 // Ignore tracks that are not from FAR stations
259 if (tracksItr->stationID() != 0 && tracksItr->stationID() != 3)
260 continue;
261
262 const auto xLocal = tracksItr->xLocal();
263 for (uint8_t train = 0; train < 4; ++train) {
264 bool matching = xLocal < m_tofTrainsCoordinates[side][train] - m_tofTrainGapSize
265 && xLocal > m_tofTrainsCoordinates[side][train + 1];
266 if (matching)
267 track_train[side] = train;
268 }
269 ++track_count[side];
270 }
271
272 for (const xAOD::AFPToFHit* hitsItr : afpToFHitContainer) {
273 const auto side = hitsItr->stationID() == 3;
274 const auto train = hitsItr->trainID();
275 const auto bar = hitsItr->barInTrainID();
276 const auto channel = 4 * train + bar;
277
278 // Ignore hits with an impossible origin
279 if (hitsItr->stationID() != 0 && hitsItr->stationID() != 3)
280 continue;
281 if (channel >= 16) continue;
282
283 if (train == track_train[side])
284 bar_hit[side][bar] = bar_hit[side][4] = true;
285 if (channel_present[side][channel])
286 multihit[side] = true;
287 channel_present[side][channel] = true;
288 }
289
290 for (uint8_t side : {0, 1}) {
291 // Cut on only 1 SiT track in the monitored station
292 if (track_count[side] != 1) continue;
293 // Cut on maximum of 1 hit in each ToF channel
294 if (multihit[side]) continue;
295
296 tof_eff_OFF_trains[side] = track_train[side];
297 for (uint8_t bar = 0; bar <= 4; ++bar) { // 4 = train total
298 tof_eff_OFF_bars[side] = bar;
299 tof_eff_OFF_passed[side] = bar_hit[side][bar];
300 fill( afpToFsiToolStr, tof_eff_OFF_passed[side], tof_eff_OFF_bars[side], tof_eff_OFF_trains[side] );
301 }
302 }
303
304 return StatusCode::SUCCESS;
305}
Definitions of AFP stations identification numbers.
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x,...)
double coord
Type of coordination system.
size_t size() const
Number of registered mappings.
static const Attributes_t empty
virtual StatusCode initialize() override
initialize
const float m_tofTrainGapSize
SG::ReadHandleKey< xAOD::AFPTrackContainer > m_afpTrackContainerKey
std::vector< std::string > m_planes
SG::ReadHandleKey< xAOD::AFPToFHitContainer > m_afpToFHitContainerKey
virtual StatusCode fillHistograms_eff(const xAOD::AFPTrackContainer &, const xAOD::AFPToFHitContainer &) const
SG::ReadHandleKey< xAOD::AFPSiHitContainer > m_afpSiHitContainerKey
virtual StatusCode fillHistograms(const EventContext &) const override
adds event to the monitoring histograms
std::map< std::string, int > m_GroupToFSiTCorr
const std::vector< float > m_tofTrainsCoordinates[2]
virtual StatusCode initialize() override
initialize
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
Declare a monitored scalar variable.
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode initialize(bool used=true)
Verify that the handle has been configured properly.
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable > > &&variables) const
Fills a vector of variables to a group by reference.
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:359
Generic monitoring tool for athena components.
std::vector< V > buildToolMap(const ToolHandleArray< GenericMonitoringTool > &tools, const std::string &baseName, int nHist)
Builds an array of indices (base case).
AFPSiHit_v2 AFPSiHit
Definition AFPSiHit.h:12
AFPTrack_v2 AFPTrack
Definition AFPTrack.h:12
AFPToFHitContainer_v1 AFPToFHitContainer
AFPTrackContainer_v2 AFPTrackContainer
AFPToFHit_v1 AFPToFHit
Definition AFPToFHit.h:12