CMS 3D CMS Logo

DDDividedPolyhedra.cc
Go to the documentation of this file.
2 
3 #include <stddef.h>
4 #include <iostream>
5 #include <string>
6 #include <utility>
7 #include <vector>
8 
9 #include "CLHEP/Units/GlobalSystemOfUnits.h"
10 #include "CLHEP/Units/SystemOfUnits.h"
20 
21 class DDCompactView;
22 
24  : DDDividedGeometryObject( div, cpv )
25 {
27  setType( "DivisionPolyhedraRho" );
28 
29  DDPolyhedra msol = (DDPolyhedra)( div_.parent().solid() );
30 
31  if( divisionType_ == DivWIDTH )
32  {
33  compNDiv_ = calculateNDiv( msol.rMaxVec()[0] - msol.rMinVec()[0]
34  , div_.width()
35  , div_.offset() );
36  }
37  else if( divisionType_ == DivNDIV )
38  {
39  compWidth_ = calculateWidth( msol.rMaxVec()[0] - msol.rMinVec()[0]
40  , div_.nReplicas()
41  , div_.offset() );
42  }
43 }
44 
45 void
47 {
49 
50  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
51 
53  {
54  std::cout << "WARNING - "
55  << "DDDividedPolyhedraRho::checkParametersValidity()"
56  << std::endl
57  << " Solid " << msol << std::endl
58  << " Division along R will be done with a width "
59  << "different for each solid section." << std::endl
60  << " WIDTH will not be used !" << std::endl;
61  }
62  if( div_.offset() != 0. )
63  {
64  std::cout << "WARNING - "
65  << "DDDividedPolyhedraRho::checkParametersValidity()"
66  << std::endl
67  << " Solid " << msol << std::endl
68  << " Division along R will be done with a width "
69  << "different for each solid section." << std::endl
70  << " OFFSET will not be used !" << std::endl;
71  }
72 }
73 
74 double
76 {
77  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
78  return msol.rMaxVec()[0] - msol.rMinVec()[0];
79 }
80 
83 {
84  return DDTranslation();
85 }
86 
88 DDDividedPolyhedraRho::makeDDRotation( const int copyNo ) const
89 {
90  return DDRotation();
91 }
92 
95 {
96  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
97  DDMaterial usemat = div_.parent().material();
98 
99  std::vector<double> localrMaxVec = msol.rMaxVec();
100  std::vector<double> localrMinVec = msol.rMinVec();
101  std::vector<double> localzVec = msol.zVec();
102  std::vector<double> newrMinVec;
103  std::vector<double> newrMaxVec;
104  int nZplanes = localzVec.size();
105 
106  double width = 0.;
107  for(int ii = 0; ii < nZplanes; ++ii)
108  {
109  // width = CalculateWidth( origparamMother->Rmax[ii]
110  // - origparamMother->Rmin[ii], compNDiv_, foffset );
111  // origparam.Rmin[ii] = origparamMother->Rmin[ii]+foffset+width*copyNo;
112  // origparam.Rmax[ii] = origparamMother->Rmin[ii]+foffset+width*(copyNo+1);
113  width = calculateWidth(localrMaxVec[ii] - localrMinVec[ii], compNDiv_, div_.offset());
114  newrMinVec[ii] = localrMinVec[ii] + div_.offset() + width * copyNo;
115  newrMaxVec[ii] = localrMaxVec[ii] + div_.offset() + width * (copyNo + 1);
116  }
117 
118  // phedra.SetOriginalParameters(&origparam); // copy values & transfer pointers
119  // phedra.Reset(); // reset to new solid parameters
120 
121  DDName solname(div_.parent().ddname().name() + "_DIVCHILD" + std::to_string(copyNo),
122  div_.parent().ddname().ns());
123 
124  DDSolid dsol = DDSolidFactory::polyhedra(solname
125  , msol.sides()
126  , msol.startPhi()
127  , msol.deltaPhi()
128  , localzVec
129  , newrMinVec
130  , newrMaxVec);
131  DDLogicalPart ddlp = DDLogicalPart(solname, usemat, dsol);
132  return ddlp;
133 }
134 
136  : DDDividedGeometryObject( div, cpv )
137 {
139  setType( "DivisionPolyhedraPhi" );
140 
141  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
142  // double deltaPhi = msol->GetEndPhi() - msol->GetStartPhi();
143 
144  if( divisionType_ == DivWIDTH )
145  {
146  //If you divide a tube of 360 degrees the offset displaces the starting angle, but you still fill the 360 degrees
147  if( msol.deltaPhi() == 360.*deg ) {
148  compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), 0. );
149  }else {
151  }
152  }
153  else if( divisionType_ == DivNDIV )
154  {
155  if( msol.deltaPhi() == 360.*deg ) {
156  compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), 0. );
157  }else {
158  // original line looks wrong!
160  }
161  }
162 }
163 
164 double
166 {
167  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
168  return msol.deltaPhi(); //msol->GetEndPhi() - msol->GetStartPhi();
169 }
170 
171 void
173 {
175 
176  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
177 
179  {
180  std::cout << "WARNING - "
181  << "DDDividedPolyhedraPhi::checkParametersValidity()"
182  << std::endl
183  << " Solid " << msol << std::endl
184  << " Division along PHI will be done splitting "
185  << "in the defined numSide." << std::endl
186  << " WIDTH will not be used !" << std::endl;
187  }
188  if( div_.offset() != 0. )
189  {
190  std::cout << "WARNING - "
191  << "DDDividedPolyhedraPhi::checkParametersValidity()"
192  << std::endl
193  << " Solid " << msol << std::endl
194  << " Division along PHI will be done splitting "
195  << "in the defined numSide." << std::endl
196  << " OFFSET will not be used !" << std::endl;
197  }
198 
199  if ( msol.sides() != compNDiv_ )
200  {
201  std::cout << "ERROR - "
202  << "DDDividedPolyhedraPhi::checkParametersValidity()"
203  << std::endl
204  << " Division along PHI will be done splitting in the defined"
205  << std::endl
206  << " numSide, i.e, the number of division would be :"
207  << " " << msol.sides()
208  << " instead of " << compNDiv_ << " !"
209  << std::endl;
210  std::string s = "DDDividedPolyhedraPhi::checkParametersValidity() Not supported configuration.";
211  throw cms::Exception("DDException") << s;
212  }
213 }
214 
217 {
218  return DDTranslation();
219 }
220 
222 DDDividedPolyhedraPhi::makeDDRotation( const int copyNo ) const
223 {
224 
225  double posi = ( copyNo - 1 ) * compWidth_;
226 
227  // ChangeRotMatrix( physVol, -posi );
228  DDRotationMatrix* rotMat = changeRotMatrix( posi);
229  // how to name the rotation??
230  // i do not like this...
231  DDName ddrotname(div_.parent().ddname().name() + "_DIVCHILD_ROT" + std::to_string(copyNo),
232  div_.parent().ddname().ns());
233  DDRotation myddrot = DDrot(ddrotname, rotMat);
234  return myddrot;
235 }
236 
239 {
240  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
241  DDMaterial usemat = div_.parent().material();
242 
243  DDName solname( div_.parent().ddname().name() + "_DIVCHILD",
244  div_.parent().ddname().ns());
245  DDSolid dsol(solname);
246  if (!dsol.isDefined().second)
247  {
248  dsol = DDSolidFactory::polyhedra( solname,
249  msol.sides(),
250  msol.startPhi()+div_.offset(),
251  compWidth_,
252  msol.zVec(),
253  msol.rMinVec(),
254  msol.rMaxVec());
255  }
256  DDLogicalPart ddlp(solname);
257  if (!ddlp.isDefined().second)
258  DDLogicalPart ddlp2 = DDLogicalPart(solname, usemat, dsol);
259  return ddlp;
260 }
261 
263  : DDDividedGeometryObject( div, cpv )
264 {
266  setType( "DivisionPolyhedraZ" );
267 
268  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
269 
270  std::vector<double> zvec = msol.zVec();
271 
272  if ( divisionType_ == DivWIDTH )
273  {
274  compNDiv_ =
275  calculateNDiv( zvec[zvec.size() - 1] - zvec[0], div_.width(), div_.offset() );
276  }
277  else if( divisionType_ == DivNDIV )
278  {
279  compWidth_ = calculateWidth( zvec[zvec.size() - 1] - zvec[0],
280  div_.nReplicas(),
281  div_.offset());
282  // ?what? CalculateNDiv( zvec[zvec.size() - 1] - zvec[0], origparamMother->Z_values[origparamMother->Num_z_planes-1]
283  // - origparamMother->Z_values[0] , nDiv, offset );
284  }
285 }
286 
287 double
289 {
290  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
291 
292  std::vector<double> zvec = msol.zVec();
293  return (zvec[zvec.size() - 1] - zvec[0]);
294 }
295 
296 void
298 {
300 
301  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
302 
304  {
305  std::cout << "WARNING - "
306  << "DDDividedPolyhedraZ::checkParametersValidity()"
307  << std::endl
308  << " Solid " << msol << std::endl
309  << " Division along Z will be done splitting "
310  << "in the defined z_planes." << std::endl
311  << " WIDTH will not be used !" << std::endl;
312  }
313 
314  if( div_.offset() != 0. )
315  {
316  std::cout << "WARNING - "
317  << "DDDividedPolyhedraZ::checkParametersValidity()"
318  << std::endl
319  << " Solid " << msol << std::endl
320  << " Division along Z will be done splitting "
321  << "in the defined z_planes." << std::endl
322  << " OFFSET will not be used !" << std::endl;
323  }
324 
325  std::vector<double> zvec = msol.zVec();
326 
327  if ( zvec.size() - 1 != size_t(compNDiv_) )
328  {
329  std::cout << "ERROR - "
330  << "DDDividedPolyhedraZ::checkParametersValidity()"
331  << std::endl
332  << " Division along Z can only be done by splitting in the defined"
333  << std::endl
334  << " z_planes, i.e, the number of division would be :"
335  << " " << zvec.size() - 1
336  << " instead of " << compNDiv_ << " !"
337  << std::endl;
338  std::string s = "DDDividedPolyhedraZ::checkParametersValidity()";
339  s += "Illegal Construct. Not a supported configuration.";
340  throw cms::Exception("DDException") << s;
341  }
342 }
343 
345 DDDividedPolyhedraZ::makeDDTranslation( const int copyNo ) const
346 {
347  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
348  std::vector<double> zvec = msol.zVec();
349 
350  //----- set translation: along Z axis
351  double posi = (zvec[copyNo] + zvec[copyNo+1])/2;
352 
353  DDTranslation tr(0,0,posi);
354  //----- calculate rotation matrix: unit
355  return tr;
356 }
357 
359 DDDividedPolyhedraZ::makeDDRotation( const int copyNo ) const
360 {
361  return DDRotation();
362 }
363 
365 DDDividedPolyhedraZ::makeDDLogicalPart( const int copyNo ) const
366 {
367  // only for mother number of planes = 2!!
368  // mec: what? why? comment above and = 2 below straight from G4 impl.
369  DDPolyhedra msol = (DDPolyhedra)( div_.parent().solid());
370  DDMaterial usemat = div_.parent().material();
371 
372  std::vector<double> zvec = msol.zVec();
373  std::vector<double> rminvec = msol.rMinVec();
374  std::vector<double> rmaxvec = msol.rMaxVec();
375 
376  double posi = ( zvec[ copyNo ] + zvec[ copyNo + 1 ] ) / 2.0;
377 
378  DDName solname( div_.parent().ddname().name() + "_DIVCHILD" + std::to_string( copyNo ),
379  div_.parent().ddname().ns());
380  std::vector<double> newRmin, newRmax, newZ;
381  newZ.push_back( zvec[ copyNo ] - posi );
382  newZ.push_back( zvec[ copyNo + 1 ] - posi );
383  newRmin.push_back( rminvec[ copyNo ]);
384  newRmin.push_back( rminvec[ copyNo + 1 ]);
385  newRmax.push_back( rmaxvec[ copyNo ]);
386  newRmax.push_back( rmaxvec[ copyNo + 1 ]);
387 
388  DDSolid dsol = DDSolidFactory::polyhedra( solname,
389  msol.sides(),
390  msol.startPhi(),
391  msol.deltaPhi(),
392  newZ,
393  newRmin,
394  newRmax );
395  DDLogicalPart lp( solname, usemat, dsol );
396  return lp;
397 }
398 
virtual DDLogicalPart makeDDLogicalPart(const int copyNo) const override
double startPhi(void) const
Definition: DDSolid.cc:424
virtual void checkParametersValidity() override
virtual DDTranslation makeDDTranslation(const int copyNo) const override
DDDividedPolyhedraRho(const DDDivision &div, DDCompactView *cpv)
virtual double getMaxParameter() const override
std::vector< double > rMaxVec(void) const
Definition: DDSolid.cc:454
int nReplicas() const
Definition: DDDivision.cc:71
virtual DDRotation makeDDRotation(const int copyNo) const override
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
double offset() const
Definition: DDDivision.cc:81
int calculateNDiv(double motherDim, double width, double offset) const
virtual double getMaxParameter() const override
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:104
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
DDDividedPolyhedraPhi(const DDDivision &div, DDCompactView *cpv)
double calculateWidth(double motherDim, int nDiv, double offset) const
virtual DDLogicalPart makeDDLogicalPart(const int copyNo) const override
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
virtual void checkParametersValidity() override
A DDSolid represents the shape of a part.
Definition: DDSolid.h:38
virtual void checkParametersValidity(void)
virtual DDTranslation makeDDTranslation(const int copyNo) const override
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:64
virtual void checkParametersValidity() override
virtual DDRotation makeDDRotation(const int copyNo) const override
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
virtual void setType(const std::string &type)
std::vector< double > rMinVec(void) const
Definition: DDSolid.cc:446
DDRotation DDrot(const DDName &name, DDRotationMatrix *rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:90
virtual DDLogicalPart makeDDLogicalPart(const int copyNo) const override
ii
Definition: cuy.py:588
int sides(void) const
Definition: DDSolid.cc:421
std::vector< double > zVec(void) const
Definition: DDSolid.cc:438
double width() const
Definition: DDDivision.cc:76
double deltaPhi(void) const
Definition: DDSolid.cc:427
virtual DDRotation makeDDRotation(const int copyNo) const override
const DDLogicalPart & parent() const
Definition: DDDivision.cc:86
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
DDDividedPolyhedraZ(const DDDivision &div, DDCompactView *cpv)
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
static DDSolid polyhedra(const DDName &name, int sides, double startPhi, double deltaPhi, const std::vector< double > &z, const std::vector< double > &rmin, const std::vector< double > &rmax)
Creates a polyhedra (refere to Geant3 or Geant4 documentation)
Definition: DDSolid.cc:843
virtual double getMaxParameter() const override
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
virtual DDTranslation makeDDTranslation(const int copyNo) const override
const N & ddname() const
Definition: DDBase.h:80
DDRotationMatrix * changeRotMatrix(double rotZ=0.) const