test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCGeometryBuilderFromDDD.cc
Go to the documentation of this file.
1 
9 
13 
18 
21 
23 
24 #include "CLHEP/Units/GlobalSystemOfUnits.h"
25 
26 #include <iostream>
27 #include <algorithm>
28 
29 RPCGeometryBuilderFromDDD::RPCGeometryBuilderFromDDD(bool comp11) : theComp11Flag(comp11)
30 { }
31 
33 { }
34 
36 {
37  const std::string attribute = "ReadOutName"; // could come from .orcarc
38  const std::string value = "MuonRPCHits"; // could come from .orcarc
39  DDValue val(attribute, value, 0.0);
40 
41  // Asking only for the MuonRPC's
43  filter.setCriteria(val, // name & value of a variable
46  true, // compare strings otherwise doubles
47  true // use merged-specifics or simple-specifics
48  );
49  DDFilteredView fview(*cview);
50  fview.addFilter(filter);
51 
52  return this->buildGeometry(fview, muonConstants);
53 }
54 
56 {
57  LogDebug("RPCGeometryBuilderFromDDD") <<"Building the geometry service";
59 
60  LogDebug("RPCGeometryBuilderFromDDD") << "About to run through the RPC structure\n"
61  <<" First logical part "
62  <<fview.logicalPart().name().name();
63  bool doSubDets = fview.firstChild();
64 
65  LogDebug("RPCGeometryBuilderFromDDD") << "doSubDets = " << doSubDets;
66  while (doSubDets){
67  LogDebug("RPCGeometryBuilderFromDDD") <<"start the loop";
68 
69  // Get the Base Muon Number
70  MuonDDDNumbering mdddnum(muonConstants);
71  LogDebug("RPCGeometryBuilderFromDDD") <<"Getting the Muon base Number";
73  LogDebug("RPCGeometryBuilderFromDDD") <<"Start the Rpc Numbering Schema";
74  // Get the The Rpc det Id
75  RPCNumberingScheme rpcnum(muonConstants);
76 
77  LogDebug("RPCGeometryBuilderFromDDD") <<"Getting the Unit Number";
78  const int detid = rpcnum.baseNumberToUnitNumber(mbn);
79  LogDebug("RPCGeometryBuilderFromDDD") <<"Getting the RPC det Id "<<detid;
80 
81  RPCDetId rpcid(detid);
82  RPCDetId chid(rpcid.region(),rpcid.ring(),rpcid.station(),rpcid.sector(),rpcid.layer(),rpcid.subsector(),0);
83 
84  LogDebug("RPCGeometryBuilderFromDDD") <<"The RPCDetid is "<<rpcid;
85 
86  DDValue numbOfStrips("nStrips");
87 
88  std::vector<const DDsvalues_type* > specs(fview.specifics());
89  int nStrips=0;
90  for (auto is=specs.begin();is!=specs.end(); ++is){
91  if (DDfetch( *is, numbOfStrips)){
92  nStrips=int(numbOfStrips.doubles()[0]);
93  }
94  }
95 
96  LogDebug("RPCGeometryBuilderFromDDD") << ((nStrips == 0 ) ? ("No strip found!!") : (""));
97 
98  std::vector<double> dpar=fview.logicalPart().solid().parameters();
99  std::string name=fview.logicalPart().name().name();
100  DDTranslation tran = fview.translation();
101  //removed .Inverse after comparing to DT...
102  DDRotationMatrix rota = fview.rotation();//.Inverse();
103  Surface::PositionType pos(tran.x()/cm,tran.y()/cm, tran.z()/cm);
104  // CLHEP way
105  // Surface::RotationType rot(rota.xx(),rota.xy(),rota.xz(),
106  // rota.yx(),rota.yy(),rota.yz(),
107  // rota.zx(),rota.zy(),rota.zz());
108 
109  //ROOT::Math way
110  DD3Vector x, y, z;
111  rota.GetComponents(x,y,z);
112  // doesn't this just re-inverse???
113  Surface::RotationType rot (float(x.X()),float(x.Y()),float(x.Z()),
114  float(y.X()),float(y.Y()),float(y.Z()),
115  float(z.X()),float(z.Y()),float(z.Z()));
116 
117  RPCRollSpecs* rollspecs= 0;
118  Bounds* bounds = 0;
119 
120  if (dpar.size()==3){
121  const float width = dpar[0]/cm;
122  const float length = dpar[1]/cm;
123  const float thickness = dpar[2]/cm;
124  //RectangularPlaneBounds*
125  bounds = new RectangularPlaneBounds(width,length,thickness);
126  const std::vector<float> pars = {width, length, float(numbOfStrips.doubles()[0]) /*h/2*/};
127 
128  if (!theComp11Flag) {
129  //Correction of the orientation to get the REAL geometry.
130  //Change of axes for the +z part only.
131  //Including the 0 wheel
132  if (tran.z() >-1500. ){
133  Basic3DVector<float> newX(-1.,0.,0.);
134  Basic3DVector<float> newY(0.,-1.,0.);
135  Basic3DVector<float> newZ(0.,0.,1.);
136  rot.rotateAxes(newX, newY,newZ);
137  }
138  }
139 
140  rollspecs = new RPCRollSpecs(GeomDetEnumerators::RPCBarrel,name,pars);
141  LogDebug("RPCGeometryBuilderFromDDD") <<"Barrel "<<name
142  <<" par "<<width
143  <<" "<<length<<" "<<thickness;
144  }
145  else {
146  const float be = dpar[4]/cm;
147  const float te = dpar[8]/cm;
148  const float ap = dpar[0]/cm;
149  const float ti = 0.4/cm;
150  // TrapezoidalPlaneBounds*
151  bounds = new TrapezoidalPlaneBounds(be,te,ap,ti);
152  const std::vector<float> pars = {float(dpar[4]/cm) /*b/2*/, float(dpar[8]/cm) /*B/2*/,
153  float(dpar[0]/cm) /*h/2*/, float(numbOfStrips.doubles()[0]) /*h/2*/};
154 
155  LogDebug("RPCGeometryBuilderFromDDD") <<"Forward "<<name
156  <<" par "<<dpar[4]/cm
157  <<" "<<dpar[8]/cm<<" "<<dpar[3]/cm<<" "
158  <<dpar[0];
159 
160  rollspecs = new RPCRollSpecs(GeomDetEnumerators::RPCEndcap,name,pars);
161 
162  //Change of axes for the forward
163  Basic3DVector<float> newX(1.,0.,0.);
164  Basic3DVector<float> newY(0.,0.,1.);
165  // if (tran.z() > 0. )
166  newY *= -1;
167  Basic3DVector<float> newZ(0.,1.,0.);
168  rot.rotateAxes (newX, newY,newZ);
169  }
170  LogDebug("RPCGeometryBuilderFromDDD") <<" Number of strips "<<nStrips;
171 
172  BoundPlane* bp = new BoundPlane(pos,rot,bounds);
174  RPCRoll* r=new RPCRoll(rpcid,surf,rollspecs);
175  geometry->add(r);
176 
177  auto rls = chids.find(chid);
178  if ( rls == chids.end() ) rls = chids.insert(std::make_pair(chid, std::list<RPCRoll*>())).first;
179  rls->second.push_back(r);
180 
181  doSubDets = fview.nextSibling(); // go to next layer
182  }
183  // Create the RPCChambers and store them on the Geometry
184  for ( auto ich=chids.begin(); ich != chids.end(); ++ich ) {
185  const RPCDetId& chid = ich->first;
186  const auto& rls = ich->second;
187 
188  // compute the overall boundplane.
189  BoundPlane* bp=0;
190  if ( !rls.empty() ) {
191  // First set the baseline plane to calculate relative poisions
192  const auto& refSurf = (*rls.begin())->surface();
193  if ( chid.region() == 0 ) {
194  float corners[6] = {0,0,0,0,0,0};
195  for ( auto rl : rls ) {
196  const double h2 = rl->surface().bounds().length()/2;
197  const double w2 = rl->surface().bounds().width()/2;
198  const auto x1y1AtRef = refSurf.toLocal(rl->toGlobal(LocalPoint(-w2,-h2,0)));
199  const auto x2y2AtRef = refSurf.toLocal(rl->toGlobal(LocalPoint(+w2,+h2,0)));
200  corners[0] = std::min(corners[0], x1y1AtRef.x());
201  corners[1] = std::min(corners[1], x1y1AtRef.y());
202  corners[2] = std::max(corners[2], x2y2AtRef.x());
203  corners[3] = std::max(corners[3], x2y2AtRef.y());
204 
205  corners[4] = std::min(corners[4], x1y1AtRef.z());
206  corners[5] = std::max(corners[5], x1y1AtRef.z());
207  }
208  const LocalPoint lpOfCentre((corners[0]+corners[2])/2, (corners[1]+corners[3])/2, 0);
209  const auto gpOfCentre = refSurf.toGlobal(lpOfCentre);
210  auto bounds = new RectangularPlaneBounds((corners[2]-corners[0])/2, (corners[3]-corners[1])/2, (corners[5]-corners[4])+0.5);
211  bp = new BoundPlane(gpOfCentre, refSurf.rotation(), bounds);
212  }
213  else {
214  float cornersLo[3] = {0,0,0}, cornersHi[3] = {0,0,0};
215  float cornersZ[2] = {0,0};
216  for ( auto rl : rls ) {
217  const double h2 = rl->surface().bounds().length()/2;
218  const double w2 = rl->surface().bounds().width()/2;
219  const auto& topo = dynamic_cast<const TrapezoidalStripTopology&>(rl->specificTopology());
220  const double r = topo.radius();
221  const double wAtLo = w2/r*(r-h2); // tan(theta/2) = (w/2)/r = x/(r-h/2)
222  const double wAtHi = w2/r*(r+h2);
223 
224  const auto x1y1AtRef = refSurf.toLocal(rl->toGlobal(LocalPoint(-wAtLo, -h2, 0)));
225  const auto x2y1AtRef = refSurf.toLocal(rl->toGlobal(LocalPoint(+wAtLo, -h2, 0)));
226  const auto x1y2AtRef = refSurf.toLocal(rl->toGlobal(LocalPoint(-wAtHi, +h2, 0)));
227  const auto x2y2AtRef = refSurf.toLocal(rl->toGlobal(LocalPoint(+wAtHi, +h2, 0)));
228 
229  cornersLo[0] = std::min(cornersLo[0], x1y1AtRef.x());
230  cornersLo[1] = std::max(cornersLo[1], x2y1AtRef.x());
231  cornersLo[2] = std::min(cornersLo[2], x1y1AtRef.y());
232 
233  cornersHi[0] = std::min(cornersHi[0], x1y2AtRef.x());
234  cornersHi[1] = std::max(cornersHi[1], x2y2AtRef.x());
235  cornersHi[2] = std::max(cornersHi[2], x1y2AtRef.y());
236 
237  cornersZ[0] = std::min(cornersZ[0], x1y1AtRef.z());
238  cornersZ[1] = std::max(cornersZ[1], x1y1AtRef.z());
239  }
240  const LocalPoint lpOfCentre((cornersHi[0]+cornersHi[1])/2, (cornersLo[2]+cornersHi[2])/2, 0);
241  const auto gpOfCentre = refSurf.toGlobal(lpOfCentre);
242  auto bounds = new TrapezoidalPlaneBounds((cornersLo[1]-cornersLo[0])/2, (cornersHi[1]-cornersHi[0])/2, (cornersHi[2]-cornersLo[2])/2, (cornersZ[1]-cornersZ[0])+0.5);
243  bp = new BoundPlane(gpOfCentre, refSurf.rotation(), bounds);
244  }
245  }
246 
248  // Create the chamber
249  RPCChamber* ch = new RPCChamber (chid, surf);
250  // Add the rolls to rhe chamber
251  for ( auto rl : rls ) ch->add(rl);
252  // Add the chamber to the geometry
253  geometry->add(ch);
254 
255  }
256  return geometry;
257 }
#define LogDebug(id)
virtual int baseNumberToUnitNumber(const MuonBaseNumber &)
void add(RPCRoll *rl)
Add Roll to the chamber which takes ownership.
Definition: RPCChamber.cc:48
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:157
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:137
const N & name() const
Definition: DDBase.h:78
virtual float length() const =0
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
void addFilter(const DDFilter &, DDLogOp op=DDLogOp::AND)
bool nextSibling()
set the current node to the next sibling ...
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
Plane BoundPlane
Definition: Plane.h:95
const Bounds & bounds() const
Definition: Surface.h:120
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
type of data representation of DDCompactView
Definition: DDCompactView.h:90
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
RPCGeometry * build(const DDCompactView *cview, const MuonDDDConstants &muonConstants)
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:80
void add(RPCRoll *roll)
Add a RPC roll to the Geometry.
Definition: RPCGeometry.cc:81
TkRotation & rotateAxes(const Basic3DVector< T > &newX, const Basic3DVector< T > &newY, const Basic3DVector< T > &newZ)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
RPCGeometry * buildGeometry(DDFilteredView &fview, const MuonDDDConstants &muonConstants)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
int ring() const
Definition: RPCDetId.h:72
std::map< RPCDetId, std::list< RPCRoll * > > chids
T min(T a, T b)
Definition: MathUtil.h:58
int layer() const
Definition: RPCDetId.h:108
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:102
ESHandle< TrackerGeometry > geometry
int subsector() const
SubSector id : some sectors are divided along the phi direction in subsectors (from 1 to 4 in Barrel...
Definition: RPCDetId.h:114
bool firstChild()
set the current node to the first child ...
Definition: Bounds.h:22
const DDTranslation & translation() const
The absolute translation of the current node.
std::vector< const DDsvalues_type * > specifics() const
MuonBaseNumber geoHistoryToBaseNumber(const DDGeoHistory &history)
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
void setCriteria(const DDValue &nameVal, DDCompOp, DDLogOp l=DDLogOp::AND, bool asString=true, bool merged=true)
Definition: DDFilter.cc:253
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.
Definition: DDFilter.h:33