Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
genie::MECHadronTensor Class Reference

Singleton class to load and store MEC hadron tensor tables, to aid in the implementation (and improve the CPU efficiency of) MEC cross-section models. More...

#include <MECHadronTensor.h>

Classes

struct  Cleaner
 
class  MECHadronTensorTable
 

Public Types

enum  EMECHadronTensorType {
  kMHTUndefined = -1, kMHTValenciaFullAll, kMHTValenciaFullpn, kMHTValenciaDeltaAll,
  kMHTValenciaDeltapn
}
 
typedef enum genie::MECHadronTensor::EMECHadronTensorType MECHadronTensorType_t
 

Public Member Functions

bool KnownTarget (int targetpdg)
 
bool KnownTensor (int targetpdg)
 
const vector< genie::BLI2DNonUnifGrid * > & TensorTable (int targetpdg, MECHadronTensor::MECHadronTensorType_t type)
 

Static Public Member Functions

static MECHadronTensorInstance ()
 

Private Member Functions

 MECHadronTensor ()
 
 MECHadronTensor (const MECHadronTensor &)
 
 ~MECHadronTensor ()
 
void LoadTensorTables (int targetpdg)
 
void ReadHadTensorqzq0File (string filename, int nwpoints, int nqzpoints, int nq0points, double hadtensor_w_array[][14400])
 

Private Attributes

std::map< int, MECHadronTensorTablefTargetTensorTables
 
std::vector< int > fKnownTensors
 

Static Private Attributes

static MECHadronTensorfgInstance = 0
 

Friends

struct Cleaner
 

Detailed Description

Singleton class to load and store MEC hadron tensor tables, to aid in the implementation (and improve the CPU efficiency of) MEC cross-section models.

Author
Code contributed by Jackie Schwehr Substantial refactorization by the core GENIE group.

Hadron tensors used here are those computed by the following models:

      J. Nieves, I. Ruiz Simo, M.J. Vicente Vacas,
      Inclusive quasi-elastic neutrino reactions, PRC 83 (2011) 045501

September 12, 2014

Copyright (c) 2003-2020, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 44 of file MECHadronTensor.h.

Member Typedef Documentation

Member Enumeration Documentation

Constructor & Destructor Documentation

MECHadronTensor::MECHadronTensor ( )
private

Definition at line 37 of file MECHadronTensor.cxx.

38 {
39  // This list should be abstracted to a configuration file
40  // Along with the known target method.
41 
42  // Three targets have explicit tensor tables.
43  //
44  fKnownTensors.push_back(kPdgTgtC12); // C12
45  fKnownTensors.push_back(kPdgTgtO16); // O16
46  fKnownTensors.push_back(1000140280); // Si28
47  fKnownTensors.push_back(kPdgTgtCa40); // Ca40, also for Ar40
48  fKnownTensors.push_back(1000280560); // Ni56, actually it is pseudo-Fe56
49  fKnownTensors.push_back(1000561120); // Ba112, actually it is pseudo-Cd112
50  fKnownTensors.push_back(1001042080); // Rf208, actually it is pseudo-Pb208
51  // why pseudo ? The had tensor calculation requires the nuclear density function
52  // simple two-parameter hartree fock Fermi function for heavy nuclei .
53  // and in principle modified harmonic oscillator function for light nuclei
54  // we are never really going to want isoscalar Ni56, so I used density for Fe56.
55  // likewise never want Rf208, I used the density for Pb208
56  // likewise never want Ba112, I used the density for Cd112
57 
58  // this one loads all known targets when instantiated, regardless of what the user wants.
59  // is there a point to being efficient, check if the requested one is loaded ?
60  // TODO there is a fail if the spline file is missing one of the known targets
61  // and the user requests a mix of two targets.
63  for( ; it!=fKnownTensors.end(); ++it) {
64  this->LoadTensorTables(*it);
65  // this method will fail silently if the target list here does not match later.
66  }
67  fgInstance = 0;
68 }
std::vector< int > fKnownTensors
intermediate_table::const_iterator const_iterator
const int kPdgTgtCa40
Definition: PDGCodes.h:184
const int kPdgTgtO16
Definition: PDGCodes.h:183
static MECHadronTensor * fgInstance
void LoadTensorTables(int targetpdg)
const int kPdgTgtC12
Definition: PDGCodes.h:182
genie::MECHadronTensor::MECHadronTensor ( const MECHadronTensor )
private
MECHadronTensor::~MECHadronTensor ( )
private

Definition at line 70 of file MECHadronTensor.cxx.

71 {
73  for( ; it!=fKnownTensors.end(); ++it) {
75  for(int tensorType = 0; tensorType <= MECHadronTensor::kMHTValenciaDeltapn; ++tensorType) {
76  vector<genie::BLI2DNonUnifGrid*> Grids = table.Table[(MECHadronTensor::MECHadronTensorType_t)tensorType];
77  for (vector<genie::BLI2DNonUnifGrid*>::iterator gridit = Grids.begin() ; gridit != Grids.end(); ++gridit){
78  genie::BLI2DNonUnifGrid *hadTensorGrid = *gridit;
79  if(hadTensorGrid) {
80  delete hadTensorGrid;
81  hadTensorGrid=0;
82  }
83  }
84  }
85  }
86 }
intermediate_table::iterator iterator
enum genie::MECHadronTensor::EMECHadronTensorType MECHadronTensorType_t
map< MECHadronTensor::MECHadronTensorType_t, vector< genie::BLI2DNonUnifGrid * > > Table
std::vector< int > fKnownTensors
intermediate_table::const_iterator const_iterator
std::map< int, MECHadronTensorTable > fTargetTensorTables

Member Function Documentation

MECHadronTensor * MECHadronTensor::Instance ( void  )
static

Definition at line 88 of file MECHadronTensor.cxx.

89 {
90  if(fgInstance == 0) {
91  LOG("MECHadronTensor", pDEBUG) << "Late initialization";
92  static MECHadronTensor::Cleaner cleaner;
95  }
96  return fgInstance;
97 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
static MECHadronTensor * fgInstance
#define pDEBUG
Definition: Messenger.h:63
bool MECHadronTensor::KnownTarget ( int  targetpdg)

Definition at line 99 of file MECHadronTensor.cxx.

100 {
101  if(std::count(fKnownTensors.begin(), fKnownTensors.end(), targetpdg)!=0) {
102  return true;
103  }
104 
105  // abstract these limits. They are used also in XSecFour.
106  // hard coding things in two locations isn't a good idea.
107  // also, future-person might give a had tensor and want to not allow scaling.
108 
109  int Arequest = pdg::IonPdgCodeToA(targetpdg);
110  int Zrequest = pdg::IonPdgCodeToZ(targetpdg);
111  if(Arequest >= 9 || (Arequest == 4 && Zrequest == 2)){
112  return true;
113  }
114  return false;
115 }
int IonPdgCodeToA(int pdgc)
Definition: PDGUtils.cxx:60
std::vector< int > fKnownTensors
int IonPdgCodeToZ(int pdgc)
Definition: PDGUtils.cxx:52
bool MECHadronTensor::KnownTensor ( int  targetpdg)

Definition at line 117 of file MECHadronTensor.cxx.

118 {
119  return std::count(fKnownTensors.begin(), fKnownTensors.end(), targetpdg)!=0;
120 }
std::vector< int > fKnownTensors
void MECHadronTensor::LoadTensorTables ( int  targetpdg)
private

Definition at line 128 of file MECHadronTensor.cxx.

129 {
130 // Load the hadron tensor tables.
131 // For the Nieves model they are in ${GENIE}/data/evgen/mectensor/nieves/
132 
133  // define dimensions of data in the hadron tensor files
134  int nwpoints = 5;
135  const int nq0points = 120;
136  const int nqzpoints = 120;
137  const int nq0qzpoints = nq0points*nqzpoints;
138  double arraystep = 0.01; // GeV
139  // if later we use tables that are not 120x120
140  // then extract these constants to the config file with the input table specs
141  // or find a way for the input tables to be self-descriptive.
142 
143  string tensorLocation = string("/data/evgen/mectensor/nieves");
144  string tensorFileStart = "HadTensor120-Nieves-";
145  string tensorFileEnd = "-20150210.dat";
146 
147  if(!KnownTarget(targetpdg)){
148  LOG("MECHadronTensor", pERROR)
149  << "No MEC tensor table for target with PDG code: "
150  << targetpdg;
151  return;
152  }
153 
154  // define directory of hadron tensor files
155  // Ideally, the xml configuration can override the default location
156  string data_dir = string(gSystem->Getenv("GENIE")) + tensorLocation;
157 
158  // define arrays to fill from data files
159  double hadtensor_q0_array[nq0points];
160  double hadtensor_qz_array[nqzpoints];
161  double hadtensor_w_array[nwpoints][nq0qzpoints];
162 
163  // fill q0 array (in GeV)
164  // 240 5MeV bins or 120 10 MeV bins
165  for (int a = 0; a < nq0points; a++){
166  hadtensor_q0_array[a]=double(a+1)*arraystep;
167  }
168 
169  // fill qz array (in GeV)
170  for (int a = 0; a < nqzpoints; a++){
171  hadtensor_qz_array[a]=double(a+1)*arraystep;
172  }
173 
174  // possible future feature, allow a model to not deliver Delta tensors.
175  std::map<MECHadronTensor::MECHadronTensorType_t, std::string> tensorTypeNames;
176  tensorTypeNames[MECHadronTensor::kMHTValenciaFullAll] = "FullAll";
177  tensorTypeNames[MECHadronTensor::kMHTValenciaFullpn] = "Fullpn";
178  tensorTypeNames[MECHadronTensor::kMHTValenciaDeltaAll] = "DeltaAll";
179  tensorTypeNames[MECHadronTensor::kMHTValenciaDeltapn] = "Deltapn";
180 
181  // iterate over all four hadron tensor types in the map above.
182  for(int tensorType = 0;
183  tensorType <= MECHadronTensor::kMHTValenciaDeltapn; ++tensorType) {
184 
185  // build filenames from the bits of string
186  ostringstream datafile;
187  datafile << data_dir << "/" << tensorFileStart << targetpdg << "-"
188  << tensorTypeNames[(MECHadronTensor::MECHadronTensorType_t)tensorType]
189  << tensorFileEnd;
190 
191  // make sure data files are available
192  LOG("MECHadronTensor", pDEBUG)
193  << "Asserting that file " << datafile.str().c_str() << " exists...";
194  assert (! gSystem->AccessPathName(datafile.str().c_str()));
195 
196  // read data file
198  datafile.str(), nwpoints, nqzpoints, nq0points, hadtensor_w_array
199  );
200 
201  //loop over all 5 tensors
202  for (int i = 0; i < nwpoints; i++){
203 
204  // create a non uniform grid from tensor data
205  genie::BLI2DNonUnifGrid *hadTensorGrid =
207  nqzpoints,
208  nq0points,
209  hadtensor_qz_array,
210  hadtensor_q0_array,
211  hadtensor_w_array[i]
212  );
213 
214  // and store in a map using the target PDG as a key
215  fTargetTensorTables[targetpdg].Table[
216  (MECHadronTensor::MECHadronTensorType_t)tensorType].push_back(hadTensorGrid);
217  }
218  }
219 }
#define pERROR
Definition: Messenger.h:59
std::string string
Definition: nybbler.cc:12
enum genie::MECHadronTensor::EMECHadronTensorType MECHadronTensorType_t
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void ReadHadTensorqzq0File(string filename, int nwpoints, int nqzpoints, int nq0points, double hadtensor_w_array[][14400])
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
std::map< int, MECHadronTensorTable > fTargetTensorTables
bool KnownTarget(int targetpdg)
#define pDEBUG
Definition: Messenger.h:63
void MECHadronTensor::ReadHadTensorqzq0File ( string  filename,
int  nwpoints,
int  nqzpoints,
int  nq0points,
double  hadtensor_w_array[][14400] 
)
private

Definition at line 221 of file MECHadronTensor.cxx.

224 {
225  // open file
226  std::ifstream tensor_stream(filename.c_str(), ios::in);
227 
228  // check file exists
229  if(!tensor_stream.good()){
230  LOG("MECHadronTensor", pERROR) << "Bad file name: " << filename;
231  return;
232  }
233 
234  double temp;
235  for (int ij = 0; ij < (nqzpoints*nq0points); ij++){
236  for (int k = 0; k < nwpoints; k++) {
237  tensor_stream >> temp;
238  hadtensor_w_array[k][ij]=temp;
239  }
240  }
241 }
#define pERROR
Definition: Messenger.h:59
string filename
Definition: train.py:213
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
const vector< genie::BLI2DNonUnifGrid * > & MECHadronTensor::TensorTable ( int  targetpdg,
MECHadronTensor::MECHadronTensorType_t  type 
)

Definition at line 123 of file MECHadronTensor.cxx.

124 {
125  return fTargetTensorTables[targetpdg].Table[type];
126 }
std::map< int, MECHadronTensorTable > fTargetTensorTables
static QCString type
Definition: declinfo.cpp:672

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 122 of file MECHadronTensor.h.

Member Data Documentation

MECHadronTensor * MECHadronTensor::fgInstance = 0
staticprivate

Definition at line 95 of file MECHadronTensor.h.

std::vector<int> genie::MECHadronTensor::fKnownTensors
private

Definition at line 107 of file MECHadronTensor.h.

std::map<int, MECHadronTensorTable> genie::MECHadronTensor::fTargetTensorTables
private

Definition at line 103 of file MECHadronTensor.h.


The documentation for this class was generated from the following files: