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";
00037 std::string value = "MuonRPCHits";
00038 DDValue val(attribute, value, 0.0);
00039
00040
00041 DDSpecificsFilter filter;
00042 filter.setCriteria(val,
00043 DDSpecificsFilter::matches,
00044 DDSpecificsFilter::AND,
00045 true,
00046 true
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
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
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
00103 DDRotationMatrix rota = fview.rotation();
00104 Surface::PositionType pos(tran.x()/cm,tran.y()/cm, tran.z()/cm);
00105
00106
00107
00108
00109
00110
00111 DD3Vector x, y, z;
00112 rota.GetComponents(x,y,z);
00113
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
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]);
00134
00135 if (!theComp11Flag) {
00136
00137
00138
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
00158 bounds =
00159 new TrapezoidalPlaneBounds(be,te,ap,ti);
00160 pars.push_back(dpar[4]/cm);
00161 pars.push_back(dpar[8]/cm);
00162 pars.push_back(dpar[0]/cm);
00163 pars.push_back(numbOfStrips.doubles()[0]);
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
00173 Basic3DVector<float> newX(1.,0.,0.);
00174 Basic3DVector<float> newY(0.,0.,1.);
00175
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();
00196 }
00197
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
00204
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
00214 RPCChamber* ch = new RPCChamber (chid, surf);
00215
00216 for(std::list<RPCRoll *>::iterator rl=rls.begin();
00217 rl!=rls.end(); rl++){
00218 ch->add(*rl);
00219 }
00220
00221 geometry->add(ch);
00222 }
00223 return geometry;
00224 }