XSecAlgorithmMap.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2019, The GENIE 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 - May 13, 2005
9 
10  For the class documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13 
14 */
15 //____________________________________________________________________________
16 
25 
26 using std::endl;
27 using namespace genie;
28 
29 //____________________________________________________________________________
30 namespace genie {
31  ostream & operator << (ostream & stream, const XSecAlgorithmMap & intl)
32  {
33  intl.Print(stream);
34  return stream;
35  }
36 }
37 //___________________________________________________________________________
39 map<string, const XSecAlgorithmI *> ()
40 {
41  this->Init();
42 }
43 //___________________________________________________________________________
45 map<string, const XSecAlgorithmI *> ()
46 {
47  this->Copy(xsmap);
48 }
49 //___________________________________________________________________________
51 {
52  this->CleanUp();
53 }
54 //___________________________________________________________________________
56 {
57  this->CleanUp();
58  this->Init();
59 }
60 //___________________________________________________________________________
62 {
64 
67 }
68 //___________________________________________________________________________
70 {
71  delete fInitState;
72  delete fInteractionList;
73 
74  this->clear();
75 }
76 //___________________________________________________________________________
78 {
80 
81  fInitState -> Copy (*xsmap.fInitState);
83 
84  this->clear();
85 
86  XSecAlgorithmMap::const_iterator iter;
87 
88  for(iter = xsmap.begin(); iter != xsmap.end(); ++iter) {
89  string code = iter->first;
90  const XSecAlgorithmI * alg = iter->second;
91 
92  this->insert(map<string, const XSecAlgorithmI *>::value_type(code,alg));
93  }
94 }
95 //___________________________________________________________________________
97 {
99 }
100 //___________________________________________________________________________
101 void XSecAlgorithmMap::BuildMap(const InitialState & init_state)
102 {
103  LOG("XSecAlgMap", pNOTICE)
104  << "Building 'interaction' -> 'xsec algorithm' associations";
105  LOG("XSecAlgMap", pNOTICE)
106  << "Using all simulated interactions for init-state: "
107  << init_state.AsString();
108  if(!fEventGeneratorList) {
109  LOG("XSecAlgMap", pWARN)
110  << "No EventGeneratorList was loaded. Will not build XSecAlgorithmMap";
111  return;
112  }
113 
114  fInitState->Copy(init_state);
115 
116  EventGeneratorList::const_iterator evgliter; // event generator list iter
117  InteractionList::iterator intliter; // interaction list iter
118 
119  // loop over all EventGenerator objects used in the current job
120  for(evgliter = fEventGeneratorList->begin();
121  evgliter != fEventGeneratorList->end(); ++evgliter) {
122  // current EventGenerator
123  const EventGeneratorI * evgen = *evgliter;
124  assert(evgen);
125 
126  // ask the event generator to produce a list of all interaction it can
127  // generate for the input initial state
128  LOG("XSecAlgMap", pNOTICE)
129  << "Querying [" << evgen->Id().Key() << "] for its InteractionList";
130 
131  const InteractionListGeneratorI * ilstgen = evgen->IntListGenerator();
132  InteractionList * ilst = ilstgen->CreateInteractionList(init_state);
133 
134  // no point to go on if the list is NULL - continue to next iteration
135  if(!ilst) continue;
136 
137  // append the new InteractionList to the local copy
138  fInteractionList->Append(*ilst);
139 
140  // cross section algorithm used by this EventGenerator
141  const XSecAlgorithmI * xsec_alg = evgen->CrossSectionAlg();
142 
143  // loop over all interaction that can be genererated by the current
144  // EventGenerator and link all of them to the current XSecAlgorithmI
145  for(intliter = ilst->begin(); intliter != ilst->end(); ++intliter)
146  {
147  // current interaction
148  Interaction * interaction = *intliter;
149  string code = interaction->AsString();
150 
151  // link with the xsec algorithm
152  SLOG("XSecAlgMap", pINFO)
153  << "\nLinking: " << code
154  << "\n --> with xsec algorithm: " << xsec_alg->Id().Key();
155  this->insert(
156  map<string, const XSecAlgorithmI *>::value_type(code,xsec_alg));
157 
158  } // loop over interactions
159  delete ilst;
160  ilst = 0;
161  } // loop over event generators
162 }
163 //___________________________________________________________________________
165  const Interaction * interaction) const
166 {
167  if(!interaction) {
168  LOG("XSecAlgMap", pWARN) << "Null interaction!!";
169  return 0;
170  }
171 
172  string code = interaction->AsString();
173 
174  XSecAlgorithmMap::const_iterator xsec_alg_iter = this->find(code);
175  if(xsec_alg_iter == this->end()) {
176  LOG("XSecAlgMap", pWARN)
177  << "No XSecAlgorithmI was found for interaction: \n" << code;
178  return 0;
179  }
180 
181  const XSecAlgorithmI * xsec_alg = xsec_alg_iter->second;
182  return xsec_alg;
183 }
184 //___________________________________________________________________________
186 {
187  return *fInteractionList;
188 }
189 //___________________________________________________________________________
190 void XSecAlgorithmMap::Print(ostream & stream) const
191 {
192  XSecAlgorithmMap::const_iterator iter;
193 
194  stream<< "Printing 'interaction' -> 'xsec algorithm' associations" << endl;
195 
196  for(iter = this->begin(); iter != this->end(); ++iter) {
197  string code = iter->first;
198  const XSecAlgorithmI * alg = iter->second;
199  if(alg) {
200  stream << code << " -> " << alg->Id().Key() << endl;
201  } else {
202  stream << code << " -> **** NULL XSEC ALGORITHM ****" << endl;
203  }
204  }
205 }
206 //___________________________________________________________________________
208 {
209  this->Copy(xs);
210  return (*this);
211 }
212 //___________________________________________________________________________
213 
214 
Cross Section Calculation Interface.
XSecAlgorithmMap & operator=(const XSecAlgorithmMap &xsmap)
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
const InteractionList & GetInteractionList(void) const
Defines the InteractionListGeneratorI interface. Concrete implementations of this interface generate ...
virtual const InteractionListGeneratorI * IntListGenerator(void) const =0
const EventGeneratorList * fEventGeneratorList
vector< vector< double > > clear
Defines the EventGeneratorI interface.
string AsString(void) const
void Copy(const XSecAlgorithmMap &xsmap)
void BuildMap(const InitialState &init_state)
Summary information for an interaction.
Definition: Interaction.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
An Interaction -> XSecAlgorithmI associative container. The container is being built for the loaded E...
const XSecAlgorithmI * FindXSecAlgorithm(const Interaction *in) const
void Copy(const InitialState &init_state)
void UseGeneratorList(const EventGeneratorList *list)
string AsString(void) const
#define pINFO
Definition: Messenger.h:63
void Print(ostream &stream) const
virtual InteractionList * CreateInteractionList(const InitialState &init) const =0
#define pWARN
Definition: Messenger.h:61
virtual const XSecAlgorithmI * CrossSectionAlg(void) const =0
Definition: inftrees.h:24
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition: Algorithm.h:98
void Append(const InteractionList &intl)
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
InteractionList * fInteractionList
def insert(astring, substr, pos, overwrite=True)
assert(nhit_max >=nhit_nbins)
A vector of Interaction objects.
A vector of EventGeneratorI objects.
#define pNOTICE
Definition: Messenger.h:62
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:85
Module to generate only pions from cosmic rays.
string Key(void) const
Definition: AlgId.h:47
Initial State information.
Definition: InitialState.h:49
enum BeamMode string