GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
genie::evtlib::EventLibraryInterface Class Reference

Reads pre-generated events produced by an external generator. On an event-by-event basis, it can accept GENIE input specifying the neutrino and target IDs and neutrino energy and, therefore, it can re-use the upstream GENIE flux and geometry tools. More...

#include <EventLibraryInterface.h>

Inheritance diagram for genie::evtlib::EventLibraryInterface:
Inheritance graph
[legend]
Collaboration diagram for genie::evtlib::EventLibraryInterface:
Collaboration graph
[legend]

Public Member Functions

 EventLibraryInterface ()
 
 EventLibraryInterface (string config)
 
 ~EventLibraryInterface ()
 
void ProcessEventRecord (GHepRecord *event) const override
 
void Configure (const Registry &config) override
 
void Configure (string config) override
 
- Public Member Functions inherited from genie::EventRecordVisitorI
virtual ~EventRecordVisitorI ()
 
- Public Member Functions inherited from genie::Algorithm
virtual ~Algorithm ()
 
virtual void FindConfig (void)
 
virtual const RegistryGetConfig (void) const
 
RegistryGetOwnedConfig (void)
 
virtual const AlgIdId (void) const
 Get algorithm ID. More...
 
virtual AlgStatus_t GetStatus (void) const
 Get algorithm status. More...
 
virtual bool AllowReconfig (void) const
 
virtual AlgCmp_t Compare (const Algorithm *alg) const
 Compare with input algorithm. More...
 
virtual void SetId (const AlgId &id)
 Set algorithm ID. More...
 
virtual void SetId (string name, string config)
 
const AlgorithmSubAlg (const RgKey &registry_key) const
 
void AdoptConfig (void)
 
void AdoptSubstructure (void)
 
virtual void Print (ostream &stream) const
 Print algorithm info. More...
 

Protected Member Functions

const EvtLibRecordGetRecord (const Interaction *interaction) const
 
void LoadRecords ()
 
void Cleanup ()
 
void FillKinematics (const GHepRecord &, genie::Kinematics &kine, int primary_lep_id) const
 
- Protected Member Functions inherited from genie::EventRecordVisitorI
 EventRecordVisitorI ()
 
 EventRecordVisitorI (string name)
 
 EventRecordVisitorI (string name, string config)
 
- Protected Member Functions inherited from genie::Algorithm
 Algorithm ()
 
 Algorithm (string name)
 
 Algorithm (string name, string config)
 
void Initialize (void)
 
void DeleteConfig (void)
 
void DeleteSubstructure (void)
 
RegistryExtractLocalConfig (const Registry &in) const
 
RegistryExtractLowerConfig (const Registry &in, const string &alg_key) const
 Split an incoming configuration Registry into a block valid for the sub-algo identified by alg_key. More...
 
template<class T >
bool GetParam (const RgKey &name, T &p, bool is_top_call=true) const
 
template<class T >
bool GetParamDef (const RgKey &name, T &p, const T &def) const
 
template<class T >
int GetParamVect (const std::string &comm_name, std::vector< T > &v, bool is_top_call=true) const
 Handle to load vectors of parameters. More...
 
int GetParamVectKeys (const std::string &comm_name, std::vector< RgKey > &k, bool is_top_call=true) const
 
template<class T >
int GetParamMat (const std::string &comm_name, TMatrixT< T > &mat, bool is_top_call=true) const
 Handle to load matrix of parameters. More...
 
template<class T >
int GetParamMatSym (const std::string &comm_name, TMatrixTSym< T > &mat, bool is_top_call=true) const
 
int GetParamMatKeys (const std::string &comm_name, std::vector< RgKey > &k, bool is_top_call=true) const
 
int AddTopRegistry (Registry *rp, bool owns=true)
 add registry with top priority, also update ownership More...
 
int AddLowRegistry (Registry *rp, bool owns=true)
 add registry with lowest priority, also update ownership More...
 
int MergeTopRegistry (const Registry &r)
 
int AddTopRegisties (const vector< Registry * > &rs, bool owns=false)
 Add registries with top priority, also udated Ownerships. More...
 

Private Attributes

std::map< Key, const
IEvtLibRecordList * > 
fRecords
 
TFile * fRecordFile
 

Additional Inherited Members

- Static Public Member Functions inherited from genie::Algorithm
static string BuildParamVectKey (const std::string &comm_name, unsigned int i)
 
static string BuildParamVectSizeKey (const std::string &comm_name)
 
static string BuildParamMatKey (const std::string &comm_name, unsigned int i, unsigned int j)
 
static string BuildParamMatRowSizeKey (const std::string &comm_name)
 
static string BuildParamMatColSizeKey (const std::string &comm_name)
 
- Protected Attributes inherited from genie::Algorithm
bool fAllowReconfig
 
bool fOwnsSubstruc
 true if it owns its substructure (sub-algs,...) More...
 
AlgId fID
 algorithm name and configuration set More...
 
vector< Registry * > fConfVect
 
vector< bool > fOwnerships
 ownership for every registry in fConfVect More...
 
AlgStatus_t fStatus
 algorithm execution status More...
 
AlgMapfOwnedSubAlgMp
 local pool for owned sub-algs (taken out of the factory pool) More...
 

Detailed Description

Reads pre-generated events produced by an external generator. On an event-by-event basis, it can accept GENIE input specifying the neutrino and target IDs and neutrino energy and, therefore, it can re-use the upstream GENIE flux and geometry tools.

Author
Created:
February 28, 2020
License:
Copyright (c) 2003-2024, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 43 of file EventLibraryInterface.h.

Constructor & Destructor Documentation

EventLibraryInterface::EventLibraryInterface ( )

Definition at line 29 of file EventLibraryInterface.cxx.

29  :
30  EventRecordVisitorI("genie::evtlib::EventLibraryInterface"),
31  fRecordFile(0)
32 {
33 
34 }
EventLibraryInterface::EventLibraryInterface ( string  config)

Definition at line 37 of file EventLibraryInterface.cxx.

37  :
38  EventRecordVisitorI("genie::evtlib::EventLibraryInterface", config),
39  fRecordFile(0)
40 {
41 
42 }
EventLibraryInterface::~EventLibraryInterface ( )

Definition at line 45 of file EventLibraryInterface.cxx.

References Cleanup().

Member Function Documentation

void EventLibraryInterface::Cleanup ( )
protected

Definition at line 219 of file EventLibraryInterface.cxx.

References fRecordFile, and fRecords.

Referenced by LoadRecords(), and ~EventLibraryInterface().

220 {
221  for(auto it: fRecords) delete it.second;
222  fRecords.clear();
223  delete fRecordFile;
224  fRecordFile = 0;
225 }
std::map< Key, const IEvtLibRecordList * > fRecords
void EventLibraryInterface::Configure ( const Registry config)
overridevirtual

Configure the algorithm with an external registry The registry is merged with the top level registry if it is owned, Otherwise a copy of it is added with the highest priority

Reimplemented from genie::Algorithm.

Definition at line 205 of file EventLibraryInterface.cxx.

References genie::Algorithm::Configure(), and LoadRecords().

206 {
207  Algorithm::Configure(config);
208  LoadRecords();
209 }
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
void EventLibraryInterface::Configure ( string  config)
overridevirtual

Configure the algorithm from the AlgoConfigPool based on param_set string given in input An algorithm contains a vector of registries coming from different xml configuration files, which are loaded according a very precise prioriy This methods will load a number registries in order of priority: 1) "Tunable" parameter set from CommonParametes. This is loaded with the highest prioriry and it is designed to be used for tuning procedure Usage not expected from the user. 2) For every string defined in "CommonParame" the corresponding parameter set will be loaded from CommonParameter.xml 3) parameter set specified by the config string and defined in the xml file of the algorithm 4) if config is not "Default" also the Default parameter set from the same xml file will be loaded Effectively this avoids the repetion of a parameter when it is not changed in the requested configuration

Reimplemented from genie::Algorithm.

Definition at line 212 of file EventLibraryInterface.cxx.

References genie::Algorithm::Configure(), and LoadRecords().

213 {
214  Algorithm::Configure(config);
215  LoadRecords();
216 }
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
void EventLibraryInterface::FillKinematics ( const GHepRecord event,
genie::Kinematics kine,
int  primary_lep_id 
) const
protected

Definition at line 296 of file EventLibraryInterface.cxx.

References genie::Kinematics::SetQ2(), genie::Kinematics::SetW(), genie::Kinematics::Setx(), and genie::Kinematics::Sety().

Referenced by ProcessEventRecord().

298  {
299 
300 
301  const TLorentzVector & p_probe = * event.Particle( 0 ) -> P4() ;
302 
303  const TLorentzVector & p_lep = * event.Particle( primary_lep_id ) -> P4() ;
304 
305  const TLorentzVector q = p_probe - p_lep;
306 
307  // Initial hadronic state, semi-arbitrary
308  const TLorentzVector & p_tgt = * event.Particle( 1 ) -> P4() ;
309 
310  kine.SetQ2(-q.Mag2(), true);
311  kine.SetW((q + p_tgt).Mag(), true);
312  kine.Setx(-q.Mag2() / (2*p_tgt.Dot(q)), true);
313  kine.Sety( p_tgt.Dot( q ) / p_tgt.Dot( p_probe ), true ) ;
314 
315 }
void SetQ2(double Q2, bool selected=false)
Definition: Kinematics.cxx:255
void Setx(double x, bool selected=false)
Definition: Kinematics.cxx:231
void SetW(double W, bool selected=false)
Definition: Kinematics.cxx:279
void Sety(double y, bool selected=false)
Definition: Kinematics.cxx:243
const EvtLibRecord * EventLibraryInterface::GetRecord ( const Interaction interaction) const
protected

Definition at line 157 of file EventLibraryInterface.cxx.

References fRecords, genie::Interaction::InitState(), genie::Target::IsNucleus(), genie::ProcessInfo::IsWeakCC(), genie::ProcessInfo::IsWeakNC(), genie::kPdgAntiNuMu, genie::kPdgNuMu, genie::kRfLab, LOG, pINFO, genie::InitialState::ProbeE(), genie::InitialState::ProbePdg(), genie::Interaction::ProcInfo(), genie::InitialState::Tgt(), and genie::InitialState::TgtPdg().

Referenced by ProcessEventRecord().

158 {
159  const InitialState& init_state = interaction->InitState();
160 
161  const double probe_E = init_state.ProbeE(kRfLab);
162 
163  if(!init_state.Tgt().IsNucleus()){
164  LOG("ELI", pINFO) << "Skippping non-nuclear target " << init_state;
165  return 0;
166  }
167 
168  const int tgt_pdgc = init_state.TgtPdg();
169 
170  const ProcessInfo& proc = interaction->ProcInfo();
171 
172  if(!proc.IsWeakCC() && !proc.IsWeakNC()){
173  LOG("ELI", pINFO) << "Skipping unknown process " << proc;
174  return 0;
175  }
176 
177  int probe_pdgc = init_state.ProbePdg();
178 
179  // Use nu_mu for NC as a convention internal to this code to index into the
180  // records map.
181  if(proc.IsWeakNC()){
182  if(probe_pdgc > 0) probe_pdgc = kPdgNuMu;
183  else probe_pdgc = kPdgAntiNuMu;
184  }
185 
186  const Key key(tgt_pdgc, probe_pdgc, proc.IsWeakCC());
187 
188  const auto rec_it = fRecords.find(key);
189 
190  if(rec_it == fRecords.end()){
191  LOG("ELI", pINFO) << "Skippping " << key << " -- not found in library";
192  return 0;
193  }
194 
195  const EvtLibRecord* rec = rec_it->second->GetRecord(probe_E);
196 
197  if(!rec){
198  LOG("ELI", pINFO) << "Skippping " << key << " at " << probe_E << " GeV -- not found in library";
199  return 0;
200  }
201 
202  return rec;
203 }
bool IsWeakCC(void) const
std::map< Key, const IEvtLibRecordList * > fRecords
bool IsNucleus(void) const
Definition: Target.cxx:272
const int kPdgNuMu
Definition: PDGCodes.h:30
bool IsWeakNC(void) const
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
A class encapsulating an enumeration of interaction types (EM, Weak-CC, Weak-NC) and scattering types...
Definition: ProcessInfo.h:46
int ProbePdg(void) const
Definition: InitialState.h:64
#define pINFO
Definition: Messenger.h:62
const int kPdgAntiNuMu
Definition: PDGCodes.h:31
int TgtPdg(void) const
const InitialState & InitState(void) const
Definition: Interaction.h:69
const ProcessInfo & ProcInfo(void) const
Definition: Interaction.h:70
const Target & Tgt(void) const
Definition: InitialState.h:66
double ProbeE(RefFrame_t rf) const
Initial State information.
Definition: InitialState.h:48
void EventLibraryInterface::LoadRecords ( )
protected

Definition at line 228 of file EventLibraryInterface.cxx.

References Cleanup(), genie::PDGLibrary::DBase(), dir, genie::evtlib::Expand(), genie::PDGLibrary::Find(), genie::utils::style::Format(), fRecordFile, fRecords, genie::Algorithm::GetParam(), genie::PDGLibrary::Instance(), genie::pdg::IsAntiNeutrino(), genie::kPdgAntiNuE, genie::kPdgAntiNuMu, genie::kPdgAntiNuTau, genie::kPdgNuE, genie::kPdgNuMu, genie::kPdgNuTau, LOG, pINFO, and pWARN.

Referenced by Configure().

229 {
230  Cleanup();
231 
232  std::string libPath;
233  GetParam("EventLibraryPath", libPath);
234  Expand(libPath);
235 
236  bool onDemand;
237  GetParam("OnDemand", onDemand);
238 
239  PDGLibrary* pdglib = PDGLibrary::Instance();
240 
241  fRecordFile = new TFile(libPath.c_str());
242  if(fRecordFile->IsZombie()) exit(1);
243 
244  TIter next(fRecordFile->GetListOfKeys());
245  while(TObject* dir = next()){
246  const std::string& tgtName = dir->GetName();
247  const TParticlePDG* tgtPart = pdglib->DBase()->GetParticle(tgtName.c_str());
248  if(!tgtPart){
249  LOG("ELI", pWARN) << "Unknown nucleus " << tgtName
250  << " found in " << libPath
251  << " -- skipping";
252  continue;
253  }
254 
255  for(int pdg: {kPdgNuE, kPdgAntiNuE,
258 
259  for(bool iscc: {true, false}){
260  // NCs should be the same for all flavours. Use nu_mu as a convention
261  // internal to this code to index into the records map.
262  if(!iscc && abs(pdg) != kPdgNuMu) continue;
263 
264  std::string nuName = pdglib->Find(pdg)->GetName();
265  if(!iscc) nuName = pdg::IsAntiNeutrino(pdg) ? "nu_bar" : "nu";
266 
267  const std::string treeName =
268  TString::Format("%s/%s/%s/records",
269  tgtName.c_str(),
270  iscc ? "cc" : "nc",
271  nuName.c_str()).Data();
272 
273  const Key key(tgtPart->PdgCode(), pdg, iscc);
274 
275  TTree* tr = (TTree*)fRecordFile->Get(treeName.c_str());
276 
277  if(!tr){
278  LOG("ELI", pINFO) << treeName << " not found in "
279  << libPath << " -- skipping";
280  continue;
281  }
282 
283  if(onDemand)
284  fRecords[key] = new OnDemandRecordList(tr, treeName);
285  else
286  fRecords[key] = new SimpleRecordList(tr, treeName);
287  } // end for iscc
288  } // end for pdg
289  } // end for dir
290 
291  // Need to keep the record file open for OnDemand, but not Simple
292  if(!onDemand){delete fRecordFile; fRecordFile = 0;}
293 }
const int kPdgNuE
Definition: PDGCodes.h:28
std::map< Key, const IEvtLibRecordList * > fRecords
const int kPdgAntiNuE
Definition: PDGCodes.h:29
void Expand(std::string &s)
Expand env vars/homedirs/wildcards in s.
Definition: Utils.cxx:8
TDatabasePDG * DBase(void)
Definition: PDGLibrary.cxx:81
const int kPdgNuMu
Definition: PDGCodes.h:30
string dir
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool IsAntiNeutrino(int pdgc)
Definition: PDGUtils.cxx:118
#define pINFO
Definition: Messenger.h:62
const int kPdgAntiNuTau
Definition: PDGCodes.h:33
const int kPdgAntiNuMu
Definition: PDGCodes.h:31
#define pWARN
Definition: Messenger.h:60
const int kPdgNuTau
Definition: PDGCodes.h:32
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:68
Singleton class to load &amp; serve a TDatabasePDG.
Definition: PDGLibrary.h:35
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:146
TParticlePDG * Find(int pdgc, bool must_exist=true)
Definition: PDGLibrary.cxx:86
bool GetParam(const RgKey &name, T &p, bool is_top_call=true) const
void EventLibraryInterface::ProcessEventRecord ( GHepRecord event) const
overridevirtual

Implements genie::EventRecordVisitorI.

Definition at line 51 of file EventLibraryInterface.cxx.

References genie::evtlib::EvtLibRecord::E, FillKinematics(), GetRecord(), genie::Interaction::InitState(), genie::RandomGen::Instance(), genie::pdg::IsLepton(), genie::ProcessInfo::IsWeakNC(), genie::Interaction::KinePtr(), genie::kIStStableFinalState, genie::constants::kPi, LOG, genie::GHepParticle::P4(), pINFO, genie::InitialState::ProbePdg(), genie::Interaction::ProcInfo(), and genie::RandomGen::RndEvg().

52 {
53 // Get event summary constructed by GENIE
54 //
55  Interaction* interaction = event->Summary();
56  const InitialState & init_state = interaction->InitState();
57 
58  const EvtLibRecord* rec = GetRecord(interaction);
59  if(!rec) return; // Reason has already been printed
60 
61 
62  // at this point we have the event to add to our event record
63  // the energy might be not the same
64  // so first we correct the probe:
65  // we maintain the same direction but we set the energy selected
66  // by the record.
67  // We only change the the particle in the event record,
68  // Not the summary so that we keep the history
69  // of the event construction
70 
71  // Neutrino is a parent to the lepton(s)
72  GHepParticle * probe = event->Particle(0) ;
73 
74  TLorentzVector probe_p4 ( * probe->P4() ) ;
75 
76  LOG("ELI", pINFO) << "Difference between requested neutrino E and used neutrino energy: " << probe_p4.E() - rec -> E ;
77 
78  probe_p4 *= rec -> E / probe_p4.E() ;
79  probe -> SetMomentum( probe_p4 ) ;
80 
81  // because of the selection procedure there might not be enough
82  // events in the library
83  // so we add a roation around the z axis which is random for each event
84  double alpha = RandomGen::Instance()->RndEvg().Uniform(0, 2*constants::kPi );
85 
86 
87  // now we simply have to add the particles from the EvtLibRecord
88  // But we need to rotate the particles along the direction of the beam
89  // so we evaluate this direction once and for all
90  TVector3 unit_nudir = probe->P4()->Vect().Unit();
91 
92 
93  int firstLep = -1 ;
94  const auto & parts = rec -> parts ;
95 
96  for ( unsigned int i = 0; i < parts.size() ; ++i ) {
97 
98  const auto & part = parts[i] ;
99 
100  int pdg = part.pdg;
101 
102  if(pdg::IsLepton(part.pdg)) {
103  if ( firstLep == -1 ) {
104  firstLep = i ;
105  interaction -> KinePtr() -> SetFSLeptonP4( part.px, part.py, part.pz, part.E ) ;
106  }
107  }
108 
109  // Fix up the outgoing lepton for NC events (due to lepton universality
110  // it could be any value in the library)
111 
112  if( interaction->ProcInfo().IsWeakNC() ) {
113  if ( int(i) == firstLep ) {
114  // in the case of NC the process is always stored as numu (or numubar)
115  // as the couplings are the same
116  // here we restore the proper pdg on what we think it is the leading neutrino
117  pdg = init_state.ProbePdg();
118  }
119  }
120 
121  TLorentzVector p4(part.px, part.py, part.pz, part.E) ;
122 
123  // The next is the rotation of the event according to the common alpha
124  p4.RotateZ( alpha ) ;
125 
126  // Now we rotate the events so that it matches the direction of the incoming neutrino
127  p4.RotateUz(unit_nudir);
128 
129  event->AddParticle(pdg,
131  0 , 1, -1, -1, // child of the neutrino and nucleus
132  p4,
133  TLorentzVector(0, 0, 0, 0));
134 
135  }
136 
137  // we now have the particle in the right direction inside the record we just need to
138  // decorate the summary kinematics
139 
140  if ( firstLep < 0 ) {
141  firstLep = 2 ;
142  }
143  else {
144  firstLep += 2 ;
145  }
146  // these are events from outside, there are no assumptions on the lepton
147  // If we are simulating BSM physics there might not even be a lepton in the final state
148  // So if there is a lepton we evaluate Q2 based on that lepton
149  // If not we evaluate Q2 using the first particle we have available
150 
151  FillKinematics( *event, *interaction->KinePtr(), firstLep );
152 
153 }
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:71
const TLorentzVector * P4(void) const
Definition: GHepParticle.h:78
Kinematics * KinePtr(void) const
Definition: Interaction.h:76
Summary information for an interaction.
Definition: Interaction.h:56
bool IsWeakNC(void) const
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
int ProbePdg(void) const
Definition: InitialState.h:64
TRandom3 & RndEvg(void) const
rnd number generator used by the event generation drivers
Definition: RandomGen.h:74
#define pINFO
Definition: Messenger.h:62
const InitialState & InitState(void) const
Definition: Interaction.h:69
const ProcessInfo & ProcInfo(void) const
Definition: Interaction.h:70
const EvtLibRecord * GetRecord(const Interaction *interaction) const
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
bool IsLepton(int pdgc)
Definition: PDGUtils.cxx:86
void FillKinematics(const GHepRecord &, genie::Kinematics &kine, int primary_lep_id) const
Initial State information.
Definition: InitialState.h:48

Member Data Documentation

TFile* genie::evtlib::EventLibraryInterface::fRecordFile
private

Definition at line 72 of file EventLibraryInterface.h.

Referenced by Cleanup(), and LoadRecords().

std::map<Key, const IEvtLibRecordList*> genie::evtlib::EventLibraryInterface::fRecords
private

Definition at line 71 of file EventLibraryInterface.h.

Referenced by Cleanup(), GetRecord(), and LoadRecords().


The documentation for this class was generated from the following files: