22 #include <ktracker/SRecEvent.h>
33 , m_vec_rec_trk(nullptr)
38 , m_legacy_rec_container(true)
39 , m_do_evt_header(true)
40 , m_do_truthtrk_tagging(true)
41 , m_matching_threshold(0.75)
50 if (! m_evt )
delete m_evt;
51 if (! m_mcevt )
delete m_mcevt;
52 if (! m_vec_trk)
delete m_vec_trk;
53 if (! m_vec_dim)
delete m_vec_dim;
63 int ret = GetNodes(topNode);
65 ret = MakeNodes(topNode);
74 if (genevtmap->
size() != 1) {
75 cout <<
"TruthNodeMaker::process_event(): size != 1 unexpectedly." << endl;
81 cout <<
"No PHHepMCGenEvent object." << endl;
84 HepMC::GenEvent *evt = genevt->
getEvent();
86 cout <<
"No HepMC::GenEvent object." << endl;
95 HepMC::GenEvent::particle_const_iterator it = evt->particles_begin();
97 for (
int iii = 0; iii < 4; iii++) {
99 const HepMC::GenParticle* par = *it;
100 const HepMC::FourVector * mom = &par->momentum();
102 lvec.SetPxPyPzE(mom->px(), mom->py(), mom->pz(), mom->e());
111 map<int, int> trkid_idx;
112 vector<int> vec_vtx_id;
116 if (abs(pid) != 13)
continue;
127 trkid_idx[trk_id] = m_vec_trk->
size();
129 vec_vtx_id.push_back(vtx_id);
135 unsigned int n_trk = m_vec_trk->
size();
136 for (
unsigned int i1 = 0; i1 < n_trk; i1++) {
139 for (
unsigned int i2 = 0; i2 < n_trk; i2++) {
142 if (vec_vtx_id[i1] != vec_vtx_id[i2])
continue;
158 map<int, vector<SQHit*> > trkid_hitvec;
159 int n_digihits = m_vec_hit->
size();
160 for(
int i = 0; i < n_digihits; ++i) {
164 if(detid >
nChamberPlanes || (detid >= 7 && detid <= 12))
continue;
167 if(trkid_idx.find(trkid) == trkid_idx.end())
continue;
169 if(trkid_hitvec.find(trkid) == trkid_hitvec.end()) {
170 trkid_hitvec[trkid] = vector<SQHit*>();
172 trkid_hitvec[trkid].push_back(hit);
176 for(
unsigned int i = 0; i < n_trk; ++i) {
180 if(trkid_hitvec.find(trkid) == trkid_hitvec.end()) {
188 int detIDs_st1[6] = {3, 4, 2, 5, 1, 6};
189 if(FindHitAtStation(detIDs_st1, trkid, trkid_hitvec[trkid], pos, mom)) {
194 int detIDs_st3p[6] = {21, 22, 20, 23, 19, 24};
195 int detIDs_st3m[6] = {27, 28, 26, 29, 25, 30};
196 if(FindHitAtStation(detIDs_st3p, trkid, trkid_hitvec[trkid], pos, mom) ||
197 FindHitAtStation(detIDs_st3m, trkid, trkid_hitvec[trkid], pos, mom)) {
208 map<int, vector<int> > rtrkid_hitidvec;
209 if(m_legacy_rec_container) {
211 for(
int i = 0; i < n_rtrks; i++) {
213 rtrkid_hitidvec[i] = vector<int>();
216 for(
int j = 0; j < n_rhits; ++j) {
217 rtrkid_hitidvec[i].push_back(recTrack.
getHitIndex(j));
220 sort(rtrkid_hitidvec[i].begin(), rtrkid_hitidvec[i].end());
223 n_rtrks = m_vec_rec_trk->
size();
224 for(
int i = 0; i < n_rtrks; ++i) {
226 rtrkid_hitidvec[i] = vector<int>();
229 for(
int j = 0; j < n_rhits; ++j) {
230 rtrkid_hitidvec[i].push_back(recTrack->
getHitIndex(j));
233 sort(rtrkid_hitidvec[i].begin(), rtrkid_hitidvec[i].end());
239 map<int, vector<int> > ttrkid_hitidvec;
240 for(
auto it = trkid_hitvec.begin(); it != trkid_hitvec.end(); ++it) {
241 ttrkid_hitidvec[it->first] = vector<int>();
242 for(
auto jt = it->second.begin(); jt != it->second.end(); ++jt) {
243 ttrkid_hitidvec[it->first].push_back((*jt)->get_hit_id());
245 sort(ttrkid_hitidvec[it->first].begin(), ttrkid_hitidvec[it->first].end());
249 for(
unsigned int i = 0; i < n_trk; ++i) {
254 unsigned int n_match = 0;
255 for(
auto it = rtrkid_hitidvec.begin(); it != rtrkid_hitidvec.end(); ++it) {
256 int n_match_new = FindCommonHitIDs(ttrkid_hitidvec[ttrkid], it->second);
257 if(n_match < n_match_new) {
258 n_match = n_match_new;
263 if(rtrkid >= 0 &&
double(n_match)/
double(ttrkid_hitidvec[ttrkid].size()) > m_matching_threshold) {
278 g4true = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
280 cerr <<
Name() <<
": failed locating G4TruthInfo, abort" << endl;
284 m_vec_hit = findNode::getClass<SQHitVector>(topNode,
"SQHitVector");
286 cerr <<
Name() <<
": failed locating the digitized hit vector, abort" << endl;
290 genevtmap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
292 m_do_evt_header =
false;
293 cout <<
Name() <<
": failed locating HepMCGenEvent, event process info will be missing" << endl;
300 m_g4hc[i] = findNode::getClass<PHG4HitContainer>(topNode, g4hitNodeName);
303 if(m_legacy_rec_container) {
304 m_rec_evt = findNode::getClass<SRecEvent>(topNode,
"SRecEvent");
306 m_do_truthtrk_tagging =
false;
307 cout <<
Name() <<
": failed locating rec event, no truth track tagging." << endl;
310 m_vec_rec_trk = findNode::getClass<SQTrackVector>(topNode,
"SQRecTrackVector");
312 m_do_truthtrk_tagging =
false;
313 cout <<
Name() <<
": failed locating rec track vector, no truth track tagging." << endl;
325 cout <<
"No DST node!?" << endl;
329 m_evt = findNode::getClass<SQEvent>(topNode,
"SQEvent");
335 m_mcevt = findNode::getClass<SQMCEvent>(topNode,
"SQMCEvent");
341 m_vec_trk = findNode::getClass<SQTrackVector>(topNode,
"SQTruthTrackVector");
347 m_vec_dim = findNode::getClass<SQDimuonVector>(topNode,
"SQTruthDimuonVector");
356 bool TruthNodeMaker::FindHitAtStation(
int target_detIDs[],
int trkid,
const vector<SQHit*>& hitvec, TVector3& pos, TLorentzVector& mom)
358 for(
int i = 0; i < 6; ++i) {
360 for(
unsigned int j = 0; j < hitvec.size(); ++j) {
361 if(hitvec[j]->get_detector_id() == target_detIDs[i]) {
362 pos.SetXYZ(hitvec[j]->get_truth_x(), hitvec[j]->get_truth_y(), hitvec[j]->get_truth_z());
363 mom.SetXYZM(hitvec[j]->get_truth_px(), hitvec[j]->get_truth_py(), hitvec[j]->get_truth_pz(),
M_MU);
369 if(!m_g4hc[target_detIDs[i]])
continue;
383 int TruthNodeMaker::FindCommonHitIDs(vector<int>& hitidvec1, vector<int>& hitidvec2)
386 auto iter = hitidvec1.begin();
387 auto jter = hitidvec2.begin();
390 while(iter != hitidvec1.end() && jter != hitidvec2.end()) {
394 if(!(*jter < *iter)) {
virtual TVector3 get_pos_vtx() const =0
Return the track position at vertex.
virtual float get_x(const int i) const
int process_event(PHCompositeNode *topNode)
Int_t getNTracks()
Get tracks.
std::string getDetectorName(const int &detectorID) const
virtual float get_pz(const int i) const
virtual TLorentzVector get_mom_vtx() const =0
Return the track momentum at vertex.
virtual void set_charge(const int a)
void set_track_id_neg(const int a)
virtual void set_mom_st3(const TLorentzVector a)=0
virtual size_t size() const =0
virtual void set_run_id(const int a)=0
virtual double get_x() const
virtual void set_pos_st3(const TVector3 a)=0
virtual void set_pos_vtx(const TVector3 a)
PHBoolean addNode(PHNode *)
virtual int get_trkid() const
ConstIter begin() const
iterator from lowest ID to highest, i.e. background to signal
virtual HepMC::GenEvent * getEvent()
int Init(PHCompositeNode *topNode)
An SQ interface class to hold one detector hit.
virtual void set_event_id(const int a)=0
virtual double get_py() const
virtual void set_num_hits(const int a)=0
void set_track_id_pos(const int a)
Int_t getHitIndex(Int_t i)
int End(PHCompositeNode *topNode)
Called at the end of all processing.
void set_mom(const TLorentzVector a)
virtual void set_mom_vtx(const TLorentzVector a)
virtual const SQTrack * at(const size_t id) const =0
void set_dimuon_id(const int a)
std::map< int, PHHepMCGenEvent * >::iterator Iter
virtual void set_rec_track_id(const int a)=0
virtual double get_z() const
virtual void push_back(const SQTrack *trk)=0
virtual const std::string Name() const
Returns the name of this module.
virtual void set_pos_st1(const TVector3 a)=0
virtual void set_particle_id(const int i, const int a)=0
virtual int get_track_id() const
Return the track ID associated with this hit. Probably the value is not properly set at present...
virtual const SQHit * at(const size_t idkey) const
virtual short get_detector_id() const
Return the detector ID of this hit.
virtual float get_y(const int i) const
virtual int get_charge() const =0
Return the charge, i.e. +1 or -1.
void set_mom_neg(const TLorentzVector a)
An SQ interface class to hold one true or reconstructed track.
int InitRun(PHCompositeNode *topNode)
virtual int get_pid() const
std::pair< ConstIterator, ConstIterator > ConstRange
virtual double get_pz() const
Map::const_iterator ConstIterator
Range GetPrimaryParticleRange()
virtual void set_track_id(const int a)
virtual void set_particle_momentum(const int i, const TLorentzVector a)=0
virtual double get_e() const
virtual float get_z(const int i) const
virtual int get_track_id() const
SRecTrack & getTrack(Int_t i)
virtual double get_px() const
virtual ~TruthNodeMaker()
void set_mom_pos(const TLorentzVector a)
virtual void set_spill_id(const int a)=0
static GeomSvc * instance()
singlton instance
virtual size_t size() const
virtual float get_px(const int i) const
virtual double get_y() const
virtual void set_process_id(const int a)=0
void set_pos(const TVector3 a)
virtual void push_back(const SQDimuon *dim)=0
virtual int get_vtx_id() const
virtual int get_track_id() const =0
Return the track ID, which is unique per event(?).
virtual void set_mom_st1(const TLorentzVector a)=0
virtual float get_py(const int i) const
PHG4VtxPoint * GetVtx(const int vtxid)