Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
43  LIGHT_FROM_MUON = 1001, //!< direct and scattered light from muon
44  LIGHT_FROM_EMSHOWERS = 1003, //!< direct and scattered light from EM showers
45  LIGHT_FROM_DELTARAYS = 1005, //!< direct and scattered light from delta-rays
46  LIGHT_FROM_EMSHOWER = 1013 //!< direct and scattered light from EM shower
47  };
48 
49 
50  static const char WILD_CARD = '%'; //!< wild card character for file name substitution
51 
52 
53  /**
54  * Get PDF label.
55  *
56  * \param pdf PDF type
57  * \return PDF label
58  */
59  inline std::string getLabel(const JPDFType_t pdf)
60  {
61  std::ostringstream os;
62 
63  os << pdf;
64 
65  return os.str();
66  }
67 
68 
69  /**
70  * Get PDF type.
71  *
72  * \param file_name file name
73  * \return PDF type (-1 in case of error)
74  */
75  inline int getPDFType(const std::string& file_name)
76  {
77  using namespace std;
78 
79  static const char* digits = "0123456789";
80 
81  int type = -1;
82 
83  string buffer = JEEP::getFilename(file_name);
84 
85  string::size_type pos = buffer.find_first_of(digits);
86 
87  if (pos != string::npos) {
88 
89  string::size_type len = buffer.substr(pos).find_first_not_of(digits);
90 
91  istringstream(buffer.substr(pos, len)) >> type;
92  }
93 
94  return type;
95  }
96 
97 
98  /**
99  * Check wild card.
100  *
101  * \param file_name file name
102  * \return true if wild card present; else false
103  */
104  inline bool hasWildCard(const std::string& file_name)
105  {
106  return (file_name.find(WILD_CARD) != std::string::npos);
107  }
108 
109 
110  /**
111  * Get PDF file name.
112  *
113  * The input file name should contain the wild card character WILD_CARD
114  * which will be replaced by the label corresponding to the given PDF type.
115  *
116  * \param file_name input file name
117  * \param pdf PDF type
118  * \return output file name
119  */
120  inline std::string getFilename(const std::string& file_name,
121  const JPDFType_t pdf)
122  {
123  using namespace std;
124 
125  string buffer = file_name;
126 
127  string::size_type pos = buffer.find(WILD_CARD);
128 
129  if (pos == string::npos) {
130  throw JException(string("Method getFilename(): Missing wild card character \'") + WILD_CARD + "\'.");
131  }
132 
133  return buffer.replace(pos, 1, getLabel(pdf));
134  }
135 
136 
137  /**
138  * Test if given PDF type corresponds to Cherenkov light from muon.
139  *
140  * \param pdf PDF type
141  * \return true if PDF corresponds to muon; else false
142  */
143  inline bool is_muon(const int pdf)
144  {
145  return (pdf == DIRECT_LIGHT_FROM_MUON ||
146  pdf == SCATTERED_LIGHT_FROM_MUON ||
147  pdf == LIGHT_FROM_MUON);
148  }
149 
150 
151  /**
152  * Test if given PDF type corresponds to Cherenkov light from Bremsstrahlung.
153  *
154  * \param pdf PDF type
155  * \return true if PDF corresponds to Bremsstrahlung; else false
156  */
157  inline bool is_bremsstrahlung(const int pdf)
158  {
159  return (pdf == DIRECT_LIGHT_FROM_EMSHOWERS ||
161  pdf == LIGHT_FROM_EMSHOWERS);
162  }
163 
164 
165  /**
166  * Test if given PDF type corresponds to Cherenkov light from delta-rays.
167  *
168  * \param pdf PDF type
169  * \return true if PDF corresponds to delta-rays; else false
170  */
171  inline bool is_deltarays(const int pdf)
172  {
173  return (pdf == DIRECT_LIGHT_FROM_DELTARAYS ||
175  pdf == LIGHT_FROM_DELTARAYS);
176  }
177 
178 
179  /**
180  * Test if given PDF type corresponds to scattered light.
181  *
182  * \param pdf PDF type
183  * \return true if PDF corresponds to scattered light; else false
184  */
185  inline bool is_scattered(const int pdf)
186  {
187  return (pdf == SCATTERED_LIGHT_FROM_MUON ||
192  }
193 }
194 
195 #endif
General exception.
Definition: JException.hh:40
Exceptions.
direct and scattered light from EM shower
Definition: JPDFTypes.hh:46
direct and scattered light from muon
Definition: JPDFTypes.hh:43
scattered light from muon
Definition: JPDFTypes.hh:38
scattered light from EM shower
Definition: JPDFTypes.hh:41
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
direct light from EM showers
Definition: JPDFTypes.hh:32
direct light from muon
Definition: JPDFTypes.hh:29
bool is_bremsstrahlung(const int pdf)
Test if given PDF type corresponds to Cherenkov light from Bremsstrahlung.
Definition: JPDFTypes.hh:157
scattered light from muon
Definition: JPDFTypes.hh:30
Auxiliary methods for handling file names, type names and environment.
scattered light from delta-rays
Definition: JPDFTypes.hh:36
direct light from EM shower
Definition: JPDFTypes.hh:40
scattered light from EM showers
Definition: JPDFTypes.hh:33
JPDFType_t
PDF types.
Definition: JPDFTypes.hh:27
std::string getLabel(const JPDFType_t pdf)
Get PDF label.
Definition: JPDFTypes.hh:59
direct light from delta-rays
Definition: JPDFTypes.hh:35
int getPDFType(const std::string &file_name)
Get PDF type.
Definition: JPDFTypes.hh:75
direct and scattered light from delta-rays
Definition: JPDFTypes.hh:45
bool is_scattered(const int pdf)
Test if given PDF type corresponds to scattered light.
Definition: JPDFTypes.hh:185
static const char WILD_CARD
Definition: JDAQTags.hh:34
direct and scattered light from EM showers
Definition: JPDFTypes.hh:44
bool is_deltarays(const int pdf)
Test if given PDF type corresponds to Cherenkov light from delta-rays.
Definition: JPDFTypes.hh:171
std::string getFilename(const std::string &file_name)
Get file name part, i.e.
Definition: JeepToolkit.hh:85
bool hasWildCard(const std::string &file_name)
Check wild card.
Definition: JPDFTypes.hh:104