109 using namespace genie;
113 using std::stringstream;
116 void GetEventRange (Long64_t nev_in_file, Long64_t & nfirst, Long64_t & nlast);
143 tree = dynamic_cast <TTree *> ( file.Get(
"gtree") );
147 <<
"Can't find a GHEP tree in input file: "<< file.GetName();
152 LOG(
"grwghtnp",
pNOTICE) <<
"Input tree header: " << *thdr;
155 LOG(
"grwghtnp",
pFATAL) <<
"Error: conflicting systematics";
173 TMatrixD *cmat = NULL;
185 tree->SetBranchAddress(
"gmcrec", &mcrec);
187 Long64_t nev_in_file = tree->GetEntries();
191 int nev =
int(nlast - nfirst + 1);
193 LOG(
"grwghtnp",
pNOTICE) <<
"Will process " << nev <<
" events";
223 TVectorD twkvals(n_params);
226 for (
int ipr = 0; ipr < n_params; ipr++) { twkvals(ipr) = 0.; }
229 int branch_eventnum = 0;
230 double branch_weight = 0.;
234 stringstream twk_dial_brnch_name;
235 stringstream tmpName;
242 TFile * wght_file = NULL;
243 TTree * wght_tree = NULL;
244 for (
int itk = 0; itk <
gOptNTwk; itk++) {
249 tmpName <<
"_temporary_rwght." <<itk <<
"." <<
gOptRunKey <<
".root";
250 LOG(
"grwghtnp",
pINFO) <<
"temporary file: " <<tmpName.str();
251 wght_file =
new TFile(tmpName.str().c_str(),
"RECREATE");
252 wght_tree =
new TTree(
"covrwt",
"GENIE weights tree");
255 wght_tree->Branch(
"eventnum", &branch_eventnum);
256 wght_tree->Branch(
"weights", &branch_weight);
264 for (it = gOptVSyst.begin();it != gOptVSyst.end(); it++, ip++) {
265 twk_dial_brnch_name.str(
"");
268 wght_tree->Branch(twk_dial_brnch_name.str().c_str(), &twkvals(ip));
271 syst.
Set(*it,twkvals(ip));
275 stringstream str_wght;
277 str_wght <<
", parameter tweaks : ";
278 for (
int ipr=0; ipr < n_params; ipr++) {
279 if (ipr > 0) str_wght <<
", ";
280 str_wght << ipr <<
" -> " << twkvals(ipr);
283 for(
int iev = nfirst; iev <= nlast; iev++) {
284 branch_eventnum = iev;
288 LOG(
"rwghtzexpaxff",
pNOTICE) <<
"Event_num => " << iev;
313 wght_tree =
new TTree(
"covrwt",
"GENIE covariant reweighting tree");
314 wght_tree->Branch(
"n_tweaks", &gOptNTwk);
315 wght_tree->Branch(
"eventnum", &branch_eventnum);
316 TFile * file_list[n_tweaks];
317 TTree * wght_list[n_tweaks];
318 for (
int itk=0; itk < n_tweaks; itk++) {
320 tmpName <<
"_temporary_rwght." <<itk <<
"." <<
gOptRunKey <<
".root";
321 file_list[itk] =
new TFile(tmpName.str().c_str(),
"READ");
322 wght_list[itk] = (TTree*)file_list[itk]->Get(
"covrwt");
326 TArrayD branch_weights_array(gOptNTwk);
327 double * branch_weights_ptr = branch_weights_array.GetArray();
328 TArrayD * branch_twkdials_array[n_params];
329 double * branch_twkdials_ptr [n_params];
332 wght_tree->Branch(
"weights", &branch_weights_array);
333 for (
int itk = 0; itk <
gOptNTwk; itk++) {
334 wght_list[itk]->SetBranchAddress(
"weights",&branch_weights_ptr[itk]);
338 for (it = gOptVSyst.begin();it != gOptVSyst.end(); it++, ip++) {
339 twk_dial_brnch_name.str(
"");
343 branch_twkdials_array[ip] =
new TArrayD(gOptNTwk);
344 branch_twkdials_ptr[ip] = branch_twkdials_array[ip]->GetArray();
347 wght_tree->Branch(twk_dial_brnch_name.str().c_str(), branch_twkdials_array[ip]);
348 LOG(
"grwghtnp",
pINFO) <<
"Creating tweak branch : " << twk_dial_brnch_name.str();
351 for (
int i=0;
i < n_tweaks;
i++) {
352 wght_list[
i]->SetBranchAddress(twk_dial_brnch_name.str().c_str(),&branch_twkdials_ptr[ip][
i]);
362 for(
int iev = nfirst; iev <= nlast; iev++) {
363 branch_eventnum = iev;
364 for (
int itk = 0; itk < n_tweaks; itk++) {
365 wght_list[itk]->GetEntry(iev);
377 for (
int itk = 0; itk <
gOptNTwk; itk++) {
379 tmpName <<
"_temporary_rwght." <<itk <<
"." <<
gOptRunKey <<
".root";
380 if(
remove(tmpName.str().c_str()) != 0 )
381 {
LOG(
"grwghtnp",
pWARN) <<
"Could not delete temporary file : " << tmpName.str(); }
391 for (
int ipr = 0; ipr < n_params; ipr++) {
392 delete branch_twkdials_array[ipr];
401 LOG(
"grwghtnp",
pINFO) <<
"*** Parsing command line arguments";
407 LOG(
"grwghtnp",
pINFO) <<
"Reading event sample filename";
411 <<
"Unspecified input filename - Exiting";
418 LOG(
"grwghtnp",
pINFO) <<
"Reading covariance matrix filename";
422 <<
"Unspecified covariance filename - Exiting";
429 LOG(
"grwghtnp",
pINFO) <<
"Reading requested output filename";
432 LOG(
"grwghtnp",
pINFO) <<
"Setting default output filename";
438 LOG(
"grwghtnp",
pINFO) <<
"Reading number of events to analyze";
440 if (nev.find(
",") != string::npos) {
443 LOG(
"grwghtnp",
pFATAL) <<
"Invalid syntax";
460 <<
"Unspecified number of events to analyze - Use all";
469 LOG(
"grwghtnp",
pINFO) <<
"Reading systematics";
474 for(it=lsyst.begin();it != lsyst.end();it++,ik++)
477 LOG(
"grwghtnp",
pINFO)<<
"Read systematic "<<ik+1<<
" : "<< lsyst[ik];
484 <<
"Unspecified systematics - Exiting";
491 LOG(
"grwghtnp",
pINFO) <<
"Reading parameter central values";
494 if (
gOptNSyst != (
int)gOptVCentVal.size()) {
496 <<
"Number of systematic central values does not match number of systematics- Exiting";
502 <<
"Unspecified systematic central values - Exiting";
509 LOG(
"grwghtnp",
pINFO) <<
"Reading number of tweaks";
514 LOG(
"grwghtnp",
pFATAL) <<
"Must have at least 1 tweak - Exiting";
521 <<
"Unspecified tweaks for parameters - Exiting";
528 LOG(
"grwghtnp",
pINFO) <<
"Reading run key";
537 void GetEventRange(Long64_t nev_in_file, Long64_t & nfirst, Long64_t & nlast)
547 nlast = TMath::Min(nev_in_file-1,
gOptNEvt2);
550 if(gOptNEvt1<0 && gOptNEvt2>=0) {
555 nlast = TMath::Min(nev_in_file-1,
gOptNEvt2-1);
561 nlast = nev_in_file-1;
564 assert(nfirst <= nlast && nfirst >= 0 && nlast <= nev_in_file-1);
580 TFile * fin =
new TFile(fname.c_str(),
"READ");
582 TMatrixD * inmat =
new TMatrixD();
583 if(cmat) {
delete cmat; }
586 TIter next(fin->GetListOfKeys());
587 fkey = (TKey *)next();
593 LOG(
"grwghtnp",
pFATAL) <<
"Error reading covariance matrix - Exiting";
597 if (inmat->GetNrows() != inmat->GetNcols()) {
598 LOG(
"grwghtnp",
pFATAL) <<
"Covariance matrix not square - Exiting";
603 LOG(
"grwghtnp",
pFATAL) <<
"Number of systematics does not match covariance matrix size- Exiting";
609 TMatrixD tmpmat = TMatrixD(*inmat);
615 itd = gOptVCentVal.begin();
616 for (it = gOptVSyst.begin();it != gOptVSyst.end(); it++, itd++, i++) {
617 for(
int j=0;j<tmpmat.GetNcols();j++){
618 if(i!=j) { tmpmat(i,j) = 0.; }
624 TMath::Sqrt(tmpmat(i,i))/(*itd));
625 tmpmat(i,i) = 1./TMath::Sqrt(tmpmat(i,i));
633 TMatrixD sigmat = TMatrixD(tmpmat);
634 tmpmat = TMatrixD(*inmat,TMatrixD::kMult,sigmat);
635 cmat =
new TMatrixD(sigmat,TMatrixD::kMult,tmpmat);
683 for(it0=lsyst.begin();it0 != lsyst.end();it0++)
688 for(it1=it0;it1 != lsyst.end();it1++){
689 for(
int i=0;
i<2;
i++){
if(ccqe_ma_shp_norm[
i] == *it1)
return false; }
690 for(
int i=0;
i<5;
i++){
if(ccqe_z_shp[
i] == *it1)
return false; }
693 case kXSecTwkDial_MaCCQEshape:
694 for(it1=it0;it1 != lsyst.end();it1++){
695 for(
int i=0;
i<1;
i++){
if(ccqe_ma_shp[
i] == *it1)
return false; }
696 for(
int i=0;
i<5;
i++){
if(ccqe_z_shp[
i] == *it1)
return false; }
703 case kXSecTwkDial_ZExpA4CCQE:
704 for(it1=it0;it1 != lsyst.end();it1++){
705 for(
int i=0;
i<1;
i++){
if(ccqe_ma_shp[
i] == *it1)
return false; }
706 for(
int i=0;
i<2;
i++){
if(ccqe_ma_shp_norm[
i] == *it1)
return false; }
711 case kXSecTwkDial_MvCCRES:
712 for(it1=it0;it1 != lsyst.end();it1++){
713 for(
int i=0;
i<3;
i++){
if(ccres_shp_norm[
i] == *it1)
return false; }
718 case kXSecTwkDial_MvCCRESshape:
719 for(it1=it0;it1 != lsyst.end();it1++){
720 for(
int i=0;
i<2;
i++){
if(ccres_shp[
i] == *it1)
return false; }
727 case kXSecTwkDial_CV2uBYshape:
728 for(it1=it0;it1 != lsyst.end();it1++){
729 for(
int i=0;
i<4;
i++){
if(dis_shp_norm[
i] == *it1)
return false; }
735 case kXSecTwkDial_CV2uBY:
736 for(it1=it0;it1 != lsyst.end();it1++){
737 for(
int i=0;
i<4;
i++){
if(dis_shp[
i] == *it1)
return false; }
742 case kXSecTwkDial_MvNCRES:
743 for(it1=it0;it1 != lsyst.end();it1++){
744 for(
int i=0;
i<3;
i++){
if(ncres_shp_norm[
i] == *it1)
return false; }
749 case kXSecTwkDial_MvNCRESshape:
750 for(it1=it0;it1 != lsyst.end();it1++){
751 for(
int i=0;
i<2;
i++){
if(ncres_shp[
i] == *it1)
return false; }
770 for(it=lsyst.begin();it != lsyst.end();it++)
778 LOG(
"grwghtnp",
pNOTICE) <<
"Adopting xsec_ccqe weight calc";
783 rwccqe->
SetMode(GReWeightNuXSecCCQE::kModeMa); }
784 else { rwccqe->
SetMode(GReWeightNuXSecCCQE::kModeNormAndMaShape); }
793 LOG(
"grwghtnp",
pNOTICE) <<
"Adopting xsec_ccqe weight calc";
797 rwccqe->
SetMode(GReWeightNuXSecCCQE::kModeZExp);
804 LOG(
"grwghtnp",
pNOTICE) <<
"Adopting xsec_ccres weight calc";
808 rwccres->
SetMode(GReWeightNuXSecCCRES::kModeMaMv);
815 LOG(
"grwghtnp",
pNOTICE) <<
"Adopting xsec_ccres weight calc";
819 rwccres->
SetMode(GReWeightNuXSecCCRES::kModeNormAndMaMvShape);
828 LOG(
"grwghtnp",
pNOTICE) <<
"Adopting xsec_dis weight calc";
832 rwdis->
SetMode(GReWeightNuXSecDIS::kModeABCV12uShape);
840 LOG(
"grwghtnp",
pNOTICE) <<
"Adopting xsec_dis weight calc";
844 rwdis->
SetMode(GReWeightNuXSecDIS::kModeABCV12u);
851 LOG(
"grwghtnp",
pNOTICE) <<
"Adopting xsec_ncres weight calc";
855 rwncres->
SetMode(GReWeightNuXSecNCRES::kModeMaMv);
862 LOG(
"grwghtnp",
pNOTICE) <<
"Adopting xsec_ncres weight calc";
866 rwncres->
SetMode(GReWeightNuXSecNCRES::kModeNormAndMaMvShape);
880 <<
" -f input_event_file \n" 881 <<
" -c input_covariance_file\n" 883 <<
" -s syst1[,syst2[,...]] \n" 884 <<
" -v cval1[,cval2[,...]] \n" 885 <<
" [-n n1[,n2]] \n" 886 <<
" [-r run_key] \n" 887 <<
" [-o output_weights_file]";
Reweighting GENIE DIS neutrino-nucleus cross sections.
tweak Mv CCRES, affects d2sigma(CCRES)/dWdQ2 both in shape and normalization
tweak Z-expansion coefficient 1, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Resonance_t FromString(const char *res)
string -> resonance id
tweak Mv CCRES, affects d2sigma(CCRES)/dWdQ2 in shape only (normalized to constant integral) ...
string ArgAsString(char opt)
#include "Numerical/GSFunc.h"
MINOS-style ntuple record. Each such ntuple record holds a generated EventRecord object. Ntuples of this type are intended for feeding GENIE events into other applications (for example the GEANT4 based MC generation framework of an experiment) if no direct interface exists.
Reweighting CCQE GENIE neutrino cross sections.
tweak CCQE normalization (energy independent)
vector< long > ArgAsLongTokens(char opt, string delimeter)
tweak the Bodek-Yang model parameter B_{ht} - shape only effect to d2sigma(DIS)/dxdy ...
Reweight GENIE NC resonance neutrino-production cross section. Basically a clone of the corresponding...
std::string AsString(TrkPoint_t trkpt)
void SetUncertainty(GSyst_t syst, double plus_err, double minus_err)
void Reconfigure(void)
reconfigure weight calculators with new params
Simple mathematical utilities not found in ROOT's TMath.
TMatrixD CholeskyDecomposition(const TMatrixD &cov)
GReWeightI * WghtCalc(string name)
access a weight calculator by name
void Set(GSyst_t syst, double current_value)
tweak Z-expansion coefficient 4, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
tweak Z-expansion coefficient 3, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
vector< double > ArgAsDoubleTokens(char opt, string delimeter)
tweak the Bodek-Yang model parameter CV2u - incl. both shape and normalization effect ...
tweak Z-expansion coefficient 2, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
tweak Z-expansion CCQE normalization (energy independent)
An enumeration of systematic parameters.
void AdoptWghtCalc(string name, GReWeightI *wcalc)
add concrete weight calculator, transfers ownership
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
tweak CCRES normalization
tweak Mv NCRES, affects d2sigma(NCRES)/dWdQ2 both in shape and normalization
tweak the Bodek-Yang model parameter A_{ht} - incl. both shape and normalization effect ...
tweak the Bodek-Yang model parameter A_{ht} - shape only effect to d2sigma(DIS)/dxdy ...
vector< string > Split(string input, string delim)
tweak Ma CCRES, affects d2sigma(CCRES)/dWdQ2 both in shape and normalization
tweak NCRES normalization
tweak Ma CCQE, affects dsigma(CCQE)/dQ2 both in shape and normalization
tweak the Bodek-Yang model parameter CV1u - shape only effect to d2sigma(DIS)/dxdy ...
tweak Ma CCRES, affects d2sigma(CCRES)/dWdQ2 in shape only (normalized to constant integral) ...
double CalcWeight(const genie::EventRecord &event)
calculate weight for input event
TVectorD CholeskyGenerateCorrelatedParamVariations(const TMatrixD &Lch)
tweak the Bodek-Yang model parameter CV1u - incl. both shape and normalization effect ...
Reweight GENIE CC resonance neutrino-production.
Command line argument parser.
tweak Ma NCRES, affects d2sigma(NCRES)/dWdQ2 in shape only (normalized to constant integral) ...
GSystSet & Systematics(void)
set of enabled systematic params & values
void Clear(Option_t *opt="")
tweak Mv NCRES, affects d2sigma(NCRES)/dWdQ2 in shape only (normalized to constant integral) ...
tweak the Bodek-Yang model parameter CV2u - shape only effect to d2sigma(DIS)/dxdy ...
Set of systematics to be considered by the reweighting package.
tweak Ma CCQE, affects dsigma(CCQE)/dQ2 in shape only (normalized to constant integral) ...
bool OptionExists(char opt)
was option set?
Interface to the GENIE event reweighting engines.
Event finding and building.
tweak the Bodek-Yang model parameter B_{ht} - incl. both shape and normalization effect ...
tweak Ma NCRES, affects d2sigma(NCRES)/dWdQ2 both in shape and normalization