-
Notifications
You must be signed in to change notification settings - Fork 38
Handle CAF making when Pandora runs after the NuGraph2 filter #616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 3 commits
351d379
762e6ed
78a0667
d5d32a0
cf283cb
98a4654
612ae6a
55812bc
d483222
deb9088
6aa4a4c
074258e
0800060
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
rtriozzi marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1717,6 +1717,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { | |
|
|
||
| // collect the TPC slices | ||
| std::vector<art::Ptr<recob::Slice>> slices; | ||
| std::vector<art::Ptr<recob::Slice>> nuGraphSlices; | ||
| std::vector<std::string> slice_tag_suffixes; | ||
| std::vector<unsigned> slice_tag_indices; | ||
| for (unsigned i_tag = 0; i_tag < pandora_tag_suffixes.size(); i_tag++) { | ||
|
|
@@ -1726,24 +1727,17 @@ void CAFMaker::produce(art::Event& evt) noexcept { | |
| GetByLabelStrict(evt, fParams.PFParticleLabel() + pandora_tag_suffix, thisSlices); | ||
| if (thisSlices.isValid()) { | ||
| art::fill_ptr_vector(slices, thisSlices); | ||
| nuGraphSlices = evt.getProduct<std::vector<art::Ptr<recob::Slice>>>(fParams.NuGraphSlicesLabel().label() + pandora_tag_suffix); | ||
| if (fParams.UsePandoraAfterNuGraph()) { | ||
| nuGraphSlices = slices; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this logic. if (!fParams.UsePandoraAfterNuGraph()) {
auto const& moreSlices = evt.getProduct<std::vector<art::Ptr<recob::Slice>>>(fParams.NuGraphSlicesLabel().label() + pandora_tag_suffix);
nuGraphSlices.insert(nuGraphSlices.end(), moreSlices.begin(), moreSlices.end());
} |
||
| for (unsigned i = 0; i < thisSlices->size(); i++) { | ||
| slice_tag_suffixes.push_back(pandora_tag_suffix); | ||
| slice_tag_indices.push_back(i_tag); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // nu graph | ||
| std::vector< art::Handle<std::vector<unsigned int>> > ng2_slice_hit_map_handle(pandora_tag_suffixes.size()); | ||
| std::vector< art::Handle<std::vector<anab::FeatureVector<1>>> > ng2_filter_handle(pandora_tag_suffixes.size()); | ||
| std::vector< art::Handle<std::vector<anab::FeatureVector<5>>> > ng2_semantic_handle(pandora_tag_suffixes.size()); | ||
| for (unsigned i_tag = 0; i_tag < pandora_tag_suffixes.size(); i_tag++) { | ||
| const std::string &pandora_tag_suffix = pandora_tag_suffixes[i_tag]; | ||
| GetByLabelIfExists(evt, fParams.NuGraphSliceHitLabel().encode() + pandora_tag_suffix, ng2_slice_hit_map_handle[i_tag]); | ||
| GetByLabelIfExists(evt, fParams.NuGraphFilterLabel().label() + pandora_tag_suffix + ":" + fParams.NuGraphFilterLabel().instance(), ng2_filter_handle[i_tag]); | ||
| GetByLabelIfExists(evt, fParams.NuGraphSemanticLabel().label() + pandora_tag_suffix + ":" + fParams.NuGraphSemanticLabel().instance(), ng2_semantic_handle[i_tag]); | ||
| } | ||
|
|
||
| // The Standard Record | ||
| // Branch entry definition -- contains list of slices, CRT information, and truth information | ||
| StandardRecord rec; | ||
|
|
@@ -1799,17 +1793,38 @@ void CAFMaker::produce(art::Event& evt) noexcept { | |
| fmatch_assn_map.emplace(std::make_pair(fname_opdet, sfm_assn)); | ||
| } | ||
| } | ||
|
|
||
| if (std::find(nuGraphSlices.begin(), nuGraphSlices.end(), slice) != nuGraphSlices.end()) { | ||
| std::vector<art::Ptr<anab::FeatureVector<1>>> ng2_filter_vec; | ||
| std::vector<art::Ptr<anab::FeatureVector<5>>> ng2_semantic_vec; | ||
| art::FindOneP<anab::FeatureVector<1>> findOneFilter(slcHits, evt, fParams.NuGraphFilterLabel().label() + slice_tag_suff + ":" + fParams.NuGraphFilterLabel().instance()); | ||
| art::FindOneP<anab::FeatureVector<5>> findOneSemantic(slcHits, evt, fParams.NuGraphSemanticLabel().label() + slice_tag_suff + ":" + fParams.NuGraphSemanticLabel().instance()); | ||
| // iteration is the only way to get something out of a FindOne or FindMany... | ||
| if (findOneFilter.isValid()) { | ||
| for (size_t hitIdx = 0; hitIdx < slcHits.size(); ++hitIdx) { | ||
| if (findOneFilter.at(hitIdx).isNull()) { | ||
| slcHits.erase(slcHits.begin()+hitIdx); | ||
| hitIdx--; | ||
| continue; | ||
| } | ||
| ng2_filter_vec.emplace_back(findOneFilter.at(hitIdx)); | ||
| } | ||
| } | ||
|
|
||
| std::vector<art::Ptr<anab::FeatureVector<1>>> ng2_filter_vec; | ||
| std::vector<art::Ptr<anab::FeatureVector<5>>> ng2_semantic_vec; | ||
| if (ng2_filter_handle[producer].isValid()) { | ||
| art::fill_ptr_vector(ng2_filter_vec,ng2_filter_handle[producer]); | ||
| } | ||
| if (ng2_semantic_handle[producer].isValid()) { | ||
| art::fill_ptr_vector(ng2_semantic_vec,ng2_semantic_handle[producer]); | ||
| } | ||
| if (ng2_slice_hit_map_handle[producer].isValid()) { | ||
| FillSliceNuGraph(slcHits,*ng2_slice_hit_map_handle[producer],ng2_filter_vec,ng2_semantic_vec,recslc); | ||
| if (findOneSemantic.isValid()) { | ||
| for (size_t hitIdx = 0; hitIdx < slcHits.size(); ++hitIdx) { | ||
| if (findOneSemantic.at(hitIdx).isNull()) { | ||
| slcHits.erase(slcHits.begin()+hitIdx); | ||
| hitIdx--; | ||
| continue; | ||
| } | ||
| ng2_semantic_vec.emplace_back(findOneSemantic.at(hitIdx)); | ||
| } | ||
| } | ||
|
|
||
| if (ng2_filter_vec.size() > 0 || ng2_semantic_vec.size() > 0) { | ||
| FillSliceNuGraph(slcHits, ng2_filter_vec, ng2_semantic_vec, recslc); | ||
| } | ||
| } | ||
|
|
||
| art::FindManyP<sbn::OpT0Finder> fmOpT0 = | ||
|
|
@@ -2189,8 +2204,38 @@ void CAFMaker::produce(art::Event& evt) noexcept { | |
| FillCNNScores(thisParticle, cnnScores, pfp); | ||
| } | ||
|
|
||
| if (ng2_slice_hit_map_handle[producer].isValid()) { | ||
| FillPFPNuGraph(*ng2_slice_hit_map_handle[producer], ng2_filter_vec, ng2_semantic_vec, fmPFPartHits.at(iPart), pfp); | ||
| if (std::find(nuGraphSlices.begin(), nuGraphSlices.end(), slice) != nuGraphSlices.end()) { | ||
| std::vector<art::Ptr<recob::Hit>>& PFPHits = fmPFPartHits.at(iPart); | ||
| art::FindOneP<anab::FeatureVector<1>> findOneFilter(PFPHits, evt, fParams.NuGraphFilterLabel().label() + slice_tag_suff + ":" + fParams.NuGraphFilterLabel().instance()); | ||
| art::FindOneP<anab::FeatureVector<5>> findOneSemantic(PFPHits, evt, fParams.NuGraphSemanticLabel().label() + slice_tag_suff + ":" + fParams.NuGraphSemanticLabel().instance()); | ||
| std::vector<art::Ptr<anab::FeatureVector<1>>> ng2_filter_vec; | ||
| std::vector<art::Ptr<anab::FeatureVector<5>>> ng2_semantic_vec; | ||
|
|
||
| if (findOneFilter.isValid()) { | ||
| for (size_t hitIdx = 0; hitIdx < PFPHits.size(); ++hitIdx) { | ||
| if (findOneFilter.at(hitIdx).isNull()) { | ||
| PFPHits.erase(PFPHits.begin() + hitIdx); | ||
| hitIdx--; | ||
| continue; | ||
| } | ||
| ng2_filter_vec.emplace_back(findOneFilter.at(hitIdx)); | ||
| } | ||
| } | ||
|
|
||
| if (findOneSemantic.isValid()) { | ||
| for (size_t hitIdx = 0; hitIdx < PFPHits.size(); ++hitIdx) { | ||
| if (findOneSemantic.at(hitIdx).isNull()) { | ||
| PFPHits.erase(PFPHits.begin() + hitIdx); | ||
| hitIdx--; | ||
| continue; | ||
| } | ||
| ng2_semantic_vec.emplace_back(findOneSemantic.at(hitIdx)); | ||
| } | ||
| } | ||
|
Comment on lines
+2238
to
+2258
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels quite familiar... same comments as for twin code above. std::tuple<
std::vector<art::Ptr<anab::FeatureVector<1>>>,
std::vector<art::Ptr<anab::FeatureVector<5>>>
>
CAFMaker::readNuGraphHitFeatures(
std::vector<art::Ptr<recob::Hit>> const& hits,
art::Event const& event, std::string const& suffix
) const; |
||
|
|
||
| if (ng2_filter_vec.size() > 0 || ng2_semantic_vec.size() > 0) { | ||
| FillPFPNuGraph(PFPHits, ng2_filter_vec, ng2_semantic_vec, pfp); | ||
| } | ||
| } | ||
|
|
||
| if (!thisTrack.empty()) { // it has a track! | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -581,16 +581,16 @@ namespace caf | |||||||
| } | ||||||||
|
|
||||||||
| void FillSliceNuGraph(const std::vector<art::Ptr<recob::Hit>> &inputHits, | ||||||||
| const std::vector<unsigned int> &sliceHitsMap, | ||||||||
| const std::vector<art::Ptr<anab::FeatureVector<1>>> &ngFilterResult, | ||||||||
| const std::vector<art::Ptr<anab::FeatureVector<5>>> &ngSemanticResult, | ||||||||
| caf::SRSlice &slice) | ||||||||
| { | ||||||||
|
|
||||||||
| //need to double check that the slice processed by NuGraph is the same under consideration | ||||||||
| //std::cout << "sizes=" << inputHits.size() << " " << sliceHitsMap.size() << " " << ngFilterResult.size() << " " << ngSemanticResult.size() << std::endl; | ||||||||
| // std::cout << "sizes=" << inputHits.size() << " " << " " << ngFilterResult.size() << " " << ngSemanticResult.size() << std::endl; | ||||||||
| unsigned int nHits = inputHits.size(); | ||||||||
| if (nHits==0 || nHits!=sliceHitsMap.size() || inputHits[0].key()!=sliceHitsMap[0]) return;//not the same slice! | ||||||||
| // implementing this same-slice check with the updated architecture would be a major headache and I believe is not required given how inputHits is retrieved. | ||||||||
| // if (nHits==0 || nHits!=sliceHitsMap.size() || inputHits[0].key()!=sliceHitsMap[0]) return;//not the same slice! | ||||||||
|
|
||||||||
| unsigned int npass = 0; | ||||||||
| for ( unsigned int i = 0; i < nHits; i++ ) { | ||||||||
|
|
@@ -1024,38 +1024,26 @@ namespace caf | |||||||
| srpfp.cnnscore.nclusters = cnnscore->nClusters; | ||||||||
| } | ||||||||
|
|
||||||||
| void FillPFPNuGraph(const std::vector<unsigned int> &sliceHitsMap, | ||||||||
| void FillPFPNuGraph(const std::vector<art::Ptr<recob::Hit>> &pfpHits, | ||||||||
| const std::vector<art::Ptr<anab::FeatureVector<1>>> &ngFilterResult, | ||||||||
| const std::vector<art::Ptr<anab::FeatureVector<5>>> &ngSemanticResult, | ||||||||
| const std::vector<art::Ptr<recob::Hit>> &pfpHits, | ||||||||
| caf::SRPFP& srpfp, | ||||||||
| bool allowEmpty) | ||||||||
| { | ||||||||
|
|
||||||||
| // the nugraph elements are ordered the same as the sliceHitsMap | ||||||||
| std::vector<size_t> mappedhits; | ||||||||
| for (auto& hit : pfpHits) { | ||||||||
| auto it = std::find(sliceHitsMap.begin(), sliceHitsMap.end(), hit.key()); | ||||||||
| if (it != sliceHitsMap.end()) { | ||||||||
| size_t index = std::distance(sliceHitsMap.begin(), it); | ||||||||
| mappedhits.push_back(index); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| if (mappedhits.size()>0) { | ||||||||
| if (pfpHits.size()>0) { | ||||||||
| std::vector<float> ng2sempfpcounts(5,0); | ||||||||
| size_t ng2bkgpfpcount = 0; | ||||||||
| for (size_t pos : mappedhits) { | ||||||||
| auto const& bkgscore = ngFilterResult.at(pos); | ||||||||
| if (bkgscore->at(0)<ng_filter_cut) { | ||||||||
| ng2bkgpfpcount++; | ||||||||
| } else { | ||||||||
| auto const& scores = ngSemanticResult.at(pos); | ||||||||
| std::vector<float> ng2semscores; | ||||||||
| for (size_t i=0;i<scores->size();i++) ng2semscores.push_back(scores->at(i)); | ||||||||
| size_t sem_label = std::distance(ng2semscores.begin(), std::max_element(ng2semscores.begin(), ng2semscores.end()));//arg_max(ng2semscores); | ||||||||
| ng2sempfpcounts[sem_label]++; | ||||||||
| } | ||||||||
| for (size_t pos = 0; pos < pfpHits.size(); pos++) { | ||||||||
| auto const& bkgscore = ngFilterResult.at(pos); | ||||||||
| if (bkgscore->at(0)<ng_filter_cut) { | ||||||||
| ng2bkgpfpcount++; | ||||||||
| } else { | ||||||||
| auto const& scores = ngSemanticResult.at(pos); | ||||||||
| std::vector<float> ng2semscores; | ||||||||
| for (size_t i=0;i<scores->size();i++) ng2semscores.push_back(scores->at(i)); | ||||||||
|
Comment on lines
+1131
to
+1132
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| size_t sem_label = std::distance(ng2semscores.begin(), std::max_element(ng2semscores.begin(), ng2semscores.end()));//arg_max(ng2semscores); | ||||||||
| ng2sempfpcounts[sem_label]++; | ||||||||
| } | ||||||||
| } | ||||||||
| srpfp.ngscore.sem_cat = SRNuGraphScore::NuGraphCategory(std::distance(ng2sempfpcounts.begin(), std::max_element(ng2sempfpcounts.begin(), ng2sempfpcounts.end())));//arg_max(ng2sempfpcounts); | ||||||||
| size_t nonBkgHits = (pfpHits.size() > ng2bkgpfpcount ? pfpHits.size()-ng2bkgpfpcount : 0); | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.