GReWeight.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2017, GENIE Neutrino MC Generator Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Authors: Jim Dobson <J.Dobson07 \at imperial.ac.uk>
8  Imperial College London
9 
10  Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
11  University of Liverpool & STFC Rutherford Appleton Lab
12 
13  For the class documentation see the corresponding header file.
14 
15  Important revisions after version 2.0.0 :
16  @ Aug 01, 2009 - CA
17  Was adapted from Jim's and Costas' T2K-specific GENIE reweighting code.
18  First included in v2.5.1.
19  @ May 18, 2010 - CA
20  AdoptWghtCalc(string,GReWeightI*) allows user to decide which weight
21  calculator to include. Weight calculators are owned by GReWeight and are
22  identified by a name. Weight calculators can be retrieved via the
23  WghtCalc(string) method and their reweighting options can be fine-tuned.
24 */
25 //____________________________________________________________________________
26 
27 #include <vector>
28 
29 #include <TMath.h>
30 #include <TString.h>
31 
32 #include "EVGCore/EventRecord.h"
33 #include "Messenger/Messenger.h"
34 #include "Utils/RunOpt.h"
35 #include "ReWeight/GReWeight.h"
36 
37 using std::vector;
38 
39 using namespace genie;
40 using namespace genie::rew;
41 
42 //____________________________________________________________________________
44 {
45  // Disable cacheing that interferes with event reweighting
47 }
48 //____________________________________________________________________________
50 {
51  this->CleanUp();
52 }
53 //____________________________________________________________________________
55 {
56  if(!wcalc) return;
57 
58  fWghtCalc.insert(map<string, GReWeightI*>::value_type(name,wcalc));
59 }
60 //____________________________________________________________________________
62 {
64  if(iter != fWghtCalc.end()) return iter->second;
65 
66  return 0;
67 }
68 //____________________________________________________________________________
70 {
71  return fSystSet;
72 }
73 //____________________________________________________________________________
75 {
76  LOG("ReW", pNOTICE) << "Reconfiguring ...";
77 
78  vector<genie::rew::GSyst_t> svec = fSystSet.AllIncluded();
79 
81  for( ; it != fWghtCalc.end(); ++it) {
82 
83  GReWeightI * wcalc = it->second;
84 
85  vector<genie::rew::GSyst_t>::const_iterator parm_iter = svec.begin();
86  for( ; parm_iter != svec.end(); ++parm_iter) {
87  GSyst_t syst = *parm_iter;
88  double val = fSystSet.Info(syst)->CurValue;
89  wcalc->SetSystematic(syst, val);
90  }//params
91 
92  wcalc->Reconfigure();
93 
94  }//weight calculators
95 
96  LOG("ReW", pDEBUG) << "Done reconfiguring";
97 }
98 //____________________________________________________________________________
100 {
101 // calculate weight for all tweaked physics parameters
102 //
103  double weight = 1.0;
105  for( ; it != fWghtCalc.end(); ++it) {
106  GReWeightI * wcalc = it->second;
107  double w = wcalc->CalcWeight(event);
108  LOG("ReW", pNOTICE)
109  << "Calculator: " << it->first << " => wght = " << w;
110  weight *= w;
111  }
112  return weight;
113 }
114 //____________________________________________________________________________
116 {
118  for( ; it != fWghtCalc.end(); ++it) {
119  GReWeightI * rw = it->second;
120  if(rw) {
121  delete rw;
122  rw=0;
123  }
124  }
125  fWghtCalc.clear();
126 }
127 //____________________________________________________________________________
129 {
130  vector<genie::rew::GSyst_t> syst_vec = this->Systematics().AllIncluded();
131  int vec_size = syst_vec.size();
132 
133  LOG("ReW", pNOTICE) << "Current set of systematic params:";
134  for(int i = 0 ; i < vec_size ; i ++){
135  LOG("ReW", pNOTICE)
136  << " --o " << GSyst::AsString(syst_vec[i])
137  << " is set at " << this->Systematics().Info(syst_vec[i])->CurValue;
138  }
139 }
140 //____________________________________________________________________________
141 
142 
#include "Numerical/GSFunc.h"
Definition: AlgCmp.h:26
intermediate_table::iterator iterator
void Reconfigure(void)
reconfigure weight calculators with new params
Definition: GReWeight.cxx:74
GReWeightI * WghtCalc(string name)
access a weight calculator by name
Definition: GReWeight.cxx:61
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:87
intermediate_table::const_iterator const_iterator
An enumeration of systematic parameters.
map< string, GReWeightI * > fWghtCalc
concrete weight calculators
Definition: GReWeight.h:58
virtual void Reconfigure(void)=0
propagate updated nuisance parameter values to actual MC, etc
virtual double CalcWeight(const genie::EventRecord &event)=0
calculate a weight for the input event using the current nuisance param values
void AdoptWghtCalc(string name, GReWeightI *wcalc)
add concrete weight calculator, transfers ownership
Definition: GReWeight.cxx:54
GSystSet fSystSet
set of enabled nuisance parameters
Definition: GReWeight.h:57
const GSystInfo * Info(GSyst_t syst) const
Definition: GSystSet.cxx:81
virtual void SetSystematic(GSyst_t syst, double val)=0
update the value for the specified nuisance param
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
static RunOpt * Instance(void)
Definition: RunOpt.cxx:55
static string AsString(GSyst_t syst)
Definition: GSyst.h:175
void Print(void)
print
Definition: GReWeight.cxx:128
double CalcWeight(const genie::EventRecord &event)
calculate weight for input event
Definition: GReWeight.cxx:99
weight
Definition: test.py:293
#define pNOTICE
Definition: Messenger.h:52
GSystSet & Systematics(void)
set of enabled systematic params & values
Definition: GReWeight.cxx:69
vector< genie::rew::GSyst_t > AllIncluded(void)
Definition: GSystSet.cxx:69
Set of systematics to be considered by the reweighting package.
Definition: GSystSet.h:37
void EnableBareXSecPreCalc(bool flag)
Definition: RunOpt.h:55
Event finding and building.
GENIE event reweighting engine ABC.
Definition: GReWeightI.h:31
#define pDEBUG
Definition: Messenger.h:54