LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
NuReweight.cxx
Go to the documentation of this file.
1 
8 // C/C++ includes
9 #include <math.h>
10 #include <map>
11 #include <fstream>
12 #include <memory>
13 
14 //ROOT includes
15 #include "TVector3.h"
16 #include "TLorentzVector.h"
17 #include "TSystem.h"
18 
19 //GENIE includes
20 #include "Conventions/Units.h"
21 #include "EVGCore/EventRecord.h"
22 #include "GHEP/GHepUtils.h"
23 
24 #include "ReWeight/GReWeightI.h"
25 #include "ReWeight/GSystSet.h"
26 #include "ReWeight/GSyst.h"
27 #include "ReWeight/GReWeight.h"
28 #include "ReWeight/GReWeightNuXSecNCEL.h"
29 #include "ReWeight/GReWeightNuXSecCCQE.h"
30 #include "ReWeight/GReWeightNuXSecCCRES.h"
31 #include "ReWeight/GReWeightNuXSecCOH.h"
32 #include "ReWeight/GReWeightNonResonanceBkg.h"
33 #include "ReWeight/GReWeightFGM.h"
34 #include "ReWeight/GReWeightDISNuclMod.h"
35 #include "ReWeight/GReWeightResonanceDecay.h"
36 #include "ReWeight/GReWeightFZone.h"
37 #include "ReWeight/GReWeightINuke.h"
38 #include "ReWeight/GReWeightAGKY.h"
39 #include "ReWeight/GReWeightNuXSecCCQEvec.h"
40 #include "ReWeight/GReWeightNuXSecNCRES.h"
41 #include "ReWeight/GReWeightNuXSecDIS.h"
42 #include "ReWeight/GReWeightNuXSecNC.h"
43 #include "ReWeight/GSystUncertainty.h"
44 #include "ReWeight/GReWeightUtils.h"
45 
46 #include "Geo/ROOTGeomAnalyzer.h"
47 #include "Geo/GeomVolSelectorFiducial.h"
48 #include "Geo/GeomVolSelectorRockBox.h"
49 #include "Utils/StringUtils.h"
50 #include "Utils/XmlParserUtils.h"
51 #include "Interaction/InitialState.h"
52 #include "Interaction/Interaction.h"
53 #include "Interaction/Kinematics.h"
54 #include "Interaction/KPhaseSpace.h"
55 #include "Interaction/ProcessInfo.h"
56 #include "Interaction/XclsTag.h"
57 #include "GHEP/GHepParticle.h"
58 #include "PDG/PDGCodeList.h"
59 #include "Conventions/Constants.h" //for calculating event kinematics
60 
61 //NuTools includes
67 
68 namespace rwgt {
69 
72  //mf::LogVerbatim("GENIEReweight") << "Create GENIEReweight object";
73  }
74 
77  // Don't delete fWcalc here. The GENIEReweight parent class handles it.
78  }
79 
80  double NuReweight::CalcWeight(const simb::MCTruth & truth, const simb::GTruth & gtruth) const {
81  genie::EventRecord evr = this->RetrieveGHEP(truth, gtruth);
82  double wgt = this->CalculateWeight(evr);
83  //mf::LogVerbatim("GENIEReweight") << "New Event Weight is: " << wgt;
84  return wgt;
85  }
86 
87  genie::EventRecord NuReweight::RetrieveGHEP(const simb::MCTruth & truth, const simb::GTruth & gtruth) const {
88  genie::EventRecord newEvent;
89  newEvent.SetWeight(gtruth.fweight);
90  newEvent.SetProbability(gtruth.fprobability);
91  newEvent.SetXSec(gtruth.fXsec);
92 #ifndef SETDIFFXSEC_1ARG
93  // this argument is used only for bookkeeping purposes in a GHepRecord.
94  // since we're making a GHepRecord that will be thrown away
95  // as soon as we're done getting the weights for it,
96  // it doesn't matter what we put here.
97  genie::KinePhaseSpace_t space = genie::kPSNull;
98  newEvent.SetDiffXSec(gtruth.fDiffXsec,space);
99 #else
100  newEvent.SetDiffXSec(gtruth.fDiffXsec);
101 #endif
102  TLorentzVector vtx = gtruth.fVertex;
103  newEvent.SetVertex(vtx);
104 
105  for(int i = 0; i < truth.NParticles(); i++) {
106  simb::MCParticle mcpart = truth.GetParticle(i);
107 
108  int gmid = mcpart.PdgCode();
109  genie::GHepStatus_t gmst = (genie::GHepStatus_t)mcpart.StatusCode();
110  int gmmo = mcpart.Mother();
111  int ndaughters = mcpart.NumberDaughters();
112  //find the track ID of the first and last daughter particles
113  int fdtrkid = 0;
114  int ldtrkid = 0;
115  if(ndaughters !=0) {
116  fdtrkid = mcpart.Daughter(0);
117  if(ndaughters == 1) {
118  ldtrkid = 1;
119  }
120  else if(ndaughters >1) {
121  fdtrkid = mcpart.Daughter(ndaughters-1);
122  }
123  }
124  int gmfd = -1;
125  int gmld = -1;
126  //Genie uses the index in the particle array to reference the daughter particles.
127  //MCTruth keeps the particles in the same order so use the track ID to find the proper index.
128  for(int j = 0; j < truth.NParticles(); j++) {
129  simb::MCParticle temp = truth.GetParticle(i);
130  if(temp.TrackId() == fdtrkid) {
131  gmfd = j;
132  }
133  if(temp.TrackId() == ldtrkid) {
134  gmld = j;
135  }
136  }
137 
138  double gmpx = mcpart.Px(0);
139  double gmpy = mcpart.Py(0);
140  double gmpz = mcpart.Pz(0);
141  double gme = mcpart.E(0);
142  double gmvx = mcpart.Gvx();
143  double gmvy = mcpart.Gvy();
144  double gmvz = mcpart.Gvz();
145  double gmvt = mcpart.Gvt();
146  int gmri = mcpart.Rescatter();
147 
148  genie::GHepParticle gpart(gmid, gmst, gmmo, -1, gmfd, gmld, gmpx, gmpy, gmpz, gme, gmvx, gmvy, gmvz, gmvt);
149  gpart.SetRescatterCode(gmri);
150  TVector3 polz = mcpart.Polarization();
151  if(polz.x() !=0 || polz.y() !=0 || polz.z() !=0) {
152  gpart.SetPolarization(polz);
153  }
154  newEvent.AddParticle(gpart);
155 
156  }
157 
158  genie::ProcessInfo proc_info;
159  genie::ScatteringType_t gscty = (genie::ScatteringType_t)gtruth.fGscatter;
160  genie::InteractionType_t ginty = (genie::InteractionType_t)gtruth.fGint;
161 
162  proc_info.Set(gscty,ginty);
163 
164  genie::XclsTag gxt;
165 
166  //Set Exclusive Final State particle numbers
167  genie::Resonance_t gres = (genie::Resonance_t)gtruth.fResNum;
168  gxt.SetResonance(gres);
169  gxt.SetNPions(gtruth.fNumPiPlus, gtruth.fNumPi0, gtruth.fNumPiMinus);
170  gxt.SetNNucleons(gtruth.fNumProton, gtruth.fNumNeutron);
171 
172  if(gtruth.fIsCharm) {
173  gxt.SetCharm(0);
174  }
175  else {
176  gxt.UnsetCharm();
177  }
178 
179  //Set the GENIE kinematic info
180  genie::Kinematics gkin;
181  gkin.Setx(gtruth.fgX, true);
182  gkin.Sety(gtruth.fgY, true);
183  gkin.Sett(gtruth.fgT, true);
184  gkin.SetW(gtruth.fgW, true);
185  gkin.SetQ2(gtruth.fgQ2, true);
186  gkin.Setq2(gtruth.fgq2, true);
187  simb::MCNeutrino nu = truth.GetNeutrino();
188  simb::MCParticle lep = nu.Lepton();
189  gkin.SetFSLeptonP4(lep.Px(), lep.Py(), lep.Pz(), lep.E());
190  gkin.SetHadSystP4(gtruth.fFShadSystP4.Px(), gtruth.fFShadSystP4.Py(), gtruth.fFShadSystP4.Pz(), gtruth.fFShadSystP4.E());
191 
192  //Set the GENIE final state interaction info
193  genie::Interaction * p_gint = new genie::Interaction;
194  genie::InitialState * p_ginstate = p_gint->InitStatePtr();
195  //int Z = gtruth.ftgtZ;
196  //int A = gtruth.ftgtA;
197  int targetNucleon = nu.HitNuc();
198  int struckQuark = nu.HitQuark();
199  int incoming = gtruth.fProbePDG;
200  p_ginstate->SetProbePdg(incoming);
201 
202  genie::Target* target123 = p_ginstate->TgtPtr();
203 
204  target123->SetId(gtruth.ftgtPDG);
205  //target123->SetId(Z,A);
206 
207  //int pdg_code = pdg::IonPdgCode(A, Z);
208  //TParticlePDG * p = PDGLibrary::Instance()->Find(pdg_code);
209 
210  //mf::LogWarning("GENIEReweight") << "Setting Target Z and A";
211  //mf::LogWarning("GENIEReweight") << "Saved PDG: " << gtruth.ftgtPDG;
212  //mf::LogWarning("GENIEReweight") << "Target PDG: " << target123->Pdg();
213  target123->SetHitNucPdg(targetNucleon);
214  target123->SetHitQrkPdg(struckQuark);
215  target123->SetHitSeaQrk(gtruth.fIsSeaQuark);
216 
217  if(newEvent.HitNucleonPosition()> 0) {
218  genie::GHepParticle * hitnucleon = newEvent.HitNucleon();
219  std::unique_ptr<TLorentzVector> p4hitnucleon(hitnucleon->GetP4());
220  target123->SetHitNucP4(*p4hitnucleon);
221  }
222  else {
223  TLorentzVector dummy(0.,0.,0.,0.);
224  target123->SetHitNucP4(dummy);
225  }
226 
227  genie::GHepParticle * probe = newEvent.Probe();
228  std::unique_ptr<TLorentzVector> p4probe(probe->GetP4());
229  p_ginstate->SetProbeP4(*p4probe);
230  if(newEvent.TargetNucleusPosition()> 0) {
231  genie::GHepParticle * target = newEvent.TargetNucleus();
232  std::unique_ptr<TLorentzVector> p4target(target->GetP4());
233  p_ginstate->SetTgtP4(*p4target);
234  } else {
235  TLorentzVector dummy(0.,0.,0.,0.);
236  p_ginstate->SetTgtP4(dummy);
237  }
238  p_gint->SetProcInfo(proc_info);
239  p_gint->SetKine(gkin);
240  p_gint->SetExclTag(gxt);
241  newEvent.AttachSummary(p_gint);
242 
243  /*
244  //For temporary debugging purposes
245  genie::Interaction *inter = newEvent.Summary();
246  const genie::InitialState &initState = inter->InitState();
247  const genie::Target &tgt = initState.Tgt();
248  std::cout << "TargetPDG as Recorded: " << gtruth.ftgtPDG << std::endl;
249  std::cout << "TargetZ as Recorded: " << gtruth.ftgtZ << std::endl;
250  std::cout << "TargetA as Recorded: " << gtruth.ftgtA << std::endl;
251  std::cout << "TargetPDG as Recreated: " << tgt.Pdg() << std::endl;
252  std::cout << "TargetZ as Recreated: " << tgt.Z() << std::endl;
253  std::cout << "TargetA as Recreated: " << tgt.A() << std::endl;
254  */
255  return newEvent;
256 
257  }
258 
259 }
double fgW
Definition: GTruth.h:48
double E(const int i=0) const
Definition: MCParticle.h:237
int fGint
interaction code
Definition: GTruth.h:25
const TVector3 & Polarization() const
Definition: MCParticle.h:218
int PdgCode() const
Definition: MCParticle.h:216
double fgq2
Definition: GTruth.h:47
const simb::MCNeutrino & GetNeutrino() const
Definition: MCTruth.h:74
double fgX
Definition: GTruth.h:50
double Py(const int i=0) const
Definition: MCParticle.h:235
double Gvz() const
Definition: MCParticle.h:252
int HitQuark() const
Definition: MCNeutrino.h:157
cout<< "-> Edep in the target
Definition: analysis.C:54
int Mother() const
Definition: MCParticle.h:217
double Px(const int i=0) const
Definition: MCParticle.h:234
int fNumNeutron
number of neutrons after reaction, before FSI
Definition: GTruth.h:40
int HitNuc() const
Definition: MCNeutrino.h:156
double CalculateWeight(const genie::EventRecord &evr) const
double fXsec
cross section of interaction
Definition: GTruth.h:32
int fNumPiPlus
number of pi pluses after reaction, before FSI
Definition: GTruth.h:36
int StatusCode() const
Definition: MCParticle.h:215
int fNumPiMinus
number of pi minuses after reaction, before FSI
Definition: GTruth.h:37
double Gvx() const
Definition: MCParticle.h:250
int NParticles() const
Definition: MCTruth.h:72
double Gvy() const
Definition: MCParticle.h:251
Particle class.
int NumberDaughters() const
Definition: MCParticle.h:221
int TrackId() const
Definition: MCParticle.h:214
int Daughter(const int i) const
Definition: MCParticle.cxx:112
int fResNum
resonance number
Definition: GTruth.h:42
int fNumProton
number of protons after reaction, before FSI
Definition: GTruth.h:39
double fprobability
interaction probability
Definition: GTruth.h:31
const simb::MCParticle & Lepton() const
Definition: MCNeutrino.h:151
int fProbePDG
Definition: GTruth.h:62
int fGscatter
neutrino scattering code
Definition: GTruth.h:26
int fNumPi0
number of pi0 after reaction, before FSI
Definition: GTruth.h:38
bool fIsCharm
did the interaction produce a charmed hadron?
Definition: GTruth.h:41
double fweight
event interaction weight (genie internal)
Definition: GTruth.h:30
NuReweight()
<constructor
Definition: NuReweight.cxx:71
const simb::MCParticle & GetParticle(int i) const
Definition: MCTruth.h:73
int ftgtPDG
PDG of Target Nucleus, nucleon only if free.
Definition: GTruth.h:59
double fgQ2
< these are for the internal (on shell) genie kinematics
Definition: GTruth.h:46
double Gvt() const
Definition: MCParticle.h:253
TLorentzVector fFShadSystP4
Definition: GTruth.h:52
double Pz(const int i=0) const
Definition: MCParticle.h:236
genie::EventRecord RetrieveGHEP(const simb::MCTruth &truth, const simb::GTruth &gtruth) const
Definition: NuReweight.cxx:87
int Rescatter() const
Definition: MCParticle.h:256
double fgT
Definition: GTruth.h:49
Event generator information.
Definition: MCTruth.h:30
Event generator information.
Definition: MCNeutrino.h:18
bool fIsSeaQuark
Definition: GTruth.h:55
double CalcWeight(const simb::MCTruth &truth, const simb::GTruth &gtruth) const
Definition: NuReweight.cxx:80
TLorentzVector fVertex
Definition: GTruth.h:64
double fgY
Definition: GTruth.h:51
double fDiffXsec
differential cross section of interaction
Definition: GTruth.h:33
Wrapper for reweightings neutrino interactions within the ART framework.