00001
00008 #include <Geometry/DTGeometryBuilder/src/DTGeometryParsFromDD.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 <CondFormats/GeometryObjects/interface/RecoIdealGeometry.h>
00014 #include <DetectorDescription/Core/interface/DDFilter.h>
00015 #include <DetectorDescription/Core/interface/DDFilteredView.h>
00016 #include <DetectorDescription/Core/interface/DDSolid.h>
00017 #include "Geometry/MuonNumbering/interface/MuonDDDNumbering.h"
00018 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
00019 #include "Geometry/MuonNumbering/interface/DTNumberingScheme.h"
00020 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00021 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00022
00023
00024 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
00025
00026 #include <string>
00027
00028 using namespace std;
00029
00030 #include <string>
00031
00032 using namespace std;
00033
00034 DTGeometryParsFromDD::DTGeometryParsFromDD() {}
00035
00036 DTGeometryParsFromDD::~DTGeometryParsFromDD(){}
00037
00038
00039 void DTGeometryParsFromDD::build(const DDCompactView* cview,
00040 const MuonDDDConstants& muonConstants,
00041 RecoIdealGeometry& rig) {
00042
00043
00044
00045
00046 std::string attribute = "MuStructure";
00047 std::string value = "MuonBarrelDT";
00048 DDValue val(attribute, value, 0.0);
00049
00050
00051 DDSpecificsFilter filter;
00052 filter.setCriteria(val,
00053 DDSpecificsFilter::matches,
00054 DDSpecificsFilter::AND,
00055 true,
00056 true
00057 );
00058 DDFilteredView fview(*cview);
00059 fview.addFilter(filter);
00060 buildGeometry(fview, muonConstants, rig);
00061
00062 }
00063
00064
00065 void DTGeometryParsFromDD::buildGeometry(DDFilteredView& fv,
00066 const MuonDDDConstants& muonConstants,
00067 RecoIdealGeometry& rig) const {
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 insertChamber(fv,type, muonConstants,rig);
00086
00087
00088 bool doSL = fv.firstChild();
00089 int SLCounter=0;
00090 while (doSL) {
00091 SLCounter++;
00092 insertSuperLayer(fv, type, muonConstants,rig);
00093
00094 bool doL = fv.firstChild();
00095 int LCounter=0;
00096
00097 while (doL) {
00098 LCounter++;
00099 insertLayer(fv, type, muonConstants, rig);
00100
00101
00102 doL = fv.nextSibling();
00103 }
00104
00105 fv.parent();
00106 doSL = fv.nextSibling();
00107 }
00108
00109 fv.parent();
00110 doChamber = fv.nextSibling();
00111 }
00112 }
00113
00114 void DTGeometryParsFromDD::insertChamber(DDFilteredView& fv,
00115 const string& type,
00116 const MuonDDDConstants& muonConstants,
00117 RecoIdealGeometry& rig) const {
00118 MuonDDDNumbering mdddnum (muonConstants);
00119 DTNumberingScheme dtnum (muonConstants);
00120 int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
00121 DTChamberId detId(rawid);
00122
00123
00124
00125 vector<double> par;
00126 par.push_back(DTChamberTag);
00127 vector<double> size= extractParameters(fv);
00128 par.insert(par.end(), size.begin(), size.end());
00129
00131
00132
00133
00134
00135 PosRotPair posRot(plane(fv));
00136
00137 rig.insert(rawid, posRot.first, posRot.second, par);
00138 }
00139
00140 void DTGeometryParsFromDD::insertSuperLayer(DDFilteredView& fv,
00141 const std::string& type,
00142 const MuonDDDConstants& muonConstants,
00143 RecoIdealGeometry& rig) const {
00144
00145 MuonDDDNumbering mdddnum(muonConstants);
00146 DTNumberingScheme dtnum(muonConstants);
00147 int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
00148 DTSuperLayerId slId(rawid);
00149
00150
00151
00152 vector<double> par;
00153 par.push_back(DTSuperLayerTag);
00154 vector<double> size= extractParameters(fv);
00155 par.insert(par.end(), size.begin(), size.end());
00156
00157
00158 PosRotPair posRot(plane(fv));
00159
00160 rig.insert(slId, posRot.first, posRot.second, par);
00161 }
00162
00163 void DTGeometryParsFromDD::insertLayer(DDFilteredView& fv,
00164 const std::string& type,
00165 const MuonDDDConstants& muonConstants,
00166 RecoIdealGeometry& rig) const {
00167
00168 MuonDDDNumbering mdddnum(muonConstants);
00169 DTNumberingScheme dtnum(muonConstants);
00170 int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
00171 DTLayerId layId(rawid);
00172
00173
00174
00175 vector<double> par;
00176 par.push_back(DTLayerTag);
00177 vector<double> size= extractParameters(fv);
00178 par.insert(par.end(), size.begin(), size.end());
00179
00180
00181 bool doWire = fv.firstChild();
00182 int WCounter=0;
00183 int firstWire=fv.copyno();
00184
00185 while (doWire) {
00186 WCounter++;
00187 doWire = fv.nextSibling();
00188 }
00189 vector<double> sensSize= extractParameters(fv);
00190
00191 par.push_back(firstWire);
00192 par.push_back(WCounter);
00193 par.push_back(sensSize[1]);
00194 fv.parent();
00195
00196 PosRotPair posRot(plane(fv));
00197
00198 rig.insert(layId, posRot.first, posRot.second, par);
00199
00200 }
00201
00202 vector<double>
00203 DTGeometryParsFromDD::extractParameters(DDFilteredView& fv) const {
00204 vector<double> par;
00205 if (fv.logicalPart().solid().shape() != ddbox) {
00206 DDBooleanSolid bs(fv.logicalPart().solid());
00207 DDSolid A = bs.solidA();
00208 while (A.shape() != ddbox) {
00209 DDBooleanSolid bs(A);
00210 A = bs.solidA();
00211 }
00212 par=A.parameters();
00213 } else {
00214 par = fv.logicalPart().solid().parameters();
00215 }
00216 return par;
00217 }
00218
00219 DTGeometryParsFromDD::PosRotPair
00220 DTGeometryParsFromDD::plane(const DDFilteredView& fv) const {
00221
00222 const DDTranslation & trans(fv.translation());
00223
00224 std::vector<double> gtran( 3 );
00225 gtran[0] = (float) 1.0 * (trans.x() / cm);
00226 gtran[1] = (float) 1.0 * (trans.y() / cm);
00227 gtran[2] = (float) 1.0 * (trans.z() / cm);
00228
00229
00230
00231
00232
00233
00234
00235 DDRotationMatrix rotation = fv.rotation();
00236 DD3Vector x, y, z;
00237 rotation.GetComponents(x,y,z);
00238
00239
00240
00241
00242
00243
00244 std::vector<double> grmat( 9 );
00245 grmat[0] = (float) 1.0 * x.X();
00246 grmat[1] = (float) 1.0 * x.Y();
00247 grmat[2] = (float) 1.0 * x.Z();
00248
00249 grmat[3] = (float) 1.0 * y.X();
00250 grmat[4] = (float) 1.0 * y.Y();
00251 grmat[5] = (float) 1.0 * y.Z();
00252
00253 grmat[6] = (float) 1.0 * z.X();
00254 grmat[7] = (float) 1.0 * z.Y();
00255 grmat[8] = (float) 1.0 * z.Z();
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 return pair<std::vector<double>, std::vector<double> >(gtran, grmat);
00266 }