GReWeightNuXSecCCRES.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: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
8  University of Liverpool & STFC Rutherford Appleton Lab
9 
10  Jim Dobson <J.Dobson07 \at imperial.ac.uk>
11  Imperial College London
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 17, 2010 - CA
20  Code extracted from GReWeightNuXSec and redeveloped in preparation for
21  the Summer 2010 T2K analyses.
22  @ Oct 20, 2010 - CA
23  Made static consts `kModeMaMv' and `kModeNormAndMaMvShape' public to
24  aid external configuration.
25 */
26 //____________________________________________________________________________
27 
28 #include <cassert>
29 
30 #include <TMath.h>
31 #include <TFile.h>
32 #include <TNtupleD.h>
33 
34 #include "Algorithm/AlgFactory.h"
36 #include "Base/XSecAlgorithmI.h"
37 #include "Conventions/Units.h"
38 #include "Conventions/Controls.h"
39 #include "EVGCore/EventRecord.h"
40 #include "GHEP/GHepParticle.h"
42 #include "Messenger/Messenger.h"
43 #include "PDG/PDGCodes.h"
45 #include "ReWeight/GSystSet.h"
47 #include "Registry/Registry.h"
48 
49 using namespace genie;
50 using namespace genie::rew;
51 
54 
55 //_______________________________________________________________________________________
57 {
58  this->Init();
59 }
60 //_______________________________________________________________________________________
62 {
63 #ifdef _G_REWEIGHT_CCRES_DEBUG_
64  fTestFile->cd();
65  fTestNtp ->Write();
66  fTestFile->Close();
67  delete fTestFile;
68 #endif
69 }
70 //_______________________________________________________________________________________
72 {
73  bool handle;
74 
75  switch(syst) {
76 
77  case ( kXSecTwkDial_NormCCRES ) :
78  case ( kXSecTwkDial_MaCCRESshape ) :
79  case ( kXSecTwkDial_MvCCRESshape ) :
81  handle = true;
82  } else {
83  handle = false;
84  }
85  break;
86 
87  case ( kXSecTwkDial_MaCCRES ) :
88  case ( kXSecTwkDial_MvCCRES ) :
89  if(fMode==kModeMaMv) {
90  handle = true;
91  } else {
92  handle = false;
93  }
94  break;
95 
96  default:
97  handle = false;
98  break;
99  }
100 
101  return handle;
102 }
103 //_______________________________________________________________________________________
104 void GReWeightNuXSecCCRES::SetSystematic(GSyst_t syst, double twk_dial)
105 {
106  if(!this->IsHandled(syst)) return;
107 
108  switch(syst) {
109  case ( kXSecTwkDial_NormCCRES ) :
110  fNormTwkDial = twk_dial;
111  break;
112  case ( kXSecTwkDial_MaCCRESshape ) :
113  case ( kXSecTwkDial_MaCCRES ) :
114  fMaTwkDial = twk_dial;
115  break;
116  case ( kXSecTwkDial_MvCCRESshape ) :
117  case ( kXSecTwkDial_MvCCRES ) :
118  fMvTwkDial = twk_dial;
119  break;
120  default:
121  break;
122  }
123 }
124 //_______________________________________________________________________________________
126 {
127  fNormTwkDial = 0.;
129  fMaTwkDial = 0.;
130  fMaCurr = fMaDef;
131  fMvTwkDial = 0.;
132  fMvCurr = fMvDef;
133 
134  this->Reconfigure();
135 }
136 //_______________________________________________________________________________________
138 {
140 
141  if(fMode==kModeMaMv) {
142  double fracerr_ma = fracerr->OneSigmaErr(kXSecTwkDial_MaCCRES);
143  double fracerr_mv = fracerr->OneSigmaErr(kXSecTwkDial_MvCCRES);
144  fMaCurr = fMaDef * (1. + fMaTwkDial * fracerr_ma);
145  fMvCurr = fMvDef * (1. + fMvTwkDial * fracerr_mv);
146  }
147  else
149  double fracerr_norm = fracerr->OneSigmaErr(kXSecTwkDial_NormCCRES);
150  double fracerr_mash = fracerr->OneSigmaErr(kXSecTwkDial_MaCCRESshape);
151  double fracerr_mvsh = fracerr->OneSigmaErr(kXSecTwkDial_MvCCRESshape);
152  fNormCurr = fNormDef * (1. + fNormTwkDial * fracerr_norm);
153  fMaCurr = fMaDef * (1. + fMaTwkDial * fracerr_mash);
154  fMvCurr = fMvDef * (1. + fMvTwkDial * fracerr_mvsh);
155  }
156 
157  fNormCurr = TMath::Max(0., fNormCurr);
158  fMaCurr = TMath::Max(0., fMaCurr );
159  fMvCurr = TMath::Max(0., fMvCurr );
160 
162 
163  r.Set(fMaPath, fMaCurr);
164  r.Set(fMvPath, fMvCurr);
165  fXSecModel->Configure(r);
166 
167 //LOG("ReW, pDEBUG) << *fXSecModel;
168 }
169 //_______________________________________________________________________________________
171 {
172  bool is_res = event.Summary()->ProcInfo().IsResonant();
173  bool is_cc = event.Summary()->ProcInfo().IsWeakCC();
174  if(!is_res || !is_cc) return 1.;
175 
176  int nupdg = event.Probe()->Pdg();
177  if(nupdg==kPdgNuMu && !fRewNumu ) return 1.;
178  if(nupdg==kPdgAntiNuMu && !fRewNumubar) return 1.;
179  if(nupdg==kPdgNuE && !fRewNue ) return 1.;
180  if(nupdg==kPdgAntiNuE && !fRewNuebar ) return 1.;
181 
182  if(fMode==kModeMaMv) {
183  double wght = this->CalcWeightMaMv(event);
184  return wght;
185  }
186  else
188  double wght =
189  this->CalcWeightNorm (event) *
190  this->CalcWeightMaMvShape (event);
191  return wght;
192  }
193 
194  return 1.;
195 }
196 //_______________________________________________________________________________________
198 {
199  AlgId id("genie::ReinSehgalRESPXSec","Default");
200 
201  AlgFactory * algf = AlgFactory::Instance();
202 
203  Algorithm * algdef = algf->AdoptAlgorithm(id);
204  fXSecModelDef = dynamic_cast<XSecAlgorithmI*>(algdef);
206 
207  Algorithm * alg = algf->AdoptAlgorithm(id);
208  fXSecModel = dynamic_cast<XSecAlgorithmI*>(alg);
210 
212 //LOG("ReW", pNOTICE) << *fXSecModelConfig;
213 
215 
216  this->RewNue (true);
217  this->RewNuebar (true);
218  this->RewNumu (true);
219  this->RewNumubar(true);
220 
221  this->SetMaPath("Ma");
222  this->SetMvPath("Mv");
223 
224  fNormTwkDial = 0.;
225  fNormDef = 1.;
227  fMaTwkDial = 0.;
229  fMaCurr = fMaDef;
230  fMvTwkDial = 0.;
232  fMvCurr = fMvDef;
233 
234 #ifdef _G_REWEIGHT_CCRES_DEBUG_
235  fTestFile = new TFile("./ccres_reweight_test.root","recreate");
236  fTestNtp = new TNtupleD("testntp","","E:Q2:W:wght");
237 #endif
238 }
239 //_______________________________________________________________________________________
241 {
242  bool tweaked = (TMath::Abs(fNormTwkDial) > controls::kASmallNum);
243  if(!tweaked) return 1.0;
244 
245  double wght = fNormCurr;
246  return wght;
247 }
248 //_______________________________________________________________________________________
250 {
251  bool tweaked =
252  (TMath::Abs(fMaTwkDial) > controls::kASmallNum) ||
253  (TMath::Abs(fMvTwkDial) > controls::kASmallNum);
254  if(!tweaked) return 1.0;
255 
256  Interaction * interaction = event.Summary();
257 
258  interaction->KinePtr()->UseSelectedKinematics();
259 
260  double old_xsec = event.DiffXSec();
261  double old_weight = event.Weight();
262  double new_xsec = fXSecModel->XSec(interaction, kPSWQ2fE);
263  double new_weight = old_weight * (new_xsec/old_xsec);
264 
265  interaction->KinePtr()->ClearRunningValues();
266 
267  return new_weight;
268 }
269 //_______________________________________________________________________________________
271 {
272  bool tweaked =
273  (TMath::Abs(fMaTwkDial) > controls::kASmallNum) ||
274  (TMath::Abs(fMvTwkDial) > controls::kASmallNum);
275  if(!tweaked) return 1.0;
276 
277  Interaction * interaction = event.Summary();
278 
279  interaction->KinePtr()->UseSelectedKinematics();
280 
281  double old_xsec = event.DiffXSec();
282  double old_weight = event.Weight();
283  double new_xsec = fXSecModel->XSec(interaction, kPSWQ2fE);
284  double new_weight = old_weight * (new_xsec/old_xsec);
285 
286 //LOG("ReW", pDEBUG) << "differential cross section (old) = " << old_xsec;
287 //LOG("ReW", pDEBUG) << "differential cross section (new) = " << new_xsec;
288 //LOG("ReW", pDEBUG) << "event generation weight = " << old_weight;
289 //LOG("ReW", pDEBUG) << "new weight = " << new_weight;
290 
291 //double old_integrated_xsec = event.XSec();
292  double old_integrated_xsec = fXSecModelDef -> Integral(interaction);
293  double twk_integrated_xsec = fXSecModel -> Integral(interaction);
294  assert(twk_integrated_xsec > 0);
295  new_weight *= (old_integrated_xsec/twk_integrated_xsec);
296 
297 //LOG("ReW", pDEBUG) << "integrated cross section (old) = " << old_integrated_xsec;
298 //LOG("ReW", pDEBUG) << "integrated cross section (twk) = " << twk_integrated_xsec;
299 //LOG("ReW", pDEBUG) << "new weight (normalized to const integral) = " << new_weight;
300 
301  interaction->KinePtr()->ClearRunningValues();
302 
303 #ifdef _G_REWEIGHT_CCRES_DEBUG_
304  double E = interaction->InitState().ProbeE(kRfHitNucRest);
305  double Q2 = interaction->Kine().Q2(true);
306  double W = interaction->Kine().W(true);
307  fTestNtp->Fill(E,Q2,W,new_weight);
308 #endif
309 
310  return new_weight;
311 }
312 //_______________________________________________________________________________________
virtual const Registry & GetConfig(void) const
Get configuration registry.
Definition: Algorithm.h:63
Cross Section Calculation Interface.
tweak Mv CCRES, affects d2sigma(CCRES)/dWdQ2 both in shape and normalization
Definition: GSyst.h:59
double W(bool selected=false) const
Definition: Kinematics.cxx:167
tweak Mv CCRES, affects d2sigma(CCRES)/dWdQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:57
const int kPdgNuE
Definition: PDGCodes.h:25
#include "Numerical/GSFunc.h"
Definition: AlgCmp.h:26
double Q2(const Interaction *const i)
Definition: KineUtils.cxx:642
Registry * fXSecModelConfig
config in tweaked model
Kinematics * KinePtr(void) const
Definition: Interaction.h:73
virtual double XSec(const Interaction *i, KinePhaseSpace_t k=kPSfE) const =0
Compute the cross section for the input interaction.
double CalcWeightMaMv(const EventRecord &event)
const int kPdgAntiNuE
Definition: PDGCodes.h:26
void Reconfigure(void)
propagate updated nuisance parameter values to actual MC, etc
const int kPdgNuMu
Definition: PDGCodes.h:27
Algorithm abstract base class.
Definition: Algorithm.h:48
RgDbl GetDouble(RgKey key) const
Definition: Registry.cxx:488
void Reset(void)
set all nuisance parameters to default values
double OneSigmaErr(GSyst_t syst, int sign=0) const
XSecAlgorithmI * fXSecModelDef
default model
Summary information for an interaction.
Definition: Interaction.h:53
void UseSelectedKinematics(void)
Definition: Kinematics.cxx:369
const Kinematics & Kine(void) const
Definition: Interaction.h:68
virtual void Configure(const Registry &config)
Configure the algorithm.
Definition: Algorithm.cxx:70
static const double kASmallNum
Definition: Controls.h:40
An enumeration of systematic parameters.
void AdoptSubstructure(void)
Definition: Algorithm.cxx:287
Algorithm * AdoptAlgorithm(const AlgId &algid) const
Definition: AlgFactory.cxx:127
const int kPdgAntiNuMu
Definition: PDGCodes.h:28
bool fRewNuebar
reweight nu_e_bar CC?
double CalcWeightMaMvShape(const EventRecord &event)
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
bool IsHandled(GSyst_t syst)
does the current weight calculator handle the input nuisance param?
Algorithm ID (algorithm name + configuration set name)
Definition: AlgId.h:35
tweak CCRES normalization
Definition: GSyst.h:55
double CalcWeight(const EventRecord &event)
calculate a weight for the input event using the current nuisance param values
static AlgFactory * Instance()
Definition: AlgFactory.cxx:75
tweak Ma CCRES, affects d2sigma(CCRES)/dWdQ2 both in shape and normalization
Definition: GSyst.h:58
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:66
string fMvPath
M_{V} path in configuration.
tweak Ma CCRES, affects d2sigma(CCRES)/dWdQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:56
string fMaPath
M_{A} path in configuration.
const InitialState & InitState(void) const
Definition: Interaction.h:66
int fMode
0: Ma/Mv, 1: Norm and MaShape/MvShape
static GSystUncertainty * Instance(void)
bool fRewNumubar
reweight nu_mu_bar CC?
double Q2(bool selected=false) const
Definition: Kinematics.cxx:135
void ClearRunningValues(void)
Definition: Kinematics.cxx:357
The GENIE Algorithm Factory.
Definition: AlgFactory.h:40
double CalcWeightNorm(const EventRecord &event)
void Set(RgIMapPair entry)
Definition: Registry.cxx:281
double ProbeE(RefFrame_t rf) const
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils...
void SetSystematic(GSyst_t syst, double val)
update the value for the specified nuisance param
Event finding and building.
XSecAlgorithmI * fXSecModel
tweaked model