CMS 3D CMS Logo

RPCGeometryBuilderFromDDD.cc

Go to the documentation of this file.
00001 
00006 #include "Geometry/RPCGeometryBuilder/src/RPCGeometryBuilderFromDDD.h"
00007 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00008 #include "Geometry/RPCGeometry/interface/RPCRollSpecs.h"
00009 
00010 #include <DetectorDescription/Core/interface/DDFilter.h>
00011 #include <DetectorDescription/Core/interface/DDFilteredView.h>
00012 #include <DetectorDescription/Core/interface/DDSolid.h>
00013 
00014 #include "Geometry/MuonNumbering/interface/MuonDDDNumbering.h"
00015 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
00016 #include "Geometry/MuonNumbering/interface/RPCNumberingScheme.h"
00017 
00018 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
00019 #include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h"
00020 
00021 #include "DataFormats/GeometryVector/interface/Basic3DVector.h"
00022 
00023 #include "CLHEP/Units/SystemOfUnits.h"
00024 
00025 #include <iostream>
00026 #include <algorithm>
00027 
00028 RPCGeometryBuilderFromDDD::RPCGeometryBuilderFromDDD(bool comp11) : theComp11Flag(comp11)
00029 { }
00030 
00031 RPCGeometryBuilderFromDDD::~RPCGeometryBuilderFromDDD() 
00032 { }
00033 
00034 RPCGeometry* RPCGeometryBuilderFromDDD::build(const DDCompactView* cview, const MuonDDDConstants& muonConstants)
00035 {
00036   std::string attribute = "ReadOutName"; // could come from .orcarc
00037   std::string value     = "MuonRPCHits";    // could come from .orcarc
00038   DDValue val(attribute, value, 0.0);
00039 
00040   // Asking only for the MuonRPC's
00041   DDSpecificsFilter filter;
00042   filter.setCriteria(val, // name & value of a variable 
00043                      DDSpecificsFilter::matches,
00044                      DDSpecificsFilter::AND, 
00045                      true, // compare strings otherwise doubles
00046                      true // use merged-specifics or simple-specifics
00047                      );
00048   DDFilteredView fview(*cview);
00049   fview.addFilter(filter);
00050 
00051   return this->buildGeometry(fview, muonConstants);
00052 }
00053 
00054 RPCGeometry* RPCGeometryBuilderFromDDD::buildGeometry(DDFilteredView& fview, const MuonDDDConstants& muonConstants)
00055 {
00056 #ifdef LOCAL_DEBUG  
00057   std::cout <<"Building the geometry service"<<std::endl;
00058 #endif
00059   RPCGeometry* geometry = new RPCGeometry();
00060 
00061 #ifdef LOCAL_DEBUG  
00062   std::cout << "About to run through the RPC structure" << std::endl;
00063   std::cout <<" First logical part "
00064             <<fview.logicalPart().name().name()<<std::endl;
00065 #endif
00066   bool doSubDets = fview.firstChild();
00067 
00068 #ifdef LOCAL_DEBUG  
00069   std::cout << "doSubDets = " << doSubDets << std::endl;
00070 #endif
00071   while (doSubDets){
00072 
00073 #ifdef LOCAL_DEBUG  
00074     std::cout <<"start the loop"<<std::endl; 
00075 #endif
00076 
00077     // Get the Base Muon Number
00078     MuonDDDNumbering mdddnum(muonConstants);
00079 #ifdef LOCAL_DEBUG  
00080     std::cout <<"Getting the Muon base Number"<<std::endl;
00081 #endif
00082     MuonBaseNumber   mbn=mdddnum.geoHistoryToBaseNumber(fview.geoHistory());
00083 
00084 #ifdef LOCAL_DEBUG  
00085     std::cout <<"Start the Rpc Numbering Schema"<<std::endl;
00086 #endif
00087     // Get the The Rpc det Id 
00088     RPCNumberingScheme rpcnum(muonConstants);
00089     int detid = 0;
00090 
00091 #ifdef LOCAL_DEBUG  
00092     std::cout <<"Getting the Unit Number"<<std::endl;
00093 #endif
00094     detid = rpcnum.baseNumberToUnitNumber(mbn);
00095 #ifdef LOCAL_DEBUG  
00096     std::cout <<"Getting the RPC det Id "<<detid <<std::endl;
00097 #endif
00098     RPCDetId rpcid(detid);
00099     RPCDetId chid(rpcid.region(),rpcid.ring(),rpcid.station(),rpcid.sector(),rpcid.layer(),rpcid.subsector(),0);
00100 
00101 #ifdef LOCAL_DEBUG  
00102     std::cout <<"The RPCDetid is "<<rpcid<<std::endl;
00103 #endif
00104 
00105     DDValue numbOfStrips("nStrips");
00106 
00107     std::vector<const DDsvalues_type* > specs(fview.specifics());
00108     std::vector<const DDsvalues_type* >::iterator is=specs.begin();
00109     int nStrips=0;
00110     for (;is!=specs.end(); is++){
00111       if (DDfetch( *is, numbOfStrips)){
00112         nStrips=int(numbOfStrips.doubles()[0]); 
00113       }
00114     }
00115 #ifdef LOCAL_DEBUG  
00116     if (nStrips == 0 )
00117       std::cout <<"No strip found!!"<<std::endl;
00118 #endif
00119     
00120     std::vector<double> dpar=fview.logicalPart().solid().parameters();
00121     std::string name=fview.logicalPart().name().name();
00122     DDTranslation tran    = fview.translation();
00123     //removed .Inverse after comparing to DT...
00124     DDRotationMatrix rota = fview.rotation();//.Inverse();
00125     Surface::PositionType pos(tran.x()/cm,tran.y()/cm, tran.z()/cm);
00126     // CLHEP way
00127 //     Surface::RotationType rot(rota.xx(),rota.xy(),rota.xz(),
00128 //                            rota.yx(),rota.yy(),rota.yz(),
00129 //                            rota.zx(),rota.zy(),rota.zz());
00130 
00131 //ROOT::Math way
00132     DD3Vector x, y, z;
00133     rota.GetComponents(x,y,z);
00134     // doesn't this just re-inverse???
00135     Surface::RotationType rot (float(x.X()),float(x.Y()),float(x.Z()),
00136                                float(y.X()),float(y.Y()),float(y.Z()),
00137                                float(z.X()),float(z.Y()),float(z.Z())); 
00138     
00139     std::vector<float> pars;
00140     RPCRollSpecs* rollspecs= 0;
00141     Bounds* bounds = 0;
00142 
00143 
00144 
00145     if (dpar.size()==3){
00146       float width     = dpar[0]/cm;
00147       float length    = dpar[1]/cm;
00148       float thickness = dpar[2]/cm;
00149       //RectangularPlaneBounds* 
00150       bounds = 
00151         new RectangularPlaneBounds(width,length,thickness);
00152       pars.push_back(width);
00153       pars.push_back(length);
00154       pars.push_back(numbOfStrips.doubles()[0]); //h/2;
00155 
00156       if (!theComp11Flag) {
00157         //Correction of the orientation to get the REAL geometry.
00158         //Change of axes for the +z part only.
00159         //Including the 0 whell
00160         if (tran.z() >-1500. ){
00161           Basic3DVector<float> newX(-1.,0.,0.);
00162           Basic3DVector<float> newY(0.,-1.,0.);
00163           Basic3DVector<float> newZ(0.,0.,1.);
00164           rot.rotateAxes (newX, newY,newZ);
00165         }
00166       }
00167       
00168       rollspecs = new RPCRollSpecs(GeomDetEnumerators::RPCBarrel,name,pars);
00169 #ifdef LOCAL_DEBUG  
00170       std::cout <<"Barrel "<<name
00171                 <<" par "<<width
00172                 <<" "<<length<<" "<<thickness;
00173 #endif
00174     }else{
00175       float be = dpar[4]/cm;
00176       float te = dpar[8]/cm;
00177       float ap = dpar[0]/cm;
00178       float ti = 0.4/cm;
00179       //  TrapezoidalPlaneBounds* 
00180       bounds = 
00181         new TrapezoidalPlaneBounds(be,te,ap,ti);
00182       pars.push_back(dpar[4]/cm); //b/2;
00183       pars.push_back(dpar[8]/cm); //B/2;
00184       pars.push_back(dpar[0]/cm); //h/2;
00185       pars.push_back(numbOfStrips.doubles()[0]); //h/2;
00186       
00187 #ifdef LOCAL_DEBUG  
00188       std::cout <<"Forward "<<name
00189                 <<" par "<<dpar[4]/cm
00190                 <<" "<<dpar[8]/cm<<" "<<dpar[3]/cm<<" "
00191                 <<dpar[0];
00192 #endif      
00193 
00194       rollspecs = new RPCRollSpecs(GeomDetEnumerators::RPCEndcap,name,pars);
00195 
00196       //Change of axes for the forward
00197       Basic3DVector<float> newX(1.,0.,0.);
00198       Basic3DVector<float> newY(0.,0.,1.);
00199       if (tran.z() > 0. )
00200         newY *= -1;
00201       Basic3DVector<float> newZ(0.,1.,0.);
00202       rot.rotateAxes (newX, newY,newZ);
00203       
00204     }
00205 #ifdef LOCAL_DEBUG  
00206     std::cout <<"   Number of strips "<<nStrips<<std::endl;
00207 #endif  
00208 
00209 
00210     
00211     BoundPlane* bp = new BoundPlane(pos,rot,bounds);
00212     ReferenceCountingPointer<BoundPlane> surf(bp);
00213     RPCRoll* r=new RPCRoll(rpcid,surf,rollspecs);
00214     geometry->add(r);
00215     
00216 
00217     std::list<RPCRoll *> rls;
00218     if (chids.find(chid)!=chids.end()){
00219       rls = chids[chid];
00220     }
00221     rls.push_back(r);
00222     chids[chid]=rls;
00223 
00224     doSubDets = fview.nextSibling(); // go to next layer
00225   }
00226   // Create the RPCChambers and store them on the Geometry 
00227   for( std::map<RPCDetId, std::list<RPCRoll *> >::iterator ich=chids.begin();
00228        ich != chids.end(); ich++){
00229     RPCDetId chid = ich->first;
00230     std::list<RPCRoll * > rls = ich->second;
00231 
00232     // compute the overall boundplane. At the moment we use just the last
00233     // surface
00234     BoundPlane* bp=0;
00235     for(std::list<RPCRoll *>::iterator rl=rls.begin();
00236     rl!=rls.end(); rl++){
00237       const BoundPlane& bps = (*rl)->surface();
00238       bp = const_cast<BoundPlane *>(&bps);
00239     }
00240 
00241     ReferenceCountingPointer<BoundPlane> surf(bp);
00242     // Create the chamber 
00243     RPCChamber* ch = new RPCChamber (chid, surf); 
00244     // Add the rolls to rhe chamber
00245     for(std::list<RPCRoll *>::iterator rl=rls.begin();
00246     rl!=rls.end(); rl++){
00247       ch->add(*rl);
00248     }
00249     // Add the chamber to the geometry
00250     geometry->add(ch);
00251   } 
00252   return geometry;
00253 }
00254 
00255     
00256 

Generated on Tue Jun 9 17:37:32 2009 for CMSSW by  doxygen 1.5.4