Jpp
JPDFTypes.hh
Go to the documentation of this file.
1 #ifndef __JPHYSICS__JPDFTYPES__
2 #define __JPHYSICS__JPDFTYPES__
3 
4 #include <string>
5 #include <sstream>
6 
7 #include "JLang/JException.hh"
8 #include "Jeep/JeepToolkit.hh"
9 
10 /**
11  * \file
12  *
13  * Numbering scheme for PDF types.
14  * \author mdejong
15  */
16 namespace JPHYSICS {}
17 namespace JPP { using namespace JPHYSICS; }
18 
19 namespace JPHYSICS {
20 
21  using JLANG::JException;
22 
23 
24  /**
25  * PDF types
26  */
27  enum JPDFType_t {
28 
29  DIRECT_LIGHT_FROM_MUON = 1, //!< direct light from muon
30  SCATTERED_LIGHT_FROM_MUON = 2, //!< scattered light from muon
31 
32  DIRECT_LIGHT_FROM_EMSHOWERS = 3, //!< direct light from EM showers
33  SCATTERED_LIGHT_FROM_EMSHOWERS = 4, //!< scattered light from EM showers
34 
35  DIRECT_LIGHT_FROM_DELTARAYS = 5, //!< direct light from delta-rays
36  SCATTERED_LIGHT_FROM_DELTARAYS = 6, //!< scattered light from delta-rays
37 
38  SCATTERED_LIGHT_FROM_MUON_5D = 12, //!< scattered light from muon
39 
40  DIRECT_LIGHT_FROM_EMSHOWER = 13, //!< direct light from EM shower
41  SCATTERED_LIGHT_FROM_EMSHOWER = 14, //!< scattered light from EM shower
42  DIRECT_LIGHT_FROM_SHOWER = 15, //!< direct + scattered light from HADRONIC shower
43 
44  LIGHT_FROM_MUON = 1001, //!< direct and scattered light from muon
45  LIGHT_FROM_EMSHOWERS = 1003, //!< direct and scattered light from EM showers
46  LIGHT_FROM_DELTARAYS = 1005, //!< direct and scattered light from delta-rays
47  LIGHT_FROM_EMSHOWER = 1013 //!< direct and scattered light from EM shower
48  };
49 
50 
51  static const char WILD_CARD = '%'; //!< wild card character for file name substitution
52 
53 
54  /**
55  * Get PDF label.
56  *
57  * \param pdf PDF type
58  * \return PDF label
59  */
60  inline std::string getLabel(const JPDFType_t pdf)
61  {
62  std::ostringstream os;
63 
64  os << pdf;
65 
66  return os.str();
67  }
68 
69 
70  /**
71  * Get PDF type.
72  *
73  * \param file_name file name
74  * \return PDF type (-1 in case of error)
75  */
76  inline int getPDFType(const std::string& file_name)
77  {
78  using namespace std;
79 
80  static const char* digits = "0123456789";
81 
82  int type = -1;
83 
84  string buffer = JEEP::getFilename(file_name);
85 
86  string::size_type pos = buffer.find_first_of(digits);
87 
88  if (pos != string::npos) {
89 
90  string::size_type len = buffer.substr(pos).find_first_not_of(digits);
91 
92  istringstream(buffer.substr(pos, len)) >> type;
93  }
94 
95  return type;
96  }
97 
98 
99  /**
100  * Check wild card.
101  *
102  * \param file_name file name
103  * \return true if wild card present; else false
104  */
105  inline bool hasWildCard(const std::string& file_name)
106  {
107  return (file_name.find(WILD_CARD) != std::string::npos);
108  }
109 
110 
111  /**
112  * Get PDF file name.
113  *
114  * The input file name should contain the wild card character WILD_CARD
115  * which will be replaced by the label corresponding to the given PDF type.
116  *
117  * \param file_name input file name
118  * \param pdf PDF type
119  * \return output file name
120  */
121  inline std::string getFilename(const std::string& file_name,
122  const JPDFType_t pdf)
123  {
124  using namespace std;
125 
126  string buffer = file_name;
127 
128  string::size_type pos = buffer.find(WILD_CARD);
129 
130  if (pos == string::npos) {
131  throw JException(string("Method getFilename(): Missing wild card character \'") + WILD_CARD + "\'.");
132  }
133 
134  return buffer.replace(pos, 1, getLabel(pdf));
135  }
136 
137 
138  /**
139  * Test if given PDF type corresponds to Cherenkov light from muon.
140  *
141  * \param pdf PDF type
142  * \return true if PDF corresponds to muon; else false
143  */
144  inline bool is_muon(const int pdf)
145  {
146  return (pdf == DIRECT_LIGHT_FROM_MUON ||
147  pdf == SCATTERED_LIGHT_FROM_MUON ||
148  pdf == LIGHT_FROM_MUON);
149  }
150 
151 
152  /**
153  * Test if given PDF type corresponds to Cherenkov light from Bremsstrahlung.
154  *
155  * \param pdf PDF type
156  * \return true if PDF corresponds to Bremsstrahlung; else false
157  */
158  inline bool is_bremsstrahlung(const int pdf)
159  {
160  return (pdf == DIRECT_LIGHT_FROM_EMSHOWERS ||
162  pdf == LIGHT_FROM_EMSHOWERS);
163  }
164 
165 
166  /**
167  * Test if given PDF type corresponds to Cherenkov light from delta-rays.
168  *
169  * \param pdf PDF type
170  * \return true if PDF corresponds to delta-rays; else false
171  */
172  inline bool is_deltarays(const int pdf)
173  {
174  return (pdf == DIRECT_LIGHT_FROM_DELTARAYS ||
176  pdf == LIGHT_FROM_DELTARAYS);
177  }
178 
179 
180  /**
181  * Test if given PDF type corresponds to scattered light.
182  *
183  * \param pdf PDF type
184  * \return true if PDF corresponds to scattered light; else false
185  */
186  inline bool is_scattered(const int pdf)
187  {
188  return (pdf == SCATTERED_LIGHT_FROM_MUON ||
193  }
194 }
195 
196 #endif
JPHYSICS::getFilename
std::string getFilename(const std::string &file_name, const JPDFType_t pdf)
Get PDF file name.
Definition: JPDFTypes.hh:121
JException.hh
JPHYSICS::DIRECT_LIGHT_FROM_DELTARAYS
direct light from delta-rays
Definition: JPDFTypes.hh:35
JPHYSICS::LIGHT_FROM_EMSHOWER
direct and scattered light from EM shower
Definition: JPDFTypes.hh:47
JPHYSICS::is_deltarays
bool is_deltarays(const int pdf)
Test if given PDF type corresponds to Cherenkov light from delta-rays.
Definition: JPDFTypes.hh:172
JPHYSICS::DIRECT_LIGHT_FROM_SHOWER
direct + scattered light from HADRONIC shower
Definition: JPDFTypes.hh:42
JPHYSICS::DIRECT_LIGHT_FROM_EMSHOWER
direct light from EM shower
Definition: JPDFTypes.hh:40
JPHYSICS
Auxiliary classes and methods for calculation of PDF and muon energy loss.
Definition: JAbstractMedium.hh:9
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JPHYSICS::getPDFType
int getPDFType(const std::string &file_name)
Get PDF type.
Definition: JPDFTypes.hh:76
JPHYSICS::LIGHT_FROM_EMSHOWERS
direct and scattered light from EM showers
Definition: JPDFTypes.hh:45
JPHYSICS::SCATTERED_LIGHT_FROM_EMSHOWER
scattered light from EM shower
Definition: JPDFTypes.hh:41
JPHYSICS::hasWildCard
bool hasWildCard(const std::string &file_name)
Check wild card.
Definition: JPDFTypes.hh:105
JPHYSICS::is_bremsstrahlung
bool is_bremsstrahlung(const int pdf)
Test if given PDF type corresponds to Cherenkov light from Bremsstrahlung.
Definition: JPDFTypes.hh:158
JEEP::getFilename
std::string getFilename(const std::string &file_name)
Get file name part, i.e.
Definition: JeepToolkit.hh:86
JPHYSICS::getLabel
std::string getLabel(const JPDFType_t pdf)
Get PDF label.
Definition: JPDFTypes.hh:60
JPHYSICS::SCATTERED_LIGHT_FROM_EMSHOWERS
scattered light from EM showers
Definition: JPDFTypes.hh:33
JPHYSICS::SCATTERED_LIGHT_FROM_MUON_5D
scattered light from muon
Definition: JPDFTypes.hh:38
JPHYSICS::LIGHT_FROM_MUON
direct and scattered light from muon
Definition: JPDFTypes.hh:44
JPHYSICS::JPDFType_t
JPDFType_t
PDF types.
Definition: JPDFTypes.hh:27
JPHYSICS::LIGHT_FROM_DELTARAYS
direct and scattered light from delta-rays
Definition: JPDFTypes.hh:46
JPHYSICS::is_scattered
bool is_scattered(const int pdf)
Test if given PDF type corresponds to scattered light.
Definition: JPDFTypes.hh:186
std
Definition: jaanetDictionary.h:36
JPHYSICS::WILD_CARD
static const char WILD_CARD
wild card character for file name substitution
Definition: JPDFTypes.hh:51
JeepToolkit.hh
JPHYSICS::DIRECT_LIGHT_FROM_MUON
direct light from muon
Definition: JPDFTypes.hh:29
JPHYSICS::is_muon
bool is_muon(const int pdf)
Test if given PDF type corresponds to Cherenkov light from muon.
Definition: JPDFTypes.hh:144
JPHYSICS::DIRECT_LIGHT_FROM_EMSHOWERS
direct light from EM showers
Definition: JPDFTypes.hh:32
JPHYSICS::SCATTERED_LIGHT_FROM_DELTARAYS
scattered light from delta-rays
Definition: JPDFTypes.hh:36
JLANG::JException
General exception.
Definition: JException.hh:40
JPHYSICS::SCATTERED_LIGHT_FROM_MUON
scattered light from muon
Definition: JPDFTypes.hh:30