Belle II Software development
TruthAxialSegmentPairVarSet.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/axialSegmentPair/TruthAxialSegmentPairVarSet.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/mclookup/CDCMCManager.h>
15
16#include <tracking/trackFindingCDC/eventdata/tracks/CDCAxialSegmentPair.h>
17#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
18#include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit2D.h>
19#include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
20#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory3D.h>
21
22#include <tracking/trackFindingCDC/numerics/Angle.h>
23
24#include <cdc/dataobjects/CDCSimHit.h>
25
26using namespace Belle2;
27using namespace TrackFindingCDC;
28
30{
33}
34
36{
39}
40
42{
43 if (not ptrAxialSegmentPair) return false;
44
45 const CDCAxialSegmentPair& segmentPair = *ptrAxialSegmentPair;
46
47 const CDCSegment2D* ptrFromSegment = segmentPair.getStartSegment();
48 const CDCSegment2D* ptrToSegment = segmentPair.getEndSegment();
49
50 const CDCSegment2D& fromSegment = *ptrFromSegment;
51 const CDCSegment2D& toSegment = *ptrToSegment;
52
53 const CDCMCHitLookUp& mcHitLookUp = CDCMCHitLookUp::getInstance();
55 const CDCMCTrackStore& mcTrackStore = CDCMCTrackStore::getInstance();
56 const std::map<ITrackType, CDCMCTrackStore::CDCHitVector>& mcTracks =
57 mcTrackStore.getMCTracksByMCParticleIdx();
58
59 CDCTrajectory3D trueTrajectory = mcSegmentLookUp.getTrajectory3D(&toSegment);
60 var<named("truth_curv")>() = trueTrajectory.getCurvatureXY();
61 var<named("truth_tanl")>() = trueTrajectory.getTanLambda();
62 var<named("truth_z")>() = trueTrajectory.getSupport().z();
63
64 // Hits
65 const CDCRecoHit2D& fromLastHit = fromSegment.back();
66 const CDCRecoHit2D& toFirstHit = toSegment.front();
67
68 const CDCSimHit* fromSimHit = mcHitLookUp.getClosestPrimarySimHit(fromLastHit.getWireHit().getHit());
69 const CDCSimHit* toSimHit = mcHitLookUp.getClosestPrimarySimHit(toFirstHit.getWireHit().getHit());
70 if (fromSimHit and toSimHit) {
71 double truthFromAlpha = -fromSimHit->getPosTrack().DeltaPhi(fromSimHit->getMomentum());
72 double truthToAlpha = -toSimHit->getPosTrack().DeltaPhi(toSimHit->getMomentum());
73 var<named("truth_from_alpha")>() = truthFromAlpha;
74 var<named("truth_to_alpha")>() = truthToAlpha;
75 var<named("truth_delta_alpha")>() = AngleUtil::normalised(truthToAlpha - truthFromAlpha);
76 } else {
77 var<named("truth_from_alpha")>() = NAN;
78 var<named("truth_to_alpha")>() = NAN;
79 var<named("truth_delta_alpha")>() = NAN;
80 }
81
82 ITrackType fromTrackId = mcSegmentLookUp.getMCTrackId(&fromSegment);
83 double fromMCTrackSize = 0;
84 if (mcTracks.count(fromTrackId)) {
85 fromMCTrackSize = mcTracks.find(fromTrackId)->second.size();
86 }
87
88 ITrackType toTrackId = mcSegmentLookUp.getMCTrackId(&toSegment);
89 double toMCTrackSize = 0;
90 if (mcTracks.count(toTrackId)) {
91 toMCTrackSize = mcTracks.find(toTrackId)->second.size();
92 }
93
94 double trackFraction = fromSegment.size() / fromMCTrackSize + toSegment.size() / toMCTrackSize;
95 var<named("truth_track_fraction")>() = trackFraction;
96
97 double fromRLPurity = mcSegmentLookUp.getRLPurity(&fromSegment);
98 double toRLPurity = mcSegmentLookUp.getRLPurity(&toSegment);
99 if (fromRLPurity < 0.5) fromRLPurity = 0;
100 if (toRLPurity < 0.5) toRLPurity = 0;
101
102 EForwardBackward pairFBInfo = mcSegmentLookUp.areAlignedInMCTrack(&fromSegment, &toSegment);
103
104 // False combinations have always full weight - true combinations are down weighted for their rl purity
105 double weight = pairFBInfo != EForwardBackward::c_Invalid ? fromRLPurity * toRLPurity : 1;
106 var<named("__weight__")>() = weight;
107
108 return true;
109}
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
Class representing a pair of reconstructed axial segements in adjacent superlayer.
const CDCAxialSegment2D * getEndSegment() const
Getter for the end segment.
const CDCAxialSegment2D * getStartSegment() const
Getter for the start segment.
ITrackType getMCTrackId(const ACDCHitCollection *ptrHits) const
Getter for the Monte Carlo track id matched to this collection of hits.
double getRLPurity(const ACDCHitCollection *ptrHits) const
Getter for the right left passge purity which respects the forward backward reconstruction.
CDCTrajectory3D getTrajectory3D(const ACDCHitCollection *ptrHits) const
Returns the trajectory of the collection of hits.
EForwardBackward areAlignedInMCTrack(const ACDCHitCollection *ptrFromHits, const ACDCHitCollection *ptrToHits) const
Returns if the second collection of hits follows the first collection of hits in their common Monte C...
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.
void requireTruthInformation()
Require the mc information store arrays.
void fill()
Fill Monte Carlo look up maps from the DataStore.
static CDCMCManager & getInstance()
Getter for the singletone instance.
Definition: CDCMCManager.cc:74
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
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
void initialize() override
Receive and dispatch signal before the start of the event processing.
void beginEvent() override
Receive and dispatch signal for the start of a new event.
void initialize() final
Require the Monte Carlo information before the event processing starts.
void beginEvent() final
Signal the begin of a new event.
bool extract(const CDCAxialSegmentPair *ptrAxialSegmentPair) 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
EForwardBackward
Enumeration to represent the distinct possibilities of the right left passage information.
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