ThinTargetnucleonAReweighter.cpp
Go to the documentation of this file.
1 
3 #include <iostream>
4 #include <cstdlib>
5 #include "MakeReweight.h"
6 #include "ThinTargetMC.h"
7 
8 namespace NeutrinoFluxReweight{
9 
10  ThinTargetnucleonAReweighter::ThinTargetnucleonAReweighter(int iuniv, const ParameterTable& cv_pars, const ParameterTable& univ_pars):iUniv(iuniv),cvPars(cv_pars),univPars(univ_pars){
11 
13 
14  vbin_data_pip.reserve(Thinbins->GetNbins_material_scaling());
15  vbin_data_pim.reserve(Thinbins->GetNbins_material_scaling());
16  vbin_data_kap.reserve(Thinbins->GetNbins_material_scaling());
17  vbin_data_kam.reserve(Thinbins->GetNbins_material_scaling());
18 
19  //Currently, We are using the same number of xF ranges for nucleon inc. and meson inc.
20  vbin_prt_inc_pip.reserve(Thinbins->GetNbins_meson_incident());
21  vbin_prt_inc_pim.reserve(Thinbins->GetNbins_meson_incident());
22  vbin_prt_inc_kap.reserve(Thinbins->GetNbins_meson_incident());
23  vbin_prt_inc_kam.reserve(Thinbins->GetNbins_meson_incident());
24  vbin_prt_inc_k0.reserve(Thinbins->GetNbins_meson_incident());
25  vbin_prt_inc_p.reserve(Thinbins->GetNbins_meson_incident());
26  vbin_prt_inc_n.reserve(Thinbins->GetNbins_meson_incident());
27  vbin_neu_inc_pip.reserve(Thinbins->GetNbins_meson_incident());
28  vbin_neu_inc_pim.reserve(Thinbins->GetNbins_meson_incident());
29  vbin_neu_inc_kap.reserve(Thinbins->GetNbins_meson_incident());
30  vbin_neu_inc_kam.reserve(Thinbins->GetNbins_meson_incident());
31  vbin_neu_inc_k0.reserve(Thinbins->GetNbins_meson_incident());
32  vbin_neu_inc_p.reserve(Thinbins->GetNbins_meson_incident());
33  vbin_neu_inc_n.reserve(Thinbins->GetNbins_meson_incident());
34 
35  // const boost::interprocess::flat_map<std::string, double>& cv_table = cvPars.getMap();
36  // const boost::interprocess::flat_map<std::string, double>& univ_table = univPars.getMap();
37  char namepar[100];
38 
39  data_prod_xs = univPars.getParameterValue("prod_prtC_xsec");
40 
41  //4 particles
42  const char* cinc[4] = {"pip","pim","kap","kam"};
43  for(int ii=0;ii<4;ii++){
44  for(int jj=0;jj<Thinbins->GetNbins_material_scaling();jj++){
45  sprintf(namepar,"ThinTarget_material_scaling_%s_%d",cinc[ii],jj);
46  double dataval = univPars.getParameterValue(std::string(namepar));
47  if(ii==0)vbin_data_pip.push_back(dataval);
48  if(ii==1)vbin_data_pim.push_back(dataval);
49  if(ii==2)vbin_data_kap.push_back(dataval);
50  if(ii==3)vbin_data_kam.push_back(dataval);
51  }
52  }
53 
54  //for all nucleons incident not covered by any thin target reweighters
55  //2 incident nucleons, 7 produced particles:
56  const char* nuinc[2] = {"prt","neu"};
57  const char* cpro[7] = {"pip","pim","kap","kam","k0","n","p"};
58 
59  for(int ii=0;ii<2;ii++){
60  for(int jj=0;jj<7;jj++){
61  for(int kk=0;kk<Thinbins->GetNbins_meson_incident();kk++){
62  sprintf(namepar,"ThinTarget_%s_incident_%s_%d",nuinc[ii],cpro[jj],kk);
63  double dataval = univPars.getParameterValue(std::string(namepar));
64  if(ii==0 && jj==0)vbin_prt_inc_pip.push_back(dataval);
65  if(ii==0 && jj==1)vbin_prt_inc_pim.push_back(dataval);
66  if(ii==0 && jj==2)vbin_prt_inc_kap.push_back(dataval);
67  if(ii==0 && jj==3)vbin_prt_inc_kam.push_back(dataval);
68  if(ii==0 && jj==4)vbin_prt_inc_k0.push_back(dataval);
69  if(ii==0 && jj==5)vbin_prt_inc_n.push_back(dataval);
70  if(ii==0 && jj==6)vbin_prt_inc_p.push_back(dataval);
71  if(ii==1 && jj==0)vbin_neu_inc_pip.push_back(dataval);
72  if(ii==1 && jj==1)vbin_neu_inc_pim.push_back(dataval);
73  if(ii==1 && jj==2)vbin_neu_inc_kap.push_back(dataval);
74  if(ii==1 && jj==3)vbin_neu_inc_kam.push_back(dataval);
75  if(ii==1 && jj==4)vbin_neu_inc_k0.push_back(dataval);
76  if(ii==1 && jj==5)vbin_neu_inc_n.push_back(dataval);
77  if(ii==1 && jj==6)vbin_neu_inc_p.push_back(dataval);
78  }
79  }
80  }
81  //left over:
82  sprintf(namepar,"ThinTarget_prtleftover_incident_%d",0);
84  sprintf(namepar,"ThinTarget_neuleftover_incident_%d",0);
86 
87  }
88 
90 
91  }
93 
94  //checking:
95  if(aa.Inc_pdg != 2212 && aa.Inc_pdg != 2112)return false;
96  // if(aa.Inc_P < 12.0)return false;
97  // if(aa.Vol == "TGT1" || aa.Vol == "BudalMonitor")return false;
98  //if(aa.Prod_pdg != 211 && aa.Prod_pdg != -211 && aa.Prod_pdg !=321 && aa.Prod_pdg != -321 && aa.Prod_pdg !=310 && aa.Prod_pdg != 130)return false;
99 
100  // ThinTargetBins* Thinbins = ThinTargetBins::getInstance();
101  //int bin = Thinbins->material_scaling_BinID(aa.xF,aa.Pt,aa.Prod_pdg);
102  // if(bin<0)return false;
103 
104  /*
105  MakeReweight* makerew = MakeReweight::getInstance();
106  if(aa.Inc_pdg == 2212){
107  if(aa.Prod_pdg == 211 || aa.Prod_pdg == -211){
108  if(iUniv==-1)tt_pCPionRew = (makerew->cv_rw)->THINTARGET_PC_PION_Universe;
109  else tt_pCPionRew = (makerew->vec_rws[iUniv])->THINTARGET_PC_PION_Universe;
110  return tt_pCPionRew->canReweight(*aux_aa);
111  }
112  else if(aa.Prod_pdg == 321 || aa.Prod_pdg == -321 || aa.Prod_pdg == 310 || aa.Prod_pdg == 130){
113  if(iUniv==-1)tt_pCKaonRew = (makerew->cv_rw)->THINTARGET_PC_KAON_Universe;
114  else tt_pCKaonRew = (makerew->vec_rws[iUniv])->THINTARGET_PC_KAON_Universe;
115  return tt_pCKaonRew->canReweight(*aux_aa);
116  }
117  }
118  else if(aa.Inc_pdg == 2112){
119  if(aa.Prod_pdg == 211 || aa.Prod_pdg == -211){
120  if(iUniv==-1)tt_nCPionRew = (makerew->cv_rw)->THINTARGET_NC_PION_Universe;
121  else tt_nCPionRew = (makerew->vec_rws[iUniv])->THINTARGET_NC_PION_Universe;
122  return tt_nCPionRew->canReweight(*aux_aa);
123  }
124  }
125  */
126 
127  return true;
128  }
129 
131 
132  double wgt = 1.0;
133  std::string mode(getenv("MODE"));
134  //checking:
135  if(aa.Inc_pdg != 2212 && aa.Inc_pdg != 2112)return wgt;
136  /*
137  if(aa.Inc_P < 12.0)return wgt;
138  if(aa.Vol == "TGT1" || aa.Vol == "BudalMonitor")return wgt;
139  if(aa.Prod_pdg != 211 && aa.Prod_pdg != -211 && aa.Prod_pdg !=321 && aa.Prod_pdg != -321 && aa.Prod_pdg !=310 && aa.Prod_pdg != 130)return wgt;
140  */
142  int bin = Thinbins->material_scaling_BinID(aa.xF,aa.Pt,aa.Prod_pdg);
143  bool is_data_based = (aa.Inc_P >= 12.0) && (aa.Vol != "TGT1" && aa.Vol != "BudalMonitor" && aa.Vol != "Budal_HFVS" && aa.Vol != "Budal_VFHS") &&
144  (aa.Prod_pdg == 211 || aa.Prod_pdg == -211 || aa.Prod_pdg ==321 || aa.Prod_pdg == -321 || aa.Prod_pdg ==310 || aa.Prod_pdg == 130) &&
145  (bin>=0);
146 
147  if((mode=="REF")||(mode=="OPT")){
148  is_data_based = (aa.Inc_P >= 12.0) && (aa.Vol != "TargetNoSplitSegment" && aa.Vol != "TargetFinHorizontal") && aa.Vol!= "tCoreLog" &&
149  (aa.Prod_pdg == 211 || aa.Prod_pdg == -211 || aa.Prod_pdg ==321 || aa.Prod_pdg == -321 || aa.Prod_pdg ==310 || aa.Prod_pdg == 130) &&
150  (bin>=0);
151  }
152  double inc_mom[3] = {aa.Inc_P4[0], aa.Inc_P4[1], aa.Inc_P4[2]};
153  double prod_mom[3] = {aa.Prod_P4[0],aa.Prod_P4[1],aa.Prod_P4[2]};
154  double vtx_int[3] = {aa.Vtx[0],aa.Vtx[1],aa.Vtx[2]};
155  std::string tgtent = "TGT1";
156  if((mode=="REF")||(mode=="OPT"))tgtent= "tCoreLog";//"TargetFinHorizontal";
157  InteractionData aux_aa2(aa.gen,inc_mom,aa.Inc_pdg,prod_mom,aa.Prod_pdg,tgtent,aa.Proc,vtx_int);
158 
159  bool not_handled = false;
160  if(is_data_based){
161 
163  double mc_prod = mc->getMCxs_pC_piK(0,aa.Inc_P);
164  double fact_gen0 = data_prod_xs/mc_prod;
166 
167  if(aa.Inc_pdg == 2212){
168 
169  if(aa.Prod_pdg == 211 || aa.Prod_pdg == -211){
170 
171  if(iUniv==-1)tt_pCPionRew = (makerew->cv_rw)->THINTARGET_PC_PION_Universe;
172  else tt_pCPionRew = (makerew->vec_rws[iUniv])->THINTARGET_PC_PION_Universe;
173 
174  if(tt_pCPionRew->canReweight(aux_aa2)){
175  wgt = tt_pCPionRew->calculateWeight(aux_aa2);
176  if(aux_aa2.gen == 0) wgt *= fact_gen0;
177  }
178  else not_handled = true;
179  }
180 
181  else if(aa.Prod_pdg == 321 || aa.Prod_pdg == -321 || aa.Prod_pdg == 130 || aa.Prod_pdg == 310){
182 
183  if(iUniv==-1)tt_pCKaonRew = (makerew->cv_rw)->THINTARGET_PC_KAON_Universe;
184  else tt_pCKaonRew = (makerew->vec_rws[iUniv])->THINTARGET_PC_KAON_Universe;
185 
186  if(tt_pCKaonRew->canReweight(aux_aa2)){
187  wgt = tt_pCKaonRew->calculateWeight(aux_aa2);
188  if(aux_aa2.gen == 0) wgt *= fact_gen0;
189  }
190  else not_handled = true;
191  }
192  else not_handled = true;
193  }
194  else if(aa.Inc_pdg == 2112){
195  if(aa.Prod_pdg == 211 || aa.Prod_pdg == -211){
196 
197  if(iUniv==-1)tt_nCPionRew = (makerew->cv_rw)->THINTARGET_NC_PION_Universe;
198  else tt_nCPionRew = (makerew->vec_rws[iUniv])->THINTARGET_NC_PION_Universe;
199 
200  if(tt_nCPionRew->canReweight(aux_aa2)){
201  wgt = tt_nCPionRew->calculateWeight(aux_aa2);
202  if(aux_aa2.gen == 0) wgt *= fact_gen0;
203  }
204  else not_handled = true;
205  }
206  else not_handled = true;
207  }
208  else not_handled = true;
209 
210  double scaling = 1.0;
211  if(aa.Prod_pdg == 211)scaling = vbin_data_pip[bin];
212  if(aa.Prod_pdg ==-211)scaling = vbin_data_pim[bin];
213  if(aa.Prod_pdg == 321)scaling = vbin_data_kap[bin];
214  if(aa.Prod_pdg ==-321)scaling = vbin_data_kam[bin];
215  if(aa.Prod_pdg == 310 || aa.Prod_pdg == 130)scaling = vbin_data_kap[bin];
216  wgt *= scaling;
217  if(!not_handled)return wgt;
218  }
219 
220  //trick... using a function for meson incident... same binning.
221  int binnu = Thinbins->meson_inc_BinID(aa.xF,aa.Pt,211);
222  if(binnu<0)return 1.0;
223 
224  if(aa.Inc_pdg ==2212){
225  if(aa.Prod_pdg == 211) wgt = vbin_prt_inc_pip[binnu];
226  else if(aa.Prod_pdg ==-211) wgt = vbin_prt_inc_pim[binnu];
227  else if(aa.Prod_pdg == 321) wgt = vbin_prt_inc_kap[binnu];
228  else if(aa.Prod_pdg ==-321) wgt = vbin_prt_inc_kam[binnu];
229  else if(aa.Prod_pdg ==130 || aa.Prod_pdg ==310) wgt = vbin_prt_inc_k0[binnu];
230  else if(aa.Prod_pdg ==2212) wgt = vbin_prt_inc_p[binnu];
231  else if(aa.Prod_pdg ==2112) wgt = vbin_prt_inc_n[binnu];
232  else wgt = bin_prtleftover_inc;
233  }
234  else if(aa.Inc_pdg ==2112){
235  if(aa.Prod_pdg == 211) wgt = vbin_neu_inc_pip[binnu];
236  else if(aa.Prod_pdg ==-211) wgt = vbin_neu_inc_pim[binnu];
237  else if(aa.Prod_pdg == 321) wgt = vbin_neu_inc_kap[binnu];
238  else if(aa.Prod_pdg ==-321) wgt = vbin_neu_inc_kam[binnu];
239  else if(aa.Prod_pdg ==130 || aa.Prod_pdg ==310) wgt = vbin_neu_inc_k0[binnu];
240  else if(aa.Prod_pdg ==2212) wgt = vbin_neu_inc_p[binnu];
241  else if(aa.Prod_pdg ==2112) wgt = vbin_neu_inc_n[binnu];
242  else wgt = bin_neuleftover_inc;
243  }
244 
245  return wgt;
246 
247  }
248 
249 
250 }
A class to manage the bin definitions for MIPP Numi Yields.
A list/table of parameter names and values.
virtual double calculateWeight(const InteractionData &aa)
calculate a weight for this interaction given the central value parameters and the parameters for thi...
A class to make the reweight event by event.
Definition: MakeReweight.h:32
std::string string
Definition: nybbler.cc:12
virtual double calculateWeight(const InteractionData &aa)
calculate a weight for this interaction given the central value parameters and the parameters for thi...
int Prod_pdg
pdg code of the produced particle
static MakeReweight * getInstance()
double Pt
Transversal momentum (GeV/c) of the produced particle.
ThinTargetnucleonAReweighter(int iuniv, const ParameterTable &cv_pars, const ParameterTable &univ_pars)
double Vtx[3]
Location of the interaction.
double getParameterValue(const std::string &name) const
get the value of a parameter. throw an exception of a well defined type if we don&#39;t have it ...
The information about a hadronic interaction needed to calculate weights.
virtual bool canReweight(const InteractionData &aa)
can the particular instance of this class reweight this interaction?
double Inc_P4[4]
Momentum 4 vector of the incident particle, E=p[3].
double xF
Feynmann-x of the produced particle: .
virtual double calculateWeight(const InteractionData &aa)
calculate a weight for this interaction given the central value parameters and the parameters for thi...
virtual double calculateWeight(const InteractionData &inter_data)
calculate a weight for this interaction given the central value parameters and the parameters for thi...
A class to manage the MC value for thin target.
Definition: ThinTargetMC.h:14
int material_scaling_BinID(double xf, double pt, int pdgcode)
Return material scaling bin.
double Prod_P4[4]
Momentum 4 vector of the produced particle, E=p[3].
int meson_inc_BinID(double xf, double pt, int pdgcode)
Return Pion incident bin.
std::string getenv(std::string const &name)
Definition: getenv.cc:15
std::string Proc
Interaction process.
virtual bool canReweight(const InteractionData &aa)
can the particular instance of this class reweight this interaction?
double Inc_P
Momentum magnitude of the incident particle.
std::string Vol
Interaction volume.
virtual bool canReweight(const InteractionData &aa)
can the particular instance of this class reweight this interaction?
int Inc_pdg
pdg code of the incident particle
double getMCxs_pC_piK(int genid, double inc_mom)
Get the MC roduction cross-section pC->pi, K:
static ThinTargetBins * getInstance()
std::vector< ReweightDriver * > vec_rws
vector of Reweighter Drivers, one per universe
Definition: MakeReweight.h:65
QTextStream & bin(QTextStream &s)
virtual bool canReweight(const InteractionData &aa)
can the particular instance of this class reweight this interaction?
ReweightDriver * cv_rw
Reweighter Drivers for the central value.
Definition: MakeReweight.h:68
static ThinTargetMC * getInstance()