GReWeightNuXSecNCRES.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  @ Jun 09, 2010 - CA
17  Created by cloning the CCRES reweight code so that NCRES events can
18  be tweaked / reweighted independently. First included in v2.7.1.
19  @ Oct 20, 2010 - CA
20  Made static consts `kModeMaMv' and `kModeNormAndMaMvShape' public to
21  aid external configuration.
22 
23 */
24 //____________________________________________________________________________
25 
26 #include <cassert>
27 
28 #include <TMath.h>
29 
30 #include "Algorithm/AlgFactory.h"
32 #include "Base/XSecAlgorithmI.h"
33 #include "Conventions/Units.h"
34 #include "Conventions/Controls.h"
35 #include "EVGCore/EventRecord.h"
36 #include "GHEP/GHepParticle.h"
38 #include "Messenger/Messenger.h"
39 #include "PDG/PDGCodes.h"
41 #include "ReWeight/GSystSet.h"
43 #include "Registry/Registry.h"
44 
45 using namespace genie;
46 using namespace genie::rew;
47 
50 
51 //_______________________________________________________________________________________
53 {
54  this->Init();
55 }
56 //_______________________________________________________________________________________
58 {
59 
60 }
61 //_______________________________________________________________________________________
63 {
64  bool handle;
65 
66  switch(syst) {
67 
68  case ( kXSecTwkDial_NormNCRES ) :
69  case ( kXSecTwkDial_MaNCRESshape ) :
70  case ( kXSecTwkDial_MvNCRESshape ) :
72  handle = true;
73  } else {
74  handle = false;
75  }
76  break;
77 
78  case ( kXSecTwkDial_MaNCRES ) :
79  case ( kXSecTwkDial_MvNCRES ) :
80  if(fMode==kModeMaMv) {
81  handle = true;
82  } else {
83  handle = false;
84  }
85  break;
86 
87  default:
88  handle = false;
89  break;
90  }
91 
92  return handle;
93 }
94 //_______________________________________________________________________________________
95 void GReWeightNuXSecNCRES::SetSystematic(GSyst_t syst, double twk_dial)
96 {
97  if(!this->IsHandled(syst)) return;
98 
99  switch(syst) {
100  case ( kXSecTwkDial_NormNCRES ) :
101  fNormTwkDial = twk_dial;
102  break;
103  case ( kXSecTwkDial_MaNCRESshape ) :
104  case ( kXSecTwkDial_MaNCRES ) :
105  fMaTwkDial = twk_dial;
106  break;
107  case ( kXSecTwkDial_MvNCRESshape ) :
108  case ( kXSecTwkDial_MvNCRES ) :
109  fMvTwkDial = twk_dial;
110  break;
111  default:
112  break;
113  }
114 }
115 //_______________________________________________________________________________________
117 {
118  fNormTwkDial = 0.;
120  fMaTwkDial = 0.;
121  fMaCurr = fMaDef;
122  fMvTwkDial = 0.;
123  fMvCurr = fMvDef;
124 
125  this->Reconfigure();
126 }
127 //_______________________________________________________________________________________
129 {
131 
132  if(fMode==kModeMaMv) {
133  double fracerr_ma = fracerr->OneSigmaErr(kXSecTwkDial_MaNCRES);
134  double fracerr_mv = fracerr->OneSigmaErr(kXSecTwkDial_MvNCRES);
135  fMaCurr = fMaDef * (1. + fMaTwkDial * fracerr_ma);
136  fMvCurr = fMvDef * (1. + fMvTwkDial * fracerr_mv);
137  }
138  else
140  double fracerr_norm = fracerr->OneSigmaErr(kXSecTwkDial_NormNCRES);
141  double fracerr_mash = fracerr->OneSigmaErr(kXSecTwkDial_MaNCRESshape);
142  double fracerr_mvsh = fracerr->OneSigmaErr(kXSecTwkDial_MvNCRESshape);
143  fNormCurr = fNormDef * (1. + fNormTwkDial * fracerr_norm);
144  fMaCurr = fMaDef * (1. + fMaTwkDial * fracerr_mash);
145  fMvCurr = fMvDef * (1. + fMvTwkDial * fracerr_mvsh);
146  }
147 
148  fNormCurr = TMath::Max(0., fNormCurr);
149  fMaCurr = TMath::Max(0., fMaCurr );
150  fMvCurr = TMath::Max(0., fMvCurr );
151 
153 
154  r.Set(fMaPath, fMaCurr);
155  r.Set(fMvPath, fMvCurr);
156  fXSecModel->Configure(r);
157 
158 //LOG("ReW, pDEBUG) << *fXSecModel;
159 }
160 //_______________________________________________________________________________________
162 {
163  bool is_res = event.Summary()->ProcInfo().IsResonant();
164  bool is_nc = event.Summary()->ProcInfo().IsWeakNC();
165  if(!is_res || !is_nc) return 1.;
166 
167  int nupdg = event.Probe()->Pdg();
168  if(nupdg==kPdgNuMu && !fRewNumu ) return 1.;
169  if(nupdg==kPdgAntiNuMu && !fRewNumubar) return 1.;
170  if(nupdg==kPdgNuE && !fRewNue ) return 1.;
171  if(nupdg==kPdgAntiNuE && !fRewNuebar ) return 1.;
172 
173  if(fMode==kModeMaMv) {
174  double wght = this->CalcWeightMaMv(event);
175  return wght;
176  }
177  else
179  double wght =
180  this->CalcWeightNorm (event) *
181  this->CalcWeightMaMvShape (event);
182  return wght;
183  }
184 
185  return 1.;
186 }
187 //_______________________________________________________________________________________
189 {
190  AlgId id("genie::ReinSehgalRESPXSec","Default");
191 
192  AlgFactory * algf = AlgFactory::Instance();
193 
194  Algorithm * algdef = algf->AdoptAlgorithm(id);
195  fXSecModelDef = dynamic_cast<XSecAlgorithmI*>(algdef);
197 
198  Algorithm * alg = algf->AdoptAlgorithm(id);
199  fXSecModel = dynamic_cast<XSecAlgorithmI*>(alg);
201 
203 //LOG("ReW", pNOTICE) << *fXSecModelConfig;
204 
206 
207  this->RewNue (true);
208  this->RewNuebar (true);
209  this->RewNumu (true);
210  this->RewNumubar(true);
211 
212  this->SetMaPath("Ma");
213  this->SetMvPath("Mv");
214 
215  fNormTwkDial = 0.;
216  fNormDef = 1.;
218  fMaTwkDial = 0.;
220  fMaCurr = fMaDef;
221  fMvTwkDial = 0.;
223  fMvCurr = fMvDef;
224 }
225 //_______________________________________________________________________________________
227 {
228  bool tweaked = (TMath::Abs(fNormTwkDial) > controls::kASmallNum);
229  if(!tweaked) return 1.0;
230 
231  double wght = fNormCurr;
232  return wght;
233 }
234 //_______________________________________________________________________________________
236 {
237  bool tweaked =
238  (TMath::Abs(fMaTwkDial) > controls::kASmallNum) ||
239  (TMath::Abs(fMvTwkDial) > controls::kASmallNum);
240  if(!tweaked) return 1.0;
241 
242  Interaction * interaction = event.Summary();
243 
244  interaction->KinePtr()->UseSelectedKinematics();
245 
246  double old_xsec = event.DiffXSec();
247  double old_weight = event.Weight();
248  double new_xsec = fXSecModel->XSec(interaction, kPSWQ2fE);
249  double new_weight = old_weight * (new_xsec/old_xsec);
250 
251  interaction->KinePtr()->ClearRunningValues();
252 
253  return new_weight;
254 }
255 //_______________________________________________________________________________________
257 {
258  bool tweaked =
259  (TMath::Abs(fMaTwkDial) > controls::kASmallNum) ||
260  (TMath::Abs(fMvTwkDial) > controls::kASmallNum);
261  if(!tweaked) return 1.0;
262 
263  Interaction * interaction = event.Summary();
264 
265  interaction->KinePtr()->UseSelectedKinematics();
266 
267  double old_xsec = event.DiffXSec();
268  double old_weight = event.Weight();
269  double new_xsec = fXSecModel->XSec(interaction, kPSWQ2fE);
270  double new_weight = old_weight * (new_xsec/old_xsec);
271 
272 //LOG("ReW", pDEBUG) << "differential cross section (old) = " << old_xsec;
273 //LOG("ReW", pDEBUG) << "differential cross section (new) = " << new_xsec;
274 //LOG("ReW", pDEBUG) << "event generation weight = " << old_weight;
275 //LOG("ReW", pDEBUG) << "new weight = " << new_weight;
276 
277 //double old_integrated_xsec = event.XSec();
278  double old_integrated_xsec = fXSecModelDef -> Integral(interaction);
279  double twk_integrated_xsec = fXSecModel -> Integral(interaction);
280  assert(twk_integrated_xsec > 0);
281  new_weight *= (old_integrated_xsec/twk_integrated_xsec);
282 
283 //LOG("ReW", pDEBUG) << "integrated cross section (old) = " << old_integrated_xsec;
284 //LOG("ReW", pDEBUG) << "integrated cross section (twk) = " << twk_integrated_xsec;
285 //LOG("ReW", pDEBUG) << "new weight (normalized to const integral) = " << new_weight;
286 
287  interaction->KinePtr()->ClearRunningValues();
288 
289  return new_weight;
290 }
291 //_______________________________________________________________________________________
double CalcWeight(const EventRecord &event)
calculate a weight for the input event using the current nuisance param values
virtual const Registry & GetConfig(void) const
Get configuration registry.
Definition: Algorithm.h:63
Cross Section Calculation Interface.
Registry * fXSecModelConfig
config in tweaked model
bool fRewNuebar
reweight nu_e_bar NC?
XSecAlgorithmI * fXSecModelDef
default model
const int kPdgNuE
Definition: PDGCodes.h:25
#include "Numerical/GSFunc.h"
Definition: AlgCmp.h:26
double CalcWeightNorm(const EventRecord &event)
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.
const int kPdgAntiNuE
Definition: PDGCodes.h:26
const int kPdgNuMu
Definition: PDGCodes.h:27
Algorithm abstract base class.
Definition: Algorithm.h:48
RgDbl GetDouble(RgKey key) const
Definition: Registry.cxx:488
double CalcWeightMaMv(const EventRecord &event)
int fMode
0: Ma/Mv, 1: Norm and MaShape/MvShape
double OneSigmaErr(GSyst_t syst, int sign=0) const
bool fRewNumubar
reweight nu_mu_bar NC?
Summary information for an interaction.
Definition: Interaction.h:53
void UseSelectedKinematics(void)
Definition: Kinematics.cxx:369
double CalcWeightMaMvShape(const EventRecord &event)
virtual void Configure(const Registry &config)
Configure the algorithm.
Definition: Algorithm.cxx:70
bool IsHandled(GSyst_t syst)
does the current weight calculator handle the input nuisance param?
void SetSystematic(GSyst_t syst, double val)
update the value for the specified nuisance param
static const double kASmallNum
Definition: Controls.h:40
An enumeration of systematic parameters.
void AdoptSubstructure(void)
Definition: Algorithm.cxx:287
void Reconfigure(void)
propagate updated nuisance parameter values to actual MC, etc
Algorithm * AdoptAlgorithm(const AlgId &algid) const
Definition: AlgFactory.cxx:127
const int kPdgAntiNuMu
Definition: PDGCodes.h:28
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
string fMvPath
M_{V} path in configuration.
Algorithm ID (algorithm name + configuration set name)
Definition: AlgId.h:35
tweak Mv NCRES, affects d2sigma(NCRES)/dWdQ2 both in shape and normalization
Definition: GSyst.h:64
static AlgFactory * Instance()
Definition: AlgFactory.cxx:75
void Reset(void)
set all nuisance parameters to default values
tweak NCRES normalization
Definition: GSyst.h:60
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:66
XSecAlgorithmI * fXSecModel
tweaked model
static GSystUncertainty * Instance(void)
void ClearRunningValues(void)
Definition: Kinematics.cxx:357
The GENIE Algorithm Factory.
Definition: AlgFactory.h:40
tweak Ma NCRES, affects d2sigma(NCRES)/dWdQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:61
tweak Mv NCRES, affects d2sigma(NCRES)/dWdQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:62
void Set(RgIMapPair entry)
Definition: Registry.cxx:281
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils...
string fMaPath
M_{A} path in configuration.
Event finding and building.
tweak Ma NCRES, affects d2sigma(NCRES)/dWdQ2 both in shape and normalization
Definition: GSyst.h:63