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;
154 auto residualGroup =
getGroup(
"Residuals");
157 bool hasBeenCalledThisEvent=
false;
163 if (!hasBeenCalledThisEvent){
166 hasBeenCalledThisEvent=
true;
172 fill(
"residualGroup", mu_m);
177 if (not tracks.isValid()) {
179 return StatusCode::RECOVERABLE;
183 ATH_MSG_DEBUG (
"IDAlignMonResidual: Start loop on tracks. Number of tracks " << tracks->size());
187 if ( !trksItr || trksItr->perigeeParameters() ==
nullptr ) {
188 ATH_MSG_DEBUG(
"InDetAlignmentMonitoringRun3: NULL track pointer in collection" );
200 ATH_MSG_DEBUG(
"Not all TSOS contain track parameters - will be missing residuals/pulls");
203 ATH_MSG_DEBUG(
"All TSOS of track " << nTracks <<
"/" << tracks->size() <<
" contain track parameters - Good!");
207 ATH_MSG_DEBUG(
"** IDAlignMonResiduals::fillHistograms() ** track: " << nTracks <<
" has " << trksItr->trackStateOnSurfaces()->size() <<
" TrkSurfaces");
212 const Trk::Perigee* measPer = trksItr->perigeeParameters();
213 float charge = 1;
if (measPer->charge() < 0)
charge = -1;
215 trkpt = measPer->pT()/1000.;
223 if (tsos ==
nullptr) {
229 ATH_MSG_DEBUG(
" --> testing if hit " << nTSOS <<
"/" << trksItr->trackStateOnSurfaces()->size() <<
" is a track measurement");
231 ATH_MSG_DEBUG(
"Skipping TSOS " << nTSOS <<
" because it is an outlier (or the first TSOS on the track)");
236 ATH_MSG_DEBUG(
" --> Defined hit measurementOnTrack() for hit: " << nTSOS <<
"/" << trksItr->trackStateOnSurfaces()->size() <<
" of track " << nTracks);
240 ATH_MSG_DEBUG(
" --> Going to retrive the Trk::RIO_OnTrack for hit " << nTSOS);
243 if (nHits >0)
ATH_MSG_DEBUG(
"No hit associated with TSOS " << nTSOS);
247 ATH_MSG_DEBUG(
" --> Going to retrive the track parameters of this TSOS: " << nTSOS);
249 if(trackParameter==
nullptr) {
251 ATH_MSG_DEBUG(
" Skipping TSOS " << nTSOS <<
" because it does not have TrackParameters");
255 const AmgSymMatrix(5)* TrackParCovariance = trackParameter ? trackParameter->covariance() :
nullptr;
257 if(TrackParCovariance==
nullptr) {
260 ATH_MSG_DEBUG(
"Skipping TSOS " << nTSOS <<
" because does not have MeasuredTrackParameters");
265 " --> going to define residuals and everything of TSOS #" << nTSOS <<
"/" <<
266 trksItr->trackStateOnSurfaces()->size());
268 float residualX = 9999.0;
269 float residualY = 9999.0;
270 float pullX = 9999.0;
271 float pullY = 9999.0;
272 float biasedResidualX = 9999.0;
273 float biasedResidualY = 9999.0;
278 int layer_or_wheel = 99;
290 if ( detType == 99) {
291 ATH_MSG_DEBUG(
" --> Hit " << nTSOS <<
" with detector type " << detType <<
" is not an Inner Detector hit -> skip this hit");
297 ATH_MSG_DEBUG(
"** IDAlignMonResidualsAlg::fillHistograms() ** Hit is from the TRT, finding residuals... ");
301 if (!trackParameter) {
302 ATH_MSG_WARNING(
"No TrackParameters associated with TRT TrkSurface " << nTSOS);
306 float trketa = tsos->trackParameters()->eta();
315 ATH_MSG_DEBUG(
"Found Trk::TrackParameters for hit " << nTSOS <<
" --> TRT hit (detType= " << detType <<
")" );
321 if (!trackParameterUnbiased) {
322 ATH_MSG_WARNING(
"Cannot define unbiased parameters for hit, skipping it.");
325 ATH_MSG_DEBUG(
" --> TRT UnBiased TrackParameters of hit " << nTSOS <<
" FOUND");
327 float predictR = trackParameterUnbiased->parameters()[
Trk::locR];
330 std::optional<Trk::ResidualPull> residualPull =
332 trackParameterUnbiased.get(),
339 ATH_MSG_DEBUG(
" no covariance of the track parameters given, can not calculate pull!");
344 float residualR = hitR - predictR;
349 if (trtCircle !=
nullptr) {
350 ATH_MSG_DEBUG(
" fillHistograms() ** filling TRT histograms for hit/tsos #" << nTSOS
351 <<
" Barrel/EndCap: " << barrel_ec
352 <<
" layer/wheel: " << layer_or_wheel
353 <<
" phi: " << phi_module
354 <<
" Residual: " << residualR);
371 ATH_MSG_DEBUG(
"applying hit quality cuts to Silicon hit...");
379 else ATH_MSG_DEBUG(
"hit quality cuts NOT APPLIED to Silicon hit.");
401 ATH_MSG_DEBUG(
"Found Trk::TrackParameters " << trackParameter);
403 double unbiasedResXY[4] = {9999.0,9999.0,9999.0,9999.0};
404 double biasedResXY[4] = {9999.0,9999.0,9999.0,9999.0};
409 if (
sc.isFailure()) {
410 ATH_MSG_DEBUG(
"Problem in determining unbiased residuals! Hit is skipped.");
412 fill(residualGroup, detType_m);
418 residualX = (
float)unbiasedResXY[0];
419 residualY = (
float)unbiasedResXY[1];
420 pullX = (
float)unbiasedResXY[2];
421 pullY = (
float)unbiasedResXY[3];
425 if (
sc.isFailure()) {
426 ATH_MSG_DEBUG(
"Problem in determining biased residuals! Hit is skipped.");
432 biasedResidualX = (
float)biasedResXY[0];
433 biasedResidualY = (
float)biasedResXY[1];
437 ATH_MSG_DEBUG(
"No TrackParameters associated with Si TrkSurface "<< nTSOS <<
" - Hit is probably an outlier");
472 ATH_MSG_DEBUG(
" This is a PIXEL hit " << hitId <<
" - filling histograms");
474 si_residualx_m = residualX;
475 fill(residualGroup, si_residualx_m);
478 int ModEtaShift[4] = {0, 30, 53, 76};
479 int ModPhiShift[4] = {0, 24, 56, 104};
482 si_b_residualx_m = residualX;
483 fill(residualGroup, si_b_residualx_m);
485 layerDisk_si_m = layerDisk;
486 si_barrel_resX_m = residualX;
487 si_barrel_resY_m = residualY;
488 si_barrel_pullX_m = pullX;
489 si_barrel_pullY_m = pullY;
490 fill(residualGroup, layerDisk_si_m, si_barrel_resX_m, si_barrel_resY_m, si_barrel_pullX_m, si_barrel_pullY_m);
497 fill(residualGroup, pix_b_residualx_m, pix_b_biased_residualx_m, pix_b_residualy_m, pix_b_biased_residualy_m);
517 auto modPhiShift_barrel_m =
Monitored::Scalar<int>(
"m_modPhiShift_barrel", modPhi + ModPhiShift[layerDisk] );
518 auto modEtaShift_barrel_m =
Monitored::Scalar<int>(
"m_modEtaShift_barrel", modEta + ModEtaShift[layerDisk] );
519 fill(residualGroup, modPhiShift_barrel_m, residualX_barrel_m, residualY_barrel_m);
520 fill(residualGroup, modEtaShift_barrel_m, residualX_barrel_m, residualY_barrel_m);
522 else if(barrelEC==2){
523 int ModPhiShift[3] = {0, 55, 110};
526 layerDisk_si_m = layerDisk;
527 si_eca_resX_m = residualX;
528 si_eca_resY_m = residualY;
529 si_eca_pullX_m = pullX;
530 si_eca_pullY_m = pullY;
531 fill(residualGroup, layerDisk_si_m, si_eca_resX_m, si_eca_resY_m, si_eca_pullX_m, si_eca_pullY_m);
539 fill(residualGroup, pix_eca_residualx_m, pix_eca_residualy_m);
543 fill(residualGroup, pix_eca_pullx_m, pix_eca_pully_m);
551 fill(residualGroup, modPhiShift_eca_m, residualX_eca_m, residualY_eca_m);
553 else if(barrelEC==-2){
554 int ModPhiShift[3] = {0, 55, 110};
557 layerDisk_si_m = layerDisk;
558 si_ecc_resX_m = residualX;
559 si_ecc_resY_m = residualY;
560 si_ecc_pullX_m = pullX;
561 si_ecc_pullY_m = pullY;
562 fill(residualGroup, layerDisk_si_m, si_ecc_resX_m, si_ecc_resY_m, si_ecc_pullX_m, si_ecc_pullY_m);
570 fill(residualGroup, pix_ecc_residualx_m, pix_ecc_residualy_m);
574 fill(residualGroup, pix_ecc_pullx_m, pix_ecc_pully_m);
582 fill(residualGroup, modPhiShift_ecc_m, residualX_ecc_m, residualY_ecc_m);
585 else if (detType==1) {
586 si_residualx_m = residualX;
587 fill(residualGroup, si_residualx_m);
589 ATH_MSG_DEBUG(
" This is a SCT hit " << hitId <<
" - filling histograms");
592 int ModPhiShift[4] = {0, 42, 92, 150};
593 int ModEtaShift[4] = {0, 23, 46, 69};
596 si_b_residualx_m = residualX;
597 fill(residualGroup, si_b_residualx_m);
599 layerDisk_si_m = 4 + 2 * layerDisk + sctSide;
600 si_barrel_resX_m = residualX;
601 si_barrel_pullX_m = pullX;
602 fill(residualGroup, layerDisk_si_m, si_barrel_resX_m, si_barrel_pullX_m);
606 fill(residualGroup, sct_b_residualx_m);
624 auto modPhiShift_sct_barrel_m =
Monitored::Scalar<int>(
"m_modPhiShift_sct_barrel", modPhi + ModPhiShift[layerDisk] );
625 auto modEtaShift_sct_barrel_m =
Monitored::Scalar<int>(
"m_modEtaShift_sct_barrel", modEta + ModEtaShift[layerDisk] );
626 fill(residualGroup, modPhiShift_sct_barrel_m, modEtaShift_sct_barrel_m, residualX_sct_barrel_m);
629 else if(barrelEC==2){
634 layerDisk_si_m = 3 + 2 * layerDisk + sctSide;
635 si_eca_resX_m = residualX;
636 si_eca_pullX_m = pullX;
637 fill(residualGroup, layerDisk_si_m, si_eca_resX_m, si_eca_pullX_m);
643 fill(residualGroup, sct_eca_residualx_m, sct_eca_pullx_m);
652 auto modPhiShift_sct_eca_m =
Monitored::Scalar<int>(
"m_modPhiShift_sct_eca", modPhi + layerDisk * (gap_sct + Nmods) );
653 fill(residualGroup, modPhiShift_sct_eca_m, residualX_sct_eca_m);
656 else if(barrelEC==-2){
661 layerDisk_si_m = 3 + 2 * layerDisk + sctSide;
662 si_ecc_resX_m = residualX;
663 si_ecc_pullX_m = pullX;
664 fill(residualGroup, layerDisk_si_m, si_ecc_resX_m, si_ecc_pullX_m);
670 fill(residualGroup, sct_ecc_residualx_m, sct_ecc_pullx_m);
679 auto modPhiShift_sct_ecc_m =
Monitored::Scalar<int>(
"m_modPhiShift_sct_ecc", modPhi + layerDisk * (gap_sct + Nmods) );
680 fill(residualGroup, modPhiShift_sct_ecc_m, residualX_sct_ecc_m);
690 return StatusCode::SUCCESS;
696 if (!
m_doPulls)
return StatusCode::FAILURE;
700 double residualX = -9999.0;
701 double residualY = -9999.0;
702 double pullX = -9999.0;
703 double pullY = -9999.0;
710 std::unique_ptr <Trk::TrackParameters> trackParameterUnbiased{};
714 std::unique_ptr <Trk::TrackParameters> trackParameterForResiduals{};
715 if(trackParameterUnbiased){
716 trackParameterForResiduals = std:: move(trackParameterUnbiased);
721 trackParameterForResiduals = std::move(uTrkPtr);
726 if (hit && trackParameterForResiduals) {
730 std::optional<Trk::ResidualPull> residualPull = std::nullopt;
738 residualX = residualPull->residual()[
Trk::loc1];
739 if(residualPull->isPullValid()) pullX = residualPull->pull()[
Trk::loc1];
741 ATH_MSG_DEBUG(
"ResidualPullCalculator finds invalid X Pull!!!");
742 sc = StatusCode::FAILURE;
745 if (residualPull->dimension() >= 2){
748 residualY = residualPull->residual()[
Trk::loc2];
751 if(residualPull->isPullValid()) pullY = residualPull->pull()[
Trk::loc2];
753 ATH_MSG_DEBUG(
"ResidualPullCalculator finds invalid Y Pull!!!");
754 sc = StatusCode::FAILURE;
760 sc = StatusCode::FAILURE;
774 if(pullX!=pullX || pullY!=pullY){
776 sc = StatusCode::FAILURE;
785 bool LRcorrect = (predictR * hitR > 0);
788 if (barrel_ec == -1) {
792 if (barrel_ec == 1 || barrel_ec == -1)
805 if (barrel_ec == 2 || barrel_ec == -2)
828 else if (
side == 1 && barrel_ec == 1)
doFill =
true;
829 else if (
side == 2 && barrel_ec == -1)
doFill =
true;
850 if (LRcorrect && !isTubeHit) trt_b_lr_m = 0.5;
851 if (LRcorrect && isTubeHit) trt_b_lr_m = 1.5;
852 if (!LRcorrect && !isTubeHit) trt_b_lr_m = 2.5;
853 if (!LRcorrect && isTubeHit) trt_b_lr_m = 3.5;
861 trt_b_lrVsPhiSec_m = LRcorrect;
869 void IDAlignMonResidualsAlg::fillTRTEndcapHistograms(
int barrel_ec,
int layer_or_wheel,
int phi_module,
float predictR,
float hitR,
float residualR,
float pullR,
bool LRcorrect,
bool isTubeHit,
float trketa,
float qpT)
const {
870 for (
unsigned int endcap = 0; endcap < 2; ++endcap) {
872 if (!endcap && barrel_ec == 2)
doFill =
true;
873 else if (endcap && barrel_ec == -2)
doFill =
true;
899 if (LRcorrect && !isTubeHit) trt_ec_lr_m = 0.5;
900 else if (LRcorrect && isTubeHit) trt_ec_lr_m = 1.5;
901 else if (!LRcorrect && !isTubeHit) trt_ec_lr_m = 2.5;
902 else if (!LRcorrect && isTubeHit) trt_ec_lr_m = 3.5;
921 std::unique_ptr <Trk::TrackParameters> TrackParams{};
922 std::unique_ptr <Trk::TrackParameters> UnbiasedTrackParams{};
923 std::unique_ptr <Trk::TrackParameters> PropagatedTrackParams{};
924 std::unique_ptr <Trk::TrackParameters> OtherSideUnbiasedTrackParams{};
927 bool trueUnbiased =
true;
937 if (hitOnTrack !=
nullptr) surfaceID = hitOnTrack->
identify();
941 if (surfaceID.is_valid() && trueUnbiased &&
m_idHelper->
is_sct(surfaceID)) {
948 IdentifierHash otherSideHash;
955 if (TempHitOnTrack !=
nullptr) {
958 OtherModuleSideHit = TempTsos;
963 if (OtherModuleSideHit) {
965 const AmgSymMatrix(5)* OMSHmeasuredTrackParameterCov = OMSHmeasuredTrackParameter ? OMSHmeasuredTrackParameter->covariance() :
nullptr;
968 if (OMSHmeasuredTrackParameterCov) {
974 if (OtherSideUnbiasedTrackParams) {
975 ATH_MSG_VERBOSE(
"Unbiased OtherSideTrackParameters: " << *OtherSideUnbiasedTrackParams);
989 ATH_MSG_VERBOSE(
"TempSurface->associatedLayer()->enclosingTrackingVolume exists");
996 Gaudi::Hive::currentContext(),
997 *OtherSideUnbiasedTrackParams,
1004 ATH_MSG_VERBOSE(
"TempSurface->associatedLayer()->enclosingTrackingVolume does not exist");
1010 ATH_MSG_VERBOSE(
"After OtherSide surface call. Surface does not exist");
1014 if (PropagatedTrackParams) {
1015 ATH_MSG_VERBOSE(
"Propagated Track Parameters: " << *PropagatedTrackParams);
1017 ATH_MSG_DEBUG(
"Propagation of unbiased OtherSideParameters failed");
1020 ATH_MSG_DEBUG(
"RemoveFromState did not work for OtherSideParameters");
1023 ATH_MSG_VERBOSE(
"No OtherModuleSideHit Measured Track Parameters found");
1031 if (!PropagatedTrackParams) {
1033 PropagatedTrackParams = std::move(uTrkPtr);
1036 UnbiasedTrackParams =
1038 ->removeFromState(*PropagatedTrackParams,
1042 if (UnbiasedTrackParams) {
1044 ATH_MSG_VERBOSE(
"Unbiased Trackparameters: " << *UnbiasedTrackParams);
1046 TrackParams = std::move(UnbiasedTrackParams);
1049 ATH_MSG_WARNING(
"RemoveFromState did not work, using original TrackParameters");
1052 TrackParams = std::move(uTrkPtr);
1092 return StatusCode::FAILURE;
1097 return StatusCode::FAILURE;
1101 ATH_MSG_DEBUG(
"No residual/pull calculator for general hit residuals configured.");
1102 ATH_MSG_DEBUG(
"It is recommended to give R/P calculators to the det-specific tool handle lists then.");
1110 ATH_MSG_DEBUG(
"Generic hit residuals&pulls will be calculated in one or both available local coordinates");
1115 ATH_MSG_DEBUG(
"No hit quality tool configured - not hit quality cuts will be imposed");
1122 ATH_MSG_DEBUG(
"Hit quality tool setup - hit quality cuts will be applied to Si hits");
1127 return StatusCode::SUCCESS;
1141 int nHitsNoParams = 0;
1147 if(tsos ==
nullptr)
continue;
1153 if (mesh==
nullptr)
continue;
1155 if (hit==
nullptr)
continue;
1160 if(trackParameter==
nullptr) ++nHitsNoParams;
1164 ATH_MSG_DEBUG(
"Total nhits on track (excluding outliers) = " << nHits <<
", nhits without trackparameters = " << nHitsNoParams);
1166 if(nHitsNoParams>0) {