RawParticle

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
#ifndef CommonTools_BaseParticlePropagator_RawParticle_h
#define CommonTools_BaseParticlePropagator_RawParticle_h

#include "DataFormats/Math/interface/LorentzVector.h"
#include "DataFormats/Math/interface/Vector3D.h"

#include "Math/GenVector/RotationX.h"
#include "Math/GenVector/RotationY.h"
#include "Math/GenVector/RotationZ.h"
#include "Math/GenVector/Rotation3D.h"
#include "Math/GenVector/AxisAngle.h"
#include "Math/GenVector/Boost.h"

#include <string>
#include <iosfwd>

#include <memory>

/**
 * A prototype for a particle class.
 *  This class describes a general particle beeing a fourvector 
 *  and containing a vertex (fourvector). It is defined in RawParticle.h
 * \author Stephan Wynhoff
 */
typedef math::XYZTLorentzVector XYZTLorentzVector;
typedef math::XYZVector XYZVector;

class RawParticle;

namespace rawparticle {
  ///Create a particle with momentum 'p' at space-time point xStart
  /// The particle will be a muon if iParticle==true, else it will
  /// be an anti-muon.
  RawParticle makeMuon(bool isParticle, const XYZTLorentzVector& p, const XYZTLorentzVector& xStart);
}  // namespace rawparticle

class RawParticle {
public:
  friend RawParticle rawparticle::makeMuon(bool, const XYZTLorentzVector&, const XYZTLorentzVector&);
  friend RawParticle unchecked_makeParticle(int id, const math::XYZTLorentzVector& p, double mass, double charge);
  friend RawParticle unchecked_makeParticle(
      int id, const math::XYZTLorentzVector& p, const math::XYZTLorentzVector& xStart, double mass, double charge);

  typedef ROOT::Math::AxisAngle Rotation;
  typedef ROOT::Math::Rotation3D Rotation3D;
  typedef ROOT::Math::RotationX RotationX;
  typedef ROOT::Math::RotationY RotationY;
  typedef ROOT::Math::RotationZ RotationZ;
  typedef ROOT::Math::Boost Boost;

  RawParticle() = default;

  /** Construct from a fourvector.
   *  The fourvector is taken for the particle, the vertex is set to 0. 
   */
  RawParticle(const XYZTLorentzVector& p);

  /** Construct from 2 fourvectors.
   *  The first fourvector is taken for the particle, the second for its vertex.
   */
  RawParticle(const XYZTLorentzVector& p, const XYZTLorentzVector& xStart, double charge = 0.);

  /** Construct from fourmomentum components.
   *  Vertex is set to 0.
   */
  RawParticle(double px, double py, double pz, double e, double charge = 0.);

  /** Copy constructor    */
  RawParticle(const RawParticle& p) = default;
  RawParticle(RawParticle&& p) = default;

  /** Copy assignment operator */
  RawParticle& operator=(const RawParticle& rhs) = default;
  RawParticle& operator=(RawParticle&& rhs) = default;

public:
  /** Set the status of this particle.
   *  The coding follows PYTHIAs convention:
   *  1 = stable
   */
  void setStatus(int istat);

  /// set the RECONSTRUCTED mass
  void setMass(float m);

  /// set the MEASURED charge
  void setCharge(float q);

  /// set the time of creation
  void setT(const double t);

  ///  set the vertex
  void setVertex(const XYZTLorentzVector& vtx);
  void setVertex(double xv, double yv, double zv, double tv);

  ///  set the momentum
  void setMomentum(const XYZTLorentzVector& vtx);
  void setMomentum(double xv, double yv, double zv, double tv);

  void SetPx(double);
  void SetPy(double);
  void SetPz(double);
  void SetE(double);

  /***  methods to be overloaded to include vertex ***/

  /** Boost the particle. 
   *  The arguments are the \f$\beta\f$ values of the boost in x, y 
   * and z direction. \warning What happens to the vertex?
   */
  void boost(double bx, double by, double bz);
  void boost(const Boost& b);

  //  inline void boost(const Hep3Vector<double> &bv );

  /** Rotate the particle around an axis in space.
   *  The arguments give the amount to rotate \a rphi in radian and a vector
   *  \a raxis in 3D space around which the rotation is done. The vertex is
   *  rotated using the same transformation.
   */
  void rotate(double rphi, const XYZVector& raxis);
  void rotate(const Rotation& r);
  void rotate(const Rotation3D& r);

  /** \warning not yet implemented   */
  //   void rotateUz(Hep3Vector &nuz);

  /** Rotate around x axis.
   *  Rotate \a rphi radian around the x axis. The Vertex is rotated as well.
   */
  void rotateX(double rphi);
  void rotate(const RotationX& r);

  /** Rotate around z axis.
   *  Rotate \a rphi radian around the z axis. The Vertex is rotated as well.
   */

  void rotateY(double rphi);
  void rotate(const RotationY& r);
  /** Rotate around z axis.
   *  Rotate \a rphi radian around the z axis. The Vertex is rotated as well.
   */

  void rotateZ(double rphi);
  void rotate(const RotationZ& r);

  /** Translate the vertex by a given space amount */
  void translate(const XYZVector& t);

  //  inline RawParticle & transform(const HepRotation &rot);
  //  inline RawParticle & transform(const HepLorentzRotation &rot);

  /** Convert the particle to its charge conjugate state.
      This operation resets the particle ID to that of the charge conjugated 
      particle (if one exists). Also the measured charge is multiplied by -1.
   */
  void chargeConjugate();

  int pid() const;  //!< get the HEP particle ID number

  int status() const;  //!< get the particle status

  double charge() const;  //!< get the MEASURED charge

  double mass() const;  //!< get the MEASURED mass

  /** Get the pseudo rapidity of the particle.
   * \f$ \eta = -\log ( \tan ( \vartheta/2)) \f$
   */
  double eta() const;

  /// Cos**2(theta) is faster to determine than eta
  double cos2Theta() const;
  double cos2ThetaV() const;

  double et() const;  //!< get the transverse energy

  double x() const;  //!< x of vertex
  double X() const;  //!< x of vertex

  double y() const;  //!< y of vertex
  double Y() const;  //!< y of vertex

  double z() const;  //!< z of vertex
  double Z() const;  //!< z of vertex

  double t() const;  //!< vertex time
  double T() const;  //!< vertex time

  double r() const;  //!< vertex radius
  double R() const;  //!< vertex radius

  double r2() const;  //!< vertex radius**2
  double R2() const;  //!< vertex radius**2

  const XYZTLorentzVector& vertex() const;  //!< the vertex fourvector

  double px() const;  //!< x of the momentum
  double Px() const;  //!< x of the momentum

  double py() const;  //!< y of the momentum
  double Py() const;  //!< y of the momentum

  double pz() const;  //!< z of the momentum
  double Pz() const;  //!< z of the momentum

  double e() const;  //!< energy of the momentum
  double E() const;  //!< energy of the momentum

  double Pt() const;  //!< transverse momentum
  double pt() const;  //!< transverse momentum

  double Perp2() const;  //!< perpendicular momentum squared

  double mag() const;  //!< the magnitude of the momentum

  double theta() const;  //!< theta of momentum vector
  double phi() const;    //!< phi of momentum vector

  double M2() const;  //!< mass squared

  const XYZTLorentzVector& momentum() const;  //!< the momentum fourvector
  XYZTLorentzVector& momentum();              //!< the momentum fourvector

  XYZVector Vect() const;  //!< the momentum threevector

  /** Print the name of the particle.
   *  The name is deduced from the particle ID using a particle data table.
   *  It is printed with a length of 10 characters. If the id number cannot
   *  be found in the table "unknown" is printed as name.
   */
  void printName() const;

  /** Print the formated particle information.
   *  The format is:
   *  NAME______PX______PY______PZ______E_______Mtheo___Mrec____Qrec____X_______Y_______Z_______T_______
   */
  void print() const;

  /** Is the particle marked as used.
   *  The three methods isUsed(), use() and reUse() implement a simple
   *  locking mechanism. 
   */
  int isUsed() const { return myUsed; }

  /** Lock the particle, see isUsed()
   */
  void use() { myUsed = 1; }

  /** Unlock the particle, see isUsed()
   */
  void reUse() { myUsed = 0; }

private:
  /** Construct from a fourvector and a PID.
   *  The fourvector and PID are taken for the particle, the vertex is set to 0.
   */
  RawParticle(const int id, const XYZTLorentzVector& p, double mass, double charge);

  /** Construct from 2 fourvectosr and a PID.
   *  The fourvector and PID are taken for the particle, the vertex is set to 0.
   */
  RawParticle(const int id, const XYZTLorentzVector& p, const XYZTLorentzVector& xStart, double mass, double charge);

private:
  XYZTLorentzVector myMomentum;  //!< the four vector of the momentum
  XYZTLorentzVector myVertex;    //!< the four vector of the vertex
  double myCharge = 0.;          //!< the MEASURED charge
  double myMass = 0.;            //!< the RECONSTRUCTED mass
  int myId = 0;                  //!< the particle id number HEP-PID
  int myStatus = 99;             //!< the status code according to PYTHIA
  int myUsed = 0;                //!< status of the locking
};

std::ostream& operator<<(std::ostream& o, const RawParticle& p);

inline int RawParticle::pid() const { return myId; }
inline int RawParticle::status() const { return myStatus; }
inline double RawParticle::eta() const { return -std::log(std::tan(this->theta() / 2.)); }
inline double RawParticle::cos2Theta() const { return Pz() * Pz() / myMomentum.Vect().Mag2(); }
inline double RawParticle::cos2ThetaV() const { return Z() * Z() / myVertex.Vect().Mag2(); }
inline double RawParticle::x() const { return myVertex.Px(); }
inline double RawParticle::y() const { return myVertex.Py(); }
inline double RawParticle::z() const { return myVertex.Pz(); }
inline double RawParticle::t() const { return myVertex.E(); }
inline double RawParticle::X() const { return myVertex.Px(); }
inline double RawParticle::Y() const { return myVertex.Py(); }
inline double RawParticle::Z() const { return myVertex.Pz(); }
inline double RawParticle::T() const { return myVertex.E(); }
inline double RawParticle::R() const { return std::sqrt(R2()); }
inline double RawParticle::R2() const { return myVertex.Perp2(); }
inline double RawParticle::r() const { return std::sqrt(r2()); }
inline double RawParticle::r2() const { return myVertex.Perp2(); }
inline double RawParticle::charge() const { return myCharge; }
inline double RawParticle::mass() const { return myMass; }
inline double RawParticle::px() const { return myMomentum.px(); }
inline double RawParticle::Px() const { return myMomentum.Px(); }

inline double RawParticle::py() const { return myMomentum.py(); }
inline double RawParticle::Py() const { return myMomentum.Py(); }

inline double RawParticle::pz() const { return myMomentum.pz(); }
inline double RawParticle::Pz() const { return myMomentum.Pz(); }

inline double RawParticle::e() const { return myMomentum.e(); }
inline double RawParticle::E() const { return myMomentum.E(); }

inline double RawParticle::Pt() const { return myMomentum.Pt(); }
inline double RawParticle::pt() const { return myMomentum.pt(); }

inline double RawParticle::Perp2() const { return myMomentum.Perp2(); }

inline double RawParticle::mag() const { return myMomentum.mag(); }

inline double RawParticle::theta() const { return myMomentum.theta(); }
inline double RawParticle::phi() const { return myMomentum.phi(); }

inline double RawParticle::M2() const { return myMomentum.M2(); }

inline const XYZTLorentzVector& RawParticle::vertex() const { return myVertex; }
inline const XYZTLorentzVector& RawParticle::momentum() const { return myMomentum; }
inline XYZTLorentzVector& RawParticle::momentum() { return myMomentum; }
inline XYZVector RawParticle::Vect() const { return myMomentum.Vect(); }

inline void RawParticle::setVertex(const XYZTLorentzVector& vtx) { myVertex = vtx; }
inline void RawParticle::setVertex(double a, double b, double c, double d) { myVertex.SetXYZT(a, b, c, d); }

inline void RawParticle::setMomentum(const XYZTLorentzVector& p4) { myMomentum = p4; }
inline void RawParticle::setMomentum(double a, double b, double c, double d) { myMomentum.SetXYZT(a, b, c, d); }

inline void RawParticle::SetPx(double px) { myMomentum.SetPx(px); }
inline void RawParticle::SetPy(double py) { myMomentum.SetPy(py); }
inline void RawParticle::SetPz(double pz) { myMomentum.SetPz(pz); }
inline void RawParticle::SetE(double e) { myMomentum.SetE(e); }

inline void RawParticle::rotate(const RawParticle::Rotation3D& r) {
  XYZVector v(r(myMomentum.Vect()));
  setMomentum(v.X(), v.Y(), v.Z(), E());
}

inline void RawParticle::rotate(const RawParticle::Rotation& r) {
  XYZVector v(r(myMomentum.Vect()));
  setMomentum(v.X(), v.Y(), v.Z(), E());
}

inline void RawParticle::rotate(const RawParticle::RotationX& r) {
  XYZVector v(r(myMomentum.Vect()));
  setMomentum(v.X(), v.Y(), v.Z(), E());
}

inline void RawParticle::rotate(const RawParticle::RotationY& r) {
  XYZVector v(r(myMomentum.Vect()));
  setMomentum(v.X(), v.Y(), v.Z(), E());
}

inline void RawParticle::rotate(const RawParticle::RotationZ& r) {
  XYZVector v(r(myMomentum.Vect()));
  setMomentum(v.X(), v.Y(), v.Z(), E());
}

inline void RawParticle::boost(const RawParticle::Boost& b) {
  XYZTLorentzVector p(b(momentum()));
  setMomentum(p.Px(), p.Py(), p.Pz(), p.E());
}

inline void RawParticle::translate(const XYZVector& tr) {
  myVertex.SetXYZT(X() + tr.X(), Y() + tr.Y(), Z() + tr.Z(), T());
}

#endif