38 constexpr
float solenoidRadius = 1280.;
45 m_histSvc(
"THistSvc",
name) {
46 declareInterface<ITrackDepositInCaloTool>(
this);
56 if (!
m_tileDDM) {
return StatusCode::FAILURE; }
64 return StatusCode::SUCCESS;
72 const EventContext& ctx = Gaudi::Hive::currentContext();
74 std::vector<DepositInCalo>
result;
79 if (!caloCellCont)
return result;
82 if (!caloDetDescrMgrHandle.isValid()) {
91 std::vector<Amg::Vector3D> extrapolations;
92 std::map<double, const CaloDetDescriptor*> caloInfo;
98 if (
getTraversedLayers(caloDDM,currentPar.get(), caloInfo, extrapolations).isFailure()) {
104 for (
const std::pair<const double, const CaloDetDescriptor*>& detDescrIt : caloInfo) {
117 currentPar.swap(parEntrance);
121 double energyLoss =
calcEnergy(parEntrance.get(), muonHypo) -
calcEnergy(parExit.get(), muonHypo);
124 std::vector<const CaloCell*>
cells =
128 double sumEnergy = 0;
132 sumEnergy +=
cell->energy();
139 ATH_MSG_DEBUG(
"Energy = " << sumEnergy <<
" for sample " <<
descr->getSampling() <<
" in " <<
cells.size() <<
" cells.");
143 currentPar.swap(parEntrance);
153 ATH_MSG_DEBUG(
"In TrackDepositsInCaloTool::getDeposits() - new");
154 std::vector<DepositInCalo>
result;
159 std::unique_ptr<const Rec::ParticleCellAssociation>
association =
167 std::vector<std::pair<const CaloCell*, Rec::ParticleCellIntersection*>> cellIntersections =
association->cellIntersections();
176 ATH_MSG_DEBUG(
" nr of cell intersections " << cellIntersections.size());
177 if (cellIntersections.size() < 3)
ATH_MSG_WARNING(
" Strange nr of calorimeter cell intersections " << cellIntersections.size());
187 std::vector<float> exp_E(
nSamples, 0.0);
188 std::vector<float> meas_E(
nSamples, 0.0);
189 std::vector<float> meas_Et(
nSamples, 0.0);
190 std::vector<int> LayerHit(
nSamples, 0);
196 for (
auto&
it : cellIntersections) {
198 if (curr_cell->
badcell())
continue;
204 lEntry =
pos->second.first;
205 lExit =
pos->second.second;
207 meas_E[cellSampling] += Float_t(curr_cell->
energy());
208 meas_Et[cellSampling] += Float_t(curr_cell->
energy() * curr_cell->
sinTh());
209 exp_E[cellSampling] = Float_t((
it.second)->expectedEnergyLoss());
210 LayerHit[cellSampling]++;
212 <<
" Exp : " << (
it.second)->expectedEnergyLoss());
219 if (LayerHit[
i] > 0) {
222 ATH_MSG_DEBUG(
" Layer : " <<
sample <<
" Energy = " << meas_E[
i] <<
" nCells : " << LayerHit[
i] <<
" Exp: " << exp_E[
i]);
239 if (
descr->is_tile()) {
249 std::vector<const CaloCell*>
result;
250 result.push_back(cellEntrance);
251 if (cellEntrance != cellExit) {
252 result.push_back(cellExit);
271 std::vector<const CaloCell*>
result{};
273 double phiPar = parEntrance->
position().phi();
274 double phiParEntrance = phiPar;
275 double zParEntrance = parEntrance->
position().z();
276 double phiParExit = parExit->
position().phi();
277 double zParExit = parExit->
position().z();
278 double diffZPar = zParExit - zParEntrance;
279 double etaPar = parEntrance->
position().eta();
281 double etaWidth = 2 * (
descr->calo_eta_max() -
descr->calo_eta_min()) /
descr->n_eta();
282 double etaMin = etaPar - etaWidth;
283 double etaMax = etaPar + etaWidth;
291 std::vector<IdentifierHash> vecHash;
295 std::map<double, const CaloCell*> neighbourMap0;
296 std::map<double, const CaloCell*> neighbourMap1;
304 double dPhiCell = dde->
dphi();
305 double phiCellMin = dde->
phi() - dPhiCell / 2;
306 double phiCellMax = phiCellMin + dPhiCell;
307 if (!(phiParEntrance > phiCellMin && phiParExit < phiCellMax) && !(phiParExit > phiCellMin && phiParExit < phiCellMax)) {
312 double zCellMin0{0}, zCellMax0{0}, zCellMin1{0}, zCellMax1{0};
320 zCellMin0 = cellDim->
getZMin(0);
321 zCellMax0 = cellDim->
getZMax(0);
322 zCellMin1 = cellDim->
getZMin(3);
323 zCellMax1 = cellDim->
getZMax(3);
325 zCellMin0 = cellDim->
getZMin(0);
326 zCellMax0 = cellDim->
getZMax(0);
327 zCellMin1 = zCellMin0;
328 zCellMax1 = zCellMax0;
333 if (zParEntrance >= zCellMin0 && zParEntrance <= zCellMax0 && phiParEntrance > phiCellMin && phiParEntrance < phiCellMax) {
338 if (zParExit >= zCellMin1 && zParExit <= zCellMax1 && phiParExit > phiCellMin && phiParExit < phiCellMax) {
344 if (zParEntrance < zCellMin0 && zParExit > zCellMax1) {
349 if (zParEntrance > zCellMax0 && zParExit < zCellMin1) {
365 std::unique_ptr<const Trk::TrackParameters> paramEntrance;
366 bool checkBoundary =
true;
376 if (!paramEntrance) {
377 ATH_MSG_DEBUG(
"Extrapolation to entrance failed without boundary check.");
382 if (surfEntrance->isOnSurface(posVecEntrance, checkBoundary)) {
383 ATH_MSG_VERBOSE(
"Successfully extrapolated to entrance of calo for sample " <<
descr->getSampling());
384 return paramEntrance;
388 std::unique_ptr<const Trk::TrackParameters> paramOnInside{
391 ATH_MSG_VERBOSE(
"Successfully extrapolated to inner side of calo for sample " <<
descr->getSampling());
392 paramEntrance.swap(paramOnInside);
398 return paramEntrance;
407 std::unique_ptr<const Trk::TrackParameters> paramExit;
408 bool checkBoundary =
true;
425 if (!surfOutside) {
return nullptr; }
428 ATH_MSG_VERBOSE(
"Succesfully extrapolated to outer side of calo for sample " <<
descr->getSampling());
446 constexpr
double halfLengthOfCylinder = 3700;
447 bool checkBoundary =
true;
451 std::unique_ptr<const Trk::TrackParameters> parAtSolenoid{
452 m_extrapolator->extrapolate(ctx, *
par, solenoid, direction, checkBoundary, muonHypo)};
453 if (!parAtSolenoid) {
455 double zTrans =
par->eta() > 0 ? halfLengthOfCylinder : -halfLengthOfCylinder;
458 parAtSolenoid =
m_extrapolator->extrapolate(ctx, *
par, disc, direction, checkBoundary, muonHypo);
460 if (!parAtSolenoid) {
461 ATH_MSG_VERBOSE(
"extrapolateToSolenoid(): Extrapolation to cap of solenoid failed. Trying opposite side.");
463 parAtSolenoid =
m_extrapolator->extrapolate(ctx, *
par, discOpp, direction, checkBoundary, muonHypo);
466 if (parAtSolenoid) {
ATH_MSG_VERBOSE(
"extrapolateToSolenoid(): Extrapolation succeeded for disc-type surface."); }
469 ATH_MSG_VERBOSE(
"extrapolateToSolenoid(): Extrapolation succeeded for cylinder-type surface.");
472 return parAtSolenoid;
491 std::vector<DepositInCalo>
result;
492 const EventContext& ctx = Gaudi::Hive::currentContext();
498 if (!caloDetDescrMgrHandle.isValid()) {
505 bool checkBoundary =
true;
508 std::vector<Amg::Vector3D> extrapolations;
509 std::map<double, const CaloDetDescriptor*> caloInfo;
512 if (
getTraversedLayers(caloDDM, parAtSolenoid.get(), caloInfo, extrapolations).isFailure()) {
522 for (
const std::pair<const double, const CaloDetDescriptor*>&
it : caloInfo) {
524 double energyEntrance{0}, energyExit{0},
energyDeposit{0}, ETDeposit{0}, energyLoss{0};
525 bool eLossFound =
false;
536 std::unique_ptr<const Trk::TrackParameters> paramEntrance{
538 if (!paramEntrance) {
542 const Amg::Vector3D& posVecEntrance = paramEntrance->position();
543 if (!surfEntrance->isOnSurface(posVecEntrance, checkBoundary)) {
546 std::unique_ptr<const Trk::TrackParameters> paramOnInside{
550 paramEntrance.swap(paramOnInside);
558 energyEntrance =
calcEnergy(paramEntrance.get(), muonHypo);
562 std::unique_ptr<const Trk::TrackParameters> paramMiddle{
569 ETDeposit =
cell->et();
573 std::unique_ptr<const Trk::TrackParameters> paramExit;
578 energyExit =
calcEnergy(paramExit.get(), muonHypo);
588 energyExit =
calcEnergy(paramExit.get(), muonHypo);
608 energyLoss = eLossFound ? -(energyExit - energyEntrance) : 0;
614 h.m_hParELossEta->Fill(energyLoss, itP->eta());
615 h.m_hParELossSample->Fill(energyLoss,
sample);
622 ATH_MSG_VERBOSE(
"---TRACKDEPOSITINCALOTOOL---TRACKDEPOSITINCALOTOOL---TRACKDEPOSITINCALOTOOL");
632 double pX =
par->momentum().x();
633 double pY =
par->momentum().y();
634 double pZ =
par->momentum().z();
635 return std::sqrt(
mass *
mass + pX * pX + pY * pY + pZ * pZ);
651 if (
descr->is_lar_em_barrel()) {
653 double thickness =
descr->calo_r_max() -
descr->calo_r_min();
654 double r =
descr->calo_r_min() + thickness / 2.0;
662 double thickness =
descr->calo_z_max() -
descr->calo_z_min();
663 double z =
descr->calo_z_min() + thickness / 2.0;
685 double thickness =
descr->calo_r_max() -
descr->calo_r_min();
686 double r =
descr->calo_r_min() + thickness / 2.0;
703 double x0 = initialPosition.x();
704 double y0 = initialPosition.y();
705 double z0 = initialPosition.z();
708 double c = x0 * x0 + y0 * y0 -
r *
r;
709 double det =
b *
b - 4 *
c;
714 lsin = (-
b + std::sqrt(
det)) / 2;
720 if (std::abs(xe * xe + ye * ye -
r *
r) > 10 &&
det > 0) {
725 return std::make_unique<Amg::Vector3D>(xe, ye, ze);
733 double x0 = initialPosition.x();
734 double y0 = initialPosition.y();
735 double z0 = initialPosition.z();
736 double cosTheta0 =
std::cos(theta0);
738 double dist =
z -
z0;
739 double lambda = dist / cosTheta0;
748 return std::make_unique<Amg::Vector3D>(xe, ye, ze);
760 std::map<double, const CaloDetDescriptor*>& caloInfo,
761 std::vector<Amg::Vector3D>& extrapolations)
const {
770 bool parIsAtSolenoid =
true;
771 if (parIsAtSolenoid) parAtSolenoid =
par;
777 double deltaR_solLast = std::abs(parAtSolenoid->
position().perp() -
par->position().perp());
778 double deltaEta_solLast = std::abs(parAtSolenoid->
position().eta() -
par->position().eta());
781 h.m_hDeltaEtaLastPar->Fill(deltaEta_solLast);
782 h.m_hDeltaRadiusLastPar->Fill(deltaR_solLast);
786 double theta0 = parAtSolenoid->
momentum().theta();
790 for (
const std::pair<
const double, std::vector<const CaloDetDescriptor*>>& mapIt : layerMaps.
m_barrelLayerMap) {
791 const double&
radius = mapIt.first;
793 if (!extrapolation) {
continue; }
795 double zSigned = extrapolation->z() *
descr->calo_sign();
796 if (zSigned >=
descr->calo_z_min() && zSigned <= descr->calo_z_max()) {
797 double distance = (*extrapolation - positionAtSolenoid).
mag();
799 extrapolations.emplace_back(*extrapolation);
805 for (
const std::pair<
const double, std::vector<const CaloDetDescriptor*>>& mapIt : layerMaps.
m_endCapLayerMap) {
806 const double& zCenter = mapIt.first;
808 double z = zCenter *
descr->calo_sign();
809 std::unique_ptr<Amg::Vector3D> extrapolation =
extrapolateZ(positionAtSolenoid,
phi0, theta0,
z);
810 if (!extrapolation)
continue;
812 double radius = extrapolation->perp();
813 if (
radius >=
descr->calo_r_min() && radius <= descr->calo_r_max()) {
814 double distance = (*extrapolation - positionAtSolenoid).
mag();
816 extrapolations.emplace_back(*extrapolation);
822 return StatusCode::FAILURE;
825 return StatusCode::SUCCESS;
841 if (
descr->is_tile() ||
descr->is_lar_em_barrel()) {
843 if (
type >= Entrance &&
type <= Exit) {
844 double thickness =
descr->calo_r_max() -
descr->calo_r_min();
845 double halfLength = (
descr->calo_z_max() -
descr->calo_z_min()) / 2;
846 double middle =
descr->calo_z_min() + halfLength;
852 }
else if (
type == Inside ||
type == Outside) {
854 if (
type == Inside) {
862 ATH_MSG_WARNING(
"Type error in CaloTrkMuIdDetStore::createSurface().");
867 if (
type >= Entrance &&
type <= Exit) {
868 double thickness =
descr->calo_z_max() -
descr->calo_z_min();
872 }
else if (
type == Inside ||
type == Outside) {
874 if (
type == Inside) {
879 double halfLength = (
descr->calo_z_max() -
descr->calo_z_min()) / 2.0;
884 ATH_MSG_WARNING(
"Type error in CaloTrkMuIdDetStore::createSurface().");
908 if (
descr->is_tile()) {
946 std::map<double, const CaloCell*> neighbourMap;
949 double etaPar =
par->position().eta();
950 double phiPar =
par->position().phi();
951 double etaWidth = 2 * (
descr->calo_eta_max() -
descr->calo_eta_min()) /
descr->n_eta();
952 double etaMin = etaPar - etaWidth;
953 double etaMax = etaPar + etaWidth;
963 std::vector<IdentifierHash> vecHash;
967 double dR2Min{ 999 };
976 const double etaCell = dde->
eta();
977 const double phiCell = dde->
phi();
978 const double dEta = etaPar - etaCell;
981 neighbourMap[sqrt(dR2)] =
cell;
991 for (
const std::pair<const double, const CaloCell*>& mapIt : neighbourMap) {
1010 ATH_MSG_FATAL(
"Filling histograms not supported in MT jobs.");
1011 return StatusCode::FAILURE;
1015 m_h = std::make_unique<Hists>();
1017 return StatusCode::SUCCESS;
1025 m_hParELossEta =
new TH2F(
"hParELossEta",
"Parametrized eLoss vs eta", 40, 0, 4000, 30, -3, 3);
1026 m_hParELossSample =
new TH2F(
"hParELossSample",
"Parametrized eLoss vs sample", 40, 0, 4000, 21, 0, 21);
1041 #define H_CHECK(X) if((X).isFailure()) return StatusCode::FAILURE
1062 return StatusCode::SUCCESS;
1082 double halfWidth = domainWidth / 2;
1084 if (std::abs(std::abs(domainCenter) -
M_PI) < domainWidth) {
1086 domainCenter +=
M_PI;
1087 if (position >
M_PI) { position -= 2 *
M_PI; }
1088 if (domainCenter >
M_PI) { domainCenter -= 2 *
M_PI; }
1091 double boundLow = domainCenter - halfWidth;
1092 double boundHigh = domainCenter + halfWidth;
1093 if (position < boundLow)
return false;
1094 if (position > boundHigh)
return false;
1100 if (!dde)
return false;
1125 double diff_x =
p1.x() -
p2.x();
1126 double diff_y =
p1.y() -
p2.y();
1127 double diff_z =
p1.z() -
p2.z();
1128 return std::hypot(diff_x, diff_y, diff_z);