49 m_trtcaldbTool(
"TRT_CalDbTool", this),
50 m_iUpdator (
"Trk::KalmanUpdator"),
51 m_propagator (
"Trk::RungeKuttaPropagator"),
52 m_residualPullCalculator(
"Trk::ResidualPullCalculator/ResidualPullCalculator"),
53 m_trackSelection(
"InDet::InDetTrackSelectionTool/TrackSelectionTool", this),
74 ATH_MSG_DEBUG(
"Calling initialize() to setup tools/services");
78 return StatusCode::SUCCESS;
153 auto residualGroup =
getGroup(
"Residuals");
156 bool hasBeenCalledThisEvent=
false;
162 if (!hasBeenCalledThisEvent){
165 hasBeenCalledThisEvent=
true;
171 fill(
"residualGroup", mu_m);
176 if (not tracks.isValid()) {
178 return StatusCode::RECOVERABLE;
182 ATH_MSG_DEBUG (
"IDAlignMonResidual: Start loop on tracks. Number of tracks " << tracks->size());
186 if ( !trksItr || trksItr->perigeeParameters() ==
nullptr ) {
187 ATH_MSG_DEBUG(
"InDetAlignmentMonitoringRun3: NULL track pointer in collection" );
199 ATH_MSG_DEBUG(
"Not all TSOS contain track parameters - will be missing residuals/pulls");
202 ATH_MSG_DEBUG(
"All TSOS of track " << nTracks <<
"/" << tracks->size() <<
" contain track parameters - Good!");
206 ATH_MSG_DEBUG(
"** IDAlignMonResiduals::fillHistograms() ** track: " << nTracks <<
" has " << trksItr->trackStateOnSurfaces()->size() <<
" TrkSurfaces");
216 if (tsos ==
nullptr) {
222 ATH_MSG_DEBUG(
" --> testing if hit " << nTSOS <<
"/" << trksItr->trackStateOnSurfaces()->size() <<
" is a track measurement");
224 ATH_MSG_DEBUG(
"Skipping TSOS " << nTSOS <<
" because it is an outlier (or the first TSOS on the track)");
229 ATH_MSG_DEBUG(
" --> Defined hit measurementOnTrack() for hit: " << nTSOS <<
"/" << trksItr->trackStateOnSurfaces()->size() <<
" of track " << nTracks);
233 ATH_MSG_DEBUG(
" --> Going to retrive the Trk::RIO_OnTrack for hit " << nTSOS);
236 if (nHits >0)
ATH_MSG_DEBUG(
"No hit associated with TSOS " << nTSOS);
240 ATH_MSG_DEBUG(
" --> Going to retrive the track parameters of this TSOS: " << nTSOS);
242 if(trackParameter==
nullptr) {
244 ATH_MSG_DEBUG(
" Skipping TSOS " << nTSOS <<
" because it does not have TrackParameters");
248 const AmgSymMatrix(5)* TrackParCovariance = trackParameter ? trackParameter->covariance() :
nullptr;
250 if(TrackParCovariance==
nullptr) {
253 ATH_MSG_DEBUG(
"Skipping TSOS " << nTSOS <<
" because does not have MeasuredTrackParameters");
258 " --> going to define residuals and everything of TSOS #" << nTSOS <<
"/" <<
259 trksItr->trackStateOnSurfaces()->size());
261 float residualX = 9999.0;
262 float residualY = 9999.0;
263 float pullX = 9999.0;
264 float pullY = 9999.0;
265 float biasedResidualX = 9999.0;
266 float biasedResidualY = 9999.0;
281 if ( detType == 99) {
282 ATH_MSG_DEBUG(
" --> Hit " << nTSOS <<
" with detector type " << detType <<
" is not an Inner Detector hit -> skip this hit");
288 ATH_MSG_DEBUG(
"** IDAlignMonResidualsAlg::fillHistograms() ** Hit is from the TRT, finding residuals... ");
292 if (!trackParameter) {
293 ATH_MSG_WARNING(
"No TrackParameters associated with TRT TrkSurface " << nTSOS);
297 float trketa = tsos->trackParameters()->eta();
306 ATH_MSG_DEBUG(
"Found Trk::TrackParameters for hit " << nTSOS <<
" --> TRT hit (detType= " << detType <<
")" );
312 if (!trackParameterUnbiased) {
313 ATH_MSG_WARNING(
"Cannot define unbiased parameters for hit, skipping it.");
316 ATH_MSG_DEBUG(
" --> TRT UnBiased TrackParameters of hit " << nTSOS <<
" FOUND");
318 float predictR = trackParameterUnbiased->parameters()[
Trk::locR];
321 std::optional<Trk::ResidualPull> residualPull =
323 trackParameterUnbiased.get(),
330 ATH_MSG_DEBUG(
" no covariance of the track parameters given, can not calculate pull!");
335 float residualR = hitR - predictR;
340 if (trtCircle !=
nullptr) {
341 ATH_MSG_DEBUG(
" fillHistograms() ** filling TRT histograms for hit/tsos #" << nTSOS
342 <<
" Barrel/EndCap: " << barrel_ec
343 <<
" layer/wheel: " << layer_or_wheel
344 <<
" phi: " << phi_module
345 <<
" Residual: " << residualR);
361 ATH_MSG_DEBUG(
"applying hit quality cuts to Silicon hit...");
369 else ATH_MSG_DEBUG(
"hit quality cuts NOT APPLIED to Silicon hit.");
391 ATH_MSG_DEBUG(
"Found Trk::TrackParameters " << trackParameter);
393 double unbiasedResXY[4] = {9999.0,9999.0,9999.0,9999.0};
394 double biasedResXY[4] = {9999.0,9999.0,9999.0,9999.0};
399 if (
sc.isFailure()) {
400 ATH_MSG_DEBUG(
"Problem in determining unbiased residuals! Hit is skipped.");
402 fill(residualGroup, detType_m);
408 residualX = (
float)unbiasedResXY[0];
409 residualY = (
float)unbiasedResXY[1];
410 pullX = (
float)unbiasedResXY[2];
411 pullY = (
float)unbiasedResXY[3];
415 if (
sc.isFailure()) {
416 ATH_MSG_DEBUG(
"Problem in determining biased residuals! Hit is skipped.");
422 biasedResidualX = (
float)biasedResXY[0];
423 biasedResidualY = (
float)biasedResXY[1];
427 ATH_MSG_DEBUG(
"No TrackParameters associated with Si TrkSurface "<< nTSOS <<
" - Hit is probably an outlier");
462 ATH_MSG_DEBUG(
" This is a PIXEL hit " << hitId <<
" - filling histograms");
464 si_residualx_m = residualX;
465 fill(residualGroup, si_residualx_m);
468 int ModEtaShift[4] = {0, 30, 53, 76};
469 int ModPhiShift[4] = {0, 24, 56, 104};
472 si_b_residualx_m = residualX;
473 fill(residualGroup, si_b_residualx_m);
475 layerDisk_si_m = layerDisk;
476 si_barrel_resX_m = residualX;
477 si_barrel_resY_m = residualY;
478 si_barrel_pullX_m = pullX;
479 si_barrel_pullY_m = pullY;
480 fill(residualGroup, layerDisk_si_m, si_barrel_resX_m, si_barrel_resY_m, si_barrel_pullX_m, si_barrel_pullY_m);
487 fill(residualGroup, pix_b_residualx_m, pix_b_biased_residualx_m, pix_b_residualy_m, pix_b_biased_residualy_m);
507 auto modPhiShift_barrel_m =
Monitored::Scalar<int>(
"m_modPhiShift_barrel", modPhi + ModPhiShift[layerDisk] );
508 auto modEtaShift_barrel_m =
Monitored::Scalar<int>(
"m_modEtaShift_barrel", modEta + ModEtaShift[layerDisk] );
509 fill(residualGroup, modPhiShift_barrel_m, residualX_barrel_m, residualY_barrel_m);
510 fill(residualGroup, modEtaShift_barrel_m, residualX_barrel_m, residualY_barrel_m);
512 else if(barrelEC==2){
513 int ModPhiShift[3] = {0, 55, 110};
516 layerDisk_si_m = layerDisk;
517 si_eca_resX_m = residualX;
518 si_eca_resY_m = residualY;
519 si_eca_pullX_m = pullX;
520 si_eca_pullY_m = pullY;
521 fill(residualGroup, layerDisk_si_m, si_eca_resX_m, si_eca_resY_m, si_eca_pullX_m, si_eca_pullY_m);
529 fill(residualGroup, pix_eca_residualx_m, pix_eca_residualy_m);
533 fill(residualGroup, pix_eca_pullx_m, pix_eca_pully_m);
541 fill(residualGroup, modPhiShift_eca_m, residualX_eca_m, residualY_eca_m);
543 else if(barrelEC==-2){
544 int ModPhiShift[3] = {0, 55, 110};
547 layerDisk_si_m = layerDisk;
548 si_ecc_resX_m = residualX;
549 si_ecc_resY_m = residualY;
550 si_ecc_pullX_m = pullX;
551 si_ecc_pullY_m = pullY;
552 fill(residualGroup, layerDisk_si_m, si_ecc_resX_m, si_ecc_resY_m, si_ecc_pullX_m, si_ecc_pullY_m);
560 fill(residualGroup, pix_ecc_residualx_m, pix_ecc_residualy_m);
564 fill(residualGroup, pix_ecc_pullx_m, pix_ecc_pully_m);
572 fill(residualGroup, modPhiShift_ecc_m, residualX_ecc_m, residualY_ecc_m);
575 else if (detType==1) {
576 si_residualx_m = residualX;
577 fill(residualGroup, si_residualx_m);
579 ATH_MSG_DEBUG(
" This is a SCT hit " << hitId <<
" - filling histograms");
582 int ModPhiShift[4] = {0, 42, 92, 150};
583 int ModEtaShift[4] = {0, 23, 46, 69};
586 si_b_residualx_m = residualX;
587 fill(residualGroup, si_b_residualx_m);
589 layerDisk_si_m = 4 + 2 * layerDisk + sctSide;
590 si_barrel_resX_m = residualX;
591 si_barrel_pullX_m = pullX;
592 fill(residualGroup, layerDisk_si_m, si_barrel_resX_m, si_barrel_pullX_m);
596 fill(residualGroup, sct_b_residualx_m);
614 auto modPhiShift_sct_barrel_m =
Monitored::Scalar<int>(
"m_modPhiShift_sct_barrel", modPhi + ModPhiShift[layerDisk] );
615 auto modEtaShift_sct_barrel_m =
Monitored::Scalar<int>(
"m_modEtaShift_sct_barrel", modEta + ModEtaShift[layerDisk] );
616 fill(residualGroup, modPhiShift_sct_barrel_m, modEtaShift_sct_barrel_m, residualX_sct_barrel_m);
619 else if(barrelEC==2){
624 layerDisk_si_m = 3 + 2 * layerDisk + sctSide;
625 si_eca_resX_m = residualX;
626 si_eca_pullX_m = pullX;
627 fill(residualGroup, layerDisk_si_m, si_eca_resX_m, si_eca_pullX_m);
633 fill(residualGroup, sct_eca_residualx_m, sct_eca_pullx_m);
642 auto modPhiShift_sct_eca_m =
Monitored::Scalar<int>(
"m_modPhiShift_sct_eca", modPhi + layerDisk * (gap_sct + Nmods) );
643 fill(residualGroup, modPhiShift_sct_eca_m, residualX_sct_eca_m);
646 else if(barrelEC==-2){
651 layerDisk_si_m = 3 + 2 * layerDisk + sctSide;
652 si_ecc_resX_m = residualX;
653 si_ecc_pullX_m = pullX;
654 fill(residualGroup, layerDisk_si_m, si_ecc_resX_m, si_ecc_pullX_m);
660 fill(residualGroup, sct_ecc_residualx_m, sct_ecc_pullx_m);
669 auto modPhiShift_sct_ecc_m =
Monitored::Scalar<int>(
"m_modPhiShift_sct_ecc", modPhi + layerDisk * (gap_sct + Nmods) );
670 fill(residualGroup, modPhiShift_sct_ecc_m, residualX_sct_ecc_m);
680 return StatusCode::SUCCESS;
686 if (!
m_doPulls)
return StatusCode::FAILURE;
690 double residualX = -9999.0;
691 double residualY = -9999.0;
692 double pullX = -9999.0;
693 double pullY = -9999.0;
700 std::unique_ptr <Trk::TrackParameters> trackParameterUnbiased{};
704 std::unique_ptr <Trk::TrackParameters> trackParameterForResiduals{};
705 if(trackParameterUnbiased){
706 trackParameterForResiduals = std:: move(trackParameterUnbiased);
711 trackParameterForResiduals = std::move(uTrkPtr);
716 if (hit && trackParameterForResiduals) {
720 std::optional<Trk::ResidualPull> residualPull = std::nullopt;
728 residualX = residualPull->residual()[
Trk::loc1];
729 if(residualPull->isPullValid()) pullX = residualPull->pull()[
Trk::loc1];
731 ATH_MSG_DEBUG(
"ResidualPullCalculator finds invalid X Pull!!!");
732 sc = StatusCode::FAILURE;
735 if (residualPull->dimension() >= 2){
738 residualY = residualPull->residual()[
Trk::loc2];
741 if(residualPull->isPullValid()) pullY = residualPull->pull()[
Trk::loc2];
743 ATH_MSG_DEBUG(
"ResidualPullCalculator finds invalid Y Pull!!!");
744 sc = StatusCode::FAILURE;
750 sc = StatusCode::FAILURE;
764 if(pullX!=pullX || pullY!=pullY){
766 sc = StatusCode::FAILURE;
775 bool LRcorrect = (predictR * hitR > 0);
778 if (barrel_ec == -1) {
782 if (barrel_ec == 1 || barrel_ec == -1)
795 if (barrel_ec == 2 || barrel_ec == -2)
816 else if (
side == 1 && barrel_ec == 1)
doFill =
true;
817 else if (
side == 2 && barrel_ec == -1)
doFill =
true;
838 if (LRcorrect && !isTubeHit) trt_b_lr_m = 0.5;
839 if (LRcorrect && isTubeHit) trt_b_lr_m = 1.5;
840 if (!LRcorrect && !isTubeHit) trt_b_lr_m = 2.5;
841 if (!LRcorrect && isTubeHit) trt_b_lr_m = 3.5;
849 trt_b_lrVsPhiSec_m = LRcorrect;
858 for (
unsigned int endcap = 0; endcap < 2; ++endcap) {
860 if (!endcap && barrel_ec == 2)
doFill =
true;
861 else if (endcap && barrel_ec == -2)
doFill =
true;
882 if (LRcorrect && !isTubeHit) trt_ec_lr_m = 0.5;
883 else if (LRcorrect && isTubeHit) trt_ec_lr_m = 1.5;
884 else if (!LRcorrect && !isTubeHit) trt_ec_lr_m = 2.5;
885 else if (!LRcorrect && isTubeHit) trt_ec_lr_m = 3.5;
904 std::unique_ptr <Trk::TrackParameters> TrackParams{};
905 std::unique_ptr <Trk::TrackParameters> UnbiasedTrackParams{};
906 std::unique_ptr <Trk::TrackParameters> PropagatedTrackParams{};
907 std::unique_ptr <Trk::TrackParameters> OtherSideUnbiasedTrackParams{};
910 bool trueUnbiased =
true;
920 if (hitOnTrack !=
nullptr) surfaceID = hitOnTrack->
identify();
924 if (surfaceID.is_valid() && trueUnbiased &&
m_idHelper->
is_sct(surfaceID)) {
931 IdentifierHash otherSideHash;
938 if (TempHitOnTrack !=
nullptr) {
941 OtherModuleSideHit = TempTsos;
946 if (OtherModuleSideHit) {
948 const AmgSymMatrix(5)* OMSHmeasuredTrackParameterCov = OMSHmeasuredTrackParameter ? OMSHmeasuredTrackParameter->covariance() :
nullptr;
951 if (OMSHmeasuredTrackParameterCov) {
957 if (OtherSideUnbiasedTrackParams) {
958 ATH_MSG_VERBOSE(
"Unbiased OtherSideTrackParameters: " << *OtherSideUnbiasedTrackParams);
972 ATH_MSG_VERBOSE(
"TempSurface->associatedLayer()->enclosingTrackingVolume exists");
979 Gaudi::Hive::currentContext(),
980 *OtherSideUnbiasedTrackParams,
987 ATH_MSG_VERBOSE(
"TempSurface->associatedLayer()->enclosingTrackingVolume does not exist");
993 ATH_MSG_VERBOSE(
"After OtherSide surface call. Surface does not exist");
997 if (PropagatedTrackParams) {
998 ATH_MSG_VERBOSE(
"Propagated Track Parameters: " << *PropagatedTrackParams);
1000 ATH_MSG_DEBUG(
"Propagation of unbiased OtherSideParameters failed");
1003 ATH_MSG_DEBUG(
"RemoveFromState did not work for OtherSideParameters");
1006 ATH_MSG_VERBOSE(
"No OtherModuleSideHit Measured Track Parameters found");
1014 if (!PropagatedTrackParams) {
1016 PropagatedTrackParams = std::move(uTrkPtr);
1019 UnbiasedTrackParams =
1021 ->removeFromState(*PropagatedTrackParams,
1025 if (UnbiasedTrackParams) {
1027 ATH_MSG_VERBOSE(
"Unbiased Trackparameters: " << *UnbiasedTrackParams);
1029 TrackParams = std::move(UnbiasedTrackParams);
1032 ATH_MSG_WARNING(
"RemoveFromState did not work, using original TrackParameters");
1035 TrackParams = std::move(uTrkPtr);
1075 return StatusCode::FAILURE;
1080 return StatusCode::FAILURE;
1084 ATH_MSG_DEBUG(
"No residual/pull calculator for general hit residuals configured.");
1085 ATH_MSG_DEBUG(
"It is recommended to give R/P calculators to the det-specific tool handle lists then.");
1093 ATH_MSG_DEBUG(
"Generic hit residuals&pulls will be calculated in one or both available local coordinates");
1098 ATH_MSG_DEBUG(
"No hit quality tool configured - not hit quality cuts will be imposed");
1105 ATH_MSG_DEBUG(
"Hit quality tool setup - hit quality cuts will be applied to Si hits");
1110 return StatusCode::SUCCESS;
1124 int nHitsNoParams = 0;
1130 if(tsos ==
nullptr)
continue;
1136 if (mesh==
nullptr)
continue;
1138 if (hit==
nullptr)
continue;
1143 if(trackParameter==
nullptr) ++nHitsNoParams;
1147 ATH_MSG_DEBUG(
"Total nhits on track (excluding outliers) = " << nHits <<
", nhits without trackparameters = " << nHitsNoParams);
1149 if(nHitsNoParams>0) {