ATLAS Offline Software
BucketDumperAlg.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 #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 {
18  union bucketId{
19  int8_t fields[4];
20  int hash;
21  };
22 
23 }
24 
25 namespace MuonR4{
28  ATH_CHECK(m_idHelperSvc.retrieve());
30  ATH_CHECK(m_inSegmentKey.initialize(!m_inSegmentKey.empty()));
31  m_tree.addBranch(std::make_shared<MuonVal::EventHashBranch>(m_tree.tree()));
32  ATH_CHECK(m_tree.init(this));
33  ATH_CHECK(m_idHelperSvc.retrieve());
34  ATH_MSG_DEBUG("Successfully initialized");
35 
36  return StatusCode::SUCCESS;
37  }
38 
41  return StatusCode::SUCCESS;
42  }
43 
45  const EventContext& ctx{Gaudi::Hive::currentContext()};
46 
47  std::unordered_map <const SpacePointBucket*, std::vector<const MuonR4::Segment*>> segmentMap; // MuonR4Segment
48 
49  SG::ReadHandle readSegment(m_inSegmentKey, ctx);
50  ATH_CHECK(readSegment.isPresent());
51  for (const MuonR4::Segment* segment : *readSegment) {
52  segmentMap[segment->parent()->parentBucket()].push_back(segment);
53  }
54 
55  SG::ReadHandle gctx(m_geoCtxKey, ctx);
56  ATH_CHECK(gctx.isPresent());
57 
59  ATH_CHECK(readHandle.isPresent());
60 
61  CLHEP::HepRandomEngine* rndEngine = getRandomEngine(ctx);
62 
63  for(const SpacePointBucket* bucket : *readHandle) {
64 
65  if ( !m_isMC && segmentMap[bucket].size() == 0) {
66  if (CLHEP::RandFlat::shoot(rndEngine,0.,1.) > m_fracToKeep) {
67  ATH_MSG_VERBOSE("Skipping bucket without segment");
68  continue;
69  }
70  }
71 
72  m_bucket_min = bucket->coveredMin();
73  m_bucket_max = bucket->coveredMax();
74  m_bucket_segments = segmentMap[bucket].size();
75 
76  std::unordered_map<const SpacePoint*, std::vector<int16_t>> spacePointToSegment;
77 
78  auto match_itr = segmentMap.find(bucket);
79 
80  if (match_itr != segmentMap.end()) {
81  unsigned int segIdx{0};
82  for (const MuonR4::Segment* segment : match_itr->second) {
83  for (const auto& meas : segment->measurements()) {
84  spacePointToSegment[meas->spacePoint()].push_back(segIdx);
85  }
86  ++segIdx;
87  }
88 
89  for ( const MuonR4::Segment* segment: match_itr->second) {
90  m_segmentPos.push_back(segment->position());
91  m_segmentDir.push_back(segment->direction());
94  }
95  }
96 
98  unsigned int layer{0};
99 
100  for (const auto& hitsInLay : sorter.mdtHits()) {
101  for (const auto sp : hitsInLay){
102 
103  const auto* dc = static_cast<const xAOD::MdtDriftCircle*>(sp->primaryMeasurement());
105  continue;
106  }
107 
108  m_spoint_id.push_back(sp->identify());
109 
110  Identifier id = sp->identify();
111  unsigned int mdt_ML = m_idHelperSvc->mdtIdHelper().multilayer(id);
112  unsigned int mdt_TL = m_idHelperSvc->mdtIdHelper().tubeLayer(id);
113  unsigned int mdt_nL = m_idHelperSvc->mdtIdHelper().tubeLayerMax(id);
114  m_spoint_mdtLayer = mdt_ML * (mdt_nL-1) + mdt_TL;
115  m_spoint_mdtTube = m_idHelperSvc->mdtIdHelper().tube(id);
116 
117  const std::vector<int16_t>& segIdxs = spacePointToSegment[sp];
118 
119  m_spoint_mat[m_spoint_mat.size()] = segIdxs;
120  m_spoint_nSegments.push_back(segIdxs.size());
121 
122  m_bucket_spacePoints = bucket->size();
123  m_spoint_localPosition.push_back(sp->positionInChamber());
124  m_spoint_adc.push_back(dc->adc());
125  m_spoint_tdc.push_back(dc->tdc());
126  m_spoint_covX.push_back(sp->covariance()(Amg::x, Amg::x));
127  m_spoint_covY.push_back(sp->covariance()(Amg::y, Amg::y));
128  m_spoint_covXY.push_back(sp->covariance()(Amg::x, Amg::y));
129  m_spoint_covYX.push_back(sp->covariance()(Amg::y, Amg::x));
130  m_spoint_driftR.push_back(sp->driftRadius());
131  m_spoint_measuresEta.push_back(sp->measuresEta());
132  m_spoint_measuresPhi.push_back(sp->measuresPhi());
133  m_spoint_nEtaInstances.push_back(sp->nEtaInstanceCounts());
134  m_spoint_nPhiInstances.push_back(sp->nPhiInstanceCounts());
135  m_spoint_dimension.push_back(sp->dimension());
139 
140  Amg::Vector3D globalPos = sp->msSector()->localToGlobalTrans(*gctx) * sp->positionInChamber();
141  m_spoint_globalPosition.push_back( globalPos );
142 
143  }
144  ++layer;
145 
146  }
147 
148  for (const auto& hitsInLay : sorter.stripHits()) {
149 
150  for (const auto sp : hitsInLay){
151 
152  const std::vector<int16_t>& segIdxs = spacePointToSegment[sp];
153 
154  m_spoint_mat[m_spoint_mat.size()] = segIdxs;
155  m_spoint_nSegments.push_back(segIdxs.size());
156 
157  m_spoint_id.push_back(sp->identify());
158  m_bucket_spacePoints = bucket->size();
159  m_spoint_localPosition.push_back(sp->positionInChamber());
160 
161  m_spoint_covX.push_back(sp->covariance()(Amg::x, Amg::x));
162  m_spoint_covY.push_back(sp->covariance()(Amg::y, Amg::y));
163  m_spoint_covXY.push_back(sp->covariance()(Amg::x, Amg::y));
164  m_spoint_covYX.push_back(sp->covariance()(Amg::y, Amg::x));
165  m_spoint_driftR.push_back(sp->driftRadius());
166  m_spoint_measuresEta.push_back(sp->measuresEta());
167  m_spoint_measuresPhi.push_back(sp->measuresPhi());
168  m_spoint_nEtaInstances.push_back(sp->nEtaInstanceCounts());
169  m_spoint_nPhiInstances.push_back(sp->nPhiInstanceCounts());
170  m_spoint_dimension.push_back(sp->dimension());
173  m_spoint_isMdt.push_back(false);
174 
175  Amg::Vector3D globalPos = sp->msSector()->localToGlobalTrans(*gctx) * sp->positionInChamber();
176  m_spoint_globalPosition.push_back( globalPos );
177 
178  // check the technology to fill channel, adc and tdc... pushing back 0 for now
181 
182  }
183  ++layer;
184  }
185 
187 
188  if (!m_tree.fill(ctx)) return StatusCode::FAILURE;
189 
190  }
191 
192  return StatusCode::SUCCESS;
193 
194  }
195 
196  CLHEP::HepRandomEngine* BucketDumperAlg::getRandomEngine(const EventContext&ctx) const {
197  ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, m_streamName);
198  std::string rngName = m_streamName;
199  rngWrapper->setSeed(rngName, ctx);
200  return rngWrapper->getEngine(ctx);
201  }
202 
203 }
MuonR4::BucketDumperAlg::m_spoint_measuresPhi
MuonVal::VectorBranch< bool > & m_spoint_measuresPhi
Definition: BucketDumperAlg.h:88
MuonR4::BucketDumperAlg::m_spoint_measuresEta
MuonVal::VectorBranch< bool > & m_spoint_measuresEta
Definition: BucketDumperAlg.h:87
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:91
UtilFunctions.h
MuonR4::BucketDumperAlg::getRandomEngine
CLHEP::HepRandomEngine * getRandomEngine(const EventContext &ctx) const
Definition: BucketDumperAlg.cxx:196
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_inSegmentKey
SG::ReadHandleKey< MuonR4::SegmentContainer > m_inSegmentKey
Definition: BucketDumperAlg.h:50
MuonR4::BucketDumperAlg::m_spoint_adc
MuonVal::VectorBranch< uint16_t > & m_spoint_adc
Definition: BucketDumperAlg.h:78
MuonR4::BucketDumperAlg::m_bucket_max
MuonVal::ScalarBranch< float > & m_bucket_max
Definition: BucketDumperAlg.h:63
MuonR4::SpacePointPerLayerSorter
The SpacePointPerLayerSorter groups the space points by their layer Identifier.
Definition: SpacePointPerLayerSorter.h:14
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonR4::BucketDumperAlg::m_tree
MuonVal::MuonTesterTree m_tree
Definition: BucketDumperAlg.h:60
MuonR4::BucketDumperAlg::m_spoint_covYX
MuonVal::VectorBranch< float > & m_spoint_covYX
Definition: BucketDumperAlg.h:83
MuonR4::BucketDumperAlg::execute
virtual StatusCode execute() override final
Definition: BucketDumperAlg.cxx:44
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:71
Amg::y
@ y
Definition: GeoPrimitives.h:35
MuonR4::BucketDumperAlg::m_spoint_globalPosition
MuonVal::ThreeVectorBranch m_spoint_globalPosition
Definition: BucketDumperAlg.h:69
MuonR4::BucketDumperAlg::finalize
virtual StatusCode finalize() override final
Definition: BucketDumperAlg.cxx:39
postInclude.sorter
sorter
Definition: postInclude.SortInput.py:23
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonR4::BucketDumperAlg::m_geoCtxKey
SG::ReadHandleKey< ActsGeometryContext > m_geoCtxKey
Definition: BucketDumperAlg.h:52
EventHashBranch.h
MuonR4::BucketDumperAlg::m_bucket_min
MuonVal::ScalarBranch< float > & m_bucket_min
Definition: BucketDumperAlg.h:62
MuonR4::BucketDumperAlg::m_spoint_mdtLayer
MuonVal::ScalarBranch< short > & m_spoint_mdtLayer
Definition: BucketDumperAlg.h:75
MuonR4::BucketDumperAlg::m_spoint_nPhiInstances
MuonVal::VectorBranch< unsigned int > & m_spoint_nPhiInstances
Definition: BucketDumperAlg.h:90
Muon::MdtStatusDriftTime
@ MdtStatusDriftTime
The tube produced a vaild measurement.
Definition: MdtDriftCircleStatus.h:34
MuonR4::BucketDumperAlg::m_rndmSvc
ServiceHandle< IAthRNGSvc > m_rndmSvc
Definition: BucketDumperAlg.h:57
MuonR4::BucketDumperAlg::m_segmentPos
MuonVal::ThreeVectorBranch m_segmentPos
Definition: BucketDumperAlg.h:95
MuonR4::BucketDumperAlg::m_spoint_covXY
MuonVal::VectorBranch< float > & m_spoint_covXY
Definition: BucketDumperAlg.h:82
MuonR4::BucketDumperAlg::m_spoint_covY
MuonVal::VectorBranch< float > & m_spoint_covY
Definition: BucketDumperAlg.h:84
MuonR4::BucketDumperAlg::m_bucket_layers
MuonVal::ScalarBranch< uint16_t > & m_bucket_layers
Definition: BucketDumperAlg.h:66
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_isMdt
MuonVal::VectorBranch< bool > & m_spoint_isMdt
Definition: BucketDumperAlg.h:74
MuonR4::BucketDumperAlg::m_spoint_localPosition
MuonVal::ThreeVectorBranch m_spoint_localPosition
Definition: BucketDumperAlg.h:68
MuonR4::BucketDumperAlg::m_spoint_isStrip
MuonVal::VectorBranch< bool > & m_spoint_isStrip
Definition: BucketDumperAlg.h:73
MuonR4::BucketDumperAlg::m_isMC
Gaudi::Property< bool > m_isMC
Definition: BucketDumperAlg.h:54
MuonR4::BucketDumperAlg::m_spoint_mdtTube
MuonVal::ScalarBranch< short > & m_spoint_mdtTube
Definition: BucketDumperAlg.h:76
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:55
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
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:48
MuonR4::BucketDumperAlg::m_spoint_mat
MuonVal::MatrixBranch< int16_t > & m_spoint_mat
Definition: BucketDumperAlg.h:94
MuonR4::BucketDumperAlg::m_spoint_driftR
MuonVal::VectorBranch< float > & m_spoint_driftR
Definition: BucketDumperAlg.h:85
MdtDriftCircle.h
MuonVal::VectorBranch::push_back
void push_back(const T &value)
Adds a new element at the end of the vector.
MuonR4::BucketDumperAlg::initialize
virtual StatusCode initialize() override final
Definition: BucketDumperAlg.cxx:26
MuonR4::BucketDumperAlg::m_spoint_layer
MuonVal::VectorBranch< uint16_t > & m_spoint_layer
Definition: BucketDumperAlg.h:72
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:79
BucketDumperAlg.h
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonR4::BucketDumperAlg::m_bucket_spacePoints
MuonVal::ScalarBranch< uint16_t > & m_bucket_spacePoints
Definition: BucketDumperAlg.h:64
MuonR4::BucketDumperAlg::m_bucket_segments
MuonVal::ScalarBranch< uint16_t > & m_bucket_segments
Definition: BucketDumperAlg.h:65
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
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
MuonR4::BucketDumperAlg::m_segment_numberDoF
MuonVal::VectorBranch< float > & m_segment_numberDoF
Definition: BucketDumperAlg.h:98
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:97
MuonVal::MuonTesterTree::write
StatusCode write()
Finally write the TTree objects.
Definition: MuonTesterTree.cxx:178
MuonR4::BucketDumperAlg::m_readKey
SG::ReadHandleKey< SpacePointContainer > m_readKey
Definition: BucketDumperAlg.h:47
MuonVal::VectorBranch::size
size_t size() const
Returns the number of actual saved elements.
SG::VarHandleBase::isPresent
bool isPresent() const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:394
MuonR4::BucketDumperAlg::m_streamName
Gaudi::Property< std::string > m_streamName
Definition: BucketDumperAlg.h:56
CaloCondBlobAlgs_fillNoiseFromASCII.fields
fields
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:106
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
MuonR4::BucketDumperAlg::m_segmentDir
MuonVal::ThreeVectorBranch m_segmentDir
Definition: BucketDumperAlg.h:96
MuonR4::BucketDumperAlg::m_spoint_nEtaInstances
MuonVal::VectorBranch< unsigned int > & m_spoint_nEtaInstances
Definition: BucketDumperAlg.h:89
MuonR4::BucketDumperAlg::m_spoint_covX
MuonVal::VectorBranch< float > & m_spoint_covX
Definition: BucketDumperAlg.h:81
MuonVal::MuonTesterTree::tree
TTree * tree()
TTree object.
Definition: MuonTesterTree.cxx:22
SpacePointPerLayerSorter.h
MuonR4::BucketDumperAlg::m_spoint_nSegments
MuonVal::VectorBranch< uint16_t > & m_spoint_nSegments
Definition: BucketDumperAlg.h:93
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