10 #include <tracking/modules/spacePointCreator/RT2SPTCConverterModuleDev.h>
11 #include <tracking/spacePointCreation/SpacePointTrackCand.h>
13 #include <framework/dataobjects/EventMetaData.h>
14 #include <framework/datastore/StoreObjPtr.h>
18 #include <svd/dataobjects/SVDCluster.h>
19 #include <mdst/dataobjects/MCParticle.h>
20 #include <svd/dataobjects/SVDTrueHit.h>
21 #include <pxd/dataobjects/PXDTrueHit.h>
24 using ConversionState = std::bitset<2>;
33 setDescription(
"Module for converting RecoTracks (e.g. from TrackFinderMCTruth) to SpacePointTrackCands.");
34 setPropertyFlags(c_ParallelProcessingCertified);
37 addParam(
"RecoTracksName", m_RecoTracksName,
"Name of container of RecoTracks", std::string(
""));
40 addParam(
"SVDClusters", m_SVDClusterName,
"SVDCluster collection name", std::string(
""));
42 addParam(
"SVDSpacePointStoreArrayName", m_svdSpacePointsStoreArrayName,
"Name of the collection for SVD.",
43 boost::make_optional<std::string>(
"SVDSpacePoints"));
44 addParam(
"PXDSpacePointStoreArrayName", m_pxdSpacePointsStoreArrayName,
"Name of the collection for PXD.",
45 boost::make_optional<std::string>(
"PXDSpacePoints"));
48 addParam(
"SVDSingleClusterSP", m_SVDSingleClusterSPName,
"SVD single Cluster SpacePoints collection name.", std::string(
""));
51 addParam(
"SpacePointTCName", m_SPTCName,
52 "Name of the container under which SpacePointTrackCands will be stored in the DataStore (NOTE: These SpaceTrackCands are not checked for curling behaviour, but are simply converted and stored!)",
56 addParam(
"minSP", m_minSP,
57 "Minimum number of SpacePoints a SpacePointTrackCand has to contain in order to get registered in the DataStore. If set to 0, any number is accepted",
60 addParam(
"useTrueHits", m_useTrueHits,
"Converts clusters via their relations to TrueHits.",
false);
62 addParam(
"skipProblematicCluster", m_skipProblematicCluster,
63 "If set to true clusters that could not be converted are skipped instead of throwing away the complete SPTC",
66 addParam(
"useSingleClusterSP", m_useSingleClusterSP,
"Set to true if these SpacePoints should be used as fallback.",
false);
68 addParam(
"markRecoTracks", m_markRecoTracks,
"If True RecoTracks where conversion problems occurred are marked dirty.",
false);
70 addParam(
"noKickCutsFile", m_noKickCutsFile,
71 "TFile that contains the list of cuts to select trainins sample. If parameter left empty NoKickCuts are not applied",
74 addParam(
"noKickOutput", m_noKickOutput,
75 "If true produce a TFile with some histograms useful to understand behaviour of training sample selection",
false);
77 addParam(
"ignorePXDHits", m_ignorePXDHits,
"If true no PXD hits will be used when creating the SpacePointTrackCand",
bool(
false));
79 addParam(
"convertFittedOnly", m_convertFittedOnly,
"If true only RecoTracks with successful fit will be converted to "
80 "SpacePointTrackCands", m_convertFittedOnly);
94 B2INFO(
"RT2SPTCConverter -------------- initialize() ---------------------");
118 if (mcparticles.isOptional()) {
137 const int eventCounter = eventMetaDataPtr->getEvent();
138 B2DEBUG(20,
"RT2SPTCConverter::event(). Processing event " << eventCounter <<
" --------");
145 for (
auto& recoTrack : m_recoTracks) {
159 std::pair<std::vector<const SpacePoint*>,
ConversionState> spacePointStatePair;
162 std::vector<RecoHitInformation*> hitInfos = recoTrack.getRecoHitInformations(
true);
167 std::vector<RecoHitInformation*> hitInfos_buff;
168 for (std::vector<RecoHitInformation*>::iterator it = hitInfos.begin(); it < hitInfos.end(); ++it) {
169 if ((*it)->getTrackingDetector() != RecoHitInformation::c_PXD) hitInfos_buff.push_back(*it);
171 hitInfos = hitInfos_buff;
174 B2DEBUG(20,
"New call getSpacePointsFromRecoHitInformationViaTrueHits. Number of hitInfos: " << hitInfos.size());
175 B2DEBUG(20,
"number of SVD hits in RecoTrack : " << recoTrack.getNumberOfSVDHits());
176 B2DEBUG(20,
"number of PXD hits in RecoTrack : " << recoTrack.getNumberOfPXDHits());
177 B2DEBUG(20,
"number of CDC hits in RecoTrack : " << recoTrack.getNumberOfCDCHits());
184 B2DEBUG(20,
"RT2SPTCConverter::event: Number of SpacePoints: " << spacePointStatePair.first.size() <<
"State: " <<
185 spacePointStatePair.second);
187 if (
int(spacePointStatePair.first.size()) <
m_minSP) {
188 B2DEBUG(20,
"RT2SPTCConverter::event: Not enough number of SpacePoints: " << spacePointStatePair.first.size() <<
195 if (spacePointStatePair.second.test(c_undefinedError)) {
207 recoTrack.getArrayIndex());
209 spacePointTC =
SpacePointTrackCand(spacePointStatePair.first, 0, 0, recoTrack.getArrayIndex());
214 if (spacePointStatePair.second.test(c_singleCluster)) {
221 TVector3 momentumSeed = recoTrack.getMomentumSeed();
222 TVector3 positionSeed = recoTrack.getPositionSeed();
225 seed6D[0] = positionSeed.x();
226 seed6D[1] = positionSeed.y();
227 seed6D[2] = positionSeed.z();
228 seed6D[3] = momentumSeed.Px();
229 seed6D[4] = momentumSeed.Py();
230 seed6D[5] = momentumSeed.Pz();
232 spacePointTC.
setCovSeed(recoTrack.getSeedCovariance());
243 std::pair<std::vector<const SpacePoint*>, ConversionState>
246 std::vector<const SpacePoint*> finalSpacePoints;
254 if (hitInfo->getTrackingDetector() != RecoHitInformation::c_SVD && hitInfo->getTrackingDetector() != RecoHitInformation::c_PXD)
262 if (hitInfo->getTrackingDetector() == RecoHitInformation::c_SVD) {
263 cluster = hitInfo->getRelatedTo<
SVDCluster>();
265 relatedTrueHit = cluster->getRelatedTo<
SVDTrueHit>();
266 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: Number of related SVDTrueHits: " <<
267 cluster->getRelationsTo<
SVDTrueHit>().size());
272 if (hitInfo->getTrackingDetector() == RecoHitInformation::c_PXD) {
273 cluster = hitInfo->getRelatedTo<
PXDCluster>();
275 relatedTrueHit = cluster->getRelatedTo<
PXDTrueHit>();
276 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: Number of related PXDTrueHits: "
277 << cluster->getRelationsTo<
PXDTrueHit>().size());
281 if (!relatedTrueHit) {
282 state.set(c_undefinedError);
283 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: TrueHit missing.");
300 if (hitInfo->getTrackingDetector() == RecoHitInformation::c_SVD) {
307 if (!relatedSpacePoint) {
308 state.set(c_undefinedError);
309 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: SpacePoint missing.");
316 if (std::find(finalSpacePoints.begin(), finalSpacePoints.end(), relatedSpacePoint) == finalSpacePoints.end()) {
317 finalSpacePoints.push_back(relatedSpacePoint);
320 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: Number of SpacePoints: " << finalSpacePoints.size());
321 return std::make_pair(finalSpacePoints, state);
325 std::pair<std::vector<const SpacePoint*>, ConversionState>
328 std::vector<const SpacePoint*> finalSpacePoints;
332 for (
size_t iHit = 0; iHit < hitInfos.size(); ++iHit) {
335 if (hitInfos[iHit]->getTrackingDetector() != RecoHitInformation::c_SVD &&
336 hitInfos[iHit]->getTrackingDetector() != RecoHitInformation::c_PXD)
continue;
339 std::vector<const SpacePoint*> spacePointCandidates;
343 if (hitInfos[iHit]->getTrackingDetector() == RecoHitInformation::c_PXD) {
346 if (pxdCluster) relatedPXDSP = pxdCluster->
getRelated<
SpacePoint>(*m_pxdSpacePointsStoreArrayName);
349 finalSpacePoints.push_back(relatedPXDSP);
360 B2WARNING(
"SVDCluster to hit not found! This should not happen!");
361 state.set(c_undefinedError);
371 if (iHit + 1 < hitInfos.size()) clusterB = hitInfos.at(iHit + 1)->getRelated<
SVDCluster>();
373 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClusters: Number of SpacePoints related to first cluster: " <<
374 relatedSpacePointsA.
size());
377 if (clusterA && clusterB && (clusterA->
isUCluster() != clusterB->isUCluster())) {
378 auto relatedSpacePointsB = clusterB->getRelationsFrom<
SpacePoint>(*m_svdSpacePointsStoreArrayName);
381 for (
const auto& spacePoint : relatedSpacePointsA) {
382 for (
const auto& spacePointCompare : relatedSpacePointsB) {
384 if (spacePoint == spacePointCompare) {
385 spacePointCandidates.push_back(&spacePoint);
390 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClusters: Number of intersections with next cluster: " <<
391 spacePointCandidates.size());
393 if (spacePointCandidates.size() == 1) ++iHit;
402 if (relatedSpacePoints.size() == 1) {
403 state.set(c_singleCluster);
404 spacePointCandidates.push_back(relatedSpacePoints[0]);
408 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClusters: Conversion state is: " << state);
410 if (spacePointCandidates.size() != 1) {
411 state.set(c_undefinedError);
415 finalSpacePoints.push_back(spacePointCandidates.at(0));
418 return std::make_pair(finalSpacePoints, state);
423 B2RESULT(
"Number of Selected Tracks (NoKickRTSel): " <<
m_npass);
424 B2RESULT(
"Number of Rejected Tracks (NoKickRTSel): " <<
m_ncut);
432 B2RESULT(
"RT2SPTCConverter::terminate: Converted " <<
m_noFailCtr <<
"Reco Tracks without errors and "
434 <<
m_missingTrueHitCtr <<
" Tracks were skipped because they contained SpacePoints that had no relations to TrueHits, "
435 <<
m_minSPCtr <<
" Tracks were skipped because they didn't contain enough SpacePoints and for "