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
00137 RCPPlane surf(plane(fv, new RectangularPlaneBounds(width, length, thickness) ));
00138
00139 DTChamber* chamber = new DTChamber(detId, surf);
00140
00141 return chamber;
00142 }
00143
00144 DTSuperLayer* DTGeometryBuilderFromDDD::buildSuperLayer(DDFilteredView& fv,
00145 DTChamber* chamber,
00146 const std::string& type,
00147 const MuonDDDConstants& muonConstants) const {
00148
00149 MuonDDDNumbering mdddnum(muonConstants);
00150 DTNumberingScheme dtnum(muonConstants);
00151 int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
00152 DTSuperLayerId slId(rawid);
00153
00154
00155 vector<double> par = extractParameters(fv);
00156
00157 float width = par[0]/cm;
00158 float length = par[1]/cm;
00159 float thickness = par[2]/cm;
00160
00161
00162 RCPPlane surf(plane(fv, new RectangularPlaneBounds(width, length, thickness) ));
00163
00164 DTSuperLayer* slayer = new DTSuperLayer(slId, surf, chamber);
00165
00166
00167
00168
00169
00170 chamber->add(slayer);
00171 return slayer;
00172 }
00173
00174
00175 DTLayer* DTGeometryBuilderFromDDD::buildLayer(DDFilteredView& fv,
00176 DTSuperLayer* sl,
00177 const std::string& type,
00178 const MuonDDDConstants& muonConstants) const {
00179
00180 MuonDDDNumbering mdddnum(muonConstants);
00181 DTNumberingScheme dtnum(muonConstants);
00182 int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
00183 DTLayerId layId(rawid);
00184
00185
00186 vector<double> par = extractParameters(fv);
00187 float width = par[0]/cm;
00188 float length = par[1]/cm;
00189 float thickness = par[2]/cm;
00190
00191 RCPPlane surf(plane(fv, new RectangularPlaneBounds(width, length, thickness) ));
00192
00193
00194 bool doWire = fv.firstChild();
00195 int WCounter=0;
00196 int firstWire=fv.copyno();
00197 par = extractParameters(fv);
00198 float wireLength = par[1]/cm;
00199 while (doWire) {
00200 WCounter++;
00201 doWire = fv.nextSibling();
00202 }
00203
00204 DTTopology topology(firstWire, WCounter, wireLength);
00205
00206 DTLayerType layerType;
00207
00208 DTLayer* layer = new DTLayer(layId, surf, topology, layerType, sl);
00209
00210 sl->add(layer);
00211 return layer;
00212 }
00213
00214 vector<double>
00215 DTGeometryBuilderFromDDD::extractParameters(DDFilteredView& fv) const {
00216 vector<double> par;
00217 if (fv.logicalPart().solid().shape() != ddbox) {
00218 DDBooleanSolid bs(fv.logicalPart().solid());
00219 DDSolid A = bs.solidA();
00220 while (A.shape() != ddbox) {
00221 DDBooleanSolid bs(A);
00222 A = bs.solidA();
00223 }
00224 par=A.parameters();
00225 } else {
00226 par = fv.logicalPart().solid().parameters();
00227 }
00228 return par;
00229 }
00230
00231 DTGeometryBuilderFromDDD::RCPPlane
00232 DTGeometryBuilderFromDDD::plane(const DDFilteredView& fv,
00233 Bounds * bounds) const {
00234
00235 const DDTranslation & trans(fv.translation());
00236
00237 const Surface::PositionType posResult(float(trans.x()/cm),
00238 float(trans.y()/cm),
00239 float(trans.z()/cm));
00240
00241
00242
00243
00244
00245
00246 DDRotationMatrix rotation = fv.rotation();
00247 DD3Vector x, y, z;
00248 rotation.GetComponents(x,y,z);
00249
00250
00251
00252
00253
00254
00255 Surface::RotationType rotResult(float(x.X()),float(x.Y()),float(x.Z()),
00256 float(y.X()),float(y.Y()),float(y.Z()),
00257 float(z.X()),float(z.Y()),float(z.Z()));
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 return RCPPlane( new Plane( posResult, rotResult, bounds));
00268 }