GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions | Variables
gBeamHNLEvGen.cxx File Reference
#include <cassert>
#include <cstdlib>
#include <string>
#include <vector>
#include <sstream>
#include <TSystem.h>
#include "Framework/Algorithm/AlgFactory.h"
#include "Framework/Conventions/Controls.h"
#include "Framework/EventGen/EventRecord.h"
#include "Framework/EventGen/EventGeneratorI.h"
#include "Framework/EventGen/EventRecordVisitorI.h"
#include "Framework/EventGen/GMCJMonitor.h"
#include "Framework/GHEP/GHepParticle.h"
#include "Framework/Messenger/Messenger.h"
#include "Framework/Ntuple/NtpWriter.h"
#include "Physics/BeamHNL/HNLDecayMode.h"
#include "Physics/BeamHNL/HNLDecayUtils.h"
#include "Physics/BeamHNL/HNLVertexGenerator.h"
#include "Physics/BeamHNL/HNLFluxContainer.h"
#include "Physics/BeamHNL/HNLFluxCreator.h"
#include "Physics/BeamHNL/HNLDecayer.h"
#include "Physics/BeamHNL/SimpleHNL.h"
#include "Framework/Numerical/RandomGen.h"
#include "Framework/ParticleData/PDGCodes.h"
#include "Framework/ParticleData/PDGUtils.h"
#include "Framework/ParticleData/PDGLibrary.h"
#include "Framework/Utils/StringUtils.h"
#include "Framework/Utils/UnitUtils.h"
#include "Framework/Utils/PrintUtils.h"
#include "Framework/Utils/AppInit.h"
#include "Framework/Utils/TuneId.h"
#include "Framework/Utils/RunOpt.h"
#include "Framework/Utils/CmdLnArgParser.h"
Include dependency graph for gBeamHNLEvGen.cxx:

Go to the source code of this file.

Functions

void GetCommandLineArgs (int argc, char **argv)
 
void PrintSyntax (void)
 
int SelectDecayMode (std::vector< HNLDecayMode_t > *intChannels, SimpleHNL sh)
 
const EventRecordVisitorIHNLGenerator (void)
 
TLorentzVector GeneratePosition (GHepRecord *event)
 
int main (int argc, char **argv)
 

Variables

string kDefOptGeomLUnits = "mm"
 
string kDefOptGeomDUnits = "g_cm3"
 
NtpMCFormat_t kDefOptNtpFormat = kNFGHEP
 
string kDefOptEvFilePrefix = "gntp"
 
string kDefOptFluxFilePath = "./input-flux.root"
 
string kDefOptSName = "genie::EventGenerator"
 
string kDefOptSConfig = "BeamHNL"
 
string kDefOptSTune = "GHNL20_00a_00_000"
 
Long_t gOptRunNu = 1000
 
int gOptNev = 10
 
double gOptEnergyHNL = -1
 
double gOptMassHNL = -1
 
double gOptECoupling = -1
 
double gOptMCoupling = -1
 
double gOptTCoupling = -1
 
bool gOptIsMajorana = false
 
bool gOptIsMonoEnFlux = true
 
HNLDecayMode_t gOptDecayMode = kHNLDcyNull
 
std::vector< HNLDecayMode_tgOptIntChannels
 
string gOptEvFilePrefix = kDefOptEvFilePrefix
 
bool gOptUsingRootGeom = false
 
string gOptRootGeom
 
string gOptRootGeomTopVol = ""
 
double gOptGeomLUnits = 0
 
long int gOptRanSeed = -1
 
double fdx = 0
 
double fdy = 0
 
double fdz = 0
 
double fox = 0
 
double foy = 0
 
double foz = 0
 
double NTP_IS_E = 0.
 
double NTP_IS_PX = 0.
 
double NTP_IS_PY = 0.
 
double NTP_IS_PZ = 0.
 
double NTP_FS0_E = 0.
 
double NTP_FS0_PX = 0.
 
double NTP_FS0_PY = 0.
 
double NTP_FS0_PZ = 0.
 
double NTP_FS1_E = 0.
 
double NTP_FS1_PX = 0.
 
double NTP_FS1_PY = 0.
 
double NTP_FS1_PZ = 0.
 
double NTP_FS2_E = 0.
 
double NTP_FS2_PX = 0.
 
double NTP_FS2_PY = 0.
 
double NTP_FS2_PZ = 0.
 
int NTP_FS0_PDG = 0
 
int NTP_FS1_PDG = 0
 
int NTP_FS2_PDG = 0
 
double CoMLifetime = -1.0
 
double decayMod = 1.0
 
double evWeight = 1.0
 

Function Documentation

TLorentzVector GeneratePosition ( GHepRecord event)

Definition at line 711 of file gBeamHNLEvGen.cxx.

References genie::hnl::selector::__attribute__(), fdx, fdy, fdz, fox, foy, foz, genie::RandomGen::Instance(), and genie::RandomGen::RndGeom().

Referenced by main().

712 {
713  __attribute__((unused)) RandomGen * rnd = RandomGen::Instance();
714  TRandom3 & rnd_geo = rnd->RndGeom();
715 
716  double rndx = 2 * (rnd_geo.Rndm() - 0.5); // [-1,1]
717  double rndy = 2 * (rnd_geo.Rndm() - 0.5); // [-1,1]
718  double rndz = 2 * (rnd_geo.Rndm() - 0.5); // [-1,1]
719 
720  double t_gen = 0;
721  double x_gen = fox + rndx * fdx;
722  double y_gen = foy + rndy * fdy;
723  double z_gen = foz + rndz * fdz;
724 
725  TLorentzVector pos(x_gen, y_gen, z_gen, t_gen);
726  return pos;
727 }
double foy
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
double fox
double fdy
static __attribute__((unused)) double fDecayGammas[]
double fdx
double foz
double fdz
void GetCommandLineArgs ( int  argc,
char **  argv 
)
const EventRecordVisitorI * HNLGenerator ( void  )

Definition at line 729 of file gBeamHNLEvGen.cxx.

References genie::gAbortingInErr, genie::AlgFactory::GetAlgorithm(), genie::AlgFactory::Instance(), kDefOptSConfig, kDefOptSName, LOG, pDEBUG, pFATAL, and pINFO.

Referenced by main(), and TestDecay().

730 {
731  //string sname = "genie::EventGenerator";
732  //string sconfig = "BeamHNL";
733  AlgFactory * algf = AlgFactory::Instance();
734 
735  LOG("gevgen_hnl", pINFO)
736  << "Instantiating HNL generator.";
737 
738  const Algorithm * algmcgen = algf->GetAlgorithm(kDefOptSName, kDefOptSConfig);
739  LOG("gevgen_hnl", pDEBUG)
740  << "Got algorithm " << kDefOptSName.c_str() << "/" << kDefOptSConfig.c_str();;
741 
742  const EventRecordVisitorI * mcgen =
743  dynamic_cast< const EventRecordVisitorI * >( algmcgen );
744  if(!mcgen) {
745  LOG("gevgen_hnl", pFATAL) << "Couldn't instantiate the HNL generator";
746  gAbortingInErr = true;
747  exit(1);
748  }
749 
750  LOG("gevgen_hnl", pINFO)
751  << "HNL generator instantiated successfully.";
752 
753  return mcgen;
754 }
Defines the EventRecordVisitorI interface. Concrete implementations of this interface use the &#39;Visito...
#define pFATAL
Definition: Messenger.h:56
Algorithm abstract base class.
Definition: Algorithm.h:54
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
string kDefOptSName
const Algorithm * GetAlgorithm(const AlgId &algid)
Definition: AlgFactory.cxx:75
#define pINFO
Definition: Messenger.h:62
string kDefOptSConfig
The GENIE Algorithm Factory.
Definition: AlgFactory.h:39
bool gAbortingInErr
Definition: Messenger.cxx:34
#define pDEBUG
Definition: Messenger.h:63
int main ( int  argc,
char **  argv 
)

Definition at line 219 of file gBeamHNLEvGen.cxx.

References genie::hnl::selector::__attribute__(), genie::NtpWriter::AddEventRecord(), CoMLifetime, genie::NtpWriter::CustomizeFilenamePrefix(), decayMod, e, genie::NtpWriter::EventTree(), evWeight, GeneratePosition(), genie::AlgFactory::GetAlgorithm(), genie::hnl::SimpleHNL::GetCoMLifetime(), GetCommandLineArgs(), genie::hnl::Decayer::GetHNLCouplings(), genie::hnl::Decayer::GetHNLInterestingChannels(), genie::hnl::Decayer::GetHNLLifetime(), genie::hnl::FluxCreator::GetNFluxEntries(), genie::hnl::SimpleHNL::GetValidChannels(), gOptDecayMode, gOptECoupling, gOptEnergyHNL, gOptEvFilePrefix, gOptIntChannels, gOptIsMajorana, gOptIsMonoEnFlux, gOptMassHNL, gOptMCoupling, gOptNev, gOptRanSeed, gOptRootGeom, gOptRunNu, gOptTCoupling, gOptUsingRootGeom, genie::Interaction::HNL(), HNLGenerator(), genie::NtpWriter::Initialize(), genie::Interaction::InitStatePtr(), genie::RandomGen::Instance(), genie::RunOpt::Instance(), genie::AlgFactory::Instance(), genie::hnl::Decayer::IsHNLMajorana(), kDefOptNtpFormat, kDefOptSConfig, genie::hnl::kHNLDcyNull, genie::kIStInitialState, genie::kPdgHNL, genie::kPdgKP, LOG, genie::utils::app_init::MesgThresholds(), NTP_FS0_E, NTP_FS0_PDG, NTP_FS0_PX, NTP_FS0_PY, NTP_FS0_PZ, NTP_FS1_E, NTP_FS1_PDG, NTP_FS1_PX, NTP_FS1_PY, NTP_FS1_PZ, NTP_FS2_E, NTP_FS2_PDG, NTP_FS2_PX, NTP_FS2_PY, NTP_FS2_PZ, NTP_IS_E, NTP_IS_PX, NTP_IS_PY, NTP_IS_PZ, genie::utils::print::P4AsString(), pDEBUG, pINFO, pNOTICE, genie::hnl::Decayer::ProcessEventRecord(), genie::hnl::VertexGenerator::ProcessEventRecord(), genie::hnl::FluxCreator::ProcessEventRecord(), pWARN, genie::utils::app_init::RandGen(), genie::hnl::FluxCreator::RetrieveFluxInfo(), genie::RandomGen::RndGen(), genie::NtpWriter::Save(), SelectDecayMode(), genie::hnl::FluxCreator::SetFirstFluxEntry(), genie::hnl::VertexGenerator::SetGeomFile(), genie::hnl::FluxCreator::SetGeomFile(), genie::hnl::FluxCreator::SetInputFluxPath(), genie::GHepRecord::SetPrintLevel(), genie::InitialState::SetProbeP4(), genie::InitialState::SetProbePdg(), genie::GMCJMonitor::SetRefreshRate(), genie::GHepRecord::SetWeight(), and genie::GMCJMonitor::Update().

220 {
221  // suppress ROOT Info messages
222  gErrorIgnoreLevel = kWarning;
223 
224  // Parse command line arguments
225  GetCommandLineArgs(argc,argv);
226 
227  // Init messenger and random number seed
228  utils::app_init::MesgThresholds(RunOpt::Instance()->MesgThresholdFiles());
230 
231  __attribute__((unused)) RandomGen * rnd = RandomGen::Instance();
232 
233  // Get the HNL generator first to load config
234  // config loaded upon instantiation of HNLGenerator algorithm
235  // calls LoadConfig() of each sub-alg
236  __attribute__((unused)) const EventRecordVisitorI * mcgen = HNLGenerator();
237  const Algorithm * algFluxCreator = AlgFactory::Instance()->GetAlgorithm("genie::hnl::FluxCreator", "Default");
238  const Algorithm * algHNLGen = AlgFactory::Instance()->GetAlgorithm("genie::hnl::Decayer", "Default");
239  const Algorithm * algVtxGen = AlgFactory::Instance()->GetAlgorithm("genie::hnl::VertexGenerator", "Default");
240 
241  const FluxCreator * fluxCreator = dynamic_cast< const FluxCreator * >( algFluxCreator );
242  const Decayer * hnlgen = dynamic_cast< const Decayer * >( algHNLGen );
243  const VertexGenerator * vtxGen = dynamic_cast< const VertexGenerator * >( algVtxGen );
244 
245  //string confString = kDefOptSName + "/" + kDefOptSConfig;
246  string confString = kDefOptSConfig;
247 
248  CoMLifetime = hnlgen->GetHNLLifetime(); // GeV^{-1}
249 
250  std::vector< double > U4l2s = hnlgen->GetHNLCouplings();
251  gOptECoupling = U4l2s.at(0);
252  gOptMCoupling = U4l2s.at(1);
253  gOptTCoupling = U4l2s.at(2);
254  gOptIsMajorana = hnlgen->IsHNLMajorana();
255 
256  std::string stIntChannels = hnlgen->GetHNLInterestingChannels(); int iChan = -1;
257  if( gOptIntChannels.size() > 0 ) gOptIntChannels.clear();
258  while( stIntChannels.size() > 0 ){ // read channels from right (lowest mass) to left (highest mass)
259  iChan++;
260  HNLDecayMode_t md = static_cast< HNLDecayMode_t >( iChan );
261  std::string tmpSt = stIntChannels.substr( stIntChannels.size()-1, stIntChannels.size() );
262  if( std::strcmp( tmpSt.c_str(), "1" ) == 0 )
263  gOptIntChannels.emplace_back( md );
264 
265  stIntChannels.erase( stIntChannels.end()-1, stIntChannels.end() );
266  }
267 
268  //gOptIntChannels = confIntChan;
269 
270  // Initialize an Ntuple Writer to save GHEP records into a TTree
272  ntpw.CustomizeFilenamePrefix(gOptEvFilePrefix);
273  ntpw.Initialize();
274 
275  // add flux info to the tree
276  FluxContainer gnmf;
277  if( gOptIsUsingDk2nu ) {
278  // fill the flux object with nonsense to start with
279  FluxContainer * ptGnmf = new FluxContainer();
280  gnmf = *ptGnmf;
281  delete ptGnmf;
282  FillFluxNonsense( gnmf );
283  TBranch * flux = ntpw.EventTree()->Branch( "flux",
284  "genie::hnl::FluxContainer",
285  &gnmf, 32000, 1 );
286  flux->SetAutoDelete(kFALSE);
287  }
288 
289  LOG("gevgen_hnl", pNOTICE)
290  << "Initialised Ntuple Writer";
291 
292  // add another few branches to tree.
293  ntpw.EventTree()->Branch("hnl_mass", &gOptMassHNL, "gOptMassHNL/D");
294  ntpw.EventTree()->Branch("hnl_coup_e", &gOptECoupling, "gOptECoupling/D");
295  ntpw.EventTree()->Branch("hnl_coup_m", &gOptMCoupling, "gOptMCoupling/D");
296  ntpw.EventTree()->Branch("hnl_coup_t", &gOptTCoupling, "gOptTCoupling/D");
297  ntpw.EventTree()->Branch("hnl_ismaj", &gOptIsMajorana, "gOptIsMajorana/I");
298 
299  // Create a MC job monitor for a periodically updated status file
300  GMCJMonitor mcjmonitor(gOptRunNu);
301  mcjmonitor.SetRefreshRate(RunOpt::Instance()->MCJobStatusRefreshRate());
302 
303  LOG("gevgen_hnl", pNOTICE)
304  << "Initialised MC job monitor";
305 
306  // Set GHEP print level
307  GHepRecord::SetPrintLevel(RunOpt::Instance()->EventRecordPrintLevel());
308 
309 #ifdef __CAN_USE_ROOT_GEOM__
310  // Read geometry bounding box - for vertex position generation
311  if( gOptUsingRootGeom ){
312  InitBoundingBox();
313  }
314 #endif // #ifdef __CAN_USE_ROOT_GEOM__
315 
316  if( !gOptIsMonoEnFlux ){
317  LOG( "gevgen_hnl", pWARN )
318  << "Using input flux files. These are *flat dk2nu-like ROOT trees, so far...*";
319 
320  }
321  // Event loop
322  int iflux = (gOptFirstEvent < 0) ? 0 : gOptFirstEvent; int ievent = iflux;
323  int maxFluxEntries = -1;
324  fluxCreator->SetInputFluxPath( gOptFluxFilePath );
325  fluxCreator->SetGeomFile( gOptRootGeom );
326  fluxCreator->SetFirstFluxEntry( iflux );
327  vtxGen->SetGeomFile( gOptRootGeom );
328 
329  bool tooManyEntries = false;
330  while (1)
331  {
332  if( tooManyEntries ){
333  if( gOptNev >= 10000 ){
334  if( (ievent-gOptFirstEvent) % (gOptNev / 1000) == 0 ){
335  int irat = (iflux-gOptFirstEvent) / ( gOptNev / 1000 );
336  std::cerr << 0.1 * irat << " % " << " ( " << (iflux-gOptFirstEvent)
337  << " seen ), ( " << (ievent-gOptFirstEvent) << " / " << gOptNev << " processed ) \r" << std::flush;
338  }
339  } else if( gOptNev >= 100 ) {
340  if( (ievent-gOptFirstEvent) % (gOptNev / 10) == 0 ){
341  int irat = (iflux-gOptFirstEvent) / ( gOptNev / 10 );
342  std::cerr << 10.0 * irat << " % " << " ( " << (iflux-gOptFirstEvent)
343  << " seen ), ( " << (ievent-gOptFirstEvent) << " / " << gOptNev << " processed ) \r" << std::flush;
344  }
345  }
346  } else {
347  if( gOptNev >= 10000 ){
348  if( (ievent-gOptFirstEvent) % (gOptNev / 1000) == 0 ){
349  int irat = (ievent-gOptFirstEvent) / ( gOptNev / 1000 );
350  std::cerr << 0.1 * irat << " % " << " ( " << (iflux-gOptFirstEvent)
351  << " seen ), ( " << (ievent-gOptFirstEvent) << " / " << gOptNev << " processed ) \r" << std::flush;
352  }
353  } else if( gOptNev >= 100 ) {
354  if( (ievent-gOptFirstEvent) % (gOptNev / 10) == 0 ){
355  int irat = (ievent-gOptFirstEvent) / ( gOptNev / 10 );
356  std::cerr << 10.0 * irat << " % " << " ( " << (iflux-gOptFirstEvent)
357  << " seen ), ( " << (ievent-gOptFirstEvent) << " / " << gOptNev << " processed ) \r" << std::flush;
358  }
359  }
360  }
361 
362  if( tooManyEntries && ((iflux-gOptFirstEvent) == gOptNev) ) break;
363  else if( (ievent-gOptFirstEvent) == gOptNev ) break;
364 
365  if( ievent < gOptFirstEvent ){ ievent++; continue; }
366 
367  assert( ievent >= gOptFirstEvent && gOptFirstEvent >= 0 );
368 
369  LOG("gevgen_hnl", pNOTICE)
370  << " *** Generating event............ " << (ievent-gOptFirstEvent);
371 
372  EventRecord * event = new EventRecord;
373  event->SetWeight(1.0);
374  event->SetProbability( CoMLifetime );
375  event->SetXSec( iflux ); // will be overridden, use as handy container
376  evWeight = 1.0;
377 
378  if( !gOptIsMonoEnFlux ){
379  fluxCreator->ProcessEventRecord( event );
380 
381  // fluxCreator->ProcessEventRecord now tells us how many entries there are
382  maxFluxEntries = fluxCreator->GetNFluxEntries();
383  if( gOptNev > maxFluxEntries - gOptFirstEvent ){
384  LOG( "gevgen_hnl", pWARN )
385  << "You have asked for " << gOptNev << " events, but only provided "
386  << maxFluxEntries - gOptFirstEvent << " flux entries. Truncating events to " << maxFluxEntries - gOptFirstEvent << ".";
387  gOptNev = maxFluxEntries - gOptFirstEvent;
388  tooManyEntries = true;
389  }
390  if( iflux >= maxFluxEntries - 1 ){
391  LOG( "gevgen_hnl", pWARN )
392  << "Reached end of flux input (iflux = " << iflux << "), about to stop.";
393  break;
394  }
395 
396  FluxContainer retGnmf = fluxCreator->RetrieveFluxInfo();
397  FillFlux( gnmf, retGnmf );
398 
399  // check to see if this was nonsense
400  if( ! event->Particle(0) ){ iflux++; delete event; continue; }
401 
402  gOptEnergyHNL = event->Particle(0)->GetP4()->E();
403  iflux++;
404  } else { // monoenergetic HNL. Add it with energy and momentum pointing on z axis
405 
406  assert( gOptEnergyHNL > gOptMassHNL );
407  double HNLP = std::sqrt( gOptEnergyHNL*gOptEnergyHNL - gOptMassHNL*gOptMassHNL );
408  TLorentzVector probeP4( 0.0, 0.0, HNLP, gOptEnergyHNL );
409  TLorentzVector v4( 0.0, 0.0, 0.0, 0.0 );
410  GHepParticle ptHNL( kPdgHNL, kIStInitialState, -1, -1, -1, -1, probeP4, v4 );
411  event->AddParticle( ptHNL );
412 
413  }
414  assert( gOptEnergyHNL > gOptMassHNL );
415 
416  int hpdg = genie::kPdgHNL;
417  int typeMod = 1;
418  if( gOptIsMajorana ) typeMod = ( rnd->RndGen().Uniform( 0.0, 1.0 ) >= 0.5 ) ? -1 : 1;
419  else if( event->Particle(0)->Pdg() > 0 ) typeMod = 1;
420  else if( event->Particle(0)->Pdg() < 0 ) typeMod = -1;
421 
422  // int target = SelectInitState();
423  int decay = (int) gOptDecayMode;
424 
425  assert( gOptECoupling >= 0.0 && gOptMCoupling >= 0.0 && gOptTCoupling >= 0.0 );
426 
427  // RETHERE assuming all these HNL have K+- parent. This is wrong
428  // (but not very wrong for interesting masses)
429  SimpleHNL sh( "HNL", ievent, hpdg, genie::kPdgKP,
431 
432  const std::map< HNLDecayMode_t, double > gammaMap = sh.GetValidChannels();
433  CoMLifetime = sh.GetCoMLifetime();
434 
435  if( gOptDecayMode == kHNLDcyNull ){ // select from available modes
436  LOG("gevgen_hnl", pNOTICE)
437  << "No decay mode specified - sampling from all available modes.";
438 
439  std::vector< HNLDecayMode_t > * intChannels = &gOptIntChannels;
440 
441  decay = SelectDecayMode( intChannels, sh );
442  }
443 
444  Interaction * interaction = Interaction::HNL(typeMod * genie::kPdgHNL, gOptEnergyHNL, decay);
445 
446  if( event->Particle(0) ){ // we have an HNL with definite momentum, so let's set it now
447  interaction->InitStatePtr()->SetProbeP4( *(event->Particle(0)->P4()) );
448  interaction->InitStatePtr()->SetProbePdg( event->Particle(0)->Pdg() );
449  LOG( "gevgen_hnl", pDEBUG )
450  << "\nsetting probe p4 = " << utils::print::P4AsString( event->Particle(0)->P4() );
451  }
452 
453  event->AttachSummary(interaction);
454 
455  // Simulate decay
456  hnlgen->ProcessEventRecord(event);
457 
458  // add the FS 4-momenta to special branches
459  // Quite inelegant. Gets the job done, though
460  NTP_FS0_PDG = (event->Particle(1))->Pdg();
461  NTP_FS0_E = ((event->Particle(1))->P4())->E();
462  NTP_FS0_PX = ((event->Particle(1))->P4())->Px();
463  NTP_FS0_PY = ((event->Particle(1))->P4())->Py();
464  NTP_FS0_PZ = ((event->Particle(1))->P4())->Pz();
465  NTP_FS1_PDG = (event->Particle(2))->Pdg();
466  NTP_FS1_E = ((event->Particle(2))->P4())->E();
467  NTP_FS1_PX = ((event->Particle(2))->P4())->Px();
468  NTP_FS1_PY = ((event->Particle(2))->P4())->Py();
469  NTP_FS1_PZ = ((event->Particle(2))->P4())->Pz();
470  if( event->Particle(3) ){
471  NTP_FS2_PDG = (event->Particle(3))->Pdg();
472  NTP_FS2_E = ((event->Particle(3))->P4())->E();
473  NTP_FS2_PX = ((event->Particle(3))->P4())->Px();
474  NTP_FS2_PY = ((event->Particle(3))->P4())->Py();
475  NTP_FS2_PZ = ((event->Particle(3))->P4())->Pz();
476  }
477  else{
478  NTP_FS2_PDG = 0;
479  NTP_FS2_E = 0.0;
480  NTP_FS2_PX = 0.0;
481  NTP_FS2_PY = 0.0;
482  NTP_FS2_PZ = 0.0;
483  }
484 
485  // Generate (or read) a position for the decay vertex
486  // also currently handles the geometrical weight
487  TLorentzVector x4mm;
488  if( gOptUsingRootGeom ){
489  TLorentzVector * p4HNL = event->Particle(0)->GetP4();
490  NTP_IS_E = p4HNL->E(); NTP_IS_PX = p4HNL->Px(); NTP_IS_PY = p4HNL->Py(); NTP_IS_PZ = p4HNL->Pz();
491  vtxGen->ProcessEventRecord( event );
492  x4mm = *(event->Vertex());
493  } else {
494  x4mm = GeneratePosition( event );
495  }
496 
497  // update weight to scale for couplings, inhibited decays
498  // acceptance is already handled in FluxCreator
499  // geometry handled in VertexGenerator
500  evWeight = event->Weight();
502  evWeight *= 1.0 / decayMod;
503  event->SetWeight( evWeight / 1.0e+20 ); // in units of 1e+20 POT
504 
505  // store the decayMod in the second daughter's polarisation
506  event->Particle(2)->SetPolarization( 1.0, decayMod );
507 
508  // why does InitState show the wrong p4 here?
509  interaction->InitStatePtr()->SetProbeP4( *(event->Particle(0)->P4()) );
510 
511  LOG("gevgen_hnl", pDEBUG) << "Weight = " << evWeight;
512 
513  LOG("gevgen_hnl", pINFO)
514  << "Generated event: " << *event;
515 
516  // Add event at the output ntuple, refresh the mc job monitor & clean-up
517  ntpw.AddEventRecord(ievent, event);
518  mcjmonitor.Update(ievent,event);
519 
520  delete event;
521 
522  ievent++;
523  } // event loop
524 
525  // Save the generated event tree & close the output file
526  ntpw.Save();
527 
528  LOG("gevgen_hnl", pNOTICE) << "Done!";
529 
530  return 0;
531 }
void RandGen(long int seed)
Definition: AppInit.cxx:30
double NTP_IS_PX
HNLDecayMode_t gOptDecayMode
double CoMLifetime
TLorentzVector GeneratePosition(GHepRecord *event)
virtual void SetWeight(double wght)
Definition: GHepRecord.h:130
Heavy Neutral Lepton final-state product generator.
Definition: HNLDecayer.h:41
Heavy Neutral Lepton decay vertex generator given production vertex and momentum ***.
double NTP_FS1_PX
string gOptEvFilePrefix
Definition: gAtmoEvGen.cxx:310
void SetProbeP4(const TLorentzVector &P4)
Defines the EventRecordVisitorI interface. Concrete implementations of this interface use the &#39;Visito...
double gOptECoupling
double decayMod
HNL object.
Definition: SimpleHNL.h:36
A GENIE flux container specific for HNL containers. Based on the dk2nu flux paradigm and genie::flux:...
string P4AsString(const TLorentzVector *p)
Definition: PrintUtils.cxx:27
Algorithm abstract base class.
Definition: Algorithm.h:54
int NTP_FS0_PDG
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
double NTP_FS0_PX
bool gOptIsMajorana
double NTP_IS_E
double evWeight
Summary information for an interaction.
Definition: Interaction.h:56
Simple class to create &amp; update MC job status files and env. vars. This is used to be able to keep tr...
Definition: GMCJMonitor.h:31
Calculates HNL production kinematics &amp; production vertex. Is a concrete implementation of the FluxRec...
double NTP_IS_PY
const double e
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
double NTP_FS2_PY
double gOptEnergyHNL
double NTP_FS2_PX
int gOptNev
Definition: gAtmoEvGen.cxx:305
const int kPdgKP
Definition: PDGCodes.h:172
const int kPdgHNL
Definition: PDGCodes.h:224
enum genie::hnl::EHNLDecayMode HNLDecayMode_t
#define pINFO
Definition: Messenger.h:62
double NTP_IS_PZ
double NTP_FS0_PY
string gOptRootGeom
Definition: gAtmoEvGen.cxx:300
#define pWARN
Definition: Messenger.h:60
Long_t gOptRunNu
Definition: gAtmoEvGen.cxx:295
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
double gOptTCoupling
double NTP_FS2_PZ
A utility class to facilitate creating the GENIE MC Ntuple from the output GENIE GHEP event records...
Definition: NtpWriter.h:39
static __attribute__((unused)) double fDecayGammas[]
double NTP_FS2_E
double gOptMCoupling
double NTP_FS0_E
bool gOptIsMonoEnFlux
double NTP_FS1_PY
double NTP_FS1_E
string kDefOptSConfig
NtpMCFormat_t kDefOptNtpFormat
Definition: gAtmoEvGen.cxx:319
InitialState * InitStatePtr(void) const
Definition: Interaction.h:74
int SelectDecayMode(std::vector< HNLDecayMode_t > *intChannels, SimpleHNL sh)
vector< vector< double > > clear
void SetProbePdg(int pdg_code)
void MesgThresholds(string inpfile)
Definition: AppInit.cxx:99
const EventRecordVisitorI * HNLGenerator(void)
#define pNOTICE
Definition: Messenger.h:61
void GetCommandLineArgs(int argc, char **argv)
Definition: gAtmoEvGen.cxx:563
The GENIE Algorithm Factory.
Definition: AlgFactory.h:39
double NTP_FS1_PZ
int NTP_FS1_PDG
int NTP_FS2_PDG
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
double gOptMassHNL
double NTP_FS0_PZ
std::vector< HNLDecayMode_t > gOptIntChannels
bool gOptUsingRootGeom
Definition: gAtmoEvGen.cxx:298
#define pDEBUG
Definition: Messenger.h:63
long int gOptRanSeed
Definition: gAtmoEvGen.cxx:312
void PrintSyntax ( void  )
int SelectDecayMode ( std::vector< HNLDecayMode_t > *  intChannels,
SimpleHNL  sh 
)

Definition at line 756 of file gBeamHNLEvGen.cxx.

References genie::utils::hnl::AsString(), CoMLifetime, decayMod, genie::hnl::SimpleHNL::GetCoMLifetime(), genie::hnl::selector::GetProbabilities(), genie::hnl::SimpleHNL::GetValidChannels(), gOptMassHNL, genie::RandomGen::Instance(), genie::utils::hnl::IsKinematicallyAllowed(), LOG, pDEBUG, pFATAL, genie::RandomGen::RndGen(), genie::hnl::selector::SelectChannelInclusive(), genie::hnl::selector::SetInterestingChannels(), and genie::hnl::SimpleHNL::SetInterestingChannels().

Referenced by main().

757 {
758  const std::map< HNLDecayMode_t, double > gammaMap = sh.GetValidChannels();
759 
760  // set CoM lifetime now if unset
761  if( CoMLifetime < 0.0 ){
763  }
764 
765  std::vector< HNLDecayMode_t > intAndValidChannels;
766  for( std::vector< HNLDecayMode_t >::iterator it = intChannels->begin(); it != intChannels->end(); ++it ){
767  HNLDecayMode_t mode = *it;
768 
769  //check if this is a valid mode
770  if( !utils::hnl::IsKinematicallyAllowed( mode, gOptMassHNL ) ) continue;
771 
772  intAndValidChannels.emplace_back( mode );
773  auto mapG = gammaMap.find( mode );
774  double theGamma = mapG->second;
775  LOG("gevgen_hnl", pDEBUG)
776  << "For mode " << utils::hnl::AsString( mode ) << " gamma = " << theGamma;
777  }
778 
779  if( intAndValidChannels.size() == 0 ){ // all the modes picked by user are too heavy. Abort.
780  LOG( "gevgen_hnl", pFATAL )
781  << "None of the channels specified as interesting are kinematically allowed. Please either increase the HNL mass or change interesting channels in config.";
782  exit(1);
783  }
784 
785  std::map< HNLDecayMode_t, double > intMap =
786  selector::SetInterestingChannels( intAndValidChannels, gammaMap );
787 
788  sh.SetInterestingChannels( intMap );
789 
790  // update fraction of total decay width that is not in inhibited channels
791  double gammaAll = 0.0, gammaInt = 0.0;
792  for( std::map< HNLDecayMode_t, double >::const_iterator itall = gammaMap.begin() ;
793  itall != gammaMap.end() ; ++itall ){
794  gammaAll += (*itall).second;
795  }
796  for( std::map< HNLDecayMode_t, double >::iterator itint = intMap.begin() ;
797  itint != intMap.end() ; ++itint ){
798  gammaInt += (*itint).second;
799  }
800  assert( gammaInt > 0.0 && gammaAll >= gammaInt );
801  decayMod = gammaInt / gammaAll;
802 
803  // get probability that channels in intAndValidChannels will be selected
804  std::map< HNLDecayMode_t, double > PMap =
805  selector::GetProbabilities( intMap );
806 
807  // now do a random throw
808  RandomGen * rnd = RandomGen::Instance();
809  double ranThrow = rnd->RndGen().Uniform( 0., 1. ); // HNL's fate is sealed.
810 
811  HNLDecayMode_t selectedDecayChan =
812  selector::SelectChannelInclusive( PMap, ranThrow );
813 
814  int decay = ( int ) selectedDecayChan;
815  return decay;
816 }
double CoMLifetime
double decayMod
#define pFATAL
Definition: Messenger.h:56
double GetCoMLifetime()
Definition: SimpleHNL.h:96
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
std::map< genie::hnl::HNLDecayMode_t, double > SetInterestingChannels(std::vector< genie::hnl::HNLDecayMode_t > intChannels, std::map< genie::hnl::HNLDecayMode_t, double > gammaMap)
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
std::map< genie::hnl::HNLDecayMode_t, double > GetValidChannels()
Definition: SimpleHNL.h:154
enum genie::hnl::EHNLDecayMode HNLDecayMode_t
void SetInterestingChannels(const std::map< genie::hnl::HNLDecayMode_t, double > gammaMap)
Definition: SimpleHNL.h:276
std::map< genie::hnl::HNLDecayMode_t, double > GetProbabilities(std::map< genie::hnl::HNLDecayMode_t, double > gammaMap)
TRandom3 & RndGen(void) const
rnd number generator for generic usage
Definition: RandomGen.h:80
const char * AsString(Resonance_t res)
resonance id -&gt; string
genie::hnl::HNLDecayMode_t SelectChannelInclusive(std::map< genie::hnl::HNLDecayMode_t, double > Pmap, double ranThrow)
double gOptMassHNL
bool IsKinematicallyAllowed(genie::hnl::HNLDecayMode_t hnldm, double Mhnl)
#define pDEBUG
Definition: Messenger.h:63

Variable Documentation

double CoMLifetime = -1.0
double decayMod = 1.0

Definition at line 214 of file gBeamHNLEvGen.cxx.

Referenced by main(), and SelectDecayMode().

double evWeight = 1.0

Definition at line 216 of file gBeamHNLEvGen.cxx.

Referenced by main().

double fdx = 0

Definition at line 198 of file gBeamHNLEvGen.cxx.

Referenced by GeneratePosition().

double fdy = 0

Definition at line 199 of file gBeamHNLEvGen.cxx.

Referenced by GeneratePosition().

double fdz = 0

Definition at line 200 of file gBeamHNLEvGen.cxx.

Referenced by GeneratePosition().

double fox = 0

Definition at line 201 of file gBeamHNLEvGen.cxx.

Referenced by GeneratePosition().

double foy = 0

Definition at line 202 of file gBeamHNLEvGen.cxx.

Referenced by GeneratePosition().

double foz = 0

Definition at line 203 of file gBeamHNLEvGen.cxx.

Referenced by GeneratePosition().

HNLDecayMode_t gOptDecayMode = kHNLDcyNull

Definition at line 181 of file gBeamHNLEvGen.cxx.

Referenced by main(), and SelectAnnihilationMode().

double gOptECoupling = -1

Definition at line 167 of file gBeamHNLEvGen.cxx.

Referenced by main().

double gOptEnergyHNL = -1

Definition at line 165 of file gBeamHNLEvGen.cxx.

Referenced by GenerateOriginMomentum(), main(), ReadInConfig(), and TestDecay().

string gOptEvFilePrefix = kDefOptEvFilePrefix

Definition at line 184 of file gBeamHNLEvGen.cxx.

double gOptGeomLUnits = 0

Definition at line 194 of file gBeamHNLEvGen.cxx.

std::vector< HNLDecayMode_t > gOptIntChannels

Definition at line 182 of file gBeamHNLEvGen.cxx.

Referenced by main().

bool gOptIsMajorana = false

Definition at line 171 of file gBeamHNLEvGen.cxx.

Referenced by main().

bool gOptIsMonoEnFlux = true

Definition at line 179 of file gBeamHNLEvGen.cxx.

Referenced by main().

double gOptMassHNL = -1

Definition at line 166 of file gBeamHNLEvGen.cxx.

Referenced by GenerateOriginMomentum(), main(), and SelectDecayMode().

double gOptMCoupling = -1

Definition at line 168 of file gBeamHNLEvGen.cxx.

Referenced by main().

int gOptNev = 10

Definition at line 163 of file gBeamHNLEvGen.cxx.

long int gOptRanSeed = -1

Definition at line 195 of file gBeamHNLEvGen.cxx.

string gOptRootGeom

Definition at line 186 of file gBeamHNLEvGen.cxx.

string gOptRootGeomTopVol = ""

Definition at line 193 of file gBeamHNLEvGen.cxx.

Long_t gOptRunNu = 1000

Definition at line 162 of file gBeamHNLEvGen.cxx.

double gOptTCoupling = -1

Definition at line 169 of file gBeamHNLEvGen.cxx.

Referenced by main().

bool gOptUsingRootGeom = false

Definition at line 185 of file gBeamHNLEvGen.cxx.

string kDefOptEvFilePrefix = "gntp"

Definition at line 154 of file gBeamHNLEvGen.cxx.

string kDefOptFluxFilePath = "./input-flux.root"

Definition at line 155 of file gBeamHNLEvGen.cxx.

string kDefOptGeomDUnits = "g_cm3"

Definition at line 152 of file gBeamHNLEvGen.cxx.

string kDefOptGeomLUnits = "mm"

Definition at line 151 of file gBeamHNLEvGen.cxx.

NtpMCFormat_t kDefOptNtpFormat = kNFGHEP

Definition at line 153 of file gBeamHNLEvGen.cxx.

string kDefOptSConfig = "BeamHNL"

Definition at line 158 of file gBeamHNLEvGen.cxx.

Referenced by HNLGenerator(), and main().

string kDefOptSName = "genie::EventGenerator"

Definition at line 157 of file gBeamHNLEvGen.cxx.

Referenced by HNLGenerator(), and main().

string kDefOptSTune = "GHNL20_00a_00_000"

Definition at line 159 of file gBeamHNLEvGen.cxx.

double NTP_FS0_E = 0.

Definition at line 206 of file gBeamHNLEvGen.cxx.

Referenced by main().

int NTP_FS0_PDG = 0

Definition at line 209 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_FS0_PX = 0.

Definition at line 206 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_FS0_PY = 0.

Definition at line 206 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_FS0_PZ = 0.

Definition at line 206 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_FS1_E = 0.

Definition at line 207 of file gBeamHNLEvGen.cxx.

Referenced by main().

int NTP_FS1_PDG = 0

Definition at line 209 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_FS1_PX = 0.

Definition at line 207 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_FS1_PY = 0.

Definition at line 207 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_FS1_PZ = 0.

Definition at line 207 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_FS2_E = 0.

Definition at line 208 of file gBeamHNLEvGen.cxx.

Referenced by main().

int NTP_FS2_PDG = 0

Definition at line 209 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_FS2_PX = 0.

Definition at line 208 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_FS2_PY = 0.

Definition at line 208 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_FS2_PZ = 0.

Definition at line 208 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_IS_E = 0.

Definition at line 205 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_IS_PX = 0.

Definition at line 205 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_IS_PY = 0.

Definition at line 205 of file gBeamHNLEvGen.cxx.

Referenced by main().

double NTP_IS_PZ = 0.

Definition at line 205 of file gBeamHNLEvGen.cxx.

Referenced by main().