Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
lem::FindMatchesAlg Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-01-16/LEM/func/FindMatchesAlg.h"

Public Member Functions

 FindMatchesAlg (const std::string &libDir, bool preload, bool useHeads)
 
 ~FindMatchesAlg ()
 
std::vector< MatchFindMatches (const MatchableEvent &trial, unsigned int numMatches, int enrich) const
 
const LibraryGetLibrary () const
 

Protected Member Functions

std::vector< MatchFindMatchesNoHeads (const MatchableEvent &trial, unsigned int numMatches, int enrich) const
 
std::vector< MatchFindMatchesHeads (const MatchableEvent &trial, unsigned int numMatches, int enrich) const
 
int BestHeadFor (const FlippedPotentials &trialVs, const MatchableEvent &trial, bool &bestFlipEven, bool &bestFlipOdd, double &bestEnergy) const
 
std::vector< MatchPackageMatches (const std::multiset< Match > &matches, const MatchableEvent &trial) const
 

Protected Attributes

LibraryfLib
 
HeadsfHeads
 

Detailed Description

Definition at line 17 of file FindMatchesAlg.h.

Constructor & Destructor Documentation

lem::FindMatchesAlg::FindMatchesAlg ( const std::string libDir,
bool  preload,
bool  useHeads 
)

Definition at line 40 of file FindMatchesAlg.cxx.

References ana::assert(), lem::Heads::FromMMap(), and lem::Library::FromMMap().

43  {
44  fLib = Library::FromMMap(libDir, preload);
45  assert(fLib);
46 
47  if(useHeads){
48  fHeads = Heads::FromMMap(libDir, preload);
49  assert(fHeads);
50  }
51  else{
52  fHeads = 0;
53  }
54  }
assert(nhit_max >=nhit_nbins)
static Heads * FromMMap(const std::string &libPath, bool touchAll)
Definition: Heads.cxx:23
static Library * FromMMap(const std::string &libPath, bool touchAll)
Definition: Library.cxx:62
lem::FindMatchesAlg::~FindMatchesAlg ( )

Definition at line 57 of file FindMatchesAlg.cxx.

References PackageMatches().

58  {
59  delete fLib;
60  delete fHeads;
61  }

Member Function Documentation

int lem::FindMatchesAlg::BestHeadFor ( const FlippedPotentials trialVs,
const MatchableEvent trial,
bool &  bestFlipEven,
bool &  bestFlipOdd,
double &  bestEnergy 
) const
protected

Definition at line 130 of file FindMatchesAlg.cxx.

References ana::assert(), lem::CalcEnergy(), E, FindMatchesHeads(), and lem::FlippedPotentials::V.

Referenced by GetLibrary().

134  {
135  int bestHead = -1;
136  bestEnergy = FLT_MAX;
137 
138  const int nHeads = fHeads->NHeads();
139  for(int iHead = 0; iHead < nHeads; ++iHead){
140  const MatchableEvent& headEvt = fLib->Event(fHeads->HeadIdx(iHead));
141 
142  for(int flipEven: {0, 1}){
143  for(int flipOdd: {0, 1}){
144  const float E = CalcEnergy(trialVs.V[flipEven][flipOdd], trial,
145  headEvt);
146  if(E < bestEnergy){
147  bestEnergy = E;
148  bestHead = iHead;
149  bestFlipEven = flipEven;
150  bestFlipOdd = flipOdd;
151  }
152  }
153  }
154  }
155  assert(bestHead >= 0);
156 
157  return bestHead;
158  }
float CalcEnergy(const Potential &Va, const MatchableEvent &a, const MatchableEvent &b)
Definition: FindMatches.cxx:21
Float_t E
Definition: plot.C:20
int NHeads() const
Definition: Heads.h:26
const MatchableEvent & Event(int i) const
Definition: Library.h:32
assert(nhit_max >=nhit_nbins)
int HeadIdx(int i) const
Definition: Heads.h:27
std::vector< Match > lem::FindMatchesAlg::FindMatches ( const MatchableEvent trial,
unsigned int  numMatches,
int  enrich 
) const

Definition at line 83 of file FindMatchesAlg.cxx.

References FindMatchesNoHeads().

Referenced by PackageMatches(), and lem::FindLEMMatches::produce().

86  {
87  if(fHeads)
88  return FindMatchesHeads (trial, numMatches, enrich);
89  else
90  return FindMatchesNoHeads(trial, numMatches, enrich);
91  }
std::vector< Match > FindMatchesHeads(const MatchableEvent &trial, unsigned int numMatches, int enrich) const
std::vector< Match > FindMatchesNoHeads(const MatchableEvent &trial, unsigned int numMatches, int enrich) const
std::vector< Match > lem::FindMatchesAlg::FindMatchesHeads ( const MatchableEvent trial,
unsigned int  numMatches,
int  enrich 
) const
protected

Definition at line 162 of file FindMatchesAlg.cxx.

References lem::CalcEnergy(), E, lem::SortedMatchList::emplace(), lem::EventSummary::enrich, lem::FillPotential(), MECModelEnuComparisons::i, calib::j, genie::utils::mec::J(), lem::FlippedPotentials::V, and lem::MatchableEvent::weight.

Referenced by BestHeadFor(), and GetLibrary().

165  {
166  FlippedPotentials trialVs;
167  FillPotential(trial, trialVs);
168 
169  bool headFlipEven, headFlipOdd;
170  double headE;
171  const int headIdx = BestHeadFor(trialVs, trial,
172  headFlipEven, headFlipOdd, headE);
173  // const MatchableEvent& head = fLib->Event(fHeads->HeadIdx(headIdx));
174 
175  // Candidates for return, remains sorted
176  SortedMatchList Elist(numMatches);
177 
178  // This is the quickest ordering of the loops (locality into lib?)
179  const unsigned int J = fHeads->HeadSeqsLen();
180  for(unsigned int j = 0; j < J; ++j){
181  const int i = fHeads->ChildIdxFor(headIdx, j);
182 
183  const MatchableEvent& libEvt = fLib->Event(i);
184 
185  if(enrich != 2){
186  if(libEvt.enrich != bool(enrich)) continue;
187  }
188 
189  // There's beam nue in the library, but we don't want to match to it
190  if(libEvt.weight == 0) continue;
191 
192  const bool flipEven = (fHeads->FlipEvenFor(headIdx, j) ^ headFlipEven);
193  const bool flipOdd = (fHeads->FlipOddFor (headIdx, j) ^ headFlipOdd );
194 
195  const float E = CalcEnergy(trialVs.V[flipEven][flipOdd], trial, libEvt);
196  Elist.emplace(E, &libEvt, flipEven, flipOdd, j);
197  } // end for i/j
198 
199  return PackageMatches(Elist, trial);
200  }
float CalcEnergy(const Potential &Va, const MatchableEvent &a, const MatchableEvent &b)
Definition: FindMatches.cxx:21
double J(double q0, double q3, double Enu, double ml)
Definition: MECUtils.cxx:141
int ChildIdxFor(int head, int child) const
Definition: Heads.cxx:78
bool FlipEvenFor(int head, int child) const
Definition: Heads.cxx:85
std::vector< Match > PackageMatches(const std::multiset< Match > &matches, const MatchableEvent &trial) const
bool FlipOddFor(int head, int child) const
Definition: Heads.cxx:92
Float_t E
Definition: plot.C:20
const double j
Definition: BetheBloch.cxx:29
int HeadSeqsLen() const
Definition: Heads.h:28
void FillPotential(const EventSummary &trial, Potential &V, bool flipEven, bool flipOdd)
Definition: FindMatches.cxx:76
const MatchableEvent & Event(int i) const
Definition: Library.h:32
int BestHeadFor(const FlippedPotentials &trialVs, const MatchableEvent &trial, bool &bestFlipEven, bool &bestFlipOdd, double &bestEnergy) const
std::vector< Match > lem::FindMatchesAlg::FindMatchesNoHeads ( const MatchableEvent trial,
unsigned int  numMatches,
int  enrich 
) const
protected

Definition at line 95 of file FindMatchesAlg.cxx.

References lem::CalcEnergy(), E, lem::SortedMatchList::emplace(), lem::EventSummary::enrich, lem::FillPotential(), MECModelEnuComparisons::i, lem::FlippedPotentials::V, and lem::MatchableEvent::weight.

Referenced by FindMatches(), and GetLibrary().

98  {
99  FlippedPotentials trialVs;
100  FillPotential(trial, trialVs);
101 
102  // Candidates for return, remains sorted
103  SortedMatchList Elist(numMatches);
104 
105  // This is the quickest ordering of the loops (locality into lib?)
106  const unsigned int I = fLib->NEvents();
107  for(unsigned int i = 0; i < I; ++i){
108  const MatchableEvent& libEvt = fLib->Event(i);
109 
110  if(enrich != 2){
111  if(libEvt.enrich != bool(enrich)) continue;
112  }
113 
114  // There's beam nue in the library, but we don't want to match to it
115  if(libEvt.weight == 0) continue;
116 
117  for(int flipEven: {0, 1}){
118  for(int flipOdd: {0, 1}){
119 
120  const float E = CalcEnergy(trialVs.V[flipEven][flipOdd], trial, libEvt);
121  Elist.emplace(E, &libEvt, flipEven, flipOdd, i);
122  } // end for flipOdd
123  } // end for flipEven
124  } // end for i
125 
126  return PackageMatches(Elist, trial);
127  }
float CalcEnergy(const Potential &Va, const MatchableEvent &a, const MatchableEvent &b)
Definition: FindMatches.cxx:21
std::vector< Match > PackageMatches(const std::multiset< Match > &matches, const MatchableEvent &trial) const
Float_t E
Definition: plot.C:20
unsigned int NEvents() const
Definition: Library.h:31
void FillPotential(const EventSummary &trial, Potential &V, bool flipEven, bool flipOdd)
Definition: FindMatches.cxx:76
const MatchableEvent & Event(int i) const
Definition: Library.h:32
const Library* lem::FindMatchesAlg::GetLibrary ( ) const
inline
std::vector< Match > lem::FindMatchesAlg::PackageMatches ( const std::multiset< Match > &  matches,
const MatchableEvent trial 
) const
protected

Definition at line 65 of file FindMatchesAlg.cxx.

References FindMatches(), lem::FracChargeMatched(), m, runNovaSAM::ret, and lem::MatchableEvent::selfEnergy.

Referenced by GetLibrary(), and ~FindMatchesAlg().

67  {
68  // Convert back to a vector, and calculate the qfrac variable for surviving
69  // matches.
70  std::vector<Match> ret;
71  ret.reserve(matches.size());
72  for(const Match& m: matches){
73  ret.push_back(m);
74  ret.back().qfrac = FracChargeMatched(trial, *m.evt, m.flipEven, m.flipOdd);
75  ret.back().energy /= trial.selfEnergy; // Normalize to approx 0-1
76  }
77 
78  return ret;
79  }
double FracChargeMatched(const EventSummary &a, const EventSummary &b, bool flipEven, bool flipOdd)
Definition: FindMatches.cxx:37

Member Data Documentation

Heads* lem::FindMatchesAlg::fHeads
protected

Definition at line 47 of file FindMatchesAlg.h.

Library* lem::FindMatchesAlg::fLib
protected

Definition at line 46 of file FindMatchesAlg.h.

Referenced by GetLibrary().


The documentation for this class was generated from the following files: