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

Event library interface #103

Closed
wants to merge 68 commits into from
Closed
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
ffb9e8b
first commit of VMC skeleton
candreop Mar 9, 2020
10e0a01
Trivial build fixes
cjbacchus Mar 17, 2020
0e25754
Direct port of RecordList classes from novasoft.
cjbacchus Mar 17, 2020
e5ae0dd
Port in the body of the logic. Very unlikely to actually run correctl…
cjbacchus Mar 17, 2020
cbbff3f
Refactor a little
cjbacchus Mar 17, 2020
7872e3d
Add XML lines to be able to instantiate EventLibraryInterface
cjbacchus Mar 17, 2020
949f7f9
One more missing namespace
cjbacchus Mar 17, 2020
28ecd8e
Configuration that gets a little further.
cjbacchus Mar 17, 2020
23d1ba9
Configuration options and better error handling.
cjbacchus Mar 17, 2020
6ff6430
Generate random numbers in the correct way.
cjbacchus Mar 17, 2020
bc686ec
Use standard tools for neutrino name strings.
cjbacchus Mar 17, 2020
7e1a277
Another missing namespace waiting to bite us.
cjbacchus Mar 17, 2020
96c9596
Get rid of the hardcoded list of nuclei names.
cjbacchus Mar 17, 2020
f216aa7
An XML configuration that actually runs (if you also edit NNBarOscDum…
cjbacchus Mar 17, 2020
d3c22ae
Slightly more systematic directory naming.
cjbacchus Mar 17, 2020
708a232
Make the lazy loading even lazier for faster startup.
cjbacchus Mar 17, 2020
77ea624
Let's use a real xsec model so that it has splines and we don't have …
cjbacchus Mar 17, 2020
e3ada81
Satisfy picky XML parser
cjbacchus Mar 17, 2020
9dbf6d4
Use correct NC/CC information from the GHepRecord.
cjbacchus Mar 17, 2020
608e0d6
Sort out parent and child pointers.
cjbacchus Mar 17, 2020
7712c68
Add our own trivial InteractionListGenerator for library generation.
cjbacchus Mar 18, 2020
c6477a0
Add our own cross-section model too.
cjbacchus Mar 18, 2020
59f96e1
Now we control our own xsec model we can generate NC events as well.
cjbacchus Mar 18, 2020
77dd1ea
Update to format with all record lists in one library file.
cjbacchus Mar 30, 2020
faf780f
Allow skipping missing trees.
cjbacchus Mar 30, 2020
6cbbdd6
Automatically discover which nuclei are in the library file.
cjbacchus Mar 30, 2020
cf8726f
Factor out some pieces we'll need in a moment.
cjbacchus Mar 30, 2020
e9e211f
Load cross-sections from the library file.
cjbacchus Mar 30, 2020
456bae3
Add nutau.
cjbacchus Mar 31, 2020
78757cd
Adjust to a reorganization of the library files to more clearly refle…
cjbacchus Apr 14, 2020
1d3e6a3
We need to keep the record file open throughout the job, otherwise On…
cjbacchus Apr 24, 2020
fee6a25
Add REVIEW-tagged comments.
cjbacchus May 4, 2020
e22790f
Use GetParam() rather than GetParamDef() to take advantage of built-i…
cjbacchus May 11, 2020
52b3290
Update name of the parameter to EventLibraryPath.
cjbacchus May 11, 2020
ac43ad9
Add documentation to the config files.
cjbacchus May 11, 2020
f2c7c18
Prefix EvtLib to the various Record types.
cjbacchus May 11, 2020
afc92d4
Document Expand() function a little.
cjbacchus May 11, 2020
f06d3d3
Improve comments on the subject of NC = numu
cjbacchus May 11, 2020
897ec3d
Load xsecs in upfront, avoiding a "mutable".
cjbacchus May 11, 2020
b76e67b
Create RecordList objects up-front, removing more instances of mutable.
cjbacchus May 11, 2020
6fab4b4
Add a comment about the maximum number of particles limit.
cjbacchus May 11, 2020
8774a94
Add a comment about record sorting.
cjbacchus May 11, 2020
b1a65a9
Switch the namespace from genie::vmc to genie::evtlib
cjbacchus May 11, 2020
b1c2e52
Rename Tools/VMC/ directory to Tools/EvtLib/
cjbacchus May 11, 2020
c8f6d7e
One residual trace of "vmc" name.
cjbacchus May 11, 2020
1c35b70
Fill kinematic info.
cjbacchus May 11, 2020
064b64a
Include hit nucleon to satisfy gntpc.
cjbacchus May 11, 2020
af1f5ca
Switch cross-section units to /nucleus from /nucleon.
cjbacchus May 12, 2020
86d8b5a
Add and make use of a new scattering type for external generators.
cjbacchus May 12, 2020
773d92b
Use PDG code enumerations.
cjbacchus May 13, 2020
6d659d5
Fix strange capitalization caused by find/replace
cjbacchus May 13, 2020
ef6d278
Seperate evtlib configuration out into its own EX00_00a.
cjbacchus May 20, 2020
942e442
Put the whitespace back exactly as we found it.
cjbacchus May 20, 2020
6126c4a
Update comment.
cjbacchus May 20, 2020
a48d001
Add --enable-event-library configure switch (defaulted to false).
cjbacchus May 20, 2020
7382d1e
Redefinition of file path
mroda88 Nov 25, 2020
33d1e6d
Fix issue with daughter/mother relations
mroda88 Nov 26, 2020
1548067
Create dedicated CommonParam for EX00_00a
mroda88 Nov 26, 2020
06d9af0
Get Rid of hit nucleon
mroda88 Nov 26, 2020
d035946
Proper record visitor chain
mroda88 Nov 26, 2020
c6ae1cb
Add Proper rotations
mroda88 Nov 26, 2020
db8e590
temporary remove correction
mroda88 Nov 26, 2020
2a19ebc
Hopefully fix the problem where neutrino energy was zero in the EvtLi…
cjbacchus Nov 26, 2020
0be81c0
Added library generation macro scheleton
mroda88 Nov 27, 2020
ff28882
start writing the factory
mroda88 Nov 27, 2020
bebb7f0
Add an info about delta E
mroda88 Dec 1, 2020
20eae13
Change interaction flag for external generator
mroda88 Dec 1, 2020
9411909
Merge branch 'master' into ExtNuGen
mroda88 Dec 4, 2020
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
18 changes: 18 additions & 0 deletions Makefile
Expand Up @@ -31,6 +31,7 @@ INITIAL_BUILD_TARGETS = print-make-info \
physics-boosted-dark-matter \
tools-flux-drivers \
tools-geometry-drivers \
tools-vmc \
tools-masterclass
FINAL_BUILD_TARGETS = doxygen-doc \
apps \
Expand Down Expand Up @@ -202,6 +203,18 @@ else
@echo "** Building geometry-drivers was not enabled. Skipping..."
endif

tools-vmc: FORCE
cjbacchus marked this conversation as resolved.
Show resolved Hide resolved
#ifeq ($(strip $(GOPT_ENABLE_VMC)),YES)
@echo " "
@echo "** Building VMC..."
cd ${GENIE}/src/Tools/VMC && \
$(MAKE) && \
cd ${GENIE}
#else
# @echo " "
# @echo "** Building VMC was not enabled. Skipping..."
#endif


tools-masterclass: FORCE
ifeq ($(strip $(GOPT_ENABLE_MASTERCLASS)),YES)
Expand Down Expand Up @@ -368,6 +381,7 @@ make-install-dirs: FORCE
mkdir ${GENIE_INC_INSTALLATION_PATH}/Tools/Flux
mkdir ${GENIE_INC_INSTALLATION_PATH}/Tools/Geometry
mkdir ${GENIE_INC_INSTALLATION_PATH}/Tools/Masterclass
mkdir ${GENIE_INC_INSTALLATION_PATH}/Tools/VMC


copy-install-files: FORCE
Expand Down Expand Up @@ -424,6 +438,7 @@ copy-install-files: FORCE
cd ${GENIE}/src/Tools/Flux && $(MAKE) install && \
cd ${GENIE}/src/Tools/Geometry && $(MAKE) install && \
cd ${GENIE}/src/Tools/Masterclass && $(MAKE) install && \
cd ${GENIE}/src/Tools/VMC && $(MAKE) install && \
cd ${GENIE}


Expand Down Expand Up @@ -479,6 +494,7 @@ purge: FORCE
cd ${GENIE}/src/Tools/Flux && $(MAKE) purge && \
cd ${GENIE}/src/Tools/Geometry && $(MAKE) purge && \
cd ${GENIE}/src/Tools/Masterclass && $(MAKE) purge && \
cd ${GENIE}/src/Tools/VMC && $(MAKE) purge && \
cd ${GENIE}

clean: clean-files clean-dir clean-etc
Expand Down Expand Up @@ -535,6 +551,7 @@ clean-files: FORCE
cd ${GENIE}/src/Tools/Flux && $(MAKE) clean && \
cd ${GENIE}/src/Tools/Geometry && $(MAKE) clean && \
cd ${GENIE}/src/Tools/Masterclass && $(MAKE) clean && \
cd ${GENIE}/src/Tools/VMC && $(MAKE) clean && \
cd ${GENIE}/src/Apps && $(MAKE) clean && \
cd ${GENIE}/src/scripts && $(MAKE) clean && \
cd ${GENIE}
Expand Down Expand Up @@ -604,6 +621,7 @@ distclean: FORCE
cd ${GENIE}/src/Tools/Flux && $(MAKE) distclean && \
cd ${GENIE}/src/Tools/Geometry && $(MAKE) distclean && \
cd ${GENIE}/src/Tools/Masterclass && $(MAKE) distclean && \
cd ${GENIE}/src/Tools/VMC && $(MAKE) distclean && \
cd ${GENIE}/src/Apps && $(MAKE) distclean && \
cd ${GENIE}/src/scripts && $(MAKE) distclean && \
cd ${GENIE}
Expand Down
10 changes: 10 additions & 0 deletions config/EventGenerator.xml
Expand Up @@ -115,6 +115,16 @@ XSecModel alg Yes Cross section model used at the thread
</param_set>


<!--
VMC / EventLibraryInterface
-->
<param_set name="EventLibraryInterface">
<param type="string" name="VldContext"> </param>
<param type="int" name="NModules"> 1 </param>
Copy link
Member

Choose a reason for hiding this comment

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

We need a dedicated inital state appender or the flux driver will never work properly

<param type="alg" name="Module-0"> genie::vmc::EventLibraryInterface/Default </param>
<param type="alg" name="ILstGen"> genie::vmc::EvtLibInteractionListGenerator/Default </param>
</param_set>


<!--
Event generation for Smith-Moniz CCQE model
Expand Down
5 changes: 5 additions & 0 deletions config/EventGeneratorListAssembler.xml
Expand Up @@ -47,6 +47,11 @@ Generator-%d alg No

-->

<param_set name="EventLibraryInterface">
<param type="int" name="NGenerators"> 1 </param>
<param type="alg" name="Generator-0"> genie::EventGenerator/EventLibraryInterface </param>
</param_set>

<param_set name="AnomalyMediatedNuGamma">
<param type="int" name="NGenerators"> 1 </param>
<param type="alg" name="Generator-0"> genie::EventGenerator/AM-NUGAMMA </param>
Expand Down
8 changes: 8 additions & 0 deletions config/EventLibraryInterface.xml
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="ISO-8859-1"?>

<alg_conf>
<param_set name="Default">
<param type="string" name="LibraryPath"> Dummy.root </param>
cjbacchus marked this conversation as resolved.
Show resolved Hide resolved
<param type="bool" name="OnDemand"> true </param>
</param_set>
</alg_conf>
6 changes: 6 additions & 0 deletions config/EvtLibInteractionListGenerator.xml
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>

<alg_conf>
<param_set name="Default">
</param_set>
</alg_conf>
7 changes: 7 additions & 0 deletions config/EvtLibPXSec.xml
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="ISO-8859-1"?>

<alg_conf>
<param_set name="Default">
<param type="string" name="LibraryPath"> Dummy.root </param>
cjbacchus marked this conversation as resolved.
Show resolved Hide resolved
</param_set>
</alg_conf>
2 changes: 1 addition & 1 deletion config/G18_02a/ModelConfiguration.xml
Expand Up @@ -138,7 +138,7 @@ STFC, Rutherford Appleton Laboratory
<param type="alg" name="XSecModel@genie::EventGenerator/NucleonDecay"> genie::DummyPXSec/Default </param>
<param type="alg" name="XSecModel@genie::EventGenerator/NNBarOsc"> genie::NNBarOscDummyPXSec/Default </param>


<param type="alg" name="XSecModel@genie::EventGenerator/EventLibraryInterface"> genie::vmc::EvtLibPXSec/Default </param>
cjbacchus marked this conversation as resolved.
Show resolved Hide resolved
</param_set>


Expand Down
4 changes: 4 additions & 0 deletions config/master_config.xml
Expand Up @@ -208,4 +208,8 @@
<!-- ****** CONFIGURATION FOR REWEIGHT ALGORITHMS ****** -->
<config alg="genie::rew::GSystUncertaintyTable"> GSystUncertaintyTable.xml </config>

<!-- ****** VMC / EventLibraryInterface ****** -->
<config alg="genie::vmc::EventLibraryInterface"> EventLibraryInterface.xml </config>
<config alg="genie::vmc::EvtLibInteractionListGenerator"> EvtLibInteractionListGenerator.xml </config>
<config alg="genie::vmc::EvtLibPXSec"> EvtLibPXSec.xml </config>
</genie_config>
261 changes: 261 additions & 0 deletions src/Tools/VMC/EventLibraryInterface.cxx
@@ -0,0 +1,261 @@
//____________________________________________________________________________
/*
Copyright (c) 2003-2020, The GENIE Collaboration
For the full text of the license visit http://copyright.genie-mc.org


*/
//____________________________________________________________________________

#include "Framework/Messenger/Messenger.h"
#include "Framework/Numerical/RandomGen.h"
#include "Framework/GHEP/GHepRecord.h"
#include "Framework/GHEP/GHepParticle.h"
#include "Framework/ParticleData/PDGUtils.h"
#include "Framework/ParticleData/PDGLibrary.h"
#include "Framework/Interaction/Interaction.h"
#include "Tools/VMC/EventLibraryInterface.h"
#include "Tools/VMC/RecordList.h"
#include "Tools/VMC/Utils.h"

#include "TFile.h"

using namespace genie;
using namespace genie::vmc;

//____________________________________________________________________________
EventLibraryInterface::EventLibraryInterface() :
EventRecordVisitorI("genie::vmc::EventLibraryInterface"),
fRecordFile(0)
{

}
//____________________________________________________________________________
EventLibraryInterface::EventLibraryInterface(string config) :
EventRecordVisitorI("genie::vmc::EventLibraryInterface", config),
fRecordFile(0)
{

}
//____________________________________________________________________________
EventLibraryInterface::~EventLibraryInterface()
{
for(auto it: fRecords) delete it.second;
delete fRecordFile;
}
//____________________________________________________________________________
void EventLibraryInterface::ProcessEventRecord(GHepRecord * event) const
{
// Get event summary constructed by GENIE
//
Interaction* interaction = event->Summary();
const InitialState & init_state = interaction->InitState();

const Record* rec = GetRecord(interaction);
cjbacchus marked this conversation as resolved.
Show resolved Hide resolved
if(!rec) return; // Reason has already been printed

std::unique_ptr<TLorentzVector> probe_p4(init_state.GetProbeP4(kRfLab));
Copy link
Member

Choose a reason for hiding this comment

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

This is not ok if we want to release it in v 3.2, otherwise it will be ok

Copy link
Author

Choose a reason for hiding this comment

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

I had no idea genie was compatible with such ancient standards. I take it the plan is to drop that requirement soon?

Copy link
Author

Choose a reason for hiding this comment

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

How do I set my built up to use C++98? There look to be a lot of places and I'm likely to miss one.

Alternately -- is it possible to have this component optional, and require a higher compiler version if it's enabled? I don't think any potential users are on anything like so old a standard.


unsigned int nLep = 0;
for(const Particle& part: rec->parts) if(pdg::IsLepton(part.pdg)) ++nLep;
Copy link
Member

Choose a reason for hiding this comment

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

same here: not C++98


const int firstLep = (nLep == 0) ? -1 : 2;
const int lastLep = (nLep == 0) ? -1 : 1+nLep;

const int firstHad = (rec->parts.size() == nLep) ? -1 : 2+nLep;
const int lastHad = (rec->parts.size() == nLep) ? -1 : 1+rec->parts.size();

// Neutrino is a parent to the lepton(s)
event->AddParticle(init_state.ProbePdg(),
kIStInitialState,
-1, -1, firstLep, lastLep,
*probe_p4,
TLorentzVector(0, 0, 0, 0));

const int tgt_A = init_state.Tgt().A();
const int tgt_Z = init_state.Tgt().Z();
const int tgt_pdgc = pdg::IonPdgCode(tgt_A, tgt_Z);
// REVIEW: it was like this in Costas' example code. Can it just be
// init_state.TgtPdg()?

LOG("ELI", pINFO)
<< "Adding nucleus [A = " << tgt_A << ", Z = " << tgt_Z
<< ", pdg = " << tgt_pdgc << "]";

// Nucleus is a parent to everything else
event->AddParticle(tgt_pdgc,
kIStInitialState,
-1, -1, firstHad, lastHad,
0, 0, 0, PDGLibrary::Instance()->Find(tgt_pdgc)->Mass(),
0, 0, 0, 0);

const std::vector<TVector3> basis = Basis(probe_p4->Vect());

for(bool lep: {true, false}){ // make sure lepton in first
for(const Particle& part: rec->parts){
if(lep != pdg::IsLepton(part.pdg)) continue;

// Fix up the outgoing lepton for NC events (in the library it's always
// nu_mu...)
int pdg = part.pdg;
if(interaction->ProcInfo().IsWeakNC()) pdg = init_state.ProbePdg();

event->AddParticle(pdg,
kIStStableFinalState,
(lep ? 0 : 1), -1, -1, -1, // child of the neutrino or nucleus
TLorentzVector(part.px*basis[0] +
part.py*basis[1] +
part.pz*basis[2],
part.E),
TLorentzVector(0, 0, 0, 0));
}
}
}

//____________________________________________________________________________
const Record* EventLibraryInterface::GetRecord(const Interaction* interaction) const
{
if(fRecords.empty()) LoadRecords();

const InitialState& init_state = interaction->InitState();

const double probe_E = init_state.ProbeE(kRfLab);

if(!init_state.Tgt().IsNucleus()){
LOG("ELI", pINFO) << "Skippping non-nuclear target " << init_state;
return 0;
}

const int tgt_pdgc = init_state.TgtPdg();

const ProcessInfo& proc = interaction->ProcInfo();

if(!proc.IsWeakCC() && !proc.IsWeakNC()){
LOG("ELI", pINFO) << "Skipping unknown process " << proc;
return 0;
}

int probe_pdgc = init_state.ProbePdg();

// Use nu_mu for NC by convention
if(proc.IsWeakNC()){
cjbacchus marked this conversation as resolved.
Show resolved Hide resolved
if(probe_pdgc > 0) probe_pdgc = +14; else probe_pdgc = -14;
}

const Key key(tgt_pdgc, probe_pdgc, proc.IsWeakCC());

const auto rec_it = fRecords.find(key);

if(rec_it == fRecords.end()){
LOG("ELI", pINFO) << "Skippping " << key << " -- not found in library";
return 0;
}

const Record* rec = rec_it->second->GetRecord(probe_E);

if(!rec){
LOG("ELI", pINFO) << "Skippping " << key << " at " << probe_E << " GeV -- not found in library";
return 0;
}

return rec;
}

//____________________________________________________________________________
std::vector<TVector3> EventLibraryInterface::Basis(const TVector3& z) const
{
TVector3 up(0, 1, 0);
if(up.Dot(z) == 0) up = TVector3(1, 0, 0);

const TVector3 x = up.Cross(z).Unit(); // Perpendicular to neutrino and up
const TVector3 y = x.Cross(z).Unit(); // Defines the third axis

const double a = RandomGen::Instance()->RndEvg().Uniform(0, 2*M_PI);

const TVector3 xp = cos(a) * x + sin(a) * y;
const TVector3 yp = -sin(a) * x + cos(a) * y;
const TVector3 zp = z.Unit();

return {xp, yp, zp};
}

//____________________________________________________________________________
void EventLibraryInterface::Configure(const Registry & config)
{
Algorithm::Configure(config);
}
//___________________________________________________________________________
void EventLibraryInterface::Configure(string config)
{
Algorithm::Configure(config);
}

//___________________________________________________________________________
void EventLibraryInterface::LoadRecords() const
{
assert(!fRecordFile);

std::string libPath;
if(!GetParamDef( "LibraryPath", libPath, std::string() )){
LOG("ELI", pFATAL) << "Must specify 'LibraryPath'";
exit(1);
}

Expand(libPath);

bool onDemand;
GetParamDef( "OnDemand", onDemand, true );

PDGLibrary* pdglib = PDGLibrary::Instance();

fRecordFile = new TFile(libPath.c_str());
if(fRecordFile->IsZombie()) exit(1);

TIter next(fRecordFile->GetListOfKeys());
while(TObject* dir = next()){
const std::string& tgtName = dir->GetName();
const TParticlePDG* tgtPart = pdglib->DBase()->GetParticle(tgtName.c_str());
if(!tgtPart){
LOG("ELI", pWARN) << "Unknown nucleus " << tgtName
<< " found in " << libPath
<< " -- skipping";
continue;
}

for(int sign: {+1, -1}){
cjbacchus marked this conversation as resolved.
Show resolved Hide resolved
for(int pdg: {12, 14, 16}){
for(bool iscc: {true, false}){
// NCs should be the same for all flavours. Use numu by convention.
if(!iscc && pdg != 14) continue;

std::string nuName = pdglib->Find(sign*pdg)->GetName();
if(!iscc) nuName = (sign > 0) ? "nu" : "nu_bar";

const std::string treeName =
TString::Format("%s/%s/%s/records",
tgtName.c_str(),
iscc ? "cc" : "nc",
nuName.c_str()).Data();

const Key key(tgtPart->PdgCode(), sign*pdg, iscc);

TTree* tr = (TTree*)fRecordFile->Get(treeName.c_str());

if(!tr){
LOG("ELI", pINFO) << treeName << " not found in "
<< libPath << " -- skipping";
continue;
}

if(onDemand)
fRecords[key] = new OnDemandRecordList(tr, treeName);
else
fRecords[key] = new SimpleRecordList(tr, treeName);
} // end for nucleus
} // end for pdg
} // end for sign
} // end for iscc

// Need to keep the record file open for OnDemand, but not Simple
if(!onDemand){delete fRecordFile; fRecordFile = 0;}
}