Belle II Software  release-05-02-19
MisalignmentCache.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Peter Kvasnicka *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 
12 #include <vxd/geometry/MisalignmentCache.h>
13 #include <vxd/dataobjects/VxdID.h>
14 #include <framework/gearbox/Unit.h>
15 #include <framework/logging/Logger.h>
16 #include <framework/utilities/FileSystem.h>
17 
18 #include <boost/property_tree/ptree.hpp>
19 #include <boost/property_tree/xml_parser.hpp>
20 
21 using namespace std;
22 using namespace boost::property_tree;
23 
24 namespace Belle2 {
29  namespace VXD {
30 
31  const TGeoHMatrix& MisalignmentCache::getMisalignmentTransform(VxdID id) const
32  {
33  static const TGeoHMatrix unity;
34 
35  id.setSegmentNumber(0);
36  MisalignmentMap::const_iterator info = m_misalignments.find(id);
37  if (info == m_misalignments.end())
38  return unity;
39  else return info->second;
40  }
41 
42  void MisalignmentCache::readMisalignmentsFromXml(const string& filename)
43  {
44  const double mradToDeg = 0.18 / 3.1415926;
45  ptree propertyTree;
46 
47  // Identify the location of the xml file.
48  string xmlFullPath = FileSystem::findFile(filename);
49 
50  if (! FileSystem::fileExists(xmlFullPath)) {
51  B2ERROR("The filename: " << filename << endl <<
52  "resolved to: " << xmlFullPath << endl <<
53  "by FileSystem::findFile but has no file with it." << endl <<
54  "Misaligner cache cannot be initialized." << endl <<
55  "No misalignment will be applied." << endl
56  );
57  return;
58  }
59 
60  try {
61  read_xml(xmlFullPath, propertyTree);
62  } catch (std::exception const& ex) {
63  B2ERROR("Excpetion raised during xml parsing " << ex.what() << endl <<
64  "Misaligner cache cannot be initialized." << endl <<
65  "No misalignment will be applied." << endl);
66  return;
67  } catch (...) {
68  B2ERROR("Unknown excpetion raised during xml parsing "
69  "Misaligner cache cannot be initialized." << endl <<
70  "No misalignment will be applied." << endl);
71  return;
72  }
73 
74  try {
75  // traverse pt: let us navigate through the daughters of <SVD>
76  for (ptree::value_type const& detector : propertyTree.get_child("SVDMisalignment")) {
77  for (ptree::value_type const& layer : detector.second.get_child("layer"))
78  for (ptree::value_type const& ladder : layer.second.get_child("ladder"))
79  for (ptree::value_type const& sensor : ladder.second.get_child("sensor")) {
80  // Only here we have some data
81  TGeoHMatrix transform;
82  transform.SetDx(sensor.second.get<double>("du") * Unit::um);
83  transform.SetDy(sensor.second.get<double>("dv") * Unit::um);
84  transform.SetDz(sensor.second.get<double>("dw") * Unit::um);
85  transform.RotateX(sensor.second.get<double>("dalpha") * mradToDeg);
86  transform.RotateY(sensor.second.get<double>("dbeta") * mradToDeg);
87  transform.RotateZ(sensor.second.get<double>("dgamma") * mradToDeg);
88  VxdID sensorID(sensor.second.get<VxdID::baseType>("<xmlattr>.id"));
89  m_misalignments[sensorID] = transform;
90  }
91  }
92  } catch (...) {
93  B2ERROR("Unknown excpetion raised during map initialization! "
94  "Misalignment data corrupted." << endl <<
95  "No misalignment will be applied." << endl);
96  m_misalignments.clear();
97  return;
98  }
99  m_isAlive = true;
100  }
101 
102  MisalignmentCache::MisalignmentShiftType MisalignmentCache::getMisalignmentShift(const VXDTrueHit* hit)
103  {
104  if (!m_isAlive || !hit) return make_tuple(false, 0.0, 0.0);
105  VxdID sensorID = hit->getSensorID();
106  const TGeoHMatrix& transform = getMisalignmentTransform(sensorID);
107  // 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.
108  const double xea[3] = {hit->getEntryU(), hit->getEntryV(), 0.0};
109  TVector3 tev(hit->getEntryMomentum().Unit());
110  const double tea[3] = {tev.X(), tev.Y(), tev.Z()};
111  double xca[3], tca[3];
112  transform.MasterToLocal(xea, xca);
113  transform.MasterToLocalVect(tea, tca);
114  if (abs(tca[2]) > 0.0) {
115  double factor = - xca[2] / tca[2];
116  double dx = xca[0] + factor * tca[0] - xea[0];
117  double dy = xca[1] + factor * tca[1] - xea[1];
118  return make_tuple(true, dx, dy);
119  } else {
120  return make_tuple(false, 0.0, 0.0);
121  }
122  }
123 
124  MisalignmentCache& MisalignmentCache::getInstance()
125  {
126  static unique_ptr<MisalignmentCache> instance(new MisalignmentCache());
127  return *instance;
128  }
129 
130  } // VXD namespace
132 } //Belle2 namespace
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::VXD::MisalignmentCache
Class to hold misalignment information.
Definition: MisalignmentCache.h:39
Belle2::VXDTrueHit
Class VXDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Definition: VXDTrueHit.h:38
Belle2::VxdID::baseType
unsigned short baseType
The base integer type for VxdID.
Definition: VxdID.h:46
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VXD::MisalignmentCache::MisalignmentShiftType
std::tuple< bool, double, double > MisalignmentShiftType
Misalignment shift information contains a validity flag (if false, the misaligned object falls outsid...
Definition: MisalignmentCache.h:45