CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/Geometry/DTGeometryBuilder/src/DTGeometryBuilderFromDDD.cc

Go to the documentation of this file.
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   //  cout << "DTGeometryBuilderFromDDD::build" << endl;
00042   //   static const string t0 = "DTGeometryBuilderFromDDD::build";
00043   //   TimeMe timer(t0,true);
00044 
00045   std::string attribute = "MuStructure"; 
00046   std::string value     = "MuonBarrelDT";
00047   DDValue val(attribute, value, 0.0);
00048 
00049   // Asking only for the Muon DTs
00050   DDSpecificsFilter filter;
00051   filter.setCriteria(val,  // name & value of a variable 
00052                      DDSpecificsFilter::matches,
00053                      DDSpecificsFilter::AND, 
00054                      true, // compare strings otherwise doubles
00055                      true  // use merged-specifics or simple-specifics
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   // static const string t0 = "DTGeometryBuilderFromDDD::buildGeometry";
00067   // TimeMe timer(t0,true);
00068 
00069   //DTGeometry* theGeometry = new DTGeometry;
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     DTChamber* chamber = buildChamber(fv,type, muonConstants);
00086 
00087     // Loop on SLs
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       // Loop on SLs
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(); // go to next layer
00105       } // layers
00106 
00107       fv.parent();
00108       doSL = fv.nextSibling(); // go to next SL
00109     } // sls
00110     theGeometry->add(chamber);
00111 
00112     fv.parent();
00113     doChamber = fv.nextSibling(); // go to next chamber
00114   } // chambers
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   // Chamber specific parameter (size) 
00125   // FIXME: some trouble for boolean solids?
00126   vector<double> par = extractParameters(fv);
00127 
00128   float width = par[0]/cm;     // r-phi  dimension - different in different chambers
00129   float length = par[1]/cm;    // z      dimension - constant 125.55 cm
00130   float thickness = par[2]/cm; // radial thickness - almost constant about 18 cm
00131 
00133   // width is along local X
00134   // length is along local Y
00135   // thickness is long local Z
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   // Slayer specific parameter (size)
00156   vector<double> par = extractParameters(fv);
00157 
00158   float width = par[0]/cm;     // r-phi  dimension - changes in different chambers
00159   float length = par[1]/cm;    // z      dimension - constant 126.8 cm
00160   float thickness = par[2]/cm; // radial thickness - almost constant about 20 cm
00161 
00162   RectangularPlaneBounds bound(width, length, thickness);
00163 
00164   // Ok this is the slayer position...
00165   RCPPlane surf(plane(fv,bound));
00166 
00167   DTSuperLayer* slayer = new DTSuperLayer(slId, surf, chamber);
00168 
00169   //LocalPoint lpos(10,20,30);
00170   //GlobalPoint gpos=slayer->toGlobal(lpos);
00171 
00172   // add to the chamber
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   // Layer specific parameter (size)
00189   vector<double> par = extractParameters(fv);
00190   float width = par[0]/cm;     // r-phi  dimension - changes in different chambers
00191   float length = par[1]/cm;    // z      dimension - constant 126.8 cm
00192   float thickness = par[2]/cm; // radial thickness - almost constant about 20 cm
00193 
00194   // define Bounds
00195   RectangularPlaneBounds bound(width, length, thickness);
00196 
00197   RCPPlane surf(plane(fv,bound));
00198 
00199   // Loop on wires
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(); // next wire
00208   }
00209   //int lastWire=fv.copyno();
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   // extract the position
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   // now the rotation
00247   //  DDRotationMatrix tmp = fv.rotation();
00248   // === DDD uses 'active' rotations - see CLHEP user guide ===
00249   //     ORCA uses 'passive' rotation. 
00250   //     'active' and 'passive' rotations are inverse to each other
00251   //  DDRotationMatrix tmp = fv.rotation();
00252   DDRotationMatrix rotation = fv.rotation();//REMOVED .Inverse();
00253   DD3Vector x, y, z;
00254   rotation.GetComponents(x,y,z);
00255 //   std::cout << "INVERSE rotation by its own operator: "<< fv.rotation() << std::endl;
00256 //   std::cout << "INVERSE rotation manually: "
00257 //          << x.X() << ", " << x.Y() << ", " << x.Z() << std::endl
00258 //          << y.X() << ", " << y.Y() << ", " << y.Z() << std::endl
00259 //          << z.X() << ", " << z.Y() << ", " << z.Z() << std::endl;
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 //   std::cout << "rotation by its own operator: "<< tmp << std::endl;
00266 //   DD3Vector tx, ty,tz;
00267 //   tmp.GetComponents(tx, ty, tz);
00268 //   std::cout << "rotation manually: "
00269 //          << tx.X() << ", " << tx.Y() << ", " << tx.Z() << std::endl
00270 //          << ty.X() << ", " << ty.Y() << ", " << ty.Z() << std::endl
00271 //          << tz.X() << ", " << tz.Y() << ", " << tz.Z() << std::endl;
00272 
00273   return RCPPlane( new BoundPlane( posResult, rotResult, bounds));
00274 }