19 #include "G4ErrorRunManagerHelper.hh" 20 #include "G4ErrorFreeTrajState.hh" 21 #include "G4ErrorPlaneSurfaceTarget.hh" 22 #include "G4ErrorCylSurfaceTarget.hh" 23 #include "G4ErrorPropagatorData.hh" 24 #include "G4EventManager.hh" 25 #include "G4SteppingControl.hh" 26 #include "G4TransportationManager.hh" 29 #include "G4UImanager.hh" 30 #include "G4GeometryTolerance.hh" 31 #include "G4TransportationManager.hh" 33 #include "G4FieldManager.hh" 36 #include "CLHEP/Units/GlobalSystemOfUnits.h" 42 Propagator(dir), theField(field), theParticleName(
43 particleName), theG4eManager(
44 G4ErrorPropagatorManager::GetErrorPropagatorManager()), theG4eData(
45 G4ErrorPropagatorData::GetErrorPropagatorData())
47 LogDebug(
"Geant4e") <<
"Geant4e Propagator initialized";
58 LogDebug(
"Geant4e") <<
"Geant4ePropagator::~Geant4ePropagator()" << std::endl;
74 LogDebug(
"Geant4e") <<
"ensureGeant4eIsInitilized called" << std::endl;
75 if ( (G4ErrorPropagatorData::GetErrorPropagatorData()->GetState()
76 == G4ErrorState_PreInit) || forceInit )
78 LogDebug(
"Geant4e") <<
"Initializing G4 propagator" << std::endl;
80 G4UImanager::GetUIpointer()->ApplyCommand(
81 "/exerror/setField -10. kilogauss");
85 const G4Field* field =
86 G4TransportationManager::GetTransportationManager()->GetFieldManager()->GetDetectorField();
91 LogDebug(
"Geant4e") <<
"G4 propagator initialized" << std::endl;
94 LogDebug(
"Geant4e") <<
"G4 not in preinit state: " << G4ErrorPropagatorData::GetErrorPropagatorData()->GetState() << std::endl;
99 G4UImanager::GetUIpointer()->ApplyCommand(
100 "/geant4e/limits/stepLength 10.0 mm");
105 const Plane& pDest,
bool moveTargetToEndOfSurface)
const 110 normalPlane = normalPlane.
unit();
115 HepGeom::Point3D<double> surfPos =
117 HepGeom::Normal3D<double> surfNorm =
122 std::make_shared < G4ErrorPlaneSurfaceTarget > (surfNorm, surfPos));
127 const Cylinder& pDest,
bool moveTargetToEndOfSurface)
const 132 G4float radCyl = pDest.
radius() * cm;
143 LogDebug(
"Geant4e") <<
"G4e - G4Rotation" << rotCyl <<
"mm";
146 std::make_shared < G4ErrorCylSurfaceTarget
147 > (radCyl, posCyl, rotCyl));
185 if (pDest.
localZ(cmsInitPos) * pDest.
localZ(cmsInitMom) < 0)
187 mode = G4ErrorMode_PropForwards;
188 LogDebug(
"Geant4e") <<
"G4e - Propagator mode is \'forwards\' indirect via the Any direction" << std::endl;
192 mode = G4ErrorMode_PropBackwards;
193 LogDebug(
"Geant4e") <<
"G4e - Propagator mode is \'backwards\' indirect via the Any direction" << std::endl;
211 mode = G4ErrorMode_PropBackwards;
212 LogDebug(
"Geant4e") <<
"G4e - Propagator mode is \'backwards\' indirect via the Any direction";
216 mode = G4ErrorMode_PropForwards;
217 LogDebug(
"Geant4e") <<
"G4e - Propagator mode is \'forwards\' indirect via the Any direction";
223 template<
class SurfaceType>
225 SurfaceType
const& pDest,
GlobalPoint const& cmsInitPos,
230 mode = G4ErrorMode_PropBackwards;
231 LogDebug(
"Geant4e") <<
"G4e - Propagator mode is \'backwards\' " << std::endl;
235 mode = G4ErrorMode_PropForwards;
236 LogDebug(
"Geant4e") <<
"G4e - Propagator mode is \'forwards\'" << std::endl;
246 edm::LogError(
"Geant4e") <<
"G4e - Unsupported propagation mode";
252 template<
class SurfaceType>
272 cmsInitMom = -cmsInitMom;
277 G4ErrorMode
mode = G4ErrorMode_PropForwards;
282 if (mode == G4ErrorMode_PropBackwards && !flipped)
283 cmsInitMom = -cmsInitMom;
303 G4ErrorTrajErr g4error(5, 1);
309 initErr, ftsStart.
charge());
310 LogDebug(
"Geant4e") <<
"CMS - Error matrix: " << std::endl
314 LogDebug(
"Geant4e") <<
"No error matrix available" << std::endl;
318 LogDebug(
"Geant4e") <<
"G4e - Error matrix: " << std::endl << g4error;
321 if (mode == G4ErrorMode_PropForwards)
323 G4ErrorPropagatorData::GetErrorPropagatorData()->SetStage(
324 G4ErrorStage_Inflation);
326 else if (mode == G4ErrorMode_PropBackwards)
328 G4ErrorPropagatorData::GetErrorPropagatorData()->SetStage(
329 G4ErrorStage_Deflation);
333 g4InitPos, g4InitMom, g4error);
334 LogDebug(
"Geant4e") <<
"G4e - Traj. State: " << (g4eTrajState);
339 double finalPathLength = 0;
341 HepGeom::Point3D<double> finalRecoPos;
343 G4ErrorPropagatorData::GetErrorPropagatorData()->SetMode(mode);
345 theG4eData->SetTarget(g4eTarget_center.second.get());
346 LogDebug(
"Geant4e") <<
"Running Propagation to the RECO surface" << std::endl;
350 bool continuePropagation =
true;
351 while (continuePropagation)
354 LogDebug(
"Geant4e") << std::endl <<
"step count " << iterations <<
" step length " << finalPathLength;
356 const int ierr =
theG4eManager->PropagateOneStep(&g4eTrajState, mode);
365 g4eTrajState.GetG4Track()->GetStepLength());
369 finalPathLength += thisPathLength;
372 if (std::fabs(finalPathLength) > 200.0f)
375 <<
"ERROR: Quitting propagation: path length mega large" 377 theG4eManager->GetPropagator()->InvokePostUserTrackingAction(
378 g4eTrajState.GetG4Track());
379 continuePropagation =
false;
381 <<
"WARNING: Quitting propagation: max path length exceeded, returning invalid state" 389 g4eTrajState.GetG4Track()))
391 theG4eManager->GetPropagator()->InvokePostUserTrackingAction(
392 g4eTrajState.GetG4Track());
393 continuePropagation =
false;
399 finalPathLength = -finalPathLength;
402 LogDebug(
"Geant4e") <<
"Position on the RECO surface" 403 << g4eTrajState.GetPosition() << std::endl;
404 finalRecoPos = g4eTrajState.GetPosition();
408 LogDebug(
"Geant4e") <<
"Final position of the Track :" << g4eTrajState.GetPosition()
416 const HepGeom::Vector3D<double> momEnd = g4eTrajState.GetMomentum();
430 G4ErrorTrajErr g4errorEnd = g4eTrajState.GetError();
436 if (mode == G4ErrorMode_PropBackwards)
443 momEndGV = -momEndGV;
446 LogDebug(
"Geant4e") <<
"G4e - Error matrix after propagation: " 447 << std::endl << g4errorEnd;
449 LogDebug(
"Geant4e") <<
"CMS - Error matrix after propagation: " 450 << std::endl << curvError.
matrix();
514 HepGeom::Point3D<double>
const& surfPos,
516 HepGeom::Normal3D<double>
const& surfNorm,
const Plane& pDest)
const 518 LogDebug(
"Geant4e") <<
"G4e - Destination CMS plane position:" << posPlane
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()
526 LogDebug(
"Geant4e") <<
"G4e - Destination CMS plane normal : " 527 << normalPlane <<
"\n" 528 <<
"G4e - Destination G4 plane normal : " 530 LogDebug(
"Geant4e") <<
"G4e - Distance from plane position to plane: " 531 << pDest.
localZ(posPlane) <<
" cm";
534 template<
class SurfaceType>
536 GlobalPoint const& cmsInitPos, CLHEP::Hep3Vector
const& g4InitPos,
537 GlobalVector const& cmsInitMom, CLHEP::Hep3Vector
const& g4InitMom,
538 const SurfaceType& pDest)
const 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";
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
std::pair< TrajectoryStateOnSurface, double > TsosPP
Local3DVector LocalVector
Point3DBase< Scalar, LocalTag > LocalPoint
Geant4ePropagator(const MagneticField *field=0, std::string particleName="mu", PropagationDirection dir=alongMomentum)
const GlobalTrajectoryParameters & parameters() const
HepGeom::Normal3D< double > globalVectorToHepNormal3D(const GlobalVector &p)
void debugReportPlaneSetup(GlobalPoint const &posPlane, HepGeom::Point3D< double > const &surfPos, GlobalVector const &normalPlane, HepGeom::Normal3D< double > const &surfNorm, const Plane &pDest) const
Side side(const LocalPoint &p, Scalar toler) const override
double g4doubleToCmsDouble(const G4double &d)
Geom::Phi< T > phi() const
float localZ(const GlobalPoint &gp) const
std::string theParticleName
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
CLHEP::HepRotation tkRotationFToHepRotation(const TkRotation< float > &tkr)
virtual PropagationDirection propagationDirection() const final
Scalar radius() const
Radius of the cylinder.
AlgebraicSymMatrix55 g4ErrorTrajErrToAlgebraicSymMatrix55(const G4ErrorTrajErr &e, const int q)
G4ErrorPropagatorData * theG4eData
LocalPoint toLocal(const GlobalPoint &gp) const
FreeTrajectoryState const * freeState(bool withErrors=true) const
void debugReportTrackState(std::string const ¤tContext, 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)
GlobalVector momentum() const
Vector3DBase unit() const
std::pair< TrajectoryStateOnSurface, double > propagateGeneric(const FreeTrajectoryState &ftsStart, const SurfaceType &pDest) const
GlobalPoint position() const
HepGeom::Point3D< double > globalPointToHepPoint3D(const GlobalPoint &r)
~Geant4ePropagator() override
ErrorTargetPair transformToG4SurfaceTarget(const SurfaceType &pDest, bool moveTargetToEndOfSurface) const
std::string getSurfaceType(SurfaceType const &surface) const
GlobalVector hep3VectorToGlobalVector(const CLHEP::Hep3Vector &p)
bool configureAnyPropagation(G4ErrorMode &mode, SurfaceType const &pDest, GlobalPoint const &cmsInitPos, GlobalVector const &cmsInitMom) const
const AlgebraicSymMatrix55 & matrix() const
const RotationType & rotation() const
const MagneticField & magneticField() const
G4ErrorTrajErr algebraicSymMatrix55ToG4ErrorTrajErr(const AlgebraicSymMatrix55 &e, const int q)
std::string generateParticleName(int charge) const
std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Plane &) const override
TrackCharge charge() const
const PositionType & position() const
CLHEP::Hep3Vector globalPointToHep3Vector(const GlobalPoint &r)
void ensureGeant4eIsInitilized(bool forceInit) const
std::pair< bool, std::shared_ptr< G4ErrorTarget > > ErrorTargetPair