Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
BucketDumperAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "BucketDumperAlg.h"
6 
7 #include "StoreGate/ReadHandle.h"
12 #include <fstream>
13 #include <TString.h>
15 #include "CLHEP/Random/RandFlat.h"
16 
17 namespace MuonR4{
19  ATH_CHECK(m_spacePointKeys.initialize());
20  ATH_CHECK(m_inSegmentKeys.initialize());
21 
22  ATH_CHECK(m_idHelperSvc.retrieve());
24  m_tree.addBranch(std::make_shared<MuonVal::EventHashBranch>(m_tree.tree()));
25  ATH_CHECK(m_visionTool.retrieve(EnableTool{!m_visionTool.empty()}));
26  if (m_visionTool.empty()) {
28  }
29  ATH_CHECK(m_tree.init(this));
30  ATH_CHECK(m_idHelperSvc.retrieve());
31  ATH_MSG_DEBUG("Successfully initialized");
32 
33  return StatusCode::SUCCESS;
34  }
35 
38  return StatusCode::SUCCESS;
39  }
40 
42  const EventContext& ctx{Gaudi::Hive::currentContext()};
44  ATH_CHECK(emptyKey.initialize(SG::AllowEmpty));
45  for (unsigned keyNum = 0 ; keyNum < m_spacePointKeys.size(); ++keyNum) {
47  keyNum < m_inSegmentKeys.size() ? m_inSegmentKeys[keyNum] : emptyKey ));
48  }
49  return StatusCode::SUCCESS;
50  }
51  StatusCode BucketDumperAlg::dumpContainer(const EventContext& ctx,
52  const SG::ReadHandleKey<SpacePointContainer>& spacePointKey,
53  const SG::ReadHandleKey<SegmentContainer>& segmentKey) {
54 
55  std::unordered_map <const SpacePointBucket*, std::vector<const Segment*>> segmentMap; // MuonR4Segment
56 
57  const SegmentContainer* readSegment{nullptr};
58  ATH_CHECK(SG::get(readSegment, segmentKey, ctx));
59  if (readSegment) {
60  for (const Segment* segment : *readSegment) {
61  segmentMap[segment->parent()->parentBucket()].push_back(segment);
62  }
63  }
64 
65  const ActsGeometryContext* gctx{nullptr};
66  ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
67 
68  const SpacePointContainer* spContainer{nullptr};
69  ATH_CHECK(SG::get(spContainer, spacePointKey, ctx));
70 
71  CLHEP::HepRandomEngine* rndEngine = getRandomEngine(ctx);
72 
73  const SpacePointPerLayerSorter layerSorter{m_idHelperSvc.get()};
74 
75  for(const SpacePointBucket* bucket : *spContainer) {
76 
77  if (!m_isMC && segmentMap[bucket].size() && m_fracToKeep < 1. &&
78  CLHEP::RandFlat::shoot(rndEngine,0.,1.) > m_fracToKeep) {
79  ATH_MSG_VERBOSE("Skipping bucket without segment");
80  continue;
81  }
82 
83  m_bucket_min = bucket->coveredMin();
84  m_bucket_max = bucket->coveredMax();
85  m_bucket_segments = segmentMap[bucket].size();
86 
87  std::unordered_map<const SpacePoint*, std::vector<int16_t>> spacePointToSegment;
88 
89  auto match_itr = segmentMap.find(bucket);
90 
91  if (match_itr != segmentMap.end()) {
92  unsigned int segIdx{0};
93  for (const Segment* segment : match_itr->second) {
94  for (const auto& meas : segment->measurements()) {
95  if (meas->fitState() == CalibratedSpacePoint::State::Valid) {
96  spacePointToSegment[meas->spacePoint()].push_back(segIdx);
97  }
98  }
99  ++segIdx;
100  }
101 
102  for ( const Segment* segment: match_itr->second) {
103  m_segmentPos.push_back(segment->position());
104  m_segmentDir.push_back(segment->direction());
107  }
108  }
109 
110  std::unordered_map<Identifier, unsigned> layNumbers{};
111 
112  for(const SpacePointBucket::value_type& sp : *bucket) {
113  const unsigned layer{layNumbers.insert(
114  std::make_pair(layerSorter.detectorLayerId(sp->identify()),
115  layNumbers.size())).first->second};
116 
117  const Identifier& id = sp->identify();
118 
119  if (sp->type() == xAOD::UncalibMeasType::MdtDriftCircleType) {
120  const auto* dc = static_cast<const xAOD::MdtDriftCircle*>(sp->primaryMeasurement());
122  continue;
123  }
126  m_spoint_adc.push_back(dc->adc());
127  m_spoint_tdc.push_back(dc->tdc());
128  } else {
129  // check the technology to fill channel, adc and tdc... pushing back 0 for now
132  m_spoint_isMdt.push_back(false);
134  }
135 
137 
138 
139  const std::vector<int16_t>& segIdxs = spacePointToSegment[sp.get()];
140 
141  m_spoint_mat[m_spoint_mat.size()] = segIdxs;
142  m_spoint_nSegments.push_back(segIdxs.size());
143 
144  m_bucket_spacePoints = bucket->size();
145  m_spoint_localPosition.push_back(sp->positionInChamber());
146  m_spoint_covX.push_back(sp->covariance()(Amg::x, Amg::x));
147  m_spoint_covY.push_back(sp->covariance()(Amg::y, Amg::y));
148  m_spoint_covXY.push_back(sp->covariance()(Amg::x, Amg::y));
149  m_spoint_covYX.push_back(sp->covariance()(Amg::y, Amg::x));
150  m_spoint_driftR.push_back(sp->driftRadius());
151  m_spoint_measuresEta.push_back(sp->measuresEta());
152  m_spoint_measuresPhi.push_back(sp->measuresPhi());
153  m_spoint_nEtaInstances.push_back(sp->nEtaInstanceCounts());
154  m_spoint_nPhiInstances.push_back(sp->nPhiInstanceCounts());
155  m_spoint_dimension.push_back(sp->dimension());
157  if (m_visionTool.isEnabled()) {
158  m_spoint_trueLabel.push_back(m_visionTool->isLabeled(*sp));
159  }
160 
161  Amg::Vector3D globalPos = sp->msSector()->localToGlobalTrans(*gctx) * sp->positionInChamber();
162  m_spoint_globalPosition.push_back( globalPos );
163  }
164 
165  m_bucket_layers = layNumbers.size();
166 
167  if (!m_tree.fill(ctx)) {
168  return StatusCode::FAILURE;
169  }
170  }
171 
172  return StatusCode::SUCCESS;
173 
174  }
175 
176  CLHEP::HepRandomEngine* BucketDumperAlg::getRandomEngine(const EventContext&ctx) const {
177  ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, m_streamName);
178  std::string rngName = m_streamName;
179  rngWrapper->setSeed(rngName, ctx);
180  return rngWrapper->getEngine(ctx);
181  }
182 
183 }
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
MuonR4::BucketDumperAlg::m_spoint_dimension
MuonVal::VectorBranch< unsigned int > & m_spoint_dimension
Definition: BucketDumperAlg.h:94
UtilFunctions.h
MuonR4::BucketDumperAlg::getRandomEngine
CLHEP::HepRandomEngine * getRandomEngine(const EventContext &ctx) const
Definition: BucketDumperAlg.cxx:176
MuonR4::SpacePointBucket
: The muon space point bucket represents a collection of points that will bre processed together in t...
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/MuonSpacePoint/SpacePointContainer.h:21
MuonVal::MuonTesterTree::init
StatusCode init(OWNER *instance)
Initialize method.
MuonR4::BucketDumperAlg::m_spoint_adc
MuonVal::VectorBranch< uint16_t > & m_spoint_adc
Definition: BucketDumperAlg.h:80
MuonR4::BucketDumperAlg::m_bucket_max
MuonVal::ScalarBranch< float > & m_bucket_max
Definition: BucketDumperAlg.h:67
MuonR4::SpacePointPerLayerSorter
The SpacePointPerLayerSorter sort two given space points by their layer Identifier.
Definition: SpacePointPerLayerSorter.h:18
MuonR4::BucketDumperAlg::m_tree
MuonVal::MuonTesterTree m_tree
Definition: BucketDumperAlg.h:64
MuonR4::BucketDumperAlg::m_spoint_covYX
MuonVal::VectorBranch< float > & m_spoint_covYX
Definition: BucketDumperAlg.h:85
MuonR4::BucketDumperAlg::execute
virtual StatusCode execute() override final
Definition: BucketDumperAlg.cxx:41
MuonR4::Segment
Placeholder for what will later be the muon segment EDM representation.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:19
MuonR4::BucketDumperAlg::m_spoint_id
MuonVal::MuonIdentifierBranch m_spoint_id
Definition: BucketDumperAlg.h:75
Amg::y
@ y
Definition: GeoPrimitives.h:35
MuonR4::BucketDumperAlg::m_spoint_globalPosition
MuonVal::ThreeVectorBranch m_spoint_globalPosition
Definition: BucketDumperAlg.h:73
MuonR4::BucketDumperAlg::m_spacePointKeys
SG::ReadHandleKeyArray< SpacePointContainer > m_spacePointKeys
Definition: BucketDumperAlg.h:47
MuonR4::BucketDumperAlg::finalize
virtual StatusCode finalize() override final
Definition: BucketDumperAlg.cxx:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
MuonR4::BucketDumperAlg::m_geoCtxKey
SG::ReadHandleKey< ActsGeometryContext > m_geoCtxKey
Definition: BucketDumperAlg.h:53
EventHashBranch.h
MuonR4::BucketDumperAlg::m_bucket_min
MuonVal::ScalarBranch< float > & m_bucket_min
Definition: BucketDumperAlg.h:66
MuonR4::BucketDumperAlg::m_spoint_nPhiInstances
MuonVal::VectorBranch< unsigned int > & m_spoint_nPhiInstances
Definition: BucketDumperAlg.h:93
Muon::MdtStatusDriftTime
@ MdtStatusDriftTime
The tube produced a vaild measurement.
Definition: MdtDriftCircleStatus.h:34
MuonR4::BucketDumperAlg::m_rndmSvc
ServiceHandle< IAthRNGSvc > m_rndmSvc
Definition: BucketDumperAlg.h:58
MuonR4::BucketDumperAlg::m_segmentPos
MuonVal::ThreeVectorBranch m_segmentPos
Definition: BucketDumperAlg.h:98
MuonR4::BucketDumperAlg::m_spoint_covXY
MuonVal::VectorBranch< float > & m_spoint_covXY
Definition: BucketDumperAlg.h:84
MuonR4::BucketDumperAlg::m_spoint_covY
MuonVal::VectorBranch< float > & m_spoint_covY
Definition: BucketDumperAlg.h:86
MuonR4::BucketDumperAlg::m_bucket_layers
MuonVal::ScalarBranch< uint16_t > & m_bucket_layers
Definition: BucketDumperAlg.h:70
MuonR4::BucketDumperAlg::m_spoint_measuresPhi
MuonVal::VectorBranch< unsigned short > & m_spoint_measuresPhi
Definition: BucketDumperAlg.h:90
MuonVal::ThreeVectorBranch::push_back
void push_back(const Amg::Vector3D &vec)
interface using the Amg::Vector3D
Definition: ThreeVectorBranch.cxx:23
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
MuonR4::BucketDumperAlg::m_spoint_localPosition
MuonVal::ThreeVectorBranch m_spoint_localPosition
Definition: BucketDumperAlg.h:72
MuonR4::BucketDumperAlg::m_isMC
Gaudi::Property< bool > m_isMC
Definition: BucketDumperAlg.h:55
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
MuonVal::MuonTesterTree::disableBranch
void disableBranch(const std::string &br_name)
Skips the branch from being added to the tree.
Definition: MuonTesterTree.cxx:199
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
MuonR4::BucketDumperAlg::m_fracToKeep
Gaudi::Property< double > m_fracToKeep
Definition: BucketDumperAlg.h:56
Amg::x
@ x
Definition: GeoPrimitives.h:34
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
MuonVal::MuonIdentifierBranch::push_back
virtual void push_back(const Identifier &id)
Definition: IdentifierBranch.cxx:14
MuonR4::BucketDumperAlg::m_spoint_isStrip
MuonVal::VectorBranch< unsigned short > & m_spoint_isStrip
Definition: BucketDumperAlg.h:77
MuonR4::BucketDumperAlg::m_spoint_isMdt
MuonVal::VectorBranch< unsigned short > & m_spoint_isMdt
Definition: BucketDumperAlg.h:78
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
MuonR4::BucketDumperAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: BucketDumperAlg.h:49
MuonR4::BucketDumperAlg::m_spoint_measuresEta
MuonVal::VectorBranch< unsigned short > & m_spoint_measuresEta
Definition: BucketDumperAlg.h:89
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
MuonR4::BucketDumperAlg::m_spoint_mat
MuonVal::MatrixBranch< int16_t > & m_spoint_mat
Definition: BucketDumperAlg.h:97
MuonR4::BucketDumperAlg::m_spoint_trueLabel
MuonVal::VectorBranch< unsigned short > & m_spoint_trueLabel
Definition: BucketDumperAlg.h:91
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
MuonVal::MuonTesterBranch::name
std::string name() const override final
Returns the name of the branch.
Definition: MuonTesterBranch.cxx:51
MuonR4::BucketDumperAlg::m_spoint_driftR
MuonVal::VectorBranch< float > & m_spoint_driftR
Definition: BucketDumperAlg.h:87
MdtDriftCircle.h
MuonVal::VectorBranch::push_back
void push_back(const T &value)
Adds a new element at the end of the vector.
MuonR4::CalibratedSpacePoint::State::Valid
@ Valid
MuonR4::BucketDumperAlg::initialize
virtual StatusCode initialize() override final
Definition: BucketDumperAlg.cxx:18
MuonR4::BucketDumperAlg::m_spoint_layer
MuonVal::VectorBranch< uint16_t > & m_spoint_layer
Definition: BucketDumperAlg.h:76
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
MuonR4::BucketDumperAlg::m_spoint_tdc
MuonVal::VectorBranch< uint16_t > & m_spoint_tdc
Definition: BucketDumperAlg.h:81
BucketDumperAlg.h
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonR4::BucketDumperAlg::m_inSegmentKeys
SG::ReadHandleKeyArray< MuonR4::SegmentContainer > m_inSegmentKeys
Definition: BucketDumperAlg.h:51
MuonR4::BucketDumperAlg::m_bucket_spacePoints
MuonVal::ScalarBranch< uint16_t > & m_bucket_spacePoints
Definition: BucketDumperAlg.h:68
MuonR4::BucketDumperAlg::m_bucket_segments
MuonVal::ScalarBranch< uint16_t > & m_bucket_segments
Definition: BucketDumperAlg.h:69
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
MuonR4::BucketDumperAlg::dumpContainer
StatusCode dumpContainer(const EventContext &ctx, const SG::ReadHandleKey< SpacePointContainer > &spacePointKey, const SG::ReadHandleKey< SegmentContainer > &segmentKey)
Dumps the space point container with the associated muon segment container.
Definition: BucketDumperAlg.cxx:51
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MuonR4::BucketDumperAlg::m_segment_numberDoF
MuonVal::VectorBranch< float > & m_segment_numberDoF
Definition: BucketDumperAlg.h:101
MuonVal::MuonTesterTree::fill
bool fill(const EventContext &ctx)
Fills the tree per call.
Definition: MuonTesterTree.cxx:89
MuonR4::BucketDumperAlg::m_segment_chiSquared
MuonVal::VectorBranch< float > & m_segment_chiSquared
Definition: BucketDumperAlg.h:100
MuonVal::MuonTesterTree::write
StatusCode write()
Finally write the TTree objects.
Definition: MuonTesterTree.cxx:178
MuonR4::BucketDumperAlg::m_visionTool
ToolHandle< MuonValR4::IPatternVisualizationTool > m_visionTool
Pattern visualization tool.
Definition: BucketDumperAlg.h:61
MuonVal::VectorBranch::size
size_t size() const
Returns the number of actual saved elements.
MuonR4::BucketDumperAlg::m_streamName
Gaudi::Property< std::string > m_streamName
Definition: BucketDumperAlg.h:57
ReadHandle.h
Handle class for reading from StoreGate.
xAOD::MdtDriftCircle_v1
https://gitlab.cern.ch/atlas/athena/-/blob/master/MuonSpectrometer/MuonReconstruction/MuonRecEvent/Mu...
Definition: MdtDriftCircle_v1.h:21
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
MuonR4::BucketDumperAlg::m_segmentDir
MuonVal::ThreeVectorBranch m_segmentDir
Definition: BucketDumperAlg.h:99
MuonR4::BucketDumperAlg::m_spoint_nEtaInstances
MuonVal::VectorBranch< unsigned int > & m_spoint_nEtaInstances
Definition: BucketDumperAlg.h:92
MuonR4::BucketDumperAlg::m_spoint_covX
MuonVal::VectorBranch< float > & m_spoint_covX
Definition: BucketDumperAlg.h:83
MuonVal::MuonTesterTree::tree
TTree * tree()
TTree object.
Definition: MuonTesterTree.cxx:22
xAOD::UncalibMeasType::MdtDriftCircleType
@ MdtDriftCircleType
SpacePointPerLayerSorter.h
MuonR4::BucketDumperAlg::m_spoint_nSegments
MuonVal::VectorBranch< uint16_t > & m_spoint_nSegments
Definition: BucketDumperAlg.h:96
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5
MuonVal::MuonTesterTree::addBranch
bool addBranch(std::shared_ptr< IMuonTesterBranch > branch)
Branch is added to the tree without transferring the ownership.
Definition: MuonTesterTree.cxx:61
Identifier
Definition: IdentifierFieldParser.cxx:14