ThinTargetBins.cpp
Go to the documentation of this file.
1 
2 #include "ThinTargetBins.h"
3 #include <set>
4 #include <string>
5 #include <iostream>
6 #include <sstream>
7 
8 #include <boost/property_tree/ptree.hpp>
9 #include <boost/property_tree/xml_parser.hpp>
10 
11 namespace NeutrinoFluxReweight{
12 
13  ThinTargetBins* ThinTargetBins::instance = 0;
14 
16 
17  }
18 
20  using boost::property_tree::ptree;
21  ptree top;
22  read_xml(filename,top,2);
23  ptree& binsPI = top.get_child("bins.ThinTarget_pC_pi");
24  ptree::iterator it = binsPI.begin();
25 
26  //int idx=0;
27  double aux_xfmin,aux_xfmax,aux_ptmin,aux_ptmax;
28  for(; it!=binsPI.end(); ++it){
29  std::string xf_string=it->second.get<std::string>("xfrange");
30  std::string pt_string=it->second.get<std::string>("ptrange");
31 
32  std::stringstream ss1(xf_string);
33  std::stringstream ss2(pt_string);
34  ss1 >> aux_xfmin >> aux_xfmax;
35  ss2 >> aux_ptmin >> aux_ptmax;
36 
37  pC_pi_xfmin.push_back(aux_xfmin);
38  pC_pi_xfmax.push_back(aux_xfmax);
39  pC_pi_ptmin.push_back(aux_ptmin);
40  pC_pi_ptmax.push_back(aux_ptmax);
41 
42  }
43 
44  }
45 
47  using boost::property_tree::ptree;
48  ptree top;
49  read_xml(filename,top,2);
50  ptree& binsPI = top.get_child("bins.ThinTargetBarton_pC_pi");
51  ptree::iterator it = binsPI.begin();
52 
53  //int idx=0;
54  double aux_xfmin,aux_xfmax,aux_ptmin,aux_ptmax;
55  for(; it!=binsPI.end(); ++it){
56  std::string xf_string=it->second.get<std::string>("xfrange");
57  std::string pt_string=it->second.get<std::string>("ptrange");
58 
59  std::stringstream ss1(xf_string);
60  std::stringstream ss2(pt_string);
61  ss1 >> aux_xfmin >> aux_xfmax;
62  ss2 >> aux_ptmin >> aux_ptmax;
63 
64  b_pC_pi_xfmin.push_back(aux_xfmin);
65  b_pC_pi_xfmax.push_back(aux_xfmax);
66  b_pC_pi_ptmin.push_back(aux_ptmin);
67  b_pC_pi_ptmax.push_back(aux_ptmax);
68 
69  }
70 
71  }
72 
74  using boost::property_tree::ptree;
75  ptree top;
76  read_xml(filename,top,2);
77  ptree& binsP = top.get_child("bins.ThinTarget_pC_p");
78  ptree::iterator it = binsP.begin();
79 
80  //int idx=0;
81  double aux_xfmin,aux_xfmax,aux_ptmin,aux_ptmax;
82  for(; it!=binsP.end(); ++it){
83  std::string xf_string=it->second.get<std::string>("xfrange");
84  std::string pt_string=it->second.get<std::string>("ptrange");
85 
86  std::stringstream ss1(xf_string);
87  std::stringstream ss2(pt_string);
88  ss1 >> aux_xfmin >> aux_xfmax;
89  ss2 >> aux_ptmin >> aux_ptmax;
90 
91  pC_p_xfmin.push_back(aux_xfmin);
92  pC_p_xfmax.push_back(aux_xfmax);
93  pC_p_ptmin.push_back(aux_ptmin);
94  pC_p_ptmax.push_back(aux_ptmax);
95 
96  }
97 
98  }
99 
101  using boost::property_tree::ptree;
102  ptree top;
103  read_xml(filename,top,2);
104  ptree& binsN = top.get_child("bins.ThinTarget_pC_n");
105  ptree::iterator it = binsN.begin();
106 
107  //int idx=0;
108  double aux_xfmin,aux_xfmax;
109  for(; it!=binsN.end(); ++it){
110  std::string xf_string=it->second.get<std::string>("xfrange");
111  std::stringstream ss1(xf_string);
112  ss1 >> aux_xfmin >> aux_xfmax;
113 
114  pC_n_xfmin.push_back(aux_xfmin);
115  pC_n_xfmax.push_back(aux_xfmax);
116 
117  }
118 
119  }
120 
122  using boost::property_tree::ptree;
123  ptree top;
124  read_xml(filename,top,2);
125  ptree& binsK = top.get_child("bins.ThinTargetLowxF_pC_k");
126  ptree::iterator it = binsK.begin();
127 
128  //int idx=0;
129  double aux_xfmin,aux_xfmax,aux_ptmin,aux_ptmax;
130  for(; it!=binsK.end(); ++it){
131  std::string xf_string=it->second.get<std::string>("xfrange");
132  std::string pt_string=it->second.get<std::string>("ptrange");
133 
134  std::stringstream ss1(xf_string);
135  std::stringstream ss2(pt_string);
136  ss1 >> aux_xfmin >> aux_xfmax;
137  ss2 >> aux_ptmin >> aux_ptmax;
138 
139  pC_k_xfmin.push_back(aux_xfmin);
140  pC_k_xfmax.push_back(aux_xfmax);
141  pC_k_ptmin.push_back(aux_ptmin);
142  pC_k_ptmax.push_back(aux_ptmax);
143 
144  }
145 
146  }
147 
149  using boost::property_tree::ptree;
150  ptree top;
151  read_xml(filename,top,2);
152  ptree& binsK = top.get_child("bins.ThinTarget_k_pi");
153  ptree::iterator it = binsK.begin();
154 
155  //int idx=0;
156  double aux_pzmin,aux_pzmax,aux_ptmin,aux_ptmax;
157  for(; it!=binsK.end(); ++it){
158  std::string pz_string=it->second.get<std::string>("pzrange");
159  std::string pt_string=it->second.get<std::string>("ptrange");
160 
161  std::stringstream ss1(pz_string);
162  std::stringstream ss2(pt_string);
163  ss1 >> aux_pzmin >> aux_pzmax;
164  ss2 >> aux_ptmin >> aux_ptmax;
165 
166  mipp_pC_k_pzmin.push_back(aux_pzmin);
167  mipp_pC_k_pzmax.push_back(aux_pzmax);
168  mipp_pC_k_ptmin.push_back(aux_ptmin);
169  mipp_pC_k_ptmax.push_back(aux_ptmax);
170 
171  }
172 
173 }
174 
176  using boost::property_tree::ptree;
177  ptree top;
178  read_xml(filename,top,2);
179  ptree& bins = top.get_child("bins.ThinTarget_MesonIncident");
180  ptree::iterator it = bins.begin();
181 
182  //int idx=0;
183  double aux_xfmin,aux_xfmax,aux_ptmin,aux_ptmax;
184  for(; it!=bins.end(); ++it){
185  std::string xf_string=it->second.get<std::string>("xfrange");
186  std::string pt_string=it->second.get<std::string>("ptrange");
187 
188  std::stringstream ss1(xf_string);
189  std::stringstream ss2(pt_string);
190  ss1 >> aux_xfmin >> aux_xfmax;
191  ss2 >> aux_ptmin >> aux_ptmax;
192 
193  meson_inc_xfmin.push_back(aux_xfmin);
194  meson_inc_xfmax.push_back(aux_xfmax);
195  meson_inc_ptmin.push_back(aux_ptmin);
196  meson_inc_ptmax.push_back(aux_ptmax);
197 
198  }
199 
200  }
201 
203  using boost::property_tree::ptree;
204  ptree top;
205  read_xml(filename,top,2);
206  ptree& bins = top.get_child("bins.ThinTarget_material_scaling");
207  ptree::iterator it = bins.begin();
208 
209  //int idx=0;
210  double aux_xfmin,aux_xfmax,aux_ptmin,aux_ptmax;
211  for(; it!=bins.end(); ++it){
212  std::string xf_string=it->second.get<std::string>("xfrange");
213  std::string pt_string=it->second.get<std::string>("ptrange");
214 
215  std::stringstream ss1(xf_string);
216  std::stringstream ss2(pt_string);
217  ss1 >> aux_xfmin >> aux_xfmax;
218  ss2 >> aux_ptmin >> aux_ptmax;
219 
220  mat_scal_xfmin.push_back(aux_xfmin);
221  mat_scal_xfmax.push_back(aux_xfmax);
222  mat_scal_ptmin.push_back(aux_ptmin);
223  mat_scal_ptmax.push_back(aux_ptmax);
224 
225  }
226 
227  }
228 
229  /////////////////////////////////////////////////////////////////
230  int ThinTargetBins::BinID_pC_pi(double xf, double pt,int pdgcode){
231 
232  int ibinID = -1;
233  int size = 0;
234 
235  if(pdgcode == 211 || pdgcode == -211){
236  size = pC_pi_xfmin.size();
237  for(int ii=0;ii<size;++ii){
238  if(xf>pC_pi_xfmin[ii] && xf<pC_pi_xfmax[ii] && pt>pC_pi_ptmin[ii] && pt<pC_pi_ptmax[ii]){
239  ibinID = ii;
240  }
241  }
242  }
243 
244  return ibinID;
245 
246  }
247 
248  int ThinTargetBins::barton_BinID_pC_pi(double xf, double pt,int pdgcode){
249 
250  int ibinID = -1;
251  int size = 0;
252 
253  if(pdgcode == 211 || pdgcode == -211){
254  size = b_pC_pi_xfmin.size();
255  for(int ii=0;ii<size;ii++){
256  if(xf>b_pC_pi_xfmin[ii] && xf<b_pC_pi_xfmax[ii] && pt>b_pC_pi_ptmin[ii] && pt<b_pC_pi_ptmax[ii]){
257  ibinID = ii;
258  }
259  }
260  }
261 
262  return ibinID;
263 
264  }
265 
266  int ThinTargetBins::BinID_pC_p(double xf, double pt,int pdgcode){
267 
268  int ibinID = -1;
269  int size = 0;
270 
271  if(pdgcode == 2212){
272  size = pC_p_xfmin.size();
273  for(int ii=0;ii<size;++ii){
274  if(xf>pC_p_xfmin[ii] && xf<pC_p_xfmax[ii] && pt>pC_p_ptmin[ii] && pt<pC_p_ptmax[ii]){
275  ibinID = ii;
276  }
277  }
278  }
279 
280  return ibinID;
281 
282  }
283 
284  int ThinTargetBins::BinID_pC_n(double xf, int pdgcode){
285 
286  int ibinID = -1;
287  int size = 0;
288  if(pdgcode == 2112){
289  size = pC_n_xfmin.size();
290  for(int ii=0;ii<size;++ii){
291  if( (xf>pC_n_xfmin[ii]) && (xf<pC_n_xfmax[ii])){
292  ibinID = ii;
293  }
294  }
295  }
296 
297  return ibinID;
298 
299  }
300 
301  int ThinTargetBins::BinID_pC_k(double xf, double pt,int pdgcode){
302 
303  int ibinID = -1;
304  int size = 0;
305 
306  if(pdgcode == 321 || pdgcode == -321 || pdgcode == 130 || pdgcode == 310){
307  size = pC_k_xfmin.size();
308  for(int ii=0;ii<size;++ii){
309  if(xf>pC_k_xfmin[ii] && xf<pC_k_xfmax[ii] && pt>pC_k_ptmin[ii] && pt<pC_k_ptmax[ii]){
310  ibinID = ii;
311  }
312  }
313  }
314 
315  return ibinID;
316 
317  }
318 
319  int ThinTargetBins::mipp_BinID_pC_k(double pz, double pt,int pdgcode){
320 
321  int ibinID = -1;
322  int size = 0;
323 
324  if(pdgcode == 321 || pdgcode == -321 || pdgcode == 130 || pdgcode == 310){
325  size = mipp_pC_k_pzmin.size();
326  for(int ii=0;ii<size;++ii){
327  if(pz>mipp_pC_k_pzmin[ii] && pz<mipp_pC_k_pzmax[ii] && pt>mipp_pC_k_ptmin[ii] && pt<mipp_pC_k_ptmax[ii]){
328  ibinID = ii;
329  }
330  }
331  }
332 
333  return ibinID;
334 
335  }
336 
337 int ThinTargetBins::meson_inc_BinID(double xf, double pt,int pdgcode){
338 
339  int ibinID = -1;
340  int size = 0;
341 
342  if(pdgcode == 211 || pdgcode == -211 || pdgcode == 321 || pdgcode == -321|| pdgcode == 130 || pdgcode == 310){
343  size = meson_inc_xfmin.size();
344  for(int ii=0;ii<size;++ii){
345  if(xf>meson_inc_xfmin[ii] && xf<meson_inc_xfmax[ii] && pt>meson_inc_ptmin[ii] && pt<meson_inc_ptmax[ii]){
346  ibinID = ii;
347  }
348  }
349  }
350 
351  return ibinID;
352 
353  }
354 
355 int ThinTargetBins::material_scaling_BinID(double xf, double pt,int pdgcode){
356 
357  int ibinID = -1;
358  int size = 0;
359 
360  if(pdgcode == 211 || pdgcode == -211 || pdgcode == 321 || pdgcode == -321|| pdgcode == 130 || pdgcode == 310){
361  size = mat_scal_xfmin.size();
362  for(int ii=0;ii<size;++ii){
363  if((xf>mat_scal_xfmin[ii]) && (xf<mat_scal_xfmax[ii]) && (pt>mat_scal_ptmin[ii]) && (pt<mat_scal_ptmax[ii])){
364  ibinID = ii;
365  }
366  }
367  }
368 
369  return ibinID;
370 
371  }
372 
374  if(pC_pi_xfmin.size()==0)throw std::runtime_error("ThinTargetBins has not been initialized!!");
375  return pC_pi_xfmin.size();
376  }
378  if(b_pC_pi_xfmin.size()==0)throw std::runtime_error("ThinTargetBins has not been initialized!!");
379  return b_pC_pi_xfmin.size();
380  }
382  if(pC_p_xfmin.size()==0)throw std::runtime_error("ThinTargetBins has not been initialized!!");
383  return pC_p_xfmin.size();
384  }
386  if(pC_n_xfmin.size()==0)throw std::runtime_error("ThinTargetBins has not been initialized!!");
387  return pC_n_xfmin.size();
388  }
390  if(pC_k_xfmin.size()==0)throw std::runtime_error("ThinTargetBins has not been initialized!!");
391  return pC_k_xfmin.size();
392  }
394  if(mipp_pC_k_pzmin.size()==0)throw std::runtime_error("ThinTargetBins has not been initialized!!");
395  return mipp_pC_k_pzmin.size();
396  }
398  if(meson_inc_xfmin.size()==0)throw std::runtime_error("ThinTargetBins has not been initialized!!");
399  return meson_inc_xfmin.size();
400  }
402  if(mat_scal_xfmin.size()==0)throw std::runtime_error("ThinTargetBins has not been initialized!!");
403  return mat_scal_xfmin.size();
404  }
405 
407  if (instance == 0) instance = new ThinTargetBins;
408  return instance;
409  }
410 
411 }
A class to manage the bin definitions for MIPP Numi Yields.
intermediate_table::iterator iterator
int BinID_pC_n(double xf, int pdgcode)
Return the Bin ID for this data.
void meson_incident_from_xml(const char *filename)
Read a pion incident.
static ThinTargetBins * instance
std::string string
Definition: nybbler.cc:12
std::vector< double > mipp_pC_k_ptmin
std::vector< double > meson_inc_ptmin
std::vector< double > mipp_pC_k_pzmin
string filename
Definition: train.py:213
void barton_pC_pi_from_xml(const char *filename)
Barton:
std::vector< double > mat_scal_ptmin
void material_scaling_from_xml(const char *filename)
Read a pion incident.
std::vector< double > meson_inc_xfmax
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
std::vector< double > b_pC_pi_xfmax
int material_scaling_BinID(double xf, double pt, int pdgcode)
Return material scaling bin.
int BinID_pC_p(double xf, double pt, int pdgcode)
Return the Bin ID for this data.
void mipp_pC_k_pi_from_xml(const char *filename)
MIPP k/pi:
std::vector< double > b_pC_pi_xfmin
std::vector< double > b_pC_pi_ptmax
int meson_inc_BinID(double xf, double pt, int pdgcode)
Return Pion incident bin.
void pC_pi_from_xml(const char *filename)
Read a NA49 data pip xml file name to parse the bins.
std::vector< double > mat_scal_ptmax
void pC_p_from_xml(const char *filename)
Read a NA49 data prt xml file name to parse the bins.
void pC_n_from_xml(const char *filename)
Read a NA49 data neutron xml file name to parse the bins.
std::vector< double > b_pC_pi_ptmin
int BinID_pC_k(double xf, double pt, int pdgcode)
Return the Bin ID for this data.
std::vector< double > mat_scal_xfmax
std::vector< double > meson_inc_xfmin
std::vector< double > mat_scal_xfmin
int BinID_pC_pi(double xf, double pt, int pdgcode)
Return the Bin ID for this data.
static ThinTargetBins * getInstance()
int barton_BinID_pC_pi(double xf, double pt, int pdgcode)
Return the Bin ID for this data.
std::vector< double > mipp_pC_k_ptmax
std::vector< double > meson_inc_ptmax
int mipp_BinID_pC_k(double pz, double pt, int pdgcode)
Return the MIPP Thin Target Bin ID for this data.
std::vector< double > mipp_pC_k_pzmax
void pC_k_from_xml(const char *filename)
Read a NA49 data K xml file name to parse the bins.