10#include <vxd/geometry/MisalignmentCache.h>
11#include <vxd/dataobjects/VxdID.h>
12#include <framework/gearbox/Unit.h>
13#include <framework/logging/Logger.h>
14#include <framework/utilities/FileSystem.h>
16#include <boost/property_tree/ptree.hpp>
17#include <boost/property_tree/xml_parser.hpp>
20using namespace boost::property_tree;
31 static const TGeoHMatrix unity;
33 id.setSegmentNumber(0);
37 else return info->second;
42 const double mradToDeg = 0.18 / M_PI;
49 B2ERROR(
"The filename: " << filename << endl <<
50 "resolved to: " << xmlFullPath << endl <<
51 "by FileSystem::findFile but has no file with it." << endl <<
52 "Misaligner cache cannot be initialized." << endl <<
53 "No misalignment will be applied." << endl
59 read_xml(xmlFullPath, propertyTree);
60 }
catch (std::exception
const& ex) {
61 B2ERROR(
"Excpetion raised during xml parsing " << ex.what() << endl <<
62 "Misaligner cache cannot be initialized." << endl <<
63 "No misalignment will be applied." << endl);
66 B2ERROR(
"Unknown excpetion raised during xml parsing "
67 "Misaligner cache cannot be initialized." << endl <<
68 "No misalignment will be applied." << endl);
74 for (ptree::value_type
const& detector : propertyTree.get_child(
"SVDMisalignment")) {
75 for (ptree::value_type
const& layer : detector.second.get_child(
"layer"))
76 for (ptree::value_type
const& ladder : layer.second.get_child(
"ladder"))
77 for (ptree::value_type
const& sensor : ladder.second.get_child(
"sensor")) {
79 TGeoHMatrix transform;
80 transform.SetDx(sensor.second.get<
double>(
"du") *
Unit::um);
81 transform.SetDy(sensor.second.get<
double>(
"dv") *
Unit::um);
82 transform.SetDz(sensor.second.get<
double>(
"dw") *
Unit::um);
83 transform.RotateX(sensor.second.get<
double>(
"dalpha") * mradToDeg);
84 transform.RotateY(sensor.second.get<
double>(
"dbeta") * mradToDeg);
85 transform.RotateZ(sensor.second.get<
double>(
"dgamma") * mradToDeg);
91 B2ERROR(
"Unknown excpetion raised during map initialization! "
92 "Misalignment data corrupted." << endl <<
93 "No misalignment will be applied." << endl);
102 if (!
m_isAlive || !hit)
return make_tuple(
false, 0.0, 0.0);
103 VxdID sensorID = hit->getSensorID();
106 const double xea[3] = {hit->getEntryU(), hit->getEntryV(), 0.0};
107 ROOT::Math::XYZVector tev(hit->getEntryMomentum().Unit());
108 const double tea[3] = {tev.X(), tev.Y(), tev.Z()};
109 double xca[3], tca[3];
110 transform.MasterToLocal(xea, xca);
111 transform.MasterToLocalVect(tea, tca);
112 if (abs(tca[2]) > 0.0) {
113 double factor = - xca[2] / tca[2];
114 double dx = xca[0] + factor * tca[0] - xea[0];
115 double dy = xca[1] + factor * tca[1] - xea[1];
116 return make_tuple(
true, dx, dy);
118 return make_tuple(
false, 0.0, 0.0);
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
static bool fileExists(const std::string &filename)
Check if the file with given filename exists.
static const double um
[micrometers]
Class VXDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Class to hold misalignment information.
MisalignmentCache()
Singleton class, hidden constructor.
bool m_isAlive
Is the cache alive?
MisalignmentShiftType getMisalignmentShift(const VXDTrueHit *hit)
Return misalignment shift for a VXDTrueHit.
const TGeoHMatrix & getMisalignmentTransform(Belle2::VxdID id) const
Return the misalignment transform for a given sensor.
std::tuple< bool, double, double > MisalignmentShiftType
Misalignment shift information contains a validity flag (if false, the misaligned object falls outsid...
MisalignmentMap m_misalignments
Map to hold solid body misalignments for sensors.
static MisalignmentCache & getInstance()
Return a reference to the singleton instance.
void readMisalignmentsFromXml(const std::string &filename)
Read misalignment data from an xml file and store sensor misalignments.
Class to uniquely identify a any structure of the PXD and SVD.
unsigned short baseType
The base integer type for VxdID.
Abstract base class for different kinds of events.