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