ATLAS Offline Software
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 
11 #include "MuonNSWAsBuilt/Element.h"
14 
15 using namespace NswAsBuilt;
16 
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 
46 void 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 //
61 std::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 }
NswAsBuilt::StgcStripCalculator::json_t
Definition: StgcStripCalculator.cxx:17
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
fitman.sy
sy
Definition: fitman.py:524
NswAsBuilt::StgcStripCalculator::position_t
The return object for querying strip positions with the method getPositionAlongStrip: a single point ...
Definition: StgcStripCalculator.h:67
NswAsBuilt::CathodeBoardElement::stgcStripConfiguration_t
Definition: CathodeBoardElement.h:38
NswAsBuilt::stripIdentifier_t::quadruplet
quadrupletIdentifier_t quadruplet
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:82
json
nlohmann::json json
Definition: HistogramDef.cxx:9
NswAsBuilt::CathodeBoardElement::stgcStripConfiguration_t::fCenterPoint
stgcStripPoint_t fCenterPoint
Definition: CathodeBoardElement.h:40
dumpTgcDigiDeadChambers.stationName
dictionary stationName
Definition: dumpTgcDigiDeadChambers.py:30
NswAsBuilt::CathodeBoardElement::stgcStripConfiguration_t::lastStripNumber
int lastStripNumber
Definition: CathodeBoardElement.h:39
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
NswAsBuilt::StgcStripCalculator::m_rootElements
std::vector< std::unique_ptr< Element > > m_rootElements
Definition: StgcStripCalculator.h:87
NswAsBuilt::quadrupletIdentifier_t::stationEta
int stationEta
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:34
python.compressB64.sx
string sx
Definition: compressB64.py:96
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:396
NswAsBuilt::quadrupletIdentifier_t::STS
@ STS
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:29
NswAsBuilt::StgcStripCalculator::parseJSON
void parseJSON(const std::string &in)
Parses a std::istream with JSON-formatted configuration of the as-built parameters.
Definition: StgcStripCalculator.cxx:46
NswAsBuilt::StgcStripCalculator::getQuadrupletIdentifier
quadrupletIdentifier_t getQuadrupletIdentifier(json_t j) const
Definition: StgcStripCalculator.cxx:96
sendEI_SPB.root
root
Definition: sendEI_SPB.py:34
NswAsBuilt::StgcStripCalculator::m_pcbMap
std::unordered_map< pcbIdentifier_t, CathodeBoardElement > m_pcbMap
Definition: StgcStripCalculator.h:88
NswAsBuilt::CathodeBoardElement::stgcStripConfiguration_t::sRightPoint
stgcStripPoint_t sRightPoint
Definition: CathodeBoardElement.h:45
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
NswAsBuilt::StgcStripCalculator::json_t::json_t
json_t(const nlohmann::json &j)
Definition: StgcStripCalculator.cxx:19
NswAsBuilt::CathodeBoardElement
Helper class saving all the needed information to compute strips for a particular cathode board.
Definition: CathodeBoardElement.h:26
NswAsBuilt::StgcStripCalculator::IsValid::VALID
@ VALID
NswAsBuilt::pcbIdentifier_t
The indices of a MM PCB.
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:59
StgcStripCalculator.h
Element.h
NswAsBuilt::quadrupletIdentifier_t::stationName
StationName stationName
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:33
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
NswAsBuilt::CathodeBoardElement::stgcStripPoint_t
Definition: CathodeBoardElement.h:33
NswAsBuilt::CathodeBoardElement::stgcStripConfiguration_t::fLeftPoint
stgcStripPoint_t fLeftPoint
Definition: CathodeBoardElement.h:41
NswAsBuilt::quadrupletIdentifier_t::multilayer
int multilayer
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:36
NswAsBuilt::pcbIdentifier_t::quadruplet
quadrupletIdentifier_t quadruplet
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:60
NswAsBuilt::stripIdentifier_t
Athena indices of a MM strip.
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:81
NswAsBuilt::quadrupletIdentifier_t
Athena indices for a MM quadruplet:
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:25
NswAsBuilt::Element::ParameterClass::NOMINAL
@ NOMINAL
calibdata.exception
exception
Definition: calibdata.py:496
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ElementModelRigid.h
NswAsBuilt::StgcStripCalculator::buildElement
std::unique_ptr< Element > buildElement(json_t j) const
Definition: StgcStripCalculator.cxx:61
NswAsBuilt::CathodeBoardElement::stgcStripConfiguration_t::sLeftPoint
stgcStripPoint_t sLeftPoint
Definition: CathodeBoardElement.h:44
NswAsBuilt::StgcStripCalculator::getPositionAlongStgcStrip
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...
Definition: StgcStripCalculator.cxx:34
NswAsBuilt::StgcStripCalculator::collectStrip
void collectStrip(quadrupletIdentifier_t quad_id, Element &element, json_t j)
Definition: StgcStripCalculator.cxx:142
NswAsBuilt::CathodeBoardElement::stgcStripConfiguration_t::sCenterPoint
stgcStripPoint_t sCenterPoint
Definition: CathodeBoardElement.h:43
NswAsBuilt::CathodeBoardElement::stgcStripConfiguration_t::lLeftPoint
stgcStripPoint_t lLeftPoint
Definition: CathodeBoardElement.h:47
NswAsBuilt::StgcStripCalculator::parseRootElement
void parseRootElement(json_t j)
Definition: StgcStripCalculator.cxx:150
NswAsBuilt::StgcStripCalculator::getPcbIdentifier
pcbIdentifier_t getPcbIdentifier(quadrupletIdentifier_t quad_id, json_t j) const
Definition: StgcStripCalculator.cxx:112
NswAsBuilt::StgcStripCalculator::getStgcStripConfiguration
CathodeBoardElement::stgcStripConfiguration_t getStgcStripConfiguration(json_t j) const
Definition: StgcStripCalculator.cxx:119
NswAsBuilt::CathodeBoardElement::stgcStripConfiguration_t::lRightPoint
stgcStripPoint_t lRightPoint
Definition: CathodeBoardElement.h:48
NswAsBuilt::StgcStripCalculator::getStgcStrip
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.
Definition: StgcStripCalculator.cxx:22
NswAsBuilt::pcbIdentifier_t::ipcb
int ipcb
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:62
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
NswAsBuilt::Element::ParameterClass
ParameterClass
Definition: Element.h:63
NswAsBuilt::StgcStripCalculator::stgcStrip_t
The return object for querying strip positions: three points along the strip are provided,...
Definition: StgcStripCalculator.h:47
NswAsBuilt::stripIdentifier_t::ilayer
int ilayer
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:83
NswAsBuilt::StgcStripCalculator::json_t::json
const nlohmann::json & json
Definition: StgcStripCalculator.cxx:18
correlationModel::model
model
Definition: AsgElectronEfficiencyCorrectionTool.cxx:46
ElementModelSTGC.h
NswAsBuilt::stripIdentifier_t::istrip
int istrip
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:84
NswAsBuilt::CathodeBoardElement::stgcStripConfiguration_t::fRightPoint
stgcStripPoint_t fRightPoint
Definition: CathodeBoardElement.h:42
NswAsBuilt::quadrupletIdentifier_t::STL
@ STL
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:30
NswAsBuilt
Definition: CathodeBoardElement.h:12
NswAsBuilt::Element
Element: a node in a hierarchy of alignment frames.
Definition: Element.h:52
NswAsBuilt::pcbIdentifier_t::ilayer
int ilayer
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:61
NswAsBuilt::Element::ParameterClass::CORRECTION
@ CORRECTION
NswAsBuilt::quadrupletIdentifier_t::stationPhi
int stationPhi
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:35
NswAsBuilt::CathodeBoardElement::stgcStripConfiguration_t::lCenterPoint
stgcStripPoint_t lCenterPoint
Definition: CathodeBoardElement.h:46