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