From f22e5e5bf78a6aa69e96426246dbaa30df77e8c4 Mon Sep 17 00:00:00 2001 From: icaromx Date: Thu, 6 Mar 2025 11:03:30 -0600 Subject: [PATCH 1/8] updated code for making cafs from overlay files now using v10 --- sbncode/CAFMaker/CAFMakerParams.h | 4 ++++ sbncode/CAFMaker/CAFMaker_module.cc | 24 +++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/sbncode/CAFMaker/CAFMakerParams.h b/sbncode/CAFMaker/CAFMakerParams.h index d05eb8b9b..dab095902 100644 --- a/sbncode/CAFMaker/CAFMakerParams.h +++ b/sbncode/CAFMaker/CAFMakerParams.h @@ -44,6 +44,10 @@ namespace caf Atom SaveGENIEEventRecord { Name("SaveGENIEEventRecord"), Comment("Whether to produce GENIE event record to the output file"), false }; + + Atom OverrideRealData { Name("OverrideRealData"), + Comment("Whether to ignore things aimed at real data -- e.g. if instead the event in an overlay"), false + }; Atom PrescaleFactor { Name("PrescaleFactor"), Comment("Factor by which to prescale unblind events"), 10 diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 2728b395f..62feede18 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -199,7 +199,8 @@ class CAFMaker : public art::EDProducer { std::string fSourceFile; std::uint32_t fSourceFileHash; - + + bool fOverrideRealData; bool fFirstInSubRun; unsigned int fIndexInFile = SRHeader::NoSourceIndex; bool fFirstBlindInSubRun; @@ -401,6 +402,7 @@ class CAFMaker : public art::EDProducer { // Note: we will define isRealData on a per event basis in produce function [using event.isRealData()], at least for now. fCafFilename = fParams.CAFFilename(); + fOverrideRealData = fParams.OverrideRealData(); fFlatCafFilename = fParams.FlatCAFFilename(); // Normally CAFMaker is run wit no output ART stream, so these go @@ -847,9 +849,18 @@ void CAFMaker::beginSubRun(art::SubRun& sr) { std::cout << std::endl; abort(); } - + if ( fOverrideRealData ) { + // Expects a generator POT summary then... + if(auto pot_handle = sr.getHandle(fParams.GenLabel())){ + fSubRunPOT = pot_handle->totgoodpot; + fTotalPOT += fSubRunPOT; + }else{ + std::cout << "Did not find MC POT info under " << fParams.GenLabel() << std::endl; + if(fParams.StrictMode()) abort(); + } + }else{ if(bnb_spill){ - FillExposure(*bnb_spill, fBNBInfo, fSubRunPOT); + FillExposure(*bnb_spill, fBNBInfo, fSubRunPOT); fTotalPOT += fSubRunPOT; // Find the spill for each event and fill the event map: @@ -908,10 +919,9 @@ void CAFMaker::beginSubRun(art::SubRun& sr) { << std::endl; if(fParams.StrictMode()) abort(); } - // Otherwise, if one label is blank, maybe no POT was the expected result } - + } std::cout << "POT: " << fSubRunPOT << std::endl; fFirstInSubRun = true; @@ -1263,8 +1273,8 @@ void CAFMaker::produce(art::Event& evt) noexcept { bool const firstInFile = (fIndexInFile++ == 0); - // is this event real data? - bool isRealData = evt.isRealData(); + // is this event real data? -- BH: if fOverrideRealData, treat it as MC. Otherwise, get the info from the art event. + bool isRealData = ( fOverrideRealData ? false : evt.isRealData() ); std::unique_ptr> srcol( new std::vector); From 5c2a3f5ebc20ea0c35911be8d1f1d8c7241a8b5a Mon Sep 17 00:00:00 2001 From: Gray Putnam Date: Tue, 11 Mar 2025 19:05:41 -0500 Subject: [PATCH 2/8] Update MergeSimSourceSBN to new interface. --- sbncode/LArG4/MergeSimSourcesSBN_module.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sbncode/LArG4/MergeSimSourcesSBN_module.cc b/sbncode/LArG4/MergeSimSourcesSBN_module.cc index da84303a7..ee4967227 100644 --- a/sbncode/LArG4/MergeSimSourcesSBN_module.cc +++ b/sbncode/LArG4/MergeSimSourcesSBN_module.cc @@ -119,6 +119,12 @@ class sbn::MergeSimSourcesSBN : public art::EDProducer { false // default }; + fhicl::Atom SkipTrackIDOffsets { + fhicl::Name{"SkipTrackIDOffsets"}, + fhicl::Comment{"whether to skip track ID offsets in merge"}, + false // default + }; + fhicl::Sequence AuxDetHitsInstanceLabels{ fhicl::Name{"AuxDetHitsInstanceLabels"}, fhicl::Comment{"labels of AuxDetHits collections to merge"}, @@ -158,6 +164,7 @@ class sbn::MergeSimSourcesSBN : public art::EDProducer { bool const fFillSimChannels; bool const fFillAuxDetSimChannels; bool const fFillSimEnergyDeposits; + bool const fSkipTrackIDOffsets; std::vector const fEnergyDepositionInstances; bool const fFillAuxDetHits; std::vector const fAuxDetHitsInstanceLabels; @@ -202,6 +209,7 @@ sbn::MergeSimSourcesSBN::MergeSimSourcesSBN(Parameters const& params) , fFillSimEnergyDeposits( getOptionalValue(params().FillSimEnergyDeposits) .value_or(art::ServiceHandle()->FillSimEnergyDeposits())) + , fSkipTrackIDOffsets(params().SkipTrackIDOffsets()) , fEnergyDepositionInstances(params().EnergyDepositInstanceLabels()) , fFillAuxDetHits(params().FillAuxDetHits()) , fAuxDetHitsInstanceLabels(params().AuxDetHitsInstanceLabels()) @@ -349,7 +357,7 @@ void sbn::MergeSimSourcesSBN::produce(art::Event& e) if (fFillSimChannels) { auto const& input_scCol = e.getProduct>(input_label); - MergeUtility.MergeSimChannels(*scCol, input_scCol, i_source); + MergeUtility.MergeSimChannels(*scCol, input_scCol, i_source, fSkipTrackIDOffsets); } if (fFillAuxDetSimChannels) { From 5234493b599f6cd58e0bc7bf4caf0de244277efd Mon Sep 17 00:00:00 2001 From: Gray Putnam Date: Mon, 24 Mar 2025 10:00:55 -0500 Subject: [PATCH 3/8] Add in option to shift SimEnergyDepositLites to TriggerSimAdjuster --- sbncode/DetSim/AdjustSimForTrigger_module.cc | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/sbncode/DetSim/AdjustSimForTrigger_module.cc b/sbncode/DetSim/AdjustSimForTrigger_module.cc index 14c7cabe2..5f6c5eee9 100644 --- a/sbncode/DetSim/AdjustSimForTrigger_module.cc +++ b/sbncode/DetSim/AdjustSimForTrigger_module.cc @@ -22,6 +22,7 @@ #include "lardataobj/Simulation/AuxDetSimChannel.h" #include "lardataobj/Simulation/BeamGateInfo.h" #include "lardataobj/Simulation/SimEnergyDeposit.h" +#include "lardataobj/Simulation/SimEnergyDepositLite.h" #include "lardataobj/Simulation/SimPhotons.h" #include @@ -49,11 +50,13 @@ class AdjustSimForTrigger : public art::EDProducer { art::InputTag fInitAuxDetSimChannelLabel; art::InputTag fInitBeamGateInfoLabel; art::InputTag fInitSimEnergyDepositLabel; + art::InputTag fInitSimEnergyDepositLiteLabel; art::InputTag fInitSimPhotonsLabel; art::InputTag fInitWaveformLabel; bool fShiftAuxDetIDEs; bool fShiftBeamGateInfo; bool fShiftSimEnergyDeposits; + bool fShiftSimEnergyDepositLites; bool fShiftSimPhotons; bool fShiftWaveforms; double fAdditionalOffset; @@ -66,29 +69,33 @@ AdjustSimForTrigger::AdjustSimForTrigger(fhicl::ParameterSet const& p) , fInitAuxDetSimChannelLabel(p.get("InitAuxDetSimChannelLabel", "undefined")) , fInitBeamGateInfoLabel{p.get("InitBeamGateInfoLabel", "undefined")} , fInitSimEnergyDepositLabel{p.get("InitSimEnergyDepositLabel", "undefined")} + , fInitSimEnergyDepositLiteLabel{p.get("InitSimEnergyDepositLiteLabel", "undefined")} , fInitSimPhotonsLabel{p.get("InitSimPhotonsLabel", "undefined")} , fInitWaveformLabel(p.get("InitWaveformLabel", "undefined")) , fShiftAuxDetIDEs{p.get("ShiftAuxDetIDEs", false)} , fShiftBeamGateInfo{p.get("ShiftBeamGateInfo", false)} , fShiftSimEnergyDeposits{p.get("ShiftSimEnergyDeposits", false)} + , fShiftSimEnergyDepositLites{p.get("ShiftSimEnergyDepositLites", false)} , fShiftSimPhotons{p.get("ShiftSimPhotons", false)} , fShiftWaveforms{p.get("ShiftWaveforms", false)} , fAdditionalOffset{p.get("AdditionalOffset", 0.)} { if (!(fShiftSimEnergyDeposits || fShiftSimPhotons || fShiftWaveforms || fShiftAuxDetIDEs || - fShiftBeamGateInfo)) { + fShiftBeamGateInfo || fShiftSimEnergyDepositLites)) { throw art::Exception(art::errors::EventProcessorFailure) << kModuleName << ": NO SHIFTS ENABLED!\n"; } mf::LogInfo(kModuleName) << std::boolalpha << "SHIFTING AUXDETIDES? " << fShiftAuxDetIDEs << '\n' << "SHIFTING BEAMGATEINFO? " << fShiftBeamGateInfo << '\n' << "SHIFTING SIMENERGYDEPOSITS? " << fShiftSimEnergyDeposits << '\n' + << "SHIFTING SIMENERGYDEPOSITLITES? " << fShiftSimEnergyDepositLites << '\n' << "SHIFTING SIMPHOTONS? " << fShiftSimPhotons << '\n' << "SHIFTING OPDETWAVEFORMS? " << fShiftWaveforms; if (fShiftAuxDetIDEs) { produces>(); } if (fShiftBeamGateInfo) { produces>(); } if (fShiftSimEnergyDeposits) { produces>(); } + if (fShiftSimEnergyDepositLites) { produces>(); } if (fShiftSimPhotons) { produces>(); } if (fShiftWaveforms) { produces>(); } } @@ -205,6 +212,24 @@ void AdjustSimForTrigger::produce(art::Event& e) } e.put(std::move(pSimEDeps)); } + // and SimEnergyDepositLite's + if (fShiftSimEnergyDepositLites) { + auto const& simEDepLites = + e.getProduct>(fInitSimEnergyDepositLiteLabel); + + auto pSimEDepLites = std::make_unique>(); + + for (auto const& inSimEDepLite : simEDepLites) { + double energy = inSimEDepLite.Energy(); + geo::Point_t middlePos = inSimEDepLite.Position(); + double middleTime = inSimEDepLite.Time() + timeShiftForTrigger_ns; + int ID = inSimEDepLite.TrackID(); + + pSimEDepLites->emplace_back(energy, middlePos, middleTime, ID); + } + + e.put(std::move(pSimEDepLites)); + } // Repeat for sim::SimPhotons if (fShiftSimPhotons) { From 42db454e27514578c45132dd81f1f464e61a32d0 Mon Sep 17 00:00:00 2001 From: Gray Putnam Date: Sat, 5 Apr 2025 16:59:48 -0500 Subject: [PATCH 4/8] Fix association bug --- sbncode/Calibration/TrackCaloSkimmer_module.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbncode/Calibration/TrackCaloSkimmer_module.cc b/sbncode/Calibration/TrackCaloSkimmer_module.cc index 8b424aed7..4588634cd 100644 --- a/sbncode/Calibration/TrackCaloSkimmer_module.cc +++ b/sbncode/Calibration/TrackCaloSkimmer_module.cc @@ -234,7 +234,7 @@ void sbn::TrackCaloSkimmer::analyze(art::Event const& e) // Hits (ICARUS style) art::FindManyP fmT0CRTHit(tracks, e, fCRTHitT0producer); - art::FindManyP fmCRTHitT0TaggingInfo(PFParticleList, e, fCRTHitT0producer); + art::FindManyP fmCRTHitT0TaggingInfo(tracks, e, fCRTHitT0producer); // Track - associated data art::FindManyP fmTracks(PFParticleList, e, fTRKproducer); From 4f505f666ab23a7750deed126ff42e532ee1043d Mon Sep 17 00:00:00 2001 From: Gray Putnam Date: Sat, 5 Apr 2025 19:25:59 -0500 Subject: [PATCH 5/8] Protect against overflow when filling flat GENIE record. --- sbncode/CAFMaker/CAFMaker_module.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 62feede18..32013baca 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -1469,7 +1469,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { int iparticle=0; genie::GHepParticle * p = 0; - while( genie_rec->Particle(iparticle) != 0 ) { + while( (genie_rec->Particle(iparticle) != 0) && (iparticle < 250) ) { p = genie_rec->Particle(iparticle); fGenieEvtRec_brStdHepPdg[iparticle] = p->Pdg(); fGenieEvtRec_brStdHepStatus[iparticle] = (int) p->Status(); From 319e1a9e275de672d0c1db3583d663ff52ff2166 Mon Sep 17 00:00:00 2001 From: Gray Putnam Date: Wed, 23 Apr 2025 14:30:13 -0500 Subject: [PATCH 6/8] Include SimEnergyDepositLites in simedep filter. --- .../DetSim/FilterSimEnergyDeposits_module.cc | 27 +++++++++++++++++++ sbncode/DetSim/fcl/icarus_simedepfilter.fcl | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/sbncode/DetSim/FilterSimEnergyDeposits_module.cc b/sbncode/DetSim/FilterSimEnergyDeposits_module.cc index ffb45d6e3..087c7ae96 100644 --- a/sbncode/DetSim/FilterSimEnergyDeposits_module.cc +++ b/sbncode/DetSim/FilterSimEnergyDeposits_module.cc @@ -18,6 +18,7 @@ #include "larcorealg/Geometry/BoxBoundedGeo.h" #include "lardataobj/Simulation/SimEnergyDeposit.h" +#include "lardataobj/Simulation/SimEnergyDepositLite.h" #include @@ -43,6 +44,7 @@ class FilterSimEnergyDeposits : public art::EDProducer { // Declare member data here. art::InputTag fInitSimEnergyDepositLabel; + art::InputTag fInitSimEnergyDepositLiteLabel; geo::BoxBoundedGeo fBox; static constexpr auto kModuleName = "FilterSimEnergyDeposit"; double ShiftX(double z) const; @@ -56,6 +58,7 @@ class FilterSimEnergyDeposits : public art::EDProducer { FilterSimEnergyDeposits::FilterSimEnergyDeposits(fhicl::ParameterSet const& p) : EDProducer{p} , fInitSimEnergyDepositLabel{p.get("InitSimEnergyDepositLabel", "undefined")} + , fInitSimEnergyDepositLiteLabel{p.get("InitSimEnergyDepositLiteLabel", "undefined")} , fBox{p.get("P1_X"), p.get("P2_X"), p.get("P1_Y"), p.get("P2_Y"), p.get("P1_Z"), p.get("P2_Z")} @@ -66,6 +69,9 @@ FilterSimEnergyDeposits::FilterSimEnergyDeposits(fhicl::ParameterSet const& p) // Call appropriate produces<>() functions here. // Call appropriate consumes<>() for any products to be retrieved by this module. produces>(); + + + if (fInitSimEnergyDepositLiteLabel != "undefined") { produces>(); } } @@ -126,6 +132,27 @@ void FilterSimEnergyDeposits::produce(art::Event& e) origID)); } e.put(std::move(pSimEDeps)); + + // also futz with the SimEnergyDepositLite's if configured to + if (fInitSimEnergyDepositLiteLabel == "undefined") return; + + auto const& simEDepLites = + e.getProduct>(fInitSimEnergyDepositLiteLabel); + auto pSimEDepLites = std::make_unique>(); + pSimEDepLites->reserve(simEDepLites.size()); + + for (auto const& inSimEDepLite : simEDepLites) { + geo::Point_t middlePos = inSimEDepLite.Position(); + if(fBox.ContainsPosition(middlePos)) + continue; + double energy = inSimEDepLite.Energy(); + double middleTime = inSimEDepLite.Time(); + int ID = inSimEDepLite.TrackID(); + + pSimEDepLites->emplace_back(energy, middlePos, middleTime, ID); + } + + e.put(std::move(pSimEDepLites)); } DEFINE_ART_MODULE(FilterSimEnergyDeposits) diff --git a/sbncode/DetSim/fcl/icarus_simedepfilter.fcl b/sbncode/DetSim/fcl/icarus_simedepfilter.fcl index 124a50981..e56b2db8b 100644 --- a/sbncode/DetSim/fcl/icarus_simedepfilter.fcl +++ b/sbncode/DetSim/fcl/icarus_simedepfilter.fcl @@ -3,6 +3,7 @@ BEGIN_PROLOG simedepfilter_ind1gap: { module_type: "FilterSimEnergyDeposits" InitSimEnergyDepositLabel: "ionization" + InitSimEnergyDepositLiteLabel: "sedlite" P1_X: -400 #cm, create a box that spans the full x,y range. Not super-precise. P1_Y: -200 #cm, create a box that spans the full x,y range. Not super-precise. P1_Z: -2 #cm, one edge of the filtered gap based on the 37 mm total size of the wire gap @@ -16,4 +17,4 @@ simedepfilter_ind1gap: { } -END_PROLOG \ No newline at end of file +END_PROLOG From 9b443ee15d9f81a3bbd3d26359453ecbc24d81b6 Mon Sep 17 00:00:00 2001 From: gputnam Date: Thu, 24 Apr 2025 10:21:53 -0500 Subject: [PATCH 7/8] Clarify OverrideRealData comment. Co-authored-by: Gianluca Petrillo --- sbncode/CAFMaker/CAFMakerParams.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbncode/CAFMaker/CAFMakerParams.h b/sbncode/CAFMaker/CAFMakerParams.h index dab095902..ba84fb398 100644 --- a/sbncode/CAFMaker/CAFMakerParams.h +++ b/sbncode/CAFMaker/CAFMakerParams.h @@ -46,7 +46,7 @@ namespace caf }; Atom OverrideRealData { Name("OverrideRealData"), - Comment("Whether to ignore things aimed at real data -- e.g. if instead the event in an overlay"), false + Comment("when true, some algorithms (e.g. PoT count) treat events as MC rather than real data -- e.g. set it if the event is an overlay"), false }; Atom PrescaleFactor { Name("PrescaleFactor"), From 7b0737d65eb5c63cc5518ae9cc241cfc2ca4b9da Mon Sep 17 00:00:00 2001 From: gputnam Date: Thu, 24 Apr 2025 10:22:49 -0500 Subject: [PATCH 8/8] Idiomatic isRealData Co-authored-by: Gianluca Petrillo --- sbncode/CAFMaker/CAFMaker_module.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbncode/CAFMaker/CAFMaker_module.cc b/sbncode/CAFMaker/CAFMaker_module.cc index 32013baca..80e099102 100644 --- a/sbncode/CAFMaker/CAFMaker_module.cc +++ b/sbncode/CAFMaker/CAFMaker_module.cc @@ -1274,7 +1274,7 @@ void CAFMaker::produce(art::Event& evt) noexcept { bool const firstInFile = (fIndexInFile++ == 0); // is this event real data? -- BH: if fOverrideRealData, treat it as MC. Otherwise, get the info from the art event. - bool isRealData = ( fOverrideRealData ? false : evt.isRealData() ); + bool isRealData = !fOverrideRealData && evt.isRealData(); std::unique_ptr> srcol( new std::vector);