ATLAS Offline Software
Loading...
Searching...
No Matches
Muon::MdtRdoToPrepDataToolMT Class Reference

Tool to produce MDT PRDs. More...

#include <MdtRdoToPrepDataToolMT.h>

Inheritance diagram for Muon::MdtRdoToPrepDataToolMT:
Collaboration diagram for Muon::MdtRdoToPrepDataToolMT:

Classes

struct  ConvCache
 Helper struct to parse the event data around the tool. More...

Public Member Functions

virtual ~MdtRdoToPrepDataToolMT ()=default
 default destructor
virtual StatusCode initialize () override
 standard Athena-Algorithm method
virtual StatusCode decode (const EventContext &ctx, const std::vector< IdentifierHash > &idVect) const override
 Decode method - declared in Muon::IMuonRdoToPrepDataTool.
virtual StatusCode provideEmptyContainer (const EventContext &ctx) const override
virtual StatusCode decode (const EventContext &ctx, const std::vector< uint32_t > &robIds) const override

Protected Member Functions

void printPrepDataImpl (const Muon::MdtPrepDataContainer *mdtPrepDataContainer) const
Muon::MdtDriftCircleStatus getMdtTwinPosition (const MdtDigit &prompt_digit, const MdtDigit &twin_digit, double &radius, double &errRadius, double &zTwin, double &errZTwin, bool &twinIsPrompt) const
 method to get the twin tube 2nd coordinate
StatusCode processCsm (const EventContext &ctx, ConvCache &mdtPrepDataContainer, const MdtCsm *rdoColl) const
StatusCode processCsmTwin (const EventContext &ctx, ConvCache &mdtPrepDataContainer, const MdtCsm *rdoColll) const
std::unique_ptr< MdtPrepDatacreatePrepData (const MdtCalibInput &calibInput, const MdtCalibOutput &calibOutput) const
 Creates the PRD object.
ConvCache setupMdtPrepDataContainer (const EventContext &ctx) const
 Creates the prep data container to be written.
const MdtCsmContainergetRdoContainer (const EventContext &ctx) const
 Loads the input RDO container from StoreGate.
void processPRDHashes (const EventContext &ctx, ConvCache &mdtPrepDataContainer, const std::vector< IdentifierHash > &chamberHashInRobs) const
bool handlePRDHash (const EventContext &ctx, ConvCache &mdtPrepDataContainer, IdentifierHash rdoHash) const
void initDeadChannels (const MuonGM::MdtReadoutElement *mydetEl)

Protected Attributes

ServiceHandle< Muon::IMuonIdHelperSvcm_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}
ToolHandle< IMdtCalibrationToolm_calibrationTool {this, "CalibrationTool", "MdtCalibrationTool"}
 MDT calibration service.
SG::WriteHandleKey< Muon::MdtPrepDataContainerm_mdtPrepDataContainerKey {this, "OutputCollection", "MDT_DriftCircles"}
 MdtPrepRawData containers.
SG::ReadHandleKey< MdtCsmContainerm_rdoContainerKey {this, "RDOContainer", "MDTCSM"}
Gaudi::Property< int > m_adcCut
 member variables for algorithm properties:
Gaudi::Property< bool > m_calibratePrepData {this, "CalibratePrepData", true}
 toggle on/off calibration of MdtPrepData
Gaudi::Property< bool > m_decodeData {this, "DecodeData", true}
 toggle on/off the decoding of MDT RDO into MdtPrepData
bool m_sortPrepData = false
 Toggle on/off the sorting of the MdtPrepData.
ToolHandle< Muon::IMDT_RDO_Decoderm_mdtDecoder {this, "Decoder", "Muon::MdtRDO_Decoder/MdtRDO_Decoder"}
bool m_BMGpresent {false}
int m_BMGid {-1}
Gaudi::Property< bool > m_useTwin {this, "UseTwin", true}
Gaudi::Property< bool > m_discardSecondaryHitTwin {this, "DiscardSecondaryHitTwin", false}
SG::ReadCondHandleKey< TwinTubeMapm_twinTubeKey {this, "TwinTubeKey", "MdtTwinTubeMap"}
std::unordered_set< Identifierm_DeadChannels {}
SG::ReadCondHandleKey< MuonMDT_CablingMapm_readKey {this, "ReadKey", "MuonMDT_CablingMap", "Key of MuonMDT_CablingMap"}
SG::ReadCondHandleKey< MuonGM::MuonDetectorManagerm_muDetMgrKey
SG::UpdateHandleKey< MdtPrepDataCollection_Cachem_prdContainerCacheKey
 This is the key for the cache for the MDT PRD containers, can be empty.

Detailed Description

Tool to produce MDT PRDs.

Definition at line 35 of file MdtRdoToPrepDataToolMT.h.

Constructor & Destructor Documentation

◆ ~MdtRdoToPrepDataToolMT()

virtual Muon::MdtRdoToPrepDataToolMT::~MdtRdoToPrepDataToolMT ( )
virtualdefault

default destructor

Member Function Documentation

◆ createPrepData()

std::unique_ptr< MdtPrepData > Muon::MdtRdoToPrepDataToolMT::createPrepData ( const MdtCalibInput & calibInput,
const MdtCalibOutput & calibOutput ) const
protected

Creates the PRD object.

Test by how much do we break frozen Tier0

Definition at line 208 of file MdtRdoToPrepDataToolMT.cxx.

209 {
210 if (calibInput.adc() < m_adcCut ||
211 calibOutput.status() == MdtDriftCircleStatus::MdtStatusUnDefined) {
212 ATH_MSG_VERBOSE("Do not create calib hit for "<<m_idHelperSvc->toString(calibInput.identify())
213 <<", adc: "<<calibInput.adc()<<" vs. "<<m_adcCut<<", calibration bailed out "
214 <<(calibOutput.status() == MdtDriftCircleStatus::MdtStatusUnDefined? "si": "no"));
215 return nullptr;
216 }
217 const MuonGM::MdtReadoutElement* descriptor = calibInput.legacyDescriptor();
218 ATH_MSG_VERBOSE("Calibrated prepdata "<<m_idHelperSvc->toString(calibInput.identify())
219 <<std::endl<<calibInput<<std::endl<<calibOutput);
220
221 Amg::Vector2D driftRadius{Amg::Vector2D::Zero()};
222 Amg::MatrixX cov(1, 1);
223 if (calibOutput.status() == MdtDriftCircleStatus::MdtStatusDriftTime){
225 const float r = calibOutput.driftRadius();
226 const float sigR = calibOutput.driftRadiusUncert();
227 driftRadius[0] = r;
228 (cov)(0, 0) = sigR * sigR;
229 } else (cov)(0, 0) = std::pow(descriptor->innerTubeRadius(), 2);
230
231 return std::make_unique<MdtPrepData>(calibInput.identify(),
232 std::move(driftRadius),
233 std::move(cov),
234 descriptor,
235 calibInput.tdc(),
236 calibInput.adc(),
237 calibOutput.status());
238 }
#define ATH_MSG_VERBOSE(x)
const MuonGM::MdtReadoutElement * legacyDescriptor() const
Returns the legacy readout element.
int16_t tdc() const
Returns the tdc counts of the hit.
int16_t adc() const
Returns the amount of accumulated charge.
const Identifier & identify() const
Returns the Identifier of the hit.
double driftRadiusUncert() const
Returns the uncertainty on the drift radius.
double driftRadius() const
Returns the drift radius of the calibrated object.
MdtDriftCircleStatus status() const
Status of the calibration.
double innerTubeRadius() const
Returns the inner tube radius excluding the aluminium walls.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Gaudi::Property< int > m_adcCut
member variables for algorithm properties:
int r
Definition globals.cxx:22
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 2, 1 > Vector2D
@ driftRadius
trt, straws
Definition ParamDefs.h:53

◆ decode() [1/2]

StatusCode Muon::MdtRdoToPrepDataToolMT::decode ( const EventContext & ctx,
const std::vector< IdentifierHash > & idVect ) const
overridevirtual

Decode method - declared in Muon::IMuonRdoToPrepDataTool.

Construct the hashes from the existing RDOs

Definition at line 174 of file MdtRdoToPrepDataToolMT.cxx.

175 {
176
177 ATH_MSG_DEBUG("decodeMdtRDO for " << idVect.size() << " offline collections called");
178
179 // setup output container
180 ConvCache mdtPrepDataContainer = setupMdtPrepDataContainer(ctx);
181 if (!mdtPrepDataContainer.isValid) {
182 return StatusCode::FAILURE;
183 }
184
185
186 if (!m_decodeData) {
187 ATH_MSG_DEBUG("Stored empty container. Decoding MDT RDO into MDT PrepRawData is switched off");
188 return StatusCode::SUCCESS;
189 }
190 // seeded or unseeded decoding
191 if (!idVect.empty()) {
192 processPRDHashes(ctx, mdtPrepDataContainer, idVect);
193 } else {
195 std::vector<IdentifierHash> rdoHashes{};
196 const MdtCsmContainer* rdoContainer = getRdoContainer(ctx);
197 if (!rdoContainer || rdoContainer->empty()) return StatusCode::SUCCESS;
198 rdoHashes.reserve(rdoContainer->size());
199 for (const MdtCsm* csm : *rdoContainer) rdoHashes.push_back(csm->identifyHash());
200
201 processPRDHashes(ctx, mdtPrepDataContainer, rdoHashes);
202 }
203 ATH_CHECK(mdtPrepDataContainer.finalize(msgStream()));
204
205 return StatusCode::SUCCESS;
206 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current MdtCsm
bool empty() const
return true if container is empty
size_t size() const
Duplicate of fullSize for backwards compatability.
ConvCache setupMdtPrepDataContainer(const EventContext &ctx) const
Creates the prep data container to be written.
const MdtCsmContainer * getRdoContainer(const EventContext &ctx) const
Loads the input RDO container from StoreGate.
void processPRDHashes(const EventContext &ctx, ConvCache &mdtPrepDataContainer, const std::vector< IdentifierHash > &chamberHashInRobs) const
Gaudi::Property< bool > m_decodeData
toggle on/off the decoding of MDT RDO into MdtPrepData
Helper struct to parse the event data around the tool.

◆ decode() [2/2]

StatusCode Muon::MdtRdoToPrepDataToolMT::decode ( const EventContext & ctx,
const std::vector< uint32_t > & robIds ) const
overridevirtual

Definition at line 126 of file MdtRdoToPrepDataToolMT.cxx.

126 {
127 const MuonMDT_CablingMap* readCdo{nullptr};
128 ATH_CHECK(SG::get(readCdo, m_readKey, ctx));
129 return decode(ctx, readCdo->getMultiLayerHashVec(robIds, msgStream()));
130 }
std::vector< IdentifierHash > getMultiLayerHashVec(const std::vector< uint32_t > &ROBId_list, MsgStream &log) const
return a vector of HashId lists for a given list of ROD's
SG::ReadCondHandleKey< MuonMDT_CablingMap > m_readKey
virtual StatusCode decode(const EventContext &ctx, const std::vector< IdentifierHash > &idVect) const override
Decode method - declared in Muon::IMuonRdoToPrepDataTool.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.

◆ getMdtTwinPosition()

Muon::MdtDriftCircleStatus Muon::MdtRdoToPrepDataToolMT::getMdtTwinPosition ( const MdtDigit & prompt_digit,
const MdtDigit & twin_digit,
double & radius,
double & errRadius,
double & zTwin,
double & errZTwin,
bool & twinIsPrompt ) const
protected

method to get the twin tube 2nd coordinate

◆ getRdoContainer()

const MdtCsmContainer * Muon::MdtRdoToPrepDataToolMT::getRdoContainer ( const EventContext & ctx) const
protected

Loads the input RDO container from StoreGate.

Definition at line 132 of file MdtRdoToPrepDataToolMT.cxx.

132 {
133 SG::ReadHandle rdoContainerHandle{m_rdoContainerKey, ctx};
134 if (rdoContainerHandle.isValid()) {
135 ATH_MSG_DEBUG("MdtgetRdoContainer success");
136 return rdoContainerHandle.cptr();
137 }
138 ATH_MSG_WARNING("Retrieval of Mdt RDO container failed !");
139 return nullptr;
140 }
#define ATH_MSG_WARNING(x)
SG::ReadHandleKey< MdtCsmContainer > m_rdoContainerKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.

◆ handlePRDHash()

bool Muon::MdtRdoToPrepDataToolMT::handlePRDHash ( const EventContext & ctx,
ConvCache & mdtPrepDataContainer,
IdentifierHash rdoHash ) const
protected

Definition at line 153 of file MdtRdoToPrepDataToolMT.cxx.

155 {
156 const MdtCsmContainer* rdoContainer{getRdoContainer(ctx)};
157
158 if (rdoContainer->empty()) {
159 ATH_MSG_DEBUG("The container is empty");
160 return true;
161 }
162 const MdtCsm* rdoColl = rdoContainer->indexFindPtr(rdoHash);
163 if (!rdoColl) {
164 ATH_MSG_DEBUG("The rdo container does not have the hash " << rdoHash);
165 return true;
166 }
167 if (processCsm(ctx, mdtPrepDataContainer, rdoColl).isFailure()) {
168 ATH_MSG_WARNING("processCsm failed for RDO id " << m_idHelperSvc->toString(rdoColl->identify()));
169 return false;
170 }
171 return true;
172 }
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
Identifier identify() const
Returns the CSM offline identifier (chamber offline id).
Definition MdtCsm.h:55
StatusCode processCsm(const EventContext &ctx, ConvCache &mdtPrepDataContainer, const MdtCsm *rdoColl) const

◆ initDeadChannels()

void Muon::MdtRdoToPrepDataToolMT::initDeadChannels ( const MuonGM::MdtReadoutElement * mydetEl)
protected

Definition at line 452 of file MdtRdoToPrepDataToolMT.cxx.

452 {
453 PVConstLink cv = mydetEl->getMaterialGeom(); // it is "Multilayer"
454 int nGrandchildren = cv->getNChildVols();
455 if (nGrandchildren <= 0) return;
456
457 std::vector<int> tubes;
458 geoGetIds([&](int id) { tubes.push_back(id); }, &*cv);
459 std::sort(tubes.begin(), tubes.end());
460
461 const Identifier detElId = mydetEl->identify();
462 const int ml = mydetEl->getMultilayer();
463 std::vector<int>::iterator it = tubes.begin();
464 for (int layer = 1; layer <= mydetEl->getNLayers(); layer++) {
465 for (int tube = 1; tube <= mydetEl->getNtubesperlayer(); tube++) {
466 int want_id = layer * maxNTubesPerLayer + tube;
467 if (it != tubes.end() && *it == want_id) {
468 ++it;
469 } else {
470 it = std::lower_bound(tubes.begin(), tubes.end(), want_id);
471 if (it != tubes.end() && *it == want_id) {
472 ++it;
473 } else {
474 Identifier deadTubeId = m_idHelperSvc->mdtIdHelper().channelID(detElId, ml, layer, tube);
475 m_DeadChannels.insert(deadTubeId);
476 ATH_MSG_VERBOSE("adding dead tube "<<m_idHelperSvc->toString(deadTubeId));
477 }
478 }
479 }
480 }
481
482 }
void geoGetIds(FUNCTION f, const GeoGraphNode *node, int depthLimit=1)
Template helper for running the visitor.
Definition GeoGetIds.h:82
int getNLayers() const
Returns the number of tube layers inside the multilayer.
int getMultilayer() const
Returns the multilayer represented by the readout element.
int getNtubesperlayer() const
Returns the number of tubes in each tube layer.
Identifier identify() const override final
Returns the ATLAS Identifier of the MuonReadOutElement.
std::unordered_set< Identifier > m_DeadChannels
@ layer
Definition HitInfo.h:79
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ initialize()

StatusCode Muon::MdtRdoToPrepDataToolMT::initialize ( )
overridevirtual

standard Athena-Algorithm method

Definition at line 86 of file MdtRdoToPrepDataToolMT.cxx.

86 {
87 ATH_CHECK(m_calibrationTool.retrieve());
88 ATH_MSG_VERBOSE("MdtCalibrationTool retrieved with pointer = " << m_calibrationTool);
90 ATH_CHECK(m_idHelperSvc.retrieve());
91 // Retrieve the RDO decoder
92 ATH_CHECK(m_mdtDecoder.retrieve());
93
95
96 m_BMGid = m_idHelperSvc->mdtIdHelper().stationNameIndex("BMG");
97 m_BMGpresent = m_BMGid != -1;
98 if (m_BMGpresent) {
99 const MuonGM::MuonDetectorManager* muDetMgr = nullptr;
100 ATH_CHECK(detStore()->retrieve(muDetMgr));
101
102 ATH_MSG_INFO("Processing configuration for layouts with BMG chambers.");
103
104 for (int phi = 6; phi < 8; phi++) { // phi sectors
105 for (int eta = 1; eta < 4; eta++) { // eta sectors
106 for (int side = -1; side < 2; side += 2) { // side
107 if (!muDetMgr->getMuonStation("BMG", side * eta, phi)) continue;
108 for (int roe = 1; roe <= (muDetMgr->getMuonStation("BMG", side * eta, phi))->nMuonReadoutElements();
109 roe++) { // iterate on readout elemets
110 const MdtReadoutElement* mdtRE = dynamic_cast<const MdtReadoutElement*>(
111 (muDetMgr->getMuonStation("BMG", side * eta, phi))->getMuonReadoutElement(roe)); // has to be an MDT
112 if (mdtRE) initDeadChannels(mdtRE);
113 }
114 }
115 }
116 }
117 }
118 // initialize handle keys
119 ATH_CHECK(m_rdoContainerKey.initialize());
121 ATH_CHECK(m_readKey.initialize());
122 ATH_CHECK(m_muDetMgrKey.initialize());
123 return StatusCode::SUCCESS;
124 }
Scalar eta() const
pseudorapidity method
#define ATH_MSG_INFO(x)
const MuonStation * getMuonStation(const std::string &stName, int eta, int phi) const
SG::UpdateHandleKey< MdtPrepDataCollection_Cache > m_prdContainerCacheKey
This is the key for the cache for the MDT PRD containers, can be empty.
ToolHandle< IMdtCalibrationTool > m_calibrationTool
MDT calibration service.
SG::ReadCondHandleKey< TwinTubeMap > m_twinTubeKey
SG::WriteHandleKey< Muon::MdtPrepDataContainer > m_mdtPrepDataContainerKey
MdtPrepRawData containers.
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_muDetMgrKey
void initDeadChannels(const MuonGM::MdtReadoutElement *mydetEl)
ToolHandle< Muon::IMDT_RDO_Decoder > m_mdtDecoder
@ phi
Definition ParamDefs.h:75

◆ printPrepDataImpl()

void Muon::MdtRdoToPrepDataToolMT::printPrepDataImpl ( const Muon::MdtPrepDataContainer * mdtPrepDataContainer) const
protected

◆ processCsm()

StatusCode Muon::MdtRdoToPrepDataToolMT::processCsm ( const EventContext & ctx,
ConvCache & mdtPrepDataContainer,
const MdtCsm * rdoColl ) const
protected

MDT hit context

Definition at line 240 of file MdtRdoToPrepDataToolMT.cxx.

240 {
241 const MdtIdHelper& id_helper = m_idHelperSvc->mdtIdHelper();
242 // first handle the case of twin tubes
243 if (m_useTwin) {
244 if (cache.twinTubeMap->isTwinTubeLayer(rdoColl->identify())) {
245 return processCsmTwin(ctx, cache, rdoColl);
246 }
247 }
248
249 ATH_MSG_DEBUG(" ***************** Start of processCsm");
250
252 const Identifier elementId = id_helper.parentID(rdoColl->identify());
253
254 uint16_t subdetId = rdoColl->SubDetId();
255 uint16_t mrodId = rdoColl->MrodId();
256 uint16_t csmId = rdoColl->CsmId();
257 ATH_MSG_VERBOSE("Identifier = " << m_idHelperSvc->toString(elementId) << " subdetId/ mrodId/ csmId = " << subdetId << " / "
258 << mrodId << " / " << csmId);
259
260 // for each Csm, loop over AmtHit, converter AmtHit to digit
261 // retrieve/create digit collection, and insert digit into collection
262 unsigned mc{0};
263
264 for (const MdtAmtHit* amtHit : *rdoColl) {
265 ++mc;
266
267 // FIXME: Still use the digit class.
268 ATH_MSG_VERBOSE("Amt Hit n. " << mc << " tdcId = " << amtHit->tdcId());
269 std::unique_ptr<MdtDigit> newDigit{m_mdtDecoder->getDigit(ctx, *amtHit, subdetId, mrodId, csmId)};
270 if (!newDigit) {
271 ATH_MSG_WARNING("Found issue MDT RDO decoder for subdetId/mrodId/csmId "
272 << subdetId << "/" << mrodId << "/" << csmId << " amtHit channelId/tdcId =" << amtHit->channelId() << "/"
273 << amtHit->tdcId());
274 continue;
275 }
276 // Do something with it
277 Identifier channelId = newDigit->identify();
278 if (newDigit->isMasked() || m_DeadChannels.count(channelId)) {
279 continue;
280 }
281 // Retrieve the proper PRD container. Note that there are cases where one CSM is either split into 2 chambers (BEE / BIS78
282 // legacy) or 2 CSMs are split into one chamber
283 MdtPrepDataCollection* driftCircleColl = cache.createCollection(channelId);
284 if (!driftCircleColl) {
285 ATH_MSG_DEBUG("Corresponding multi layer " << m_idHelperSvc->toString(channelId) << " is already decoded.");
286 continue;
287 }
288
289 // check if the module ID of this channel is different from the CSM one
290 // If it's the first case, create the additional collection
291
292 ATH_MSG_VERBOSE("got digit with id ext / hash " << m_idHelperSvc->toString(channelId) << " / "
293 << driftCircleColl->identifyHash());
294
295 // Rescale ADC/TDC of chambers using HPTDC digitization chip
296 // Must create a new digit from the old one, because MdtDigit has no methods to set ADC/TDC
297 if (m_idHelperSvc->hasHPTDC(channelId)) {
298 newDigit->setAdc(newDigit->adc() / 4);
299 newDigit->setTdc(newDigit->tdc() / 4);
300 }
301
302 const MdtCalibInput calibIn{*newDigit, *cache.legacyDetMgr};
303 const MdtCalibOutput calibResult{m_calibrationTool->calibrate(ctx, calibIn, false)};
304
305 std::unique_ptr<MdtPrepData> newPrepData = createPrepData(calibIn, calibResult);
306 if (!newPrepData) {
307 continue;
308 }
309 if (driftCircleColl->size()) {
310 MdtPrepData* prevPrd = driftCircleColl->at(driftCircleColl->size()-1);
311 if (prevPrd->identify() == channelId) {
312 std::stringstream sstr{};
313 ATH_MSG_VERBOSE("Duplicated prep data object detected: "<<std::endl
314 <<" **** "<<print(*prevPrd)<<std::endl
315 <<" **** "<<print(*newPrepData));
316 if (prevPrd->status() == MdtDriftCircleStatus::MdtStatusDriftTime) {
317 ATH_MSG_VERBOSE("Prd is already good");
318 } else if (newPrepData->status() == MdtDriftCircleStatus::MdtStatusDriftTime) {
319 (*prevPrd) = std::move(*newPrepData);
320 prevPrd->setHashAndIndex(driftCircleColl->identifyHash(), driftCircleColl->size()-1);
321 }
322 continue;
323 }
324 }
325 ATH_MSG_VERBOSE("New prd created "<<print(*newPrepData));
326 newPrepData->setHashAndIndex(driftCircleColl->identifyHash(), driftCircleColl->size());
327 driftCircleColl->push_back(std::move(newPrepData));
328 }
329 return StatusCode::SUCCESS;
330 }
uint16_t CsmId() const
Returns the CSM online id (online identifier inside a MROD).
Definition MdtCsm.h:65
uint16_t MrodId() const
Returns the MROD id from the CSM header.
Definition MdtCsm.h:63
uint16_t SubDetId() const
Returns the sub-detector Id.
Definition MdtCsm.h:61
Identifier parentID(const Identifier &id) const
get parent id from channel id
std::unique_ptr< MdtPrepData > createPrepData(const MdtCalibInput &calibInput, const MdtCalibOutput &calibOutput) const
Creates the PRD object.
StatusCode processCsmTwin(const EventContext &ctx, ConvCache &mdtPrepDataContainer, const MdtCsm *rdoColll) const
std::string print(const MuPatSegment &)
MuonPrepDataCollection< MdtPrepData > MdtPrepDataCollection
const IIntersectionCache * cache() const
Retrieve the associated cache block, if it exists.
setWord1 uint16_t

◆ processCsmTwin()

StatusCode Muon::MdtRdoToPrepDataToolMT::processCsmTwin ( const EventContext & ctx,
ConvCache & mdtPrepDataContainer,
const MdtCsm * rdoColll ) const
protected

MDT hit context

Create new PrepData

check for the twin tube id

Definition at line 331 of file MdtRdoToPrepDataToolMT.cxx.

331 {
332 const MdtIdHelper& id_helper = m_idHelperSvc->mdtIdHelper();
333 ATH_MSG_DEBUG(" ***************** Start of processCsmTwin");
334 ATH_MSG_DEBUG(" Number of AmtHit in this Csm " << rdoColl->size());
336 Identifier elementId = id_helper.parentID(rdoColl->identify());
337
338 uint16_t subdetId = rdoColl->SubDetId();
339 uint16_t mrodId = rdoColl->MrodId();
340 uint16_t csmId = rdoColl->CsmId();
341 ATH_MSG_VERBOSE("Identifier = " << m_idHelperSvc->toString(elementId) << " subdetId/ mrodId/ csmId = " << rdoColl->SubDetId()
342 << " / " << rdoColl->MrodId() << " / " << rdoColl->CsmId());
343
344 // for each Csm, loop over AmtHit, converter AmtHit to digit
345 // retrieve/create digit collection, and insert digit into collection
346 std::map<Identifier, std::array<std::unique_ptr<MdtDigit>, 2>> mdtDigitColl{};
347
348 for (const MdtAmtHit* amtHit : *rdoColl) {
349 std::unique_ptr<MdtDigit> newDigit{m_mdtDecoder->getDigit(ctx, *amtHit, subdetId, mrodId, csmId)};
350
351 if (!newDigit) {
352 ATH_MSG_WARNING("Error in MDT RDO decoder for subdetId/mrodId/csmId "
353 << subdetId << "/" << mrodId << "/" << csmId << " amtHit channelId/tdcId =" << amtHit->channelId() << "/"
354 << amtHit->tdcId());
355 continue;
356 }
357 std::array<std::unique_ptr<MdtDigit>, 2> & moveTo = mdtDigitColl[newDigit->identify()];
358 if (!moveTo[0]) {
359 moveTo[0] = std::move(newDigit);
360 } else if (!moveTo[1] && !m_discardSecondaryHitTwin) {
361 moveTo[1] = std::move(newDigit);
362 } else {
363 ATH_MSG_VERBOSE(" TWIN TUBES: found a tertiary hit in a twin tube in one RdoCollection for "
364 << m_idHelperSvc->toString(newDigit->identify()) << " with adc = " << newDigit->adc()
365 << " tdc = " << newDigit->tdc());
366 }
367 } // end for-loop over rdoColl
368
369 auto convertTwins = [this, &cache, &ctx](std::unique_ptr<MdtDigit> digit,
370 std::unique_ptr<MdtDigit> digit2) {
371 if (!digit || digit->isMasked()) { return; }
372
373 MdtPrepDataCollection* driftCircleColl = cache.createCollection(digit->identify());
374
375 if (!digit2 || digit2->isMasked()) {
376 ATH_MSG_VERBOSE("Got single digit " << m_idHelperSvc->toString(digit->identify())<<", tdc: "
377 <<digit->tdc()<<", adc: "<<digit->adc()
378 << ", hash: "<< driftCircleColl->identifyHash());
379
380 const MdtCalibInput mdtCalibIn{*digit, *cache.legacyDetMgr};
381 const MdtCalibOutput mdtCalibOut{m_calibrationTool->calibrate(ctx, mdtCalibIn, false)};
382
384 std::unique_ptr<MdtPrepData> newPrepData = createPrepData(mdtCalibIn, mdtCalibOut);
385 if (!newPrepData) return;
386
387 newPrepData->setHashAndIndex(driftCircleColl->identifyHash(), driftCircleColl->size());
388 driftCircleColl->push_back(std::move(newPrepData));
389 return;
390 }
391 ATH_MSG_VERBOSE("Twin digit calibration "<<m_idHelperSvc->toString(digit->identify())
392 <<", tdc: "<<digit->tdc()<<", adc: "<<digit->adc()<<" -- "
393 <<m_idHelperSvc->toString(digit2->identify())
394 <<", tdc: "<<digit2->tdc()<<", adc: "<<digit2->adc());
395
396 MdtCalibInput mdtCalib1st{*digit, *cache.legacyDetMgr};
397 MdtCalibInput mdtCalib2nd{*digit2, *cache.legacyDetMgr};
398
399 updateClosestApproachTwin(mdtCalib1st);
400 updateClosestApproachTwin(mdtCalib2nd);
401
402 const MdtCalibTwinOutput twinCalib = m_calibrationTool->calibrateTwinTubes(ctx,
403 std::move(mdtCalib1st),
404 std::move(mdtCalib2nd));
405
406 Amg::Vector2D hitPos{twinCalib.primaryDriftR(), twinCalib.locZ()};
407 Amg::MatrixX cov(2, 2);
408 cov(0, 0) = twinCalib.uncertPrimaryR() * twinCalib.uncertPrimaryR();
409 cov(1, 1) = twinCalib.sigmaZ() * twinCalib.sigmaZ();
410 cov(0, 1) = cov(1, 0) = 0;
411
412 const MuonGM::MdtReadoutElement* descriptor = cache.legacyDetMgr->getMdtReadoutElement(digit->identify());
413 auto twin_newPrepData = std::make_unique<MdtTwinPrepData>(twinCalib.primaryID(),
414 std::move(hitPos),
415 std::move(cov),
416 descriptor,
417 twinCalib.primaryTdc(),
418 twinCalib.primaryAdc(),
419 twinCalib.twinTdc(),
420 twinCalib.twinAdc(),
421 twinCalib.primaryStatus());
422
423 ATH_MSG_VERBOSE(" MADE A 2D TWINPREPDATA " << m_idHelperSvc->toString(twinCalib.primaryID()) << " & "
424 << m_idHelperSvc->toString(twinCalib.twinID()) << " "<<twinCalib);
425
426 ATH_MSG_VERBOSE("global pos center tube " << Amg::toString(twin_newPrepData->globalPosition(), 2) << std::endl
427 <<"local pos center tube w/ TWIN INFO "<<Amg::toString(twinCalib.locZ() * Amg::Vector3D::UnitZ(), 2)<<std::endl
428 <<"global pos w/o TWIN INFO "<<Amg::toString(descriptor->tubePos(twinCalib.primaryID())));
429
430 twin_newPrepData->setHashAndIndex(driftCircleColl->identifyHash(), driftCircleColl->size());
431 driftCircleColl->push_back(std::move(twin_newPrepData));
432 };
433
434 // iterate over mdtDigitColl
435 for (auto &[id, digits] : mdtDigitColl) {
436 // get the twin hits from mdtDigitColl
437 const Identifier twinId = cache.twinTubeMap->twinId(id);
439 if (id != twinId) {
440 std::array<std::unique_ptr<MdtDigit>, 2>& twinDigits = mdtDigitColl[twinId];
441 ATH_MSG_VERBOSE("Convert digits: "<<digits[0].get()<<" "<<twinDigits[0].get());
442 convertTwins(std::move(digits[0]), std::move(twinDigits[0]));
443 ATH_MSG_VERBOSE("Convert digits: "<<digits[1].get()<<" "<<twinDigits[1].get());
444 convertTwins(std::move(digits[1]), std::move(twinDigits[1]));
445 } else {
446 convertTwins(std::move(digits[0]), nullptr);
447 convertTwins(std::move(digits[1]), nullptr);
448 }
449 }
450 return StatusCode::SUCCESS;
451 }
MdtDriftCircleStatus primaryStatus() const
double primaryDriftR() const
Identifier twinID() const
Identifier primaryID() const
double uncertPrimaryR() const
Amg::Vector3D tubePos(const Identifier &id) const
Returns the global position of the given tube.
Gaudi::Property< bool > m_discardSecondaryHitTwin
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.

◆ processPRDHashes()

void Muon::MdtRdoToPrepDataToolMT::processPRDHashes ( const EventContext & ctx,
ConvCache & mdtPrepDataContainer,
const std::vector< IdentifierHash > & chamberHashInRobs ) const
protected

Definition at line 146 of file MdtRdoToPrepDataToolMT.cxx.

147 {
148 for (const IdentifierHash& hash : multiLayerHashInRobs) {
149 if (!handlePRDHash(ctx, mdtPrepDataContainer, hash)) { ATH_MSG_DEBUG("Failed to process hash " << hash); }
150 } // ends loop over chamberhash
151 }
bool handlePRDHash(const EventContext &ctx, ConvCache &mdtPrepDataContainer, IdentifierHash rdoHash) const

◆ provideEmptyContainer()

StatusCode Muon::MdtRdoToPrepDataToolMT::provideEmptyContainer ( const EventContext & ctx) const
overridevirtual

Definition at line 142 of file MdtRdoToPrepDataToolMT.cxx.

142 {
143 return setupMdtPrepDataContainer(ctx).isValid ? StatusCode::SUCCESS : StatusCode::FAILURE;
144 }
bool isValid
Flag set to indicate that the complete validation was successful.

◆ setupMdtPrepDataContainer()

MdtRdoToPrepDataToolMT::ConvCache Muon::MdtRdoToPrepDataToolMT::setupMdtPrepDataContainer ( const EventContext & ctx) const
protected

Creates the prep data container to be written.

Definition at line 483 of file MdtRdoToPrepDataToolMT.cxx.

483 {
484
486
487 SG::WriteHandle<MdtPrepDataContainer> handle{m_mdtPrepDataContainerKey, ctx};
488 // Caching of PRD container
489 if (m_prdContainerCacheKey.key().empty()) {
490 // without the cache we just record the container
491 StatusCode status = handle.record(std::make_unique<MdtPrepDataContainer>(m_idHelperSvc->mdtIdHelper().module_hash_max()));
492 if (status.isFailure() || !handle.isValid()) {
493 ATH_MSG_FATAL("Could not record container of MDT PrepData Container at " << m_mdtPrepDataContainerKey.key());
494 return cache;
495 }
496 ATH_MSG_VERBOSE("Created container " << m_mdtPrepDataContainerKey.key());
497 cache.legacyPrd = handle.ptr();
498 } else {
499 // use the cache to get the container
500 SG::UpdateHandle update{m_prdContainerCacheKey, ctx};
501 if (!update.isValid()) {
502 ATH_MSG_FATAL("Invalid UpdateHandle " << m_prdContainerCacheKey.key());
503 return cache;
504 }
505 StatusCode status = handle.record(std::make_unique<MdtPrepDataContainer>(update.ptr()));
506 if (status.isFailure() || !handle.isValid()) {
507 ATH_MSG_FATAL("Could not record container of MDT PrepData Container using cache " << m_prdContainerCacheKey.key() << " - "
509 return cache;
510 }
511 ATH_MSG_VERBOSE("Created container using cache for " << m_prdContainerCacheKey.key());
512 cache.legacyPrd = handle.ptr();
513 }
514 cache.isValid = SG::get(cache.legacyDetMgr, m_muDetMgrKey, ctx).isSuccess() &&
515 SG::get(cache.twinTubeMap, m_twinTubeKey, ctx).isSuccess();
516 return cache;
517 }
#define ATH_MSG_FATAL(x)
virtual void handle(const Incident &inc)
Handle end of run incidents to save the metadata at that point.
::StatusCode StatusCode
StatusCode definition for legacy code.
status
Definition merge.py:16

Member Data Documentation

◆ m_adcCut

Gaudi::Property<int> Muon::MdtRdoToPrepDataToolMT::m_adcCut
protected
Initial value:
{this, "AdcCut", 50,
"Minimal cut on the adc to convert it into a prepdata object"}

member variables for algorithm properties:

Definition at line 116 of file MdtRdoToPrepDataToolMT.h.

116 {this, "AdcCut", 50,
117 "Minimal cut on the adc to convert it into a prepdata object"};

◆ m_BMGid

int Muon::MdtRdoToPrepDataToolMT::m_BMGid {-1}
protected

Definition at line 125 of file MdtRdoToPrepDataToolMT.h.

125{-1};

◆ m_BMGpresent

bool Muon::MdtRdoToPrepDataToolMT::m_BMGpresent {false}
protected

Definition at line 124 of file MdtRdoToPrepDataToolMT.h.

124{false};

◆ m_calibratePrepData

Gaudi::Property<bool> Muon::MdtRdoToPrepDataToolMT::m_calibratePrepData {this, "CalibratePrepData", true}
protected

toggle on/off calibration of MdtPrepData

Definition at line 118 of file MdtRdoToPrepDataToolMT.h.

118{this, "CalibratePrepData", true};

◆ m_calibrationTool

ToolHandle<IMdtCalibrationTool> Muon::MdtRdoToPrepDataToolMT::m_calibrationTool {this, "CalibrationTool", "MdtCalibrationTool"}
protected

MDT calibration service.

Definition at line 107 of file MdtRdoToPrepDataToolMT.h.

107{this, "CalibrationTool", "MdtCalibrationTool"};

◆ m_DeadChannels

std::unordered_set<Identifier> Muon::MdtRdoToPrepDataToolMT::m_DeadChannels {}
protected

Definition at line 134 of file MdtRdoToPrepDataToolMT.h.

134{};

◆ m_decodeData

Gaudi::Property<bool> Muon::MdtRdoToPrepDataToolMT::m_decodeData {this, "DecodeData", true}
protected

toggle on/off the decoding of MDT RDO into MdtPrepData

Definition at line 119 of file MdtRdoToPrepDataToolMT.h.

119{this, "DecodeData", true};

◆ m_discardSecondaryHitTwin

Gaudi::Property<bool> Muon::MdtRdoToPrepDataToolMT::m_discardSecondaryHitTwin {this, "DiscardSecondaryHitTwin", false}
protected

Definition at line 129 of file MdtRdoToPrepDataToolMT.h.

129{this, "DiscardSecondaryHitTwin", false};

◆ m_idHelperSvc

ServiceHandle<Muon::IMuonIdHelperSvc> Muon::MdtRdoToPrepDataToolMT::m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}
protected

Definition at line 104 of file MdtRdoToPrepDataToolMT.h.

104{this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};

◆ m_mdtDecoder

ToolHandle<Muon::IMDT_RDO_Decoder> Muon::MdtRdoToPrepDataToolMT::m_mdtDecoder {this, "Decoder", "Muon::MdtRDO_Decoder/MdtRDO_Decoder"}
protected

Definition at line 122 of file MdtRdoToPrepDataToolMT.h.

122{this, "Decoder", "Muon::MdtRDO_Decoder/MdtRDO_Decoder"};

◆ m_mdtPrepDataContainerKey

SG::WriteHandleKey<Muon::MdtPrepDataContainer> Muon::MdtRdoToPrepDataToolMT::m_mdtPrepDataContainerKey {this, "OutputCollection", "MDT_DriftCircles"}
protected

MdtPrepRawData containers.

Definition at line 110 of file MdtRdoToPrepDataToolMT.h.

110{this, "OutputCollection", "MDT_DriftCircles"};

◆ m_muDetMgrKey

SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> Muon::MdtRdoToPrepDataToolMT::m_muDetMgrKey
protected
Initial value:
{this, "DetectorManagerKey", "MuonDetectorManager",
"Key of input MuonDetectorManager condition data"}

Definition at line 139 of file MdtRdoToPrepDataToolMT.h.

139 {this, "DetectorManagerKey", "MuonDetectorManager",
140 "Key of input MuonDetectorManager condition data"};

◆ m_prdContainerCacheKey

SG::UpdateHandleKey<MdtPrepDataCollection_Cache> Muon::MdtRdoToPrepDataToolMT::m_prdContainerCacheKey
protected
Initial value:
{this, "MdtPrdContainerCacheKey", "",
"Optional external cache for the MDT PRD container"}

This is the key for the cache for the MDT PRD containers, can be empty.

Definition at line 142 of file MdtRdoToPrepDataToolMT.h.

142 {this, "MdtPrdContainerCacheKey", "",
143 "Optional external cache for the MDT PRD container"};

◆ m_rdoContainerKey

SG::ReadHandleKey<MdtCsmContainer> Muon::MdtRdoToPrepDataToolMT::m_rdoContainerKey {this, "RDOContainer", "MDTCSM"}
protected

Definition at line 112 of file MdtRdoToPrepDataToolMT.h.

112{this, "RDOContainer", "MDTCSM"};

◆ m_readKey

SG::ReadCondHandleKey<MuonMDT_CablingMap> Muon::MdtRdoToPrepDataToolMT::m_readKey {this, "ReadKey", "MuonMDT_CablingMap", "Key of MuonMDT_CablingMap"}
protected

Definition at line 137 of file MdtRdoToPrepDataToolMT.h.

137{this, "ReadKey", "MuonMDT_CablingMap", "Key of MuonMDT_CablingMap"};

◆ m_sortPrepData

bool Muon::MdtRdoToPrepDataToolMT::m_sortPrepData = false
protected

Toggle on/off the sorting of the MdtPrepData.

Definition at line 120 of file MdtRdoToPrepDataToolMT.h.

◆ m_twinTubeKey

SG::ReadCondHandleKey<TwinTubeMap> Muon::MdtRdoToPrepDataToolMT::m_twinTubeKey {this, "TwinTubeKey", "MdtTwinTubeMap"}
protected

Definition at line 132 of file MdtRdoToPrepDataToolMT.h.

132{this, "TwinTubeKey", "MdtTwinTubeMap"};

◆ m_useTwin

Gaudi::Property<bool> Muon::MdtRdoToPrepDataToolMT::m_useTwin {this, "UseTwin", true}
protected

Definition at line 128 of file MdtRdoToPrepDataToolMT.h.

128{this, "UseTwin", true};

The documentation for this class was generated from the following files: