All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UnisimWeightCalc.cxx
Go to the documentation of this file.
1 //Built from FluxUnisimWeightCalc.cxx in ubcode/EventWeight/Calculator/Flux/ directory
2 
3 #include "FluxCalcPrep.h"
4 
5 
6 namespace sbn {
7  namespace evwgh {
8 
9  double FluxWeightCalc::UnisimWeightCalc(double enu, int ptype, int ntype, double randomN, bool noNeg)
10  {//same copy from the FluxWeightCalc.cxx in ubsim/EventWeight/
11  //Keng Lin June 2021
12 
13  double weight = 1;
14 
15  int bin = int(enu/0.05); //convert energy (in GeV) into 50 MeV bin
16 
17 
18  // pseudocode:
19  // Scaled Reweighting = ScaleFactor * Reweighting + ( 1 - ScaleFactor) * Central Value
20  //
21  double scaled_pos = fScalePos*fRWpos[ptype][ntype][bin] +
22  (1-fScalePos)*fCV[ptype][ntype][bin];
23 
24  double scaled_neg = fScaleNeg*fRWneg[ptype][ntype][bin] +
25  (1-fScaleNeg)*fCV[ptype][ntype][bin];
26 
27  // pseudocode:
28  // Check value of Random Number for this universe such that:
29  // If random# > 0
30  // Weight = 1 + ( random# * [ { Scaled Reweighting[pos] / Central Value } - 1 ] )
31  // If random# < 0
32  // Weight = 1 - ( random# * [ { Scaled Reweighting[neg] / Central Value } - 1 ] )
33  //
34  // if there is only one systematic histogram offered sub this:
35  // If random# < 0
36  // Weight = 1 - ( random# * [ < 2 - { Scaled Reweighting[pos] / Central Value } > - 1 ] )
37  //
38 
39  if(randomN > 0){
40  double syst = randomN*((scaled_pos/fCV[ptype][ntype][bin])-1);
41  weight = 1 + (syst);
42 
43  if(scaled_pos == 0) weight = 1;
44  }
45 
46  else if(noNeg == true){
47  double syst = randomN*( (2 - (scaled_pos/fCV[ptype][ntype][bin])) - 1);
48  weight = 1 - (syst);
49 
50  if(scaled_pos == 0) weight = 1;
51 
52  }
53  else{
54  double syst = randomN*((scaled_neg/fCV[ptype][ntype][bin])-1);
55  weight = 1 - (syst);
56 
57  if(scaled_neg == 0) weight = 1;
58 
59  }
60 
61  if(fabs(fCV[ptype][ntype][bin]) < 1.e-12) weight = 1;
62 
63  if(weight < 0) weight = 1;
64  if(weight > 30) weight = 30;
65  if(!(std::isfinite(weight))){
66  std::cout << "UniSim " << fParameterSet.fName << " : Failed to get a finite weight" << std::endl;
67  weight = 30;}
68 
69  if( (ntype == 0 || ntype == 1) && ptype == 1) weight = 1;//nue/nuebar from pion
70  if( (ntype == 1 || ntype == 3) && ptype == 3) weight = 1;//nuebar/numubar from pi or charged kaon
71 
72  // std::cout<<weight<<" ("<<randomN<<") ";
73  return weight;
74 
75  }
76 
77  } // namespace evwgh
78 } // namespace sbn
79 
80 
81 
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
double UnisimWeightCalc(double enu, int ptype, int ntype, double randomN, bool noNeg)
double fRWpos[4][4][200]
Definition: FluxCalcPrep.h:64
bool isfinite(Vector const &v)
Returns whether all components of the vector are finite.
then ntype
double fRWneg[4][4][200]
Definition: FluxCalcPrep.h:65
std::string fName
Name of the parameter set.
double fCV[4][4][200]
Definition: FluxCalcPrep.h:63
BEGIN_PROLOG could also be cout