ATLAS Offline Software
Loading...
Searching...
No Matches
PRDHandle_Pixel.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
10
11#include <Inventor/nodes/SoSeparator.h>
12#include <Inventor/nodes/SoTranslation.h>
13#include <Inventor/nodes/SoMaterial.h>
14#include <Inventor/nodes/SoLineSet.h>
15
17
19
20
21
22//____________________________________________________________________
28
29//____________________________________________________________________
30void PRDHandle_Pixel::buildShapes(SoNode*&shape_simple, SoNode*&shape_detailed)
31{
32 SoSeparator * errSimple = new SoSeparator;
33 SoSeparator * errDetailed = new SoSeparator;
34
35 if (!isSane()) {
36 std::cerr<<"isSane check failed for PRD: "<<*m_cluster<<std::endl;
37 return;
38 }
39 errSimple->addChild(common()->nodeManager()->getShapeNode_Point());
40
41 Amg::Vector2D localpos = m_cluster->localPosition();
42 Amg::Vector2D localposHIT = m_cluster->detectorElement()->rawLocalPositionOfCell( m_cluster->identify() ); // Lorentz shift is not corrected because this class cannot use SiLorentzAngleTool
43 SoTranslation * localtrans0 = new SoTranslation;
44
45 double xdiff = localposHIT[Trk::locX]-localpos[Trk::locX];
46 double ydiff = localposHIT[Trk::locY]-localpos[Trk::locY];
47
48 if (xdiff!=xdiff || ydiff!=ydiff) {
49 std::cerr<<"NaN is in local pos calc"<<std::endl;
50 if (xdiff!=xdiff) std::cerr<<"X diff"<<std::endl;
51 if (ydiff!=ydiff) std::cerr<<"Y diff"<<std::endl;
52 std::cerr<<"localposHIT:"<<localposHIT<<std::endl;
53 std::cerr<<"localpos:"<<localpos<<std::endl;
54 std::cerr<<"localposHIT[Trk::locX]-localpos[Trk::locX]:"<<xdiff<<std::endl;
55 std::cerr<<"localposHIT[Trk::locY]-localpos[Trk::locY]:"<<ydiff<<std::endl;
56 localtrans0->unref();
57 return;
58 } else {
59 localtrans0->translation.setValue(localposHIT[Trk::locX]-localpos[Trk::locX],localposHIT[Trk::locY]-localpos[Trk::locY],0);
60 }
61
62 const std::vector<Identifier> rdolist = m_cluster->rdoList();
63 if (rdolist.size() == 1 || !collHandle()->drawRDOs())
64 {
65 errDetailed->addChild(localtrans0);
66 //FIXME: dont hardcode thickness
67 errDetailed->addChild(common()->nodeManager()->getShapeNode_Strip(m_cluster->detectorElement()->etaPitch(),m_cluster->detectorElement()->etaPitch(),m_cluster->detectorElement()->thickness()/10.0));
68
69 //Translate back so errDetailed is left sane (eg. when drawing errors later)
70 SoTranslation * localtransBack = new SoTranslation;
71 localtransBack->translation.setValue(-(localtrans0->translation.getValue()));
72 errDetailed->addChild(localtransBack);
73 } else {
74 SoSeparator * rdos = new SoSeparator;
75 rdos->addChild(localtrans0);
76
77 rdos->addChild(common()->nodeManager()->getShapeNode_Strip(m_cluster->detectorElement()->etaPitch(),m_cluster->detectorElement()->phiPitch( m_cluster->localPosition() ),m_cluster->detectorElement()->thickness()/10.0));
78
79 SoTransparency * transparent = new SoTransparency;
80 transparent->transparency.setValue(0.5);
81 rdos->addChild( transparent );
82 Amg::Vector2D localposOLD = localposHIT;
83 for (const Identifier& rdo_id : rdolist)
84 {
85 if (rdo_id == m_cluster->identify() )
86 continue;
87
88 const Amg::Vector2D localposRDO = m_cluster->detectorElement()->rawLocalPositionOfCell(rdo_id); // Lorentz shift is not corrected because this class cannot use SiLorentzAngleTool
89
90 SoTranslation * localtrans = new SoTranslation;
91 localtrans->translation.setValue(localposRDO[Trk::locX]-localposOLD[Trk::locX],
92 localposRDO[Trk::locY]-localposOLD[Trk::locY],
93 0);
94 rdos->addChild(localtrans);
95
96 //FIXME: dont hardcode thickness
97 rdos->addChild(common()->nodeManager()->getShapeNode_Strip(m_cluster->detectorElement()->etaPitch(),
98 m_cluster->detectorElement()->phiPitch( m_cluster->localPosition() ),
99 m_cluster->detectorElement()->thickness()/10.0));
100
101 localposOLD = localposRDO;
102 }
103 errDetailed->addChild(rdos);
104 }
105
106 const double settingsSIGMASCALE=3.0;
107 if (collHandle()->drawErrors())
108 {
109 SoGroup * gr = createErrorAtPixelCluster( settingsSIGMASCALE, 36);
110 if (gr->getNumChildren()==0) {
111 gr->unref();
112 std::cerr<<"Something seems to have gone wrong: no error added. Dumping PRD: "<<*m_cluster<<std::endl;
113 } else {
114 errSimple->addChild( gr );
115 errDetailed->addChild( gr );
116 }
117 }
118
119 //FIXME: hardcoded colour
120 SoMaterial * mat = new SoMaterial;
121 mat->diffuseColor.setValue(1.0,0,0);
122 errDetailed->addChild(mat);
123 errDetailed->addChild(common()->nodeManager()->getShapeNode_Cross(0.1));
124
125 shape_simple = errSimple;
126 shape_detailed = errDetailed;
127}
128
129//____________________________________________________________________
130int PRDHandle_Pixel::regionIndex() { //instead of identifier juggling, we simply discretize by center coordinate.
131 static const double l=200.0;//CLHEP::mm
132 return static_cast<int>(m_cluster->detectorElement()->center().z()/l)
133 +1000*static_cast<int>(m_cluster->detectorElement()->center().y()/l)
134 +1000000*static_cast<int>(m_cluster->detectorElement()->center().x()/l);
135 //Fixme: Use identifiers instead for more intuitive regions.
136}
137
138
139//____________________________________________________________________
140SoGroup * PRDHandle_Pixel::createErrorAtPixelCluster( const double& sigmaScale,
141 const int& numPoints ) const
142{
143 SoGroup * ellipseGrp = new SoSeparator;
144
145 //FIXME: Try to automatically use the pixel height as in PRDHandle_Pixel.cxx (this is just copy paste)
146 // change the last true to false above to get rid of one of the error ellipses
147// VP1ErrorUtils::addRotatedErrorEllipse(ellipseGrp, m_cluster->localErrorMatrix().covariance(), sigmaScale, numPoints,m_cluster->detectorElement()->thickness()/20.0 + 0.001, true);
148 VP1ErrorUtils::addRotatedErrorEllipse(ellipseGrp, m_cluster->localCovariance(), sigmaScale, numPoints,m_cluster->detectorElement()->thickness()/20.0 + 0.001, true);
149
150 return ellipseGrp;
151}
152
154 // check for NaNs
155 bool isSane=true;
156 const InDet::PixelCluster * prd =cluster();
157 if (!prd) return false;
158 if (prd->localPosition()[0]!=prd->localPosition()[0] || prd->localPosition()[1]!=prd->localPosition()[1]){
159 isSane=false;
160 std::cerr<<"For pixel cluster with Id="<<prd->identify()<<", localposition is not sane:"<<(prd->localPosition())<<std::endl;
161 }
162 bool etaNan = std::isnan(m_cluster->detectorElement()->etaPitch());
163 bool phiNan = std::isnan(m_cluster->detectorElement()->phiPitch( m_cluster->localPosition()));
164 bool thickNan = std::isnan(m_cluster->detectorElement()->thickness());
165
166 if ( etaNan || phiNan || thickNan){
167 std::cerr<<"For pixel cluster with Id="<<prd->identify()<<", NaN is in detectorElement pitches "<<std::endl;
168 if (etaNan) std::cerr<<" - eta (which is returning "<<m_cluster->detectorElement()->etaPitch()<<")"<<std::endl;
169 if (phiNan) std::cerr<<" - phi (which is returning "<<m_cluster->detectorElement()->phiPitch(m_cluster->localPosition())<<")"<<std::endl;
170 if (thickNan) std::cerr<<" - thickness (which is returning "<<m_cluster->detectorElement()->thickness()<<")"<<std::endl;
171 }
172
173 return isSane;
174}
#define gr
#define y
#define x
#define z
PRDHandleBase(PRDCollHandleBase *)
PRDSysCommonData * common() const
PRDCollHandleBase * collHandle() const
virtual Amg::Vector3D center() const
void buildShapes(SoNode *&shape_simple, SoNode *&shape_detailed)
const InDet::PixelCluster * m_cluster
SoGroup * createErrorAtPixelCluster(const double &sigmaScale, const int &numPoints) const
const InDet::PixelCluster * cluster() const
PRDHandle_Pixel(PRDCollHandle_Pixel *, const InDet::PixelCluster *)
bool isSane() const
returns false if anything seems weird about the Pixelcluster
static void initClass()
SoSFFloat transparency
const Amg::Vector2D & localPosition() const
return the local position reference
Identifier identify() const
return the identifier
static void addRotatedErrorEllipse(SoGroup *gr, const AmgSymMatrix(5)&covmat, const double &sigmaScale, int numNodes=12, const double &translate=0.0, const bool &symmetric=false)
Eigen::Matrix< double, 2, 1 > Vector2D
@ locY
local cartesian
Definition ParamDefs.h:38
@ locX
Definition ParamDefs.h:37