ATLAS Offline Software
Loading...
Searching...
No Matches
NswAsBuilt::StgcStripCalculator Class Reference

The main interface of the NswAsBuilt package: determines strip positions in the frame of the quadruplet. More...

#include <StgcStripCalculator.h>

Collaboration diagram for NswAsBuilt::StgcStripCalculator:

Classes

struct  json_t
struct  position_t
 The return object for querying strip positions with the method getPositionAlongStrip: a single point on strip is returned, in the coordinate system of the quadruplet. More...
struct  stgcStrip_t
 The return object for querying strip positions: three points along the strip are provided, in the coordinate system of the quadruplet. More...

Public Types

enum class  IsValid { INVALID =0 , VALID =1 }
 VALID: strip is found, INVALID: strip is not found. More...
using ParameterClass = Element::ParameterClass

Public Member Functions

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.
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 the quadruplet.
void parseJSON (const std::string &in)
 Parses a std::istream with JSON-formatted configuration of the as-built parameters.

Private Member Functions

void parseRootElement (json_t j)
std::unique_ptr< ElementbuildElement (json_t j) const
quadrupletIdentifier_t getQuadrupletIdentifier (json_t j) const
pcbIdentifier_t getPcbIdentifier (quadrupletIdentifier_t quad_id, json_t j) const
void collectStrip (quadrupletIdentifier_t quad_id, Element &element, json_t j)
CathodeBoardElement::stgcStripConfiguration_t getStgcStripConfiguration (json_t j) const

Private Attributes

std::vector< std::unique_ptr< Element > > m_rootElements
std::unordered_map< pcbIdentifier_t, CathodeBoardElementm_pcbMap

Detailed Description

The main interface of the NswAsBuilt package: determines strip positions in the frame of the quadruplet.

Once instanciated, the as-built geometry must be read in from a stream of JSON formatted data, using the method parseJSON.

Strip positions may then be queried, using the method getStgcStrip. (The method getStgcStrip is thread-safe.)

Definition at line 31 of file StgcStripCalculator.h.

Member Typedef Documentation

◆ ParameterClass

Member Enumeration Documentation

◆ IsValid

VALID: strip is found, INVALID: strip is not found.

Enumerator
INVALID 
VALID 

Definition at line 38 of file StgcStripCalculator.h.

38 {
39 INVALID=0,
40 VALID=1
41 };

Member Function Documentation

◆ buildElement()

std::unique_ptr< Element > StgcStripCalculator::buildElement ( json_t j) const
private

Definition at line 61 of file StgcStripCalculator.cxx.

61 {
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}
Eigen::Matrix< double, 3, 1 > Vector3D

◆ collectStrip()

void StgcStripCalculator::collectStrip ( quadrupletIdentifier_t quad_id,
Element & element,
json_t j )
private

Definition at line 142 of file StgcStripCalculator.cxx.

142 {
143 if (j.json.contains("strip_configuration") && j.json.contains("identifier")) {
144 pcbIdentifier_t pcb_id = getPcbIdentifier(quad_id, j.json.at("identifier"));
145 CathodeBoardElement::stgcStripConfiguration_t config = getStgcStripConfiguration(j.json.at("strip_configuration"));
146 m_pcbMap.insert(std::make_pair(pcb_id, CathodeBoardElement(config, element)));
147 }
148}
CathodeBoardElement::stgcStripConfiguration_t getStgcStripConfiguration(json_t j) const
std::unordered_map< pcbIdentifier_t, CathodeBoardElement > m_pcbMap
pcbIdentifier_t getPcbIdentifier(quadrupletIdentifier_t quad_id, json_t j) const

◆ getPcbIdentifier()

pcbIdentifier_t StgcStripCalculator::getPcbIdentifier ( quadrupletIdentifier_t quad_id,
json_t j ) const
private

Definition at line 112 of file StgcStripCalculator.cxx.

◆ getPositionAlongStgcStrip()

StgcStripCalculator::position_t StgcStripCalculator::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 the quadruplet.

s is in [-1,1]: -1 returns the left-most point along the strip, 0 returns the center point and +1 return the right-most point

Definition at line 34 of file StgcStripCalculator.cxx.

34 {
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}

◆ getQuadrupletIdentifier()

quadrupletIdentifier_t StgcStripCalculator::getQuadrupletIdentifier ( json_t j) const
private

Definition at line 96 of file StgcStripCalculator.cxx.

96 {
97 quadrupletIdentifier_t ret;
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}

◆ getStgcStrip()

StgcStripCalculator::stgcStrip_t StgcStripCalculator::getStgcStrip ( ParameterClass iclass,
stripIdentifier_t strip_id ) const

Computes 3 reference points along a strip identified by strip_id, in coordinate system of quadruplet.

Use iclass=ParameterClass::NOMINAL or ParameterClass::CORRECTION to get the nominal or as-built values, respectively.

Definition at line 22 of file StgcStripCalculator.cxx.

22 {
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}

◆ getStgcStripConfiguration()

CathodeBoardElement::stgcStripConfiguration_t StgcStripCalculator::getStgcStripConfiguration ( json_t j) const
private

Definition at line 119 of file StgcStripCalculator.cxx.

119 {
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 };
128 CathodeBoardElement::stgcStripConfiguration_t ret;
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}

◆ parseJSON()

void StgcStripCalculator::parseJSON ( const std::string & in)

Parses a std::istream with JSON-formatted configuration of the as-built parameters.

Definition at line 46 of file StgcStripCalculator.cxx.

46 {
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}
nlohmann::json json

◆ parseRootElement()

void StgcStripCalculator::parseRootElement ( json_t j)
private

Definition at line 150 of file StgcStripCalculator.cxx.

150 {
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}
void collectStrip(quadrupletIdentifier_t quad_id, Element &element, json_t j)
quadrupletIdentifier_t getQuadrupletIdentifier(json_t j) const
std::vector< std::unique_ptr< Element > > m_rootElements
std::unique_ptr< Element > buildElement(json_t j) const

Member Data Documentation

◆ m_pcbMap

std::unordered_map<pcbIdentifier_t, CathodeBoardElement> NswAsBuilt::StgcStripCalculator::m_pcbMap
private

Definition at line 88 of file StgcStripCalculator.h.

◆ m_rootElements

std::vector<std::unique_ptr<Element> > NswAsBuilt::StgcStripCalculator::m_rootElements
private

Definition at line 87 of file StgcStripCalculator.h.


The documentation for this class was generated from the following files: