ATLAS Offline Software
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 //____________________________________________________________________
24  : PRDHandleBase(static_cast<PRDCollHandleBase*>(collhandle)), m_cluster(clus)
25 {
27 }
28 
29 //____________________________________________________________________
30 void 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 
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(),
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 //____________________________________________________________________
130 int 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 //____________________________________________________________________
140 SoGroup * 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 }
HitsSoNodeManager.h
VP1ErrorUtils.h
Trk::locX
@ locX
Definition: ParamDefs.h:43
Trk::locY
@ locY
local cartesian
Definition: ParamDefs.h:44
PRDHandle_Pixel.h
VP1ErrorUtils::addRotatedErrorEllipse
static void addRotatedErrorEllipse(SoGroup *gr, const AmgSymMatrix(5)&covmat, const double &sigmaScale, int numNodes=12, const double &translate=0.0, const bool &symmetric=false)
Definition: VP1ErrorUtils.cxx:53
SoTransparency
Definition: SoTransparency.h:20
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
InDetDD::SolidStateDetectorElementBase::center
virtual const Amg::Vector3D & center() const override final
Center in global coordinates.
mat
GeoMaterial * mat
Definition: LArDetectorConstructionTBEC.cxx:53
PRDHandleBase::collHandle
PRDCollHandleBase * collHandle() const
Definition: PRDHandleBase.cxx:228
Trk::PrepRawData::localCovariance
const Amg::MatrixX & localCovariance() const
return const ref to the error matrix
Trk::PrepRawData::rdoList
const std::vector< Identifier > & rdoList() const
return the List of rdo identifiers (pointers)
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
gr
#define gr
SoTransparency.h
PRDHandleBase::common
PRDSysCommonData * common() const
Definition: PRDHandleBase.h:53
InDetDD::SolidStateDetectorElementBase::etaPitch
double etaPitch() const
Pitch (inline methods)
SoTransparency::transparency
SoSFFloat transparency
Definition: SoTransparency.h:27
PRDHandle_Pixel::buildShapes
void buildShapes(SoNode *&shape_simple, SoNode *&shape_detailed)
Definition: PRDHandle_Pixel.cxx:30
GeoPrimitives.h
PRDHandle_Pixel::regionIndex
int regionIndex()
Definition: PRDHandle_Pixel.cxx:130
PRDCollHandleBase
Definition: PRDCollHandleBase.h:25
InDetDD::SiDetectorElement::phiPitch
double phiPitch() const
Pitch (inline methods)
SoTransparency::initClass
static void initClass()
Definition: SoTransparency.cxx:29
PRDHandle_Pixel::createErrorAtPixelCluster
SoGroup * createErrorAtPixelCluster(const double &sigmaScale, const int &numPoints) const
Definition: PRDHandle_Pixel.cxx:140
InDetDD::SolidStateDetectorElementBase::thickness
double thickness() const
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
InDet::SiCluster::detectorElement
virtual const InDetDD::SiDetectorElement * detectorElement() const override final
return the detector element corresponding to this PRD The pointer will be zero if the det el is not d...
Trk::PrepRawData::identify
Identifier identify() const
return the identifier
Trk::PrepRawData::localPosition
const Amg::Vector2D & localPosition() const
return the local position reference
PRDHandle_Pixel::isSane
bool isSane() const
returns false if anything seems weird about the Pixelcluster
Definition: PRDHandle_Pixel.cxx:153
SiDetectorElement.h
InDet::PixelCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:49
PRDCollHandle_Pixel
Definition: PRDCollHandle_Pixel.h:11
InDetDD::SolidStateDetectorElementBase::rawLocalPositionOfCell
Amg::Vector2D rawLocalPositionOfCell(const SiCellId &cellId) const
Returns position (center) of cell.
Definition: SolidStateDetectorElementBase.cxx:230
PRDHandle_Pixel::PRDHandle_Pixel
PRDHandle_Pixel(PRDCollHandle_Pixel *, const InDet::PixelCluster *)
Definition: PRDHandle_Pixel.cxx:23
PRDHandle_Pixel::cluster
const InDet::PixelCluster * cluster() const
Definition: PRDHandle_Pixel.h:23
PRDHandleBase
Definition: PRDHandleBase.h:35
PRDHandle_Pixel::m_cluster
const InDet::PixelCluster * m_cluster
Definition: PRDHandle_Pixel.h:30
PRDCollHandle_Pixel.h