GReWeightNuXSecCCQE.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 22, 2010 - CA
23  Make static consts kModeMa and kModeNormAndMaShape public to aid
24  external configuration.
25  @ Nov 25, 2010 - CA
26  Allow asymmetric errors
27  @ Jan 29, 2013 - CA
28  In SetSystematic() add protection against using systematic params which are
29  inconsistent with the current reweighting mode [reported by Rik Gran].
30  @ Dec 26, 2014 - AM
31  Added Support for z-expansion axial form factor reweighting
32  @ Jul 19, 2015 - AM
33  Updated z-expansion reweighting for explicit rather than general coefficient nobs
34  Added norm and shape z-expansion reweighting
35 */
36 //____________________________________________________________________________
37 
38 #include <TMath.h>
39 #include <TFile.h>
40 #include <TNtupleD.h>
41 #include <cstdlib>
42 #include <sstream>
43 
44 #include "Algorithm/AlgFactory.h"
46 #include "Base/XSecAlgorithmI.h"
47 #include "Conventions/Units.h"
48 #include "Conventions/Controls.h"
49 #include "EVGCore/EventRecord.h"
50 #include "GHEP/GHepParticle.h"
52 #include "Messenger/Messenger.h"
53 #include "PDG/PDGCodes.h"
55 #include "ReWeight/GSystSet.h"
58 #include "Registry/Registry.h"
59 
60 using namespace genie;
61 using namespace genie::rew;
62 using std::ostringstream;
63 
64 static const char* kModelDipole = "genie::DipoleAxialFormFactorModel";
65 static const char* kModelZExp = "genie::ZExpAxialFormFactorModel";
66 
71 
72 //_______________________________________________________________________________________
74 {
75  this->Init();
76 }
77 //_______________________________________________________________________________________
79 {
80 #ifdef _G_REWEIGHT_CCQE_DEBUG_
81  fTestFile->cd();
82  fTestNtp ->Write();
83  fTestFile->Close();
84  delete fTestFile;
85 #endif
86 }
87 //_______________________________________________________________________________________
89 {
90 // read form factor model and compare to mode
91  bool handle;
92 
93  switch(syst) {
94 
95  case ( kXSecTwkDial_NormCCQE ) :
96  if(fMode==kModeNormAndMaShape && strcmp(fFFModel.c_str(),kModelDipole) == 0)
97  {
98  handle = true;
99  } else {
100  handle = false;
101  }
102  break;
103 
104  case ( kXSecTwkDial_MaCCQEshape ) :
105  if(fMode==kModeNormAndMaShape && strcmp(fFFModel.c_str(),kModelDipole) == 0)
106  {
107  handle = true;
108  } else {
109  handle = false;
110  }
111  break;
112 
113  case ( kXSecTwkDial_MaCCQE ) :
114  if(fMode==kModeMa && strcmp(fFFModel.c_str(),kModelDipole) == 0)
115  {
116  handle = true;
117  } else {
118  handle = false;
119  }
120  break;
121 
122  case ( kXSecTwkDial_ZNormCCQE ) :
123  if(fMode==kModeZExp && strcmp(fFFModel.c_str(),kModelZExp) == 0)
124  {
125  handle = true;
126  } else {
127  handle = false;
128  }
129  break;
130 
131  case ( kXSecTwkDial_ZExpA1CCQE ):
132  case ( kXSecTwkDial_ZExpA2CCQE ):
133  case ( kXSecTwkDial_ZExpA3CCQE ):
134  case ( kXSecTwkDial_ZExpA4CCQE ):
135  if(fMode==kModeZExp && strcmp(fFFModel.c_str(),kModelZExp) == 0)
136  {
137  handle = true;
138  } else {
139  handle = false;
140  }
141  break;
142 
143  default:
144  handle = false;
145  break;
146  }
147 
148  return handle;
149 }
150 //_______________________________________________________________________________________
151 void GReWeightNuXSecCCQE::SetSystematic(GSyst_t syst, double twk_dial)
152 {
153  if(!this->IsHandled(syst))
154  {
155  LOG("ReW",pWARN) << "Systematic " << GSyst::AsString(syst) << " is not handled for algorithm "
156  << fFFModel << " and mode " << fMode;
157  return;
158  }
159 
160  switch(syst) {
161  case ( kXSecTwkDial_NormCCQE ) :
162  case ( kXSecTwkDial_ZNormCCQE ) :
163  fNormTwkDial = twk_dial;
164  break;
165  case ( kXSecTwkDial_MaCCQEshape ) :
166  case ( kXSecTwkDial_MaCCQE ) :
167  fMaTwkDial = twk_dial;
168  break;
169  case ( kXSecTwkDial_ZExpA1CCQE ) :
170  if(fZExpMaxCoef>0){ fZExpTwkDial[0] = twk_dial; }
171  break;
172  case ( kXSecTwkDial_ZExpA2CCQE ) :
173  if(fZExpMaxCoef>1){ fZExpTwkDial[1] = twk_dial; }
174  break;
175  case ( kXSecTwkDial_ZExpA3CCQE ) :
176  if(fZExpMaxCoef>2){ fZExpTwkDial[2] = twk_dial; }
177  break;
178  case ( kXSecTwkDial_ZExpA4CCQE ) :
179  if(fZExpMaxCoef>3){ fZExpTwkDial[3] = twk_dial; }
180  break;
181  default:
182  break;
183  }
184 }
185 //_______________________________________________________________________________________
187 {
188  fNormTwkDial = 0.;
190  fMaTwkDial = 0.;
191  fMaCurr = fMaDef;
192 
193  for (int i=0;i<fZExpMaxSyst;i++)
194  {
195  fZExpTwkDial[i] = 0.;
196  fZExpCurr [i] = fZExpDef[i];
197  }
198 
199  this->Reconfigure();
200 }
201 //_______________________________________________________________________________________
203 {
205 
206  if(fMode==kModeMa && strcmp(fFFModel.c_str(),kModelDipole) == 0) {
207  int sign_matwk = utils::rew::Sign(fMaTwkDial);
208  double fracerr_ma = fracerr->OneSigmaErr(kXSecTwkDial_MaCCQE, sign_matwk);
209  fMaCurr = fMaDef * (1. + fMaTwkDial * fracerr_ma);
210  fMaCurr = TMath::Max(0., fMaCurr );
211  }
212  else
213  if(fMode==kModeNormAndMaShape && strcmp(fFFModel.c_str(),kModelDipole) == 0) {
214  int sign_normtwk = utils::rew::Sign(fNormTwkDial);
215  int sign_mashtwk = utils::rew::Sign(fMaTwkDial );
216  double fracerr_norm = fracerr->OneSigmaErr(kXSecTwkDial_NormCCQE, sign_normtwk);
217  double fracerr_mash = fracerr->OneSigmaErr(kXSecTwkDial_MaCCQEshape, sign_mashtwk);
218  fNormCurr = fNormDef * (1. + fNormTwkDial * fracerr_norm);
219  fMaCurr = fMaDef * (1. + fMaTwkDial * fracerr_mash);
220  fNormCurr = TMath::Max(0., fNormCurr);
221  fMaCurr = TMath::Max(0., fMaCurr );
222  }
223  else
224  if(fMode==kModeZExp && strcmp(fFFModel.c_str(),kModelZExp) == 0) {
225  int sign_twk = 0;
226  int sign_normtwk = utils::rew::Sign(fNormTwkDial);
227  double fracerr_zexp = 0.;
228  double fracerr_norm = fracerr->OneSigmaErr(kXSecTwkDial_ZNormCCQE, sign_normtwk);
229  GSyst_t syst;
230  // loop over all indices and update each
231  for (int i=0;i<fZExpMaxCoef;i++)
232  {
233  switch(i){
234  case 0: syst = kXSecTwkDial_ZExpA1CCQE; break;
235  case 1: syst = kXSecTwkDial_ZExpA2CCQE; break;
236  case 2: syst = kXSecTwkDial_ZExpA3CCQE; break;
237  case 3: syst = kXSecTwkDial_ZExpA4CCQE; break;
238  default: return; break;
239  }
240  sign_twk = utils::rew::Sign(fZExpTwkDial[i]);
241  fracerr_zexp = fracerr->OneSigmaErr(syst, sign_twk);
242  fZExpCurr[i] = fZExpDef[i] * (1. + fZExpTwkDial[i] * fracerr_zexp);
243  }
244  fNormCurr = fNormDef * (1. + fNormTwkDial * fracerr_norm);
245  fNormCurr = TMath::Max(0., fNormCurr);
246  }
247  else {
248  return;
249  }
250 
253  {
254  r.Set(fMaPath, fMaCurr);
255  }
256  else
257  if (fMode==kModeZExp)
258  {
259  ostringstream alg_key;
260  for (int i=0;i<fZExpMaxCoef;i++)
261  {
262  alg_key.str(""); // algorithm key for each coefficient
263  alg_key << fZExpPath << "QEL-Z_A" << i+1;
264  r.Set(alg_key.str(), fZExpCurr[i]);
265  }
266  }
267  fXSecModel->Configure(r);
268 }
269 //_______________________________________________________________________________________
271 {
272  bool is_qe = event.Summary()->ProcInfo().IsQuasiElastic();
273  bool is_cc = event.Summary()->ProcInfo().IsWeakCC();
274  if(!is_qe || !is_cc) return 1.;
275 
276  bool charm = event.Summary()->ExclTag().IsCharmEvent(); // skip CCQE charm
277  if(charm) return 1.;
278 
279  int nupdg = event.Probe()->Pdg();
280  if(nupdg==kPdgNuMu && !fRewNumu ) return 1.;
281  if(nupdg==kPdgAntiNuMu && !fRewNumubar) return 1.;
282  if(nupdg==kPdgNuE && !fRewNue ) return 1.;
283  if(nupdg==kPdgAntiNuE && !fRewNuebar ) return 1.;
284 
285  if(fMode==kModeMa && strcmp(fFFModel.c_str(),kModelDipole) == 0) {
286  double wght = this->CalcWeightMa(event);
287  return wght;
288  }
289  else
290  if(fMode==kModeNormAndMaShape && strcmp(fFFModel.c_str(),kModelDipole) == 0) {
291  double wght =
292  this->CalcWeightNorm (event) *
293  this->CalcWeightMaShape (event);
294  return wght;
295  }
296  else
297  if(fMode==kModeZExp && strcmp(fFFModel.c_str(),kModelZExp) == 0) {
298  double wght =
299  this->CalcWeightNorm(event) *
300  this->CalcWeightZExp(event);
301  return wght;
302  }
303 
304  return 1.;
305 }
306 //_______________________________________________________________________________________
308 {
309  AlgId id("genie::LwlynSmithQELCCPXSec","Default");
310 
311  AlgFactory * algf = AlgFactory::Instance();
312 
313  Algorithm * algdef = algf->AdoptAlgorithm(id);
314  fXSecModelDef = dynamic_cast<XSecAlgorithmI*>(algdef);
316 
317  Algorithm * alg = algf->AdoptAlgorithm(id);
318  fXSecModel = dynamic_cast<XSecAlgorithmI*>(alg);
320 
322  fFFModel = fXSecModelConfig->GetAlg("FormFactorsAlg/AxialFormFactorModel").name;
323 
324  this->RewNue (true);
325  this->RewNuebar (true);
326  this->RewNumu (true);
327  this->RewNumubar(true);
328 
329  //this->SetMaPath("FormFactorsAlg/Ma");
330  this->SetMaPath("FormFactorsAlg/AxialFormFactorModel/QEL-Ma");
331  this->SetZExpPath("FormFactorsAlg/AxialFormFactorModel/");
332 
333  if (strcmp(fFFModel.c_str(),kModelDipole) == 0)
334  {
337  fZExpMaxCoef = 0;
338  } else
339  if (strcmp(fFFModel.c_str(),kModelZExp) == 0)
340  {
341  this->SetMode(kModeZExp);
342  fMaDef = 0.;
343  fZExpMaxCoef =
344  TMath::Min(fXSecModelConfig->GetInt(fZExpPath + "QEL-Kmax"),
345  this->fZExpMaxSyst);
346  }
347 
348  fNormTwkDial = 0.;
349  fNormDef = 1.;
351  fMaTwkDial = 0.;
352  fMaCurr = fMaDef;
353 
354  ostringstream alg_key;
355  for (int i=0;i<fZExpMaxSyst;i++)
356  {
357  alg_key.str("");
358  alg_key << fZExpPath << "QEL-Z_A" << i+1;
359  if (strcmp(fFFModel.c_str(),kModelZExp) == 0 && i < fZExpMaxCoef)
360  { fZExpDef[i] = fXSecModelConfig->GetDouble(alg_key.str()); }
361  else
362  { fZExpDef[i] = 0.; }
363  fZExpTwkDial[i] = 0.;
364  fZExpCurr [i] = fZExpDef[i];
365  }
366 
367 #ifdef _G_REWEIGHT_CCQE_DEBUG_
368  fTestFile = new TFile("./ccqe_reweight_test.root","recreate");
369  fTestNtp = new TNtupleD("testntp","","E:Q2:wght");
370 #endif
371 }
372 //_______________________________________________________________________________________
374 {
375  bool tweaked = (TMath::Abs(fNormTwkDial) > controls::kASmallNum);
376  if(!tweaked) return 1.0;
377 
378  double wght = fNormCurr;
379  return wght;
380 }
381 //_______________________________________________________________________________________
383 {
384  bool tweaked = (TMath::Abs(fMaTwkDial) > controls::kASmallNum);
385  if(!tweaked) return 1.0;
386 
387  Interaction * interaction = event.Summary();
388 
389  interaction->KinePtr()->UseSelectedKinematics();
390  interaction->SetBit(kIAssumeFreeNucleon);
391 
392  double old_xsec = event.DiffXSec();
393  double old_weight = event.Weight();
394  double new_xsec = fXSecModel->XSec(interaction, kPSQ2fE);
395  double new_weight = old_weight * (new_xsec/old_xsec);
396 
397 //LOG("ReW", pDEBUG) << "differential cross section (old) = " << old_xsec;
398 //LOG("ReW", pDEBUG) << "differential cross section (new) = " << new_xsec;
399 //LOG("ReW", pDEBUG) << "event generation weight = " << old_weight;
400 //LOG("ReW", pDEBUG) << "new weight = " << new_weight;
401 
402  interaction->KinePtr()->ClearRunningValues();
403  interaction->ResetBit(kIAssumeFreeNucleon);
404 
405  return new_weight;
406 }
407 //_______________________________________________________________________________________
409 {
410  bool tweaked = (TMath::Abs(fMaTwkDial) > controls::kASmallNum);
411  if(!tweaked) return 1.0;
412 
413  Interaction * interaction = event.Summary();
414 
415  interaction->KinePtr()->UseSelectedKinematics();
416  interaction->SetBit(kIAssumeFreeNucleon);
417 
418  double old_xsec = event.DiffXSec();
419  double old_weight = event.Weight();
420  double new_xsec = fXSecModel->XSec(interaction, kPSQ2fE);
421  double new_weight = old_weight * (new_xsec/old_xsec);
422 
423 //LOG("ReW", pDEBUG) << "differential cross section (old) = " << old_xsec;
424 //LOG("ReW", pDEBUG) << "differential cross section (new) = " << new_xsec;
425 //LOG("ReW", pDEBUG) << "event generation weight = " << old_weight;
426 //LOG("ReW", pDEBUG) << "new weight = " << new_weight;
427 
428 //double old_integrated_xsec = event.XSec();
429  double old_integrated_xsec = fXSecModelDef -> Integral(interaction);
430  double new_integrated_xsec = fXSecModel -> Integral(interaction);
431  assert(new_integrated_xsec > 0);
432  new_weight *= (old_integrated_xsec/new_integrated_xsec);
433 
434 //LOG("ReW", pDEBUG) << "integrated cross section (old) = " << old_integrated_xsec;
435 //LOG("ReW", pDEBUG) << "integrated cross section (new) = " << new_integrated_xsec;
436 //LOG("ReW", pDEBUG) << "new weight (normalized to const integral) = " << new_weight;
437 
438  interaction->KinePtr()->ClearRunningValues();
439  interaction->ResetBit(kIAssumeFreeNucleon);
440 
441 #ifdef _G_REWEIGHT_CCQE_DEBUG_
442  double E = interaction->InitState().ProbeE(kRfHitNucRest);
443  double Q2 = interaction->Kine().Q2(true);
444  fTestNtp->Fill(E,Q2,new_weight);
445 #endif
446 
447  return new_weight;
448 }
449 //_______________________________________________________________________________________
451 {
452  // very similar to CalcWeightMa
453  bool tweaked = false;
454  for (int i=0;i<fZExpMaxCoef;i++)
455  {
456  tweaked = tweaked || (TMath::Abs(fZExpTwkDial[i]) > controls::kASmallNum);
457  }
458  if(!tweaked) { return 1.0; }
459 
460  Interaction * interaction = event.Summary();
461 
462  interaction->KinePtr()->UseSelectedKinematics();
463  interaction->SetBit(kIAssumeFreeNucleon);
464 
465  double old_xsec = event.DiffXSec();
466  double old_weight = event.Weight();
467  double new_xsec = fXSecModel->XSec(interaction, kPSQ2fE);
468  double new_weight = old_weight * (new_xsec/old_xsec);
469 
470  interaction->KinePtr()->ClearRunningValues();
471  interaction->ResetBit(kIAssumeFreeNucleon);
472 
473  return new_weight;
474 }
475 //_______________________________________________________________________________________
476 
virtual const Registry & GetConfig(void) const
Get configuration registry.
Definition: Algorithm.h:63
Cross Section Calculation Interface.
bool fRewNuebar
reweight nu_e_bar CC?
tweak Z-expansion coefficient 1, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Definition: GSyst.h:157
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
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
tweak CCQE normalization (energy independent)
Definition: GSyst.h:49
string fMaPath
M_{A} path in config Registry.
Algorithm abstract base class.
Definition: Algorithm.h:48
double CalcWeightZExp(const EventRecord &event)
RgDbl GetDouble(RgKey key) const
Definition: Registry.cxx:488
double fZExpCurr[fZExpMaxSyst]
array of current parameter values
RgInt GetInt(RgKey key) const
Definition: Registry.cxx:481
bool fRewNumubar
reweight nu_mu_bar CC?
XSecAlgorithmI * fXSecModelDef
default model
double OneSigmaErr(GSyst_t syst, int sign=0) const
tweak Z-expansion coefficient 4, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Definition: GSyst.h:160
Summary information for an interaction.
Definition: Interaction.h:53
void UseSelectedKinematics(void)
Definition: Kinematics.cxx:369
double CalcWeightMaShape(const EventRecord &event)
Registry * fXSecModelConfig
config in tweaked model
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:87
tweak Z-expansion coefficient 3, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Definition: GSyst.h:159
tweak Z-expansion coefficient 2, affects dsigma(CCQE)/dQ2 both in shape and normalization ...
Definition: GSyst.h:158
const Kinematics & Kine(void) const
Definition: Interaction.h:68
virtual void Configure(const Registry &config)
Configure the algorithm.
Definition: Algorithm.cxx:70
void SetSystematic(GSyst_t syst, double val)
update the value for the specified nuisance param
tweak Z-expansion CCQE normalization (energy independent)
Definition: GSyst.h:156
static const double kASmallNum
Definition: Controls.h:40
An enumeration of systematic parameters.
void AdoptSubstructure(void)
Definition: Algorithm.cxx:287
static const char * kModelZExp
double CalcWeightMa(const EventRecord &event)
Algorithm * AdoptAlgorithm(const AlgId &algid) const
Definition: AlgFactory.cxx:127
const int kPdgAntiNuMu
Definition: PDGCodes.h:28
void Reconfigure(void)
propagate updated nuisance parameter values to actual MC, etc
#define pWARN
Definition: Messenger.h:51
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
Algorithm ID (algorithm name + configuration set name)
Definition: AlgId.h:35
static AlgFactory * Instance()
Definition: AlgFactory.cxx:75
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:66
tweak Ma CCQE, affects dsigma(CCQE)/dQ2 both in shape and normalization
Definition: GSyst.h:52
const UInt_t kIAssumeFreeNucleon
Definition: Interaction.h:46
static string AsString(GSyst_t syst)
Definition: GSyst.h:175
string fZExpPath
algorithm path to get coefficients
int fMode
0: Ma, 1: Norm and MaShape, 2: Z-Expansion
bool fRewNumu
reweight nu_mu CC?
const InitialState & InitState(void) const
Definition: Interaction.h:66
static GSystUncertainty * Instance(void)
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
XSecAlgorithmI * fXSecModel
tweaked model
int fZExpMaxCoef
max number of coefficients to use
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...
tweak Ma CCQE, affects dsigma(CCQE)/dQ2 in shape only (normalized to constant integral) ...
Definition: GSyst.h:51
double CalcWeight(const EventRecord &event)
calculate a weight for the input event using the current nuisance param values
double CalcWeightNorm(const EventRecord &event)
RgAlg GetAlg(RgKey key) const
Definition: Registry.cxx:502
void Reset(void)
set all nuisance parameters to default values
Event finding and building.
static const int fZExpMaxSyst
maximum number of systematics
bool IsHandled(GSyst_t syst)
does the current weight calculator handle the input nuisance param?
int Sign(double twkdial)
static const char * kModelDipole