9#include <tracking/modules/spacePointCreator/RT2SPTCConverterModuleDev.h>
11#include <framework/dataobjects/EventMetaData.h>
12#include <framework/datastore/StoreObjPtr.h>
17using ConversionState = std::bitset<2>;
26 setDescription(
"Module for converting RecoTracks (e.g. from TrackFinderMCTruth) to SpacePointTrackCands.");
36 std::make_optional<std::string>(
"SVDSpacePoints"));
38 std::make_optional<std::string>(
"PXDSpacePoints"));
45 "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!)",
50 "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",
56 "If set to true clusters that could not be converted are skipped instead of throwing away the complete SPTC",
61 addParam(
"markRecoTracks",
m_markRecoTracks,
"If True RecoTracks where conversion problems occurred are marked dirty.",
false);
64 "TFile that contains the list of cuts to select trainins sample. If parameter left empty NoKickCuts are not applied",
68 "If true produce a TFile with some histograms useful to understand behaviour of training sample selection",
false);
70 addParam(
"ignorePXDHits",
m_ignorePXDHits,
"If true no PXD hits will be used when creating the SpacePointTrackCand",
bool(
false));
87 B2INFO(
"RT2SPTCConverter -------------- initialize() ---------------------");
124 const int eventCounter = eventMetaDataPtr->getEvent();
125 B2DEBUG(20,
"RT2SPTCConverter::event(). Processing event " << eventCounter <<
" --------");
141 std::pair<std::vector<const SpacePoint*>,
ConversionState> spacePointStatePair;
144 std::vector<RecoHitInformation*> hitInfos = recoTrack.getRecoHitInformations(
true);
149 std::vector<RecoHitInformation*> hitInfos_buff;
150 for (std::vector<RecoHitInformation*>::iterator it = hitInfos.begin(); it < hitInfos.end(); ++it) {
151 if ((*it)->getTrackingDetector() != RecoHitInformation::c_PXD) hitInfos_buff.push_back(*it);
153 hitInfos = hitInfos_buff;
156 B2DEBUG(20,
"New call getSpacePointsFromRecoHitInformationViaTrueHits. Number of hitInfos: " << hitInfos.size());
157 B2DEBUG(20,
"number of SVD hits in RecoTrack : " << recoTrack.getNumberOfSVDHits());
158 B2DEBUG(20,
"number of PXD hits in RecoTrack : " << recoTrack.getNumberOfPXDHits());
159 B2DEBUG(20,
"number of CDC hits in RecoTrack : " << recoTrack.getNumberOfCDCHits());
166 B2DEBUG(20,
"RT2SPTCConverter::event: Number of SpacePoints: " << spacePointStatePair.first.size() <<
"State: " <<
167 spacePointStatePair.second);
169 if (
int(spacePointStatePair.first.size()) <
m_minSP) {
170 B2DEBUG(20,
"RT2SPTCConverter::event: Not enough number of SpacePoints: " << spacePointStatePair.first.size() <<
177 if (spacePointStatePair.second.test(c_undefinedError)) {
189 recoTrack.getArrayIndex());
191 spacePointTC =
SpacePointTrackCand(spacePointStatePair.first, 0, 0, recoTrack.getArrayIndex());
196 if (spacePointStatePair.second.test(c_singleCluster)) {
203 const ROOT::Math::XYZVector& momentumSeed = recoTrack.getMomentumSeed();
204 const ROOT::Math::XYZVector& positionSeed = recoTrack.getPositionSeed();
207 seed6D[0] = positionSeed.X();
208 seed6D[1] = positionSeed.Y();
209 seed6D[2] = positionSeed.Z();
210 seed6D[3] = momentumSeed.X();
211 seed6D[4] = momentumSeed.Y();
212 seed6D[5] = momentumSeed.Z();
214 spacePointTC.
setCovSeed(recoTrack.getSeedCovariance());
225std::pair<std::vector<const SpacePoint*>, ConversionState>
228 std::vector<const SpacePoint*> finalSpacePoints;
236 if (hitInfo->getTrackingDetector() != RecoHitInformation::c_SVD && hitInfo->getTrackingDetector() != RecoHitInformation::c_PXD)
244 if (hitInfo->getTrackingDetector() == RecoHitInformation::c_SVD) {
245 cluster = hitInfo->getRelatedTo<
SVDCluster>();
247 relatedTrueHit = cluster->getRelatedTo<
SVDTrueHit>();
248 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: Number of related SVDTrueHits: " <<
249 cluster->getRelationsTo<
SVDTrueHit>().size());
254 if (hitInfo->getTrackingDetector() == RecoHitInformation::c_PXD) {
255 cluster = hitInfo->getRelatedTo<
PXDCluster>();
257 relatedTrueHit = cluster->getRelatedTo<
PXDTrueHit>();
258 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: Number of related PXDTrueHits: "
259 << cluster->getRelationsTo<
PXDTrueHit>().size());
263 if (!relatedTrueHit) {
264 state.set(c_undefinedError);
265 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: TrueHit missing.");
284 if (hitInfo->getTrackingDetector() == RecoHitInformation::c_SVD) {
291 if (!relatedSpacePoint) {
292 state.set(c_undefinedError);
293 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: SpacePoint missing.");
300 if (std::find(finalSpacePoints.begin(), finalSpacePoints.end(), relatedSpacePoint) == finalSpacePoints.end()) {
301 finalSpacePoints.push_back(relatedSpacePoint);
304 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: Number of SpacePoints: " << finalSpacePoints.size());
305 return std::make_pair(finalSpacePoints, state);
309std::pair<std::vector<const SpacePoint*>, ConversionState>
312 std::vector<const SpacePoint*> finalSpacePoints;
316 for (
size_t iHit = 0; iHit < hitInfos.size(); ++iHit) {
319 if (hitInfos[iHit]->getTrackingDetector() != RecoHitInformation::c_SVD &&
320 hitInfos[iHit]->getTrackingDetector() != RecoHitInformation::c_PXD)
continue;
323 std::vector<const SpacePoint*> spacePointCandidates;
327 if (hitInfos[iHit]->getTrackingDetector() == RecoHitInformation::c_PXD) {
330 if (pxdCluster) relatedPXDSP = pxdCluster->
getRelated<
SpacePoint>(*m_pxdSpacePointsStoreArrayName);
333 finalSpacePoints.push_back(relatedPXDSP);
344 B2WARNING(
"SVDCluster to hit not found! This should not happen!");
345 state.set(c_undefinedError);
357 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClusters: Number of SpacePoints related to first cluster: " <<
358 relatedSpacePointsA.
size());
362 if (clusterA && clusterB && (clusterA->
isUCluster() != clusterB->isUCluster())) {
363 auto relatedSpacePointsB = clusterB->getRelationsFrom<
SpacePoint>(*m_svdSpacePointsStoreArrayName);
366 for (
const auto& spacePoint : relatedSpacePointsA) {
367 for (
const auto& spacePointCompare : relatedSpacePointsB) {
368 if (spacePoint == spacePointCompare) {
369 spacePointCandidates.push_back(&spacePoint);
374 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClusters: Number of intersections with next cluster: " <<
375 spacePointCandidates.size());
377 if (spacePointCandidates.size() == 1) ++iHit;
387 if (relatedSpacePoints.size() == 1) {
388 state.set(c_singleCluster);
389 spacePointCandidates.push_back(relatedSpacePoints[0]);
393 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClusters: Conversion state is: " << state);
395 if (spacePointCandidates.size() != 1) {
396 state.set(c_undefinedError);
400 finalSpacePoints.push_back(spacePointCandidates.at(0));
403 return std::make_pair(finalSpacePoints, state);
408 B2RESULT(
"Number of Selected Tracks (NoKickRTSel): " <<
m_npass);
409 B2RESULT(
"Number of Rejected Tracks (NoKickRTSel): " <<
m_ncut);
417 B2RESULT(
"RT2SPTCConverter::terminate: Converted " <<
m_noFailCtr <<
"Reco Tracks without errors and "
419 <<
m_missingTrueHitCtr <<
" Tracks were skipped because they contained SpacePoints that had no relations to TrueHits, "
420 <<
m_minSPCtr <<
" Tracks were skipped because they didn't contain enough SpacePoints and for "
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
A Class to store the Monte Carlo particle information.
float getCharge() const
Return the particle charge defined in TDatabasePDG.
int getPDG() const
Return PDG code of particle.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
This class implement some methods useful for the application of cuts evaluated in NoKickCutsEval modu...
bool trackSelector(const RecoTrack &track)
This method return true if every segment (see segmentSelector) of the input track respects the cuts c...
void produceHistoNoKick()
This method produce the validation histograms (to be used the endrun combined with the filling in tra...
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Class PXDTrueHit - Records of tracks that either enter or leave the sensitive volume.
unsigned int m_singleClusterUseCtr
Counts how many tracks contained a single cluster.
bool m_ignorePXDHits
PXD hits will be ignored when creating the SP track candidate.
bool m_noKickOutput
true=produce TFile with effects of NoKickCuts on tracks
StoreArray< SVDCluster > m_SVDClusters
SVDClusters StoreArray.
unsigned int m_minSPCtr
Counts how many tracks didn't contain enough SpacePoints after conversion.
void initialize() override
Initialize module (e.g. check if all required StoreArrays are present or registering new StoreArrays)
int m_npass
counter of the selected tracks
StoreArray< SpacePointTrackCand > m_SpacePointTrackCands
SpacePointTrackCands StoreArray.
void event() override
Event: convert RecoTracks to SpacePointTrackCands.
int m_minSP
parameter for specifying a minimal number of SpacePoints a SpacePointTrackCand has to have in order t...
void endRun() override
End Run function.
bool m_mcParticlesPresent
If MCParticles are available.
void terminate() override
Terminate: print some summary information on the processed events.
bool m_skipProblematicCluster
If true problematic clusters are ignored.
std::string m_SVDSingleClusterSPName
Single Cluster SVD SpacePoints collection name.
bool m_useTrueHits
If true the method getSpacePointsFromSVDClustersViaTrueHits is utilized.
std::pair< std::vector< const SpacePoint * >, ConversionState > getSpacePointsFromRecoHitInformations(std::vector< RecoHitInformation * > hitInfos)
Convert Clusters to SpacePoints using the Relation: Cluster->SpacePoint.
StoreArray< SpacePoint > m_SVDSpacePoints
SVDSpacePoints StoreArray.
std::string m_noKickCutsFile
name of TFile of the cuts
std::optional< std::string > m_pxdSpacePointsStoreArrayName
PXD SpacePoints collection names.
RT2SPTCConverterModule()
Constructor.
StoreArray< SVDTrueHit > m_SVDTrueHit
SVDTrueHits StoreArray.
std::string m_SPTCName
Name of collection under which SpacePointTrackCands will be stored in the StoreArray.
std::string m_RecoTracksName
Name of collection of RecoTrack StoreArray.
unsigned int m_missingTrueHitCtr
Counts how many times a SpacePoint had no relation to a SVDTrueHit.
bool m_convertFittedOnly
if true only RecoTracks with successful fit will be converted
std::string m_SVDClusterName
SVDCluster collection name.
std::bitset< 2 > ConversionState
Used to store conversionFlags and pass them between methods.
NoKickRTSel * m_trackSel
data members used for the NoKickCuts method
std::optional< std::string > m_svdSpacePointsStoreArrayName
Non SingleCluster SVD SpacePoints collection names.
StoreArray< RecoTrack > m_RecoTracks
RecoTracks StoreArray.
void initializeCounters()
reset counters to 0 to avoid indeterministic behaviour
unsigned int m_undefinedErrorCtr
Counts how many tracks failed to be converted.
bool m_useSingleClusterSP
If true use single cluster SpacePoint collection as fallback.
unsigned int m_noFailCtr
Counts how many tracks could be converted without any problems.
StoreArray< SpacePoint > m_PXDSpacePoints
PXDSpacePoints StoreArray.
int m_ncut
counter of the cut tracks
StoreArray< MCParticle > m_MCParticles
MCParticles StoreArray.
bool m_markRecoTracks
If True RecoTracks where conversion problems occurred are marked dirty.
std::pair< std::vector< const SpacePoint * >, ConversionState > getSpacePointsFromRecoHitInformationViaTrueHits(std::vector< RecoHitInformation * > hitInfos)
Convert Clusters to SpacePoints using the Relation: Cluster->TrueHit->SpacePoint.
~RT2SPTCConverterModule()
Destructor.
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
Defines interface for accessing relations of objects in StoreArray.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
RelationVector< FROM > getRelationsFrom(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from another store array to this object.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
bool isUCluster() const
Get the direction of strips.
Class SVDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Storage for (VXD) SpacePoint-based track candidates.
void set6DSeed(const TVectorD &state6D)
set the 6D state seed
void setCovSeed(const TMatrixDSym &cov)
set the covariance matrix seed
@ c_checkedTrueHits
bit 5: All SpacePoints of the SPTC have a relation to at least one TrueHit.
@ c_singleClustersSPs
bit 10: SPTC contains single Cluster SpacePoints.
void addRefereeStatus(unsigned short int bitmask)
add a referee status
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
T * appendNew()
Construct a new T object at the end of the array.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Type-safe access to single objects in the data store.
Class VXDTrueHit - Records of tracks that either enter or leave the sensitive volume.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.