108int main(
int argc,
char ** argv)
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;
176 const int n_params = (
const int) (
gOptKmaxInc + 1);
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";
430 assert(sigrange.size() == (
unsigned int) 2*
gOptKmaxInc);
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";
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);
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...