40 template<
class T>
inline constexpr
T square(
const T&
x ) {
return x*
x; }
46 if( phi >= M_PI )
return phi - 2*M_PI;
47 else if( phi < -M_PI )
return phi + 2*M_PI;
56 inline constexpr
double get_sector_phi(
int isec )
57 {
return isec*M_PI/6; }
60 static const std::vector<float> phi_rec = { get_sector_phi(9) };
61 static const std::vector<float> z_rec = { 5. };
64 static constexpr
float m_phimin = 0;
65 static constexpr
float m_phimax = 2.*M_PI;
69 static constexpr
float m_rmin = 20;
70 static constexpr
float m_rmax = 78;
73 static constexpr
float m_zmin = -105.5;
74 static constexpr
float m_zmax = 105.5;
79 std::vector<TrkrDefs::cluskey>
out;
83 { std::copy(
seed->begin_cluster_keys(),
seed->end_cluster_keys(), std::back_inserter( out ) ); }
90 int count_clusters(
const std::vector<TrkrDefs::cluskey>& keys )
92 return std::count_if( keys.begin(), keys.end(),
98 out <<
"(" << vector.x() <<
", " << vector.y() <<
", " << vector.z() <<
")";
145 std::cout <<
"TpcSpaceChargeReconstruction::InitRun - m_outputfile: " <<
m_outputfile << std::endl;
146 std::cout <<
"TpcSpaceChargeReconstruction::InitRun - m_use_micromegas: " << std::boolalpha <<
m_use_micromegas << std::endl;
147 std::cout <<
"TpcSpaceChargeReconstruction::InitRun - m_max_talpha: " <<
m_max_talpha << std::endl;
148 std::cout <<
"TpcSpaceChargeReconstruction::InitRun - m_max_drphi: " <<
m_max_drphi << std::endl;
149 std::cout <<
"TpcSpaceChargeReconstruction::InitRun - m_max_tbeta: " <<
m_max_tbeta << std::endl;
150 std::cout <<
"TpcSpaceChargeReconstruction::InitRun - m_max_dz: " <<
m_max_dz << std::endl;
151 std::cout <<
"TpcSpaceChargeReconstruction::InitRun - m_min_pt: " <<
m_min_pt <<
" GeV/c" << std::endl;
181 std::unique_ptr<TFile> outputfile( TFile::Open(
m_outputfile.c_str(),
"RECREATE" ) );
190 for(
const auto& [cell,
h]:
m_h_drphi ) {
if(
h)
h->Write(); }
191 for(
const auto& [cell,
h]:
m_h_dz ) {
if(
h)
h->Write(); }
199 <<
"TpcSpaceChargeReconstruction::End -"
206 <<
"TpcSpaceChargeReconstruction::End -"
229 m_tgeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
232 m_track_map = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
235 m_cluster_map = findNode::getClass<TrkrClusterContainer>(topNode,
"CORRECTED_TRKR_CLUSTER");
240 { std::cout <<
"TpcSpaceChargeReconstruction::load_nodes - Using CORRECTED_TRKR_CLUSTER node " << std::endl; }
245 { std::cout <<
"TpcSpaceChargeReconstruction::load_nodes - CORRECTED_TRKR_CLUSTER node not found, using TRKR_CLUSTER" << std::endl; }
246 m_cluster_map = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
254 m_dcc_static = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainerStatic");
255 m_dcc_average = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainerAverage");
256 m_dcc_fluctuation = findNode::getClass<TpcDistortionCorrectionContainer>(topNode,
"TpcDistortionCorrectionContainerFluctuation");
264 std::cout <<
"TpcSpaceChargeReconstruction::create_histograms - writing evaluation histograms to: " <<
m_histogramfilename << std::endl;
275 std::set<int> phibin_rec;
276 std::transform( phi_rec.begin(), phi_rec.end(), std::inserter( phibin_rec, phibin_rec.end() ), [&](
const float& phi ) {
return phibins*(phi-m_phimin)/(m_phimax-m_phimin); } );
278 std::set<int> zbin_rec;
279 std::transform( z_rec.begin(), z_rec.end(), std::inserter( zbin_rec, zbin_rec.end() ), [&](
const float&
z ) {
return zbins*(z-m_zmin)/(m_zmax-m_zmin); } );
282 for(
int iphi = 0; iphi <
phibins; ++iphi )
283 for(
int ir = 0; ir < rbins; ++ir )
284 for(
int iz = 0; iz < zbins; ++iz )
287 if( phibin_rec.find( iphi ) == phibin_rec.end() || zbin_rec.find( iz ) == zbin_rec.end() )
continue;
292 const auto hname = Form(
"residual_drphi_p%i_r%i_z%i", iphi, ir, iz );
294 h->GetXaxis()->SetTitle(
"r.#Delta#phi_{cluster-track} (cm)" );
295 m_h_drphi.insert( std::make_pair( icell,
h ) );
300 const auto hname = Form(
"residual_2d_drphi_p%i_r%i_z%i", iphi, ir, iz );
302 h->GetXaxis()->SetTitle(
"tan#alpha" );
303 h->GetYaxis()->SetTitle(
"r.#Delta#phi_{cluster-track} (cm)" );
309 const auto hname = Form(
"residual_dz_p%i_r%i_z%i", iphi, ir, iz );
311 h->GetXaxis()->SetTitle(
"#Deltaz_{cluster-track} (cm)" );
312 m_h_dz.insert( std::make_pair( icell,
h ) );
317 static constexpr
double max_tbeta = 0.5;
318 const auto hname = Form(
"residual_2d_dz_p%i_r%i_z%i", iphi, ir, iz );
319 auto h =
new TH2F( hname, hname, 100, -max_tbeta, max_tbeta, 100, -
m_max_dz, +
m_max_dz );
320 h->GetXaxis()->SetTitle(
"tan#beta" );
321 h->GetYaxis()->SetTitle(
"#Deltaz_{cluster-track} (cm)" );
357 return globalPosition;
386 if( count_clusters<TrkrDefs::mvtxId>(cluster_keys) < 2 )
return false;
387 if( count_clusters<TrkrDefs::inttId>(cluster_keys) < 2 )
return false;
388 if(
m_use_micromegas && count_clusters<TrkrDefs::micromegasId>(cluster_keys) < 2 )
return false;
403 const auto& [pathlength,
state] = *iter;
405 const auto phi = std::atan2(
state->get_y(),
state->get_x() );
406 std::cout <<
"TpcSpaceChargeReconstruction::process_track -"
407 <<
" pathlength: " << pathlength
410 <<
" z: " <<
state->get_z()
418 assert( crossing != SHRT_MAX );
430 std::cout <<
PHWHERE <<
" unable to find cluster for key " << cluster_key << std::endl;
442 const auto cluster_r =
get_r( global_position.x(), global_position.y() );
443 const auto cluster_phi = std::atan2( global_position.y(), global_position.x() );
444 const auto cluster_z = global_position.z();
447 double cluster_rphi_error = cluster->getRPhiError();
448 double cluster_z_error = cluster->getZError();
458 for(
auto iter = state_iter; iter != track->
end_states(); ++iter )
460 const auto dr = std::abs( cluster_r -
get_r( iter->second->get_x(), iter->second->get_y() ) );
461 if( dr_min < 0 || dr < dr_min )
470 const auto state = state_iter->second;
474 const auto dr = cluster_r - track_r;
475 const auto track_drdt = (
state->get_x()*
state->get_px() +
state->get_y()*
state->get_py())/track_r;
476 const auto track_dxdr =
state->get_px()/track_drdt;
477 const auto track_dydr =
state->get_py()/track_drdt;
478 const auto track_dzdr =
state->get_pz()/track_drdt;
481 const auto track_x =
state->get_x() + dr*track_dxdr;
482 const auto track_y =
state->get_y() + dr*track_dydr;
483 const auto track_z =
state->get_z() + dr*track_dzdr;
484 const auto track_phi = std::atan2( track_y, track_x );
487 const auto cosphi( std::cos( track_phi ) );
488 const auto sinphi( std::sin( track_phi ) );
489 const auto track_pphi = -
state->get_px()*sinphi +
state->get_py()*cosphi;
490 const auto track_pr =
state->get_px()*cosphi +
state->get_py()*sinphi;
491 const auto track_pz =
state->get_pz();
492 const auto talpha = -track_pphi/track_pr;
493 const auto tbeta = -track_pz/track_pr;
496 if( std::isnan(talpha) )
498 std::cout <<
"TpcSpaceChargeReconstruction::process_track - talpha is nan" << std::endl;
502 if( std::isnan(tbeta) )
504 std::cout <<
"TpcSpaceChargeReconstruction::process_track - tbeta is nan" << std::endl;
509 const auto track_rphi_error =
state->get_rphi_error();
510 const auto track_z_error =
state->get_z_error();
513 const auto drp = cluster_r*
delta_phi( cluster_phi - track_phi );
514 const auto dz = cluster_z - track_z;
517 if( std::isnan(drp) )
519 std::cout <<
"TpcSpaceChargeReconstruction::process_track - drp is nan" << std::endl;
525 std::cout <<
"TpcSpaceChargeReconstruction::process_track - dz is nan" << std::endl;
530 const auto erp =
square(track_rphi_error) +
square(cluster_rphi_error);
531 const auto ez =
square(track_z_error) +
square(cluster_z_error);
535 if( std::isnan( erp ) )
537 std::cout <<
"TpcSpaceChargeReconstruction::process_track - erp is nan" << std::endl;
541 if( std::isnan( ez ) )
543 std::cout <<
"TpcSpaceChargeReconstruction::process_track - ez is nan" << std::endl;
551 std::cout <<
"TpcSpaceChargeReconstruction::process_track - invalid cell index" << std::endl;
557 {
const auto iter =
m_h_drphi.find(
i );
if( iter !=
m_h_drphi.end() ) iter->second->Fill( drp ); }
559 {
const auto iter =
m_h_dz.find(
i );
if( iter !=
m_h_dz.end() ) iter->second->Fill(
dz ); }
573 std::cout <<
"TpcSpaceChargeReconstruction::process_track - layer: " << (int)
TrkrDefs::getLayer(cluster_key) << std::endl;
574 std::cout <<
"TpcSpaceChargeReconstruction::process_track -"
575 <<
" cluster: (" << cluster_r <<
", " << cluster_r*cluster_phi <<
", " << cluster_z <<
")"
576 <<
" (" << cluster_rphi_error <<
", " << cluster_z_error <<
")"
578 std::cout <<
"TpcSpaceChargeReconstruction::process_track -"
579 <<
" track: (" << track_r <<
", " << cluster_r*track_phi <<
", " << track_z <<
")"
580 <<
" (" << talpha <<
", " << tbeta <<
")"
581 <<
" (" << track_rphi_error <<
", " << track_z_error <<
")"
583 std::cout << std::endl;
625 float phi = std::atan2( global_position.y(), global_position.x() );
626 while( phi < m_phimin ) phi += 2.*M_PI;
627 while( phi >= m_phimax ) phi -= 2.*M_PI;
628 int iphi = phibins*(phi-m_phimin)/(m_phimax-m_phimin);
631 const float r =
get_r( global_position.x(), global_position.y() );
632 if( r < m_rmin || r >= m_rmax )
return -1;
633 int ir = rbins*(r-m_rmin)/(m_rmax-m_rmin);
636 const float z = global_position.z();
637 if( z < m_zmin || z >= m_zmax )
return -1;
638 int iz = zbins*(z-m_zmin)/(m_zmax-m_zmin);