GReWeightFZone.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  STFC, Rutherford Appleton Laboratory
9 
10  For the class documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13  @ Sep 20, 2009 - CA
14  Skeleton first included in v2.5.1.
15  @ Dec 17, 2010 - JD
16  First implementation of FZone reweighting.
17  @ Feb 08, 2013 - CA
18  Mean free path is function of Z too. Make sure it is passed on.
19  Use new INTRANUKE FSI flags. Use formation zone code from PhysUtils.
20 */
21 //____________________________________________________________________________
22 
23 #include "Conventions/Controls.h"
24 #include "Conventions/Units.h"
25 #include "EVGCore/EventRecord.h"
26 #include "GHEP/GHepParticle.h"
27 #include "GHEP/GHepStatus.h"
28 #include "Messenger/Messenger.h"
29 #include "PDG/PDGCodes.h"
30 #include "PDG/PDGUtils.h"
34 #include "Utils/PrintUtils.h"
35 #include "Utils/PhysUtils.h"
36 
37 using namespace genie;
38 using namespace genie::rew;
39 using namespace genie::utils;
40 
41 //_______________________________________________________________________________________
43 GReWeightI()
44 {
45  this->Init();
46 }
47 //_______________________________________________________________________________________
49 {
50 
51 }
52 //_______________________________________________________________________________________
54 {
55  switch(syst) {
57  return true;
58  break;
59  default:
60  return false;
61  break;
62  }
63  return false;
64 }
65 //_______________________________________________________________________________________
66 void GReWeightFZone::SetSystematic(GSyst_t syst, double twk_dial)
67 {
68  switch(syst) {
70  fFZoneTwkDial = twk_dial;
71  break;
72  default:
73  return;
74  }
75 }
76 //_______________________________________________________________________________________
78 {
79  fFZoneTwkDial = 0.;
80 }
81 //_______________________________________________________________________________________
83 {
84 
85 }
86 //_______________________________________________________________________________________
88 {
89  // Physics parameter tweaked?
90  bool tweaked = (TMath::Abs(fFZoneTwkDial) > controls::kASmallNum);
91  if(!tweaked) return 1.;
92 
93  // Skip events not involving nuclear targets.
94  GHepParticle * tgt = event.TargetNucleus();
95  if (!tgt) return 1.;
96  double A = tgt->A();
97  double Z = tgt->Z();
98  if (A<=1) return 1.;
99  if (Z<=1) return 1.0;
100 
101 
102  // Skip event if was not DIS scattering.
103  bool is_dis = event.Summary()->ProcInfo().IsDeepInelastic();
104  if(!is_dis) {
105  LOG("ReW", pDEBUG) << "Not a DIS event";
106  return 1.;
107  }
108 
109  //
110  // Calculate event weight.
111  //
112 
113  double event_weight = 1.;
114 
115  // hadronic system 4-/3-momentum
116  TLorentzVector p4hadr = utils::rew::Hadronic4pLAB(event);
117  TVector3 p3hadr = p4hadr.Vect();
118 
119  // vertex
120  assert(event.HitNucleon());
121  const TLorentzVector & vtx = *(event.HitNucleon()->X4());
122 
123  // formation zone: fractional 1sigma err
125  double fracerr = uncertainty->OneSigmaErr(kHadrNuclTwkDial_FormZone);
126 
127  // Loop over particles calculate weights for all primary hadrons inside the nucleus.
128  int ip=-1;
129  GHepParticle * p = 0;
130  TIter event_iter(&event);
131  while ( (p = dynamic_cast<GHepParticle *>(event_iter.Next())) ) {
132  ip++;
133 
134  // Skip particles with code other than 'hadron in the nucleus'
135  GHepStatus_t ist = p->Status();
136  if(ist != kIStHadronInTheNucleus)
137  {
138  continue;
139  }
140  // JIMTODO - Skip if is not a hadron
141  // I am not sure why the above conditional would not catch this out - need to investigate.
142  int pdgc = p->Pdg(); // hadron pdg code
143  if (pdg::IsHadron(pdgc) == false)
144  {
145  continue;
146  }
147 
148  // Determine whether it interacted or not
149  int fsi_code = p->RescatterCode();
150  if(fsi_code == -1 || fsi_code == (int)kIHAFtUndefined) {
151  LOG("ReW", pFATAL) << "INTRANUKE didn't set a valid rescattering code for event in position: " << ip;
152  LOG("ReW", pFATAL) << "Here is the problematic event:";
153  LOG("ReW", pFATAL) << event;
154 // exit(1);
155  fsi_code = kIHAFtNoInteraction;
156  }
157  bool escaped = (fsi_code == (int)kIHAFtNoInteraction);
158  bool interacted = !escaped;
159 
160  LOG("ReW", pDEBUG)
161  << "Attempting to reweight hadron at position = " << ip
162  << " with PDG code = " << pdgc
163  << ". The hadron "
164  << ((interacted) ? "re-interacted" : "did not re-interact");
165 
166  // Default formation zone
167  double m = p->Mass();
168  TLorentzVector * p4 = p->P4();
169 
170  double ct0=0.;
171  pdg::IsNucleon(pdgc) ? ct0=fct0nucleon : ct0=fct0pion;
172  double fz_def = phys::FormationZone(m,*p4,p3hadr,ct0,fK);
173 
174  double fz_scale_factor = (1 + fFZoneTwkDial * fracerr);
175  double fz_twk = fz_def * fz_scale_factor;
176  fz_twk = TMath::Max(0.,fz_twk);
177 
178  LOG("ReW", pDEBUG)
179  << "Formation zone = " << fz_def << " fm (nominal), "
180  << fz_twk << " fm (tweaked) - scale factor = " << fz_scale_factor;
181 
182  // Calculate hadron's position at the end of the formation zone step
183  TVector3 step3v = p4->Vect();
184  step3v.SetMag(fz_def);
185  TLorentzVector step4v(step3v, 0.);
186 
187  TLorentzVector x4 = vtx + step4v;
188  LOG("ReW", pDEBUG) << "Vtx position: "<< print::X4AsString(&vtx);
189  LOG("ReW", pDEBUG) << "Hadron position: "<< print::X4AsString(&x4);
190 
191  // Calculate particle weight
192  double hadron_weight = genie::utils::rew::FZoneWeight(
193  pdgc, vtx, x4, *p4, A, Z, fz_scale_factor, interacted);
194 
195  // Update event weight
196  event_weight *= hadron_weight;
197  }
198 
199  return event_weight;
200 }
201 //_______________________________________________________________________________________
203 {
204  fFZoneTwkDial = 0.;
205 
206  this->SetR0 (1.3);//fm
207  this->SetNR (3.);
208  this->SetCT0Pion (0.342);//fm
209  this->SetCT0Nucleon (2.300);//fm
210  this->SetK (0.);
211 }
212 //_______________________________________________________________________________________
213 
double FZoneWeight(int pdgc, const TLorentzVector &vtx, const TLorentzVector &x4, const TLorentzVector &p4, double A, double Z, double fz_scale_factor, bool interacted, double nRpi=0.5, double nRnuc=1.0, double NR=3, double R0=1.4)
static const double m
Definition: Units.h:79
int Z(void) const
int RescatterCode(void) const
Definition: GHepParticle.h:66
#include "Numerical/GSFunc.h"
Definition: AlgCmp.h:26
double fFZoneTwkDial
formation zone tweaking dial
bool IsNucleon(int pdgc)
Definition: PDGUtils.cxx:316
enum genie::EGHepStatus GHepStatus_t
TLorentzVector Hadronic4pLAB(const EventRecord &event)
#define pFATAL
Definition: Messenger.h:47
void SetCT0Nucleon(double ct0)
double Mass(void) const
Mass that corresponds to the PDG code.
double CalcWeight(const EventRecord &event)
calculate a weight for the input event using the current nuisance param values
GHepStatus_t Status(void) const
Definition: GHepParticle.h:65
double FormationZone(double m, const TLorentzVector &p, const TVector3 &p3hadr, double ct0, double K)
Definition: PhysUtils.cxx:29
double OneSigmaErr(GSyst_t syst, int sign=0) const
int Pdg(void) const
Definition: GHepParticle.h:64
bool IsHadron(int pdgc)
Definition: PDGUtils.cxx:362
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:87
bool IsHandled(GSyst_t syst)
does the current weight calculator handle the input nuisance param?
void SetCT0Pion(double ct0)
static const double kASmallNum
Definition: Controls.h:40
An enumeration of systematic parameters.
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
p
Definition: test.py:228
static const double A
Definition: Units.h:82
tweak formation zone
Definition: GSyst.h:113
virtual GHepParticle * HitNucleon(void) const
Definition: GHepRecord.cxx:343
void SetSystematic(GSyst_t syst, double val)
update the value for the specified nuisance param
void Reset(void)
set all nuisance parameters to default values
static GSystUncertainty * Instance(void)
int A(void) const
string X4AsString(const TLorentzVector *x)
Definition: PrintUtils.cxx:64
TLorentzVector * P4(void) const
Definition: GHepParticle.h:79
void Reconfigure(void)
propagate updated nuisance parameter values to actual MC, etc
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:40
Root of GENIE utility namespaces.
Event finding and building.
GENIE event reweighting engine ABC.
Definition: GReWeightI.h:31
#define pDEBUG
Definition: Messenger.h:54