20 return numb > 0 ? 1 : (numb == 0 ? 0 : -1);
45 auto mdtStationIndex = [
this] (
const std::string& stName) {
48 auto tgcStationIndex = [
this] (
const std::string& stName) {
52 const std::set<int> stIndicesEIL{mdtStationIndex(
"EIL"), mdtStationIndex(
"T4E")};
53 const std::set<int> stIndicesEM{mdtStationIndex(
"EML"), mdtStationIndex(
"EMS"),
54 tgcStationIndex(
"T1E"), tgcStationIndex(
"T1F"),
55 tgcStationIndex(
"T2E"), tgcStationIndex(
"T2F"),
56 tgcStationIndex(
"T3E"), tgcStationIndex(
"T3F")};
63 std::vector<MuonReadoutElement*> allReadOutEles =
mgr.getAllReadoutElements();
65 std::vector<defineArgs> muonChamberCandidates{};
72 std::find_if(muonChamberCandidates.begin(), muonChamberCandidates.end(),
73 [
this, readOutEle, &stIndicesEIL, &stIndicesEM, &BOE_ids](
const defineArgs&
args){
74 const MuonReadoutElement* refEle = args.readoutEles[0];
75 const Identifier refId = refEle->identify();
76 const Identifier testId = readOutEle->identify();
78 if (sign(refEle->stationEta()) != sign(readOutEle->stationEta())) {
92 if (readOutEle->stationName() == refEle->stationName()) {
96 if (isNsw(readOutEle) && isNsw(refEle))
return true;
98 if (stIndicesEM.count(readOutEle->stationName()) &&
99 stIndicesEM.count(refEle->stationName())) {
103 if (stIndicesEIL.count(readOutEle->stationName()) &&
104 stIndicesEIL.count(refEle->stationName())) {
110 if (
exist == muonChamberCandidates.end()) {
113 muonChamberCandidates.push_back(std::move(newChamb));
115 exist->readoutEles.push_back(readOutEle);
135 for (
defineArgs& candidate : muonChamberCandidates) {
136 std::vector<Amg::Vector3D> edgePoints{};
137 std::vector<Identifier> reIds{};
139 const Amg::Transform3D toCenter = axisRotation * candidate.readoutEles[0]->globalToLocalTrans(gctx);
140 for (
const MuonReadoutElement*
re : candidate.readoutEles) {
141 const GeoShape* readOutShape =
re->getMaterialGeom()->getLogVol()->getShape();
142 std::vector<Amg::Vector3D> reEdges = m_geoUtilTool->shapeEdges(readOutShape,
143 toCenter *
re->localToGlobalTrans(gctx));
145 std::stringstream edgeStream{};
150 <<m_geoUtilTool->dumpShape(readOutShape)<<std::endl<<std::endl<<edgeStream.str());
152 edgePoints.insert(edgePoints.end(), std::make_move_iterator(reEdges.begin()),
153 std::make_move_iterator(reEdges.end()));
154 reIds.push_back(
re->identify());
157 double minX{1.e6}, minY{1.e6}, minZ{1.e6}, maxX{-1.e6}, maxY{-1.e6}, maxZ{-1.e6}, maxXNegY{-1.e6};;
168 const double midX = 0.5*(minX + maxX);
169 const double midY = 0.5*(minY + maxY);
170 const double midZ = 0.5*(minZ + maxZ);
172 const double hLengthY = 0.5 * (maxY - minY);
173 const double hLengthZ = 0.5 * (maxZ - minZ);
175 candidate.centerTrans = axisRotation.inverse() *
Amg::Translation3D{midX, midY, midZ};
184 maxXNegY =
std::max(maxXNegY, localedge.x());
197 if (std::abs(localedge.y() - refEdge.y()) < 1.e-10)
continue;
199 if (localedge.x() > refEdge.x() ||
200 std::abs(localedge.x() - refEdge.x()) < 1.e-10) {
201 double phi = std::atan2((localedge.y() - refEdge.y()),
202 (localedge.x() - refEdge.x()));
208 candidate.halfXShort = maxXNegY + margin;
209 candidate.halfY = hLengthY + margin;
210 candidate.halfZ = hLengthZ + margin;
211 candidate.halfXLong =
212 candidate.halfXShort + 2 * candidate.halfY /
std::tan(minPhi) + margin;
215 std::stringstream debugStream{};
216 debugStream<<
"minY: "<<minY<<
", maxY: "<<maxY<<
", minZ: "<<minZ<<
", maxZ: "<<maxZ<<
" -- ";
217 debugStream<<candidate<<std::endl;
218 const Amg::Transform3D globChambTrf{candidate.readoutEles[0]->localToGlobalTrans(gctx) * candidate.centerTrans};
219 for (
const MuonReadoutElement* ele: candidate.readoutEles){
220 if(m_idHelperSvc->stationNameString(ele->identify()) ==
"BIR") {
221 const MdtReadoutElement* mdtRe =
static_cast<const MdtReadoutElement*
>(ele);
223 debugStream<<
" *** "<<m_idHelperSvc->toString(ele->identify())<<
" "
224 <<
Amg::toString(globChambTrf.inverse()*mdtRe->highVoltPos(gctx, mdtRe->identify()))
225 <<
" -- "<<
Amg::toString(globChambTrf.inverse()*mdtRe->readOutPos(gctx, mdtRe->identify()))<<std::endl;
227 debugStream<<
" **** "<<m_idHelperSvc->toStringDetEl(ele->identify())<<
", local RE center: "
228 <<
Amg::toString(globChambTrf.inverse() * ele->center(gctx))<<
", global: "
236 mgr.getReadoutElement(chId)->setChamberLink(newChamber);
239 return StatusCode::SUCCESS;