32 #include <TDatabasePDG.h>
33 #include <TParticlePDG.h>
35 #include <gsl/gsl_randist.h>
36 #include <gsl/gsl_rng.h>
41 {
template<
class T>
inline constexpr
T square(
const T&
x ) {
return x*
x; } }
49 m_rng.reset( gsl_rng_alloc(gsl_rng_mt19937) );
72 cout <<
"PHTruthSiliconAssociation::process_event(PHCompositeNode *topNode) Processing Event" << endl;
80 for (
unsigned int phtrk_iter = 0;
93 <<
": Processing seed itrack: " << phtrk_iter
94 <<
": nhits: " <<
_tracklet-> size_cluster_keys()
101 if(
Verbosity() > 0) std::cout <<
" g4particle_vec.size() " << g4particle_vec.size() << std::endl;
103 if(g4particle_vec.size() < 1)
continue;
107 std::cout <<
" tpc seed track:" << endl;
111 for(
unsigned int ig4=0;ig4 < g4particle_vec.size(); ++ig4)
116 if(clusters.size() < 3)
continue;
123 auto seed = std::make_unique<SvtxTrackSeed_v1>();
124 seed->set_tpc_seed_index(phtrk_iter);
125 seed->set_silicon_seed_index(silicon_seed_index);
132 std::cout <<
" Created SvtxTrackSeed " << combined_seed_index
143 for (
unsigned int phtrk_iter = 0;
150 auto tpc_index =
seed->get_tpc_seed_index();
151 auto silicon_index =
seed->get_silicon_seed_index();
153 std::cout <<
"SvtxSeedTrack: " << phtrk_iter
154 <<
" tpc_index " << tpc_index
155 <<
" silicon_index " << silicon_index
158 std::cout <<
" ---------- silicon tracklet " << silicon_index << std::endl;
160 if(!silicon_tracklet)
continue;
163 std::cout <<
" ---------- tpc tracklet " << tpc_index << std::endl;
165 if(!tpc_tracklet)
continue;
171 cout <<
"PHTruthSiliconAssociation::process_event(PHCompositeNode *topNode) Leaving process_event" << endl;
229 _g4truth_container = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
232 cerr <<
PHWHERE <<
" ERROR: Can't find node G4TruthInfo" << endl;
236 _cluster_crossing_map = findNode::getClass<TrkrClusterCrossingAssoc>(topNode,
"TRKR_CLUSTERCROSSINGASSOC");
239 cerr <<
PHWHERE <<
" ERROR: Can't find TRKR_CLUSTERCROSSINGASSOC " << endl;
250 _cluster_map = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
253 cerr <<
PHWHERE <<
" ERROR: Can't find node TRKR_CLUSTER" << endl;
257 _hit_truth_map = findNode::getClass<TrkrHitTruthAssoc>(topNode,
"TRKR_HITTRUTHASSOC");
260 cerr <<
PHWHERE <<
" ERROR: Can't find TrkrHitTruthAssoc." << endl;
264 _cluster_hit_map = findNode::getClass<TrkrClusterHitAssoc>(topNode,
"TRKR_CLUSTERHITASSOC");
267 cerr <<
PHWHERE <<
" ERROR: Can't find TrkrClusterHitAssoc." << endl;
271 _tgeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
274 std::cerr <<
PHWHERE <<
"ERROR: can't find acts tracking geometry" << std::endl;
285 std::cerr <<
"DST Node missing, quitting" << std::endl;
286 throw std::runtime_error(
"failed to find DST node in PHTruthSiliconAssociation::createNodes");
300 _silicon_track_map = findNode::getClass<TrackSeedContainer>(topNode,
"SiliconTrackSeedContainer");
306 svtxNode->
addNode(si_tracks_node);
309 _tpc_track_map = findNode::getClass<TrackSeedContainer>(topNode,
"TpcTrackSeedContainer");
312 cerr <<
PHWHERE <<
" ERROR: Can't find TpcTrackSeedContainer: " << endl;
316 _svtx_seed_map = findNode::getClass<TrackSeedContainer>(topNode,
"SvtxTrackSeedContainer");
324 _g4hits_tpc = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_TPC");
325 _g4hits_intt = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_INTT");
326 _g4hits_mvtx = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_MVTX");
335 std::vector<PHG4Particle*> g4part_vec;
337 std::multimap<int, int> pid_count;
349 std::pair<std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator, std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator>
352 for(std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator
353 clushititer = hitrange.first; clushititer != hitrange.second; ++clushititer)
360 std::multimap< TrkrDefs::hitsetkey, std::pair<TrkrDefs::hitkey, PHG4HitDefs::keytype> > temp_map;
362 for(std::multimap<
TrkrDefs::hitsetkey, std::pair<TrkrDefs::hitkey, PHG4HitDefs::keytype> >::iterator htiter = temp_map.begin(); htiter != temp_map.end(); ++htiter)
381 pid_count.insert(std::make_pair(g4hit->
get_trkid(), cnt));
389 for(
auto it = pid.begin();
it != pid.end(); ++
it)
391 if(*
it < 0)
continue;
394 std::pair<std::multimap<int, int>::iterator, std::multimap<int,int>::iterator> this_pid = pid_count.equal_range(*
it);
395 for(
auto cnt_it = this_pid.first; cnt_it != this_pid.second; ++cnt_it)
400 if(
Verbosity() >= 1) std::cout <<
" pid: " << *
it <<
" nfound " << nfound << std::endl;
401 if(nfound > minfound)
415 std::set<TrkrDefs::cluskey>
clusters;
421 if(
layer > 6)
continue;
424 for(
auto clusIter = range.first; clusIter != range.second; ++clusIter ){
429 std::pair<std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator, std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator>
432 for(std::multimap<TrkrDefs::cluskey, TrkrDefs::hitkey>::const_iterator
433 clushititer = hitrange.first; clushititer != hitrange.second; ++clushititer)
440 std::multimap< TrkrDefs::hitsetkey, std::pair<TrkrDefs::hitkey, PHG4HitDefs::keytype> > temp_map;
442 for(std::multimap<
TrkrDefs::hitsetkey, std::pair<TrkrDefs::hitkey, PHG4HitDefs::keytype> >::iterator htiter = temp_map.begin(); htiter != temp_map.end(); ++htiter)
460 clusters.insert(cluster_key);
473 std::set<short int> intt_crossings;
492 for(
auto iter = crossings.first; iter != crossings.second; ++iter)
494 const auto& [key, crossing] = *iter;
496 { std::cout <<
"PHTruthSiliconAssociation::getInttCrossings - si Track cluster " << key <<
" layer " << layer <<
" crossing " << crossing << std::endl; }
497 intt_crossings.insert(crossing);
503 return intt_crossings;
508 auto track = std::make_unique<TrackSeed_FastSim_v1>();
509 bool silicon =
false;
510 for (
const auto&
cluskey : clusters){
514 track->insert_cluster_key(
cluskey);
517 const auto particle = TDatabasePDG::Instance()->GetParticle(g4particle->
get_pid());
525 auto random1 = gsl_ran_flat(
m_rng.get(), 0.95, 1.05);
526 float px = g4particle->
get_px() * random1;
527 float py = g4particle->
get_py() * random1;
528 float pz = g4particle->
get_pz() * random1;
531 auto random2 = gsl_ran_flat(
m_rng.get(), -0.002, 0.002);
532 float x = g4vertex->get_x() + random2;
533 float y = g4vertex->get_y() + random2;
534 float z = g4vertex->get_z() + random2;
536 float pt = sqrt(px*px+py*py);
537 float phi = atan2(py,px);
538 float R = 100 * pt / (0.3*1.4);
539 float theta = atan2(pt,pz);
545 float eta = -log(tan(theta/2.));
549 float tanphisq =
square(tan(phi));
550 float a = tanphisq + 1;
551 float b =-2*y*(tanphisq+1);
554 float Y0_1 = (-b + sqrt(
square(b)-4*a*c)) / (2.*a);
555 float Y0_2 = (-b - sqrt(
square(b)-4*a*c)) / (2.*a);
556 float X0_1 = sqrt(pow(R, 2) - pow(Y0_1 - y, 2)) +
x;
557 float X0_2 = -sqrt(pow(R, 2) - pow(Y0_2 - y, 2)) +
x;
560 track->set_qOverR(charge / R);
561 track->set_slope(1. / tan(theta));
569 if( fabs(newphi-phi) > 0.03)
574 if( fabs(newphi-phi) > 0.03)
579 if( fabs(newphi-phi) > 0.03)
589 std::cout <<
"Charge is " << charge << std::endl;
592 std::cout <<
"truth/reco pz " << pz <<
", " << track->get_pz() << std::endl;
593 std::cout <<
"truth/reco pt " << pt <<
", " << track->get_pt() << std::endl;
595 std::cout <<
"truth/reco eta " << eta <<
", " << track->get_eta() << std::endl;
596 std::cout <<
"truth/reco x " << x <<
", " << track->get_x() << std::endl;
597 std::cout <<
"truth/reco y " << y <<
", " << track->get_y() << std::endl;
598 std::cout <<
"truth/reco z " << z <<
", " << track->get_z() << std::endl;
608 if(intt_crossings.empty())
610 if(
Verbosity() > 1) std::cout <<
"PHTruthTrackSeeding::Process - Silicon track " << container->
size() - 1 <<
" has no INTT clusters" << std::endl;
611 return (container->
size() -1);
612 }
else if( intt_crossings.size() > 1 ) {
614 { std::cout <<
"PHTruthTrackSeeding::Process - INTT crossings not all the same for track " << container->
size() - 1 <<
" crossing_keep - dropping this match " << std::endl; }
617 const auto& crossing = *intt_crossings.begin();
618 track->set_crossing(crossing);
620 std::cout <<
"PHTruthTrackSeeding::Process - Combined track " << container->
size() - 1 <<
" bunch crossing " << crossing << std::endl;
626 track->set_crossing(SHRT_MAX);
629 container->
insert(track.get());
631 return (container->
size() - 1);