CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Geometry/RPCGeometryBuilder/src/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/GlobalSystemOfUnits.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   LogDebug("RPCGeometryBuilderFromDDD") <<"Building the geometry service";
00057   RPCGeometry* geometry = new RPCGeometry();
00058 
00059   LogDebug("RPCGeometryBuilderFromDDD") << "About to run through the RPC structure\n" 
00060                                         <<" First logical part "
00061                                         <<fview.logicalPart().name().name();
00062   bool doSubDets = fview.firstChild();
00063 
00064   LogDebug("RPCGeometryBuilderFromDDD") << "doSubDets = " << doSubDets;
00065   while (doSubDets){
00066     LogDebug("RPCGeometryBuilderFromDDD") <<"start the loop"; 
00067 
00068     // Get the Base Muon Number
00069     MuonDDDNumbering mdddnum(muonConstants);
00070     LogDebug("RPCGeometryBuilderFromDDD") <<"Getting the Muon base Number";
00071     MuonBaseNumber   mbn=mdddnum.geoHistoryToBaseNumber(fview.geoHistory());
00072     LogDebug("RPCGeometryBuilderFromDDD") <<"Start the Rpc Numbering Schema";
00073     // Get the The Rpc det Id 
00074     RPCNumberingScheme rpcnum(muonConstants);
00075     int detid = 0;
00076 
00077     LogDebug("RPCGeometryBuilderFromDDD") <<"Getting the Unit Number";
00078     detid = rpcnum.baseNumberToUnitNumber(mbn);
00079     LogDebug("RPCGeometryBuilderFromDDD") <<"Getting the RPC det Id "<<detid;
00080 
00081     RPCDetId rpcid(detid);
00082     RPCDetId chid(rpcid.region(),rpcid.ring(),rpcid.station(),rpcid.sector(),rpcid.layer(),rpcid.subsector(),0);
00083 
00084     LogDebug("RPCGeometryBuilderFromDDD") <<"The RPCDetid is "<<rpcid;
00085 
00086     DDValue numbOfStrips("nStrips");
00087 
00088     std::vector<const DDsvalues_type* > specs(fview.specifics());
00089     std::vector<const DDsvalues_type* >::iterator is=specs.begin();
00090     int nStrips=0;
00091     for (;is!=specs.end(); is++){
00092       if (DDfetch( *is, numbOfStrips)){
00093         nStrips=int(numbOfStrips.doubles()[0]); 
00094       }
00095     }
00096 
00097     LogDebug("RPCGeometryBuilderFromDDD") << ((nStrips == 0 ) ? ("No strip found!!") : (""));
00098     
00099     std::vector<double> dpar=fview.logicalPart().solid().parameters();
00100     std::string name=fview.logicalPart().name().name();
00101     DDTranslation tran    = fview.translation();
00102     //removed .Inverse after comparing to DT...
00103     DDRotationMatrix rota = fview.rotation();//.Inverse();
00104     Surface::PositionType pos(tran.x()/cm,tran.y()/cm, tran.z()/cm);
00105     // CLHEP way
00106 //     Surface::RotationType rot(rota.xx(),rota.xy(),rota.xz(),
00107 //                            rota.yx(),rota.yy(),rota.yz(),
00108 //                            rota.zx(),rota.zy(),rota.zz());
00109 
00110 //ROOT::Math way
00111     DD3Vector x, y, z;
00112     rota.GetComponents(x,y,z);
00113     // doesn't this just re-inverse???
00114     Surface::RotationType rot (float(x.X()),float(x.Y()),float(x.Z()),
00115                                float(y.X()),float(y.Y()),float(y.Z()),
00116                                float(z.X()),float(z.Y()),float(z.Z())); 
00117     
00118     std::vector<float> pars;
00119     RPCRollSpecs* rollspecs= 0;
00120     Bounds* bounds = 0;
00121 
00122 
00123 
00124     if (dpar.size()==3){
00125       float width     = dpar[0]/cm;
00126       float length    = dpar[1]/cm;
00127       float thickness = dpar[2]/cm;
00128       //RectangularPlaneBounds* 
00129       bounds = 
00130         new RectangularPlaneBounds(width,length,thickness);
00131       pars.push_back(width);
00132       pars.push_back(length);
00133       pars.push_back(numbOfStrips.doubles()[0]); //h/2;
00134 
00135       if (!theComp11Flag) {
00136         //Correction of the orientation to get the REAL geometry.
00137         //Change of axes for the +z part only.
00138         //Including the 0 whell
00139         if (tran.z() >-1500. ){
00140           Basic3DVector<float> newX(-1.,0.,0.);
00141           Basic3DVector<float> newY(0.,-1.,0.);
00142           Basic3DVector<float> newZ(0.,0.,1.);
00143           rot.rotateAxes (newX, newY,newZ);
00144         }
00145       }
00146       
00147       rollspecs = new RPCRollSpecs(GeomDetEnumerators::RPCBarrel,name,pars);
00148       LogDebug("RPCGeometryBuilderFromDDD") <<"Barrel "<<name
00149                                             <<" par "<<width
00150                                             <<" "<<length<<" "<<thickness;
00151     }
00152     else{
00153       float be = dpar[4]/cm;
00154       float te = dpar[8]/cm;
00155       float ap = dpar[0]/cm;
00156       float ti = 0.4/cm;
00157       //  TrapezoidalPlaneBounds* 
00158       bounds = 
00159         new TrapezoidalPlaneBounds(be,te,ap,ti);
00160       pars.push_back(dpar[4]/cm); //b/2;
00161       pars.push_back(dpar[8]/cm); //B/2;
00162       pars.push_back(dpar[0]/cm); //h/2;
00163       pars.push_back(numbOfStrips.doubles()[0]); //h/2;
00164       
00165       LogDebug("RPCGeometryBuilderFromDDD") <<"Forward "<<name
00166                                             <<" par "<<dpar[4]/cm
00167                                             <<" "<<dpar[8]/cm<<" "<<dpar[3]/cm<<" "
00168                                             <<dpar[0];
00169 
00170       rollspecs = new RPCRollSpecs(GeomDetEnumerators::RPCEndcap,name,pars);
00171 
00172       //Change of axes for the forward
00173       Basic3DVector<float> newX(1.,0.,0.);
00174       Basic3DVector<float> newY(0.,0.,1.);
00175       //      if (tran.z() > 0. )
00176       newY *= -1;
00177       Basic3DVector<float> newZ(0.,1.,0.);
00178       rot.rotateAxes (newX, newY,newZ);
00179       
00180     }
00181     LogDebug("RPCGeometryBuilderFromDDD") <<"   Number of strips "<<nStrips;
00182     
00183     BoundPlane* bp = new BoundPlane(pos,rot,bounds);
00184     ReferenceCountingPointer<BoundPlane> surf(bp);
00185     RPCRoll* r=new RPCRoll(rpcid,surf,rollspecs);
00186     geometry->add(r);
00187 
00188     std::list<RPCRoll *> rls;
00189     if (chids.find(chid)!=chids.end()){
00190       rls = chids[chid];
00191     }
00192     rls.push_back(r);
00193     chids[chid]=rls;
00194 
00195     doSubDets = fview.nextSibling(); // go to next layer
00196   }
00197   // Create the RPCChambers and store them on the Geometry 
00198   for( std::map<RPCDetId, std::list<RPCRoll *> >::iterator ich=chids.begin();
00199        ich != chids.end(); ich++){
00200     RPCDetId chid = ich->first;
00201     std::list<RPCRoll * > rls = ich->second;
00202 
00203     // compute the overall boundplane. At the moment we use just the last
00204     // surface
00205     BoundPlane* bp=0;
00206     for(std::list<RPCRoll *>::iterator rl=rls.begin();
00207     rl!=rls.end(); rl++){
00208       const BoundPlane& bps = (*rl)->surface();
00209       bp = const_cast<BoundPlane *>(&bps);
00210     }
00211 
00212     ReferenceCountingPointer<BoundPlane> surf(bp);
00213     // Create the chamber 
00214     RPCChamber* ch = new RPCChamber (chid, surf); 
00215     // Add the rolls to rhe chamber
00216     for(std::list<RPCRoll *>::iterator rl=rls.begin();
00217     rl!=rls.end(); rl++){
00218       ch->add(*rl);
00219     }
00220     // Add the chamber to the geometry
00221     geometry->add(ch);
00222   } 
00223   return geometry;
00224 }