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

virtual 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=0, std::string particleName="mu", PropagationDirection dir=alongMomentum)
 
template<>
std::string getSurfaceType (Cylinder const &c) const
 
template<>
std::string getSurfaceType (Plane const &c) const
 
virtual const MagneticFieldmagneticField () const override
 
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath (const FreeTrajectoryState &, const Plane &) const override
 
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath (const FreeTrajectoryState &, const Cylinder &) const override
 
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath (const TrajectoryStateOnSurface &, const Plane &) const override
 
virtual 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
 
virtual ~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

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

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

Definition at line 83 of file Geant4ePropagator.h.

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

Definition at line 82 of file Geant4ePropagator.h.

Constructor & Destructor Documentation

Geant4ePropagator::Geant4ePropagator ( const MagneticField field = 0,
std::string  particleName = "mu",
PropagationDirection  dir = alongMomentum 
)

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().

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

Destructor.

Definition at line 56 of file Geant4ePropagator.cc.

References LogDebug.

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

Member Function Documentation

virtual Geant4ePropagator* Geant4ePropagator::clone ( void  ) const
inlineoverridevirtual

Implements Propagator.

Definition at line 72 of file Geant4ePropagator.h.

References Geant4ePropagator().

72  {
73  return new Geant4ePropagator(*this);
74  }
Geant4ePropagator(const MagneticField *field=0, std::string particleName="mu", PropagationDirection dir=alongMomentum)
template<class SurfaceType >
bool Geant4ePropagator::configureAnyPropagation ( G4ErrorMode &  mode,
SurfaceType const &  pDest,
GlobalPoint const &  cmsInitPos,
GlobalVector const &  cmsInitMom 
) const
private

Referenced by configurePropagation().

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

Definition at line 181 of file Geant4ePropagator.cc.

References Plane::localZ(), and LogDebug.

184 {
185  if (pDest.localZ(cmsInitPos) * pDest.localZ(cmsInitMom) < 0)
186  {
187  mode = G4ErrorMode_PropForwards;
188  LogDebug("Geant4e") << "G4e - Propagator mode is \'forwards\' indirect via the Any direction" << std::endl;
189  }
190  else
191  {
192  mode = G4ErrorMode_PropBackwards;
193  LogDebug("Geant4e") << "G4e - Propagator mode is \'backwards\' indirect via the Any direction" << std::endl;
194  }
195 
196  return true;
197 }
#define LogDebug(id)
template<>
bool Geant4ePropagator::configureAnyPropagation ( G4ErrorMode &  mode,
Cylinder const &  pDest,
GlobalPoint const &  cmsInitPos,
GlobalVector const &  cmsInitMom 
) const

Definition at line 200 of file Geant4ePropagator.cc.

References LogDebug, SurfaceOrientation::positiveSide, Cylinder::side(), and GloballyPositioned< T >::toLocal().

203 {
204  //------------------------------------
205  //For cylinder assume outside is backwards, inside is along
206  //General use for particles from collisions
207  LocalPoint lpos = pDest.toLocal(cmsInitPos);
208  Surface::Side theSide = pDest.side(lpos, 0);
209  if (theSide == SurfaceOrientation::positiveSide)
210  { //outside cylinder
211  mode = G4ErrorMode_PropBackwards;
212  LogDebug("Geant4e") << "G4e - Propagator mode is \'backwards\' indirect via the Any direction";
213  }
214  else
215  { //inside cylinder
216  mode = G4ErrorMode_PropForwards;
217  LogDebug("Geant4e") << "G4e - Propagator mode is \'forwards\' indirect via the Any direction";
218  }
219 
220  return true;
221 }
#define LogDebug(id)
template<class SurfaceType >
bool Geant4ePropagator::configurePropagation ( G4ErrorMode &  mode,
SurfaceType const &  pDest,
GlobalPoint const &  cmsInitPos,
GlobalVector const &  cmsInitMom 
) const
private

Definition at line 224 of file Geant4ePropagator.cc.

References alongMomentum, anyDirection, configureAnyPropagation(), LogDebug, oppositeToMomentum, and Propagator::propagationDirection().

Referenced by propagateGeneric().

227 {
229  {
230  mode = G4ErrorMode_PropBackwards;
231  LogDebug("Geant4e") << "G4e - Propagator mode is \'backwards\' " << std::endl;
232  }
233  else if (propagationDirection() == alongMomentum)
234  {
235  mode = G4ErrorMode_PropForwards;
236  LogDebug("Geant4e") << "G4e - Propagator mode is \'forwards\'" << std::endl;
237  }
238  else if (propagationDirection() == anyDirection)
239  {
240  if (configureAnyPropagation(mode, pDest, cmsInitPos, cmsInitMom)
241  == false)
242  return false;
243  }
244  else
245  {
246  edm::LogError("Geant4e") << "G4e - Unsupported propagation mode";
247  return false;
248  }
249  return true;
250 }
#define LogDebug(id)
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:151
bool configureAnyPropagation(G4ErrorMode &mode, SurfaceType const &pDest, GlobalPoint const &cmsInitPos, GlobalVector const &cmsInitMom) const
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 513 of file Geant4ePropagator.cc.

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

517 {
518  LogDebug("Geant4e") << "G4e - Destination CMS plane position:" << posPlane
519  << "cm\n"
520  << "G4e - (Ro, eta, phi): ("
521  << posPlane.perp() << " cm, " << posPlane.eta()
522  << ", " << posPlane.phi().degrees() << " deg)\n"
523  << "G4e - Destination G4 plane position: "
524  << surfPos << " mm, Ro = " << surfPos.perp()
525  << " mm";
526  LogDebug("Geant4e") << "G4e - Destination CMS plane normal : "
527  << normalPlane << "\n"
528  << "G4e - Destination G4 plane normal : "
529  << normalPlane;
530  LogDebug("Geant4e") << "G4e - Distance from plane position to plane: "
531  << pDest.localZ(posPlane) << " cm";
532 }
#define LogDebug(id)
float localZ(const GlobalPoint &gp) const
Definition: Plane.h:45
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 535 of file Geant4ePropagator.cc.

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

Referenced by propagateGeneric().

539 {
540  LogDebug("Geant4e") << "G3 -- Current Context: " << currentContext;
541  LogDebug("Geant4e") << "G4e - CMS point position:" << cmsInitPos << "cm\n"
542  << "G4e - (Ro, eta, phi): ("
543  << cmsInitPos.perp() << " cm, "
544  << cmsInitPos.eta() << ", "
545  << cmsInitPos.phi().degrees() << " deg)\n"
546  << "G4e - G4 point position: " << g4InitPos
547  << " mm, Ro = " << g4InitPos.perp() << " mm";
548  LogDebug("Geant4e") << "G4e - CMS momentum :" << cmsInitMom
549  << "GeV\n" << " pt: " << cmsInitMom.perp()
550  << "G4e - G4 momentum : "
551  << g4InitMom << " MeV";
552 }
#define LogDebug(id)
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 72 of file Geant4ePropagator.cc.

References LogDebug, and theG4eManager.

Referenced by Geant4ePropagator().

73 {
74  LogDebug("Geant4e") << "ensureGeant4eIsInitilized called" << std::endl;
75  if ( (G4ErrorPropagatorData::GetErrorPropagatorData()->GetState()
76  == G4ErrorState_PreInit) || forceInit )
77  {
78  LogDebug("Geant4e") << "Initializing G4 propagator" << std::endl;
79 
80  G4UImanager::GetUIpointer()->ApplyCommand(
81  "/exerror/setField -10. kilogauss");
82 
83  theG4eManager->InitGeant4e();
84 
85  const G4Field* field =
86  G4TransportationManager::GetTransportationManager()->GetFieldManager()->GetDetectorField();
87  if (field == nullptr)
88  {
89  edm::LogError("Geant4e") << "No G4 magnetic field defined";
90  }
91  LogDebug("Geant4e") << "G4 propagator initialized" << std::endl;
92  }
93  else {
94  LogDebug("Geant4e") << "G4 not in preinit state: " << G4ErrorPropagatorData::GetErrorPropagatorData()->GetState() << std::endl;
95  }
96 
97  // example code uses
98  // G4UImanager::GetUIpointer()->ApplyCommand("/geant4e/limits/stepLength 100 mm");
99  G4UImanager::GetUIpointer()->ApplyCommand(
100  "/geant4e/limits/stepLength 10.0 mm");
101 }
#define LogDebug(id)
G4ErrorPropagatorManager * theG4eManager
std::string Geant4ePropagator::generateParticleName ( int  charge) const
private

Definition at line 162 of file Geant4ePropagator.cc.

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

Referenced by propagateGeneric().

163 {
165 
166  if (charge > 0)
167  {
168  particleName += "+";
169  }
170  if ( charge < 0)
171  {
172  particleName += "-";
173  }
174 
175  LogDebug("Geant4e") << "G4e - Particle name: " << particleName;
176 
177  return particleName;
178 }
#define LogDebug(id)
std::string theParticleName
template<class SurfaceType >
std::string Geant4ePropagator::getSurfaceType ( SurfaceType const &  surface) const
private
template<>
std::string Geant4ePropagator::getSurfaceType ( Cylinder const &  c) const

Definition at line 151 of file Geant4ePropagator.cc.

152 {
153  return "Cylinder";
154 }
template<>
std::string Geant4ePropagator::getSurfaceType ( Plane const &  c) const

Definition at line 157 of file Geant4ePropagator.cc.

158 {
159  return "Plane";
160 }
virtual const MagneticField* Geant4ePropagator::magneticField ( ) const
inlineoverridevirtual

Implements Propagator.

Definition at line 76 of file Geant4ePropagator.h.

References theField.

76  {
77  return theField;
78  }
const MagneticField * theField
template<class SurfaceType >
std::pair< TrajectoryStateOnSurface, double > Geant4ePropagator::propagateGeneric ( const FreeTrajectoryState ftsStart,
const SurfaceType &  pDest 
) const
private

Definition at line 253 of file Geant4ePropagator.cc.

References SurfaceSideDefinition::afterSurface, TrackPropagation::algebraicSymMatrix55ToG4ErrorTrajErr(), alongMomentum, SurfaceSideDefinition::beforeSurface, GlobalTrajectoryParameters::charge(), FreeTrajectoryState::charge(), configurePropagation(), FreeTrajectoryState::curvilinearError(), debugReportTrackState(), f, TrackPropagation::g4doubleToCmsDouble(), TrackPropagation::g4ErrorTrajErrToAlgebraicSymMatrix55(), generateParticleName(), GeV, 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().

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

References propagateGeneric().

477 {
478  //Finally build the pair<...> that needs to be returned where the second
479  //parameter is the exact path length. Currently calculated with a stepping
480  //action that adds up the length of every step
481  return propagateGeneric(ftsStart, pDest);
482 
483 }
std::pair< TrajectoryStateOnSurface, double > propagateGeneric(const FreeTrajectoryState &ftsStart, const SurfaceType &pDest) const
std::pair< TrajectoryStateOnSurface, double > Geant4ePropagator::propagateWithPath ( const FreeTrajectoryState ftsStart,
const Cylinder cDest 
) const
overridevirtual

Implements Propagator.

Definition at line 485 of file Geant4ePropagator.cc.

References propagateGeneric().

487 {
488  //Finally build the pair<...> that needs to be returned where the second
489  //parameter is the exact path length.
490  return propagateGeneric(ftsStart, cDest);
491 }
std::pair< TrajectoryStateOnSurface, double > propagateGeneric(const FreeTrajectoryState &ftsStart, const SurfaceType &pDest) const
std::pair< TrajectoryStateOnSurface, double > Geant4ePropagator::propagateWithPath ( const TrajectoryStateOnSurface tsosStart,
const Plane pDest 
) const
overridevirtual

Reimplemented from Propagator.

Definition at line 493 of file Geant4ePropagator.cc.

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

495 {
496  //Finally build the pair<...> that needs to be returned where the second
497  //parameter is the exact path length.
498  const FreeTrajectoryState ftsStart = *tsosStart.freeState();
499  return propagateGeneric(ftsStart, pDest);
500 
501 }
FreeTrajectoryState const * freeState(bool withErrors=true) const
std::pair< TrajectoryStateOnSurface, double > propagateGeneric(const FreeTrajectoryState &ftsStart, const SurfaceType &pDest) const
std::pair< TrajectoryStateOnSurface, double > Geant4ePropagator::propagateWithPath ( const TrajectoryStateOnSurface tsosStart,
const Cylinder cDest 
) const
overridevirtual

Reimplemented from Propagator.

Definition at line 503 of file Geant4ePropagator.cc.

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

505 {
506  const FreeTrajectoryState ftsStart = *tsosStart.freeState();
507  //Finally build the pair<...> that needs to be returned where the second
508  //parameter is the exact path length.
509  return propagateGeneric(ftsStart, cDest);
510 
511 }
FreeTrajectoryState const * freeState(bool withErrors=true) const
std::pair< TrajectoryStateOnSurface, double > propagateGeneric(const FreeTrajectoryState &ftsStart, const SurfaceType &pDest) const
template<class SurfaceType >
ErrorTargetPair Geant4ePropagator::transformToG4SurfaceTarget ( const SurfaceType &  pDest,
bool  moveTargetToEndOfSurface 
) const
private

Referenced by propagateGeneric().

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

Definition at line 104 of file Geant4ePropagator.cc.

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

106 {
107  //* Get position and normal (orientation) of the destination plane
108  GlobalPoint posPlane = pDest.toGlobal(LocalPoint(0, 0, 0));
109  GlobalVector normalPlane = pDest.toGlobal(LocalVector(0, 0, 1.));
110  normalPlane = normalPlane.unit();
111 
112  //* Transform this into HepGeom::Point3D<double> and HepGeom::Normal3D<double> that define a plane for
113  // Geant4e.
114  // CMS uses cm and GeV while Geant4 uses mm and MeV
115  HepGeom::Point3D<double> surfPos =
117  HepGeom::Normal3D<double> surfNorm =
119 
120  //* Set the target surface
121  return ErrorTargetPair(false,
122  std::make_shared < G4ErrorPlaneSurfaceTarget > (surfNorm, surfPos));
123 }
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
Local3DVector LocalVector
Definition: LocalVector.h:12
HepGeom::Normal3D< double > globalVectorToHepNormal3D(const GlobalVector &p)
Vector3DBase unit() const
Definition: Vector3DBase.h:57
HepGeom::Point3D< double > globalPointToHepPoint3D(const GlobalPoint &r)
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
std::pair< bool, std::shared_ptr< G4ErrorTarget > > ErrorTargetPair
template<>
Geant4ePropagator::ErrorTargetPair Geant4ePropagator::transformToG4SurfaceTarget ( const Cylinder pDest,
bool  moveTargetToEndOfSurface 
) const

Definition at line 126 of file Geant4ePropagator.cc.

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

128 {
129  //Get Cylinder parameters.
130  //CMS uses cm and GeV while Geant4 uses mm and MeV.
131  // - Radius
132  G4float radCyl = pDest.radius() * cm;
133  // - Position: PositionType & GlobalPoint are Basic3DPoint<float,GlobalTag>
134  G4ThreeVector posCyl = TrackPropagation::globalPointToHep3Vector(
135  pDest.position());
136  // - Rotation: Type in CMSSW is RotationType == TkRotation<T>, T=float
137  G4RotationMatrix rotCyl = TrackPropagation::tkRotationFToHepRotation(
138  pDest.rotation());
139 
140  //DEBUG
142  LogDebug("Geant4e") << "G4e - TkRotation" << rotation;
143  LogDebug("Geant4e") << "G4e - G4Rotation" << rotCyl << "mm";
144 
145  return ErrorTargetPair(!moveTargetToEndOfSurface,
146  std::make_shared < G4ErrorCylSurfaceTarget
147  > (radCyl, posCyl, rotCyl));
148 }
#define LogDebug(id)
CLHEP::HepRotation tkRotationFToHepRotation(const TkRotation< float > &tkr)
Scalar radius() const
Radius of the cylinder.
Definition: Cylinder.h:67
const RotationType & rotation() const
const PositionType & position() const
CLHEP::Hep3Vector globalPointToHep3Vector(const GlobalPoint &r)
std::pair< bool, std::shared_ptr< G4ErrorTarget > > ErrorTargetPair

Member Data Documentation

const MagneticField* Geant4ePropagator::theField
private

Definition at line 86 of file Geant4ePropagator.h.

Referenced by magneticField(), and propagateGeneric().

G4ErrorPropagatorData* Geant4ePropagator::theG4eData
private

Definition at line 93 of file Geant4ePropagator.h.

Referenced by propagateGeneric().

G4ErrorPropagatorManager* Geant4ePropagator::theG4eManager
private

Definition at line 92 of file Geant4ePropagator.h.

Referenced by ensureGeant4eIsInitilized(), and propagateGeneric().

std::string Geant4ePropagator::theParticleName
private

Definition at line 89 of file Geant4ePropagator.h.

Referenced by generateParticleName().