GMonoEnergeticFlux.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2020, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
7  University of Liverpool & STFC Rutherford Appleton Laboratory
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 GMonoEnergeticFlux::GMonoEnergeticFlux(double Ev, int pdg) :
36 GFluxI()
37 {
38  this->Initialize(Ev,pdg);
39 }
40 //___________________________________________________________________________
42  double Ev, const map<int,double> & numap) :
43 GFluxI()
44 {
45  this->Initialize(Ev,numap);
46 }
47 //___________________________________________________________________________
49 {
50  this->CleanUp();
51 }
52 //___________________________________________________________________________
54 {
56  double p = fProbMax * rnd->RndFlux().Rndm();
57 
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  LOG("Flux", pINFO)
69  << "Generated neutrino: "
70  << "\n pdg-code: " << fgPdgC
71  << "\n p4: " << utils::print::P4AsShortString(&fgP4)
72  << "\n x4: " << utils::print::X4AsString(&fgX4);
73 
74  return true;
75 }
76 //___________________________________________________________________________
78 {
79 // Dummy clear method needed to conform to GFluxI interface
80 //
81  LOG("Flux", pERROR) <<
82  "No Clear(Option_t * opt) method implemented for opt: "<< opt;
83 }
84 //___________________________________________________________________________
85 void GMonoEnergeticFlux::GenerateWeighted(bool gen_weighted)
86 {
87 // Dummy implementation needed to conform to GFluxI interface
88 //
89  LOG("Flux", pERROR) <<
90  "No GenerateWeighted(bool gen_weighted) method implemented for " <<
91  "gen_weighted: " << gen_weighted;
92 }
93 //___________________________________________________________________________
94 void GMonoEnergeticFlux::Initialize(double Ev, int pdg)
95 {
96  map<int,double> numap;
97  numap.insert( map<int, double>::value_type(pdg, 1.) );
98 
99  this->Initialize(Ev,numap);
100 }
101 //___________________________________________________________________________
102 void GMonoEnergeticFlux::Initialize(double Ev, const map<int,double> & numap)
103 {
104  LOG("Flux", pNOTICE) << "Initializing GMonoEnergeticFlux driver";
105 
106  fMaxEv = Ev + 0.05;
107 
108  fPdgCList = new PDGCodeList;
109  fPdgCList->clear();
110 
111  fProbMax = 0;
112  fProb.clear();
113 
115  for(iter = numap.begin(); iter != numap.end(); ++iter) {
116  int nupdgc = iter->first;
117  double nuwgt = iter->second;
118 
119  fPdgCList->push_back(nupdgc);
120 
121  fProbMax+=nuwgt;
122  fProb.insert(map<int, double>::value_type(nupdgc,fProbMax));
123  }
124 
125  fgPdgC = 0;
126  fgP4.SetPxPyPzE (0.,0.,Ev,Ev);
127  fgX4.SetXYZT (0.,0.,0.,0.);
128 }
129 //___________________________________________________________________________
131 {
132  LOG("Flux", pNOTICE) << "Cleaning up...";
133 
134  if (fPdgCList) delete fPdgCList;
135 }
136 //___________________________________________________________________________
137 void GMonoEnergeticFlux::SetDirectionCos(double dx, double dy, double dz)
138 {
139  TVector3 dircos1 = TVector3(dx,dy,dz).Unit();
140  LOG("Flux", pNOTICE) << "SetDirectionCos "
141  << utils::print::P3AsString(&dircos1);
142  double E = fgP4.E();
143  fgP4.SetVect(E*dircos1);
144 
145 }
146 //___________________________________________________________________________
147 void GMonoEnergeticFlux::SetRayOrigin(double x, double y, double z)
148 {
149  TVector3 xyz(x,y,z);
150  LOG("Flux", pNOTICE) << "SetRayOrigin "
152  fgX4.SetVect(xyz);
153 }
154 //___________________________________________________________________________
156 {
157  SetDirectionCos(direction.x(), direction.y(), direction.z());
158 }
159 //___________________________________________________________________________
160 void GMonoEnergeticFlux::SetBeamSpot(const TVector3 & spot)
161 {
162  SetRayOrigin(spot.x(), spot.y(), spot.z());
163 }
164 //___________________________________________________________________________
void GenerateWeighted(bool gen_weighted)
set whether to generate weighted or unweighted neutrinos
string P4AsShortString(const TLorentzVector *p)
Definition: PrintUtils.cxx:45
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
#define pERROR
Definition: Messenger.h:59
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:71
int fgPdgC
running generated nu pdg-code
TLorentzVector fgP4
running generated nu 4-momentum
opt
Definition: train.py:196
string P3AsString(const TVector3 *vec)
Definition: PrintUtils.cxx:69
intermediate_table::const_iterator const_iterator
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:29
void Initialize(double Ev, int pdg)
A list of PDG codes.
Definition: PDGCodeList.h:32
void SetNuDirection(const TVector3 &direction)
void SetDirectionCos(double dx, double dy, double dz)
void SetRayOrigin(double x, double y, double z)
#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
A simple GENIE flux driver for monoenergetic neutrinos along the z direction. Can handle a mix of neu...
p
Definition: test.py:223
#define pINFO
Definition: Messenger.h:62
list x
Definition: train.py:276
TLorentzVector fgX4
running generated nu 4-position
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 Clear(Option_t *opt)
reset state variables based on opt
#define FLUXDRIVERREG4(_nsa, _nsb, _name, _fqname)
string Vec3AsString(const TVector3 *vec)
Definition: PrintUtils.cxx:80
void push_back(int pdg_code)
Definition: PDGCodeList.cxx:58
GENIE Interface for user-defined flux classes.
Definition: GFluxI.h:29