ATLAS Offline Software
PRDHandle_TGC.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "VP1Utils/VP1DetInfo.h"
8 #include "VP1Base/VP1Msg.h"
11 
12 #include <Inventor/nodes/SoSeparator.h>
13 #include <Inventor/nodes/SoTranslation.h>
14 #include <Inventor/nodes/SoTransform.h>
15 
17 
21 
22 
23 //____________________________________________________________________
25  : PRDHandleBase(static_cast<PRDCollHandleBase*>(collhandle)), m_tgc(tgc)
26 {
28 }
29 
30 //____________________________________________________________________
31 SoTransform * PRDHandle_TGC::createTransform() const
32 {
33  const TgcIdHelper * idhelper = VP1DetInfo::tgcIDHelper();
34  const Muon::TgcPrepData * prd = tgc();
35  if (!prd || !idhelper) {
36  return new SoTransform;
37  }
38 
39  const Trk::Surface& theSurface = prd->detectorElement()->surface(prd->identify());
40  SoTransform * theHitTransform =0;
41  if (idhelper->isStrip( prd->identify() )){
42 
43  int stripNo = idhelper->channel(prd->identify());
44  int gasGap = idhelper->gasGap(prd->identify());
45 
46  const MuonGM::TgcReadoutElement* detEl = prd->detectorElement();
47 
48  // calculate two points along the tgc phi strip in the local tgc reference frame
49  const Amg::Vector3D lposTGC = detEl->stripCenterLocX(gasGap, stripNo, 0.) * Amg::Vector3D::UnitX();
50  const double shift = detEl->getStationEta() > 0 ? 1.*Gaudi::Units::cm : - 1.*Gaudi::Units::cm;
51  const Amg::Vector3D lposTgcShifted = detEl->stripCenterLocX(gasGap, stripNo, shift) * Amg::Vector3D::UnitX()+
52  shift * Amg::Vector3D::UnitY();
53  const double angle = (lposTGC - lposTgcShifted).phi();
54  // for phi strips, use sinstereo to get correct orientation
55  Amg::RotationMatrix3D localRot{Amg::RotationMatrix3D::Identity()};
56 
57 
58  // std::ostream os;
59  // std::cout<<localRot.print(os)<<std::endl;
60  //double angle = M_PI/2.0 - asin(prd->detectorElement()->sinStereo(prd->identify())) ;
61  // double angle = asin(prd->detectorElement()->sinStereo(prd->identify())) ;
62  // trying by trial and error to set right component of matrix!
63  // setting theta=PI/4 rotated strips 45deg around z axis, but also a bit around x and y too! So clearly not working as expected.
64 
65  // localRot.setPhi (M_PI/4);
66 
67  if (0 < detEl->getStationEta()) {
68  Amg::setPhi (localRot, angle);
69  } else {
70  Amg::setPhi (localRot, -angle);
71  }
72  // std::cout<<localRot.print(os)<<std::endl;
73  // localRot.setPhi (angle);
74 
75  // VP1Msg::message(QString::number(prd->identify().get_compact())+": angle="+QString::number(angle));
76  localRot*=theSurface.transform().rotation ();
77 
78  Amg::Transform3D trans (localRot, theSurface.transform().translation());
79  // Trk::GlobalDirection difPosGlobal = gpos_shift-gpos;
80  // HepTransform3D toLocal = trans.inverse();
81  // Trk::GlobalDirection difPosLocal = toLocal*difPosGlobal;
82  // Trk::GlobalDirection difPosLocal2 = trans*difPosGlobal;
83 
84  // std::cout << " global strip direction " << difPosGlobal << " local " << difPosLocal << " local2 " << difPosLocal2 << std::endl;
85  theHitTransform = VP1LinAlgUtils::toSoTransform(trans);
86  } else {
87  // eta strips just use surface orientiation
88  theHitTransform = VP1LinAlgUtils::toSoTransform(theSurface.transform());
89  }
90 
91  Amg::Vector3D theHitGPos= theSurface.localToGlobal(prd->localPosition());
92  theHitTransform->translation.setValue((theHitGPos)[0], (theHitGPos)[1], (theHitGPos)[2]);
93  return theHitTransform;
94 }
95 
96 //____________________________________________________________________
97 void PRDHandle_TGC::buildShapes(SoNode*&shape_simple, SoNode*&shape_detailed)
98 {
99  const TgcIdHelper * idhelper = VP1DetInfo::tgcIDHelper();
100  if (!idhelper)
101  return;
102 
103  Identifier id = m_tgc->identify();
104 
105  int plane = idhelper->gasGap( id );
106  int strip = idhelper->channel( id );
107  int isStrip = idhelper->isStrip( id );
108 
109  double striplength =0.0, stripWidth = 0.0;
110 
111  if (isStrip){
112  striplength = m_tgc->detectorElement()->stripLength();
113  stripWidth = m_tgc->detectorElement()->stripWidth(plane, strip);
114  } else {
115  striplength = m_tgc->detectorElement()->gangShortWidth(plane, strip);
116  stripWidth = m_tgc->detectorElement()->gangRadialLength(plane, strip);
117  }
118 
119  if (static_cast<PRDCollHandle_TGC*>(collHandle())->project())
120  striplength += 300.0;//Fixme: Rough extension for now
121 
122  shape_simple = common()->nodeManager()->getShapeNode_Strip(striplength);
123 
124  const bool settingsShowRDOs = true; //FIXME: get from controller
125  SoSeparator * errDetailed = new SoSeparator;
126  const std::vector<Identifier> rdolist = m_tgc->rdoList();
127  if (rdolist.size() == 1 || !settingsShowRDOs)
128  {
129  errDetailed->addChild(common()->nodeManager()->getShapeNode_Strip(striplength,
130  std::max(10.0,stripWidth), //strip width -> fixme: std::max hack for now since stripWidth returns 0.0
131  3*0.8)); //strip thickness - hardcoded to be ~= the gas gap
132  } else
133  {
134  VP1Msg::message("Warning: TGC has additional elements in rdoList: THIS HAS NEVER BEEN TESTED");
135  SoSeparator * rdos = new SoSeparator;
136 
137  const Amg::Vector3D& globalposHIT = m_tgc->detectorElement()->channelPos( id );
138  // get local position on wire plane, here we have to use a tolarance as the wire plane is located 2.5 CLHEP::mm
139  // from the strip plane
140  double tolerance = 3.;
141  std::optional<Amg::Vector2D>localposHIT = m_tgc->detectorElement()->surface( id ).Trk::Surface::globalToLocal(globalposHIT,tolerance);
142  if( !localposHIT )
143  {
144  localposHIT.emplace();
145  localposHIT->setZero();
146  VP1Msg::message("Warning: Local wire position is NULL");
147  }
148 
149  rdos->addChild(common()->nodeManager()->getShapeNode_Strip(striplength,
150  std::max(10.0,stripWidth), //strip width -> fixme: std::max hack for now since stripWidth returns 0.0
151  3*0.8)); //strip thickness - hardcoded to be ~= the gas gap
152 
153  SoTransparency * transparent = new SoTransparency;
154  transparent->transparency.setValue(0.5);
155  rdos->addChild( transparent );
156  Amg::Vector2D localposOLD = *localposHIT;
157  for (const Identifier& rdo_id : rdolist)
158  {
159  if (rdo_id == id )
160  continue;
161  const Amg::Vector3D& globalposRDO = m_tgc->detectorElement()->channelPos( rdo_id );
162  std::optional<Amg::Vector2D> localposRDO = m_tgc->detectorElement()->surface( rdo_id ).Trk::Surface::globalToLocal(globalposRDO,tolerance);
163  if (!localposRDO)
164  {
165  VP1Msg::message("Warning: Local wire position is NULL");
166  continue;
167  }
168 
169  SoTranslation * localtrans = new SoTranslation;
170  localtrans->translation.setValue((*localposRDO)[Trk::locX]-localposOLD[Trk::locX],(*localposRDO)[Trk::locY]-localposOLD[Trk::locY],0);
171  rdos->addChild(localtrans);
172 
173  rdos->addChild(common()->nodeManager()->getShapeNode_Strip(striplength,
174  std::max(10.0,stripWidth), //strip width -> fixme: std::max hack for now since stripWidth returns 0.0
175  3*0.8)); //strip thickness - hardcoded to be ~= the gas gap
176 
177  localposOLD = *localposRDO;
178  }
179  errDetailed->addChild(rdos);
180  }
181  shape_detailed = errDetailed;
182  }
183 
184 //____________________________________________________________________
186  {
187  //Unique for each station.
189  return station->getPhiIndex()-99999*station->getEtaIndex();//hopefully unique.
190  }
HitsSoNodeManager.h
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
SiliconTech::strip
@ strip
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
Trk::locX
@ locX
Definition: ParamDefs.h:37
Trk::locY
@ locY
local cartesian
Definition: ParamDefs.h:38
TgcIdHelper::gasGap
int gasGap(const Identifier &id) const override
get the hashes
Definition: TgcIdHelper.cxx:642
SoTransparency
Definition: SoTransparency.h:20
TgcIdHelper
Definition: TgcIdHelper.h:50
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
VP1Msg.h
PRDHandleBase::collHandle
PRDCollHandleBase * collHandle() const
Definition: PRDHandleBase.cxx:228
PRDCollHandle_TGC
Definition: PRDCollHandle_TGC.h:10
MuonGM::TgcReadoutElement::stripCenterLocX
double stripCenterLocX(int gasGap, int strip, double radialPos) const
Returns the local X of the strip center at a given local radial position.
Definition: MuonDetDescr/MuonReadoutGeometry/src/TgcReadoutElement.cxx:123
Trk::PrepRawData::rdoList
const std::vector< Identifier > & rdoList() const
return the List of rdo identifiers (pointers)
MuonGM::TgcReadoutElement::stripLength
double stripLength() const
Returns the length of each strip which is equal to the height of the chamber.
Muon::TgcPrepData::detectorElement
virtual const MuonGM::TgcReadoutElement * detectorElement() const override final
Returns the detector element corresponding to this PRD The pointer will be zero if the det el is not ...
Definition: TgcPrepData.h:120
SoTransparency.h
PRDHandle_TGC::regionIndex
int regionIndex()
Definition: PRDHandle_TGC.cxx:185
PRDHandleBase::common
PRDSysCommonData * common() const
Definition: PRDHandleBase.h:53
MuonGM::MuonClusterReadoutElement::surface
virtual const Trk::PlaneSurface & surface() const override
access to chamber surface (phi orientation), uses the first gas gap
Definition: MuonClusterReadoutElement.h:123
Amg::setPhi
Amg::RotationMatrix3D setPhi(Amg::RotationMatrix3D mat, double angle, int convention=0)
Definition: EulerAnglesHelpers.h:102
EulerAnglesHelpers.h
SoTransparency::transparency
SoSFFloat transparency
Definition: SoTransparency.h:27
MuonGM::TgcReadoutElement::channelPos
Amg::Vector3D channelPos(const Identifier &id) const
Returns the position of the active channel (wireGang or strip)
TgcIdHelper::channel
int channel(const Identifier &id) const override
Definition: TgcIdHelper.cxx:649
PRDSysCommonData::nodeManager
HitsSoNodeManager * nodeManager() const
Definition: PRDSysCommonData.h:79
VP1LinAlgUtils.h
VP1DetInfo.h
PRDHandle_TGC::tgc
const Muon::TgcPrepData * tgc() const
Definition: PRDHandle_TGC.h:23
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
VP1DetInfo::tgcIDHelper
static const TgcIdHelper * tgcIDHelper()
Definition: VP1DetInfo.cxx:160
GeoPrimitives.h
PRDCollHandleBase
Definition: PRDCollHandleBase.h:25
MuonGM::MuonStation::getPhiIndex
int getPhiIndex() const
a la AMDB
Definition: MuonStation.h:162
MuonGM::TgcReadoutElement::stripWidth
double stripWidth(int gasGap, int strip) const
Returns the width of a given strip in the gasGap i.
Definition: MuonDetDescr/MuonReadoutGeometry/src/TgcReadoutElement.cxx:146
SoTransparency::initClass
static void initClass()
Definition: SoTransparency.cxx:29
angle
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
Definition: TRTDetectorFactory_Full.cxx:73
MuonGM::TgcReadoutElement::gangShortWidth
double gangShortWidth(int gasGap, int gang) const
Returns the length of the most bottom wire in the gang.
Definition: MuonDetDescr/MuonReadoutGeometry/src/TgcReadoutElement.cxx:79
MuonGM::MuonReadoutElement::parentMuonStation
const MuonStation * parentMuonStation() const
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonReadoutElement.cxx:135
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
MuonGM::MuonStation
Definition: MuonStation.h:51
MuonGM::TgcReadoutElement
A TgcReadoutElement corresponds to a single TGC chamber; therefore typically a TGC station contains s...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/TgcReadoutElement.h:42
HitsSoNodeManager::getShapeNode_Strip
SoNode * getShapeNode_Strip(double length, double width=0, double depth=0)
Definition: HitsSoNodeManager.cxx:269
MuonGM::TgcReadoutElement::gangRadialLength
double gangRadialLength(int gasGap, int gang) const
Returns the length of the wire gang along the radial direction [pitch x N_{wire}^{gang}].
Definition: MuonDetDescr/MuonReadoutGeometry/src/TgcReadoutElement.cxx:72
TgcIdHelper::isStrip
int isStrip(const Identifier &id) const
isStrip corresponds to measuresPhi
Definition: TgcIdHelper.cxx:645
CLHEPtoEigenConverter.h
tolerance
Definition: suep_shower.h:17
Trk::PrepRawData::identify
Identifier identify() const
return the identifier
PRDHandle_TGC::m_tgc
const Muon::TgcPrepData * m_tgc
Definition: PRDHandle_TGC.h:30
dumpTgcDigiThreshold.isStrip
list isStrip
Definition: dumpTgcDigiThreshold.py:33
PRDHandle_TGC::createTransform
SoTransform * createTransform() const
Definition: PRDHandle_TGC.cxx:31
Trk::PrepRawData::localPosition
const Amg::Vector2D & localPosition() const
return the local position reference
PRDHandle_TGC::PRDHandle_TGC
PRDHandle_TGC(PRDCollHandle_TGC *, const Muon::TgcPrepData *)
Definition: PRDHandle_TGC.cxx:24
PRDHandle_TGC.h
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
project
T_ResultType project(ParameterMapping::type< N > parameter_map, const T_Matrix &matrix)
Definition: MeasurementSelector.h:142
VP1Msg::message
static void message(const QString &, IVP1System *sys=0)
Definition: VP1Msg.cxx:30
Amg::RotationMatrix3D
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Definition: GeoPrimitives.h:49
MuonGM::MuonStation::getEtaIndex
int getEtaIndex() const
a la AMDB
Definition: MuonStation.h:163
Muon::TgcPrepData
Class to represent TGC measurements.
Definition: TgcPrepData.h:32
PRDHandleBase
Definition: PRDHandleBase.h:35
MuonStation.h
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
VP1LinAlgUtils::toSoTransform
static SoTransform * toSoTransform(const HepGeom::Transform3D &, SoTransform *t=0)
Definition: VP1LinAlgUtils.cxx:40
PRDHandle_TGC::buildShapes
void buildShapes(SoNode *&shape_simple, SoNode *&shape_detailed)
Definition: PRDHandle_TGC.cxx:97
Trk::Surface::localToGlobal
virtual void localToGlobal(const Amg::Vector2D &locp, const Amg::Vector3D &mom, Amg::Vector3D &glob) const =0
Specified by each surface type: LocalToGlobal method without dynamic memory allocation.
MuonGM::MuonReadoutElement::getStationEta
int getStationEta() const
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonReadoutElement.h:193
Identifier
Definition: IdentifierFieldParser.cxx:14