10 #include <hfjettruthgeneration/HFJetDefs.h>
25 #include <g4jets/Jet.h>
26 #include <g4jets/JetMap.h>
30 #include <trackbase_historic/SvtxVertex.h>
31 #include <trackbase_historic/SvtxVertexMap.h>
36 #include <HepMC/GenEvent.h>
37 #include <HepMC/GenVertex.h>
41 #include "TDatabasePDG.h"
42 #include "TLorentzVector.h"
49 #define LogDebug(exp) std::cout << "DEBUG: " << __FILE__ << ": " << __LINE__ << ": " << exp << "\n"
50 #define LogError(exp) std::cout << "ERROR: " << __FILE__ << ": " << __LINE__ << ": " << exp << "\n"
51 #define LogWarning(exp) std::cout << "WARNING: " << __FILE__ << ": " << __LINE__ << ": " << exp << "\n"
58 , _truthjetmap_name(
"AntiKt_Truth_r04")
59 , _recojetmap_name(
"AntiKt_Tower_r04")
60 , _trackmap_name(
"SvtxTrackMap")
61 , _vertexmap_name(
"SvtxVertexMap")
76 _tree =
new TTree(
"T",
"a withered deciduous tree");
78 _tree->Branch(
"event", &
_b_event,
"event/I");
84 double calc_dca(
const TVector3 &track_point,
const TVector3 &track_direction,
const TVector3 &
vertex)
86 TVector3 VP = vertex - track_point;
89 if (track_direction.Mag() > 0)
91 d = (track_direction.Cross(VP)).Mag() / track_direction.Mag();
98 double &dca_xy,
double &dca_z,
99 const TVector3 &track_point,
const TVector3 &track_direction,
const TVector3 &
vertex)
104 if (track_direction.Mag() == 0)
return false;
106 TVector3 PV = track_point - vertex;
107 if (PV.Mag() < 0.000001)
114 TVector3 PVxMom = track_direction.Cross(PV);
116 TVector3 PCA = track_direction;
118 if (PVxMom.Mag() < 0.000001)
120 std::cout << __FILE__ <<
": " << __LINE__ <<
": PVxMom.Mag2() < 0.000001" << std::endl;
124 PCA.Rotate(TMath::PiOver2(), PVxMom);
128 PCA.SetMag(PV.Dot(PCA));
130 TVector3
r = track_direction.Cross(TVector3(0, 0, 1));
141 double &dca_xy,
double &dca_z,
142 const TVector3 &track_point ,
const TVector3 &track_mom ,
const TVector3 &
vertex,
143 const double &q = 1. ,
const double &B = 1.4 )
145 double z0 = track_point.Z() - vertex.Z();
146 double r0 = (track_point - vertex).Perp();
147 double pz = track_mom.Z();
148 double pt = track_mom.Perp();
150 if (pt == 0 || B == 0 || q == 0)
158 dca_z = z0 - pz / pt *
r0;
160 const double ten_over_c = 333.564095198;
161 double R = pt / B / q * ten_over_c;
164 TVector3 track_point_2d(track_point.X(), track_point.Y(), 0);
165 TVector3 track_mom_2d(track_mom.X(), track_mom.Y(), 0);
166 TVector3 vertex_2d(vertex.X(), vertex.Y(), 0);
169 TVector3 track_2d_circle_center = track_mom_2d;
170 track_2d_circle_center.RotateZ(TMath::PiOver2());
171 track_2d_circle_center.SetMag(R);
172 track_2d_circle_center += track_point_2d;
174 dca_xy = TMath::Abs(R) - (track_2d_circle_center - vertex_2d).Mag();
186 topNode,
"PHHepMCGenEventMap");
190 <<
" - Fatal error - missing node PHHepMCGenEventMap"
199 <<
" - Fatal error - node PHHepMCGenEventMap missing subevent with embedding ID "
201 std::cout <<
". Print PHHepMCGenEventMap:";
207 HepMC::GenEvent *theEvent = genevt->
getEvent();
217 TVector3 truth_primary_vertex(first_point->get_x(), first_point->get_y(), first_point->get_z());
227 JetRecoEval *jet_reco_eval = jet_eval_stack->get_reco_eval();
241 Jet *truth_jet = iter->second;
242 if (truth_jet->
get_pt() < 10 || fabs(truth_jet->
get_eta()) > 2)
249 int jet_flavor = -999;
252 if (abs(jet_flavor) < 100)
256 if (abs(jet_flavor) < 100)
266 Jet* matchedjet =
nullptr;
267 float mindr = std::numeric_limits<float>::max();
268 for (
JetMap::Iter riter = reco_jets->begin(); riter != reco_jets->end();
271 Jet* mjet = riter->second;
311 for (
auto iter = range.first; iter != range.second; ++iter)
320 float truth_pt = t.Pt();
321 if (truth_pt < 0.5)
continue;
322 float truth_eta = t.Eta();
323 if (fabs(truth_eta) > 1.1)
continue;
324 float truth_phi = t.Phi();
325 int truth_pid = g4particle->
get_pid();
342 if (!(abs(truth_pid) == 211 || abs(truth_pid) == 321 || abs(truth_pid) == 2212 || abs(truth_pid) == 11 || abs(truth_pid) == 13))
359 double truth_dca_xy = NAN;
360 double truth_dca_z = NAN;
365 calc_dca3d_line(truth_dca_xy, truth_dca_z, track_point, track_mom, truth_primary_vertex);
369 cout <<
"track_point: --------------" << endl;
372 cout <<
"track_mom: --------------" << endl;
375 cout <<
"truth_primary_vertex: --------------" << endl;
376 truth_primary_vertex.Print();
380 <<
": " << TDatabasePDG::Instance()->GetParticle(truth_pid)->GetName()
381 <<
": truth_dca_xy: " << truth_dca_xy
382 <<
": truth_dca_z: " << truth_dca_z
426 auto svtxevalstack = unique_ptr<SvtxEvalStack>(
new SvtxEvalStack(topNode));
433 svtxevalstack->next_event(topNode);
436 float vertex_x = -99;
437 float vertex_y = -99;
438 float vertex_z = -99;
450 float track_pt = track->
get_pt();
451 float track_eta = track->
get_eta();
452 float track_phi = track->
get_phi();
456 if (fabs(track_eta) > 1.1)
463 unsigned int nclusters_by_layer = 0;
476 nclusters_by_layer |= (0x3FFFFFFF & (0x1 << cluster_layer));
484 nclusters_by_layer |= (0x3FFFFFFF & (0x1 << cluster_layer));
495 unsigned int truth_embed_id = truthinfo->
isEmbeded(
497 bool truth_is_primary = truthinfo->
is_primary(g4particle);
498 int truth_pid = g4particle->
get_pid();
509 vertex_x = svertex->
get_x();
510 vertex_y = svertex->get_y();
511 vertex_z = svertex->get_z();
512 TVector3
vertex(vertex_x, vertex_y, vertex_z);
514 TVector3 track_point_2d(track->
get_x(), track->
get_y(), 0);
515 TVector3 track_direction_2d(track->
get_px(), track->
get_py(), 0);
516 TVector3 vertex_2d(vertex_x, vertex_y, 0);
517 float dca3d_xy = NAN;
518 float dca3d_xy_error = NAN;
520 float dca3d_z_error = NAN;
521 calc3DDCA(track, vertexmap, dca3d_xy, dca3d_xy_error, dca3d_z, dca3d_z_error);
523 float dca2d_calc =
calc_dca(track_point_2d, track_direction_2d, vertex_2d);
524 float dca2d_calc_truth =
calc_dca(track_point_2d, track_direction_2d, TVector3(0, 0, 0));
526 float dca3d_calc =
calc_dca(track_point, track_direction, vertex);
527 float dca3d_calc_truth =
calc_dca(track_point, track_direction, TVector3(0, 0, 0));
546 t.SetPxPyPzE(g4particle->
get_px(), g4particle->
get_py(),
549 float truth_pt = t.Pt();
550 float truth_eta = t.Eta();
551 float truth_phi = t.Phi();
558 TVector3 track_best_point(point->
get_x(), point->
get_y(), point->
get_z());
559 TVector3 track_best_mom(g4particle->
get_px(), g4particle->
get_py(), g4particle->
get_pz());
561 double truth_dca_xy = NAN;
562 double truth_dca_z = NAN;
567 calc_dca3d_line(truth_dca_xy, truth_dca_z, track_best_point, track_best_mom, truth_primary_vertex);
576 for (HepMC::GenEvent::particle_const_iterator
p =
577 theEvent->particles_begin();
578 p != theEvent->particles_end();
581 if ((*p)->pdg_id() != truth_pid)
584 if (fabs(truth_pt - (*p)->momentum().perp()) > 0.001)
586 if (fabs(truth_eta - (*p)->momentum().pseudoRapidity()) > 0.001)
588 if (fabs(truth_phi - (*p)->momentum().phi()) > 0.001)
591 HepMC::GenVertex *production_vertex = (*p)->production_vertex();
593 truth_in = production_vertex->particles_in_size();
594 truth_out = production_vertex->particles_out_size();
596 HepMC::GenVertex::particles_in_const_iterator first_parent =
597 production_vertex->particles_in_const_begin();
657 float& dca3d_xy,
float& dca3d_xy_error,
658 float& dca3d_z,
float& dca3d_z_error)
668 auto svtxVertex = vertexmap->
get(vtxid);
671 svtxVertex->get_z());
675 Acts::ActsSymMatrix<3> posCov;
676 for(
int i = 0;
i < 3; ++
i)
678 for(
int j = 0;
j < 3; ++
j)
685 float phi = atan2(
r(1),
r(0));
690 rot(0,1) = -sin(phi);
699 rot_T = rot.transpose();
702 Acts::ActsSymMatrix<3> rotCov = rot * posCov * rot_T;
706 dca3d_xy_error = sqrt(rotCov(0,0));
707 dca3d_z_error = sqrt(rotCov(2,2));
714 for (
int n = 0;
n < 10;
n++)
732 for (
int n = 0;
n < 1000;
n++)