All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PrimaryHadronFeynmanScalingWeightCalc.cxx
Go to the documentation of this file.
1 //Built from PrimaryHadronFeynmanScaling.cxx in ubcode/EventWeight/Calculator/Flux/BNBPrimaryHadron directory
2 
3 #include "FluxCalcPrep.h"
4 
5 
6 namespace sbn {
7  namespace evwgh {
8 
9  std::pair<bool, double> FluxWeightCalc::PHFSWeightCalc(simb::MCFlux flux, std::vector<float> rand){
10 
11  //
12  // Largely built off the MiniBooNE code
13  // but this is intended to expand beyond it
14  //
15  // Edits from MiniBooNE code:
16  //
17  // JZ (6/2017) : Remove max weight, set to max_limit of a double
18  // JZ (6/2017) : Fixed typo in the E_cm calculation per Mike S. suggestions
19  //
20 
21  // We need to guard against unphysical parameters
22  bool parameters_pass = false;
23 
24  // Get Neutrino Parent Kinimatics
25  double HadronMass = 0.4937;
26 
27  // if(fabs(fprimaryHad) == 321) HadronMass = 0.4937; //Charged Kaon
28  // else{
29  // throw art::Exception(art::errors::StdException)
30  // << "Feynman Scaling is only configured for Charged Kaons ";
31  // }
32 
33  TLorentzVector HadronVec;
34  double HadronPx = flux.ftpx;
35  double HadronPy = flux.ftpy;
36  double HadronPz = flux.ftpz;
37  double HadronE = sqrt(HadronPx*HadronPx +
38  HadronPy*HadronPy +
39  HadronPz*HadronPz +
40  HadronMass*HadronMass);
41  HadronVec.SetPxPyPzE(HadronPx,HadronPy,HadronPz,HadronE);
42 
43  // Get Initial Proton Kinitmatics
44  // CURRENTLY GSimple flux files drop information about
45  // the initial state proton, but that this
46  TLorentzVector ProtonVec;
47  double ProtonMass = 0.9382720;
48  double ProtonPx = 0;
49  double ProtonPy = 0;
50  double ProtonPz = 8.89; //GeV
51  double ProtonE = sqrt(ProtonPx*ProtonPx +
52  ProtonPy*ProtonPy +
53  ProtonPz*ProtonPz +
54  ProtonMass*ProtonMass);
55  ProtonVec.SetPxPyPzE(ProtonPx,ProtonPy,ProtonPz,ProtonE);
56 
57  //
58  // From Mike S. :
59  // The fitting was done without this error so I think that you need to use:
60  // ecm = sqrt(2.*mp**2+2.*mp*eb)
61  //
62  double E_cm = sqrt(2*ProtonMass*ProtonMass + 2*ProtonMass*ProtonVec.E());
63 
64  double gamma = (ProtonE + ProtonMass) / E_cm;
65  double gammaBeta = ProtonVec.P()/E_cm;
66 
67  double MaxThreshold = 2.053;
68  // if(fabs(fprimaryHad) == 321){
69  // MaxThreshold = 2.053; // Mike S. Comment: K+: lambda + proton
70  // }
71  // else{
72  // throw art::Exception(art::errors::StdException)
73  // << "Feynman Scaling is only configured for Charged Kaons ";
74  // }
75 
76  double E_cm_max = (E_cm*E_cm
77  +HadronMass*HadronMass
78  -MaxThreshold*MaxThreshold)/(2*E_cm);
79  double p_cm_max = sqrt(E_cm_max*E_cm_max-HadronMass*HadronMass);
80 
81  double HadronPT = HadronVec.Pt();
82  double HadronPparallel = HadronVec.P()*cos(HadronVec.Theta());
83  double ParallelCMp = gamma*HadronPparallel - gammaBeta*HadronE;
84 
85  double xF;
86 
87  xF = ParallelCMp / p_cm_max;
88 
89  // Define the scale central value cross section
90 
91  // Pull out the parameters for the Feynman Scaling
92  double c1 = FitVal.at(0);
93  double c2 = FitVal.at(1);
94  double c3 = FitVal.at(2);
95  double c4 = FitVal.at(3);
96  double c5 = FitVal.at(4);
97  double c6 = FitVal.at(5);
98  double c7 = FitVal.at(6);
99 
100  double CV = c1*(HadronVec.P()*HadronVec.P()/HadronE)*exp(-1.*c3*pow(fabs(xF),c4)
101  - c7*pow(fabs(HadronPT*xF),c6)
102  - c2*HadronPT
103  - c5*HadronPT*HadronPT);
104 
105  if(CV < 0) CV = 0;
106  if(fabs(xF) > 1) CV = 0;
107  // Define the variations around that cross section
108  // To do this we will call the a function from WeightCalc
109  // that will generate a set of smeared parameters based
110  // on the covariance matrix that we imported
111  std::vector< double > FSKPlusFitSmeared = MultiGaussianSmearing(FitVal, FitCov, rand);//Defined in sbncode/SBNEventWeight/Base/SmearingUtils.h
112 
113  // Pull out the parameters for the Feynman Scaling
114  double smeared_c1 = FSKPlusFitSmeared.at(0);
115  double smeared_c2 = FSKPlusFitSmeared.at(1);
116  double smeared_c3 = FSKPlusFitSmeared.at(2);
117  double smeared_c4 = FSKPlusFitSmeared.at(3);
118  double smeared_c5 = FSKPlusFitSmeared.at(4);
119  double smeared_c6 = FSKPlusFitSmeared.at(5);
120  double smeared_c7 = FSKPlusFitSmeared.at(6);
121 
122  if(smeared_c1 > 0 &&
123  smeared_c2 > 0 &&
124  smeared_c3 > 0 &&
125  smeared_c5 > 0 &&
126  smeared_c7 > 0){
127  parameters_pass = true;
128  }
129 
130  double RW = smeared_c1*(HadronVec.P()*HadronVec.P()/HadronE)*exp(-1.*smeared_c3*pow(fabs(xF),smeared_c4)
131  - smeared_c7*pow(fabs(HadronPT*xF),smeared_c6)
132  - smeared_c2*HadronPT
133  - smeared_c5*HadronPT*HadronPT);
134 
135  if(RW < 0) RW = 0;
136  if(fabs(xF) > 1) RW = 0;
137 
138  double weight = 1;
139 
140  if(RW < 0 || CV < 0){
141  weight = 1;
142  }
143  else if(CV < 1.e-12){
144  weight = 1;
145  }
146  else{
147  weight *= RW/CV;
148  }
149 
150  if(weight < 0) weight = 0;
151  if(weight > 30) weight = 30;
152  if(!(std::isfinite(weight))){
153  std::cout << "FS : Failed to get a finite weight" << std::endl;
154  weight = 30;}
155 
156  std::pair<bool, double> output(parameters_pass, weight);
157 
158 
159 
160  return output;
161 
162  }
163 
164 
165 
166  } // namespace evwgh
167 } // namespace sbn
168 
169 
170 
std::vector< double > FitVal
Definition: FluxCalcPrep.h:71
bool isfinite(Vector const &v)
Returns whether all components of the vector are finite.
BEGIN_PROLOG sequence::SlidingWindowTriggerPatternsOppositeWindows END_PROLOG simSlidingORM6O6 effSlidingORW output
std::vector< std::vector< double > > MultiGaussianSmearing(std::vector< double > const &centralValue, std::vector< std::vector< double > > const &inputCovarianceMatrix, int n_multisims, CLHEP::RandGaussQ &GaussRandom)
do i e
std::pair< bool, double > PHFSWeightCalc(simb::MCFlux flux, std::vector< float > rand)
BEGIN_PROLOG could also be cout