16 const fhicl::ParameterSet& pset =
p.get<fhicl::ParameterSet>(
GetName());
21 auto const& pars = pset.get<std::vector<std::string> >(
"parameter_list");
22 std::vector< float > parsigmas(pars.size(), 1.0);
23 if (pars.size() != parsigmas.size()) {
24 throw cet::exception(__PRETTY_FUNCTION__) <<
GetName() <<
": "
25 <<
"parameter_list and parameter_sigma length mismatch."
29 if(!pset.get_if_present(
"parameter_sigma", parsigmas)){
30 std::cout<<
"SBNEventWeight Flux: `parameter_sigma` was not set; now it is set as 1"<<std::endl;
33 std::string
fMode = pset.get<std::string>(
"mode");
34 int number_of_multisims = pset.get<
int>(
"number_of_multisims", 1);
37 for (
size_t i=0; i<pars.size(); i++) {
44 CalcType = pset.get< std::string >(
"calc_type");
47 fScalePos = pset.get<
double>(
"scale_factor_pos");
48 if(!pset.get_if_present(
"scale_factor_neg",
fScaleNeg)){
49 std::cout<<
"SBNEventWeight Flux: auto-assignment: scale_factor_neg = 1."<<std::endl;
52 cet::search_path sp(
"FW_SEARCH_PATH");
64 std::string dataInput1 = pset.get< std::string >(
"CentralValue_hist_file");
65 std::string cvfile_path = sp.find_file(dataInput1);
66 TFile fcv(Form(
"%s",cvfile_path.c_str()));
68 std::string dataInput2pos = pset.get< std::string >(
"PositiveSystematicVariation_hist_file");
69 std::string rwfilepos = sp.find_file(dataInput2pos);
70 TFile frwpos(Form(
"%s", rwfilepos.c_str()));
72 std::string dataInput2neg = pset.get< std::string >(
"NegativeSystematicVariation_hist_file");
73 std::string rwfileneg = sp.find_file(dataInput2neg);
74 TFile frwneg(Form(
"%s", rwfileneg.c_str()));
76 if(dataInput2pos == dataInput2neg)
PosOnly =
true;
78 int cptype[4] = {1,2,3,4};
79 int cntype[4] = {1,2,3,4};
81 for (
int iptyp=0;iptyp<4;iptyp++) {
82 for (
int intyp=0;intyp<4;intyp++) {
83 for (
int ibin=0;ibin<200;ibin++) {
84 fCV[iptyp][intyp][ibin]=(
dynamic_cast<TH1F*
> (fcv.Get(Form(
"h5%d%d",cptype[iptyp],cntype[intyp]))))->GetBinContent(ibin+1);
85 fRWpos[iptyp][intyp][ibin]=(
dynamic_cast<TH1F*
> (frwpos.Get(Form(
"h5%d%d",cptype[iptyp],cntype[intyp]))))->GetBinContent(ibin+1);
86 fRWneg[iptyp][intyp][ibin]=(
dynamic_cast<TH1F*
> (frwneg.Get(Form(
"h5%d%d",cptype[iptyp],cntype[intyp]))))->GetBinContent(ibin+1);
97 }
else if(
CalcType.compare(0, 13,
"PrimaryHadron") == 0){
99 fprimaryHad = pset.get< std::vector<int>>(
"PrimaryHadronGeantCode");
101 if(
CalcType ==
"PrimaryHadronNormalization" ){
107 std::string dataInput = pset.get< std::string >(
"ExternalData");
108 std::string ExternalDataInput = sp.find_file(dataInput);
109 TFile*
file =
new TFile(Form(
"%s",ExternalDataInput.c_str()));
111 std::vector< std::string > pname;
112 if(
CalcType ==
"PrimaryHadronFeynmanScaling" ){
114 pname.push_back(
"FS/KPlus/FSKPlusFitVal");
115 pname.push_back(
"FS/KPlus/FSKPlusFitCov");
117 TArrayD* FSKPlusFitValArray = (TArrayD*) file->Get(pname[0].c_str());
119 FitCov = (TMatrixD*) file->Get(pname[1].c_str());
122 }
else if(
CalcType ==
"PrimaryHadronSanfordWang" ){
123 pname.push_back(
"SW/K0s/SWK0sFitVal");
124 pname.push_back(
"SW/K0s/SWK0sFitCov");
125 TArrayD* SWK0FitValArray = (TArrayD*) file->Get(pname[0].c_str());
128 FitCov = (TMatrixD*) file->Get(pname[1].c_str());
131 }
else if(
CalcType ==
"PrimaryHadronSWCentralSplineVariation" ){
133 std::string fitInput = pset.get< std::string >(
"ExternalFit");
134 std::string HadronName;
135 std::string HadronAbriviation;
137 HadronName =
"PiPlus";
138 HadronAbriviation =
"PP";
140 HadronName =
"PiMinus";
141 HadronAbriviation =
"PM";
143 throw art::Exception(art::errors::StdException)
144 <<
"sanford-wang is only configured for charged pions ";
146 pname.push_back( Form(
"HARPData/%s/%sCrossSection",HadronName.c_str(),HadronAbriviation.c_str()) );
147 pname.push_back( Form(
"HARPData/%s/%scovarianceMatrix",HadronName.c_str(),HadronAbriviation.c_str()) );
148 pname.push_back( Form(
"HARPData/%s/%smomentumBoundsArray",HadronName.c_str(),HadronAbriviation.c_str()) );
149 pname.push_back( Form(
"HARPData/%s/%sthetaBoundsArray",HadronName.c_str(),HadronAbriviation.c_str()) );
151 HARPXSec = (TMatrixD*) file->Get(pname[0].c_str());
152 TMatrixD* HARPCov = (TMatrixD*) file->Get(pname[1].c_str());
154 TDecompChol dc = TDecompChol(*(HARPCov));
156 throw art::Exception(art::errors::StdException)
157 <<
"Cannot decompose covariance matrix to begin smearing.";
163 FitCov =
new TMatrixD(dc.GetU());
166 TArrayD* HARPmomentumBoundsArray = (TArrayD*) file->Get(pname[2].c_str());
169 TArrayD* HARPthetaBoundsArray = (TArrayD*) file->Get(pname[3].c_str());
178 std::string ExternalFitInput = sp.find_file(fitInput);
179 TFile* Fitfile =
new TFile(Form(
"%s",ExternalFitInput.c_str()));
182 fitname = Form(
"SW/%s/SW%sFitVal",HadronName.c_str(),HadronName.c_str());
184 TArrayD* SWParamArray = (TArrayD*) Fitfile->Get(fitname.c_str());
188 }
else validC =
false;
193 for(
int index = 1; index < 2*(
FitCov->GetNcols()); index ++){
198 throw cet::exception(__PRETTY_FUNCTION__) <<
GetName() <<
": "
199 <<
" calculator "+
CalcType +
"is invalid"
206 }
else validC =
false;
void AddParameter(std::string name, float width, float mean=0, size_t covIndex=0)
EventWeightParameterSet fParameterSet
std::vector< double > FitVal
std::vector< double > HARPmomentumBounds
std::string fGeneratorModuleLabel
void Configure(std::string name, ReweightType rwtype, size_t nuni=1)
void Sample(CLHEP::HepRandomEngine &engine)
std::vector< double > SWParam
std::vector< double > ConvertToVector(TArrayD const *array)
std::vector< double > HARPthetaBounds
std::vector< int > fprimaryHad
BEGIN_PROLOG could also be cout
std::string GetFullName()