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