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