ATLAS Offline Software
Polarization.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 /* Author: Andrii Verbytskyi andrii.verbytskyi@mpp.mpg.de */
5 
6 #ifndef ATLASHEPMC_POLARIZATION_H
7 #define ATLASHEPMC_POLARIZATION_H
8 #ifdef HEPMC3
9 #include "HepMC3/GenParticle.h"
10 #include "HepMC3/Attribute.h"
11 namespace HepMC {
12 class Polarization {
13 public:
14  Polarization( const double a=0.0, const double b=0.0,
15  bool is_defined = false)
16  : m_theta(a), m_phi(b), m_is_defined(is_defined) {};
17  ~Polarization() {};
18  double theta() const { return m_theta;}
19  double phi() const { return m_phi;}
20  bool is_defined() const { return m_is_defined; }
21  inline bool operator ==(const Polarization &a) const { return (std::abs(a.phi() - phi()) <= 0.00001) && (std::abs(a.theta() - theta()) <= 0.00001);}
22 private:
23  double m_theta;
24  double m_phi;
25  bool m_is_defined;
26 };
28 inline Polarization polarization(const T& a) {
29  std::shared_ptr<HepMC3::DoubleAttribute> phi_A = a->template attribute<HepMC3::DoubleAttribute>("phi");
30  std::shared_ptr<HepMC3::DoubleAttribute> theta_A = a->template attribute<HepMC3::DoubleAttribute>("theta");
31  double phi = (phi_A ? phi_A->value() : 0.0);
32  double theta = (theta_A ? theta_A->value() : 0.0);
33  bool is_defined = phi_A && theta_A;
34  return Polarization(theta, phi, is_defined);
35 }
36 template<class T> inline void set_polarization( T& a, const Polarization& b) {
37  a->add_attribute("phi",std::make_shared<HepMC3::DoubleAttribute>(b.phi()));
38  a->add_attribute("theta",std::make_shared<HepMC3::DoubleAttribute>(b.theta()));
39 }
40 }
41 #else
42 #include "HepMC/Polarization.h"
43 namespace HepMC {
44 template <class T> inline void set_polarization( T& a, const Polarization& b) {
45  a->set_polarization(b);
46 }
47 template <class T> inline Polarization polarization(const T& a) {
48  return a->polarization();
49 }
50 }
51 #endif
52 #endif
operator==
bool operator==(const DataVector< T > &a, const DataVector< T > &b)
Vector equality comparison.
HepMC::polarization
Polarization polarization(const T &a)
Definition: Polarization.h:47
HepMC::set_polarization
void set_polarization(T &a, const Polarization &b)
Definition: Polarization.h:44
athena.value
value
Definition: athena.py:124
xAOD::phi
setEt phi
Definition: TrigEMCluster_v1.cxx:29
jobOption.theta
theta
Definition: jobOption.ParticleGun_fwd_sequence.py:13
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
a
TList * a
Definition: liststreamerinfos.cxx:10
HepMC
Definition: Barcode.h:14
Polarization.h