ProngCVNVars.cxx
Go to the documentation of this file.
2 
3 namespace SliceLID
4 {
5 
6 /* TODO: replace return value by std::optional with c++17 */
7 template<class T, size_t N>
8 std::pair<bool, size_t> getIndex(const std::array<T, N> &array, const T &value)
9 {
10  auto it = std::find(array.begin(), array.end(), value);
11  if (it == array.end()) {
12  return std::make_pair(false, 0);
13  }
14 
15  return std::make_pair(true, it - array.begin());
16 }
17 
18 std::array<double, N_CVN> ProngCVNVars::getFallbackCVNVars(
19  const BasicProngVars &pngVars, size_t pngIdx
20 )
21 {
22  std::array<double, N_CVN> pids;
23  pids.fill(0);
24 
25  if (pngVars.len[pngIdx] > 500) {
27  if (index.first) {
28  pids[index.second] = 1;
29  }
30  }
31 
32  return pids;
33 }
34 
35 std::array<double, N_CVN> ProngCVNVars::getCVNVars(
36  const art::FindManyP<rb::PID> &prongCVN_fmp,
37  const BasicProngVars &pngVars,
38  size_t pngIdx
39 )
40 {
41  std::array<double, N_CVN> pids;
42  pids.fill(0);
43 
44  if (! prongCVN_fmp.isValid()) {
45  return pids;
46  }
47 
48  auto cvnparts = prongCVN_fmp.at(pngIdx);
49  if (cvnparts.empty()) {
50  return getFallbackCVNVars(pngVars, pngIdx);
51  }
52 
53  for (auto &cvn : cvnparts)
54  {
55  auto index = getIndex(CVN_PNG_LIST, cvn->Pdg());
56  if (index.first) {
57  pids[index.second] = cvn->Value();
58  }
59  }
60 
61  return pids;
62 }
63 
64 void ProngCVNVars::init(const art::Event &evt, const BasicProngVars &pngVars)
65 {
66  if (! pngVars.hasProngs) {
67  return;
68  }
69 
70  art::FindManyP<rb::PID> prongCVN_fmp(pngVars.prongs, evt, prongCVNLabel);
71  cvnVars.reserve(pngVars.prongs.size());
72 
73  for (size_t pngIdx = 0; pngIdx < pngVars.prongs.size(); pngIdx++) {
74  cvnVars.emplace_back(getCVNVars(prongCVN_fmp, pngVars, pngIdx));
75  }
76 }
77 
79  std::unordered_map<std::string, std::vector<double>> &dict,
80  const std::string &prefix
81 ) const
82 {
83  std::array<std::vector<double>, N_CVN> result;
84 
85  for (size_t cvnIdx = 0; cvnIdx < N_CVN; cvnIdx++) {
86  result[cvnIdx].reserve(cvnVars.size());
87  }
88 
89  for (auto &cvnArray : cvnVars)
90  {
91  for (size_t cvnIdx = 0; cvnIdx < N_CVN; cvnIdx++)
92  {
93  result[cvnIdx].push_back(cvnArray[cvnIdx]);
94  }
95  }
96 
97  for (size_t cvnIdx = 0; cvnIdx < N_CVN; cvnIdx++)
98  {
99  const std::string &name =
100  prefix + "cvnpart." + PDG_TO_NAME_MAP.at(CVN_PNG_LIST[cvnIdx]);
101 
102  dict.emplace(name, std::move(result[cvnIdx]));
103  }
104 }
105 
107  const art::Event &evt,
108  const BasicProngVars &pngVars,
110 ) : prongCVNLabel(prongCVNLabel)
111 {
112  init(evt, pngVars);
113 }
114 
115 }
const std::unordered_map< int, std::string > PDG_TO_NAME_MAP({{PDG_ELECTRON,"electronid"},{PDG_MUON,"muonid"},{PDG_PROTON,"protonid"},{PDG_PIPLUS,"pionid"},{PDG_GAMMA,"photonid"},})
const XML_Char * name
Definition: expat.h:151
set< int >::iterator it
void saveToDict(std::unordered_map< std::string, std::vector< double >> &dict, const std::string &prefix) const
const std::array< int, N_CVN > CVN_PNG_LIST({PDG_ELECTRON, PDG_MUON, PDG_PROTON, PDG_PIPLUS, PDG_GAMMA,})
const size_t N_CVN
Definition: ProngCVNVars.h:9
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
Defines an enumeration for prong classification.
std::pair< bool, size_t > getIndex(const std::array< T, N > &array, const T &value)
Definition: ProngCVNVars.cxx:8
std::vector< art::Ptr< rb::Prong > > prongs
const XML_Char int const XML_Char * value
Definition: expat.h:331
int evt
const int PDG_MUON
Definition: ProngCVNVars.h:12
ProngCVNVars(const art::Event &evt, const BasicProngVars &pngVars, const std::string &prongCVNLabel)
static std::array< double, N_CVN > getCVNVars(const art::FindManyP< rb::PID > &prongCVN_fmp, const BasicProngVars &pngVars, size_t pngIdx)
const XML_Char * prefix
Definition: expat.h:380
std::vector< std::array< double, N_CVN > > cvnVars
Definition: ProngCVNVars.h:37
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::vector< double > len
double T
Definition: Xdiff_gwt.C:5
void init(const art::Event &evt, const BasicProngVars &pngVars)
static std::array< double, N_CVN > getFallbackCVNVars(const BasicProngVars &pngVars, size_t pngIdx)
std::string prongCVNLabel
Definition: ProngCVNVars.h:52