GReWeightINuke.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2017, GENIE Neutrino MC Generator Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Authors: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
8  University of Liverpool & STFC Rutherford Appleton Lab
9 
10  Jim Dobson <J.Dobson07 \at imperial.ac.uk>
11  Imperial College London
12 
13  For the class documentation see the corresponding header file.
14 
15  Important revisions after version 2.0.0 :
16  @ Sep 10, 2009 - CA
17  Was adapted from Jim's and Costas' T2K-specific GENIE reweighting code.
18  First included in v2.5.1.
19  @ Jul 29, 2011 - SD,AM
20  Mean free path is now function of Z too.
21  @ Sep 20, 2011 - CA
22  Determine 'no interaction' by looking-up the FSI code set by INTRANUKE.
23  INTRANUKE now sets a value in all cases rather than leaving it unset for
24  particles which escape the target nucleus.
25 
26 */
27 //____________________________________________________________________________
28 
29 #include <cassert>
30 #include <cstdlib>
31 
32 #include <TMath.h>
33 #include <TNtuple.h>
34 #include <TFile.h>
35 #include <TLorentzVector.h>
36 #include <TVector.h>
37 
38 #include "Conventions/Units.h"
39 #include "EVGCore/EventRecord.h"
40 #include "GHEP/GHepParticle.h"
44 #include "Messenger/Messenger.h"
45 #include "Numerical/Spline.h"
46 #include "PDG/PDGUtils.h"
50 #include "Utils/NuclearUtils.h"
51 
52 using namespace genie;
53 using namespace genie::rew;
54 
55 //_______________________________________________________________________________________
57 GReWeightI()
58 {
59 #ifdef _G_REWEIGHT_INUKE_DEBUG_NTP_
60  fTestFile = new TFile("./intranuke_reweight_test.root","recreate");
61  fTestNtp = new TNtuple("testntp","","pdg:E:mfp_twk_dial:d:d_mfp:fate:interact:w_mfp:w_fate");
62 #endif
63 }
64 //_______________________________________________________________________________________
66 {
67 #ifdef _G_REWEIGHT_INUKE_DEBUG_NTP_
68  assert(fTestFile);
69  assert(fTestNtp);
70  fTestFile->cd();
71  fTestNtp->Write();
72  fTestFile->Close();
73  delete fTestFile;
74  //delete fTestNtp;
75 #endif
76 }
77 //_______________________________________________________________________________________
79 {
80  bool handle;
81 
82  switch(syst) {
83  case ( kINukeTwkDial_MFP_pi ) :
84  case ( kINukeTwkDial_MFP_N ) :
85  case ( kINukeTwkDial_FrCEx_pi ) :
86  case ( kINukeTwkDial_FrElas_pi ) :
87  case ( kINukeTwkDial_FrInel_pi ) :
88  case ( kINukeTwkDial_FrAbs_pi ) :
89  case ( kINukeTwkDial_FrPiProd_pi ) :
90  case ( kINukeTwkDial_FrCEx_N ) :
91  case ( kINukeTwkDial_FrElas_N ) :
92  case ( kINukeTwkDial_FrInel_N ) :
93  case ( kINukeTwkDial_FrAbs_N ) :
94  case ( kINukeTwkDial_FrPiProd_N ) :
95  handle = true;
96  break;
97 
98  default:
99  handle = false;
100  }
101 
102  return handle;
103 }
104 //_______________________________________________________________________________________
106 {
107  if(this->IsHandled(syst)) {
108  fINukeRwParams.SetTwkDial(syst, val);
109  }
110 }
111 //_______________________________________________________________________________________
113 {
115  this->Reconfigure();
116 }
117 //_______________________________________________________________________________________
119 {
121 }
122 //_______________________________________________________________________________________
124 {
125  // get the atomic mass number for the hit nucleus
126  GHepParticle * tgt = event.TargetNucleus();
127  if (!tgt) return 1.0;
128  double A = tgt->A();
129  double Z = tgt->Z();
130  if (A<=1) return 1.0;
131  if (Z<=1) return 1.0;
132 
133  double event_weight = 1.0;
134 
135  // Loop over stdhep entries and only calculate weights for particles.
136  // All particles that are not hadrons generated inside the nucleus are given weights of 1.0
137  int ip=-1;
138  GHepParticle * p = 0;
139  TIter event_iter(&event);
140  while ( (p = dynamic_cast<GHepParticle *>(event_iter.Next())) ) {
141  ip++;
142 
143  // Skip particles not rescattered by the actual hadron transport code
144  int pdgc = p->Pdg();
145  bool is_pion = pdg::IsPion (pdgc);
146  bool is_nucleon = pdg::IsNucleon(pdgc);
147  if(!is_pion && !is_nucleon)
148  {
149  continue;
150  }
151 
152  // Skip particles with code other than 'hadron in the nucleus'
153  GHepStatus_t ist = p->Status();
154  if(ist != kIStHadronInTheNucleus)
155  {
156  continue;
157  }
158 
159  // Determine the interaction type for current hadron in nucleus, if any
160  int fsi_code = p->RescatterCode();
161  LOG("ReW", pDEBUG)
162  << "Attempting to reweight hadron at position = " << ip
163  << " with PDG code = " << pdgc
164  << " and FSI code = " << fsi_code
165  << " (" << INukeHadroFates::AsString((INukeFateHA_t)fsi_code) << ")";
166  if(fsi_code == -1 || fsi_code == (int)kIHAFtUndefined) {
167  LOG("ReW", pFATAL) << "INTRANUKE didn't set a valid rescattering code for event in position: " << ip;
168  LOG("ReW", pFATAL) << "Here is the problematic event:";
169  LOG("ReW", pFATAL) << event;
170  exit(1);
171  }
172  bool escaped = (fsi_code == (int)kIHAFtNoInteraction);
173  bool interacted = !escaped;
174 
175  // Get 4-momentum and 4-position
176  TLorentzVector x4 (p->Vx(), p->Vy(), p->Vz(), 0. );
177  TLorentzVector p4 (p->Px(), p->Py(), p->Pz(), p->E());
178 
179  // Init current hadron weights
180  double w_mfp = 1.0;
181  double w_fate = 1.0;
182 
183  // Check which weights need to be calculated (only if relevant params were tweaked)
184  bool calc_w_mfp = fINukeRwParams.MeanFreePathParams(pdgc)->IsTweaked();
185  bool calc_w_fate = fINukeRwParams.FateParams(pdgc)->IsTweaked();
186 
187  // Compute weight to account for changes in the total rescattering probability
188  double mfp_scale_factor = 1.;
189  if(calc_w_mfp)
190  {
191  mfp_scale_factor = fINukeRwParams.MeanFreePathParams(pdgc)->ScaleFactor();
192  w_mfp = utils::rew::MeanFreePathWeight(pdgc,x4,p4,A,Z,mfp_scale_factor,interacted);
193  } // calculate mfp weight?
194 
195  // Compute weight to account for changes in relative fractions of reaction channels
196  if(calc_w_fate && interacted)
197  {
198  double fate_fraction_scale_factor =
200  GSyst::INukeFate2GSyst((INukeFateHA_t)fsi_code,pdgc), p4);
201  w_fate = fate_fraction_scale_factor;
202  }
203 
204  // Calculate the current hadron weight
205  double hadron_weight = w_mfp * w_fate;
206 
207  LOG("ReW", pNOTICE)
208  << "Reweighted hadron at position = " << ip
209  << " with PDG code = " << pdgc
210  << ", FSI code = " << fsi_code
211  << " (" << INukeHadroFates::AsString((INukeFateHA_t)fsi_code) << ") :"
212  << " w_mfp = " << w_mfp
213  <<", w_fate = " << w_fate;
214 
215  // Debug info
216 #ifdef _G_REWEIGHT_INUKE_DEBUG_NTP_
217  double d = utils::intranuke::Dist2Exit(x4,p4,A);
218  double d_mfp = utils::intranuke::Dist2ExitMFP(pdgc,x4,p4,A,Z);
219  double Eh = p->E();
220  double iflag = (interacted) ? 1 : 0;
221  fTestNtp->Fill(pdgc, Eh, mfp_scale_factor, d, d_mfp, fsi_code, iflag, w_mfp, w_fate);
222 #endif
223 
224  // Update the current event weight
225  event_weight *= hadron_weight;
226 
227  }//particle loop
228 
229  return event_weight;
230 }
231 //_______________________________________________________________________________________
enum genie::EINukeFateHA_t INukeFateHA_t
int Z(void) const
bool IsPion(int pdgc)
Definition: PDGUtils.cxx:296
int RescatterCode(void) const
Definition: GHepParticle.h:66
tweak inelastic probability for pions, for given total rescattering probability
Definition: GSyst.h:128
bool IsHandled(GSyst_t syst)
does the current weight calculator handle the input nuisance param?
#include "Numerical/GSFunc.h"
Definition: AlgCmp.h:26
double E(void) const
Get energy.
Definition: GHepParticle.h:90
MFP * MeanFreePathParams(int pdgc) const
bool IsNucleon(int pdgc)
Definition: PDGUtils.cxx:316
bool IsTweaked(GSyst_t s) const
is included & tweaked to non-def value?
tweak elastic probability for pions, for given total rescattering probability
Definition: GSyst.h:127
enum genie::EGHepStatus GHepStatus_t
#define pFATAL
Definition: Messenger.h:47
tweak charge exchange probability for nucleons, for given total rescattering probability ...
Definition: GSyst.h:131
void Reconfigure(void)
propagate updated nuisance parameter values to actual MC, etc
double CalcWeight(const EventRecord &event)
calculate a weight for the input event using the current nuisance param values
double Dist2ExitMFP(int pdgc, const TLorentzVector &x4, const TLorentzVector &p4, double A, double Z, double NR=3, double R0=1.4)
Distance to exit.
Definition: INukeUtils.cxx:306
tweak pion production probability for pions, for given total rescattering probability ...
Definition: GSyst.h:130
double Pz(void) const
Get Pz.
Definition: GHepParticle.h:89
GHepStatus_t Status(void) const
Definition: GHepParticle.h:65
double Px(void) const
Get Px.
Definition: GHepParticle.h:87
int Pdg(void) const
Definition: GHepParticle.h:64
tweak inelastic probability for nucleons, for given total rescattering probability ...
Definition: GSyst.h:133
tweak absorption probability for nucleons, for given total rescattering probability ...
Definition: GSyst.h:134
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:87
void Reset(void)
set all nuisance parameters to default values
tweak absorption probability for pions, for given total rescattering probability
Definition: GSyst.h:129
void SetTwkDial(GSyst_t s, double val)
void SetSystematic(GSyst_t syst, double val)
update the value for the specified nuisance param
An enumeration of systematic parameters.
tweak elastic probability for nucleons, for given total rescattering probability
Definition: GSyst.h:132
double MeanFreePathWeight(int pdgc, const TLorentzVector &x4, const TLorentzVector &p4, double A, double Z, double mfp_scale_factor, bool interacted, double nRpi=0.5, double nRnuc=1.0, double NR=3, double R0=1.4)
GReWeightINukeParams fINukeRwParams
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
p
Definition: test.py:228
tweak mean free path for nucleons
Definition: GSyst.h:125
tweak mean free path for pions
Definition: GSyst.h:124
static const double A
Definition: Units.h:82
double Dist2Exit(const TLorentzVector &x4, const TLorentzVector &p4, double A, double NR=3, double R0=1.4)
Distance to exit.
Definition: INukeUtils.cxx:279
double Vz(void) const
Get production z.
Definition: GHepParticle.h:95
static string AsString(INukeFateHN_t fate)
double ScaleFactor(void) const
mean free path scale factor = 1 + twk_dial * fractional_err
tweak pion production probability for nucleons, for given total rescattering probability ...
Definition: GSyst.h:135
double ScaleFactor(GSyst_t s, const TLorentzVector &p4) const
see next
double Vy(void) const
Get production y.
Definition: GHepParticle.h:94
int A(void) const
#define pNOTICE
Definition: Messenger.h:52
tweak charge exchange probability for pions, for given total rescattering probability ...
Definition: GSyst.h:126
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:40
static GSyst_t INukeFate2GSyst(INukeFateHA_t fate, int pdgc)
Definition: GSyst.h:469
Event finding and building.
double Vx(void) const
Get production x.
Definition: GHepParticle.h:93
GENIE event reweighting engine ABC.
Definition: GReWeightI.h:31
#define pDEBUG
Definition: Messenger.h:54
double Py(void) const
Get Py.
Definition: GHepParticle.h:88