10 #include <tracking/modules/spacePointCreator/SPTC2GFTCConverterModule.h>
11 #include <tracking/spacePointCreation/SpacePointTrackCand.h>
13 #include <genfit/TrackCand.h>
15 #include <framework/dataobjects/EventMetaData.h>
16 #include <framework/datastore/StoreArray.h>
17 #include <framework/datastore/StoreObjPtr.h>
19 #include <framework/gearbox/Const.h>
29 setDescription(
"Module for converting SpacePointTrackCand to genfit::TrackCand.");
30 setPropertyFlags(c_ParallelProcessingCertified);
32 addParam(
"SpacePointTCName", m_SPTCName,
"Name of the container containing the SpacePointTrackCands to convert",
string(
""));
33 addParam(
"genfitTCName", m_genfitTCName,
"Name of the container of the (output) genfit::TrackCands",
string(
""));
34 addParam(
"PXDClusters", m_PXDClustersName,
"Name of the container of the PXD Clusters",
string(
""));
35 addParam(
"SVDClusters", m_SVDClustersName,
"Name of the container of the SVD Clusters",
string(
""));
40 void SPTC2GFTCConverterModule::initialize()
42 B2INFO(
"SPTC2GFTCConverter --------------- initialize() -------------------");
48 genfitTCs.registerInDataStore(m_genfitTCName, DataStore::c_ErrorIfAlreadyRegistered);
51 spTCs.isRequired(m_SPTCName);
60 void SPTC2GFTCConverterModule::event()
63 const int eventCounter = eventMetaData->getEvent();
64 B2DEBUG(10,
"SPTC2GFTCConverter::event() processing event " << eventCounter <<
" ----------");
70 B2DEBUG(15,
"Found " << nSPTCs <<
" SpacePointTrackCands in StoreArray " << spacePointTCs.getName());
72 for (
int iTC = 0; iTC < nSPTCs; ++iTC) {
74 m_SpacePointTCCtr += 1;
77 B2DEBUG(20,
"SpacePointTrackCand " << iTC <<
" contains " << trackCand->
getNHits() <<
" SpacePoints");
79 std::vector<const SpacePoint*> tcSpacePoints = trackCand->
getHits();
83 for (
unsigned int iTCSP = 0; iTCSP < tcSpacePoints.size(); ++iTCSP) {
85 double sortingParam = sortingParams[iTCSP];
88 int detID = detType == VXD::SensorInfoBase::SVD ? Const::SVD : Const::PXD;
89 vector<int> clusterInds;
93 if (detType == VXD::SensorInfoBase::PXD) { clusterInds = getRelatedClusters<PXDCluster>(aSP, m_PXDClustersName); }
94 else if (detType == VXD::SensorInfoBase::SVD) { clusterInds = getRelatedClusters<SVDCluster>(aSP, m_SVDClustersName); }
95 else throw SpacePointTrackCand::UnsupportedDetType();
97 }
catch (std::runtime_error& anE) {
98 B2WARNING(
"Caught exception during creation of a genfit::TrackCand: " << anE.what());
102 B2WARNING(
"Caught unknown exception during conversion from SPTC to GFTC!");
106 for (
int hitID : clusterInds) {
107 genfitTC.addHit(detID, hitID, -1, sortingParam);
108 B2DEBUG(60,
"Added Cluster " << hitID <<
" with detID " << detID <<
" to genfit::TrackCand");
119 if (LogSystem::Instance().isLevelEnabled(LogConfig::c_Debug, 150, PACKAGENAME())) genfitTC.
Print();
120 B2DEBUG(15,
"genfit::TrackCand contains " << genfitTC.getNHits() <<
" TrackCandHits.");
123 B2DEBUG(15,
"Added relation between SPTC " << trackCand->
getArrayIndex() <<
" from Array " << trackCand->
getArrayName() <<
128 void SPTC2GFTCConverterModule::terminate()
131 output <<
"SPTC2GFTCConverter::terminate: got " << m_SpacePointTCCtr <<
" SpacePointTrackCands and created " << m_genfitTCCtr <<
132 " genfit::TrackCands";
133 if (m_skippedSPsCtr) output <<
". " << m_skippedSPsCtr <<
" SpacePoints were skipped!";
134 B2INFO(output.str());
138 template<
typename ClusterType>
139 std::vector<int> SPTC2GFTCConverterModule::getRelatedClusters(
const Belle2::SpacePoint* spacePoint,
const std::string& clusterNames)
141 std::vector<int> clusterInds;
144 if (relatedClusters.
size() == 0) {
145 B2DEBUG(1,
"Found no related Clusters for SpacePoint " << spacePoint->
getArrayIndex() <<
" from Array " <<
147 throw ClusterNotFound();
148 }
else B2ASSERT(
"Too many clusters!", relatedClusters.
size() < 3);
150 for (
const ClusterType& cluster : relatedClusters) {
151 clusterInds.push_back(cluster.getArrayIndex());
152 B2DEBUG(60,
"Cluster " << cluster.getArrayIndex() <<
" from Array " << cluster.getArrayName() <<
" is related to SpacePoint " <<
159 void SPTC2GFTCConverterModule::initializeCounters()
161 m_SpacePointTCCtr = 0;