-
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 all 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,33 +1717,30 @@ 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++) { | ||||||||||||||||||
| const std::string &pandora_tag_suffix = pandora_tag_suffixes[i_tag]; | ||||||||||||||||||
|
|
||||||||||||||||||
| // Get a handle on the slices | ||||||||||||||||||
| art::Handle<std::vector<recob::Slice>> thisSlices; | ||||||||||||||||||
| GetByLabelStrict(evt, fParams.PFParticleLabel() + pandora_tag_suffix, thisSlices); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (thisSlices.isValid()) { | ||||||||||||||||||
| art::fill_ptr_vector(slices, thisSlices); | ||||||||||||||||||
| if (fParams.UsePandoraAfterNuGraph()) { | ||||||||||||||||||
| nuGraphSlices = slices; | ||||||||||||||||||
| } else { | ||||||||||||||||||
| nuGraphSlices = evt.getProduct<std::vector<art::Ptr<recob::Slice>>>(fParams.NuGraphSlicesLabel().label() + pandora_tag_suffix); | ||||||||||||||||||
| } | ||||||||||||||||||
|
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,19 +1796,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { | |||||||||||||||||
| fmatch_assn_map.emplace(std::make_pair(fname_opdet, sfm_assn)); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| 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); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| art::FindManyP<sbn::OpT0Finder> fmOpT0 = | ||||||||||||||||||
| FindManyPStrict<sbn::OpT0Finder>(sliceList, evt, fParams.OpT0Label() + slice_tag_suff); | ||||||||||||||||||
| std::vector<art::Ptr<sbn::OpT0Finder>> slcOpT0; | ||||||||||||||||||
|
|
@@ -1865,15 +1850,15 @@ void CAFMaker::produce(art::Event& evt) noexcept { | |||||||||||||||||
| // make Ptr's to clusters for cluster -> other object associations | ||||||||||||||||||
| if (fmPFPClusters.isValid()) { | ||||||||||||||||||
| for (size_t ipf=0; ipf<fmPFPart.size();++ipf) { | ||||||||||||||||||
| std::vector<art::Ptr<recob::Hit>> pfphits; | ||||||||||||||||||
| std::vector<art::Ptr<recob::Cluster>> pfclusters = fmPFPClusters.at(ipf); | ||||||||||||||||||
| art::FindManyP<recob::Hit> fmCluHits = FindManyPStrict<recob::Hit>(pfclusters, evt, fParams.PFParticleLabel() + slice_tag_suff); | ||||||||||||||||||
| for (size_t icl=0; icl<fmCluHits.size();icl++) { | ||||||||||||||||||
| for (auto hit : fmCluHits.at(icl)) { | ||||||||||||||||||
| pfphits.push_back(hit); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| fmPFPartHits.push_back(pfphits); | ||||||||||||||||||
| std::vector<art::Ptr<recob::Hit>> pfphits; | ||||||||||||||||||
| std::vector<art::Ptr<recob::Cluster>> pfclusters = fmPFPClusters.at(ipf); | ||||||||||||||||||
|
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. Avoid copies:
Suggested change
|
||||||||||||||||||
| art::FindManyP<recob::Hit> fmCluHits = FindManyPStrict<recob::Hit>(pfclusters, evt, fParams.PFParticleLabel() + slice_tag_suff); | ||||||||||||||||||
| for (size_t icl=0; icl<fmCluHits.size();icl++) { | ||||||||||||||||||
| for (auto hit : fmCluHits.at(icl)) { | ||||||||||||||||||
|
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. Avoid copies:
Suggested change
|
||||||||||||||||||
| pfphits.push_back(hit); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| fmPFPartHits.push_back(pfphits); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -2043,8 +2028,8 @@ void CAFMaker::produce(art::Event& evt) noexcept { | |||||||||||||||||
| // primary particle and meta-data | ||||||||||||||||||
| const recob::PFParticle *primary = (iPart == fmPFPart.size()) ? NULL : fmPFPart[iPart].get(); | ||||||||||||||||||
| const larpandoraobj::PFParticleMetadata *primary_meta = (iPart == fmPFPart.size()) ? NULL : fmPFPMeta.at(iPart).at(0).get(); | ||||||||||||||||||
| // get the flash match | ||||||||||||||||||
|
|
||||||||||||||||||
| // get the flash match | ||||||||||||||||||
| std::map<std::string, const sbn::SimpleFlashMatch*> fmatch_map; | ||||||||||||||||||
| std::map<std::string, art::FindManyP<sbn::SimpleFlashMatch>>::iterator fmatch_it; | ||||||||||||||||||
| for(fmatch_it = fmatch_assn_map.begin();fmatch_it != fmatch_assn_map.end();fmatch_it++) { | ||||||||||||||||||
|
|
@@ -2060,12 +2045,72 @@ void CAFMaker::produce(art::Event& evt) noexcept { | |||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // get the primary vertex | ||||||||||||||||||
| const recob::Vertex *vertex = (iPart == fmPFPart.size() || !fmVertex.at(iPart).size()) ? NULL : fmVertex.at(iPart).at(0).get(); | ||||||||||||||||||
|
|
||||||||||||||||||
| //####################################################### | ||||||||||||||||||
| // Add slice info. | ||||||||||||||||||
| //####################################################### | ||||||||||||||||||
| 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()); | ||||||||||||||||||
|
Comment on lines
+2058
to
+2059
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. It's hard to see whether the labels are the same. Define the tag first:
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| // filter | ||||||||||||||||||
| if (findOneFilter.isValid()) { | ||||||||||||||||||
| ng2_filter_vec.reserve(slcHits.size()); | ||||||||||||||||||
| for (size_t hitIdx = 0; hitIdx < slcHits.size(); ++hitIdx) { | ||||||||||||||||||
| ng2_filter_vec.emplace_back(findOneFilter.at(hitIdx)); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // semantic tagging | ||||||||||||||||||
| if (findOneSemantic.isValid()) { | ||||||||||||||||||
| ng2_semantic_vec.reserve(slcHits.size()); | ||||||||||||||||||
| for (size_t hitIdx = 0; hitIdx < slcHits.size(); ++hitIdx) { | ||||||||||||||||||
| ng2_semantic_vec.emplace_back(findOneSemantic.at(hitIdx)); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // vertex projection onto the three wire planes | ||||||||||||||||||
| float vtx_wire[3]; | ||||||||||||||||||
| float vtx_tick[3]; | ||||||||||||||||||
|
|
||||||||||||||||||
| if (vertex != NULL) { | ||||||||||||||||||
|
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. What kind of garbage is going to end into the tree if the vertex is null? The arrays need to be initialised somehow.
Suggested change
Contributor
Author
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. going through the comments right now! about this: every slice has to have a vertex, sort of by definition in Pandora (e.g., even if the reconstruction is sure that the slice is a cosmic, the vertex will just be the highest-y hit) I think there are also protections for failed vertexing (which should be very rare: we really just need a hit to define a vertex...) within Pandora, so that we always get something when we grab the vertex in the CAF maker... anyway, I agree it's bad practice from the CAF maker stand point (+ the |
||||||||||||||||||
| auto const& tpcID = geom->FindTPCAtPosition(vertex->position()); | ||||||||||||||||||
| if (tpcID.isValid) { | ||||||||||||||||||
| for (geo::PlaneID const& p : wireReadout.Iterate<geo::PlaneID>()) { | ||||||||||||||||||
| auto const& planeID = geo::PlaneID{tpcID, p.Plane}; | ||||||||||||||||||
| const geo::PlaneGeo& planeGeo = wireReadout.Plane(planeID); | ||||||||||||||||||
|
Comment on lines
+2084
to
+2086
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 should work:
Suggested change
(plane number is |
||||||||||||||||||
| vtx_wire[p.Plane] = planeGeo.WireCoordinate(vertex->position()); ///< wire projection | ||||||||||||||||||
| vtx_tick[p.Plane] = dprop.ConvertXToTicks(vertex->position().X(), planeID); ///< drift projection | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (ng2_filter_vec.size() > 0 || ng2_semantic_vec.size() > 0) { | ||||||||||||||||||
|
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. Semantics:
Suggested change
|
||||||||||||||||||
| FillSliceNuGraph(slcHits, ng2_filter_vec, ng2_semantic_vec, fmPFPartHits, | ||||||||||||||||||
| vtx_wire, vtx_tick, fParams.NuGraphHIPTagWireDist(), fParams.NuGraphHIPTagTickDist(), | ||||||||||||||||||
| fParams.NuGraphFilterCut(), recslc); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // overwrite the `ng_filt_pass_frac` variable with post-NuGraph2-filtering | ||||||||||||||||||
| if (fParams.UsePandoraAfterNuGraph()) { | ||||||||||||||||||
| art::Handle<std::vector<anab::FeatureVector<1>>> ngFilterVecHandle; | ||||||||||||||||||
| evt.getByLabel(art::InputTag("NGMultiSlice" + slice_tag_suff, "filter"), ngFilterVecHandle); | ||||||||||||||||||
|
Comment on lines
+2101
to
+2102
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. Smoother (less repetitions, less maintenance):
Suggested change
|
||||||||||||||||||
| art::Handle<std::vector<recob::Hit>> ngFilteredHitsHandle; | ||||||||||||||||||
| GetByLabelStrict(evt, "ngfilteredhits" + slice_tag_suff, ngFilteredHitsHandle); | ||||||||||||||||||
|
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. Why is this "strict" and the previous is not? |
||||||||||||||||||
| if (ngFilterVecHandle.isValid() && | ||||||||||||||||||
| ngFilteredHitsHandle.isValid() && | ||||||||||||||||||
| ngFilterVecHandle->size() > 0) { | ||||||||||||||||||
| recslc.ng_filt_pass_frac = float(ngFilteredHitsHandle->size()) / float(ngFilterVecHandle->size()); | ||||||||||||||||||
|
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. Single precision
Suggested change
|
||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| FillSliceVars(*slice, primary, producer, recslc); | ||||||||||||||||||
| FillSliceMetadata(primary_meta, recslc); | ||||||||||||||||||
| FillSliceFlashMatch(fmatch_map["fmatch"], recslc.fmatch); | ||||||||||||||||||
|
|
@@ -2189,8 +2234,32 @@ 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; | ||||||||||||||||||
|
|
||||||||||||||||||
| // filter | ||||||||||||||||||
| if (findOneFilter.isValid()) { | ||||||||||||||||||
| ng2_filter_vec.reserve(PFPHits.size()); | ||||||||||||||||||
| for (size_t hitIdx = 0; hitIdx < PFPHits.size(); ++hitIdx) { | ||||||||||||||||||
| ng2_filter_vec.emplace_back(findOneFilter.at(hitIdx)); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // semantic tagging | ||||||||||||||||||
| if (findOneSemantic.isValid()) { | ||||||||||||||||||
| ng2_semantic_vec.reserve(PFPHits.size()); | ||||||||||||||||||
| for (size_t hitIdx = 0; hitIdx < PFPHits.size(); ++hitIdx) { | ||||||||||||||||||
| 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, fParams.NuGraphFilterCut(), pfp); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (!thisTrack.empty()) { // it has a track! | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.