Belle II Software  release-05-01-25
TruthSegmentPairVarSet.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/filters/segmentPair/TruthSegmentPairVarSet.h>
11 
12 #include <tracking/trackFindingCDC/mclookup/CDCMCHitLookUp.h>
13 #include <tracking/trackFindingCDC/mclookup/CDCMCSegment2DLookUp.h>
14 #include <tracking/trackFindingCDC/mclookup/CDCMCTrackStore.h>
15 
16 #include <tracking/trackFindingCDC/eventdata/tracks/CDCSegmentPair.h>
17 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
18 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
19 
20 #include <tracking/trackFindingCDC/numerics/Angle.h>
21 
22 #include <cdc/dataobjects/CDCSimHit.h>
23 
24 using namespace Belle2;
25 using namespace TrackFindingCDC;
26 
28 {
29  if (not ptrSegmentPair) return false;
30 
31  const CDCSegmentPair& segmentPair = *ptrSegmentPair;
32 
33  const CDCSegment2D* ptrFromSegment = segmentPair.getFromSegment();
34  const CDCSegment2D* ptrToSegment = segmentPair.getToSegment();
35 
36  const CDCSegment2D& fromSegment = *ptrFromSegment;
37  const CDCSegment2D& toSegment = *ptrToSegment;
38 
39  const CDCMCHitLookUp& mcHitLookUp = CDCMCHitLookUp::getInstance();
41  const CDCMCTrackStore& mcTrackStore = CDCMCTrackStore::getInstance();
42  const std::map<ITrackType, CDCMCTrackStore::CDCHitVector>& mcTracks =
43  mcTrackStore.getMCTracksByMCParticleIdx();
44 
45  CDCTrajectory3D trueTrajectory = mcSegmentLookUp.getTrajectory3D(&toSegment);
46  var<named("truth_curv")>() = trueTrajectory.getCurvatureXY();
47  var<named("truth_tanl")>() = trueTrajectory.getTanLambda();
48  var<named("truth_z")>() = trueTrajectory.getSupport().z();
49 
50  // Hits
51  const CDCRecoHit2D& fromLastHit = fromSegment.back();
52  const CDCRecoHit2D& toFirstHit = toSegment.front();
53 
54  const CDCSimHit* fromSimHit = mcHitLookUp.getClosestPrimarySimHit(fromLastHit.getWireHit().getHit());
55  const CDCSimHit* toSimHit = mcHitLookUp.getClosestPrimarySimHit(toFirstHit.getWireHit().getHit());
56  if (fromSimHit and toSimHit) {
57  double truthFromAlpha = -fromSimHit->getPosTrack().DeltaPhi(fromSimHit->getMomentum());
58  double truthToAlpha = -toSimHit->getPosTrack().DeltaPhi(toSimHit->getMomentum());
59  var<named("truth_from_alpha")>() = truthFromAlpha;
60  var<named("truth_to_alpha")>() = truthToAlpha;
61  var<named("truth_delta_alpha")>() = AngleUtil::normalised(truthToAlpha - truthFromAlpha);
62  } else {
63  var<named("truth_from_alpha")>() = NAN;
64  var<named("truth_to_alpha")>() = NAN;
65  var<named("truth_delta_alpha")>() = NAN;
66  }
67 
68  ITrackType fromTrackId = mcSegmentLookUp.getMCTrackId(&fromSegment);
69  double fromMCTrackSize = 0;
70  if (mcTracks.count(fromTrackId)) {
71  fromMCTrackSize = mcTracks.find(fromTrackId)->second.size();
72  }
73 
74  ITrackType toTrackId = mcSegmentLookUp.getMCTrackId(&toSegment);
75  double toMCTrackSize = 0;
76  if (mcTracks.count(toTrackId)) {
77  toMCTrackSize = mcTracks.find(toTrackId)->second.size();
78  }
79 
80  double trackFraction = fromSegment.size() / fromMCTrackSize + toSegment.size() / toMCTrackSize;
81  var<named("truth_track_fraction")>() = trackFraction;
82  var<named("__weight__")>() = std::isfinite(trackFraction) ? trackFraction : 0;
83  return true;
84 }
Belle2::TrackFindingCDC::CDCTrajectory3D::getTanLambda
double getTanLambda() const
Getter for the slope of z over the transverse travel distance s.
Definition: CDCTrajectory3D.h:299
Belle2::TrackFindingCDC::CDCSegmentPair
Class representing a pair of one reconstructed axial segement and one stereo segment in adjacent supe...
Definition: CDCSegmentPair.h:44
Belle2::CDCSimHit::getPosTrack
TVector3 getPosTrack() const
The method to get position on the track.
Definition: CDCSimHit.h:234
Belle2::TrackFindingCDC::CDCTrajectory3D::getCurvatureXY
double getCurvatureXY() const
Getter for the curvature as seen from the xy projection.
Definition: CDCTrajectory3D.h:305
Belle2::TrackFindingCDC::CDCMCHitLookUp::getClosestPrimarySimHit
const CDCSimHit * getClosestPrimarySimHit(const CDCHit *ptrHit) const
Getter for the closest simulated hit of a primary particle to the given hit - may return nullptr of n...
Definition: CDCMCHitLookUp.cc:103
Belle2::TrackFindingCDC::CDCMCSegment2DLookUp
Specialisation of the lookup for the truth values of two dimensional segments.
Definition: CDCMCSegment2DLookUp.h:33
Belle2::TrackFindingCDC::CDCMCTrackStore
Class to organize and present the monte carlo hit information.
Definition: CDCMCTrackStore.h:38
Belle2::TrackFindingCDC::CDCWireHit::getHit
const CDCHit * getHit() const
Getter for the CDCHit pointer into the StoreArray.
Definition: CDCWireHit.h:167
Belle2::TrackFindingCDC::CDCMCHitCollectionLookUp::getMCTrackId
ITrackType getMCTrackId(const ACDCHitCollection *ptrHits) const
Getter for the Monte Carlo track id matched to this collection of hits.
Definition: CDCMCHitCollectionLookUp.icc.h:101
Belle2::TrackFindingCDC::CDCMCSegment2DLookUp::getInstance
static const CDCMCSegment2DLookUp & getInstance()
Getter for the singletone instance.
Definition: CDCMCSegment2DLookUp.cc:23
Belle2::CDCSimHit
Example Detector.
Definition: CDCSimHit.h:33
Belle2::TrackFindingCDC::TruthSegmentPairVarSet::extract
bool extract(const CDCSegmentPair *ptrSegmentPair) final
Generate and assign the contained variables.
Definition: TruthSegmentPairVarSet.cc:27
Belle2::TrackFindingCDC::CDCSegmentPair::getToSegment
const CDCSegment2D * getToSegment() const
Getter for the to segment.
Definition: CDCSegmentPair.h:132
Belle2::TrackFindingCDC::CDCRecoHit2D
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:57
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::CDCMCHitLookUp
Interface class to the Monte Carlo information for individual hits.
Definition: CDCMCHitLookUp.h:41
Belle2::TrackFindingCDC::CDCMCTrackStore::getInstance
static const CDCMCTrackStore & getInstance()
Getter for the singletone instance.
Definition: CDCMCTrackStore.cc:29
Belle2::TrackFindingCDC::CDCMCTrackStore::getMCTracksByMCParticleIdx
const std::map< ITrackType, Belle2::TrackFindingCDC::CDCMCTrackStore::CDCHitVector > & getMCTracksByMCParticleIdx() const
Getter for the stored Monte Carlo tracks ordered by their Monte Carlo Id.
Definition: CDCMCTrackStore.h:66
Belle2::TrackFindingCDC::CDCTrajectory3D::getSupport
Vector3D getSupport() const
Getter for the support point of the trajectory in global coordinates, where arcLength2D = 0.
Definition: CDCTrajectory3D.h:229
Belle2::TrackFindingCDC::CDCMCHitLookUp::getInstance
static const CDCMCHitLookUp & getInstance()
Getter for the singletone instance.
Definition: CDCMCHitLookUp.cc:32
Belle2::TrackFindingCDC::CDCSegment2D
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:40
Belle2::TrackFindingCDC::VarSet< TruthSegmentPairVarNames >::named
constexpr static int named(const char *name)
Getter for the index from the name.
Definition: VarSet.h:88
Belle2::TrackFindingCDC::Vector3D::z
double z() const
Getter for the z coordinate.
Definition: Vector3D.h:488
Belle2::CDCSimHit::getMomentum
TVector3 getMomentum() const
The method to get momentum.
Definition: CDCSimHit.h:210
Belle2::TrackFindingCDC::VarSet< TruthSegmentPairVarNames >::var
Float_t & var()
Reference getter for the value of the ith variable. Static version.
Definition: VarSet.h:103
Belle2::TrackFindingCDC::CDCSegmentPair::getFromSegment
const CDCSegment2D * getFromSegment() const
Getter for the from segment.
Definition: CDCSegmentPair.h:120
Belle2::TrackFindingCDC::CDCTrajectory3D
Particle full three dimensional trajectory.
Definition: CDCTrajectory3D.h:47
Belle2::TrackFindingCDC::CDCMCHitCollectionLookUp::getTrajectory3D
CDCTrajectory3D getTrajectory3D(const ACDCHitCollection *ptrHits) const
Returns the trajectory of the collection of hits.
Definition: CDCMCHitCollectionLookUp.icc.h:359
Belle2::TrackFindingCDC::CDCRecoHit2D::getWireHit
const CDCWireHit & getWireHit() const
Getter for the wire hit assoziated with the reconstructed hit.
Definition: CDCRecoHit2D.h:203
Belle2::TrackFindingCDC::AngleUtil::normalised
static double normalised(const double angle)
Normalise an angle to lie in the range from [-pi, pi].
Definition: Angle.h:43