9 #include <tracking/modules/spacePointCreator/RT2SPTCConverterModuleDev.h>
10 #include <tracking/spacePointCreation/SpacePointTrackCand.h>
12 #include <framework/dataobjects/EventMetaData.h>
13 #include <framework/datastore/StoreObjPtr.h>
17 #include <svd/dataobjects/SVDCluster.h>
18 #include <mdst/dataobjects/MCParticle.h>
19 #include <svd/dataobjects/SVDTrueHit.h>
20 #include <pxd/dataobjects/PXDTrueHit.h>
23 using ConversionState = std::bitset<2>;
32 setDescription(
"Module for converting RecoTracks (e.g. from TrackFinderMCTruth) to SpacePointTrackCands.");
33 setPropertyFlags(c_ParallelProcessingCertified);
36 addParam(
"RecoTracksName", m_RecoTracksName,
"Name of container of RecoTracks", std::string(
""));
39 addParam(
"SVDClusters", m_SVDClusterName,
"SVDCluster collection name", std::string(
""));
41 addParam(
"SVDSpacePointStoreArrayName", m_svdSpacePointsStoreArrayName,
"Name of the collection for SVD.",
42 boost::make_optional<std::string>(
"SVDSpacePoints"));
43 addParam(
"PXDSpacePointStoreArrayName", m_pxdSpacePointsStoreArrayName,
"Name of the collection for PXD.",
44 boost::make_optional<std::string>(
"PXDSpacePoints"));
47 addParam(
"SVDSingleClusterSP", m_SVDSingleClusterSPName,
"SVD single Cluster SpacePoints collection name.", std::string(
""));
50 addParam(
"SpacePointTCName", m_SPTCName,
51 "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!)",
55 addParam(
"minSP", m_minSP,
56 "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",
59 addParam(
"useTrueHits", m_useTrueHits,
"Converts clusters via their relations to TrueHits.",
false);
61 addParam(
"skipProblematicCluster", m_skipProblematicCluster,
62 "If set to true clusters that could not be converted are skipped instead of throwing away the complete SPTC",
65 addParam(
"useSingleClusterSP", m_useSingleClusterSP,
"Set to true if these SpacePoints should be used as fallback.",
false);
67 addParam(
"markRecoTracks", m_markRecoTracks,
"If True RecoTracks where conversion problems occurred are marked dirty.",
false);
69 addParam(
"noKickCutsFile", m_noKickCutsFile,
70 "TFile that contains the list of cuts to select trainins sample. If parameter left empty NoKickCuts are not applied",
73 addParam(
"noKickOutput", m_noKickOutput,
74 "If true produce a TFile with some histograms useful to understand behaviour of training sample selection",
false);
76 addParam(
"ignorePXDHits", m_ignorePXDHits,
"If true no PXD hits will be used when creating the SpacePointTrackCand",
bool(
false));
78 addParam(
"convertFittedOnly", m_convertFittedOnly,
"If true only RecoTracks with successful fit will be converted to "
79 "SpacePointTrackCands", m_convertFittedOnly);
93 B2INFO(
"RT2SPTCConverter -------------- initialize() ---------------------");
136 const int eventCounter = eventMetaDataPtr->getEvent();
137 B2DEBUG(20,
"RT2SPTCConverter::event(). Processing event " << eventCounter <<
" --------");
144 for (
auto& recoTrack : m_recoTracks) {
158 std::pair<std::vector<const SpacePoint*>,
ConversionState> spacePointStatePair;
161 std::vector<RecoHitInformation*> hitInfos = recoTrack.getRecoHitInformations(
true);
166 std::vector<RecoHitInformation*> hitInfos_buff;
167 for (std::vector<RecoHitInformation*>::iterator it = hitInfos.begin(); it < hitInfos.end(); ++it) {
168 if ((*it)->getTrackingDetector() != RecoHitInformation::c_PXD) hitInfos_buff.push_back(*it);
170 hitInfos = hitInfos_buff;
173 B2DEBUG(20,
"New call getSpacePointsFromRecoHitInformationViaTrueHits. Number of hitInfos: " << hitInfos.size());
174 B2DEBUG(20,
"number of SVD hits in RecoTrack : " << recoTrack.getNumberOfSVDHits());
175 B2DEBUG(20,
"number of PXD hits in RecoTrack : " << recoTrack.getNumberOfPXDHits());
176 B2DEBUG(20,
"number of CDC hits in RecoTrack : " << recoTrack.getNumberOfCDCHits());
183 B2DEBUG(20,
"RT2SPTCConverter::event: Number of SpacePoints: " << spacePointStatePair.first.size() <<
"State: " <<
184 spacePointStatePair.second);
186 if (
int(spacePointStatePair.first.size()) <
m_minSP) {
187 B2DEBUG(20,
"RT2SPTCConverter::event: Not enough number of SpacePoints: " << spacePointStatePair.first.size() <<
194 if (spacePointStatePair.second.test(c_undefinedError)) {
206 recoTrack.getArrayIndex());
208 spacePointTC =
SpacePointTrackCand(spacePointStatePair.first, 0, 0, recoTrack.getArrayIndex());
213 if (spacePointStatePair.second.test(c_singleCluster)) {
220 TVector3 momentumSeed = recoTrack.getMomentumSeed();
221 TVector3 positionSeed = recoTrack.getPositionSeed();
224 seed6D[0] = positionSeed.x();
225 seed6D[1] = positionSeed.y();
226 seed6D[2] = positionSeed.z();
227 seed6D[3] = momentumSeed.Px();
228 seed6D[4] = momentumSeed.Py();
229 seed6D[5] = momentumSeed.Pz();
231 spacePointTC.
setCovSeed(recoTrack.getSeedCovariance());
242 std::pair<std::vector<const SpacePoint*>, ConversionState>
245 std::vector<const SpacePoint*> finalSpacePoints;
253 if (hitInfo->getTrackingDetector() != RecoHitInformation::c_SVD && hitInfo->getTrackingDetector() != RecoHitInformation::c_PXD)
261 if (hitInfo->getTrackingDetector() == RecoHitInformation::c_SVD) {
262 cluster = hitInfo->getRelatedTo<
SVDCluster>();
264 relatedTrueHit = cluster->getRelatedTo<
SVDTrueHit>();
265 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: Number of related SVDTrueHits: " <<
266 cluster->getRelationsTo<
SVDTrueHit>().size());
271 if (hitInfo->getTrackingDetector() == RecoHitInformation::c_PXD) {
272 cluster = hitInfo->getRelatedTo<
PXDCluster>();
274 relatedTrueHit = cluster->getRelatedTo<
PXDTrueHit>();
275 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: Number of related PXDTrueHits: "
276 << cluster->getRelationsTo<
PXDTrueHit>().size());
280 if (!relatedTrueHit) {
281 state.set(c_undefinedError);
282 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: TrueHit missing.");
299 if (hitInfo->getTrackingDetector() == RecoHitInformation::c_SVD) {
306 if (!relatedSpacePoint) {
307 state.set(c_undefinedError);
308 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: SpacePoint missing.");
315 if (std::find(finalSpacePoints.begin(), finalSpacePoints.end(), relatedSpacePoint) == finalSpacePoints.end()) {
316 finalSpacePoints.push_back(relatedSpacePoint);
319 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClustersViaTrueHits: Number of SpacePoints: " << finalSpacePoints.size());
320 return std::make_pair(finalSpacePoints, state);
324 std::pair<std::vector<const SpacePoint*>, ConversionState>
327 std::vector<const SpacePoint*> finalSpacePoints;
331 for (
size_t iHit = 0; iHit < hitInfos.size(); ++iHit) {
334 if (hitInfos[iHit]->getTrackingDetector() != RecoHitInformation::c_SVD &&
335 hitInfos[iHit]->getTrackingDetector() != RecoHitInformation::c_PXD)
continue;
338 std::vector<const SpacePoint*> spacePointCandidates;
342 if (hitInfos[iHit]->getTrackingDetector() == RecoHitInformation::c_PXD) {
345 if (pxdCluster) relatedPXDSP = pxdCluster->
getRelated<
SpacePoint>(*m_pxdSpacePointsStoreArrayName);
348 finalSpacePoints.push_back(relatedPXDSP);
359 B2WARNING(
"SVDCluster to hit not found! This should not happen!");
360 state.set(c_undefinedError);
372 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClusters: Number of SpacePoints related to first cluster: " <<
373 relatedSpacePointsA.
size());
376 if (clusterA && clusterB && (clusterA->
isUCluster() != clusterB->isUCluster())) {
377 auto relatedSpacePointsB = clusterB->getRelationsFrom<
SpacePoint>(*m_svdSpacePointsStoreArrayName);
380 for (
const auto& spacePoint : relatedSpacePointsA) {
381 for (
const auto& spacePointCompare : relatedSpacePointsB) {
382 if (spacePoint == spacePointCompare) {
383 spacePointCandidates.push_back(&spacePoint);
388 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClusters: Number of intersections with next cluster: " <<
389 spacePointCandidates.size());
391 if (spacePointCandidates.size() == 1) ++iHit;
401 if (relatedSpacePoints.size() == 1) {
402 state.set(c_singleCluster);
403 spacePointCandidates.push_back(relatedSpacePoints[0]);
407 B2DEBUG(20,
"RT2SPTCConverter::getSpacePointsFromClusters: Conversion state is: " << state);
409 if (spacePointCandidates.size() != 1) {
410 state.set(c_undefinedError);
414 finalSpacePoints.push_back(spacePointCandidates.at(0));
417 return std::make_pair(finalSpacePoints, state);
422 B2RESULT(
"Number of Selected Tracks (NoKickRTSel): " <<
m_npass);
423 B2RESULT(
"Number of Rejected Tracks (NoKickRTSel): " <<
m_ncut);
431 B2RESULT(
"RT2SPTCConverter::terminate: Converted " <<
m_noFailCtr <<
"Reco Tracks without errors and "
433 <<
m_missingTrueHitCtr <<
" Tracks were skipped because they contained SpacePoints that had no relations to TrueHits, "
434 <<
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.
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.
Module for converting RecoTracks to SpacePointTrackCands.
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.
boost::optional< std::string > m_pxdSpacePointsStoreArrayName
PXD SpacePoints collection names.
boost::optional< std::string > m_svdSpacePointsStoreArrayName
Non SingleCluster SVD SpacePoints collection names.
bool m_noKickOutput
true=produce TFile with effects of NoKickCuts on tracks
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
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.
std::string m_noKickCutsFile
name of TFile of the cuts
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 fot the NoKickCuts method
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.
int m_ncut
counter of the cuttet tracks
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).
RelationVector< FROM > getRelationsFrom(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from another store array to this object.
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to 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.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.