CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
Geant4ePropagator Class Reference

#include <Geant4ePropagator.h>

Inheritance diagram for Geant4ePropagator:
Propagator

Public Member Functions

Geant4ePropagatorclone () const override
 
template<>
bool configureAnyPropagation (G4ErrorMode &mode, Plane const &pDest, GlobalPoint const &cmsInitPos, GlobalVector const &cmsInitMom) const
 
template<>
bool configureAnyPropagation (G4ErrorMode &mode, Cylinder const &pDest, GlobalPoint const &cmsInitPos, GlobalVector const &cmsInitMom) const
 
 Geant4ePropagator (const MagneticField *field=nullptr, std::string particleName="mu", PropagationDirection dir=alongMomentum, double plimit=1.0)
 
template<>
std::string getSurfaceType (Cylinder const &c) const
 
template<>
std::string getSurfaceType (Plane const &c) const
 
const MagneticFieldmagneticField () const override
 
std::pair< TrajectoryStateOnSurface, double > propagateWithPath (const FreeTrajectoryState &, const Plane &) const override
 
std::pair< TrajectoryStateOnSurface, double > propagateWithPath (const FreeTrajectoryState &, const Cylinder &) const override
 
std::pair< TrajectoryStateOnSurface, double > propagateWithPath (const TrajectoryStateOnSurface &, const Plane &) const override
 
std::pair< TrajectoryStateOnSurface, double > propagateWithPath (const TrajectoryStateOnSurface &, const Cylinder &) const override
 
template<>
Geant4ePropagator::ErrorTargetPair transformToG4SurfaceTarget (const Plane &pDest, bool moveTargetToEndOfSurface) const
 
template<>
Geant4ePropagator::ErrorTargetPair transformToG4SurfaceTarget (const Cylinder &pDest, bool moveTargetToEndOfSurface) const
 
 ~Geant4ePropagator () override
 
- Public Member Functions inherited from Propagator
template<typename STA , typename SUR >
TrajectoryStateOnSurface propagate (STA const &state, SUR const &surface) const
 
virtual FreeTrajectoryState propagate (const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
 
virtual FreeTrajectoryState propagate (const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest1, const GlobalPoint &pDest2) const final
 
virtual FreeTrajectoryState propagate (const FreeTrajectoryState &ftsStart, const reco::BeamSpot &beamSpot) const final
 
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath (const FreeTrajectoryState &, const Surface &) const final
 
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath (const TrajectoryStateOnSurface &tsos, const Surface &sur) const final
 
virtual std::pair< FreeTrajectoryState, double > propagateWithPath (const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const
 
virtual std::pair< FreeTrajectoryState, double > propagateWithPath (const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest1, const GlobalPoint &pDest2) const
 Propagate to PCA to a line (given by 2 points) given a starting point. More...
 
virtual std::pair< FreeTrajectoryState, double > propagateWithPath (const FreeTrajectoryState &ftsStart, const reco::BeamSpot &beamSpot) const
 Propagate to PCA to a line (given by beamSpot position and slope) given a starting point. More...
 
virtual PropagationDirection propagationDirection () const final
 
 Propagator (PropagationDirection dir=alongMomentum)
 
virtual bool setMaxDirectionChange (float phiMax)
 
virtual void setPropagationDirection (PropagationDirection dir)
 
virtual ~Propagator ()
 

Private Types

typedef std::pair< bool, std::shared_ptr< G4ErrorTarget > > ErrorTargetPair
 
typedef std::pair< TrajectoryStateOnSurface, double > TsosPP
 

Private Member Functions

template<class SurfaceType >
bool configureAnyPropagation (G4ErrorMode &mode, SurfaceType const &pDest, GlobalPoint const &cmsInitPos, GlobalVector const &cmsInitMom) const
 
template<class SurfaceType >
bool configurePropagation (G4ErrorMode &mode, SurfaceType const &pDest, GlobalPoint const &cmsInitPos, GlobalVector const &cmsInitMom) const
 
void debugReportPlaneSetup (GlobalPoint const &posPlane, HepGeom::Point3D< double > const &surfPos, GlobalVector const &normalPlane, HepGeom::Normal3D< double > const &surfNorm, const Plane &pDest) const
 
template<class SurfaceType >
void debugReportTrackState (std::string const &currentContext, GlobalPoint const &cmsInitPos, CLHEP::Hep3Vector const &g4InitPos, GlobalVector const &cmsInitMom, CLHEP::Hep3Vector const &g4InitMom, const SurfaceType &pDest) const
 
void ensureGeant4eIsInitilized (bool forceInit) const
 
std::string generateParticleName (int charge) const
 
template<class SurfaceType >
std::string getSurfaceType (SurfaceType const &surface) const
 
template<class SurfaceType >
std::pair< TrajectoryStateOnSurface, double > propagateGeneric (const FreeTrajectoryState &ftsStart, const SurfaceType &pDest) const
 
template<class SurfaceType >
ErrorTargetPair transformToG4SurfaceTarget (const SurfaceType &pDest, bool moveTargetToEndOfSurface) const
 

Private Attributes

double plimit_
 
const MagneticFieldtheField
 
G4ErrorPropagatorData * theG4eData
 
G4ErrorPropagatorManager * theG4eManager
 
std::string theParticleName
 

Detailed Description

Propagator based on the Geant4e package. Uses the Propagator class in the TrackingTools/GeomPropagators package to define the interface. See that class for more details.

Definition at line 20 of file Geant4ePropagator.h.

Member Typedef Documentation

◆ ErrorTargetPair

typedef std::pair<bool, std::shared_ptr<G4ErrorTarget> > Geant4ePropagator::ErrorTargetPair
private

Definition at line 84 of file Geant4ePropagator.h.

◆ TsosPP

typedef std::pair<TrajectoryStateOnSurface, double> Geant4ePropagator::TsosPP
private

Definition at line 83 of file Geant4ePropagator.h.

Constructor & Destructor Documentation

◆ Geant4ePropagator()

Geant4ePropagator::Geant4ePropagator ( const MagneticField field = nullptr,
std::string  particleName = "mu",
PropagationDirection  dir = alongMomentum,
double  plimit = 1.0 
)

Constructor. Takes as arguments:

  • The magnetic field
  • The particle name whose properties will be used in the propagation. Without the charge, i.e. "mu", "pi", ...
  • The propagation direction. It may be: alongMomentum, oppositeToMomentum

Constructor.

Definition at line 40 of file Geant4ePropagator.cc.

References ensureGeant4eIsInitilized(), and LogDebug.

Referenced by clone().

44  : Propagator(dir),
45  theField(field),
47  theG4eManager(G4ErrorPropagatorManager::GetErrorPropagatorManager()),
48  theG4eData(G4ErrorPropagatorData::GetErrorPropagatorData()),
49  plimit_(plimit) {
50  LogDebug("Geant4e") << "Geant4e Propagator initialized";
51 
52  // has to be called here, doing it later will not load the G4 physics list
53  // properly when using the G4 ES Producer. Reason: unclear
55 }
Propagator(PropagationDirection dir=alongMomentum)
Definition: Propagator.h:46
std::string theParticleName
const MagneticField * theField
G4ErrorPropagatorManager * theG4eManager
void ensureGeant4eIsInitilized(bool forceInit) const
G4ErrorPropagatorData * theG4eData
#define LogDebug(id)

◆ ~Geant4ePropagator()

Geant4ePropagator::~Geant4ePropagator ( )
override

Destructor.

Definition at line 59 of file Geant4ePropagator.cc.

References LogDebug.

59  {
60  LogDebug("Geant4e") << "Geant4ePropagator::~Geant4ePropagator()" << std::endl;
61 
62  // don't close the g4 Geometry here, because the propagator might have been
63  // cloned
64  // but there is only one, globally-shared Geometry
65 }
#define LogDebug(id)

Member Function Documentation

◆ clone()

Geant4ePropagator* Geant4ePropagator::clone ( void  ) const
inlineoverridevirtual

Implements Propagator.

Definition at line 78 of file Geant4ePropagator.h.

References Geant4ePropagator().

78 { return new Geant4ePropagator(*this); }
Geant4ePropagator(const MagneticField *field=nullptr, std::string particleName="mu", PropagationDirection dir=alongMomentum, double plimit=1.0)

◆ configureAnyPropagation() [1/3]

template<class SurfaceType >
bool Geant4ePropagator::configureAnyPropagation ( G4ErrorMode &  mode,
SurfaceType const &  pDest,
GlobalPoint const &  cmsInitPos,
GlobalVector const &  cmsInitMom 
) const
private

Referenced by configurePropagation().

◆ configureAnyPropagation() [2/3]

template<>
bool Geant4ePropagator::configureAnyPropagation ( G4ErrorMode &  mode,
Plane const &  pDest,
GlobalPoint const &  cmsInitPos,
GlobalVector const &  cmsInitMom 
) const

Definition at line 162 of file Geant4ePropagator.cc.

References Plane::localZ(), LogDebug, PV3DBase< T, PVType, FrameType >::mag(), ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, and plimit_.

165  {
166  if (cmsInitMom.mag() < plimit_)
167  return false;
168  if (pDest.localZ(cmsInitPos) * pDest.localZ(cmsInitMom) < 0) {
169  mode = G4ErrorMode_PropForwards;
170  LogDebug("Geant4e") << "G4e - Propagator mode is \'forwards\' indirect "
171  "via the Any direction"
172  << std::endl;
173  } else {
174  mode = G4ErrorMode_PropBackwards;
175  LogDebug("Geant4e") << "G4e - Propagator mode is \'backwards\' indirect "
176  "via the Any direction"
177  << std::endl;
178  }
179 
180  return true;
181 }
#define LogDebug(id)

◆ configureAnyPropagation() [3/3]

template<>
bool Geant4ePropagator::configureAnyPropagation ( G4ErrorMode &  mode,
Cylinder const &  pDest,
GlobalPoint const &  cmsInitPos,
GlobalVector const &  cmsInitMom 
) const

Definition at line 184 of file Geant4ePropagator.cc.

References LogDebug, PV3DBase< T, PVType, FrameType >::mag(), ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, plimit_, SurfaceOrientation::positiveSide, Cylinder::side(), and GloballyPositioned< T >::toLocal().

187  {
188  if (cmsInitMom.mag() < plimit_)
189  return false;
190  //------------------------------------
191  // For cylinder assume outside is backwards, inside is along
192  // General use for particles from collisions
193  LocalPoint lpos = pDest.toLocal(cmsInitPos);
194  Surface::Side theSide = pDest.side(lpos, 0);
195  if (theSide == SurfaceOrientation::positiveSide) { // outside cylinder
196  mode = G4ErrorMode_PropBackwards;
197  LogDebug("Geant4e") << "G4e - Propagator mode is \'backwards\' indirect "
198  "via the Any direction";
199  } else { // inside cylinder
200  mode = G4ErrorMode_PropForwards;
201  LogDebug("Geant4e") << "G4e - Propagator mode is \'forwards\' indirect "
202  "via the Any direction";
203  }
204 
205  return true;
206 }
#define LogDebug(id)

◆ configurePropagation()

template<class SurfaceType >
bool Geant4ePropagator::configurePropagation ( G4ErrorMode &  mode,
SurfaceType const &  pDest,
GlobalPoint const &  cmsInitPos,
GlobalVector const &  cmsInitMom 
) const
private

Definition at line 209 of file Geant4ePropagator.cc.

References alongMomentum, anyDirection, configureAnyPropagation(), LogDebug, PV3DBase< T, PVType, FrameType >::mag(), ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, oppositeToMomentum, plimit_, and Propagator::propagationDirection().

Referenced by propagateGeneric().

212  {
213  if (cmsInitMom.mag() < plimit_)
214  return false;
216  mode = G4ErrorMode_PropBackwards;
217  LogDebug("Geant4e") << "G4e - Propagator mode is \'backwards\' " << std::endl;
218  } else if (propagationDirection() == alongMomentum) {
219  mode = G4ErrorMode_PropForwards;
220  LogDebug("Geant4e") << "G4e - Propagator mode is \'forwards\'" << std::endl;
221  } else if (propagationDirection() == anyDirection) {
222  if (configureAnyPropagation(mode, pDest, cmsInitPos, cmsInitMom) == false)
223  return false;
224  } else {
225  edm::LogError("Geant4e") << "G4e - Unsupported propagation mode";
226  return false;
227  }
228  return true;
229 }
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
Log< level::Error, false > LogError
bool configureAnyPropagation(G4ErrorMode &mode, SurfaceType const &pDest, GlobalPoint const &cmsInitPos, GlobalVector const &cmsInitMom) const
#define LogDebug(id)

◆ debugReportPlaneSetup()

void Geant4ePropagator::debugReportPlaneSetup ( GlobalPoint const &  posPlane,
HepGeom::Point3D< double > const &  surfPos,
GlobalVector const &  normalPlane,
HepGeom::Normal3D< double > const &  surfNorm,
const Plane pDest 
) const
private

Definition at line 457 of file Geant4ePropagator.cc.

References Geom::Phi< T1, Range >::degrees(), PV3DBase< T, PVType, FrameType >::eta(), Plane::localZ(), LogDebug, PV3DBase< T, PVType, FrameType >::perp(), and PV3DBase< T, PVType, FrameType >::phi().

461  {
462  LogDebug("Geant4e") << "G4e - Destination CMS plane position:" << posPlane << "cm\n"
463  << "G4e - (Ro, eta, phi): (" << posPlane.perp() << " cm, " << posPlane.eta()
464  << ", " << posPlane.phi().degrees() << " deg)\n"
465  << "G4e - Destination G4 plane position: " << surfPos << " mm, Ro = " << surfPos.perp()
466  << " mm";
467  LogDebug("Geant4e") << "G4e - Destination CMS plane normal : " << normalPlane << "\n"
468  << "G4e - Destination G4 plane normal : " << normalPlane;
469  LogDebug("Geant4e") << "G4e - Distance from plane position to plane: " << pDest.localZ(posPlane) << " cm";
470 }
float localZ(const GlobalPoint &gp) const
Definition: Plane.h:45
#define LogDebug(id)

◆ debugReportTrackState()

template<class SurfaceType >
void Geant4ePropagator::debugReportTrackState ( std::string const &  currentContext,
GlobalPoint const &  cmsInitPos,
CLHEP::Hep3Vector const &  g4InitPos,
GlobalVector const &  cmsInitMom,
CLHEP::Hep3Vector const &  g4InitMom,
const SurfaceType &  pDest 
) const
private

Definition at line 473 of file Geant4ePropagator.cc.

References Geom::Phi< T1, Range >::degrees(), PV3DBase< T, PVType, FrameType >::eta(), LogDebug, PV3DBase< T, PVType, FrameType >::perp(), and PV3DBase< T, PVType, FrameType >::phi().

Referenced by propagateGeneric().

478  {
479  LogDebug("Geant4e") << "G4e - Current Context: " << currentContext;
480  LogDebug("Geant4e") << "G4e - CMS point position:" << cmsInitPos << "cm\n"
481  << "G4e - (Ro, eta, phi): (" << cmsInitPos.perp() << " cm, " << cmsInitPos.eta()
482  << ", " << cmsInitPos.phi().degrees() << " deg)\n"
483  << "G4e - G4 point position: " << g4InitPos << " mm, Ro = " << g4InitPos.perp() << " mm";
484  LogDebug("Geant4e") << "G4e - CMS momentum :" << cmsInitMom << "GeV\n"
485  << " pt: " << cmsInitMom.perp() << "G4e - G4 momentum : " << g4InitMom << " MeV";
486 }
#define LogDebug(id)

◆ ensureGeant4eIsInitilized()

void Geant4ePropagator::ensureGeant4eIsInitilized ( bool  forceInit) const
private

Propagate from a free state (e.g. position and momentum in in global cartesian coordinates) to a plane.

Definition at line 75 of file Geant4ePropagator.cc.

References LogDebug, and theG4eManager.

Referenced by Geant4ePropagator().

75  {
76  LogDebug("Geant4e") << "ensureGeant4eIsInitilized called" << std::endl;
77  if ((G4ErrorPropagatorData::GetErrorPropagatorData()->GetState() == G4ErrorState_PreInit) || forceInit) {
78  LogDebug("Geant4e") << "Initializing G4 propagator" << std::endl;
79 
80  //G4UImanager::GetUIpointer()->ApplyCommand("/exerror/setField -10. kilogauss");
81 
82  theG4eManager->InitGeant4e();
83 
84  const G4Field *field = G4TransportationManager::GetTransportationManager()->GetFieldManager()->GetDetectorField();
85  if (field == nullptr) {
86  edm::LogError("Geant4e") << "No G4 magnetic field defined";
87  }
88  LogDebug("Geant4e") << "G4 propagator initialized" << std::endl;
89  } else {
90  LogDebug("Geant4e") << "G4 not in preinit state: " << G4ErrorPropagatorData::GetErrorPropagatorData()->GetState()
91  << std::endl;
92  }
93  // define 10 mm step limit for propagator
94  G4UImanager::GetUIpointer()->ApplyCommand("/geant4e/limits/stepLength 10.0 mm");
95 }
Log< level::Error, false > LogError
G4ErrorPropagatorManager * theG4eManager
#define LogDebug(id)

◆ generateParticleName()

std::string Geant4ePropagator::generateParticleName ( int  charge) const
private

Definition at line 146 of file Geant4ePropagator.cc.

References ALCARECOTkAlJpsiMuMu_cff::charge, LogDebug, HiggsValidation_cfi::particleName, AlCaHLTBitMon_QueryRunRegistry::string, and theParticleName.

Referenced by propagateGeneric().

146  {
148 
149  if (charge > 0) {
150  particleName += "+";
151  }
152  if (charge < 0) {
153  particleName += "-";
154  }
155 
156  LogDebug("Geant4e") << "G4e - Particle name: " << particleName;
157 
158  return particleName;
159 }
std::string theParticleName
#define LogDebug(id)

◆ getSurfaceType() [1/3]

template<>
std::string Geant4ePropagator::getSurfaceType ( Cylinder const &  c) const

Definition at line 137 of file Geant4ePropagator.cc.

137  {
138  return "Cylinder";
139 }

◆ getSurfaceType() [2/3]

template<>
std::string Geant4ePropagator::getSurfaceType ( Plane const &  c) const

Definition at line 142 of file Geant4ePropagator.cc.

142  {
143  return "Plane";
144 }

◆ getSurfaceType() [3/3]

template<class SurfaceType >
std::string Geant4ePropagator::getSurfaceType ( SurfaceType const &  surface) const
private

◆ magneticField()

const MagneticField* Geant4ePropagator::magneticField ( ) const
inlineoverridevirtual

Implements Propagator.

Definition at line 80 of file Geant4ePropagator.h.

References theField.

80 { return theField; }
const MagneticField * theField

◆ propagateGeneric()

template<class SurfaceType >
std::pair< TrajectoryStateOnSurface, double > Geant4ePropagator::propagateGeneric ( const FreeTrajectoryState ftsStart,
const SurfaceType &  pDest 
) const
private

Definition at line 232 of file Geant4ePropagator.cc.

References SurfaceSideDefinition::afterSurface, TrackPropagation::algebraicSymMatrix55ToG4ErrorTrajErr(), alongMomentum, SurfaceSideDefinition::beforeSurface, FreeTrajectoryState::charge(), GlobalTrajectoryParameters::charge(), configurePropagation(), FreeTrajectoryState::curvilinearError(), debugReportTrackState(), f, TrackPropagation::g4doubleToCmsDouble(), TrackPropagation::g4ErrorTrajErrToAlgebraicSymMatrix55(), generateParticleName(), TrackPropagation::globalPointToHep3Vector(), TrackPropagation::globalVectorToHep3Vector(), FreeTrajectoryState::hasError(), TrackPropagation::hep3VectorToGlobalVector(), TrackPropagation::hepPoint3DToGlobalPoint(), LogDebug, GlobalTrajectoryParameters::magneticField(), CurvilinearTrajectoryError::matrix(), ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, FreeTrajectoryState::momentum(), oppositeToMomentum, FreeTrajectoryState::parameters(), FreeTrajectoryState::position(), Propagator::propagationDirection(), theField, theG4eData, theG4eManager, and transformToG4SurfaceTarget().

Referenced by propagateWithPath().

233  {
235  // Construct the target surface
236  //
237  //* Set the target surface
238 
239  ErrorTargetPair g4eTarget_center = transformToG4SurfaceTarget(pDest, false);
240 
241  // * Get the starting point and direction and convert them to
242  // CLHEP::Hep3Vector
243  // for G4. CMS uses cm and GeV while Geant4 uses mm and MeV
244  GlobalPoint cmsInitPos = ftsStart.position();
245  GlobalVector cmsInitMom = ftsStart.momentum();
246  bool flipped = false;
248  // flip the momentum vector as Geant4 will not do this
249  // on it's own in a backward propagation
250  cmsInitMom = -cmsInitMom;
251  flipped = true;
252  }
253 
254  // Set the mode of propagation according to the propagation direction
255  G4ErrorMode mode = G4ErrorMode_PropForwards;
256  if (!configurePropagation(mode, pDest, cmsInitPos, cmsInitMom))
257  return TsosPP(TrajectoryStateOnSurface(), 0.0f);
258 
259  // re-check propagation direction chosen in case of AnyDirection
260  if (mode == G4ErrorMode_PropBackwards && !flipped)
261  cmsInitMom = -cmsInitMom;
262 
263  CLHEP::Hep3Vector g4InitPos = TrackPropagation::globalPointToHep3Vector(cmsInitPos);
264  CLHEP::Hep3Vector g4InitMom = TrackPropagation::globalVectorToHep3Vector(cmsInitMom * GeV);
265 
266  debugReportTrackState("intitial", cmsInitPos, g4InitPos, cmsInitMom, g4InitMom, pDest);
267 
268  // Set the mode of propagation according to the propagation direction
269  // G4ErrorMode mode = G4ErrorMode_PropForwards;
270 
271  // if (!configurePropagation(mode, pDest, cmsInitPos, cmsInitMom))
272  // return TsosPP(TrajectoryStateOnSurface(), 0.0f);
273 
275  // Set the error and trajectories, and finally propagate
276  //
277  G4ErrorTrajErr g4error(5, 1);
278  if (ftsStart.hasError()) {
280  initErr = ftsStart.curvilinearError();
281  g4error = TrackPropagation::algebraicSymMatrix55ToG4ErrorTrajErr(initErr, ftsStart.charge());
282  LogDebug("Geant4e") << "CMS - Error matrix: " << std::endl << initErr.matrix();
283  } else {
284  LogDebug("Geant4e") << "No error matrix available" << std::endl;
285  return TsosPP(TrajectoryStateOnSurface(), 0.0f);
286  }
287 
288  LogDebug("Geant4e") << "G4e - Error matrix: " << std::endl << g4error;
289 
290  // in CMSSW, the state errors are deflated when performing the backward
291  // propagation
292  if (mode == G4ErrorMode_PropForwards) {
293  G4ErrorPropagatorData::GetErrorPropagatorData()->SetStage(G4ErrorStage_Inflation);
294  } else if (mode == G4ErrorMode_PropBackwards) {
295  G4ErrorPropagatorData::GetErrorPropagatorData()->SetStage(G4ErrorStage_Deflation);
296  }
297 
298  G4ErrorFreeTrajState g4eTrajState(generateParticleName(ftsStart.charge()), g4InitPos, g4InitMom, g4error);
299  LogDebug("Geant4e") << "G4e - Traj. State: " << (g4eTrajState);
300 
302  // Propagate
303  int iterations = 0;
304  double finalPathLength = 0;
305 
306  HepGeom::Point3D<double> finalRecoPos;
307 
308  G4ErrorPropagatorData::GetErrorPropagatorData()->SetMode(mode);
309 
310  theG4eData->SetTarget(g4eTarget_center.second.get());
311  LogDebug("Geant4e") << "Running Propagation to the RECO surface" << std::endl;
312 
313  theG4eManager->InitTrackPropagation();
314 
315  // re-initialize navigator to avoid mismatches and/or segfaults
316  theG4eManager->GetErrorPropagationNavigator()->LocateGlobalPointAndSetup(
317  g4InitPos, &g4InitMom, /*pRelativeSearch = */ false, /*ignoreDirection = */ false);
318 
319  bool continuePropagation = true;
320  while (continuePropagation) {
321  iterations++;
322  LogDebug("Geant4e") << std::endl << "step count " << iterations << " step length " << finalPathLength;
323 
324  // re-initialize navigator to avoid mismatches and/or segfaults
325  theG4eManager->GetErrorPropagationNavigator()->LocateGlobalPointWithinVolume(g4eTrajState.GetPosition());
326 
327  const int ierr = theG4eManager->PropagateOneStep(&g4eTrajState, mode);
328 
329  if (ierr != 0) {
330  // propagation failed, return invalid track state
331  return TsosPP(TrajectoryStateOnSurface(), 0.0f);
332  }
333 
334  const float thisPathLength = TrackPropagation::g4doubleToCmsDouble(g4eTrajState.GetG4Track()->GetStepLength());
335 
336  LogDebug("Geant4e") << "step Length was " << thisPathLength << " cm, current global position: "
337  << TrackPropagation::hepPoint3DToGlobalPoint(g4eTrajState.GetPosition()) << std::endl;
338 
339  finalPathLength += thisPathLength;
340 
341  // if (std::fabs(finalPathLength) > 10000.0f)
342  if (std::fabs(finalPathLength) > 200.0f) {
343  LogDebug("Geant4e") << "ERROR: Quitting propagation: path length mega large" << std::endl;
344  theG4eManager->GetPropagator()->InvokePostUserTrackingAction(g4eTrajState.GetG4Track());
345  continuePropagation = false;
346  LogDebug("Geant4e") << "WARNING: Quitting propagation: max path length "
347  "exceeded, returning invalid state"
348  << std::endl;
349 
350  // reached maximum path length, bail out
351  return TsosPP(TrajectoryStateOnSurface(), 0.0f);
352  }
353 
354  if (theG4eManager->GetPropagator()->CheckIfLastStep(g4eTrajState.GetG4Track())) {
355  theG4eManager->GetPropagator()->InvokePostUserTrackingAction(g4eTrajState.GetG4Track());
356  continuePropagation = false;
357  }
358  }
359 
360  // CMSSW Tracking convention, backward propagations have negative path length
362  finalPathLength = -finalPathLength;
363 
364  // store the correct location for the hit on the RECO surface
365  LogDebug("Geant4e") << "Position on the RECO surface" << g4eTrajState.GetPosition() << std::endl;
366  finalRecoPos = g4eTrajState.GetPosition();
367 
368  theG4eManager->EventTermination();
369 
370  LogDebug("Geant4e") << "Final position of the Track :" << g4eTrajState.GetPosition() << std::endl;
371 
373  // Retrieve the state in the end from Geant4e, convert them to CMS vectors
374  // and points, and build global trajectory parameters.
375  // CMS uses cm and GeV while Geant4 uses mm and MeV
376  //
377  const HepGeom::Vector3D<double> momEnd = g4eTrajState.GetMomentum();
378 
379  // use the hit on the the RECO plane as the final position to be d'accor with
380  // the RecHit measurements
381  const GlobalPoint posEndGV = TrackPropagation::hepPoint3DToGlobalPoint(finalRecoPos);
383 
384  debugReportTrackState("final", posEndGV, finalRecoPos, momEndGV, momEnd, pDest);
385 
386  // Get the error covariance matrix from Geant4e. It comes in curvilinear
387  // coordinates so use the appropiate CMS class
388  G4ErrorTrajErr g4errorEnd = g4eTrajState.GetError();
389 
390  CurvilinearTrajectoryError curvError(
392 
393  if (mode == G4ErrorMode_PropBackwards) {
395  posEndGV, momEndGV, ftsStart.parameters().charge(), &ftsStart.parameters().magneticField());
396 
397  // flip the momentum direction because it has been flipped before running
398  // G4's backwards prop
399  momEndGV = -momEndGV;
400  }
401 
402  LogDebug("Geant4e") << "G4e - Error matrix after propagation: " << std::endl << g4errorEnd;
403 
404  LogDebug("Geant4e") << "CMS - Error matrix after propagation: " << std::endl << curvError.matrix();
405 
406  GlobalTrajectoryParameters tParsDest(posEndGV, momEndGV, ftsStart.charge(), theField);
407 
409 
412 
413  return TsosPP(TrajectoryStateOnSurface(tParsDest, curvError, pDest, side), finalPathLength);
414 }
std::pair< TrajectoryStateOnSurface, double > TsosPP
const CurvilinearTrajectoryError & curvilinearError() const
void debugReportTrackState(std::string const &currentContext, GlobalPoint const &cmsInitPos, CLHEP::Hep3Vector const &g4InitPos, GlobalVector const &cmsInitMom, CLHEP::Hep3Vector const &g4InitMom, const SurfaceType &pDest) const
double g4doubleToCmsDouble(const G4double &d)
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
CLHEP::Hep3Vector globalVectorToHep3Vector(const GlobalVector &p)
const MagneticField * theField
const GlobalTrajectoryParameters & parameters() const
G4ErrorPropagatorManager * theG4eManager
GlobalPoint position() const
AlgebraicSymMatrix55 g4ErrorTrajErrToAlgebraicSymMatrix55(const G4ErrorTrajErr &e, const int q)
G4ErrorPropagatorData * theG4eData
TrackCharge charge() const
GlobalPoint hepPoint3DToGlobalPoint(const HepGeom::Point3D< double > &r)
std::pair< bool, std::shared_ptr< G4ErrorTarget > > ErrorTargetPair
GlobalVector momentum() const
double f[11][100]
const AlgebraicSymMatrix55 & matrix() const
const MagneticField & magneticField() const
GlobalVector hep3VectorToGlobalVector(const CLHEP::Hep3Vector &p)
std::string generateParticleName(int charge) const
bool configurePropagation(G4ErrorMode &mode, SurfaceType const &pDest, GlobalPoint const &cmsInitPos, GlobalVector const &cmsInitMom) const
G4ErrorTrajErr algebraicSymMatrix55ToG4ErrorTrajErr(const AlgebraicSymMatrix55 &e, const int q)
ErrorTargetPair transformToG4SurfaceTarget(const SurfaceType &pDest, bool moveTargetToEndOfSurface) const
CLHEP::Hep3Vector globalPointToHep3Vector(const GlobalPoint &r)
#define LogDebug(id)

◆ propagateWithPath() [1/4]

std::pair< TrajectoryStateOnSurface, double > Geant4ePropagator::propagateWithPath ( const FreeTrajectoryState ftsStart,
const Plane pDest 
) const
overridevirtual

Propagate from a free state (e.g. position and momentum in in global cartesian coordinates) to a surface.Propagate from a state on surface (e.g. position and momentum in in global cartesian coordinates associated with a layer) to a surface.The methods propagateWithPath() are identical to the corresponding methods propagate() in what concerns the resulting TrajectoryStateOnSurface, but they provide in addition the exact path length along the trajectory. All of these method calls are internally mapped to

The methods propagateWithPath() are identical to the corresponding methods propagate() in what concerns the resulting TrajectoryStateOnSurface, but they provide in addition the exact path length along the trajectory.

Implements Propagator.

Definition at line 426 of file Geant4ePropagator.cc.

References propagateGeneric().

427  {
428  // Finally build the pair<...> that needs to be returned where the second
429  // parameter is the exact path length. Currently calculated with a stepping
430  // action that adds up the length of every step
431  return propagateGeneric(ftsStart, pDest);
432 }
std::pair< TrajectoryStateOnSurface, double > propagateGeneric(const FreeTrajectoryState &ftsStart, const SurfaceType &pDest) const

◆ propagateWithPath() [2/4]

std::pair< TrajectoryStateOnSurface, double > Geant4ePropagator::propagateWithPath ( const FreeTrajectoryState ftsStart,
const Cylinder cDest 
) const
overridevirtual

Implements Propagator.

Definition at line 434 of file Geant4ePropagator.cc.

References propagateGeneric().

435  {
436  // Finally build the pair<...> that needs to be returned where the second
437  // parameter is the exact path length.
438  return propagateGeneric(ftsStart, cDest);
439 }
std::pair< TrajectoryStateOnSurface, double > propagateGeneric(const FreeTrajectoryState &ftsStart, const SurfaceType &pDest) const

◆ propagateWithPath() [3/4]

std::pair< TrajectoryStateOnSurface, double > Geant4ePropagator::propagateWithPath ( const TrajectoryStateOnSurface tsosStart,
const Plane pDest 
) const
overridevirtual

Reimplemented from Propagator.

Definition at line 441 of file Geant4ePropagator.cc.

References TrajectoryStateOnSurface::freeState(), and propagateGeneric().

442  {
443  // Finally build the pair<...> that needs to be returned where the second
444  // parameter is the exact path length.
445  const FreeTrajectoryState ftsStart = *tsosStart.freeState();
446  return propagateGeneric(ftsStart, pDest);
447 }
FreeTrajectoryState const * freeState(bool withErrors=true) const
std::pair< TrajectoryStateOnSurface, double > propagateGeneric(const FreeTrajectoryState &ftsStart, const SurfaceType &pDest) const

◆ propagateWithPath() [4/4]

std::pair< TrajectoryStateOnSurface, double > Geant4ePropagator::propagateWithPath ( const TrajectoryStateOnSurface tsosStart,
const Cylinder cDest 
) const
overridevirtual

Reimplemented from Propagator.

Definition at line 449 of file Geant4ePropagator.cc.

References TrajectoryStateOnSurface::freeState(), and propagateGeneric().

450  {
451  const FreeTrajectoryState ftsStart = *tsosStart.freeState();
452  // Finally build the pair<...> that needs to be returned where the second
453  // parameter is the exact path length.
454  return propagateGeneric(ftsStart, cDest);
455 }
FreeTrajectoryState const * freeState(bool withErrors=true) const
std::pair< TrajectoryStateOnSurface, double > propagateGeneric(const FreeTrajectoryState &ftsStart, const SurfaceType &pDest) const

◆ transformToG4SurfaceTarget() [1/3]

template<>
Geant4ePropagator::ErrorTargetPair Geant4ePropagator::transformToG4SurfaceTarget ( const Plane pDest,
bool  moveTargetToEndOfSurface 
) const

Definition at line 98 of file Geant4ePropagator.cc.

References TrackPropagation::globalPointToHepPoint3D(), TrackPropagation::globalVectorToHepNormal3D(), Surface::toGlobal(), and Vector3DBase< T, FrameTag >::unit().

99  {
100  //* Get position and normal (orientation) of the destination plane
101  GlobalPoint posPlane = pDest.toGlobal(LocalPoint(0, 0, 0));
102  GlobalVector normalPlane = pDest.toGlobal(LocalVector(0, 0, 1.));
103  normalPlane = normalPlane.unit();
104 
105  //* Transform this into HepGeom::Point3D<double> and
106  // HepGeom::Normal3D<double> that define a plane for
107  // Geant4e.
108  // CMS uses cm and GeV while Geant4 uses mm and MeV
109  HepGeom::Point3D<double> surfPos = TrackPropagation::globalPointToHepPoint3D(posPlane);
110  HepGeom::Normal3D<double> surfNorm = TrackPropagation::globalVectorToHepNormal3D(normalPlane);
111 
112  //* Set the target surface
113  return ErrorTargetPair(false, std::make_shared<G4ErrorPlaneSurfaceTarget>(surfNorm, surfPos));
114 }
Local3DVector LocalVector
Definition: LocalVector.h:12
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
HepGeom::Normal3D< double > globalVectorToHepNormal3D(const GlobalVector &p)
std::pair< bool, std::shared_ptr< G4ErrorTarget > > ErrorTargetPair
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
HepGeom::Point3D< double > globalPointToHepPoint3D(const GlobalPoint &r)
Vector3DBase unit() const
Definition: Vector3DBase.h:54

◆ transformToG4SurfaceTarget() [2/3]

template<class SurfaceType >
ErrorTargetPair Geant4ePropagator::transformToG4SurfaceTarget ( const SurfaceType &  pDest,
bool  moveTargetToEndOfSurface 
) const
private

Referenced by propagateGeneric().

◆ transformToG4SurfaceTarget() [3/3]

template<>
Geant4ePropagator::ErrorTargetPair Geant4ePropagator::transformToG4SurfaceTarget ( const Cylinder pDest,
bool  moveTargetToEndOfSurface 
) const

Definition at line 117 of file Geant4ePropagator.cc.

References TrackPropagation::globalPointToHep3Vector(), LogDebug, GloballyPositioned< T >::position(), Cylinder::radius(), idealTransformation::rotation, GloballyPositioned< T >::rotation(), and TrackPropagation::tkRotationFToHepRotation().

118  {
119  // Get Cylinder parameters.
120  // CMS uses cm and GeV while Geant4 uses mm and MeV.
121  // - Radius
122  G4float radCyl = pDest.radius() * cm;
123  // - Position: PositionType & GlobalPoint are Basic3DPoint<float,GlobalTag>
124  G4ThreeVector posCyl = TrackPropagation::globalPointToHep3Vector(pDest.position());
125  // - Rotation: Type in CMSSW is RotationType == TkRotation<T>, T=float
126  G4RotationMatrix rotCyl = TrackPropagation::tkRotationFToHepRotation(pDest.rotation());
127 
128  // DEBUG
130  LogDebug("Geant4e") << "G4e - TkRotation" << rotation;
131  LogDebug("Geant4e") << "G4e - G4Rotation" << rotCyl << "mm";
132 
133  return ErrorTargetPair(!moveTargetToEndOfSurface, std::make_shared<G4ErrorCylSurfaceTarget>(radCyl, posCyl, rotCyl));
134 }
CLHEP::HepRotation tkRotationFToHepRotation(const TkRotation< float > &tkr)
std::pair< bool, std::shared_ptr< G4ErrorTarget > > ErrorTargetPair
const PositionType & position() const
Scalar radius() const
Radius of the cylinder.
Definition: Cylinder.h:64
const RotationType & rotation() const
CLHEP::Hep3Vector globalPointToHep3Vector(const GlobalPoint &r)
#define LogDebug(id)

Member Data Documentation

◆ plimit_

double Geant4ePropagator::plimit_
private

Definition at line 95 of file Geant4ePropagator.h.

Referenced by configureAnyPropagation(), and configurePropagation().

◆ theField

const MagneticField* Geant4ePropagator::theField
private

Definition at line 87 of file Geant4ePropagator.h.

Referenced by magneticField(), and propagateGeneric().

◆ theG4eData

G4ErrorPropagatorData* Geant4ePropagator::theG4eData
private

Definition at line 94 of file Geant4ePropagator.h.

Referenced by propagateGeneric().

◆ theG4eManager

G4ErrorPropagatorManager* Geant4ePropagator::theG4eManager
private

Definition at line 93 of file Geant4ePropagator.h.

Referenced by ensureGeant4eIsInitilized(), and propagateGeneric().

◆ theParticleName

std::string Geant4ePropagator::theParticleName
private

Definition at line 90 of file Geant4ePropagator.h.

Referenced by generateParticleName().