Belle II Software development
PCmsLabTransform.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#include <analysis/utility/PCmsLabTransform.h>
10
11#include <initializer_list>
12
13using namespace Belle2;
14
15namespace {
17 struct CmsTransformCache {
19 DBObjPtr<CollisionInvariantMass> invariantMass;
21 DBObjPtr<CollisionBoostVector> boostVector;
23 DBObjPtr<CollisionAxisCMS> axisCms;
24
26 bool valid = false;
28 double cmsEnergy = 0;
30 ROOT::Math::XYZVector boost;
32 ROOT::Math::LorentzRotation labToCms;
34 ROOT::Math::LorentzRotation cmsToLab;
36 ROOT::Math::PxPyPzEVector beamFourMomentum;
37
38 CmsTransformCache()
39 {
40 for (DBAccessorBase* accessor : std::initializer_list<DBAccessorBase*> {&invariantMass, &boostVector, &axisCms}) {
41 // Invalidate when a payload changes (new run or intra-run dependency) and when the DBStore entry is
42 // destroyed (DBStore reset): in the latter case the accessor is reattached on its next use, which
43 // happens when the cache is recomputed.
44 accessor->addCallback([this]() { valid = false; }, false);
45 accessor->addCallback([this]() { valid = false; }, true);
46 }
47 }
48
50 const CmsTransformCache& get()
51 {
52 if (!valid) {
53 cmsEnergy = invariantMass->getMass();
54 boost = ROOT::Math::XYZVector(boostVector->getBoost());
55 labToCms = LabToCms::rotateLabToCms(boost, axisCms->getAngleXZ(), axisCms->getAngleYZ());
56 cmsToLab = labToCms.Inverse();
57 beamFourMomentum = cmsToLab * ROOT::Math::PxPyPzEVector(0, 0, 0, cmsEnergy);
58 valid = true;
59 }
60 return *this;
61 }
62 };
63
65 const CmsTransformCache& cmsTransform()
66 {
67 static CmsTransformCache cache;
68 return cache.get();
69 }
70}
71
72ROOT::Math::XYZVector PCmsLabTransform::getBoostVector()
73{
74 return cmsTransform().boost;
75}
76
78{
79 return cmsTransform().cmsEnergy;
80}
81
82ROOT::Math::PxPyPzEVector PCmsLabTransform::getBeamFourMomentum()
83{
84 return cmsTransform().beamFourMomentum;
85}
86
87const ROOT::Math::LorentzRotation PCmsLabTransform::rotateLabToCms()
88{
89 return cmsTransform().labToCms;
90}
91
92const ROOT::Math::LorentzRotation PCmsLabTransform::rotateCmsToLab()
93{
94 return cmsTransform().cmsToLab;
95}
96
97ROOT::Math::PxPyPzMVector PCmsLabTransform::labToCms(const ROOT::Math::PxPyPzMVector& vector)
98{
100 return T.rotateLabToCms() * vector;
101}
102
103ROOT::Math::PxPyPzMVector PCmsLabTransform::cmsToLab(const ROOT::Math::PxPyPzMVector& vector)
104{
106 return T.rotateCmsToLab() * vector;
107}
108
109ROOT::Math::PxPyPzEVector PCmsLabTransform::labToCms(const ROOT::Math::PxPyPzEVector& vector)
110{
112 return T.rotateLabToCms() * vector;
113}
114
115ROOT::Math::PxPyPzEVector PCmsLabTransform::cmsToLab(const ROOT::Math::PxPyPzEVector& vector)
116{
118 return T.rotateCmsToLab() * vector;
119}
120
static ROOT::Math::LorentzRotation rotateLabToCms(const ROOT::Math::XYZVector &boostVector, double cmsAngleXZ, double cmsAngleYZ)
Function takes 3D boostVector and angles of the HER momentum in the CM system obtained by pure boost.
Definition LabToCms.h:44
static const ROOT::Math::LorentzRotation rotateCmsToLab()
Returns Lorentz transformation from CMS to Lab.
static ROOT::Math::PxPyPzMVector labToCms(const ROOT::Math::PxPyPzMVector &vec)
Transforms Lorentz vector into CM System.
PCmsLabTransform()
Constructor.
static ROOT::Math::PxPyPzMVector cmsToLab(const ROOT::Math::PxPyPzMVector &vec)
Transforms Lorentz vector into Laboratory System.
static const ROOT::Math::LorentzRotation rotateLabToCms()
Returns Lorentz transformation from Lab to CMS.
static ROOT::Math::PxPyPzEVector getBeamFourMomentum()
Returns LAB four-momentum of e+e-, i.e.
static double getCMSEnergy()
Returns CMS energy of e+e- (aka.
static ROOT::Math::XYZVector getBoostVector()
Returns boost vector (beta=p/E)
Abstract base class for different kinds of events.