GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Friends | List of all members
genie::PathLengthList Class Reference

Object to be filled with the neutrino path-length, for all detector geometry materials, when starting from a position x and travelling along the direction of the neutrino 4-momentum. More...

#include <PathLengthList.h>

Inheritance diagram for genie::PathLengthList:
Inheritance graph
[legend]
Collaboration diagram for genie::PathLengthList:
Collaboration graph
[legend]

Public Member Functions

 PathLengthList ()
 
 PathLengthList (const PDGCodeList &pdglist)
 
 PathLengthList (const PathLengthList &plist)
 
 PathLengthList (const map< int, double > &plist)
 
 ~PathLengthList ()
 
void AddPathLength (int pdgc, double pl)
 
void SetPathLength (int pdgc, double pl)
 
void SetAllToZero (void)
 
bool AreAllZero (void) const
 
void ScalePathLength (int pdgc, double scale)
 
double PathLength (int pdgc) const
 
XmlParserStatus_t LoadFromXml (string filename)
 
void SaveAsXml (string filename) const
 
void Copy (const PathLengthList &plist)
 
void Print (ostream &stream) const
 
PathLengthListoperator= (const PathLengthList &list)
 

Friends

ostream & operator<< (ostream &stream, const PathLengthList &list)
 

Detailed Description

Object to be filled with the neutrino path-length, for all detector geometry materials, when starting from a position x and travelling along the direction of the neutrino 4-momentum.

Author
Costas Andreopoulos <c.andreopoulos cern.ch> University of Liverpool
Created:
May 24, 2005
License:
Copyright (c) 2003-2024, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 42 of file PathLengthList.h.

Constructor & Destructor Documentation

PathLengthList::PathLengthList ( void  )

Definition at line 45 of file PathLengthList.cxx.

45  :
46 map<int, double>()
47 {
48 
49 }
PathLengthList::PathLengthList ( const PDGCodeList pdglist)

Definition at line 51 of file PathLengthList.cxx.

51  :
52 map<int, double>()
53 {
54  PDGCodeList::const_iterator pdg_iter;
55 
56  for(pdg_iter = pdg_list.begin(); pdg_iter != pdg_list.end(); ++pdg_iter) {
57  int pdgc = *pdg_iter;
58  this->insert( map<int, double>::value_type(pdgc, 0.) );
59  }
60 }
PathLengthList::PathLengthList ( const PathLengthList plist)

Definition at line 62 of file PathLengthList.cxx.

References Copy().

62  :
63 map<int, double>()
64 {
65  this->Copy(plist);
66 }
void Copy(const PathLengthList &plist)
PathLengthList::PathLengthList ( const map< int, double > &  plist)

Definition at line 68 of file PathLengthList.cxx.

68  :
69 map<int, double>()
70 {
71  map<int,double>::const_iterator iter;
72 
73  for(iter = plist.begin(); iter != plist.end(); ++iter) {
74  int pdgc = iter->first;
75  double pl = iter->second;
76  this->insert( map<int, double>::value_type(pdgc, pl) );
77  }
78 }
PathLengthList::~PathLengthList ( )

Definition at line 80 of file PathLengthList.cxx.

81 {
82 
83 }

Member Function Documentation

void PathLengthList::AddPathLength ( int  pdgc,
double  pl 
)

Definition at line 85 of file PathLengthList.cxx.

References LOG, and pWARN.

Referenced by genie::geometry::ROOTGeomAnalyzer::ComputePathLengths().

86 {
87 // Adds pl to the total path length for material with code = pdgc
88 
89  if (this->count(pdgc) == 1) { (*this)[pdgc] += pl; }
90  else {
91  LOG("PathL", pWARN)
92  << "No material with PDG code = " << pdgc << " in path length list";
93  }
94 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
bool PathLengthList::AreAllZero ( void  ) const

Definition at line 145 of file PathLengthList.cxx.

References genie::utils::math::AreEqual().

Referenced by GetTargetMaterial().

146 {
147  bool allzero = true;
148 
149  PathLengthList::const_iterator pl_iter;
150 
151  for(pl_iter = this->begin(); pl_iter != this->end(); ++pl_iter) {
152  double pl = pl_iter->second;
153  allzero = allzero && (utils::math::AreEqual(pl,0.));
154  }
155  return allzero;
156 }
bool AreEqual(double x1, double x2)
Definition: MathUtils.cxx:236
void PathLengthList::Copy ( const PathLengthList plist)

Definition at line 158 of file PathLengthList.cxx.

References clear.

Referenced by operator=(), and PathLengthList().

159 {
160  this->clear();
161  PathLengthList::const_iterator pl_iter;
162  for(pl_iter = plist.begin(); pl_iter != plist.end(); ++pl_iter) {
163  int pdgc = pl_iter->first;
164  double pl = pl_iter->second;
165  this->insert( map<int, double>::value_type(pdgc, pl) );
166  }
167 }
vector< vector< double > > clear
XmlParserStatus_t PathLengthList::LoadFromXml ( string  filename)

Definition at line 196 of file PathLengthList.cxx.

References clear, genie::PDGLibrary::Find(), genie::utils::xml::GetAttribute(), genie::PDGLibrary::Instance(), genie::kXmlEmpty, genie::kXmlInvalidRoot, genie::kXmlNotParsed, genie::kXmlOK, LOG, pDEBUG, pERROR, pINFO, genie::utils::str::TrimSpaces(), and genie::utils::xml::TrimSpaces().

197 {
198  this->clear();
199  PDGLibrary * pdglib = PDGLibrary::Instance();
200 
201  LOG("PathL", pINFO)
202  << "Loading PathLengthList from XML file: " << filename;
203 
204  xmlDocPtr xml_doc = xmlParseFile(filename.c_str() );
205 
206  if(xml_doc==NULL) {
207  LOG("PathL", pERROR)
208  << "XML file could not be parsed! [filename: " << filename << "]";
209  return kXmlNotParsed;
210  }
211 
212  xmlNodePtr xmlCur = xmlDocGetRootElement(xml_doc);
213 
214  if(xmlCur==NULL) {
215  LOG("PathL", pERROR)
216  << "XML doc. has null root element! [filename: " << filename << "]";
217  return kXmlEmpty;
218  }
219 
220  if( xmlStrcmp(xmlCur->name, (const xmlChar *) "path_length_list") ) {
221  LOG("PathL", pERROR)
222  << "XML doc. has invalid root element! [filename: " << filename << "]";
223  return kXmlInvalidRoot;
224  }
225 
226  LOG("PathL", pINFO) << "XML file was successfully parsed";
227 
228  xmlCur = xmlCur->xmlChildrenNode; // <path_length>'s
229 
230  // loop over all xml tree nodes that are children of the root node
231  while (xmlCur != NULL) {
232 
233  // enter everytime you find a <path_length> tag
234  if( (!xmlStrcmp(xmlCur->name, (const xmlChar *) "path_length")) ) {
235 
236  xmlNodePtr xmlPlVal = xmlCur->xmlChildrenNode;
237 
238  string spdgc = utils::str::TrimSpaces(
239  utils::xml::GetAttribute(xmlCur, "pdgc"));
240 
241  string spl = utils::xml::TrimSpaces(
242  xmlNodeListGetString(xml_doc, xmlPlVal, 1));
243 
244  LOG("PathL", pDEBUG) << "pdgc = " << spdgc << " --> pl = " << spl;
245 
246  int pdgc = atoi( spdgc.c_str() );
247  double pl = atof( spl.c_str() );
248 
249  TParticlePDG * p = pdglib->Find(pdgc);
250  if(!p) {
251  LOG("PathL", pERROR)
252  << "No particle with pdgc " << pdgc
253  << " found. Will not load its path length";
254  } else
255  this->insert( map<int, double>::value_type(pdgc, pl) );
256 
257  xmlFree(xmlPlVal);
258  }
259  xmlCur = xmlCur->next;
260  } // [end of] loop over tags within root elements
261 
262  xmlFree(xmlCur);
263  return kXmlOK;
264 }
#define pERROR
Definition: Messenger.h:59
string TrimSpaces(xmlChar *xmls)
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pINFO
Definition: Messenger.h:62
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:68
Singleton class to load &amp; serve a TDatabasePDG.
Definition: PDGLibrary.h:35
vector< vector< double > > clear
TParticlePDG * Find(int pdgc, bool must_exist=true)
Definition: PDGLibrary.cxx:86
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
#define pDEBUG
Definition: Messenger.h:63
PathLengthList & PathLengthList::operator= ( const PathLengthList list)

Definition at line 309 of file PathLengthList.cxx.

References Copy().

310 {
311  this->Copy(list);
312  return (*this);
313 }
void Copy(const PathLengthList &plist)
double PathLengthList::PathLength ( int  pdgc) const

Definition at line 121 of file PathLengthList.cxx.

References LOG, and pWARN.

Referenced by GetTargetMaterial(), genie::geometry::ROOTGeomAnalyzer::MaxPathLengthsBoxMethod(), and genie::geometry::ROOTGeomAnalyzer::MaxPathLengthsFluxMethod().

122 {
123 // Gets the total path length for material with code = pdgc to be pl
124 
125  if ( this->count(pdgc) == 1 ) {
126  map<int, double>::const_iterator pl_iter = this->find(pdgc);
127  return pl_iter->second;
128  } else {
129  LOG("PathL", pWARN)
130  << "No material with PDG code = " << pdgc << " in path length list";
131  }
132  return 0;
133 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
void PathLengthList::Print ( ostream &  stream) const

Definition at line 169 of file PathLengthList.cxx.

References genie::PDGLibrary::Find(), and genie::PDGLibrary::Instance().

Referenced by genie::operator<<().

170 {
171  stream << "\n[-]" << endl;
172 
173  PDGLibrary * pdglib = PDGLibrary::Instance();
174 
175  PathLengthList::const_iterator pl_iter;
176  size_t nc = this->size();
177 
178  for(pl_iter = this->begin(); pl_iter != this->end(); ++pl_iter) {
179 
180  int pdgc = pl_iter->first;
181  double pl = pl_iter->second; // path length
182 
183  TParticlePDG * p = pdglib->Find(pdgc);
184 
185  if(!p) {
186  stream << " |---o ** ERR: no particle with PDG code: " << pdgc;
187  } else {
188  string name = p->GetName();
189  stream << " |---o code: " << pdgc << " [" << setfill(' ')
190  << setw(5) << name << "] " << "-----> path-length = " << pl;
191  }
192  if( (--nc) > 0) stream << endl;
193  }
194 }
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:68
const char * name
Singleton class to load &amp; serve a TDatabasePDG.
Definition: PDGLibrary.h:35
TParticlePDG * Find(int pdgc, bool must_exist=true)
Definition: PDGLibrary.cxx:86
void PathLengthList::SaveAsXml ( string  filename) const

Save path length list to XML file

Definition at line 266 of file PathLengthList.cxx.

References genie::PDGLibrary::Find(), genie::PDGLibrary::Instance(), LOG, pERROR, and pINFO.

Referenced by main().

267 {
268 //! Save path length list to XML file
269 
270  LOG("PathL", pINFO)
271  << "Saving PathLengthList as XML in file: " << filename;
272 
273  PDGLibrary * pdglib = PDGLibrary::Instance();
274 
275  ofstream outxml(filename.c_str());
276  if(!outxml.is_open()) {
277  LOG("PathL", pERROR) << "Couldn't create file = " << filename;
278  return;
279  }
280  outxml << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
281  outxml << endl << endl;
282  outxml << "<!-- generated by PathLengthList::SaveAsXml() -->";
283  outxml << endl << endl;
284 
285  outxml << "<path_length_list>" << endl << endl;
286 
287  PathLengthList::const_iterator pl_iter;
288 
289  for(pl_iter = this->begin(); pl_iter != this->end(); ++pl_iter) {
290 
291  int pdgc = pl_iter->first;
292  double pl = pl_iter->second; // path length
293 
294  TParticlePDG * p = pdglib->Find(pdgc);
295 
296  outxml << " <path_length pdgc=\"" << pdgc << "\"> "
297  << setfill(' ') << setw(10) << pl << " </path_length>";
298  if ( p ) outxml << " <!-- [" << setfill(' ')
299  << setw(5) << p->GetName() << "] -->";
300  outxml << endl;
301  }
302  outxml << endl << "</path_length_list>";
303  outxml << endl;
304 
305  outxml.close();
306 
307 }
#define pERROR
Definition: Messenger.h:59
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pINFO
Definition: Messenger.h:62
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:68
Singleton class to load &amp; serve a TDatabasePDG.
Definition: PDGLibrary.h:35
TParticlePDG * Find(int pdgc, bool must_exist=true)
Definition: PDGLibrary.cxx:86
void PathLengthList::ScalePathLength ( int  pdgc,
double  scale 
)

Definition at line 107 of file PathLengthList.cxx.

References LOG, and pWARN.

Referenced by genie::geometry::ROOTGeomAnalyzer::Local2SI().

108 {
109 // Scales pl for material with code = pdgc with the input scale factor
110 
111  if (this->count(pdgc) == 1) {
112  double pl = (*this)[pdgc];
113  pl *= scale;
114  (*this)[pdgc] = pl;
115  } else {
116  LOG("PathL", pWARN)
117  << "No material with PDG code = " << pdgc << " in path length list";
118  }
119 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
void PathLengthList::SetAllToZero ( void  )

Definition at line 135 of file PathLengthList.cxx.

Referenced by genie::geometry::ROOTGeomAnalyzer::ComputeMaxPathLengths(), and genie::geometry::ROOTGeomAnalyzer::ComputePathLengths().

136 {
137  PathLengthList::const_iterator pl_iter;
138 
139  for(pl_iter = this->begin(); pl_iter != this->end(); ++pl_iter) {
140  int pdgc = pl_iter->first;
141  (*this)[pdgc] = 0.;
142  }
143 }
void PathLengthList::SetPathLength ( int  pdgc,
double  pl 
)

Definition at line 96 of file PathLengthList.cxx.

References LOG, and pWARN.

Referenced by genie::geometry::ROOTGeomAnalyzer::MaxPathLengthsBoxMethod(), and genie::geometry::ROOTGeomAnalyzer::MaxPathLengthsFluxMethod().

97 {
98 // Sets the total path length for material with code = pdgc to be pl
99 
100  if (this->count(pdgc) == 1) { (*this)[pdgc] = pl; }
101  else {
102  LOG("PathL", pWARN)
103  << "No material with PDG code = " << pdgc << " in path length list";
104  }
105 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60

Friends And Related Function Documentation

ostream& operator<< ( ostream &  stream,
const PathLengthList list 
)
friend

Definition at line 38 of file PathLengthList.cxx.

39  {
40  list.Print(stream);
41  return stream;
42  }
void Print(ostream &stream) const

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