MakeReweight.cpp
Go to the documentation of this file.
1 #include "MakeReweight.h"
2 
3 #include <boost/property_tree/ptree.hpp>
4 #include <boost/property_tree/xml_parser.hpp>
5 
6 namespace NeutrinoFluxReweight{
7 
8  MakeReweight* MakeReweight::instance = 0;
10  }
12  fileOptions = fileIn;
13  ParseOptions();
14  Initialize();
15  }
16 
18  //Parsing the file input:
19  using boost::property_tree::ptree;
20  ptree top;
21  read_xml(fileOptions.c_str(),top,2); // option 2 removes comment strings
22  ptree& options = top.get_child("inputs.Settings");
23 
24  mippCorrOption = options.get<std::string>("MIPPCorrOption");
25  Nuniverses = options.get<int>("NumberOfUniverses");
26 
27  }
29 
30  //Getting MIPP binning and the correlation parameters:
35  const char* ppfxDir = getenv("PPFX_DIR");
36 
37  std::cout<<"Initializing correlation parameters"<<std::endl;
38  cvu->readFromXML(Form("%s/uncertainties/Parameters_%s.xml",ppfxDir,mippCorrOption.c_str()));
39 
40  std::cout<<"Initializing bin data conventions"<<std::endl;
41  myb->pip_data_from_xml(Form("%s/data/BINS/MIPPNumiData_PIP_Bins.xml",ppfxDir));
42  myb->pim_data_from_xml(Form("%s/data/BINS/MIPPNumiData_PIM_Bins.xml",ppfxDir));
43  myb->k_pi_data_from_xml(Form("%s/data/BINS/MIPPNumiData_K_PI_Bins.xml",ppfxDir));
44  thinbin->pC_pi_from_xml(Form("%s/data/BINS/ThinTarget_pC_pi_Bins.xml",ppfxDir));
45  thinbin->barton_pC_pi_from_xml(Form("%s/data/BINS/ThinTargetBarton_pC_pi_Bins.xml",ppfxDir));
46  thinbin->pC_k_from_xml(Form("%s/data/BINS/ThinTargetLowxF_pC_k_Bins.xml",ppfxDir));
47  thinbin->mipp_pC_k_pi_from_xml(Form("%s/data/BINS/ThinTarget_K_PI_Bins.xml",ppfxDir));
48  thinbin->meson_incident_from_xml(Form("%s/data/BINS/ThinTarget_MesonIncident.xml",ppfxDir));
49  thinbin->pC_p_from_xml(Form("%s/data/BINS/ThinTarget_pC_p_Bins.xml",ppfxDir));
50  thinbin->pC_n_from_xml(Form("%s/data/BINS/ThinTarget_pC_n_Bins.xml",ppfxDir));
51  thinbin->material_scaling_from_xml(Form("%s/data/BINS/ThinTarget_material_scaling_Bins.xml",ppfxDir));
52 
53  std::cout<<"Initializing MC values"<<std::endl;
54  mymc->pip_mc_from_xml(Form("%s/data/MIPP/MIPPNuMI_MC_PIP.xml",ppfxDir));
55  mymc->pim_mc_from_xml(Form("%s/data/MIPP/MIPPNuMI_MC_PIM.xml",ppfxDir));
56  mymc->kap_mc_from_xml(Form("%s/data/MIPP/MIPPNuMI_MC_KAP.xml",ppfxDir));
57  mymc->kam_mc_from_xml(Form("%s/data/MIPP/MIPPNuMI_MC_KAM.xml",ppfxDir));
58  mymc->k0l_mc_from_xml(Form("%s/data/MIPP/MIPPNuMI_MC_K0L.xml",ppfxDir));
59  mymc->k0s_mc_from_xml(Form("%s/data/MIPP/MIPPNuMI_MC_K0S.xml",ppfxDir));
60 
61  //Reweighter drivers:
62  vec_rws.reserve(Nuniverses);
63  std::cout<<"Initializing reweight drivers for "<<Nuniverses<<" universes"<<std::endl;
64 
65  const int base_universe=1000000;
66  // cvPars.reserve(Nuniverses+1);
67  univPars.reserve(Nuniverses+1);
68 
70 
71  std::cout<<"Loading parameters for universe: ";
72  for(int ii=0;ii<Nuniverses;ii++){
73  std::cout << ii << " " << std::flush;
74  // cvPars.push_back(cvu->getCVPars());
75  univPars.push_back(cvu->calculateParsForUniverse(ii+base_universe));
76  vec_rws.push_back(new ReweightDriver(ii,cvPars,univPars[ii],fileOptions));
77  vec_wgts.push_back(1.0);
78  }
79  std::cout << std::endl;
80 
81  //Central Value driver:
82  //by convention, we use universe -1 to hold the cv. It is in agreement with CentralValueAndUncertainties
83  const int cv_id = -1;
84  std::cout<<"Loading parameters for cv"<<std::endl;
85  // cvPars.push_back(cvu->getCVPars());
86  univPars.push_back(cvu->calculateParsForUniverse(cv_id));
87  cv_rw = new ReweightDriver(cv_id,cvPars,univPars[Nuniverses],fileOptions);
88 
89  cv_wgt = 1.0;
90 
91  std::cout<<"Done configuring universes"<<std::endl;
92 
93  }
94 
95  std::vector<double> MakeReweight::GetTotalWeights(){
96  return vec_wgts;
97  }
98  /////
99  void MakeReweight::calculateWeights(nu_g4numi* nu, const char* tgtcfg, const char* horncfg){
100  InteractionChainData inter_chain(nu,tgtcfg,horncfg);
101  doTheJob(&inter_chain);
102  }
103  /////
104  void MakeReweight::calculateWeights(bsim::Dk2Nu* nu, bsim::DkMeta* meta){
105  InteractionChainData inter_chain(nu,meta);
106  doTheJob(&inter_chain);
107  }
108  /////
110 
111  //universe calculation:
112  map_rew_wgts.clear();
113  for(int ii=0;ii<Nuniverses;ii++){
114  vec_wgts[ii] = vec_rws[ii]->calculateWeight(*icd);
115 
116  map_rew_wgts["MIPPNumiPionYields"].push_back(vec_rws[ii]->mipp_pion_wgt);
117  map_rew_wgts["MIPPNumiKaonYields"].push_back(vec_rws[ii]->mipp_kaon_wgt);
118 
119  map_rew_wgts["TargetAttenuation"].push_back(vec_rws[ii]->att_wgt);
120  map_rew_wgts["AbsorptionIC"].push_back(vec_rws[ii]->abs_ic_wgt);
121  map_rew_wgts["AbsorptionDPIP"].push_back(vec_rws[ii]->abs_dpip_wgt);
122  map_rew_wgts["AbsorptionDVOL"].push_back(vec_rws[ii]->abs_dvol_wgt);
123  map_rew_wgts["AbsorptionNucleon"].push_back(vec_rws[ii]->abs_nucleon_wgt);
124  map_rew_wgts["AbsorptionOther"].push_back(vec_rws[ii]->abs_other_wgt);
125  map_rew_wgts["TotalAbsorption"].push_back(vec_rws[ii]->tot_abs_wgt);
126 
127  map_rew_wgts["ThinTargetpCPion"].push_back(vec_rws[ii]->pC_pi_wgt);
128  map_rew_wgts["ThinTargetpCKaon"].push_back(vec_rws[ii]->pC_k_wgt);
129  map_rew_wgts["ThinTargetnCPion"].push_back(vec_rws[ii]->nC_pi_wgt);
130  map_rew_wgts["ThinTargetpCNucleon"].push_back(vec_rws[ii]->pC_nu_wgt);
131  map_rew_wgts["ThinTargetMesonIncident"].push_back(vec_rws[ii]->meson_inc_wgt);
132  map_rew_wgts["ThinTargetnucleonA"].push_back(vec_rws[ii]->nuA_wgt);
133  map_rew_wgts["Other"].push_back(vec_rws[ii]->other_wgt);
134 
135  }
136 
137  //cv calculation:
138  cv_wgt = cv_rw->calculateWeight(*icd);
139 
140  }
141  ////
142  std::vector<double> MakeReweight::GetWeights(std::string nameReweighter){
143 
144  std::vector<double> tmp_vec;
145  std::map<std::string,std::vector<double> >::iterator it = map_rew_wgts.begin();
146  it = map_rew_wgts.find(nameReweighter);
147  if(it!=map_rew_wgts.end())tmp_vec = it->second;
148 
149  return tmp_vec;
150 
151  }
152  ////
154  return cv_wgt;
155  }
156  ///
158  return Nuniverses;
159  }
161 
162  }
163  ///
165  if (instance == 0) instance = new MakeReweight;
166  return instance;
167  }
168  ////
170  {
171  delete instance;
172  instance = 0;
173  }
174 }
A class to manage the bin definitions for MIPP Numi Yields.
void k_pi_data_from_xml(const char *filename)
Read a xml kaons over pions file name to parse the bins.
A list/table of parameter names and values.
void doTheJob(InteractionChainData *icd)
void meson_incident_from_xml(const char *filename)
Read a pion incident.
std::vector< double > GetWeights(std::string nameReweighter)
get the vector of the weights for a given reweighter
A class to manage the MC value for MIPP NuMI.
Definition: MIPPNumiMC.h:16
void pim_data_from_xml(const char *filename)
Read a xml pim file name to parse the bins.
A class to make the reweight event by event.
Definition: MakeReweight.h:32
void k0l_mc_from_xml(const char *filename)
Read a xml file name to get the mc value for k0l.
Definition: MIPPNumiMC.cpp:156
double GetCVWeight()
get the cv weights
std::string string
Definition: nybbler.cc:12
Information about the chain of interactions leading to a neutrino.
static MakeReweight * getInstance()
A class to manage and drive the weight calculation procedure.
double calculateWeight(const InteractionChainData &icd)
void barton_pC_pi_from_xml(const char *filename)
Barton:
void material_scaling_from_xml(const char *filename)
Read a pion incident.
static MIPPNumiMC * getInstance()
Definition: MIPPNumiMC.cpp:295
std::vector< ParameterTable > cvPars
Definition: MakeReweight.h:80
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 mipp_pC_k_pi_from_xml(const char *filename)
MIPP k/pi:
ParameterTable calculateParsForUniverse(int universe)
Calculate a table of randomly varied parameters for a particular universe i. The universe number is u...
void pC_pi_from_xml(const char *filename)
Read a NA49 data pip xml file name to parse the bins.
std::string getenv(std::string const &name)
Definition: getenv.cc:15
QTextStream & flush(QTextStream &s)
int GetNumberOfUniversesUsed()
number of universes used in this run
static MakeReweight * instance
Definition: MakeReweight.h:88
void pC_p_from_xml(const char *filename)
Read a NA49 data prt xml file name to parse the bins.
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 pC_n_from_xml(const char *filename)
Read a NA49 data neutron xml file name to parse the bins.
A class to manage the bin definitions for MIPP Numi Yields.
void kap_mc_from_xml(const char *filename)
Read a xml file name to get the mc value for kap.
Definition: MIPPNumiMC.cpp:89
static ThinTargetBins * getInstance()
static MIPPNumiYieldsBins * getInstance()
void pip_mc_from_xml(const char *filename)
Read a xml file name to get the mc value for pip.
Definition: MIPPNumiMC.cpp:18
A class to manage parameter central values and their uncertanities.
void calculateWeights(nu_g4numi *nu, const char *tgtcfg, const char *horncfg)
ParameterTable getCVPars()
Get the central value parameters.
std::vector< ReweightDriver * > vec_rws
vector of Reweighter Drivers, one per universe
Definition: MakeReweight.h:65
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::map< std::string, std::vector< double > > map_rew_wgts
Definition: MakeReweight.h:85
std::vector< ParameterTable > univPars
Definition: MakeReweight.h:80
ReweightDriver * cv_rw
Reweighter Drivers for the central value.
Definition: MakeReweight.h:68
std::vector< double > vec_wgts
Definition: MakeReweight.h:84
void readFromXML(const char *filename)
Read a xml file name to parse the parameters.
std::vector< double > GetTotalWeights()
total weights
void pip_data_from_xml(const char *filename)
Read a xml pip file name to parse the bins.
QTextStream & endl(QTextStream &s)
void SetOptions(std::string fileIn)
void pC_k_from_xml(const char *filename)
Read a NA49 data K xml file name to parse the bins.