00001 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
00002 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00003 #include "Geometry/TrackerGeometryBuilder/interface/PlaneBuilderForGluedDet.h"
00004 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00005 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00006 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetType.h"
00007 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00008 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetType.h"
00009 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00010 #include "Geometry/TrackerGeometryBuilder/interface/PixelTopologyBuilder.h"
00011 #include "Geometry/TrackerGeometryBuilder/interface/StripTopologyBuilder.h"
00012 #include "DataFormats/DetId/interface/DetId.h"
00013 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00014 #include "DataFormats/GeometrySurface/interface/MediumProperties.h"
00015
00016 #include <cfloat>
00017 #include <cassert>
00018 using std::vector;
00019 using std::string;
00020
00021 namespace {
00022 void verifyDUinTG(TrackerGeometry const & tg, bool upgradeGeometry) {
00023 int off=0; int end=0;
00024 for ( int i=1; i!=7; i++) {
00025 auto det = GeomDetEnumerators::tkDetEnum[i];
00026 off = tg.offsetDU(det);
00027 end = tg.endsetDU(det);
00028
00029
00030
00031 if(! upgradeGeometry)
00032 assert(end>off);
00033
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*
00044 TrackerGeomBuilderFromGeometricDet::build( const GeometricDet* gd, const edm::ParameterSet& pSet )
00045 {
00046 bool upgradeGeometry = false;
00047 int BIG_PIX_PER_ROC_X = 1;
00048 int BIG_PIX_PER_ROC_Y = 2;
00049
00050 if( pSet.exists( "trackerGeometryConstants" ))
00051 {
00052 const edm::ParameterSet tkGeomConsts( pSet.getParameter<edm::ParameterSet>( "trackerGeometryConstants" ));
00053 upgradeGeometry = tkGeomConsts.getParameter<bool>( "upgradeGeometry" );
00054 BIG_PIX_PER_ROC_X = tkGeomConsts.getParameter<int>( "BIG_PIX_PER_ROC_X" );
00055 BIG_PIX_PER_ROC_Y = tkGeomConsts.getParameter<int>( "BIG_PIX_PER_ROC_Y" );
00056 }
00057
00058 thePixelDetTypeMap.clear();
00059 theStripDetTypeMap.clear();
00060
00061 TrackerGeometry* tracker = new TrackerGeometry(gd);
00062 std::vector<const GeometricDet*> comp;
00063 gd->deepComponents(comp);
00064
00065 std::vector<const GeometricDet*> dets[6];
00066 std::vector<const GeometricDet*> & pixB = dets[0]; pixB.reserve(comp.size());
00067 std::vector<const GeometricDet*> & pixF = dets[1]; pixF.reserve(comp.size());
00068 std::vector<const GeometricDet*> & tib = dets[2]; tib.reserve(comp.size());
00069 std::vector<const GeometricDet*> & tid = dets[3]; tid.reserve(comp.size());
00070 std::vector<const GeometricDet*> & tob = dets[4]; tob.reserve(comp.size());
00071 std::vector<const GeometricDet*> & tec = dets[5]; tec.reserve(comp.size());
00072
00073 for(u_int32_t i = 0;i<comp.size();i++)
00074 dets[comp[i]->geographicalID().subdetId()-1].push_back(comp[i]);
00075
00076
00077 buildPixel(pixB,tracker,GeomDetEnumerators::SubDetector::PixelBarrel,
00078 upgradeGeometry,
00079 BIG_PIX_PER_ROC_X,
00080 BIG_PIX_PER_ROC_Y);
00081 buildPixel(pixF,tracker,GeomDetEnumerators::SubDetector::PixelEndcap,
00082 upgradeGeometry,
00083 BIG_PIX_PER_ROC_X,
00084 BIG_PIX_PER_ROC_Y);
00085 buildSilicon(tib,tracker,GeomDetEnumerators::SubDetector::TIB, "barrel");
00086 buildSilicon(tid,tracker,GeomDetEnumerators::SubDetector::TID, "endcap");
00087 buildSilicon(tob,tracker,GeomDetEnumerators::SubDetector::TOB, "barrel");
00088 buildSilicon(tec,tracker,GeomDetEnumerators::SubDetector::TEC, "endcap");
00089 buildGeomDet(tracker);
00090
00091 verifyDUinTG(*tracker, upgradeGeometry);
00092
00093 return tracker;
00094 }
00095
00096 void TrackerGeomBuilderFromGeometricDet::buildPixel(std::vector<const GeometricDet*> const & gdv,
00097 TrackerGeometry* tracker,
00098 GeomDetType::SubDetector det,
00099 bool upgradeGeometry,
00100 int BIG_PIX_PER_ROC_X,
00101 int BIG_PIX_PER_ROC_Y)
00102 {
00103 tracker->setOffsetDU(det);
00104
00105 for(u_int32_t i=0; i<gdv.size(); i++){
00106
00107 std::string const & detName = gdv[i]->name().fullname();
00108 if (thePixelDetTypeMap.find(detName) == thePixelDetTypeMap.end()) {
00109 std::auto_ptr<const Bounds> bounds(gdv[i]->bounds());
00110
00111 PixelTopology* t =
00112 PixelTopologyBuilder().build(&*bounds,
00113 upgradeGeometry,
00114 gdv[i]->pixROCRows(),
00115 gdv[i]->pixROCCols(),
00116 BIG_PIX_PER_ROC_X,
00117 BIG_PIX_PER_ROC_Y,
00118 gdv[i]->pixROCx(), gdv[i]->pixROCy());
00119
00120 thePixelDetTypeMap[detName] = new PixelGeomDetType(t,detName,det);
00121 tracker->addType(thePixelDetTypeMap[detName]);
00122 }
00123
00124 PlaneBuilderFromGeometricDet::ResultType plane = buildPlaneWithMaterial(gdv[i]);
00125 GeomDetUnit* temp = new PixelGeomDetUnit(&(*plane),thePixelDetTypeMap[detName],gdv[i]);
00126
00127 tracker->addDetUnit(temp);
00128 tracker->addDetUnitId(gdv[i]->geographicalID());
00129 }
00130 tracker->setEndsetDU(det);
00131
00132 }
00133
00134 void TrackerGeomBuilderFromGeometricDet::buildSilicon(std::vector<const GeometricDet*> const & gdv,
00135 TrackerGeometry* tracker,
00136 GeomDetType::SubDetector det,
00137 const std::string& part)
00138 {
00139 tracker->setOffsetDU(det);
00140
00141 for(u_int32_t i=0;i<gdv.size();i++){
00142
00143 std::string const & detName = gdv[i]->name().fullname();
00144 if (theStripDetTypeMap.find(detName) == theStripDetTypeMap.end()) {
00145 std::auto_ptr<const Bounds> bounds(gdv[i]->bounds());
00146 StripTopology* t =
00147 StripTopologyBuilder().build(&*bounds,
00148 gdv[i]->siliconAPVNum(),
00149 part);
00150 theStripDetTypeMap[detName] = new StripGeomDetType( t,detName,det,
00151 gdv[i]->stereo());
00152 tracker->addType(theStripDetTypeMap[detName]);
00153 }
00154
00155 StripSubdetector sidet( gdv[i]->geographicalID());
00156 double scale = (sidet.partnerDetId()) ? 0.5 : 1.0 ;
00157
00158 PlaneBuilderFromGeometricDet::ResultType plane = buildPlaneWithMaterial(gdv[i],scale);
00159 GeomDetUnit* temp = new StripGeomDetUnit(&(*plane), theStripDetTypeMap[detName],gdv[i]);
00160
00161 tracker->addDetUnit(temp);
00162 tracker->addDetUnitId(gdv[i]->geographicalID());
00163 }
00164 tracker->setEndsetDU(det);
00165
00166 }
00167
00168
00169 void TrackerGeomBuilderFromGeometricDet::buildGeomDet(TrackerGeometry* tracker){
00170 PlaneBuilderForGluedDet gluedplaneBuilder;
00171 std::vector<GeomDetUnit*> const & gdu= tracker->detUnits();
00172 std::vector<DetId> const & gduId = tracker->detUnitIds();
00173
00174 for(u_int32_t i=0;i<gdu.size();i++){
00175 StripSubdetector sidet( gduId[i].rawId());
00176 tracker->addDet((GeomDet*) gdu[i]);
00177 tracker->addDetId(gduId[i]);
00178 if(sidet.glued()!=0&&sidet.stereo()==1){
00179 int partner_pos=-1;
00180 for(u_int32_t jj=0;jj<gduId.size();jj++){
00181 if(sidet.partnerDetId()== gduId[jj]) {
00182 partner_pos=jj;
00183 break;
00184 }
00185 }
00186 const GeomDetUnit* dus = gdu[i];
00187 if(partner_pos==-1){
00188 throw cms::Exception("Configuration") <<"No partner detector found \n"
00189 <<"There is a problem on Tracker geometry configuration\n";
00190 }
00191 const GeomDetUnit* dum = gdu[partner_pos];
00192 std::vector<const GeomDetUnit *> glued(2);
00193 glued[0]=dum;
00194 glued[1]=dus;
00195 PlaneBuilderForGluedDet::ResultType plane = gluedplaneBuilder.plane(glued);
00196 GluedGeomDet* gluedDet = new GluedGeomDet(&(*plane),dum,dus);
00197 tracker->addDet((GeomDet*) gluedDet);
00198 tracker->addDetId(DetId(sidet.glued()));
00199 }
00200 }
00201 }
00202
00203 PlaneBuilderFromGeometricDet::ResultType
00204 TrackerGeomBuilderFromGeometricDet::buildPlaneWithMaterial(const GeometricDet* gd,
00205 double scale) const
00206 {
00207 PlaneBuilderFromGeometricDet planeBuilder;
00208 PlaneBuilderFromGeometricDet::ResultType plane = planeBuilder.plane(gd);
00209
00210
00211
00212 plane->setMediumProperties(MediumProperties(gd->radLength()*scale,gd->xi()*scale));
00213
00214 return plane;
00215 }