Belle II Software development
PXDStateTruthVarSet.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/ckf/pxd/filters/states/PXDStateTruthVarSet.h>
9
10#include <framework/core/ModuleParamList.h>
11#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
12
13#include <tracking/mcMatcher/TrackMatchLookUp.h>
14#include <tracking/dataobjects/RecoTrack.h>
15
16#include <TRandom.h>
17
18using namespace Belle2;
19using namespace TrackFindingCDC;
20
22{
23 const std::vector<TrackFindingCDC::WithWeight<const CKFToPXDState*>>& previousStates = pair->first;
24 const CKFToPXDState* state = pair->second;
25
26 std::vector<TrackFindingCDC::WithWeight<const CKFToPXDState*>> allStates = previousStates;
27 allStates.emplace_back(state, 0);
28
29 const RecoTrack* seedTrack = previousStates.front()->getSeed();
30 B2ASSERT("Path without seed?", seedTrack);
31
32 var<named("truth_event_id")>() = m_eventMetaData->getEvent();
33 var<named("truth_seed_number")>() = seedTrack->getArrayIndex();
34
35 // Default to 0
36 var<named("truth_position_x")>() = 0;
37 var<named("truth_position_y")>() = 0;
38 var<named("truth_position_z")>() = 0;
39 var<named("truth_momentum_x")>() = 0;
40 var<named("truth_momentum_y")>() = 0;
41 var<named("truth_momentum_z")>() = 0;
42 var<named("truth")>() = 0;
43
44 if (not m_mcUtil.allStatesCorrect(allStates)) {
45 if (m_UseFractionOfBackground and gRandom->Uniform() > m_BackgroundFraction) {
46 return false;
47 }
48 // Keep all variables set to false and return.
49 return true;
50 }
51
52 const std::string& seedTrackStoreArrayName = seedTrack->getArrayName();
53
54 TrackMatchLookUp mcCDCMatchLookUp("MCRecoTracks", seedTrackStoreArrayName);
55 const RecoTrack* cdcMCTrack = mcCDCMatchLookUp.getRelatedMCRecoTrack(*seedTrack);
56
57 var<named("truth")>() = 1;
58
59 var<named("truth_position_x")>() = cdcMCTrack->getPositionSeed().X();
60 var<named("truth_position_y")>() = cdcMCTrack->getPositionSeed().Y();
61 var<named("truth_position_z")>() = cdcMCTrack->getPositionSeed().Z();
62 var<named("truth_momentum_x")>() = cdcMCTrack->getMomentumSeed().X();
63 var<named("truth_momentum_y")>() = cdcMCTrack->getMomentumSeed().Y();
64 var<named("truth_momentum_z")>() = cdcMCTrack->getMomentumSeed().Z();
65
66 return true;
67}
68
69void PXDStateTruthVarSet::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
70{
71 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "useFractionOfBackground"), m_UseFractionOfBackground,
72 "Use only a fraction of background hits and combinations in recording to improve the signal fraction in the recording.",
74
75 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "backgroundFraction"), m_BackgroundFraction,
76 "Fraction of background hits and combinations to be used in recording to improve the signal fraction in the recording if " + \
77 TrackFindingCDC::prefixed(prefix, "useFractionOfBackground") + " is true.",
79}
Specialized CKF State for extrapolating into the PXD.
Definition: CKFToPXDState.h:27
bool allStatesCorrect(const std::vector< TrackFindingCDC::WithWeight< const CKFToPXDState * > > &states) const
Are all hits related to the same MC track the seed is related to?
Definition: PXDMCUtil.cc:75
The Module parameter list class.
double m_BackgroundFraction
Fraction of background to use in case m_UseFractionOfBackground is true The default value of 0....
MCUtil m_mcUtil
MC information used in the PXD CKF.
virtual bool extract(const BasePXDStateFilter::Object *result) override
Generate and assign the variables from the object.
StoreObjPtr< EventMetaData > m_eventMetaData
Pointer to the object containing event number etc.
bool m_UseFractionOfBackground
Only use a fraction of background events for recording for MVA training.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters to the outside world.
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
ROOT::Math::XYZVector getPositionSeed() const
Return the position seed stored in the reco track. ATTENTION: This is not the fitted position.
Definition: RecoTrack.h:480
ROOT::Math::XYZVector getMomentumSeed() const
Return the momentum seed stored in the reco track. ATTENTION: This is not the fitted momentum.
Definition: RecoTrack.h:487
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
AObject Object
Type of the object to be analysed.
Definition: Filter.dcl.h:35
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
Class to provide convenient methods to look up matching information between pattern recognition and M...
const RecoTrack * getRelatedMCRecoTrack(const RecoTrack &prRecoTrack) const
Looks for a related Monte Carlo track for the given pattern recognition track and return it if found.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Abstract base class for different kinds of events.