46 #include "TGeoManager.h"
48 #include "TGeoMatrix.h"
55 #include "TEveVector.h"
56 #include "TEveTrans.h"
61 typedef std::map< const float*, TGeoVolume*> CaloVolMap;
75 void AddLeafNode(TGeoVolume* mother, TGeoVolume* daughter,
const char*
name, TGeoMatrix* mtx )
77 int n = mother->GetNdaughters();
78 mother->AddNode(daughter, 1, mtx);
79 mother->GetNode(n)->SetName(name);
83 TGeoCombiTrans* createPlacement(
const GeomDet *det )
90 TGeoTranslation
trans( posx, posy, posz );
97 const Double_t
matrix[9] = { detRot.
xx(), detRot.
yx(), detRot.
zx(),
98 detRot.
xy(), detRot.
yy(), detRot.
zy(),
99 detRot.
xz(), detRot.
yz(), detRot.
zz()
101 rotation.SetMatrix( matrix );
103 return new TGeoCombiTrans(
trans, rotation );
114 if (mother->GetNdaughters()) {
115 TGeoNode* n = mother->FindNode(Form(
"%s_%d_1", prefix,
id));
116 if ( n ) res = n->GetVolume();
120 res =
new TGeoVolumeAssembly( Form(
"%s_%d", prefix,
id ));
122 mother->AddNode(res, 1);
131 if (mother->GetNdaughters()) {
132 TGeoNode* n = mother->FindNode(Form(
"%s_1",prefix));
133 if ( n ) res = n->GetVolume();
138 res =
new TGeoVolumeAssembly(prefix);
140 mother->AddNode(res, 1);
157 std::map<ERecoDet, TGeoMedium*>::iterator it =
m_recoMedium.find(det);
207 printf(
"invalid medium id \n");
211 TGeoMaterial* mat =
new TGeoMaterial(name.c_str(), 0, 0, 0);
213 m_recoMedium[det] =
new TGeoMedium(name.c_str(), 0, mat);
214 mat->SetFillStyle(3000);
225 boost::shared_ptr<FWTGeoRecoGeometry>
238 TGeoManager*
geom =
new TGeoManager(
"cmsGeo",
"CMS Detector" );
239 if( 0 == gGeoIdentity )
241 gGeoIdentity =
new TGeoIdentity(
"Identity" );
247 TGeoMaterial *vacuum =
new TGeoMaterial(
"Vacuum", 0 ,0 ,0 );
256 return boost::shared_ptr<FWTGeoRecoGeometry>();
260 top->SetVisibility( kFALSE );
261 top->SetLineColor( kBlue );
278 <<
"addGEMGeometry() Exception caught while building GEM geometry: " << exception.
what()
288 geom->CloseGeometry();
290 geom->DefaultColors();
291 geom->CloseGeometry();
300 TGeoShape* shape = 0;
307 std::array< const float, 4 >
const & par = b2->
parameters ();
310 float hBottomEdge = par [0];
311 float hTopEdge = par [1];
312 float thickness = par [2];
313 float apothem = par [3];
317 << hBottomEdge <<
"_"
328 shape =
new TGeoTrap(
345 if( dynamic_cast<const RectangularPlaneBounds *> (b) != 0 )
364 shape =
new TGeoBBox( name.c_str(), width / 2., length / 2., thickness / 2. );
379 std::map<TGeoShape*, TGeoVolume*>::iterator vIt =
m_shapeToVolume.find(solid);
383 TGeoVolume* volume =
new TGeoVolume( name.c_str(),solid,
GetMedium(mid));
413 unsigned int rawid = detid.
rawId();
422 AddLeafNode(holder, child, name.c_str(), createPlacement( *it ));
454 AddLeafNode(holder, child, name.c_str(), createPlacement( *it ));
483 AddLeafNode(holder, child, name.c_str(), createPlacement( *it ));
509 AddLeafNode(holder, child, name.c_str(), createPlacement( *it ));
534 AddLeafNode(holder, child, name.c_str(), createPlacement( *it ));
562 AddLeafNode(holder, child, name.c_str(), createPlacement( *it ));
585 for(
auto it = dtChamberGeom.begin(),
586 end = dtChamberGeom.end();
589 if(
auto chamber = dynamic_cast< const DTChamber *>(*it))
601 AddLeafNode(holder, child, name.c_str(), createPlacement( chamber));
610 for(
auto it = dtSuperLayerGeom.begin(),
611 end = dtSuperLayerGeom.end();
614 if(
auto * superlayer = dynamic_cast<const DTSuperLayer*>(*it))
627 AddLeafNode(holder, child, name.c_str(), createPlacement( superlayer));
635 for(
auto it = dtLayerGeom.begin(),
636 end = dtLayerGeom.end();
639 if(
auto layer = dynamic_cast<const DTLayer*>(*it))
655 AddLeafNode(holder, child, name.c_str(), createPlacement( layer));
666 throw cms::Exception(
"FatalError" ) <<
"Cannnot find CSCGeometry\n";
673 for(
auto it = cscGeom.begin(), itEnd = cscGeom.end(); it != itEnd; ++it )
675 unsigned int rawid = (*it)->geographicalId();
681 TGeoVolume*
child = 0;
683 if(
auto chamber = dynamic_cast<const CSCChamber*>(*it))
685 else if(
auto * layer = dynamic_cast<const CSCLayer*>(*it))
697 AddLeafNode(holder, child, name.c_str(), createPlacement(*it));
735 AddLeafNode(holder, child, name.c_str(), createPlacement(*it));
751 for(
auto it = rpcGeom->
rolls().begin(),
772 AddLeafNode(holder, child, name.c_str(), createPlacement(*it));
780 double etatotheta(
double eta)
782 using namespace TMath;
785 return 3.14 - 2*ATan(Exp(-
Abs(eta)));
787 return 2*ATan(Exp(-
Abs(eta)));
804 CaloVolMap caloShapeMapP;
805 CaloVolMap caloShapeMapN;
806 for( std::vector<DetId>::const_iterator it = vid.begin(),
end = vid.end(); it !=
end; ++it)
814 if (!cell) { printf (
"HB not olique !!!\n");
continue; }
816 TGeoVolume* volume = 0;
817 CaloVolMap& caloShapeMap = (cell->
etaPos() > 0) ? caloShapeMapP : caloShapeMapN;
818 CaloVolMap::iterator volIt = caloShapeMap.find(cell->
param());
819 if (volIt == caloShapeMap.end())
825 HepGeom::Vector3D<float> lCenter;
826 for(
int c = 0;
c < 8; ++
c)
830 static const int arr[] = { 1, 0, 3, 2, 5, 4, 7, 6 };
832 for (
int c = 0;
c < 8; ++
c) {
834 points[
c*2 + 0 ] = -(lc[arr[
c]].
z() - lCenter.z());
836 points[
c*2 + 0 ] = (lc[arr[
c]].z() - lCenter.z());
838 points[
c*2 + 1 ] = (lc[arr[
c]].y() - lCenter.y());
842 float dz = (lc[4].x() -lc[0].x()) * 0.5;
843 TGeoShape* solid =
new TGeoArb8(dz, &points[0]);
844 volume =
new TGeoVolume(
"hcal oblique prism", solid,
GetMedium(
kHCal));
845 caloShapeMap[cell->
param()] = volume;
849 volume = volIt->second;
853 HepGeom::Vector3D<float> gCenter;
855 for (
int c = 0;
c < 8; ++
c)
856 gCenter += HepGeom::Vector3D<float>(gc[
c].
x(), gc[
c].
y(), gc[
c].
z());
859 TGeoTranslation gtr(gCenter.x(), gCenter.y(), gCenter.z());
864 rotPhi.SetAngles(0, -cell->
phiPos()*TMath::RadToDeg(), 0);
865 rot.MultiplyBy(&rotPhi);
869 std::stringstream nname;
871 AddLeafNode(holder, volume, nname.str().c_str(),
new TGeoCombiTrans(gtr, rot));
884 CaloVolMap caloShapeMapP;
885 CaloVolMap caloShapeMapN;
892 for( std::vector<DetId>::const_iterator it = vid.begin(),
end = vid.end(); it !=
end; ++it)
897 if (!cell) { printf (
"EC not olique \n");
continue; }
899 TGeoVolume* volume = 0;
900 CaloVolMap& caloShapeMap = (cell->etaPos() > 0) ? caloShapeMapP : caloShapeMapN;
901 CaloVolMap::iterator volIt = caloShapeMap.find(cell->param());
902 if ( volIt == caloShapeMap.end())
907 HepGeom::Vector3D<float> lCenter;
908 for(
int c = 0;
c < 8; ++
c)
916 static const int arrP[] = { 3, 2, 1, 0, 7, 6, 5, 4 };
917 static const int arrN[] = { 7, 6, 5, 4 ,3, 2, 1, 0};
918 const int* arr = (detid.
ieta() > 0) ? &arrP[0] : &arrN[0];
921 for (
int c = 0;
c < 8; ++
c) {
922 points[
c*2 + 0 ] = lc[arr[
c]].x() - lCenter.x();
923 points[
c*2 + 1 ] = lc[arr[
c]].y() - lCenter.y();
926 float dz = (lc[4].z() -lc[0].z()) * 0.5;
927 TGeoShape* solid =
new TGeoArb8(dz, &points[0]);
928 volume =
new TGeoVolume(
"ecal oblique prism", solid,
GetMedium(
kHCal));
929 caloShapeMap[cell->param()] = volume;
933 volume = volIt->second;
937 HepGeom::Vector3D<float> gCenter;
939 for (
int c = 0;
c < 8; ++
c) {
940 gCenter += HepGeom::Vector3D<float>(gc[
c].x(), gc[
c].y(), gc[
c].z());
945 TGeoTranslation gtr(gCenter.x(), gCenter.y(), gCenter.z());
947 rot.SetAngles(cell->phiPos()*TMath::RadToDeg(), 0, 0);
951 std::stringstream nname;
953 AddLeafNode(holder, volume, nname.str().c_str(),
new TGeoCombiTrans(gtr, rot));
966 for (
int i = 0;
i < 8; ++
i)
967 gCenter += TEveVector(gc[
i].
x(), gc[
i].
y(), gc[
i].
z());
971 for (
int i = 4;
i < 8; ++
i)
972 tgCenter += TEveVector(gc[
i].
x(), gc[
i].
y(), gc[
i].
z());
976 TEveVector axis = tgCenter - gCenter;
981 tr.GetBaseVec(1, v1t);
984 TEveVector v1(v1t.x(), v1t.y(), v1t.z());
985 double dot13 = axis.Dot(v1);
986 TEveVector gd = axis;
991 TMath::Cross(v1.Arr(), axis.Arr(), v2.Arr());
992 TMath::Cross(axis.Arr(), v1.Arr(), v2.Arr());
995 tr.SetBaseVec(1, v1.fX, v1.fY, v1.fZ);
996 tr.SetBaseVec(2, v2.fX, v2.fY, v2.fZ);
997 tr.SetBaseVec(3, axis.fX, axis.fY, axis.fZ);
998 tr.Move3PF(gCenter.fX, gCenter.fY, gCenter.fZ);
1000 TGeoHMatrix*
out =
new TGeoHMatrix();
1001 tr.SetGeoHMatrix(*out);
1009 const HepGeom::Transform3D idtr;
1017 for(
int c = 0;
c < 8; ++
c )
1019 points[
c*2 ] = co[
c].x();
1020 points[
c*2+1] = co[
c].y();
1022 TGeoShape* solid =
new TGeoArb8(cell->
param()[0], points);
1035 CaloVolMap caloShapeMap;
1041 for( std::vector<DetId>::const_iterator it = vid.begin(),
end = vid.end(); it !=
end; ++it)
1045 if (!cell) { printf(
"ecalBarrel cell not a TruncatedPyramid !!\n");
return; }
1047 TGeoVolume* volume = 0;
1048 CaloVolMap::iterator volIt = caloShapeMap.find(cell->
param());
1049 if ( volIt == caloShapeMap.end())
1052 caloShapeMap[cell->
param()] = volume;
1055 volume = volIt->second;
1060 std::stringstream nname;
1062 AddLeafNode(holder, volume, nname.str().c_str(), mtx);
1071 for( std::vector<DetId>::const_iterator it = vid.begin(),
end = vid.end(); it !=
end; ++it)
1075 if (!cell) { printf(
"ecalEndcap cell not a TruncatedPyramid !!\n");
continue;}
1077 TGeoVolume* volume = 0;
1078 CaloVolMap::iterator volIt = caloShapeMap.find(cell->
param());
1079 if ( volIt == caloShapeMap.end())
1083 caloShapeMap[cell->
param()] = volume;
1086 volume = volIt->second;
1091 std::stringstream nname;
1093 AddLeafNode(holder, volume, nname.str().c_str(), mtx);
virtual char const * what() const
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
TGeoMedium * m_dummyMedium
const TrackerGeometry * m_trackerGeom
virtual float length() const =0
virtual const std::array< const float, 4 > parameters() const
edm::ESHandle< CaloGeometry > m_caloGeom
edm::ESHandle< GlobalTrackingGeometry > m_geomRecord
int zside() const
get the z-side of the cell (1/-1)
TGeoShape * createShape(const GeomDet *det)
const std::vector< const RPCRoll * > & rolls() const
Return a vector of all RPC rolls.
virtual ~FWTGeoRecoGeometryESProducer(void)
CaloCellGeometry::Pt3D Pt3D
const Bounds & bounds() const
std::map< TGeoShape *, TGeoVolume * > m_shapeToVolume
const Plane & surface() const
The nominal surface of the GeomDet.
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
unsigned int layer() const
layer id
uint32_t rawId() const
get the raw id
virtual float thickness() const =0
const DepRecordT & getRecord() const
TGeoMedium * GetMedium(ERecoDet)
const CCGFloat * param() const
CaloCellGeometry::Pt3D Pt3D
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
const DetContainer & detsTEC() const
TGeoHMatrix * getEcalTrans(CaloCellGeometry::CornersVec const &gc)
void addEcalCaloGeometry()
std::map< std::string, TGeoShape * > m_nameToShape
CaloCellGeometry::Pt3DVec Pt3DVec
int ieta() const
get the cell ieta
const DetContainer & detsPXB() const
unsigned int module() const
det id
const std::vector< const GEMEtaPartition * > & etaPartitions() const
Return a vector of all GEM chambers.
DetId geographicalId() const
The label of this GeomDet.
void addHcalCaloGeometryBarrel()
int ieta() const
get the crystal ieta
std::map< ERecoDet, TGeoMedium * > m_recoMedium
const DetContainer & detsTIB() const
TGeoShape * makeEcalShape(const TruncatedPyramid *cell)
TGeoVolume * GetDaughter(TGeoVolume *mother, const char *prefix, ERecoDet cidx, int id)
boost::shared_ptr< FWTGeoRecoGeometry > produce(const FWTGeoRecoGeometryRecord &)
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code...
boost::shared_ptr< FWTGeoRecoGeometry > m_fwGeometry
void addPixelForwardGeometry()
FWTGeoRecoGeometryESProducer(const edm::ParameterSet &)
const DetContainer & detsPXF() const
const DetContainer & detsTOB() const
const RotationType & rotation() const
TGeoVolume * GetTopHolder(const char *prefix, ERecoDet cidx)
const CornersVec & getCorners() const
Returns the corner points of this cell's volume.
virtual float width() const =0
const PositionType & position() const
void addHcalCaloGeometryEndcap()
void addPixelBarrelGeometry()
CaloCellGeometry::Pt3DVec Pt3DVec
TGeoVolume * createVolume(const std::string &name, const GeomDet *det, ERecoDet=kDummy)
const DetContainer & detsTID() const
int zside() const
get the z-side of the crystal (1/-1)