11 #include <analysis/modules/BtubeCreator/BtubeCreatorModule.h>
14 #include <framework/gearbox/Unit.h>
15 #include <framework/gearbox/Const.h>
16 #include <framework/logging/Logger.h>
19 #include <analysis/dataobjects/Particle.h>
20 #include <analysis/dataobjects/ParticleList.h>
21 #include <analysis/DecayDescriptor/ParticleListName.h>
24 #include <analysis/utility/PCmsLabTransform.h>
25 #include <analysis/utility/ParticleCopy.h>
28 #include <framework/geometry/BFieldManager.h>
49 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 addParam(
"listName", m_listName,
"name of mother particle list",
string(
""));
53 addParam(
"decayString", m_decayString,
54 "decay string of the mother particle, the selected daughter specifies which daughter will be used as reference to create Btube",
56 addParam(
"associateBtubeToBselected", m_associateBtubeToBselected,
57 "whether to associate the Btube with the selected B",
59 addParam(
"verbosity", m_verbose,
"print statements",
true);
62 void BtubeCreatorModule::initialize()
65 m_Bfield = BFieldManager::getField(TVector3(0, 0, 0)).Z() / Unit::T;
67 m_BeamSpotCenter = m_beamSpotDB->getIPPosition();
68 m_beamSpotCov.ResizeTo(3, 3);
69 m_beamSpotCov = m_beamSpotDB->getCovVertex();
70 B2INFO(
"BtubeCreator : magnetic field = " << m_Bfield);
72 tubeArray.registerInDataStore();
73 particles.registerRelationTo(tubeArray);
75 bool valid = m_decaydescriptor.init(m_decayString);
77 B2ERROR(
"BtubeCreatorModule: invalid decay string" << m_decayString);
78 int nProducts = m_decaydescriptor.getNDaughters();
80 B2ERROR(
"BtubeCreatorModule: decay string should contain only two daughters");
83 void BtubeCreatorModule::event()
87 B2ERROR(
"ParticleList " << m_listName <<
" not found");
91 analysis::RaveSetup::initialize(1, m_Bfield);
93 std::vector<unsigned int> toRemove;
94 unsigned int n = plist->getListSize();
96 for (
unsigned i = 0; i < n; i++) {
97 Particle* particle = plist->getParticle(i);
99 std::vector<Particle*> daughtervec = particle->getDaughters();
100 std::vector<const Particle*> selParticles = m_decaydescriptor.getSelectionParticles(particle);
101 if (selParticles.size() > 1) {
102 B2FATAL(
"Please select only one daughter which will be used as reference to create Btube");
106 if ((daughtervec.at(0))->getArrayIndex() == (selParticles.at(0))->getArrayIndex()) selectindex = 0 ;
108 Particle* tubecreatorB =
const_cast<Particle*
>(particle->getDaughter(selectindex));
109 Particle* otherB =
const_cast<Particle*
>(particle->getDaughter(1 - selectindex));
112 B2FATAL(
"Please perform a vertex fit of the selected B before calling this module");
117 Particle* tubecreatorBCopy = ParticleCopy::copyParticle(tubecreatorB);
120 B2DEBUG(10,
"tubecreator B decay vertex: ");
121 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << tubecreatorBCopy->
getVertex()[0] <<
"," << std::fixed <<
123 20) << tubecreatorBCopy->
getVertex()[1] <<
"," << std::fixed << std::setprecision(20) << tubecreatorBCopy->
getVertex()[2] <<
"}");
126 bool ok0 = doVertexFit(tubecreatorBCopy);
129 particle->setVertex(tubecreatorBCopy->
getVertex());
150 Eigen::Matrix<double, 3, 1> tubecreatorBOriginpos(tubecreatorBCopy->
getVertex()[0], tubecreatorBCopy->
getVertex()[1],
152 TLorentzVector v4Final = tubecreatorBCopy->
get4Vector();
155 TLorentzVector vecNew(-1 * vec.Px(), -1 * vec.Py(), -1 * vec.Pz(), vec.E());
159 B2DEBUG(10,
"beamspot center :");
160 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << m_BeamSpotCenter.X() <<
"," << std::fixed << std::setprecision(
161 20) << m_BeamSpotCenter.Y() <<
"," << std::fixed << std::setprecision(20) << m_BeamSpotCenter.Z() <<
"}");
162 B2DEBUG(10,
"beamspot cov :");
164 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << m_beamSpotCov(0,
165 0) <<
"," << std::fixed << std::setprecision(20) << m_beamSpotCov(0,
166 1) <<
"," << std::fixed << std::setprecision(20) << m_beamSpotCov(0, 2) <<
"},");
167 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << m_beamSpotCov(1,
168 0) <<
"," << std::fixed << std::setprecision(20) << m_beamSpotCov(1,
169 1) <<
"," << std::fixed << std::setprecision(20) << m_beamSpotCov(1, 2) <<
"},");
170 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << m_beamSpotCov(2,
171 0) <<
"," << std::fixed << std::setprecision(20) << m_beamSpotCov(2,
172 1) <<
"," << std::fixed << std::setprecision(20) << m_beamSpotCov(2, 2) <<
"}");
180 double theta = v4FinalNew.Theta();
181 double phi = v4FinalNew.Phi();
183 double st = TMath::Sin(theta);
184 double ct = TMath::Cos(theta);
185 double sp = TMath::Sin(phi);
186 double cp = TMath::Cos(phi);
188 TMatrix r2z(3, 3); r2z(2, 2) = 1;
189 r2z(0, 0) = cp; r2z(0, 1) = -1 * sp;
190 r2z(1, 0) = sp; r2z(1, 1) = cp;
192 TMatrix r2y(3, 3); r2y(1, 1) = 1;
193 r2y(0, 0) = ct; r2y(0, 2) = st;
194 r2y(2, 0) = -1 * st; r2y(2, 2) = ct;
196 TMatrix r2(3, 3); r2.Mult(r2z, r2y);
197 TMatrix r2t(3, 3); r2t.Transpose(r2);
199 TMatrix longerror(3, 3); longerror(2, 2) = 1000;
200 TMatrix longerror_temp(3, 3); longerror_temp.Mult(r2, longerror);
201 TMatrix longerrorRotated(3, 3); longerrorRotated.Mult(longerror_temp, r2t);
205 pvNew += longerrorRotated;
207 TMatrixFSym errNew(7);
208 errNew.SetSub(0, 0, pp);
209 errNew.SetSub(4, 4, pvNew);
212 TMatrixFSym tubeMat(3);
213 tubeMat.SetSub(0, 0, pvNew);
215 TMatrixFSym tubeMatCenterError(3);
216 tubeMatCenterError.SetSub(0, 0, pv);
219 B2DEBUG(10,
"B origin error matrix : ");
220 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << pv(0, 0) <<
"," << std::fixed << std::setprecision(20) << pv(0,
221 1) <<
"," << std::fixed << std::setprecision(20) << pv(0, 2) <<
"},");
222 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << pv(1, 0) <<
"," << std::fixed << std::setprecision(20) << pv(1,
223 1) <<
"," << std::fixed << std::setprecision(20) << pv(1, 2) <<
"},");
224 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << pv(2, 0) <<
"," << std::fixed << std::setprecision(20) << pv(2,
225 1) <<
"," << std::fixed << std::setprecision(20) << pv(2, 2) <<
"}");
227 B2DEBUG(10,
"B tube error matrix : ");
228 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << pvNew(0, 0) <<
"," << std::fixed << std::setprecision(20) << pvNew(0,
229 1) <<
"," << std::fixed << std::setprecision(20) << pvNew(0, 2) <<
"},");
230 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << pvNew(1, 0) <<
"," << std::fixed << std::setprecision(20) << pvNew(1,
231 1) <<
"," << std::fixed << std::setprecision(20) << pvNew(1, 2) <<
"},");
232 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << pvNew(2, 0) <<
"," << std::fixed << std::setprecision(20) << pvNew(2,
233 1) <<
"," << std::fixed << std::setprecision(20) << pvNew(2, 2) <<
"}");
235 B2DEBUG(10,
"B origin ");
236 B2DEBUG(10,
"{" << std::fixed << std::setprecision(20) << tubecreatorBCopy->
getVertex()[0] <<
"," << std::fixed <<
238 20) << tubecreatorBCopy->
getVertex()[1] <<
"," << std::fixed << std::setprecision(20) << tubecreatorBCopy->
getVertex()[2] <<
"}");
243 Btube* tubeconstraint = tubeArray.appendNew(
Btube());
244 if (m_associateBtubeToBselected) {
254 if (m_associateBtubeToBselected) {
255 addextrainfos(tubecreatorB, tubecreatorBCopy, pvNew, v4FinalNew);
257 addextrainfos(otherB, tubecreatorBCopy, pvNew, v4FinalNew);
260 if (!ok0) toRemove.push_back(particle->getArrayIndex());
262 plist->removeParticles(toRemove);
264 analysis::RaveSetup::getInstance()->reset();
267 bool BtubeCreatorModule::doVertexFit(
Particle* mother)
269 analysis::RaveSetup::getInstance()->setBeamSpot(m_BeamSpotCenter, m_beamSpotCov);
273 int nvert = rsg.
fit(
"avf");
277 }
else {
return false;}
281 void BtubeCreatorModule::addextrainfos(
Particle* daughter,
Particle* copy, TMatrix mat, TLorentzVector TLV)
283 daughter->writeExtraInfo(
"TubePosX", copy->getVertex()[0]);
284 daughter->writeExtraInfo(
"TubePosY", copy->getVertex()[1]);
285 daughter->writeExtraInfo(
"TubePosZ", copy->getVertex()[2]);
287 daughter->writeExtraInfo(
"TubeCov00", mat(0, 0));
288 daughter->writeExtraInfo(
"TubeCov01", mat(0, 1));
289 daughter->writeExtraInfo(
"TubeCov02", mat(0, 2));
290 daughter->writeExtraInfo(
"TubeCov10", mat(1, 0));
291 daughter->writeExtraInfo(
"TubeCov11", mat(1, 1));
292 daughter->writeExtraInfo(
"TubeCov12", mat(1, 2));
293 daughter->writeExtraInfo(
"TubeCov20", mat(2, 0));
294 daughter->writeExtraInfo(
"TubeCov21", mat(2, 1));
295 daughter->writeExtraInfo(
"TubeCov22", mat(2, 2));
297 daughter->writeExtraInfo(
"TubeDirX", TLV.Px());
298 daughter->writeExtraInfo(
"TubeDirY", TLV.Py());
299 daughter->writeExtraInfo(
"TubeDirZ", TLV.Pz());