GENIEGenerator
Loading...
Searching...
No Matches
GPowerLawFlux.cxx
Go to the documentation of this file.
1//____________________________________________________________________________
2/*
3 Copyright (c) 2003-2025, The GENIE Collaboration
4 For the full text of the license visit http://copyright.genie-mc.org
5
6 Alfonso Garcia <aagarciasoto \at km3net.de>
7 IFIC
8*/
9//____________________________________________________________________________
10
11#include <cassert>
12
19
22
23using namespace genie;
24using namespace genie::constants;
25using namespace genie::flux;
26
27//____________________________________________________________________________
29GFluxI()
30{
31 // default ctor for consistency with GFluxDriverFactory needs
32 // up to user to call Initialize() to set energy and flavor(s)
33}
34//____________________________________________________________________________
35GPowerLawFlux::GPowerLawFlux(double alpha, double emin, double emax, int pdg) :
36GFluxI()
37{
38 this->Initialize(alpha,emin,emax,pdg);
39}
40//___________________________________________________________________________
42 double alpha, double emin, double emax, const map<int,double> & numap) :
43GFluxI()
44{
45 this->Initialize(alpha,emin,emax,numap);
46}
47//___________________________________________________________________________
52//___________________________________________________________________________
54{
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}
86//___________________________________________________________________________
87void GPowerLawFlux::Clear(Option_t * opt)
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}
94//___________________________________________________________________________
95void GPowerLawFlux::GenerateWeighted(bool gen_weighted)
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}
103//___________________________________________________________________________
104void GPowerLawFlux::Initialize(double alpha, double emin, double emax, int pdg)
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}
111//___________________________________________________________________________
112void GPowerLawFlux::Initialize(double alpha, double emin, double emax, const map<int,double> & numap)
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
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}
143//___________________________________________________________________________
145{
146 LOG("Flux", pNOTICE) << "Cleaning up...";
147
148 if (fPdgCList) delete fPdgCList;
149}
150//___________________________________________________________________________
151void GPowerLawFlux::SetDirectionCos(double dx, double dy, double dz)
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}
160//___________________________________________________________________________
161void GPowerLawFlux::SetRayOrigin(double x, double y, double z)
162{
163 TVector3 xyz(x,y,z);
164 LOG("Flux", pNOTICE) << "SetRayOrigin "
166 fgX4.SetVect(xyz);
167}
168//___________________________________________________________________________
169void GPowerLawFlux::SetNuDirection(const TVector3 & direction)
170{
171 SetDirectionCos(direction.x(), direction.y(), direction.z());
172}
173//___________________________________________________________________________
174void GPowerLawFlux::SetBeamSpot(const TVector3 & spot)
175{
176 SetRayOrigin(spot.x(), spot.y(), spot.z());
177}
178//___________________________________________________________________________
#define FLUXDRIVERREG4(_nsa, _nsb, _name, _fqname)
#define pNOTICE
Definition Messenger.h:61
#define pINFO
Definition Messenger.h:62
#define pERROR
Definition Messenger.h:59
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
A list of PDG codes.
Definition PDGCodeList.h:32
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition RandomGen.h:29
static RandomGen * Instance()
Access instance.
Definition RandomGen.cxx:74
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
Definition RandomGen.h:71
A simple GENIE flux driver for neutrinos following a power law spectrum. Can handle a mix of neutrino...
void Initialize(double alpha, double emin, double emax, int pdg)
double fMaxEv
maximum energy
void SetNuDirection(const TVector3 &direction)
bool GenerateNext(void)
generate the next flux neutrino (return false in err)
double fSpectralIndex
spectral index (E^{-alpha})
TLorentzVector fgX4
running generated nu 4-position
void SetDirectionCos(double dx, double dy, double dz)
TLorentzVector fgP4
running generated nu 4-momentum
int fgPdgC
running generated nu pdg-code
map< int, double > fProb
cumulative probability of neutrino types
void GenerateWeighted(bool gen_weighted)
set whether to generate weighted or unweighted neutrinos
void SetRayOrigin(double x, double y, double z)
void SetBeamSpot(const TVector3 &spot)
PDGCodeList * fPdgCList
list of neutrino pdg-codes
void Clear(Option_t *opt)
reset state variables based on opt
double fMinEv
minimum energy
void Initialize(void)
Basic constants.
GENIE flux drivers.
Utilities for improving the code readability when using PDG codes.
string Vec3AsString(const TVector3 *vec)
string X4AsString(const TLorentzVector *x)
string P3AsString(const TVector3 *vec)
string P4AsShortString(const TLorentzVector *p)
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25