Skip to content

Commit

Permalink
Merge branch 'develop' into v09_81_02_feat_Jwa
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelnebot authored Jan 24, 2024
2 parents a446f83 + 7effc23 commit 1b78be9
Show file tree
Hide file tree
Showing 16 changed files with 876 additions and 97 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ find_package( lardata REQUIRED )
find_package( larevt REQUIRED )
find_package( larsim REQUIRED )
find_package( larreco REQUIRED )
find_package( larrecodnn REQUIRED )
find_package( larpandora REQUIRED )
find_package( larpandoracontent REQUIRED )
find_package( artdaq_core EXPORT REQUIRED )
Expand Down
36 changes: 33 additions & 3 deletions sbncode/CAFMaker/CAFMakerParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ namespace caf
"pandora"
};

Atom<string> CNNScoreLabel {
Name("CNNScoreLabel"),
Comment("Base label of CNN score producer."),
"cnnid"
};

Atom<string> StubLabel {
Name("StubLabel"),
Comment("Base label of Stub producer."),
Expand Down Expand Up @@ -252,6 +258,18 @@ namespace caf
"pandoraTrackCRTTrack"
};

Atom<string> CRTSpacePointMatchLabel {
Name("CRTSpacePointMatchLabel"),
Comment("Base label of track to CRT spacepoint matching producer."),
"crtspacepointmatching"
};

Atom<string> SBNDCRTTrackMatchLabel {
Name("SBNDCRTTrackMatchLabel"),
Comment("Base label of track to SBND CRT track matching producer."),
"crttrackmatching"
};

Atom<string> TrackMCSLabel {
Name("TrackMCSLabel"),
Comment("Base label of track MCS momentum calculation producer."),
Expand All @@ -267,15 +285,27 @@ namespace caf
Atom<string> CRTHitLabel {
Name("CRTHitLabel"),
Comment("Label of sbn CRT hits."),
"crthit" // same for icarus and sbnd
"crthit" // icarus
};

Atom<string> CRTTrackLabel {
Name("CRTTrackLabel"),
Comment("Label of sbn CRT tracks."),
"crttrack" // same for icarus and sbnd
"crttrack" // icarus
};


Atom<string> CRTSpacePointLabel {
Name("CRTSpacePointLabel"),
Comment("Label of sbnd CRT spacepoints."),
"crtspacepoints" // sbnd
};

Atom<string> SBNDCRTTrackLabel {
Name("SBNDCRTTrackLabel"),
Comment("Label of sbnd CRT tracks."),
"crttracks" // sbnd
};

Atom<string> CRTPMTLabel {
Name("CRTPMTLabel"),
Comment("Label for the CRTPMT Matched variables from the crtpmt data product"),
Expand Down
165 changes: 125 additions & 40 deletions sbncode/CAFMaker/CAFMaker_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
#include "sbnobj/Common/SBNEventWeight/EventWeightMap.h"
#include "sbnobj/Common/SBNEventWeight/EventWeightParameterSet.h"
#include "sbnobj/Common/Reco/MVAPID.h"
#include "sbnobj/Common/Reco/CNNScore.h"
#include "sbnobj/Common/Reco/ScatterClosestApproach.h"
#include "sbnobj/Common/Reco/StoppingChi2Fit.h"
#include "sbnobj/Common/POTAccounting/BNBSpillInfo.h"
Expand Down Expand Up @@ -276,6 +277,10 @@ class CAFMaker : public art::EDProducer {
art::FindOneP<T> FindOnePStrict(const U& from, const art::Event& evt,
const art::InputTag& label) const;

template <class T, class D, class U>
art::FindOneP<T, D> FindOnePDStrict(const U& from,
const art::Event& evt,
const art::InputTag& tag) const;

/// \brief Retrieve an object from an association, with error handling
///
Expand Down Expand Up @@ -1005,6 +1010,25 @@ art::FindOneP<T> CAFMaker::FindOnePStrict(const U& from,
return ret;
}

//......................................................................
template <class T, class D, class U>
art::FindOneP<T, D> CAFMaker::FindOnePDStrict(const U& from,
const art::Event& evt,
const art::InputTag& tag) const {
art::FindOneP<T, D> ret(from, evt, tag);

if (!tag.label().empty() && !ret.isValid() && fParams.StrictMode()) {
std::cout << "CAFMaker: No Assn from '"
<< cet::demangle_symbol(typeid(from).name()) << "' to '"
<< cet::demangle_symbol(typeid(T).name())
<< "' found under label '" << tag << "'. "
<< "Set 'StrictMode: false' to continue anyway." << std::endl;
abort();
}

return ret;
}

//......................................................................
template <class T>
bool CAFMaker::GetAssociatedProduct(const art::FindManyP<T>& fm, int idx,
Expand Down Expand Up @@ -1311,40 +1335,64 @@ void CAFMaker::produce(art::Event& evt) noexcept {
pass_flash_trig = *flashtrig_handle;
}

// Fill various detector information associated with the event
//
// Get all of the CRT hits
std::vector<caf::SRCRTHit> srcrthits;

art::Handle<std::vector<sbn::crt::CRTHit>> crthits_handle;
GetByLabelStrict(evt, fParams.CRTHitLabel(), crthits_handle);
// fill into event
//int64_t CRT_T0_reference_time = fParams.ReferenceCRTT0ToBeam() ? -srtrigger.beam_gate_time_abs : 0; // ns, signed
//double CRT_T1_reference_time = fParams.ReferenceCRTT1FromTriggerToBeam() ? srtrigger.trigger_within_gate : 0.;
int64_t CRT_T0_reference_time = isRealData ? -srtrigger.beam_gate_time_abs : -fParams.CRTSimT0Offset();
double CRT_T1_reference_time = isRealData ? srtrigger.trigger_within_gate : -fParams.CRTSimT0Offset();

if (crthits_handle.isValid()) {
const std::vector<sbn::crt::CRTHit> &crthits = *crthits_handle;
for (unsigned i = 0; i < crthits.size(); i++) {
srcrthits.emplace_back();
FillCRTHit(crthits[i], fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, srcrthits.back());
}
}
// Fill various detector information associated with the event

// Get all of the CRT Tracks
std::vector<caf::SRCRTHit> srcrthits;
std::vector<caf::SRCRTTrack> srcrttracks;
std::vector<caf::SRCRTSpacePoint> srcrtspacepoints;
std::vector<caf::SRSBNDCRTTrack> srsbndcrttracks;

art::Handle<std::vector<sbn::crt::CRTTrack>> crttracks_handle;
GetByLabelStrict(evt, fParams.CRTTrackLabel(), crttracks_handle);
// fill into event
if (crttracks_handle.isValid()) {
const std::vector<sbn::crt::CRTTrack> &crttracks = *crttracks_handle;
for (unsigned i = 0; i < crttracks.size(); i++) {
srcrttracks.emplace_back();
FillCRTTrack(crttracks[i], fParams.CRTUseTS0(), srcrttracks.back());
if(fDet == kICARUS)
{
art::Handle<std::vector<sbn::crt::CRTHit>> crthits_handle;
GetByLabelStrict(evt, fParams.CRTHitLabel(), crthits_handle);
// fill into event
if (crthits_handle.isValid()) {
const std::vector<sbn::crt::CRTHit> &crthits = *crthits_handle;
for (unsigned i = 0; i < crthits.size(); i++) {
srcrthits.emplace_back();
FillCRTHit(crthits[i], fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, srcrthits.back());
}
}

art::Handle<std::vector<sbn::crt::CRTTrack>> crttracks_handle;
GetByLabelStrict(evt, fParams.CRTTrackLabel(), crttracks_handle);
// fill into event
if (crttracks_handle.isValid()) {
const std::vector<sbn::crt::CRTTrack> &crttracks = *crttracks_handle;
for (unsigned i = 0; i < crttracks.size(); i++) {
srcrttracks.emplace_back();
FillCRTTrack(crttracks[i], fParams.CRTUseTS0(), srcrttracks.back());
}
}
}
else if(fDet == kSBND)
{
art::Handle<std::vector<sbnd::crt::CRTSpacePoint>> crtspacepoints_handle;
GetByLabelStrict(evt, fParams.CRTSpacePointLabel(), crtspacepoints_handle);

if (crtspacepoints_handle.isValid()) {
const std::vector<sbnd::crt::CRTSpacePoint> &crtspacepoints = *crtspacepoints_handle;
for (unsigned i = 0; i < crtspacepoints.size(); i++) {
srcrtspacepoints.emplace_back();
FillCRTSpacePoint(crtspacepoints[i], srcrtspacepoints.back());
}
}

art::Handle<std::vector<sbnd::crt::CRTTrack>> sbndcrttracks_handle;
GetByLabelStrict(evt, fParams.SBNDCRTTrackLabel(), sbndcrttracks_handle);
// fill into event
if (sbndcrttracks_handle.isValid()) {
const std::vector<sbnd::crt::CRTTrack> &sbndcrttracks = *sbndcrttracks_handle;
for (unsigned i = 0; i < sbndcrttracks.size(); i++) {
srsbndcrttracks.emplace_back();
FillSBNDCRTTrack(sbndcrttracks[i], srsbndcrttracks.back());
}
}
}
}

// Get all of the CRTPMT Matches ..
std::vector<caf::SRCRTPMTMatch> srcrtpmtmatches;
Expand Down Expand Up @@ -1599,6 +1647,10 @@ void CAFMaker::produce(art::Event& evt) noexcept {
FindManyPStrict<sbn::MVAPID>(slcShowers, evt,
fParams.ShowerRazzleLabel() + slice_tag_suff);

art::FindOneP<sbn::PFPCNNScore> foCNNScores =
FindOnePStrict<sbn::PFPCNNScore>(fmPFPart, evt,
fParams.CNNScoreLabel() + slice_tag_suff);

art::FindManyP<recob::Vertex> fmVertex =
FindManyPStrict<recob::Vertex>(fmPFPart, evt,
fParams.PFParticleLabel() + slice_tag_suff);
Expand All @@ -1622,6 +1674,14 @@ void CAFMaker::produce(art::Event& evt) noexcept {
FindManyPStrict<anab::T0>(slcTracks, evt,
fParams.CRTTrackMatchLabel() + slice_tag_suff);

art::FindOneP<sbnd::crt::CRTSpacePoint, anab::T0> foCRTSpacePointMatch =
FindOnePDStrict<sbnd::crt::CRTSpacePoint, anab::T0>(slcTracks, evt,
fParams.CRTSpacePointMatchLabel() + slice_tag_suff);

art::FindOneP<sbnd::crt::CRTTrack, anab::T0> foSBNDCRTTrackMatch =
FindOnePDStrict<sbnd::crt::CRTTrack, anab::T0>(slcTracks, evt,
fParams.SBNDCRTTrackMatchLabel() + slice_tag_suff);

std::vector<art::FindManyP<recob::MCSFitResult>> fmMCSs;
static const std::vector<std::string> PIDnames {"muon", "pion", "kaon", "proton"};
for (std::string pid: PIDnames) {
Expand Down Expand Up @@ -1788,6 +1848,11 @@ void CAFMaker::produce(art::Event& evt) noexcept {
const larpandoraobj::PFParticleMetadata *pfpMeta = (fmPFPMeta.at(iPart).empty()) ? NULL : fmPFPMeta.at(iPart).at(0).get();
FillPFPVars(thisParticle, primary, pfpMeta, thisPFPT0, pfp);

if (foCNNScores.isValid()) {
const sbn::PFPCNNScore *cnnScores = foCNNScores.at(iPart).get();
FillCNNScores(thisParticle, cnnScores, pfp);
}

if (!thisTrack.empty()) { // it has a track!
assert(thisTrack.size() == 1);

Expand Down Expand Up @@ -1836,7 +1901,7 @@ void CAFMaker::produce(art::Event& evt) noexcept {
fParams.TrackHitFillRRStartCut(), fParams.TrackHitFillRREndCut(),
lar::providerFrom<geo::Geometry>(), dprop, trk);
}
if (fmCRTHitMatch.isValid()) {
if (fmCRTHitMatch.isValid() && fDet == kICARUS) {
art::FindManyP<sbn::crt::CRTHit> CRTT02Hit = FindManyPStrict<sbn::crt::CRTHit>
(fmCRTHitMatch.at(iPart), evt, fParams.CRTHitMatchLabel() + slice_tag_suff);

Expand All @@ -1846,9 +1911,25 @@ void CAFMaker::produce(art::Event& evt) noexcept {
FillTrackCRTHit(fmCRTHitMatch.at(iPart), crthitmatch, fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, trk);
}
// NOTE: SEE TODO AT fmCRTTrackMatch
if (fmCRTTrackMatch.isValid()) {
if (fmCRTTrackMatch.isValid() && fDet == kICARUS) {
FillTrackCRTTrack(fmCRTTrackMatch.at(iPart), trk);
}

if(foCRTSpacePointMatch.isValid() && fDet == kSBND)
{
const art::Ptr<sbnd::crt::CRTSpacePoint> crtspacepoint = foCRTSpacePointMatch.at(iPart);

if(crtspacepoint.isNonnull())
FillTrackCRTSpacePoint(foCRTSpacePointMatch.data(iPart).ref(), crtspacepoint, trk);
}
if(foSBNDCRTTrackMatch.isValid() && fDet == kSBND)
{
const art::Ptr<sbnd::crt::CRTTrack> sbndcrttrack = foSBNDCRTTrackMatch.at(iPart);

if(sbndcrttrack.isNonnull())
FillTrackSBNDCRTTrack(foSBNDCRTTrackMatch.data(iPart).ref(), sbndcrttrack, trk);
}

// Truth matching
if (fmTrackHit.isValid()) {
if ( !isRealData ) {
Expand Down Expand Up @@ -1912,17 +1993,21 @@ void CAFMaker::produce(art::Event& evt) noexcept {
//#######################################################
// Fill rec Tree
//#######################################################
rec.nslc = rec.slc.size();
rec.mc = srtruthbranch;
rec.fake_reco = srfakereco;
rec.nfake_reco = srfakereco.size();
rec.pass_flashtrig = pass_flash_trig; // trigger result
rec.crt_hits = srcrthits;
rec.ncrt_hits = srcrthits.size();
rec.crt_tracks = srcrttracks;
rec.ncrt_tracks = srcrttracks.size();
rec.opflashes = srflashes;
rec.nopflashes = srflashes.size();
rec.nslc = rec.slc.size();
rec.mc = srtruthbranch;
rec.fake_reco = srfakereco;
rec.nfake_reco = srfakereco.size();
rec.pass_flashtrig = pass_flash_trig; // trigger result
rec.crt_hits = srcrthits;
rec.ncrt_hits = srcrthits.size();
rec.crt_tracks = srcrttracks;
rec.ncrt_tracks = srcrttracks.size();
rec.crt_spacepoints = srcrtspacepoints;
rec.ncrt_spacepoints = srcrtspacepoints.size();
rec.sbnd_crt_tracks = srsbndcrttracks;
rec.nsbnd_crt_tracks = srsbndcrttracks.size();
rec.opflashes = srflashes;
rec.nopflashes = srflashes.size();
if (fParams.FillTrueParticles()) {
rec.true_particles = true_particles;
}
Expand Down
1 change: 1 addition & 0 deletions sbncode/CAFMaker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ art_make_library( LIBRARY_NAME sbncode_CAFMaker
sbnobj::Common_CRT
sbnobj::Common_Reco
sbnobj::Common_Analysis
sbnobj::SBND_CRT
lardataalg::DetectorInfo
art::Framework_Services_System_TriggerNamesService_service
sbncode_Metadata_MetadataSBN_service
Expand Down
Loading

0 comments on commit 1b78be9

Please sign in to comment.