MIPPNumiMC.cpp
Go to the documentation of this file.
1 
2 #include "MIPPNumiMC.h"
3 #include <boost/property_tree/ptree.hpp>
4 #include <boost/property_tree/xml_parser.hpp>
5 
6 namespace NeutrinoFluxReweight{
7 
8  MIPPNumiMC* MIPPNumiMC::instance = 0;
9 
11  ranges_already_filled = false;
12 
13  //FRaction of protons not interacting in the target or Budal Monitor for
14  //LE NuMI mode using FTFP.
15  proton_no_interacting = 0.13288294;
16  }
17 
19  using boost::property_tree::ptree;
20  ptree top;
21  read_xml(filename,top,2);
22  ptree bins;
23  bins = top.get_child("mcbin.MIPPNuMI_MC_pip");
24  ptree::iterator it;
25  // we know that pip, pim, kap and kam have the same binning
26  double cv,pzmin,pzmax,ptmin,ptmax;
27 
28  for(it = bins.begin(); it!=bins.end(); ++it){
29 
30  std::string cv_string=it->second.get<std::string>("cvmc");
31  std::string pz_string=it->second.get<std::string>("pzrange");
32  std::string pt_string=it->second.get<std::string>("ptrange");
33 
34  std::stringstream ss1(cv_string);
35  std::stringstream ss2(pz_string);
36  std::stringstream ss3(pt_string);
37  ss1 >> cv;
38  ss2 >> pzmin >> pzmax;
39  ss3 >> ptmin >> ptmax;
40 
41  pip_cv.push_back(cv);
42  if(ranges_already_filled==false){
43  v_pzmin.push_back(pzmin);
44  v_pzmax.push_back(pzmax);
45  v_ptmin.push_back(ptmin);
46  v_ptmax.push_back(ptmax);
47  }
48 
49  }
51 
52  }
53 
55  using boost::property_tree::ptree;
56  ptree top;
57  read_xml(filename,top,2);
58  ptree bins;
59  bins = top.get_child("mcbin.MIPPNuMI_MC_pim");
60  ptree::iterator it;
61  // we know that pip, pim, kap and kam have the same binning
62  double cv,pzmin,pzmax,ptmin,ptmax;
63 
64  for(it = bins.begin(); it!=bins.end(); ++it){
65 
66  std::string cv_string=it->second.get<std::string>("cvmc");
67  std::string pz_string=it->second.get<std::string>("pzrange");
68  std::string pt_string=it->second.get<std::string>("ptrange");
69 
70  std::stringstream ss1(cv_string);
71  std::stringstream ss2(pz_string);
72  std::stringstream ss3(pt_string);
73  ss1 >> cv;
74  ss2 >> pzmin >> pzmax;
75  ss3 >> ptmin >> ptmax;
76 
77  pim_cv.push_back(cv);
78  if(ranges_already_filled==false){
79  v_pzmin.push_back(pzmin);
80  v_pzmax.push_back(pzmax);
81  v_ptmin.push_back(ptmin);
82  v_ptmax.push_back(ptmax);
83  }
84  }
86 }
87 
88 
90  using boost::property_tree::ptree;
91  ptree top;
92  read_xml(filename,top,2);
93  ptree bins;
94  bins = top.get_child("mcbin.MIPPNuMI_MC_kap");
95  ptree::iterator it;
96  // we know that pip, pim, kap and kam have the same binning
97  double cv,pzmin,pzmax,ptmin,ptmax;
98 
99  for(it = bins.begin(); it!=bins.end(); ++it){
100 
101  std::string cv_string=it->second.get<std::string>("cvmc");
102  std::string pz_string=it->second.get<std::string>("pzrange");
103  std::string pt_string=it->second.get<std::string>("ptrange");
104 
105  std::stringstream ss1(cv_string);
106  std::stringstream ss2(pz_string);
107  std::stringstream ss3(pt_string);
108  ss1 >> cv;
109  ss2 >> pzmin >> pzmax;
110  ss3 >> ptmin >> ptmax;
111 
112  kap_cv.push_back(cv);
113  if(ranges_already_filled==false){
114  v_pzmin.push_back(pzmin);
115  v_pzmax.push_back(pzmax);
116  v_ptmin.push_back(ptmin);
117  v_ptmax.push_back(ptmax);
118  }
119  }
121  }
122 
124  using boost::property_tree::ptree;
125  ptree top;
126  read_xml(filename,top,2);
127  ptree bins;
128  bins = top.get_child("mcbin.MIPPNuMI_MC_kam");
129  ptree::iterator it;
130  // we know that pip, pim, kap and kam have the same binning
131  double cv,pzmin,pzmax,ptmin,ptmax;
132 
133  for(it = bins.begin(); it!=bins.end(); ++it){
134 
135  std::string cv_string=it->second.get<std::string>("cvmc");
136  std::string pz_string=it->second.get<std::string>("pzrange");
137  std::string pt_string=it->second.get<std::string>("ptrange");
138  std::stringstream ss1(cv_string);
139  std::stringstream ss2(pz_string);
140  std::stringstream ss3(pt_string);
141  ss1 >> cv;
142  ss2 >> pzmin >> pzmax;
143  ss3 >> ptmin >> ptmax;
144 
145  kam_cv.push_back(cv);
146  if(ranges_already_filled==false){
147  v_pzmin.push_back(pzmin);
148  v_pzmax.push_back(pzmax);
149  v_ptmin.push_back(ptmin);
150  v_ptmax.push_back(ptmax);
151  }
152  }
154  }
155 
157  using boost::property_tree::ptree;
158  ptree top;
159  read_xml(filename,top,2);
160  ptree bins;
161  bins = top.get_child("mcbin.MIPPNuMI_MC_k0l");
162  ptree::iterator it;
163  // we know that pip, pim, kap, kam, k0l and k0s have the same binning
164  double cv,pzmin,pzmax,ptmin,ptmax;
165 
166  for(it = bins.begin(); it!=bins.end(); ++it){
167 
168  std::string cv_string=it->second.get<std::string>("cvmc");
169  std::string pz_string=it->second.get<std::string>("pzrange");
170  std::string pt_string=it->second.get<std::string>("ptrange");
171  std::stringstream ss1(cv_string);
172  std::stringstream ss2(pz_string);
173  std::stringstream ss3(pt_string);
174  ss1 >> cv;
175  ss2 >> pzmin >> pzmax;
176  ss3 >> ptmin >> ptmax;
177 
178  k0l_cv.push_back(cv);
179  if(ranges_already_filled==false){
180  v_pzmin.push_back(pzmin);
181  v_pzmax.push_back(pzmax);
182  v_ptmin.push_back(ptmin);
183  v_ptmax.push_back(ptmax);
184  }
185  }
187  }
188 
190  using boost::property_tree::ptree;
191  ptree top;
192  read_xml(filename,top,2);
193  ptree bins;
194  bins = top.get_child("mcbin.MIPPNuMI_MC_k0s");
195  ptree::iterator it;
196  // we know that pip, pim, kap, kam, k0l and k0s have the same binning
197  double cv,pzmin,pzmax,ptmin,ptmax;
198 
199  for(it = bins.begin(); it!=bins.end(); ++it){
200 
201  std::string cv_string=it->second.get<std::string>("cvmc");
202  std::string pz_string=it->second.get<std::string>("pzrange");
203  std::string pt_string=it->second.get<std::string>("ptrange");
204  std::stringstream ss1(cv_string);
205  std::stringstream ss2(pz_string);
206  std::stringstream ss3(pt_string);
207  ss1 >> cv;
208  ss2 >> pzmin >> pzmax;
209  ss3 >> ptmin >> ptmax;
210 
211  k0s_cv.push_back(cv);
212  if(ranges_already_filled==false){
213  v_pzmin.push_back(pzmin);
214  v_pzmax.push_back(pzmax);
215  v_ptmin.push_back(ptmin);
216  v_ptmax.push_back(ptmax);
217  }
218  }
220  }
221 
222  double MIPPNumiMC::getMCval(double pz,double pt, int pdgcode){
223 
224  double cvmc = -1;
225  if(abs(pdgcode)!=211 && abs(pdgcode)!=321 && pdgcode!=130 && pdgcode!=310)return cvmc;
226  int size = 0;
227 
228  //pip:
229  if(pdgcode==211){
230  size = pip_cv.size();
231  for(int ii=0;ii<size;++ii){
232  if(pz>v_pzmin[ii] && pz<v_pzmax[ii] && pt>v_ptmin[ii] && pt<v_ptmax[ii]){
233  cvmc = pip_cv[ii];
234  }
235  }
236  }
237 
238  //pim:
239  if(pdgcode==-211){
240  size = pim_cv.size();
241  for(int ii=0;ii<size;++ii){
242  if(pz>v_pzmin[ii] && pz<v_pzmax[ii] && pt>v_ptmin[ii] && pt<v_ptmax[ii]){
243  cvmc = pim_cv[ii];
244  }
245  }
246  }
247 
248  //kap
249  if(pdgcode==321){
250  size = kap_cv.size();
251  for(int ii=0;ii<size;++ii){
252  if(pz>v_pzmin[ii] && pz<v_pzmax[ii] && pt>v_ptmin[ii] && pt<v_ptmax[ii]){
253  cvmc = kap_cv[ii];
254  }
255  }
256  }
257 
258  //kam:
259  if(pdgcode==-321){
260  size = kam_cv.size();
261  for(int ii=0;ii<size;++ii){
262  if(pz>v_pzmin[ii] && pz<v_pzmax[ii] && pt>v_ptmin[ii] && pt<v_ptmax[ii]){
263  cvmc = kam_cv[ii];
264  }
265  }
266  }
267  //k0l:
268  if(pdgcode== 130){
269  size = k0l_cv.size();
270  for(int ii=0;ii<size;++ii){
271  if(pz>v_pzmin[ii] && pz<v_pzmax[ii] && pt>v_ptmin[ii] && pt<v_ptmax[ii]){
272  cvmc = k0l_cv[ii];
273  }
274  }
275  }
276 
277  //k0s:
278  if(pdgcode== 310){
279  size = k0s_cv.size();
280  for(int ii=0;ii<size;++ii){
281  if(pz>v_pzmin[ii] && pz<v_pzmax[ii] && pt>v_ptmin[ii] && pt<v_ptmax[ii]){
282  cvmc = k0s_cv[ii];
283  }
284  }
285  }
286 
287  //The values store in the files correspond to the Number of hadron per POT.
288  // But we are going to trasform to Number of hadron per interaction.
289 
290  cvmc /= (1.0-proton_no_interacting);
291  return cvmc;
292 
293  }
294 
296  if (instance == 0) instance = new MIPPNumiMC;
297  return instance;
298  }
299 
300 }
std::vector< double > kap_cv
Definition: MIPPNumiMC.h:46
double getMCval(double pz, double pt, int pdgcode)
MC value for this HP production.
Definition: MIPPNumiMC.cpp:222
intermediate_table::iterator iterator
A class to manage the MC value for MIPP NuMI.
Definition: MIPPNumiMC.h:16
static MIPPNumiMC * instance
Definition: MIPPNumiMC.h:50
std::vector< double > kam_cv
Definition: MIPPNumiMC.h:46
void k0l_mc_from_xml(const char *filename)
Read a xml file name to get the mc value for k0l.
Definition: MIPPNumiMC.cpp:156
std::string string
Definition: nybbler.cc:12
std::vector< double > pip_cv
Definition: MIPPNumiMC.h:46
std::vector< double > k0l_cv
Definition: MIPPNumiMC.h:46
std::vector< double > v_ptmin
Definition: MIPPNumiMC.h:47
string filename
Definition: train.py:213
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
static MIPPNumiMC * getInstance()
Definition: MIPPNumiMC.cpp:295
T abs(T value)
void pim_mc_from_xml(const char *filename)
Read a xml file name to get the mc value for pim.
Definition: MIPPNumiMC.cpp:54
void kam_mc_from_xml(const char *filename)
Read a xml file name to get the mc value for kam.
Definition: MIPPNumiMC.cpp:123
void kap_mc_from_xml(const char *filename)
Read a xml file name to get the mc value for kap.
Definition: MIPPNumiMC.cpp:89
std::vector< double > v_pzmin
Definition: MIPPNumiMC.h:47
std::vector< double > v_pzmax
Definition: MIPPNumiMC.h:47
void pip_mc_from_xml(const char *filename)
Read a xml file name to get the mc value for pip.
Definition: MIPPNumiMC.cpp:18
std::vector< double > v_ptmax
Definition: MIPPNumiMC.h:47
std::vector< double > k0s_cv
Definition: MIPPNumiMC.h:46
void k0s_mc_from_xml(const char *filename)
Read a xml file name to get the mc value for k0s.
Definition: MIPPNumiMC.cpp:189
std::vector< double > pim_cv
Definition: MIPPNumiMC.h:46