CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Geometry/TrackerGeometryBuilder/src/TrackerGeomBuilderFromGeometricDet.cc

Go to the documentation of this file.
00001 
00002 
00003 //#include "DetectorDescription/Core/interface/DDExpandedView.h"
00004 //temporary
00005 //#include "DetectorDescription/Core/interface/DDSolid.h"
00006 //
00007 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
00008 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00009 #include "Geometry/TrackerGeometryBuilder/interface/PlaneBuilderForGluedDet.h"
00010 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00011 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00012 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00013 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetType.h"
00014 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00015 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetType.h"
00016 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00017 #include "DataFormats/DetId/interface/DetId.h"
00018 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00019 #include "DataFormats/GeometrySurface/interface/MediumProperties.h"
00020 
00021 
00022 #include <cfloat>
00023 #include <cassert>
00024 using std::vector;
00025 using std::string;
00026 
00027 namespace {
00028   void verifyDUinTG(TrackerGeometry const & tg) {
00029     int off=0; int end=0;
00030     for ( int i=1; i!=7; i++) {
00031       auto det = GeomDetEnumerators::tkDetEnum[i];
00032       off = tg.offsetDU(det);
00033       end = tg.endsetDU(det); assert(end>off);
00034       for (int j=off; j!=end; ++j) {
00035         assert(tg.detUnits()[j]->geographicalId().subdetId()==i);
00036         assert(tg.detUnits()[j]->subDetector()==det);
00037         assert(tg.detUnits()[j]->index()==j);
00038       }
00039     }
00040   }
00041 }
00042 
00043 TrackerGeometry* TrackerGeomBuilderFromGeometricDet::build( const GeometricDet* gd){
00044 
00045   thePixelDetTypeMap.clear();
00046   theStripDetTypeMap.clear();
00047    
00048   TrackerGeometry* tracker = new TrackerGeometry(gd);
00049   std::vector<const GeometricDet*> comp;
00050   gd->deepComponents(comp);
00051 
00052   std::vector<const GeometricDet*> dets[6];
00053   std::vector<const GeometricDet*> & pixB = dets[0]; pixB.reserve(comp.size());
00054   std::vector<const GeometricDet*> & pixF = dets[1]; pixF.reserve(comp.size());
00055   std::vector<const GeometricDet*> & tib  = dets[2];  tib.reserve(comp.size());
00056   std::vector<const GeometricDet*> & tid  = dets[3];  tid.reserve(comp.size());
00057   std::vector<const GeometricDet*> & tob  = dets[4];  tob.reserve(comp.size());
00058   std::vector<const GeometricDet*> & tec  = dets[5];  tec.reserve(comp.size());
00059 
00060   for(u_int32_t i = 0;i<comp.size();i++)
00061     dets[comp[i]->geographicalID().subdetId()-1].push_back(comp[i]);
00062   
00063   // this order is VERY IMPORTANT!!!!!
00064   buildPixel(pixB,tracker,theDetIdToEnum.type(1), "barrel"); //"PixelBarrel" 
00065   buildPixel(pixF,tracker,theDetIdToEnum.type(2), "endcap"); //"PixelEndcap" 
00066   buildSilicon(tib,tracker,theDetIdToEnum.type(3), "barrel");// "TIB"   
00067   buildSilicon(tid,tracker,theDetIdToEnum.type(4), "endcap");//"TID" 
00068   buildSilicon(tob,tracker,theDetIdToEnum.type(5), "barrel");//"TOB"    
00069   buildSilicon(tec,tracker,theDetIdToEnum.type(6), "endcap");//"TEC"        
00070   buildGeomDet(tracker);//"GeomDet"
00071 
00072   verifyDUinTG(*tracker);
00073 
00074   return tracker;
00075 }
00076 
00077 void TrackerGeomBuilderFromGeometricDet::buildPixel(std::vector<const GeometricDet*>  const & gdv, 
00078                                                     TrackerGeometry* tracker,
00079                                                     GeomDetType::SubDetector det,
00080                                                     const std::string& part){ 
00081   tracker->setOffsetDU(det);
00082 
00083   for(u_int32_t i=0; i<gdv.size(); i++){
00084 
00085     std::string const & detName = gdv[i]->name().fullname();
00086     if (thePixelDetTypeMap.find(detName) == thePixelDetTypeMap.end()) {
00087       std::auto_ptr<const Bounds> bounds(gdv[i]->bounds());
00088       PixelTopology* t = 
00089         theTopologyBuilder->buildPixel(&*bounds,
00090                                        gdv[i]->pixROCRows(),
00091                                        gdv[i]->pixROCCols(),
00092                                        gdv[i]->pixROCx(),
00093                                        gdv[i]->pixROCy(),
00094                                        part);
00095       
00096       thePixelDetTypeMap[detName] = new PixelGeomDetType(t,detName,det);
00097       tracker->addType(thePixelDetTypeMap[detName]);
00098     }
00099 
00100     PlaneBuilderFromGeometricDet::ResultType plane = buildPlaneWithMaterial(gdv[i]);
00101     GeomDetUnit* temp =  new PixelGeomDetUnit(&(*plane),thePixelDetTypeMap[detName],gdv[i]);
00102 
00103     tracker->addDetUnit(temp);
00104     tracker->addDetUnitId(gdv[i]->geographicalID());
00105   }
00106   tracker->setEndsetDU(det);
00107 
00108 }
00109 
00110 void TrackerGeomBuilderFromGeometricDet::buildSilicon(std::vector<const GeometricDet*>  const & gdv, 
00111                                                       TrackerGeometry* tracker,
00112                                                       GeomDetType::SubDetector det,
00113                                                       const std::string& part)
00114 { 
00115   tracker->setOffsetDU(det);
00116 
00117   for(u_int32_t i=0;i<gdv.size();i++){
00118 
00119     std::string const & detName = gdv[i]->name().fullname();
00120     if (theStripDetTypeMap.find(detName) == theStripDetTypeMap.end()) {
00121        std::auto_ptr<const Bounds> bounds(gdv[i]->bounds());
00122        StripTopology* t =
00123         theTopologyBuilder->buildStrip(&*bounds,
00124                                        gdv[i]->siliconAPVNum(),
00125                                        part);
00126       theStripDetTypeMap[detName] = new  StripGeomDetType( t,detName,det,
00127                                                    gdv[i]->stereo());
00128       tracker->addType(theStripDetTypeMap[detName]);
00129     }
00130      
00131     StripSubdetector sidet( gdv[i]->geographicalID());
00132     double scale  = (sidet.partnerDetId()) ? 0.5 : 1.0 ;        
00133 
00134     PlaneBuilderFromGeometricDet::ResultType plane = buildPlaneWithMaterial(gdv[i],scale);  
00135     GeomDetUnit* temp = new StripGeomDetUnit(&(*plane), theStripDetTypeMap[detName],gdv[i]);
00136     
00137     tracker->addDetUnit(temp);
00138     tracker->addDetUnitId(gdv[i]->geographicalID());
00139   }  
00140   tracker->setEndsetDU(det);
00141 
00142 }
00143 
00144 
00145 void TrackerGeomBuilderFromGeometricDet::buildGeomDet(TrackerGeometry* tracker){
00146   PlaneBuilderForGluedDet gluedplaneBuilder;
00147   std::vector<GeomDetUnit*> const & gdu= tracker->detUnits();
00148   std::vector<DetId> const & gduId = tracker->detUnitIds();
00149 
00150   for(u_int32_t i=0;i<gdu.size();i++){
00151     StripSubdetector sidet( gduId[i].rawId());
00152     tracker->addDet((GeomDet*) gdu[i]);
00153     tracker->addDetId(gduId[i]);      
00154     if(sidet.glued()!=0&&sidet.stereo()==1){
00155       int partner_pos=-1;
00156       for(u_int32_t jj=0;jj<gduId.size();jj++){
00157         if(sidet.partnerDetId()== gduId[jj]) {
00158           partner_pos=jj;
00159           break;
00160         }
00161       }
00162       const GeomDetUnit* dus = gdu[i];
00163       if(partner_pos==-1){
00164         throw cms::Exception("Configuration") <<"No partner detector found \n"
00165                                         <<"There is a problem on Tracker geometry configuration\n";
00166       }
00167       const GeomDetUnit* dum = gdu[partner_pos];
00168       std::vector<const GeomDetUnit *> glued(2);
00169       glued[0]=dum;
00170       glued[1]=dus;
00171       PlaneBuilderForGluedDet::ResultType plane = gluedplaneBuilder.plane(glued);
00172       GluedGeomDet* gluedDet = new GluedGeomDet(&(*plane),dum,dus);
00173       tracker->addDet((GeomDet*) gluedDet);
00174       tracker->addDetId(DetId(sidet.glued()));
00175     }
00176   }
00177 }
00178 
00179 
00180 // std::string TrackerGeomBuilderFromGeometricDet::getString(const std::string & s, DDExpandedView* ev) const
00181 // {
00182 //     DDValue val(s);
00183 //     vector<const DDsvalues_type *> result;
00184 //     ev->specificsV(result);
00185 //     vector<const DDsvalues_type *>::iterator it = result.begin();
00186 //     bool foundIt = false;
00187 //     for (; it != result.end(); ++it)
00188 //     {
00189 //      foundIt = DDfetch(*it,val);
00190 //      if (foundIt) break;
00191 
00192 //     }    
00193 //     if (foundIt)
00194 //     { 
00195 //      const std::vector<std::string> & temp = val.strings(); 
00196 //      if (temp.size() != 1)
00197 //      {
00198 //        throw cms::Exception("Configuration") << "I need 1 "<< s << " tags";
00199 //      }
00200 //      return temp[0]; 
00201 //     }
00202 //     return "NotFound";
00203 // }
00204 
00205 // double TrackerGeomBuilderFromGeometricDet::getDouble(const std::string & s,  DDExpandedView* ev) const 
00206 // {
00207 //   DDValue val(s);
00208 //   vector<const DDsvalues_type *> result;
00209 //   ev->specificsV(result);
00210 //   vector<const DDsvalues_type *>::iterator it = result.begin();
00211 //   bool foundIt = false;
00212 //   for (; it != result.end(); ++it)
00213 //     {
00214 //       foundIt = DDfetch(*it,val);
00215 //       if (foundIt) break;
00216 //     }    
00217 //   if (foundIt)
00218 //     { 
00219 //       const std::vector<std::string> & temp = val.strings(); 
00220 //       if (temp.size() != 1)
00221 //      {
00222 //        throw cms::Exception("Configuration") << "I need 1 "<< s << " tags";
00223 //      }
00224 //       return double(atof(temp[0].c_str())); 
00225 //     }
00226 //   return 0;
00227 // }
00228 
00229 PlaneBuilderFromGeometricDet::ResultType
00230 TrackerGeomBuilderFromGeometricDet::buildPlaneWithMaterial(const GeometricDet* gd,
00231                                                            double scale) const
00232 {
00233   PlaneBuilderFromGeometricDet planeBuilder;
00234   PlaneBuilderFromGeometricDet::ResultType plane = planeBuilder.plane(gd);  
00235   //
00236   // set medium properties (if defined)
00237   //
00238   plane->setMediumProperties(MediumProperties(gd->radLength()*scale,gd->xi()*scale));
00239 
00240   return plane;
00241 }