VertexGenerator.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 <TMath.h>
12 
27 
28 using namespace genie;
29 using namespace genie::utils;
30 using namespace genie::controls;
31 using namespace genie::constants;
32 
33 //___________________________________________________________________________
35 EventRecordVisitorI("genie::VertexGenerator")
36 {
37 
38 }
39 //___________________________________________________________________________
41 EventRecordVisitorI("genie::VertexGenerator", config)
42 {
43 
44 }
45 //___________________________________________________________________________
47 {
48 
49 }
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 //___________________________________________________________________________
79 {
80  Algorithm::Configure(config);
81  this->LoadConfig();
82 }
83 //____________________________________________________________________________
85 {
86  Algorithm::Configure(config);
87  this->LoadConfig();
88 }
89 //____________________________________________________________________________
91 {
92 
93  GetParam( "VtxGenerationMethod", fVtxGenMethod ) ;
94  GetParam( "NUCL-R0", fR0 ) ; //fm
95 
96 }
97 //____________________________________________________________________________
99  double A) const{
100  RandomGen * rnd = RandomGen::Instance();
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 
122  if(is_coh||is_ve) {
123  // ** For COH or ve- set a vertex positon on the nuclear boundary
124  //
125  LOG("Vtx", pINFO) << "Setting vertex on the nuclear boundary";
126  double phi = 2*kPi * rnd->RndFsi().Rndm();
127  double cosphi = TMath::Cos(phi);
128  double sinphi = TMath::Sin(phi);
129  double costheta = -1 + 2 * rnd->RndFsi().Rndm();
130  double sintheta = TMath::Sqrt(1-costheta*costheta);
131  vtx.SetX(R*sintheta*cosphi);
132  vtx.SetY(R*sintheta*sinphi);
133  vtx.SetZ(R*costheta);
134  }
135  else {
136  // ** For other events on nuclear targets set the interaction vertex
137  // ** using the requested method: either using a realistic nuclear
138  // ** density or by setting it uniformly within the nucleus
139  //
140  if(realistic) {
141  // Generate the vertex using a realistic nuclear density
142  //
143  LOG("Vtx", pINFO)
144  << "Generating vertex according to a realistic nuclear density profile";
145  // get inputs to the rejection method
146  double ymax = -1;
147  double rmax = 3*R;
148  double dr = R/40.;
149  for(double r = 0; r < rmax; r+=dr) {
150  ymax = TMath::Max(ymax, r*r * utils::nuclear::Density(r,(int)A));
151  }
152  ymax *= 1.2;
153 
154  // select a vertex using the rejection method
155  unsigned int iter = 0;
156  while(1) {
157  iter++;
158 
159  // throw an exception if it hasn't find a solution after many attempts
160  if(iter > kRjMaxIterations) {
161  LOG("Vtx", pWARN)
162  << "Couldn't generate a vertex position after " << iter << " iterations";
163  //evrec->EventFlags()->SetBitNumber(kGenericErr, true);
165  exception.SetReason("Couldn't generate vertex");
166  exception.SwitchOnFastForward();
167  throw exception;
168  }
169 
170  double r = rmax * rnd->RndFsi().Rndm();
171  double t = ymax * rnd->RndFsi().Rndm();
172  double y = r*r * utils::nuclear::Density(r,(int)A);
173  if(y > ymax) {
174  LOG("Vtx", pERROR)
175  << "y = " << y << " > ymax = " << ymax
176  << " for r = " << r << ", A = " << A;
177  }
178  bool accept = (t < y);
179  if(accept) {
180  double phi = 2*kPi * rnd->RndFsi().Rndm();
181  double cosphi = TMath::Cos(phi);
182  double sinphi = TMath::Sin(phi);
183  double costheta = -1 + 2 * rnd->RndFsi().Rndm();
184  double sintheta = TMath::Sqrt(1-costheta*costheta);
185  vtx.SetX(r*sintheta*cosphi);
186  vtx.SetY(r*sintheta*sinphi);
187  vtx.SetZ(r*costheta);
188  break;
189  }
190  }//w(1)
191  } //use density?
192 
193  if(uniform) {
194  // Generate the vertex uniformly within the nucleus
195  //
196  LOG("Vtx", pINFO)
197  << "Generating intranuclear vertex uniformly in volume";
198  while(vtx.Mag() > R) {
199  vtx.SetX(-R + 2*R * rnd->RndFsi().Rndm());
200  vtx.SetY(-R + 2*R * rnd->RndFsi().Rndm());
201  vtx.SetZ(-R + 2*R * rnd->RndFsi().Rndm());
202  }
203  }// uniform?
204 
205  } // coh or ve-?
206  //} // nuclear target ?
207 
208  LOG("Vtx", pINFO)
209  << "Generated vtx @ r = " << vtx.Mag() << " fm / "
210  << print::Vec3AsString(&vtx);
211  return vtx;
212 }
TVector3 GenerateVertex(const Interaction *in, double A) const
int fVtxGenMethod
vtx generation method (0: uniform, 1: according to nuclear density [def])
double fR0
parameter controlling nuclear sizes
Basic constants.
TRandom3 & RndFsi(void) const
rnd number generator used by intranuclear cascade monte carlos
Definition: RandomGen.h:59
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
#define pERROR
Definition: Messenger.h:59
virtual Interaction * Summary(void) const
Definition: GHepRecord.cxx:91
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:71
Defines the EventRecordVisitorI interface. Concrete implementations of this interface use the &#39;Visito...
double Density(double r, int A, double ring=0.)
bool IsInverseMuDecay(void) const
bool IsCoherentProduction(void) const
Definition: ProcessInfo.cxx:99
bool IsIMDAnnihilation(void) const
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
int Pdg(void) const
Definition: GHepParticle.h:63
string Name(void) const
Name that corresponds to the PDG code.
Summary information for an interaction.
Definition: Interaction.h:56
void SetPosition(const TLorentzVector &v4)
An exception thrown by EventRecordVisitorI when the normal processing sequence has to be disrupted (f...
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool IsCoherentElastic(void) const
bool IsNuElectronElastic(void) const
static Config * config
Definition: config.cpp:1054
A class encapsulating an enumeration of interaction types (EM, Weak-CC, Weak-NC) and scattering types...
Definition: ProcessInfo.h:46
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
p
Definition: test.py:223
virtual GHepParticle * TargetNucleus(void) const
Definition: GHepRecord.cxx:286
#define pINFO
Definition: Messenger.h:62
Misc GENIE control constants.
#define pWARN
Definition: Messenger.h:60
void Configure(const Registry &config)
bool IsIon(int pdgc)
Definition: PDGUtils.cxx:39
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
bool IsPseudoParticle(int pdgc)
Definition: PDGUtils.cxx:24
#define A
Definition: memgrp.cpp:38
const ProcessInfo & ProcInfo(void) const
Definition: Interaction.h:70
int A(void) const
bool GetParam(const RgKey &name, T &p, bool is_top_call=true) const
static const unsigned int kRjMaxIterations
Definition: Controls.h:26
GENIE&#39;s GHEP MC event record.
Definition: GHepRecord.h:45
static const double kPi
Definition: Constants.h:37
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
string Vec3AsString(const TVector3 *vec)
Definition: PrintUtils.cxx:80
Root of GENIE utility namespaces.
void ProcessEventRecord(GHepRecord *event_rec) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33