10 #include <tracking/modules/spacePointCreator/TCConvertersTestModule.h>
12 #include <framework/datastore/StoreArray.h>
13 #include <framework/datastore/StoreObjPtr.h>
14 #include <framework/dataobjects/EventMetaData.h>
27 setDescription(
"Module for testing the functionality of the TrackCand converter modules and their underlying classes.");
29 addParam(
"PXDClusters", m_PXDClusterName,
"PXDCluster collection name. WARNING: it is only checked if these exist, "\
30 "they are not actually used at the moment!",
string(
""));
31 addParam(
"SVDClusters", m_SVDClusterName,
"SVDCluster collection name WARNING: it is only checked if these exist, "\
32 " they are not actually used at the moment!",
string(
""));
33 addParam(
"SpacePointTCName", m_SPTCName,
"Name of the container under which SpacePoints are stored in the DataStore",
string(
""));
35 std::vector<std::string> emptyDefaultStringVec = { std::string(
"") };
36 addParam(
"genfitTCNames", m_genfitTCNames,
"Names of containers of genfit::TrackCands. "\
37 "WARNING: For this module provide two names! First is the name of the container with the genfit::TrackCands"\
38 " which were used to create SpacePointTrackCands (e.g. from MCTrackFinderTruth), second are the genfit::TrackCands"\
39 " obtaineed by the 'back conversion' from the SpacePointTrackCands!", emptyDefaultStringVec);
47 B2INFO(
"TCConvertersTest ---------------------------- initialize ------------------ ");
51 for (
string aName : m_genfitTCNames) {
53 TCs.isRequired(aName);
66 const int eventCounter = eventMetaDataPtr->getEvent();
67 B2DEBUG(10,
"TCConvertersTest::event(). Processing event " << eventCounter <<
" --------");
76 int nConvertedTCs = convertedGenfitTCs.
getEntries();
77 int nSpacePointTCs = SpacePointTCs.
getEntries();
79 m_genfitTCCtr += nGenfitTCs;
80 m_convertedTCCtr += nConvertedTCs;
81 m_SpacePointTCCtr += nSpacePointTCs;
83 B2DEBUG(11,
"Found " << nGenfitTCs <<
" genfit::TrackCands, " << nSpacePointTCs <<
" SpacePointTrackCands and " << \
84 nConvertedTCs <<
" genfit::TrackCands created by conversion from a SpacePointTrackCand");
89 m_failedNoSPTC += (nGenfitTCs - nSpacePointTCs);
90 m_failedNoGFTC += (nSpacePointTCs - nConvertedTCs);
94 for (
int iTC = 0; iTC < nSpacePointTCs; ++iTC) {
97 B2DEBUG(20,
"Now comparing genfit::TrackCands related from SpacePointTrackCand " << trackCand->
getArrayIndex() << \
106 if (genfitTC == NULL) {
107 B2DEBUG(50,
"Found no original genfit::TrackCand related from SpacePointTrackCand " << trackCand->
getArrayIndex() << \
109 ++m_failedNoRelationOrig;
112 if (convertedTC == NULL) {
113 B2DEBUG(50,
"Found no converted genfit::TrackCand related from SpacePointTrackCand " << trackCand->
getArrayIndex() << \
115 ++m_failedNoRelationConv;
122 convertedTC->Print();
126 if (*genfitTC == *convertedTC) {
127 B2DEBUG(20,
"The two genfit::TrackCands are equal!");
130 B2DEBUG(20,
"The two genfit::TrackCands differ!");
131 if (analyzeMisMatch(genfitTC, convertedTC, trackCand)) {
132 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!)");
135 B2WARNING(
"Two genfit::TrackCands differ but there is no appearant reason why they should be allowed to do so!");
145 stringstream results;
146 results <<
"There were " << m_failedOther <<
" cases that one should look into and " << \
147 m_differButOKCtr <<
" cases where the failure of the comparison can be explained.";
149 B2INFO(
"TCConverterTest::terminate(): Got " << m_genfitTCCtr <<
" 'original' genfit::TrackCands, " << \
150 m_convertedTCCtr <<
" genfit::TrackCands to compare and " << m_SpacePointTCCtr <<
" SpacePointTrackCands. " << results.str());
152 if (m_failedOther) { B2WARNING(
"There were cases during comparison that need to be looked at!"); }
155 stringstream verbose;
156 verbose << m_lessHitsCtr <<
" times the original GFTC had less hits than the converted" << endl;
157 verbose << m_moreHitsCtr <<
" times the converted GFTC had less hits than the original" << endl;
158 verbose << m_failedWrongSortingParam <<
" times the sorting parameters did not match" << endl;
159 verbose << m_failedWrongOrder <<
" times the hits were contained in the wrong order " << endl;
160 verbose << m_failedNotSameHits <<
" times there were hits in the converted GFTC that were not in the original" << endl;
161 verbose << m_failedNoRelationConv <<
" times there was no related converted GFTC to a SPTC" << endl;
162 verbose << m_failedNoRelationConv <<
" times there was no related original GFTC to a SPTC" << endl;
163 verbose <<
"In " << m_failedNoSPTC <<
" cases the conversion from GFTC -> SPTC went wrong and in ";
164 verbose << m_failedNoGFTC <<
" cases the conversion from SPTC -> GFTC went wrong" << endl;
165 B2DEBUG(1, verbose.str());
174 size_t nOrigHits = origTC->getNHits();
175 size_t nConvHits = convTC->getNHits();
176 bool diffNHits = nOrigHits != nConvHits;
178 B2DEBUG(100,
"The number of hits do not match. original GFTC: " << nOrigHits <<
", converted GFTC: " << nConvHits);
179 if (nOrigHits > nConvHits) m_moreHitsCtr++;
180 else m_lessHitsCtr++;
183 B2WARNING(
"The number of hits does not match but the referee status omittedClusters is not set for the SPTC!");
189 vector<trackCandHit> origHits = getTrackCandHits(origTC);
190 vector<trackCandHit> convHits = getTrackCandHits(convTC);
192 array<bool, 4> foundHits = checkHits(origHits, convHits);
193 B2DEBUG(1999,
"Contents of foundHits: " << get<0>(foundHits) <<
" " << get<1>(foundHits) << \
194 " " << get<2>(foundHits) <<
" " << get<3>(foundHits));
197 B2WARNING(
"Not all hits from the converted GFTC are in the original GFTC!");
198 m_failedNotSameHits++;
202 B2DEBUG(1,
"The hits appear in the wrong order in the converted GFTC compared to the original GFTC!");
203 m_failedWrongOrder++;
206 B2WARNING(
"The sorting parameters are not matching!");
207 m_failedWrongSortingParam++;
217 vector<trackCandHit> tcHits;
218 for (
size_t iHit = 0; iHit < trackCand->getNHits(); ++iHit) {
220 tcHits.push_back(make_tuple(hit->getDetId(), hit->getHitId(), hit->getPlaneId(), hit->getSortingParameter()));
227 const std::vector<trackCandHit>& convHits)
229 std::array<bool, 4> checkResults = {{
true,
true,
true,
true }};
230 typedef vector<trackCandHit>::const_iterator vectorIt;
233 B2DEBUG(499,
"Checking if all hits of converted TC can be found in the original TC!");
234 stringstream allHitsOut;
236 allHitsOut << get<0>(hit) <<
"\t" << get<1>(hit) <<
"\t" << get<2>(hit) <<
"\t" << get<3>(hit) << endl;
238 B2DEBUG(499,
"Hits of original TC:\ndetId\thitId\tplaneId\tsort.Param:\n" << allHitsOut.str());
240 for (
size_t iHit = 0; iHit < convHits.size(); ++iHit) {
244 hitOut <<
"Checking hit " << get<0>(hit) <<
" " << get<1>(hit) <<
" " << get<2>(hit) <<
" " << get<3>(hit) <<
" -> ";
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:" << 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 " << 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!" << endl;
257 checkResults[3] =
false;
259 if (foundNoPlaneIdIt == origHits.end()) {
260 hitOut <<
" the planeIDs are not matching!" << endl;
261 checkResults[2] =
false;
264 hitOut <<
" hit is not contained in origHits!" << endl;
265 checkResults[0] =
false;
269 pos = foundIt - origHits.begin();
270 hitOut <<
" hit found at position " << pos << endl;
272 B2DEBUG(499, hitOut.str());
273 B2DEBUG(499,
"This hit appears in position " << pos <<
" in the original TC " <<
" the last checked hit was on position " <<
276 if (pos <= priorPos) {
277 B2DEBUG(499,
"The ordering of hits is wrong!");
278 checkResults[1] =
false;
288 B2INFO(
"TCConvertersTestModule initializing Counter variables");
290 m_SpacePointTCCtr = 0;
291 m_convertedTCCtr = 0;
295 m_failedNotSameHits = 0;
296 m_failedWrongOrder = 0;
297 m_failedWrongSortingParam = 0;
298 m_failedNoRelationOrig = 0;
299 m_failedNoRelationConv = 0;
303 m_differButOKCtr = 0;