MIPPNumiYieldsBins.cpp
Go to the documentation of this file.
1 
2 #include "MIPPNumiYieldsBins.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  MIPPNumiYieldsBins* MIPPNumiYieldsBins::instance = 0;
14 
16  }
17 
19  using boost::property_tree::ptree;
20  ptree top;
21 
22  read_xml(filename,top,2); // option 2 removes comment strings
23 
24  ptree& binsPIP = top.get_child("bins.MIPP_Numi_pip");
25 
26  ptree::iterator it = binsPIP.begin();
27  //int idx=0;
28  double aux_pzmin,aux_pzmax,aux_ptmin,aux_ptmax;
29 
30  for(; it!=binsPIP.end(); ++it){
31  // it->first is the name
32  // it->second is the child property tree
33  std::string pz_string=it->second.get<std::string>("pzrange");
34  std::string pt_string=it->second.get<std::string>("ptrange");
35 
36  std::stringstream ss1(pz_string);
37  std::stringstream ss2(pt_string);
38  ss1 >> aux_pzmin >> aux_pzmax;
39  ss2 >> aux_ptmin >> aux_ptmax;
40 
41  pip_data_pzmin.push_back(aux_pzmin);
42  pip_data_pzmax.push_back(aux_pzmax);
43  pip_data_ptmin.push_back(aux_ptmin);
44  pip_data_ptmax.push_back(aux_ptmax);
45  }
46  }
47 
49  using boost::property_tree::ptree;
50  ptree top;
51 
52  read_xml(filename,top,2); // option 2 removes comment strings
53 
54  ptree& binsPIM = top.get_child("bins.MIPP_Numi_pim");
55 
56  ptree::iterator it = binsPIM.begin();
57  double aux_pzmin,aux_pzmax,aux_ptmin,aux_ptmax;
58 
59  for(; it!=binsPIM.end(); ++it){
60  // it->first is the name
61  // it->second is the child property tree
62  std::string pz_string=it->second.get<std::string>("pzrange");
63  std::string pt_string=it->second.get<std::string>("ptrange");
64 
65  std::stringstream ss1(pz_string);
66  std::stringstream ss2(pt_string);
67  ss1 >> aux_pzmin >> aux_pzmax;
68  ss2 >> aux_ptmin >> aux_ptmax;
69 
70  pim_data_pzmin.push_back(aux_pzmin);
71  pim_data_pzmax.push_back(aux_pzmax);
72  pim_data_ptmin.push_back(aux_ptmin);
73  pim_data_ptmax.push_back(aux_ptmax);
74  }
75  }
76 
78  using boost::property_tree::ptree;
79  ptree top;
80 
81  read_xml(filename,top,2);
82 
83  ptree& binsK_PI = top.get_child("bins.MIPP_Numi_k_pi");
84 
85  ptree::iterator it = binsK_PI.begin();
86  //int idx=0;
87  double aux_pzmin,aux_pzmax,aux_ptmin,aux_ptmax;
88 
89  for(; it!=binsK_PI.end(); ++it){
90  std::string pz_string=it->second.get<std::string>("pzrange");
91  std::string pt_string=it->second.get<std::string>("ptrange");
92 
93  std::stringstream ss1(pz_string);
94  std::stringstream ss2(pt_string);
95  ss1 >> aux_pzmin >> aux_pzmax;
96  ss2 >> aux_ptmin >> aux_ptmax;
97 
98  k_pi_data_pzmin.push_back(aux_pzmin);
99  k_pi_data_pzmax.push_back(aux_pzmax);
100  k_pi_data_ptmin.push_back(aux_ptmin);
101  k_pi_data_ptmax.push_back(aux_ptmax);
102  }
103  }
104 
105  int MIPPNumiYieldsBins::BinID(double pz,double pt, int pdgcode){
106 
107  int ibinID = -1;
108 
109  int size = 0;
110  if(pdgcode==211){
111  size = pip_data_pzmin.size();
112  for(int ii=0;ii<size;++ii){
113  if(pz>pip_data_pzmin[ii] && pz<pip_data_pzmax[ii] && pt>pip_data_ptmin[ii] && pt<pip_data_ptmax[ii]){
114  ibinID = ii;
115  }
116  }
117 
118  }
119  if(pdgcode==-211){
120  size = pim_data_pzmin.size();
121  for(int ii=0;ii<size;++ii){
122  if(pz>pim_data_pzmin[ii] && pz<pim_data_pzmax[ii] && pt>pim_data_ptmin[ii] && pt<pim_data_ptmax[ii]){
123  ibinID = ii;
124  }
125  }
126 
127  }
128  if(pdgcode==321 || pdgcode==-321 || pdgcode==130 || pdgcode==310){
129  size = k_pi_data_pzmin.size();
130  for(int ii=0;ii<size;++ii){
131  if(pz>k_pi_data_pzmin[ii] && pz<k_pi_data_pzmax[ii] && pt>k_pi_data_ptmin[ii] && pt<k_pi_data_ptmax[ii]){
132  ibinID = ii;
133  }
134  }
135  }
136  return ibinID;
137 
138  }
139 
141  if(pip_data_pzmin.size()==0)throw std::runtime_error("MIPPNumiYieldsBins has not been initialized!!");
142  return pip_data_pzmin.size();
143  }
145  if(pip_data_pzmin.size()==0)throw std::runtime_error("MIPPNumiYieldsBins has not been initialized!!");
146  return pim_data_pzmin.size();
147  }
149  if(k_pi_data_pzmin.size()==0)throw std::runtime_error("MIPPNumiYieldsBins has not been initialized!!");
150  return k_pi_data_pzmin.size();
151  }
152 
154  if (instance == 0) instance = new MIPPNumiYieldsBins;
155  return instance;
156  }
157 
158 }
intermediate_table::iterator iterator
void k_pi_data_from_xml(const char *filename)
Read a xml kaons over pions file name to parse the bins.
void pim_data_from_xml(const char *filename)
Read a xml pim file name to parse the bins.
std::string string
Definition: nybbler.cc:12
string filename
Definition: train.py:213
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
int BinID(double pz, double pt, int pdgcode)
Return the Bin ID for this data.
A class to manage the bin definitions for MIPP Numi Yields.
static MIPPNumiYieldsBins * getInstance()
void pip_data_from_xml(const char *filename)
Read a xml pip file name to parse the bins.