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
15
16#include <utility>
17#include <vector>
18
19
20namespace{
21 const std::string afpToFsiToolStr{"AFPToFSiTTool"};
22}
23
24AFPToFSiTAlgorithm::AFPToFSiTAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
25 : AthMonitorAlgorithm( name, pSvcLocator ), m_afpSiHitContainerKey( "AFPSiHitContainer" ), m_afpToFHitContainerKey( "AFPToFHitContainer" ), m_afpTrackContainerKey( "AFPTrackContainer" ) {
26 declareProperty( "AFPSiHitContainer", m_afpSiHitContainerKey );
27 declareProperty( "AFPToFHitContainer", m_afpToFHitContainerKey );
28 declareProperty( "AFPTrackContainer", m_afpTrackContainerKey );
29
30}
31
33
35
36 using namespace Monitored;
37
39
40 // We must declare to the framework in initialize what SG objects we are going to use
41 SG::ReadHandleKey<xAOD::AFPSiHitContainer> afpSiHitContainerKey( "AFPSiHits" );
42 ATH_CHECK( m_afpSiHitContainerKey.initialize() );
43 SG::ReadHandleKey<xAOD::AFPToFHitContainer> afpToFHitContainerKey( "AFPToFHits" );
44 ATH_CHECK( m_afpToFHitContainerKey.initialize() );
45 SG::ReadHandleKey<xAOD::AFPTrackContainer> afpTrackContainerKey( "AFPTracks" );
46 ATH_CHECK( m_afpTrackContainerKey.initialize() );
47
49}
50
51StatusCode AFPToFSiTAlgorithm::fillHistograms( const EventContext& ctx ) const {
53 if ( !afpSiHitContainer.isValid() ) {
54 ATH_MSG_WARNING( "evtStore() does not contain hits collection with name " << m_afpSiHitContainerKey );
55 return StatusCode::SUCCESS;
56 }
57 ATH_CHECK( afpSiHitContainer.initialize() );
58
60 if ( !afpTrackContainer.isValid() ) {
61 ATH_MSG_WARNING( "evtStore() does not contain hits collection with name " << m_afpTrackContainerKey );
62 return StatusCode::SUCCESS;
63 }
64 ATH_CHECK( afpTrackContainer.initialize() );
65
67 if ( !afpToFHitContainer.isValid() ) {
68 ATH_MSG_WARNING( "evtStore() does not contain hits collection with name " << m_afpToFHitContainerKey );
69 return StatusCode::SUCCESS;
70 }
71 ATH_CHECK( afpToFHitContainer.initialize() );
72
73 Monitored::Scalar<float> lqbar[ 2 ] = { Monitored::Scalar<float>( "lqBar_A", 0.0 ),
74 Monitored::Scalar<float>( "lqBar_C", 0.0 ) };
75
76 Monitored::Scalar<float> lqbar_tight[ 2 ] = { Monitored::Scalar<float>( "lqBar_tight_A", 0.0 ),
77 Monitored::Scalar<float>( "lqBar_tight_C", 0.0 ) };
78 Monitored::Scalar<float> fsp0_rows_tight[ 2 ] = { Monitored::Scalar<float>( "fsp0_rows_tight_A", 0.0 ),
79 Monitored::Scalar<float>( "fsp0_rows_tight_C", 0.0 ) };
80 Monitored::Scalar<float> fsp0_columns_tight[ 2 ] = { Monitored::Scalar<float>( "fsp0_columns_tight_A", 0.0 ),
81 Monitored::Scalar<float>( "fsp0_columns_tight_C", 0.0 ) };
82
83 Monitored::Scalar<float> trainHits[ 2 ] = { Monitored::Scalar<float>( "trainHits_A", 0.0 ),
84 Monitored::Scalar<float>( "trainHits_C", 0.0 ) };
85
86 Monitored::Scalar<float> tofHits[ 2 ] = { Monitored::Scalar<float>( "tofHits_A", 0.0 ),
87 Monitored::Scalar<float>( "tofHits_C", 0.0 ) };
88 Monitored::Scalar<float> fsp0Hits[ 2 ] = { Monitored::Scalar<float>( "fsp0Hits_A", 0.0 ),
89 Monitored::Scalar<float>( "fsp0Hits_C", 0.0 ) };
90
91 Monitored::Scalar<float> fs_rows_full[ 2 ] = { Monitored::Scalar<float>( "fs_rows_full_A", 0.0 ),
92 Monitored::Scalar<float>( "fs_rows_full_C", 0.0 ) };
93 Monitored::Scalar<float> fs_rows[ 2 ] = { Monitored::Scalar<float>( "fs_rows_A", 0.0 ),
94 Monitored::Scalar<float>( "fs_rows_C", 0.0 ) };
95 Monitored::Scalar<float> fs_columns[ 2 ] = { Monitored::Scalar<float>( "fs_columns_A", 0.0 ),
96 Monitored::Scalar<float>( "fs_columns_C", 0.0 ) };
97
98
99 std::vector<std::pair<int, int>> fsp[ 2 ][ 2 ] = {};
100 std::vector<std::pair<int, int>> fsp_full[ 4 ][ 2 ] = {};
101
102 for ( const xAOD::AFPSiHit* hitsItr : *afpSiHitContainer ) {
103 if ( hitsItr->stationID() != 0 && hitsItr->stationID() != 3 ) continue;
104 int side = hitsItr->stationID() / 2;
105 if ( hitsItr->pixelLayerID() >= 0 && hitsItr->pixelLayerID() < 4 )
106 {
107 int plane_full = hitsItr->pixelLayerID();
108 fsp_full[ plane_full ][ side ].emplace_back( hitsItr->pixelRowIDChip(), hitsItr->pixelColIDChip() );
109 }
110
111 if ( hitsItr->pixelLayerID() != 0 && hitsItr->pixelLayerID() != 2 ) continue;
112 int plane = hitsItr->pixelLayerID() / 2;
113
114 fsp[ plane ][ side ].emplace_back( hitsItr->pixelRowIDChip(), hitsItr->pixelColIDChip() );
115 }
116
117 int numToFHitsTrain[ 4 ][ 2 ] = {};
118 bool ToFHasHit = false;
119
120 for ( const xAOD::AFPToFHit* hitsItr : *afpToFHitContainer ) {
121 int side = hitsItr->stationID() / 2;
122 float bar = hitsItr->trainID() + hitsItr->barInTrainID() / 4.0;
123 for ( auto& coord : fsp[ 0 ][ side ] ) {
124 bool match = false;
125 if ( fsp[ 0 ][ side ].size() == 2 && fsp[ 1 ][ side ].size() == 2 ) {
126 for ( auto& coord2 : fsp[ 1 ][ side ] ) {
127 match |= std::abs( coord2.first - coord.first ) < 3 && std::abs( coord2.second - coord.second ) < 2;
128 }
129 }
130 if ( match ) {
131 lqbar_tight[ side ] = bar;
132 fsp0_rows_tight[ side ] = coord.first;
133 fsp0_columns_tight[ side ] = coord.second;
134
135 fill( afpToFsiToolStr, lqbar_tight[ side ], fsp0_rows_tight[ side ] );
136 fill( afpToFsiToolStr, lqbar_tight[ side ], fsp0_columns_tight[ side ] );
137
138 lqbar_tight[ side ] = -0.5;
139
140 fill( afpToFsiToolStr, lqbar_tight[ side ], fsp0_rows_tight[ side ] );
141 fill( afpToFsiToolStr, lqbar_tight[ side ], fsp0_columns_tight[ side ] );
142 }
143 }
144 //additional TofSitCorr hists
145 for (int j = 0; j < 4; j++)
146 for ( auto& coord : fsp_full[ j ][ side ] )
147 {
148 lqbar[ side ] = bar;
149 fs_rows[ side ] = coord.first;
150 fs_columns[ side ] = coord.second;
151 fs_rows_full[ side ] = coord.first;
152 fill(m_tools[m_GroupToFSiTCorr.at(m_planes.at(j))], lqbar[ side ], fs_rows[ side ]);
153 fill(m_tools[m_GroupToFSiTCorr.at(m_planes.at(j))], lqbar[ side ], fs_columns[ side ]);
154 fill( afpToFsiToolStr, lqbar[ side ], fs_rows_full[ side ] );
155 }
156
157 for (int j = 0; j < 4; j++)
158 {
159 if ( fsp_full[ j ][ side ].empty() )
160 {
161 lqbar[ side ] = bar;
162 fs_columns[ side ] = -5;
163 for ( int k = -10; k < -1; ++k )
164 {
165 fs_rows[ side ] = k;
166 fs_rows_full[ side ] = k;
167 fill(m_tools[m_GroupToFSiTCorr.at(m_planes.at(j))], lqbar[ side ], fs_rows[ side ]);
168 }
169 fill(m_tools[m_GroupToFSiTCorr.at(m_planes.at(j))], lqbar[ side ], fs_columns[ side ]);
170 }
171 }
172
173 ++numToFHitsTrain[ hitsItr->trainID() ][ side ];
174 ToFHasHit = true;
175
176 ++tofHits[ side ];
177 }
178
179 for ( auto side : { 0, 1 } ) {
180 bool wasMatch = false;
181 if ( fsp[ 0 ][ side ].size() == 2 && fsp[ 1 ][ side ].size() == 2 ) {
182 for ( auto& coord : fsp[ 0 ][ side ] ) {
183 bool match = false;
184 for ( auto& coord2 : fsp[ 1 ][ side ] ) {
185 match |= std::abs( coord2.first - coord.first ) < 3 && std::abs( coord2.second - coord.second ) < 2;
186 }
187 if ( match ) {
188 for ( int itrain = 0; itrain < 4; ++itrain ) {
189 trainHits[ side ] = itrain + numToFHitsTrain[ itrain ][ side ] / 5.0;
190 fsp0_rows_tight[ side ] = coord.first;
191 fsp0_columns_tight[ side ] = coord.second;
192
193 fill( afpToFsiToolStr, trainHits[ side ], fsp0_rows_tight[ side ] );
194 fill( afpToFsiToolStr, trainHits[ side ], fsp0_columns_tight[ side ] );
195 }
196 if ( numToFHitsTrain[ 0 ][ side ] > 4 || numToFHitsTrain[ 1 ][ side ] > 4
197 || numToFHitsTrain[ 2 ][ side ] > 4 || numToFHitsTrain[ 3 ][ side ] > 4 ) {
198 trainHits[ side ] = -1;
199 fsp0_rows_tight[ side ] = coord.first;
200 fsp0_columns_tight[ side ] = coord.second;
201
202 fill( afpToFsiToolStr, trainHits[ side ], fsp0_rows_tight[ side ] );
203 fill( afpToFsiToolStr, trainHits[ side ], fsp0_columns_tight[ side ] );
204 }
205 }
206 wasMatch |= match;
207 }
208 }
209
210 if ( !ToFHasHit ) {
211 for ( auto& coord : fsp[ 0 ][ side ] ) {
212 if ( wasMatch ) {
213 lqbar_tight[ side ] = -1;
214 fsp0_rows_tight[ side ] = coord.first;
215 fsp0_columns_tight[ side ] = coord.second;
216
217 fill( afpToFsiToolStr, lqbar_tight[ side ], fsp0_rows_tight[ side ] );
218 fill( afpToFsiToolStr, lqbar_tight[ side ], fsp0_columns_tight[ side ] );
219 }
220 }
221 for (int j = 0; j < 4; j++)
222 for ( auto& coord : fsp_full[ j ][ side ] )
223 {
224 lqbar[ side ] = -1;
225 fs_rows[ side ] = coord.first;
226 fs_columns[ side ] = coord.second;
227 fill(m_tools[m_GroupToFSiTCorr.at(m_planes.at(j))], lqbar[ side ], fs_rows[ side ]);
228 fill(m_tools[m_GroupToFSiTCorr.at(m_planes.at(j))], lqbar[ side ], fs_columns[ side ]);
229 }
230 }
231
232 fsp0Hits[ side ] = fsp[ 0 ][ side ].size();
233 fill( afpToFsiToolStr, tofHits[ side ], fsp0Hits[ side ] );
234 }
235
236 return fillHistograms_eff(*afpTrackContainer, *afpToFHitContainer);
237}
238
240 const xAOD::AFPTrackContainer& afpTrackContainer,
241 const xAOD::AFPToFHitContainer& afpToFHitContainer) const {
242 // Initialize monitored variables for histogram filling
243 Monitored::Scalar<bool> tof_eff_OFF_passed[2] = {
244 Monitored::Scalar<bool>( "tof_eff_OFF_passed_A", false ),
245 Monitored::Scalar<bool>( "tof_eff_OFF_passed_C", false )
246 };
247 Monitored::Scalar<uint8_t> tof_eff_OFF_trains[2] = {
248 Monitored::Scalar<uint8_t>( "tof_eff_OFF_trains_A", 0 ),
249 Monitored::Scalar<uint8_t>( "tof_eff_OFF_trains_C", 0 )
250 };
251 Monitored::Scalar<uint8_t> tof_eff_OFF_bars[2] = {
252 Monitored::Scalar<uint8_t>( "tof_eff_OFF_bars_A", 0 ),
253 Monitored::Scalar<uint8_t>( "tof_eff_OFF_bars_C", 0 )
254 };
255
256 bool bar_hit[2][5] = {};
257 bool channel_present[2][16] = {};
258 bool multihit[2] = {};
259 uint8_t track_train[2] = {};
260 std::size_t track_count[2] = {};
261
262 // Load the necessary information
263 for (const xAOD::AFPTrack* tracksItr : afpTrackContainer) {
264 const auto side = tracksItr->stationID() == 3;
265
266 // Ignore tracks that are not from FAR stations
267 if (tracksItr->stationID() != 0 && tracksItr->stationID() != 3)
268 continue;
269
270 const auto xLocal = tracksItr->xLocal();
271 for (uint8_t train = 0; train < 4; ++train) {
272 bool matching = xLocal < m_tofTrainsCoordinates[side][train] - m_tofTrainGapSize
273 && xLocal > m_tofTrainsCoordinates[side][train + 1];
274 if (matching)
275 track_train[side] = train;
276 }
277 ++track_count[side];
278 }
279
280 for (const xAOD::AFPToFHit* hitsItr : afpToFHitContainer) {
281 const auto side = hitsItr->stationID() == 3;
282 const auto train = hitsItr->trainID();
283 const auto bar = hitsItr->barInTrainID();
284 const auto channel = 4 * train + bar;
285
286 // Ignore hits with an impossible origin
287 if (hitsItr->stationID() != 0 && hitsItr->stationID() != 3)
288 continue;
289 if (channel >= 16) continue;
290
291 if (train == track_train[side])
292 bar_hit[side][bar] = bar_hit[side][4] = true;
293 if (channel_present[side][channel])
294 multihit[side] = true;
295 channel_present[side][channel] = true;
296 }
297
298 for (uint8_t side : {0, 1}) {
299 // Cut on only 1 SiT track in the monitored station
300 if (track_count[side] != 1) continue;
301 // Cut on maximum of 1 hit in each ToF channel
302 if (multihit[side]) continue;
303
304 tof_eff_OFF_trains[side] = track_train[side];
305 for (uint8_t bar = 0; bar <= 4; ++bar) { // 4 = train total
306 tof_eff_OFF_bars[side] = bar;
307 tof_eff_OFF_passed[side] = bar_hit[side][bar];
308 fill( afpToFsiToolStr, tof_eff_OFF_passed[side], tof_eff_OFF_bars[side], tof_eff_OFF_trains[side] );
309 }
310 }
311
312 return StatusCode::SUCCESS;
313}
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
AFPToFSiTAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
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]
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual StatusCode initialize() override
initialize
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
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