NuToolsInterface.cxx
Go to the documentation of this file.
1 /*
2  * NuToolsInterface.cxx:
3  * Interface to FNAL NuTools simb::Events.
4  *
5  * Created on: Oct. 26, 2018
6  * Author: J. Wolcott <jwolcott@fnal.gov>
7  */
8 
9 
10 #include <unordered_map>
11 
15 
16 #include "NOvARwgt/rwgt/EventRecord.h"
17 #include "NOvARwgt/util/GeneratorSupportConfig.h"
18 
19 namespace novarwgt
20 {
21 
22  // anonymous namespace since it shouldn't be in the interface
23  namespace
24  {
25  novarwgt::Generator DecodeGenerator(simb::Generator_t gen)
26  {
27  switch (gen)
28  {
30  return novarwgt::kGENIE;
31 
32  default:
34  }
35  }
36 
37  }
38 
39 
40  novarwgt::EventRecord ConvertNuToolsEvent(const simb::MCTruth * mctruth, const simb::GTruth * gtruth, const novarwgt::ReweightList & rwList)
41  {
42  novarwgt::EventRecord rec;
43 
44  // this is very rudimentary caching
45  rec.generator = DecodeGenerator(mctruth->GeneratorInfo().generator);
46  static std::string oldVersionStr = std::string{};
47  static std::vector<int> oldVersionVec = std::vector<int>{};
48  static std::unordered_map<std::string, std::string> oldGenConfig = std::unordered_map<std::string, std::string>{};
49  static std::string oldGenConfigStr = std::string{};
50  if (mctruth->GeneratorInfo().generatorVersion != oldVersionStr || mctruth->GeneratorInfo().generatorConfig != oldGenConfig)
51  {
52  oldVersionStr = mctruth->GeneratorInfo().generatorVersion;
53  oldVersionVec = DecodeGeneratorVersion(mctruth->GeneratorInfo().generatorVersion);
54  oldGenConfig = mctruth->GeneratorInfo().generatorConfig;
55  oldGenConfigStr = "";
56  for (const auto & configPair: oldGenConfig)
57  {
58  if (configPair.first == "tune")
59  oldGenConfigStr = configPair.second;
60  else
61  std::cerr << "Don't know how to store generator config parameter named '" << configPair.first << "'";
62  }
63  }
64  rec.generatorVersion = oldVersionVec;
65  if (!oldGenConfigStr.empty())
66  rec.generatorConfigStr = oldGenConfigStr;
67 
68  const auto & nu = mctruth->GetNeutrino();
69  rec.nupdg = nu.Nu().PdgCode();
70  rec.isCC = nu.CCNC() == simb::kCC;
71  rec.reaction = novarwgt::ReactionType(int(nu.Mode())); // these were pulled from the GENIE enum I think so just cast
72  rec.struckNucl = nu.HitNuc();
73 
74  rec.Enu = nu.Nu().E();
75  rec.q = TLorentzVector(1, 0, 0, nu.Y() * nu.Nu().E()); // need to make up the direction since we didn't store it
76  rec.q.SetRho(sqrt(nu.QSqr() + rec.q.E()*rec.q.E()));
77  rec.y = nu.Y();
78  rec.W = nu.W();
79 
80  rec.A = nu.Target() % 10000 / 10; // convert from PDG +10LZZZAAAI format
81 
82  rec.npiplus = gtruth->fNumPiPlus;
83  rec.npizero = gtruth->fNumPi0;
84  rec.npiminus = gtruth->fNumPiMinus;
85 
86  for (int i = 0; i < mctruth->NParticles(); i++)
87  {
88  const auto & part = mctruth->GetParticle(i);
89  rec.fsPartMult[part.PdgCode()]++; // default constructor initializes to 0
90  rec.fsPartKE[part.PdgCode()] += part.E() - part.Mass(); // ditto
91  }
92 
93  rec.genieWeights = rwList;
94 
95  return rec;
96 
97  }
98 
99 }
int PdgCode() const
Definition: MCParticle.h:211
const simb::MCNeutrino & GetNeutrino() const
Definition: MCTruth.h:76
const simb::MCParticle & Nu() const
Definition: MCNeutrino.h:146
T sqrt(T number)
Definition: d0nt_math.hpp:156
OStream cerr
Definition: OStream.cxx:7
caf::StandardRecord * rec
Definition: tutCAFMacro.C:20
int fNumPiPlus
number of pi pluses after reaction, before FSI
Definition: GTruth.h:78
enum simb::_ev_generator Generator_t
generator used to produce event, if applicable
int fNumPiMinus
number of pi minuses after reaction, before FSI
Definition: GTruth.h:79
int NParticles() const
Definition: MCTruth.h:74
std::vector< int > DecodeGeneratorVersion(const std::string &versionString)
novarwgt::EventRecord ConvertNuToolsEvent(const simb::MCTruth *mctruth, const simb::GTruth *gtruth, const novarwgt::ReweightList &rwList)
TString part[npart]
Definition: Style.C:32
int fNumPi0
number of pi0 after reaction, before FSI
Definition: GTruth.h:77
simb::Generator_t generator
event generator that generated this event
const simb::MCParticle & GetParticle(int i) const
Definition: MCTruth.h:75
std::string generatorVersion
event generator version
Event generator information.
Definition: MCTruth.h:32
std::unordered_map< std::string, std::string > generatorConfig
free-form field that can be used to keep track of generator configuration (e.g. GENIE tune) ...
const simb::MCGeneratorInfo & GeneratorInfo() const
Definition: MCTruth.h:72
enum BeamMode string