GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GLRESGenerator.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Alfonso Garcia <aagarciasoto \at km3net.de>
7  IFIC & Harvard University
8 */
9 //____________________________________________________________________________
10 
11 #include <cstring>
12 
13 #include <RVersion.h>
14 #include <TClonesArray.h>
15 #include <TMath.h>
16 
30 
31 #ifdef __GENIE_PYTHIA6_ENABLED__
32 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,6)
33 #include <TMCParticle.h>
34 #else
35 #include <TMCParticle6.h>
36 #endif
37 #endif // __GENIE_PYTHIA6_ENABLED__
38 
39 using namespace genie;
40 using namespace genie::constants;
41 using namespace genie::utils::math;
42 
43 //___________________________________________________________________________
45 EventRecordVisitorI("genie::GLRESGenerator")
46 {
47  born = new Born();
48 }
49 //___________________________________________________________________________
51 EventRecordVisitorI("genie::GLRESGenerator", config)
52 {
53 
54 }
55 //___________________________________________________________________________
57 {
58 
59 }
60 //___________________________________________________________________________
63  event // avoid unused variable warning if PYTHIA6 is not enabled
64  #endif
65 ) const
66 {
67 
68 #ifdef __GENIE_PYTHIA6_ENABLED__
69 
70  Interaction * interaction = event->Summary();
71  const InitialState & init_state = interaction->InitState();
72 
73  //incoming v & struck particle & remnant nucleus
74  GHepParticle * nu = event->Probe();
75  GHepParticle * el = event->HitElectron();
76 
77  GHepParticle * target = event -> TargetNucleus();
78  if(target) event->AddParticle(target->Pdg(), kIStFinalStateNuclearRemnant, 1,-1,-1,-1, *(target->P4()), *(target->X4()) );
79 
80  TVector3 unit_nu = nu->P4()->Vect().Unit();
81 
82  long double mlout = interaction->FSPrimLepton()->Mass(); //mass of charged lepton
83  long double mlin = kElectronMass; //mass of incoming charged lepton
84 
85  long double Enuin = init_state.ProbeE(kRfLab);
86  long double s = born->GetS(mlin,Enuin);
87 
88  long double n1 = interaction->Kine().GetKV(kKVn1);
89  long double n2 = interaction->Kine().GetKV(kKVn2);
90 
91  long double costhCM = n1;
92  long double sinthCM = sqrtl(1-costhCM*costhCM);
93 
94  long double t = born->GetT(mlin,mlout,s,n1);
95  long double zeta = born->GetReAlpha()/kPi*(2.0*logl(sqrtl(-t)/kElectronMass)-1.0);
96  long double omx = powl(n2, 1.0/zeta );
97  long double s_r = s*( 1.-omx );
98 
99  // Boost velocity CM -> LAB
100  long double EnuinCM = (s_r-mlin*mlin)/sqrtl(s_r)/2.;
101  long double beta = (powl(Enuin,2)-powl(EnuinCM,2))/(powl(Enuin,2)+powl(EnuinCM,2));
102 
103  // Final state primary lepton PDG code
104  int pdgl = interaction->FSPrimLeptonPdg();
105  assert(pdgl!=0);
106 
107  if ( pdg::IsElectron(TMath::Abs(pdgl)) || pdg::IsMuon(TMath::Abs(pdgl)) || pdg::IsTau(TMath::Abs(pdgl)) ) {
108 
109  long double ElpoutCM = (s_r+mlout*mlout)/sqrtl(s_r)/2.;
110  long double EnuoutCM = (s_r-mlout*mlout)/sqrtl(s_r)/2.;
111  LongLorentzVector p4_lpout( 0., EnuoutCM*sinthCM, EnuoutCM*costhCM, ElpoutCM );
112  LongLorentzVector p4_nuout( 0., -EnuoutCM*sinthCM, -EnuoutCM*costhCM, EnuoutCM );
113 
114  p4_lpout.BoostZ(beta);
115  p4_nuout.BoostZ(beta);
116 
117  TLorentzVector p4lp_o( (double)p4_lpout.Px(), (double)p4_lpout.Py(), (double)p4_lpout.Pz(), (double)p4_lpout.E() );
118  TLorentzVector p4nu_o( (double)p4_nuout.Px(), (double)p4_nuout.Py(), (double)p4_nuout.Pz(), (double)p4_nuout.E() );
119 
120  // Randomize transverse components
121  RandomGen * rnd = RandomGen::Instance();
122  double phi = 2* kPi * rnd->RndLep().Rndm();
123  p4lp_o.RotateZ(phi);
124  p4nu_o.RotateZ(phi);
125 
126  //rotate from LAB=[0,0,Ev,Ev]->[px,py,pz,E]
127  p4lp_o.RotateUz(unit_nu);
128  p4nu_o.RotateUz(unit_nu);
129 
130  int pdgvout = 0;
131  if ( pdg::IsElectron(pdgl) ) pdgvout = kPdgAntiNuE;
132  else if ( pdg::IsPositron(pdgl) ) pdgvout = kPdgNuE;
133  else if ( pdg::IsMuon(pdgl) ) pdgvout = kPdgAntiNuMu;
134  else if ( pdg::IsAntiMuon(pdgl) ) pdgvout = kPdgNuMu;
135  else if ( pdg::IsTau(pdgl) ) pdgvout = kPdgAntiNuTau;
136  else if ( pdg::IsAntiTau(pdgl) ) pdgvout = kPdgNuTau;
137 
138  int pdgboson = pdg::IsNeutrino(init_state.ProbePdg()) ? kPdgWP : kPdgWM;
139 
140  // Create a GHepParticle and add it to the event record
141  event->AddParticle( pdgboson, kIStDecayedState, 0, -1, 5, 6, *nu->P4()+*el->P4(), *(nu->X4()) ); //W [mothers: nuebar_in,e_in][daugthers: nulbar_out,lp_out]
142  event->AddParticle( pdgl, kIStStableFinalState, 4, -1, -1, -1, p4lp_o, *(nu->X4()) );
143  event->AddParticle( pdgvout, kIStStableFinalState, 4, -1, -1, -1, p4nu_o, *(nu->X4()) );
144  event->Summary()->KinePtr()->SetFSLeptonP4(p4lp_o);
145 
146  }
147  else {
148 
149  char p6frame[10],p6nu[10],p6tgt[10];
150  strcpy(p6frame, "CMS" );
151  strcpy(p6nu, "nu_ebar" );
152  strcpy(p6tgt, "e-" );
153 
154  int def61 = fPythia->GetMSTP(61);
155  int def71 = fPythia->GetMSTP(71);
156  int def206 = fPythia->GetMDME(206,1);
157  int def207 = fPythia->GetMDME(207,1);
158  int def208 = fPythia->GetMDME(208,1);
159  fPythia->SetMSTP(61,0); // (Default=2) master switch for initial-state QCD and QED radiation.
160  fPythia->SetMSTP(71,0); // (Default=2) master switch for initial-state QCD and QED radiation.
161  fPythia->SetMDME(206,1,0); //swicht off W decay leptonic modes
162  fPythia->SetMDME(207,1,0);
163  fPythia->SetMDME(208,1,0);
164 
165  fPythia->Pyinit(p6frame, p6nu, p6tgt, sqrtl(s_r));
166  fPythia->Pyevnt();
167 
168  fPythia->SetMSTP(61,def61);
169  fPythia->SetMSTP(71,def71);
170  fPythia->SetMDME(206,1,def206);
171  fPythia->SetMDME(207,1,def207);
172  fPythia->SetMDME(208,1,def208);
173 
174  // get LUJETS record
175  fPythia->GetPrimaries();
176  TClonesArray * pythia_particles = (TClonesArray *) fPythia->ImportParticles("All");
177  int np = pythia_particles->GetEntries();
178  assert(np>0);
179 
180  TMCParticle * particle = 0;
181  TIter piter(pythia_particles);
182  while( (particle = (TMCParticle *) piter.Next()) ) {
183 
184  int pdgc = particle->GetKF();
185  int ks = particle->GetKS();
186 
187  if ( ks==21 ) { continue; } //we dont want to save first particles from pythia (init states)
188 
189  LongLorentzVector p4longo(particle->GetPx(), particle->GetPy(), particle->GetPz(), particle->GetEnergy());
190  p4longo.BoostZ(beta);
191 
192  TLorentzVector p4o( (double)p4longo.Px(), (double)p4longo.Py(), (double)p4longo.Pz(), (double)p4longo.E() );
193  p4o.RotateUz(unit_nu);
194 
195  TParticlePDG * part = PDGLibrary::Instance()->Find(pdgc);
196  if ( (ks==1 || ks==4) && p4o.E() < part->Mass() ) {
197  LOG("GLRESGenerator", pWARN) << "Putting at rest one stable particle generated by PYTHIA because E < m";
198  LOG("GLRESGenerator", pWARN) << "PDG = " << pdgc << " // State = " << ks;
199  LOG("GLRESGenerator", pWARN) << "E = " << p4o.E() << " // |p| = " << TMath::Sqrt(p4o.P());
200  LOG("GLRESGenerator", pWARN) << "p = [ " << p4o.Px() << " , " << p4o.Py() << " , " << p4o.Pz() << " ]";
201  LOG("GLRESGenerator", pWARN) << "m = " << p4o.M() << " // mpdg = " << part->Mass();
202  p4o.SetXYZT(0,0,0,part->Mass());
203  }
204 
205  // copy final state particles to the event record
207 
208  // fix numbering scheme used for mother/daughter assignments
209  int firstmother = -1;
210  int lastmother = -1;
211  int firstchild = -1;
212  int lastchild = -1;
213 
214  if ( particle->GetParent() < 10 ) {
215  if ( TMath::Abs(pdgc)<7 ) { //outgoing quarks: mother will be the boson (saved in position 4)
216  firstmother = 4;
217  firstchild = particle->GetFirstChild() - 6;
218  lastchild = particle->GetLastChild() - 6;
219  }
220  else if ( TMath::Abs(pdgc)==24 ) { //produced W boson: mother will be the incoming neutrino
221  firstmother = 0;
222  firstchild = particle->GetFirstChild() - 6;
223  lastchild = particle->GetLastChild() - 6;
224  }
225  else if ( pdgc==22 ) { //radiative photons: mother will be the incoming electron
226  firstmother = 2;
227  }
228  }
229  else { //rest
230  firstmother = particle->GetParent() - 6; //shift to match boson position
231  firstchild = (particle->GetFirstChild()==0) ? particle->GetFirstChild() - 1 : particle->GetFirstChild() - 6;
232  lastchild = (particle->GetLastChild()==0) ? particle->GetLastChild() - 1 : particle->GetLastChild() - 6;
233  }
234 
235  double lightspeed = 299792458e3; //c in mm/s. Used for time in PYTHIA t[s]=t_pythia[mm]/c[mm/s]
236  double vx = nu->X4()->X() + particle->GetVx()*1e12; //pythia gives position in [mm] while genie uses [fm]
237  double vy = nu->X4()->Y() + particle->GetVy()*1e12;
238  double vz = nu->X4()->Z() + particle->GetVz()*1e12;
239  double vt = nu->X4()->T() + particle->GetTime()/lightspeed;
240  TLorentzVector pos( vx, vy, vz, vt );
241 
242  event->AddParticle(pdgc, ist, firstmother, lastmother, firstchild, lastchild, p4o, pos );
243 
244  }
245 
246  delete particle;
247  pythia_particles->Clear("C");
248 
249  }
250 
251 #else
252  LOG("GLRESGenerator", pFATAL)
253  << "Calling GENIE/PYTHIA6 without enabling PYTHIA6";
254  gAbortingInErr = true;
255  std::exit(1);
256 #endif
257 
258 }
259 //___________________________________________________________________________
261 {
262  Algorithm::Configure(config);
263  this->LoadConfig();
264 }
265 //____________________________________________________________________________
266 void GLRESGenerator::Configure(string config)
267 {
268  Algorithm::Configure(config);
269  this->LoadConfig();
270 }
271 //____________________________________________________________________________
273 {
274 
275 #ifdef __GENIE_PYTHIA6_ENABLED__
276  fPythia = TPythia6::Instance();
277 
278  // sync GENIE/PYTHIA6 seed number
280 
281  // PYTHIA parameters only valid for HEDIS
282  double wmin; GetParam( "Xsec-Wmin", wmin ) ;
283  int warnings; GetParam( "Warnings", warnings ) ;
284  int errors; GetParam( "Errors", errors ) ;
285  int qrk_mass; GetParam( "QuarkMass", qrk_mass ) ;
286  fPythia->SetPARP(2, wmin); //(D = 10. GeV) lowest c.m. energy for the event as a whole that the program will accept to simulate. (bellow 2GeV pythia crashes)
287  fPythia->SetMSTU(26, warnings); // (Default=10) maximum number of warnings that are printed
288  fPythia->SetMSTU(22, errors); // (Default=10) maximum number of errors that are printed
289  fPythia->SetMSTJ(93, qrk_mass); // light (d, u, s, c, b) quark masses are taken from PARF(101) - PARF(105) rather than PMAS(1,1) - PMAS(5,1). Diquark masses are given as sum of quark masses, without spin splitting term.
290 
291  fPythia->SetPMAS(24,1,kMw); //mass of the W boson (pythia=80.450 // genie=80.385)
292  fPythia->SetPMAS(24,2,0.); //set to 0 the width of the W boson to avoid problems with energy conservation
293  fPythia->SetPMAS(6,2,0.); //set to 0 the width of the top to avoid problems with energy conservation
294 #endif // __GENIE_PYTHIA6_ENABLED__
295 
296 }
297 //____________________________________________________________________________
const int kPdgNuE
Definition: PDGCodes.h:28
bool IsNeutrino(int pdgc)
Definition: PDGUtils.cxx:110
double GetT(double mlin, double mlout, double s, double costhCM)
Definition: Born.cxx:200
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:71
const TLorentzVector * P4(void) const
Definition: GHepParticle.h:78
#define __GENIE_PYTHIA6_ENABLED__
Defines the EventRecordVisitorI interface. Concrete implementations of this interface use the &#39;Visito...
const int kPdgAntiNuE
Definition: PDGCodes.h:29
const int kPdgWM
Definition: PDGCodes.h:192
#define pFATAL
Definition: Messenger.h:56
const int kPdgNuMu
Definition: PDGCodes.h:30
static constexpr double s
Definition: Units.h:95
static const double kElectronMass
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
int FSPrimLeptonPdg(void) const
final state primary lepton pdg
double GetReAlpha(void)
Definition: Born.h:32
int Pdg(void) const
Definition: GHepParticle.h:63
Summary information for an interaction.
Definition: Interaction.h:56
TPythia6 * fPythia
PYTHIA6 wrapper class.
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void Configure(const Registry &config)
const Kinematics & Kine(void) const
Definition: Interaction.h:71
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
int ProbePdg(void) const
Definition: InitialState.h:64
bool IsAntiMuon(int pdgc)
Definition: PDGUtils.cxx:203
bool IsTau(int pdgc)
Definition: PDGUtils.cxx:208
double GetKV(KineVar_t kv) const
Definition: Kinematics.cxx:323
bool IsPositron(int pdgc)
Definition: PDGUtils.cxx:193
bool IsMuon(int pdgc)
Definition: PDGUtils.cxx:198
double GetS(double mlin, double Enuin)
Definition: Born.cxx:195
const int kPdgAntiNuTau
Definition: PDGCodes.h:33
const int kPdgAntiNuMu
Definition: PDGCodes.h:31
#define pWARN
Definition: Messenger.h:60
TParticlePDG * FSPrimLepton(void) const
final state primary lepton
const int kPdgNuTau
Definition: PDGCodes.h:32
Born level nu-electron cross section.
Definition: Born.h:26
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:68
const TLorentzVector * X4(void) const
Definition: GHepParticle.h:79
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
void ProcessEventRecord(GHepRecord *event) const
const InitialState & InitState(void) const
Definition: Interaction.h:69
TParticlePDG * Find(int pdgc, bool must_exist=true)
Definition: PDGLibrary.cxx:86
bool GetParam(const RgKey &name, T &p, bool is_top_call=true) const
bool gAbortingInErr
Definition: Messenger.cxx:34
double ProbeE(RefFrame_t rf) const
GENIE&#39;s GHEP MC event record.
Definition: GHepRecord.h:45
const int kPdgWP
Definition: PDGCodes.h:191
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils...
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
bool IsAntiTau(int pdgc)
Definition: PDGUtils.cxx:213
bool IsElectron(int pdgc)
Definition: PDGUtils.cxx:188
enum genie::EGHepStatus GHepStatus_t
Initial State information.
Definition: InitialState.h:48