NHLPrimaryVtxGenerator.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 
29 
30 using namespace genie;
31 
32 //____________________________________________________________________________
34 EventRecordVisitorI("genie::NHLPrimaryVtxGenerator")
35 {
36 
37 }
38 //____________________________________________________________________________
40 EventRecordVisitorI("genie::NHLPrimaryVtxGenerator",config)
41 {
42 
43 }
44 //____________________________________________________________________________
46 {
47 
48 }
49 //____________________________________________________________________________
51 {
52  Interaction * interaction = event->Summary();
53 
54  fCurrDecayMode = (NHLDecayMode_t) interaction->ExclTag().DecayMode();
55 
56  LOG("NHL", pNOTICE)
57  << "Simulating NHL decay " << utils::nhl::AsString(fCurrDecayMode);
58 
59  this->AddInitialState(event);
60  this->GenerateDecayProducts(event);
61 }
62 //____________________________________________________________________________
64 {
65  TLorentzVector v4(0,0,0,0);
66 
67  Interaction * interaction = event->Summary();
68  double E = interaction->InitState().ProbeE(kRfLab);
69  double M = PDGLibrary::Instance()->Find(kPdgNHL)->Mass();
70  double p = TMath::Sqrt(E*E-M*M);
71 
72  TLorentzVector p4(0,0,p,E);
73 
74  event->AddParticle(kPdgNHL, kIStInitialState, 0,-1,-1,-1, p4, v4);
75 }
76 //____________________________________________________________________________
78 {
79  LOG("NHL", pINFO) << "Generating decay...";
80 
82  LOG("NHL", pINFO) << "Decay product IDs: " << pdgv;
83  assert ( pdgv.size() > 1);
84 
85  LOG("NHL", pINFO) << "Performing a phase space decay...";
86 
87  // Get the decay product masses
88 
90  int i = 0;
91  double * mass = new double[pdgv.size()];
92  double sum = 0;
93  for(pdg_iter = pdgv.begin(); pdg_iter != pdgv.end(); ++pdg_iter) {
94  int pdgc = *pdg_iter;
95  double m = PDGLibrary::Instance()->Find(pdgc)->Mass();
96  mass[i++] = m;
97  sum += m;
98  }
99 
100  LOG("NHL", pINFO)
101  << "Decaying N = " << pdgv.size() << " particles / total mass = " << sum;
102 
103  int nhl_id = 0;
104  GHepParticle * nhl = event->Particle(nhl_id);
105  assert(nhl);
106  TLorentzVector * p4d = nhl->GetP4();
107  TLorentzVector * v4d = nhl->GetX4();
108 
109  LOG("NHL", pINFO)
110  << "Decaying system p4 = " << utils::print::P4AsString(p4d);
111 
112  // Set the decay
113  bool permitted = fPhaseSpaceGenerator.SetDecay(*p4d, pdgv.size(), mass);
114  if(!permitted) {
115  LOG("NHL", pERROR)
116  << " *** Phase space decay is not permitted \n"
117  << " Total particle mass = " << sum << "\n"
118  << " Decaying system p4 = " << utils::print::P4AsString(p4d);
119  // clean-up
120  delete [] mass;
121  delete p4d;
122  delete v4d;
123  // throw exception
125  exception.SetReason("Decay not permitted kinematically");
126  exception.SwitchOnFastForward();
127  throw exception;
128  }
129 
130  // Get the maximum weight
131  //double wmax = fPhaseSpaceGenerator.GetWtMax();
132  double wmax = -1;
133  for(int idec=0; idec<200; idec++) {
134  double w = fPhaseSpaceGenerator.Generate();
135  wmax = TMath::Max(wmax,w);
136  }
137  assert(wmax>0);
138  wmax *= 2;
139 
140  LOG("NHL", pNOTICE)
141  << "Max phase space gen. weight @ current hadronic system: " << wmax;
142 
143  // Generate an unweighted decay
144  RandomGen * rnd = RandomGen::Instance();
145 
146  bool accept_decay=false;
147  unsigned int itry=0;
148  while(!accept_decay)
149  {
150  itry++;
151 
153  // report, clean-up and return
154  LOG("NHL", pWARN)
155  << "Couldn't generate an unweighted phase space decay after "
156  << itry << " attempts";
157  // clean up
158  delete [] mass;
159  delete p4d;
160  delete v4d;
161  // throw exception
163  exception.SetReason("Couldn't select decay after N attempts");
164  exception.SwitchOnFastForward();
165  throw exception;
166  }
167  double w = fPhaseSpaceGenerator.Generate();
168  if(w > wmax) {
169  LOG("NHL", pWARN)
170  << "Decay weight = " << w << " > max decay weight = " << wmax;
171  }
172  double gw = wmax * rnd->RndHadro().Rndm();
173  accept_decay = (gw<=w);
174 
175  LOG("NHL", pINFO)
176  << "Decay weight = " << w << " / R = " << gw
177  << " - accepted: " << accept_decay;
178 
179  } //!accept_decay
180 
181  // Insert final state products into a TClonesArray of GHepParticle's
182  TLorentzVector v4(*v4d);
183  int idp = 0;
184  for(pdg_iter = pdgv.begin(); pdg_iter != pdgv.end(); ++pdg_iter) {
185  int pdgc = *pdg_iter;
186  TLorentzVector * p4fin = fPhaseSpaceGenerator.GetDecay(idp);
188  event->AddParticle(pdgc, ist, nhl_id,-1,-1,-1, *p4fin, v4);
189  idp++;
190  }
191 
192  // Clean-up
193  delete [] mass;
194  delete p4d;
195  delete v4d;
196 }
197 //____________________________________________________________________________
199 {
200  Algorithm::Configure(config);
201  this->LoadConfig();
202 }
203 //___________________________________________________________________________
205 {
206  Algorithm::Configure(config);
207  this->LoadConfig();
208 }
209 //___________________________________________________________________________
211 {
212 
213 }
214 //___________________________________________________________________________
void AddInitialState(GHepRecord *event) const
TLorentzVector * GetX4(void) const
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
#define pERROR
Definition: Messenger.h:59
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:71
Defines the EventRecordVisitorI interface. Concrete implementations of this interface use the &#39;Visito...
void Configure(const Registry &config)
void GenerateDecayProducts(GHepRecord *event) const
string P4AsString(const TLorentzVector *p)
Definition: PrintUtils.cxx:27
static const unsigned int kMaxUnweightDecayIterations
Definition: Controls.h:61
intermediate_table::const_iterator const_iterator
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
PDGCodeList DecayProductList(NHLDecayMode_t nhldm)
A list of PDG codes.
Definition: PDGCodeList.h:32
Summary information for an interaction.
Definition: Interaction.h:56
An exception thrown by EventRecordVisitorI when the normal processing sequence has to be disrupted (f...
const int kPdgNHL
Definition: PDGCodes.h:221
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
static Config * config
Definition: config.cpp:1054
TLorentzVector * GetP4(void) const
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
size_t size
Definition: lodepng.cpp:55
int DecayMode(void) const
Definition: XclsTag.h:70
p
Definition: test.py:223
#define pINFO
Definition: Messenger.h:62
#define pWARN
Definition: Messenger.h:60
TRandom3 & RndHadro(void) const
rnd number generator used by hadronization models
Definition: RandomGen.h:53
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:57
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
const XclsTag & ExclTag(void) const
Definition: Interaction.h:72
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:75
#define pNOTICE
Definition: Messenger.h:61
string AsString(NHLDecayMode_t nhldm)
double ProbeE(RefFrame_t rf) const
GENIE&#39;s GHEP MC event record.
Definition: GHepRecord.h:45
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
enum genie::ENHLDecayMode NHLDecayMode_t
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Event finding and building.
enum genie::EGHepStatus GHepStatus_t