22 #include <trackbase_historic/SvtxVertex.h>
23 #include <trackbase_historic/SvtxVertexMap.h>
24 #include <trackbase_historic/SvtxVertexMap_v1.h>
25 #include <trackbase_historic/SvtxVertex_v1.h>
27 #include <phgenfit/Fitter.h>
28 #include <phgenfit/Measurement.h>
29 #include <phgenfit/PlanarMeasurement.h>
30 #include <phgenfit/SpacepointMeasurement.h>
31 #include <phgenfit/Track.h>
45 #include <phfield/PHFieldUtility.h>
46 #include <phgeom/PHGeomUtility.h>
48 #include <GenFit/AbsMeasurement.h>
49 #include <GenFit/EventDisplay.h>
50 #include <GenFit/Exception.h>
51 #include <GenFit/GFRaveConverters.h>
52 #include <GenFit/GFRaveTrackParameters.h>
53 #include <GenFit/GFRaveVertex.h>
54 #include <GenFit/GFRaveVertexFactory.h>
55 #include <GenFit/KalmanFitterInfo.h>
56 #include <GenFit/MeasuredStateOnPlane.h>
57 #include <GenFit/RKTrackRep.h>
59 #include <GenFit/TrackPoint.h>
62 #include <rave/ConstantMagneticField.h>
63 #include <rave/VacuumPropagator.h>
64 #include <rave/VertexFactory.h>
66 #include <TClonesArray.h>
67 #include <TMatrixDSymfwd.h>
68 #include <TMatrixFfwd.h>
70 #include <TMatrixTSym.h>
71 #include <TMatrixTUtils.h>
72 #include <TRotation.h>
75 #include <TVectorDfwd.h>
94 #define LogDebug(exp) std::cout << "DEBUG: " << __FILE__ << ": " << __LINE__ << ": " << exp << std::endl
95 #define LogError(exp) std::cout << "ERROR: " << __FILE__ << ": " << __LINE__ << ": " << exp << std::endl
96 #define LogWarning(exp) std::cout << "WARNING: " << __FILE__ << ": " << __LINE__ << ": " << exp << std::endl
98 #define WILD_FLOAT -9999.
100 #define _DEBUG_MODE_ 0
112 rave::ConstantMagneticField mfield(0., 0., 0.);
113 _factory =
new rave::VertexFactory(mfield, rave::VacuumPropagator(),
116 IdGFTrackStateMap_.clear();
127 void findVertices(std::vector<genfit::GFRaveVertex*>*
vertices,
128 const std::vector<genfit::Track*>&
tracks,
const bool use_beamspot =
false)
137 IdGFTrackStateMap_, 0),
143 std::cerr << e.
what();
147 void findVertices(std::vector<genfit::GFRaveVertex*>*
vertices,
148 const std::vector<genfit::Track*>&
tracks,
149 std::vector<genfit::MeasuredStateOnPlane*>& GFStates,
150 const bool use_beamspot =
false)
159 IdGFTrackStateMap_, 0),
165 std::cerr << e.
what();
172 for (
unsigned int i = 0;
i < IdGFTrackStateMap_.size(); ++
i)
173 delete IdGFTrackStateMap_[
i].state_;
175 IdGFTrackStateMap_.clear();
190 , _over_write_svtxtrackmap(
true)
191 , _over_write_svtxvertexmap(
true)
192 , _fit_primary_tracks(
false)
193 , _use_truth_vertex(
false)
195 , _track_fitting_alg_name(
"DafRef")
196 , _primary_pid_guess(2212)
198 , _vertex_min_ndf(20)
199 , _vertex_finder(NULL)
200 , _vertexing_method(
"avf-smoothing:1")
205 , _trackmap_refit(NULL)
206 , _primary_trackmap(NULL)
207 , _vertexmap_refit(NULL)
209 , _eval_outname(
"TpcPrototypeGenFitTrkFitter_eval.root")
212 , _tca_particlemap(NULL)
214 , _tca_trackmap(NULL)
215 , _tca_tpctrackmap(nullptr)
216 , _tca_vertexmap(NULL)
217 , _tca_trackmap_refit(NULL)
218 , _tca_primtrackmap(NULL)
219 , _tca_vertexmap_refit(NULL)
220 , _do_evt_display(
false)
304 std::cout <<
PHWHERE <<
"Events processed: " <<
_event << std::endl;
313 vector<genfit::Track*> rf_gf_tracks;
314 rf_gf_tracks.clear();
316 vector<std::shared_ptr<PHGenFit::Track> > rf_phgf_tracks;
319 map<unsigned int, unsigned int> svtxtrack_genfittrack_map;
331 cout <<
" process SVTXTrack " << iter->first << endl;
340 std::shared_ptr<PHGenFit::Track> rf_phgf_track =
ReFitTrack(topNode, svtx_track);
344 svtxtrack_genfittrack_map[svtx_track->
get_id()] =
345 rf_phgf_tracks.size();
346 rf_phgf_tracks.push_back(rf_phgf_track);
348 rf_gf_tracks.push_back(rf_phgf_track->getGenFitTrack());
363 set<TrkrDefs::cluskey> cluster_ids;
366 for (
auto iter = cluster_range.first; iter != cluster_range.second; ++iter)
368 cluster_ids.insert(iter->first);
378 cluster_ids.erase(*iter);
383 vector<genfit::Track*> copy;
391 for (
const auto cluster_id : cluster_ids)
397 std::shared_ptr<PHGenFit::Track> cluster_holder =
DisplayCluster(cluster);
398 if (cluster_holder.get())
399 copy.push_back(
new genfit::Track(*cluster_holder->getGenFitTrack()));
407 std::shared_ptr<PHGenFit::Track> rf_phgf_track = NULL;
409 if (svtxtrack_genfittrack_map.find(iter->second->get_id()) != svtxtrack_genfittrack_map.end())
411 unsigned int itrack =
412 svtxtrack_genfittrack_map[iter->second->get_id()];
413 rf_phgf_track = rf_phgf_tracks[itrack];
432 std::shared_ptr<SvtxTrack> rf_track =
MakeSvtxTrack(iter->second, rf_phgf_track,
439 auto key = iter->first;
469 auto key = iter->first;
481 rf_phgf_tracks.clear();
489 cout << __LINE__ << endl;
623 _eval_tree =
new TTree(
"T",
"TpcPrototypeGenFitTrkFitter Evaluation");
679 "PHCompositeNode",
"DST"));
682 cerr <<
PHWHERE <<
"DST Node missing, doing nothing." << endl;
689 "PHCompositeNode",
"SVTX"));
695 cout <<
"SVTX node added" << endl;
705 cout <<
"Svtx/SvtxTrackMapRefit node added" << endl;
714 tb_node->
addNode(primary_tracks_node);
716 cout <<
"Svtx/PrimaryTrackMap node added" << endl;
724 tb_node->
addNode(vertexes_node);
726 cout <<
"Svtx/SvtxVertexMapRefit node added" << endl;
728 else if (!findNode::getClass<SvtxVertexMap>(topNode,
"SvtxVertexMap"))
733 tb_node->
addNode(vertexes_node);
735 cout <<
"Svtx/SvtxVertexMap node added" << endl;
760 _clustermap = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
763 cout <<
PHWHERE <<
" TRKR_CLUSTER node not found on node tree"
769 _trackmap = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
772 cout <<
PHWHERE <<
" SvtxTrackMap node not found on node tree"
778 _vertexmap = findNode::getClass<SvtxVertexMap>(topNode,
"SvtxVertexMap");
781 cout <<
PHWHERE <<
" SvtxVertexrMap node not found on node tree"
790 "SvtxTrackMapRefit");
793 cout <<
PHWHERE <<
" SvtxTrackMapRefit node not found on node tree"
806 cout <<
PHWHERE <<
" PrimaryTrackMap node not found on node tree"
816 "SvtxVertexMapRefit");
819 cout <<
PHWHERE <<
" SvtxVertexMapRefit node not found on node tree"
834 cout << __PRETTY_FUNCTION__ <<
": process cluster: ";
839 TVector3 seed_mom(100, 0, 0);
840 TVector3 seed_pos(0, 0, 0);
841 TMatrixDSym seed_cov(6);
842 for (
int i = 0;
i < 6;
i++)
844 for (
int j = 0;
j < 6;
j++)
846 seed_cov[
i][
j] = 100.;
851 std::vector<PHGenFit::Measurement*> measurements;
857 seed_mom.SetPhi(
pos.Phi());
858 seed_mom.SetTheta(
pos.Theta());
865 for (
int radial_shift = -1; radial_shift <= 1; ++radial_shift)
867 const double new_radial =
pos.Perp() + radial_shift * 0.1;
868 TVector3 new_pos(
pos);
869 new_pos.SetPerp(new_radial);
887 cout <<
"Add meas layer " << layer <<
" cluskey " << cluster_key
889 <<
" pos.X " <<
pos.X() <<
" pos.Y " <<
pos.Y() <<
" pos.Z " <<
pos.Z()
890 <<
" n.X " <<
n.X() <<
" n.Y " <<
n.Y()
895 measurements.push_back(meas);
909 std::shared_ptr<PHGenFit::Track> track(
new PHGenFit::Track(rep, seed_pos, seed_mom,
913 track->addMeasurements(measurements);
926 cout << __PRETTY_FUNCTION__ <<
": failed cluster build: track->getChisq() " << track->get_chi2() <<
" get_ndf " << track->get_ndf()
927 <<
" mom.X " << track->get_mom().X()
928 <<
" mom.Y " << track->get_mom().Y()
929 <<
" mom.Z " << track->get_mom().Z()
937 cout <<
" track->getChisq() " << track->get_chi2() <<
" get_ndf " << track->get_ndf()
938 <<
" mom.X " << track->get_mom().X()
939 <<
" mom.Y " << track->get_mom().Y()
940 <<
" mom.Z " << track->get_mom().Z()
965 cerr <<
PHWHERE <<
" Input SvtxTrack is NULL!" << endl;
970 TVector3 seed_mom(100, 0, 0);
971 TVector3 seed_pos(0, 0, 0);
972 TMatrixDSym seed_cov(6);
973 for (
int i = 0;
i < 6;
i++)
975 for (
int j = 0;
j < 6;
j++)
977 seed_cov[
i][
j] = 100.;
982 std::vector<PHGenFit::Measurement*> measurements;
985 const double vertex_chi2_over_dnf_cut = 1000;
986 const double vertex_cov_element_cut = 10000;
993 bool is_vertex_cov_sane =
true;
994 for (
unsigned int i = 0;
i < 3;
i++)
995 for (
unsigned int j = 0;
j < 3;
j++)
1002 is_vertex_cov_sane =
false;
1006 if (is_vertex_cov_sane)
1010 measurements.push_back(meas);
1020 std::map<float, TrkrDefs::cluskey> m_r_cluster_id;
1028 float r = sqrt(x * x + y * y);
1029 m_r_cluster_id.insert(std::pair<float, TrkrDefs::cluskey>(r, cluster_key));
1031 if (
Verbosity() > 20) cout <<
" Layer " << layer_out <<
" cluster " << cluster_key <<
" radius " << r << endl;
1034 for (
auto iter = m_r_cluster_id.begin();
1035 iter != m_r_cluster_id.end();
1048 seed_mom.SetPhi(
pos.Phi());
1049 seed_mom.SetTheta(
pos.Theta());
1079 cout <<
"Add meas layer " << layer <<
" cluskey " << cluster_key
1081 <<
" pos.X " <<
pos.X() <<
" pos.Y " <<
pos.Y() <<
" pos.Z " <<
pos.Z()
1082 <<
" n.X " <<
n.X() <<
" n.Y " <<
n.Y()
1087 measurements.push_back(meas);
1101 std::shared_ptr<PHGenFit::Track> track(
new PHGenFit::Track(rep, seed_pos, seed_mom,
1103 track->addMeasurements(measurements);
1116 cout << __PRETTY_FUNCTION__ <<
" track->getChisq() " << track->get_chi2() <<
" get_ndf " << track->get_ndf()
1117 <<
" mom.X " << track->get_mom().X()
1118 <<
" mom.Y " << track->get_mom().Y()
1119 <<
" mom.Z " << track->get_mom().Z()
1127 cout <<
" track->getChisq() " << track->get_chi2() <<
" get_ndf " << track->get_ndf()
1128 <<
" mom.X " << track->get_mom().X()
1129 <<
" mom.Y " << track->get_mom().Y()
1130 <<
" mom.Z " << track->get_mom().Z()
1141 cout << __PRETTY_FUNCTION__ <<
" refit ";
1147 track->trackID = svtxtrack->
get_id();
1149 track->ndf = svtxtrack->
get_ndf();
1150 track->px = svtxtrack->
get_px();
1151 track->py = svtxtrack->
get_py();
1152 track->pz = svtxtrack->
get_pz();
1153 track->x = svtxtrack->
get_x();
1154 track->y = svtxtrack->
get_y();
1155 track->z = svtxtrack->
get_z();
1157 track->nCluster = 0;
1161 vector<TrkrCluster*> clusterLayer(track->nLayer,
nullptr);
1171 cout << __PRETTY_FUNCTION__ <<
" - layer sorting cluster ";
1176 assert(layer < track->nLayer);
1179 if (clusterLayer[layer])
1181 cout << __PRETTY_FUNCTION__ <<
" -WARNING- more than one cluster at layer " << layer <<
": " << endl;
1182 clusterLayer[
layer]->identify();
1187 clusterLayer[
layer] = cluster;
1188 track->nCluster += 1;
1192 if (track->nCluster < 4)
1198 seed_mom.SetMag(120);
1200 TVector3 seed_pos(svtxtrack->
get_x(), svtxtrack->
get_y(), svtxtrack->
get_z());
1201 TMatrixDSym seed_cov(6);
1202 for (
int i = 0;
i < 6;
i++)
1204 for (
int j = 0;
j < 6;
j++)
1206 seed_cov[
i][
j] = 100.;
1209 for (
int layerStudy = 0; layerStudy < track->nLayer; ++layerStudy)
1212 const static double errorScaleFactor = 100;
1214 if (clusterLayer[layerStudy] ==
nullptr)
continue;
1217 std::vector<PHGenFit::Measurement*> measurements;
1219 int indexStudy = -1;
1220 int currentIndex = 0;
1221 for (
const auto cluster : clusterLayer)
1223 if (!cluster)
continue;
1229 const double scale_this_layer = (layer == layerStudy) ? errorScaleFactor : 1;
1231 TVector3
pos(cluster->getPosition(0), cluster->getPosition(1), cluster->getPosition(2));
1237 TVector3
n(cluster->getPosition(0), cluster->getPosition(1), 0);
1240 cluster->getRPhiError() * scale_this_layer,
1241 cluster->getZError() * scale_this_layer);
1243 measurements.push_back(meas);
1245 if (layer == layerStudy) indexStudy = currentIndex;
1249 assert(indexStudy < track->nLayer);
1253 std::shared_ptr<PHGenFit::Track> phgf_track(
new PHGenFit::Track(rep, seed_pos, seed_mom,
1255 phgf_track->addMeasurements(measurements);
1261 cout << __PRETTY_FUNCTION__ <<
" track->getChisq() " << phgf_track->get_chi2() <<
" get_ndf " << phgf_track->get_ndf()
1262 <<
" mom.X " << phgf_track->get_mom().X()
1263 <<
" mom.Y " << phgf_track->get_mom().Y()
1264 <<
" mom.Z " << phgf_track->get_mom().Z()
1273 std::shared_ptr<const genfit::MeasuredStateOnPlane> gf_state = NULL;
1276 const genfit::Track* gftrack = phgf_track->getGenFitTrack();
1300 TVector3 extra_pos(gf_state->getPos());
1302 const TrkrCluster* cluster(clusterLayer[layerStudy]);
1304 TVector3 cluster_pos(cluster->getPosition(0), cluster->getPosition(1), cluster->getPosition(2));
1306 TVector3 n_dir(cluster->getPosition(0), cluster->getPosition(1), 0);
1308 TVector3 z_dir(0, 0, 1);
1309 TVector3 azimuth_dir(z_dir.Cross(n_dir));
1310 TVector3 pos_diff = cluster_pos - extra_pos;
1311 const double n_residual = pos_diff.Dot(n_dir);
1312 const double z_residual = pos_diff.Dot(z_dir);
1313 const double azimuth_residual = pos_diff.Dot(azimuth_dir);
1317 cout << __PRETTY_FUNCTION__;
1318 cout <<
" - layer " << layerStudy <<
" at index " << indexStudy;
1319 cout <<
" cluster @ " << cluster_pos.x() <<
", " << cluster_pos.y() <<
", " << cluster_pos.z();
1320 cout <<
" extrapolate to " << extra_pos.x() <<
", " << extra_pos.y() <<
", " << extra_pos.z();
1321 cout <<
", n_residual = " << n_residual;
1322 cout <<
", z_residual = " << z_residual;
1323 cout <<
", azimuth_residual = " << azimuth_residual;
1326 cout <<
"Cluster data which provide much more detailed information on the raw signals: "<<endl;
1330 assert(prototype_cluster);
1334 assert(abs(n_residual) < 1
e-4);
1336 (track->clusterKey)[layerStudy] = cluster->getClusKey();
1337 (track->clusterlayer)[layerStudy] = layerStudy;
1340 (track->clusterX)[layerStudy] = cluster->getPosition(0);
1341 (track->clusterY)[layerStudy] = cluster->getPosition(1);
1342 (track->clusterZ)[layerStudy] = cluster->getPosition(2);
1343 (track->clusterE)[layerStudy] = cluster->getAdc();
1344 (track->clusterSizePhi)[layerStudy] = cluster->getPhiSize();
1345 (track->clusterResidualPhi)[layerStudy] = azimuth_residual;
1346 (track->clusterProjectionPhi)[layerStudy] = extra_pos.Phi();
1347 (track->clusterResidualZ)[layerStudy] = z_residual;
1360 const std::shared_ptr<PHGenFit::Track>& phgf_track,
const SvtxVertex*
vertex)
1362 double chi2 = phgf_track->get_chi2();
1363 double ndf = phgf_track->get_ndf();
1365 TVector3 vertex_position(0, 0, 0);
1366 TMatrixF vertex_cov(3, 3);
1392 std::shared_ptr<genfit::MeasuredStateOnPlane> gf_state_beam_line_ca = NULL;
1395 gf_state_beam_line_ca = std::shared_ptr<genfit::MeasuredStateOnPlane>(phgf_track->extrapolateToLine(vertex_position,
1396 TVector3(0., 0., 1.)));
1403 if (!gf_state_beam_line_ca)
return NULL;
1412 double u = gf_state_beam_line_ca->getState()[3];
1413 double v = gf_state_beam_line_ca->getState()[4];
1415 double du2 = gf_state_beam_line_ca->getCov()[3][3];
1416 double dv2 = gf_state_beam_line_ca->getCov()[4][4];
1423 std::shared_ptr<SvtxTrack_v1> out_track = std::shared_ptr<SvtxTrack_v1>(
new SvtxTrack_v1(*static_cast<const SvtxTrack_v1*>(svtx_track)));
1425 out_track->set_dca2d(u);
1426 out_track->set_dca2d_error(sqrt(du2 + dvr2));
1428 std::shared_ptr<genfit::MeasuredStateOnPlane> gf_state_vertex_ca = NULL;
1431 gf_state_vertex_ca = std::shared_ptr<genfit::MeasuredStateOnPlane>(phgf_track->extrapolateToPoint(vertex_position));
1438 if (!gf_state_vertex_ca)
1444 TVector3 mom = gf_state_vertex_ca->getMom();
1445 TVector3
pos = gf_state_vertex_ca->getPos();
1446 TMatrixDSym
cov = gf_state_vertex_ca->get6DCov();
1452 u = gf_state_vertex_ca->getState()[3];
1453 v = gf_state_vertex_ca->getState()[4];
1455 du2 = gf_state_vertex_ca->getCov()[3][3];
1456 dv2 = gf_state_vertex_ca->getCov()[4][4];
1458 double dca3d = sqrt(u * u + v * v);
1459 double dca3d_error = sqrt(du2 + dv2 + dvr2 + dvz2);
1461 out_track->set_dca(dca3d);
1462 out_track->set_dca_error(dca3d_error);
1467 float dca3d_xy = NAN;
1468 float dca3d_z = NAN;
1469 float dca3d_xy_error = NAN;
1470 float dca3d_z_error = NAN;
1474 TMatrixF pos_in(3, 1);
1475 TMatrixF cov_in(3, 3);
1476 TMatrixF pos_out(3, 1);
1477 TMatrixF cov_out(3, 3);
1480 TMatrixDSym cov6(6, 6);
1482 gf_state_vertex_ca->get6DStateCov(state6, cov6);
1484 TVector3 vn(state6[3], state6[4], state6[5]);
1487 pos_in[0][0] = state6[0] - vertex_position.X();
1488 pos_in[1][0] = state6[1] - vertex_position.Y();
1489 pos_in[2][0] = state6[2] - vertex_position.Z();
1491 for (
int i = 0;
i < 3; ++
i)
1493 for (
int j = 0;
j < 3; ++
j)
1495 cov_in[
i][
j] = cov6[
i][
j] + vertex_cov[
i][
j];
1504 cout <<
" vn.X " << vn.X() <<
" vn.Y " << vn.Y() <<
" vn.Z " << vn.Z() << endl;
1505 cout <<
" pos_in.X " << pos_in[0][0] <<
" pos_in.Y " << pos_in[1][0] <<
" pos_in.Z " << pos_in[2][0] << endl;
1506 cout <<
" pos_out.X " << pos_out[0][0] <<
" pos_out.Y " << pos_out[1][0] <<
" pos_out.Z " << pos_out[2][0] << endl;
1509 dca3d_xy = pos_out[0][0];
1510 dca3d_z = pos_out[2][0];
1511 dca3d_xy_error = sqrt(cov_out[0][0]);
1512 dca3d_z_error = sqrt(cov_out[2][2]);
1520 out_track->set_dca3d_xy(dca3d_xy);
1521 out_track->set_dca3d_z(dca3d_z);
1522 out_track->set_dca3d_xy_error(dca3d_xy_error);
1523 out_track->set_dca3d_z_error(dca3d_z_error);
1527 out_track->set_chisq(chi2);
1528 out_track->set_ndf(ndf);
1529 out_track->set_charge(phgf_track->get_charge());
1531 out_track->set_px(mom.Px());
1532 out_track->set_py(mom.Py());
1533 out_track->set_pz(mom.Pz());
1535 out_track->set_x(pos.X());
1536 out_track->set_y(pos.Y());
1537 out_track->set_z(pos.Z());
1539 for (
int i = 0;
i < 6;
i++)
1541 for (
int j =
i;
j < 6;
j++)
1543 out_track->set_error(
i,
j, cov[
i][
j]);
1547 const genfit::Track* gftrack = phgf_track->getGenFitTrack();
1568 std::shared_ptr<const genfit::MeasuredStateOnPlane> gf_state = NULL;
1589 std::shared_ptr<SvtxTrackState>
state = std::shared_ptr<SvtxTrackState>(
new SvtxTrackState_v1(pathlength));
1590 state->set_x(gf_state->getPos().x());
1591 state->set_y(gf_state->getPos().y());
1592 state->set_z(gf_state->getPos().z());
1594 state->set_px(gf_state->getMom().x());
1595 state->set_py(gf_state->getMom().y());
1596 state->set_pz(gf_state->getMom().z());
1600 for (
int i = 0;
i < 6;
i++)
1602 for (
int j =
i;
j < 6;
j++)
1604 state->set_error(
i,
j, gf_state->get6DCov()[
i][
j]);
1608 out_track->insert_state(state.get());
1618 const std::vector<genfit::GFRaveVertex*>& rave_vertices,
1619 const std::vector<genfit::Track*>& gf_tracks)
1626 for (
unsigned int ivtx = 0; ivtx < rave_vertices.size(); ++ivtx)
1638 svtx_vtx->set_chisq(rave_vtx->
getChi2());
1639 svtx_vtx->set_ndof(rave_vtx->
getNdf());
1640 svtx_vtx->set_position(0, rave_vtx->
getPos().X());
1641 svtx_vtx->set_position(1, rave_vtx->
getPos().Y());
1642 svtx_vtx->set_position(2, rave_vtx->
getPos().Z());
1644 for (
int i = 0;
i < 3;
i++)
1645 for (
int j = 0;
j < 3;
j++)
1646 svtx_vtx->set_error(
i,
j, rave_vtx->
getCov()[
i][
j]);
1653 for (
unsigned int j = 0;
j < gf_tracks.size();
j++)
1655 if (rave_track == gf_tracks[
j])
1656 svtx_vtx->insert_track(j);
1696 const TVector3&
n,
const TMatrixF& pos_in,
const TMatrixF& cov_in,
1697 TMatrixF& pos_out, TMatrixF& cov_out)
const
1699 if (pos_in.GetNcols() != 1 || pos_in.GetNrows() != 3)
1705 if (cov_in.GetNcols() != 3 || cov_in.GetNrows() != 3)
1711 TVector3 Z_uvn(u.Z(), v.Z(), n.Z());
1712 TVector3 up_uvn = TVector3(0., 0., 1.).Cross(Z_uvn);
1714 if (up_uvn.Mag() < 0.00001)
1727 float phi = -atan2(up_uvn.Y(), up_uvn.X());
1729 R[0][1] = -sin(phi);
1748 pos_out.ResizeTo(3, 1);
1749 cov_out.ResizeTo(3, 3);
1751 pos_out = R * pos_in;
1752 cov_out = R * cov_in * R_T;
1758 const TVector3&
v,
const TVector3&
n,
const TMatrixF& cov_in,
1759 TMatrixF& cov_out)
const
1772 if (!(abs(R.Determinant() - 1) < 0.01))
1775 LogWarning(
"!(abs(R.Determinant()-1)<0.0001)");
1779 if (R.GetNcols() != 3 || R.GetNrows() != 3)
1782 LogWarning(
"R.GetNcols() != 3 || R.GetNrows() != 3");
1786 if (cov_in.GetNcols() != 3 || cov_in.GetNrows() != 3)
1789 LogWarning(
"cov_in.GetNcols() != 3 || cov_in.GetNrows() != 3");
1797 cov_out.ResizeTo(3, 3);
1799 cov_out = R * cov_in * R_T;
1805 const TVector3&
n,
const TMatrixF& pos_in,
const TMatrixF& cov_in,
1806 TMatrixF& pos_out, TMatrixF& cov_out)
const
1808 if (pos_in.GetNcols() != 1 || pos_in.GetNrows() != 3)
1814 if (cov_in.GetNcols() != 3 || cov_in.GetNrows() != 3)
1822 TVector3
r = n.Cross(TVector3(0., 0., 1.));
1823 if (r.Mag() < 0.00001)
1836 float phi = -atan2(r.Y(), r.X());
1838 R[0][1] = -sin(phi);
1857 pos_out.ResizeTo(3, 1);
1858 cov_out.ResizeTo(3, 3);
1860 pos_out = R * pos_in;
1861 cov_out = R * cov_in * R_T;
1871 const TVector3
y,
const TVector3
z,
const TVector3 xp,
const TVector3 yp,
1872 const TVector3 zp)
const
1876 TVector3 xu = x.Unit();
1877 TVector3 yu = y.Unit();
1878 TVector3 zu = z.Unit();
1880 const float max_diff = 0.01;
1883 abs(xu * yu) < max_diff and
1884 abs(xu * zu) < max_diff and
1885 abs(yu * zu) < max_diff))
1892 TVector3 xpu = xp.Unit();
1893 TVector3 ypu = yp.Unit();
1894 TVector3 zpu = zp.Unit();
1897 abs(xpu * ypu) < max_diff and
1898 abs(xpu * zpu) < max_diff and
1899 abs(ypu * zpu) < max_diff))
1911 TVector3
u(xpu.Dot(xu), xpu.Dot(yu), xpu.Dot(zu));
1912 TVector3
v(ypu.Dot(xu), ypu.Dot(yu), ypu.Dot(zu));
1913 TVector3
n(zpu.Dot(xu), zpu.Dot(yu), zpu.Dot(zu));
1917 std::shared_ptr<TRotation> rotation(
new TRotation());
1921 rotation->RotateAxes(
u,
v,
n);
1923 R[0][0] = rotation->XX();
1924 R[0][1] = rotation->XY();
1925 R[0][2] = rotation->XZ();
1926 R[1][0] = rotation->YX();
1927 R[1][1] = rotation->YY();
1928 R[1][2] = rotation->YZ();
1929 R[2][0] = rotation->ZX();
1930 R[2][1] = rotation->ZY();
1931 R[2][2] = rotation->ZZ();