9#include <analysis/modules/BtubeCreator/BtubeCreatorModule.h>
12#include <framework/gearbox/Unit.h>
13#include <framework/gearbox/Const.h>
14#include <framework/logging/Logger.h>
17#include <analysis/dataobjects/Particle.h>
18#include <analysis/DecayDescriptor/ParticleListName.h>
21#include <analysis/utility/PCmsLabTransform.h>
22#include <analysis/utility/ParticleCopy.h>
25#include <framework/geometry/BFieldManager.h>
46 setDescription(
"BtubeCreator : This module creates Btube object, an object geometrically similar to a very long ellipsoid along a particular direction and can be used as a constraint in vertexing B particles. Upsilon4S decays to two Bs. the user selects one B with a ^ in decaystring. The order of daughters in reconstructdecay of Upsilon4S and this decaystring should be same. Using selected B as reference, the module calculates the direction in which the other B should fly and constructs a Btube object along that direction. In semi-leptonic analyses, the selected B is usually the fully reconstructed one, while for time dependent studies, the selected B is usually signal B which can be partially reconstructed");
52 "decay string of the mother particle, the selected daughter specifies which daughter will be used as reference to create Btube",
55 "whether to associate the Btube with the selected B",
71 B2INFO(
"BtubeCreator : magnetic field = " <<
m_Bfield);
78 B2ERROR(
"BtubeCreatorModule: invalid decay string" <<
m_decayString);
81 B2ERROR(
"BtubeCreatorModule: decay string should contain only two daughters");
88 std::vector<unsigned int> toRemove;
89 unsigned int n =
m_plist->getListSize();
91 for (
unsigned i = 0; i < n; i++) {
94 std::vector<Particle*> daughtervec = particle->
getDaughters();
96 if (selParticles.size() > 1) {
97 B2FATAL(
"Please select only one daughter which will be used as reference to create Btube");
101 if ((daughtervec.at(0))->getArrayIndex() == (selParticles.at(0))->getArrayIndex()) selectindex = 0 ;
107 B2FATAL(
"Please perform a vertex fit of the selected B before calling this module");
115 B2DEBUG(10,
"tubecreator B decay vertex: ");
116 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << tubecreatorBCopy->
getVertex().X() <<
"," << std::fixed <<
118 20) << tubecreatorBCopy->
getVertex().Y() <<
"," << std::fixed << std::setprecision(20) << tubecreatorBCopy->
getVertex().Z() <<
"}");
148 Eigen::Matrix<double, 3, 1> tubecreatorBOriginpos(tubecreatorBCopy->
getVertex().X(), tubecreatorBCopy->
getVertex().Y(),
150 ROOT::Math::PxPyPzEVector v4Final = tubecreatorBCopy->
get4Vector();
153 ROOT::Math::PxPyPzEVector vecNew(-1 * vec.Px(), -1 * vec.Py(), -1 * vec.Pz(), vec.E());
154 ROOT::Math::PxPyPzEVector v4FinalNew = T.
rotateCmsToLab() * vecNew;
157 B2DEBUG(10,
"beamspot center :");
158 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) <<
m_BeamSpotCenter.
X() <<
"," << std::fixed << std::setprecision(
160 B2DEBUG(10,
"beamspot cov :");
162 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) <<
m_beamSpotCov(0,
163 0) <<
"," << std::fixed << std::setprecision(20) <<
m_beamSpotCov(0,
164 1) <<
"," << std::fixed << std::setprecision(20) <<
m_beamSpotCov(0, 2) <<
"},");
165 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) <<
m_beamSpotCov(1,
166 0) <<
"," << std::fixed << std::setprecision(20) <<
m_beamSpotCov(1,
167 1) <<
"," << std::fixed << std::setprecision(20) <<
m_beamSpotCov(1, 2) <<
"},");
168 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) <<
m_beamSpotCov(2,
169 0) <<
"," << std::fixed << std::setprecision(20) <<
m_beamSpotCov(2,
170 1) <<
"," << std::fixed << std::setprecision(20) <<
m_beamSpotCov(2, 2) <<
"}");
178 double theta = v4FinalNew.Theta();
179 double phi = v4FinalNew.Phi();
181 double st = TMath::Sin(theta);
182 double ct = TMath::Cos(theta);
183 double sp = TMath::Sin(phi);
184 double cp = TMath::Cos(phi);
186 TMatrix r2z(3, 3); r2z(2, 2) = 1;
187 r2z(0, 0) = cp; r2z(0, 1) = -1 * sp;
188 r2z(1, 0) = sp; r2z(1, 1) = cp;
190 TMatrix r2y(3, 3); r2y(1, 1) = 1;
191 r2y(0, 0) = ct; r2y(0, 2) = st;
192 r2y(2, 0) = -1 * st; r2y(2, 2) = ct;
194 TMatrix r2(3, 3); r2.Mult(r2z, r2y);
195 TMatrix r2t(3, 3); r2t.Transpose(r2);
197 TMatrix longerror(3, 3); longerror(2, 2) = 1000;
198 TMatrix longerror_temp(3, 3); longerror_temp.Mult(r2, longerror);
199 TMatrix longerrorRotated(3, 3); longerrorRotated.Mult(longerror_temp, r2t);
203 pvNew += longerrorRotated;
205 TMatrixFSym errNew(7);
206 errNew.SetSub(0, 0, pp);
207 errNew.SetSub(4, 4, pvNew);
210 TMatrixFSym tubeMat(3);
211 tubeMat.SetSub(0, 0, pvNew);
213 TMatrixFSym tubeMatCenterError(3);
214 tubeMatCenterError.SetSub(0, 0, pv);
217 B2DEBUG(10,
"B origin error matrix : ");
218 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << pv(0, 0) <<
"," << std::fixed << std::setprecision(20) << pv(0,
219 1) <<
"," << std::fixed << std::setprecision(20) << pv(0, 2) <<
"},");
220 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << pv(1, 0) <<
"," << std::fixed << std::setprecision(20) << pv(1,
221 1) <<
"," << std::fixed << std::setprecision(20) << pv(1, 2) <<
"},");
222 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << pv(2, 0) <<
"," << std::fixed << std::setprecision(20) << pv(2,
223 1) <<
"," << std::fixed << std::setprecision(20) << pv(2, 2) <<
"}");
225 B2DEBUG(10,
"B tube error matrix : ");
226 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << pvNew(0, 0) <<
"," << std::fixed << std::setprecision(20) << pvNew(0,
227 1) <<
"," << std::fixed << std::setprecision(20) << pvNew(0, 2) <<
"},");
228 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << pvNew(1, 0) <<
"," << std::fixed << std::setprecision(20) << pvNew(1,
229 1) <<
"," << std::fixed << std::setprecision(20) << pvNew(1, 2) <<
"},");
230 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << pvNew(2, 0) <<
"," << std::fixed << std::setprecision(20) << pvNew(2,
231 1) <<
"," << std::fixed << std::setprecision(20) << pvNew(2, 2) <<
"}");
233 B2DEBUG(10,
"B origin ");
234 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << tubecreatorBCopy->
getVertex().X() <<
"," << std::fixed <<
236 20) << tubecreatorBCopy->
getVertex().Y() <<
"," << std::fixed << std::setprecision(20) << tubecreatorBCopy->
getVertex().Z() <<
"}");
253 addextrainfos(tubecreatorB, tubecreatorBCopy, pvNew, v4FinalNew);
261 m_plist->removeParticles(toRemove);
272 int nvert = rsg.
fit(
"avf");
278 }
else {
return false;}
284 daughter->writeExtraInfo(
"TubePosX", copy->getVertex().X());
285 daughter->writeExtraInfo(
"TubePosY", copy->getVertex().Y());
286 daughter->writeExtraInfo(
"TubePosZ", copy->getVertex().Z());
288 daughter->writeExtraInfo(
"TubeCov00", mat(0, 0));
289 daughter->writeExtraInfo(
"TubeCov01", mat(0, 1));
290 daughter->writeExtraInfo(
"TubeCov02", mat(0, 2));
291 daughter->writeExtraInfo(
"TubeCov10", mat(1, 0));
292 daughter->writeExtraInfo(
"TubeCov11", mat(1, 1));
293 daughter->writeExtraInfo(
"TubeCov12", mat(1, 2));
294 daughter->writeExtraInfo(
"TubeCov20", mat(2, 0));
295 daughter->writeExtraInfo(
"TubeCov21", mat(2, 1));
296 daughter->writeExtraInfo(
"TubeCov22", mat(2, 2));
298 daughter->writeExtraInfo(
"TubeDirX", (TLV.Px() / TLV.P()));
299 daughter->writeExtraInfo(
"TubeDirY", (TLV.Py() / TLV.P()));
300 daughter->writeExtraInfo(
"TubeDirZ", (TLV.Pz() / TLV.P()));
301 daughter->writeExtraInfo(
"TubeB_p_estimated", TLV.P());
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType X() const
access variable X (= .at(0) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
static ROOT::Math::XYZVector getFieldInTesla(const ROOT::Math::XYZVector &pos)
return the magnetic field at a given position in Tesla.
TMatrixDSym m_beamSpotCov
Beam spot covariance matrix.
virtual void initialize() override
declare data store elements
StoreArray< Btube > m_tubeArray
the (output) array of Btube objects
virtual void event() override
process event
std::string m_decayString
specifies which daughter particles will be used as reference to create Btube
std::string m_listName
name of particle list
B2Vector3D m_BeamSpotCenter
Beam spot position.
BtubeCreatorModule()
Constructor: Sets the description, the properties and the parameters of the module.
DBObjPtr< BeamSpot > m_beamSpotDB
Beam spot database object.
bool doVertexFit(Particle *p)
Main steering routine.
double m_confidenceLevel
required fit confidence level
DecayDescriptor m_decaydescriptor
Decay descriptor of decays to look for.
void addextrainfos(Particle *daughter, Particle *copy, TMatrix mat, ROOT::Math::PxPyPzEVector TLV)
fills extrainfos to the particle
double m_Bfield
magnetic field from data base
StoreObjPtr< ParticleList > m_plist
the input particle list
bool m_verbose
run fit with a lot of B2INFOs for debugging
bool m_associateBtubeToBselected
whether to associate the Btube with the selected B
For each MCParticle with hits in the CDC, this class stores some summarising information on those hit...
void setTubeCenterErrorMatrix(const TMatrixFSym &tubecentererrormatrix)
Sets Btube Center Error Matrix.
void setTubeCenter(const Eigen::Matrix< double, 3, 1 > &tubecenter)
Sets Btube Center.
void setTubeMatrix(const TMatrixFSym &tubematrix)
Sets Btube Matrix.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
int getNDaughters() const
return number of direct daughters.
std::vector< const Particle * > getSelectionParticles(const Particle *particle)
Get a vector of pointers with selected daughters in the decay tree.
void setDescription(const std::string &description)
Sets the description of the module.
Class to store reconstructed particles.
TMatrixFSym getVertexErrorMatrix() const
Returns the 3x3 position error sub-matrix.
void writeExtraInfo(const std::string &name, const double value)
Sets the user defined extraInfo.
void setVertex(const ROOT::Math::XYZVector &vertex)
Sets position (decay vertex)
double getPValue() const
Returns chi^2 probability of fit if done or -1.
ROOT::Math::XYZVector getVertex() const
Returns vertex position (POCA for charged, IP for neutral FS particles)
std::vector< Belle2::Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
ROOT::Math::PxPyPzEVector get4Vector() const
Returns Lorentz vector.
TMatrixFSym getMomentumErrorMatrix() const
Returns the 4x4 momentum error matrix.
void setMomentumVertexErrorMatrix(const TMatrixFSym &errMatrix)
Sets 7x7 error matrix.
void setPValue(double pValue)
Sets chi^2 probability of fit.
TMatrixFSym getMomentumVertexErrorMatrix() const
Returns 7x7 error matrix.
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
Accessor to arrays stored in the data store.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
static void initialize(int verbosity=1, double MagneticField=1.5)
Set everything up so everything needed for vertex fitting is there.
static RaveSetup * getInstance()
get the pointer to the instance to get/set any of options stored in RaveSetup
void setBeamSpot(const B2Vector3D &beamSpot, const TMatrixDSym &beamSpotCov)
The beam spot position and covariance is known you can set it here so that and a vertex in the beam s...
void reset()
frees memory allocated by initialize().
The RaveVertexFitter class is part of the RaveInterface together with RaveSetup.
int fit(std::string options="default")
do the vertex fit with all tracks previously added with the addTrack or addMother function.
void addTrack(const Particle *const aParticlePtr)
add a track (in the format of a Belle2::Particle) to set of tracks that should be fitted to a vertex
void updateDaughters()
update the Daughters particles
double getPValue(VecSize vertexId=0) const
get the p value of the fitted vertex.
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.
Particle * copyParticle(const Particle *original)
Function takes argument Particle and creates a copy of it and copies of all its (grand-)^n-daughters.
Abstract base class for different kinds of events.