CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Geometry/TrackerNumberingBuilder/src/GeometricDet.cc

Go to the documentation of this file.
00001 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00002 #include "Geometry/TrackerNumberingBuilder/interface/TrackerShapeToBounds.h"
00003 #include "DetectorDescription/Core/interface/DDFilteredView.h"
00004 #include "DetectorDescription/Core/interface/DDSolid.h"
00005 #include "DetectorDescription/Core/interface/DDMaterial.h"
00006 #include "DetectorDescription/Core/interface/DDExpandedNode.h"
00007 #include "CondFormats/GeometryObjects/interface/PGeometricDet.h"
00008 
00009 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00010 
00011 #include <boost/bind.hpp>
00012 
00013 #include <cfloat>
00014 #include <vector>
00015 #include <string>
00016 
00017 namespace {
00018 
00019   std::string strue("true");
00020 
00021   template<typename DDView>
00022   double  getDouble(const  char * s,  DDView const & ev) {
00023     DDValue val(s);
00024     std::vector<const DDsvalues_type *> result;
00025     ev.specificsV(result);
00026     std::vector<const DDsvalues_type *>::iterator it = result.begin();
00027     bool foundIt = false;
00028     for (; it != result.end(); ++it)
00029       {
00030         foundIt = DDfetch(*it,val);
00031         if (foundIt) break;
00032       }    
00033     if (foundIt)
00034       { 
00035         const std::vector<std::string> & temp = val.strings(); 
00036         if (temp.size() != 1)
00037           {
00038             throw cms::Exception("Configuration") << "I need 1 "<< s << " tags";
00039           }
00040         return double(::atof(temp[0].c_str())); 
00041       }
00042     return 0;
00043   }
00044 
00045   template<typename DDView>
00046   std::string  getString(const  char * s,  DDView const & ev) {
00047     DDValue val(s);
00048     std::vector<const DDsvalues_type *> result;
00049     ev.specificsV(result);
00050     std::vector<const DDsvalues_type *>::iterator it = result.begin();
00051     bool foundIt = false;
00052     for (; it != result.end(); ++it)
00053     {
00054         foundIt = DDfetch(*it,val);
00055         if (foundIt) break;
00056 
00057     }    
00058     if (foundIt)
00059     { 
00060         const std::vector<std::string> & temp = val.strings(); 
00061         if (temp.size() != 1)
00062         {
00063           throw cms::Exception("Configuration") << "I need 1 "<< s << " tags";
00064         }
00065         return temp[0]; 
00066     }
00067     return "NotFound";
00068   }
00069 }
00070 
00071 
00076 GeometricDet::~GeometricDet(){
00077   //std::cout << "~GeometricDet5" << std::endl;
00078   deleteComponents();
00079 }
00080 #ifdef GEOMETRICDETDEBUG
00081 // for use outside CMSSW framework only since it asks for a default DDCompactView...
00082 GeometricDet::GeometricDet(DDnav_type const & navtype, GeometricEnumType type) :
00083   _ddd(navtype.begin(),navtype.end()), _type(type){ 
00084   //
00085   // I need to find the params by myself :(
00086   //
00087   //std::cout << "GeometricDet1" << std::endl;
00088   _fromDD = true;
00089   DDCompactView cpv; // bad, bad, bad!
00090   DDExpandedView ev(cpv);
00091   ev.goTo(navtype);
00092   _params = ((ev.logicalPart()).solid()).parameters();
00093   _trans = ev.translation();
00094   _phi = _trans.Phi();
00095   _rho = _trans.Rho();
00096   _rot = ev.rotation();
00097   _shape = ((ev.logicalPart()).solid()).shape();
00098   _ddname = ((ev.logicalPart()).ddname()).name();
00099   _parents = GeoHistory(ev.geoHistory().begin(),ev.geoHistory().end()) ;
00100   _volume   = ((ev.logicalPart()).solid()).volume();
00101   _density  = ((ev.logicalPart()).material()).density();
00102   //  _weight  = (ev.logicalPart()).weight();
00103   _weight   = _density * ( _volume / 1000.); // volume mm3->cm3
00104   _copy     = ev.copyno();
00105   _material = ((ev.logicalPart()).material()).name().fullname();
00106   _radLength = getDouble("TrackerRadLength",ev);
00107   _xi = getDouble("TrackerXi",ev);
00108   _pixROCRows = getDouble("PixelROCRows",ev);
00109   _pixROCCols = getDouble("PixelROCCols",ev);
00110   _pixROCx = getDouble("PixelROC_X",ev);
00111   _pixROCy = getDouble("PixelROC_Y",ev);
00112   _stereo =  getString("TrackerStereoDetectors",ev)==strue;
00113   _siliconAPVNum = getDouble("SiliconAPVNumber",ev);
00114 
00115 }
00116 
00117 GeometricDet::GeometricDet(DDExpandedView* fv, GeometricEnumType type) :  _type(type) {
00118   //
00119   // Set by hand the _ddd
00120   //
00121   //std::cout << "GeometricDet2" << std::endl;
00122   _fromDD = true;
00123   _ddd = nav_type(fv->navPos().begin(),fv->navPos().end() );
00124   _params = ((fv->logicalPart()).solid()).parameters();  
00125   _trans = fv->translation();
00126   _phi = _trans.Phi();
00127   _rho = _trans.Rho();
00128   _rot = fv->rotation();
00129   _shape = ((fv->logicalPart()).solid()).shape();
00130   _ddname = ((fv->logicalPart()).ddname()).name();
00131   _parents = GeoHistory(fv->geoHistory().begin(),fv->geoHistory().end()) ;
00132   _volume   = ((fv->logicalPart()).solid()).volume();  
00133   _density  = ((fv->logicalPart()).material()).density();
00134   //  _weight   = (fv->logicalPart()).weight();  
00135   _weight   = _density * ( _volume / 1000.); // volume mm3->cm3
00136   _copy     = fv->copyno();
00137   _material = ((fv->logicalPart()).material()).name().fullname();
00138   _radLength = getDouble("TrackerRadLength",*fv);
00139   _xi = getDouble("TrackerXi",*fv);
00140   _pixROCRows = getDouble("PixelROCRows",*fv);
00141   _pixROCCols = getDouble("PixelROCCols",*fv);
00142   _pixROCx = getDouble("PixelROC_X",*fv);
00143   _pixROCy = getDouble("PixelROC_Y",*fv);
00144   _stereo =  getString("TrackerStereoDetectors",*fv)=="true";
00145   _siliconAPVNum = getDouble("SiliconAPVNumber",*fv);
00146 
00147 }
00148 #endif
00149 
00150 GeometricDet::GeometricDet(DDFilteredView* fv, GeometricEnumType type) : 
00151   //
00152   // Set by hand the _ddd
00153   //
00154   _trans(fv->translation()),
00155   _phi(_trans.Phi()),
00156   _rho(_trans.Rho()),
00157   _rot(fv->rotation()),
00158   _shape(((fv->logicalPart()).solid()).shape()),
00159   _ddname(((fv->logicalPart()).ddname()).name()),
00160   _type(type),
00161   _params(((fv->logicalPart()).solid()).parameters()),
00162   //  want this :) _ddd(fv->navPos().begin(),fv->navPos().end()),
00163 #ifdef GEOMTRICDETDEBUG
00164   _parents(fv->geoHistory().begin(),fv->geoHistory().end()),
00165   _volume(((fv->logicalPart()).solid()).volume()),
00166   _density(((fv->logicalPart()).material()).density()),
00167   //  _weight   = (fv->logicalPart()).weight();
00168   _weight(_density * ( _volume / 1000.)), // volume mm3->cm3
00169   _copy(fv->copyno()),
00170   _material(((fv->logicalPart()).material()).name().fullname()),
00171 #endif
00172   _radLength(getDouble("TrackerRadLength",*fv)),
00173   _xi(getDouble("TrackerXi",*fv)),
00174   _pixROCRows(getDouble("PixelROCRows",*fv)),
00175   _pixROCCols(getDouble("PixelROCCols",*fv)),
00176   _pixROCx(getDouble("PixelROC_X",*fv)),
00177   _pixROCy(getDouble("PixelROC_Y",*fv)),
00178   _stereo(getString("TrackerStereoDetectors",*fv)==strue),
00179   _siliconAPVNum(getDouble("SiliconAPVNumber",*fv))
00180 #ifdef GEOMTRICDETDEBUG
00181   ,
00182   _fromDD(true)
00183 #endif
00184 {
00185   //std::cout << "GeometricDet3" << std::endl;
00186   //  workaround instead of this at initialization _ddd(fv->navPos().begin(),fv->navPos().end()),
00187   const DDFilteredView::nav_type& nt = fv->navPos();
00188   _ddd = nav_type(nt.begin(), nt.end());
00189 }
00190 
00191 // PGeometricDet is persistent version... make it... then come back here and make the
00192 // constructor.
00193 GeometricDet::GeometricDet ( const PGeometricDet::Item& onePGD, GeometricEnumType type) :
00194   _trans(onePGD._x, onePGD._y, onePGD._z),
00195   _phi(onePGD._phi), //_trans.Phi()),
00196   _rho(onePGD._rho), //_trans.Rho()),
00197   _rot(onePGD._a11, onePGD._a12, onePGD._a13, 
00198        onePGD._a21, onePGD._a22, onePGD._a23,
00199        onePGD._a31, onePGD._a32, onePGD._a33),
00200   _shape(DDSolidShapesName::index(onePGD._shape)),
00201   _ddd(), 
00202   _ddname(onePGD._name, onePGD._ns),//, "fromdb");
00203   _type(type),
00204   _params(),
00205   _geographicalID(onePGD._geographicalID),
00206 #ifdef GEOMTRICDETDEBUG
00207   _parents(), // will remain empty... hate wasting the space but want all methods to work.
00208   _volume(onePGD._volume),
00209   _density(onePGD._density),
00210   _weight(onePGD._weight),
00211   _copy(onePGD._copy),
00212   _material(onePGD._material),
00213 #endif
00214   _radLength(onePGD._radLength),
00215   _xi(onePGD._xi),
00216   _pixROCRows(onePGD._pixROCRows),
00217   _pixROCCols(onePGD._pixROCCols),
00218   _pixROCx(onePGD._pixROCx),
00219   _pixROCy(onePGD._pixROCy),
00220   _stereo(onePGD._stereo),
00221   _siliconAPVNum(onePGD._siliconAPVNum)
00222 #ifdef GEOMTRICDETDEBUG
00223   , // mind the tricky comma is needed.
00224   _fromDD(false)
00225 #endif
00226 {
00227   //std::cout << "GeometricDet4" << std::endl;
00228   
00229   if(onePGD._shape==1||onePGD._shape==3){ //The parms vector is neede only in the case of box or trap shape
00230     _params.reserve(11);
00231     _params.push_back(onePGD._params0);
00232     _params.push_back(onePGD._params1);
00233     _params.push_back(onePGD._params2);
00234     _params.push_back(onePGD._params3);
00235     _params.push_back(onePGD._params4);
00236     _params.push_back(onePGD._params5);
00237     _params.push_back(onePGD._params6);
00238     _params.push_back(onePGD._params7);
00239     _params.push_back(onePGD._params8);
00240     _params.push_back(onePGD._params9);
00241     _params.push_back(onePGD._params10);
00242   }
00243  
00244   _ddd.reserve(onePGD._numnt);
00245   _ddd.push_back(onePGD._nt0);
00246   _ddd.push_back(onePGD._nt1);
00247   _ddd.push_back(onePGD._nt2);
00248   _ddd.push_back(onePGD._nt3);
00249   if ( onePGD._numnt > 4 ) {
00250     _ddd.push_back(onePGD._nt4);
00251     if ( onePGD._numnt > 5 ) {
00252       _ddd.push_back(onePGD._nt5);
00253       if ( onePGD._numnt > 6 ) {
00254         _ddd.push_back(onePGD._nt6);
00255         if ( onePGD._numnt > 7 ) {
00256           _ddd.push_back(onePGD._nt7);
00257           if ( onePGD._numnt > 8 ) {
00258             _ddd.push_back(onePGD._nt8);
00259             if ( onePGD._numnt > 9 ) {
00260               _ddd.push_back(onePGD._nt9);
00261               if ( onePGD._numnt > 10 ) {
00262                 _ddd.push_back(onePGD._nt10);
00263               }}}}}}
00264   }
00265  
00266 }
00267 
00268 GeometricDet::ConstGeometricDetContainer GeometricDet::deepComponents() const {
00269   //
00270   // iterate on all the components ;)
00271   //
00272   //std::cout << "deepComponents1" << std::endl;
00273   ConstGeometricDetContainer _temp;
00274   deepComponents(_temp);
00275   return _temp;
00276 }
00277 
00278 void GeometricDet::deepComponents(GeometricDetContainer & cont) const {
00279   //std::cout << "const deepComponents2" << std::endl;
00280   if (isLeaf())
00281     cont.push_back(const_cast<GeometricDet*>(this));
00282   else 
00283     std::for_each(_container.begin(),_container.end(), 
00284                   boost::bind(&GeometricDet::deepComponents,_1,boost::ref(cont))
00285                   );
00286 }
00287 
00288 
00289 void GeometricDet::addComponents(GeometricDetContainer const & cont){
00290   //std::cout << "addComponents" << std::endl;
00291   if (_container.empty()) {
00292     _container=cont;
00293     return;
00294   }
00295   _container.reserve(_container.size()+cont.size());
00296   std::copy(cont.begin(), cont.end(), back_inserter(_container));
00297 }
00298 
00299 
00300 void GeometricDet::addComponent(GeometricDet* det){
00301   //std::cout << "deepComponent" << std::endl;
00302   _container.push_back(det);
00303 }
00304 
00305 namespace {
00306   struct Deleter {
00307     void operator()(GeometricDet const* det) const { delete const_cast<GeometricDet*>(det);}
00308   };
00309 }
00310 
00311 void GeometricDet::deleteComponents(){
00312   //std::cout << "deleteComponents" << std::endl;
00313   std::for_each(_container.begin(),_container.end(),Deleter()); 
00314   _container.clear();
00315 }
00316 
00317 
00318 GeometricDet::Position GeometricDet::positionBounds() const{
00319   //std::cout << "positionBounds" << std::endl;
00320   Position _pos(float(_trans.x()/cm), 
00321                 float(_trans.y()/cm), 
00322                 float(_trans.z()/cm));
00323   return _pos;
00324 }
00325 
00326 GeometricDet::Rotation GeometricDet::rotationBounds() const{
00327   //std::cout << "rotationBounds" << std::endl;
00328   DD3Vector x, y, z;
00329   _rot.GetComponents(x, y, z);
00330   Rotation _rotation(float(x.X()),float(x.Y()),float(x.Z()),
00331                      float(y.X()),float(y.Y()),float(y.Z()),
00332                      float(z.X()),float(z.Y()),float(z.Z())); 
00333   return _rotation;
00334 }
00335 
00336 const Bounds * GeometricDet::bounds() const{
00337   //std::cout << "bounds" << std::endl;
00338   const std::vector<double>& par = _params;
00339   Bounds * bounds = 0;
00340   TrackerShapeToBounds shapeToBounds;
00341   bounds = shapeToBounds.buildBounds(_shape,par);
00342   return bounds;
00343 }
00344