53 #include "EVGCore/EventRecord.h" 58 #include "ReWeight/GReWeightI.h" 59 #include "ReWeight/GSystSet.h" 60 #include "ReWeight/GReWeight.h" 61 #include "ReWeight/GReWeightNuXSecCCQE.h" 62 #include "ReWeight/GReWeightNuXSecCCQEvec.h" 63 #include "ReWeight/GReWeightNuXSecCCRES.h" 64 #include "ReWeight/GReWeightNuXSecNCRES.h" 65 #include "ReWeight/GReWeightNuXSecDIS.h" 66 #include "ReWeight/GReWeightNuXSecCOH.h" 67 #include "ReWeight/GReWeightNonResonanceBkg.h" 68 #include "ReWeight/GReWeightFGM.h" 69 #include "ReWeight/GReWeightDISNuclMod.h" 70 #include "ReWeight/GReWeightResonanceDecay.h" 71 #include "ReWeight/GReWeightFZone.h" 72 #include "ReWeight/GReWeightINuke.h" 73 #include "ReWeight/GReWeightAGKY.h" 74 #include "ReWeight/GSystUncertainty.h" 81 using namespace genie;
84 using std::ostringstream;
87 void GetEventRange (Long64_t nev_in_file, Long64_t & nfirst, Long64_t & nlast);
91 float* twkvals, GSystSet& syst);
116 tree = dynamic_cast <TTree *> (
file.Get(
"gtree") );
118 LOG(
"rwghtzexpaxff",
pNOTICE) <<
"Input tree header: " << *thdr;
121 <<
"Can't find a GHEP tree in input file: "<<
file.GetName();
127 tree->SetBranchAddress(
"gmcrec", &mcrec);
129 Long64_t nev_in_file = tree->GetEntries();
133 int nev =
int(nlast - nfirst + 1);
135 LOG(
"rwghtzexpaxff",
pNOTICE) <<
"Will process " << nev <<
" events";
146 rw.AdoptWghtCalc(
"xsec_ccqe",
new GReWeightNuXSecCCQE );
160 GSystSet & syst = rw.Systematics();
163 GReWeightNuXSecCCQE * rwccqe =
164 dynamic_cast<GReWeightNuXSecCCQE *
> (rw.WghtCalc(
"xsec_ccqe"));
165 rwccqe->SetMode(GReWeightNuXSecCCQE::kModeZExp);
167 GSystUncertainty * unc = GSystUncertainty::Instance();
175 const int n_events = (
const int) nev;
182 float weights [n_events][n_points];
183 float twkvals [n_points][n_params];
186 for (
int ipt = 0; ipt < n_points; ipt++)
188 for (
int iev = 0; iev < nev; iev++) { weights[iev][ipt] = 1.; }
190 for (
int ipr = 1; ipr < n_params; ipr++)
192 twkvals[ipt][ipr] = (
gOptNTweaks[ipr-1] > 1 ? -1 : 0);
199 syst.Set(kXSecTwkDial_ZNormCCQE, twkvals[0][0]);
200 LOG(
"rwghtzexpaxff",
pNOTICE) <<
"Setting z-expansion tweak for norm : " 204 for (
int ipr = 1; ipr < n_params; ipr++)
207 syst.Set(gsyst, twkvals[0][ipr]);
208 LOG(
"rwghtzexpaxff",
pNOTICE) <<
"Setting z-expansion tweak for param " 209 <<ipr<<
" : " << twkvals[0][ipr];
213 LOG(
"rwghtzexpaxff",
pNOTICE) <<
"Setting z-expansion sigma for param " 219 for (
int ipt = 0; ipt < n_points; ipt++) {
222 for(
int iev = nfirst; iev <= nlast; iev++) {
226 LOG(
"rwghtzexpaxff",
pNOTICE) <<
"Event number = " << iev;
229 double wght = rw.CalcWeight(
event);
231 LOG(
"rwghtzexpaxff",
pNOTICE) <<
"Overall weight = " << wght;
234 weights[iev - nfirst][ipt] = wght;
240 if (ipt < n_points-1) {
241 for (
int ipr=0;ipr<n_params;ipr++)
243 twkvals[ipt+1][ipr] = twkvals[ipt][ipr];
246 twkvals[ipt+1],syst);
259 TTree * wght_tree =
new TTree(
"ZExpCCQE",
"GENIE weights tree");
261 int branch_eventnum = 0;
262 TArrayF * branch_weight_array =
new TArrayF(n_points);
263 TArrayF ** branch_twkdials_array =
new TArrayF* [n_params];
265 wght_tree->Branch(
"eventnum", &branch_eventnum);
266 wght_tree->Branch(
"weights", &branch_weight_array);
269 ostringstream twk_dial_brnch_name;
270 for (
int ipr = 0; ipr < n_params; ipr++) {
272 twk_dial_brnch_name.str(
"");
273 if (ipr == 0) { twk_dial_brnch_name <<
"twk_dial_param_norm"; }
274 else { twk_dial_brnch_name <<
"twk_dial_param_" << ipr; }
275 LOG(
"rwghtzexpaxff",
pWARN) <<
"Branch name = " << twk_dial_brnch_name.str();
276 branch_twkdials_array[ipr] =
new TArrayF(n_points);
277 wght_tree->Branch(twk_dial_brnch_name.str().c_str(), branch_twkdials_array[ipr]);
280 ostringstream str_wght;
281 for(
int iev = nfirst; iev <= nlast; iev++) {
282 branch_eventnum = iev;
284 for(
int ipt = 0; ipt < n_points; ipt++){
288 str_wght <<
", tweaked parameter values : ";
289 for (
int ipr = 0; ipr < n_params; ipr++) {
290 if (ipr > 0) str_wght <<
", ";
291 str_wght << ipr <<
" -> " << twkvals[ipt][ipr];
294 <<
"Filling tree with wght = " << weights[iev - nfirst][ipt] << str_wght.str();
297 branch_weight_array -> AddAt (weights [iev - nfirst][ipt], ipt);
298 for (
int ipr = (
gOptDoNorm ? 0 : 1); ipr < n_params; ipr++)
299 { branch_twkdials_array[ipr] -> AddAt (twkvals[ipt][ipr], ipt); }
313 for (
int ipr = 0; ipr < n_params; ipr++) {
315 delete branch_twkdials_array[ipr];
317 delete branch_twkdials_array;
318 delete branch_weight_array;
326 LOG(
"rwghtzexpaxff",
pINFO) <<
"*** Parsing command line arguments";
332 LOG(
"rwghtzexpaxff",
pINFO) <<
"Reading event sample filename";
336 <<
"Unspecified input filename - Exiting";
343 LOG(
"rwghtzexpaxff",
pINFO) <<
"Reading requested output filename";
346 LOG(
"rwghtzexpaxff",
pINFO) <<
"Setting default output filename";
352 LOG(
"grwghtzexpaxff",
pINFO) <<
"Reading number of events to analyze";
354 if (nev.find(
",") != string::npos) {
357 LOG(
"grwghtzexpaxff",
pFATAL) <<
"Invalid syntax";
374 <<
"Unspecified number of events to analyze - Use all";
383 LOG(
"rwghtzexpaxff",
pINFO) <<
"Reading number of tweaks";
392 <<
"Too many coefficients: increase MAX_COEF in source code and recompile";
413 LOG(
"rwghtzexpaxff",
pINFO)<<
"Number of tweaks on coefficient "<<ik+1<<
" : "<<
gOptNTweaks[ik];
417 <<
"Unspecified tweaks for parameters - Exiting";
424 LOG(
"rwghtzexpaxff",
pINFO) <<
"Reading specified parameter uncertainties";
434 gOptSigMin[ik] = atof(sigrange[ik*2 ].c_str());
435 gOptSigMax[ik] = atof(sigrange[ik*2+1].c_str());
445 LOG(
"rwghtzexpaxff",
pINFO) <<
"Reading number of tweaks on normalization";
453 void GetEventRange(Long64_t nev_in_file, Long64_t & nfirst, Long64_t & nlast)
463 nlast = TMath::Min(nev_in_file-1,
gOptNEvt2);
466 if(gOptNEvt1<0 && gOptNEvt2>=0) {
471 nlast = TMath::Min(nev_in_file-1,
gOptNEvt2-1);
477 nlast = nev_in_file-1;
480 assert(nfirst <= nlast && nfirst >= 0 && nlast <= nev_in_file-1);
484 float* twkvals, GSystSet& syst)
486 if (kmaxinc < 2 && ! donorm)
488 LOG(
"grwghtzexpaxff",
pERROR) <<
"No coefficients to increment";
493 bool stopflag =
false;
494 GSyst_t gsyst = kXSecTwkDial_ZNormCCQE;
497 if (ip > 0 || (ip == 0 && donorm))
499 if (ip == 0) { twkvals[0 ] = (normtwk > 1 ? -1. : 0.); }
500 else { twkvals[ip] = (ntwk[ip-1] > 1 ? -1. : 0.); }
503 syst.Set(gsyst, twkvals[ip]);
504 LOG(
"rwghtzexpaxff",
pNOTICE) <<
"Setting z-expansion tweak for param " 505 <<ip<<
" : " << twkvals[ip];
510 if (ip == kmaxinc) {
return false; }
511 if (ip == 0 && ! donorm)
517 if (ip == 0) { gsyst = kXSecTwkDial_ZNormCCQE; }
523 if (normtwk > 1) { twkvals[0] += 2./
float(normtwk-1); }
524 else { stopflag =
false;
continue; }
528 if (ntwk[ip-1] > 1) { twkvals[ip] += 2./
float(ntwk[ip-1]-1); }
529 else { stopflag =
false;
continue; }
534 syst.Set(gsyst, twkvals[ip]);
535 LOG(
"rwghtzexpaxff",
pNOTICE) <<
"Setting z-expansion tweak for param " 536 <<ip<<
" : " << twkvals[ip];
539 }
while (! stopflag);
550 for (
int i=0;i<kmaxinc;i++)
552 if (ntwk[i] > 1) num_pts *= ntwk[i];
556 if (normtwk > 1) num_pts *= normtwk;
564 case 1:
return kXSecTwkDial_ZExpA1CCQE;
break;
565 case 2:
return kXSecTwkDial_ZExpA2CCQE;
break;
566 case 3:
return kXSecTwkDial_ZExpA3CCQE;
break;
567 case 4:
return kXSecTwkDial_ZExpA4CCQE;
break;
570 <<
"Cannot find systematic corresponding to parameter " << ip;
580 <<
"grwghtzexpaxff \n" 581 <<
" -f input_event_file \n" 582 <<
" -t ntwk1[,ntwk2[,...]] \n" 584 <<
" [-s sigLo1,sigHi1[,...]] \n" 585 <<
" [-o output_weights_file] \n" 586 <<
" [-m ntwkNorm]" ;
GSyst_t GetZExpSystematic(int ip)
string ArgAsString(char opt)
THE MAIN GENIE PROJECT NAMESPACE
float gOptSigMax[MAX_COEF]
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.
vector< long > ArgAsLongTokens(char opt, string delimeter)
float gOptSigMin[MAX_COEF]
void GetEventRange(Long64_t nev_in_file, Long64_t &nfirst, Long64_t &nlast)
int gOptNTweaks[MAX_COEF]
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
int GetNumberOfWeights(int *ntwk, int kmaxinc, int normtwk, bool donorm)
static const double kASmallNum
void GetCommandLineArgs(int argc, char **argv)
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
bool IncrementCoefficients(int *ntwk, int kmaxinc, int normtwk, bool donorm, float *twkvals, GSystSet &syst)
vector< string > Split(string input, string delim)
int main(int argc, char **argv)
Command line argument parser.
void Clear(Option_t *opt="")
bool OptionExists(char opt)
was option set?
Event finding and building.
#define MAX_COEF
A simple program to illustrate how to use the GENIE event reweighting for use with the z-expansion ax...