GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GPowerLawFlux.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, 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 
23 using namespace genie;
24 using namespace genie::constants;
25 using namespace genie::flux;
26 
27 //____________________________________________________________________________
29 GFluxI()
30 {
31  // default ctor for consistency with GFluxDriverFactory needs
32  // up to user to call Initialize() to set energy and flavor(s)
33 }
34 //____________________________________________________________________________
35 GPowerLawFlux::GPowerLawFlux(double alpha, double emin, double emax, int pdg) :
36 GFluxI()
37 {
38  this->Initialize(alpha,emin,emax,pdg);
39 }
40 //___________________________________________________________________________
42  double alpha, double emin, double emax, const map<int,double> & numap) :
43 GFluxI()
44 {
45  this->Initialize(alpha,emin,emax,numap);
46 }
47 //___________________________________________________________________________
49 {
50  this->CleanUp();
51 }
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 //___________________________________________________________________________
87 void 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 //___________________________________________________________________________
95 void 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 //___________________________________________________________________________
104 void 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 //___________________________________________________________________________
112 void 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 
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 }
143 //___________________________________________________________________________
145 {
146  LOG("Flux", pNOTICE) << "Cleaning up...";
147 
148  if (fPdgCList) delete fPdgCList;
149 }
150 //___________________________________________________________________________
151 void 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 //___________________________________________________________________________
161 void 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 //___________________________________________________________________________
169 void GPowerLawFlux::SetNuDirection(const TVector3 & direction)
170 {
171  SetDirectionCos(direction.x(), direction.y(), direction.z());
172 }
173 //___________________________________________________________________________
174 void GPowerLawFlux::SetBeamSpot(const TVector3 & spot)
175 {
176  SetRayOrigin(spot.x(), spot.y(), spot.z());
177 }
178 //___________________________________________________________________________
void SetRayOrigin(double x, double y, double z)
string P4AsShortString(const TLorentzVector *p)
Definition: PrintUtils.cxx:45
#define pERROR
Definition: Messenger.h:59
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:71
string P3AsString(const TVector3 *vec)
Definition: PrintUtils.cxx:69
map< int, double > fProb
cumulative probability of neutrino types
Definition: GPowerLawFlux.h:81
A simple GENIE flux driver for neutrinos following a power law spectrum. Can handle a mix of neutrino...
Definition: GPowerLawFlux.h:36
PDGCodeList * fPdgCList
list of neutrino pdg-codes
Definition: GPowerLawFlux.h:77
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
A list of PDG codes.
Definition: PDGCodeList.h:32
double fSpectralIndex
spectral index (E^{-alpha})
Definition: GPowerLawFlux.h:74
TLorentzVector fgX4
running generated nu 4-position
Definition: GPowerLawFlux.h:80
void Clear(Option_t *opt)
reset state variables based on opt
double fMaxEv
maximum energy
Definition: GPowerLawFlux.h:76
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool GenerateNext(void)
generate the next flux neutrino (return false in err)
void SetNuDirection(const TVector3 &direction)
#define pINFO
Definition: Messenger.h:62
void SetDirectionCos(double dx, double dy, double dz)
int fgPdgC
running generated nu pdg-code
Definition: GPowerLawFlux.h:78
void GenerateWeighted(bool gen_weighted)
set whether to generate weighted or unweighted neutrinos
void SetBeamSpot(const TVector3 &spot)
#define pNOTICE
Definition: Messenger.h:61
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
Definition: RandomGen.h:71
string X4AsString(const TLorentzVector *x)
Definition: PrintUtils.cxx:57
void Initialize(double alpha, double emin, double emax, int pdg)
#define FLUXDRIVERREG4(_nsa, _nsb, _name, _fqname)
string Vec3AsString(const TVector3 *vec)
Definition: PrintUtils.cxx:80
double fMinEv
minimum energy
Definition: GPowerLawFlux.h:75
void push_back(int pdg_code)
Definition: PDGCodeList.cxx:58
GENIE Interface for user-defined flux classes.
Definition: GFluxI.h:29
TLorentzVector fgP4
running generated nu 4-momentum
Definition: GPowerLawFlux.h:79