GENIEGenerator
Loading...
Searching...
No Matches
GFluxBlender.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 Robert Hatcher <rhatcher@fnal.gov>
7 Fermi National Accelerator Laboratory
8*/
9//____________________________________________________________________________
10
11#include <math.h>
12#include <iostream>
13#include <iomanip>
14
15//GENIE includes
20
24#define LOG_BEGIN(a,b) LOG(a,b)
25#define LOG_END ""
26
27namespace genie {
28namespace flux {
29
30//____________________________________________________________________________
31
47
49{
50 if ( fRealGFluxI ) { delete fRealGFluxI; fRealGFluxI = 0; }
51 if ( fFlavorMixer ) { delete fFlavorMixer; fFlavorMixer = 0; }
52}
53
54//____________________________________________________________________________
56{
57 /// Return (reference to) list of possible neutrinos *after* mixing.
58 /// These are PDG code that might be interacted.
59
60 // this is only ever called by GMCJDriver::GetParticleLists()
61 // during GMCJDriver::Configure() which should happen just once
62 // so don't try to be too clever.
63 fPDGListGenerator = fRealGFluxI->FluxParticles();
64
65 // okay, really stupid at this time ...
66 fPDGListMixed.clear();
67 fPDGListMixed.push_back(kPdgNuE);
68 fPDGListMixed.push_back(kPdgNuMu);
69 fPDGListMixed.push_back(kPdgNuTau);
70 fPDGListMixed.push_back(kPdgAntiNuE);
71 fPDGListMixed.push_back(kPdgAntiNuMu);
73
74 // size the probability arrays to the same number of entries
75 fNPDGOut = fPDGListMixed.size();
76 fProb.resize(fNPDGOut);
77 fSumProb.resize(fNPDGOut);
78
79 if ( ! fFlavorMixer ) return fRealGFluxI->FluxParticles();
80 else return fPDGListMixed;
81}
82
83//____________________________________________________________________________
85{
86
87 bool gen1 = false;
88 while ( ! gen1 ) {
89 if ( ! fRealGFluxI->GenerateNext() ) return false;
90 // have a new entry
91 fPdgCGenerated = fRealGFluxI->PdgCode();
92 if ( ! fFlavorMixer ) {
93 // simple case when not configured with a mixing model
95 gen1 = true;
96 } else {
97 // now pick a new flavor
99 if ( fGNuMIFlux ) fDistance = fGNuMIFlux->GetDecayDist();
100 if ( fGSimpleFlux ) fDistance = fGSimpleFlux->GetDecayDist();
101 fEnergy = fRealGFluxI->Momentum().Energy();
103 // we may have to generate a new neutrino if it oscillates away
104 // don't pass non-particles to GENIE ... it won't like it
105 gen1 = ( fPdgCMixed != 0 );
106 }
107 }
108 return true;
109}
110//____________________________________________________________________________
111void GFluxBlender::Clear(Option_t * opt)
112{
113// Clear method needed to conform to GFluxI interface
114//
115 fRealGFluxI->Clear(opt);
116}
117//____________________________________________________________________________
119{
120// Index method needed to conform to GFluxI interface
121//
122 return fRealGFluxI->Index();
123}
124//____________________________________________________________________________
125void GFluxBlender::GenerateWeighted(bool gen_weighted)
126{
127// Dummy implementation needed to conform to GFluxI interface
128//
129 LOG("FluxBlender", pERROR) <<
130 "No GenerateWeighted(bool gen_weighted) method implemented for " <<
131 "gen_weighted: " << gen_weighted;
132}
133//____________________________________________________________________________
135{
136 GFluxI* oldgen = fRealGFluxI;
138 // avoid re-casting
139 fGNuMIFlux = dynamic_cast<GNuMIFlux*>(fRealGFluxI);
140 fGSimpleFlux = dynamic_cast<GSimpleNtpFlux*>(fRealGFluxI);
141 // force evaluation of particle lists
142 this->FluxParticles();
143
144 return oldgen;
145}
146
147//____________________________________________________________________________
149{
150 GFlavorMixerI* oldmix = fFlavorMixer;
151 fFlavorMixer = mixer;
152 return oldmix;
153}
154
155//____________________________________________________________________________
156int GFluxBlender::ChooseFlavor(int pdg_init, double energy, double dist)
157{
158 // choose a new flavor
159 bool isset = false;
160 int pdg_out = 0;
161 double sumprob = 0;
162
163 fRndm = RandomGen::Instance()->RndFlux().Rndm();
164 for (size_t indx = 0; indx < fNPDGOut; ++indx ) {
165 int pdg_test = fPDGListMixed[indx];
166 double prob = fFlavorMixer->Probability(pdg_init,pdg_test,energy,dist);
167 fProb[indx] = prob;
168 sumprob += fProb[indx];
169 fSumProb[indx] = sumprob;
170 if ( ! isset && fRndm < sumprob ) {
171 isset = true;
172 pdg_out = pdg_test;
173 }
174 }
175
176 return pdg_out;
177}
178
179//____________________________________________________________________________
181{
182 LOG_BEGIN("FluxBlender", pINFO) << "GFluxBlender::PrintConfig()" << LOG_END;
183 if ( fRealGFluxI ) {
184 LOG_BEGIN("FluxBlender", pINFO)
185 << " fRealGFluxI is a \""
186 << typeid(fRealGFluxI).name() << "\""
187 << LOG_END;
188 } else {
189 LOG_BEGIN("FluxBlender", pINFO)
190 << " fRealGFluxI is not initialized" << LOG_END;
191 }
192 if ( fFlavorMixer ) {
193 LOG_BEGIN("FluxBlender", pINFO)
194 << " fFlavorMixer is a \""
195 << typeid(fFlavorMixer).name() << "\""
196 << LOG_END;
197 } else {
198 LOG_BEGIN("FluxBlender", pINFO)
199 << " fFlavorMixer is not initialized" << LOG_END;
200 }
201 LOG_BEGIN("FluxBlender", pINFO)
202 << " BaselineDist " << fBaselineDist << LOG_END;
203 LOG_BEGIN("FluxBlender", pINFO)
204 << "PDG List from Generator" << fPDGListGenerator << LOG_END;
205 LOG_BEGIN("FluxBlender", pINFO)
206 << "PDG List after mixing (n=" << fNPDGOut << ")"
208
209}
210
211//____________________________________________________________________________
212void GFluxBlender::PrintState(bool verbose)
213{
214 LOG_BEGIN("FluxBlender", pINFO) << "GFluxBlender::PrintState()" << LOG_END;
215 LOG_BEGIN("FluxBlender", pINFO)
216 << " Flavor " << fPdgCGenerated
217 << " ==> " << fPdgCMixed
218 << " (E=" << fEnergy << ", dist=" << fDistance << ")" << LOG_END;
219 if ( verbose ) {
220 LOG_BEGIN("FluxBlender", pINFO) << " Rndm = " << fRndm << LOG_END;
221 for (size_t indx = 0; indx < fNPDGOut; ++indx ) {
222 LOG_BEGIN("FluxBlender", pINFO)
223 << " [" << indx << "] "
224 << std::setw(3) << fPdgCGenerated << " => "
225 << std::setw(3) << fPDGListMixed[indx]
226 << " p = " << std::setw(10) << fProb[indx]
227 << " sum_p = " << std::setw(10) << fSumProb[indx] << LOG_END;
228 }
229 }
230}
231
232//____________________________________________________________________________
233} // namespace flux
234} // namespace genie
#define LOG_BEGIN(a, b)
#define LOG_END
#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
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils.
A list of PDG codes.
Definition PDGCodeList.h:32
static RandomGen * Instance()
Access instance.
Definition RandomGen.cxx:74
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
Definition RandomGen.h:71
GENIE interface for flavor modification.
bool GenerateNext(void)
generate the next flux neutrino (return false in err)
std::vector< double > fSumProb
cummulative probability
double fDistance
current neutrino's travel distance
int ChooseFlavor(int pdg_init, double energy, double dist)
double fRndm
random # used to make choice
double fBaselineDist
travel dist for mixing (if flux doesn't support GetDecayDist())
GSimpleNtpFlux * fGSimpleFlux
ref to avoid repeat dynamic_cast
std::vector< double > fProb
individual transition probs
const PDGCodeList & FluxParticles(void)
declare list of flux neutrinos that can be generated (for init. purposes)
int fPdgCMixed
current neutrino's new flavor
void GenerateWeighted(bool gen_weighted)
set whether to generate weighted or unweighted neutrinos
void PrintState(bool verbose=true)
GFluxI * fRealGFluxI
actual flux generator
PDGCodeList fPDGListMixed
possible flavors after mixing
void Clear(Option_t *opt)
reset state variables based on opt
long int Index(void)
returns corresponding index for current flux neutrino (e.g. for a flux ntuple returns the current ent...
double fEnergy
current neutrino's energy
GFluxI * AdoptFluxGenerator(GFluxI *generator)
return previous
GNuMIFlux * fGNuMIFlux
ref to avoid repeat dynamic_cast
GFlavorMixerI * AdoptFlavorMixer(GFlavorMixerI *mixer)
return previous
PDGCodeList fPDGListGenerator
possible flavors from generator
int fPdgCGenerated
current neutrino's original flavor
GFlavorMixerI * fFlavorMixer
flavor modification schema
A GENIE flux driver encapsulating the NuMI neutrino flux. It reads-in the official GNUMI neutrino flu...
Definition GNuMIFlux.h:221
A GENIE flux driver using a simple ntuple format.
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25
const int kPdgAntiNuE
Definition PDGCodes.h:29
const int kPdgAntiNuTau
Definition PDGCodes.h:33
const int kPdgNuE
Definition PDGCodes.h:28
const int kPdgNuTau
Definition PDGCodes.h:32
const int kPdgAntiNuMu
Definition PDGCodes.h:31
const int kPdgNuMu
Definition PDGCodes.h:30
TRandom3 generator(0)