CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/Geometry/DTGeometryBuilder/src/DTGeometryParsFromDD.cc

Go to the documentation of this file.
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   //  cout << "DTGeometryParsFromDD::build" << endl;
00043   //   static const string t0 = "DTGeometryParsFromDD::build";
00044   //   TimeMe timer(t0,true);
00045 
00046   std::string attribute = "MuStructure"; 
00047   std::string value     = "MuonBarrelDT";
00048   DDValue val(attribute, value, 0.0);
00049 
00050   // Asking only for the Muon DTs
00051   DDSpecificsFilter filter;
00052   filter.setCriteria(val,  // name & value of a variable 
00053                      DDSpecificsFilter::matches,
00054                      DDSpecificsFilter::AND, 
00055                      true, // compare strings otherwise doubles
00056                      true  // use merged-specifics or simple-specifics
00057                      );
00058   DDFilteredView fview(*cview);
00059   fview.addFilter(filter);
00060   buildGeometry(fview, muonConstants, rig);
00061   //cout << "RecoIdealGeometry " << rig.size() << endl;
00062 }
00063 
00064 
00065 void DTGeometryParsFromDD::buildGeometry(DDFilteredView& fv,
00066                                          const MuonDDDConstants& muonConstants,
00067                                          RecoIdealGeometry& rig) const {
00068   // static const string t0 = "DTGeometryParsFromDD::buildGeometry";
00069   // TimeMe timer(t0,true);
00070 
00071   bool doChamber = fv.firstChild();
00072 
00073   // Loop on chambers
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(&params,val)) type = val.strings()[0];
00081     // FIXME
00082     val=DDValue("FEPos");
00083     string FEPos;
00084     if (DDfetch(&params,val)) FEPos = val.strings()[0];
00085     insertChamber(fv,type, muonConstants,rig);
00086 
00087     // Loop on SLs
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       // Loop on SLs
00097       while (doL) {
00098         LCounter++;
00099         insertLayer(fv, type, muonConstants, rig);
00100 
00101         // fv.parent();
00102         doL = fv.nextSibling(); // go to next layer
00103       } // layers
00104 
00105       fv.parent();
00106       doSL = fv.nextSibling(); // go to next SL
00107     } // sls
00108 
00109     fv.parent();
00110     doChamber = fv.nextSibling(); // go to next chamber
00111   } // chambers
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   //cout << "inserting Chamber " << detId << endl;
00123 
00124   // Chamber specific parameter (size) 
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   // width is along local X
00132   // length is along local Y
00133   // thickness is long local Z
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   //cout << "inserting SuperLayer " << slId << endl;
00150 
00151   // Slayer specific parameter (size)
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   // Ok this is the slayer position...
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   //cout << "inserting Layer " << layId << endl;
00173 
00174   // Layer specific parameter (size)
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   // Loop on wires
00181   bool doWire = fv.firstChild();
00182   int WCounter=0;
00183   int firstWire=fv.copyno();
00184   //float wireLength = par[1]/cm;
00185   while (doWire) {
00186     WCounter++;
00187     doWire = fv.nextSibling(); // next wire
00188   }
00189   vector<double> sensSize= extractParameters(fv);
00190   //int lastWire=fv.copyno();
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   // extract the position
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   // now the rotation
00230   //  DDRotationMatrix tmp = fv.rotation();
00231   // === DDD uses 'active' rotations - see CLHEP user guide ===
00232   //     ORCA uses 'passive' rotation. 
00233   //     'active' and 'passive' rotations are inverse to each other
00234   //  DDRotationMatrix tmp = fv.rotation();
00235   DDRotationMatrix rotation = fv.rotation();//REMOVED .Inverse();
00236   DD3Vector x, y, z;
00237   rotation.GetComponents(x,y,z);
00238 //   std::cout << "INVERSE rotation by its own operator: "<< fv.rotation() << std::endl;
00239 //   std::cout << "INVERSE rotation manually: "
00240 //          << x.X() << ", " << x.Y() << ", " << x.Z() << std::endl
00241 //          << y.X() << ", " << y.Y() << ", " << y.Z() << std::endl
00242 //          << z.X() << ", " << z.Y() << ", " << z.Z() << std::endl;
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 //   std::cout << "rotation by its own operator: "<< tmp << std::endl;
00258 //   DD3Vector tx, ty,tz;
00259 //   tmp.GetComponents(tx, ty, tz);
00260 //   std::cout << "rotation manually: "
00261 //          << tx.X() << ", " << tx.Y() << ", " << tx.Z() << std::endl
00262 //          << ty.X() << ", " << ty.Y() << ", " << ty.Z() << std::endl
00263 //          << tz.X() << ", " << tz.Y() << ", " << tz.Z() << std::endl;
00264 
00265   return pair<std::vector<double>, std::vector<double> >(gtran, grmat);
00266 }