Classes | Functions | Variables
novarwgt::test Namespace Reference

Classes

struct  NuSimDataEvt
 

Functions

caf::StandardRecord ToStandardRecord (const novarwgt::EventRecord &rec)
 Utility function to convert an EventRecord back into a StandardRecord. More...
 
NuSimDataEvt ToNuSimData (const novarwgt::EventRecord &rec)
 Utility function to convert an EventRecord back into NuSimData components. More...
 

Variables

const std::unordered_map< novarwgt::ReactionType, caf::mode_type_REACTION_ENUM_MAP
 
const std::unordered_map< novarwgt::Generator, caf::generator_GENERATOR_ID_MAP
 

Function Documentation

NuSimDataEvt novarwgt::test::ToNuSimData ( const novarwgt::EventRecord &  rec)

Utility function to convert an EventRecord back into NuSimData components.

Definition at line 40 of file nutools_test.cxx.

References gen_flatrecord::config, novarwgt::EncodeGeneratorVersion(), make_root_from_grid_output::evt, novarwgt::test::NuSimDataEvt::gtruth, novarwgt::test::NuSimDataEvt::hadParts, MECModelEnuComparisons::i, simb::kCC, simb::kGENIE, simb::kNC, cvn::kUnknown, novarwgt::test::NuSimDataEvt::lepPart, novarwgt::test::NuSimDataEvt::mctruth, novarwgt::test::NuSimDataEvt::nuPart, make_root_from_grid_output::pdg, and std::sqrt().

Referenced by main().

41  {
42  NuSimDataEvt evt;
43 
44  evt.mctruth = std::make_unique<simb::MCTruth>();
45 
46  std::unordered_map<std::string, std::string> config;
47  if (!rec.generatorConfigStr.empty())
48  config["tune"] = rec.generatorConfigStr;
49  evt.mctruth->SetGeneratorInfo(rec.generator == novarwgt::kGENIE ? simb::Generator_t::kGENIE : simb::Generator_t::kUnknown,
50  EncodeGeneratorVersion(rec.generatorVersion),
51  config);
52 
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);
58  evt.mctruth->Add(*evt.nuPart);
59 
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);
63  evt.mctruth->Add(*evt.lepPart);
64 
65  // not exactly right, but we aren't currently storing Z
66  // format is +10LZZZAAAI
67  int targetPdg = (rec.A == 1) ? 1000010010 : 1000000000 + (rec.A/2)*10000 + rec.A*10;
68  evt.mctruth->SetNeutrino(
69  rec.isCC ? simb::kCC : simb::kNC,
70  simb::int_type_(rec.reaction),
71  simb::int_type_(rec.reaction+1000), // not exactly right, but we don't use this
72  targetPdg,
73  rec.struckNucl,
74  0, // not storing struck quark
75  rec.W,
76  0, // not storing x
77  rec.y,
78  rec.Q2());
79 
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;
84 
85  // the final-state hadrons
86  for (const auto & fsMultPair : rec.fsPartMult)
87  {
88  // we'll divide it up equally amongst the particles since we don't save any more info
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++)
98  {
99  int particleIdx = 2+i+1; // 2=(original neutrino + lepton above)
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);
103  evt.mctruth->Add(*evt.hadParts.back());
104 
105  }
106  }
107 
108 
109  return evt;
110  }
const char * p
Definition: xmltok.h:285
T sqrt(T number)
Definition: d0nt_math.hpp:156
caf::StandardRecord * rec
Definition: tutCAFMacro.C:20
std::string EncodeGeneratorVersion(const std::vector< int > &verVec)
int_type_
Neutrino interaction categories.
Definition: MCNeutrino.h:79
caf::StandardRecord novarwgt::test::ToStandardRecord ( const novarwgt::EventRecord &  rec)

Utility function to convert an EventRecord back into a StandardRecord.

Definition at line 50 of file novarwgt_sr_interface_test.cxx.

References caf::SRNeutrino::E, caf::SRLorentzVector::E, febshutoff_auto::end, srt_file_template::find_if, caf::SRNeutrino::genConfigString, caf::SRNeutrino::generator, GENERATOR_ID_MAP, caf::SRMCReweight::genie, caf::SRNeutrino::genVersion, caf::SRNeutrino::hitnuc, MECModelEnuComparisons::i, compare_h5_caf::idx, caf::SRNeutrino::iscc, caf::SRNeutrino::isvtxcont, novarwgt::kNugenKnobTranslationTable, caf::kUnknownGenerator, caf::StandardRecord::mc, caf::SRNeutrino::mode, caf::SRTruthBranch::nnu, caf::SRNeutrino::npiminus, caf::SRNeutrino::npiplus, caf::SRNeutrino::npizero, caf::SRTruthBranch::nu, caf::SRTrueParticle::p, part, caf::SRTrueParticle::pdg, caf::SRNeutrino::pdg, make_root_from_grid_output::pdg, caf::SRNeutrino::prim, caf::SRLorentzVector::px, caf::SRLorentzVector::py, caf::SRLorentzVector::pz, caf::SRNeutrino::q2, REACTION_ENUM_MAP, caf::SRNeutrino::rwgt, std::sqrt(), caf::SRNeutrino::tgtA, caf::SRNeutrino::W2, and caf::SRNeutrino::y.

Referenced by main().

51  {
52  caf::StandardRecord srrec;
53  caf::SRNeutrino nu;
54 
55  nu.generator = GENERATOR_ID_MAP.find(rec.generator) != GENERATOR_ID_MAP.end()
56  ? GENERATOR_ID_MAP.at(rec.generator)
58  nu.genVersion.insert(nu.genVersion.begin(), rec.generatorVersion.begin(), rec.generatorVersion.end());
59  nu.genConfigString = rec.generatorConfigStr;
60 
61  nu.pdg = rec.nupdg;
62  nu.iscc = rec.isCC;
63  nu.mode = REACTION_ENUM_MAP.at(rec.reaction);
64  nu.hitnuc = rec.struckNucl;
65 
66  nu.E = rec.Enu;
67  nu.q2 = -rec.q * rec.q;
68  nu.y = rec.y;
69  nu.W2 = rec.W * rec.W;
70 
71  nu.tgtA = rec.A;
72 
73  nu.npiplus = rec.npiplus;
74  nu.npizero = rec.npizero;
75  nu.npiminus = rec.npiminus;
76 
77  // the final-state hadrons
78  for (const auto & fsMultPair : rec.fsPartMult)
79  {
80  // we'll divide it up equally amongst the particles since we don't save any more info
81  int pdg = fsMultPair.first;
82  const auto itKE = rec.fsPartKE.find(pdg);
83  double totalKE = ((itKE == rec.fsPartKE.end()) ? 0 : itKE->second);
84  unsigned int nPart = fsMultPair.second;
85  double KEPerParticle = totalKE / nPart;
86  double mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
87  double EPerParticle = KEPerParticle + mass;
88  double MomPerParticle = sqrt(EPerParticle*EPerParticle - mass*mass);
89  for (unsigned int i = 0; i < nPart; i++)
90  {
92  part.pdg = pdg;
93  part.p = caf::SRLorentzVector();
94  part.p.E = EPerParticle;
95  part.p.px = MomPerParticle;
96  part.p.py = 0;
97  part.p.pz = 0;
98  nu.prim.emplace_back(std::move(part));
99  }
100  }
101 
102 
103  nu.rwgt.genie.resize(rec.genieWeights.size());
104  for (std::size_t idx = 0; idx < rec.genieWeights.size(); idx++)
105  {
106  if (rec.genieWeights.IsSet(idx))
107  {
108  auto nugenIdx = std::find_if(novarwgt::kNugenKnobTranslationTable.begin(),
110  [idx](const auto & pair)
111  {
112  return std::size_t(pair.second) == idx;
113  })->first;
114 
115  nu.rwgt.genie[nugenIdx].minus2sigma = rec.genieWeights[idx].minus2sigma;
116  nu.rwgt.genie[nugenIdx].minus1sigma = rec.genieWeights[idx].minus1sigma;
117  nu.rwgt.genie[nugenIdx].plus1sigma = rec.genieWeights[idx].plus1sigma;
118  nu.rwgt.genie[nugenIdx].plus2sigma = rec.genieWeights[idx].plus2sigma;
119  }
120  }
121 
122  nu.isvtxcont = !rec.expectNoWeights;
123 
124  srrec.mc.nu.emplace_back(std::move(nu));
125  srrec.mc.nnu = 1;
126 
127  return std::move(srrec);
128  }
unsigned int npizero
Number of &#39;s after neutrino reaction, before FSI.
Definition: SRNeutrino.h:62
float q2
Squared momentum transfer [GeV^2].
Definition: SRNeutrino.h:74
T sqrt(T number)
Definition: d0nt_math.hpp:156
std::vector< SRTrueParticle > prim
Primary daughters, lepton comes first in vector.
Definition: SRNeutrino.h:81
unsigned int npiplus
Number of &#39;s after neutrino reaction, before FSI.
Definition: SRNeutrino.h:60
SRMCReweight rwgt
Definition: SRNeutrino.h:87
std::vector< unsigned int > genVersion
Version of the generator that created this neutrino interaction.
Definition: SRNeutrino.h:84
caf::StandardRecord * rec
Definition: tutCAFMacro.C:20
const std::unordered_map< rwgt::ReweightLabel_t, novarwgt::ReweightKnob > kNugenKnobTranslationTable
int tgtA
A of target nucleus.
Definition: SRNeutrino.h:72
std::string genConfigString
String associated with generator configuration. (For GENIE 3, this is the "Comprehensive Model Config...
Definition: SRNeutrino.h:85
The SRNeutrino is a representation of neutrino interaction information.
Definition: SRNeutrino.h:19
unsigned int npiminus
Number of &#39;s after neutrino reaction, before FSI.
Definition: SRNeutrino.h:61
TString part[npart]
Definition: Style.C:32
bool iscc
true if charged-current interaction, false if not.
Definition: SRNeutrino.h:57
float W2
Invariant mass of final state squared. [GeV^2].
Definition: SRNeutrino.h:77
const std::unordered_map< novarwgt::ReactionType, caf::mode_type_ > REACTION_ENUM_MAP
short nnu
Number of neutrinos in nu vector (0 or 1)
Definition: SRTruthBranch.h:37
int mode
interaction mode from enum mode_type::[QE, RES, COH, ...]
Definition: SRNeutrino.h:56
4-vector with more efficient storage than TLorentzVector
short pdg
pdg code
Definition: SRNeutrino.h:23
bool isvtxcont
Checks if neutrino true vertex is within detector.
Definition: SRNeutrino.h:36
The StandardRecord is the primary top-level object in the Common Analysis File trees.
const std::unordered_map< novarwgt::Generator, caf::generator_ > GENERATOR_ID_MAP
SRTruthBranch mc
Truth branch for MC: energy, flavor, etc.
float E
True energy [GeV].
Definition: SRNeutrino.h:26
std::vector< SRGenieWeights > genie
GENIE weights.
Definition: SRMCReweight.h:22
float y
Bjorken y = (p.q) / (k.p), fractional energy loss of incoming particle [Dimensionless].
Definition: SRNeutrino.h:76
std::vector< SRNeutrino > nu
implemented as a vector to maintain mc.nu structure, i.e. not a pointer, but with 0 or 1 entries...
Definition: SRTruthBranch.h:25
SRLorentzVector p
Momentum 4-vector.
generator_ generator
The generator that created this neutrino interaction.
Definition: SRNeutrino.h:83

Variable Documentation

const std::unordered_map<novarwgt::Generator, caf::generator_> novarwgt::test::GENERATOR_ID_MAP
Initial value:
{
{novarwgt::kGENIE, caf::kGENIE}
}

Definition at line 45 of file novarwgt_sr_interface_test.cxx.

Referenced by novarwgt::ConvertSRTruth(), and ToStandardRecord().

const std::unordered_map<novarwgt::ReactionType, caf::mode_type_> novarwgt::test::REACTION_ENUM_MAP
Initial value:
{
}

Definition at line 28 of file novarwgt_sr_interface_test.cxx.

Referenced by novarwgt::ConvertSRTruth(), and ToStandardRecord().