Belle II Software  release-08-01-10
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 /* Basf2 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/eklm/EKLMElementNumbers.h>
23 #include <klm/dataobjects/KLMElementNumbers.h>
24 #include <klm/dataobjects/KLMHit2d.h>
25 #include <klm/dbobjects/KLMChannelStatus.h>
26 #include <klm/dbobjects/KLMStripEfficiency.h>
27 #include <klm/dbobjects/KLMLikelihoodParameters.h>
28 #include <klm/eklm/geometry/TransformDataGlobalAligned.h>
29 #include <structure/dbobjects/COILGeometryPar.h>
30 
31 /* Geant4 headers. */
32 #include <G4ErrorTrajErr.hh>
33 #include <G4ThreeVector.hh>
34 #include <G4TouchableHandle.hh>
35 
36 /* C++ headers. */
37 #include <map>
38 #include <string>
39 #include <vector>
40 
41 class G4ErrorSymMatrix;
42 class G4VPhysicalVolume;
43 class G4ErrorFreeTrajState;
44 class G4StepPoint;
45 
46 namespace Belle2 {
52  class ECLCluster;
53  class KLMCluster;
54  class KLMMuidHit;
55  class KLMMuidLikelihood;
56  class MuidBuilder;
57  class Track;
58 
59  namespace Simulation {
60  class ExtCylSurfaceTarget;
61  class ExtManager;
62  }
63 
65  enum VolTypes {
88  };
89 
91  struct ExtState {
93  const Track* track;
95  int pdgCode;
97  bool isCosmic;
99  double tof;
101  double length;
103  G4ThreeVector directionAtIP;
105  double chi2;
107  int nPoint;
125  bool escaped;
126  };
127 
129  struct Intersection {
131  int hit;
133  bool inBarrel;
135  bool isForward;
137  int sector;
139  int layer;
141  G4ThreeVector position;
143  G4ThreeVector momentum;
145  G4ErrorSymMatrix covariance;
147  G4ThreeVector positionAtHitPlane;
149  double time;
151  double chi2;
152  };
153 
169 
170  public:
171 
174 
177 
183  void initialize(double minPt, double minKE,
184  std::vector<Const::ChargedStable>& hypotheses);
185 
197  void initialize(double meanDt, double maxDt, double maxSeparation,
198  double maxKLMTrackClusterDistance, double maxECLTrackClusterDistance,
199  double minPt, double minKE, bool addHitsToRecoTrack, std::vector<Const::ChargedStable>& hypotheses);
200 
203  void beginRun(bool flag);
204 
207  void event(bool flag);
208 
211  void endRun(bool flag);
212 
215  void terminate(bool flag);
216 
223  void extrapolate(int pdgCode,
224  double tof,
225  const G4ThreeVector& position,
226  const G4ThreeVector& momentum,
227  const G4ErrorSymMatrix& covariance);
228 
229  private:
230 
233 
236 
238  void swim(ExtState&, G4ErrorFreeTrajState&,
239  const std::vector<std::pair<ECLCluster*, G4ThreeVector> >*,
240  const std::vector<std::pair<KLMCluster*, G4ThreeVector> >*,
241  std::vector<std::map<const Track*, double> >*);
242 
244  void swim(ExtState&, G4ErrorFreeTrajState&);
245 
248  void registerVolumes();
249 
251  void getVolumeID(const G4TouchableHandle&, Const::EDetector&, int&);
252 
254  void fromG4eToPhasespace(const G4ErrorFreeTrajState&, G4ErrorSymMatrix&);
255 
257  void fromPhasespaceToG4e(const G4ThreeVector&, const G4ErrorSymMatrix&, G4ErrorTrajErr&);
258 
260  void fromPhasespaceToG4e(const TVector3&, const TMatrixDSym&, G4ErrorTrajErr&);
261 
263  ExtState getStartPoint(const Track&, int, G4ErrorFreeTrajState&);
264 
266  void createExtHit(ExtHitStatus, const ExtState&, const G4ErrorFreeTrajState&, const G4StepPoint*, const G4TouchableHandle&);
267 
269  void createECLHit(const ExtState&, const G4ErrorFreeTrajState&, const G4StepPoint*, const G4StepPoint*, const G4TouchableHandle&,
270  const std::pair<ECLCluster*, G4ThreeVector>&, double, double);
271 
273  bool createMuidHit(ExtState&, G4ErrorFreeTrajState&, KLMMuidLikelihood*, std::vector<std::map<const Track*, double> >*);
274 
276  bool findBarrelIntersection(ExtState&, const G4ThreeVector&, Intersection&);
277 
279  bool findEndcapIntersection(ExtState&, const G4ThreeVector&, Intersection&);
280 
283 
286 
288  void adjustIntersection(Intersection&, const double*, const G4ThreeVector&, const G4ThreeVector&);
289 
291  void finishTrack(const ExtState&, KLMMuidLikelihood*, bool);
292 
295 
298 
301 
303  double m_MeanDt;
304 
306  double m_MaxDt;
307 
310 
313 
316 
319 
321  double m_MinPt;
322 
324  double m_MinKE;
325 
328 
330  const std::vector<Const::ChargedStable>* m_HypothesesExt;
331 
333  const std::vector<Const::ChargedStable>* m_HypothesesMuid;
334 
336  std::vector<Const::ChargedStable>* m_DefaultHypotheses;
337 
339  std::map<G4VPhysicalVolume*, enum VolTypes>* m_EnterExit;
340 
342  std::vector<G4VPhysicalVolume*>* m_BKLMVolumes;
343 
346 
349 
352 
355 
358 
360  double m_OffsetZ;
361 
364 
366  double m_BarrelMaxR;
367 
369  double m_BarrelMinR;
370 
373 
376 
379 
382 
385 
389 
392 
395 
397  double m_EndcapMaxR;
398 
400  double m_EndcapMinR;
401 
404 
407 
410 
413 
416 
419 
421  bool m_addHitsToRecoTrack = false;
422 
424  std::map<int, MuidBuilder*> m_MuidBuilderMap;
425 
428 
431 
434 
437 
440 
443 
446 
449 
452 
455 
458 
461 
464 
467 
470 
471  };
472 
474 } // 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)
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.
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.
StoreArray< KLMHit2d > m_klmHit2ds
KLM 2d hits.
std::map< G4VPhysicalVolume *, enum VolTypes > * m_EnterExit
Pointers to geant4 physical volumes whose entry/exit points will be saved.
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 (in number of 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:27
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