ATLAS Offline Software
SeedToTrackAnalysisAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
8 namespace ActsTrk {
9 
11  ISvcLocator* pSvcLocator)
12  : AthMonitorAlgorithm(name, pSvcLocator)
13  {}
14 
16  ATH_MSG_DEBUG("Initializing " << name() << " ...");
17 
18  ATH_CHECK( m_seedsKey.initialize() );
19  ATH_CHECK( m_paramsKey.initialize() );
22 
25 
26  m_seedVars = Monitored::buildToolMap<int>(m_tools, "seedVars", m_nLayers);
28 
30  }
31 
32  StatusCode SeedToTrackAnalysisAlg::fillHistograms(const EventContext& ctx) const {
33  ATH_MSG_DEBUG( "Filling Histograms for " << name() << " ... " );
34 
36  ATH_CHECK( seedsHandle.isValid() );
37  const ActsTrk::SeedContainer* seeds = seedsHandle.cptr();
38 
40  ATH_CHECK( paramsHandle.isValid() );
41  const ActsTrk::BoundTrackParametersContainer* params = paramsHandle.cptr();
42 
44  ATH_CHECK( destiniesHandle.isValid() );
45  const std::vector<int>* destinies = destiniesHandle.cptr();
46 
47  // Read the Beam Spot information
49  ATH_CHECK( beamSpotHandle.isValid() );
50  const InDet::BeamSpotData* beamSpotData = beamSpotHandle.cptr();
51 
52  // Beam Spot Position
53  Acts::Vector3 beamPos( beamSpotData->beamPos().x() * Acts::UnitConstants::mm,
54  beamSpotData->beamPos().y() * Acts::UnitConstants::mm,
55  beamSpotData->beamPos().z() * Acts::UnitConstants::mm );
56 
57  if (seeds->size() != params->size() or
58  seeds->size() != destinies->size()) {
59  ATH_MSG_ERROR("Inconsistent size of collections");
60  ATH_MSG_ERROR("- " << m_seedsKey);
61  ATH_MSG_ERROR("- " << m_paramsKey);
63  return StatusCode::FAILURE;
64  }
65 
66 
67  std::vector< const ActsTrk::MeasurementToTruthParticleAssociation* > truthAssociationMaps (DetectorType::nTypes, nullptr);
68  if ( not m_pixelAssociuationMapKey.empty() ) {
71  ATH_CHECK( pixelAssociuationMapHandle.isValid() );
72  truthAssociationMaps[DetectorType::PIXEL] = pixelAssociuationMapHandle.cptr();
73  }
74 
75  if ( not m_stripAssociuationMapKey.empty() ) {
78  ATH_CHECK( stripAssociuationMapHandle.isValid() );
79  truthAssociationMaps[DetectorType::STRIP] = stripAssociuationMapHandle.cptr();
80  }
81 
82 
83  std::size_t nElements = seeds->size();
84 
85  for (std::size_t i(0); i<nElements; ++i) {
86  const ActsTrk::Seed* seed = seeds->at(i);
87  const Acts::BoundTrackParameters* pars = params->at(i);
88  const int destiny = destinies->at(i);
89 
90  // in case param estimation for this seed failed somehow
91  if (not pars) continue;
92 
93  const auto& sps = seed->sp();
94  const auto& bottom = sps[0];
95  const auto& middle = sps[1];
96  const auto& top = sps[2];
97 
98  float bottomX = bottom->x() - beamPos.x();
99  float bottomY = bottom->y() - beamPos.y();
100  float bottomZ = bottom->z();
101  float bottomR = std::sqrt( bottomX * bottomX + bottomY * bottomY );
102 
103  float middleX = middle->x() - beamPos.x();
104  float middleY = middle->y() - beamPos.y();
105  float middleZ = middle->z();
106  float middleR = std::sqrt( middleX * middleX + middleY * middleY );
107 
108  float topX = top->x() - beamPos.x();
109  float topY = top->y() - beamPos.y();
110  float topZ = top->z();
111  float topR = std::sqrt( topX * topX + topY * topY );
112 
113  float probability = 0.f;
115  truthAssociationMaps,
116  probability) );
117 
118  auto monitor_bottom_x = Monitored::Scalar<float>( "bottomX", bottomX );
119  auto monitor_bottom_y = Monitored::Scalar<float>( "bottomY", bottomY );
120  auto monitor_bottom_z = Monitored::Scalar<float>( "bottomZ", bottomZ );
121  auto monitor_bottom_r = Monitored::Scalar<float>( "bottomR", bottomR );
122 
123  auto monitor_middle_x = Monitored::Scalar<float>( "middleX", middleX );
124  auto monitor_middle_y = Monitored::Scalar<float>( "middleY", middleY );
125  auto monitor_middle_z = Monitored::Scalar<float>( "middleZ", middleZ );
126  auto monitor_middle_r = Monitored::Scalar<float>( "middleR", middleR );
127 
128  auto monitor_top_x = Monitored::Scalar<float>( "topX", topX );
129  auto monitor_top_y = Monitored::Scalar<float>( "topY", topY );
130  auto monitor_top_z = Monitored::Scalar<float>( "topZ", topZ );
131  auto monitor_top_r = Monitored::Scalar<float>( "topR", topR );
132 
133  auto monitor_cotTheta_bm = Monitored::Scalar<float>( "cotTheta_BM", (middleZ - bottomZ) / (middleR - bottomR) );
134  auto monitor_cotTheta_mt = Monitored::Scalar<float>( "cotTheta_MT", (topZ - middleZ) / (topR - middleR) );
135  auto monitor_cotTheta_bt = Monitored::Scalar<float>( "cotTheta_BT", (topZ - bottomZ) / (topR - bottomR) );
136 
137  auto monitor_delta_cotTheta_bm_mt = Monitored::Scalar<float>( "deltaCotTheta_BM_MT", monitor_cotTheta_mt - monitor_cotTheta_bm );
138 
139  auto monitor_delta_r_bt = Monitored::Scalar<float>( "deltaR_BT", topR - bottomR );
140  auto monitor_delta_r_bm = Monitored::Scalar<float>( "deltaR_BM", middleR - bottomR );
141  auto monitor_delta_r_mt = Monitored::Scalar<float>( "deltaR_MT", topR - middleR );
142 
143  auto monitor_seed_eta = Monitored::Scalar<float>( "eta", Acts::VectorHelpers::eta(pars->momentum()) );
144  auto monitor_seed_pt = Monitored::Scalar<float>( "pt", pars->transverseMomentum() );
145  auto monitor_seed_quality = Monitored::Scalar<float>( "quality", seed->seedQuality() );
146  auto monitor_seed_vtx_z = Monitored::Scalar<float>( "vtxZ", seed->z() );
147 
148  auto monitor_seed_probability = Monitored::Scalar<float>( "truthProb", probability );
149 
150  // fill inclusive
151  fill(m_tools[m_seedVars[4]],
152  monitor_bottom_x, monitor_bottom_y, monitor_bottom_z, monitor_bottom_r,
153  monitor_middle_x, monitor_middle_y, monitor_middle_z, monitor_middle_r,
154  monitor_top_x, monitor_top_y, monitor_top_z, monitor_top_r,
155  monitor_seed_eta, monitor_seed_pt, monitor_seed_quality, monitor_seed_vtx_z,
156  monitor_delta_r_bt, monitor_delta_r_bm, monitor_delta_r_mt,
157  monitor_cotTheta_bm, monitor_cotTheta_mt, monitor_cotTheta_bt,
158  monitor_delta_cotTheta_bm_mt,
159  monitor_seed_probability);
160 
161  fill(m_tools[m_seedVars[destiny]],
162  monitor_bottom_x, monitor_bottom_y, monitor_bottom_z, monitor_bottom_r,
163  monitor_middle_x, monitor_middle_y, monitor_middle_z, monitor_middle_r,
164  monitor_top_x, monitor_top_y, monitor_top_z, monitor_top_r,
165  monitor_seed_eta, monitor_seed_pt, monitor_seed_quality, monitor_seed_vtx_z,
166  monitor_delta_r_bt, monitor_delta_r_bm, monitor_delta_r_mt,
167  monitor_cotTheta_bm, monitor_cotTheta_mt, monitor_cotTheta_bt,
168  monitor_delta_cotTheta_bm_mt,
169  monitor_seed_probability);
170  }
171 
172  return StatusCode::SUCCESS;
173  }
174 
176  const std::vector< const ActsTrk::MeasurementToTruthParticleAssociation* >& associationMaps,
177  float& probability) const
178  {
179  bool hasTruthInfo = false;
180  for ( const ActsTrk::MeasurementToTruthParticleAssociation* map : associationMaps ) {
181  if (not map) continue;
182  hasTruthInfo = true;
183  break;
184  }
185  if (not hasTruthInfo)
186  return StatusCode::SUCCESS;
187 
188  std::size_t nMeasurements = 0ul;
189  std::unordered_map<std::size_t, int> particleIds {};
190 
191  const auto& sps = seed.sp();
192  for (const xAOD::SpacePoint* sp : sps) {
193  const auto& measurements = sp->measurements();
194  for (const xAOD::UncalibratedMeasurement* meas : measurements ) {
195  ++nMeasurements;
196 
197  const ActsTrk::MeasurementToTruthParticleAssociation* truth = nullptr;
198  const xAOD::UncalibMeasType measType = meas->type();
199  if (measType == xAOD::UncalibMeasType::PixelClusterType) {
200  truth = associationMaps.at(DetectorType::PIXEL);
201  } else if (measType == xAOD::UncalibMeasType::StripClusterType) {
202  truth = associationMaps.at(DetectorType::STRIP);
203  } else {
204  ATH_MSG_ERROR("Cluster type is not supported");
205  return StatusCode::FAILURE;
206  }
207 
208  if (not truth) {
209  ATH_MSG_ERROR("Cannot use truth information");
210  return StatusCode::FAILURE;
211  }
212 
213  auto tps = truth->at(meas->index());
214  if (tps.empty()) continue;
215 
216  for (const auto* tp : tps) {
217  std::size_t pid = HepMC::uniqueID(tp);
218  particleIds.try_emplace( pid, 0 );
219  ++particleIds[pid];
220 
221  // get the mother particle
223  if (not motherParticle) continue;
224 
225  std::size_t motherPid = HepMC::uniqueID(motherParticle);
226  if (pid == motherPid) continue;
227  particleIds.try_emplace( motherPid, 0 );
228  ++particleIds[motherPid];
229  } // loop on tps
230 
231  } // loop on measurements
232  } // loop on sps
233 
234  // probability
235  for (const auto [pid, nEntries] : particleIds) {
236  float prob = static_cast<float>(nEntries) / nMeasurements;
237  probability = std::max(probability, prob);
238  }
239 
240  return StatusCode::SUCCESS;
241  }
242 
243 }
244 
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
ActsTrk::SeedToTrackAnalysisAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: SeedToTrackAnalysisAlg.cxx:32
python.SystemOfUnits.mm
float mm
Definition: SystemOfUnits.py:98
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ElasticDecayUtil::getMother
const xAOD::TruthParticle * getMother(const xAOD::TruthParticle &truth_particle, float max_energy_loss) const
follow decay chain upwards assuming quasi elastic processes.
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
xAOD::UncalibMeasType::StripClusterType
@ StripClusterType
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:210
ParticleTest.tp
tp
Definition: ParticleTest.py:25
xAOD::SpacePoint_v1
Definition: SpacePoint_v1.h:29
ActsTrk::SeedToTrackAnalysisAlg::m_energyLossBinning
EmptyProperty m_energyLossBinning
Definition: SeedToTrackAnalysisAlg.h:47
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
covarianceTool.prob
prob
Definition: covarianceTool.py:678
ActsTrk::SeedToTrackAnalysisAlg::m_maxEnergyLoss
Gaudi::Property< float > m_maxEnergyLoss
Definition: SeedToTrackAnalysisAlg.h:48
ActsTrk::MeasurementToTruthParticleAssociation
Definition: MeasurementToTruthParticleAssociation.h:18
ActsTrk::SeedToTrackAnalysisAlg::m_paramsKey
SG::ReadHandleKey< ActsTrk::BoundTrackParametersContainer > m_paramsKey
Definition: SeedToTrackAnalysisAlg.h:34
ActsTrk::SeedToTrackAnalysisAlg::initialize
virtual StatusCode initialize() override
initialize
Definition: SeedToTrackAnalysisAlg.cxx:15
ActsTrk::SeedToTrackAnalysisAlg::m_stripAssociuationMapKey
SG::ReadHandleKey< ActsTrk::MeasurementToTruthParticleAssociation > m_stripAssociuationMapKey
Definition: SeedToTrackAnalysisAlg.h:41
ActsTrk::SeedToTrackAnalysisAlg::m_seedsKey
SG::ReadHandleKey< ActsTrk::SeedContainer > m_seedsKey
Definition: SeedToTrackAnalysisAlg.h:33
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
ActsTrk::SeedToTrackAnalysisAlg::m_elasticDecayUtil
ElasticDecayUtil< false > m_elasticDecayUtil
Definition: SeedToTrackAnalysisAlg.h:49
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
ActsTrk::SeedToTrackAnalysisAlg::m_destiniesKey
SG::ReadHandleKey< std::vector< int > > m_destiniesKey
Definition: SeedToTrackAnalysisAlg.h:35
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ActsTrk::SeedToTrackAnalysisAlg::SeedToTrackAnalysisAlg
SeedToTrackAnalysisAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SeedToTrackAnalysisAlg.cxx:10
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:116
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
detail::ul
unsigned long ul
Definition: PrimitiveHelpers.h:46
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.
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
ActsTrk::SeedToTrackAnalysisAlg::m_seedVars
std::vector< int > m_seedVars
Definition: SeedToTrackAnalysisAlg.h:44
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
InDet::BeamSpotData::beamPos
const Amg::Vector3D & beamPos() const noexcept
Definition: BeamSpotData.h:68
AthMonitorAlgorithm::m_tools
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
Definition: AthMonitorAlgorithm.h:338
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
MagicNumbers.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
ActsTrk::SeedToTrackAnalysisAlg::m_nLayers
static const int m_nLayers
Definition: SeedToTrackAnalysisAlg.h:43
ActsTrk::ActsSeed
Definition: Seed.h:18
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
InDet::BeamSpotData
Definition: BeamSpotData.h:21
LVL1TGCTrigger::STRIP
@ STRIP
Definition: TGCNumbering.h:52
xAOD::UncalibMeasType
UncalibMeasType
Define the type of the uncalibrated measurement.
Definition: MeasurementDefs.h:25
ActsTrk::SeedToTrackAnalysisAlg::getTruthProbability
StatusCode getTruthProbability(const ActsTrk::Seed &seed, const std::vector< const ActsTrk::MeasurementToTruthParticleAssociation * > &associationMaps, float &probability) const
Definition: SeedToTrackAnalysisAlg.cxx:175
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MSTrackingVolumeBuilder.cxx:24
top
@ top
Definition: TruthClasses.h:64
ActsTrk::SeedToTrackAnalysisAlg::m_beamSpotKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition: SeedToTrackAnalysisAlg.h:36
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
ActsTrk::SeedToTrackAnalysisAlg::m_pixelAssociuationMapKey
SG::ReadHandleKey< ActsTrk::MeasurementToTruthParticleAssociation > m_pixelAssociuationMapKey
Definition: SeedToTrackAnalysisAlg.h:40
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:72
ElasticDecayUtil::setEnergyLossBinning
void setEnergyLossBinning(const typename std::conditional< IsDebug, std::vector< float >, EmptyProperty >::type &binning)
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
SeedToTrackAnalysisAlg.h
xAOD::UncalibMeasType::PixelClusterType
@ PixelClusterType
PIXEL
@ PIXEL
Definition: RegSelEnums.h:24
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition: ReadCondHandle.h:71