ATLAS Offline Software
Loading...
Searching...
No Matches
StgcStripCalculator.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 <list>
6#include <iostream>
7#include <memory>
8#include <nlohmann/json.hpp>
9
14
15using namespace NswAsBuilt;
16
18 const nlohmann::json& json;
19 json_t(const nlohmann::json& j) : json(j) {}
20};
21
23 int ipcb = 9; // since sTGC strip boards are identical
24 pcbIdentifier_t pcb_id { strip_id.quadruplet, strip_id.ilayer, ipcb };
25 auto it = m_pcbMap.find(pcb_id);
26
27 if (it == m_pcbMap.end()) {
28 return {};
29 }
30
31 auto strip = it->second.getStgcStrip(iclass, strip_id.istrip);
32 return { IsValid::VALID, strip.center, strip.left, strip.right };
33}
35 int ipcb = 9; // since sTGC strip boards are identical
36 pcbIdentifier_t pcb_id { strip_id.quadruplet, strip_id.ilayer, ipcb };
37 auto it = m_pcbMap.find(pcb_id);
38
39 if (it == m_pcbMap.end()) {
40 return {};
41 }
42
43 return { IsValid::VALID, it->second.getPositionAlongStgcStrip(iclass, strip_id.istrip, sx, sy) };
44}
45
46void StgcStripCalculator::parseJSON(const std::string& in) {
47 try {
48 using json = nlohmann::json;
49 json jroot = json::parse(in);
50 for (const json& jmodule : jroot.at("elementarray")) {
51 parseRootElement(jmodule);
52 }
53 } catch (const std::exception& e) {
54 throw std::runtime_error(e.what());
55 }
56}
57
58//
59// Follows: private methods for parsing the JSON CLOB
60//
61std::unique_ptr<Element> StgcStripCalculator::buildElement(json_t j) const {
62 // Build the appropriate deformation model
63 std::unique_ptr<ElementModel> deformation_model;
64 std::string model = j.json.at("model");
65 if (model == "nodefo") {
66 deformation_model = std::make_unique<ElementModelRigid>();
67 }
68 else if (model == "stgc") {
69 double lenX, lenY;
70 Amg::Vector3D defo0;
71 const auto& jc = j.json.at("model_constant_pars");
72 jc.at("len_x").get_to(lenX);
73 jc.at("len_y").get_to(lenY);
74 jc.at("defo0_x").get_to(defo0[0]);
75 jc.at("defo0_y").get_to(defo0[1]);
76 jc.at("defo0_z").get_to(defo0[2]);
77 deformation_model = std::make_unique<ElementModelSTGC>(lenX, lenY, defo0);
78 }
79 else {
80 throw std::runtime_error("Unknown model: "+model);
81 }
82
83 // Build the element
84 std::unique_ptr<Element> el = std::make_unique<Element>(std::move(deformation_model));
85
86 // Set the model parameters
87 std::map<std::string, double> correctionPars, nominalPars;
88 j.json.at("pars_corrected").get_to(correctionPars);
89 j.json.at("pars_nominal").get_to(nominalPars);
90 el->setParametersFromMap(ParameterClass::CORRECTION, correctionPars);
91 el->setParametersFromMap(ParameterClass::NOMINAL, nominalPars);
92
93 return el;
94}
95
98 std::string stationName;
99 j.json.at("station_name").get_to(stationName);
100 if (stationName == "STS") {
102 } else if (stationName == "STL") {
104 } else {
105 throw std::runtime_error("StgcStripCalculator: stationName not implemented: "+stationName);
106 }
107 j.json.at("station_eta").get_to(ret.stationEta);
108 j.json.at("station_phi").get_to(ret.stationPhi);
109 j.json.at("multilayer").get_to(ret.multilayer);
110 return ret;
111}
113 pcbIdentifier_t ret;
114 ret.quadruplet = quad_id;
115 j.json.at("ilayer").get_to(ret.ilayer);
116 j.json.at("ipcb").get_to(ret.ipcb);
117 return ret;
118}
120 auto getPoint = [](const nlohmann::json& j) {
121 double xpos, ypos, xpitch, ypitch;
122 j.at("pos").at("x").get_to(xpos);
123 j.at("pos").at("y").get_to(ypos);
124 j.at("pitch").at("x").get_to(xpitch);
125 j.at("pitch").at("y").get_to(ypitch);
126 return CathodeBoardElement::stgcStripPoint_t{{xpos,ypos,0.0},{xpitch,ypitch,0.0}};
127 };
129 j.json.at("nstrip").get_to(ret.lastStripNumber);
130 ret.fCenterPoint = getPoint(j.json.at("first_strip_center"));
131 ret.fLeftPoint = getPoint(j.json.at("first_strip_left"));
132 ret.fRightPoint = getPoint(j.json.at("first_strip_right"));
133 ret.sCenterPoint = getPoint(j.json.at("second_strip_center"));
134 ret.sLeftPoint = getPoint(j.json.at("second_strip_left"));
135 ret.sRightPoint = getPoint(j.json.at("second_strip_right"));
136 ret.lCenterPoint = getPoint(j.json.at("last_strip_center"));
137 ret.lLeftPoint = getPoint(j.json.at("last_strip_left"));
138 ret.lRightPoint = getPoint(j.json.at("last_strip_right"));
139 return ret;
140}
141
143 if (j.json.contains("strip_configuration") && j.json.contains("identifier")) {
144 pcbIdentifier_t pcb_id = getPcbIdentifier(quad_id, j.json.at("identifier"));
146 m_pcbMap.insert(std::make_pair(pcb_id, CathodeBoardElement(config, element)));
147 }
148}
149
151 using json = nlohmann::json;
152 struct tree_t {
153 json::const_iterator it;
154 json::const_iterator end;
155 };
156
157 if (!j.json.contains("identifier")) {
158 // No athena identifier given for this element, skip
159 return;
160 }
161
162 std::unique_ptr<Element> root = buildElement(j);
163 quadrupletIdentifier_t quad_id = getQuadrupletIdentifier(j.json.at("identifier"));
164 Element* mom = root.get();
165 const std::string KEY = "zdaughters";
166
167 // Depth-traversal of json tree, collect elements along the way
168 std::list<tree_t> jtree;
169 jtree.push_back({j.json.at(KEY).begin(), j.json.at(KEY).end()});
170 while (!jtree.empty()) {
171 auto& it = jtree.back().it;
172 if (it != jtree.back().end) {
173 std::unique_ptr<Element> daughter = buildElement(*it);
174 collectStrip(quad_id, *daughter, *it);
175 Element* daugref = mom->addDaughter(std::move(daughter));
176 if (it->contains(KEY)) {
177 jtree.push_back({it->at(KEY).begin(), it->at(KEY).end()});
178 mom = daugref;
179 }
180 ++it;
181 } else {
182 jtree.pop_back();
183 mom = mom->mother();
184 }
185 }
186
187 m_rootElements.push_back(std::move(root));
188}
nlohmann::json json
Helper class saving all the needed information to compute strips for a particular cathode board.
Element: a node in a hierarchy of alignment frames.
Definition Element.h:52
CathodeBoardElement::stgcStripConfiguration_t getStgcStripConfiguration(json_t j) const
void parseJSON(const std::string &in)
Parses a std::istream with JSON-formatted configuration of the as-built parameters.
void collectStrip(quadrupletIdentifier_t quad_id, Element &element, json_t j)
quadrupletIdentifier_t getQuadrupletIdentifier(json_t j) const
Element::ParameterClass ParameterClass
position_t getPositionAlongStgcStrip(ParameterClass iclass, stripIdentifier_t strip_id, double sx, double sy) const
Returns a the position of a point along the strip, parameterized by s, in the coordinate system of th...
std::unordered_map< pcbIdentifier_t, CathodeBoardElement > m_pcbMap
std::vector< std::unique_ptr< Element > > m_rootElements
pcbIdentifier_t getPcbIdentifier(quadrupletIdentifier_t quad_id, json_t j) const
stgcStrip_t getStgcStrip(ParameterClass iclass, stripIdentifier_t strip_id) const
Computes 3 reference points along a strip identified by strip_id, in coordinate system of quadruplet.
std::unique_ptr< Element > buildElement(json_t j) const
Eigen::Matrix< double, 3, 1 > Vector3D
The return object for querying strip positions with the method getPositionAlongStrip: a single point ...
The return object for querying strip positions: three points along the strip are provided,...