13 #include "TDatabasePDG.h" 15 #include "NOvARwgt/rwgt/EventRecord.h" 16 #include "NOvARwgt/interfaces/NuToolsInterface.h" 17 #include "NOvARwgt/test/TestEventTools.h" 31 std::unique_ptr<simb::MCParticle>
nuPart;
32 std::unique_ptr<simb::MCParticle>
lepPart;
33 std::vector<std::unique_ptr<simb::MCParticle>>
hadParts;
36 std::unique_ptr<simb::GTruth>
gtruth;
44 evt.
mctruth = std::make_unique<simb::MCTruth>();
46 std::unordered_map<std::string, std::string>
config;
47 if (!rec.generatorConfigStr.empty())
48 config[
"tune"] = rec.generatorConfigStr;
53 TLorentzVector fourMom;
54 fourMom.SetE(rec.Enu);
56 evt.
nuPart = std::make_unique<simb::MCParticle>(1, rec.nupdg,
"");
57 evt.
nuPart->AddTrajectoryPoint({0,0,0,0}, fourMom);
60 fourMom.SetE((1-rec.y)*rec.Enu);
61 evt.
lepPart = std::make_unique<simb::MCParticle>(2, rec.isCC ? (rec.nupdg > 0 ? rec.nupdg-1 : rec.nupdg+1) : rec.nupdg,
"", 1);
62 evt.
lepPart->AddTrajectoryPoint({0,0,0,0}, fourMom);
67 int targetPdg = (rec.A == 1) ? 1000010010 : 1000000000 + (rec.A/2)*10000 + rec.A*10;
80 evt.
gtruth = std::make_unique<simb::GTruth>();
81 evt.
gtruth->fNumPi0 = rec.npizero;
82 evt.
gtruth->fNumPiMinus = rec.npiminus;
83 evt.
gtruth->fNumPiPlus = rec.npiplus;
86 for (
const auto & fsMultPair : rec.fsPartMult)
89 int pdg = fsMultPair.first;
90 const auto itKE = rec.fsPartKE.find(pdg);
91 double totalKE = ((itKE == rec.fsPartKE.end()) ? 0 : itKE->second);
92 unsigned int nPart = fsMultPair.second;
93 double KEPerParticle = totalKE / nPart;
94 double mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
95 double EPerParticle = KEPerParticle + mass;
96 double MomPerParticle =
sqrt(EPerParticle*EPerParticle - mass*mass);
97 for (
unsigned int i = 0;
i < nPart;
i++)
99 int particleIdx = 2+
i+1;
100 evt.
hadParts.emplace_back(std::make_unique<simb::MCParticle>(particleIdx, pdg,
"", 1, mass));
101 TLorentzVector fourMom(MomPerParticle, 0, 0, EPerParticle);
102 evt.
hadParts.back()->AddTrajectoryPoint({0,0,0,0}, fourMom);
117 std::cout <<
"NOvARwgt self-test: NuTools (simb::MCTruth and simb::GTruth)" <<
std::endl;
118 std::cout <<
"============================================================" <<
std::endl;
121 novarwgt::InputVals
params 123 {
"EmpiricalMEC",
true},
126 auto testEventsIn = novarwgt::test::GetTestEvents();
128 decltype(testEventsIn) testEventsOut;
129 for (
const auto & evtInPair : testEventsIn)
131 const auto &
evt = evtInPair.second;
140 std::unique_ptr<std::exception> exc =
nullptr;
141 if (
evt.ExpectedException())
142 exc = std::make_unique<novarwgt::UnsupportedGeneratorException>(*dynamic_cast<const novarwgt::UnsupportedGeneratorException*>(
evt.ExpectedException()));
144 testEventsOut.emplace( evtInPair.first,
145 novarwgt::test::TestEvent<novarwgt::EventRecord>(newEvt,
146 evt.ExpectedWeight(),
151 bool ok = novarwgt::test::Validate(testEventsOut,
params,
true);
153 std::cout <<
"All " << testEventsOut.size() <<
" events produced the expected behavior." <<
std::endl;
std::unique_ptr< simb::MCTruth > mctruth
std::unique_ptr< simb::MCParticle > lepPart
caf::StandardRecord * rec
std::unique_ptr< simb::MCParticle > nuPart
std::unique_ptr< simb::GTruth > gtruth
novarwgt::EventRecord ConvertNuToolsEvent(const simb::MCTruth *mctruth, const simb::GTruth *gtruth, const novarwgt::ReweightList &rwList)
NuSimDataEvt ToNuSimData(const novarwgt::EventRecord &rec)
Utility function to convert an EventRecord back into NuSimData components.
std::vector< std::unique_ptr< simb::MCParticle > > hadParts
std::string EncodeGeneratorVersion(const std::vector< int > &verVec)
int_type_
Neutrino interaction categories.