ATLAS Offline Software
Loading...
Searching...
No Matches
GeoModelCscTest.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4#include "GeoModelCscTest.h"
5
6#include <fstream>
7#include <iostream>
8
13
14
15namespace MuonGM {
16
18 ATH_CHECK(m_tree.write());
19 return StatusCode::SUCCESS;
20}
22 ATH_CHECK(m_detMgrKey.initialize());
23 ATH_CHECK(m_idHelperSvc.retrieve());
24 ATH_CHECK(m_tree.init(this));
25
26 const CscIdHelper& idHelper{m_idHelperSvc->cscIdHelper()};
27 auto translateTokenList = [this, &idHelper](const std::vector<std::string>& chNames){
28
29 std::set<Identifier> transcriptedIds{};
30 for (const std::string& token : chNames) {
31 if (token.size() != 6) {
32 ATH_MSG_WARNING("Wrong format given for "<<token<<". Expecting 6 characters");
33 continue;
34 }
36 const std::string statName = token.substr(0, 3);
37 const unsigned statEta = std::atoi(token.substr(3, 1).c_str()) * (token[4] == 'A' ? 1 : -1);
38 const unsigned statPhi = std::atoi(token.substr(5, 1).c_str());
39 bool isValid{false};
40 const Identifier eleId = idHelper.elementID(statName, statEta, statPhi, isValid);
41 if (!isValid) {
42 ATH_MSG_WARNING("Failed to deduce a station name for " << token);
43 continue;
44 }
45 transcriptedIds.insert(eleId);
46 const Identifier secMlId = idHelper.channelID(eleId,2, 1, 0, 1, isValid);
47 if (isValid){
48 transcriptedIds.insert(m_idHelperSvc->detElId(secMlId));
49 }
50 }
51 return transcriptedIds;
52 };
53
54 std::vector <std::string>& selectedSt = m_selectStat.value();
55 const std::vector <std::string>& excludedSt = m_excludeStat.value();
56 selectedSt.erase(std::remove_if(selectedSt.begin(), selectedSt.end(),
57 [&excludedSt](const std::string& token){
58 return std::ranges::find(excludedSt, token) != excludedSt.end();
59 }), selectedSt.end());
60
61 if (selectedSt.size()) {
62 m_testStations = translateTokenList(selectedSt);
63 std::stringstream sstr{};
64 for (const Identifier& id : m_testStations) {
65 sstr<<" *** "<<m_idHelperSvc->toString(id)<<std::endl;
66 }
67 ATH_MSG_INFO("Test only the following stations "<<std::endl<<sstr.str());
68 } else {
69 const std::set<Identifier> excluded = translateTokenList(excludedSt);
71 for(auto itr = idHelper.detectorElement_begin();
72 itr!= idHelper.detectorElement_end();++itr){
73 if (!excluded.count(*itr)) {
74 m_testStations.insert(*itr);
75 }
76 }
78 if (!excluded.empty()) {
79 std::stringstream excluded_report{};
80 for (const Identifier& id : excluded){
81 excluded_report << " *** " << m_idHelperSvc->toStringDetEl(id) << std::endl;
82 }
83 ATH_MSG_INFO("Test all station except the following excluded ones " << std::endl << excluded_report.str());
84 }
85 }
86 return StatusCode::SUCCESS;
87}
88StatusCode GeoModelCscTest::execute(const EventContext& ctx) {
90 if (!detMgr.isValid()) {
91 ATH_MSG_FATAL("Failed to retrieve MuonDetectorManager "
92 << m_detMgrKey.fullKey());
93 return StatusCode::FAILURE;
94 }
95 for (const Identifier& test_me : m_testStations) {
96 ATH_MSG_VERBOSE("Test retrieval of Mdt detector element "
97 << m_idHelperSvc->toStringDetEl(test_me));
98 const CscReadoutElement* reElement = detMgr->getCscReadoutElement(test_me);
99 if (!reElement) {
100 ATH_MSG_VERBOSE("Detector element is invalid");
101 continue;
102 }
104 if (reElement->identify() != test_me) {
105 ATH_MSG_FATAL("Expected to retrieve "
106 << m_idHelperSvc->toStringDetEl(test_me) << ". But got instead "
107 << m_idHelperSvc->toStringDetEl(reElement->identify()));
108 return StatusCode::FAILURE;
109 }
110 ATH_CHECK(dumpToTree(ctx, reElement));
111 }
112 return StatusCode::SUCCESS;
113}
114StatusCode GeoModelCscTest::dumpToTree(const EventContext& ctx, const CscReadoutElement* readoutEle) {
115 m_stIndex = readoutEle->getStationIndex();
116 m_stEta = readoutEle->getStationEta();
117 m_stPhi = readoutEle->getStationPhi();
118 m_stMultiLayer = readoutEle->ChamberLayer();
119
120 const CscIdHelper& idHelper{m_idHelperSvc->cscIdHelper()};
121
122 const Amg::Transform3D& trans{readoutEle->transform()};
123 m_readoutTransform = trans;
124
125 const MuonGM::MuonStation* station = readoutEle->parentMuonStation();
126 if (station->hasALines()){
127 m_ALineTransS = station->getALine_tras();
128 m_ALineTransT = station->getALine_traz();
129 m_ALineTransZ = station->getALine_trat();
130 m_ALineRotS = station->getALine_rots();
131 m_ALineRotT = station->getALine_rotz();
132 m_ALineRotZ = station->getALine_rott();
133 }
134 for (bool measPhi : {false, true}) {
135 for (int layer = 1 ; layer <= readoutEle->numberOfLayers(measPhi); ++layer){
136 const Identifier id = idHelper.channelID(readoutEle->identify(),readoutEle->ChamberLayer(),layer, measPhi,1);
137 m_layerTrans.push_back(readoutEle->localToGlobalTransf(id));
138 m_layMeasPhi.push_back(measPhi);
139 m_layNumber.push_back(layer);
140 }
141 }
142 return m_tree.fill(ctx) ? StatusCode::SUCCESS : StatusCode::FAILURE;
143}
144
145
146}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Identifier channelID(int stationName, int stationEta, int stationPhi, int chamberLayer, int wireLayer, int measuresPhi, int strip) const
Identifier elementID(int stationName, int stationEta, int stationPhi) const
virtual int numberOfLayers(bool) const override final
number of layers in phi/eta projection
Amg::Transform3D localToGlobalTransf(const Identifier &id) const
MuonVal::CoordSystemsBranch m_layerTrans
MuonVal::ScalarBranch< float > & m_ALineTransT
StatusCode dumpToTree(const EventContext &ctx, const CscReadoutElement *readoutEle)
MuonVal::VectorBranch< bool > & m_layMeasPhi
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_detMgrKey
MuonDetectorManager from the conditions store.
MuonVal::ScalarBranch< float > & m_ALineRotZ
MuonVal::ScalarBranch< short > & m_stEta
MuonVal::ScalarBranch< float > & m_ALineRotT
StatusCode finalize() override
Gaudi::Property< std::vector< std::string > > m_excludeStat
StatusCode initialize() override
MuonVal::ScalarBranch< float > & m_ALineTransS
Alignment parameters.
MuonVal::ScalarBranch< float > & m_ALineTransZ
Gaudi::Property< std::vector< std::string > > m_selectStat
String should be formated like <stationName><stationEta><A/C><stationPhi>.
MuonVal::ScalarBranch< float > & m_ALineRotS
MuonVal::ScalarBranch< short > & m_stMultiLayer
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
std::set< Identifier > m_testStations
Set of stations to be tested.
MuonVal::CoordTransformBranch m_readoutTransform
Transformation of the readout element (Translation, ColX, ColY, ColZ).
MuonVal::ScalarBranch< unsigned short > & m_stIndex
Identifier of the readout element.
MuonVal::MuonTesterTree m_tree
MuonVal::VectorBranch< uint8_t > & m_layNumber
MuonVal::ScalarBranch< short > & m_stPhi
StatusCode execute(const EventContext &ctx) override
Execute method.
virtual const Amg::Transform3D & transform() const override
Return local to global transform.
Identifier identify() const override final
Returns the ATLAS Identifier of the MuonReadOutElement.
double getALine_trat() const
double getALine_rott() const
double getALine_rots() const
bool hasALines() const
double getALine_tras() const
double getALine_rotz() const
double getALine_traz() const
const_id_iterator detectorElement_begin() const
Iterators over full set of ids.
const_id_iterator detectorElement_end() const
Eigen::Affine3d Transform3D
Ensure that the Athena extensions are properly loaded.
Definition GeoMuonHits.h:27
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.