Belle II Software  release-05-02-19
TrackQETrainingDataCollectorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jonas Wagner, Sebastian Racs *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <tracking/modules/trackQualityEstimator/TrackQETrainingDataCollectorModule.h>
12 
13 using namespace Belle2;
14 
15 
16 REG_MODULE(TrackQETrainingDataCollector)
17 
19 {
20  //Set module properties
21  setDescription("Module to collect training data for a specified qualityEstimator and store it in a root file.");
22  setPropertyFlags(c_ParallelProcessingCertified | c_TerminateInAllProcesses);
23 
24  addParam("recoTracksStoreArrayName",
25  m_recoTracksStoreArrayName,
26  "Name of the recoTrack StoreArray.",
27  m_recoTracksStoreArrayName);
28 
29  addParam("SVDCDCRecoTracksStoreArrayName",
30  m_svdCDCRecoTracksStoreArrayName,
31  "Name of the SVD-CDC StoreArray.",
32  m_svdCDCRecoTracksStoreArrayName);
33 
34  addParam("SVDPlusCDCStandaloneRecoTracksStoreArrayName",
35  m_svdPlusCDCStandaloneRecoTracksStoreArrayName,
36  "Name of the combined CDC-SVD StoreArray with tracks added from the CDC to SVD CKF.",
37  m_svdPlusCDCStandaloneRecoTracksStoreArrayName);
38 
39  addParam("CDCRecoTracksStoreArrayName",
40  m_cdcRecoTracksStoreArrayName,
41  "Name of the CDC StoreArray.",
42  m_cdcRecoTracksStoreArrayName);
43 
44  addParam("SVDRecoTracksStoreArrayName",
45  m_svdRecoTracksStoreArrayName,
46  "Name of the SVD StoreArray.",
47  m_svdRecoTracksStoreArrayName);
48 
49  addParam("PXDRecoTracksStoreArrayName",
50  m_pxdRecoTracksStoreArrayName,
51  "Name of the PXD StoreArray.",
52  m_pxdRecoTracksStoreArrayName);
53 
54  addParam("TrainingDataOutputName",
55  m_TrainingDataOutputName,
56  "Name of the output rootfile.",
57  m_TrainingDataOutputName);
58 
59  addParam("collectEventFeatures",
60  m_collectEventFeatures,
61  "Whether to use eventwise features.",
62  m_collectEventFeatures);
63 }
64 
66 {
69  m_eventInfoExtractor = std::make_unique<EventInfoExtractor>(m_variableSet);
70  }
71  m_recoTrackExtractor = std::make_unique<RecoTrackExtractor>(m_variableSet);
72  m_subRecoTrackExtractor = std::make_unique<SubRecoTrackExtractor>(m_variableSet);
73  m_hitInfoExtractor = std::make_unique<HitInfoExtractor>(m_variableSet);
74 
75  m_variableSet.emplace_back("truth", &m_truth);
76 
77  m_recorder = std::make_unique<SimpleVariableRecorder>(m_variableSet, m_TrainingDataOutputName, "tree");
78 }
79 
81 {
82 
83 }
84 
86 {
87  for (const RecoTrack& recoTrack : m_recoTracks) {
88  m_truth = float(recoTrack.getMatchingStatus() == RecoTrack::MatchingStatus::c_matched);
89 
90  RecoTrack* pxdRecoTrackPtr = recoTrack.getRelatedTo<RecoTrack>(m_pxdRecoTracksStoreArrayName);
91  // combined CDC and SVD tracks after both CDC-to-SVD and also SVD-to-CDC CKF
92  RecoTrack* svdCDCRecoTrackPtr = recoTrack.getRelatedTo<RecoTrack>(m_svdCDCRecoTracksStoreArrayName);
93  // combined SVD and CDC-standalone tracks after CDC-to-SVD CKF
94  RecoTrack* svdPlusCDCStandaloneRecoTrackPtr = nullptr;
95  // CDC tracks from CDC-standalone tracking
96  RecoTrack* cdcRecoTrackPtr = nullptr;
97  // SVD tracks from VXDTF2 (SVD-standalone) tracking
98  RecoTrack* svdRecoTrackPtr = nullptr;
99 
100  if (svdCDCRecoTrackPtr) {
101  // Relation graph when SVD-to-CDC CFK is enabled:
102  // SVDCDCRecoTracks -> SVDPlusCDCStandaloneRecoTracks -> CDCRecoTracks & SVDRecoTracks
103  svdPlusCDCStandaloneRecoTrackPtr = svdCDCRecoTrackPtr->getRelatedTo<RecoTrack>(
105  if (not svdPlusCDCStandaloneRecoTrackPtr) {
106  // Relation graph when SVD-to-CDC CFK is disabled:
107  // SVDCDCRecoTracks -> CDCRecoTracks & SVDRecoTracks
108  svdPlusCDCStandaloneRecoTrackPtr = svdCDCRecoTrackPtr;
109  }
110  cdcRecoTrackPtr = svdPlusCDCStandaloneRecoTrackPtr->getRelatedTo<RecoTrack>(m_cdcRecoTracksStoreArrayName);
111  svdRecoTrackPtr = svdPlusCDCStandaloneRecoTrackPtr->getRelatedTo<RecoTrack>(m_svdRecoTracksStoreArrayName);
112  }
113 
115  m_eventInfoExtractor->extractVariables(m_recoTracks, recoTrack);
116  }
117  m_recoTrackExtractor->extractVariables(recoTrack);
118  // TODO: also use `CKFCDCRecoTracks` and its features in quality estimation
119  m_subRecoTrackExtractor->extractVariables(cdcRecoTrackPtr, svdRecoTrackPtr, pxdRecoTrackPtr);
120  m_hitInfoExtractor->extractVariables(recoTrack);
121 
122  // record variables
123  m_recorder->record();
124  }
125 }
126 
128 {
129  m_recorder->write();
130  m_recorder.reset();
131 }
Belle2::TrackQETrainingDataCollectorModule::m_cdcRecoTracksStoreArrayName
std::string m_cdcRecoTracksStoreArrayName
Name of the CDC StoreArray.
Definition: TrackQETrainingDataCollectorModule.h:70
Belle2::TrackQETrainingDataCollectorModule::m_truth
float m_truth
truth information collected with m_estimatorMC type is float to be consistend with m_variableSet (and...
Definition: TrackQETrainingDataCollectorModule.h:102
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::TrackQETrainingDataCollectorModule::m_svdRecoTracksStoreArrayName
std::string m_svdRecoTracksStoreArrayName
Name of the SVD StoreArray.
Definition: TrackQETrainingDataCollectorModule.h:72
Belle2::RelationsInterface::getRelatedTo
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
Definition: RelationsObject.h:250
Belle2::TrackQETrainingDataCollectorModule::beginRun
void beginRun() override
sets magnetic field strength
Definition: TrackQETrainingDataCollectorModule.cc:80
Belle2::TrackQETrainingDataCollectorModule::m_collectEventFeatures
bool m_collectEventFeatures
Parameter to enable event-wise features.
Definition: TrackQETrainingDataCollectorModule.h:80
Belle2::TrackQETrainingDataCollectorModule::m_TrainingDataOutputName
std::string m_TrainingDataOutputName
name of the output rootfile
Definition: TrackQETrainingDataCollectorModule.h:77
Belle2::TrackQETrainingDataCollectorModule::m_subRecoTrackExtractor
std::unique_ptr< SubRecoTrackExtractor > m_subRecoTrackExtractor
pointer to object that extracts info from the related sub RecoTracks
Definition: TrackQETrainingDataCollectorModule.h:90
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::TrackQETrainingDataCollectorModule::m_svdCDCRecoTracksStoreArrayName
std::string m_svdCDCRecoTracksStoreArrayName
Name of the SVD-CDC StoreArray.
Definition: TrackQETrainingDataCollectorModule.h:66
Belle2::TrackQETrainingDataCollectorModule::m_variableSet
std::vector< Named< float * > > m_variableSet
set of named variables to be collected
Definition: TrackQETrainingDataCollectorModule.h:98
Belle2::TrackQETrainingDataCollectorModule::m_hitInfoExtractor
std::unique_ptr< HitInfoExtractor > m_hitInfoExtractor
pointer to object that extracts info from the hits within the RecoTrack
Definition: TrackQETrainingDataCollectorModule.h:92
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackQETrainingDataCollectorModule
Quality Estimator Data Collector Module to collect data for a MVA training using VXDQE_teacher....
Definition: TrackQETrainingDataCollectorModule.h:42
Belle2::TrackQETrainingDataCollectorModule::terminate
void terminate() override
write out data from m_recorder
Definition: TrackQETrainingDataCollectorModule.cc:127
Belle2::TrackQETrainingDataCollectorModule::event
void event() override
applies the selected quality estimation method for a given set of TCs
Definition: TrackQETrainingDataCollectorModule.cc:85
Belle2::TrackQETrainingDataCollectorModule::m_pxdRecoTracksStoreArrayName
std::string m_pxdRecoTracksStoreArrayName
Name of the PXD StoreArray.
Definition: TrackQETrainingDataCollectorModule.h:74
Belle2::TrackQETrainingDataCollectorModule::m_recoTracksStoreArrayName
std::string m_recoTracksStoreArrayName
Name of the recoTrack StoreArray.
Definition: TrackQETrainingDataCollectorModule.h:64
Belle2::TrackQETrainingDataCollectorModule::m_recoTracks
StoreArray< RecoTrack > m_recoTracks
Store Array of the recoTracks.
Definition: TrackQETrainingDataCollectorModule.h:83
Belle2::TrackQETrainingDataCollectorModule::m_svdPlusCDCStandaloneRecoTracksStoreArrayName
std::string m_svdPlusCDCStandaloneRecoTracksStoreArrayName
Name of the StoreArray of SVD tracks combined with CDC-tracks from standalone CDC tracking.
Definition: TrackQETrainingDataCollectorModule.h:68
Belle2::TrackQETrainingDataCollectorModule::m_eventInfoExtractor
std::unique_ptr< EventInfoExtractor > m_eventInfoExtractor
pointer to object that extracts info from the whole event
Definition: TrackQETrainingDataCollectorModule.h:86
Belle2::TrackQETrainingDataCollectorModule::m_recorder
std::unique_ptr< SimpleVariableRecorder > m_recorder
pointer to the object that writes out the collected data into a root file
Definition: TrackQETrainingDataCollectorModule.h:95
Belle2::TrackQETrainingDataCollectorModule::initialize
void initialize() override
Initializes the Module.
Definition: TrackQETrainingDataCollectorModule.cc:65
Belle2::TrackQETrainingDataCollectorModule::m_recoTrackExtractor
std::unique_ptr< RecoTrackExtractor > m_recoTrackExtractor
pointer to object that extracts info from the root RecoTrack
Definition: TrackQETrainingDataCollectorModule.h:88