8 #include <trackbase_historic/SvtxVertex.h>
9 #include <trackbase_historic/SvtxVertex_v1.h>
11 #include <trackbase_historic/SvtxVertexMap.h>
18 #include <mvtx/MvtxDefs.h>
19 #include <intt/InttDefs.h>
21 #include <g4jets/JetMap.h>
37 #include <phgenfit/Fitter.h>
38 #include <phgenfit/PlanarMeasurement.h>
39 #include <phgenfit/Track.h>
40 #include <phgenfit/SpacepointMeasurement.h>
48 #include <phgeom/PHGeomUtility.h>
49 #include <phfield/PHFieldUtility.h>
51 #include <GenFit/FieldManager.h>
52 #include <GenFit/GFRaveVertex.h>
53 #include <GenFit/GFRaveVertexFactory.h>
54 #include <GenFit/MeasuredStateOnPlane.h>
55 #include <GenFit/RKTrackRep.h>
56 #include <GenFit/StateOnPlane.h>
58 #include <GenFit/KalmanFitterInfo.h>
62 #include <TClonesArray.h>
63 #include <TMatrixDSym.h>
67 #include <TRotation.h>
73 #define LogDebug(exp) std::cout<<"DEBUG: " <<__FILE__<<": "<<__LINE__<<": "<< exp <<std::endl
74 #define LogError(exp) std::cout<<"ERROR: " <<__FILE__<<": "<<__LINE__<<": "<< exp <<std::endl
75 #define LogWarning(exp) std::cout<<"WARNING: "<<__FILE__<<": "<<__LINE__<<": "<< exp <<std::endl
93 _mag_field_file_name(
"/phenix/upgrades/decadal/fieldmaps/sPHENIX.2d.root"),
94 _mag_field_re_scaling_factor(1.4 / 1.5),
95 _reverse_mag_field(
false),
97 _track_fitting_alg_name(
"DafRef"),
100 _primary_pid_guess(11),
101 _cut_Ncluster(
false),
105 _use_ladder_geom(
false),
106 _vertex_finder(NULL),
107 _vertexing_method(
"avf-smoothing:1"),
113 _do_evt_display(
false)
120 cout<<
"getting SVR nodes"<<endl;
125 _main_rf_phgf_tracks.clear();
132 cout<<
"start SVR track loop"<<endl;
142 int n_MVTX = 0, n_INTT = 0, n_TPC = 0;
169 _main_rf_phgf_tracks.push_back(rf_phgf_track);
172 cout<<
"exit track loop ntracks="<<_main_rf_phgf_tracks.size()<<
'\n';
202 std::cerr<<
PHWHERE<<
" bad run init no SVR"<<endl;
215 vector<genfit::GFRaveVertex*> rave_vertices_conversion;
216 vector<genfit::Track*> rf_gf_tracks_conversion;
223 rf_gf_tracks_conversion.push_back(rf_phgf_track->
getGenFitTrack());
233 rf_gf_tracks_conversion.push_back(rf_phgf_track->
getGenFitTrack());
235 if (rf_gf_tracks_conversion.size()>1){
239 std::cout <<
PHWHERE <<
"GFRaveVertexFactory::findVertices failed!";
250 if(rave_vertices_conversion.size()>0)
return rave_vertices_conversion[0];
279 TVector3 vertex_position(0, 0, 0);
281 std::shared_ptr<genfit::MeasuredStateOnPlane> gf_state_vertex_ca = NULL;
283 gf_state_vertex_ca = std::shared_ptr < genfit::MeasuredStateOnPlane> (track->
extrapolateToPoint(vertex_position));
288 TVector3 mom = gf_state_vertex_ca->getMom();
289 TMatrixDSym
cov = gf_state_vertex_ca->get6DCov();
291 cout <<
"OUT Ex: " << sqrt(cov[0][0]) <<
", Ey: " << sqrt(cov[1][1]) <<
", Ez: " << sqrt(cov[2][2]) << endl;
292 cout <<
"OUT Px: " << mom.X() <<
", Py: " << mom.Y() <<
", Pz: " << mom.Z() << endl;
300 for (
int i=0;
i<3;
i++){
307 for (
int ijet=0; ijet<10; ijet++){
315 for (
int ivtx=0; ivtx<30; ivtx++){
360 _clustermap = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
362 cout <<
PHWHERE <<
" TRKR_CLUSTERS node not found on node tree"
367 _trackmap = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
369 cout <<
PHWHERE <<
" SvtxTrackMap node not found on node tree"
374 _vertexmap = findNode::getClass<SvtxVertexMap>(topNode,
"SvtxVertexMap");
376 cout <<
PHWHERE <<
" SvtxVertexrMap node not found on node tree"
381 _geom_container_intt = findNode::getClass<PHG4CylinderGeomContainer>(topNode,
"CYLINDERGEOM_INTT");
384 cout <<
PHWHERE <<
"CYLINDERGEOM_INTT node not found on node tree"
388 _geom_container_maps = findNode::getClass<PHG4CylinderGeomContainer>(topNode,
"CYLINDERGEOM_MVTX");
391 cout <<
PHWHERE <<
"CYLINDERGEOM_MVTX node not found on node tree"
396 std::cerr<<
PHWHERE<<
" bad run init no SVR"<<endl;
407 cerr <<
PHWHERE <<
" Input SvtxTrack is NULL!" << endl;
412 cout <<
PHWHERE <<
"No PHG4CylinderGeomContainer found!" << endl;
416 TVector3 seed_pos(intrack->
get_x(), intrack->
get_y(), intrack->
get_z());
418 TMatrixDSym seed_cov(6);
419 for (
int i=0;
i<6;
i++){
420 for (
int j=0;
j<6;
j++){
426 std::vector<PHGenFit::Measurement*> measurements;
437 float radius = sqrt(x*x+y*y);
439 seed_mom.SetPhi(
pos.Phi());
440 seed_mom.SetTheta(
pos.Theta());
452 double ladder_location[3] = { 0.0, 0.0, 0.0 };
457 n.SetXYZ(ladder_location[0], ladder_location[1], 0);
463 double hit_location[3] = { 0.0, 0.0, 0.0 };
466 n.SetXYZ(hit_location[0], hit_location[1], 0);
471 measurements.push_back(meas);
491 cerr <<
PHWHERE <<
" Input SvtxTrack is NULL!" << endl;
496 cout <<
PHWHERE <<
"No PHG4CylinderGeomContainer found!" << endl;
501 std::vector<PHGenFit::Measurement*> measurements;
508 bool is_vertex_cov_sane =
true;
509 cout<<
"Making covarience for vtx measurement"<<endl;
510 for (
unsigned int i = 0;
i < 3;
i++)
511 for (
unsigned int j = 0;
j < 3;
j++) {
515 cout<<
"Made covarience"<<endl;
516 if (is_vertex_cov_sane) {
519 measurements.push_back(meas);
523 TVector3 seed_pos(intrack->
get_x(), intrack->
get_y(), intrack->
get_z());
525 TMatrixDSym seed_cov(6);
526 for (
int i=0;
i<6;
i++){
527 for (
int j=0;
j<6;
j++){
531 cout<<
"Making track cluster measurments"<<endl;
542 float radius = sqrt(x*x+y*y);
544 seed_mom.SetPhi(
pos.Phi());
545 seed_mom.SetTheta(
pos.Theta());
557 double ladder_location[3] = { 0.0, 0.0, 0.0 };
562 n.SetXYZ(ladder_location[0], ladder_location[1], 0);
568 double hit_location[3] = { 0.0, 0.0, 0.0 };
571 n.SetXYZ(hit_location[0], hit_location[1], 0);
576 measurements.push_back(meas);
591 cerr<<
PHWHERE<<
": invalid vertex"<<endl;
600 cerr <<
PHWHERE <<
" Input SvtxTrack is NULL!" << endl;
605 cout <<
PHWHERE <<
"No PHG4CylinderGeomContainer found!" << endl;
610 std::vector<PHGenFit::Measurement*> measurements;
614 if (invertex and invertex->
getNTracks() > 1) {
619 measurements.push_back(meas);
622 TVector3 seed_pos(intrack->
get_x(), intrack->
get_y(), intrack->
get_z());
624 TMatrixDSym seed_cov(6);
625 for (
int i=0;
i<6;
i++){
626 for (
int j=0;
j<6;
j++){
630 cout<<
"Making track cluster measurments"<<endl;
641 float radius = sqrt(x*x+y*y);
643 seed_mom.SetPhi(pos.Phi());
644 seed_mom.SetTheta(pos.Theta());
656 double ladder_location[3] = { 0.0, 0.0, 0.0 };
661 n.SetXYZ(ladder_location[0], ladder_location[1], 0);
667 double hit_location[3] = { 0.0, 0.0, 0.0 };
670 n.SetXYZ(hit_location[0], hit_location[1], 0);
675 measurements.push_back(meas);
690 cerr<<
PHWHERE<<
": invalid vertex"<<endl;
801 for (
int i = 0;
i < 3;
i++)
802 for (
int j = 0;
j < 3;
j++)
821 const std::vector<genfit::GFRaveVertex*>& rave_vertices,
822 const std::vector<genfit::Track*>& gf_tracks){
824 for (
unsigned int ivtx=0; ivtx<rave_vertices.size(); ++ivtx){
892 float sum_E = 0, sum_px = 0, sum_py = 0, sum_pz = 0;
894 int N_good = 0, N_good_pv = 0;
896 for (
unsigned int itrk=0; itrk<rave_vtx->
getNTracks(); itrk++){
901 sum_px += mom_trk.X();
902 sum_py += mom_trk.Y();
903 sum_pz += mom_trk.Z();
904 sum_E += sqrt(mom_trk.Mag2() + 0.140*0.140);
919 vtx_mass = sqrt(sum_E*sum_E - sum_px*sum_px - sum_py*sum_py - sum_pz*sum_pz);
924 ntrk_good_pv = N_good_pv;
932 const std::vector<genfit::GFRaveVertex*>& rave_vertices,
933 const std::vector<genfit::Track*>& gf_tracks){
941 cout<<
"good genfit refit"<<endl;
946 cout<<
"No refit possible"<<endl;
954 cout<<
"good genfit refit"<<endl;
959 cout<<
"No refit possible"<<endl;
985 double chi2 = phgf_track->
get_chi2();
986 double ndf = phgf_track->
get_ndf();
988 TVector3 vertex_position(0, 0, 0);
989 TMatrixF vertex_cov(3,3);
994 vertex_position.SetXYZ(vertex->
get_x(), vertex->
get_y(),
1000 for(
int j=0;
j<3;
j++)
1004 cerr<<
PHWHERE<<
": No vertex to make SvtxTrack"<<endl;
1008 std::shared_ptr<genfit::MeasuredStateOnPlane> gf_state_beam_line_ca =
nullptr;
1010 gf_state_beam_line_ca = std::shared_ptr<genfit::MeasuredStateOnPlane>(phgf_track->
extrapolateToLine(vertex_position,
1011 TVector3(0., 0., 1.)));
1016 if(!gf_state_beam_line_ca)
return nullptr;
1025 double u = gf_state_beam_line_ca->getState()[3];
1026 double v = gf_state_beam_line_ca->getState()[4];
1028 double du2 = gf_state_beam_line_ca->getCov()[3][3];
1029 double dv2 = gf_state_beam_line_ca->getCov()[4][4];
1036 std::shared_ptr < SvtxTrack_v1 > out_track = std::shared_ptr <
SvtxTrack_v1
1037 > (
new SvtxTrack_v1(*static_cast<const SvtxTrack_v1*>(svtx_track)));
1040 out_track->set_dca2d_error(sqrt(du2 + dvr2));
1042 std::shared_ptr<genfit::MeasuredStateOnPlane> gf_state_vertex_ca =
nullptr;
1050 if (!gf_state_vertex_ca) {
1055 TVector3 mom = gf_state_vertex_ca->getMom();
1056 TVector3
pos = gf_state_vertex_ca->getPos();
1057 TMatrixDSym
cov = gf_state_vertex_ca->get6DCov();
1063 u = gf_state_vertex_ca->getState()[3];
1064 v = gf_state_vertex_ca->getState()[4];
1066 du2 = gf_state_vertex_ca->getCov()[3][3];
1067 dv2 = gf_state_vertex_ca->getCov()[4][4];
1070 double dca3d = sqrt(u * u + v * v);
1071 double dca3d_error = sqrt(du2 + dv2 + dvr2 + dvz2);
1073 out_track->set_dca(dca3d);
1074 out_track->set_dca_error(dca3d_error);
1136 float dca3d_xy = NAN;
1137 float dca3d_z = NAN;
1138 float dca3d_xy_error = NAN;
1139 float dca3d_z_error = NAN;
1142 TMatrixF pos_in(3,1);
1143 TMatrixF cov_in(3,3);
1144 TMatrixF pos_out(3,1);
1145 TMatrixF cov_out(3,3);
1148 TMatrixDSym cov6(6,6);
1150 gf_state_vertex_ca->get6DStateCov(state6, cov6);
1152 TVector3 vn(state6[3], state6[4], state6[5]);
1155 pos_in[0][0] = state6[0] - vertex_position.X();
1156 pos_in[1][0] = state6[1] - vertex_position.Y();
1157 pos_in[2][0] = state6[2] - vertex_position.Z();
1160 for(
int i=0;
i<3;++
i){
1161 for(
int j=0;
j<3;++
j){
1162 cov_in[
i][
j] = cov6[
i][
j] + vertex_cov[
i][
j];
1166 dca3d_xy = pos_out[0][0];
1167 dca3d_z = pos_out[2][0];
1168 dca3d_xy_error = sqrt(cov_out[0][0]);
1169 dca3d_z_error = sqrt(cov_out[2][2]);
1172 cout<<__LINE__<<
": Vertex: ----------------"<<endl;
1173 vertex_position.Print();
1176 cout<<__LINE__<<
": State: ----------------"<<endl;
1180 cout<<__LINE__<<
": Mean: ----------------"<<endl;
1185 cout<<__LINE__<<
": Cov: ----------------"<<endl;
1198 out_track->set_dca3d_xy(dca3d_xy);
1199 out_track->set_dca3d_z(dca3d_z);
1200 out_track->set_dca3d_xy_error(dca3d_xy_error);
1201 out_track->set_dca3d_z_error(dca3d_z_error);
1205 out_track->set_chisq(chi2);
1206 out_track->set_ndf(ndf);
1207 out_track->set_charge(phgf_track->
get_charge());
1209 out_track->set_px(mom.Px());
1210 out_track->set_py(mom.Py());
1211 out_track->set_pz(mom.Pz());
1213 out_track->set_x(pos.X());
1214 out_track->set_y(pos.Y());
1215 out_track->set_z(pos.Z());
1217 for (
int i = 0;
i < 6;
i++) {
1218 for (
int j =
i;
j < 6;
j++) {
1219 out_track->set_error(
i,
j, cov[
i][
j]);
1284 cout << __LINE__ << endl;
1305 std::shared_ptr<const genfit::MeasuredStateOnPlane> gf_state =
nullptr;
1322 std::shared_ptr<SvtxTrackState>
state = std::shared_ptr<SvtxTrackState> (
new SvtxTrackState_v1(pathlength));
1323 state->set_x(gf_state->getPos().x());
1324 state->set_y(gf_state->getPos().y());
1325 state->set_z(gf_state->getPos().z());
1327 state->set_px(gf_state->getMom().x());
1328 state->set_py(gf_state->getMom().y());
1329 state->set_pz(gf_state->getMom().z());
1333 for (
int i = 0;
i < 6;
i++) {
1334 for (
int j =
i;
j < 6;
j++) {
1335 state->set_error(
i,
j, gf_state->get6DCov()[
i][
j]);
1339 out_track->insert_state(state.get());
1345 <<
": " << pathlength <<
" => "
1346 <<sqrt(state->get_x()*state->get_x() + state->get_y()*state->get_y())