Skip to content

Remove wrongly used HepMC::Polarization

Andrii Verbytskyi requested to merge averbyts/athena:remove_norm3d into master

In this MR:

  • replace complicated manipulations with polarization with a clear code. This also assures HePMC3 compatibility.

A bit detailed explanation for a potentially curious shifter:

Let us look at the following code:

 	             double polX, polY, polZ;	
	             HepMC::Polarization pol(0.0,0.0);
	             polX = polY = polZ = 0.0;
	             HepMC::Polarization pol;
	             pol.set_normal3d( HepGeom::Normal3D<double>( polX, polY, polZ ) );

In the end the last line is equivalent to

pol.set_normal3d( HepMC::ThreeVector(0.0, 0.0, 0.0));

Where ThreeVector appears via a templated constructor.

The set_normal3d( const ThreeVector& ) is just the following code (return value is ignored)

    ThreeVector Polarization::set_normal3d( const ThreeVector& vec3in ) {
	set_theta( vec3in.theta() );
	set_phi( vec3in.phi() );
	m_defined = true;
	return vec3in;
    }

The theta() and phi() functions are

inline double ThreeVector::theta() const	 {
  return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
}

inline double ThreeVector::phi() const {
  return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
}

So in the end two levels of templates are involved, and at least 3 inline functions in HepMC only.

On the other hand the HepMC::Polarization has a standard constructor

Polarization::Polarization( double theta, double phi )
    : m_theta( valid_theta(theta) ),
      m_phi  ( valid_phi(phi) ),
      m_defined( true )
    { }

which is doing the job w/o all these complications and actually validates the input.

To my opinion this is a remarkable example of how a trivial thing was overcomplicated.

Edited by Andrii Verbytskyi

Merge request reports