5 #include "CLHEP/Random/RandGaussQ.h" 7 #include "MakeReweight.h" 8 #include "cetlib/search_path.h" 9 #include "dk2nu/tree/dk2nu.h" 10 #include "dk2nu/tree/dkmeta.h" 32 NeutrinoFluxReweight::MakeReweight*
fPPFXrw;
49 fMode = pset.
get<std::string>(
"mode");
50 fHorn = pset.
get<std::string>(
"horn_curr");
51 fTarget = pset.
get<std::string>(
"target_config");
52 fSeed = pset.
get<
int>(
"random_seed", -1);
54 gSystem->Setenv(
"MODE", fPPFXMode.c_str());
56 fPPFXrw = NeutrinoFluxReweight::MakeReweight::getInstance();
57 std::cout <<
"PPFX instance " <<
fPPFXrw << std::endl;
59 std::string inputOptions;
60 std::string mode_file =
"inputs_" + fPPFXMode +
".xml";
61 cet::search_path sp(
"FW_SEARCH_PATH");
62 sp.find_file(mode_file, inputOptions);
64 if (fSeed != -1)
fPPFXrw->setBaseSeed(fSeed);
65 std::cout <<
"is PPFX setup : " <<
fPPFXrw->AlreadyInitialized() << std::endl;
66 std::cout <<
"Setting PPFX, inputs: " << inputOptions << std::endl;
67 std::cout <<
"Setting Horn Current Configuration to: " << fHorn << std::endl;
68 std::cout <<
"Setting Target Configuration to: " << fTarget << std::endl;
69 if (!(
fPPFXrw->AlreadyInitialized())) {
fPPFXrw->SetOptions(inputOptions); }
70 std::cout <<
"PPFX just set with mode: " << fPPFXMode << std::endl;
75 std::vector<std::vector<double>>
weight;
79 int nmctruth = 0, nmatched = 0;
82 std::vector<art::Handle<std::vector<bsim::Dk2Nu>>> dk2nus2 =
83 e.
getMany<std::vector<bsim::Dk2Nu>>();
84 for (
size_t dk2 = 0; dk2 < dk2nus2.size(); ++dk2) {
87 while ((flag = mcitr.
Next())) {
88 std::string label = mcitr.
GetLabel();
92 const bsim::Dk2Nu* pdk2nu = mcitr.
GetDk2Nu();
99 std::cout <<
"FluxWeightCalculator [" << std::setw(4) << ievt <<
"] " 100 <<
" label \"" << label <<
"\" MCTruth@ " << pmctruth <<
" Dk2Nu@ " << pdk2nu
103 if (!pdk2nu)
continue;
114 dkmeta_obj.horncfg =
fHorn;
115 (dkmeta_obj.vintnames).push_back(
"Index_Tar_In_Ancestry");
116 (dkmeta_obj.vintnames).push_back(
"Playlist");
117 bsim::DkMeta* tmp_dkmeta = &dkmeta_obj;
126 bsim::Dk2Nu* tmp_dk2nu =
const_cast<bsim::Dk2Nu*
>(pdk2nu);
128 fPPFXrw->calculateWeights(tmp_dk2nu, tmp_dkmeta);
131 std::cerr <<
"Failed to calcualte weight" << std::endl;
135 if (
fMode ==
"reweight") {
136 double ppfx_cv_wgt =
fPPFXrw->GetCVWeight();
137 std::vector<double> wvec = {ppfx_cv_wgt};
138 weight.push_back(wvec);
141 std::vector<double> vmipppion =
fPPFXrw->GetWeights(
"MIPPNumiPionYields");
142 std::vector<double> vmippkaon =
fPPFXrw->GetWeights(
"MIPPNumiKaonYields");
143 std::vector<double> vtgtatt =
fPPFXrw->GetWeights(
"TargetAttenuation");
144 std::vector<double> vabsorp =
fPPFXrw->GetWeights(
"TotalAbsorption");
145 std::vector<double> vttpcpion =
fPPFXrw->GetWeights(
"ThinTargetpCPion");
146 std::vector<double> vttpckaon =
fPPFXrw->GetWeights(
"ThinTargetpCKaon");
147 std::vector<double> vttpcnucleon =
fPPFXrw->GetWeights(
"ThinTargetpCNucleon");
148 std::vector<double> vttncpion =
fPPFXrw->GetWeights(
"ThinTargetnCPion");
149 std::vector<double> vttnucleona =
fPPFXrw->GetWeights(
"ThinTargetnucleonA");
150 std::vector<double> vttmesoninc =
fPPFXrw->GetWeights(
"ThinTargetMesonIncident");
151 std::vector<double> vothers =
fPPFXrw->GetWeights(
"Other");
153 std::vector<double> tmp_vhptot;
154 for (
unsigned int iuniv = 0; iuniv < vtgtatt.size(); iuniv++) {
155 tmp_vhptot.push_back(
float(vmipppion[iuniv] * vmippkaon[iuniv] * vtgtatt[iuniv] *
156 vabsorp[iuniv] * vttpcpion[iuniv] * vttpckaon[iuniv] *
157 vttpcnucleon[iuniv] * vttncpion[iuniv] * vttnucleona[iuniv] *
158 vttmesoninc[iuniv] * vothers[iuniv]));
160 weight.push_back(tmp_vhptot);
const simb::MCTruth * GetMCTruth() const
void Configure(fhicl::ParameterSet const &p, CLHEP::HepRandomEngine &engine) override
std::vector< std::vector< double > > GetWeight(art::Event &e) override
#define DECLARE_WEIGHTCALC(wghcalc)
T get(std::string const &key) const
std::vector< std::string > fInputLabels
std::string fGenieModuleLabel
NeutrinoFluxReweight::MakeReweight * fPPFXrw
Event generator information.
std::string GetLabel() const
const bsim::Dk2Nu * GetDk2Nu() const
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
#define REGISTER_WEIGHTCALC(wghcalc)