ATLAS Offline Software
MDTHitsTestTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "MDTHitsTestTool.h"
6 
7 #include "Identifier/Identifier.h"
8 
10 
13 
16 
18 #include "MuonSimEvent/MDTSimHit.h"
19 
21 #include "CLHEP/Vector/LorentzVector.h"
22 
23 #include "GaudiKernel/NTuple.h"
24 #include "GaudiKernel/SmartDataPtr.h"
25 #include "GaudiKernel/IDataProviderSvc.h"
26 #include "GaudiKernel/ITHistSvc.h"
27 #include "GaudiKernel/INTupleSvc.h"
28 
29 #include "TH2D.h"
30 #include "TTree.h"
31 #include "TROOT.h"
32 #include "TFile.h"
33 #include "TF1.h"
34 #include "TH1F.h"
35 
36 using namespace MuonGM;
37 
39 {
40  const MdtHitIdHelper* mdthelper = MdtHitIdHelper::GetHelper(m_pMdtIdHelper->tubeMax());
41  std::string mdt_stname = mdthelper->GetStationName(mdthit);
42  int mdt_steta = mdthelper->GetZSector(mdthit);
43  int mdt_stphi = mdthelper->GetPhiSector(mdthit);
44  int mdt_ml = mdthelper->GetMultiLayer(mdthit);
45  int mdt_tl = mdthelper->GetLayer(mdthit);
46  int mdt_tube = mdthelper->GetTube(mdthit);
47 
48  // Create the offline identifiers, fill them with hit info. Ready to be
49  // accessed and retrieve info. Currently not used in this code except
50  // for some checks.
51  Identifier offid = m_pMdtIdHelper->channelID(mdt_stname, mdt_steta, mdt_stphi,mdt_ml,mdt_tl,mdt_tube);
52  if (offid == 0){
53  ATH_MSG_FATAL("MDT: Cannot build a valid Identifier; skip ");
54  }
55 
56  ATH_MSG_VERBOSE(" MDT: Offline Id "<<m_pMdtIdHelper->show_to_string(offid));
57  return offid;
58 }
59 
61  const MuonGM::MdtReadoutElement* descriptor = m_pMuonMgr->getMdtReadoutElement(offid);
62  if (descriptor == NULL) {
63  ATH_MSG_FATAL("MDT readout element not found for Id = " << m_pMdtIdHelper->show_to_string(offid));
64  return StatusCode::FAILURE;
65  }
66 
67  // Testing Sim to Offline ID conversion
68  Amg::Vector3D mdt_gPos = descriptor->tubePos(offid);
69  // double mdt_tube_pos = sqrt(mdt_gPos.perp()*mdt_gPos.perp()+mdt_gPos.z()*mdt_gPos.z());
70  double mdt_tube_phi = mdt_gPos.phi();
71  if (mdt_tube_phi < 0.) mdt_tube_phi += 2.*M_PI;
72  // double mdt_tube_perp = mdt_gPos.perp();
73  // double mdt_tube_z = mdt_gPos.z();
74  // double mdt_tube_cot = 1./tan(mdt_gPos.theta());
75  //Amg::Transform3D xf = descriptor->getMaterialGeom()->getAbsoluteTransform(); //FIXME in the future??
76  //*AS* Amg::Vector3D xU = xf*Amg::Vector3D((*i_hit).localPosition().x(),-(*i_hit).localPosition().z(), (*i_hit).localPosition().y());
77  //*AS*Amg::Vector3D gx = mdt_gPos + xU;
78 
79  return StatusCode::SUCCESS;
80 }
81 
83  CHECK(executeCheckEventInfo());
84 
85  // MuonSpectrometer
86  // Get the generic MuonSpectrometer (MDT,RPC,CSC,TGC) histograms
87  // Short description:
88  // MuonSpectrometer cross section
89  // MuonSpectrometer longitudinal
90  // Number of events processed from truth
91  // Event specific run number
92  // Eta, Theta, Phi, z residual (...), phi residual (...) of hits in MuonSpectrometer
93 
94  // MDT
95  // Get the MDT histograms
96  // Short description:
97  // MuonSpectrometer MDT cross section (affected by m_BarrelEtaCut)
98  // MuonSpectrometer MDT longitudinal
99  // Eta, Theta, Phi, z residual (...), phi residual (...) of hits in MDTs
100 
101 
102  if (m_DoMDTTest) {
103  const MDTSimHitCollection* p_collection = nullptr;
104  if (evtStore()->retrieve(p_collection,"MDT_Hits") == StatusCode::SUCCESS) {
105  for (const MDTSimHit& hit : *p_collection) {
106  // Check the Hits identifiers, access the functions that give:
107  // Station name, station eta, station phi, multilayer ID, layer ID, tube ID.
108  HitID mdthit= (hit).MDTid();
109  Identifier offid= getIdentifier(mdthit);
110  CHECK(checkIdentifier(offid));
111 
112 
113 
114  // Check Hits
115  // For every hit within the event, get the global position Amg::Vector3D u and then retrieve all releveant info
116  // either from the Amg::Vector3D or from the MC vector (direction)
117  GeoMDTHit ghit(hit);
118  if (!ghit) continue;
120  CHECK(executeFillHistos(u));
121  }
122  }
123  }
124 
125  return StatusCode::SUCCESS;
126 }
127 
128 
131  // CHECK(detStore()->retrieve(m_pMuonMgr));
132  m_pMdtIdHelper = m_pMuonMgr->mdtIdHelper();
133  return StatusCode::SUCCESS;
134 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
MdtHitIdHelper::GetMultiLayer
int GetMultiLayer(const int &hid) const
Definition: MdtHitIdHelper.cxx:79
MdtReadoutElement.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MuonGM
Ensure that the Athena extensions are properly loaded.
Definition: GeoMuonHits.h:27
MdtHitIdHelper
Definition: MdtHitIdHelper.h:13
GeoMDTHit
Definition: GeoMuonHits.h:64
MDTSimHit
Definition: MDTSimHit.h:21
AtlasHitsVector
Definition: AtlasHitsVector.h:33
mdthit
Definition: MuonFeatureDetails_p2.h:26
M_PI
#define M_PI
Definition: ActiveFraction.h:11
GeoMuonHits.h
MDTHitsTestTool.h
MdtHitIdHelper::GetZSector
int GetZSector(const int &hid) const
Definition: MdtHitIdHelper.cxx:73
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MdtHitIdHelper::GetHelper
static const MdtHitIdHelper * GetHelper(unsigned int nTubes=78)
Definition: MdtHitIdHelper.cxx:24
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
MDTHitsTestTool::getIdentifier
Identifier getIdentifier(HitID cschit)
Definition: MDTHitsTestTool.cxx:38
MdtHitIdHelper::GetPhiSector
int GetPhiSector(const int &hid) const
Definition: MdtHitIdHelper.cxx:68
MdtHitIdHelper::GetStationName
std::string GetStationName(const int &hid) const
Definition: MdtHitIdHelper.cxx:57
MDTSimHit.h
MuonGM::MdtReadoutElement
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MdtReadoutElement.h:50
McEventCollection.h
MDTHitsTestTool::processEvent
StatusCode processEvent()
Definition: MDTHitsTestTool.cxx:82
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MdtIdHelper.h
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
MdtHitIdHelper::GetLayer
int GetLayer(const int &hid) const
Definition: MdtHitIdHelper.cxx:84
MDTSimHitCollection.h
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonDetectorManager.h
MuonGM::MdtReadoutElement::tubePos
Amg::Vector3D tubePos(const Identifier &id) const
Returns the global position of the given tube.
MuonHitTestToolBase::initialize
virtual StatusCode initialize() override
Definition: MuonHitTestToolBase.cxx:111
MdtHitIdHelper.h
MdtHitIdHelper::GetTube
int GetTube(const int &hid) const
Definition: MdtHitIdHelper.cxx:89
GeoMDTHit::getGlobalPosition
Amg::Vector3D getGlobalPosition() const
HitID
int HitID
Definition: GenericMuonSimHit.h:13
MDTHitsTestTool::initialize
StatusCode initialize()
Definition: MDTHitsTestTool.cxx:129
MDTHitsTestTool::checkIdentifier
StatusCode checkIdentifier(Identifier offid)
Definition: MDTHitsTestTool.cxx:60