9#include <tracking/modules/spacePointCreator/TCConvertersTestModule.h>
11#include <framework/datastore/StoreArray.h>
12#include <framework/datastore/StoreObjPtr.h>
13#include <framework/dataobjects/EventMetaData.h>
25 setDescription(
"Module for testing the functionality of the TrackCand converter modules and their underlying classes.");
27 addParam(
"PXDClusters",
m_PXDClusterName,
"PXDCluster collection name. WARNING: it is only checked if these exist, "\
28 "they are not actually used at the moment!", std::string(
""));
30 " they are not actually used at the moment!", std::string(
""));
31 addParam(
"SpacePointTCName",
m_SPTCName,
"Name of the container under which SpacePoints are stored in the DataStore",
34 std::vector<std::string> emptyDefaultStringVec = { std::string(
"") };
36 "WARNING: For this module provide two names! First is the name of the container with the genfit::TrackCands"\
37 " which were used to create SpacePointTrackCands (e.g. from MCTrackFinderTruth), second are the genfit::TrackCands"\
38 " obtaineed by the 'back conversion' from the SpacePointTrackCands!", emptyDefaultStringVec);
46 B2INFO(
"TCConvertersTest ---------------------------- initialize ------------------ ");
65 const int eventCounter = eventMetaDataPtr->getEvent();
66 B2DEBUG(20,
"TCConvertersTest::event(). Processing event " << eventCounter <<
" --------");
75 int nConvertedTCs = convertedGenfitTCs.
getEntries();
76 int nSpacePointTCs = SpacePointTCs.
getEntries();
82 B2DEBUG(20,
"Found " << nGenfitTCs <<
" genfit::TrackCands, " << nSpacePointTCs <<
" SpacePointTrackCands and " << \
83 nConvertedTCs <<
" genfit::TrackCands created by conversion from a SpacePointTrackCand");
93 for (
int iTC = 0; iTC < nSpacePointTCs; ++iTC) {
96 B2DEBUG(20,
"Now comparing genfit::TrackCands related from SpacePointTrackCand " << trackCand->
getArrayIndex() << \
105 if (genfitTC ==
nullptr) {
106 B2DEBUG(25,
"Found no original genfit::TrackCand related from SpacePointTrackCand " << trackCand->
getArrayIndex() << \
111 if (convertedTC ==
nullptr) {
112 B2DEBUG(25,
"Found no converted genfit::TrackCand related from SpacePointTrackCand " << trackCand->
getArrayIndex() << \
121 convertedTC->Print();
125 if (*genfitTC == *convertedTC) {
126 B2DEBUG(20,
"The two genfit::TrackCands are equal!");
129 B2DEBUG(20,
"The two genfit::TrackCands differ!");
131 B2DEBUG(20,
"It is OK for the two TrackCands to differ (i.e. the hits that miss are due to their absence in the SPTC!)");
134 B2WARNING(
"Two genfit::TrackCands differ but there is no apparent reason why they should be allowed to do so!");
144 std::stringstream results;
145 results <<
"There were " <<
m_failedOther <<
" cases that one should look into and " << \
146 m_differButOKCtr <<
" cases where the failure of the comparison can be explained.";
148 B2INFO(
"TCConverterTest::terminate(): Got " <<
m_genfitTCCtr <<
" 'original' genfit::TrackCands, " << \
151 if (
m_failedOther) { B2WARNING(
"There were cases during comparison that need to be looked at!"); }
154 std::stringstream verbose;
155 verbose <<
m_lessHitsCtr <<
" times the original GFTC had less hits than the converted" << std::endl;
156 verbose <<
m_moreHitsCtr <<
" times the converted GFTC had less hits than the original" << std::endl;
158 verbose <<
m_failedWrongOrder <<
" times the hits were contained in the wrong order " << std::endl;
159 verbose <<
m_failedNotSameHits <<
" times there were hits in the converted GFTC that were not in the original" << std::endl;
162 verbose <<
"In " <<
m_failedNoSPTC <<
" cases the conversion from GFTC -> SPTC went wrong and in ";
163 verbose <<
m_failedNoGFTC <<
" cases the conversion from SPTC -> GFTC went wrong" << std::endl;
164 B2DEBUG(20, verbose.str());
173 size_t nOrigHits = origTC->getNHits();
174 size_t nConvHits = convTC->getNHits();
175 bool diffNHits = nOrigHits != nConvHits;
177 B2DEBUG(29,
"The number of hits do not match. original GFTC: " << nOrigHits <<
", converted GFTC: " << nConvHits);
182 B2WARNING(
"The number of hits does not match but the referee status omittedClusters is not set for the SPTC!");
191 std::array<bool, 4> foundHits =
checkHits(origHits, convHits);
192 B2DEBUG(29,
"Contents of foundHits: " << std::get<0>(foundHits) <<
" " << std::get<1>(foundHits) << \
193 " " << std::get<2>(foundHits) <<
" " << std::get<3>(foundHits));
196 B2WARNING(
"Not all hits from the converted GFTC are in the original GFTC!");
201 B2DEBUG(20,
"The hits appear in the wrong order in the converted GFTC compared to the original GFTC!");
205 B2WARNING(
"The sorting parameters are not matching!");
216 std::vector<trackCandHit> tcHits;
217 for (
size_t iHit = 0; iHit < trackCand->getNHits(); ++iHit) {
218 genfit::TrackCandHit* hit = trackCand->getHit(iHit);
219 tcHits.push_back(std::make_tuple(hit->getDetId(), hit->getHitId(), hit->getPlaneId(), hit->getSortingParameter()));
226 const std::vector<trackCandHit>& convHits)
228 std::array<bool, 4> checkResults = {{
true,
true,
true,
true }};
229 typedef std::vector<trackCandHit>::const_iterator vectorIt;
232 B2DEBUG(29,
"Checking if all hits of converted TC can be found in the original TC!");
233 std::stringstream allHitsOut;
235 allHitsOut << std::get<0>(hit) <<
"\t" << std::get<1>(hit) <<
"\t" << std::get<2>(hit) <<
"\t" << std::get<3>(hit) << std::endl;
237 B2DEBUG(29,
"Hits of original TC:\ndetId\thitId\tplaneId\tsort.Param:\n" << allHitsOut.str());
239 for (
size_t iHit = 0; iHit < convHits.size(); ++iHit) {
242 std::stringstream hitOut;
243 hitOut <<
"Checking hit " << std::get<0>(hit) <<
" " << std::get<1>(hit) <<
" " << std::get<2>(hit) <<
" " << std::get<3>
245 vectorIt foundIt = find(origHits.begin(), origHits.end(), hit);
247 if (foundIt == origHits.end()) {
248 hitOut <<
"not found, now checking if omitting planeID and sortingParams helps:" << std::endl;
249 vectorIt foundOnlyHitsIt = checkEntries<0, 1>(origHits, hit);
250 if (foundOnlyHitsIt != origHits.end()) {
251 pos = foundOnlyHitsIt - origHits.begin();
252 hitOut <<
" hit is contained in origHits at position " << pos <<
"! Now checking what is not matching " << std::endl;
253 vectorIt foundNoSortIt = checkEntries<0, 1, 2>(origHits, hit);
254 vectorIt foundNoPlaneIdIt = checkEntries<0, 1, 3>(origHits, hit);
255 if (foundNoSortIt == origHits.end()) {
256 hitOut <<
" sorting parameters are not matching!" << std::endl;
257 checkResults[3] =
false;
259 if (foundNoPlaneIdIt == origHits.end()) {
260 hitOut <<
" the planeIDs are not matching!" << std::endl;
261 checkResults[2] =
false;
264 hitOut <<
" hit is not contained in origHits!" << std::endl;
265 checkResults[0] =
false;
269 pos = foundIt - origHits.begin();
270 hitOut <<
" hit found at position " << pos << std::endl;
272 B2DEBUG(29, hitOut.str());
273 B2DEBUG(29,
"This hit appears in position " << pos <<
" in the original TC " <<
" the last checked hit was on position " <<
276 if (pos <= priorPos) {
277 B2DEBUG(29,
"The ordering of hits is wrong!");
278 checkResults[1] =
false;
288 B2INFO(
"TCConvertersTestModule initializing Counter variables");
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
@ c_Debug
Debug: for code development.
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
void setDescription(const std::string &description)
Sets the description of the module.
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
Storage for (VXD) SpacePoint-based track candidates.
@ c_omittedClusters
bit 9: Not all Clusters of the genfit::TrackCand have been used to create this SPTC.
bool hasRefereeStatus(unsigned int short bitmask) const
Check if the SpacePointTrackCand has the status characterized by the bitmask.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
int getEntries() const
Get the number of objects in the array.
Type-safe access to single objects in the data store.
std::vector< trackCandHit > getTrackCandHits(const genfit::TrackCand *trackCand)
get all TrackCandHits from a genfit::TrackCand (no such method in genfit)
int m_convertedTCCtr
counter for genfit::TrackCands which where obtained by converting from a SpacePointTrackCand
int m_failedNotSameHits
Counter for failed conversions for which the genfit::TrackCandidates do not contain the same TrackCan...
std::vector< std::string > m_genfitTCNames
Names of genfit::TrackCand Store Arrays.
void initialize() override
initialize: check if all required StoreArrays are present, initialize counters, etc.
unsigned int m_lessHitsCtr
Counter for cases where the original GFTC has less hits than the converted.
void event() override
event: event-wise jobs
int m_failedWrongOrder
Counter for failed conversions due to wrong ordering of TrackCandHits.
std::string m_PXDClusterName
Container name of PXDCluster.
void terminate() override
terminate: print some summary information
int m_failedNoRelationConv
Counter for failed Relation to converted genfit::TrackCand.
TCConvertersTestModule()
constructor
std::tuple< int, int, int, double > trackCandHit
typedef to imitate a genfit::TrackCandHit
int m_failedWrongSortingParam
Counter for failed conversions due to one or more differing sorting parameters.
bool analyzeMisMatch(const genfit::TrackCand *origTC, const genfit::TrackCand *convTC, const Belle2::SpacePointTrackCand *spTC)
analyze why the conversion failed, and check if it can be explained by the referee Status of the SPTC...
int m_SpacePointTCCtr
counter for presented SpacePointTrackCands
unsigned int m_differButOKCtr
Counter for differing GFTCs, where the difference can be assigned to a refereeStatus.
std::string m_SPTCName
Container name of SpacePointTrackCands.
int m_failedOther
Counter for failed conversions for which none of the other stated could be assigned.
int m_failedNoSPTC
counter for conversions where no SpacePointTrackCand was created (i.e.
std::string m_SVDClusterName
Container name of SVDCluster.
int m_failedNoGFTC
counter for conversions where no genfit::TrackCand was created from a SpacePointTrackCand (i....
int m_failedNoRelationOrig
Counter for failed Relation to original genfit::TrackCand.
std::array< bool, 4 > checkHits(const std::vector< trackCandHit > &origHits, const std::vector< trackCandHit > &convHits)
check if the same trackCandHits are contained in both vectors
int m_genfitTCCtr
counter for presented genfit::TrackCands
void initializeCounters()
initialize all counter variables to zero, to avoid indeterministic behaviour
unsigned int m_moreHitsCtr
Counter for cases where the original GFTC has more hits than the converted.
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.