48 #include <TDatabasePDG.h>
49 #include <TParticlePDG.h>
51 #include <gsl/gsl_randist.h>
52 #include <gsl/gsl_rng.h>
65 {
template<
class T>
inline constexpr
T square(
const T&
x ) {
return x*
x; } }
69 , _clustereval(nullptr)
73 m_rng.reset( gsl_rng_alloc(gsl_rng_mt19937) );
79 std::cout <<
"Enter PHTruthTrackSeeding:: Setup" << std::endl ;
100 using TrkClustersMap = std::map<int, std::set<TrkrCluster*> >;
101 TrkClustersMap m_trackID_clusters;
103 std::vector<TrkrDefs::cluskey> ClusterKeyListSilicon;
104 std::vector<TrkrDefs::cluskey> ClusterKeyListTpc;
108 iter != range.second;
110 ClusterKeyListSilicon.clear();
111 ClusterKeyListTpc.clear();
114 if (g4particle==NULL){
115 std::cout <<__PRETTY_FUNCTION__<<
" - validity check failed: missing truth particle" << std::endl;
123 const double monentum2 =
130 std::cout <<__PRETTY_FUNCTION__<<
" ignore low momentum particle "<< gtrackID << std::endl;
143 ClusterKeyListSilicon.push_back(cluskey);
145 ClusterKeyListTpc.push_back(cluskey);
149 unsigned int nsi = ClusterKeyListSilicon.size();
150 unsigned int ntpc = ClusterKeyListTpc.size();
164 if(nsi > 0 && ntpc > 0)
167 auto track = std::make_unique<SvtxTrackSeed_v1>();
180 for (
unsigned int phtrk_iter = 0;
187 auto tpc_index =
seed->get_tpc_seed_index();
188 auto silicon_index =
seed->get_silicon_seed_index();
190 std::cout <<
"SvtxSeedTrack: " << phtrk_iter
191 <<
" tpc_index " << tpc_index
192 <<
" silicon_index " << silicon_index
195 std::cout <<
" ---------- silicon tracklet " << silicon_index << std::endl;
197 if(!silicon_tracklet)
continue;
200 std::cout <<
" ---------- tpc tracklet " << tpc_index << std::endl;
202 if(!tpc_tracklet)
continue;
216 auto track = std::make_unique<TrackSeed_FastSim_v1>();
217 bool silicon =
false;
219 for (
const auto&
cluskey : clusters){
225 track->insert_cluster_key(
cluskey);
228 const auto particle = TDatabasePDG::Instance()->GetParticle(g4particle->
get_pid());
236 auto random1 = gsl_ran_flat(
m_rng.get(), 0.95, 1.05);
237 float px = g4particle->
get_px() * random1;
238 float py = g4particle->
get_py() * random1;
239 float pz = g4particle->
get_pz() * random1;
241 auto random2 = gsl_ran_flat(
m_rng.get(), -0.02, 0.02);
242 float x = g4vertex->get_x() + random2;
243 float y = g4vertex->get_y() + random2;
244 float z = g4vertex->get_z() + random2;
246 float pt = sqrt(px*px+py*py);
247 float phi = atan2(py,px);
248 float R = 100 * pt / (0.3*1.4);
249 float theta = atan2(pt,pz);
255 float eta = -log(tan(theta/2.));
259 float tanphisq =
square(tan(phi));
260 float a = tanphisq + 1;
261 float b =-2*y*(tanphisq+1);
264 float Y0_1 = (-b + sqrt(
square(b)-4*a*c)) / (2.*a);
265 float Y0_2 = (-b - sqrt(
square(b)-4*a*c)) / (2.*a);
266 float X0_1 = sqrt(pow(R, 2) - pow(Y0_1 - y, 2)) +
x;
267 float X0_2 = -sqrt(pow(R, 2) - pow(Y0_2 - y, 2)) +
x;
270 track->set_qOverR(charge / R);
271 track->set_slope(1. / tan(theta));
279 unsigned int start_layer = 7;
280 unsigned int end_layer = 54;
289 if( fabs(newphi-phi) > 0.03)
294 if( fabs(newphi-phi) > 0.03)
299 if( fabs(newphi-phi) > 0.03)
309 std::cout <<
"Charge is " << charge << std::endl;
312 std::cout <<
"truth/reco pz " << pz <<
", " << track->get_pz() << std::endl;
313 std::cout <<
"truth/reco pt " << pt <<
", " << track->get_pt() << std::endl;
314 std::cout <<
"truth/reco phi " << phi <<
", " << track->get_phi(
m_clusterMap,
tgeometry) << std::endl;
315 std::cout <<
"truth/reco eta " << eta <<
", " << track->get_eta() << std::endl;
316 std::cout <<
"truth/reco x " << x <<
", " << track->get_x() << std::endl;
317 std::cout <<
"truth/reco y " << y <<
", " << track->get_y() << std::endl;
318 std::cout <<
"truth/reco z " << z <<
", " << track->get_z() << std::endl;
328 if(intt_crossings.empty())
330 if(
Verbosity() > 1) std::cout <<
"PHTruthTrackSeeding::Process - Silicon track " << container->
size() - 1 <<
" has no INTT clusters" << std::endl;
332 }
else if( intt_crossings.size() > 1 ) {
334 { std::cout <<
"PHTruthTrackSeeding::Process - INTT crossings not all the same for track " << container->
size() - 1 <<
" crossing_keep - dropping this match " << std::endl; }
337 const auto& crossing = *intt_crossings.begin();
338 track->set_crossing(crossing);
340 std::cout <<
"PHTruthTrackSeeding::Process - Combined track " << container->
size() - 1 <<
" bunch crossing " << crossing << std::endl;
346 track->set_crossing(SHRT_MAX);
349 container->
insert(track.get());
357 "PHCompositeNode",
"DST"));
360 std::cerr <<
PHWHERE <<
"DST Node missing, doing nothing." << std::endl;
374 std::cout <<
PHWHERE <<
"SVTX node added" << std::endl;
377 _track_map = findNode::getClass<TrackSeedContainer>(topNode,
"TpcTrackSeedContainer");
386 _track_map_silicon = findNode::getClass<TrackSeedContainer>(topNode,
"SiliconTrackSeedContainer");
395 _track_map_combined = findNode::getClass<TrackSeedContainer>(topNode,
"SvtxTrackSeedContainer");
408 tgeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
411 std::cerr <<
PHWHERE <<
"Error, can' find needed Acts nodes " << std::endl;
415 m_clusterMap = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
419 std::cerr <<
PHWHERE <<
"Error: Can't find node TRKR_CLUSTER" << std::endl ;
423 m_cluster_crossing_map = findNode::getClass<TrkrClusterCrossingAssoc>(topNode,
"TRKR_CLUSTERCROSSINGASSOC");
426 std::cerr <<
PHWHERE <<
" ERROR: Can't find TRKR_CLUSTERCROSSINGASSOC " << std::endl ;
433 std::cerr <<
PHWHERE <<
" ERROR: Can't find node G4TruthInfo" << std::endl ;
437 hittruthassoc = findNode::getClass<TrkrHitTruthAssoc>(topNode,
"TRKR_HITTRUTHASSOC");
440 std::cout <<
PHWHERE <<
"Failed to find TRKR_HITTRUTHASSOC node, quit!" << std::endl ;
444 using nodePair = std::pair<std::string, PHG4HitContainer*&>;
445 std::initializer_list<nodePair> nodes =
453 for(
auto&&
node: nodes )
455 if( !(
node.second = findNode::getClass<PHG4HitContainer>( topNode,
node.first ) ) )
456 { std::cerr <<
PHWHERE <<
" PHG4HitContainer " <<
node.first <<
" not found" << std::endl; }
470 std::cout <<
"PHTruthTrackSeeding::getInttCrossings - entering " << std::endl;
472 std::set<short int> intt_crossings;
483 if(
Verbosity() > 0) std::cout <<
" trkrid " << trkrid <<
" cluster_key " << cluster_key << std::endl;
492 for(
auto iter = crossings.first; iter != crossings.second; ++iter)
494 const auto& [key, crossing] = *iter;
496 { std::cout <<
" PHTruthTrackSeeding::getInttCrossings - si Track cluster " << key <<
" layer " << layer <<
" crossing " << crossing << std::endl; }
497 intt_crossings.insert(crossing);
502 return intt_crossings;