49 m_trtcaldbTool(
"TRT_CalDbTool", this),
50 m_trackSelection(
"InDet::InDetTrackSelectionTool/TrackSelectionTool", this),
51 m_extendedPlots(false)
53 m_iUpdator = ToolHandle<Trk::IUpdator>(
"Trk::KalmanUpdator");
54 m_propagator = ToolHandle<Trk::IPropagator>(
"Trk::RungeKuttaPropagator");
56 "Trk::ResidualPullCalculator/ResidualPullCalculator");
78 ATH_MSG_DEBUG(
"Calling initialize() to setup tools/services");
82 return StatusCode::SUCCESS;
151 auto residualGroup =
getGroup(
"Residuals");
154 bool hasBeenCalledThisEvent=
false;
160 if (!hasBeenCalledThisEvent){
163 hasBeenCalledThisEvent=
true;
169 fill(
"residualGroup", mu_m);
174 if (not tracks.isValid()) {
176 return StatusCode::RECOVERABLE;
180 ATH_MSG_DEBUG (
"IDAlignMonResidual: Start loop on tracks. Number of tracks " << tracks->size());
184 if ( !trksItr || trksItr->perigeeParameters() ==
nullptr ) {
185 ATH_MSG_DEBUG(
"InDetAlignmentMonitoringRun3: NULL track pointer in collection" );
197 ATH_MSG_DEBUG(
"Not all TSOS contain track parameters - will be missing residuals/pulls");
200 ATH_MSG_DEBUG(
"All TSOS of track " << nTracks <<
"/" << tracks->size() <<
" contain track parameters - Good!");
204 ATH_MSG_DEBUG(
"** IDAlignMonResiduals::fillHistograms() ** track: " << nTracks <<
" has " << trksItr->trackStateOnSurfaces()->size() <<
" TrkSurfaces");
214 if (tsos ==
nullptr) {
220 ATH_MSG_DEBUG(
" --> testing if hit " << nTSOS <<
"/" << trksItr->trackStateOnSurfaces()->size() <<
" is a track measurement");
222 ATH_MSG_DEBUG(
"Skipping TSOS " << nTSOS <<
" because it is an outlier (or the first TSOS on the track)");
227 ATH_MSG_DEBUG(
" --> Defined hit measurementOnTrack() for hit: " << nTSOS <<
"/" << trksItr->trackStateOnSurfaces()->size() <<
" of track " << nTracks);
231 ATH_MSG_DEBUG(
" --> Going to retrive the Trk::RIO_OnTrack for hit " << nTSOS);
234 if (nHits >0)
ATH_MSG_DEBUG(
"No hit associated with TSOS " << nTSOS);
238 ATH_MSG_DEBUG(
" --> Going to retrive the track parameters of this TSOS: " << nTSOS);
240 if(trackParameter==
nullptr) {
242 ATH_MSG_DEBUG(
" Skipping TSOS " << nTSOS <<
" because it does not have TrackParameters");
246 const AmgSymMatrix(5)* TrackParCovariance = trackParameter ? trackParameter->covariance() :
nullptr;
248 if(TrackParCovariance==
nullptr) {
251 ATH_MSG_DEBUG(
"Skipping TSOS " << nTSOS <<
" because does not have MeasuredTrackParameters");
256 " --> going to define residuals and everything of TSOS #" << nTSOS <<
"/" <<
257 trksItr->trackStateOnSurfaces()->size());
259 float residualX = 9999.0;
260 float residualY = 9999.0;
261 float pullX = 9999.0;
262 float pullY = 9999.0;
263 float biasedResidualX = 9999.0;
264 float biasedResidualY = 9999.0;
272 const Identifier & hitId = hit->
identify();
279 if ( detType == 99) {
280 ATH_MSG_DEBUG(
" --> Hit " << nTSOS <<
" with detector type " << detType <<
" is not an Inner Detector hit -> skip this hit");
286 ATH_MSG_DEBUG(
"** IDAlignMonResidualsAlg::fillHistograms() ** Hit is from the TRT, finding residuals... ");
290 float trketa = tsos->trackParameters()->eta();
299 if (!trackParameter) {
300 ATH_MSG_WARNING(
"No TrackParameters associated with TRT TrkSurface " << nTSOS);
303 ATH_MSG_DEBUG(
"Found Trk::TrackParameters for hit " << nTSOS <<
" --> TRT hit (detType= " << detType <<
")" );
309 if (!trackParameterUnbiased) {
310 ATH_MSG_WARNING(
"Cannot define unbiased parameters for hit, skipping it.");
313 ATH_MSG_DEBUG(
" --> TRT UnBiased TrackParameters of hit " << nTSOS <<
" FOUND");
315 float predictR = trackParameterUnbiased->parameters()[
Trk::locR];
318 std::optional<Trk::ResidualPull> residualPull =
320 trackParameterUnbiased.get(),
327 ATH_MSG_DEBUG(
" no covariance of the track parameters given, can not calculate pull!");
332 float residualR = hitR - predictR;
337 if (trtCircle !=
nullptr) {
338 ATH_MSG_DEBUG(
" fillHistograms() ** filling TRT histograms for hit/tsos #" << nTSOS
339 <<
" Barrel/EndCap: " << barrel_ec
340 <<
" layer/wheel: " << layer_or_wheel
341 <<
" phi: " << phi_module
342 <<
" Residual: " << residualR);
358 ATH_MSG_DEBUG(
"applying hit quality cuts to Silicon hit...");
366 else ATH_MSG_DEBUG(
"hit quality cuts NOT APPLIED to Silicon hit.");
388 ATH_MSG_DEBUG(
"Found Trk::TrackParameters " << trackParameter);
390 double unbiasedResXY[4] = {9999.0,9999.0,9999.0,9999.0};
391 double biasedResXY[4] = {9999.0,9999.0,9999.0,9999.0};
396 if (
sc.isFailure()) {
397 ATH_MSG_DEBUG(
"Problem in determining unbiased residuals! Hit is skipped.");
399 fill(residualGroup, detType_m);
405 residualX = (
float)unbiasedResXY[0];
406 residualY = (
float)unbiasedResXY[1];
407 pullX = (
float)unbiasedResXY[2];
408 pullY = (
float)unbiasedResXY[3];
412 if (
sc.isFailure()) {
413 ATH_MSG_DEBUG(
"Problem in determining biased residuals! Hit is skipped.");
419 biasedResidualX = (
float)biasedResXY[0];
420 biasedResidualY = (
float)biasedResXY[1];
424 ATH_MSG_DEBUG(
"No TrackParameters associated with Si TrkSurface "<< nTSOS <<
" - Hit is probably an outlier");
459 ATH_MSG_DEBUG(
" This is a PIXEL hit " << hitId <<
" - filling histograms");
461 si_residualx_m = residualX;
462 fill(residualGroup, si_residualx_m);
465 int ModEtaShift[4] = {0, 30, 53, 76};
466 int ModPhiShift[4] = {0, 24, 56, 104};
469 si_b_residualx_m = residualX;
470 fill(residualGroup, si_b_residualx_m);
472 layerDisk_si_m = layerDisk;
473 si_barrel_resX_m = residualX;
474 fill(residualGroup, layerDisk_si_m, si_barrel_resX_m);
475 si_barrel_resY_m = residualY;
476 fill(residualGroup, layerDisk_si_m, si_barrel_resY_m);
477 si_barrel_pullX_m = pullX;
478 fill(residualGroup, layerDisk_si_m, si_barrel_pullX_m);
479 si_barrel_pullY_m = pullY;
480 fill(residualGroup, layerDisk_si_m, si_barrel_pullY_m);
484 fill(residualGroup, pix_b_residualx_m);
486 fill(residualGroup, pix_b_biased_residualx_m);
488 fill(residualGroup, pix_b_residualy_m);
490 fill(residualGroup, pix_b_biased_residualy_m);
510 auto modPhiShift_barrel_m =
Monitored::Scalar<int>(
"m_modPhiShift_barrel", modPhi + ModPhiShift[layerDisk] );
511 auto modEtaShift_barrel_m =
Monitored::Scalar<int>(
"m_modEtaShift_barrel", modEta + ModEtaShift[layerDisk] );
512 fill(residualGroup, modPhiShift_barrel_m, residualX_barrel_m);
513 fill(residualGroup, modPhiShift_barrel_m, residualY_barrel_m);
514 fill(residualGroup, modEtaShift_barrel_m, residualX_barrel_m);
515 fill(residualGroup, modEtaShift_barrel_m, residualY_barrel_m);
517 else if(barrelEC==2){
518 int ModPhiShift[3] = {0, 55, 110};
521 layerDisk_si_m = layerDisk;
522 si_eca_resX_m = residualX;
523 fill(residualGroup, layerDisk_si_m, si_eca_resX_m);
524 si_eca_resY_m = residualY;
525 fill(residualGroup, layerDisk_si_m, si_eca_resY_m);
526 si_eca_pullX_m = pullX;
527 fill(residualGroup, layerDisk_si_m, si_eca_pullX_m);
528 si_eca_pullY_m = pullY;
529 fill(residualGroup, layerDisk_si_m, si_eca_pullY_m);
534 fill(residualGroup, pix_eca_residualx_m);
538 fill(residualGroup, pix_eca_residualy_m);
541 fill(residualGroup, pix_eca_pullx_m);
543 fill(residualGroup, pix_eca_pully_m);
551 fill(residualGroup, modPhiShift_eca_m, residualX_eca_m);
552 fill(residualGroup, modPhiShift_eca_m, residualY_eca_m);
554 else if(barrelEC==-2){
555 int ModPhiShift[3] = {0, 55, 110};
558 layerDisk_si_m = layerDisk;
559 si_ecc_resX_m = residualX;
560 fill(residualGroup, layerDisk_si_m, si_ecc_resX_m);
561 si_ecc_resY_m = residualY;
562 fill(residualGroup, layerDisk_si_m, si_ecc_resY_m);
563 si_ecc_pullX_m = pullX;
564 fill(residualGroup, layerDisk_si_m, si_ecc_pullX_m);
565 si_ecc_pullY_m = pullY;
566 fill(residualGroup, layerDisk_si_m, si_ecc_pullY_m);
571 fill(residualGroup, pix_ecc_residualx_m);
575 fill(residualGroup, pix_ecc_residualy_m);
578 fill(residualGroup, pix_ecc_pullx_m);
580 fill(residualGroup, pix_ecc_pully_m);
588 fill(residualGroup, modPhiShift_ecc_m, residualX_ecc_m);
589 fill(residualGroup, modPhiShift_ecc_m, residualY_ecc_m);
592 else if (detType==1) {
593 si_residualx_m = residualX;
594 fill(residualGroup, si_residualx_m);
596 ATH_MSG_DEBUG(
" This is a SCT hit " << hitId <<
" - filling histograms");
599 int ModPhiShift[4] = {0, 42, 92, 150};
600 int ModEtaShift[4] = {0, 23, 46, 69};
603 si_b_residualx_m = residualX;
604 fill(residualGroup, si_b_residualx_m);
606 layerDisk_si_m = 4 + 2 * layerDisk + sctSide;
607 si_barrel_resX_m = residualX;
608 fill(residualGroup, layerDisk_si_m, si_barrel_resX_m);
609 si_barrel_pullX_m = pullX;
610 fill(residualGroup, layerDisk_si_m, si_barrel_pullX_m);
614 fill(residualGroup, sct_b_residualx_m);
627 auto modPhiShift_sct_barrel_m =
Monitored::Scalar<int>(
"m_modPhiShift_sct_barrel", modPhi + ModPhiShift[layerDisk] );
628 auto modEtaShift_sct_barrel_m =
Monitored::Scalar<int>(
"m_modEtaShift_sct_barrel", modEta + ModEtaShift[layerDisk] );
629 fill(residualGroup, modPhiShift_sct_barrel_m, residualX_sct_barrel_m);
630 fill(residualGroup, modEtaShift_sct_barrel_m, residualX_sct_barrel_m);
633 else if(barrelEC==2){
638 layerDisk_si_m = 3 + 2 * layerDisk + sctSide;
639 si_eca_resX_m = residualX;
640 fill(residualGroup, layerDisk_si_m, si_eca_resX_m);
641 si_eca_pullX_m = pullX;
642 fill(residualGroup, layerDisk_si_m, si_eca_pullX_m);
646 fill(residualGroup, sct_eca_residualx_m);
649 fill(residualGroup, sct_eca_pullx_m);
653 auto modPhiShift_sct_eca_m =
Monitored::Scalar<int>(
"m_modPhiShift_sct_eca", modPhi + layerDisk * (gap_sct + Nmods) );
654 fill(residualGroup, modPhiShift_sct_eca_m, residualX_sct_eca_m);
657 else if(barrelEC==-2){
662 layerDisk_si_m = 3 + 2 * layerDisk + sctSide;
663 si_ecc_resX_m = residualX;
664 fill(residualGroup, layerDisk_si_m, si_ecc_resX_m);
665 si_ecc_pullX_m = pullX;
666 fill(residualGroup, layerDisk_si_m, si_ecc_pullX_m);
670 fill(residualGroup, sct_ecc_residualx_m);
673 fill(residualGroup, sct_ecc_pullx_m);
677 auto modPhiShift_sct_ecc_m =
Monitored::Scalar<int>(
"m_modPhiShift_sct_ecc", modPhi + layerDisk * (gap_sct + Nmods) );
678 fill(residualGroup, modPhiShift_sct_ecc_m, residualX_sct_ecc_m);
688 return StatusCode::SUCCESS;
694 if (!
m_doPulls)
return StatusCode::FAILURE;
698 double residualX = -9999.0;
699 double residualY = -9999.0;
700 double pullX = -9999.0;
701 double pullY = -9999.0;
708 std::unique_ptr <Trk::TrackParameters> trackParameterUnbiased{};
712 std::unique_ptr <Trk::TrackParameters> trackParameterForResiduals{};
713 if(trackParameterUnbiased){
714 trackParameterForResiduals = std:: move(trackParameterUnbiased);
719 trackParameterForResiduals = std::move(uTrkPtr);
724 if (hit && trackParameterForResiduals) {
728 std::optional<Trk::ResidualPull> residualPull = std::nullopt;
736 residualX = residualPull->residual()[
Trk::loc1];
737 if(residualPull->isPullValid()) pullX = residualPull->pull()[
Trk::loc1];
739 ATH_MSG_DEBUG(
"ResidualPullCalculator finds invalid X Pull!!!");
740 sc = StatusCode::FAILURE;
743 if (residualPull->dimension() >= 2){
746 residualY = residualPull->residual()[
Trk::loc2];
749 if(residualPull->isPullValid()) pullY = residualPull->pull()[
Trk::loc2];
751 ATH_MSG_DEBUG(
"ResidualPullCalculator finds invalid Y Pull!!!");
752 sc = StatusCode::FAILURE;
758 sc = StatusCode::FAILURE;
772 if(pullX!=pullX || pullY!=pullY){
774 sc = StatusCode::FAILURE;
783 bool LRcorrect = (predictR * hitR > 0);
786 if (barrel_ec == -1) {
790 if (barrel_ec == 1 || barrel_ec == -1)
803 if (barrel_ec == 2 || barrel_ec == -2)
824 else if (
side == 1 && barrel_ec == 1)
doFill =
true;
825 else if (
side == 2 && barrel_ec == -1)
doFill =
true;
846 if (LRcorrect && !isTubeHit) trt_b_lr_m = 0.5;
847 if (LRcorrect && isTubeHit) trt_b_lr_m = 1.5;
848 if (!LRcorrect && !isTubeHit) trt_b_lr_m = 2.5;
849 if (!LRcorrect && isTubeHit) trt_b_lr_m = 3.5;
857 trt_b_lrVsPhiSec_m = LRcorrect;
866 for (
unsigned int endcap = 0; endcap < 2; ++endcap) {
868 if (!endcap && barrel_ec == 2)
doFill =
true;
869 else if (endcap && barrel_ec == -2)
doFill =
true;
890 if (LRcorrect && !isTubeHit) trt_ec_lr_m = 0.5;
891 else if (LRcorrect && isTubeHit) trt_ec_lr_m = 1.5;
892 else if (!LRcorrect && !isTubeHit) trt_ec_lr_m = 2.5;
893 else if (!LRcorrect && isTubeHit) trt_ec_lr_m = 3.5;
912 std::unique_ptr <Trk::TrackParameters> TrackParams{};
913 std::unique_ptr <Trk::TrackParameters> UnbiasedTrackParams{};
914 std::unique_ptr <Trk::TrackParameters> PropagatedTrackParams{};
915 std::unique_ptr <Trk::TrackParameters> OtherSideUnbiasedTrackParams{};
918 bool trueUnbiased =
true;
920 Identifier surfaceID;
928 if (hitOnTrack !=
nullptr) surfaceID = hitOnTrack->
identify();
932 if (surfaceID.is_valid() && trueUnbiased &&
m_idHelper->
is_sct(surfaceID)) {
939 IdentifierHash otherSideHash;
946 if (TempHitOnTrack !=
nullptr) {
949 OtherModuleSideHit = TempTsos;
954 if (OtherModuleSideHit) {
956 const AmgSymMatrix(5)* OMSHmeasuredTrackParameterCov = OMSHmeasuredTrackParameter ? OMSHmeasuredTrackParameter->covariance() :
nullptr;
959 if (OMSHmeasuredTrackParameterCov) {
965 if (OtherSideUnbiasedTrackParams) {
966 ATH_MSG_VERBOSE(
"Unbiased OtherSideTrackParameters: " << *OtherSideUnbiasedTrackParams);
980 ATH_MSG_VERBOSE(
"TempSurface->associatedLayer()->enclosingTrackingVolume exists");
987 Gaudi::Hive::currentContext(),
988 *OtherSideUnbiasedTrackParams,
995 ATH_MSG_VERBOSE(
"TempSurface->associatedLayer()->enclosingTrackingVolume does not exist");
1001 ATH_MSG_VERBOSE(
"After OtherSide surface call. Surface does not exist");
1005 if (PropagatedTrackParams) {
1006 ATH_MSG_VERBOSE(
"Propagated Track Parameters: " << *PropagatedTrackParams);
1008 ATH_MSG_DEBUG(
"Propagation of unbiased OtherSideParameters failed");
1011 ATH_MSG_DEBUG(
"RemoveFromState did not work for OtherSideParameters");
1014 ATH_MSG_VERBOSE(
"No OtherModuleSideHit Measured Track Parameters found");
1022 if (!PropagatedTrackParams) {
1024 PropagatedTrackParams = std::move(uTrkPtr);
1027 UnbiasedTrackParams =
1029 ->removeFromState(*PropagatedTrackParams,
1033 if (UnbiasedTrackParams) {
1035 ATH_MSG_VERBOSE(
"Unbiased Trackparameters: " << *UnbiasedTrackParams);
1037 TrackParams = std::move(UnbiasedTrackParams);
1040 ATH_MSG_WARNING(
"RemoveFromState did not work, using original TrackParameters");
1043 TrackParams = std::move(uTrkPtr);
1083 return StatusCode::FAILURE;
1088 return StatusCode::FAILURE;
1092 ATH_MSG_DEBUG(
"No residual/pull calculator for general hit residuals configured.");
1093 ATH_MSG_DEBUG(
"It is recommended to give R/P calculators to the det-specific tool handle lists then.");
1101 ATH_MSG_DEBUG(
"Generic hit residuals&pulls will be calculated in one or both available local coordinates");
1106 ATH_MSG_DEBUG(
"No hit quality tool configured - not hit quality cuts will be imposed");
1113 ATH_MSG_DEBUG(
"Hit quality tool setup - hit quality cuts will be applied to Si hits");
1118 return StatusCode::SUCCESS;
1132 int nHitsNoParams = 0;
1138 if(tsos ==
nullptr)
continue;
1144 if (mesh==
nullptr)
continue;
1146 if (hit==
nullptr)
continue;
1151 if(trackParameter==
nullptr) ++nHitsNoParams;
1155 ATH_MSG_DEBUG(
"Total nhits on track (excluding outliers) = " << nHits <<
", nhits without trackparameters = " << nHitsNoParams);
1157 if(nHitsNoParams>0) {