LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Weight_t.h
Go to the documentation of this file.
1 #ifndef _WEIGHT_T_H_
2 #define _WEIGHT_T_H_
3 
4 #include "WeightCalc.h"
5 
6 #include <numeric> // std::accumulate()
7 
8 namespace evwgh {
9  struct Weight_t {
10 
12  : fMinWeight(std::numeric_limits<double>::max())
13  , fMaxWeight(std::numeric_limits<double>::min())
14  , fAvgWeight(0)
15  , fNcalls(0)
16  {}
17 
18  std::vector<std::vector<double>> GetWeight(art::Event& e)
19  {
20  std::vector<std::vector<double>> wgh = fWeightCalc->GetWeight(e);
21  for (unsigned int inu = 0; inu < wgh.size(); inu++) {
22  double avgwgh = std::accumulate(wgh[inu].begin(), wgh[inu].end(), 0.0) / wgh[inu].size();
23  fAvgWeight = (fAvgWeight * fNcalls + avgwgh) / float(fNcalls + 1);
24  fMinWeight = std::min(fMinWeight, *std::min_element(wgh[inu].begin(), wgh[inu].end()));
25  fMaxWeight = std::max(fMaxWeight, *std::max_element(wgh[inu].begin(), wgh[inu].end()));
26  fNcalls++;
27  }
28 
29  return wgh;
30  }
31  std::string fName;
33  std::string fWeightCalcType;
34  double fMinWeight;
35  double fMaxWeight;
36  double fAvgWeight;
37  long fNcalls;
39  };
40 
41 }
42 
43 #endif // _WEIGHT_T_H_
STL namespace.
WeightCalc * fWeightCalc
Definition: Weight_t.h:32
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
std::string fName
Definition: Weight_t.h:31
std::vector< std::vector< double > > GetWeight(art::Event &e)
Definition: Weight_t.h:18
std::string fWeightCalcType
Definition: Weight_t.h:33
double fMaxWeight
Definition: Weight_t.h:35
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
Float_t e
Definition: plot.C:35
virtual std::vector< std::vector< double > > GetWeight(art::Event &e)=0
double fMinWeight
Definition: Weight_t.h:34
double fAvgWeight
Definition: Weight_t.h:36