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}
89 const EventContext& ctx{Gaudi::Hive::currentContext()};
91 if (!detMgr.isValid()) {
92 ATH_MSG_FATAL("Failed to retrieve MuonDetectorManager "
93 << m_detMgrKey.fullKey());
94 return StatusCode::FAILURE;
95 }
96 for (const Identifier& test_me : m_testStations) {
97 ATH_MSG_VERBOSE("Test retrieval of Mdt detector element "
98 << m_idHelperSvc->toStringDetEl(test_me));
99 const CscReadoutElement* reElement = detMgr->getCscReadoutElement(test_me);
100 if (!reElement) {
101 ATH_MSG_VERBOSE("Detector element is invalid");
102 continue;
103 }
105 if (reElement->identify() != test_me) {
106 ATH_MSG_FATAL("Expected to retrieve "
107 << m_idHelperSvc->toStringDetEl(test_me) << ". But got instead "
108 << m_idHelperSvc->toStringDetEl(reElement->identify()));
109 return StatusCode::FAILURE;
110 }
111 ATH_CHECK(dumpToTree(ctx, reElement));
112 }
113 return StatusCode::SUCCESS;
114}
115StatusCode GeoModelCscTest::dumpToTree(const EventContext& ctx, const CscReadoutElement* readoutEle) {
116 m_stIndex = readoutEle->getStationIndex();
117 m_stEta = readoutEle->getStationEta();
118 m_stPhi = readoutEle->getStationPhi();
119 m_stMultiLayer = readoutEle->ChamberLayer();
120
121 const CscIdHelper& idHelper{m_idHelperSvc->cscIdHelper()};
122
123 const Amg::Transform3D& trans{readoutEle->transform()};
124 m_readoutTransform = trans;
125
126 const MuonGM::MuonStation* station = readoutEle->parentMuonStation();
127 if (station->hasALines()){
128 m_ALineTransS = station->getALine_tras();
129 m_ALineTransT = station->getALine_traz();
130 m_ALineTransZ = station->getALine_trat();
131 m_ALineRotS = station->getALine_rots();
132 m_ALineRotT = station->getALine_rotz();
133 m_ALineRotZ = station->getALine_rott();
134 }
135 for (bool measPhi : {false, true}) {
136 for (int layer = 1 ; layer <= readoutEle->numberOfLayers(measPhi); ++layer){
137 const Identifier id = idHelper.channelID(readoutEle->identify(),readoutEle->ChamberLayer(),layer, measPhi,1);
138 m_layerTrans.push_back(readoutEle->localToGlobalTransf(id));
139 m_layMeasPhi.push_back(measPhi);
140 m_layNumber.push_back(layer);
141 }
142 }
143 return m_tree.fill(ctx) ? StatusCode::SUCCESS : StatusCode::FAILURE;
144}
145
146
147}
#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)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
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() override
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.