GMonoEnergeticFlux.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2019, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Author: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
8  University of Liverpool & STFC Rutherford Appleton Lab - July 04, 2005
9 
10  For the class documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13  @ Feb 08, 2008 - CA
14  This trivial case was added in 2.3.1 so that single energy neutrinos can
15  be easily used with the event generation driver that can handle a
16  target mix or detailed geometries.
17  @ Jun 02, 2008 - CA
18  Fix bug in Initialize() where weight was used as int
19  @ Jul 21, 2009 - RH
20  Allow a bit more flexibility by giving the user the option to set the
21  neutrino ray's direction cosines and origin.
22  @ Feb 22, 2011 - JD
23  Implemented dummy versions of the new GFluxI::Clear, GFluxI::Index and
24  GFluxI::GenerateWeighted methods needed for pre-generation of flux
25  interaction probabilities in GMCJDriver.
26 
27 */
28 //____________________________________________________________________________
29 
30 #include <cassert>
31 
38 
41 
42 using namespace genie;
43 using namespace genie::constants;
44 using namespace genie::flux;
45 
46 //____________________________________________________________________________
48 GFluxI()
49 {
50  // default ctor for consistency with GFluxDriverFactory needs
51  // up to user to call Initialize() to set energy and flavor(s)
52 }
53 //____________________________________________________________________________
54 GMonoEnergeticFlux::GMonoEnergeticFlux(double Ev, int pdg) :
55 GFluxI()
56 {
57  this->Initialize(Ev,pdg);
58 }
59 //___________________________________________________________________________
61  double Ev, const map<int,double> & numap) :
62 GFluxI()
63 {
64  this->Initialize(Ev,numap);
65 }
66 //___________________________________________________________________________
68 {
69  this->CleanUp();
70 }
71 //___________________________________________________________________________
73 {
75  double p = fProbMax * rnd->RndFlux().Rndm();
76 
77  map<int,double>::const_iterator iter;
78  for(iter = fProb.begin(); iter != fProb.end(); ++iter) {
79  int nupdgc = iter->first;
80  double prob = iter->second;
81  if (p<prob) {
82  fgPdgC = nupdgc;
83  break;
84  }
85  }
86 
87  LOG("Flux", pINFO)
88  << "Generated neutrino: "
89  << "\n pdg-code: " << fgPdgC
90  << "\n p4: " << utils::print::P4AsShortString(&fgP4)
91  << "\n x4: " << utils::print::X4AsString(&fgX4);
92 
93  return true;
94 }
95 //___________________________________________________________________________
97 {
98 // Dummy clear method needed to conform to GFluxI interface
99 //
100  LOG("Flux", pERROR) <<
101  "No Clear(Option_t * opt) method implemented for opt: "<< opt;
102 }
103 //___________________________________________________________________________
105 {
106 // Dummy implementation needed to conform to GFluxI interface
107 //
108  LOG("Flux", pERROR) <<
109  "No GenerateWeighted(bool gen_weighted) method implemented for " <<
110  "gen_weighted: " << gen_weighted;
111 }
112 //___________________________________________________________________________
113 void GMonoEnergeticFlux::Initialize(double Ev, int pdg)
114 {
115  map<int,double> numap;
116  numap.insert( map<int, double>::value_type(pdg, 1.) );
117 
118  this->Initialize(Ev,numap);
119 }
120 //___________________________________________________________________________
121 void GMonoEnergeticFlux::Initialize(double Ev, const map<int,double> & numap)
122 {
123  LOG("Flux", pNOTICE) << "Initializing GMonoEnergeticFlux driver";
124 
125  fMaxEv = Ev + 0.05;
126 
127  fPdgCList = new PDGCodeList;
128  fPdgCList->clear();
129 
130  fProbMax = 0;
131  fProb.clear();
132 
133  map<int,double>::const_iterator iter;
134  for(iter = numap.begin(); iter != numap.end(); ++iter) {
135  int nupdgc = iter->first;
136  double nuwgt = iter->second;
137 
138  fPdgCList->push_back(nupdgc);
139 
140  fProbMax+=nuwgt;
141  fProb.insert(map<int, double>::value_type(nupdgc,fProbMax));
142  }
143 
144  fgPdgC = 0;
145  fgP4.SetPxPyPzE (0.,0.,Ev,Ev);
146  fgX4.SetXYZT (0.,0.,0.,0.);
147 }
148 //___________________________________________________________________________
150 {
151  LOG("Flux", pNOTICE) << "Cleaning up...";
152 
153  if (fPdgCList) delete fPdgCList;
154 }
155 //___________________________________________________________________________
156 void GMonoEnergeticFlux::SetDirectionCos(double dx, double dy, double dz)
157 {
158  TVector3 dircos1 = TVector3(dx,dy,dz).Unit();
159  LOG("Flux", pNOTICE) << "SetDirectionCos "
160  << utils::print::P3AsString(&dircos1);
161  double E = fgP4.E();
162  fgP4.SetVect(E*dircos1);
163 
164 }
165 //___________________________________________________________________________
166 void GMonoEnergeticFlux::SetRayOrigin(double x, double y, double z)
167 {
168  TVector3 xyz(x,y,z);
169  LOG("Flux", pNOTICE) << "SetRayOrigin "
171  fgX4.SetVect(xyz);
172 }
173 //___________________________________________________________________________
174 void GMonoEnergeticFlux::SetNuDirection(const TVector3 & direction)
175 {
176  SetDirectionCos(direction.x(), direction.y(), direction.z());
177 }
178 //___________________________________________________________________________
179 void GMonoEnergeticFlux::SetBeamSpot(const TVector3 & spot)
180 {
181  SetRayOrigin(spot.x(), spot.y(), spot.z());
182 }
183 //___________________________________________________________________________
void GenerateWeighted(bool gen_weighted)
set whether to generate weighted or unweighted neutrinos
A class for generating concrete GFluxI derived classes based on the factory pattern. This code supplies a CPP macro which allows the classes to self-register and thus no modification of this class is needed in order to expand the list of classes it knows about.
string P4AsShortString(const TLorentzVector *p)
Definition: PrintUtils.cxx:52
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
#define pERROR
Definition: Messenger.h:60
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:79
int fgPdgC
running generated nu pdg-code
TLorentzVector fgP4
running generated nu 4-momentum
const char * p
Definition: xmltok.h:285
string P3AsString(const TVector3 *vec)
Definition: PrintUtils.cxx:76
bool GenerateNext(void)
generate the next flux neutrino (return false in err)
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:30
Loaders::FluxType flux
void Initialize(double Ev, int pdg)
A list of PDG codes.
Definition: PDGCodeList.h:33
void SetNuDirection(const TVector3 &direction)
void SetDirectionCos(double dx, double dy, double dz)
void SetRayOrigin(double x, double y, double z)
double dy[NP][NC]
double dx[NP][NC]
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
double dz[NP][NC]
PDGCodeList * fPdgCList
list of neutrino pdg-codes
Float_t E
Definition: plot.C:20
A simple GENIE flux driver for monoenergetic neutrinos along the z direction. Can handle a mix of neu...
#define pINFO
Definition: Messenger.h:63
z
Definition: test.py:28
TLorentzVector fgX4
running generated nu 4-position
void SetBeamSpot(const TVector3 &spot)
#define pNOTICE
Definition: Messenger.h:62
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
Definition: RandomGen.h:72
string X4AsString(const TLorentzVector *x)
Definition: PrintUtils.cxx:64
void Clear(Option_t *opt)
reset state variables based on opt
#define FLUXDRIVERREG4(_nsa, _nsb, _name, _fqname)
string Vec3AsString(const TVector3 *vec)
Definition: PrintUtils.cxx:87
void push_back(int pdg_code)
Definition: PDGCodeList.cxx:67
GENIE Interface for user-defined flux classes.
Definition: GFluxI.h:37