GENIEGenerator
Loading...
Searching...
No Matches
VertexGenerator.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 Costas Andreopoulos <c.andreopoulos \at cern.ch>
7 University of Liverpool
8*/
9//____________________________________________________________________________
10
11#include <TMath.h>
12
27
28using namespace genie;
29using namespace genie::utils;
30using namespace genie::controls;
31using namespace genie::constants;
32
33//___________________________________________________________________________
35EventRecordVisitorI("genie::VertexGenerator")
36{
37
38}
39//___________________________________________________________________________
41EventRecordVisitorI("genie::VertexGenerator", config)
42{
43
44}
45//___________________________________________________________________________
50//___________________________________________________________________________
52{
53// generate a vtx and set it to all GHEP physical particles
54 Interaction * interaction = evrec->Summary();
55 GHepParticle * nucltgt = evrec->TargetNucleus();
56 TVector3 vtx(9999999.,999999.,999999.);
57 if(!nucltgt){
58 vtx.SetXYZ(0.,0.,0.);
59 }else{
60 double A = nucltgt->A();
61 vtx = GenerateVertex(interaction,A);
62 }
63
64 // Copy the vertex info to the particles already in the event record
65 //
66 TObjArrayIter piter(evrec);
67 GHepParticle * p = 0;
68 while( (p = (GHepParticle *) piter.Next()) )
69 {
70 if(pdg::IsPseudoParticle(p->Pdg())) continue;
71 if(pdg::IsIon (p->Pdg())) continue;
72
73 LOG("Vtx", pINFO) << "Setting vertex position for: " << p->Name();
74 p->SetPosition(vtx.x(), vtx.y(), vtx.z(), 0.);
75 }
76}
77//___________________________________________________________________________
83//____________________________________________________________________________
89//____________________________________________________________________________
91{
92
93 GetParam( "VtxGenerationMethod", fVtxGenMethod ) ;
94 GetParam( "NUCL-R0", fR0 ) ; //fm
95
96}
97//____________________________________________________________________________
98TVector3 VertexGenerator::GenerateVertex(const Interaction * interaction,
99 double A) const{
101 TVector3 vtx(999999.,999999.,999999.);
102
103 //GHepParticle * nucltgt = evrec->TargetNucleus();
104
105 bool uniform = fVtxGenMethod==0;
106 bool realistic = !uniform;
107
108 //if(!nucltgt) {
109 //vtx.SetXYZ(0.,0.,0.);
110 //}
111 //else {
112 //double A = nucltgt->A();
113 double R = fR0 * TMath::Power(A, 1./3.);
114
115 //Interaction * interaction = evrec->Summary();
116 const ProcessInfo & proc_info = interaction->ProcInfo();
117 bool is_coh = proc_info.IsCoherentProduction() || proc_info.IsCoherentElastic();
118 bool is_ve = proc_info.IsInverseMuDecay() ||
119 proc_info.IsIMDAnnihilation() ||
120 proc_info.IsNuElectronElastic() ||
121 proc_info.IsGlashowResonance() ||
122 proc_info.IsPhotonResonance() ||
123 proc_info.IsPhotonCoherent();
124
125 if(is_coh||is_ve) {
126 // ** For COH or ve- set a vertex positon on the nuclear boundary
127 //
128 LOG("Vtx", pINFO) << "Setting vertex on the nuclear boundary";
129 double phi = 2*kPi * rnd->RndFsi().Rndm();
130 double cosphi = TMath::Cos(phi);
131 double sinphi = TMath::Sin(phi);
132 double costheta = -1 + 2 * rnd->RndFsi().Rndm();
133 double sintheta = TMath::Sqrt(1-costheta*costheta);
134 vtx.SetX(R*sintheta*cosphi);
135 vtx.SetY(R*sintheta*sinphi);
136 vtx.SetZ(R*costheta);
137 }
138 else {
139 // ** For other events on nuclear targets set the interaction vertex
140 // ** using the requested method: either using a realistic nuclear
141 // ** density or by setting it uniformly within the nucleus
142 //
143 if(realistic) {
144 // Generate the vertex using a realistic nuclear density
145 //
146 LOG("Vtx", pINFO)
147 << "Generating vertex according to a realistic nuclear density profile";
148 // get inputs to the rejection method
149 double ymax = -1;
150 double rmax = 3*R;
151 double dr = R/40.;
152 for(double r = 0; r < rmax; r+=dr) {
153 ymax = TMath::Max(ymax, r*r * utils::nuclear::Density(r,(int)A));
154 }
155 ymax *= 1.2;
156
157 // select a vertex using the rejection method
158 unsigned int iter = 0;
159 while(1) {
160 iter++;
161
162 // throw an exception if it hasn't find a solution after many attempts
163 if(iter > kRjMaxIterations) {
164 LOG("Vtx", pWARN)
165 << "Couldn't generate a vertex position after " << iter << " iterations";
166 //evrec->EventFlags()->SetBitNumber(kGenericErr, true);
168 exception.SetReason("Couldn't generate vertex");
169 exception.SwitchOnFastForward();
170 throw exception;
171 }
172
173 double r = rmax * rnd->RndFsi().Rndm();
174 double t = ymax * rnd->RndFsi().Rndm();
175 double y = r*r * utils::nuclear::Density(r,(int)A);
176 if(y > ymax) {
177 LOG("Vtx", pERROR)
178 << "y = " << y << " > ymax = " << ymax
179 << " for r = " << r << ", A = " << A;
180 }
181 bool accept = (t < y);
182 if(accept) {
183 double phi = 2*kPi * rnd->RndFsi().Rndm();
184 double cosphi = TMath::Cos(phi);
185 double sinphi = TMath::Sin(phi);
186 double costheta = -1 + 2 * rnd->RndFsi().Rndm();
187 double sintheta = TMath::Sqrt(1-costheta*costheta);
188 vtx.SetX(r*sintheta*cosphi);
189 vtx.SetY(r*sintheta*sinphi);
190 vtx.SetZ(r*costheta);
191 break;
192 }
193 }//w(1)
194 } //use density?
195
196 if(uniform) {
197 // Generate the vertex uniformly within the nucleus
198 //
199 LOG("Vtx", pINFO)
200 << "Generating intranuclear vertex uniformly in volume";
201 while(vtx.Mag() > R) {
202 vtx.SetX(-R + 2*R * rnd->RndFsi().Rndm());
203 vtx.SetY(-R + 2*R * rnd->RndFsi().Rndm());
204 vtx.SetZ(-R + 2*R * rnd->RndFsi().Rndm());
205 }
206 }// uniform?
207
208 } // coh or ve-?
209 //} // nuclear target ?
210
211 LOG("Vtx", pINFO)
212 << "Generated vtx @ r = " << vtx.Mag() << " fm / "
213 << print::Vec3AsString(&vtx);
214 return vtx;
215}
#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
#define pWARN
Definition Messenger.h:60
bool GetParam(const RgKey &name, T &p, bool is_top_call=true) const
virtual void Configure(const Registry &config)
Definition Algorithm.cxx:62
STDHEP-like event record entry that can fit a particle or a nucleus.
string Name(void) const
Name that corresponds to the PDG code.
void SetPosition(const TLorentzVector &v4)
int Pdg(void) const
int A(void) const
GENIE's GHEP MC event record.
Definition GHepRecord.h:45
virtual GHepParticle * TargetNucleus(void) const
virtual Interaction * Summary(void) const
Summary information for an interaction.
Definition Interaction.h:56
const ProcessInfo & ProcInfo(void) const
Definition Interaction.h:70
A class encapsulating an enumeration of interaction types (EM, Weak-CC, Weak-NC) and scattering types...
Definition ProcessInfo.h:46
bool IsPhotonResonance(void) const
bool IsNuElectronElastic(void) const
bool IsInverseMuDecay(void) const
bool IsCoherentElastic(void) const
bool IsPhotonCoherent(void) const
bool IsCoherentProduction(void) const
bool IsIMDAnnihilation(void) const
bool IsGlashowResonance(void) const
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 & RndFsi(void) const
rnd number generator used by intranuclear cascade monte carlos
Definition RandomGen.h:59
A registry. Provides the container for algorithm configuration parameters.
Definition Registry.h:65
void Configure(const Registry &config)
double fR0
parameter controlling nuclear sizes
TVector3 GenerateVertex(const Interaction *in, double A) const
int fVtxGenMethod
vtx generation method (0: uniform, 1: according to nuclear density [def])
void ProcessEventRecord(GHepRecord *event_rec) const
An exception thrown by EventRecordVisitorI when the normal processing sequence has to be disrupted (f...
Basic constants.
Misc GENIE control constants.
static const unsigned int kRjMaxIterations
Definition Controls.h:26
bool IsIon(int pdgc)
Definition PDGUtils.cxx:42
bool IsPseudoParticle(int pdgc)
Definition PDGUtils.cxx:27
Simple functions for loading and reading nucleus dependent keys from config files.
double Density(double r, int A, double ring=0.)
string Vec3AsString(const TVector3 *vec)
Root of GENIE utility namespaces.
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25