Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)

find_package(cetmodules 3.20.00 REQUIRED)
project(sbncode VERSION 09.88.00.04 LANGUAGES CXX)
project(sbncode VERSION 09.89.01 LANGUAGES CXX)

message(STATUS "\n\n ========================== ${PROJECT_NAME} ==========================")

Expand Down
159 changes: 95 additions & 64 deletions sbncode/DetSim/AdjustSimForTrigger_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include "fhiclcpp/ParameterSet.h"
#include "messagefacility/MessageLogger/MessageLogger.h"

// #include "lardataalg/DetectorInfo/DetectorClocksData.h"
#include "lardataobj/RawData/OpDetWaveform.h"
#include "lardataobj/RawData/TriggerData.h"
#include "lardataobj/Simulation/AuxDetSimChannel.h"
#include "lardataobj/Simulation/BeamGateInfo.h"
#include "lardataobj/Simulation/SimEnergyDeposit.h"
#include "lardataobj/Simulation/SimPhotons.h"
Expand All @@ -45,44 +45,52 @@ class AdjustSimForTrigger : public art::EDProducer {
void produce(art::Event& e) override;

private:
art::InputTag fInputSimEnergyDepositLabel;
art::InputTag fInputSimPhotonsLabel;
art::InputTag fInputTriggerLabel;
art::InputTag fInputWaveformLabel;
art::InputTag fInputBeamGateInfoLabel;
double fAdditionalOffset;
art::InputTag fInitAuxDetSimChannelLabel;
art::InputTag fInitBeamGateInfoLabel;
art::InputTag fInitSimEnergyDepositLabel;
art::InputTag fInitSimPhotonsLabel;
art::InputTag fInitWaveformLabel;
bool fShiftAuxDetIDEs;
bool fShiftBeamGateInfo;
bool fShiftSimEnergyDeposits;
bool fShiftSimPhotons;
bool fShiftWaveforms;
bool fShiftBeamGateInfo;
double fAdditionalOffset;
static constexpr auto& kModuleName = "AdjustSimForTrigger";
};

AdjustSimForTrigger::AdjustSimForTrigger(fhicl::ParameterSet const& p)
: EDProducer{p}
, fInputSimEnergyDepositLabel{p.get<art::InputTag>("InputSimEnergyDepositLabel", "")}
, fInputSimPhotonsLabel{p.get<art::InputTag>("InputSimPhotonsLabel", "")}
, fInputTriggerLabel{p.get<art::InputTag>("InputTriggerLabel", "")}
, fInputWaveformLabel(p.get<art::InputTag>("InputWaveformLabel", ""))
, fInputBeamGateInfoLabel{p.get<art::InputTag>("InputBeamGateInfoLabel", "")}
, fAdditionalOffset{p.get<double>("AdditionalOffset")}
, fInputTriggerLabel{p.get<art::InputTag>("InputTriggerLabel", "undefined")}
, fInitAuxDetSimChannelLabel(p.get<art::InputTag>("InitAuxDetSimChannelLabel", "undefined"))
, fInitBeamGateInfoLabel{p.get<art::InputTag>("InitBeamGateInfoLabel", "undefined")}
, fInitSimEnergyDepositLabel{p.get<art::InputTag>("InitSimEnergyDepositLabel", "undefined")}
, fInitSimPhotonsLabel{p.get<art::InputTag>("InitSimPhotonsLabel", "undefined")}
, fInitWaveformLabel(p.get<art::InputTag>("InitWaveformLabel", "undefined"))
, fShiftAuxDetIDEs{p.get<bool>("ShiftAuxDetIDEs", false)}
, fShiftBeamGateInfo{p.get<bool>("ShiftBeamGateInfo", false)}
, fShiftSimEnergyDeposits{p.get<bool>("ShiftSimEnergyDeposits", false)}
, fShiftSimPhotons{p.get<bool>("ShiftSimPhotons", false)}
, fShiftWaveforms{p.get<bool>("ShiftWaveforms", false)}
, fShiftBeamGateInfo{p.get<bool>("ShiftBeamGateInfo", false)}
, fAdditionalOffset{p.get<double>("AdditionalOffset", 0.)}
{
if (!(fShiftSimEnergyDeposits | fShiftSimPhotons | fShiftWaveforms | fShiftBeamGateInfo)) {
if (!(fShiftSimEnergyDeposits || fShiftSimPhotons || fShiftWaveforms || fShiftAuxDetIDEs ||
fShiftBeamGateInfo)) {
throw art::Exception(art::errors::EventProcessorFailure)
<< "NO SHIFTS ENABLED!\n"
<< "SHIFTING SIMENERGYDEPOSITS? " << fShiftSimEnergyDeposits << '\n'
<< "SHIFTING SIMPHOTONS? " << fShiftSimPhotons << '\n'
<< "SHIFTING OPDETWAVEFORMS? " << fShiftWaveforms << '\n'
<< "SHIFTING BEAMGATEINFO? " << fShiftBeamGateInfo << '\n';
<< kModuleName << ": NO SHIFTS ENABLED!\n";
}
mf::LogInfo(kModuleName) << std::boolalpha << "SHIFTING AUXDETIDES? " << fShiftAuxDetIDEs << '\n'
<< "SHIFTING BEAMGATEINFO? " << fShiftBeamGateInfo << '\n'
<< "SHIFTING SIMENERGYDEPOSITS? " << fShiftSimEnergyDeposits << '\n'
<< "SHIFTING SIMPHOTONS? " << fShiftSimPhotons << '\n'
<< "SHIFTING OPDETWAVEFORMS? " << fShiftWaveforms;

if (fShiftAuxDetIDEs) { produces<std::vector<sim::AuxDetSimChannel>>(); }
if (fShiftBeamGateInfo) { produces<std::vector<sim::BeamGateInfo>>(); }
if (fShiftSimEnergyDeposits) { produces<std::vector<sim::SimEnergyDeposit>>(); }
if (fShiftSimPhotons) { produces<std::vector<sim::SimPhotons>>(); }
if (fShiftWaveforms) { produces<std::vector<raw::OpDetWaveform>>(); }
if (fShiftBeamGateInfo) { produces<std::vector<sim::BeamGateInfo>>(); }
}

void AdjustSimForTrigger::produce(art::Event& e)
Expand All @@ -92,10 +100,11 @@ void AdjustSimForTrigger::produce(art::Event& e)

if (triggers.size() != 1) {
if (triggers.empty()) {
throw art::Exception(art::errors::EventProcessorFailure) << "NO TRIGGER IDENTIFIED!\n";
throw art::Exception(art::errors::EventProcessorFailure)
<< kModuleName << ": NO TRIGGER IDENTIFIED!";
}
throw art::Exception(art::errors::EventProcessorFailure)
<< "MORE THAN ONE TRIGGER IN EVENT... why?\n";
<< kModuleName << ": MORE THAN ONE TRIGGER IN EVENT... why?";
}

// Assuming there is a trigger, get time shift
Expand All @@ -111,13 +120,59 @@ void AdjustSimForTrigger::produce(art::Event& e)
hasValidTriggerTime ? clock_data.TriggerTime() - trigger.TriggerTime() + fAdditionalOffset : 0.;
const double timeShiftForTrigger_ns = 1000. * timeShiftForTrigger_us;

mf::LogInfo("AdjustSimForTrigger")
<< "FOR THIS EVENT THE TIME SHIFT BEING ASSUMED IS " << timeShiftForTrigger_ns << " ns ...\n";
mf::LogInfo(kModuleName) << "FOR THIS EVENT THE TIME SHIFT BEING ASSUMED IS "
<< timeShiftForTrigger_ns << " ns ...";

// Loop over the sim::AuxDetIDE and shift time BACK by the TRIGGER
if (fShiftAuxDetIDEs) {
auto const& simChannels =
e.getProduct<std::vector<sim::AuxDetSimChannel>>(fInitAuxDetSimChannelLabel);
auto pSimChannels = std::make_unique<std::vector<sim::AuxDetSimChannel>>();

pSimChannels->reserve(simChannels.size());

for (auto const& simChannel : simChannels) {
std::vector<sim::AuxDetIDE> shiftedAuxDetIDEs = simChannel.AuxDetIDEs();
for (auto& auxDetIDE : shiftedAuxDetIDEs) {
auxDetIDE.entryT += timeShiftForTrigger_ns;
auxDetIDE.exitT += timeShiftForTrigger_ns;
}
pSimChannels->emplace_back(sim::AuxDetSimChannel(
simChannel.AuxDetID(), shiftedAuxDetIDEs, simChannel.AuxDetSensitiveID()));
}
e.put(std::move(pSimChannels));
}

// Repeat for sim::BeamGateInfo
if (fShiftBeamGateInfo) {
auto const& beamGates = e.getProduct<std::vector<sim::BeamGateInfo>>(fInitBeamGateInfoLabel);

if (beamGates.size() != 1) {
if (beamGates.empty()) {
throw art::Exception(art::errors::EventProcessorFailure)
<< kModuleName << ": THERE IS NO BEAM GATE INFO!\n";
}
throw art::Exception(art::errors::EventProcessorFailure)
<< kModuleName << ": MORE THAN ONE BEAM GATE?\n";
}

const auto& beamGate = beamGates[0];

const double shiftedBeamGateStart = beamGate.Start() + timeShiftForTrigger_ns;
const double gateWidth = beamGate.Width();
const sim::BeamType_t beam = beamGate.BeamType();

const sim::BeamGateInfo shiftedBeamGate(shiftedBeamGateStart, gateWidth, beam);

auto pBeamGateInfos = std::make_unique<std::vector<sim::BeamGateInfo>>(1, shiftedBeamGate);

e.put(std::move(pBeamGateInfos));
}

// Loop over the SimEnergyDeposit objects and shift time BACK by the TRIGGER
// Repeat for sim::SimEnergyDeposit
if (fShiftSimEnergyDeposits) {
auto const& simEDeps =
e.getProduct<std::vector<sim::SimEnergyDeposit>>(fInputSimEnergyDepositLabel);
e.getProduct<std::vector<sim::SimEnergyDeposit>>(fInitSimEnergyDepositLabel);

auto pSimEDeps = std::make_unique<std::vector<sim::SimEnergyDeposit>>();
pSimEDeps->reserve(simEDeps.size());
Expand All @@ -136,24 +191,24 @@ void AdjustSimForTrigger::produce(art::Event& e)
const int thisPDG = inSimEDep.PdgCode();
const int origID = inSimEDep.OrigTrackID();

pSimEDeps->push_back(sim::SimEnergyDeposit(numphotons,
numelectrons,
syratio,
energy,
start,
end,
startT,
endT,
thisID,
thisPDG,
origID));
pSimEDeps->emplace_back(sim::SimEnergyDeposit(numphotons,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curiosity: why was this changed? I guess it's unrelated to the trigger time shift.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unfamiliar with this specific module. I did not attempt to change anything and am a little perplexed why there would be changes in other places. I will try to figure out if this is the correct branch to make this PR against (this was the closest thing I saw to v09_89_01).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If your initial work was against the develop branch then when you rebased to the release it likely saw this as a change and included it. I would cherry pick out only your specific changes and start with a clean version of code on the release/SBN2024A branch (but see later comment).

numelectrons,
syratio,
energy,
start,
end,
startT,
endT,
thisID,
thisPDG,
origID));
}
e.put(std::move(pSimEDeps));
}

// Repeat for sim::SimPhotons
if (fShiftSimPhotons) {
auto const& simPhotons = e.getProduct<std::vector<sim::SimPhotons>>(fInputSimPhotonsLabel);
auto const& simPhotons = e.getProduct<std::vector<sim::SimPhotons>>(fInitSimPhotonsLabel);
auto pSimPhotonss = std::make_unique<std::vector<sim::SimPhotons>>(simPhotons);

for (auto& photons : *pSimPhotonss) {
Expand All @@ -166,38 +221,14 @@ void AdjustSimForTrigger::produce(art::Event& e)

// Repeat for raw::OpDetWaveform
if (fShiftWaveforms) {
auto const& waveforms = e.getProduct<std::vector<raw::OpDetWaveform>>(fInputWaveformLabel);
auto const& waveforms = e.getProduct<std::vector<raw::OpDetWaveform>>(fInitWaveformLabel);
auto pWaveforms = std::make_unique<std::vector<raw::OpDetWaveform>>(waveforms);

for (auto& waveform : *pWaveforms) {
waveform.SetTimeStamp(waveform.TimeStamp() + timeShiftForTrigger_us);
}
e.put(std::move(pWaveforms));
}

// Repeat for sim::BeamGateInfo
if (fShiftBeamGateInfo) {
auto const& beamGates = e.getProduct<std::vector<sim::BeamGateInfo>>(fInputBeamGateInfoLabel);

if (beamGates.size() != 1) {
if (beamGates.empty()) {
throw art::Exception(art::errors::EventProcessorFailure) << "THERE IS NO BEAM GATE INFO!\n";
}
throw art::Exception(art::errors::EventProcessorFailure) << "MORE THAN ONE BEAM GATE?\n";
}

const auto& beamGate = beamGates[0];

const double shiftedBeamGateStart = beamGate.Start() + timeShiftForTrigger_ns;
const double gateWidth = beamGate.Width();
const sim::BeamType_t beam = beamGate.BeamType();

const sim::BeamGateInfo shiftedBeamGate(shiftedBeamGateStart, gateWidth, beam);

auto pBeamGateInfos = std::make_unique<std::vector<sim::BeamGateInfo>>(1, shiftedBeamGate);

e.put(std::move(pBeamGateInfos));
}
}

DEFINE_ART_MODULE(AdjustSimForTrigger)
4 changes: 4 additions & 0 deletions sbncode/DetSim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ set( MODULE_LIBRARIES
ROOT::Geom
ROOT::XMLIO
ROOT::Gdml
ROOT::Core
FFTW3::FFTW3
)

cet_build_plugin(AdjustSimForTrigger art::module LIBRARIES ${MODULE_LIBRARIES})
cet_build_plugin(FilterSimEnergyDeposits art::module LIBRARIES ${MODULE_LIBRARIES})

add_subdirectory(fcl)

#install_headers()
install_fhicl()
Expand Down
Loading
Loading