ATLAS Offline Software
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 
11 #include "MuonNSWAsBuilt/Element.h"
14 
15 
16 using namespace NswAsBuilt;
17 
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 //===============================================================================
59 void 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
75 std::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"));
162  PcbElement::stripConfiguration_t config = getStripConfiguration(j.json.at("strip_configuration"));
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 
NswAsBuilt::PcbElement::stripPoint_t
Definition: PcbElement.h:32
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
NswAsBuilt::StripCalculator::position_t
Definition: StripCalculator.h:58
fitman.sy
sy
Definition: fitman.py:524
NswAsBuilt::stripIdentifier_t::quadruplet
quadrupletIdentifier_t quadruplet
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:82
json
nlohmann::json json
Definition: HistogramDef.cxx:9
NswAsBuilt::StripCalculator::IsValid::VALID
@ VALID
dumpTgcDigiDeadChambers.stationName
dictionary stationName
Definition: dumpTgcDigiDeadChambers.py:30
NswAsBuilt::StripCalculator::parseRootElement
void parseRootElement(json_t j)
Definition: StripCalculator.cxx:169
NswAsBuilt::StripCalculator::getQuadrupletIdentifier
quadrupletIdentifier_t getQuadrupletIdentifier(json_t j) const
Definition: StripCalculator.cxx:111
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
ElementModelScaleSag.h
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::StripCalculator::m_rootElements
std::vector< std::unique_ptr< Element > > m_rootElements
Definition: StripCalculator.h:74
NswAsBuilt::PcbElement::stripConfiguration_t::centralStripNumber
int centralStripNumber
Definition: PcbElement.h:39
sendEI_SPB.root
root
Definition: sendEI_SPB.py:34
NswAsBuilt::StripCalculator::m_pcbMap
std::unordered_map< pcbIdentifier_t, PcbElement > m_pcbMap
Definition: StripCalculator.h:75
NswAsBuilt::StripCalculator::getStrip
strip_t getStrip(ParameterClass iclass, stripIdentifier_t strip_id) const
Definition: StripCalculator.cxx:24
NswAsBuilt::StripCalculator::json_t
Definition: StripCalculator.cxx:18
NswAsBuilt::PcbElement::stripConfiguration_t::leftPoint
stripPoint_t leftPoint
Definition: PcbElement.h:41
NswAsBuilt::StripCalculator::collectStrip
void collectStrip(quadrupletIdentifier_t quad_id, Element &element, json_t j)
Definition: StripCalculator.cxx:159
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
NswAsBuilt::StripCalculator::json_t::json_t
json_t(const nlohmann::json &j)
Definition: StripCalculator.cxx:20
NswAsBuilt::PcbElement::stripConfiguration_t::rightPoint
stripPoint_t rightPoint
Definition: PcbElement.h:42
NswAsBuilt::pcbIdentifier_t
The indices of a MM PCB.
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:59
NswAsBuilt::StripCalculator::getPositionAlongStrip
position_t getPositionAlongStrip(ParameterClass iclass, stripIdentifier_t strip_id, double sx, double sy) const
Definition: StripCalculator.cxx:42
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::StripCalculator::getStripConfiguration
PcbElement::stripConfiguration_t getStripConfiguration(json_t j) const
Definition: StripCalculator.cxx:140
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::quadrupletIdentifier_t::MML
@ MML
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:28
NswAsBuilt::Element::ParameterClass::NOMINAL
@ NOMINAL
calibdata.exception
exception
Definition: calibdata.py:496
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ElementModelRigid.h
NswAsBuilt::StripCalculator::strip_t
Definition: StripCalculator.h:42
NswAsBuilt::StripCalculator::getPcbIdentifier
pcbIdentifier_t getPcbIdentifier(quadrupletIdentifier_t quad_id, json_t j) const
Definition: StripCalculator.cxx:130
NswAsBuilt::StripCalculator::json_t::json
const nlohmann::json & json
Definition: StripCalculator.cxx:19
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::StripCalculator::parseJSON
void parseJSON(const std::string &in)
Definition: StripCalculator.cxx:59
StripCalculator.h
NswAsBuilt::Element::ParameterClass
ParameterClass
Definition: Element.h:63
NswAsBuilt::stripIdentifier_t::ilayer
int ilayer
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:83
NswAsBuilt::quadrupletIdentifier_t::MMS
@ MMS
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:27
correlationModel::model
model
Definition: AsgElectronEfficiencyCorrectionTool.cxx:46
NswAsBuilt::StripCalculator::buildElement
std::unique_ptr< Element > buildElement(json_t j) const
Definition: StripCalculator.cxx:75
NswAsBuilt::stripIdentifier_t::istrip
int istrip
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:84
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::PcbElement::stripConfiguration_t
Definition: PcbElement.h:38
NswAsBuilt::PcbElement::stripConfiguration_t::centerPoint
stripPoint_t centerPoint
Definition: PcbElement.h:40
NswAsBuilt::PcbElement
Helper class saving all the needed information to compute strips for a particular PCB.
Definition: PcbElement.h:26
NswAsBuilt::quadrupletIdentifier_t::stationPhi
int stationPhi
Definition: MuonSpectrometer/MuonDetDescr/MuonNSWAsBuilt/MuonNSWAsBuilt/Identifier.h:35