diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSCenterPositionCalculation.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSCenterPositionCalculation.cxx index f759bf447abff81fe4e37d9871cefc3e4099d2e6..f3d14b2ba8dcc92946f741db65b6a3a2ec9cd657 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSCenterPositionCalculation.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSCenterPositionCalculation.cxx @@ -19,10 +19,28 @@ TFCSCenterPositionCalculation::TFCSCenterPositionCalculation(const char* name, c FCSReturnCode TFCSCenterPositionCalculation::simulate_hit(Hit& hit,TFCSSimulationState& /*simulstate*/,const TFCSTruthState* /*truth*/, const TFCSExtrapolationState* extrapol) { const int cs=calosample(); - hit.setCenter_r( (1.-m_extrapWeight)*extrapol->r(cs, SUBPOS_ENT) + m_extrapWeight*extrapol->r(cs, SUBPOS_EXT) ); - hit.setCenter_z( (1.-m_extrapWeight)*extrapol->z(cs, SUBPOS_ENT) + m_extrapWeight*extrapol->z(cs, SUBPOS_EXT) ); - hit.setCenter_eta( (1.-m_extrapWeight)*extrapol->eta(cs, SUBPOS_ENT) + m_extrapWeight*extrapol->eta(cs, SUBPOS_EXT) ); - hit.setCenter_phi( (1.-m_extrapWeight)*extrapol->phi(cs, SUBPOS_ENT) + m_extrapWeight*extrapol->phi(cs, SUBPOS_EXT) ); + + double r = (1.-m_extrapWeight)*extrapol->r(cs, SUBPOS_ENT) + m_extrapWeight*extrapol->r(cs, SUBPOS_EXT); + double z = (1.-m_extrapWeight)*extrapol->z(cs, SUBPOS_ENT) + m_extrapWeight*extrapol->z(cs, SUBPOS_EXT); + double eta = (1.-m_extrapWeight)*extrapol->eta(cs, SUBPOS_ENT) + m_extrapWeight*extrapol->eta(cs, SUBPOS_EXT); + double phi = (1.-m_extrapWeight)*extrapol->phi(cs, SUBPOS_ENT) + m_extrapWeight*extrapol->phi(cs, SUBPOS_EXT); + + if(!std::isfinite(r) || !std::isfinite(z) || !std::isfinite(eta) || !std::isfinite(phi)) { + ATH_MSG_WARNING("Extrapolator contains NaN or infinite number.\nSetting center position to calo boundary."); + ATH_MSG_WARNING("Before fix: center_r: " << r << " center_z: " << z << " center_phi: " << phi << " center_eta: " << eta << " weight: " << m_extrapWeight << " cs: " << cs); + // If extrapolator fails we can set position to calo boundary + r = extrapol->IDCaloBoundary_r(); + z = extrapol->IDCaloBoundary_z(); + eta = extrapol->IDCaloBoundary_eta(); + phi = extrapol->IDCaloBoundary_phi(); + + ATH_MSG_WARNING("After fix: center_r: " << r << " center_z: " << z << " center_phi: " << phi << " center_eta: " << eta << " weight: " << m_extrapWeight << " cs: " << cs); + } + + hit.setCenter_r( r ); + hit.setCenter_z( z ); + hit.setCenter_eta( eta ); + hit.setCenter_phi( phi ); ATH_MSG_DEBUG("TFCSCenterPositionCalculation: center_r: " << hit.center_r() << " center_z: " << hit.center_z() << " center_phi: " << hit.center_phi() << " center_eta: " << hit.center_eta() << " weight: " << m_extrapWeight << " cs: " << cs);