7 namespace single_photon
10 std::vector<PandoraPFParticle> all_PPFPs,
12 std::map<art::Ptr<recob::Track>, art::Ptr<simb::MCParticle> > & trackToMCParticleMap,
13 std::map< art::Ptr<simb::MCParticle>, art::Ptr<simb::MCTruth>> & MCParticleToMCTruthMap,
14 std::vector<art::Ptr<simb::MCParticle>> & mcParticleVector,
15 std::map<
int, art::Ptr<simb::MCParticle> > & MCParticleToTrackIdMap,
16 std::vector<double> & vfrac,
22 std::cout<<
"RecoMCTracks()\t||\t Begininning recob::Track Reco-MC suite on: "<<
tracks.size()<<
" tracks."<<std::endl;
30 if(trackToMCParticleMap.count(track)>0){
32 const art::Ptr<simb::MCParticle> mcparticle = trackToMCParticleMap[
track];
33 std::cout<<
"count2: "<<MCParticleToMCTruthMap.count(mcparticle)<<std::endl;
34 const art::Ptr<simb::MCTruth> mctruth = MCParticleToMCTruthMap[mcparticle];
40 std::vector<double> correctedstart(3);
41 std::vector<double> correctedend(3);
42 std::vector<double> raw_End ={mcparticle->EndX(), mcparticle->EndY(), mcparticle->EndZ()};
80 if(mcparticle->Mother()>=(int)mcParticleVector.size()){
95 std::vector<PandoraPFParticle> all_PPFPs,
97 std::map<art::Ptr<recob::Shower>,art::Ptr<simb::MCParticle>>& showerToMCParticleMap,
98 art::FindManyP<simb::MCParticle,anab::BackTrackerHitMatchingData>& mcparticles_per_hit,
99 std::vector<art::Ptr<simb::MCParticle>>& mcParticleVector,
100 std::map<
int ,art::Ptr<simb::MCParticle> > & MCParticleToTrackIdMap,
103 std::vector<double> vec_fraction_matched;
105 std::map<std::string,bool> map_is_shower_process = {{
"compt",
true},
106 {
"FastScintillation",
true},
113 std::vector<int> spacers =
Printer_header({
"pfpID",
" matched_#simb",
" pdg",
" E_plane0",
" E_plane1",
" E_plane2",
" cosmic?"});
115 for(
size_t i=0; i<showerVector.size();++i){
116 auto shower = showerVector[i];
122 const art::Ptr<recob::PFParticle> pfp = ppfp->
pPFParticle;
127 std::vector< art::Ptr<recob::Hit> > obj_hits_ptrs = ppfp->
pPFPHits;
135 std::unordered_map<int,double> objide;
139 double maxe=-1, tote=0;
141 std::vector<double> total_energy_on_plane = {0.0,0.0,0.0};
143 art::Ptr<simb::MCParticle> best_matched_mcparticle;
148 std::vector<art::Ptr<simb::MCParticle>> particle_vec;
149 std::vector<anab::BackTrackerHitMatchingData const *> match_vec;
151 int n_associated_mcparticle_hits = 0;
152 int n_not_associated_hits = 0;
155 std::vector<art::Ptr<simb::MCParticle>> asso_mcparticles_vec;
156 std::map<art::Ptr<simb::MCParticle>, std::vector<double>> map_asso_mcparticles_energy;
158 bool found_a_match =
false;
163 for(
size_t i_h=0; i_h < obj_hits_ptrs.size(); ++i_h){
165 int which_plane = (int)obj_hits_ptrs[i_h]->View();
167 particle_vec.clear(); match_vec.clear();
170 mcparticles_per_hit.get(obj_hits_ptrs[i_h].key(), particle_vec, match_vec);
179 if(particle_vec.size()>0) n_associated_mcparticle_hits++;
181 if(particle_vec.size()==0) n_not_associated_hits++;
186 for(
size_t i_p=0; i_p<particle_vec.size(); ++i_p){
188 objide[ particle_vec[i_p]->TrackId()] += match_vec[i_p]->energy;
191 if(std::find(asso_mcparticles_vec.begin(), asso_mcparticles_vec.end(), particle_vec[i_p]) == asso_mcparticles_vec.end()){
192 asso_mcparticles_vec.push_back(particle_vec[i_p]);
193 map_asso_mcparticles_energy[particle_vec[i_p]] = {0.0,0.0,0.0};
194 map_asso_mcparticles_energy[particle_vec[i_p]][which_plane] = match_vec[i_p]->energy;
196 map_asso_mcparticles_energy[particle_vec[i_p]][which_plane] += match_vec[i_p]->energy;
200 tote += match_vec[i_p]->energy;
201 total_energy_on_plane[which_plane]+=match_vec[i_p]->energy;
206 if( objide[ particle_vec[i_p]->TrackId()] > maxe ){
207 maxe = objide[ particle_vec[i_p]->TrackId() ];
208 best_matched_mcparticle = particle_vec[i_p];
209 found_a_match =
true;
216 double fraction_num_hits_overlay = (double)n_not_associated_hits/(
double)obj_hits_ptrs.size();
218 if(
g_is_verbose)
std::cout <<
"recoMC()\t||\t On Object "<<i<<
". The number of MCParticles associated with this PFP is "<<objide.size()<<std::endl;
219 if(
g_is_verbose)
std::cout<<
"recoMC()\t||\t the fraction of hits from overlay is is "<<fraction_num_hits_overlay<<
" ("<<n_not_associated_hits<<
"/"<<obj_hits_ptrs.size()<<
")"<<std::endl;
222 if(n_associated_mcparticle_hits == 0){
224 found_a_match =
false;
275 std::map<int, art::Ptr<simb::MCParticle>> mother_MCP_map;
277 std::vector<art::Ptr<simb::MCParticle>> marks_mother_vector;
278 std::map<art::Ptr<simb::MCParticle>, std::vector<double>> marks_mother_energy_fraction_map;
280 int this_mcp_id = -1;
281 int last_mcp_id = -1;
284 int num_bt_mothers =0;
288 for(
auto mcp:asso_mcparticles_vec){
290 if(
g_is_verbose)
std::cout<<
"-----------------------------Start L1 Loop --------------------------------------------------"<<std::endl;
291 if(
g_is_verbose)
std::cout<<
"L1: ("<<i<<
" <-> "<<i_mcp<<
") Start by Looking at an MCP with pdg code "<<mcp->PdgCode()<<
" and status code "<<mcp->StatusCode()<<
" TrackID: "<<mcp->TrackId()<<std::endl;
292 if(
g_is_verbose)
std::cout<<
"L1: ("<<i<<
" <-> "<<i_mcp<<
") This MCP gave "<< map_asso_mcparticles_energy[mcp][0] <<
" | "<<map_asso_mcparticles_energy[mcp][1]<<
" | "<<map_asso_mcparticles_energy[mcp][2]<<
" energy to the recob::Object on each plane"<<std::endl;
296 this_mcp_id = mcp->TrackId();
297 last_mcp_id = this_mcp_id;
302 while(this_mcp_id >= 0 ){
303 art::Ptr<simb::MCParticle> this_mcp = MCParticleToTrackIdMap[this_mcp_id];
307 if (this_mcp.isNull()){
308 if(
g_is_verbose)
std::cout<<
"L1: ("<<i<<
" <-> "<<i_mcp<<
") null pointer at id "<<this_mcp_id<<std::endl;
309 this_mcp_id = last_mcp_id;
314 if(
g_is_verbose)
std::cout<<
"L1: ("<<i<<
" <-> "<<i_mcp<<
") going up the tree at an MCP with track id "<<this_mcp_id<<
", pdg code "<<this_mcp->PdgCode()<<
", and status code "<<this_mcp->StatusCode()<<
" and Mother: "<<this_mcp->Mother()<<
" Process: "<<this_mcp->Process()<<
" EndProcess: "<<this_mcp->EndProcess()<<std::endl;
317 last_mcp_id = this_mcp_id;
318 this_mcp_id = this_mcp->Mother();
321 if(map_is_shower_process.count(this_mcp->Process()) > 0){
324 }
else if(this_mcp->Process()==
"primary"){
327 this_mcp_id = last_mcp_id;
330 if(
g_is_verbose)
std::cout<<
"L1: Backtracked to a particle created in "<<this_mcp->EndProcess()<<
"! breaking"<<std::endl;
331 this_mcp_id = last_mcp_id;
337 if (this_mcp_id >= 0){
340 if(
g_is_verbose)
std::cout<<
"L1: ("<<i<<
" <-> "<<i_mcp<<
") Storing the mother mother particle with track id "<<this_mcp_id<<
" and pdg code "<<MCParticleToTrackIdMap[this_mcp_id]->PdgCode()<<
" and status code "<<MCParticleToTrackIdMap[this_mcp_id]->StatusCode()<<std::endl;
342 mother_MCP_map[this_mcp_id] = MCParticleToTrackIdMap[this_mcp_id];
346 for(
size_t k=0;
k< marks_mother_vector.size();
k++){
348 if(marks_mother_vector[
k]==MCParticleToTrackIdMap[this_mcp_id]){
349 marks_mother_energy_fraction_map[marks_mother_vector[
k]][0] += map_asso_mcparticles_energy[mcp][0];
350 marks_mother_energy_fraction_map[marks_mother_vector[
k]][1] += map_asso_mcparticles_energy[mcp][1];
351 marks_mother_energy_fraction_map[marks_mother_vector[
k]][2] += map_asso_mcparticles_energy[mcp][2];
357 marks_mother_vector.push_back(MCParticleToTrackIdMap[this_mcp_id]);
358 marks_mother_energy_fraction_map[marks_mother_vector.back()] = {0.0,0.0,0.0};
359 marks_mother_energy_fraction_map[marks_mother_vector.back()][0] = map_asso_mcparticles_energy[mcp][0];
360 marks_mother_energy_fraction_map[marks_mother_vector.back()][1] = map_asso_mcparticles_energy[mcp][1];
361 marks_mother_energy_fraction_map[marks_mother_vector.back()][2] = map_asso_mcparticles_energy[mcp][2];
371 if(
g_is_verbose)
std::cout<<
"-----------------------------End L1 Loop --------------------------------------------------"<<std::endl;
377 if(
g_is_verbose)
std::cout<<
"recoMC()\t||\t the number of source mother particles is "<<mother_MCP_map.size()<<
" of which : "<<marks_mother_vector.size()<<
" are unique!"<<std::endl;
379 if(
g_is_verbose)
std::cout<<
"---------------------------- L2-------------------------------"<<std::endl;
381 double best_mother_index = 0;
382 double best_mother_energy = -9999;
385 for(
size_t p=0;
p< marks_mother_vector.size();
p++){
386 art::Ptr<simb::MCParticle> mother = marks_mother_vector[
p];
387 std::vector<double> mother_energy_recod = marks_mother_energy_fraction_map[mother];
388 if(
g_is_verbose)
std::cout<<
"L2: Mother candidate "<<
p<<
" TrackID "<<mother->TrackId()<<
" Process: "<<mother->Process()<<
" EndProcess: "<<mother->EndProcess()<<std::endl;
389 if(
g_is_verbose)
std::cout<<
"L2: Mother candidate "<<
p<<
" Energy "<<mother->E()<<
" Reco'd Energy: "<<mother_energy_recod[0]<<
" | "<<mother_energy_recod[1]<<
" | "<<mother_energy_recod[2]<<
" Fraction: ("<<mother_energy_recod[0]/(1000*mother->E())*100.0<<
"% , "<<mother_energy_recod[1]/(1000*mother->E())*100.0<<
"% , "<<mother_energy_recod[2]/(1000*mother->E())*100.0<<
"% )"<<std::endl;
391 if( mother_energy_recod[0] > best_mother_energy){
392 best_mother_index =
p;
393 best_mother_energy = mother_energy_recod[0];
397 if( mother_energy_recod[1] > best_mother_energy){
398 best_mother_index =
p;
399 best_mother_energy = mother_energy_recod[1];
403 if( mother_energy_recod[2] > best_mother_energy){
404 best_mother_index =
p;
405 best_mother_energy = mother_energy_recod[2];
414 if(
g_is_verbose)
std::cout<<
"---------------------------- L2-------------------------------"<<std::endl;
415 const art::Ptr<simb::MCParticle> match = marks_mother_vector[best_mother_index];
417 std::vector<double> corrected_vertex(3), corrected_start(3);
421 if(match->PdgCode()==22){
422 std::vector<double> tmp ={match->EndX(), match->EndY(), match->EndZ()};
425 }
else if(
abs(match->PdgCode())==11){
429 corrected_start = {-999,-999,-999};
433 art::Ptr<simb::MCParticle> match_mother = MCParticleToTrackIdMap[match->Mother()];
435 if (match_mother.isNull()){
474 mcParticleVector.push_back(match);
475 showerToMCParticleMap[
shower] = mcParticleVector.back();
497 std::to_string(marks_mother_vector[best_mother_index]->PdgCode()),
519 std::map<art::Ptr<recob::Track>,art::Ptr<simb::MCParticle>>& objectToMCParticleMap,
520 std::map<art::Ptr<recob::Track>,art::Ptr<recob::PFParticle>>& objectToPFParticleMap,
521 std::map<art::Ptr<recob::PFParticle>,
std::vector<art::Ptr<recob::Hit>> >& pfParticleToHitsMap,
522 art::FindManyP<simb::MCParticle,anab::BackTrackerHitMatchingData>& mcparticles_per_hit,
523 std::vector<art::Ptr<simb::MCParticle>>& mcParticleVector,
526 std::vector<double> trk_overlay_vec;
527 std::vector<double> vec_fraction_matched;
528 bool reco_verbose =
false;
530 for(
size_t i=0; i<objectVector.size();++i){
531 auto object = objectVector[i];
534 const art::Ptr<recob::PFParticle> pfp = objectToPFParticleMap[object];
539 int pdg = pfp->PdgCode();
541 std::vector< art::Ptr<recob::Hit> > obj_hits_ptrs = pfParticleToHitsMap[pfp];
543 std::unordered_map<int,double> objide;
547 double maxe=-1, tote=0;
550 art::Ptr<simb::MCParticle> best_matched_mcparticle;
555 std::vector<art::Ptr<simb::MCParticle>> particle_vec;
556 std::vector<anab::BackTrackerHitMatchingData const *> match_vec;
558 bool found_a_match =
false;
559 int n_associated_mcparticle_hits = 0;
560 int n_not_associated_hits = 0;
565 for(
size_t i_h=0; i_h < obj_hits_ptrs.size(); ++i_h){
567 particle_vec.clear(); match_vec.clear();
571 mcparticles_per_hit.get(obj_hits_ptrs[i_h].key(), particle_vec, match_vec);
581 if(particle_vec.size()>0) n_associated_mcparticle_hits++;
583 if(particle_vec.size()==0) n_not_associated_hits++;
588 for(
size_t i_p=0; i_p<particle_vec.size(); ++i_p){
590 objide[ particle_vec[i_p]->TrackId()] += match_vec[i_p]->energy;
593 tote += match_vec[i_p]->energy;
596 if( objide[ particle_vec[i_p]->TrackId() ] > maxe ){
597 maxe = objide[ particle_vec[i_p]->TrackId() ];
598 best_matched_mcparticle = particle_vec[i_p];
599 found_a_match =
true;
605 double fraction_num_hits_overlay = (double)n_not_associated_hits/(
double)obj_hits_ptrs.size();
607 trk_overlay_vec.push_back(fraction_num_hits_overlay);
608 if(n_associated_mcparticle_hits == 0){
616 mcParticleVector.push_back(best_matched_mcparticle);
617 objectToMCParticleMap[object] = mcParticleVector.back();
621 vec_fraction_matched.push_back(maxe/tote);
628 if(reco_verbose)
std::cout <<
"recoMC()\t||\t NO MATCH NO MATCH (from my loop) for PFP with pdg "<<pdg<<std::endl;
629 if(reco_verbose)
std::cout<<
" count "<<objectToMCParticleMap.count(
object)<<std::endl;
632 std::cout <<
"recoMC()\t||\t Final Match (from my loop) for PFP with pdg "<<pdg<<
" is " << best_matched_mcparticle->TrackId() <<
" with energy " << maxe <<
" over " << tote <<
" (" << maxe/tote <<
")"
633 <<
" pdg=" << best_matched_mcparticle->PdgCode()
634 <<
" trkid=" << best_matched_mcparticle->TrackId()
635 <<
" ke=" << best_matched_mcparticle->E()-best_matched_mcparticle->Mass()<<
"\n";
640 return trk_overlay_vec;
647 for(
auto &mcp: mcParticleVector){
648 int pdg = mcp->PdgCode();
649 std::string end_process = mcp->EndProcess();
650 int status = mcp->StatusCode() ;
654 std::cout<<
"PHOTO: "<<status<<
" "<<end_process<<std::endl;
std::vector< double > m_sim_shower_vertex_x
std::vector< double > m_sim_track_startx
const bool get_IsNuSlice() const
std::vector< double > m_sim_shower_py
std::vector< int > m_sim_track_origin
ClusterModuleLabel join with tracks
std::vector< double > trackRecoMCmatching(std::vector< art::Ptr< recob::Track >> &objectVector, std::map< art::Ptr< recob::Track >, art::Ptr< simb::MCParticle >> &objectToMCParticleMap, std::map< art::Ptr< recob::Track >, art::Ptr< recob::PFParticle >> &objectToPFParticleMap, std::map< art::Ptr< recob::PFParticle >, std::vector< art::Ptr< recob::Hit >> > &pfParticleToHitsMap, art::FindManyP< simb::MCParticle, anab::BackTrackerHitMatchingData > &mcparticles_per_hit, std::vector< art::Ptr< simb::MCParticle >> &mcParticleVector, var_all &vars)
std::vector< bool > m_sim_shower_is_nuslice
std::vector< double > m_sim_shower_pz
std::vector< double > m_sim_shower_vertex_z
std::vector< double > m_sim_track_energy
std::vector< int > m_sim_track_parent_pdg
std::vector< std::string > m_sim_track_process
art::Ptr< recob::PFParticle > pPFParticle
process_name use argoneut_mc_hitfinder track
std::vector< int > m_sim_track_trackID
std::vector< int > m_sim_track_sliceId
std::vector< double > m_sim_track_py
void RecoMCTracks(std::vector< PandoraPFParticle > all_PPFPs, const std::vector< art::Ptr< recob::Track >> &tracks, std::map< art::Ptr< recob::Track >, art::Ptr< simb::MCParticle > > &trackToMCParticleMap, std::map< art::Ptr< simb::MCParticle >, art::Ptr< simb::MCTruth >> &MCParticleToMCTruthMap, std::vector< art::Ptr< simb::MCParticle >> &mcParticleVector, std::map< int, art::Ptr< simb::MCParticle > > &MCParticleToTrackIdMap, std::vector< double > &vfrac, var_all &vars)
std::vector< double > m_sim_shower_matched_energy_fraction_plane2
void showerRecoMCmatching(std::vector< PandoraPFParticle > all_PPFPs, std::vector< art::Ptr< recob::Shower >> &showerVector, std::map< art::Ptr< recob::Shower >, art::Ptr< simb::MCParticle >> &showerToMCParticleMap, art::FindManyP< simb::MCParticle, anab::BackTrackerHitMatchingData > &mcparticles_per_hit, std::vector< art::Ptr< simb::MCParticle >> &mcParticleVector, std::map< int, art::Ptr< simb::MCParticle > > &MCParticleToTrackIdMap, var_all &vars)
std::vector< double > m_sim_track_endy
std::vector< double > m_sim_shower_vertex_y
std::vector< double > m_sim_shower_matched_energy_fraction_plane0
std::vector< art::Ptr< recob::Hit > > pPFPHits
std::vector< double > m_sim_shower_start_z
std::vector< double > m_sim_track_kinetic_energy
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::vector< double > m_sim_shower_kinetic_energy
std::vector< int > m_sim_shower_best_matched_plane
std::vector< double > m_sim_track_endx
std::vector< double > m_sim_track_endz
std::vector< int > Printer_header(std::vector< std::string > headings)
std::vector< double > m_sim_shower_energy
std::vector< int > m_sim_shower_matched
std::vector< double > m_sim_shower_matched_energy_fraction_plane1
std::vector< double > m_sim_shower_px
std::vector< double > m_sim_track_startz
std::vector< int > m_sim_track_pdg
std::vector< double > m_sim_shower_mass
int photoNuclearTesting(std::vector< art::Ptr< simb::MCParticle >> &mcParticleVector)
PandoraPFParticle * PPFP_GetPPFPFromTrack(std::vector< PandoraPFParticle > &PPFPs, art::Ptr< recob::Track > pTrack)
std::vector< double > m_sim_shower_nuscore
std::vector< double > m_sim_track_pz
int spacecharge_correction(const art::Ptr< simb::MCParticle > &mcparticle, std::vector< double > &corrected, std::vector< double > &input)
std::vector< double > m_sim_shower_start_y
std::vector< int > m_sim_shower_sliceId
std::vector< double > m_sim_shower_overlay_fraction
const int get_SliceID() const
std::vector< std::string > m_sim_shower_end_process
std::vector< int > m_sim_shower_trackID
std::vector< std::string > m_sim_shower_process
std::vector< double > m_sim_track_starty
std::vector< double > m_sim_shower_start_x
std::vector< int > m_sim_shower_parent_pdg
void Printer_content(std::vector< std::string > nums, std::vector< int > spacers)
std::vector< double > m_sim_track_nuscore
std::string to_string(WindowPattern const &pattern)
PandoraPFParticle * PPFP_GetPPFPFromShower(std::vector< PandoraPFParticle > &PPFPs, art::Ptr< recob::Shower > pShower)
std::vector< int > m_sim_track_matched
const double get_NuScore() const
std::vector< int > m_sim_shower_pdg
std::vector< bool > m_sim_track_isclearcosmic
const bool get_IsClearCosmic() const
std::vector< int > m_sim_shower_is_true_shower
std::vector< double > m_sim_track_length
std::vector< double > m_sim_track_overlay_fraction
std::vector< double > m_sim_track_mass
std::vector< bool > m_sim_shower_isclearcosmic
BEGIN_PROLOG could also be cout
std::vector< int > m_sim_shower_parent_trackID
std::vector< double > m_sim_track_px