Belle II Software  release-06-02-00
TrackExtrapolateG4e.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 /* Tracking headers. */
12 #include <tracking/dataobjects/ExtHit.h>
13 #include <tracking/dataobjects/RecoTrack.h>
14 #include <tracking/dataobjects/TrackClusterSeparation.h>
15 
16 /* Belle 2 headers. */
17 #include <framework/database/DBObjPtr.h>
18 #include <framework/datastore/StoreArray.h>
19 #include <framework/gearbox/Const.h>
20 #include <ir/dbobjects/BeamPipeGeo.h>
21 #include <klm/dataobjects/bklm/BKLMElementNumbers.h>
22 #include <klm/dataobjects/bklm/BKLMHit2d.h>
23 #include <klm/dataobjects/KLMElementNumbers.h>
24 #include <klm/dataobjects/eklm/EKLMElementNumbers.h>
25 #include <klm/dbobjects/KLMChannelStatus.h>
26 #include <klm/dbobjects/KLMStripEfficiency.h>
27 #include <klm/dbobjects/KLMLikelihoodParameters.h>
28 #include <klm/dataobjects/eklm/EKLMHit2d.h>
29 #include <klm/eklm/geometry/TransformDataGlobalAligned.h>
30 #include <structure/dbobjects/COILGeometryPar.h>
31 
32 /* Geant4 headers. */
33 #include <G4ErrorTrajErr.hh>
34 #include <G4ThreeVector.hh>
35 #include <G4TouchableHandle.hh>
36 
37 /* C++ headers. */
38 #include <map>
39 #include <string>
40 #include <vector>
41 
42 class G4ErrorSymMatrix;
43 class G4VPhysicalVolume;
44 class G4ErrorFreeTrajState;
45 class G4StepPoint;
46 
47 namespace Belle2 {
53  class ECLCluster;
54  class KLMCluster;
55  class KLMMuidHit;
56  class KLMMuidLikelihood;
57  class MuidBuilder;
58  class Track;
59 
60  namespace Simulation {
61  class ExtCylSurfaceTarget;
62  class ExtManager;
63  }
64 
66  enum VolTypes {
89  };
90 
92  struct ExtState {
94  const Track* track;
96  int pdgCode;
98  bool isCosmic;
100  double tof;
102  double length;
104  G4ThreeVector directionAtIP;
106  double chi2;
108  int nPoint;
126  bool escaped;
127  };
128 
130  struct Intersection {
132  int hit;
134  bool inBarrel;
136  bool isForward;
138  int sector;
140  int layer;
142  G4ThreeVector position;
144  G4ThreeVector momentum;
146  G4ErrorSymMatrix covariance;
148  G4ThreeVector positionAtHitPlane;
150  double time;
152  double chi2;
153  };
154 
170 
171  public:
172 
175 
178 
184  void initialize(double minPt, double minKE,
185  std::vector<Const::ChargedStable>& hypotheses);
186 
198  void initialize(double meanDt, double maxDt, double maxSeparation,
199  double maxKLMTrackClusterDistance, double maxECLTrackClusterDistance,
200  double minPt, double minKE, bool addHitsToRecoTrack, std::vector<Const::ChargedStable>& hypotheses);
201 
204  void beginRun(bool flag);
205 
208  void event(bool flag);
209 
212  void endRun(bool flag);
213 
216  void terminate(bool flag);
217 
224  void extrapolate(int pdgCode,
225  double tof,
226  const G4ThreeVector& position,
227  const G4ThreeVector& momentum,
228  const G4ErrorSymMatrix& covariance);
229 
237  void identifyMuon(int pdgCode,
238  double tof,
239  bool isCosmic,
240  const G4ThreeVector& position,
241  const G4ThreeVector& momentum,
242  const G4ErrorSymMatrix& covariance);
243 
244  private:
245 
248 
251 
253  void swim(ExtState&, G4ErrorFreeTrajState&,
254  const std::vector<std::pair<ECLCluster*, G4ThreeVector> >*,
255  const std::vector<std::pair<KLMCluster*, G4ThreeVector> >*,
256  std::vector<std::map<const Track*, double> >*);
257 
259  void swim(ExtState&, G4ErrorFreeTrajState&);
260 
263  void registerVolumes();
264 
266  void getVolumeID(const G4TouchableHandle&, Const::EDetector&, int&);
267 
269  void fromG4eToPhasespace(const G4ErrorFreeTrajState&, G4ErrorSymMatrix&);
270 
272  void fromPhasespaceToG4e(const G4ThreeVector&, const G4ErrorSymMatrix&, G4ErrorTrajErr&);
273 
275  void fromPhasespaceToG4e(const TVector3&, const TMatrixDSym&, G4ErrorTrajErr&);
276 
278  ExtState getStartPoint(const Track&, int, G4ErrorFreeTrajState&);
279 
281  void createExtHit(ExtHitStatus, const ExtState&, const G4ErrorFreeTrajState&, const G4StepPoint*, const G4TouchableHandle&);
282 
284  void createECLHit(const ExtState&, const G4ErrorFreeTrajState&, const G4StepPoint*, const G4StepPoint*, const G4TouchableHandle&,
285  const std::pair<ECLCluster*, G4ThreeVector>&, double, double);
286 
288  bool createMuidHit(ExtState&, G4ErrorFreeTrajState&, KLMMuidLikelihood*, std::vector<std::map<const Track*, double> >*);
289 
291  bool findBarrelIntersection(ExtState&, const G4ThreeVector&, Intersection&);
292 
294  bool findEndcapIntersection(ExtState&, const G4ThreeVector&, Intersection&);
295 
298 
301 
303  void adjustIntersection(Intersection&, const double*, const G4ThreeVector&, const G4ThreeVector&);
304 
306  void finishTrack(const ExtState&, KLMMuidLikelihood*, bool);
307 
310 
313 
316 
318  double m_MeanDt;
319 
321  double m_MaxDt;
322 
325 
328 
331 
334 
336  double m_MinPt;
337 
339  double m_MinKE;
340 
343 
345  const std::vector<Const::ChargedStable>* m_HypothesesExt;
346 
348  const std::vector<Const::ChargedStable>* m_HypothesesMuid;
349 
351  std::vector<Const::ChargedStable>* m_DefaultHypotheses;
352 
354  std::map<G4VPhysicalVolume*, enum VolTypes>* m_EnterExit;
355 
357  std::vector<G4VPhysicalVolume*>* m_BKLMVolumes;
358 
361 
364 
367 
370 
373 
375  double m_OffsetZ;
376 
379 
381  double m_BarrelMaxR;
382 
384  double m_BarrelMinR;
385 
388 
391 
394 
397 
400 
404 
407 
410 
412  double m_EndcapMaxR;
413 
415  double m_EndcapMinR;
416 
419 
422 
425 
428 
431 
434 
436  bool m_addHitsToRecoTrack = false;
437 
439  std::map<int, MuidBuilder*> m_MuidBuilderMap;
440 
443 
446 
449 
452 
455 
458 
461 
464 
467 
470 
473 
476 
479 
482 
485 
488 
489  };
490 
492 } // end of namespace Belle2
static constexpr int getMaximalLayerNumber()
Get maximal layer number (1-based).
static constexpr int getMaximalSectorNumber()
Get maximal sector number (1-based).
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:42
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
EKLM element numbers.
Transformation data (global, aligned): singleton version.
KLM element numbers.
Class to store the likelihoods from KLM with additional informations related to the extrapolation.
Defines a closed cylinder for the geant4e "target", the surface that encloses the volume within which...
It is the main interface for the user to define the setup and start the propagation.
Definition: ExtManager.h:50
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
geant4e-based track extrapolation.
double m_BarrelScintVariance
BKLM scintillator strip position variance (cm^2)
double m_EndcapHalfLength
half-length (cm) of either endcap
double m_MaxKLMTrackClusterDistance
user-defined maximum distance (mm) between KLMCluster and associated track (for KLID)
TrackExtrapolateG4e(TrackExtrapolateG4e &)
copy constructor is hidden; user calls TrackExtrapolateG4e::getInstance() instead
Simulation::ExtCylSurfaceTarget * m_TargetMuid
virtual "target" cylinder for MUID (boundary beyond which extrapolation ends)
ExtState getStartPoint(const Track &, int, G4ErrorFreeTrajState &)
Get the start point for a new reconstructed track with specific PDG hypothesis.
bool createMuidHit(ExtState &, G4ErrorFreeTrajState &, KLMMuidLikelihood *, std::vector< std::map< const Track *, double > > *)
Create another MUID extrapolation hit for a track candidate.
int m_OutermostActiveForwardEndcapLayer
outermost forward-endcap layer that is active for muon identification (user-defined)
static TrackExtrapolateG4e * getInstance()
Get the singleton's address.
void beginRun(bool flag)
Perform beginning-of-run actions.
void initialize(double minPt, double minKE, std::vector< Const::ChargedStable > &hypotheses)
Initialize for track extrapolation by the EXT module.
double m_BarrelMaxR
maximum radius (cm) of the barrel
G4ThreeVector m_BarrelSectorPhi[BKLMElementNumbers::getMaximalSectorNumber()+1]
azimuthal unit vector of each barrel sector
StoreArray< KLMMuidLikelihood > m_klmMuidLikelihoods
KLM muid likelihoods.
int m_OutermostActiveBackwardEndcapLayer
outermost backward-endcap layer that is active for muon identification (user-defined)
static TrackExtrapolateG4e * m_Singleton
Stores pointer to the singleton class.
std::vector< Const::ChargedStable > * m_DefaultHypotheses
Default ChargedStable hypotheses (needed as call argument but not used)
void identifyMuon(int pdgCode, double tof, bool isCosmic, const G4ThreeVector &position, const G4ThreeVector &momentum, const G4ErrorSymMatrix &covariance)
Performs muon identification for a single track (specified in genfit2 units).
const std::vector< Const::ChargedStable > * m_HypothesesExt
ChargedStable hypotheses for EXT.
double m_MagneticField
Magnetic field z component (gauss) at origin.
double m_BarrelHalfLength
half-length (cm) of the barrel
StoreArray< KLMCluster > m_klmClusters
KLM clusters.
double m_MaxDt
Coincidence window half-width for in-time KLM hits (ns)
double m_BarrelMinR
minimum radius (cm) of the barrel
bool findEndcapIntersection(ExtState &, const G4ThreeVector &, Intersection &)
Find the intersection point of the track with the crossed EKLM plane.
void endRun(bool flag)
Perform end-of-run actions.
void finishTrack(const ExtState &, KLMMuidLikelihood *, bool)
Complete muon identification after end of track extrapolation.
double m_BarrelModuleMiddleRadius[2][BKLMElementNumbers::getMaximalSectorNumber()+1][BKLMElementNumbers::getMaximalLayerNumber()+1]
hit-plane radius (cm) at closest distance to IP of each barrel end | sector | layer
double m_BarrelPhiStripVariance[BKLMElementNumbers::getMaximalLayerNumber()+1]
BKLM RPC phi-measuring strip position variance (cm^2) by layer.
double m_MinRadiusSq
Minimum squared radius (cm) outside of which extrapolation will continue.
StoreArray< KLMMuidHit > m_klmMuidHits
KLM muid hits.
void terminate(bool flag)
Terminates this singleton.
void createExtHit(ExtHitStatus, const ExtState &, const G4ErrorFreeTrajState &, const G4StepPoint *, const G4TouchableHandle &)
Create another EXT extrapolation hit for a track candidate.
StoreArray< BKLMHit2d > m_bklmHit2ds
BKLM 2d hits.
bool findMatchingEndcapHit(Intersection &, const Track *)
Find the matching EKLM 2D hit nearest the intersection point of the track with the crossed EKLM plane...
double m_EndcapMiddleZ
midpoint along z (cm) of the forward endcap from the KLM midpoint
const EKLMElementNumbers * m_eklmElementNumbers
EKLM element numbers.
const std::vector< Const::ChargedStable > * m_HypothesesMuid
ChargedStable hypotheses for MUID.
void fromPhasespaceToG4e(const G4ThreeVector &, const G4ErrorSymMatrix &, G4ErrorTrajErr &)
Convert the phasespace covariance to geant4e covariance.
double m_OffsetZ
offset (cm) along z axis of KLM midpoint from IP
const KLMElementNumbers * m_klmElementNumbers
KLM element numbers.
std::vector< G4VPhysicalVolume * > * m_BKLMVolumes
Pointers to BKLM geant4 sensitive (physical) volumes.
int m_OutermostActiveBarrelLayer
outermost barrel layer that is active for muon identification (user-defined)
G4ThreeVector m_BarrelSectorPerp[BKLMElementNumbers::getMaximalSectorNumber()+1]
normal unit vector of each barrel sector
bool findMatchingBarrelHit(Intersection &, const Track *)
Find the matching BKLM 2D hit nearest the intersection point of the track with the crossed BKLM plane...
double m_EndcapModuleMiddleZ[BKLMElementNumbers::getMaximalLayerNumber()+1]
hit-plane z (cm) of each IP layer relative to KLM midpoint
void getVolumeID(const G4TouchableHandle &, Const::EDetector &, int &)
Get the physical volume information for a geant4 physical volume.
DBObjPtr< KLMLikelihoodParameters > m_klmLikelihoodParameters
Conditions-database object for KLM likelihood parameters.
double m_MaxECLTrackClusterDistance
user-defined maximum distance (mm) between ECLCluster and associated track (for EID)
double m_EndcapScintVariance
EKLM scintillator strip position variance (cm^2)
StoreArray< TrackClusterSeparation > m_trackClusterSeparations
Track cluster sepration.
StoreArray< Track > m_tracks
Tracks.
void event(bool flag)
Performs track extrapolation for all tracks in one event.
double m_MinPt
Minimum transverse momentum in MeV/c for extrapolation to be started.
StoreArray< ECLCluster > m_eclClusters
ECL clusters.
bool m_addHitsToRecoTrack
Parameter to add the found hits also to the reco tracks or not. Is turned off by default.
int m_BarrelNSector
Number of barrel sectors.
std::map< G4VPhysicalVolume *, enum VolTypes > * m_EnterExit
Pointers to geant4 physical volumes whose entry/exit points will be saved.
StoreArray< EKLMHit2d > m_eklmHit2ds
EKLM 2d hits.
bool m_MuidInitialized
Flag to indicate that MUID initialize() has been called.
StoreArray< RecoTrack > m_recoTracks
Reco tracks.
double m_EndcapMinR
minimum radius (cm) of the endcaps
StoreArray< ExtHit > m_extHits
Ext hits.
std::map< int, MuidBuilder * > m_MuidBuilderMap
PDF for the charged final state particle hypotheses.
void extrapolate(int pdgCode, double tof, const G4ThreeVector &position, const G4ThreeVector &momentum, const G4ErrorSymMatrix &covariance)
Performs track extrapolation for a single track (specified in genfit2 units).
TrackExtrapolateG4e()
constructor is hidden; user calls TrackExtrapolateG4e::getInstance() instead
double m_MeanDt
Mean hit - trigger time (ns)
double m_EndcapMaxR
maximum radius (cm) of the endcaps
Simulation::ExtCylSurfaceTarget * m_TargetExt
virtual "target" cylinder for EXT (boundary beyond which extrapolation ends)
bool findBarrelIntersection(ExtState &, const G4ThreeVector &, Intersection &)
Find the intersection point of the track with the crossed BKLM plane.
bool m_ExtInitialized
Flag to indicate that EXT initialize() has been called.
DBObjPtr< KLMChannelStatus > m_klmChannelStatus
Conditions-database object for KLM channel status.
double m_MinKE
Minimum kinetic energy in MeV for extrapolation to continue.
void registerVolumes()
Register the list of geant4 physical volumes whose entry/exit points will be saved during extrapolati...
void fromG4eToPhasespace(const G4ErrorFreeTrajState &, G4ErrorSymMatrix &)
Convert the geant4e 5x5 covariance to phasespace 6x6 covariance.
Simulation::ExtManager * m_ExtMgr
Pointer to the ExtManager singleton.
DBObjPtr< KLMStripEfficiency > m_klmStripEfficiency
Conditions-database object for KLM strip efficiency.
DBObjPtr< COILGeometryPar > m_COILGeometryPar
Conditions-database object for COIL geometry.
void createECLHit(const ExtState &, const G4ErrorFreeTrajState &, const G4StepPoint *, const G4StepPoint *, const G4TouchableHandle &, const std::pair< ECLCluster *, G4ThreeVector > &, double, double)
Create another EXT ECL-crystal-crossing hit for a track candidate.
double m_MaxDistSqInVariances
user-defined maximum squared-distance (#variances) for matching hit to extrapolation
double m_BarrelZStripVariance[BKLMElementNumbers::getMaximalLayerNumber()+1]
BKLM RPC z-measuring strip position variance (cm^2) by layer.
void swim(ExtState &, G4ErrorFreeTrajState &, const std::vector< std::pair< ECLCluster *, G4ThreeVector > > *, const std::vector< std::pair< KLMCluster *, G4ThreeVector > > *, std::vector< std::map< const Track *, double > > *)
Swim a single track (MUID) until it stops or leaves the target cylinder.
void adjustIntersection(Intersection &, const double *, const G4ThreeVector &, const G4ThreeVector &)
Nudge the track using the matching hit.
const EKLM::TransformDataGlobalAligned * m_eklmTransformData
EKLM transformation data.
DBObjPtr< BeamPipeGeo > m_BeamPipeGeo
Conditions-database object for beam pipe geometry.
Class that bundles various TrackFitResults.
Definition: Track.h:25
ExtHitStatus
Define state of extrapolation for each recorded hit.
Definition: ExtHit.h:25
VolTypes
Enumeration for G4VPhysicalVolume sensitive-volume categories.
@ VOLTYPE_ARICH2
ARICH Img plate.
@ VOLTYPE_CDC
CDC.
@ VOLTYPE_TOP2
TOP quartz.
@ VOLTYPE_TOP3
TOP glue.
@ VOLTYPE_ARICH3
ARICH HAPD window.
@ VOLTYPE_BKLM2
BKLM scintillator.
@ VOLTYPE_EKLM
EKLM.
@ VOLTYPE_BKLM1
BKLM RPC.
@ VOLTYPE_ARICH1
ARICH aerogel.
@ VOLTYPE_ECL
ECL.
@ VOLTYPE_TOP1
TOP container.
Abstract base class for different kinds of events.
Data structure to define extrapolation state.
int lastEndcapExtLayer
MUID: outermost endcap layer crossed by the extrapolated track.
double chi2
MUID: accumulated chi-squared of all in-plane transverse deviations between extrapolation and matchin...
G4ThreeVector directionAtIP
MUID: initial direction of track, used for KLID.
int nPoint
MUID: accumulated number of points with matching 2D hits.
int lastEndcapHitLayer
MUID: outermost endcap layer with a matching hit.
bool isCosmic
True for back-propagation of a cosmic ray.
int firstEndcapLayer
MUID: outermost barrel layer encountered by the extrapolated track in the prior steps.
int extLayerPattern
MUID: accumulated bit pattern of layers crossed by the extrapolated track.
int pdgCode
Particle hypothesis that is being extrapolated.
double length
Length from start of extrapolation (rad lengths), updated during extrapolation.
bool escaped
MUID: flag to indicate that the extrapolated track escaped from the KLM.
int firstBarrelLayer
MUID: outermost barrel layer encountered by the extrapolated track in the prior steps.
int lastBarrelHitLayer
MUID: outermost barrel layer with a matching hit.
int hitLayerPattern
MUID: accumulated bit pattern of layers with matching hits.
int lastBarrelExtLayer
MUID: outermost barrel layer crossed by the extrapolated track.
double tof
Time of flight from IP (ns), updated during extrapolation.
const Track * track
Pointer to the reconstructed track.
intersection of muid-extrapolated track with a KLM layer
int sector
sector number (0..7 for barrel, 0..3 for endcap) of this point
G4ThreeVector momentum
extrapolated-track momentum (GeV/c) at this intersection
double chi2
chi-squared value of transverse deviation between extrapolated and measured hit positions
bool inBarrel
flag to indicate if this point is in the barrel (true) or endcap (false)
int hit
index in {B,E}KLMHit2ds of matching hit
G4ThreeVector positionAtHitPlane
extrapolated-track position (cm) projected to the 2D hit's midplane
G4ThreeVector position
extrapolated-track global position (cm) of this intersection
G4ErrorSymMatrix covariance
extrapolated-track phase-space covariance matrix at this intersection
bool isForward
flag to indicate if this point is in the forward (true) or backward (false) end
double time
time (ns) of matching BKLMHit2d
int layer
layer number (0..14 for barrel, 0..13 for endcap) of this point