Belle II Software  release-08-01-10
MisalignmentCache.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 
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>
15 
16 #include <boost/property_tree/ptree.hpp>
17 #include <boost/property_tree/xml_parser.hpp>
18 
19 using namespace std;
20 using namespace boost::property_tree;
21 
22 namespace Belle2 {
27  namespace VXD {
28 
29  const TGeoHMatrix& MisalignmentCache::getMisalignmentTransform(VxdID id) const
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  }
39 
40  void MisalignmentCache::readMisalignmentsFromXml(const string& filename)
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  }
99 
100  MisalignmentCache::MisalignmentShiftType MisalignmentCache::getMisalignmentShift(const VXDTrueHit* hit)
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  }
121 
122  MisalignmentCache& MisalignmentCache::getInstance()
123  {
124  static unique_ptr<MisalignmentCache> instance(new MisalignmentCache());
125  return *instance;
126  }
127 
128  } // VXD namespace
130 } //Belle2 namespace
Class VXDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Definition: VXDTrueHit.h:36
Class to hold misalignment information.
std::tuple< bool, double, double > MisalignmentShiftType
Misalignment shift information contains a validity flag (if false, the misaligned object falls outsid...
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
unsigned short baseType
The base integer type for VxdID.
Definition: VxdID.h:36
Abstract base class for different kinds of events.