9#include <analysis/modules/PostMergeUpdate/PostMergeUpdaterModule.h>
10#include <mdst/dbobjects/BeamSpot.h>
11#include <framework/logging/Logger.h>
12#include <analysis/utility/PCmsLabTransform.h>
13#include <TDatabasePDG.h>
14#include <Math/Vector3D.h>
28 setDescription(
"Synchronize parts of the events post merge/embedding. Used in the signal embedding pipeline. Uses kinematic information for the tag / simulated decay stored in eventExtraInfo.");
30 addParam(
"Mixing",
m_mixing,
"Mixing (true) or embedding (false) corrections",
false);
47 ROOT::Math::Rotation3D rot;
63 ROOT::Math::XYZVector sec3v = ROOT::Math::XYZVector(
m_eventExtraInfo->getExtraInfo(
"PX"),
73 const double mB = TDatabasePDG::Instance()->GetParticle(iPDG)->Mass();
74 double E =
sqrt(mB * mB + sec3v.Mag2());
75 ROOT::Math::PxPyPzEVector sec4v(sec3v.X(), sec3v.Y(), sec3v.Z(),
E);
76 ROOT::Math::PxPyPzEVector secCMS = T.labToCms(sec4v);
79 ROOT::Math::PxPyPzEVector secRoeCMS(-secCMS.X(), -secCMS.Y(), -secCMS.Z(), secCMS.E());
80 ROOT::Math::PxPyPzEVector sec4roe = T.cmsToLab(secRoeCMS);
83 sec3v.SetXYZ(sec4roe.X(), sec4roe.Y(), sec4roe.Z());
87 ROOT::Math::XYZVector cross = tag3v.Unit().Cross(sec3v.Unit());
88 double dot = tag3v.Unit().Dot(sec3v.Unit());
91 rot = ROOT::Math::Rotation3D(ROOT::Math::AxisAngle(cross, -acos(
dot)));
94 ROOT::Math::XYZVector test = rot * sec3v;
95 double smallValue = 1e-12;
96 if ((std::abs(sin(test.Phi() - tag3v.Phi())) > smallValue) or (std::abs(test.Theta() - tag3v.Theta()) > smallValue)) {
97 B2ERROR(
"Loss of accuracy during rotation" <<
LogVar(
"Delta phi", std::abs(sin(test.Phi() - tag3v.Phi())))
98 <<
LogVar(
"Delta Theta", std::abs(test.Theta() - tag3v.Theta())));
101 B2ERROR(
"No momentum information provided for the tag/simulated particle list, can not update tracks");
116 const ROOT::Math::XYZVector origSpot(xv2, yv2, zv2);
120 const ROOT::Math::XYZVector beamSpot = beamSpotDB->getIPPosition();
128 for (
short int i :
m_tracks[idxTr]->getValidIndices()) {
129 auto t_idx =
m_tracks[idxTr]->m_trackFitIndices[i];
131 short charge =
m_trackFits[t_idx]->getChargeSign();
134 helixO.passiveMoveBy(origSpot - beamSpot);
137 ROOT::Math::XYZVector position = helixO.getPerigee();
138 ROOT::Math::XYZVector momentum = rot * helixO.getMomentum(bz);
140 Helix helix(position, momentum, charge, bz);
155 B2ERROR(
"No vertex info, can not update tracks");
181 for (
short int i :
m_tracks[idxTr]->getValidIndices()) {
182 auto t_idx =
m_tracks[idxTr]->m_trackFitIndices[i];
186 helix.passiveMoveBy(vertexEmb);
188 ROOT::Math::XYZVector mom =
m_trackFits[t_idx]->getMomentum();
189 short charge =
m_trackFits[t_idx]->getChargeSign();
192 ROOT::Math::XYZVector momTag = rot * mom;
199 Helix h(vertexTag, momTag, charge, bz);
213 B2ERROR(
"No track parameters info, can not update tracks");
224 ROOT::Math::XYZVector pos =
m_eclclusters[idxCl]->getClusterPosition();
225 ROOT::Math::XYZVector newPos = rot * pos;
static ROOT::Math::XYZVector getFieldInTesla(const ROOT::Math::XYZVector &pos)
return the magnetic field at a given position in Tesla.
Class for accessing objects in the database.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
StoreObjPtr< EventExtraInfo > m_eventExtraInfo_orig
Event extra info original.
bool m_isCharged
B+ or B0.
ROOT::Math::Rotation3D tag_vertex_rotation()
Helper function to determine rotation matrix.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
StoreArray< Track > m_tracks
tracks
StoreArray< TrackFitResult > m_trackFits
track fits
PostMergeUpdaterModule()
Constructor.
StoreObjPtr< EventExtraInfo > m_mergedArrayIndices
indices where the StoreArrays were merged
void cluster_rotation(const ROOT::Math::Rotation3D &rot)
Rotate clusters.
StoreObjPtr< EventExtraInfo > m_eventExtraInfo
Event extra info.
StoreArray< ECLCluster > m_eclclusters
StoreArray of ECLCluster.
bool m_mixing
Fix to common vertex.
static const unsigned int iZ0
Index for z0.
static const unsigned int iTanLambda
Index tan lambda.
static const unsigned int iD0
Index for d0.
static const unsigned int iOmega
Index for omega.
static const unsigned int iPhi0
Index for phi0.
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
double sqrt(double a)
sqrt for double
T dot(GeneralVector< T > a, GeneralVector< T > b)
dot product of two general vectors
Abstract base class for different kinds of events.