ATLAS Offline Software
Loading...
Searching...
No Matches
MdtCalibDbAlgTest.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 "MdtCalibDbAlgTest.h"
6
7#include "GaudiKernel/PhysicalConstants.h"
10#include "GaudiKernel/ITHistSvc.h"
11#include "TH2D.h"
12#include "TCanvas.h"
13
14using namespace MuonValR4;
15
17 ATH_MSG_VERBOSE("Initializing MdtCalibDbAlgTest");
18 ATH_CHECK(m_MdtKey.initialize());
19 ATH_CHECK(m_geoCtxKey.initialize());
20 ATH_CHECK(m_calibrationTool.retrieve());
21 ATH_CHECK(m_idHelperSvc.retrieve());
22 ATH_CHECK(m_tree.init(this));
23 ATH_CHECK(book(TH2D("DriftRadiusVsTime", "DriftRadiusVsTime", 680, 0., 680., 100, 0., 15.), "MdtCalibDbAlgTest", "MdtCalibDbAlgTest"));
24 ATH_CHECK(book(TH2D("DriftVelocityVsTime", "DriftVelocityVsTime", 680, 0., 680., 140, -0.1, 0.6), "MdtCalibDbAlgTest", "MdtCalibDbAlgTest"));
25 ATH_CHECK(book(TH2D("DriftTimeVsRadius", "DriftTimeVsRadius", 100, 0., 15., 680, 0., 680.), "MdtCalibDbAlgTest", "MdtCalibDbAlgTest"));
26 ATH_CHECK(book(TH2D("DriftTimeClosure", "DriftTimeClosure", 680, 0., 680., 680, 0., 680.), "MdtCalibDbAlgTest", "MdtCalibDbAlgTest"));
27
28 return StatusCode::SUCCESS;
29}
30
32 ATH_MSG_VERBOSE("Finalizing MdtCalibDbAlgTest");
33 ATH_CHECK(m_tree.write());
34 return StatusCode::SUCCESS;
35}
36
38 const EventContext& ctx = Gaudi::Hive::currentContext();
39 SG::ReadHandle mdtContainer{m_MdtKey, ctx};
40 SG::ReadHandle geoCtx{m_geoCtxKey, ctx};
41 ATH_CHECK(mdtContainer.isPresent());
42 ATH_CHECK(geoCtx.isPresent());
43 constexpr double inversePropSpeed = 1. / Gaudi::Units::c_light;
44 for(const xAOD::MdtDriftCircle* mdt : *mdtContainer) {
45 if (mdt->status() != Muon::MdtDriftCircleStatus::MdtStatusDriftTime){
46 continue;
47 }
48 const MuonGMR4::MdtReadoutElement* mdtRE = mdt->readoutElement();
49 const Amg::Vector3D mdtGlobalTubePos = mdtRE->globalTubePos(*geoCtx, mdt->measurementHash());
50 const float tdcAdj = IMdtCalibrationTool::tdcBinSize * mdt->tdc() - inversePropSpeed * (mdtGlobalTubePos.norm() - 0.5 * mdtRE->activeTubeLength(mdt->measurementHash()));
51 m_out_tdcAdj = tdcAdj;
52 m_out_tdc = mdt->tdc();
53 m_out_driftRadius = mdt->driftRadius();
54 const float driftV = m_calibrationTool->getCalibConstants(ctx, mdt->identify())->rtRelation->rt()->driftVelocity(tdcAdj);
55 std::optional<double> driftTime = m_calibrationTool->getCalibConstants(ctx, mdt->identify())->rtRelation->tr()->driftTime(mdt->driftRadius());
56 const float f_driftTime = static_cast<float>(driftTime.value_or(0.));
57 m_out_driftVelocity = driftV;
58
59 m_out_stIndex = mdtRE->stationName();
60 m_out_stEta = mdtRE->stationEta();
61 m_out_stPhi = mdtRE->stationPhi();
62 m_out_ml = mdtRE->multilayer();
63 m_out_tl = mdt->tubeLayer();
64 m_out_tube = mdt->driftTube();
65 m_out_globalPos = mdtGlobalTubePos.norm();
66 m_out_globalPosX = mdtGlobalTubePos.x();
67 m_out_globalPosY = mdtGlobalTubePos.y();
68 m_out_globalPosZ = mdtGlobalTubePos.z();
69 m_out_tubeLength = mdtRE->activeTubeLength(mdt->measurementHash());
70 m_out_driftTime = f_driftTime;
71 hist("DriftRadiusVsTime")->Fill(tdcAdj, mdt->driftRadius());
72 hist("DriftVelocityVsTime")->Fill(tdcAdj, driftV);
73 hist("DriftTimeVsRadius")->Fill(mdt->driftRadius(), f_driftTime);
74 hist("DriftTimeClosure")->Fill(tdcAdj, f_driftTime);
75 m_tree.fill(ctx);
76 }
77
78 return StatusCode::SUCCESS;
79}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
StatusCode book(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.
TH1 * hist(const std::string &histName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered histograms of any type.
static constexpr double tdcBinSize
Conversion to go from tdc counts -> drift Time.
Amg::Vector3D globalTubePos(const ActsTrk::GeometryContext &ctx, const Identifier &measId) const
Returns the global position of the tube center.
unsigned int multilayer() const
Returns the multi layer of the MdtReadoutElement.
int stationEta() const
Returns the stationEta (positive A site, negative O site)
int stationName() const
Returns the stationName (BIS, BOS, etc) encoded into the integer.
int stationPhi() const
Returns the stationPhi (1-8) -> sector (2*phi - (isSmall))
MuonVal::ScalarBranch< float > & m_out_driftTime
MuonVal::ScalarBranch< float > & m_out_globalPosZ
SG::ReadHandleKey< xAOD::MdtDriftCircleContainer > m_MdtKey
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
MuonVal::ScalarBranch< float > & m_out_globalPos
virtual StatusCode execute() override
MuonVal::ScalarBranch< float > & m_out_tubeLength
MuonVal::ScalarBranch< float > & m_out_driftRadius
MuonVal::ScalarBranch< uint8_t > & m_out_ml
MuonVal::ScalarBranch< uint8_t > & m_out_stPhi
virtual StatusCode initialize() override
MuonVal::ScalarBranch< float > & m_out_driftVelocity
MuonVal::ScalarBranch< int16_t > & m_out_stEta
virtual StatusCode finalize() override
MuonVal::ScalarBranch< uint8_t > & m_out_tube
MuonVal::ScalarBranch< uint8_t > & m_out_stIndex
MuonVal::ScalarBranch< float > & m_out_tdc
MuonVal::ScalarBranch< float > & m_out_globalPosY
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
ToolHandle< IMdtCalibrationTool > m_calibrationTool
pointer to MdtCalibSvc
MuonVal::ScalarBranch< float > & m_out_globalPosX
MuonVal::MuonTesterTree m_tree
MuonVal::ScalarBranch< float > & m_out_tdcAdj
MuonVal::ScalarBranch< uint8_t > & m_out_tl
bool isPresent() const
Is the referenced object present in SG?
Eigen::Matrix< double, 3, 1 > Vector3D
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
MdtDriftCircle_v1 MdtDriftCircle