CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDDividedPolyhedra.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // 25.04.04 - M. Case ddd-ize G4ParameterisationPolyhedra*
4 //---------------------------------------------------------------------
7 
12 
16 
17 #include "CLHEP/Units/GlobalSystemOfUnits.h"
18 
20  : DDDividedGeometryObject( div, cpv )
21 {
23  setType( "DivisionPolyhedraRho" );
24 
25  DDPolyhedra msol = (DDPolyhedra)( div_.parent().solid() );
26 
27  if( divisionType_ == DivWIDTH )
28  {
29  compNDiv_ = calculateNDiv( msol.rMaxVec()[0] - msol.rMinVec()[0]
30  , div_.width()
31  , div_.offset() );
32  }
33  else if( divisionType_ == DivNDIV )
34  {
35  compWidth_ = calculateWidth( msol.rMaxVec()[0] - msol.rMinVec()[0]
36  , div_.nReplicas()
37  , div_.offset() );
38  }
39 
40  // for (int i = 0; i < compNDiv_; ++i)
41  // {
42  // DDpos( makeDDLogicalPart(i)
43  // , div_.parent()
44  // , i
45  // , makeDDTranslation(i)
46  // , makeDDRotation(i)
47  // , &div_
48  // );
49  // }
50 
51  DCOUT_V ('P', " DDDividedPolyhedraRho - # divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << " Width " << compWidth_ << " = " << div_.width() << "\n");
52 
53 }
54 
56 {}
57 
58 void
60 {
62 
63  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
64 
66  {
67  std::cout << "WARNING - "
68  << "DDDividedPolyhedraRho::checkParametersValidity()"
69  << std::endl
70  << " Solid " << msol << std::endl
71  << " Division along R will be done with a width "
72  << "different for each solid section." << std::endl
73  << " WIDTH will not be used !" << std::endl;
74  }
75  if( div_.offset() != 0. )
76  {
77  std::cout << "WARNING - "
78  << "DDDividedPolyhedraRho::checkParametersValidity()"
79  << std::endl
80  << " Solid " << msol << std::endl
81  << " Division along R will be done with a width "
82  << "different for each solid section." << std::endl
83  << " OFFSET will not be used !" << std::endl;
84  }
85 }
86 
87 double
89 {
90  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
91  return msol.rMaxVec()[0] - msol.rMinVec()[0];
92 }
93 
96 {
97  return DDTranslation();
98 }
99 
101 DDDividedPolyhedraRho::makeDDRotation( const int copyNo ) const
102 {
103  return DDRotation();
104 }
105 
108 {
109  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
110  DDMaterial usemat = div_.parent().material();
111 
112  std::vector<double> localrMaxVec = msol.rMaxVec();
113  std::vector<double> localrMinVec = msol.rMinVec();
114  std::vector<double> localzVec = msol.zVec();
115  std::vector<double> newrMinVec;
116  std::vector<double> newrMaxVec;
117  int nZplanes = localzVec.size();
118 
119  double width = 0.;
120  for(int ii = 0; ii < nZplanes; ++ii)
121  {
122  // width = CalculateWidth( origparamMother->Rmax[ii]
123  // - origparamMother->Rmin[ii], compNDiv_, foffset );
124  // origparam.Rmin[ii] = origparamMother->Rmin[ii]+foffset+width*copyNo;
125  // origparam.Rmax[ii] = origparamMother->Rmin[ii]+foffset+width*(copyNo+1);
126  width = calculateWidth(localrMaxVec[ii] - localrMinVec[ii], compNDiv_, div_.offset());
127  newrMinVec[ii] = localrMinVec[ii] + div_.offset() + width * copyNo;
128  newrMaxVec[ii] = localrMaxVec[ii] + div_.offset() + width * (copyNo + 1);
129  }
130 
131  // phedra.SetOriginalParameters(&origparam); // copy values & transfer pointers
132  // phedra.Reset(); // reset to new solid parameters
133 
134  DDName solname(div_.parent().ddname().name() + "_DIVCHILD" + DDXMLElement::itostr(copyNo)
135  , div_.parent().ddname().ns());
136 
137  DDSolid dsol = DDSolidFactory::polyhedra(solname
138  , msol.sides()
139  , msol.startPhi()
140  , msol.deltaPhi()
141  , localzVec
142  , newrMinVec
143  , newrMaxVec);
144  DDLogicalPart ddlp = DDLogicalPart(solname, usemat, dsol);
145  DCOUT_V ('P', "DDDividedPolyhedraRho:makeDDLogicalPart lp:" << ddlp);
146  return ddlp;
147 }
148 
150  : DDDividedGeometryObject( div, cpv )
151 {
153  setType( "DivisionPolyhedraPhi" );
154 
155  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
156  // double deltaPhi = msol->GetEndPhi() - msol->GetStartPhi();
157 
158  if( divisionType_ == DivWIDTH )
159  {
160  //If you divide a tube of 360 degrees the offset displaces the starting angle, but you still fill the 360 degrees
161  if( msol.deltaPhi() == 360.*deg ) {
162  compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), 0. );
163  }else {
165  }
166  }
167  else if( divisionType_ == DivNDIV )
168  {
169  if( msol.deltaPhi() == 360.*deg ) {
170  compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), 0. );
171  }else {
172  // original line looks wrong!
174  }
175  }
176 
177  DCOUT_V ('P', " DDDividedPolyhedraRho - # divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << " Width " << compWidth_ << " = " << div_.width() << "\n");
178 }
179 
181 {}
182 
183 double
185 {
186  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
187  return msol.deltaPhi(); //msol->GetEndPhi() - msol->GetStartPhi();
188 }
189 
190 void
192 {
194 
195  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
196 
198  {
199  std::cout << "WARNING - "
200  << "DDDividedPolyhedraPhi::checkParametersValidity()"
201  << std::endl
202  << " Solid " << msol << std::endl
203  << " Division along PHI will be done splitting "
204  << "in the defined numSide." << std::endl
205  << " WIDTH will not be used !" << std::endl;
206  }
207  if( div_.offset() != 0. )
208  {
209  std::cout << "WARNING - "
210  << "DDDividedPolyhedraPhi::checkParametersValidity()"
211  << std::endl
212  << " Solid " << msol << std::endl
213  << " Division along PHI will be done splitting "
214  << "in the defined numSide." << std::endl
215  << " OFFSET will not be used !" << std::endl;
216  }
217 
218  if ( msol.sides() != compNDiv_ )
219  {
220  std::cout << "ERROR - "
221  << "DDDividedPolyhedraPhi::checkParametersValidity()"
222  << std::endl
223  << " Division along PHI will be done splitting in the defined"
224  << std::endl
225  << " numSide, i.e, the number of division would be :"
226  << " " << msol.sides()
227  << " instead of " << compNDiv_ << " !"
228  << std::endl;
229  std::string s = "DDDividedPolyhedraPhi::checkParametersValidity() Not supported configuration.";
230  throw DDException(s);
231  }
232 }
233 
236 {
237  return DDTranslation();
238 }
239 
241 DDDividedPolyhedraPhi::makeDDRotation( const int copyNo ) const
242 {
243 
244  double posi = ( copyNo - 1 ) * compWidth_;
245 
246  DCOUT_V ('P', " DDDividedPolyhedraPhi - position: " << posi/deg << "\n copyNo: " << copyNo << " - compWidth_: " << compWidth_/deg << "\n");
247 
248  // ChangeRotMatrix( physVol, -posi );
249  DDRotationMatrix* rotMat = changeRotMatrix( posi);
250  // how to name the rotation??
251  // i do not like this...
252  DDName ddrotname(div_.parent().ddname().name() + "_DIVCHILD_ROT" + DDXMLElement::itostr(copyNo)
253  , div_.parent().ddname().ns());
254  DDRotation myddrot = DDrot(ddrotname, rotMat);
255  DCOUT_V ('P', "DDDividedPolyhedra::makeDDRotation: copyNo = " << copyNo << " rotation = " << myddrot);
256  return myddrot;
257 
258 }
259 
262 {
263  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
264  DDMaterial usemat = div_.parent().material();
265 
266  DDName solname( div_.parent().ddname().name() + "_DIVCHILD",
267  div_.parent().ddname().ns());
268  DDSolid dsol(solname);
269  if (!dsol.isDefined().second)
270  {
271  dsol = DDSolidFactory::polyhedra( solname,
272  msol.sides(),
273  msol.startPhi()+div_.offset(),
274  compWidth_,
275  msol.zVec(),
276  msol.rMinVec(),
277  msol.rMaxVec());
278  }
279  DDLogicalPart ddlp(solname);
280  if (!ddlp.isDefined().second)
281  DDLogicalPart ddlp2 = DDLogicalPart(solname, usemat, dsol);
282  DCOUT_V ('P', "DDDividedPolyhedraPhi::makeDDLogicalPart() ddlp = " << ddlp);
283  return ddlp;
284 }
285 
287  : DDDividedGeometryObject( div, cpv )
288 {
290  setType( "DivisionPolyhedraZ" );
291 
292  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
293 
294  std::vector<double> zvec = msol.zVec();
295 
296  if ( divisionType_ == DivWIDTH )
297  {
298  compNDiv_ =
299  calculateNDiv( zvec[zvec.size() - 1] - zvec[0], div_.width(), div_.offset() );
300  }
301  else if( divisionType_ == DivNDIV )
302  {
303  compWidth_ = calculateWidth( zvec[zvec.size() - 1] - zvec[0],
304  div_.nReplicas(),
305  div_.offset());
306  // ?what? CalculateNDiv( zvec[zvec.size() - 1] - zvec[0], origparamMother->Z_values[origparamMother->Num_z_planes-1]
307  // - origparamMother->Z_values[0] , nDiv, offset );
308  }
309 
310  DCOUT_V ('P', " DDDividedPolyhedraZ - # divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << " = " << div_.offset() << "\n Width " << compWidth_ << " = " << div_.width());
311 }
312 
314 {}
315 
316 double
318 {
319  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
320 
321  std::vector<double> zvec = msol.zVec();
322  return (zvec[zvec.size() - 1] - zvec[0]);
323 }
324 
325 void
327 {
329 
330  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
331 
333  {
334  std::cout << "WARNING - "
335  << "DDDividedPolyhedraZ::checkParametersValidity()"
336  << std::endl
337  << " Solid " << msol << std::endl
338  << " Division along Z will be done splitting "
339  << "in the defined z_planes." << std::endl
340  << " WIDTH will not be used !" << std::endl;
341  }
342 
343  if( div_.offset() != 0. )
344  {
345  std::cout << "WARNING - "
346  << "DDDividedPolyhedraZ::checkParametersValidity()"
347  << std::endl
348  << " Solid " << msol << std::endl
349  << " Division along Z will be done splitting "
350  << "in the defined z_planes." << std::endl
351  << " OFFSET will not be used !" << std::endl;
352  }
353 
354  std::vector<double> zvec = msol.zVec();
355 
356  if ( zvec.size() - 1 != size_t(compNDiv_) )
357  {
358  std::cout << "ERROR - "
359  << "DDDividedPolyhedraZ::checkParametersValidity()"
360  << std::endl
361  << " Division along Z can only be done by splitting in the defined"
362  << std::endl
363  << " z_planes, i.e, the number of division would be :"
364  << " " << zvec.size() - 1
365  << " instead of " << compNDiv_ << " !"
366  << std::endl;
367  std::string s = "DDDividedPolyhedraZ::checkParametersValidity()";
368  s += "Illegal Construct. Not a supported configuration.";
369  throw DDException (s);
370  }
371 }
372 
374 DDDividedPolyhedraZ::makeDDTranslation( const int copyNo ) const
375 {
376  DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
377  std::vector<double> zvec = msol.zVec();
378 
379  //----- set translation: along Z axis
380  double posi = (zvec[copyNo] + zvec[copyNo+1])/2;
381 
382  DDTranslation tr(0,0,posi);
383  //----- calculate rotation matrix: unit
384 
385  DCOUT_V ('P', " DDDividedPolyhedraZ - position: " << posi << "\n copyNo: " << copyNo << " - offset: " << div_.offset()/deg << " - compWidth_: " << compWidth_/deg << " translation = " << tr);
386  return tr;
387 }
388 
390 DDDividedPolyhedraZ::makeDDRotation( const int copyNo ) const
391 {
392  return DDRotation();
393 }
394 
396 DDDividedPolyhedraZ::makeDDLogicalPart( const int copyNo ) const
397 {
398  // only for mother number of planes = 2!!
399  // mec: what? why? comment above and = 2 below straight from G4 impl.
400  DDPolyhedra msol = (DDPolyhedra)( div_.parent().solid());
401  DDMaterial usemat = div_.parent().material();
402 
403  std::vector<double> zvec = msol.zVec();
404  std::vector<double> rminvec = msol.rMinVec();
405  std::vector<double> rmaxvec = msol.rMaxVec();
406 
407  double posi = ( zvec[ copyNo ] + zvec[ copyNo + 1 ] ) / 2.0;
408 
409  DDName solname( div_.parent().ddname().name() + "_DIVCHILD" + DDXMLElement::itostr( copyNo ),
410  div_.parent().ddname().ns());
411  std::vector<double> newRmin, newRmax, newZ;
412  newZ.push_back( zvec[ copyNo ] - posi );
413  newZ.push_back( zvec[ copyNo + 1 ] - posi );
414  newRmin.push_back( rminvec[ copyNo ]);
415  newRmin.push_back( rminvec[ copyNo + 1 ]);
416  newRmax.push_back( rmaxvec[ copyNo ]);
417  newRmax.push_back( rmaxvec[ copyNo + 1 ]);
418 
419  DDSolid dsol = DDSolidFactory::polyhedra( solname,
420  msol.sides(),
421  msol.startPhi(),
422  msol.deltaPhi(),
423  newZ,
424  newRmin,
425  newRmax );
426  DDLogicalPart lp( solname, usemat, dsol );
427 
428  DCOUT_V( 'P', "DDDividedPolyhedraZ::makeDDLogicalPart" << "\n-- Parametrised phedra copy-number: " << copyNo << "\n-- DDLogicalPart " << lp );
429  return lp;
430 }
431 
virtual void checkParametersValidity()
def_type isDefined() const
Definition: DDBase.h:121
DDDividedPolyhedraRho(const DDDivision &div, DDCompactView *cpv)
const int nReplicas() const
Definition: DDDivision.cc:90
std::vector< double > zVec() const
Definition: DDSolid.cc:429
static std::string itostr(int i)
WARNING: abused by other classes in this system: yet another conversion from int to std::string...
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
double deltaPhi() const
Definition: DDSolid.cc:420
std::vector< double > rMinVec() const
Definition: DDSolid.cc:436
int sides() const
Definition: DDSolid.cc:416
virtual double getMaxParameter() const
virtual void checkParametersValidity()
int calculateNDiv(double motherDim, double width, double offset) const
An exception for DDD errors.
Definition: DDException.h:23
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:101
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:18
DDDividedPolyhedraPhi(const DDDivision &div, DDCompactView *cpv)
double calculateWidth(double motherDim, int nDiv, double offset) const
virtual DDTranslation makeDDTranslation(const int copyNo) const
virtual DDRotation makeDDRotation(const int copyNo) const
type of data representation of DDCompactView
Definition: DDCompactView.h:81
const DDMaterial & material() const
Returns a reference object of the material this LogicalPart is made of.
double startPhi() const
Definition: DDSolid.cc:418
A DDSolid represents the shape of a part.
Definition: DDSolid.h:42
virtual void checkParametersValidity(void)
virtual DDTranslation makeDDTranslation(const int copyNo) const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:66
virtual DDLogicalPart makeDDLogicalPart(const int copyNo) const
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:95
virtual void setType(const std::string &type)
virtual void checkParametersValidity()
DDRotation DDrot(const DDName &name, DDRotationMatrix *rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:94
#define DCOUT_V(M_v_Y, M_v_S)
Definition: DDdebug.h:54
const double width() const
Definition: DDDivision.cc:95
virtual double getMaxParameter() const
std::vector< double > rMaxVec() const
Definition: DDSolid.cc:443
virtual DDTranslation makeDDTranslation(const int copyNo) const
const DDSolid & solid() const
Returns a reference object of the solid being the shape of this LogicalPart.
virtual DDLogicalPart makeDDLogicalPart(const int copyNo) const
virtual DDRotation makeDDRotation(const int copyNo) const
const double offset() const
Definition: DDDivision.cc:100
tuple cout
Definition: gather_cfg.py:41
const DDLogicalPart & parent() const
Definition: DDDivision.cc:105
virtual DDRotation makeDDRotation(const int copyNo) const
string s
Definition: asciidump.py:422
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:87
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) //! Creates a polycone (refere to Gean...
Definition: DDSolid.cc:676
virtual double getMaxParameter() const
virtual DDLogicalPart makeDDLogicalPart(const int copyNo) const
const N & ddname() const
Definition: DDBase.h:90
DDRotationMatrix * changeRotMatrix(double rotZ=0.) const