Decayer.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2019, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Author: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
7  University of Liverpool & STFC Rutherford Appleton Lab
8 */
9 //____________________________________________________________________________
10 
11 #include <algorithm>
12 #include <sstream>
13 
14 #include <TParticlePDG.h>
15 
21 #include "Physics/Decay/Decayer.h"
22 
23 using std::count;
24 using std::ostringstream;
25 
26 using namespace genie;
27 //___________________________________________________________________________
30 {
31 
32 }
33 //___________________________________________________________________________
36 {
37 
38 }
39 //___________________________________________________________________________
40 Decayer::Decayer(string name, string config) :
41 EventRecordVisitorI(name, config)
42 {
43 
44 }
45 //___________________________________________________________________________
47 {
48 
49 }
50 //___________________________________________________________________________
51 bool Decayer::ToBeDecayed(int pdg_code, GHepStatus_t status_code) const
52 {
53  // Check whether it is "unstable" (definition can vary)
54 
55  bool is_unstable = this->IsUnstable(pdg_code);
56 
57  LOG("Decay", pDEBUG)
58  << "Particle is unstable? "
59  << ((is_unstable) ? "Yes" : "No");
60 
61  if(!is_unstable) return false;
62 
63  // Check whether the given unstable particle
64  // has the appropriate status code to be decayed
65 
66  bool to_be_decayed = false;
67 
68  if(fRunBefHadroTransp) {
69  to_be_decayed =
70  (status_code == kIStHadronInTheNucleus ||
71  status_code == kIStPreDecayResonantState ||
72  status_code == kIStStableFinalState);
73  }
74  else {
75  to_be_decayed =
76  (status_code == kIStStableFinalState);
77  }
78 
79  LOG("Decay", pDEBUG)
80  << "Particle to be decayed "
81  << "[" << ((fRunBefHadroTransp) ? "Before" : "After") << " FSI]? "
82  << ((to_be_decayed) ? "Yes" : "No");
83 
84  return to_be_decayed;
85 }
86 //___________________________________________________________________________
87 bool Decayer::IsUnstable(int pdg_code) const
88 {
89  // ROOT's TParticlepdg::Lifetime() does not work properly
90  // do something else instead (temporarily)
91  //
92  // TParticlePDG * ppdg = PDGLibrary::Instance()->Find(pdg_code);
93  //if( ppdg->Lifetime() < fMaxLifetime ) { /* ... */ };
94  //
95 
96  // <temp/>
97  if( fRunBefHadroTransp ) {
98  //
99  // Run *before* the hadron transport MC
100  // At this point we decay only baryon resonances
101  //
102  bool decay = utils::res::IsBaryonResonance(pdg_code);
103  return decay;
104  }
105  else {
106  //
107  // Run *after* the hadron transport MC
108  // At this point we decay only particles in the fParticlesToDecay
109  // PDGCodeList (filled in from config inputs)
110  //
112  return decay;
113  }
114  // </temp>
115 
116  return false;
117 }
118 //___________________________________________________________________________
120 {
121  Algorithm::Configure(config);
122  this->LoadConfig();
123 
124  fAllowReconfig = false;
125 }
126 //___________________________________________________________________________
128 {
129  Algorithm::Configure(config);
130  this->LoadConfig();
131 
132  fAllowReconfig = false;
133 }
134 //___________________________________________________________________________
136 {
137  // Get the specified maximum lifetime tmax (decay with lifetime < tmax)
138  //
139  //fMaxLifetime = fConfig->GetDoubleDef("MaxLifetime", 1e-9);
140 
141  // Check whether to generate weighted or unweighted particle decays
142  fGenerateWeighted = false ;
143  //this->GetParam("GenerateWeighted", fGenerateWeighted, false);
144 
145  // Check whether the module is being run before or after the hadron
146  // transport (intranuclear rescattering) module.
147  //
148  // If it is run before the hadron transport (and after the hadronization)
149  // step it should decay only "unstable" particles (marked as hadrons in
150  // the nucleus) which would typically decay within the time required to
151  // exit the nucleus - so, the algorithm wouldn't decay particles that
152  // have to be rescattered first. In case that the generated event is off
153  // a free nucleon target, thi instance of the algorithm should do nothing.
154  //
155  // If it is run after the hadon transport, then it should decay all the
156  // 'unstable' particles marked as 'present in the final state' and which
157  // should be decay before the event is passed to the detector particle
158  // transport MC.
159  //
160  this->GetParam("RunBeforeHadronTransport", fRunBefHadroTransp) ;
161 
162  // Allow user to specify a list of particles to be decayed
163  //
164  RgKeyList klist = GetConfig().FindKeys("DecayParticleWithCode=");
165  RgKeyList::const_iterator kiter = klist.begin();
166  for( ; kiter != klist.end(); ++kiter) {
167  RgKey key = *kiter;
168  bool decay = GetConfig().GetBool(key);
169  vector<string> kv = utils::str::Split(key,"=");
170  assert(kv.size()==2);
171  int pdgc = atoi(kv[1].c_str());
172  TParticlePDG * p = PDGLibrary::Instance()->Find(pdgc);
173  if(decay) {
174  LOG("Decay", pDEBUG)
175  << "Configured to decay " << p->GetName();
177  this->UnInhibitDecay(pdgc);
178  }
179  else {
180  LOG("Decay", pDEBUG)
181  << "Configured to inhibit decays for " << p->GetName();
183  this->InhibitDecay(pdgc);
184  }// decay?
185  }// key iterator
186 
187  // Allow user to inhibit certain decay channels
188  //
189  klist = GetConfig().FindKeys("InhibitDecay/");
190  kiter = klist.begin();
191  for( ; kiter != klist.end(); ++kiter) {
192  RgKey key = *kiter;
193  if(GetConfig().GetBool(key)) {
194  string filtkey = utils::str::FilterString("InhibitDecay/", key);
195  vector<string> kv = utils::str::Split(filtkey,",");
196  assert(kv.size()==2);
197  int pdgc = atoi(utils::str::FilterString("Particle=",kv[0]).c_str());
198  int dc = atoi(utils::str::FilterString("Channel=", kv[1]).c_str());
199  TParticlePDG * p = PDGLibrary::Instance()->Find(pdgc);
200  if(!p) continue;
201  LOG("Decay", pINFO)
202  << "Configured to inhibit " << p->GetName()
203  << "'s decay channel " << dc;
204  this->InhibitDecay(pdgc, p->DecayChannel(dc));
205  }//val[key]=true?
206  }//key iterator
207 
208 
209  sort(fParticlesToDecay.begin(), fParticlesToDecay.end());
210  sort(fParticlesNotToDecay.begin(), fParticlesNotToDecay.end());
211 
212  // Print-out for only one of the two instances of this module
213  if(!fRunBefHadroTransp) {
214  LOG("Decay", pNOTICE)
215  << "\nConfigured to decay: " << fParticlesToDecay
216  << "\nConfigured to inhibit decays of: " << fParticlesNotToDecay
217  << "\n";
218  }
219 }
220 //___________________________________________________________________________
virtual bool ToBeDecayed(int pdgc, GHepStatus_t ist) const
Definition: Decayer.cxx:51
const XML_Char * name
Definition: expat.h:151
virtual bool IsUnstable(int pdgc) const
Definition: Decayer.cxx:87
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
virtual void InhibitDecay(int pdgc, TDecayChannel *dc=0) const =0
virtual ~Decayer()
Definition: Decayer.cxx:46
Defines the EventRecordVisitorI interface. Concrete implementations of this interface use the &#39;Visito...
void Configure(const Registry &config)
Definition: Decayer.cxx:119
enum genie::EGHepStatus GHepStatus_t
const char * p
Definition: xmltok.h:285
bool ExistsInPDGCodeList(int pdg_code) const
Definition: config.py:1
virtual void UnInhibitDecay(int pdgc, TDecayChannel *dc=0) const =0
virtual const Registry & GetConfig(void) const
Definition: Algorithm.cxx:254
RgKeyList FindKeys(RgKey key_part) const
create list with all keys containing &#39;key_part&#39;
Definition: Registry.cxx:855
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
bool fRunBefHadroTransp
is invoked before or after FSI?
Definition: Decayer.h:57
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:70
#define pINFO
Definition: Messenger.h:63
bool fGenerateWeighted
generate weighted or unweighted decays?
Definition: Decayer.h:56
PDGCodeList fParticlesNotToDecay
list of particles for which decay is inhibited
Definition: Decayer.h:59
vector< RgKey > RgKeyList
Definition: Registry.h:51
PDGCodeList fParticlesToDecay
list of particles to be decayed
Definition: Decayer.h:58
virtual void LoadConfig(void)
Definition: Decayer.cxx:135
string FilterString(string filt, string input)
Definition: StringUtils.cxx:85
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:43
Definition: decay.py:1
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:42
string RgKey
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:66
TParticlePDG * Find(int pdgc)
Definition: PDGLibrary.cxx:61
RgBool GetBool(RgKey key) const
Definition: Registry.cxx:475
assert(nhit_max >=nhit_nbins)
bool IsBaryonResonance(int pdgc)
is input a baryon resonance?
#define pNOTICE
Definition: Messenger.h:62
bool GetParam(const RgKey &name, T &p, bool is_top_call=true) const
void push_back(int pdg_code)
Definition: PDGCodeList.cxx:67
#define pDEBUG
Definition: Messenger.h:64