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

Wketchum/genie generator hep mc3 refactor #1488

Open
wants to merge 19 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
480427d
transfer over of GenieGenerator
wesketchum May 15, 2024
11f36ec
remove genie reweight libraries for now
wesketchum May 15, 2024
6d827eb
Merge branch 'trunk' of github.com:LDMX-Software/ldmx-sw into wketchu…
wesketchum Jul 16, 2024
7a54c71
transfer from wketchum/Genie_Generator_HepMC3Refactor branch in stand…
wesketchum Jul 17, 2024
4feda33
reenable GENIE Reweight libraries
wesketchum Jul 17, 2024
5d4039c
fix the linking orders, and get the reweight producer to be working
wesketchum Jul 18, 2024
b2761b3
updates to put the GENIE tune information into the run header, and ex…
wesketchum Jul 19, 2024
1e085f2
flesh out the genie reweighting to take in FSI calculators
wesketchum Jul 22, 2024
3a77fe3
add in a string writer so we can more easily transfer back and forth …
wesketchum Jul 25, 2024
1c02367
add a GENIE truth DQM
wesketchum Aug 1, 2024
4665e26
fix some typos, and decrease verbosity
wesketchum Sep 12, 2024
bb27efd
Merge branch 'trunk' of github.com:LDMX-Software/ldmx-sw into wketchu…
wesketchum Sep 12, 2024
f774c91
Merge branch 'trunk' of github.com:LDMX-Software/ldmx-sw into wketchu…
wesketchum Oct 8, 2024
6a062cc
Apply clang-format
github-actions[bot] Oct 16, 2024
cbc689a
Merge remote-tracking branch 'origin/wketchum/Genie_Generator_HepMC3R…
wesketchum Oct 22, 2024
d5757c0
cleanup some compile warnings and fix failing Hcal and Run_SimCore_ba…
wesketchum Oct 22, 2024
d0b995e
Apply clang-format
github-actions[bot] Oct 22, 2024
b28a6ed
Merge branch 'trunk' into wketchum/Genie_Generator_HepMC3Refactor
wesketchum Mar 11, 2025
c4230c5
update to pythia8 / remove pythia6
wesketchum Mar 11, 2025
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
57 changes: 57 additions & 0 deletions DQM/include/DQM/GenieTruthDQM.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Created by Wesley Ketchum on 8/1/24.
//

#ifndef DQM_GENIETRUTH_H
#define DQM_GENIETRUTH_H

// LDMX Framework
#include "Framework/Configure/Parameters.h" // Needed to import parameters from configuration file
#include "Framework/EventProcessor.h" //Needed to declare processor

namespace dqm {

/**
* @class GenieTruthDQM
* @brief Generate histograms/ntuple to extract genie output info
*/
class GenieTruthDQM : public framework::Analyzer {
public:
/**
* Constructor
*
* Blank Analyzer constructor
*/
GenieTruthDQM(const std::string& name, framework::Process& process)
: framework::Analyzer(name, process) {}

/**
* Input python configuration parameters
*/
virtual void configure(framework::config::Parameters& ps);

/**
* Construct histograms/ntuples
*/
virtual void onProcessStart();

/**
* Grab the run number...
*/
virtual void onNewRun(const ldmx::RunHeader& runHeader);

/**
* Fills histograms/ntuples
*/
virtual void analyze(const framework::Event& event);

private:
/// Pass Name for genie objects
std::string hepmc3CollName_;
std::string hepmc3PassName_;

int run_number_;
};
} // namespace dqm

#endif // DQM_GENIETRUTH_H
19 changes: 18 additions & 1 deletion DQM/python/dqm.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,24 @@ def __init__(self, name='SampleValidation') :
# daughters of hard brem histograms
self.build1DHistogram("pdgid_hardbremdaughters", "ID of hard brem daughters", 20, 0, 20)
self.build1DHistogram("startZ_hardbremdaughters", "Start z position of hard brem daughters [mm]", 200, -1000, 1000)


class GenieTruthDQM(ldmxcfg.Analyzer) :
"""Configured GenieTruthDQM python object

Contains an instance of GenieTruthDQM that
has already been configured.

Examples
--------
from LDMX.DQM import dqm
p.sequence.append( dqm.GenieTruthDQM() )
"""

def __init__(self,name='GenieTruthDQM',coll_name="",pass_name="") :
super().__init__(name,'dqm::GenieTruthDQM','DQM')

self.hepmc3CollName = coll_name
self.hepmc3PassName = pass_name

ecal_dqm = [
EcalDigiVerify(),
Expand Down
203 changes: 203 additions & 0 deletions DQM/src/DQM/GenieTruthDQM.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
//
// Created by Wesley Ketchum on 8/1/24.
//

#include "DQM/GenieTruthDQM.h"

#include <iostream>

#include "GENIE/Framework/Conventions/KineVar.h"
#include "SimCore/Event/HepMC3GenEvent.h"

namespace dqm {

void GenieTruthDQM::configure(framework::config::Parameters& ps) {
hepmc3CollName_ = ps.getParameter<std::string>("hepmc3CollName");
hepmc3PassName_ = ps.getParameter<std::string>("hepmc3PassName");
return;
}

void GenieTruthDQM::onProcessStart() {
getHistoDirectory();

ntuple_.create("genie_truth");

// event info
ntuple_.addVar<int>("genie_truth", "run");
ntuple_.addVar<int>("genie_truth", "event");

ntuple_.addVar<int>("genie_truth", "interaction_type");
ntuple_.addVar<int>("genie_truth", "scattering_type");
ntuple_.addVar<int>("genie_truth", "rescatter_code");

ntuple_.addVar<double>("genie_truth", "x_bj");
ntuple_.addVar<double>("genie_truth", "y_inel");
ntuple_.addVar<double>("genie_truth", "Q2");
ntuple_.addVar<double>("genie_truth", "W");

ntuple_.addVar<int>("genie_truth", "lep_pdg");

ntuple_.addVar<double>("genie_truth", "lep_i_px");
ntuple_.addVar<double>("genie_truth", "lep_i_py");
ntuple_.addVar<double>("genie_truth", "lep_i_pz");
ntuple_.addVar<double>("genie_truth", "lep_i_e");

ntuple_.addVar<double>("genie_truth", "lep_f_px");
ntuple_.addVar<double>("genie_truth", "lep_f_py");
ntuple_.addVar<double>("genie_truth", "lep_f_pz");
ntuple_.addVar<double>("genie_truth", "lep_f_e");

ntuple_.addVar<int>("genie_truth", "tgt_pdg");
ntuple_.addVar<double>("genie_truth", "tgt_px");
ntuple_.addVar<double>("genie_truth", "tgt_py");
ntuple_.addVar<double>("genie_truth", "tgt_pz");
ntuple_.addVar<double>("genie_truth", "tgt_e");

ntuple_.addVar<int>("genie_truth", "hnuc_pdg");
ntuple_.addVar<double>("genie_truth", "hnuc_px");
ntuple_.addVar<double>("genie_truth", "hnuc_py");
ntuple_.addVar<double>("genie_truth", "hnuc_pz");
ntuple_.addVar<double>("genie_truth", "hnuc_e");

ntuple_.addVar<int>("genie_truth", "hqrk_pdg");
ntuple_.addVar<int>("genie_truth", "hqrk_sea");
ntuple_.addVar<double>("genie_truth", "hadsys_px");
ntuple_.addVar<double>("genie_truth", "hadsys_py");
ntuple_.addVar<double>("genie_truth", "hadsys_pz");
ntuple_.addVar<double>("genie_truth", "hadsys_e");
}

void GenieTruthDQM::onNewRun(const ldmx::RunHeader& runHeader) {
run_number_ = runHeader.getRunNumber();
}

void GenieTruthDQM::analyze(const framework::Event& event) {
getHistoDirectory();

ntuple_.clear();
ntuple_.setVar<int>("run", run_number_);
ntuple_.setVar<int>("event", event.getEventNumber());

auto hepmc3_col = event.getObject<std::vector<ldmx::HepMC3GenEvent> >(
hepmc3CollName_, hepmc3PassName_);

if (hepmc3_col.size() < 1) {
ntuple_.fill();
return;
}

auto const& hepmc3_ev = hepmc3_col.at(0).getHepMCGenEvent();

// set interaction/scattering codes
auto interaction_type_ptr = hepmc3_ev.attribute<HepMC3::IntAttribute>(
"GENIE.Interaction.InteractionType");
if (interaction_type_ptr)
ntuple_.setVar<int>("interaction_type", interaction_type_ptr->value());
auto scattering_type_ptr = hepmc3_ev.attribute<HepMC3::IntAttribute>(
"GENIE.Interaction.ScatteringType");
if (scattering_type_ptr)
ntuple_.setVar<int>("scattering_type", scattering_type_ptr->value());
auto rescatter_code_ptr =
hepmc3_ev.attribute<HepMC3::IntAttribute>("GENIE.RescatterCode");
if (rescatter_code_ptr)
ntuple_.setVar<int>("rescatter_code", scattering_type_ptr->value());

// get kinematic vars
auto kvar_labels_ptr = hepmc3_ev.attribute<HepMC3::VectorIntAttribute>(
"GENIE.Interaction.KineVarLabels");
auto kvar_values_ptr = hepmc3_ev.attribute<HepMC3::VectorDoubleAttribute>(
"GENIE.Interaction.KineVarValues");
if (kvar_labels_ptr && kvar_values_ptr) {
auto kvar_labels = kvar_labels_ptr->value();
auto kvar_values = kvar_values_ptr->value();
for (size_t i = 0; i < kvar_labels.size(); ++i) {
if (kvar_labels[i] == genie::EKineVar::kKVSelx)
ntuple_.setVar<double>("x_bj", kvar_values[i]);
else if (kvar_labels[i] == genie::EKineVar::kKVSely)
ntuple_.setVar<double>("y_inel", kvar_values[i]);
else if (kvar_labels[i] == genie::EKineVar::kKVSelQ2)
ntuple_.setVar<double>("Q2", kvar_values[i]);
else if (kvar_labels[i] == genie::EKineVar::kKVSelW)
ntuple_.setVar<double>("W", kvar_values[i]);
}
}

// electron info
auto lep_pdg_ptr =
hepmc3_ev.attribute<HepMC3::IntAttribute>("GENIE.Interaction.ProbePDG");
if (lep_pdg_ptr) ntuple_.setVar<int>("lep_pdg", lep_pdg_ptr->value());

auto lep_i_4vec_ptr = hepmc3_ev.attribute<HepMC3::VectorDoubleAttribute>(
"GENIE.Interaction.ProbeP4");
if (lep_i_4vec_ptr) {
auto lep_i_4vec = lep_i_4vec_ptr->value();
ntuple_.setVar<double>("lep_i_px", lep_i_4vec[0]);
ntuple_.setVar<double>("lep_i_py", lep_i_4vec[1]);
ntuple_.setVar<double>("lep_i_pz", lep_i_4vec[2]);
ntuple_.setVar<double>("lep_i_e", lep_i_4vec[3]);
}
auto lep_f_4vec_ptr = hepmc3_ev.attribute<HepMC3::VectorDoubleAttribute>(
"GENIE.Interaction.FSLeptonP4");
if (lep_f_4vec_ptr) {
auto lep_f_4vec = lep_f_4vec_ptr->value();
ntuple_.setVar<double>("lep_f_px", lep_f_4vec[0]);
ntuple_.setVar<double>("lep_f_py", lep_f_4vec[1]);
ntuple_.setVar<double>("lep_f_pz", lep_f_4vec[2]);
ntuple_.setVar<double>("lep_f_e", lep_f_4vec[3]);
}

// target info
auto tgt_pdg_ptr =
hepmc3_ev.attribute<HepMC3::IntAttribute>("GENIE.Interaction.TargetPDG");
if (tgt_pdg_ptr) ntuple_.setVar<int>("tgt_pdg", tgt_pdg_ptr->value());

auto tgt_4vec_ptr = hepmc3_ev.attribute<HepMC3::VectorDoubleAttribute>(
"GENIE.Interaction.TargetP4");
if (tgt_4vec_ptr) {
auto tgt_4vec = tgt_4vec_ptr->value();
ntuple_.setVar<double>("tgt_px", tgt_4vec[0]);
ntuple_.setVar<double>("tgt_py", tgt_4vec[1]);
ntuple_.setVar<double>("tgt_pz", tgt_4vec[2]);
ntuple_.setVar<double>("tgt_e", tgt_4vec[3]);
}

// hit nucleon info
auto hnuc_pdg_ptr = hepmc3_ev.attribute<HepMC3::IntAttribute>(
"GENIE.Interaction.HitNucleonPDG");
if (hnuc_pdg_ptr) ntuple_.setVar<int>("hnuc_pdg", hnuc_pdg_ptr->value());

auto hitnuc_4vec_ptr = hepmc3_ev.attribute<HepMC3::VectorDoubleAttribute>(
"GENIE.Interaction.HitNucleonP4");
if (hitnuc_4vec_ptr) {
auto hitnuc_4vec = hitnuc_4vec_ptr->value();
ntuple_.setVar<double>("hnuc_px", hitnuc_4vec[0]);
ntuple_.setVar<double>("hnuc_py", hitnuc_4vec[1]);
ntuple_.setVar<double>("hnuc_pz", hitnuc_4vec[2]);
ntuple_.setVar<double>("hnuc_e", hitnuc_4vec[3]);
}
// hit quark info
// note: it's only there for some interaction types!
auto hqrkpdg_ptr = hepmc3_ev.attribute<HepMC3::IntAttribute>(
"GENIE.Interaction.HitQuarkPDG");
if (hqrkpdg_ptr) ntuple_.setVar<int>("hqrk_pdg", hqrkpdg_ptr->value());
auto hqrksea_ptr = hepmc3_ev.attribute<HepMC3::IntAttribute>(
"GENIE.Interaction.HitSeaQuark");
if (hqrksea_ptr) ntuple_.setVar<int>("hqrk_sea", hqrkpdg_ptr->value());

auto hadsys_4vec_ptr = hepmc3_ev.attribute<HepMC3::VectorDoubleAttribute>(
"GENIE.Interaction.HadSystP4");
if (hadsys_4vec_ptr) {
auto hadsys_4vec = hadsys_4vec_ptr->value();
ntuple_.setVar<double>("hadsys_px", hadsys_4vec[0]);
ntuple_.setVar<double>("hadsys_py", hadsys_4vec[1]);
ntuple_.setVar<double>("hadsys_pz", hadsys_4vec[2]);
ntuple_.setVar<double>("hadsys_e", hadsys_4vec[3]);
}
ntuple_.fill();

return;
}

} // namespace dqm

DECLARE_ANALYZER_NS(dqm, GenieTruthDQM);
27 changes: 24 additions & 3 deletions SimCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,30 @@ find_package(ROOT CONFIG REQUIRED)
find_package(Boost REQUIRED
COMPONENTS log)

include_directories( /usr/local/include/GENIE )

option(BUILD_EVENT_ONLY "Build the event library." ON)
if(BUILD_EVENT_ONLY)

install(FILES /usr/local/lib/libHepMC3rootIO_rdict.pcm DESTINATION lib)

register_event_object(module_path "SimCore/Event" namespace "ldmx"
class "SimCalorimeterHit" type "collection")
register_event_object(module_path "SimCore/Event" namespace "ldmx"
class "SimTrackerHit" type "collection")
register_event_object(module_path "SimCore/Event" namespace "ldmx"
class "SimParticle" type "map" key "int")
register_event_object(module_path "SimCore/Event" namespace "ldmx"
class "EventWeights")

register_event_object(module_path "SimCore/Event" namespace "ldmx"
class "HepMC3GenEvent" type "collection")

# Generate the files needed to build the event classes.
setup_library(module SimCore name Event
dependencies ROOT::Core
register_target)
dependencies ROOT::Core ${GENIE_LIBS} HepMC3 HepMC3rootIO
register_target
include )

return()

Expand All @@ -37,6 +47,9 @@ endif()
# Configure Geant4
setup_geant4_target()

#Configure Genie
setup_genie_target()

# include dark brem simulation
add_subdirectory(G4DarkBreM)

Expand Down Expand Up @@ -64,12 +77,15 @@ file(GLOB SRC_FILES CONFIGURE_DEPDENDS ${PROJECT_SOURCE_DIR}/src/SimCore/Geo/[a-
setup_library(module SimCore
dependencies Geant4::Interface
ROOT::Physics
ROOT::MathMore
HepMC3
Framework::Configure
Framework::Framework
SimCore::G4User
G4DarkBreM
DetDescr::DetDescr
Boost::log
log4cpp
"${registered_targets}"
sources ${SRC_FILES})

Expand All @@ -81,7 +97,12 @@ setup_library(module SimCore
# Primary Generators library
setup_library(module SimCore
name Generators
dependencies SimCore::SimCore SimCore::LHE)
dependencies SimCore::SimCore SimCore::LHE SimCore::Event ${GENIE_LIBS} HepMC3)

# Reweight Library
setup_library(module SimCore
name Reweight
dependencies SimCore::SimCore SimCore::Generators SimCore::Event Framework::Framework ${GENIE_LIBS} HepMC3)

# Sensitive Detectors library
setup_library(module SimCore
Expand Down
Loading
Loading