CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/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 
00024 using std::vector;
00025 using std::string;
00026 
00027 
00028 TrackerGeometry* TrackerGeomBuilderFromGeometricDet::build( const GeometricDet* gd){
00029 
00030   thePixelDetTypeMap.clear();
00031   theStripDetTypeMap.clear();
00032    
00033   TrackerGeometry* tracker = new TrackerGeometry(gd);
00034   std::vector<const GeometricDet*> comp;
00035   gd->deepComponents(comp);
00036 
00037   std::vector<const GeometricDet*> dets[6];
00038   std::vector<const GeometricDet*> & pixB = dets[0]; pixB.reserve(comp.size());
00039   std::vector<const GeometricDet*> & pixF = dets[1]; pixF.reserve(comp.size());
00040   std::vector<const GeometricDet*> & tib  = dets[2];  tib.reserve(comp.size());
00041   std::vector<const GeometricDet*> & tid  = dets[3];  tid.reserve(comp.size());
00042   std::vector<const GeometricDet*> & tob  = dets[4];  tob.reserve(comp.size());
00043   std::vector<const GeometricDet*> & tec  = dets[5];  tec.reserve(comp.size());
00044 
00045   for(u_int32_t i = 0;i<comp.size();i++)
00046     dets[comp[i]->geographicalID().subdetId()-1].push_back(comp[i]);
00047   
00048 
00049   buildPixel(pixB,tracker,theDetIdToEnum.type(1), "barrel"); //"PixelBarrel" 
00050   buildPixel(pixF,tracker,theDetIdToEnum.type(2), "endcap"); //"PixelEndcap" 
00051   buildSilicon(tib,tracker,theDetIdToEnum.type(3), "barrel");// "TIB"   
00052   buildSilicon(tid,tracker,theDetIdToEnum.type(4), "endcap");//"TID" 
00053   buildSilicon(tob,tracker,theDetIdToEnum.type(5), "barrel");//"TOB"    
00054   buildSilicon(tec,tracker,theDetIdToEnum.type(6), "endcap");//"TEC"        
00055   buildGeomDet(tracker);//"GeomDet"
00056   return tracker;
00057 }
00058 
00059 void TrackerGeomBuilderFromGeometricDet::buildPixel(std::vector<const GeometricDet*>  const & gdv, 
00060                                                     TrackerGeometry* tracker,
00061                                                     GeomDetType::SubDetector det,
00062                                                     const std::string& part){ 
00063 
00064   for(u_int32_t i=0; i<gdv.size(); i++){
00065 
00066     std::string const & detName = gdv[i]->name().fullname();
00067     if (thePixelDetTypeMap.find(detName) == thePixelDetTypeMap.end()) {
00068       std::auto_ptr<const Bounds> bounds(gdv[i]->bounds());
00069       PixelTopology* t = 
00070         theTopologyBuilder->buildPixel(&*bounds,
00071                                        gdv[i]->pixROCRows(),
00072                                        gdv[i]->pixROCCols(),
00073                                        gdv[i]->pixROCx(),
00074                                        gdv[i]->pixROCy(),
00075                                        part);
00076       
00077       thePixelDetTypeMap[detName] = new PixelGeomDetType(t,detName,det);
00078       tracker->addType(thePixelDetTypeMap[detName]);
00079     }
00080 
00081     PlaneBuilderFromGeometricDet::ResultType plane = buildPlaneWithMaterial(gdv[i]);
00082     GeomDetUnit* temp =  new PixelGeomDetUnit(&(*plane),thePixelDetTypeMap[detName],gdv[i]);
00083 
00084     tracker->addDetUnit(temp);
00085     tracker->addDetUnitId(gdv[i]->geographicalID());
00086   }
00087 }
00088 
00089 void TrackerGeomBuilderFromGeometricDet::buildSilicon(std::vector<const GeometricDet*>  const & gdv, 
00090                                                       TrackerGeometry* tracker,
00091                                                       GeomDetType::SubDetector det,
00092                                                       const std::string& part)
00093 { 
00094   for(u_int32_t i=0;i<gdv.size();i++){
00095 
00096     std::string const & detName = gdv[i]->name().fullname();
00097     if (theStripDetTypeMap.find(detName) == theStripDetTypeMap.end()) {
00098        std::auto_ptr<const Bounds> bounds(gdv[i]->bounds());
00099        StripTopology* t =
00100         theTopologyBuilder->buildStrip(&*bounds,
00101                                        gdv[i]->siliconAPVNum(),
00102                                        part);
00103       theStripDetTypeMap[detName] = new  StripGeomDetType( t,detName,det,
00104                                                    gdv[i]->stereo());
00105       tracker->addType(theStripDetTypeMap[detName]);
00106     }
00107      
00108     StripSubdetector sidet( gdv[i]->geographicalID());
00109     double scale  = (sidet.partnerDetId()) ? 0.5 : 1.0 ;        
00110 
00111     PlaneBuilderFromGeometricDet::ResultType plane = buildPlaneWithMaterial(gdv[i],scale);  
00112     GeomDetUnit* temp = new StripGeomDetUnit(&(*plane), theStripDetTypeMap[detName],gdv[i]);
00113     
00114     tracker->addDetUnit(temp);
00115     tracker->addDetUnitId(gdv[i]->geographicalID());
00116   }  
00117 }
00118 
00119 
00120 void TrackerGeomBuilderFromGeometricDet::buildGeomDet(TrackerGeometry* tracker){
00121   PlaneBuilderForGluedDet gluedplaneBuilder;
00122   std::vector<GeomDetUnit*> const & gdu= tracker->detUnits();
00123   std::vector<DetId> const & gduId = tracker->detUnitIds();
00124 
00125   for(u_int32_t i=0;i<gdu.size();i++){
00126     StripSubdetector sidet( gduId[i].rawId());
00127     tracker->addDet((GeomDet*) gdu[i]);
00128     tracker->addDetId(gduId[i]);      
00129     if(sidet.glued()!=0&&sidet.stereo()==1){
00130       int partner_pos=-1;
00131       for(u_int32_t jj=0;jj<gduId.size();jj++){
00132         if(sidet.partnerDetId()== gduId[jj]) {
00133           partner_pos=jj;
00134           break;
00135         }
00136       }
00137       const GeomDetUnit* dus = gdu[i];
00138       if(partner_pos==-1){
00139         throw cms::Exception("Configuration") <<"No partner detector found \n"
00140                                         <<"There is a problem on Tracker geometry configuration\n";
00141       }
00142       const GeomDetUnit* dum = gdu[partner_pos];
00143       std::vector<const GeomDetUnit *> glued(2);
00144       glued[0]=dum;
00145       glued[1]=dus;
00146       PlaneBuilderForGluedDet::ResultType plane = gluedplaneBuilder.plane(glued);
00147       GluedGeomDet* gluedDet = new GluedGeomDet(&(*plane),dum,dus);
00148       tracker->addDet((GeomDet*) gluedDet);
00149       tracker->addDetId(DetId(sidet.glued()));
00150     }
00151   }
00152 }
00153 
00154 
00155 // std::string TrackerGeomBuilderFromGeometricDet::getString(const std::string & s, DDExpandedView* ev) const
00156 // {
00157 //     DDValue val(s);
00158 //     vector<const DDsvalues_type *> result;
00159 //     ev->specificsV(result);
00160 //     vector<const DDsvalues_type *>::iterator it = result.begin();
00161 //     bool foundIt = false;
00162 //     for (; it != result.end(); ++it)
00163 //     {
00164 //      foundIt = DDfetch(*it,val);
00165 //      if (foundIt) break;
00166 
00167 //     }    
00168 //     if (foundIt)
00169 //     { 
00170 //      const std::vector<std::string> & temp = val.strings(); 
00171 //      if (temp.size() != 1)
00172 //      {
00173 //        throw cms::Exception("Configuration") << "I need 1 "<< s << " tags";
00174 //      }
00175 //      return temp[0]; 
00176 //     }
00177 //     return "NotFound";
00178 // }
00179 
00180 // double TrackerGeomBuilderFromGeometricDet::getDouble(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 //   if (foundIt)
00193 //     { 
00194 //       const std::vector<std::string> & temp = val.strings(); 
00195 //       if (temp.size() != 1)
00196 //      {
00197 //        throw cms::Exception("Configuration") << "I need 1 "<< s << " tags";
00198 //      }
00199 //       return double(atof(temp[0].c_str())); 
00200 //     }
00201 //   return 0;
00202 // }
00203 
00204 PlaneBuilderFromGeometricDet::ResultType
00205 TrackerGeomBuilderFromGeometricDet::buildPlaneWithMaterial(const GeometricDet* gd,
00206                                                            double scale) const
00207 {
00208   PlaneBuilderFromGeometricDet planeBuilder;
00209   PlaneBuilderFromGeometricDet::ResultType plane = planeBuilder.plane(gd);  
00210   //
00211   // set medium properties (if defined)
00212   //
00213   plane->setMediumProperties(MediumProperties(gd->radLength()*scale,gd->xi()*scale));
00214 
00215   return plane;
00216 }