GReWeightFGM.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  For the class documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13  @ Apr 27, 2010 - CA
14  First included in v2.7.1.
15 
16 */
17 //____________________________________________________________________________
18 
19 #include <TFile.h>
20 #include <TNtupleD.h>
21 
22 #include "Algorithm/AlgFactory.h"
23 #include "Conventions/Controls.h"
24 #include "EVGCore/EventRecord.h"
25 #include "GHEP/GHepParticle.h"
26 #include "Messenger/Messenger.h"
29 #include "PDG/PDGCodes.h"
30 #include "ReWeight/GReWeightFGM.h"
31 
34 #include "Utils/NuclearUtils.h"
35 
36 using namespace genie;
37 using namespace genie::rew;
38 using namespace genie::utils;
39 
40 //_______________________________________________________________________________________
42 GReWeightI()
43 {
44  this->Init();
45 }
46 //_______________________________________________________________________________________
48 {
49 #ifdef _G_REWEIGHT_FGM_DEBUG_
50  fTestFile->cd();
51  fTestNtp ->Write();
52  fTestFile->Close();
53  delete fTestFile;
54 #endif
55 }
56 //_______________________________________________________________________________________
58 {
59  switch(syst) {
60  case ( kSystNucl_CCQEPauliSupViaKF ) :
62  return true;
63  break;
64  default:
65  return false;
66  break;
67  }
68  return false;
69 }
70 //_______________________________________________________________________________________
72 {
73  switch(syst) {
74  case ( kSystNucl_CCQEPauliSupViaKF ) :
75  fKFTwkDial = val;
76  break;
79  break;
80  default:
81  return;
82  break;
83  }
84 }
85 //_______________________________________________________________________________________
87 {
88  fKFTwkDial = 0.;
89  fMomDistroTwkDial = 0.;
90 }
91 //_______________________________________________________________________________________
93 {
94 
95 }
96 //_______________________________________________________________________________________
98 {
99  double wght =
100  this->RewCCQEPauliSupViaKF (event) *
101  this->RewCCQEMomDistroFGtoSF (event);
102 
103  return wght;
104 }
105 //_______________________________________________________________________________________
107 {
108  bool kF_tweaked = (TMath::Abs(fKFTwkDial) > controls::kASmallNum);
109  if(!kF_tweaked) return 1.;
110 
111  bool is_qe = event.Summary()->ProcInfo().IsQuasiElastic();
112  bool is_cc = event.Summary()->ProcInfo().IsWeakCC();
113  if(!is_qe || !is_cc) return 1.;
114 
115  const Target & target = event.Summary()->InitState().Tgt();
116  if (!target.IsNucleus()) {
117  return 1.;
118  }
119 
120  double A = target.A();
121  if(A <= 4) {
122  return 1.;
123  }
124 
125  int target_pdgc = target.Pdg();
126  int struck_nucleon_pdgc = target.HitNucPdg();
127  int final_nucleon_pdgc = pdg::SwitchProtonNeutron(struck_nucleon_pdgc);
128 
130  const FermiMomentumTable * kft = kftp->GetTable("Default");
131 
132  // Fermi momentum for initial, final nucleons
133  double kFi = kft->FindClosestKF(target_pdgc, struck_nucleon_pdgc);
134  double kFf = kft->FindClosestKF(target_pdgc, final_nucleon_pdgc );
135 
136  // hit nucleon mass
137  double Mn = target.HitNucP4Ptr()->M(); // can be off m/shell
138 
139  // momentum transfer
140  const Kinematics & kine = event.Summary()->Kine();
141  bool selected = true;
142  double q2 = kine.q2(selected);
143 
144  const double pmax = 0.5; // GeV
145 
146  // default nuclear suppression
147  double R = utils::nuclear::RQEFG_generic(q2, Mn, kFi, kFf, pmax);
148 
149  // tweak kF
151  double kF_fracerr = uncertainty->OneSigmaErr(kSystNucl_CCQEPauliSupViaKF);
152 
153  double kFi_twk = kFi * (1 + fKFTwkDial * kF_fracerr);
154  double kFf_twk = kFf * (1 + fKFTwkDial * kF_fracerr);
155 
156  // calculate tweaked nuclear suppression factor
157  double Rtwk = nuclear::RQEFG_generic(q2, Mn, kFi_twk, kFf_twk, pmax);
158 
159  // calculate weight (ratio of suppression factors)
160 
161  double wght = 1.0;
162 
163  if(R>0 && Rtwk>0) {
164  wght = Rtwk/R;
165  }
166 
167 #ifdef _G_REWEIGHT_FGM_DEBUG_
168  fTestNtp->Fill(-q2,wght);
169 #endif
170 
171  return wght;
172 }
173 //_______________________________________________________________________________________
175 {
176  bool momdistro_tweaked = (TMath::Abs(fMomDistroTwkDial) > controls::kASmallNum);
177  if(!momdistro_tweaked) return 1.;
178 
179  bool is_qe = event.Summary()->ProcInfo().IsQuasiElastic();
180  bool is_cc = event.Summary()->ProcInfo().IsWeakCC();
181  if(!is_qe || !is_cc) return 1.;
182 
183  GHepParticle * tgtnucleus = event.TargetNucleus();
184  if(!tgtnucleus) return 1.; // scattering off free-nucleon
185 
186  GHepParticle * hitnucleon = event.HitNucleon();
187  if(!hitnucleon) return 1.;
188 
189  const double kPmax = 0.5;
190  double p = hitnucleon->P4()->Vect().Mag();
191  if(p > kPmax) return 1.;
192 
193  TH1D * hfg = 0;
194  TH1D * hsf = 0;
195 
196  int tgtpdg = tgtnucleus -> Pdg();
197  int nucpdg = hitnucleon -> Pdg();
198 
199  map<int, TH1D*> & mapfg = pdg::IsNeutron(nucpdg) ? fMapFGn : fMapFGp;
200  map<int, TH1D*> & mapsf = pdg::IsNeutron(nucpdg) ? fMapSFn : fMapSFp;
201 
203  it = mapfg.find(tgtpdg);
204  if(it != mapfg.end()) { hfg = it->second; }
205  it = mapsf.find(tgtpdg);
206  if(it != mapsf.end()) { hsf = it->second; }
207 
208  bool have_weight_func = (hfg!=0) && (hsf!=0);
209  if(!have_weight_func) {
210  const int kNEv = 20000;
211  const int kNP = 500;
212  hfg = new TH1D("","",kNP,0.,kPmax);
213  hsf = new TH1D("","",kNP,0.,kPmax);
214  hfg -> SetDirectory(0);
215  hsf -> SetDirectory(0);
216  const Target & tgt = event.Summary()->InitState().Tgt();
217  bool ok = true;
218  for(int iev=0; iev<kNEv; iev++) {
219  ok = fFG->GenerateNucleon(tgt);
220  if(!ok) {
221  delete hfg;
222  delete hsf;
223  return 1.;
224  }
225  hfg->Fill(fFG->Momentum());
226  }//fg
227  for(int iev=0; iev<kNEv; iev++) {
228  ok = fSF->GenerateNucleon(tgt);
229  if(!ok) {
230  delete hfg;
231  delete hsf;
232  return 1.;
233  }
234  hsf->Fill(fSF->Momentum());
235  }//sf
236  hfg->Scale(1. / hfg->Integral("width"));
237  hsf->Scale(1. / hsf->Integral("width"));
238  mapfg.insert(map<int,TH1D*>::value_type(tgtpdg,hfg));
239  mapsf.insert(map<int,TH1D*>::value_type(tgtpdg,hsf));
240  }//create & store momentum distributions
241 
242 
243  double f_fg = hfg->GetBinContent( hfg->FindBin(p) );
244  double f_sf = hsf->GetBinContent( hsf->FindBin(p) );
245  double dial = fMomDistroTwkDial;
246  double wght = (f_sf * dial + f_fg * (1-dial)) / f_fg;
247 
248  return wght;
249 }
250 //_______________________________________________________________________________________
252 {
253  fKFTwkDial = 0.;
254  fMomDistroTwkDial = 0.;
255 
256  AlgFactory * algf = AlgFactory::Instance();
257 
258  fFG = dynamic_cast<const NuclearModelI*> (
259  algf->GetAlgorithm("genie::FGMBodekRitchie","Default"));
260  fSF = dynamic_cast<const NuclearModelI*> (
261  algf->GetAlgorithm("genie::SpectralFunc","Default"));
262 
263 #ifdef _G_REWEIGHT_FGM_DEBUG_
264  fTestFile = new TFile("./fgm_reweight_test.root","recreate");
265  fTestNtp = new TNtupleD("testntp","","Q2:wght");
266 #endif
267 }
268 //_______________________________________________________________________________________
269 
double RewCCQEMomDistroFGtoSF(const EventRecord &event)
map< int, TH1D * > fMapFGp
Definition: GReWeightFGM.h:73
int kNP
virtual double Momentum(void) const
Definition: NuclearModelI.h:55
#include "Numerical/GSFunc.h"
Definition: AlgCmp.h:26
int HitNucPdg(void) const
Definition: Target.cxx:311
intermediate_table::iterator iterator
void Reconfigure(void)
propagate updated nuisance parameter values to actual MC, etc
int A(void) const
Definition: Target.h:71
bool IsNucleus(void) const
Definition: Target.cxx:279
int Pdg(void) const
Definition: Target.h:72
static FermiMomentumTablePool * Instance(void)
Generated/set kinematical variables for an event.
Definition: Kinematics.h:40
int SwitchProtonNeutron(int pdgc)
Definition: PDGUtils.cxx:326
Pure abstract base class. Defines the NuclearModelI interface to be implemented by any physics model ...
Definition: NuclearModelI.h:42
A table of Fermi momentum constants.
map< int, TH1D * > fMapFGn
Definition: GReWeightFGM.h:72
const NuclearModelI * fFG
Definition: GReWeightFGM.h:69
bool IsHandled(GSyst_t syst)
does the current weight calculator handle the input nuisance param?
double OneSigmaErr(GSyst_t syst, int sign=0) const
map< int, TH1D * > fMapSFp
Definition: GReWeightFGM.h:75
bool IsNeutron(int pdgc)
Definition: PDGUtils.cxx:311
double RQEFG_generic(double q2, double Mn, double kFi, double kFf, double pmax)
double q2(bool selected=false) const
Definition: Kinematics.cxx:151
Singleton class to load & serve tables of Fermi momentum constants.
const FermiMomentumTable * GetTable(string name)
A Neutrino Interaction Target. Is a transparent encapsulation of quite different physical systems suc...
Definition: Target.h:41
const Algorithm * GetAlgorithm(const AlgId &algid)
Definition: AlgFactory.cxx:86
void Reset(void)
set all nuisance parameters to default values
static const double kASmallNum
Definition: Controls.h:40
double CalcWeight(const EventRecord &event)
calculate a weight for the input event using the current nuisance param values
An enumeration of systematic parameters.
map< int, TH1D * > fMapSFn
Definition: GReWeightFGM.h:74
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
TLorentzVector * HitNucP4Ptr(void) const
Definition: Target.cxx:254
static AlgFactory * Instance()
Definition: AlgFactory.cxx:75
virtual bool GenerateNucleon(const Target &) const =0
static GSystUncertainty * Instance(void)
double FindClosestKF(int target_pdgc, int nucleon_pdgc) const
The GENIE Algorithm Factory.
Definition: AlgFactory.h:40
TLorentzVector * P4(void) const
Definition: GHepParticle.h:79
void SetSystematic(GSyst_t syst, double val)
update the value for the specified nuisance param
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
double RewCCQEPauliSupViaKF(const EventRecord &event)
Root of GENIE utility namespaces.
Event finding and building.
const NuclearModelI * fSF
Definition: GReWeightFGM.h:70
GENIE event reweighting engine ABC.
Definition: GReWeightI.h:31