NuReweight.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file NuReweight.cxx
3 /// \brief Wrapper for reweightings neutrino interactions within the ART framework
4 ///
5 /// \author nathan.mayer@tufts.edu
6 ////////////////////////////////////////////////////////////////////////
7 
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 #ifdef GENIE_PRE_R3
21  #include "Conventions/Units.h"
22  #include "EVGCore/EventRecord.h"
23  #include "GHEP/GHepUtils.h"
24 
25 #include "ReWeight/GReWeightI.h"
26 #include "ReWeight/GSystSet.h"
27 #include "ReWeight/GSyst.h"
28 #include "ReWeight/GReWeight.h"
29 #include "ReWeight/GReWeightNuXSecNCEL.h"
30 #include "ReWeight/GReWeightNuXSecCCQE.h"
31 #include "ReWeight/GReWeightNuXSecCCRES.h"
32 #include "ReWeight/GReWeightNuXSecCOH.h"
33 #include "ReWeight/GReWeightNonResonanceBkg.h"
34 #include "ReWeight/GReWeightFGM.h"
35 #include "ReWeight/GReWeightDISNuclMod.h"
36 #include "ReWeight/GReWeightResonanceDecay.h"
37 #include "ReWeight/GReWeightFZone.h"
38 #include "ReWeight/GReWeightINuke.h"
39 #include "ReWeight/GReWeightAGKY.h"
40 #include "ReWeight/GReWeightNuXSecCCQEvec.h"
41 #include "ReWeight/GReWeightNuXSecNCRES.h"
42 #include "ReWeight/GReWeightNuXSecDIS.h"
43 #include "ReWeight/GReWeightNuXSecNC.h"
44 #include "ReWeight/GSystUncertainty.h"
45 #include "ReWeight/GReWeightUtils.h"
46 
47 //#include "Geo/ROOTGeomAnalyzer.h"
48 //#include "Geo/GeomVolSelectorFiducial.h"
49 //#include "Geo/GeomVolSelectorRockBox.h"
50 //#include "Utils/StringUtils.h"
51 //#include "Utils/XmlParserUtils.h"
53  #include "Interaction/Interaction.h"
54  #include "Interaction/Kinematics.h"
55  #include "Interaction/KPhaseSpace.h"
56  #include "Interaction/ProcessInfo.h"
57  #include "Interaction/XclsTag.h"
58  #include "GHEP/GHepParticle.h"
59  #include "PDG/PDGCodeList.h"
60  #include "Conventions/Constants.h" //for calculating event kinematics
61 
62 #else
63  // GENIE includes R-3 and beyond
64  #include "GENIE/Framework/Messenger/Messenger.h"
65  #include "GENIE/Framework/Conventions/Units.h"
66  #include "GENIE/Framework/Conventions/Constants.h"
67  #include "GENIE/Framework/GHEP/GHepUtils.h"
68  #include "GENIE/Framework/EventGen/EventRecord.h"
69 
70 // #include "GENIE/Framework/Interaction/InitialState.h"
71 // #include "GENIE/Framework/Interaction/Interaction.h"
72 // #include "GENIE/Framework/Interaction/Kinematics.h"
73 // #include "GENIE/Framework/Interaction/KPhaseSpace.h"
74 // #include "GENIE/Framework/Interaction/ProcessInfo.h"
75 // #include "GENIE/Framework/Interaction/XclsTag.h"
76 
77 // #include "GENIE/Framework/ParticleData/PDGCodes.h"
78 // #include "GENIE/Framework/ParticleData/PDGCodeList.h"
79 // #include "GENIE/Framework/ParticleData/PDGLibrary.h"
80 // #include "GENIE/Framework/GHEP/GHepUtils.h"
81 
82  #include "GENIE/Framework/GHEP/GHepParticle.h"
83 
84  #include "RwFramework/GReWeightI.h"
85  #include "RwFramework/GSystSet.h"
86  #include "RwFramework/GSyst.h"
87  #include "RwFramework/GReWeight.h"
88  #include "RwFramework/GSystUncertainty.h"
89  #include "RwCalculators/GReWeightNuXSecNCEL.h"
90  #include "RwCalculators/GReWeightNuXSecCCQE.h"
91  #include "RwCalculators/GReWeightNuXSecCCRES.h"
92  #include "RwCalculators/GReWeightNuXSecCOH.h"
93  #include "RwCalculators/GReWeightNonResonanceBkg.h"
94  #include "RwCalculators/GReWeightFGM.h"
95  #include "RwCalculators/GReWeightDISNuclMod.h"
96  #include "RwCalculators/GReWeightResonanceDecay.h"
97  #include "RwCalculators/GReWeightFZone.h"
98  #include "RwCalculators/GReWeightINuke.h"
99  #include "RwCalculators/GReWeightAGKY.h"
100  #include "RwCalculators/GReWeightNuXSecCCQEvec.h"
101  #include "RwCalculators/GReWeightNuXSecNCRES.h"
102  #include "RwCalculators/GReWeightNuXSecDIS.h"
103  #include "RwCalculators/GReWeightNuXSecNC.h"
104  #include "RwCalculators/GReWeightUtils.h"
105 
106 #endif
107 
108 //NuTools includes
113 #include "nutools/NuReweight/art/NuReweight.h"
114 
115 namespace rwgt {
116 
117  ///<constructor
119  //mf::LogVerbatim("GENIEReweight") << "Create GENIEReweight object";
120  }
121 
122  ///<destructor
124  // Don't delete fWcalc here. The GENIEReweight parent class handles it.
125  }
126 
127  double NuReweight::CalcWeight(const simb::MCTruth & truth, const simb::GTruth & gtruth) const {
128  genie::EventRecord evr = this->RetrieveGHEP(truth, gtruth);
129  double wgt = this->CalculateWeight(evr);
130  //mf::LogVerbatim("GENIEReweight") << "New Event Weight is: " << wgt;
131  return wgt;
132  }
133 
135  genie::EventRecord newEvent;
136  newEvent.SetWeight(gtruth.fweight);
137  newEvent.SetProbability(gtruth.fprobability);
138  newEvent.SetXSec(gtruth.fXsec);
139 
142  newEvent.SetDiffXSec(gtruth.fDiffXsec,space);
143 
144  TLorentzVector vtx = gtruth.fVertex;
145  newEvent.SetVertex(vtx);
146 
147  for(int i = 0; i < truth.NParticles(); i++) {
148  simb::MCParticle mcpart = truth.GetParticle(i);
149 
150  int gmid = mcpart.PdgCode();
152  int gmmo = mcpart.Mother();
153  int ndaughters = mcpart.NumberDaughters();
154  //find the track ID of the first and last daughter particles
155  int fdtrkid = 0;
156  int ldtrkid = 0;
157  if(ndaughters !=0) {
158  fdtrkid = mcpart.Daughter(0);
159  if(ndaughters == 1) {
160  ldtrkid = 1;
161  }
162  else if(ndaughters >1) {
163  fdtrkid = mcpart.Daughter(ndaughters-1);
164  }
165  }
166  int gmfd = -1;
167  int gmld = -1;
168  //Genie uses the index in the particle array to reference the daughter particles.
169  //MCTruth keeps the particles in the same order so use the track ID to find the proper index.
170  for(int j = 0; j < truth.NParticles(); j++) {
171  simb::MCParticle temp = truth.GetParticle(i);
172  if(temp.TrackId() == fdtrkid) {
173  gmfd = j;
174  }
175  if(temp.TrackId() == ldtrkid) {
176  gmld = j;
177  }
178  }
179 
180  double gmpx = mcpart.Px(0);
181  double gmpy = mcpart.Py(0);
182  double gmpz = mcpart.Pz(0);
183  double gme = mcpart.E(0);
184  double gmvx = mcpart.Gvx();
185  double gmvy = mcpart.Gvy();
186  double gmvz = mcpart.Gvz();
187  double gmvt = mcpart.Gvt();
188  int gmri = mcpart.Rescatter();
189 
190  genie::GHepParticle gpart(gmid, gmst, gmmo, -1, gmfd, gmld, gmpx, gmpy, gmpz, gme, gmvx, gmvy, gmvz, gmvt);
191  gpart.SetRescatterCode(gmri);
192  TVector3 polz = mcpart.Polarization();
193  if(polz.x() !=0 || polz.y() !=0 || polz.z() !=0) {
194  gpart.SetPolarization(polz);
195  }
196  newEvent.AddParticle(gpart);
197 
198  }
199 
200  genie::ProcessInfo proc_info;
203 
204  proc_info.Set(gscty,ginty);
205 
206  genie::XclsTag gxt;
207 
208  //Set Exclusive Final State particle numbers
210  gxt.SetResonance(gres);
211  gxt.SetDecayMode(gtruth.fDecayMode);
212  gxt.SetNPions(gtruth.fNumPiPlus, gtruth.fNumPi0, gtruth.fNumPiMinus);
213  gxt.SetNNucleons(gtruth.fNumProton, gtruth.fNumNeutron);
214 
215  if (gtruth.fIsCharm) {
216  gxt.SetCharm(gtruth.fCharmHadronPdg);
217  } else {
218  gxt.UnsetCharm();
219  }
220 
221  if (gtruth.fIsStrange) {
222  gxt.SetStrange(gtruth.fStrangeHadronPdg);
223  } else {
224  gxt.UnsetStrange();
225  }
226 
227  //Set the GENIE kinematic info
228  genie::Kinematics gkin;
229  gkin.Setx(gtruth.fgX, true);
230  gkin.Sety(gtruth.fgY, true);
231  gkin.Sett(gtruth.fgT, true);
232  gkin.SetW(gtruth.fgW, true);
233  gkin.SetQ2(gtruth.fgQ2, true);
234  gkin.Setq2(gtruth.fgq2, true);
235  simb::MCNeutrino nu = truth.GetNeutrino();
236  simb::MCParticle lep = nu.Lepton();
237  gkin.SetFSLeptonP4(lep.Px(), lep.Py(), lep.Pz(), lep.E());
238  gkin.SetHadSystP4(gtruth.fFShadSystP4.Px(), gtruth.fFShadSystP4.Py(), gtruth.fFShadSystP4.Pz(), gtruth.fFShadSystP4.E());
239 
240  //Set the GENIE final state interaction info
241  genie::Interaction * p_gint = new genie::Interaction;
242  genie::InitialState * p_ginstate = p_gint->InitStatePtr();
243 
244  p_ginstate->SetPdgs(gtruth.ftgtPDG, gtruth.fProbePDG);
245 
246  int targetNucleon = nu.HitNuc();
247  int struckQuark = nu.HitQuark();
248 
249  genie::Target* target123 = p_ginstate->TgtPtr();
250  target123->SetHitNucPdg(targetNucleon);
251  target123->SetHitQrkPdg(struckQuark);
252  target123->SetHitSeaQrk(gtruth.fIsSeaQuark);
253  target123->SetHitNucPosition(gtruth.fHitNucPos);
254 
255  if(newEvent.HitNucleonPosition()> 0) {
256  genie::GHepParticle * hitnucleon = newEvent.HitNucleon();
257  std::unique_ptr<TLorentzVector> p4hitnucleon(hitnucleon->GetP4());
258  target123->SetHitNucP4(*p4hitnucleon);
259  }
260  else {
261  TLorentzVector dummy(0.,0.,0.,0.);
262  target123->SetHitNucP4(dummy);
263  }
264 
265  genie::GHepParticle * probe = newEvent.Probe();
266  std::unique_ptr<TLorentzVector> p4probe(probe->GetP4());
267  p_ginstate->SetProbeP4(*p4probe);
268  if(newEvent.TargetNucleusPosition()> 0) {
270  std::unique_ptr<TLorentzVector> p4target(target->GetP4());
271  p_ginstate->SetTgtP4(*p4target);
272  } else {
273  TLorentzVector dummy(0.,0.,0.,0.);
274  p_ginstate->SetTgtP4(dummy);
275  }
276  p_gint->SetProcInfo(proc_info);
277  p_gint->SetKine(gkin);
278  p_gint->SetExclTag(gxt);
279  newEvent.AttachSummary(p_gint);
280 
281  /*
282  //For temporary debugging purposes
283  genie::Interaction *inter = newEvent.Summary();
284  const genie::InitialState &initState = inter->InitState();
285  const genie::Target &tgt = initState.Tgt();
286 
287  std::cout << "TargetPDG as Recorded: " << gtruth.ftgtPDG << std::endl;
288  std::cout << "TargetZ as Recorded: " << gtruth.ftgtZ << std::endl;
289  std::cout << "TargetA as Recorded: " << gtruth.ftgtA << std::endl;
290  std::cout << "TargetPDG as Recreated: " << tgt.Pdg() << std::endl;
291  std::cout << "TargetZ as Recreated: " << tgt.Z() << std::endl;
292  std::cout << "TargetA as Recreated: " << tgt.A() << std::endl;
293  */
294 
295  return newEvent;
296 
297  }
298 
299 }
double fgW
Definition: GTruth.h:63
double E(const int i=0) const
Definition: MCParticle.h:232
int fGint
interaction code
Definition: GTruth.h:56
const TVector3 & Polarization() const
Definition: MCParticle.h:213
void SetTgtP4(const TLorentzVector &P4)
virtual void SetXSec(double xsec)
Definition: GHepRecord.h:133
void SetNPions(int npi_plus, int npi_0, int npi_minus)
Definition: XclsTag.cxx:97
int PdgCode() const
Definition: MCParticle.h:211
virtual void SetWeight(double wght)
Definition: GHepRecord.h:131
double fgq2
Definition: GTruth.h:62
const simb::MCNeutrino & GetNeutrino() const
Definition: MCTruth.h:77
double fgX
Definition: GTruth.h:65
double Py(const int i=0) const
Definition: MCParticle.h:230
double Gvz() const
Definition: MCParticle.h:247
void SetProbeP4(const TLorentzVector &P4)
int HitQuark() const
Definition: MCNeutrino.h:153
void SetQ2(double Q2, bool selected=false)
Definition: Kinematics.cxx:265
void Setq2(double q2, bool selected=false)
Definition: Kinematics.cxx:277
int Mother() const
Definition: MCParticle.h:212
enum genie::EGHepStatus GHepStatus_t
virtual void SetProbability(double prob)
Definition: GHepRecord.h:132
void UnsetStrange(void)
Definition: XclsTag.cxx:91
int fGPhaseSpace
phase space system of DiffXSec
Definition: GTruth.h:32
double Px(const int i=0) const
Definition: MCParticle.h:229
int fNumNeutron
number of neutrons after reaction, before FSI
Definition: GTruth.h:76
void SetHitNucP4(const TLorentzVector &p4)
Definition: Target.cxx:206
Generated/set kinematical variables for an event.
Definition: Kinematics.h:40
int HitNuc() const
Definition: MCNeutrino.h:152
double CalculateWeight(const genie::EventRecord &evr) const
void SetHitQrkPdg(int pdgc)
Definition: Target.cxx:201
virtual int HitNucleonPosition(void) const
Definition: GHepRecord.cxx:454
double fXsec
cross section of interaction
Definition: GTruth.h:30
void SetHitNucPosition(double r)
Definition: Target.cxx:227
int fNumPiPlus
number of pi pluses after reaction, before FSI
Definition: GTruth.h:78
int StatusCode() const
Definition: MCParticle.h:210
int fNumPiMinus
number of pi minuses after reaction, before FSI
Definition: GTruth.h:79
double Gvx() const
Definition: MCParticle.h:245
int NParticles() const
Definition: MCTruth.h:75
void SetKine(const Kinematics &kine)
void SetPolarization(double theta, double phi)
double Gvy() const
Definition: MCParticle.h:246
enum genie::EKinePhaseSpace KinePhaseSpace_t
Particle class.
enum genie::EResonance Resonance_t
void SetResonance(Resonance_t res)
Definition: XclsTag.cxx:137
void Set(ScatteringType_t sc_type, InteractionType_t int_type)
bool fIsStrange
strange production // added version 13
Definition: GTruth.h:73
int NumberDaughters() const
Definition: MCParticle.h:216
virtual void AttachSummary(Interaction *interaction)
Definition: GHepRecord.cxx:143
Contains minimal information for tagging exclusive processes.
Definition: XclsTag.h:39
int TrackId() const
Definition: MCParticle.h:209
int Daughter(const int i) const
Definition: MCParticle.cxx:112
void SetCharm(int charm_pdgc=0)
Definition: XclsTag.cxx:68
virtual GHepParticle * Probe(void) const
Definition: GHepRecord.cxx:321
int fResNum
resonance number
Definition: GTruth.h:80
Summary information for an interaction.
Definition: Interaction.h:55
int fNumProton
number of protons after reaction, before FSI
Definition: GTruth.h:75
int fDecayMode
Definition: GTruth.h:81
double fprobability
interaction probability
Definition: GTruth.h:29
const simb::MCParticle & Lepton() const
Definition: MCNeutrino.h:147
int fProbePDG
Definition: GTruth.h:39
void SetFSLeptonP4(const TLorentzVector &p4)
Definition: Kinematics.cxx:307
int fGscatter
neutrino scattering code
Definition: GTruth.h:55
void SetStrange(int strange_pdgc=0)
Definition: XclsTag.cxx:85
A class encapsulating an enumeration of interaction types (EM, Weak-CC, Weak-NC) and scattering types...
Definition: ProcessInfo.h:43
void SetRescatterCode(int code)
Definition: GHepParticle.h:130
int fNumPi0
number of pi0 after reaction, before FSI
Definition: GTruth.h:77
int fCharmHadronPdg
Definition: GTruth.h:72
TLorentzVector * GetP4(void) const
A Neutrino Interaction Target. Is a transparent encapsulation of quite different physical systems suc...
Definition: Target.h:41
void Sett(double t, bool selected=false)
Definition: Kinematics.cxx:301
bool fIsCharm
did the interaction produce a charmed hadron?
Definition: GTruth.h:71
double fweight
event interaction weight (genie internal)
Definition: GTruth.h:28
virtual GHepParticle * TargetNucleus(void) const
Definition: GHepRecord.cxx:330
void SetPdgs(int tgt_pdgc, int probe_pdgc)
NuReweight()
<constructor
Definition: NuReweight.cxx:118
void SetDecayMode(int decay_mode)
Definition: XclsTag.cxx:142
const simb::MCParticle & GetParticle(int i) const
Definition: MCTruth.h:76
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
void Setx(double x, bool selected=false)
Definition: Kinematics.cxx:241
void SetExclTag(const XclsTag &xcls)
void SetW(double W, bool selected=false)
Definition: Kinematics.cxx:289
void SetNNucleons(int np, int nn)
Definition: XclsTag.cxx:104
double fHitNucPos
Definition: GTruth.h:52
enum genie::EScatteringType ScatteringType_t
int ftgtPDG
PDG of Target Nucleus, nucleon only if free.
Definition: GTruth.h:47
double fgQ2
Definition: GTruth.h:61
void SetHitNucPdg(int pdgc)
Definition: Target.cxx:188
void Sety(double y, bool selected=false)
Definition: Kinematics.cxx:253
virtual GHepParticle * HitNucleon(void) const
Definition: GHepRecord.cxx:350
Target * TgtPtr(void) const
Definition: InitialState.h:68
virtual void SetVertex(double x, double y, double z, double t)
Definition: GHepRecord.cxx:863
double Gvt() const
Definition: MCParticle.h:248
TLorentzVector fFShadSystP4
generated final state hadronic system (LAB frame)
Definition: GTruth.h:68
double Pz(const int i=0) const
Definition: MCParticle.h:231
genie::EventRecord RetrieveGHEP(const simb::MCTruth &truth, const simb::GTruth &gtruth) const
Definition: NuReweight.cxx:134
int Rescatter() const
Definition: MCParticle.h:251
void UnsetCharm(void)
Definition: XclsTag.cxx:74
void SetHadSystP4(const TLorentzVector &p4)
Definition: Kinematics.cxx:317
cet::LibraryManager dummy("noplugin")
InitialState * InitStatePtr(void) const
Definition: Interaction.h:73
virtual void AddParticle(const GHepParticle &p)
Definition: GHepRecord.cxx:535
double fgT
Definition: GTruth.h:64
Event generator information.
Definition: MCTruth.h:32
void SetHitSeaQrk(bool tf)
Definition: Target.cxx:212
Event generator information.
Definition: MCNeutrino.h:18
bool fIsSeaQuark
Definition: GTruth.h:50
double CalcWeight(const simb::MCTruth &truth, const simb::GTruth &gtruth) const
Definition: NuReweight.cxx:127
TLorentzVector fVertex
Definition: GTruth.h:26
enum genie::EInteractionType InteractionType_t
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:40
double fgY
Definition: GTruth.h:66
double fDiffXsec
differential cross section of interaction
Definition: GTruth.h:31
void SetProcInfo(const ProcessInfo &proc)
virtual int TargetNucleusPosition(void) const
Definition: GHepRecord.cxx:406
virtual void SetDiffXSec(double xsec, KinePhaseSpace_t ps)
Definition: GHepRecord.h:134
Initial State information.
Definition: InitialState.h:49
int fStrangeHadronPdg
Definition: GTruth.h:74