00001
00002
00003 #include "VisReco/VisRecoGeometry/interface/VisTrackingGeometry.h"
00004 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00007 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00008 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00009 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
00010 #include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h"
00011 #include "DataFormats/GeometrySurface/interface/TkRotation.h"
00012 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00013 #include "Iguana/Inventor/interface/IgSoG4Trap.h"
00014 #include "Iguana/Inventor/interface/IgSoCube.h"
00015 #include <Inventor/nodes/SoCoordinate3.h>
00016 #include <Inventor/nodes/SoIndexedFaceSet.h>
00017 #include <Inventor/nodes/SoIndexedTriangleStripSet.h>
00018 #include <Inventor/nodes/SoMaterial.h>
00019 #include <Inventor/nodes/SoSeparator.h>
00020 #include <Inventor/nodes/SoAnnotation.h>
00021 #include <Inventor/nodes/SoTransform.h>
00022 #include <iostream>
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 SoSeparator*
00035 VisTrackingGeometry::buildDet (DetectorRep type, edm::ESHandle<TrackerGeometry> &pDD, int subDetector)
00036 {
00037 SoSeparator *sep = new SoSeparator;
00038
00039 SoMaterial *mat = new SoMaterial;
00040 mat->ambientColor.setValue (0.88445997, 0.840042, 0.53582799);
00041 mat->diffuseColor.setValue (0.66334498, 0.630032, 0.401871);
00042 mat->specularColor.setValue (0.49999201, 0.49999201, 0.49999201);
00043 mat->emissiveColor.setValue (0, 0, 0);
00044 mat->shininess = 0.1;
00045 mat->transparency = 0;
00046 sep->addChild (mat);
00047
00048 for (TrackingGeometry::DetUnitContainer::const_iterator idet = pDD->detUnits ().begin (); idet != pDD->detUnits ().end (); idet++)
00049 {
00050 if ((**idet).type ().subDetector () == subDetector)
00051 {
00052 if (visible ((*idet)->surface ().position (), type, subDetector))
00053 {
00054 SoSeparator* separator = new SoSeparator;
00055 addWafer (separator, *idet,type);
00056 sep->addChild (separator);
00057 }
00058 }
00059 }
00060 return sep;
00061 }
00062
00063 SoSeparator*
00064 VisTrackingGeometry::buildDet (DetectorRep type, std::vector<const GeomDetUnit *>& detUnits)
00065 {
00066 SoSeparator *sep = new SoSeparator;
00067
00068 SoMaterial *mat = new SoMaterial;
00069 mat->ambientColor.setValue (0.88445997, 0.840042, 0.53582799);
00070 mat->diffuseColor.setValue (0.66334498, 0.630032, 0.401871);
00071 mat->specularColor.setValue (0.49999201, 0.49999201, 0.49999201);
00072 mat->emissiveColor.setValue (0, 0, 0);
00073 mat->shininess = 0.1;
00074 mat->transparency = 0;
00075 sep->addChild (mat);
00076 for (std::vector<const GeomDetUnit *>::const_iterator idet = detUnits.begin (); idet != detUnits.end (); idet++)
00077 {
00078
00079 if (visible ( (*idet)->surface ().position (), type, (**idet).type ().subDetector ()))
00080 {
00081 SoSeparator* separator = new SoSeparator;
00082 addWafer (separator, *idet,type);
00083 sep->addChild (separator);
00084 }
00085 }
00086 return sep;
00087 }
00088
00089 SoAnnotation*
00090 VisTrackingGeometry::buildDet_anno (DetectorRep type, std::vector<const GeomDetUnit *>& detUnits)
00091 {
00092 SoAnnotation *sep = new SoAnnotation;
00093
00094 SoMaterial *mat = new SoMaterial;
00095 mat->ambientColor.setValue (0.88445997, 0.840042, 0.53582799);
00096 mat->diffuseColor.setValue (0.66334498, 0.630032, 0.401871);
00097 mat->specularColor.setValue (0.49999201, 0.49999201, 0.49999201);
00098 mat->emissiveColor.setValue (0, 0, 0);
00099 mat->shininess = 0.1;
00100 mat->transparency = 0;
00101 sep->addChild (mat);
00102 for (std::vector<const GeomDetUnit *>::const_iterator idet = detUnits.begin (); idet != detUnits.end (); idet++)
00103 {
00104 SoAnnotation* separator = new SoAnnotation;
00105 addWafer (separator, *idet, type);
00106 sep->addChild (separator);
00107 }
00108 return sep;
00109 }
00110
00111 bool
00112 VisTrackingGeometry::visible (const GlobalPoint & point, DetectorRep type, int subDetector)
00113 {
00114 bool visible = false;
00115 double width = 1.0;
00116 double length = 10.0;
00117 if (subDetector == GeomDetEnumerators::TOB) width = 10.0;
00118 if (subDetector == GeomDetEnumerators::TIB) width = 5.5;
00119 if (subDetector == GeomDetEnumerators::TID) width = 15.0;
00120 if (subDetector == GeomDetEnumerators::TEC) width = 30.0;
00121 if (subDetector == GeomDetEnumerators::CSC) width = 55.0;
00122
00123
00124 switch (type)
00125 {
00126 case FullDet:
00127 visible = true;
00128
00129
00130 break;
00131 case RZDet:
00132 if (subDetector == GeomDetEnumerators::TID || subDetector == GeomDetEnumerators::TEC) point.x () < width ? visible = true : visible = false;
00133 else {
00134 if(subDetector == GeomDetEnumerators::PixelEndcap)visible = true ; else fabs (point.x ()) < width ? visible = true : visible = false;
00135 }
00136 break;
00137 case RPhiDet:
00138 fabs (point.z ()) < length ? visible = true : visible = false;
00139 break;
00140 case CSCME1:
00141 fabs( point.z ()) < 800. ? visible = true : visible = false;
00142 break;
00143 case CSCME2:
00144 fabs( point.z ()) > 800. && fabs( point.z ()) < 900. ?
00145 visible = true : visible = false;
00146 break;
00147 case CSCME3:
00148 fabs( point.z ()) > 900. && fabs( point.z ()) < 1000. ?
00149 visible = true : visible = false;
00150 break;
00151
00152 case CSCME4:
00153 fabs( point.z ()) > 1000. ? visible = true : visible = false;
00154 break;
00155 default:
00156 break;
00157 }
00158
00159 return visible;
00160 }
00161
00163 void
00164 VisTrackingGeometry::addWafer (SoSeparator *separator, const GeomDetUnit *det, DetectorRep type)
00165 {
00166
00167 float posx = det->surface ().position ().x () / 100.0;
00168 float posy = det->surface ().position ().y () / 100.0;
00169 float posz = det->surface ().position ().z () / 100.0;
00170 if(type==RZDet) {posx=0;posy=sqrt(det->surface ().position ().x ()*det->surface ().position ().x ()+det->surface ().position ().y ()*det->surface ().position ().y ()) / 100.0; if (det->surface ().position ().y () < 0.0)posy = - posy;}
00171 float angle;
00172 SbVec3f axis;
00173 createRotation (det, axis, angle);
00174 SoTransform *transform = new SoTransform;
00175 transform->translation.setValue (posx, posy, posz);
00176 if(type==RZDet){
00177 int subdet = det->geographicalId().subdetId();
00178 if(subdet==1 || subdet==3 || subdet==5)
00179 {
00180 SbMatrix sbm (1, 0, 0, 0,
00181 0, 0, -1, 0,
00182 0, 1, 0, 0,
00183 0, 0, 0, 1);
00184 SbRotation sbr (sbm);
00185 sbr.getValue (axis, angle);
00186 transform->rotation.setValue (axis, angle);
00187 } else transform->rotation.setValue (axis, angle);
00188 } else transform->rotation.setValue (axis, angle);
00189
00190
00191 const Bounds *b = &((det->surface ()).bounds ());
00192 if (dynamic_cast<const TrapezoidalPlaneBounds *> (b))
00193 {
00194 const TrapezoidalPlaneBounds *b2 = dynamic_cast<const TrapezoidalPlaneBounds *> (b);
00195 std::vector< float > par = b2->parameters ();
00196
00197
00198 float hBottomEdge = par [0];
00199 float hTopEdge = par [1];
00200 float thickness = par [2];
00201 float apothem = par [3];
00202
00203 IgSoG4Trap *g4Trap = new IgSoG4Trap ();
00204 g4Trap->dz = thickness / 100.;
00205 g4Trap->dy1 = apothem / 100.;
00206 g4Trap->dy2 = apothem / 100.;
00207 g4Trap->dx1 = hBottomEdge / 100.;
00208 g4Trap->dx2 = hTopEdge / 100.;
00209 g4Trap->dx3 = hBottomEdge / 100.;
00210 g4Trap->dx4 = hTopEdge / 100.;
00211 g4Trap->alp1 = 0.0;
00212 g4Trap->alp2 = 0.0;
00213 separator->addChild (transform);
00214 separator->addChild (g4Trap);
00215 }
00216 if (dynamic_cast<const RectangularPlaneBounds *> (b))
00217 {
00218 IgSoCube *cube = new IgSoCube ();
00219
00220
00221 float length = det->surface ().bounds ().length () / 100.0;
00222 float width = det->surface ().bounds ().width () / 100.0;
00223 float thickness = det->surface ().bounds ().thickness () / 100.0;
00224
00225 transform->scaleFactor.setValue (width, length, thickness);
00226 separator->addChild (transform);
00227 separator->addChild (cube);
00228 }
00229 }
00230
00232 void
00233 VisTrackingGeometry::createRotation (const GeomDetUnit *det, SbVec3f & axis, float & angle)
00234 {
00235
00236
00237 TkRotation< float > rot = det->surface ().rotation ();
00238 Basic3DVector< float > nx (1., 0., 0.);
00239 Basic3DVector< float > ny (0., 1., 0.);
00240 Basic3DVector< float > nz (0., 0., 1.);
00241 Basic3DVector< float > px = rot * nx;
00242 Basic3DVector< float > py = rot * ny;
00243 Basic3DVector< float > pz = rot * nz;
00244
00245
00246
00247
00248
00249
00250
00251
00252 SbMatrix sbm (px.x (), py.x (), pz.x (), 0,
00253 px.y (), py.y (), pz.y (), 0,
00254 px.z (), py.z (), pz.z (), 0,
00255 0, 0, 0, 1);
00256 SbRotation sbr (sbm);
00257
00258 float x;
00259 float y;
00260 float z;
00261
00262 sbr.getValue (axis, angle);
00263 axis.getValue (x, y, z);
00264 }
00265
00267 void
00268 VisTrackingGeometry::addBoxWafer (SoSeparator *separator, const GeomDetUnit *det)
00269 {
00270 const int NVERT = 8;
00271
00272 Basic3DVector< float > nx (1., 0., 0.);
00273 Basic3DVector< float > ny (0., 1., 0.);
00274 Basic3DVector< float > nz (0., 0., 1.);
00275
00276 float posx = 0.;
00277 float posy = 0.;
00278 float posz = 0.;
00279 float x = 0.;
00280 float y = 0.;
00281 float z = 0.;
00282
00283 static int faceIndices[] =
00284 {0, 4, 3, 7, 2, 6, 1, 5, 0, 4, SO_END_FACE_INDEX,
00285 1, 0, 2, 3, SO_END_FACE_INDEX,
00286 6, 7, 5, 4, SO_END_FACE_INDEX
00287 };
00288
00289 static SoIndexedTriangleStripSet *detFaceSet = 0;
00290 if (detFaceSet == 0)
00291 {
00292 detFaceSet = new SoIndexedTriangleStripSet;
00293 detFaceSet->coordIndex.setValues(0, sizeof (faceIndices)/sizeof (int), faceIndices);
00294 }
00295
00296 TkRotation< float > detRot = det->surface ().rotation ();
00297 Basic3DVector< float > px = detRot * nx;
00298 Basic3DVector< float > py = detRot * ny;
00299 Basic3DVector< float > pz = detRot * nz;
00300
00301
00302 SbMatrix rotMatrix (px.x (), py.x (), pz.x (), 0,
00303 px.y (), py.y (), pz.y (), 0,
00304 px.z (), py.z (), pz.z (), 0,
00305 0, 0, 0, 1);
00306
00307
00308 posx = det->surface ().position ().x () / 100.0;
00309 posy = det->surface ().position ().y () / 100.0;
00310 posz = det->surface ().position ().z () / 100.0;
00311
00312 x = det->surface ().bounds ().width () / 100.0;
00313 y = det->surface ().bounds ().length () / 100.0;
00314 z = det->surface ().bounds ().thickness () / 100.0;
00315
00316 SbVec3f points [NVERT] = {
00317 SbVec3f ( 0.5f, -0.5f, -0.5f),
00318 SbVec3f ( 0.5f, 0.5f, -0.5f),
00319 SbVec3f ( 0.5f, 0.5f, 0.5f),
00320 SbVec3f ( 0.5f, -0.5f, 0.5f),
00321 SbVec3f (-0.5f, -0.5f, -0.5f),
00322 SbVec3f (-0.5f, 0.5f, -0.5f),
00323 SbVec3f (-0.5f, 0.5f, 0.5f),
00324 SbVec3f (-0.5f, -0.5f, 0.5f)
00325 };
00326
00327 SoMFVec3f vertexData;
00328 vertexData.setValues (0, NVERT, points);
00329
00330 SoCoordinate3 *detCoords = new SoCoordinate3;
00331 detCoords->point = vertexData;
00332
00333 SoTransform *detTransform = new SoTransform;
00334 detTransform->translation.setValue (posx, posy, posz);
00335 detTransform->rotation = SbRotation (rotMatrix);
00336 detTransform->scaleFactor.setValue (x, y, z);
00337
00338
00339 SoSeparator *facesNode = new SoSeparator;
00340 facesNode->addChild (detTransform);
00341 facesNode->addChild (detCoords);
00342 facesNode->addChild (detFaceSet);
00343
00344 separator->addChild (facesNode);
00345 }
00346
00347 int
00348 VisTrackingGeometry::subDetector (const std::string &key)
00349 {
00350 std::map<std::string, GeomDetEnumerators::SubDetector> type;
00351
00352 type ["PixelBarrel"] = GeomDetEnumerators::PixelBarrel;
00353 type ["TIB"] = GeomDetEnumerators::TIB;
00354 type ["TOB"] = GeomDetEnumerators::TOB;
00355 type ["PixelEndcap"] = GeomDetEnumerators::PixelEndcap;
00356 type ["TID"] = GeomDetEnumerators::TID;
00357 type ["TEC"] = GeomDetEnumerators::TEC;
00358 type ["CSC"] = GeomDetEnumerators::CSC;
00359
00360 return type [key];
00361 }