Jpp  18.4.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JOscChannel.hh
Go to the documentation of this file.
1 #ifndef __JOSCPROB__JOSCCHANNEL__
2 #define __JOSCPROB__JOSCCHANNEL__
3 
4 #include <iostream>
5 
8 
9 #include "JLang/JComparable.hh"
10 
11 #include "Jeep/JProperties.hh"
12 
13 
14 /**
15  * \author bjung
16  * \file
17  * Oscillation channels and auxiliary methods.
18  */
19 
20 namespace JOSCPROB {}
21 namespace JPP { using namespace JOSCPROB; }
22 
23 namespace JOSCPROB {
24 
26 
27 
28  /**
29  * Neutrino flavours.
30  */
31  enum class JFlavour_t { ELECTRON = 12,
32  MUON = 14,
33  TAU = 16,
34  FLAVOUR_UNDEFINED = 0 };
35 
36 
37  /**
38  * Charge parities.
39  */
40  enum class JChargeParity_t { ANTIPARTICLE = -1,
41  PARTICLE = +1,
42  CPARITY_UNDEFINED = 0 };
43 
44 
45  /**
46  * Auxiliary function for retrieving the flavour corresponding to a given PDG identifier.
47  *
48  * \param pdgType PDG particle identifier
49  */
50  inline JFlavour_t getFlavour(const int pdgType)
51  {
52  const int type = abs(pdgType);
53 
54  switch (type) {
55 
56  case (int) JFlavour_t::ELECTRON:
57  case (int) JFlavour_t::MUON:
58  case (int) JFlavour_t::TAU:
59  return static_cast<JFlavour_t>(type);
60  default:
61  return JFlavour_t::FLAVOUR_UNDEFINED;
62  }
63  }
64 
65 
66  /**
67  * Auxiliary function for retrieving the flavour of a given neutrino track.
68  *
69  * \param track neutrino track
70  */
71  inline JFlavour_t getFlavour(const Trk& track)
72  {
73  return getFlavour(track.type);
74  }
75 
76 
77  /**
78  * Auxiliary function for retrieving the charge-parity of a given PDG type.
79  *
80  * \param pdgType PDG particle identifier
81  * \return charge-parity (1 for neutrinos; -1 for anti-neutrinos)
82  */
83  inline JChargeParity_t getChargeParity(const int pdgType)
84  {
85  if (pdgType < 0) {
86  return JChargeParity_t::ANTIPARTICLE;
87  } else if (pdgType > 0) {
88  return JChargeParity_t::PARTICLE;
89  } else {
90  return JChargeParity_t::CPARITY_UNDEFINED;
91  }
92  }
93 
94 
95  /**
96  * Auxiliary function for retrieving the charge-parity of a given neutrino track.
97  *
98  * \param track neutrino track
99  * \return charge-parity (1 for neutrinos; -1 for anti-neutrinos)
100  */
101  inline JChargeParity_t getChargeParity(const Trk& track)
102  {
103  return getChargeParity(track.type);
104  }
105 
106 
107  /**
108  * Neutrino oscillation channel.
109  */
110  struct JOscChannel :
111  public JLANG::JComparable<JOscChannel>
112  {
113  /**
114  * Default constructor.
115  */
120  {}
121 
122 
123  /**
124  * Constructor.
125  *
126  * \param in input flavour
127  * \param out output flavour
128  * \param Cparity charge parity
129  */
131  const JFlavour_t out,
132  const JChargeParity_t Cparity) :
133  in (in),
134  out(out),
135  Cparity(Cparity)
136  {}
137 
138 
139  /**
140  * Constructor.
141  *
142  * \param in input flavour
143  * \param out output flavour
144  * \param Cparity charge parity
145  */
146  JOscChannel(const int in,
147  const int out,
148  const int Cparity) :
149  in (getFlavour(in)),
150  out(getFlavour(out)),
151  Cparity(getChargeParity(Cparity))
152  {}
153 
154 
155  /**
156  * Check validity of this oscillation channel.
157  *
158  * \return true if this oscillation channel is valid; else false.
159  */
160  inline bool is_valid() const
161  {
162  return (in != JFlavour_t::FLAVOUR_UNDEFINED &&
163  out != JFlavour_t::FLAVOUR_UNDEFINED &&
164  Cparity != JChargeParity_t::CPARITY_UNDEFINED);
165  }
166 
167 
168  /**
169  * Less-than method
170  *
171  * \param channel channel
172  * \return true this channel less than given channel; else false
173  */
174  inline bool less(const JOscChannel& channel) const
175  {
176  if (this->Cparity == channel.Cparity) {
177 
178  if (this->in == channel.in) {
179 
180  return this->out < channel.out;
181 
182  } else {
183 
184  return this->in < channel.in;
185  }
186 
187  } else {
188 
189  return this->Cparity < channel.Cparity;
190  }
191  }
192 
193 
194  /**
195  * Write channel to output.
196  *
197  * \param out output stream
198  * \param object oscillation channel
199  * \return output stream
200  */
201  friend inline std::ostream& operator<<(std::ostream& out, const JOscChannel& object)
202  {
203  return out << object.getProperties();
204  }
205 
206 
207  /**
208  * Read channel from input.
209  *
210  * \param in input stream
211  * \param object oscillation channel
212  * \return input stream
213  */
214  friend inline std::istream& operator>>(std::istream& in, JOscChannel& object)
215  {
216  JProperties properties(object.getProperties());
217 
218  in >> properties;
219 
220  object.setProperties(properties);
221 
222  return in;
223  }
224 
225 
226  /**
227  * Get equation parameters.
228  *
229  * \return equation parameters
230  */
232  {
233  static JEquationParameters equation("=", "\n\r;,", "./", "#");
234 
235  return equation;
236  }
237 
238 
239  /**
240  * Set equation parameters.
241  *
242  * \param equation equation parameters
243  */
244  static inline void setEquationParameters(const JEquationParameters& equation)
245  {
246  getEquationParameters() = equation;
247  }
248 
249 
250  /**
251  * Get properties of this class.
252  *
253  * \param equation equation parameters
254  */
256  {
257  return JOscChannelHelper(*this, equation);
258  }
259 
260 
261  /**
262  * Get properties of this class.
263  *
264  * \param equation equation parameters
265  */
267  {
268  return JOscChannelHelper(*this, equation);
269  }
270 
271 
272  /**
273  * Set properties of this class
274  *
275  * \param properties properties
276  */
277  void setProperties(const JProperties& properties)
278  {
279  this->in = getFlavour (properties.getValue<int>("in"));
280  this->out = getFlavour (properties.getValue<int>("out"));
281  this->Cparity = getChargeParity(properties.getValue<int>("Cparity"));
282  }
283 
284 
285  JFlavour_t in; //!< Incoming flavour
286  JFlavour_t out; //!< Outcoming flavour
287  JChargeParity_t Cparity; //!< Charge-parity
288 
289 
290  private:
291  /**
292  * Auxiliary class for I/O of oscillation channel.
293  */
295  public JProperties
296  {
297  /**
298  * Constructor.
299  *
300  * \param object oscillation channel
301  * \param equation equation parameters
302  */
303  template<class JOscChannel_t>
304  JOscChannelHelper(JOscChannel_t& object,
305  const JEquationParameters& equation) :
306  JProperties(equation, 1),
307  in ((int) object.in),
308  out ((int) object.out),
309  Cparity ((int) object.Cparity)
310  {
311  this->insert(gmake_property(in));
312  this->insert(gmake_property(out));
313  this->insert(gmake_property(Cparity));
314  }
315 
316  int in;
317  int out;
318  int Cparity;
319  };
320  };
321 
322 
323  /**
324  * Declare group of neutrino oscillation channels.
325  */
326  static const JOscChannel getOscChannel[] = {
327  JOscChannel(JFlavour_t::ELECTRON, JFlavour_t::ELECTRON, JChargeParity_t::PARTICLE),
328  JOscChannel(JFlavour_t::ELECTRON, JFlavour_t::MUON, JChargeParity_t::PARTICLE),
329  JOscChannel(JFlavour_t::ELECTRON, JFlavour_t::TAU, JChargeParity_t::PARTICLE),
330  JOscChannel(JFlavour_t::MUON, JFlavour_t::ELECTRON, JChargeParity_t::PARTICLE),
331  JOscChannel(JFlavour_t::MUON, JFlavour_t::MUON, JChargeParity_t::PARTICLE),
332  JOscChannel(JFlavour_t::MUON, JFlavour_t::TAU, JChargeParity_t::PARTICLE),
333  JOscChannel(JFlavour_t::TAU, JFlavour_t::ELECTRON, JChargeParity_t::PARTICLE),
334  JOscChannel(JFlavour_t::TAU, JFlavour_t::MUON, JChargeParity_t::PARTICLE),
335  JOscChannel(JFlavour_t::TAU, JFlavour_t::TAU, JChargeParity_t::PARTICLE),
336  JOscChannel(JFlavour_t::ELECTRON, JFlavour_t::ELECTRON, JChargeParity_t::ANTIPARTICLE),
337  JOscChannel(JFlavour_t::ELECTRON, JFlavour_t::MUON, JChargeParity_t::ANTIPARTICLE),
338  JOscChannel(JFlavour_t::ELECTRON, JFlavour_t::TAU, JChargeParity_t::ANTIPARTICLE),
339  JOscChannel(JFlavour_t::MUON, JFlavour_t::ELECTRON, JChargeParity_t::ANTIPARTICLE),
340  JOscChannel(JFlavour_t::MUON, JFlavour_t::MUON, JChargeParity_t::ANTIPARTICLE),
341  JOscChannel(JFlavour_t::MUON, JFlavour_t::TAU, JChargeParity_t::ANTIPARTICLE),
342  JOscChannel(JFlavour_t::TAU, JFlavour_t::ELECTRON, JChargeParity_t::ANTIPARTICLE),
343  JOscChannel(JFlavour_t::TAU, JFlavour_t::MUON, JChargeParity_t::ANTIPARTICLE),
344  JOscChannel(JFlavour_t::TAU, JFlavour_t::TAU, JChargeParity_t::ANTIPARTICLE)
345  };
346 
347 
348  /**
349  * Number of neutrino oscillation channels.
350  */
351  static const unsigned int NUMBER_OF_OSCCHANNELS = sizeof(getOscChannel) / sizeof(JOscChannel);
352 }
353 
354 #endif
JOscChannel(const JFlavour_t in, const JFlavour_t out, const JChargeParity_t Cparity)
Constructor.
Definition: JOscChannel.hh:130
static JEquationParameters & getEquationParameters()
Get equation parameters.
Definition: JOscChannel.hh:231
JOscChannel()
Default constructor.
Definition: JOscChannel.hh:116
Neutrino oscillation channel.
Definition: JOscChannel.hh:110
static void setEquationParameters(const JEquationParameters &equation)
Set equation parameters.
Definition: JOscChannel.hh:244
JOscChannelHelper(JOscChannel_t &object, const JEquationParameters &equation)
Constructor.
Definition: JOscChannel.hh:304
static const unsigned int NUMBER_OF_OSCCHANNELS
Number of neutrino oscillation channels.
Definition: JOscChannel.hh:351
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
friend std::ostream & operator<<(std::ostream &out, const JOscChannel &object)
Write channel to output.
Definition: JOscChannel.hh:201
JFlavour_t in
Incoming flavour.
Definition: JOscChannel.hh:285
JOscChannel(const int in, const int out, const int Cparity)
Constructor.
Definition: JOscChannel.hh:146
Utility class to parse parameter values.
Definition: JProperties.hh:497
Simple data structure to support I/O of equations (see class JLANG::JEquation).
friend std::istream & operator>>(std::istream &in, JOscChannel &object)
Read channel from input.
Definition: JOscChannel.hh:214
Utility class to parse parameter values.
void setProperties(const JProperties &properties)
Set properties of this class.
Definition: JOscChannel.hh:277
JChargeParity_t
Charge parities.
Definition: JOscChannel.hh:40
JProperties getProperties(const JEquationParameters &equation=JOscChannel::getEquationParameters())
Get properties of this class.
Definition: JOscChannel.hh:255
JChargeParity_t getChargeParity(const int pdgType)
Auxiliary function for retrieving the charge-parity of a given PDG type.
Definition: JOscChannel.hh:83
const T & getValue(const std::string &key) const
Get value.
Definition: JProperties.hh:976
static const JOscChannel getOscChannel[]
Declare group of neutrino oscillation channels.
Definition: JOscChannel.hh:326
JFlavour_t
Neutrino flavours.
Definition: JOscChannel.hh:31
JChargeParity_t Cparity
Charge-parity.
Definition: JOscChannel.hh:287
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:24
Auxiliary class for I/O of oscillation channel.
Definition: JOscChannel.hh:294
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
JProperties getProperties(const JEquationParameters &equation=JOscChannel::getEquationParameters()) const
Get properties of this class.
Definition: JOscChannel.hh:266
JFlavour_t out
Outcoming flavour.
Definition: JOscChannel.hh:286
JFlavour_t getFlavour(const int pdgType)
Auxiliary function for retrieving the flavour corresponding to a given PDG identifier.
Definition: JOscChannel.hh:50
bool less(const JOscChannel &channel) const
Less-than method.
Definition: JOscChannel.hh:174
bool is_valid() const
Check validity of this oscillation channel.
Definition: JOscChannel.hh:160