GReWeightNuXSecHelper.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  Author: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
8  University of Liverpool & STFC Rutherford Appleton Lab
9 
10  For the class documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13  @ Oct 09, 2007 - CA
14  This file was added in 2.0.1
15  @ Sep 08, 2009 - CA
16  Renamed from ReWeightCrossSection to GReWeightNuXSecHelper and included in
17  the genie::rew namespace. Integrated with new event reweighting framework.
18  @ Apr 27, 2010 - CA
19  Added option to reweight differential cross sections normalizing to a const
20  integral (shape only effect of tweaked physics parameter)
21 */
22 //____________________________________________________________________________
23 
24 #include "Algorithm/AlgCmp.h"
25 #include "Base/XSecAlgorithmI.h"
28 #include "EVGCore/EventRecord.h"
29 #include "EVGDrivers/GEVGDriver.h"
32 #include "Messenger/Messenger.h"
33 
34 using namespace genie;
35 using namespace genie::rew;
36 
37 //___________________________________________________________________________
39 {
40  this->Initialize();
41 }
42 //___________________________________________________________________________
44 {
45 
46 }
47 //___________________________________________________________________________
49 {
54 }
55 //___________________________________________________________________________
57 {
58  // form initial state filtering out any unwanted info
59  InitialState init_state(is.TgtPdg(), is.ProbePdg());
60 
61  // check for an event generation configured for that initial state
62  GEVGDriver * evg_driver = fGPool.FindDriver(init_state);
63 
64  // if none was found then create/configure/store one now
65  if(!evg_driver) {
66  LOG("ReW", pNOTICE)
67  << "Adding event generation driver for initial state = "
68  << init_state.AsString();
69  evg_driver = new GEVGDriver;
70  evg_driver->Configure(init_state);
71  fGPool.insert( GEVGPool::value_type(init_state.AsString(), evg_driver) );
72  }
73 }
74 //___________________________________________________________________________
77 {
78  fCrossSecModelPhSp.insert(
79  map<ScatteringType_t,KinePhaseSpace_t>::value_type(sct,kps));
80 }
81 //___________________________________________________________________________
83  const EventRecord & event, bool shape_only)
84 {
85  // Get event summary (Interaction) from the input event
86  assert(event.Summary());
87  Interaction & interaction = * event.Summary();
88 
89  //LOG("ReW", pDEBUG) << "Computing new weight for: \n" << interaction;
90 
91  // Find the event generation driver that handles the given initial state
92  const InitialState & init_state = interaction.InitState();
93  GEVGDriver * evg_driver = fGPool.FindDriver(init_state);
94  if(!evg_driver) {
95  LOG("ReW", pINFO)
96  << "Adding generator driver for init state: " << init_state.AsString();
97  evg_driver = new GEVGDriver;
98  evg_driver->Configure(init_state);
99  fGPool.insert( GEVGPool::value_type(init_state.AsString(), evg_driver) );
100  }
101  assert(evg_driver);
102 
103  // Find the event generation thread that handles the given interaction
104  const EventGeneratorI * evg_thread = evg_driver->FindGenerator(&interaction);
105  if(!evg_thread) {
106  LOG("ReW", pERROR)
107  << "No event generator thread for interaction: " << interaction;
108  return 0;
109  }
110 
111  // Get the cross section model associated with that thread
112  const XSecAlgorithmI * xsec_model = evg_thread->CrossSectionAlg();
113  if(!xsec_model) {
114  LOG("ReW", pERROR)
115  << "No cross section model for interaction: " << interaction;
116  return 0;
117  }
118 
119  // Get the kinematical phase space used for computing the differential
120  // cross sections stored in the event
121  ScatteringType_t sct = interaction.ProcInfo().ScatteringTypeId();
123  kpsi = fCrossSecModelPhSp.find(sct);
124 
125  if(kpsi == fCrossSecModelPhSp.end()) return 1;
126  KinePhaseSpace_t kps = kpsi->second;
127  if(kps==kPSNull) return 1;
128 
129  // Copy the 'selected' kinematics into the 'running' kinematics
130  interaction.KinePtr()->UseSelectedKinematics();
131 
132  // hack to match what was stored during event generation
133  // -- is currently revisited --
134  if(interaction.ProcInfo().IsQuasiElastic())
135  interaction.SetBit(kIAssumeFreeNucleon);
136 
137  double old_xsec = event.DiffXSec();
138  double old_weight = event.Weight();
139  double new_xsec = xsec_model->XSec(&interaction,kps);
140  double new_weight = old_weight * (new_xsec/old_xsec);
141 
142  if(shape_only) {
143  double old_integrated_xsec = event.XSec();
144  double new_integrated_xsec = xsec_model->Integral(&interaction);
145  assert(new_integrated_xsec > 0);
146  new_weight *= (old_integrated_xsec/new_integrated_xsec);
147  }
148 
149  // hack - closing parenthesis
150  if(interaction.ProcInfo().IsQuasiElastic())
151  interaction.ResetBit(kIAssumeFreeNucleon);
152 
153  // Clear the 'running' kinematics buffer
154  interaction.KinePtr()->ClearRunningValues();
155 
156  LOG("ReW", pINFO)
157  << "Event d{xsec}/dK : " << old_xsec << " --> " << new_xsec;
158  LOG("ReW", pINFO)
159  << "Event weight : " << old_weight << " ---> " << new_weight;
160 
161  return new_weight;
162 }
163 //___________________________________________________________________________
164 
Cross Section Calculation Interface.
#include "Numerical/GSFunc.h"
Definition: AlgCmp.h:26
#define pERROR
Definition: Messenger.h:50
virtual Interaction * Summary(void) const
Definition: GHepRecord.cxx:135
virtual double XSec(const Interaction *i, KinePhaseSpace_t k=kPSfE) const =0
Compute the cross section for the input interaction.
const EventGeneratorI * FindGenerator(const Interaction *interaction) const
Definition: GEVGDriver.cxx:393
Defines the EventGeneratorI interface.
GEVGDriver * FindDriver(const InitialState &init) const
Definition: GEVGPool.cxx:50
enum genie::EKinePhaseSpace KinePhaseSpace_t
Summary information for an interaction.
Definition: Interaction.h:53
void DiffCrossSecType(ScatteringType_t sct, KinePhaseSpace_t kps)
#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
virtual double Integral(const Interaction *i) const =0
int ProbePdg(void) const
Definition: InitialState.h:54
string AsString(void) const
GENIE Event Generation Driver. A minimalist user interface object for generating neutrino interaction...
Definition: GEVGDriver.h:55
#define pINFO
Definition: Messenger.h:53
virtual const XSecAlgorithmI * CrossSectionAlg(void) const =0
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
enum genie::EScatteringType ScatteringType_t
const UInt_t kIAssumeFreeNucleon
Definition: Interaction.h:46
int TgtPdg(void) const
void Configure(int nu_pdgc, int Z, int A)
Definition: GEVGDriver.cxx:173
#define pNOTICE
Definition: Messenger.h:52
map< ScatteringType_t, KinePhaseSpace_t > fCrossSecModelPhSp
double NewWeight(const EventRecord &event, bool shape_only=false)
Event finding and building.
void HandleInitState(const InitialState &init_state)
Initial State information.
Definition: InitialState.h:42