39 template<
class T>
class range_adaptor
42 range_adaptor(
const T& range ):m_range(range){}
43 inline const typename T::first_type&
begin() {
return m_range.first;}
44 inline const typename T::second_type&
end() {
return m_range.second;}
51 inline constexpr
T square(
const T&
x ) {
return x*
x; }
58 std::pair<double, double> line_circle_intersection(
const TVector3&
p,
const TVector3& d,
double radius )
60 std::pair<double,double> ret = std::make_pair(-1, -1);
63 const double B = 2*p.x()*d.x() + 2*p.y()*d.y();
66 if( delta < 0 )
return ret;
69 const double tup = (-B + std::sqrt(delta))/(2*A);
70 const double tdn = (-B-sqrt(delta))/(2*A);
72 ret = std::make_pair(tup, tdn);
88 inline std::ostream&
operator << (std::ostream&
out,
const TVector3& vector )
90 out <<
"( " << vector.x() <<
", " << vector.y() <<
", " << vector.z() <<
")";
98 if( phi >= M_PI )
return phi - 2*M_PI;
99 else if( phi < -M_PI )
return phi + 2*M_PI;
104 static constexpr
float m_phimin = 0;
105 static constexpr
float m_phimax = 2.*M_PI;
109 static constexpr
float m_rmin = 20;
110 static constexpr
float m_rmax = 78;
113 static constexpr
float m_zmin = -105.5;
114 static constexpr
float m_zmax = 105.5;
150 <<
"TpcDirectLaserReconstruction::InitRun\n"
154 <<
" m_max_dz: " <<
m_max_dz <<
"\n"
181 std::unique_ptr<TFile> outputfile( TFile::Open(
m_outputfile.c_str(),
"RECREATE" ) );
192 for(
const auto& o:std::initializer_list<TObject*>({
h_dca_layer,
h_deltarphi_layer_south,
h_deltarphi_layer_north,
h_deltaz_layer,
h_deltar_r,
h_deltheta_delphi,
h_deltheta_delphi_1,
h_deltheta_delphi_2,
h_deltheta_delphi_3,
h_deltheta_delphi_4,
h_deltheta_delphi_5,
h_deltheta_delphi_6,
h_deltheta_delphi_7,
h_deltheta_delphi_8,
h_entries,
h_hits,
h_hits_reco,
h_adc,
h_adc_reco,
h_adc_sum,
h_adc_sum_reco,
h_adc_sum_ratio,
h_adc_sum_ratio_true,
h_adc_vs_DCA_true,
h_adc_sum_ratio_lasrangle,
h_num_sum,
h_num_sum_reco,
h_num_sum_ratio,
194 h_relangle_theta_lasrangle,
h_relangle_phi_lasrangle,
h_GEMs_hit,
h_layers_hit,
h_xy,
h_xz,
h_xy_pca,
h_xz_pca,
h_dca_path,
h_zr,
h_zr_pca,
h_dz_z }))
196 {
if( o ) o->Write(); }
211 std::cout <<
"TpcDirectLaserReconstruction::End - m_total_hits: " <<
m_total_hits << std::endl;
212 std::cout <<
"TpcDirectLaserReconstruction::End - m_matched_hits: " <<
m_matched_hits << std::endl;
213 std::cout <<
"TpcDirectLaserReconstruction::End - m_accepted_clusters: " <<
m_accepted_clusters << std::endl;
242 m_geom_container = findNode::getClass<PHG4TpcCylinderGeomContainer>(topNode,
"CYLINDERCELLGEOM_SVTX");
246 m_tGeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
250 m_track_map = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
254 m_hit_map = findNode::getClass<TrkrHitSetContainer>(topNode,
"TRKR_HITSET");
263 std::cout <<
"TpcDirectLaserReconstruction::makeHistograms - writing evaluation histograms to: " <<
m_histogramfilename << std::endl;
268 h_dca_layer =
new TH2F(
"dca_layer",
";radius; DCA (cm)", 78, 0, 78, 500, 0, 20 );
269 h_deltarphi_layer_north =
new TH2F(
"deltarphi_layer_north",
";radius; r.#Delta#phi_{track-cluster} (cm)", 78, 0, 78, 2000, -5, 5 );
270 h_deltarphi_layer_south =
new TH2F(
"deltarphi_layer_south",
";radius; r.#Delta#phi_{track-cluster} (cm)", 78, 0, 78, 2000, -5, 5 );
271 h_deltaz_layer =
new TH2F(
"deltaz_layer",
";radius; #Deltaz_{track-cluster} (cm)", 78, 0, 78, 2000, -20, 20 );
272 h_deltar_r =
new TH2F(
"deltar_r",
";radius;#Deltar_{track-cluster} (cm)", 78,0,78,2000,-3,3);
274 h_xy =
new TH2F(
"h_xy",
" x vs y", 320,-80,80,320,-80,80);
275 h_xz =
new TH2F(
"h_xz",
" x vs z", 320,-80,80,440,-110,110);
276 h_xy_pca =
new TH2F(
"h_xy_pca",
" x vs y pca", 320,-80,80,320,-80,80);
277 h_xz_pca =
new TH2F(
"h_xz_pca",
" x vs z pca", 320,-80,80,440,-110,110);
278 h_dca_path =
new TH2F(
"h_dca_path",
" dca vs pathlength", 440,0,110,100,0,20);
279 h_zr =
new TH2F(
"h_zr",
" z vs r", 440,-110,110,1000,28,80);
280 h_zr->GetXaxis()->SetTitle(
"z");
281 h_zr->GetYaxis()->SetTitle(
"rad");
282 h_zr_pca =
new TH2F(
"h_zr_pca",
" z vs r pca", 440,-110,110,1000,28,80);
283 h_dz_z =
new TH2F(
"h_dz_z",
" dz vs z", 440,-110,110, 1000, -20, 20);
285 h_hits =
new TNtuple(
"hits",
"raw hits",
"x:y:z:adc");
286 h_hits_reco =
new TNtuple(
"hits_reco",
"raw hits",
"x:y:z:adc");
288 h_adc =
new TH1F(
"adc",
"pedestal subtracted ADC spectra of ALL lasers (MCTRUTH direction)",1063,-19.5,1042.5);
289 h_adc->SetXTitle(
"ADC - PEDESTAL [ADU]");
291 h_adc_reco =
new TH1F(
"adc_reco",
"pedestal subtracted ADC spectra of ALL lasers (RECO DIRECTION)",1063,-19.5,1042.5);
292 h_adc_reco->SetXTitle(
"ADC - PEDESTAL [ADU]");
294 h_adc_sum =
new TH1F(
"adc_sum",
"non-pedestal subtracted sum of ADC for each laser (MCTRUTH DIRECTION)",1600,-0.5,159999.5);
295 h_adc_sum->SetXTitle(
"#Sigma ADC [ADU]");
297 h_adc_sum_reco =
new TH1F(
"adc_sum_reco",
"non-pedestal subtracted sum of ADC for each laser (RECO DIRECTION)",1600,-0.5,159999.5);
300 h_num_sum =
new TH1F(
"num_sum",
"sum of hits for each laser (MCTRUTH DIRECTION)",1600,-0.5,7999.5);
301 h_num_sum->SetXTitle(
"#Sigma N_{hits}^{laser X} [arb. units]");
303 h_num_sum_reco =
new TH1F(
"num_sum_reco",
"sum of hits for each laser (RECO DIRECTION)",1600,-0.5,7999.5);
304 h_num_sum_reco->SetXTitle(
"#Sigma N_{hits}^{laser X} [arb. units]");
306 h_adc_sum_ratio =
new TH1F(
"adc_sum_ratio",
"RATIO of non-pedestal subtracted sum of ADC for each laser (RECO DIRECTION/MCTRUTH DIRECTION)",120,-0.5,5.5);
307 h_adc_sum_ratio->SetXTitle(
"#frac{#Sigma^{RECO} ADC}{#Sigma^{MCTRUTH} ADC} [arb. units]");
309 h_adc_sum_ratio_true =
new TH1F(
"adc_sum_ratio_true",
"RATIO of non-pedestal subtracted sum of ADC for each laser (MCTRUTH DIRECTION/ALL )",120,-0.5,5.5);
312 h_num_sum_ratio =
new TH1F(
"num_sum_ratio",
"RATIO of number of hits associated to each laser (RECO DIRECTION/MCTRUTH DIRECTION)",120,-0.5,5.5);
313 h_num_sum_ratio->SetXTitle(
"#frac{#Sigma^{RECO} N_{hits}^{laser X}}{#Sigma^{MCTRUTH} N_{hits}^{laser X}} [arb. units]");
315 h_num_sum_ratio_true =
new TH1F(
"num_sum_ratio_true",
"RATIO of number of hits associated to each laser (MCTRUTH DIRECTION/ALL )",120,-0.5,5.5);
316 h_num_sum_ratio_true->SetXTitle(
"#frac{#Sigma^{MCTRUTH} N_{hits}^{laser X}}{#Sigma^{ALL} N_{hits}^{laser X}} [arb. units]");
318 h_adc_vs_DCA_true =
new TH2F(
"adc_vs_DCA_true",
"PEDESTAL SUBTRACTED ADC vs DCA for ALL HITS from ALL LASERS",100,0,100,1024,-0.5,1023.5);
322 h_adc_sum_ratio_lasrangle =
new TH2F(
"adc_sum_ratio_lasrangle",
"RATIO of non-pedestal subtracted sum of ADC for LASER 1 ONLY (RECO DIRECTION/MCTRUTH DIRECTION)",91,-0.5,90.5,361,-0.5,360.5);
326 h_num_sum_ratio_lasrangle =
new TH2F(
"num_sum_ratio_lasrangle",
"RATIO of sum of hits for LASER 1 ONLY (RECO DIRECTION/MCTRUTH DIRECTION)",91,-0.5,90.5,361,-0.5,360.5);
330 h_bright_hits_laser1 =
new TNtuple(
"bright_hits_laser1",
"bright hits relative to laser 1",
"x:y:z:deltheta:delphi");
331 h_bright_hits_laser2 =
new TNtuple(
"bright_hits_laser2",
"bright hits relative to laser 2",
"x:y:z:deltheta:delphi");
332 h_bright_hits_laser3 =
new TNtuple(
"bright_hits_laser3",
"bright hits relative to laser 3",
"x:y:z:deltheta:delphi");
333 h_bright_hits_laser4 =
new TNtuple(
"bright_hits_laser4",
"bright hits relative to laser 4",
"x:y:z:deltheta:delphi");
340 h_relangle_lasrangle =
new TH2F(
"relangle_lasrangle",
"Difference in pointing angle from laser and relative angle histogram for ALL lasers",102,-25.5,25.5,102,-25.5,25.5);
344 h_relangle_theta_lasrangle =
new TH2F(
"relangle_theta_lasrangle",
"#delta#theta from laser and relative angle histogram for LASER 1 ONLY, ",91,-0.5,90.5,361,-0.5,360.5);
348 h_relangle_phi_lasrangle =
new TH2F(
"relangle_phi_lasrangle",
"#delta#phi from laser and relative angle histogram for LASER 1 ONLY",91,-0.5,90.5,361,-0.5,360.5);
352 h_deltheta_delphi =
new TH2F(
"deltheta_delphi",
"#Delta#theta, #Delta#phi for separation b/w TPC volume hits and ALL laser start points", 181, -0.5,180.5,361,-0.5,360.5);
356 h_deltheta_delphi_1 =
new TH2F(
"deltheta_delphi_1",
"#Delta#theta, #Delta#phi for separation b/w TPC volume hits and LASER 1 only", 181, -0.5,180.5,361,-0.5,360.5);
360 h_deltheta_delphi_2 =
new TH2F(
"deltheta_delphi_2",
"#Delta#theta, #Delta#phi for separation b/w TPC volume hits and LASER 2 only", 181, -0.5,180.5,361,-0.5,360.5);
364 h_deltheta_delphi_3 =
new TH2F(
"deltheta_delphi_3",
"#Delta#theta, #Delta#phi for separation b/w TPC volume hits and LASER 3 only", 181, -0.5,180.5,361,-0.5,360.5);
368 h_deltheta_delphi_4 =
new TH2F(
"deltheta_delphi_4",
"#Delta#theta, #Delta#phi for separation b/w TPC volume hits and LASER 4 only", 181, -0.5,180.5,361,-0.5,360.5);
372 h_deltheta_delphi_5 =
new TH2F(
"deltheta_delphi_5",
"#Delta#theta, #Delta#phi for separation b/w TPC volume hits and LASER 5 only", 181, -0.5,180.5,361,-0.5,360.5);
376 h_deltheta_delphi_6 =
new TH2F(
"deltheta_delphi_6",
"#Delta#theta, #Delta#phi for separation b/w TPC volume hits and LASER 6 only", 181, -0.5,180.5,361,-0.5,360.5);
380 h_deltheta_delphi_7 =
new TH2F(
"deltheta_delphi_7",
"#Delta#theta, #Delta#phi for separation b/w TPC volume hits and LASER 7 only", 181, -0.5,180.5,361,-0.5,360.5);
384 h_deltheta_delphi_8 =
new TH2F(
"deltheta_delphi_8",
"#Delta#theta, #Delta#phi for separation b/w TPC volume hits and LASER 8 only", 181, -0.5,180.5,361,-0.5,360.5);
389 h_GEMs_hit =
new TH1F(
"GEMS_hit",
"Number of Unique GEM Modules hit for each laser",8,0,8);
390 h_layers_hit =
new TH1F(
"layers_hit",
"Number of Unique Layers hit for each laser",8,8,8);
392 char GEM_bin_label[128];
393 for(
int GEMhistiter = 0; GEMhistiter < 8; GEMhistiter++)
395 sprintf(GEM_bin_label,
"laser %i",GEMhistiter+1);
396 h_GEMs_hit->GetXaxis()->SetBinLabel(GEMhistiter+1,GEM_bin_label);
397 h_layers_hit->GetXaxis()->SetBinLabel(GEMhistiter+1,GEM_bin_label);
399 h_GEMs_hit->SetYTitle(
"Number of Unique GEM Modules Hit");
410 h_entries =
new TH3F(
"entries",
";#phi;r (cm);z (cm)", phibins, m_phimin, m_phimax, rbins, m_rmin, m_rmax, zbins, m_zmin, m_zmax );
427 std::multimap<unsigned int, std::pair<float, TVector3>> cluspos_map;
428 std::set<unsigned int> layer_bin_set;
441 const unsigned int trkid = track->
get_id();
443 const float theta_orig =
origin.Theta();
444 const float phi_orig =
origin.Phi();
446 float theta_trk = direction.Theta();
447 direction2.RotateZ(-phi_orig);
448 float phi_trk = direction2.Phi();
450 if(theta_trk > M_PI/2.) theta_trk = M_PI - theta_trk;
454 while( phi_trk < m_phimin ) phi_trk += 2.*M_PI;
455 while( phi_trk >= m_phimax ) phi_trk -= 2.*M_PI;
463 if( track->
get_id() > 3 ){ phi_trk = (2 * M_PI) - phi_trk;}
467 std::cout <<
"---------- processing track " << track->
get_id() << std::endl;
468 std::cout <<
"TpcDirectLaserReconstruction::process_track - position: " <<
origin <<
" direction: " << direction << std::endl;
469 std::cout <<
"Position Orientation - Theta: " << theta_orig*(180./M_PI) <<
", Phi: " << phi_orig*(180./M_PI) << std::endl;
470 std::cout <<
"Track Angle Direction - Theta: " << theta_trk*(180./M_PI) <<
", Phi: " << phi_trk*(180./M_PI) << std::endl;
473 int GEM_Mod_Arr[72] = {0};
479 float sum_adc_truth=0;
480 float sum_adc_truth_all=0;
482 float sum_n_hits_truth=0;
483 float sum_n_hits_truth_all=0;
485 for(
auto hitsetitr = hitsetrange.first; hitsetitr != hitsetrange.second; ++hitsetitr)
490 auto hitset = hitsetitr->second;
493 const auto layer_center_radius = layergeom->
get_radius();
497 static constexpr
double AdcClockPeriod = 53.0;
498 const unsigned short NTBins = (
unsigned short)layergeom->get_zbins();
499 const float tdriftmax = AdcClockPeriod * NTBins / 2.0;
504 for (
auto hitr = hitrangei.first; hitr != hitrangei.second; ++hitr)
507 sum_n_hits_truth_all++;
512 const double phi = layergeom->get_phicenter(phibin);
513 const double x = layer_center_radius * cos(phi);
514 const double y = layer_center_radius * sin(phi);
518 if(side == 0) z *= -1;
520 const TVector3 global(x,y,z);
522 float adc = (hitr->second->getAdc()) -
m_pedestal;
523 float adc_unsub = (hitr->second->getAdc());
524 sum_adc_truth_all += adc_unsub;
531 if( adc > max_adc ){ max_adc = adc; }
536 const TVector3 oc( global.x()-
origin.x(), global.y()-
origin.y(), global.z()-
origin.z() );
537 auto t = direction.Dot( oc )/
square( direction.Mag() );
538 auto om = direction*
t;
539 const auto dca = (oc-om).Mag();
553 oc2.RotateZ(-phi_orig);
565 float deltheta = oc2.Theta();
566 float delphi = oc2.Phi();
568 if (deltheta > M_PI/2.) deltheta = M_PI - deltheta;
570 while( delphi < m_phimin ) delphi += 2.*M_PI;
571 while( delphi >= m_phimax ) delphi -= 2.*M_PI;
573 if( track->
get_id() > 3 ){ delphi = (2 * M_PI) - delphi;}
577 deltheta *= (180./M_PI);
578 delphi *= (180./M_PI);
668 if(sameside){sum_n_hits_truth++;
h_adc->Fill(adc);sum_adc_truth += adc_unsub;}
677 float r2 = std::sqrt((x*x) + (y*y));
680 while( phi3 < m_phimin ) phi3 += 2.*M_PI;
681 while( phi3 >= m_phimax ) phi3 -= 2.*M_PI;
683 const int locateid =
Locate(r2 , phi3 , z2);
685 if( z2 > m_zmin || z2 < m_zmax ) GEM_Mod_Arr[locateid-1]++;
688 const auto cluspos_pair = std::make_pair(adc, global);
689 cluspos_map.insert(std::make_pair(layer, cluspos_pair));
690 layer_bin_set.insert(layer);
697 if(sum_adc_truth_all > 0)
702 if(sum_n_hits_truth_all > 0)
708 int deltheta_max, delphi_max, dummy_z;
713 float direction_reco;
714 if( trkid < 4 ){direction_reco = -1;}
715 else{direction_reco = 1;}
717 TVector3 dir(0, 0, direction_reco);
721 h_deltheta_delphi_1->GetXaxis()->SetRangeUser(-5+(theta_trk*(180./M_PI)),5+(theta_trk*(180./M_PI)));
722 h_deltheta_delphi_1->GetYaxis()->SetRangeUser(-5+(phi_trk*(180./M_PI)),5+(phi_trk*(180./M_PI)));
728 std::cout <<
"Laser # "<<(trkid+1)<<
" naieve deltheta max: "<<
h_deltheta_delphi_1->GetXaxis()->GetBinCenter(deltheta_max) <<
", naieve delphi max: "<<
h_deltheta_delphi_1->GetYaxis()->GetBinCenter(delphi_max) << std::endl;
741 h_deltheta_delphi_2->GetXaxis()->SetRangeUser(-5+(theta_trk*(180./M_PI)),5+(theta_trk*(180./M_PI)));
742 h_deltheta_delphi_2->GetYaxis()->SetRangeUser(-5+(phi_trk*(180./M_PI)),5+(phi_trk*(180./M_PI)));
748 std::cout <<
"Laser # "<<(trkid+1)<<
" naieve deltheta max: "<<
h_deltheta_delphi_2->GetXaxis()->GetBinCenter(deltheta_max) <<
", naive delphi max: "<<
h_deltheta_delphi_2->GetYaxis()->GetBinCenter(delphi_max) << std::endl;
761 h_deltheta_delphi_3->GetXaxis()->SetRangeUser(-5+(theta_trk*(180./M_PI)),5+(theta_trk*(180./M_PI)));
762 h_deltheta_delphi_3->GetYaxis()->SetRangeUser(-5+(phi_trk*(180./M_PI)),5+(phi_trk*(180./M_PI)));
768 std::cout <<
"Laser # "<<(trkid+1)<<
" naieve deltheta max: "<<
h_deltheta_delphi_3->GetXaxis()->GetBinCenter(deltheta_max) <<
", naive delphi max: "<<
h_deltheta_delphi_3->GetYaxis()->GetBinCenter(delphi_max) << std::endl;
781 h_deltheta_delphi_4->GetXaxis()->SetRangeUser(-5+(theta_trk*(180./M_PI)),5+(theta_trk*(180./M_PI)));
782 h_deltheta_delphi_4->GetYaxis()->SetRangeUser(-5+(phi_trk*(180./M_PI)),5+(phi_trk*(180./M_PI)));
788 std::cout <<
"Laser # "<<(trkid+1)<<
" naieve deltheta max: "<<
h_deltheta_delphi_4->GetXaxis()->GetBinCenter(deltheta_max) <<
", naieve delphi max: "<<
h_deltheta_delphi_4->GetYaxis()->GetBinCenter(delphi_max) << std::endl;
801 h_deltheta_delphi_5->GetXaxis()->SetRangeUser(-5+(theta_trk*(180./M_PI)),5+(theta_trk*(180./M_PI)));
802 h_deltheta_delphi_5->GetYaxis()->SetRangeUser(-5+(phi_trk*(180./M_PI)),5+(phi_trk*(180./M_PI)));
808 std::cout <<
"Laser # "<<(trkid+1)<<
" deltheta max: "<<
h_deltheta_delphi_5->GetXaxis()->GetBinCenter(deltheta_max) <<
", delphi max: "<<
h_deltheta_delphi_5->GetYaxis()->GetBinCenter(delphi_max) << std::endl;
821 h_deltheta_delphi_6->GetXaxis()->SetRangeUser(-5+(theta_trk*(180./M_PI)),5+(theta_trk*(180./M_PI)));
822 h_deltheta_delphi_6->GetYaxis()->SetRangeUser(-5+(phi_trk*(180./M_PI)),5+(phi_trk*(180./M_PI)));
828 std::cout <<
"Laser # "<<(trkid+1)<<
" deltheta max: "<<
h_deltheta_delphi_6->GetXaxis()->GetBinCenter(deltheta_max) <<
", delphi max: "<<
h_deltheta_delphi_6->GetYaxis()->GetBinCenter(delphi_max) << std::endl;
841 h_deltheta_delphi_7->GetXaxis()->SetRangeUser(-5+(theta_trk*(180./M_PI)),5+(theta_trk*(180./M_PI)));
842 h_deltheta_delphi_7->GetYaxis()->SetRangeUser(-5+(phi_trk*(180./M_PI)),5+(phi_trk*(180./M_PI)));
848 std::cout <<
"Laser # "<<(trkid+1)<<
" deltheta max: "<<
h_deltheta_delphi_7->GetXaxis()->GetBinCenter(deltheta_max) <<
", delphi max: "<<
h_deltheta_delphi_7->GetYaxis()->GetBinCenter(delphi_max) << std::endl;
861 h_deltheta_delphi_8->GetXaxis()->SetRangeUser(-5+(theta_trk*(180./M_PI)),5+(theta_trk*(180./M_PI)));
862 h_deltheta_delphi_8->GetYaxis()->SetRangeUser(-5+(phi_trk*(180./M_PI)),5+(phi_trk*(180./M_PI)));
868 std::cout <<
"Laser # "<<(trkid+1)<<
" deltheta max: "<<
h_deltheta_delphi_8->GetXaxis()->GetBinCenter(deltheta_max) <<
", delphi max: "<<
h_deltheta_delphi_8->GetYaxis()->GetBinCenter(delphi_max) << std::endl;
880 dir.RotateY(theta_reco* direction_reco);
881 if(direction_reco == -1) dir.RotateZ(phi_reco);
882 else dir.RotateZ(-phi_reco);
883 dir.RotateZ(phi_orig);
887 TVector3 direction2_reco( dir.Px(), dir.Py(), dir.Pz() );
889 float theta_trk_reco = dir.Theta();
890 direction2_reco.RotateZ(-phi_orig);
891 float phi_trk_reco = direction2_reco.Phi();
893 if(theta_trk_reco > M_PI/2.) theta_trk_reco = M_PI - theta_trk_reco;
897 while( phi_trk_reco < m_phimin ) phi_trk_reco += 2.*M_PI;
898 while( phi_trk_reco >= m_phimax ) phi_trk_reco -= 2.*M_PI;
906 if( track->
get_id() > 3 ){ phi_trk_reco = (2 * M_PI) - phi_trk_reco;}
908 std::cout <<
"RECONSTRUCTED Track Angle Direction - Theta: " << theta_trk_reco*(180./M_PI) <<
", Phi: " << phi_trk_reco*(180./M_PI) << std::endl;
914 float sum_adc_reco=0;
915 float sum_n_hits_reco=0;
917 for(
auto hitsetitr = hitsetrange.first; hitsetitr != hitsetrange.second; ++hitsetitr)
922 auto hitset_2 = hitsetitr->second;
925 const auto layer_center_radius_2 = layergeom_2->
get_radius();
929 static constexpr
double AdcClockPeriod_2 = 53.0;
930 const unsigned short NTBins_2 = (
unsigned short)layergeom_2->get_zbins();
931 const float tdriftmax_2 = AdcClockPeriod_2 * NTBins_2 / 2.0;
936 for (
auto hitr = hitrangei_2.first; hitr != hitrangei_2.second; ++hitr)
942 const double phi_2 = layergeom_2->get_phicenter(phibin_2);
943 const double x_2 = layer_center_radius_2 * cos(phi_2);
944 const double y_2 = layer_center_radius_2 * sin(phi_2);
948 if(side_2 == 0) z_2 *= -1;
950 const TVector3 global_2(x_2,y_2,z_2);
954 float adc_2 = (hitr->second->getAdc()) -
m_pedestal;
955 float adc_2_unsub = (hitr->second->getAdc());
959 const TVector3 oc_2( global_2.x()-
origin.x(), global_2.y()-
origin.y(), global_2.z()-
origin.z() );
960 auto t_2 = dir.Dot( oc_2 )/
square( dir.Mag() );
962 const auto dca_2 = (oc_2-om_2).Mag();
965 if(sameside_reco){sum_n_hits_reco++;
h_adc_reco->Fill(adc_2);sum_adc_reco += adc_2_unsub;}
978 if(sum_adc_truth > 0)
987 if(sum_n_hits_truth > 0)
996 for(
int GEMS_iter = 0; GEMS_iter < 72; GEMS_iter++)
998 if(GEM_Mod_Arr[GEMS_iter] > 0){
1020 for(
auto layer : layer_bin_set)
1023 const auto layer_center_radius = layergeom->
get_radius();
1024 const auto layer_inner_radius = layer_center_radius - layergeom->
get_thickness() / 2.0;
1025 const auto layer_outer_radius = layer_center_radius + layergeom->
get_thickness() / 2.0;
1030 auto tupdn = line_circle_intersection(
origin, direction, layer_outer_radius);
1031 if( tupdn.first <= 0 && tupdn.second <= 0)
1033 std::cout <<
" punt: layer " <<
layer <<
" layer outer radius " << layer_outer_radius <<
" tup " << tupdn.first <<
" tdn " << tupdn.second << std::endl;
1036 double layer_entry = tupdn.first;
1037 if(tupdn.second >= 0 && tupdn.second < tupdn.first) layer_entry = tupdn.second;
1039 tupdn = line_circle_intersection(
origin, direction, layer_inner_radius);
1040 if( tupdn.first <= 0 && tupdn.second <= 0)
1042 std::cout <<
" punt: layer " <<
layer <<
" layer inner radius " << layer_inner_radius <<
" tup " << tupdn.first <<
" tdn " << tupdn.second << std::endl;
1045 double layer_exit = tupdn.first;
1046 if(tupdn.second > 0 && tupdn.second < tupdn.first) layer_exit = tupdn.second;
1047 if(
Verbosity() > 2) std::cout <<
" layer " <<
layer <<
" layer entry " << layer_entry <<
" layer exit " << layer_exit << std::endl;
1050 tupdn = line_circle_intersection(
origin, direction, layer_center_radius);
1051 double tup = tupdn.first;
1052 double tdn = tupdn.second;
1055 if(tdn > 0 && tdn < tup) t = tdn;
1058 std::cout <<
" punt: layer " <<
layer <<
" layer center radius " << layer_center_radius <<
" t " << t <<
" tup " << tupdn.first <<
" tdn " << tupdn.second << std::endl;
1063 auto om = direction*
t;
1066 const auto projection =
origin + om;
1068 double zmax = -999.;
1071 auto bin_residual = cluspos_map.equal_range(
layer);
1073 TVector3 clus_centroid(0,0,0);
1075 for(
auto mit = bin_residual.first; mit != bin_residual.second; ++mit)
1077 float adc = (float) mit->second.first;
1078 TVector3 cluspos =mit->second.second;
1080 if(fabs(cluspos.z() - projection.z()) >
m_max_zrange)
continue;
1084 std::cout <<
" layer " <<
layer <<
" adc " << adc << std::endl;
1085 std::cout <<
" cluspos " << cluspos.x() <<
" " << cluspos.y() <<
" " << cluspos.z()
1086 <<
" clus radius " << sqrt(
square(cluspos.x()) +
square(cluspos.y())) << std::endl;
1089 clus_centroid += cluspos * adc;
1092 if(cluspos.z() < zmin) zmin = cluspos.z();
1093 if(cluspos.z() > zmax) zmax = cluspos.z();
1096 clus_centroid.SetX(clus_centroid.x()/ wt);
1097 clus_centroid.SetY(clus_centroid.y()/ wt);
1098 clus_centroid.SetZ(clus_centroid.z()/ wt);
1100 double zrange = zmax-zmin;
1103 std::cout <<
" exceeded max zrange: zrange " << zrange <<
" max zrange " <<
m_max_zrange << std::endl;
1109 const TVector3 oc( clus_centroid.x()-
origin.x(), clus_centroid.y()-
origin.y(), clus_centroid.z()-
origin.z() );
1111 const auto dca = (oc-om).Mag();
1114 const auto pathlength = om.Mag();
1117 double ns_per_cm = 1e9 / 3e10;
1118 double dt = pathlength * ns_per_cm;
1121 clus_centroid.SetZ(clus_centroid.z() + transit_dz);
1123 clus_centroid.SetZ(clus_centroid.z() - transit_dz);
1127 std::cout <<
" layer " <<
layer <<
" radius " << layer_center_radius <<
" wt " << wt <<
" t " << t <<
" dca " << dca
1128 <<
" pathlength " << pathlength <<
" transit_dz " << transit_dz << std::endl;
1129 std::cout <<
" clus_centroid " << clus_centroid.x() <<
" " << clus_centroid.y() <<
" " << clus_centroid.z() <<
" zrange " << zrange << std::endl;
1130 std::cout <<
" projection " << projection.x() <<
" " << projection.y() <<
" " << projection.z() <<
" dz " << clus_centroid.z() - projection.z() << std::endl;
1135 state.
set_x( projection.x() );
1136 state.
set_y( projection.y() );
1137 state.
set_z( projection.z() );
1139 state.
set_px( direction.x());
1140 state.
set_py( direction.y());
1141 state.
set_pz( direction.z());
1148 const auto cluster_r =
get_r(clus_centroid.x(), clus_centroid.y());
1149 const auto cluster_phi = std::atan2(clus_centroid.y(),clus_centroid.x());
1150 const auto cluster_z = clus_centroid.z();
1166 const auto cluster_rphi_error = 0.015;
1167 const auto cluster_z_error = 0.075;
1170 const auto track_phi = std::atan2( projection.y(), projection.x() );
1171 const auto track_z = projection.z();
1174 const auto cosphi( std::cos( track_phi ) );
1175 const auto sinphi( std::sin( track_phi ) );
1176 const auto track_pphi = -state.
get_px()*sinphi + state.
get_py()*cosphi;
1177 const auto track_pr = state.
get_px()*cosphi + state.
get_py()*sinphi;
1178 const auto track_pz = state.
get_pz();
1179 const auto talpha = -track_pphi/track_pr;
1180 const auto tbeta = -track_pz/track_pr;
1183 if( std::isnan(talpha) )
1185 std::cout <<
"TpcDirectLaserReconstruction::process_track - talpha is nan" << std::endl;
1189 if( std::isnan(tbeta) )
1191 std::cout <<
"TpcDirectLaserReconstruction::process_track - tbeta is nan" << std::endl;
1196 const auto drp = cluster_r*
delta_phi( cluster_phi - track_phi );
1197 const auto dz = cluster_z - track_z;
1200 if( std::isnan(drp) )
1202 std::cout <<
"TpcDirectLaserReconstruction::process_track - drp is nan" << std::endl;
1206 if( std::isnan(
dz) )
1208 std::cout <<
"TpcDirectLaserReconstruction::process_track - dz is nan" << std::endl;
1214 const float r =
get_r( projection.x(), projection.y() );
1215 const float dr = cluster_r -
r;
1223 auto phi = cluster_phi;
1224 while( phi < m_phimin ) phi += 2.*M_PI;
1225 while( phi >= m_phimax ) phi -= 2.*M_PI;
1226 h_entries->Fill( phi, cluster_r, cluster_z );
1228 if(
h_xy)
h_xy->Fill(clus_centroid.x(), clus_centroid.y());
1229 if(
h_xz)
h_xz->Fill(clus_centroid.x(), clus_centroid.z());
1233 if(
h_zr)
h_zr->Fill(clus_centroid.z(), cluster_r);
1235 if(
h_dz_z)
h_dz_z->Fill(projection.z(), clus_centroid.z()- projection.z());
1244 const auto erp =
square(cluster_rphi_error);
1245 const auto ez =
square(cluster_z_error);
1248 if( std::isnan( erp ) )
1250 std::cout <<
"TpcDirectLaserReconstruction::process_track - erp is nan" << std::endl;
1254 if( std::isnan( ez ) )
1256 std::cout <<
"TpcDirectLaserReconstruction::process_track - ez is nan" << std::endl;
1266 std::cout <<
"TpcDirectLaserReconstruction::process_track - invalid cell index"
1267 <<
" r: " << cluster_r
1268 <<
" phi: " << cluster_phi
1269 <<
" z: " << cluster_z
1324 float phi = std::atan2( global.y(), global.x() );
1325 while( phi < m_phimin ) phi += 2.*M_PI;
1326 while( phi >= m_phimax ) phi -= 2.*M_PI;
1327 int iphi = phibins*(phi-m_phimin)/(m_phimax-m_phimin);
1330 const float r =
get_r( global.x(), global.y() );
1331 if( r < m_rmin || r >= m_rmax )
return -1;
1332 int ir = rbins*(r-m_rmin)/(m_rmax-m_rmin);
1335 const float z = global.z();
1336 if( z < m_zmin || z >= m_zmax )
return -1;
1337 int iz = zbins*(z-m_zmin)/(m_zmax-m_zmin);
1386 const float Angle_Bins[13] = {23*M_PI/12,1*M_PI/12,3*M_PI/12,5*M_PI/12,7*M_PI/12,9*M_PI/12,11*M_PI/12,13*M_PI/12,15*M_PI/12,17*M_PI/12,19*M_PI/12,21*M_PI/12,23*M_PI/12};
1388 const float r_bins[4] = {30,46,62,78};
1394 for(
int r_iter = 0; r_iter < 3; r_iter++ ){
1395 if( r > r_bins[r_iter] && r < r_bins[r_iter+1] )
1402 for(
int ang_iter = 0; ang_iter < 12; ang_iter++ ){
1403 if( phi > Angle_Bins[ang_iter] && phi < Angle_Bins[ang_iter+1] )
1405 angle_id = ang_iter;
1411 return GEM_Mod_ID = (36*side_id) + (3*angle_id) + r_id;
1428 if (phiorig < 0) phiorig += 2. * M_PI;
1429 else if (phiorig > 2.*M_PI) phiorig -= 2. * M_PI;
1431 float dx = x - xorig;
1432 float dy = y - yorig;
1433 float relphi = atan2(dy, dx) - phiorig;
1434 if (relphi < 0) relphi += 2. * M_PI;
1435 else if (relphi > 2.*M_PI) relphi -= 2. * M_PI;
1457 if (phiorig < 0) phiorig += 2. * M_PI;
1458 else if (phiorig > 2.*M_PI) phiorig -= 2. * M_PI;
1460 if (thetaorig < 0) thetaorig += 2. * M_PI;
1461 else if (thetaorig > 2.*M_PI) thetaorig -= 2. * M_PI;
1464 float dx = x - xorig;
1465 float dy = y - yorig;
1466 float dz = z - zorig;
1467 float r = sqrt(dx*dx + dy*dy + dz*dz);
1469 float cos_beta = (dx*cos(phiorig) + dy*sin(phiorig))/r;
1470 float sin_beta = dz/
r;
1472 float reltheta = acos(cos_beta*cos(thetaorig) + sin_beta*sin(thetaorig)) - M_PI/2.;
1473 if (reltheta < 0) reltheta += 2. * M_PI;
1474 else if (reltheta > 2.*M_PI) reltheta -= 2. * M_PI;
1481 return (num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 < 0);