16 #include "GaudiKernel/TypeNameString.h"
17 #include "GaudiKernel/ITHistSvc.h"
43 m_compareOutliers(true),
46 m_writeCompetingROT(false),
59 m_driftCircleSignFlips{},
70 m_compIsMeasurement{},
84 m_PRD_MismatchesSum{},
86 declareInterface<ITrackDiff>(
this);
89 declareProperty(
"NtupleFileName", m_ntupleFileName =
"/NTUPLES");
90 declareProperty(
"NtupleDirectoryName", m_ntupleDirName =
"TrackValidation");
91 declareProperty(
"NtupleTreeName", m_ntupleTreeName =
"TrackDiff");
93 declareProperty(
"CompareOutliers", m_compareOutliers =
true);
94 declareProperty(
"CompareAllTSoS", m_compareAll =
false);
95 declareProperty(
"WriteNtuple", m_writeNtuple =
true);
96 declareProperty(
"WriteCompetingROTdata",m_writeCompetingROT =
false);
113 SmartIF<ITHistSvc> tHistSvc{service(
"THistSvc")};
118 m_nt =
new TTree(TString(m_ntupleTreeName),
"Track diff output");
120 std::string fullNtupleName =
"/"+m_ntupleFileName+
"/"+m_ntupleDirName+
"/"+m_ntupleTreeName;
121 ATH_CHECK( tHistSvc->regTree(fullNtupleName, m_nt) );
126 m_nt->Branch(
"EventNumber", &m_eventNumber );
127 m_nt->Branch(
"RefTrackPhi0", &m_trackPhi );
128 m_nt->Branch(
"RefTrackEta0", &m_trackEta );
130 m_nt->Branch(
"nRefStates", &m_nRefStates,
"nRefStates[8]/I");
131 m_nt->Branch(
"nCompareStates", &m_nCompStates,
"nRefStates[8]/I");
132 m_nt->Branch(
"nFakeStates", &m_fakes,
"nFakeStates[8]/I");
133 m_nt->Branch(
"nMissedStates", &m_missed,
"nMissedStates[8]/I");
134 m_nt->Branch(
"nWrongType", &m_wrongType,
"nWrongType[8]/I");
135 m_nt->Branch(
"nPRD_Mismatches", &m_PRD_Mismatches,
"nPRD_Mismatches[8]/I");
136 m_nt->Branch(
"nDriftCircleSignFlips", &m_driftCircleSignFlips );
137 m_nt->Branch(
"nNoDriftTime", &m_noDriftTime );
138 m_nt->Branch(
"nRefTypes", &m_refType,
"nRefTypes[8]/I");
139 m_nt->Branch(
"nCompareTypes", &m_compareType,
"nCompareTypes[8]/I");
140 m_nt->Branch(
"nMissedTypes", &m_missingType,
"nMissedTypes[8]/I");
141 m_nt->Branch(
"nFakeTypes", &m_fakeType,
"nFakeTypes[8]/I");
143 m_nt->Branch(
"nDiffs", &m_nDiffs );
144 m_detectorType =
new std::vector<int>();
145 m_isFake =
new std::vector<int>();
146 m_isMissing =
new std::vector<int>();
147 m_isPRD_Mismatch =
new std::vector<int>();
148 m_isFlippedSign =
new std::vector<int>();
149 m_isNoDriftTime =
new std::vector<int>();
150 m_refIsMeasurement =
new std::vector<int>();
151 m_refIsOutlier =
new std::vector<int>();
152 m_compIsMeasurement =
new std::vector<int>();
153 m_compIsOutlier =
new std::vector<int>();
154 m_surfX =
new std::vector<float>();
155 m_surfY =
new std::vector<float>();
156 m_surfZ =
new std::vector<float>();
158 m_nt->Branch(
"DetectorType", &m_detectorType);
159 m_nt->Branch(
"IsFake", &m_isFake);
160 m_nt->Branch(
"IsMissing", &m_isMissing);
161 m_nt->Branch(
"IsPRD_Mismatch", &m_isPRD_Mismatch);
162 m_nt->Branch(
"IsFlippedSign", &m_isFlippedSign);
163 m_nt->Branch(
"IsNoDriftTime", &m_isNoDriftTime);
164 m_nt->Branch(
"RefIsMeasurement", &m_refIsMeasurement);
165 m_nt->Branch(
"RefIsOutlier", &m_refIsOutlier);
166 m_nt->Branch(
"ComparedIsMeasurement", &m_compIsMeasurement);
167 m_nt->Branch(
"ComparedIsOutlier", &m_compIsOutlier);
168 m_nt->Branch(
"SurfaceX" , &m_surfX);
169 m_nt->Branch(
"SurfaceY" , &m_surfY);
170 m_nt->Branch(
"SurfaceZ" , &m_surfZ);
172 if (m_writeCompetingROT) {
173 m_maxAssignProb =
new std::vector<float>();
174 m_sumAssignProb =
new std::vector<float>();
175 m_nt->Branch(
"MaxAssgnProb", &m_maxAssignProb);
176 m_nt->Branch(
"SumAssgnProb", &m_sumAssignProb);
183 return StatusCode::FAILURE;
187 m_fakesSum[detType] = 0;
188 m_missedSum[detType] = 0;
189 m_PRD_MismatchesSum[detType] = 0;
190 m_nRefStatesSum[detType] = 0;
191 m_nCompStatesSum[detType] = 0;
192 m_wrongTypeSum[detType] = 0;
193 m_fakes[detType] = 0;
194 m_missed[detType] = 0;
195 m_PRD_Mismatches[detType] = 0;
196 m_nRefStates[detType] = 0;
197 m_nCompStates[detType] = 0;
198 m_wrongType[detType] = 0;
201 return StatusCode::SUCCESS;
208 ATH_MSG_INFO (
"sums for " << m_trackSum <<
" compared tracks" );
217 return StatusCode::SUCCESS;
233 if (!
evt.isValid()) {
235 return StatusCode::FAILURE;
238 m_eventNumber =
evt->eventNumber();
253 refTrackStateData = extractDataFromTrack(referenceTrack);
254 compareTrackStateData = extractDataFromTrack(comparedTrack);
256 ATH_MSG_VERBOSE (
"number of track states: ref=" << refTrackStateData->
size() <<
", compare=" << compareTrackStateData->
size() );
257 ATH_MSG_VERBOSE (
"reference track: eta_0 = " << m_trackEta <<
", phi_0 = " << m_trackPhi );
265 for (; refIter != refTrackStateData->
end(); ++refIter) {
270 bool foundMatchingState =
false;
274 if ((*refIter)->rot()) {
275 refPRD = (*refIter)->rot()->prepRawData();
277 compIter = compareTrackStateData->
begin();
278 for ( ; compIter != compareTrackStateData->
end(); ++compIter ) {
280 if ( (*compIter)->surface() == (*refIter)->surface() ) {
282 foundMatchingState =
true;
290 }
else if ( refPRD && (*compIter)->rot() ) {
294 if ( refPRD == ((*compIter)->rot()->prepRawData()) ) {
296 foundMatchingState =
true;
304 if (!foundMatchingState) {
307 diffStateInfo((*refIter),
nullptr);
309 diffStateInfo((*refIter), (*compIter));
311 compareTrackStateData->
erase(compIter);
317 compIter = compareTrackStateData->
begin();
318 for (; compIter != compareTrackStateData->
end(); ++compIter) {
319 diffStateInfo(
nullptr, (*compIter));
339 delete refTrackStateData;
340 delete compareTrackStateData;
341 return StatusCode::SUCCESS;
350 ATH_MSG_ERROR (
"track containes no track states, diff impossible" );
361 for (; iter != trackStates->
end(); ++iter) {
368 if (m_compareOutliers) {
382 if (!measurement && !m_compareAll) {
383 ATH_MSG_ERROR (
"measurementOnTrack == Null for a TrackStateOnSurface "
384 <<
"of type Measurement or Outlier" );
407 if ( !ROT && !m_compareAll ) {
411 std::string detTypeName =
"unidentified";
414 detType = detectorType(*ROT, detTypeName);
426 return trackStateData;
435 m_driftCircleSignFlips = 0;
439 m_fakesSum[detType] += m_fakes[detType];
440 m_fakes[detType] = 0;
441 m_missedSum[detType] += m_missed[detType];
442 m_missed[detType] = 0;
443 m_PRD_MismatchesSum[detType] += m_PRD_Mismatches[detType];
444 m_PRD_Mismatches[detType] = 0;
445 m_nRefStatesSum[detType] += m_nRefStates[detType];
446 m_nRefStates[detType] = 0;
447 m_nCompStatesSum[detType] += m_nCompStates[detType];
448 m_nCompStates[detType] = 0;
449 m_wrongType[detType] += m_wrongType[detType];
450 m_wrongType[detType] = 0;
453 m_missingType[TSoSType] = 0;
454 m_fakeType[TSoSType] = 0;
455 m_refType[TSoSType] = 0;
456 m_compareType[TSoSType] = 0;
465 m_detectorType->clear();
467 m_isMissing->clear();
468 m_isPRD_Mismatch->clear();
469 m_isFlippedSign->clear();
470 m_isNoDriftTime->clear();
471 m_refIsMeasurement->clear();
472 m_refIsOutlier->clear();
473 m_compIsMeasurement->clear();
474 m_compIsOutlier->clear();
479 if (m_writeCompetingROT) {
480 m_maxAssignProb->clear();
481 m_sumAssignProb->clear();
489 std::string &detTypeName )
const {
494 if (
id.is_valid()) {
495 if (m_idHelper->is_pixel(
id) ) {
496 detTypeName =
"Pixel";
498 }
else if (m_idHelper->is_sct(
id)) {
501 }
else if (m_idHelper->is_trt(
id)) {
504 }
else if (m_idHelper->is_mdt(
id)) {
507 }
else if (m_idHelper->is_csc(
id)) {
510 }
else if (m_idHelper->is_rpc(
id)) {
513 }
else if (m_idHelper->is_tgc(
id)) {
518 detTypeName =
"unidentified";
526 bool foundDiff =
false;
529 bool isMissing =
false;
530 bool isPRD_Mismatch =
false;
531 bool isFlippedSign =
false;
532 bool isNoDriftTime =
false;
533 bool refIsMeasurement =
false;
534 bool refIsOutlier =
false;
535 bool compIsMeasurement =
false;
536 bool compIsOutlier =
false;
537 bool wrongType =
false;
538 std::string detTypeName =
"unidentified";
548 if (!compareTrackState) {
552 m_missed[ refTrackState->
detType() ]++;
555 m_nRefStates[ refTrackState->
detType() ]++;
556 detType = refTrackState->
detType();
563 m_fakes[ compareTrackState->
detType() ]++;
564 detType = compareTrackState->
detType();
567 if (compareTrackState){
571 m_nCompStates[ compareTrackState->
detType() ]++;
575 if (refTrackState && compareTrackState) {
581 if (m_compareOutliers && (refIsOutlier != compIsOutlier)) {
590 if (refIsMeasurement != compIsMeasurement ) {
593 if (refIsMeasurement) {
604 if (refROT && compareROT) {
606 isPRD_Mismatch =
true;
607 (m_PRD_Mismatches[detType])++;
611 if (isFlippedSign) m_driftCircleSignFlips++;
613 if (isNoDriftTime) m_noDriftTime++;
615 foundDiff = (foundDiff || isPRD_Mismatch || isFlippedSign || isNoDriftTime );
625 else {
msg(
MSG::DEBUG) << (refIsOutlier ?
" O" :
" ") << (refIsMeasurement ?
"M " :
" ");}
627 else {
msg(
MSG::DEBUG) << (compIsOutlier ?
" O" :
" ") << (compIsMeasurement ?
"M " :
" ");}
629 << (isMissing ?
" MissingState " :
"")
630 << (wrongType ?
" Wrong TSoS type" :
"")
631 << (isPRD_Mismatch ?
" PRD mismatch " :
"")
632 << (isFlippedSign ?
" Flipped Sign " :
"")
633 << (isNoDriftTime ?
" NoDriftTime " :
"")
634 <<
" in " << detTypeName
635 <<
" detector at surface with center " <<
endmsg;
645 ATH_MSG_DEBUG (
"(" << surfX <<
", " << surfY <<
"," << surfZ <<
")");
647 if (m_writeCompetingROT) {
649 float maxAssgnProb = -1.;
650 float sumAssgnProb = -1.;
651 if (compareTrackState) {
662 m_maxAssignProb->push_back(maxAssgnProb);
663 m_sumAssignProb->push_back(sumAssgnProb);
667 m_isFake->push_back(
isFake?1:0);
668 m_isMissing->push_back(isMissing?1:0);
669 m_detectorType->push_back(detType);
670 m_isPRD_Mismatch->push_back(isPRD_Mismatch?1:0);
671 m_isFlippedSign->push_back(isFlippedSign?1:0);
672 m_isNoDriftTime->push_back(isNoDriftTime?1:0);
673 m_refIsOutlier->push_back(refIsOutlier?1:0);
674 m_refIsMeasurement->push_back(refIsMeasurement?1:0);
675 m_compIsOutlier->push_back(compIsOutlier?1:0);
676 m_compIsMeasurement->push_back(compIsMeasurement?1:0);
677 m_surfX->push_back(surfX);
678 m_surfY->push_back(surfY);
679 m_surfZ->push_back(surfZ);