00001
00008 #include <Geometry/DTGeometryBuilder/src/DTGeometryBuilderFromDDD.h>
00009 #include <Geometry/DTGeometry/interface/DTGeometry.h>
00010 #include <Geometry/DTGeometry/interface/DTChamber.h>
00011 #include <Geometry/DTGeometry/interface/DTLayer.h>
00012
00013 #include <DetectorDescription/Core/interface/DDFilter.h>
00014 #include <DetectorDescription/Core/interface/DDFilteredView.h>
00015 #include <DetectorDescription/Core/interface/DDSolid.h>
00016 #include "Geometry/MuonNumbering/interface/MuonDDDNumbering.h"
00017 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
00018 #include "Geometry/MuonNumbering/interface/DTNumberingScheme.h"
00019 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00020 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00021
00022
00023 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
00024
00025 #include <string>
00026
00027 using namespace std;
00028
00029 #include <string>
00030
00031 using namespace std;
00032
00033 DTGeometryBuilderFromDDD::DTGeometryBuilderFromDDD() {}
00034
00035 DTGeometryBuilderFromDDD::~DTGeometryBuilderFromDDD(){}
00036
00037
00038 void DTGeometryBuilderFromDDD::build(boost::shared_ptr<DTGeometry> theGeometry,
00039 const DDCompactView* cview,
00040 const MuonDDDConstants& muonConstants){
00041
00042
00043
00044
00045 std::string attribute = "MuStructure";
00046 std::string value = "MuonBarrelDT";
00047 DDValue val(attribute, value, 0.0);
00048
00049
00050 DDSpecificsFilter filter;
00051 filter.setCriteria(val,
00052 DDSpecificsFilter::matches,
00053 DDSpecificsFilter::AND,
00054 true,
00055 true
00056 );
00057 DDFilteredView fview(*cview);
00058 fview.addFilter(filter);
00059 buildGeometry(theGeometry, fview, muonConstants);
00060 }
00061
00062
00063 void DTGeometryBuilderFromDDD::buildGeometry(boost::shared_ptr<DTGeometry> theGeometry,
00064 DDFilteredView& fv,
00065 const MuonDDDConstants& muonConstants) const {
00066
00067
00068
00069
00070
00071 bool doChamber = fv.firstChild();
00072
00073
00074 int ChamCounter=0;
00075 while (doChamber){
00076 ChamCounter++;
00077 DDValue val("Type");
00078 const DDsvalues_type params(fv.mergedSpecifics());
00079 string type;
00080 if (DDfetch(¶ms,val)) type = val.strings()[0];
00081
00082 val=DDValue("FEPos");
00083 string FEPos;
00084 if (DDfetch(¶ms,val)) FEPos = val.strings()[0];
00085 DTChamber* chamber = buildChamber(fv,type, muonConstants);
00086
00087
00088 bool doSL = fv.firstChild();
00089 int SLCounter=0;
00090 while (doSL) {
00091 SLCounter++;
00092 DTSuperLayer* sl = buildSuperLayer(fv, chamber, type, muonConstants);
00093 theGeometry->add(sl);
00094
00095 bool doL = fv.firstChild();
00096 int LCounter=0;
00097
00098 while (doL) {
00099 LCounter++;
00100 DTLayer* layer = buildLayer(fv, sl, type, muonConstants);
00101 theGeometry->add(layer);
00102
00103 fv.parent();
00104 doL = fv.nextSibling();
00105 }
00106
00107 fv.parent();
00108 doSL = fv.nextSibling();
00109 }
00110 theGeometry->add(chamber);
00111
00112 fv.parent();
00113 doChamber = fv.nextSibling();
00114 }
00115 }
00116
00117 DTChamber* DTGeometryBuilderFromDDD::buildChamber(DDFilteredView& fv,
00118 const string& type, const MuonDDDConstants& muonConstants) const {
00119 MuonDDDNumbering mdddnum (muonConstants);
00120 DTNumberingScheme dtnum (muonConstants);
00121 int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
00122 DTChamberId detId(rawid);
00123
00124
00125
00126 vector<double> par = extractParameters(fv);
00127
00128 float width = par[0]/cm;
00129 float length = par[1]/cm;
00130 float thickness = par[2]/cm;
00131
00133
00134
00135
00136 RectangularPlaneBounds bound(width, length, thickness);
00137
00138 RCPPlane surf(plane(fv,bound));
00139
00140 DTChamber* chamber = new DTChamber(detId, surf);
00141
00142 return chamber;
00143 }
00144
00145 DTSuperLayer* DTGeometryBuilderFromDDD::buildSuperLayer(DDFilteredView& fv,
00146 DTChamber* chamber,
00147 const std::string& type,
00148 const MuonDDDConstants& muonConstants) const {
00149
00150 MuonDDDNumbering mdddnum(muonConstants);
00151 DTNumberingScheme dtnum(muonConstants);
00152 int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
00153 DTSuperLayerId slId(rawid);
00154
00155
00156 vector<double> par = extractParameters(fv);
00157
00158 float width = par[0]/cm;
00159 float length = par[1]/cm;
00160 float thickness = par[2]/cm;
00161
00162 RectangularPlaneBounds bound(width, length, thickness);
00163
00164
00165 RCPPlane surf(plane(fv,bound));
00166
00167 DTSuperLayer* slayer = new DTSuperLayer(slId, surf, chamber);
00168
00169
00170
00171
00172
00173 chamber->add(slayer);
00174 return slayer;
00175 }
00176
00177
00178 DTLayer* DTGeometryBuilderFromDDD::buildLayer(DDFilteredView& fv,
00179 DTSuperLayer* sl,
00180 const std::string& type,
00181 const MuonDDDConstants& muonConstants) const {
00182
00183 MuonDDDNumbering mdddnum(muonConstants);
00184 DTNumberingScheme dtnum(muonConstants);
00185 int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
00186 DTLayerId layId(rawid);
00187
00188
00189 vector<double> par = extractParameters(fv);
00190 float width = par[0]/cm;
00191 float length = par[1]/cm;
00192 float thickness = par[2]/cm;
00193
00194
00195 RectangularPlaneBounds bound(width, length, thickness);
00196
00197 RCPPlane surf(plane(fv,bound));
00198
00199
00200 bool doWire = fv.firstChild();
00201 int WCounter=0;
00202 int firstWire=fv.copyno();
00203 par = extractParameters(fv);
00204 float wireLength = par[1]/cm;
00205 while (doWire) {
00206 WCounter++;
00207 doWire = fv.nextSibling();
00208 }
00209
00210 DTTopology topology(firstWire, WCounter, wireLength);
00211
00212 DTLayerType layerType;
00213
00214 DTLayer* layer = new DTLayer(layId, surf, topology, layerType, sl);
00215
00216 sl->add(layer);
00217 return layer;
00218 }
00219
00220 vector<double>
00221 DTGeometryBuilderFromDDD::extractParameters(DDFilteredView& fv) const {
00222 vector<double> par;
00223 if (fv.logicalPart().solid().shape() != ddbox) {
00224 DDBooleanSolid bs(fv.logicalPart().solid());
00225 DDSolid A = bs.solidA();
00226 while (A.shape() != ddbox) {
00227 DDBooleanSolid bs(A);
00228 A = bs.solidA();
00229 }
00230 par=A.parameters();
00231 } else {
00232 par = fv.logicalPart().solid().parameters();
00233 }
00234 return par;
00235 }
00236
00237 DTGeometryBuilderFromDDD::RCPPlane
00238 DTGeometryBuilderFromDDD::plane(const DDFilteredView& fv,
00239 const Bounds& bounds) const {
00240
00241 const DDTranslation & trans(fv.translation());
00242
00243 const Surface::PositionType posResult(float(trans.x()/cm),
00244 float(trans.y()/cm),
00245 float(trans.z()/cm));
00246
00247
00248
00249
00250
00251
00252 DDRotationMatrix rotation = fv.rotation();
00253 DD3Vector x, y, z;
00254 rotation.GetComponents(x,y,z);
00255
00256
00257
00258
00259
00260
00261 Surface::RotationType rotResult(float(x.X()),float(x.Y()),float(x.Z()),
00262 float(y.X()),float(y.Y()),float(y.Z()),
00263 float(z.X()),float(z.Y()),float(z.Z()));
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 return RCPPlane( new BoundPlane( posResult, rotResult, bounds));
00274 }