CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/Geometry/EcalTestBeam/plugins/EcalTBHodoscopeGeometryLoaderFromDDD.cc

Go to the documentation of this file.
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 //#include "DetectorDescription/Core/interface/DDInit.h"
00017 
00018 
00019 #include <iostream>
00020 #include <vector>
00021 
00022 EcalTBHodoscopeGeometryLoaderFromDDD::EcalTBHodoscopeGeometryLoaderFromDDD(): _scheme(0) 
00023 {
00024   _scheme=new EcalHodoscopeNumberingScheme();
00025 }
00026 
00027 std::auto_ptr<CaloSubdetectorGeometry> EcalTBHodoscopeGeometryLoaderFromDDD::load(const DDCompactView* cpv) {
00028   std::cout << "[EcalTBHodoscopeGeometryLoaderFromDDD]:: start the construction of EcalTBHodoscope" << std::endl;
00029   std::auto_ptr<CaloSubdetectorGeometry> ebg(new CaloSubdetectorGeometry());
00030   makeGeometry(cpv,dynamic_cast<CaloSubdetectorGeometry*>(ebg.get()));
00031   std::cout << "[EcalTBHodoscopeGeometryLoaderFromDDD]:: Returning EcalTBHodoscopeGeometry" << std::endl;
00032   return ebg;
00033 }
00034 
00035 void EcalTBHodoscopeGeometryLoaderFromDDD::makeGeometry(const DDCompactView* cpv,CaloSubdetectorGeometry* ebg)
00036 {
00037 
00038    if( ebg->cornersMgr() == 0 ) ebg->allocateCorners( 256 ) ;
00039    if( ebg->parMgr()     == 0 ) ebg->allocatePar( 10, 3 ) ;
00040   
00041   DDFilter* filter = getDDFilter();
00042 
00043   DDFilteredView fv(*cpv);
00044   fv.addFilter(*filter);
00045   
00046   bool doSubDets;
00047   for (doSubDets = fv.firstChild(); doSubDets ; doSubDets = fv.nextSibling())
00048     {
00049       
00050 #if 0
00051       std::string answer = getDDDString("ReadOutName",&fv);
00052       if (answer != "EcalTBH4BeamHits")
00053         continue;
00054 #endif
00055       
00056       const DDSolid & solid = fv.logicalPart().solid();
00057 
00058       if (solid.shape() != ddbox) {
00059         throw DDException(std::string(__FILE__) 
00060                           +"\n CaloGeometryEcalTBHodoscope::upDate(...): currently only box fiber shapes supported ");
00061         edm::LogWarning("EcalTBHodoscopeGeometry") << "Wrong shape for sensitive volume!" << solid;
00062       }
00063        
00064       std::vector<double> pv = solid.parameters();      
00065 
00066       // use preshower strip as box in space representation
00067 
00068        // rotate the box and then move it
00069       DD3Vector x, y, z;
00070       fv.rotation().GetComponents(x,y,z);
00071       CLHEP::Hep3Vector hx(x.X(), x.Y(), x.Z());
00072       CLHEP::Hep3Vector hy(y.X(), y.Y(), y.Z());
00073       CLHEP::Hep3Vector hz(z.X(), z.Y(), z.Z());
00074       CLHEP::HepRotation hrot(hx, hy, hz);
00075       CLHEP::Hep3Vector htran(fv.translation().X(), fv.translation().Y(), fv.translation().Z());
00076 
00077       const HepGeom::Transform3D ht3d ( hrot,                        // only scale translation
00078                                   CaloCellGeometry::k_ScaleFromDDDtoGeant*htran ) ;    
00079 
00080 
00081       const HepGeom::Point3D<double>  ctr ( ht3d*HepGeom::Point3D<double> (0,0,0) ) ;
00082 
00083       const GlobalPoint refPoint ( ctr.x(), ctr.y(), ctr.z() ) ;
00084 
00085 
00086       std::vector<double> vv ;
00087       vv.reserve( pv.size() ) ;
00088       for( unsigned int i ( 0 ) ; i != pv.size() ; ++i )
00089       {
00090          vv.push_back( CaloCellGeometry::k_ScaleFromDDDtoGeant*pv[i] ) ;
00091       }
00092       const double* pP ( CaloCellGeometry::getParmPtr( vv, 
00093                                                        ebg->parMgr(), 
00094                                                        ebg->parVecVec() ) ) ;
00095 
00096       PreshowerStrip* cell ( new PreshowerStrip( refPoint,
00097                                                  ebg->cornersMgr(),
00098                                                  pP ) ) ;
00099 
00100       //Adding cell to the Geometry
00101       ebg->addCell(DetId(getDetIdForDDDNode(fv)),cell);
00102     } // loop over all children (i.e. crystals)
00103 }
00104 
00105 unsigned int EcalTBHodoscopeGeometryLoaderFromDDD::getDetIdForDDDNode(const DDFilteredView &fv)
00106 {
00107   // perform some consistency checks
00108   // get the parents and grandparents of this node
00109   DDGeoHistory parents = fv.geoHistory();
00110   
00111   assert(parents.size() >= 3);
00112 
00113   EcalBaseNumber baseNumber;
00114   //baseNumber.setSize(parents.size());
00115 
00116   for (unsigned int i=1 ;i <= parents.size(); i++)
00117     baseNumber.addLevel(parents[parents.size()-i].logicalPart().name().name(),parents[parents.size()-i].copyno());
00118 
00119   return (_scheme->getUnitID(baseNumber));
00120   
00121 }
00122 
00123 DDFilter* EcalTBHodoscopeGeometryLoaderFromDDD::getDDFilter()
00124 {
00125   DDSpecificsFilter *filter = new DDSpecificsFilter();
00126   filter->setCriteria(DDValue("SensitiveDetector","EcalTBH4BeamDetector",0),DDSpecificsFilter::equals,DDSpecificsFilter::AND,true,true);
00127   filter->setCriteria(DDValue("ReadOutName","EcalTBH4BeamHits",0),DDSpecificsFilter::equals,DDSpecificsFilter::AND,true,true);
00128   return filter;
00129 }