00001 #include "Geometry/EcalTestBeam/plugins/EcalTBHodoscopeGeometryLoaderFromDDD.h"
00002 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00003
00004
00005 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00006 #include "Geometry/CaloGeometry/interface/PreshowerStrip.h"
00007
00008
00009 #include "DetectorDescription/Core/interface/DDFilteredView.h"
00010 #include "DetectorDescription/Core/interface/DDFilter.h"
00011 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00012 #include "DetectorDescription/Core/interface/DDSolid.h"
00013 #include "DetectorDescription/Core/interface/DDTransform.h"
00014 #include "DetectorDescription/Core/interface/DDExpandedView.h"
00015 #include "DetectorDescription/Core/interface/DDName.h"
00016
00017
00018
00019 #include <iostream>
00020 #include <vector>
00021
00022 using namespace std;
00023
00024 EcalTBHodoscopeGeometryLoaderFromDDD::EcalTBHodoscopeGeometryLoaderFromDDD(): _scheme(0)
00025 {
00026 _scheme=new EcalHodoscopeNumberingScheme();
00027 }
00028
00029 std::auto_ptr<CaloSubdetectorGeometry> EcalTBHodoscopeGeometryLoaderFromDDD::load(const DDCompactView* cpv) {
00030 std::cout << "[EcalTBHodoscopeGeometryLoaderFromDDD]:: start the construction of EcalTBHodoscope" << std::endl;
00031 std::auto_ptr<CaloSubdetectorGeometry> ebg(new CaloSubdetectorGeometry());
00032 makeGeometry(cpv,dynamic_cast<CaloSubdetectorGeometry*>(ebg.get()));
00033 std::cout << "[EcalTBHodoscopeGeometryLoaderFromDDD]:: Returning EcalTBHodoscopeGeometry" << std::endl;
00034 return ebg;
00035 }
00036
00037 void EcalTBHodoscopeGeometryLoaderFromDDD::makeGeometry(const DDCompactView* cpv,CaloSubdetectorGeometry* ebg)
00038 {
00039
00040 if( ebg->cornersMgr() == 0 ) ebg->allocateCorners( 256 ) ;
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 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 throw DDException(std::string(__FILE__)
00062 +"\n CaloGeometryEcalTBHodoscope::upDate(...): currently only box fiber shapes supported ");
00063 edm::LogWarning("EcalTBHodoscopeGeometry") << "Wrong shape for sensitive volume!" << solid;
00064 }
00065
00066 vector<double> pv = solid.parameters();
00067
00068
00069
00070
00071 DD3Vector x, y, z;
00072 fv.rotation().GetComponents(x,y,z);
00073 Hep3Vector hx(x.X(), x.Y(), x.Z());
00074 Hep3Vector hy(y.X(), y.Y(), y.Z());
00075 Hep3Vector hz(z.X(), z.Y(), z.Z());
00076 HepRotation hrot(hx, hy, hz);
00077 Hep3Vector htran(fv.translation().X(), fv.translation().Y(), fv.translation().Z());
00078
00079 const HepTransform3D ht3d ( hrot,
00080 CaloCellGeometry::k_ScaleFromDDDtoGeant*htran ) ;
00081
00082
00083 const HepPoint3D ctr ( ht3d*HepPoint3D(0,0,0) ) ;
00084
00085 const GlobalPoint refPoint ( ctr.x(), ctr.y(), ctr.z() ) ;
00086
00087
00088 std::vector<float> vv ;
00089 vv.reserve( pv.size() ) ;
00090 for( unsigned int i ( 0 ) ; i != pv.size() ; ++i )
00091 {
00092 vv.push_back( CaloCellGeometry::k_ScaleFromDDDtoGeant*pv[i] ) ;
00093 }
00094 const float* pP ( CaloCellGeometry::getParmPtr( vv,
00095 ebg->parMgr(),
00096 ebg->parVecVec() ) ) ;
00097
00098 PreshowerStrip* cell ( new PreshowerStrip( refPoint,
00099 ebg->cornersMgr(),
00100 pP ) ) ;
00101
00102
00103 ebg->addCell(DetId(getDetIdForDDDNode(fv)),cell);
00104 }
00105 }
00106
00107 unsigned int EcalTBHodoscopeGeometryLoaderFromDDD::getDetIdForDDDNode(const DDFilteredView &fv)
00108 {
00109
00110
00111 DDGeoHistory parents = fv.geoHistory();
00112
00113 assert(parents.size() >= 3);
00114
00115 EcalBaseNumber baseNumber;
00116
00117
00118 for (unsigned int i=1 ;i <= parents.size(); i++)
00119 baseNumber.addLevel(parents[parents.size()-i].logicalPart().name().name(),parents[parents.size()-i].copyno());
00120
00121 return (_scheme->getUnitID(baseNumber));
00122
00123 }
00124
00125 DDFilter* EcalTBHodoscopeGeometryLoaderFromDDD::getDDFilter()
00126 {
00127 DDSpecificsFilter *filter = new DDSpecificsFilter();
00128 filter->setCriteria(DDValue("SensitiveDetector","EcalTBH4BeamDetector",0),DDSpecificsFilter::equals,DDSpecificsFilter::AND,true,true);
00129 filter->setCriteria(DDValue("ReadOutName","EcalTBH4BeamHits",0),DDSpecificsFilter::equals,DDSpecificsFilter::AND,true,true);
00130 return filter;
00131 }