CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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 
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   // Slayer specific parameter (size)
00155   vector<double> par = extractParameters(fv);
00156 
00157   float width = par[0]/cm;     // r-phi  dimension - changes in different chambers
00158   float length = par[1]/cm;    // z      dimension - constant 126.8 cm
00159   float thickness = par[2]/cm; // radial thickness - almost constant about 20 cm
00160 
00161   // Ok this is the slayer position...
00162   RCPPlane surf(plane(fv, new RectangularPlaneBounds(width, length, thickness) ));
00163 
00164   DTSuperLayer* slayer = new DTSuperLayer(slId, surf, chamber);
00165 
00166   //LocalPoint lpos(10,20,30);
00167   //GlobalPoint gpos=slayer->toGlobal(lpos);
00168 
00169   // add to the chamber
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   // Layer specific parameter (size)
00186   vector<double> par = extractParameters(fv);
00187   float width = par[0]/cm;     // r-phi  dimension - changes in different chambers
00188   float length = par[1]/cm;    // z      dimension - constant 126.8 cm
00189   float thickness = par[2]/cm; // radial thickness - almost constant about 20 cm
00190 
00191   RCPPlane surf(plane(fv, new RectangularPlaneBounds(width, length, thickness) ));
00192 
00193   // Loop on wires
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(); // next wire
00202   }
00203   //int lastWire=fv.copyno();
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   // extract the position
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   // now the rotation
00241   //  DDRotationMatrix tmp = fv.rotation();
00242   // === DDD uses 'active' rotations - see CLHEP user guide ===
00243   //     ORCA uses 'passive' rotation. 
00244   //     'active' and 'passive' rotations are inverse to each other
00245   //  DDRotationMatrix tmp = fv.rotation();
00246   DDRotationMatrix rotation = fv.rotation();//REMOVED .Inverse();
00247   DD3Vector x, y, z;
00248   rotation.GetComponents(x,y,z);
00249 //   std::cout << "INVERSE rotation by its own operator: "<< fv.rotation() << std::endl;
00250 //   std::cout << "INVERSE rotation manually: "
00251 //          << x.X() << ", " << x.Y() << ", " << x.Z() << std::endl
00252 //          << y.X() << ", " << y.Y() << ", " << y.Z() << std::endl
00253 //          << z.X() << ", " << z.Y() << ", " << z.Z() << std::endl;
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 //   std::cout << "rotation by its own operator: "<< tmp << std::endl;
00260 //   DD3Vector tx, ty,tz;
00261 //   tmp.GetComponents(tx, ty, tz);
00262 //   std::cout << "rotation manually: "
00263 //          << tx.X() << ", " << tx.Y() << ", " << tx.Z() << std::endl
00264 //          << ty.X() << ", " << ty.Y() << ", " << ty.Z() << std::endl
00265 //          << tz.X() << ", " << tz.Y() << ", " << tz.Z() << std::endl;
00266 
00267   return RCPPlane( new Plane( posResult, rotResult, bounds));
00268 }