12#include <boost/program_options.hpp>
15#include <TGeoManager.h>
21#include "TGeoPhysicalNode.h"
22#include <rapidjson/document.h>
23#include <rapidjson/ostreamwrapper.h>
24#include <rapidjson/stringbuffer.h>
25#include <rapidjson/writer.h>
35 std::stringstream ss(
src);
37 std::vector<std::string> tokens;
39 while (std::getline(ss, token, delim)) {
41 tokens.push_back(std::move(token));
52 throw std::runtime_error(
"can not open " +
filename);
55 auto possibleGeoNames = {
"ccdb_object",
"ALICE",
"FAIRGeom",
"MCH-ONLY",
"MCH-BASICS"};
57 TGeoManager* geo{
nullptr};
59 for (
auto name : possibleGeoNames) {
60 geo =
static_cast<TGeoManager*
>(
f->Get(
name));
67 throw std::runtime_error(
"could not find ALICE geometry (using ccdb_object, ALICE or FAIRGeom names)");
72template <
typename WRITER>
76 constexpr double rad2deg = 180.0 / 3.14159265358979323846;
78 const Double_t*
t = matrix.GetTranslation();
79 const Double_t*
m = matrix.GetRotationMatrix();
80 gsl::span<double> mat(
const_cast<double*
>(
m), 9);
96std::tuple<bool, uint16_t>
isMCH(std::string alignableName)
99 bool aliroot = parts[0] ==
"MUON";
100 bool o2 = parts[0] ==
"MCH";
101 if (!
o2 && !aliroot) {
104 auto id = std::stoi(parts[1].substr(2));
105 bool ok = (aliroot && (
id <= 15)) || (
o2 && (
id <= 19));
107 if (ok && parts.size() > 2) {
108 deId = std::stoi(parts[2].substr(2));
113template <
typename WRITER>
128 rapidjson::OStreamWrapper osw(std::cout);
129 rapidjson::Writer<rapidjson::OStreamWrapper> writer(osw);
131 writer.StartObject();
132 writer.Key(
"alignables");
135 for (
auto i = 0;
i < geom.GetNAlignable();
i++) {
136 auto ae = geom.GetAlignableEntry(
i);
137 std::string symname = ae->GetName();
138 auto [mch, deId] =
isMCH(symname);
142 writer.StartObject();
147 writer.Key(
"symname");
148 writer.String(symname.c_str());
149 auto pn = ae->GetPhysicalNode();
150 const TGeoHMatrix* matrix{
nullptr};
153 matrix = pn->GetMatrix();
154 aligned = pn->IsAligned();
156 matrix = ae->GetGlobalOrig();
160 writer.Key(
"aligned");
161 writer.Bool(aligned);
170 po::variables_map vm;
171 po::options_description options;
174 options.add_options()
176 (
"geom",po::value<std::string>()->required(),
"geometry.root file");
179 po::options_description cmdline;
180 cmdline.add(options);
182 po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
184 if (vm.count(
"help")) {
185 std::cout <<
"This program extract MCH geometry transformation from "
186 "a geometry root file and write them in json format.\n";
188 std::cout << options <<
"\n";
190 std::cout <<
"Note that the json format can then be further manipulated using e.g."
192 std::cout <<
"For instance sorting by deid:\n";
193 std::cout <<
"cat output.json | jq '.alignables|=sort_by(.deid)'\n";
200 }
catch (boost::program_options::error&
e) {
201 std::cout <<
"Error: " <<
e.what() <<
"\n";
202 std::cout << options <<
"\n";
206 TGeoManager* geom =
readFromFile(vm[
"geom"].as<std::string>());
unsigned short int uint16_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
std::vector< std::string > splitString(const std::string &src, char delim)
std::tuple< bool, uint16_t > isMCH(std::string alignableName)
void matrix2json(const TGeoHMatrix &matrix, WRITER &w)
void writeMatrix(const char *name, const TGeoHMatrix *matrix, WRITER &w)
void convertGeom(const TGeoManager &geom)
TGeoManager * readFromFile(std::string filename)
GLuint const GLchar * name
GLubyte GLubyte GLubyte GLubyte w
std::tuple< double, double, double > matrix2angles(gsl::span< double > rot)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...