GENIEGenerator
Loading...
Searching...
No Matches
genie::flux::GPowerLawFlux Class Reference

A simple GENIE flux driver for neutrinos following a power law spectrum. Can handle a mix of neutrinos with their corresponding weight. More...

#include <GPowerLawFlux.h>

Inheritance diagram for genie::flux::GPowerLawFlux:
[legend]
Collaboration diagram for genie::flux::GPowerLawFlux:
[legend]

Public Member Functions

 GPowerLawFlux ()
 GPowerLawFlux (double alpha, double emin, double emax, int pdg)
 GPowerLawFlux (double alpha, double emin, double emax, const map< int, double > &numap)
 ~GPowerLawFlux ()
const PDGCodeList & FluxParticles (void)
 declare list of flux neutrinos that can be generated (for init. purposes)
double MaxEnergy (void)
 declare the max flux neutrino energy that can be generated (for init. purposes)
bool GenerateNext (void)
 generate the next flux neutrino (return false in err)
int PdgCode (void)
 returns the flux neutrino pdg code
double Weight (void)
 returns the flux neutrino weight (if any)
const TLorentzVector & Momentum (void)
 returns the flux neutrino 4-momentum
const TLorentzVector & Position (void)
 returns the flux neutrino 4-position (note: expect SI rather than physical units)
bool End (void)
 true if no more flux nu's can be thrown (eg reaching end of beam sim ntuples)
long int Index (void)
 returns corresponding index for current flux neutrino (e.g. for a flux ntuple returns the current entry number)
void Clear (Option_t *opt)
 reset state variables based on opt
void GenerateWeighted (bool gen_weighted)
 set whether to generate weighted or unweighted neutrinos
void SetDirectionCos (double dx, double dy, double dz)
void SetRayOrigin (double x, double y, double z)
void SetNuDirection (const TVector3 &direction)
void SetBeamSpot (const TVector3 &spot)
void Initialize (double alpha, double emin, double emax, int pdg)
void Initialize (double alpha, double emin, double emax, const map< int, double > &numap)
Public Member Functions inherited from genie::GFluxI
virtual ~GFluxI ()

Private Member Functions

void CleanUp (void)

Private Attributes

double fSpectralIndex
 spectral index (E^{-alpha})
double fMinEv
 minimum energy
double fMaxEv
 maximum energy
PDGCodeList * fPdgCList
 list of neutrino pdg-codes
int fgPdgC
 running generated nu pdg-code
TLorentzVector fgP4
 running generated nu 4-momentum
TLorentzVector fgX4
 running generated nu 4-position
map< int, double > fProb
 cumulative probability of neutrino types
double fProbMax

Additional Inherited Members

Protected Member Functions inherited from genie::GFluxI
 GFluxI ()

Detailed Description

A simple GENIE flux driver for neutrinos following a power law spectrum. Can handle a mix of neutrinos with their corresponding weight.

Author
Alfonso Garcia <aagarciasoto \at km3net.de> IFIC
Created:\n May 02, 2023
License:\n Copyright (c) 2003-2025, The GENIE Collaboration
For the full text of the license visit http://copyright.genie-mc.org

Definition at line 36 of file GPowerLawFlux.h.

Constructor & Destructor Documentation

◆ GPowerLawFlux() [1/3]

GPowerLawFlux::GPowerLawFlux ( )

Definition at line 28 of file GPowerLawFlux.cxx.

28 :
29GFluxI()
30{
31 // default ctor for consistency with GFluxDriverFactory needs
32 // up to user to call Initialize() to set energy and flavor(s)
33}

References genie::GFluxI::GFluxI().

◆ GPowerLawFlux() [2/3]

GPowerLawFlux::GPowerLawFlux ( double alpha,
double emin,
double emax,
int pdg )

Definition at line 35 of file GPowerLawFlux.cxx.

35 :
36GFluxI()
37{
38 this->Initialize(alpha,emin,emax,pdg);
39}
void Initialize(void)

References genie::GFluxI::GFluxI(), and Initialize().

◆ GPowerLawFlux() [3/3]

GPowerLawFlux::GPowerLawFlux ( double alpha,
double emin,
double emax,
const map< int, double > & numap )

Definition at line 41 of file GPowerLawFlux.cxx.

42 :
43GFluxI()
44{
45 this->Initialize(alpha,emin,emax,numap);
46}

References genie::GFluxI::GFluxI(), and Initialize().

◆ ~GPowerLawFlux()

GPowerLawFlux::~GPowerLawFlux ( )

Definition at line 48 of file GPowerLawFlux.cxx.

49{
50 this->CleanUp();
51}

References CleanUp().

Member Function Documentation

◆ CleanUp()

void GPowerLawFlux::CleanUp ( void )
private

Definition at line 144 of file GPowerLawFlux.cxx.

145{
146 LOG("Flux", pNOTICE) << "Cleaning up...";
147
148 if (fPdgCList) delete fPdgCList;
149}
#define pNOTICE
Definition Messenger.h:61
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
PDGCodeList * fPdgCList
list of neutrino pdg-codes

References fPdgCList, LOG, and pNOTICE.

Referenced by ~GPowerLawFlux().

◆ Clear()

void GPowerLawFlux::Clear ( Option_t * opt)
virtual

reset state variables based on opt

Implements genie::GFluxI.

Definition at line 87 of file GPowerLawFlux.cxx.

88{
89// Dummy clear method needed to conform to GFluxI interface
90//
91 LOG("Flux", pERROR) <<
92 "No Clear(Option_t * opt) method implemented for opt: "<< opt;
93}
#define pERROR
Definition Messenger.h:59

References LOG, and pERROR.

◆ End()

bool genie::flux::GPowerLawFlux::End ( void )
inlinevirtual

true if no more flux nu's can be thrown (eg reaching end of beam sim ntuples)

Implements genie::GFluxI.

Definition at line 52 of file GPowerLawFlux.h.

52{ return false; }

◆ FluxParticles()

const PDGCodeList & genie::flux::GPowerLawFlux::FluxParticles ( void )
inlinevirtual

declare list of flux neutrinos that can be generated (for init. purposes)

Implements genie::GFluxI.

Definition at line 45 of file GPowerLawFlux.h.

45{ return *fPdgCList; }

References fPdgCList.

◆ GenerateNext()

bool GPowerLawFlux::GenerateNext ( void )
virtual

generate the next flux neutrino (return false in err)

Implements genie::GFluxI.

Definition at line 53 of file GPowerLawFlux.cxx.

54{
55 RandomGen * rnd = RandomGen::Instance();
56 double p = fProbMax * rnd->RndFlux().Rndm();
57
58 map<int,double>::const_iterator iter;
59 for(iter = fProb.begin(); iter != fProb.end(); ++iter) {
60 int nupdgc = iter->first;
61 double prob = iter->second;
62 if (p<prob) {
63 fgPdgC = nupdgc;
64 break;
65 }
66 }
67
68 double Ev = 0.;
69 if (fSpectralIndex==1) Ev = TMath::Exp(TMath::Log(fMinEv)+rnd->RndFlux().Rndm()*TMath::Log(fMaxEv/fMinEv));
70 else {
71 double pemin = TMath::Power(fMinEv, 1.-fSpectralIndex);
72 double pemax = TMath::Power(fMaxEv, 1.-fSpectralIndex);
73 Ev = TMath::Power(pemin+(pemax-pemin)*rnd->RndFlux().Rndm(),1./(1.-fSpectralIndex));
74 }
75
76 fgP4.SetPxPyPzE (0.,0.,Ev,Ev);
77
78 LOG("Flux", pINFO)
79 << "Generated neutrino: "
80 << "\n pdg-code: " << fgPdgC
81 << "\n p4: " << utils::print::P4AsShortString(&fgP4)
82 << "\n x4: " << utils::print::X4AsString(&fgX4);
83
84 return true;
85}
#define pINFO
Definition Messenger.h:62
static RandomGen * Instance()
Access instance.
Definition RandomGen.cxx:74
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
Definition RandomGen.h:71
double fMaxEv
maximum energy
double fSpectralIndex
spectral index (E^{-alpha})
TLorentzVector fgX4
running generated nu 4-position
TLorentzVector fgP4
running generated nu 4-momentum
int fgPdgC
running generated nu pdg-code
map< int, double > fProb
cumulative probability of neutrino types
double fMinEv
minimum energy
string X4AsString(const TLorentzVector *x)
string P4AsShortString(const TLorentzVector *p)

References fgP4, fgPdgC, fgX4, fMaxEv, fMinEv, fProb, fProbMax, fSpectralIndex, genie::RandomGen::Instance(), LOG, genie::utils::print::P4AsShortString(), pINFO, genie::RandomGen::RndFlux(), and genie::utils::print::X4AsString().

◆ GenerateWeighted()

void GPowerLawFlux::GenerateWeighted ( bool gen_weighted)
virtual

set whether to generate weighted or unweighted neutrinos

Implements genie::GFluxI.

Definition at line 95 of file GPowerLawFlux.cxx.

96{
97// Dummy implementation needed to conform to GFluxI interface
98//
99 LOG("Flux", pERROR) <<
100 "No GenerateWeighted(bool gen_weighted) method implemented for " <<
101 "gen_weighted: " << gen_weighted;
102}

References LOG, and pERROR.

◆ Index()

long int genie::flux::GPowerLawFlux::Index ( void )
inlinevirtual

returns corresponding index for current flux neutrino (e.g. for a flux ntuple returns the current entry number)

Implements genie::GFluxI.

Definition at line 53 of file GPowerLawFlux.h.

53{ return -1; }

◆ Initialize() [1/2]

void GPowerLawFlux::Initialize ( double alpha,
double emin,
double emax,
const map< int, double > & numap )

Definition at line 112 of file GPowerLawFlux.cxx.

113{
114 LOG("Flux", pNOTICE) << "Initializing GPowerLawFlux driver";
115
116 fSpectralIndex = alpha;
117 fMinEv = emin;
118 fMaxEv = emax;
119
120 LOG("Flux", pNOTICE) << "Spectral Index : " << fSpectralIndex;
121 LOG("Flux", pNOTICE) << "Energy range : " << fMinEv << " , " << fMaxEv;
122
123 fPdgCList = new PDGCodeList;
124 fPdgCList->clear();
125
126 fProbMax = 0;
127 fProb.clear();
128
129 map<int,double>::const_iterator iter;
130 for(iter = numap.begin(); iter != numap.end(); ++iter) {
131 int nupdgc = iter->first;
132 double nuwgt = iter->second;
133
134 fPdgCList->push_back(nupdgc);
135
136 fProbMax+=nuwgt;
137 fProb.insert(map<int, double>::value_type(nupdgc,fProbMax));
138 }
139
140 fgPdgC = 0;
141 fgX4.SetXYZT (0.,0.,0.,0.);
142}

References fgPdgC, fgX4, fMaxEv, fMinEv, fPdgCList, fProb, fProbMax, fSpectralIndex, LOG, and pNOTICE.

◆ Initialize() [2/2]

void GPowerLawFlux::Initialize ( double alpha,
double emin,
double emax,
int pdg )

Definition at line 104 of file GPowerLawFlux.cxx.

105{
106 map<int,double> numap;
107 numap.insert( map<int, double>::value_type(pdg, 1.) );
108
109 this->Initialize(alpha,emin,emax,numap);
110}

References Initialize().

◆ MaxEnergy()

double genie::flux::GPowerLawFlux::MaxEnergy ( void )
inlinevirtual

declare the max flux neutrino energy that can be generated (for init. purposes)

Implements genie::GFluxI.

Definition at line 46 of file GPowerLawFlux.h.

46{ return fMaxEv; }

References fMaxEv.

◆ Momentum()

const TLorentzVector & genie::flux::GPowerLawFlux::Momentum ( void )
inlinevirtual

returns the flux neutrino 4-momentum

Implements genie::GFluxI.

Definition at line 50 of file GPowerLawFlux.h.

50{ return fgP4; }

References fgP4.

◆ PdgCode()

int genie::flux::GPowerLawFlux::PdgCode ( void )
inlinevirtual

returns the flux neutrino pdg code

Implements genie::GFluxI.

Definition at line 48 of file GPowerLawFlux.h.

48{ return fgPdgC; }

References fgPdgC.

◆ Position()

const TLorentzVector & genie::flux::GPowerLawFlux::Position ( void )
inlinevirtual

returns the flux neutrino 4-position (note: expect SI rather than physical units)

Implements genie::GFluxI.

Definition at line 51 of file GPowerLawFlux.h.

51{ return fgX4; }

References fgX4.

◆ SetBeamSpot()

void GPowerLawFlux::SetBeamSpot ( const TVector3 & spot)

Definition at line 174 of file GPowerLawFlux.cxx.

175{
176 SetRayOrigin(spot.x(), spot.y(), spot.z());
177}
void SetRayOrigin(double x, double y, double z)

References SetRayOrigin().

◆ SetDirectionCos()

void GPowerLawFlux::SetDirectionCos ( double dx,
double dy,
double dz )

Definition at line 151 of file GPowerLawFlux.cxx.

152{
153 TVector3 dircos1 = TVector3(dx,dy,dz).Unit();
154 LOG("Flux", pNOTICE) << "SetDirectionCos "
155 << utils::print::P3AsString(&dircos1);
156 double E = fgP4.E();
157 fgP4.SetVect(E*dircos1);
158
159}
string P3AsString(const TVector3 *vec)

References fgP4, LOG, genie::utils::print::P3AsString(), and pNOTICE.

Referenced by SetNuDirection().

◆ SetNuDirection()

void GPowerLawFlux::SetNuDirection ( const TVector3 & direction)

Definition at line 169 of file GPowerLawFlux.cxx.

170{
171 SetDirectionCos(direction.x(), direction.y(), direction.z());
172}
void SetDirectionCos(double dx, double dy, double dz)

References SetDirectionCos().

◆ SetRayOrigin()

void GPowerLawFlux::SetRayOrigin ( double x,
double y,
double z )

Definition at line 161 of file GPowerLawFlux.cxx.

162{
163 TVector3 xyz(x,y,z);
164 LOG("Flux", pNOTICE) << "SetRayOrigin "
166 fgX4.SetVect(xyz);
167}
string Vec3AsString(const TVector3 *vec)

References fgX4, LOG, pNOTICE, and genie::utils::print::Vec3AsString().

Referenced by SetBeamSpot().

◆ Weight()

double genie::flux::GPowerLawFlux::Weight ( void )
inlinevirtual

returns the flux neutrino weight (if any)

Implements genie::GFluxI.

Definition at line 49 of file GPowerLawFlux.h.

49{ return 1.0; }

Member Data Documentation

◆ fgP4

TLorentzVector genie::flux::GPowerLawFlux::fgP4
private

running generated nu 4-momentum

Definition at line 79 of file GPowerLawFlux.h.

Referenced by GenerateNext(), Momentum(), and SetDirectionCos().

◆ fgPdgC

int genie::flux::GPowerLawFlux::fgPdgC
private

running generated nu pdg-code

Definition at line 78 of file GPowerLawFlux.h.

Referenced by GenerateNext(), Initialize(), and PdgCode().

◆ fgX4

TLorentzVector genie::flux::GPowerLawFlux::fgX4
private

running generated nu 4-position

Definition at line 80 of file GPowerLawFlux.h.

Referenced by GenerateNext(), Initialize(), Position(), and SetRayOrigin().

◆ fMaxEv

double genie::flux::GPowerLawFlux::fMaxEv
private

maximum energy

Definition at line 76 of file GPowerLawFlux.h.

Referenced by GenerateNext(), Initialize(), and MaxEnergy().

◆ fMinEv

double genie::flux::GPowerLawFlux::fMinEv
private

minimum energy

Definition at line 75 of file GPowerLawFlux.h.

Referenced by GenerateNext(), and Initialize().

◆ fPdgCList

PDGCodeList* genie::flux::GPowerLawFlux::fPdgCList
private

list of neutrino pdg-codes

Definition at line 77 of file GPowerLawFlux.h.

Referenced by CleanUp(), FluxParticles(), and Initialize().

◆ fProb

map<int, double> genie::flux::GPowerLawFlux::fProb
private

cumulative probability of neutrino types

Definition at line 81 of file GPowerLawFlux.h.

Referenced by GenerateNext(), and Initialize().

◆ fProbMax

double genie::flux::GPowerLawFlux::fProbMax
private

Definition at line 82 of file GPowerLawFlux.h.

Referenced by GenerateNext(), and Initialize().

◆ fSpectralIndex

double genie::flux::GPowerLawFlux::fSpectralIndex
private

spectral index (E^{-alpha})

Definition at line 74 of file GPowerLawFlux.h.

Referenced by GenerateNext(), and Initialize().


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