Belle II Software development
MisalignmentCache Class Reference

Class to hold misalignment information. More...

#include <MisalignmentCache.h>

Public Types

typedef std::unordered_map< Belle2::VxdID::baseType, TGeoHMatrix > MisalignmentMap
 Hash map type to store existing misalignment transforms.
 
typedef std::tuple< bool, double, double > MisalignmentShiftType
 Misalignment shift information contains a validity flag (if false, the misaligned object falls outside its sensor) and shifts in u and v.
 

Public Member Functions

 ~MisalignmentCache ()
 destructor to clean up misalignment
 
void clear ()
 clear cache data
 
void readMisalignmentsFromXml (const std::string &filename)
 Read misalignment data from an xml file and store sensor misalignments.
 
void addMisalignment (Belle2::VxdID sensorID, const TGeoHMatrix &misalignment)
 Add a new entry to the list of sensor misalignments.
 
const MisalignmentMapgetMisalignments () const
 Return the list of sensor misalignments.
 
const TGeoHMatrix & getMisalignmentTransform (Belle2::VxdID id) const
 Return the misalignment transform for a given sensor.
 
MisalignmentShiftType getMisalignmentShift (const VXDTrueHit *hit)
 Return misalignment shift for a VXDTrueHit.
 

Static Public Member Functions

static MisalignmentShiftType getMisalignment (const VXDTrueHit *hit)
 Return misalignment shift for a VXDTrueHit.
 
static MisalignmentCachegetInstance ()
 Return a reference to the singleton instance.
 
static bool isAlive ()
 Return alive status of the cache (are there misalignment data?
 

Private Member Functions

 MisalignmentCache ()
 Singleton class, hidden constructor.
 
 MisalignmentCache (const MisalignmentCache &)=delete
 Singleton class, no copying.
 
MisalignmentCacheoperator= (const MisalignmentCache &)=delete
 Singleton class, no assignment.
 

Private Attributes

bool m_isAlive {false}
 Is the cache alive?
 
MisalignmentMap m_misalignments
 Map to hold solid body misalignments for sensors.
 

Detailed Description

Class to hold misalignment information.

Definition at line 29 of file MisalignmentCache.h.

Member Typedef Documentation

◆ MisalignmentMap

typedef std::unordered_map<Belle2::VxdID::baseType, TGeoHMatrix> MisalignmentMap

Hash map type to store existing misalignment transforms.

Definition at line 33 of file MisalignmentCache.h.

◆ MisalignmentShiftType

typedef std::tuple<bool, double, double> MisalignmentShiftType

Misalignment shift information contains a validity flag (if false, the misaligned object falls outside its sensor) and shifts in u and v.

Definition at line 35 of file MisalignmentCache.h.

Constructor & Destructor Documentation

◆ ~MisalignmentCache()

~MisalignmentCache ( )
inline

destructor to clean up misalignment

Definition at line 38 of file MisalignmentCache.h.

38{ clear(); };
void clear()
clear cache data

◆ MisalignmentCache()

MisalignmentCache ( )
inlineprivate

Singleton class, hidden constructor.

Definition at line 91 of file MisalignmentCache.h.

91{};

Member Function Documentation

◆ addMisalignment()

void addMisalignment ( Belle2::VxdID  sensorID,
const TGeoHMatrix &  misalignment 
)
inline

Add a new entry to the list of sensor misalignments.

This method will manually add a new (VxdID, Transform3D) pair to the list.

Parameters
sensorIDSensor identifier.
misalignment3D transform to add to the list of sensor misalignments.

Definition at line 53 of file MisalignmentCache.h.

54 {
55 m_misalignments[sensorID] = misalignment;
56 m_isAlive = true;
57 }
bool m_isAlive
Is the cache alive?
MisalignmentMap m_misalignments
Map to hold solid body misalignments for sensors.

◆ clear()

void clear ( )
inline

clear cache data

Definition at line 41 of file MisalignmentCache.h.

41{ m_misalignments.clear(); m_isAlive = false; }

◆ getInstance()

MisalignmentCache & getInstance ( )
static

Return a reference to the singleton instance.

Definition at line 122 of file MisalignmentCache.cc.

123 {
124 static unique_ptr<MisalignmentCache> instance(new MisalignmentCache());
125 return *instance;
126 }
MisalignmentCache()
Singleton class, hidden constructor.

◆ getMisalignment()

static MisalignmentShiftType getMisalignment ( const VXDTrueHit hit)
inlinestatic

Return misalignment shift for a VXDTrueHit.

This is a shorthand for MisalignmentCache::getInstance().getMisalignmentShift.

Definition at line 78 of file MisalignmentCache.h.

79 { return getInstance().getMisalignmentShift(hit); }
MisalignmentShiftType getMisalignmentShift(const VXDTrueHit *hit)
Return misalignment shift for a VXDTrueHit.
static MisalignmentCache & getInstance()
Return a reference to the singleton instance.

◆ getMisalignments()

const MisalignmentMap & getMisalignments ( ) const
inline

Return the list of sensor misalignments.

Definition at line 60 of file MisalignmentCache.h.

60{ return m_misalignments; }

◆ getMisalignmentShift()

MisalignmentCache::MisalignmentShiftType getMisalignmentShift ( const VXDTrueHit hit)

Return misalignment shift for a VXDTrueHit.

This is the principal misalignment method, used to misalign TrueHits or Clusters (via relation to their TrueHits.

Parameters
hitpointer to the TrueHit to misalign
Returns
std::pair<double, double> of misalignment shifts

Definition at line 100 of file MisalignmentCache.cc.

101 {
102 if (!m_isAlive || !hit) return make_tuple(false, 0.0, 0.0);
103 VxdID sensorID = hit->getSensorID();
104 const TGeoHMatrix& transform = getMisalignmentTransform(sensorID);
105 // We need entry point as a reference - the point on the original track unaffected by passage through the sensor. We also don't care for w and set it to zero.
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);
117 } else {
118 return make_tuple(false, 0.0, 0.0);
119 }
120 }
const TGeoHMatrix & getMisalignmentTransform(Belle2::VxdID id) const
Return the misalignment transform for a given sensor.

◆ getMisalignmentTransform()

const TGeoHMatrix & getMisalignmentTransform ( Belle2::VxdID  id) const

Return the misalignment transform for a given sensor.

Parameters
idVxdID of the desired sensor
Returns
identity transform if no data found.

Definition at line 29 of file MisalignmentCache.cc.

30 {
31 static const TGeoHMatrix unity;
32
33 id.setSegmentNumber(0);
34 MisalignmentMap::const_iterator info = m_misalignments.find(id);
35 if (info == m_misalignments.end())
36 return unity;
37 else return info->second;
38 }

◆ isAlive()

static bool isAlive ( )
inlinestatic

Return alive status of the cache (are there misalignment data?

Definition at line 85 of file MisalignmentCache.h.

86 { return getInstance().m_isAlive; }

◆ readMisalignmentsFromXml()

void readMisalignmentsFromXml ( const std::string &  filename)

Read misalignment data from an xml file and store sensor misalignments.

Parameters
filenamename of the xml file

Definition at line 40 of file MisalignmentCache.cc.

41 {
42 const double mradToDeg = 0.18 / M_PI;
43 ptree propertyTree;
44
45 // Identify the location of the xml file.
46 string xmlFullPath = FileSystem::findFile(filename);
47
48 if (! FileSystem::fileExists(xmlFullPath)) {
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
54 );
55 return;
56 }
57
58 try {
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);
64 return;
65 } catch (...) {
66 B2ERROR("Unknown excpetion raised during xml parsing "
67 "Misaligner cache cannot be initialized." << endl <<
68 "No misalignment will be applied." << endl);
69 return;
70 }
71
72 try {
73 // traverse pt: let us navigate through the daughters of <SVD>
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")) {
78 // Only here we have some data
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);
86 VxdID sensorID(sensor.second.get<VxdID::baseType>("<xmlattr>.id"));
87 m_misalignments[sensorID] = transform;
88 }
89 }
90 } catch (...) {
91 B2ERROR("Unknown excpetion raised during map initialization! "
92 "Misalignment data corrupted." << endl <<
93 "No misalignment will be applied." << endl);
94 m_misalignments.clear();
95 return;
96 }
97 m_isAlive = true;
98 }
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...
Definition: FileSystem.cc:151
static bool fileExists(const std::string &filename)
Check if the file with given filename exists.
Definition: FileSystem.cc:32
static const double um
[micrometers]
Definition: Unit.h:71
unsigned short baseType
The base integer type for VxdID.
Definition: VxdID.h:36

Member Data Documentation

◆ m_isAlive

bool m_isAlive {false}
private

Is the cache alive?

Definition at line 98 of file MisalignmentCache.h.

◆ m_misalignments

MisalignmentMap m_misalignments
private

Map to hold solid body misalignments for sensors.

Definition at line 100 of file MisalignmentCache.h.


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