20 std::string
to_string(
const std::vector<T>&
v) {
21 std::stringstream ostr{};
23 for (
auto x:
v)ostr<<
x<<
", ";
30 return (
pars.position().dot(parDir) > 0 ? 1 : -1) * (parDir.dot(
pos));
41 return StatusCode::SUCCESS;
49 for (
unsigned int sector = 1; sector <= 16; ++sector) {
63 using namespace MuonStationIndex;
77 std::unique_ptr<Trk::PlaneSurface> surface = std::make_unique<Trk::PlaneSurface>(trans);
86 surfaces.push_back(std::move(
data));
97 using namespace MuonStationIndex;
99 constexpr
double xToZRotation = -M_PI_2;
109 Amg::Vector3D globalPosition = sectorRotation * positionInSector;
113 trans.pretranslate(globalPosition);
114 std::unique_ptr<Trk::PlaneSurface> surface = std::make_unique<Trk::PlaneSurface>(trans);
119 <<
" ref theta " << globalPosition.theta() <<
" phi " << globalPosition.phi() <<
" r "
120 << globalPosition.perp() <<
" pos " <<
Amg::toString(globalPosition)
125 surfaces.push_back(std::move(
data));
132 if (!cache.candidate->getCaloExtension()) {
133 if (!cache.extensionContainer) {
134 std::unique_ptr<Trk::CaloExtension> caloExtension =
137 ATH_MSG_VERBOSE(
"Failed to create the calo extension for "<<cache.candidate->toString());
140 cache.candidate->setExtension(caloExtension);
143 *cache.extensionContainer);
145 ATH_MSG_VERBOSE(
"Failed to create the calo extension for "<<cache.candidate->toString());
148 cache.candidate->setExtension(caloExtension);
152 if (!cache.createSystemExtension) {
153 ATH_MSG_VERBOSE(
"No system extension is required for "<<cache.candidate->toString());
157 const Trk::TrackParameters* currentPars = cache.candidate->getCaloExtension()->muonEntryLayerIntersection();
164 std::vector<MuonSystemExtension::Intersection> intersections;
167 std::vector<std::shared_ptr<Trk::TrackParameters> > trackParametersVec;
176 <<
" r " << surface.
center().perp() <<
" z " << surface.
center().z());
178 std::unique_ptr<Trk::TrackParameters> exPars{
m_extrapolator->extrapolate(ctx, *currentPars, surface,
184 ATH_MSG_DEBUG(
"Extrapolated in event "<<ctx.eventID().event_number()<<
" track @ "<<
m_printer->print(*exPars));
195 std::shared_ptr<Trk::TrackParameters> sharedPtr{std::move(exPars)};
196 trackParametersVec.emplace_back(sharedPtr);
198 intersections.emplace_back(sharedPtr,
it);
203 currentPars = sharedPtr.get();
205 ATH_MSG_DEBUG(
"Extrapolation reached at "<<
m_printer->print(*sharedPtr)<<
" has larger uncertainties than "<<
209 ATH_MSG_DEBUG(
"Completed extrapolation: destinations " << surfaces.size() <<
" intersections " << intersections.size());
210 if (intersections.empty()){
211 ATH_MSG_DEBUG(
"No system extensions are made for "<<cache.candidate->toString()
212 <<
" will accept the candidate: "<< (!cache.requireSystemExtension ?
"si":
"no"));
213 return !cache.requireSystemExtension;
215 cache.candidate->setExtension(std::make_unique<MuonSystemExtension>(cache.candidate->getCaloExtension()->muonEntryLayerIntersection(),
216 std::move(intersections)));
220 const SystemExtensionCache& cache)
const {
221 using namespace MuonStationIndex;
225 if (
eta < -1.05) regionIndex = DetectorRegionIndex::EndcapC;
226 if (
eta > 1.05) regionIndex = DetectorRegionIndex::EndcapA;
230 std::vector<int> sectors;
234 if (cache.useHitSectors) {
235 const auto map_itr = cache.sectorsWithHits->find(regionIndex);
236 if (map_itr == cache.sectorsWithHits->end()) {
240 std::vector<int>::const_iterator sec_itr = std::find_if(
241 sectors.begin(), sectors.end(), [&map_itr](
const int sector) ->
bool { return map_itr->second.count(sector); });
242 if (sec_itr == sectors.end()) {
244 <<
" in MuonStation " <<
regionName(regionIndex));
249 for (
const int sector : sectors) {
251 surfaces.insert(surfaces.end(), toInsert.begin(), toInsert.end());
253 std::stable_sort(surfaces.begin(), surfaces.end(),
255 return std::abs(pathAlongPars(muonEntryPars,s1.surfacePtr->center())) <
256 std::abs(pathAlongPars(muonEntryPars,s2.surfacePtr->center()));
260 for (
auto& s1 : surfaces) {
263 <<
", pathAlongPars "<<pathAlongPars(muonEntryPars,s1.surfacePtr->center())
264 <<std::endl<<(*s1.surfacePtr));
272 SystemExtensionCache& cache)
const{
280 const Trk::TrackParameters* entryPars = cache.candidate->getCaloExtension()->muonEntryLayerIntersection();
281 std::vector<const Trk::TrackStateOnSurface*> cmbParVec{};
284 std::vector<MuonSystemExtension::Intersection> intersections{};
292 if (!msTSOS->measurementOnTrack()) {
298 if (!
m_idHelperSvc->isMuon(measId) || pathAlongPars(msPars, msPars.position() - entryPars->
position())< 0.){
303 using namespace MuonStationIndex;
306 if (layerIdx == LayerIndex::BarrelExtended) {
314 if (lastSurf.layerIndex == layerIdx && lastSurf.regionIndex == regionIdx && lastSurf.sector == sector) {
318 SurfaceVec::const_iterator surfItr = std::find_if(refSurfaces.begin(), refSurfaces.end(),
320 return surf.layerIndex == layerIdx;
322 if (surfItr == refSurfaces.end()) {
324 <<
", sector: "<<sector <<
", layer: "<<
layerName(layerIdx)
328 lastSurf = (*surfItr);
334 if (!tsosInChamb->measurementOnTrack())
continue;
337 if (std::abs(pathAlongPars(chPars, chPars.position() -
target.center())) >
338 std::abs(pathAlongPars(*msTSOS->trackParameters(),
339 msTSOS->trackParameters()->position() -
target.center()))) {
346 std::unique_ptr<Trk::TrackParameters> exPars{
m_extrapolator->extrapolate(ctx, *msTSOS->trackParameters(),
350 <<
", sector: "<<sector <<
", layer: "<<
layerName(layerIdx)
351 <<
", region index: "<<
regionName(regionIdx) <<
" to surface "<<std::endl<<
target<<std::endl
352 <<
", sector: "<<lastSurf.sector <<
", layer: "<<
layerName(lastSurf.layerIndex)
353 <<
", region index: "<<
regionName(lastSurf.regionIndex)
354 <<
" pathAlongPars "<<pathAlongPars(*msTSOS->trackParameters(),
target.center())
355 <<
", dir: "<<
Amg::toString(msTSOS->trackParameters()->momentum().unit()));
358 intersections.emplace_back(std::move(exPars), lastSurf);
364 if (intersections.empty()) {
365 ATH_MSG_DEBUG(
"Failed to find the intersections for the combined track");
368 cache.candidate->setExtension(std::make_unique<MuonSystemExtension>(entryPars, std::move(intersections)));