ATLAS Offline Software
Loading...
Searching...
No Matches
StripCalculator.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
15
16using namespace NswAsBuilt;
17
19 const nlohmann::json& json;
20 json_t(const nlohmann::json& j) : json(j) {}
21};
22
23//===============================================================================
25 int ipcb = (strip_id.istrip-1)/1024 + 1; // MM 1024 channels per PCB, hard-coded convention
26 if (std::abs(strip_id.quadruplet.stationEta)==2) {
27 ipcb += 5;
28 }
29 pcbIdentifier_t pcb_id { strip_id.quadruplet, strip_id.ilayer, ipcb };
30 auto it = m_pcbMap.find(pcb_id);
31
32 if (it == m_pcbMap.end()) {
33 return {};
34 }
35
36 auto strip = it->second.getStrip(iclass, strip_id.istrip);
37 return { IsValid::VALID, strip.center, strip.left, strip.right };
38}
39
40
41//===============================================================================
43 int ipcb = (strip_id.istrip-1)/1024 + 1; // MM 1024 channels per PCB, hard-coded convention
44 if (std::abs(strip_id.quadruplet.stationEta)==2) {
45 ipcb += 5;
46 }
47 pcbIdentifier_t pcb_id { strip_id.quadruplet, strip_id.ilayer, ipcb };
48 auto it = m_pcbMap.find(pcb_id);
49
50 if (it == m_pcbMap.end()) {
51 return {};
52 }
53
54 return { IsValid::VALID, it->second.getPositionAlongStrip(iclass, strip_id.istrip, sx, sy) };
55}
56
57
58//===============================================================================
59void StripCalculator::parseJSON(const std::string& in) {
60 try {
61 using json = nlohmann::json;
62 json jroot = json::parse(in);
63 for (const json& jmodule : jroot.at("elementarray")) {
64 parseRootElement(jmodule);
65 }
66 } catch (std::exception& e) {
67 throw std::runtime_error(e.what());
68 }
69}
70
71
72
73//===============================================================================
74// Follows: private methods for parsing the JSON CLOB
75std::unique_ptr<Element> StripCalculator::buildElement(json_t j) const {
76 // Build the appropriate deformation model
77 std::unique_ptr<ElementModel> deformation_model;
78 std::string model = j.json.at("model");
79 if (model == "nodefo") {
80 deformation_model = std::make_unique<ElementModelRigid>();
81 } else if (model == "scalesag") {
82 double lenX, lenY;
83 Amg::Vector3D defo0;
84 const auto& jc = j.json.at("model_constant_pars");
85 jc.at("len_x").get_to(lenX);
86 jc.at("len_y").get_to(lenY);
87 jc.at("defo0_x").get_to(defo0[0]);
88 jc.at("defo0_y").get_to(defo0[1]);
89 jc.at("defo0_z").get_to(defo0[2]);
90 deformation_model = std::make_unique<ElementModelScaleSag>(lenX, lenY, defo0);
91 } else {
92 throw std::runtime_error("Unknown model: "+model);
93 }
94
95 // Build the element
96 std::unique_ptr<Element> el = std::make_unique<Element>(std::move(deformation_model));
97 el->setAsapId(j.json.at("id_asap"));
98
99 // Set the model parameters
100 std::map<std::string, double> correctionPars, nominalPars;
101 j.json.at("pars_correction").get_to(correctionPars);
102 j.json.at("pars_nominal").get_to(nominalPars);
103 el->setParametersFromMap(ParameterClass::CORRECTION, correctionPars);
104 el->setParametersFromMap(ParameterClass::NOMINAL, nominalPars);
105
106 return el;
107}
108
109
110//===============================================================================
113 std::string stationName;
114 j.json.at("station_name").get_to(stationName);
115 if (stationName == "MMS") {
117 } else if (stationName == "MML") {
119 } else {
120 throw std::runtime_error("StripCalculator: stationName not implemented: "+stationName);
121 }
122 j.json.at("station_eta").get_to(ret.stationEta);
123 j.json.at("station_phi").get_to(ret.stationPhi);
124 j.json.at("multilayer").get_to(ret.multilayer);
125 return ret;
126}
127
128
129//===============================================================================
131 pcbIdentifier_t ret;
132 ret.quadruplet = quad_id;
133 j.json.at("ilayerath").get_to(ret.ilayer);
134 j.json.at("iboard").get_to(ret.ipcb);
135 return ret;
136}
137
138
139//===============================================================================
141 auto getPoint = [](const nlohmann::json& j) {
142 double xpos, ypos, xpitch, ypitch;
143 j.at("pos").at("x").get_to(xpos);
144 j.at("pos").at("y").get_to(ypos);
145 j.at("pitchvec").at("x").get_to(xpitch);
146 j.at("pitchvec").at("y").get_to(ypitch);
147 return PcbElement::stripPoint_t{{xpos,ypos,0.0},{xpitch,ypitch,0.0}};
148 };
150 j.json.at("central_strip_number").get_to(ret.centralStripNumber);
151 ret.centerPoint = getPoint(j.json.at("strip_center"));
152 ret.leftPoint = getPoint(j.json.at("strip_left"));
153 ret.rightPoint = getPoint(j.json.at("strip_right"));
154 return ret;
155}
156
157
158//===============================================================================
160 if (j.json.contains("strip_configuration") && j.json.contains("identifier")) {
161 pcbIdentifier_t pcb_id = getPcbIdentifier(quad_id, j.json.at("identifier"));
163 m_pcbMap.insert(std::make_pair(pcb_id, PcbElement(config, element)));
164 }
165}
166
167
168//===============================================================================
170 using json = nlohmann::json;
171 struct tree_t {
172 json::const_iterator it;
173 json::const_iterator end;
174 };
175
176 if (!j.json.contains("identifier")) {
177 // No athena identifier given for this element, skip
178 return;
179 }
180
181 std::unique_ptr<Element> root = buildElement(j);
182 quadrupletIdentifier_t quad_id = getQuadrupletIdentifier(j.json.at("identifier"));
183 Element* mom = root.get();
184 const std::string KEY = "zdaughters";
185
186 // Depth-traversal of json tree, collect elements along the way
187 std::list<tree_t> jtree;
188 jtree.push_back({j.json.at(KEY).begin(), j.json.at(KEY).end()});
189 while (!jtree.empty()) {
190 auto& it = jtree.back().it;
191 if (it != jtree.back().end) {
192 std::unique_ptr<Element> daughter = buildElement(*it);
193 collectStrip(quad_id, *daughter, *it);
194 Element* daugref = mom->addDaughter(std::move(daughter));
195 if (it->contains(KEY)) {
196 jtree.push_back({it->at(KEY).begin(), it->at(KEY).end()});
197 mom = daugref;
198 }
199 ++it;
200 } else {
201 jtree.pop_back();
202 mom = mom->mother();
203 }
204 }
205
206 m_rootElements.push_back(std::move(root));
207}
208
nlohmann::json json
Element: a node in a hierarchy of alignment frames.
Definition Element.h:52
Helper class saving all the needed information to compute strips for a particular PCB.
Definition PcbElement.h:26
void collectStrip(quadrupletIdentifier_t quad_id, Element &element, json_t j)
std::vector< std::unique_ptr< Element > > m_rootElements
std::unique_ptr< Element > buildElement(json_t j) const
PcbElement::stripConfiguration_t getStripConfiguration(json_t j) const
Element::ParameterClass ParameterClass
position_t getPositionAlongStrip(ParameterClass iclass, stripIdentifier_t strip_id, double sx, double sy) const
quadrupletIdentifier_t getQuadrupletIdentifier(json_t j) const
strip_t getStrip(ParameterClass iclass, stripIdentifier_t strip_id) const
void parseJSON(const std::string &in)
std::unordered_map< pcbIdentifier_t, PcbElement > m_pcbMap
pcbIdentifier_t getPcbIdentifier(quadrupletIdentifier_t quad_id, json_t j) const
Eigen::Matrix< double, 3, 1 > Vector3D