16 #include <phgeom/PHGeomUtility.h>
17 #include <phfield/PHFieldUtility.h>
28 #include <g4hough/SvtxCluster.h>
29 #include <g4hough/SvtxClusterMap.h>
30 #include <g4hough/SvtxHitMap.h>
31 #include <g4hough/SvtxTrack.h>
32 #include <g4hough/SvtxVertex.h>
33 #include <g4hough/SvtxTrackMap.h>
34 #include <g4hough/SvtxVertexMap.h>
36 #include <g4jets/JetMap.h>
37 #include <g4jets/Jet.h>
42 #include <g4detectors/PHG4CylinderGeom_MAPS.h>
43 #include <g4detectors/PHG4CylinderGeom_Siladders.h>
45 #include <phgenfit/Fitter.h>
46 #include <phgenfit/PlanarMeasurement.h>
47 #include <phgenfit/Track.h>
48 #include <phgenfit/SpacepointMeasurement.h>
51 #include <GenFit/FieldManager.h>
52 #include <GenFit/GFRaveConverters.h>
53 #include <GenFit/GFRaveVertex.h>
54 #include <GenFit/GFRaveVertexFactory.h>
55 #include <GenFit/MeasuredStateOnPlane.h>
56 #include <GenFit/RKTrackRep.h>
57 #include <GenFit/StateOnPlane.h>
61 #include <rave/Version.h>
62 #include <rave/Track.h>
63 #include <rave/VertexFactory.h>
64 #include <rave/ConstantMagneticField.h>
67 #include <HepMC/GenEvent.h>
68 #include <HepMC/GenVertex.h>
70 #include <HFJetTruthGeneration/HFJetDefs.h>
74 #include "TLorentzVector.h"
85 #define LogDebug(exp) std::cout<<"DEBUG: " <<__FILE__<<": "<<__LINE__<<": "<< exp <<"\n"
86 #define LogError(exp) std::cout<<"ERROR: " <<__FILE__<<": "<<__LINE__<<": "<< exp <<"\n"
87 #define LogWarning(exp) std::cout<<"WARNING: " <<__FILE__<<": "<<__LINE__<<": "<< exp <<"\n"
101 _do_evt_display(
false),
102 _use_ladder_geom(
false),
104 _cut_Ncluster(
false),
108 _primary_pid_guess(211),
114 _track_fitting_alg_name(
"DafRef"),
116 _vertexing_method(
"avf-smoothing:1"),
147 std::cerr <<
PHWHERE << std::endl;
155 std::cerr <<
PHWHERE << std::endl;
197 Jet* this_jet = iter->second;
199 float this_pt = this_jet->
get_pt();
200 float this_phi = this_jet->
get_phi();
201 float this_eta = this_jet->
get_eta();
217 std::cout <<
" truth jet #" << ijet_t <<
", pt / eta / phi = "
218 << this_pt <<
" / " << this_eta <<
" / " << this_phi
237 std::vector<genfit::Track*> rf_gf_tracks;
238 rf_gf_tracks.clear();
239 std::vector<PHGenFit::Track*> rf_phgf_tracks;
240 rf_phgf_tracks.clear();
242 std::map<unsigned int, unsigned int> svtxtrk_gftrk_map;
243 std::map<unsigned int, unsigned int> svtxtrk_nmvtx_map;
244 std::map<unsigned int, unsigned int> svtxtrk_nintt_map;
260 int n_MVTX = 0, n_INTT = 0;
267 unsigned int layer = cluster->get_layer();
269 if (layer < 3) n_MVTX++;
270 else if (layer < 7) n_INTT++;
285 svtxtrk_gftrk_map.insert(std::pair<int, int>(svtx_track->
get_id(), rf_phgf_tracks.size()));
286 svtxtrk_nmvtx_map.insert(std::pair<int, int>(svtx_track->
get_id(), n_MVTX));
287 svtxtrk_nintt_map.insert(std::pair<int, int>(svtx_track->
get_id(), n_INTT));
288 rf_phgf_tracks.push_back(rf_phgf_track);
292 if ( n_MVTX >= 1 && n_INTT >= 2 )
304 std::vector<genfit::GFRaveVertex*> rave_vertices;
305 rave_vertices.clear();
310 if (rf_gf_tracks.size() >= 2)
315 std::cout <<
PHWHERE <<
"GFRaveVertexFactory::findVertices failed!";
324 std::vector<genfit::GFRaveVertex*> rave_vertices_jet;
325 rave_vertices_jet.clear();
330 Jet *jet = iter->second;
332 float jet_pT = jet->
get_pt();
333 float jet_eta = jet->
get_eta();
334 float jet_phi = jet->
get_phi();
339 int counter_r10 = 0, counter_miss = 0;
341 std::vector<genfit::Track*> rf_gf_tracks_jet;
342 rf_gf_tracks_jet.clear();
358 float trk_phi = svtx_track->
get_phi();
359 float trk_eta = svtx_track->
get_eta();
362 float sin_phi = sin(jet_phi - trk_phi);
363 float cos_phi = cos(jet_phi - trk_phi);
364 float dphi = atan2(sin_phi, cos_phi);
366 if (sqrt((jet_eta - trk_eta) * (jet_eta - trk_eta) + dphi * dphi) < 1.0)
371 if (sqrt((jet_eta - trk_eta) * (jet_eta - trk_eta) + dphi * dphi) >
_cut_jet_R)
continue;
373 if (svtxtrk_gftrk_map.find(svtx_track->
get_id()) != svtxtrk_gftrk_map.end()) {
374 unsigned int trk_index = svtxtrk_gftrk_map[svtx_track->
get_id()];
375 unsigned int nclus_mvtx = svtxtrk_nmvtx_map[svtx_track->
get_id()];
376 unsigned int nclus_intt = svtxtrk_nintt_map[svtx_track->
get_id()];
383 if ( nclus_mvtx >= 1 && nclus_intt >= 2 ) {
404 if (rf_gf_tracks_jet.size() > 1) {
408 std::cout <<
PHWHERE <<
"GFRaveVertexFactory::findVertices failed!";
415 std::cout <<
"JET PT: " << jet_pT
417 <<
", CUT10: " << counter_r10
418 <<
", CUT04: " << rf_gf_tracks_jet.size()
419 <<
", N VTX: " << rave_vertices_jet.size()
426 for (
int ivtx = 0; ivtx < int(rave_vertices_jet.size()); ivtx++) {
438 float vtx_mass, vtx_px, vtx_py, vtx_pz;
443 TVector3 vec1(vtx_px, vtx_py, vtx_pz);
445 float theta = vec1.Angle(vec2);
446 float A = vec1.Mag() * sin(theta);
447 float vtx_mass_corr = sqrt(vtx_mass * vtx_mass + A * A) +
A;
458 rave_vertices_jet.clear();
509 _tree =
new TTree(
"ttree",
"a withered deciduous tree");
511 _tree->Branch(
"event", &
_b_event,
"event/I");
515 _tree->Branch(
"truthjet_n", &
_truthjet_n,
"truthjet_n/I");
518 _tree->Branch(
"truthjet_pt",
_truthjet_pt,
"truthjet_pt[truthjet_n]/F");
520 "truthjet_eta[truthjet_n]/F");
522 "truthjet_phi[truthjet_n]/F");
527 _tree->Branch(
"gf_prim_vtx",
gf_prim_vtx,
"gf_prim_vtx[3]/F");
528 _tree->Branch(
"gf_prim_vtx_err",
gf_prim_vtx_err,
"gf_prim_vtx_err[3]/F");
530 _tree->Branch(
"rv_prim_vtx",
rv_prim_vtx,
"rv_prim_vtx[3]/F");
531 _tree->Branch(
"rv_prim_vtx_err",
rv_prim_vtx_err,
"rv_prim_vtx_err[3]/F");
534 _tree->Branch(
"rv_sv_njets", &
rv_sv_njets,
"rv_sv_njets/I");
535 _tree->Branch(
"rv_sv_jet_id",
rv_sv_jet_id,
"rv_sv_jet_id[rv_sv_njets]/I");
536 _tree->Branch(
"rv_sv_jet_prop",
rv_sv_jet_prop,
"rv_sv_jet_prop[rv_sv_njets][2]/I");
537 _tree->Branch(
"rv_sv_jet_pT",
rv_sv_jet_pT,
"rv_sv_jet_pT[rv_sv_njets]/F");
538 _tree->Branch(
"rv_sv_jet_phi",
rv_sv_jet_phi,
"rv_sv_jet_phi[rv_sv_njets]/F");
540 _tree->Branch(
"rv_sv_pT00_nvtx",
rv_sv_pT00_nvtx,
"rv_sv_pT00_nvtx[rv_sv_njets]/I");
541 _tree->Branch(
"rv_sv_pT00_vtx_x",
rv_sv_pT00_vtx_x,
"rv_sv_pT00_vtx_x[rv_sv_njets][30]/F");
542 _tree->Branch(
"rv_sv_pT00_vtx_y",
rv_sv_pT00_vtx_y,
"rv_sv_pT00_vtx_y[rv_sv_njets][30]/F");
543 _tree->Branch(
"rv_sv_pT00_vtx_z",
rv_sv_pT00_vtx_z,
"rv_sv_pT00_vtx_z[rv_sv_njets][30]/F");
544 _tree->Branch(
"rv_sv_pT00_vtx_ex",
rv_sv_pT00_vtx_ex,
"rv_sv_pT00_vtx_ex[rv_sv_njets][30]/F");
545 _tree->Branch(
"rv_sv_pT00_vtx_ey",
rv_sv_pT00_vtx_ey,
"rv_sv_pT00_vtx_ey[rv_sv_njets][30]/F");
546 _tree->Branch(
"rv_sv_pT00_vtx_ez",
rv_sv_pT00_vtx_ez,
"rv_sv_pT00_vtx_ez[rv_sv_njets][30]/F");
547 _tree->Branch(
"rv_sv_pT00_vtx_ntrk",
rv_sv_pT00_vtx_ntrk,
"rv_sv_pT00_vtx_ntrk[rv_sv_njets][30]/I");
549 _tree->Branch(
"rv_sv_pT00_vtx_mass",
rv_sv_pT00_vtx_mass,
"rv_sv_pT00_vtx_mass[rv_sv_njets][30]/F");
551 _tree->Branch(
"rv_sv_pT00_vtx_pT",
rv_sv_pT00_vtx_pT,
"rv_sv_pT00_vtx_pT[rv_sv_njets][30]/F");
566 for (
int n = 0;
n < 10;
n++)
578 for (
int i = 0;
i < 3;
i++)
586 for (
int ijet = 0; ijet < 10; ijet++)
596 for (
int ivtx = 0; ivtx < 30; ivtx++) {
627 std::cout <<
PHWHERE <<
" AntiKt_Truth_r04 node not found ... aborting" << std::endl;
632 _clustermap = findNode::getClass<SvtxClusterMap>(topNode,
"SvtxClusterMap");
634 std::cout <<
PHWHERE <<
" SvtxClusterMap node not found on node tree"
640 _trackmap = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
642 std::cout <<
PHWHERE <<
" SvtxClusterMap node not found on node tree"
648 _vertexmap = findNode::getClass<SvtxVertexMap>(topNode,
"SvtxVertexMap");
650 std::cout <<
PHWHERE <<
" SvtxVertexrMap node not found on node tree"
672 std::cerr <<
PHWHERE <<
" Input SvtxTrack is NULL!" << std::endl;
676 SvtxHitMap* hitsmap = NULL;
677 hitsmap = findNode::getClass<SvtxHitMap>(topNode,
"SvtxHitMap");
679 std::cout <<
PHWHERE <<
"ERROR: Can't find node SvtxHitMap" << std::endl;
683 PHG4CellContainer* cells_svtx = findNode::getClass<PHG4CellContainer>(topNode,
"G4CELL_SVTX");
684 PHG4CellContainer* cells_intt = findNode::getClass<PHG4CellContainer>(topNode,
"G4CELL_SILICON_TRACKER");
685 PHG4CellContainer* cells_maps = findNode::getClass<PHG4CellContainer>(topNode,
"G4CELL_MAPS");
688 std::cout <<
PHWHERE <<
"No PHG4CellContainer found!" << std::endl;
692 PHG4CylinderGeomContainer* geom_container_intt = findNode::getClass<PHG4CylinderGeomContainer>(topNode,
"CYLINDERGEOM_SILICON_TRACKER");
693 PHG4CylinderGeomContainer* geom_container_maps = findNode::getClass<PHG4CylinderGeomContainer>(topNode,
"CYLINDERGEOM_MAPS");
696 std::cout <<
PHWHERE <<
"No PHG4CylinderGeomContainer found!" << std::endl;
701 TVector3 seed_mom(100, 0, 0);
702 TVector3 seed_pos(0, 0, 0);
703 TMatrixDSym seed_cov(6);
704 for (
int i = 0;
i < 6;
i++) {
705 for (
int j = 0;
j < 6;
j++) {
706 seed_cov[
i][
j] = 100.;
722 std::vector<PHGenFit::Measurement*> measurements;
725 std::map<float, unsigned int> m_r_cluster_id;
728 unsigned int cluster_id = *iter;
729 SvtxCluster* cluster =
_clustermap->get(cluster_id);
730 float x = cluster->get_x();
731 float y = cluster->get_y();
732 float r = sqrt(x * x + y * y);
733 m_r_cluster_id.insert(std::pair<float, unsigned int>(r, cluster_id));
736 for (
auto iter = m_r_cluster_id.begin(); iter != m_r_cluster_id.end(); ++iter) {
738 unsigned int cluster_id = iter->second;
740 SvtxCluster* cluster =
_clustermap->get(cluster_id);
746 TVector3
pos(cluster->get_x(), cluster->get_y(), cluster->get_z());
748 seed_mom.SetPhi(
pos.Phi());
749 seed_mom.SetTheta(
pos.Theta());
752 TVector3
n(cluster->get_x(), cluster->get_y(), 0);
754 unsigned int begin_hit_id = *(cluster->begin_hits());
755 SvtxHit* svtxhit = hitsmap->find(begin_hit_id)->second;
761 if (
_use_ladder_geom and cells_svtx) cell_svtx = cells_svtx->findCell(svtxhit->get_cellid());
762 if (
_use_ladder_geom and cells_intt) cell_intt = cells_intt->findCell(svtxhit->get_cellid());
763 if (
_use_ladder_geom and cells_maps) cell_maps = cells_maps->findCell(svtxhit->get_cellid());
766 LogError(
"!(cell_svtx or cell_intt or cell_maps)");
771 unsigned int layer = cluster->get_layer();
783 double ladder_location[3] = { 0.0, 0.0, 0.0 };
784 PHG4CylinderGeom_MAPS *geom = (PHG4CylinderGeom_MAPS*) geom_container_maps->GetLayerGeom(layer);
786 geom->find_sensor_center(stave_index, half_stave_index, module_index, chip_index, ladder_location);
787 n.SetXYZ(ladder_location[0], ladder_location[1], 0);
788 n.RotateZ(geom->get_stave_phi_tilt());
789 }
else if (cell_intt) {
791 PHG4CylinderGeom_Siladders* geom = (PHG4CylinderGeom_Siladders*) geom_container_intt->
GetLayerGeom(layer);
792 double hit_location[3] = { 0.0, 0.0, 0.0 };
795 n.SetXYZ(hit_location[0], hit_location[1], 0);
796 n.RotateZ(geom->get_strip_phi_tilt());
830 cluster->get_rphi_error(), cluster->get_z_error());
832 measurements.push_back(meas);
847 TVector3 vertex_position(0, 0, 0);
849 vertex_position.SetXYZ(vertex->
get_x(), vertex->
get_y(), vertex->
get_z());
852 std::shared_ptr<genfit::MeasuredStateOnPlane> gf_state_vertex_ca = NULL;
854 gf_state_vertex_ca = std::shared_ptr < genfit::MeasuredStateOnPlane> (track->
extrapolateToPoint(vertex_position));
861 TVector3 mom = gf_state_vertex_ca->getMom();
862 TMatrixDSym
cov = gf_state_vertex_ca->get6DCov();
876 const std::vector<genfit::GFRaveVertex*>& rave_vertices,
877 const std::vector<genfit::Track*>& gf_tracks) {
879 for (
unsigned int ivtx = 0; ivtx < rave_vertices.size(); ++ivtx)
890 rv_prim_vtx_err[2] = sqrt(rave_vtx->
getCov()[2][2]);
908 gf_prim_vtx_err[2] = sqrt(svtx_vertex->
get_error(2, 2));
924 float sum_E = 0, sum_px = 0, sum_py = 0, sum_pz = 0;
928 for (
unsigned int itrk = 0; itrk < rave_vtx->
getNTracks(); itrk++) {
933 sum_px += mom_trk.X();
934 sum_py += mom_trk.Y();
935 sum_pz += mom_trk.Z();
936 sum_E += sqrt(mom_trk.Mag2() + 0.140 * 0.140);
945 vtx_mass = sqrt(sum_E * sum_E - sum_px * sum_px - sum_py * sum_py - sum_pz * sum_pz);