GReWeightNuXSecDIS.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  Make static consts kModeABCV12u and kModeABCV12uShape public so as 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_DIS_DEBUG_
64  fTestFile->cd();
65  fTestNtp ->Write();
66  fTestFile->Close();
67  delete fTestFile;
68 #endif
69 }
70 //_______________________________________________________________________________________
72 {
73  bool handle = false;
74 
75  switch(syst) {
76  case ( kXSecTwkDial_AhtBYshape ) :
77  case ( kXSecTwkDial_BhtBYshape ) :
78  case ( kXSecTwkDial_CV1uBYshape ) :
79  case ( kXSecTwkDial_CV2uBYshape ) :
80 
81  if (fMode == kModeABCV12u ) handle = false;
82  else if (fMode == kModeABCV12uShape) handle = true;
83  break;
84 
85  case ( kXSecTwkDial_AhtBY ) :
86  case ( kXSecTwkDial_BhtBY ) :
87  case ( kXSecTwkDial_CV1uBY ) :
88  case ( kXSecTwkDial_CV2uBY ) :
89 
90  if (fMode == kModeABCV12u ) handle = true;
91  else if (fMode == kModeABCV12uShape) handle = false;
92  break;
93 
94  default:
95  handle = false;
96  break;
97  }
98 
99  return handle;
100 }
101 //_______________________________________________________________________________________
102 void GReWeightNuXSecDIS::SetSystematic(GSyst_t syst, double twk_dial)
103 {
104  if(! this->IsHandled(syst)) return;
105 
106  switch(syst) {
107  case ( kXSecTwkDial_AhtBY ) :
108  case ( kXSecTwkDial_AhtBYshape ) :
109  fAhtBYTwkDial = twk_dial;
110  break;
111  case ( kXSecTwkDial_BhtBY ) :
112  case ( kXSecTwkDial_BhtBYshape ) :
113  fBhtBYTwkDial = twk_dial;
114  break;
115  case ( kXSecTwkDial_CV1uBY ) :
116  case ( kXSecTwkDial_CV1uBYshape ) :
117  fCV1uBYTwkDial = twk_dial;
118  break;
119  case ( kXSecTwkDial_CV2uBY ) :
120  case ( kXSecTwkDial_CV2uBYshape ) :
121  fCV2uBYTwkDial = twk_dial;
122  break;
123  default:
124  return;
125  break;
126  }
127 }
128 //_______________________________________________________________________________________
130 {
131  fAhtBYTwkDial = 0.;
132  fBhtBYTwkDial = 0.;
133  fCV1uBYTwkDial = 0.;
134  fCV2uBYTwkDial = 0.;
135 
136  this->Reconfigure();
137 }
138 //_______________________________________________________________________________________
140 {
142 
143  double fracerr_aht = 0.;
144  double fracerr_bht = 0.;
145  double fracerr_cv1u = 0.;
146  double fracerr_cv2u = 0.;
147 
148  if(fMode == kModeABCV12u) {
149  fracerr_aht = fracerr->OneSigmaErr (kXSecTwkDial_AhtBY );
150  fracerr_bht = fracerr->OneSigmaErr (kXSecTwkDial_BhtBY );
151  fracerr_cv1u = fracerr->OneSigmaErr (kXSecTwkDial_CV1uBY);
152  fracerr_cv2u = fracerr->OneSigmaErr (kXSecTwkDial_CV2uBY);
153  }
154  else
155  if(fMode == kModeABCV12uShape) {
156  fracerr_aht = fracerr->OneSigmaErr (kXSecTwkDial_AhtBYshape );
157  fracerr_bht = fracerr->OneSigmaErr (kXSecTwkDial_BhtBYshape );
158  fracerr_cv1u = fracerr->OneSigmaErr (kXSecTwkDial_CV1uBYshape);
159  fracerr_cv2u = fracerr->OneSigmaErr (kXSecTwkDial_CV2uBYshape);
160  }
161 
162  fAhtBYCur = fAhtBYDef * (1. + fAhtBYTwkDial * fracerr_aht );
163  fBhtBYCur = fBhtBYDef * (1. + fBhtBYTwkDial * fracerr_bht );
164  fCV1uBYCur = fCV1uBYDef * (1. + fCV1uBYTwkDial * fracerr_cv1u);
165  fCV2uBYCur = fCV2uBYDef * (1. + fCV2uBYTwkDial * fracerr_cv2u);
166 
168 
169  r.Set(fAhtBYPath, fAhtBYCur );
170  r.Set(fBhtBYPath, fBhtBYCur );
171  r.Set(fCV1uBYPath, fCV1uBYCur);
172  r.Set(fCV2uBYPath, fCV2uBYCur);
173 
174  fXSecModel->Configure(r);
175 
176 //LOG("ReW", pDEBUG) << *fXSecModel;
177 }
178 //_______________________________________________________________________________________
180 {
181  bool tweaked =
182  (TMath::Abs(fAhtBYTwkDial) > controls::kASmallNum) ||
183  (TMath::Abs(fBhtBYTwkDial) > controls::kASmallNum) ||
184  (TMath::Abs(fCV1uBYTwkDial) > controls::kASmallNum) ||
185  (TMath::Abs(fCV2uBYTwkDial) > controls::kASmallNum);
186  if(!tweaked) return 1.0;
187 
188  Interaction * interaction = event.Summary();
189 
190  bool is_dis = interaction->ProcInfo().IsDeepInelastic();
191  if(!is_dis) return 1.;
192 
193  bool charm = event.Summary()->ExclTag().IsCharmEvent(); // skip DIS charm
194  if(charm) return 1.;
195 
196  bool is_cc = interaction->ProcInfo().IsWeakCC();
197  bool is_nc = interaction->ProcInfo().IsWeakNC();
198  if(is_cc && !fRewCC) return 1.;
199  if(is_nc && !fRewNC) return 1.;
200 
201  int nupdg = interaction->InitState().ProbePdg();
202  if(nupdg==kPdgNuMu && !fRewNumu ) return 1.;
203  if(nupdg==kPdgAntiNuMu && !fRewNumubar) return 1.;
204  if(nupdg==kPdgNuE && !fRewNue ) return 1.;
205  if(nupdg==kPdgAntiNuE && !fRewNuebar ) return 1.;
206 
207  bool selected = true;
208  double W = interaction->Kine().W (selected);
209  double Q2 = interaction->Kine().Q2(selected);
210  bool passes_kine_cuts = (W>=fWmin && Q2>=fQ2min);
211  if(!passes_kine_cuts) return 1.;
212 
213  //
214  // calculate weight
215  //
216 
217  double wght = 1.;
218 
219  if(fMode == kModeABCV12u) {
220  wght = this->CalcWeightABCV12u(event);
221  }
222  else
223  if(fMode == kModeABCV12uShape) {
224  wght = this->CalcWeightABCV12uShape(event);
225  }
226 
227 #ifdef _G_REWEIGHT_DIS_DEBUG_
228  double E = interaction->InitState().ProbeE(kRfHitNucRest);
229  double x = interaction->Kine().x(true);
230  double y = interaction->Kine().y(true);
231  int ccnc = (is_cc) ? 1 : 0;
232  int nuc = interaction->InitState().Tgt().HitNucPdg();
233  int qrk = interaction->InitState().Tgt().HitQrkPdg();
234  int sea = (interaction->InitState().Tgt().HitSeaQrk()) ? 1 : 0;
235  fTestNtp->Fill(E,x,y,nupdg,nuc,qrk,sea,ccnc,wght);
236 #endif
237 
238  return wght;
239 }
240 //_______________________________________________________________________________________
242 {
243  Interaction * interaction = event.Summary();
244 
245  interaction->KinePtr()->UseSelectedKinematics();
246 
247  double old_xsec = event.DiffXSec();
248  double old_weight = event.Weight();
249  double twk_xsec = fXSecModel->XSec(interaction, kPSxyfE);
250  double weight = old_weight * (twk_xsec/old_xsec);
251 
252  interaction->KinePtr()->ClearRunningValues();
253 
254  return weight;
255 }
256 //_______________________________________________________________________________________
258 {
259  Interaction * interaction = event.Summary();
260 
261  interaction->KinePtr()->UseSelectedKinematics();
262 
263  double old_xsec = event.DiffXSec();
264  double old_weight = event.Weight();
265  double twk_xsec = fXSecModel->XSec(interaction, kPSxyfE);
266  double weight = old_weight * (twk_xsec/old_xsec);
267 
268 //double old_integrated_xsec = event.XSec();
269  double old_integrated_xsec = fXSecModelDef -> Integral(interaction);
270  double twk_integrated_xsec = fXSecModel -> Integral(interaction);
271 
272  assert(twk_integrated_xsec > 0);
273  weight *= (old_integrated_xsec/twk_integrated_xsec);
274 
275  interaction->KinePtr()->ClearRunningValues();
276 
277  return weight;
278 }
279 //_______________________________________________________________________________________
281 {
282  AlgId id("genie::QPMDISPXSec","Default");
283 
284  AlgFactory * algf = AlgFactory::Instance();
285 
286  Algorithm * algdef = algf->AdoptAlgorithm(id);
287  fXSecModelDef = dynamic_cast<XSecAlgorithmI*>(algdef);
289 
290  Algorithm * alg = algf->AdoptAlgorithm(id);
291  fXSecModel = dynamic_cast<XSecAlgorithmI*>(alg);
293 
295 //LOG("ReW", pNOTICE) << *fXSecModelConfig;
296 
297  this->SetMode (kModeABCV12u);
298 
299  this->RewNue (true);
300  this->RewNuebar (true);
301  this->RewNumu (true);
302  this->RewNumubar(true);
303  this->RewCC (true);
304  this->RewNC (true);
305 
306  this->SetWminCut (1.7*units::GeV);
307  this->SetQ2minCut(1.0*units::GeV*units::GeV);
308 
309  this->SetAhtBYPath ("SFAlg/A");
310  this->SetBhtBYPath ("SFAlg/B");
311  this->SetCV1uBYPath("SFAlg/Cv1U");
312  this->SetCV2uBYPath("SFAlg/Cv2U");
313 
314  fAhtBYTwkDial = 0;
315  fBhtBYTwkDial = 0;
316  fCV1uBYTwkDial = 0;
317  fCV2uBYTwkDial = 0;
322  fAhtBYCur = fAhtBYDef;
323  fBhtBYCur = fBhtBYDef;
326 
327 #ifdef _G_REWEIGHT_DIS_DEBUG_
328  fTestFile = new TFile("./dis_reweight_test.root","recreate");
329  fTestNtp = new TNtupleD("testntp","","E:x:y:nu:nuc:qrk:sea:ccnc:wght");
330 #endif
331 }
332 //_______________________________________________________________________________________
333 
334 
virtual const Registry & GetConfig(void) const
Get configuration registry.
Definition: Algorithm.h:63
Cross Section Calculation Interface.
double W(bool selected=false) const
Definition: Kinematics.cxx:167
bool IsHandled(GSyst_t syst)
does the current weight calculator handle the input nuisance param?
bool HitSeaQrk(void) const
Definition: Target.cxx:306
bool IsWeakCC(void) const
const int kPdgNuE
Definition: PDGCodes.h:25
void SetSystematic(GSyst_t syst, double val)
update the value for the specified nuisance param
#include "Numerical/GSFunc.h"
Definition: AlgCmp.h:26
double fBhtBYTwkDial
tweak dial for BY parameter: Bht
double Q2(const Interaction *const i)
Definition: KineUtils.cxx:642
int HitNucPdg(void) const
Definition: Target.cxx:311
Kinematics * KinePtr(void) const
Definition: Interaction.h:73
double CalcWeight(const EventRecord &event)
calculate a weight for the input event using the current nuisance param values
virtual double XSec(const Interaction *i, KinePhaseSpace_t k=kPSfE) const =0
Compute the cross section for the input interaction.
int HitQrkPdg(void) const
Definition: Target.cxx:249
const int kPdgAntiNuE
Definition: PDGCodes.h:26
const int kPdgNuMu
Definition: PDGCodes.h:27
tweak the Bodek-Yang model parameter B_{ht} - shape only effect to d2sigma(DIS)/dxdy ...
Definition: GSyst.h:91
Algorithm abstract base class.
Definition: Algorithm.h:48
double x(bool selected=false) const
Definition: Kinematics.cxx:109
RgDbl GetDouble(RgKey key) const
Definition: Registry.cxx:488
XSecAlgorithmI * fXSecModelDef
default model
XSecAlgorithmI * fXSecModel
tweaked model
double OneSigmaErr(GSyst_t syst, int sign=0) const
double y(bool selected=false) const
Definition: Kinematics.cxx:122
void Reconfigure(void)
propagate updated nuisance parameter values to actual MC, etc
Summary information for an interaction.
Definition: Interaction.h:53
void UseSelectedKinematics(void)
Definition: Kinematics.cxx:369
double y
double fCV1uBYTwkDial
tweak dial for BY parameter: CV1u
bool IsWeakNC(void) const
int fMode
0: Aht,Bht,CV1u,CV2u, 1:AhtShape,BhtShape,CV1uShape,CV2uShape
bool fRewNuebar
reweight nu_e_bar?
tweak the Bodek-Yang model parameter CV2u - incl. both shape and normalization effect ...
Definition: GSyst.h:89
const Kinematics & Kine(void) const
Definition: Interaction.h:68
virtual void Configure(const Registry &config)
Configure the algorithm.
Definition: Algorithm.cxx:70
int ProbePdg(void) const
Definition: InitialState.h:54
static const double kASmallNum
Definition: Controls.h:40
void Reset(void)
set all nuisance parameters to default values
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
double fCV2uBYTwkDial
tweak dial for BY parameter: CV2u
double fWmin
W_{min} cut. Reweight only events with W > W_{min}.
double fAhtBYTwkDial
tweak dial for BY parameter: Aht
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
bool IsDeepInelastic(void) const
Definition: ProcessInfo.cxx:98
Algorithm ID (algorithm name + configuration set name)
Definition: AlgId.h:35
tweak the Bodek-Yang model parameter A_{ht} - incl. both shape and normalization effect ...
Definition: GSyst.h:86
double fQ2min
Q2_{min} cut. Reweight only events with Q2 > Q2_{min}.
tweak the Bodek-Yang model parameter A_{ht} - shape only effect to d2sigma(DIS)/dxdy ...
Definition: GSyst.h:90
static AlgFactory * Instance()
Definition: AlgFactory.cxx:75
double CalcWeightABCV12u(const genie::EventRecord &event)
rew. Aht,Bht,CV1u,CV2u
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:66
Registry * fXSecModelConfig
config in tweaked model
tweak the Bodek-Yang model parameter CV1u - shape only effect to d2sigma(DIS)/dxdy ...
Definition: GSyst.h:92
const InitialState & InitState(void) const
Definition: Interaction.h:66
const ProcessInfo & ProcInfo(void) const
Definition: Interaction.h:67
static GSystUncertainty * Instance(void)
tweak the Bodek-Yang model parameter CV1u - incl. both shape and normalization effect ...
Definition: GSyst.h:88
weight
Definition: test.py:293
double Q2(bool selected=false) const
Definition: Kinematics.cxx:135
void ClearRunningValues(void)
Definition: Kinematics.cxx:357
const Target & Tgt(void) const
Definition: InitialState.h:56
The GENIE Algorithm Factory.
Definition: AlgFactory.h:40
double CalcWeightABCV12uShape(const genie::EventRecord &event)
rew. AhtShape,BhtShape,CV1uShape,CV2uShape
static const double GeV
Definition: Units.h:29
tweak the Bodek-Yang model parameter CV2u - shape only effect to d2sigma(DIS)/dxdy ...
Definition: GSyst.h:93
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...
bool fRewNumubar
reweight nu_mu_bar?
Event finding and building.
tweak the Bodek-Yang model parameter B_{ht} - incl. both shape and normalization effect ...
Definition: GSyst.h:87