Belle II Software  release-05-02-19
MCInitialParticles.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <TLorentzVector.h>
14 #include <TLorentzRotation.h>
15 
16 namespace Belle2 {
27  class MCInitialParticles: public TObject {
28 
29  public:
30 
32  enum EGenerationFlags {
34  c_generateCMS = 1 << 0,
36  c_smearBeamEnergy = 1 << 1,
38  c_smearBeamDirection = 1 << 2,
42  c_smearVertex = 1 << 3,
45  };
46 
48  MCInitialParticles(): TObject() {}
49 
51  MCInitialParticles(const MCInitialParticles& b): TObject(), m_her(b.m_her), m_ler(b.m_ler),
53 
56  {
57  m_her = b.m_her; m_ler = b.m_ler; m_vertex = b.m_vertex;
58  m_validFlag = b.m_validFlag; m_generationFlags = b.m_generationFlags;
60  return *this;
61  }
62 
64  bool operator==(const MCInitialParticles& b) const
65  {
66  // FIXME: Ah, bloody hell. sin(x) returns slightly different values on
67  // different platforms in some cases so we cannot just do an equality
68  // comparison. We need to do this more elegantly, this is just for
69  // testing if it solves all problems
70 #if defined(MCP_DBL_CMP) || defined(MCP_VEC3_CMP) || defined(MCP_VEC4_CMP)
71 #error Macro already defined, cannot continue
72 #endif
73 #define MCP_DBL_CMP(a,b,x) ((a.x()==b.x())||(std::abs(a.x()-b.x())<1e-10))
74 #define MCP_VEC3_CMP(a,b) (MCP_DBL_CMP(a,b,X) && MCP_DBL_CMP(a,b,Y) && MCP_DBL_CMP(a,b,Z))
75 #define MCP_VEC4_CMP(a,b) (MCP_VEC3_CMP(a,b) && MCP_DBL_CMP(a,b,E))
76  return MCP_VEC4_CMP(m_her, b.m_her) && MCP_VEC4_CMP(m_ler, b.m_ler) && MCP_VEC3_CMP(m_vertex, b.m_vertex)
77  && m_validFlag == b.m_validFlag &&
78  m_generationFlags == b.m_generationFlags;
79 #undef MCP_DBL_CMP
80 #undef MCP_VEC3_CMP
81 #undef MCP_VEC4_CMP
82  }
83 
85  virtual ~MCInitialParticles() { resetBoost(); }
86 
93  void set(const TLorentzVector& her, const TLorentzVector& ler, const TVector3& vertex)
94  {
95  m_her = her;
96  m_ler = ler;
97  m_vertex = vertex;
98  m_validFlag = true;
99  resetBoost();
100  }
101 
103  void setHER(const TLorentzVector& her)
104  {
105  m_her = her;
106  resetBoost();
107  }
108 
110  void setLER(const TLorentzVector& ler)
111  {
112  m_ler = ler;
113  resetBoost();
114  }
115 
117  void setVertex(const TVector3& vertex)
118  {
119  m_vertex = vertex;
120  }
121 
123  void setTime(double time) {m_time = time;}
124 
126  void setGenerationFlags(int flags) { m_generationFlags = flags; }
127 
129  const TLorentzVector& getHER() const { return m_her; }
130 
132  const TLorentzVector& getLER() const { return m_ler; }
133 
135  const TVector3& getVertex() const { return m_vertex; }
136 
138  double getTime() const {return m_time;}
139 
141  double getEnergy() const { return (m_her + m_ler).E(); }
142 
144  double getMass() const { calculateBoost(); return m_invariantMass; }
145 
147  const TLorentzRotation& getLabToCMS() const
148  {
150  }
151 
153  const TLorentzRotation& getCMSToLab() const
154  {
156  }
157 
159  bool getValidFlag() const { return m_validFlag; }
160 
162  int getGenerationFlags() const { return m_generationFlags; }
163 
165  bool hasGenerationFlags(int flags) const { return (m_generationFlags & flags) == flags; }
166 
169  std::string getGenerationFlagString(const std::string& separator = " ") const;
170 
171  private:
172 
174  void calculateBoost() const;
176  void resetBoost();
178  TLorentzVector m_her;
180  TLorentzVector m_ler;
182  TVector3 m_vertex;
184  double m_time = 0;
186  mutable TLorentzRotation* m_labToCMS{nullptr};
187 
188  mutable TLorentzRotation* m_CMSToLab{nullptr};
189 
190  mutable double m_invariantMass{0.0};
191 
192  bool m_validFlag = false;
197  };
198 
199  inline void MCInitialParticles::calculateBoost() const
200  {
201  if (m_labToCMS)
202  return;
203 
204  TLorentzVector beam = m_her + m_ler;
205  // Save the invariant mass because it's used very often in analysis
206  m_invariantMass = beam.M();
207 
208  // If we generate events in CMS we already are in CMS and there is no
209  // transformation so let's use the identity
211  m_labToCMS = new TLorentzRotation();
212  m_CMSToLab = new TLorentzRotation();
213  return;
214  }
215 
216  // Transformation from Lab system to CMS system
217  m_labToCMS = new TLorentzRotation(-beam.BoostVector());
218  // boost HER e- from Lab system to CMS system
219  const TLorentzVector electronCMS = (*m_labToCMS) * m_her;
220  // now rotate CMS such that incoming e- is parallel to z-axis
221  const TVector3 zaxis(0., 0., 1.);
222  TVector3 rotaxis = zaxis.Cross(electronCMS.Vect()) * (1. / electronCMS.Vect().Mag());
223  double rotangle = TMath::ASin(rotaxis.Mag());
224  m_labToCMS->Rotate(-rotangle, rotaxis);
225 
226  //cache derived quantities
227  m_CMSToLab = new TLorentzRotation(m_labToCMS->Inverse());
228  }
229 
230  inline void MCInitialParticles::resetBoost()
231  {
232  delete m_labToCMS;
233  delete m_CMSToLab;
234  m_labToCMS = nullptr;
235  m_CMSToLab = nullptr;
236  m_invariantMass = 0.0;
237  }
238 
240 } //Belle2 namespace
Belle2::MCInitialParticles::getLabToCMS
const TLorentzRotation & getLabToCMS() const
Return the LorentzRotation to convert from lab to CMS frame.
Definition: MCInitialParticles.h:155
Belle2::MCInitialParticles::getLER
const TLorentzVector & getLER() const
Get 4vector of the low energy beam.
Definition: MCInitialParticles.h:140
Belle2::MCInitialParticles::c_smearBeamEnergy
@ c_smearBeamEnergy
smear energy of HER and LER (but not direction)
Definition: MCInitialParticles.h:44
Belle2::MCInitialParticles::setHER
void setHER(const TLorentzVector &her)
Set the High Energy Beam 4-momentum.
Definition: MCInitialParticles.h:111
Belle2::MCInitialParticles::operator=
MCInitialParticles & operator=(const MCInitialParticles &b)
Assignment operator.
Definition: MCInitialParticles.h:63
Belle2::MCInitialParticles::c_smearBeam
@ c_smearBeam
smear the full beam momentum (energy and direction)
Definition: MCInitialParticles.h:48
Belle2::MCInitialParticles::m_labToCMS
TLorentzRotation * m_labToCMS
Boost from Lab into CMS.
Definition: MCInitialParticles.h:194
Belle2::MCInitialParticles::m_her
TLorentzVector m_her
HER 4vector.
Definition: MCInitialParticles.h:186
Belle2::MCInitialParticles::m_invariantMass
double m_invariantMass
transient
Definition: MCInitialParticles.h:198
Belle2::MCInitialParticles::m_generationFlags
int m_generationFlags
Flags to be used when generating events.
Definition: MCInitialParticles.h:202
Belle2::MCInitialParticles::c_smearBeamDirection
@ c_smearBeamDirection
smear direction of HER and LER (but not energy)
Definition: MCInitialParticles.h:46
Belle2::MCInitialParticles::ClassDef
ClassDef(MCInitialParticles, 3)
ROOT Dictionary.
Belle2::MCInitialParticles::m_vertex
TVector3 m_vertex
collision position
Definition: MCInitialParticles.h:190
Belle2::MCInitialParticles::~MCInitialParticles
virtual ~MCInitialParticles()
Free memory of the LorentzRotation if it was created.
Definition: MCInitialParticles.h:93
Belle2::MCInitialParticles::getHER
const TLorentzVector & getHER() const
Get 4vector of the high energy beam.
Definition: MCInitialParticles.h:137
Belle2::MCInitialParticles::setGenerationFlags
void setGenerationFlags(int flags)
Set the generation flags to be used for event generation (ORed combination of EGenerationFlags)
Definition: MCInitialParticles.h:134
Belle2::MCInitialParticles::m_ler
TLorentzVector m_ler
LER 4vector.
Definition: MCInitialParticles.h:188
Belle2::MCInitialParticles::getGenerationFlagString
std::string getGenerationFlagString(const std::string &separator=" ") const
Return string representation of all active flags for printing.
Definition: MCInitialParticles.cc:15
Belle2::MCInitialParticles::c_smearVertex
@ c_smearVertex
smear vertex
Definition: MCInitialParticles.h:50
Belle2::MCInitialParticles::m_CMSToLab
TLorentzRotation * m_CMSToLab
transient
Definition: MCInitialParticles.h:196
Belle2::MCInitialParticles::setTime
void setTime(double time)
Set collison time.
Definition: MCInitialParticles.h:131
Belle2::MCInitialParticles::getTime
double getTime() const
Get collison time.
Definition: MCInitialParticles.h:146
Belle2::MCInitialParticles::m_validFlag
bool m_validFlag
transient
Definition: MCInitialParticles.h:200
Belle2::MCInitialParticles
This class contains the initial state for the given event.
Definition: MCInitialParticles.h:35
Belle2::MCInitialParticles::resetBoost
void resetBoost()
Reset cached transformations after changing parameters.
Definition: MCInitialParticles.h:238
Belle2::MCInitialParticles::getMass
double getMass() const
Get the invariant mass of the collision (= energy in CMS)
Definition: MCInitialParticles.h:152
Belle2::MCInitialParticles::c_generateCMS
@ c_generateCMS
generate initial event in CMS instead of lab
Definition: MCInitialParticles.h:42
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MCInitialParticles::setVertex
void setVertex(const TVector3 &vertex)
Set the vertex position.
Definition: MCInitialParticles.h:125
Belle2::MCInitialParticles::setLER
void setLER(const TLorentzVector &ler)
Set the Low Energy Beam 4-momentum.
Definition: MCInitialParticles.h:118
Belle2::MCInitialParticles::operator==
bool operator==(const MCInitialParticles &b) const
Equality operator.
Definition: MCInitialParticles.h:72
Belle2::MCInitialParticles::getVertex
const TVector3 & getVertex() const
Get the position of the collision.
Definition: MCInitialParticles.h:143
Belle2::MCInitialParticles::m_time
double m_time
collision time
Definition: MCInitialParticles.h:192
Belle2::MCInitialParticles::getCMSToLab
const TLorentzRotation & getCMSToLab() const
Return the LorentzRotation to convert from CMS to lab frame.
Definition: MCInitialParticles.h:161
Belle2::MCInitialParticles::getEnergy
double getEnergy() const
Get the the actual collision energy (in lab system)
Definition: MCInitialParticles.h:149
Belle2::MCInitialParticles::MCInitialParticles
MCInitialParticles()
Default constructor.
Definition: MCInitialParticles.h:56
Belle2::MCInitialParticles::EGenerationFlags
EGenerationFlags
Possible Flags for initial event generation.
Definition: MCInitialParticles.h:40
Belle2::MCInitialParticles::c_smearALL
@ c_smearALL
smear all
Definition: MCInitialParticles.h:52
Belle2::MCInitialParticles::getGenerationFlags
int getGenerationFlags() const
Get the generation flags to be used for event generation (ORed combination of EGenerationFlags)
Definition: MCInitialParticles.h:170
Belle2::MCInitialParticles::getValidFlag
bool getValidFlag() const
Get the flag to check if a valid MCInitialParticles object was already generated and filled in an eve...
Definition: MCInitialParticles.h:167
Belle2::MCInitialParticles::set
void set(const TLorentzVector &her, const TLorentzVector &ler, const TVector3 &vertex)
Set the initial event values, i.e.
Definition: MCInitialParticles.h:101
Belle2::MCInitialParticles::hasGenerationFlags
bool hasGenerationFlags(int flags) const
Check if a certain set of EGenerationFlags is set.
Definition: MCInitialParticles.h:173
Belle2::MCInitialParticles::calculateBoost
void calculateBoost() const
Calculate the boost if necessary.
Definition: MCInitialParticles.h:207