ProngBPFVars.cxx
Go to the documentation of this file.
2 
3 #include "RecoBase/Energy.h"
4 #include "RecoBase/FitSum.h"
5 
6 
7 namespace LSTME
8 {
9 
10 std::array<BPFVars, N_BPF> ProngBPFVars::getEmptyBPFVars()
11 {
12  const BPFVars emptyBPF{ 0.0, 0.0, { 0, 0, 0 } };
13  std::array<BPFVars, N_BPF> result;
14 
15  for (size_t i = 0; i < N_BPF; i++) {
16  result[i] = emptyBPF;
17  }
18 
19  return result;
20 }
21 
22 std::array<BPFVars, N_BPF> ProngBPFVars::getBPFVars(
23  const art::Event &evt,
24  const art::FindManyP<rb::Track> &prongBPF_fmp,
25  size_t pngIdx
26 )
27 {
28  std::array<BPFVars, N_BPF> result = getEmptyBPFVars();
29  if (! prongBPF_fmp.isValid()) {
30  return result;
31  }
32 
33  auto tracks = prongBPF_fmp.at(pngIdx);
34  if (tracks.empty()) {
35  return result;
36  }
37 
38  art::FindManyP<rb::FitSum> trackFits_fmp(tracks, evt, prongBPFLabel);
39  if (! trackFits_fmp.isValid()) {
40  return result;
41  }
42 
43  art::FindManyP<rb::Energy> trackOverlapE_fmp(
45  );
46 
47  if (N_BPF != tracks.size()) {
48  return result;
49  }
50 
51  for (size_t trackIdx = 0; trackIdx < tracks.size(); trackIdx++)
52  {
53  auto trackFits = trackFits_fmp.at(trackIdx);
54  if (trackFits.empty()) {
55  continue;
56  }
57 
58  const rb::FitSum &fit = *trackFits[0];
59 
60  result[trackIdx].momentum[0] = fit.FourMom().Px();
61  result[trackIdx].momentum[1] = fit.FourMom().Py();
62  result[trackIdx].momentum[2] = fit.FourMom().Pz();
63  result[trackIdx].energy = fit.FourMom().E();
64 
65  if (trackOverlapE_fmp.isValid())
66  {
67  auto overlapEnergies = trackOverlapE_fmp.at(trackIdx);
68  if (! overlapEnergies.empty()) {
69  result[trackIdx].overlapE = overlapEnergies[0]->E();
70  }
71  }
72 
73  }
74 
75  return result;
76 }
77 
78 void ProngBPFVars::init(const art::Event &evt, const BasicProngVars &pngVars)
79 {
80  if (! pngVars.hasProngs) {
81  return;
82  }
83 
84  art::FindManyP<rb::Track> prongBPF_fmp(pngVars.prongs, evt, prongBPFLabel);
85  bpfVars.reserve(pngVars.prongs.size());
86 
87  for (size_t pngIdx = 0; pngIdx < pngVars.prongs.size(); pngIdx++) {
88  bpfVars.emplace_back(getBPFVars(evt, prongBPF_fmp, pngIdx));
89  }
90 }
91 
93  std::unordered_map<std::string, std::vector<double>> &dict,
94  const std::string &prefix
95 ) const
96 {
97  std::array<std::vector<double>, N_BPF> energy;
98  std::array<std::vector<double>, N_BPF> overlapE;
99  std::array<std::vector<double>, N_BPF> momentum_x;
100  std::array<std::vector<double>, N_BPF> momentum_y;
101  std::array<std::vector<double>, N_BPF> momentum_z;
102 
103  for (size_t bpfIdx = 0; bpfIdx < N_BPF; bpfIdx++)
104  {
105  energy[bpfIdx] .reserve(bpfVars.size());
106  overlapE[bpfIdx] .reserve(bpfVars.size());
107  momentum_x[bpfIdx].reserve(bpfVars.size());
108  momentum_y[bpfIdx].reserve(bpfVars.size());
109  momentum_z[bpfIdx].reserve(bpfVars.size());
110  }
111 
112  for (auto &bpf : bpfVars)
113  {
114  for (size_t bpfIdx = 0; bpfIdx < N_BPF; bpfIdx++)
115  {
116  energy[bpfIdx] .push_back(bpf[bpfIdx].energy);
117  overlapE[bpfIdx] .push_back(bpf[bpfIdx].overlapE);
118  momentum_x[bpfIdx].push_back(bpf[bpfIdx].momentum[0]);
119  momentum_y[bpfIdx].push_back(bpf[bpfIdx].momentum[1]);
120  momentum_z[bpfIdx].push_back(bpf[bpfIdx].momentum[2]);
121  }
122  }
123 
124  for (size_t bpfIdx = 0; bpfIdx < N_BPF; bpfIdx++)
125  {
126  const std::string &fullPrefix =
127  prefix + "bpf[" + std::to_string(bpfIdx) + "]." ;
128 
129  dict.emplace(fullPrefix + "energy", std::move(energy[bpfIdx]));
130  dict.emplace(fullPrefix + "overlapE", std::move(overlapE[bpfIdx]));
131  dict.emplace(fullPrefix + "momentum.x", std::move(momentum_x[bpfIdx]));
132  dict.emplace(fullPrefix + "momentum.y", std::move(momentum_y[bpfIdx]));
133  dict.emplace(fullPrefix + "momentum.z", std::move(momentum_z[bpfIdx]));
134  }
135 }
136 
138  const art::Event &evt,
139  const BasicProngVars &pngVars,
140  const Config &config
141 ) : prongBPFLabel(config.prongBPFLabel),
144 {
145  init(evt, pngVars);
146 }
147 
148 }
std::string overlapEBPFLabel
Definition: ProngBPFVars.h:40
Definition: config.py:1
void saveToDict(std::unordered_map< std::string, std::vector< double >> &dict, const std::string &prefix) const
static std::array< BPFVars, N_BPF > getEmptyBPFVars()
ProngBPFVars(const art::Event &evt, const BasicProngVars &pngVars, const Config &config)
const TLorentzVector FourMom() const
Definition: FitSum.h:72
int evt
double energy
Definition: plottest35.C:25
std::vector< std::array< BPFVars, N_BPF > > bpfVars
Definition: ProngBPFVars.h:25
const XML_Char * prefix
Definition: expat.h:380
std::vector< art::Ptr< rb::Prong > > prongs
std::string prongBPFLabel
Definition: ProngBPFVars.h:38
std::array< BPFVars, N_BPF > getBPFVars(const art::Event &evt, const art::FindManyP< rb::Track > &prongBPF_fmp, size_t pngIdx)
std::string overlapELabel
Definition: ProngBPFVars.h:39
void init(const art::Event &evt, const BasicProngVars &pngVars)
const size_t N_BPF
Definition: ProngBPFVars.h:12
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
A container for kinematic information.
Definition: FitSum.h:22
enum BeamMode string