Skip to content
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

Update GENIEGen and other ppfx-related updates #120

Merged
merged 41 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
744b9d0
add dk2nu
Apr 7, 2020
1dfc2a8
add FluxReader module
Apr 9, 2020
46dd060
add PPFX calculators & fcl driver
Apr 9, 2020
b4273f6
update PPFX calculators to fix getEngine syntax issues
Apr 10, 2020
14f85b4
adjust EventWeight interface to fix more getEngine issues in art 3
Apr 30, 2020
3255e4d
add ppfx_uboone.fcl
Jun 1, 2020
d0d697d
add ppfx_ms weight
Jun 1, 2020
6491289
create horn & target config fcl parameters
Jun 8, 2020
76a5b86
update FluxReader to compile in MCC9
Jun 18, 2020
460dba7
change name to PPFXFluxReader
Jun 18, 2020
f610e9a
update flux calculation method to use 3D active volume
Jun 25, 2020
d72511d
Fix c2 compilation error.
hgreenlee Jul 1, 2020
83dafe3
Ppfx updates.
hgreenlee May 1, 2023
4a43299
Merge remote-tracking branch 'hbg/ppfx' into ppfx2
hgreenlee May 2, 2023
b1b9eb7
Merge remote-tracking branch 'origin/develop' into ppfx2
hgreenlee May 3, 2023
4250a1a
Fix build errors.
hgreenlee May 4, 2023
be5bfe8
only alter base seed if random_seed parameter set
pgreen135 Nov 25, 2022
841fe42
Fix and clean up ppfx weight calculator build.
hgreenlee May 4, 2023
f921362
Delete MicroBooNE-specific fcl files.
hgreenlee May 5, 2023
0e85218
Add ppfx as a dependent.
hgreenlee May 19, 2023
d8ed544
Merge remote-tracking branch 'origin/develop' into greenlee_ppfx
hgreenlee May 26, 2023
e2b705b
add ppfx_uboone.fcl
Jun 1, 2020
18d8e4a
Remove unnecessary dictionary files.
hgreenlee May 27, 2023
9c4a97d
Teach ppfx weight calculators to search for config data on $FW_SEARCH…
hgreenlee Jan 27, 2023
484235f
Don't add dk2nu data products if flux type is not "dk2nu."
hgreenlee Jun 2, 2023
997d45a
Merge remote-tracking branch 'origin/develop' into greenlee_ppfx
hgreenlee Jun 21, 2023
05bd337
Merge remote-tracking branch 'origin/develop' into greenlee_ppfx
hgreenlee Jun 21, 2023
3a68261
Update ppfx to version to v02_17_07.
hgreenlee Jun 21, 2023
02e7228
Remove ppfx_uboone.fcl.
hgreenlee Jun 21, 2023
8581b07
Update ppfx version to v02_18_00.
hgreenlee Jun 28, 2023
60a1cc6
Format updates.
hgreenlee Jun 29, 2023
a34b87e
Add "find_package(ppfx REQUIRED EXPORT)" in top level CMakeLists.txt.
hgreenlee Jun 29, 2023
6a70ca7
remove unnecessary include_directories
lgarren Jun 29, 2023
fed83f9
need lardata::Utilities
lgarren Jun 29, 2023
6610a32
use cet_build_plugin and cet_make_library
lgarren Jun 29, 2023
4b2a463
standard library name
lgarren Jun 29, 2023
a669da1
suggested improvements from Kyle
lgarren Jun 29, 2023
a057167
CMakeLists.txt format updates.
hgreenlee Jun 29, 2023
9591ac5
Merge remote-tracking branch 'lg/feature/team_for_greenlee_ppfx' into…
hgreenlee Jun 29, 2023
0ea5bb2
run code-format
lgarren Jun 29, 2023
32fe75a
Merge remote-tracking branch 'lg/feature/team_for_greenlee_ppfx' into…
hgreenlee Jun 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ find_package(nurandom REQUIRED EXPORT)
find_package(nusimdata REQUIRED EXPORT)
find_package(nutools REQUIRED EXPORT)

find_package(dk2nugenie REQUIRED EXPORT)
find_package(dk2nudata REQUIRED EXPORT)
find_package(ppfx REQUIRED EXPORT)

find_package(Boost REQUIRED COMPONENTS headers math_tr1 REQUIRED EXPORT) # boost::math::policies, boost::math::ellint*
find_package(CLHEP COMPONENTS Evaluator Geometry Random Vector REQUIRED EXPORT)
find_package(CRY REQUIRED EXPORT) # find module in nutools
Expand Down
1 change: 1 addition & 0 deletions larsim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ add_subdirectory(MergeSimSources)
add_subdirectory(SimFilters)
add_subdirectory(TriggerAlgo)
add_subdirectory(PhotonHitConverter)
add_subdirectory(PPFXFluxReader)
8 changes: 8 additions & 0 deletions larsim/EventGenerator/GENIE/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cet_build_plugin(GENIEGen art::EDProducer
LIBRARIES PRIVATE
larcore::Geometry_Geometry_service
lardata::Utilities
larcoreobj::SummaryData
lardataalg::MCDumpers
lardataobj::Simulation
Expand All @@ -14,6 +15,13 @@ cet_build_plugin(GENIEGen art::EDProducer
canvas::canvas
messagefacility::MF_MessageLogger
fhiclcpp::fhiclcpp
GENIE::GFwEG
GENIE::GFwAlg
GENIE::GFwMsg
GENIE::GFwGHEP
GENIE::GTlFlx
dk2nu::Genie
dk2nu::Tree
ROOT::Core
ROOT::EG
ROOT::Hist
Expand Down
50 changes: 50 additions & 0 deletions larsim/EventGenerator/GENIE/GENIEGen_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,23 @@
#include "larcore/Geometry/Geometry.h"
#include "larcoreobj/SummaryData/POTSummary.h"
#include "larcoreobj/SummaryData/RunData.h"
#include "lardata/Utilities/AssociationUtil.h"
#include "lardataalg/MCDumpers/MCDumpers.h" // sim::dump namespace
#include "lardataobj/Simulation/BeamGateInfo.h"
#include "nugen/EventGeneratorBase/GENIE/GENIEHelper.h"
#include "nusimdata/SimulationBase/GTruth.h"
#include "nusimdata/SimulationBase/MCFlux.h"
#include "nusimdata/SimulationBase/MCTruth.h"

// dk2nu extensions
#include "dk2nu/genie/GDk2NuFlux.h"
#include "dk2nu/tree/NuChoice.h"
#include "dk2nu/tree/dk2nu.h"

#include "GENIE/Framework/EventGen/EventRecord.h"
#include "nugen/EventGeneratorBase/GENIE/EVGBAssociationUtil.h"
#include "nugen/EventGeneratorBase/evgenbase.h"

///Event Generation using GENIE, cosmics or single particles
namespace evgen {
/**
Expand Down Expand Up @@ -166,6 +176,14 @@ namespace evgen {
produces<art::Assns<simb::MCTruth, simb::GTruth>>();
produces<std::vector<sim::BeamGateInfo>>();

// dk2nu additions
if (pset.get<std::string>("FluxType").find("dk2nu") != std::string::npos) {
produces<std::vector<bsim::Dk2Nu>>();
produces<std::vector<bsim::NuChoice>>();
produces<art::Assns<simb::MCTruth, bsim::Dk2Nu>>();
produces<art::Assns<simb::MCTruth, bsim::NuChoice>>();
}

std::string beam_type_name = pset.get<std::string>("BeamName");

if (beam_type_name == "numi")
Expand Down Expand Up @@ -374,6 +392,15 @@ namespace evgen {
std::unique_ptr<std::vector<sim::BeamGateInfo>> gateCollection(
new std::vector<sim::BeamGateInfo>);

std::unique_ptr<std::vector<bsim::Dk2Nu>> dk2nucol(new std::vector<bsim::Dk2Nu>);
std::unique_ptr<std::vector<bsim::NuChoice>> nuchoicecol(new std::vector<bsim::NuChoice>);
std::unique_ptr<art::Assns<simb::MCTruth, bsim::Dk2Nu>> dk2nuassn(
new art::Assns<simb::MCTruth, bsim::Dk2Nu>);
std::unique_ptr<art::Assns<simb::MCTruth, bsim::NuChoice>> nuchoiceassn(
new art::Assns<simb::MCTruth, bsim::NuChoice>);

genie::flux::GDk2NuFlux* dk2nuDriver =
dynamic_cast<genie::flux::GDk2NuFlux*>(fGENIEHelp->GetFluxDriver(true));
while (truthcol->size() < 1) {
while (!fGENIEHelp->Stop()) {

Expand All @@ -396,6 +423,21 @@ namespace evgen {

FillHistograms(truth);

if (dk2nuDriver) {
const bsim::Dk2Nu& dk2nuObj = dk2nuDriver->GetDk2Nu();
dk2nucol->push_back(dk2nuObj);
const bsim::NuChoice& nuchoiceObj = dk2nuDriver->GetNuChoice();
nuchoicecol->push_back(nuchoiceObj);
util::CreateAssn(
evt, *truthcol, *dk2nucol, *dk2nuassn, dk2nucol->size() - 1, dk2nucol->size());
util::CreateAssn(evt,
*truthcol,
*nuchoicecol,
*nuchoiceassn,
nuchoicecol->size() - 1,
nuchoicecol->size());
}

// check that the process code is not unsupported by GENIE
// (see issue #18025 for reference);
// if it is, print all the information we can about this truth record
Expand Down Expand Up @@ -439,6 +481,14 @@ namespace evgen {
evt.put(std::move(tgtassn));
evt.put(std::move(gateCollection));

// dk2nu additions
if (dk2nuDriver) {
evt.put(std::move(dk2nucol));
evt.put(std::move(nuchoicecol));
evt.put(std::move(dk2nuassn));
evt.put(std::move(nuchoiceassn));
}

return;
}

Expand Down
17 changes: 17 additions & 0 deletions larsim/EventWeight/Calculators/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@

cet_make_library(SOURCE GenieWeightCalc.cxx
PPFXCVWeightCalc.cxx
PPFXMIPPKaonWeightCalc.cxx
PPFXMIPPPionWeightCalc.cxx
PPFXOtherWeightCalc.cxx
PPFXTargAttenWeightCalc.cxx
PPFXThinKaonWeightCalc.cxx
PPFXThinMesonWeightCalc.cxx
PPFXThinNeutronPionWeightCalc.cxx
PPFXThinNucAWeightCalc.cxx
PPFXThinNucWeightCalc.cxx
PPFXThinPionWeightCalc.cxx
PPFXTotAbsorpWeightCalc.cxx
PPFXWeightCalc.cxx
LIBRARIES
PRIVATE
ppfx::ppfx
larsim::EventWeight_Base
nugen::EventGeneratorBase_GENIE
nusimdata::SimulationBase
Expand All @@ -9,6 +24,8 @@ cet_make_library(SOURCE GenieWeightCalc.cxx
fhiclcpp::fhiclcpp
cetlib_except::cetlib_except
${GENIE_LIB_LIST}
dk2nu::Tree
dk2nu::Genie
CLHEP::Random
log4cpp::log4cpp # FIXME Should be transitive from GENIE target(s).
)
Expand Down
166 changes: 166 additions & 0 deletions larsim/EventWeight/Calculators/PPFXCVWeightCalc.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@

#include "larsim/EventWeight/Base/WeightCalc.h"
#include "larsim/EventWeight/Base/WeightCalcCreator.h"

#include "CLHEP/Random/RandGaussQ.h"

#include "MakeReweight.h"
#include "cetlib/search_path.h"
#include "dk2nu/tree/dk2nu.h"
#include "dk2nu/tree/dkmeta.h"
#include "nugen/EventGeneratorBase/GENIE/MCTruthAndFriendsItr.h"

#include "TSystem.h"

namespace evwgh {
class PPFXCVWeightCalc : public WeightCalc {
public:
PPFXCVWeightCalc();
void Configure(fhicl::ParameterSet const& p, CLHEP::HepRandomEngine& engine) override;
std::vector<std::vector<double>> GetWeight(art::Event& e) override;

private:
std::string fGenieModuleLabel;

std::vector<std::string> fInputLabels;
std::string fPPFXMode;
std::string fMode;
std::string fHorn;
std::string fTarget;
int fSeed;
int fVerbose;
NeutrinoFluxReweight::MakeReweight* fPPFXrw;

DECLARE_WEIGHTCALC(PPFXCVWeightCalc)
};

PPFXCVWeightCalc::PPFXCVWeightCalc() {}

void PPFXCVWeightCalc::Configure(fhicl::ParameterSet const& p, CLHEP::HepRandomEngine& engine)
{
//get configuration for this function
fhicl::ParameterSet const& pset = p.get<fhicl::ParameterSet>(GetName());
fGenieModuleLabel = p.get<std::string>("genie_module_label");

//ppfx setup
fInputLabels = pset.get<std::vector<std::string>>("input_labels");
fPPFXMode = pset.get<std::string>("ppfx_mode");
fVerbose = pset.get<int>("verbose");
fMode = pset.get<std::string>("mode");
fHorn = pset.get<std::string>("horn_curr");
fTarget = pset.get<std::string>("target_config");
fSeed = pset.get<int>("random_seed", -1);

gSystem->Setenv("MODE", fPPFXMode.c_str());

fPPFXrw = NeutrinoFluxReweight::MakeReweight::getInstance();

std::string inputOptions; // Full path.
std::string mode_file = "inputs_" + fPPFXMode + ".xml"; // Just file name.
cet::search_path sp("FW_SEARCH_PATH");
sp.find_file(mode_file, inputOptions);

if (fSeed != -1) fPPFXrw->setBaseSeed(fSeed); // Set the random seed
std::cout << "is PPFX setup : " << fPPFXrw->AlreadyInitialized() << std::endl;
std::cout << "Setting PPFX, inputs: " << inputOptions << std::endl;
std::cout << "Setting Horn Current Configuration to: " << fHorn << std::endl;
std::cout << "Setting Target Configuration to: " << fTarget << std::endl;
if (!(fPPFXrw->AlreadyInitialized())) { fPPFXrw->SetOptions(inputOptions); }
std::cout << "PPFX just set with mode: " << fPPFXMode << std::endl;
}

std::vector<std::vector<double>> PPFXCVWeightCalc::GetWeight(art::Event& e)
{
std::vector<std::vector<double>> weight;
evgb::MCTruthAndFriendsItr mcitr(e, fInputLabels);
//calculate weight(s) here

int nmctruth = 0, nmatched = 0;
bool flag = true;
int ievt = -1;
std::vector<art::Handle<std::vector<bsim::Dk2Nu>>> dk2nus2 =
e.getMany<std::vector<bsim::Dk2Nu>>();
for (size_t dk2 = 0; dk2 < dk2nus2.size(); ++dk2) {
art::Handle<std::vector<bsim::Dk2Nu>> dk2nus = dk2nus2[dk2];
}
while ((flag = mcitr.Next())) {
std::string label = mcitr.GetLabel();
const simb::MCTruth* pmctruth = mcitr.GetMCTruth();
// const simb::GTruth* pgtruth = mcitr.GetGTruth();
//not-used//const simb::MCFlux* pmcflux = mcitr.GetMCFlux();
const bsim::Dk2Nu* pdk2nu = mcitr.GetDk2Nu();
//not-used//const bsim::NuChoice* pnuchoice = mcitr.GetNuChoice();
// art::Ptr<simb::MCTruth> mctruthptr = mcitr.GetMCTruthPtr();

++ievt;
++nmctruth;
if (fVerbose > 0) {
std::cout << "FluxWeightCalculator [" << std::setw(4) << ievt << "] "
<< " label \"" << label << "\" MCTruth@ " << pmctruth << " Dk2Nu@ " << pdk2nu
<< std::endl;
}
if (!pdk2nu) continue;
++nmatched;

//RWH//bsim::Dk2Nu* tmp_dk2nu = fTmpDK2NUConversorAlg.construct_toy_dk2nu( &mctruth,&mcflux);
//RWH//bsim::DkMeta* tmp_dkmeta = fTmpDK2NUConversorAlg.construct_toy_dkmeta(&mctruth,&mcflux);
//RWH// those appear to have been memory leaks
//RWH// herein begins the replacment for the "construct_toy_dkmeta"

static bsim::DkMeta
dkmeta_obj; //RWH// create this on stack (destroyed when out-of-scope) ... or static
dkmeta_obj.tgtcfg = fTarget;
dkmeta_obj.horncfg = fHorn;
(dkmeta_obj.vintnames).push_back("Index_Tar_In_Ancestry");
(dkmeta_obj.vintnames).push_back("Playlist");
bsim::DkMeta* tmp_dkmeta = &dkmeta_obj;
//RWH// herein ends this block

// sigh ....
//RWH// this is the signature in NeutrinoFluxReweight::MakeReweight :
// //! create an interaction chain from the new dk2nu(dkmeta) format
// void calculateWeights(bsim::Dk2Nu* nu, bsim::DkMeta* meta);
//RWH// these _should_ be "const <class>*" because we don't need to change them
//RWH// and the pointers we get out of the ART record are going to be const.
bsim::Dk2Nu* tmp_dk2nu = const_cast<bsim::Dk2Nu*>(pdk2nu); // remove const-ness
try {
fPPFXrw->calculateWeights(tmp_dk2nu, tmp_dkmeta);
}
catch (...) {
std::cerr << "Failed to calcualte weight" << std::endl;
continue;
}
//Get weights:
if (fMode == "reweight") {
double ppfx_cv_wgt = fPPFXrw->GetCVWeight();
std::vector<double> wvec = {ppfx_cv_wgt};
weight.push_back(wvec);
}
else {
std::vector<double> vmipppion = fPPFXrw->GetWeights("MIPPNumiPionYields");
std::vector<double> vmippkaon = fPPFXrw->GetWeights("MIPPNumiKaonYields");
std::vector<double> vtgtatt = fPPFXrw->GetWeights("TargetAttenuation");
std::vector<double> vabsorp = fPPFXrw->GetWeights("TotalAbsorption");
std::vector<double> vttpcpion = fPPFXrw->GetWeights("ThinTargetpCPion");
std::vector<double> vttpckaon = fPPFXrw->GetWeights("ThinTargetpCKaon");
std::vector<double> vttpcnucleon = fPPFXrw->GetWeights("ThinTargetpCNucleon");
std::vector<double> vttncpion = fPPFXrw->GetWeights("ThinTargetnCPion");
std::vector<double> vttnucleona = fPPFXrw->GetWeights("ThinTargetnucleonA");
std::vector<double> vttmesoninc = fPPFXrw->GetWeights("ThinTargetMesonIncident");
std::vector<double> vothers = fPPFXrw->GetWeights("Other");

std::vector<double> tmp_vhptot;
for (unsigned int iuniv = 0; iuniv < vtgtatt.size(); iuniv++) {
tmp_vhptot.push_back(float(vmipppion[iuniv] * vmippkaon[iuniv] * vtgtatt[iuniv] *
vabsorp[iuniv] * vttpcpion[iuniv] * vttpckaon[iuniv] *
vttpcnucleon[iuniv] * vttncpion[iuniv] * vttnucleona[iuniv] *
vttmesoninc[iuniv] * vothers[iuniv]));
}
weight.push_back(tmp_vhptot);
}
}

return weight;
}
REGISTER_WEIGHTCALC(PPFXCVWeightCalc)
}