Go to the documentation of this file.00001 #include "Geometry/EcalTestBeam/plugins/EcalTBHodoscopeGeometryLoaderFromDDD.h"
00002
00003 #include "Geometry/EcalTestBeam/interface/EcalTBHodoscopeGeometry.h"
00004 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
00005
00006 #include "DetectorDescription/Core/interface/DDFilteredView.h"
00007 #include "DetectorDescription/Core/interface/DDFilter.h"
00008 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00009 #include "DetectorDescription/Core/interface/DDSolid.h"
00010 #include "DetectorDescription/Core/interface/DDTransform.h"
00011 #include "DetectorDescription/Core/interface/DDExpandedView.h"
00012 #include "DetectorDescription/Core/interface/DDName.h"
00013
00014
00015 typedef CaloCellGeometry::CCGFloat CCGFloat ;
00016
00017 #include <iostream>
00018 #include <vector>
00019
00020 std::auto_ptr<CaloSubdetectorGeometry>
00021 EcalTBHodoscopeGeometryLoaderFromDDD::load( const DDCompactView* cpv )
00022 {
00023 std::cout << "[EcalTBHodoscopeGeometryLoaderFromDDD]:: start the construction of EcalTBHodoscope" << std::endl;
00024
00025 std::auto_ptr<CaloSubdetectorGeometry> ebg
00026 ( new EcalTBHodoscopeGeometry() ) ;
00027
00028 makeGeometry( cpv, ebg.get() ) ;
00029
00030 std::cout << "[EcalTBHodoscopeGeometryLoaderFromDDD]:: Returning EcalTBHodoscopeGeometry" << std::endl;
00031
00032 return ebg;
00033 }
00034
00035 void
00036 EcalTBHodoscopeGeometryLoaderFromDDD::makeGeometry(
00037 const DDCompactView* cpv ,
00038 CaloSubdetectorGeometry* ebg )
00039 {
00040 if( ebg->cornersMgr() == 0 ) ebg->allocateCorners( CaloTowerDetId::kSizeForDenseIndexing ) ;
00041 if( ebg->parMgr() == 0 ) ebg->allocatePar( 10, 3 ) ;
00042
00043 DDFilter* filter = getDDFilter();
00044
00045 DDFilteredView fv(*cpv);
00046 fv.addFilter(*filter);
00047
00048 bool doSubDets;
00049 for (doSubDets = fv.firstChild(); doSubDets ; doSubDets = fv.nextSibling())
00050 {
00051
00052 #if 0
00053 std::string answer = getDDDString("ReadOutName",&fv);
00054 if (answer != "EcalTBH4BeamHits")
00055 continue;
00056 #endif
00057
00058 const DDSolid & solid = fv.logicalPart().solid();
00059
00060 if( solid.shape() != ddbox )
00061 {
00062 throw DDException(std::string(__FILE__)
00063 +"\n CaloGeometryEcalTBHodoscope::upDate(...): currently only box fiber shapes supported ");
00064 edm::LogWarning("EcalTBHodoscopeGeometry") << "Wrong shape for sensitive volume!" << solid;
00065 }
00066
00067 std::vector<double> pv = solid.parameters();
00068
00069
00070
00071
00072 DD3Vector x, y, z;
00073 fv.rotation().GetComponents(x,y,z);
00074 CLHEP::Hep3Vector hx(x.X(), x.Y(), x.Z());
00075 CLHEP::Hep3Vector hy(y.X(), y.Y(), y.Z());
00076 CLHEP::Hep3Vector hz(z.X(), z.Y(), z.Z());
00077 CLHEP::HepRotation hrot(hx, hy, hz);
00078 CLHEP::Hep3Vector htran ( fv.translation().X(),
00079 fv.translation().Y(),
00080 fv.translation().Z() );
00081
00082 const HepGeom::Transform3D ht3d ( hrot,
00083 CaloCellGeometry::k_ScaleFromDDDtoGeant*htran ) ;
00084
00085 const HepGeom::Point3D<float> ctr (
00086 ht3d*HepGeom::Point3D<float> (0,0,0) ) ;
00087
00088 const GlobalPoint refPoint ( ctr.x(), ctr.y(), ctr.z() ) ;
00089
00090 std::vector<CCGFloat> vv ;
00091 vv.reserve( pv.size() + 1 ) ;
00092 for( unsigned int i ( 0 ) ; i != pv.size() ; ++i )
00093 {
00094 vv.push_back( CaloCellGeometry::k_ScaleFromDDDtoGeant*pv[i] ) ;
00095 }
00096 vv.push_back( 0. ) ;
00097 const CCGFloat* pP ( CaloCellGeometry::getParmPtr( vv,
00098 ebg->parMgr(),
00099 ebg->parVecVec() ) ) ;
00100
00101 const DetId detId ( getDetIdForDDDNode(fv) ) ;
00102
00103
00104
00105 ebg->newCell( refPoint, refPoint, refPoint,
00106 pP,
00107 detId ) ;
00108 }
00109 }
00110
00111 unsigned int
00112 EcalTBHodoscopeGeometryLoaderFromDDD::getDetIdForDDDNode(
00113 const DDFilteredView &fv )
00114 {
00115
00116
00117 DDGeoHistory parents = fv.geoHistory();
00118
00119 assert(parents.size() >= 3);
00120
00121 EcalBaseNumber baseNumber;
00122
00123
00124 for( unsigned int i=1 ;i <= parents.size(); i++)
00125 {
00126 baseNumber.addLevel( parents[ parents.size() - i ].logicalPart().name().name(),
00127 parents[ parents.size() - i ].copyno() ) ;
00128 }
00129
00130 return _scheme.getUnitID( baseNumber ) ;
00131 }
00132
00133 DDFilter* EcalTBHodoscopeGeometryLoaderFromDDD::getDDFilter()
00134 {
00135 DDSpecificsFilter *filter = new DDSpecificsFilter();
00136
00137 filter->setCriteria( DDValue( "SensitiveDetector",
00138 "EcalTBH4BeamDetector",
00139 0 ),
00140 DDSpecificsFilter::equals,
00141 DDSpecificsFilter::AND,
00142 true,
00143 true ) ;
00144
00145 filter->setCriteria( DDValue( "ReadOutName",
00146 "EcalTBH4BeamHits",
00147 0 ),
00148 DDSpecificsFilter::equals,
00149 DDSpecificsFilter::AND,
00150 true,
00151 true ) ;
00152 return filter;
00153 }