CMS 3D CMS Logo

DDDividedPolyhedra.cc
Go to the documentation of this file.
2 #include "CLHEP/Units/GlobalSystemOfUnits.h"
3 #include "CLHEP/Units/SystemOfUnits.h"
13 
14 #include <cstddef>
15 #include <iostream>
16 #include <string>
17 #include <utility>
18 #include <vector>
19 
20 class DDCompactView;
21 
23  : DDDividedGeometryObject( div, cpv )
24 {
26  setType( "DivisionPolyhedraRho" );
27 
28  DDPolyhedra msol = (DDPolyhedra)( div_.parent().solid() );
29 
30  if( divisionType_ == DivWIDTH )
31  {
32  compNDiv_ = calculateNDiv( msol.rMaxVec()[0] - msol.rMinVec()[0]
33  , div_.width()
34  , div_.offset() );
35  }
36  else if( divisionType_ == DivNDIV )
37  {
38  compWidth_ = calculateWidth( msol.rMaxVec()[0] - msol.rMinVec()[0]
39  , div_.nReplicas()
40  , div_.offset() );
41  }
42 }
43 
44 void
46 {
48 
49  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
50 
52  {
53  std::cout << "WARNING - "
54  << "DDDividedPolyhedraRho::checkParametersValidity()"
55  << std::endl
56  << " Solid " << msol << std::endl
57  << " Division along R will be done with a width "
58  << "different for each solid section." << std::endl
59  << " WIDTH will not be used !" << std::endl;
60  }
61  if( div_.offset() != 0. )
62  {
63  std::cout << "WARNING - "
64  << "DDDividedPolyhedraRho::checkParametersValidity()"
65  << std::endl
66  << " Solid " << msol << std::endl
67  << " Division along R will be done with a width "
68  << "different for each solid section." << std::endl
69  << " OFFSET will not be used !" << std::endl;
70  }
71 }
72 
73 double
75 {
76  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
77  return msol.rMaxVec()[0] - msol.rMinVec()[0];
78 }
79 
82 {
83  return DDTranslation();
84 }
85 
87 DDDividedPolyhedraRho::makeDDRotation( const int copyNo ) const
88 {
89  return DDRotation();
90 }
91 
94 {
95  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
96  DDMaterial usemat = div_.parent().material();
97 
98  std::vector<double> localrMaxVec = msol.rMaxVec();
99  std::vector<double> localrMinVec = msol.rMinVec();
100  std::vector<double> localzVec = msol.zVec();
101  std::vector<double> newrMinVec;
102  std::vector<double> newrMaxVec;
103  int nZplanes = localzVec.size();
104 
105  double width = 0.;
106  for(int ii = 0; ii < nZplanes; ++ii)
107  {
108  // width = CalculateWidth( origparamMother->Rmax[ii]
109  // - origparamMother->Rmin[ii], compNDiv_, foffset );
110  // origparam.Rmin[ii] = origparamMother->Rmin[ii]+foffset+width*copyNo;
111  // origparam.Rmax[ii] = origparamMother->Rmin[ii]+foffset+width*(copyNo+1);
112  width = calculateWidth(localrMaxVec[ii] - localrMinVec[ii], compNDiv_, div_.offset());
113  newrMinVec[ii] = localrMinVec[ii] + div_.offset() + width * copyNo;
114  newrMaxVec[ii] = localrMaxVec[ii] + div_.offset() + width * (copyNo + 1);
115  }
116 
117  // phedra.SetOriginalParameters(&origparam); // copy values & transfer pointers
118  // phedra.Reset(); // reset to new solid parameters
119 
120  DDName solname(div_.parent().ddname().name() + "_DIVCHILD" + std::to_string(copyNo),
121  div_.parent().ddname().ns());
122 
123  DDSolid dsol = DDSolidFactory::polyhedra(solname
124  , msol.sides()
125  , msol.startPhi()
126  , msol.deltaPhi()
127  , localzVec
128  , newrMinVec
129  , newrMaxVec);
130  DDLogicalPart ddlp = DDLogicalPart(solname, usemat, dsol);
131  return ddlp;
132 }
133 
135  : DDDividedGeometryObject( div, cpv )
136 {
138  setType( "DivisionPolyhedraPhi" );
139 
140  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
141  // double deltaPhi = msol->GetEndPhi() - msol->GetStartPhi();
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 
224  double posi = ( copyNo - 1 ) * compWidth_;
225 
226  // ChangeRotMatrix( physVol, -posi );
227  DDRotationMatrix* rotMat = changeRotMatrix( posi);
228  // how to name the rotation??
229  // i do not like this...
230  DDName ddrotname(div_.parent().ddname().name() + "_DIVCHILD_ROT" + std::to_string(copyNo),
231  div_.parent().ddname().ns());
232  DDRotation myddrot = DDrot(ddrotname, rotMat);
233  return myddrot;
234 }
235 
238 {
239  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
240  DDMaterial usemat = div_.parent().material();
241 
242  DDName solname( div_.parent().ddname().name() + "_DIVCHILD",
243  div_.parent().ddname().ns());
244  DDSolid dsol(solname);
245  if (!dsol.isDefined().second)
246  {
247  dsol = DDSolidFactory::polyhedra( solname,
248  msol.sides(),
249  msol.startPhi()+div_.offset(),
250  compWidth_,
251  msol.zVec(),
252  msol.rMinVec(),
253  msol.rMaxVec());
254  }
255  DDLogicalPart ddlp(solname);
256  if (!ddlp.isDefined().second)
257  DDLogicalPart ddlp2 = DDLogicalPart(solname, usemat, dsol);
258  return ddlp;
259 }
260 
262  : DDDividedGeometryObject( div, cpv )
263 {
265  setType( "DivisionPolyhedraZ" );
266 
267  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
268 
269  std::vector<double> zvec = msol.zVec();
270 
271  if ( divisionType_ == DivWIDTH )
272  {
273  compNDiv_ =
274  calculateNDiv( zvec[zvec.size() - 1] - zvec[0], div_.width(), div_.offset() );
275  }
276  else if( divisionType_ == DivNDIV )
277  {
278  compWidth_ = calculateWidth( zvec[zvec.size() - 1] - zvec[0],
279  div_.nReplicas(),
280  div_.offset());
281  // ?what? CalculateNDiv( zvec[zvec.size() - 1] - zvec[0], origparamMother->Z_values[origparamMother->Num_z_planes-1]
282  // - origparamMother->Z_values[0] , nDiv, offset );
283  }
284 }
285 
286 double
288 {
289  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
290 
291  std::vector<double> zvec = msol.zVec();
292  return (zvec[zvec.size() - 1] - zvec[0]);
293 }
294 
295 void
297 {
299 
300  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
301 
303  {
304  std::cout << "WARNING - "
305  << "DDDividedPolyhedraZ::checkParametersValidity()"
306  << std::endl
307  << " Solid " << msol << std::endl
308  << " Division along Z will be done splitting "
309  << "in the defined z_planes." << std::endl
310  << " WIDTH will not be used !" << std::endl;
311  }
312 
313  if( div_.offset() != 0. )
314  {
315  std::cout << "WARNING - "
316  << "DDDividedPolyhedraZ::checkParametersValidity()"
317  << std::endl
318  << " Solid " << msol << std::endl
319  << " Division along Z will be done splitting "
320  << "in the defined z_planes." << std::endl
321  << " OFFSET will not be used !" << std::endl;
322  }
323 
324  std::vector<double> zvec = msol.zVec();
325 
326  if ( zvec.size() - 1 != size_t(compNDiv_) )
327  {
328  std::cout << "ERROR - "
329  << "DDDividedPolyhedraZ::checkParametersValidity()"
330  << std::endl
331  << " Division along Z can only be done by splitting in the defined"
332  << std::endl
333  << " z_planes, i.e, the number of division would be :"
334  << " " << zvec.size() - 1
335  << " instead of " << compNDiv_ << " !"
336  << std::endl;
337  std::string s = "DDDividedPolyhedraZ::checkParametersValidity()";
338  s += "Illegal Construct. Not a supported configuration.";
339  throw cms::Exception("DDException") << s;
340  }
341 }
342 
344 DDDividedPolyhedraZ::makeDDTranslation( const int copyNo ) const
345 {
346  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
347  std::vector<double> zvec = msol.zVec();
348 
349  //----- set translation: along Z axis
350  double posi = (zvec[copyNo] + zvec[copyNo+1])/2;
351 
352  DDTranslation tr(0,0,posi);
353  //----- calculate rotation matrix: unit
354  return tr;
355 }
356 
358 DDDividedPolyhedraZ::makeDDRotation( const int copyNo ) const
359 {
360  return DDRotation();
361 }
362 
364 DDDividedPolyhedraZ::makeDDLogicalPart( const int copyNo ) const
365 {
366  // only for mother number of planes = 2!!
367  // mec: what? why? comment above and = 2 below straight from G4 impl.
368  DDPolyhedra msol = (DDPolyhedra)( div_.parent().solid());
369  DDMaterial usemat = div_.parent().material();
370 
371  std::vector<double> zvec = msol.zVec();
372  std::vector<double> rminvec = msol.rMinVec();
373  std::vector<double> rmaxvec = msol.rMaxVec();
374 
375  double posi = ( zvec[ copyNo ] + zvec[ copyNo + 1 ] ) / 2.0;
376 
377  DDName solname( div_.parent().ddname().name() + "_DIVCHILD" + std::to_string( copyNo ),
378  div_.parent().ddname().ns());
379  std::vector<double> newRmin, newRmax, newZ;
380  newZ.emplace_back( zvec[ copyNo ] - posi );
381  newZ.emplace_back( zvec[ copyNo + 1 ] - posi );
382  newRmin.emplace_back( rminvec[ copyNo ]);
383  newRmin.emplace_back( rminvec[ copyNo + 1 ]);
384  newRmax.emplace_back( rmaxvec[ copyNo ]);
385  newRmax.emplace_back( rmaxvec[ copyNo + 1 ]);
386 
387  DDSolid dsol = DDSolidFactory::polyhedra( solname,
388  msol.sides(),
389  msol.startPhi(),
390  msol.deltaPhi(),
391  newZ,
392  newRmin,
393  newRmax );
394  DDLogicalPart lp( solname, usemat, dsol );
395  return lp;
396 }
397 
double startPhi(void) const
Definition: DDSolid.cc:427
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:457
int nReplicas() const
Definition: DDDivision.cc:71
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
DDTranslation makeDDTranslation(int copyNo) const override
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
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
DDRotation makeDDRotation(int copyNo) const override
void checkParametersValidity() override
A DDSolid represents the shape of a part.
Definition: DDSolid.h:38
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:67
void checkParametersValidity() override
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
DDRotation makeDDRotation(int copyNo) const override
virtual void setType(const std::string &type)
std::vector< double > rMinVec(void) const
Definition: DDSolid.cc:449
DDLogicalPart makeDDLogicalPart(int copyNo) const override
DDRotation DDrot(const DDName &name, DDRotationMatrix *rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:90
ii
Definition: cuy.py:588
int sides(void) const
Definition: DDSolid.cc:424
std::vector< double > zVec(void) const
Definition: DDSolid.cc:441
DDTranslation makeDDTranslation(int copyNo) const override
DDLogicalPart makeDDLogicalPart(int copyNo) const override
double width() const
Definition: DDDivision.cc:76
double deltaPhi(void) const
Definition: DDSolid.cc:430
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:846
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:80
DDRotationMatrix * changeRotMatrix(double rotZ=0.) const