CMS 3D CMS Logo

DDDividedPolyhedra.cc
Go to the documentation of this file.
12 
13 #include <cstddef>
14 #include <iostream>
15 #include <string>
16 #include <utility>
17 #include <vector>
18 
19 class DDCompactView;
20 
21 using namespace dd::operators;
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 
143  if( divisionType_ == DivWIDTH )
144  {
145  //If you divide a tube of 360 degrees the offset displaces the starting angle, but you still fill the 360 degrees
146  if( msol.deltaPhi() == 360._deg ) {
147  compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), 0. );
148  }else {
150  }
151  }
152  else if( divisionType_ == DivNDIV )
153  {
154  if( msol.deltaPhi() == 360._deg ) {
155  compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), 0. );
156  }else {
157  // original line looks wrong!
159  }
160  }
161 }
162 
163 double
165 {
166  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
167  return msol.deltaPhi(); //msol->GetEndPhi() - msol->GetStartPhi();
168 }
169 
170 void
172 {
174 
175  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
176 
178  {
179  std::cout << "WARNING - "
180  << "DDDividedPolyhedraPhi::checkParametersValidity()"
181  << std::endl
182  << " Solid " << msol << std::endl
183  << " Division along PHI will be done splitting "
184  << "in the defined numSide." << std::endl
185  << " WIDTH will not be used !" << std::endl;
186  }
187  if( div_.offset() != 0. )
188  {
189  std::cout << "WARNING - "
190  << "DDDividedPolyhedraPhi::checkParametersValidity()"
191  << std::endl
192  << " Solid " << msol << std::endl
193  << " Division along PHI will be done splitting "
194  << "in the defined numSide." << std::endl
195  << " OFFSET will not be used !" << std::endl;
196  }
197 
198  if ( msol.sides() != compNDiv_ )
199  {
200  std::cout << "ERROR - "
201  << "DDDividedPolyhedraPhi::checkParametersValidity()"
202  << std::endl
203  << " Division along PHI will be done splitting in the defined"
204  << std::endl
205  << " numSide, i.e, the number of division would be :"
206  << " " << msol.sides()
207  << " instead of " << compNDiv_ << " !"
208  << std::endl;
209  std::string s = "DDDividedPolyhedraPhi::checkParametersValidity() Not supported configuration.";
210  throw cms::Exception("DDException") << s;
211  }
212 }
213 
216 {
217  return DDTranslation();
218 }
219 
221 DDDividedPolyhedraPhi::makeDDRotation( const int copyNo ) const
222 {
223  DDRotation myddrot; // sets to identity.
224  double posi = ( copyNo - 1 ) * compWidth_;
225  DDName ddrotname( div_.parent().ddname().name() +
226  "_DIVCHILD_ROT" + std::to_string( copyNo ),
227  div_.parent().ddname().ns());
228  myddrot = DDrot( ddrotname, changeRotMatrix( posi ));
229 
230  return myddrot;
231 }
232 
235 {
236  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
237  DDMaterial usemat = div_.parent().material();
238 
239  DDName solname( div_.parent().ddname().name() + "_DIVCHILD",
240  div_.parent().ddname().ns());
241  DDSolid dsol(solname);
242  if (!dsol.isDefined().second)
243  {
244  dsol = DDSolidFactory::polyhedra( solname,
245  msol.sides(),
246  msol.startPhi()+div_.offset(),
247  compWidth_,
248  msol.zVec(),
249  msol.rMinVec(),
250  msol.rMaxVec());
251  }
252  DDLogicalPart ddlp(solname);
253  if (!ddlp.isDefined().second)
254  DDLogicalPart ddlp2 = DDLogicalPart(solname, usemat, dsol);
255  return ddlp;
256 }
257 
259  : DDDividedGeometryObject( div, cpv )
260 {
262  setType( "DivisionPolyhedraZ" );
263 
264  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
265 
266  std::vector<double> zvec = msol.zVec();
267 
268  if ( divisionType_ == DivWIDTH )
269  {
270  compNDiv_ =
271  calculateNDiv( zvec[zvec.size() - 1] - zvec[0], div_.width(), div_.offset() );
272  }
273  else if( divisionType_ == DivNDIV )
274  {
275  compWidth_ = calculateWidth( zvec[zvec.size() - 1] - zvec[0],
276  div_.nReplicas(),
277  div_.offset());
278  }
279 }
280 
281 double
283 {
284  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
285 
286  std::vector<double> zvec = msol.zVec();
287  return (zvec[zvec.size() - 1] - zvec[0]);
288 }
289 
290 void
292 {
294 
295  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
296 
298  {
299  std::cout << "WARNING - "
300  << "DDDividedPolyhedraZ::checkParametersValidity()"
301  << std::endl
302  << " Solid " << msol << std::endl
303  << " Division along Z will be done splitting "
304  << "in the defined z_planes." << std::endl
305  << " WIDTH will not be used !" << std::endl;
306  }
307 
308  if( div_.offset() != 0. )
309  {
310  std::cout << "WARNING - "
311  << "DDDividedPolyhedraZ::checkParametersValidity()"
312  << std::endl
313  << " Solid " << msol << std::endl
314  << " Division along Z will be done splitting "
315  << "in the defined z_planes." << std::endl
316  << " OFFSET will not be used !" << std::endl;
317  }
318 
319  std::vector<double> zvec = msol.zVec();
320 
321  if ( zvec.size() - 1 != size_t(compNDiv_) )
322  {
323  std::cout << "ERROR - "
324  << "DDDividedPolyhedraZ::checkParametersValidity()"
325  << std::endl
326  << " Division along Z can only be done by splitting in the defined"
327  << std::endl
328  << " z_planes, i.e, the number of division would be :"
329  << " " << zvec.size() - 1
330  << " instead of " << compNDiv_ << " !"
331  << std::endl;
332  std::string s = "DDDividedPolyhedraZ::checkParametersValidity()";
333  s += "Illegal Construct. Not a supported configuration.";
334  throw cms::Exception("DDException") << s;
335  }
336 }
337 
339 DDDividedPolyhedraZ::makeDDTranslation( const int copyNo ) const
340 {
341  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
342  std::vector<double> zvec = msol.zVec();
343 
344  //----- set translation: along Z axis
345  double posi = (zvec[copyNo] + zvec[copyNo+1])/2;
346 
347  DDTranslation tr(0,0,posi);
348  //----- calculate rotation matrix: unit
349  return tr;
350 }
351 
353 DDDividedPolyhedraZ::makeDDRotation( const int copyNo ) const
354 {
355  return DDRotation();
356 }
357 
359 DDDividedPolyhedraZ::makeDDLogicalPart( const int copyNo ) const
360 {
361  // only for mother number of planes = 2!!
362  // mec: what? why? comment above and = 2 below straight from G4 impl.
363  DDPolyhedra msol = (DDPolyhedra)( div_.parent().solid());
364  DDMaterial usemat = div_.parent().material();
365 
366  std::vector<double> zvec = msol.zVec();
367  std::vector<double> rminvec = msol.rMinVec();
368  std::vector<double> rmaxvec = msol.rMaxVec();
369 
370  double posi = ( zvec[ copyNo ] + zvec[ copyNo + 1 ] ) / 2.0;
371 
372  DDName solname( div_.parent().ddname().name() + "_DIVCHILD" + std::to_string( copyNo ),
373  div_.parent().ddname().ns());
374  std::vector<double> newRmin, newRmax, newZ;
375  newZ.emplace_back( zvec[ copyNo ] - posi );
376  newZ.emplace_back( zvec[ copyNo + 1 ] - posi );
377  newRmin.emplace_back( rminvec[ copyNo ]);
378  newRmin.emplace_back( rminvec[ copyNo + 1 ]);
379  newRmax.emplace_back( rmaxvec[ copyNo ]);
380  newRmax.emplace_back( rmaxvec[ copyNo + 1 ]);
381 
382  DDSolid dsol = DDSolidFactory::polyhedra( solname,
383  msol.sides(),
384  msol.startPhi(),
385  msol.deltaPhi(),
386  newZ,
387  newRmin,
388  newRmax );
389  DDLogicalPart lp( solname, usemat, dsol );
390  return lp;
391 }
392 
double startPhi(void) const
Definition: DDSolid.cc:400
DDRotation makeDDRotation(int copyNo) const override
void checkParametersValidity() override
DDTranslation makeDDTranslation(int copyNo) const override
DDDividedPolyhedraRho(const DDDivision &div, DDCompactView *cpv)
double getMaxParameter() const override
DDLogicalPart makeDDLogicalPart(int copyNo) const override
std::vector< double > rMaxVec(void) const
Definition: DDSolid.cc:430
int nReplicas() const
Definition: DDDivision.cc:75
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:43
double offset() const
Definition: DDDivision.cc:87
int calculateNDiv(double motherDim, double width, double offset) const
DDTranslation makeDDTranslation(int copyNo) const override
double getMaxParameter() const override
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:67
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
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
DDRotation makeDDRotation(int copyNo) const override
void checkParametersValidity() override
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
virtual void checkParametersValidity(void)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:68
void checkParametersValidity() override
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
DDRotation DDrot(const DDName &name, std::unique_ptr< DDRotationMatrix > rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:80
DDRotation makeDDRotation(int copyNo) const override
virtual void setType(const std::string &type)
std::vector< double > rMinVec(void) const
Definition: DDSolid.cc:422
DDLogicalPart makeDDLogicalPart(int copyNo) const override
ii
Definition: cuy.py:590
int sides(void) const
Definition: DDSolid.cc:397
std::unique_ptr< DDRotationMatrix > changeRotMatrix(double rotZ=0.) const
std::vector< double > zVec(void) const
Definition: DDSolid.cc:414
DDTranslation makeDDTranslation(int copyNo) const override
DDLogicalPart makeDDLogicalPart(int copyNo) const override
double width() const
Definition: DDDivision.cc:81
double deltaPhi(void) const
Definition: DDSolid.cc:403
const DDLogicalPart & parent() const
Definition: DDDivision.cc:93
DDDividedPolyhedraZ(const DDDivision &div, DDCompactView *cpv)
const std::string & name() const
Returns the name.
Definition: DDName.cc:53
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:730
double getMaxParameter() const override
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
const N & ddname() const
Definition: DDBase.h:76