ATLAS Offline Software
MdtCalibDbAlgTest.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 "MdtCalibDbAlgTest.h"
6 
7 #include "GaudiKernel/PhysicalConstants.h"
10 #include "GaudiKernel/ITHistSvc.h"
11 #include "TH2D.h"
12 #include "TCanvas.h"
13 
14 using namespace MuonValR4;
15 
16 MdtCalibDbAlgTest::MdtCalibDbAlgTest(const std::string& name, ISvcLocator* pSvcLocator) :
17  AthHistogramAlgorithm(name, pSvcLocator) {}
18 
20  ATH_MSG_VERBOSE("Initializing MdtCalibDbAlgTest");
21  ATH_CHECK(m_MdtKey.initialize());
23  ATH_CHECK(m_calibrationTool.retrieve());
24  ATH_CHECK(m_idHelperSvc.retrieve());
25  ATH_CHECK(m_tree.init(this));
26  ATH_CHECK(book(TH2D("DriftRadiusVsTdc", "DriftRadiusVsTdc", 100, 0., 680., 100, 0., 15.), "MdtCalibDbAlgTest", "MdtCalibDbAlgTest"));
27  ATH_CHECK(book(TH2D("DriftdRdtVsTdc", "DriftdRdtVsTdc", 100, 0., 680., 100, 0., 0.6), "MdtCalibDbAlgTest", "MdtCalibDbAlgTest"));
28  ATH_CHECK(book(TH2D("DriftTimeVsDriftRadius", "DriftTimeVsDriftRadius", 100, 0., 15., 100, 0., 680.), "MdtCalibDbAlgTest", "MdtCalibDbAlgTest"));
29  return StatusCode::SUCCESS;
30 }
31 
33  ATH_MSG_VERBOSE("Finalizing MdtCalibDbAlgTest");
35  return StatusCode::SUCCESS;
36 }
37 
39  // ATH_MSG_ALWAYS("Executing MdtCalibDbAlgTest");
40  const EventContext& ctx = Gaudi::Hive::currentContext();
41  SG::ReadHandle mdtContainer{m_MdtKey};
43  ATH_CHECK(mdtContainer.isPresent());
44  ATH_CHECK(geoCtx.isPresent());
45  constexpr double inversePropSpeed = 1. / Gaudi::Units::c_light;
46  for(const xAOD::MdtDriftCircle* mdt : *mdtContainer) {
47  const MuonGMR4::MdtReadoutElement* mdtRE = mdt->readoutElement();
48  const Amg::Vector3D mdtGlobalTubePos = mdtRE->globalTubePos(*geoCtx, mdt->measurementHash());
49  const float tdcAdj = IMdtCalibrationTool::tdcBinSize * mdt->tdc() - inversePropSpeed * (mdtGlobalTubePos.norm() - 0.5 * mdtRE->activeTubeLength(mdt->measurementHash()));
50  m_out_tdcAdj = tdcAdj;
51  m_out_tdc = mdt->tdc();
52  m_out_driftRadius = mdt->driftRadius();
53  const float driftV = m_calibrationTool->getCalibConstants(ctx, mdt->identify())->rtRelation->rt()->driftVelocity(tdcAdj);
54  std::optional<double> driftTime = m_calibrationTool->getCalibConstants(ctx, mdt->identify())->rtRelation->tr()->driftTime(mdt->driftRadius());
55  const float f_driftTime = static_cast<float>(driftTime.value_or(0.));
56  m_out_driftdRdt = driftV;
57  m_out_identifier = mdt->identify();
58  m_out_globalPos = mdtGlobalTubePos.norm();
59  m_out_globalPosX = mdtGlobalTubePos.x();
60  m_out_globalPosY = mdtGlobalTubePos.y();
61  m_out_globalPosZ = mdtGlobalTubePos.z();
62  m_out_tubeLength = mdtRE->activeTubeLength(mdt->measurementHash());
63  m_out_driftTime = f_driftTime;
64  hist("DriftRadiusVsTdc")->Fill(tdcAdj, mdt->driftRadius());
65  hist("DriftdRdtVsTdc")->Fill(tdcAdj, driftV);
66  hist("DriftTimeVsDriftRadius")->Fill(mdt->driftRadius(), f_driftTime);
67  m_tree.fill(ctx);
68  }
69 
70  return StatusCode::SUCCESS;
71 }
MuonValR4::MdtCalibDbAlgTest::m_out_driftdRdt
MuonVal::ScalarBranch< float > & m_out_driftdRdt
Definition: MdtCalibDbAlgTest.h:46
MuonValR4::MdtCalibDbAlgTest::m_out_tubeLength
MuonVal::ScalarBranch< float > & m_out_tubeLength
Definition: MdtCalibDbAlgTest.h:53
MuonValR4::MdtCalibDbAlgTest::m_out_driftTime
MuonVal::ScalarBranch< float > & m_out_driftTime
Definition: MdtCalibDbAlgTest.h:47
MuonVal::MuonTesterTree::init
StatusCode init(OWNER *instance)
Initialize method.
MuonValR4::MdtCalibDbAlgTest::m_out_identifier
MuonVal::ScalarBranch< Identifier > & m_out_identifier
Definition: MdtCalibDbAlgTest.h:48
AthHistogramming::book
StatusCode book(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.
Definition: AthHistogramming.h:303
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonValR4::MdtCalibDbAlgTest::initialize
virtual StatusCode initialize() override
Definition: MdtCalibDbAlgTest.cxx:19
MuonGMR4::MdtReadoutElement::activeTubeLength
double activeTubeLength(const IdentifierHash &hash) const
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MdtReadoutElement.cxx:173
MuonValR4::MdtCalibDbAlgTest::m_out_tdcAdj
MuonVal::ScalarBranch< float > & m_out_tdcAdj
Definition: MdtCalibDbAlgTest.h:43
MuonValR4::MdtCalibDbAlgTest::m_geoCtxKey
SG::ReadHandleKey< ActsGeometryContext > m_geoCtxKey
Definition: MdtCalibDbAlgTest.h:38
MuonValR4::MdtCalibDbAlgTest::m_out_globalPos
MuonVal::ScalarBranch< float > & m_out_globalPos
Definition: MdtCalibDbAlgTest.h:49
MuonValR4::MdtCalibDbAlgTest::m_MdtKey
SG::ReadHandleKey< xAOD::MdtDriftCircleContainer > m_MdtKey
Definition: MdtCalibDbAlgTest.h:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonValR4::MdtCalibDbAlgTest::m_out_globalPosZ
MuonVal::ScalarBranch< float > & m_out_globalPosZ
Definition: MdtCalibDbAlgTest.h:52
MdtCalibDbAlgTest.h
MuonValR4::MdtCalibDbAlgTest::m_out_tdc
MuonVal::ScalarBranch< float > & m_out_tdc
Definition: MdtCalibDbAlgTest.h:44
TRT::Hit::driftTime
@ driftTime
Definition: HitInfo.h:43
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
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
AthHistogramAlgorithm
Definition: AthHistogramAlgorithm.h:32
MuonValR4::MdtCalibDbAlgTest::m_out_globalPosY
MuonVal::ScalarBranch< float > & m_out_globalPosY
Definition: MdtCalibDbAlgTest.h:51
MuonValR4
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
Definition: IPatternVisualizationTool.h:23
MuonGMR4::MdtReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:22
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MuonValR4::MdtCalibDbAlgTest::m_calibrationTool
ToolHandle< IMdtCalibrationTool > m_calibrationTool
pointer to MdtCalibSvc
Definition: MdtCalibDbAlgTest.h:40
MuonValR4::MdtCalibDbAlgTest::m_tree
MuonVal::MuonTesterTree m_tree
Definition: MdtCalibDbAlgTest.h:41
python.PhysicalConstants.c_light
float c_light
Definition: PhysicalConstants.py:63
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonValR4::MdtCalibDbAlgTest::m_out_driftRadius
MuonVal::ScalarBranch< float > & m_out_driftRadius
Definition: MdtCalibDbAlgTest.h:45
MuonValR4::MdtCalibDbAlgTest::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MdtCalibDbAlgTest.h:41
MdtReadoutElement.h
MuonValR4::MdtCalibDbAlgTest::MdtCalibDbAlgTest
MdtCalibDbAlgTest(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MdtCalibDbAlgTest.cxx:16
MdtFullCalibData.h
MuonValR4::MdtCalibDbAlgTest::finalize
virtual StatusCode finalize() override
Definition: MdtCalibDbAlgTest.cxx:32
MuonValR4::MdtCalibDbAlgTest::execute
virtual StatusCode execute() override
Definition: MdtCalibDbAlgTest.cxx:38
MuonVal::MuonTesterTree::fill
bool fill(const EventContext &ctx)
Fills the tree per call.
Definition: MuonTesterTree.cxx:89
MuonVal::MuonTesterTree::write
StatusCode write()
Finally write the TTree objects.
Definition: MuonTesterTree.cxx:178
MuonGMR4::MdtReadoutElement::globalTubePos
Amg::Vector3D globalTubePos(const ActsGeometryContext &ctx, const Identifier &measId) const
Returns the global position of the tube center.
AthHistogramming::hist
TH1 * hist(const std::string &histName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered histograms of any type.
Definition: AthHistogramming.cxx:198
MuonValR4::MdtCalibDbAlgTest::m_out_globalPosX
MuonVal::ScalarBranch< float > & m_out_globalPosX
Definition: MdtCalibDbAlgTest.h:50
xAOD::MdtDriftCircle_v1
https://gitlab.cern.ch/atlas/athena/-/blob/master/MuonSpectrometer/MuonReconstruction/MuonRecEvent/Mu...
Definition: MdtDriftCircle_v1.h:21
IMdtCalibrationTool::tdcBinSize
static constexpr double tdcBinSize
Conversion to go from tdc counts -> drift Time.
Definition: IMdtCalibrationTool.h:38