CMS 3D CMS Logo

DDDividedPolycone.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 
25 {
27  DDPolycone msol = (DDPolycone)(div_.parent().solid());
28  std::vector<double> localrMaxVec = msol.rMaxVec();
29  std::vector<double> localrMinVec = msol.rMinVec();
30 
31  setType( "DivisionPolyconeRho" );
32 
33  // in DDD we only have ONE representation
34  // in the case when rMinVec and rMaxVec
35  // are empty rVec and zVec are the r and z std::vectors.
36 
37  if( divisionType_ == DivWIDTH )
38  {
39  compNDiv_ = calculateNDiv( localrMaxVec[0] - localrMinVec[0], div_.width(), div_.offset());
40  }
41  else if( divisionType_ == DivNDIV )
42  {
43  compWidth_ = calculateWidth( localrMaxVec[0] - localrMinVec[0], div_.nReplicas(), div_.offset());
44  }
45 }
46 
47 void
49 {
51 
52  DDPolycone msol = (DDPolycone)(div_.parent().solid());
53 
55  {
56  std::cout << "WARNING - "
57  << "DDDividedPolyconeRho::checkParametersValidity()"
58  << std::endl
59  << " Solid " << msol << std::endl
60  << " Division along r will be done with a width "
61  << "different for each solid section." << std::endl
62  << " WIDTH will not be used !" << std::endl;
63  }
64  if( div_.offset() != 0. )
65  {
66  std::cout << "WARNING - "
67  << "DDDividedPolyconeRho::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  << " OFFSET will not be used !" << std::endl;
73  }
74 }
75 
76 double
78 {
79  DDPolycone msol = (DDPolycone)(div_.parent().solid());
80  std::vector<double> localrMaxVec = msol.rMaxVec();
81  std::vector<double> localrMinVec = msol.rMinVec();
82 
83  return localrMaxVec[0] - localrMinVec[0];
84 }
85 
87 DDDividedPolyconeRho::makeDDRotation( const int copyNo ) const
88 {
89  DDRotation myddrot; // sets to identity.
90  return myddrot;
91 }
92 
94 DDDividedPolyconeRho::makeDDTranslation( const int copyNo ) const
95 {
96  DDTranslation translation;
97  return translation;
98 }
99 
102 {
103  DDName solname;
104  DDSolid ddpolycone;
105  DDMaterial usemat(div_.parent().material());
106 
107  DDPolycone msol = (DDPolycone)(div_.parent().solid());
108  std::vector<double> localrMaxVec = msol.rMaxVec();
109  std::vector<double> localrMinVec = msol.rMinVec();
110  std::vector<double> localzVec = msol.zVec();
111 
112  int nZplanes = localzVec.size();
113 
114  std::vector<double> newrMinVec;
115  std::vector<double> newrMaxVec;
116 
117  double width = 0.;
118  for(int ii = 0; ii < nZplanes; ++ii)
119  {
120  width = calculateWidth( localrMaxVec[ii]
121  - localrMinVec[ii], compNDiv_, div_.offset() );
122  // hmmm different width every time... probably should use width
123  // not compWidth_
124  // newrMinVec[ii] = localrMinVec[ii]+div_.offset()+compWidth_*copyNo;
125  // newrMaxVec[ii] = localrMinVec[ii]+div_.offset()+compWidth_*(copyNo+1);
126  newrMinVec.push_back(localrMinVec[ii]+div_.offset()+width*copyNo);
127  newrMaxVec.push_back(localrMinVec[ii]+div_.offset()+width*(copyNo+1));
128  }
129  solname = DDName( div_.parent().ddname().name() + "_DIVCHILD" + std::to_string(copyNo),
130  div_.parent().ddname().ns());
131 
132  ddpolycone = DDSolidFactory::polycone( solname,
133  msol.startPhi(),
134  msol.deltaPhi(),
135  localzVec,
136  newrMinVec,
137  newrMaxVec );
138 
139  DDLogicalPart ddlp = DDLogicalPart( solname, usemat, ddpolycone );
140  return ddlp;
141 }
142 
145 {
147  DDPolycone msol = (DDPolycone)(div_.parent().solid());
148  setType( "DivisionPolyconePhi" );
149  // this is the g4. what do we keep??? I think it is deltaPhi
150  // double deltaPhi = msol->GetEndPhi() - msol->GetStartPhi();
151  if( divisionType_ == DivWIDTH )
152  {
153  //If you divide a tube of 360 degrees the offset displaces the starting angle, but you still fill the 360 degrees
154  if( msol.deltaPhi() == 360.*deg ) {
155  compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), 0. );
156  }else {
158  }
159  }
160  else if( divisionType_ == DivNDIV )
161  {
162  if( msol.deltaPhi() == 360.*deg ) {
163  compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), 0. );
164  }else {
166  }
167  }
168 }
169 
170 void
172 {
174 }
175 
176 double
178 {
179  DDPolycone msol = (DDPolycone)(div_.parent().solid());
180  return msol.deltaPhi();
181 }
182 
184 DDDividedPolyconePhi::makeDDRotation( const int copyNo ) const
185 {
186  DDRotation myddrot; // sets to identity.
187  double posi = ( copyNo - 1 ) * compWidth_;
188  DDRotationMatrix* rotMat = changeRotMatrix( posi );
189  // how to name the rotation??
190  // i do not like this
191  DDName ddrotname( div_.parent().ddname().name() + "_DIVCHILD_ROT" + std::to_string( copyNo ),
192  div_.parent().ddname().ns());
193  myddrot = DDrot( ddrotname, rotMat );
194 
195  return myddrot;
196 }
197 
200 {
201  DDTranslation translation;
202  return translation;
203 }
204 
207 {
208  DDName solname;
209  DDSolid ddpolycone;
210  DDMaterial usemat(div_.parent().material());
211 
212  DDPolycone msol = (DDPolycone)(div_.parent().solid());
213  std::vector<double> localrMaxVec = msol.rMaxVec();
214  std::vector<double> localrMinVec = msol.rMinVec();
215  std::vector<double> localzVec = msol.zVec();
216 
217  solname = DDName(div_.parent().ddname().name() + "_DIVCHILD",
218  div_.parent().ddname().ns());
219  DDSolid sol( solname );
220  if( !sol.isDefined().second )
221  {
222  ddpolycone = DDSolidFactory::polycone( solname,
223  msol.startPhi()+div_.offset(),
224  compWidth_,
225  localzVec,
226  localrMinVec,
227  localrMaxVec );
228  }
229  DDLogicalPart ddlp( solname );
230  if( !ddlp.isDefined().second )
231  {
232  ddlp = DDLogicalPart( solname, usemat, ddpolycone );
233  }
234 
235  return ddlp;
236 }
237 
240 {
242  DDPolycone msol = (DDPolycone)(div_.parent().solid());
243  std::vector<double> localrMaxVec = msol.rMaxVec();
244  std::vector<double> localrMinVec = msol.rMinVec();
245  std::vector<double> localzVec = msol.zVec();
246 
247  if( divisionType_ == DivWIDTH )
248  {
249  compNDiv_ =
250  calculateNDiv( localzVec[localzVec.size() - 1]
251  - localzVec[0] , div_.width(), div_.offset() );
252  }
253  else if( divisionType_ == DivNDIV )
254  {
255  compWidth_ =
256  calculateNDiv( localzVec[localzVec.size()-1]
257  - localzVec[0] , div_.nReplicas(), div_.offset() );
258  }
259 }
260 
261 void
263 {
265 
266  DDPolycone msol = (DDPolycone)(div_.parent().solid());
267  std::vector<double> localzVec = msol.zVec();
268  // CHANGE FROM G4 a polycone can be divided in Z by specifying
269  // nReplicas IF they happen to coincide with the number of
270  // z plans.
271  size_t tempNDiv = div_.nReplicas();
272  if (tempNDiv == 0)
273  tempNDiv = calculateNDiv( localzVec[localzVec.size() - 1] - localzVec[0]
274  , div_.width()
275  , div_.offset() );
276  if ((msol.zVec().size() - 1) != tempNDiv)
277  {
278  std::string s = "ERROR - DDDividedPolyconeZ::checkParametersValidity()";
279  s += "\n\tDivision along Z will be done splitting in the defined";
280  s += "\n\tz_planes, i.e, the number of division would be :";
281  s += "\n\t" + std::to_string( msol.zVec().size() - 1 );
282  s += "\n\tinstead of " + std::to_string(tempNDiv) + " !\n";
283 
284  throw cms::Exception("DDException") << s;
285  }
286 }
287 
288 double
290 {
291  DDPolycone msol = (DDPolycone)(div_.parent().solid());
292  std::vector<double> localzVec = msol.zVec();
293 
294  return (localzVec[ localzVec.size() - 1] - localzVec[0]);
295 }
296 
298 DDDividedPolyconeZ::makeDDRotation( const int copyNo ) const
299 {
300  DDRotation myddrot; // sets to identity.
301  return myddrot;
302 }
303 
305 DDDividedPolyconeZ::makeDDTranslation( const int copyNo ) const
306 {
307  DDTranslation translation;
308  DDPolycone msol = (DDPolycone)(div_.parent().solid());
309  std::vector<double> localzVec = msol.zVec();
310  double posi = (localzVec[copyNo] + localzVec[copyNo+1]) / 2;
311  translation.SetZ(posi);
312  return translation;
313 }
314 
316 DDDividedPolyconeZ::makeDDLogicalPart( const int copyNo ) const
317 {
318  DDName solname;
319  DDSolid ddpolycone;
320  DDMaterial usemat(div_.parent().material());
321 
322  DDPolycone msol = (DDPolycone)(div_.parent().solid());
323  std::vector<double> localrMaxVec = msol.rMaxVec();
324  std::vector<double> localrMinVec = msol.rMinVec();
325  std::vector<double> localzVec = msol.zVec();
326 
327  solname = DDName( div_.parent().ddname().name() + "_DIVCHILD" + std::to_string(copyNo),
328  div_.parent().ddname().ns());
329  ddpolycone = DDSolidFactory::cons( solname,
330  compWidth_ / 2,
331  localrMinVec[copyNo],
332  localrMaxVec[copyNo],
333  localrMinVec[copyNo+1],
334  localrMaxVec[copyNo+1],
335  msol.startPhi(),
336  msol.deltaPhi());
337 
338  DDLogicalPart ddlp = DDLogicalPart( solname, usemat, ddpolycone );
339 
340  return ddlp;
341 }
virtual void checkParametersValidity() override
virtual void checkParametersValidity() override
int nReplicas() const
Definition: DDDivision.cc:71
DDDividedPolyconeRho(const DDDivision &div, DDCompactView *cpv)
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
std::vector< double > rMaxVec(void) const
Definition: DDSolid.cc:393
double offset() const
Definition: DDDivision.cc:81
static DDSolid cons(const DDName &name, double zhalf, double rInMinusZ, double rOutMinusZ, double rInPlusZ, double rOutPlusZ, double phiFrom, double deltaPhi)
Definition: DDSolid.cc:836
static DDSolid polycone(const DDName &name, double startPhi, double deltaPhi, const std::vector< double > &z, const std::vector< double > &rmin, const std::vector< double > &rmax)
Creates a polycone (refere to Geant3 or Geant4 documentation)
Definition: DDSolid.cc:714
int calculateNDiv(double motherDim, double width, double offset) const
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:104
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:16
virtual double getMaxParameter() const override
double calculateWidth(double motherDim, int nDiv, double offset) const
virtual double getMaxParameter() 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 DDLogicalPart makeDDLogicalPart(const int copyNo) const override
virtual DDLogicalPart makeDDLogicalPart(const int copyNo) const override
A DDSolid represents the shape of a part.
Definition: DDSolid.h:37
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:64
virtual double getMaxParameter() const override
std::vector< double > rMinVec(void) const
Definition: DDSolid.cc:385
virtual void checkParametersValidity() override
double deltaPhi(void) const
Definition: DDSolid.cc:367
virtual DDTranslation makeDDTranslation(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)
virtual DDTranslation makeDDTranslation(const int copyNo) const override
virtual DDRotation makeDDRotation(const 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
DDDividedPolyconeZ(const DDDivision &div, DDCompactView *cpv)
DDDividedPolyconePhi(const DDDivision &div, DDCompactView *cpv)
double width() const
Definition: DDDivision.cc:76
virtual DDTranslation makeDDTranslation(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.
virtual DDRotation makeDDRotation(const int copyNo) const override
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
std::vector< double > zVec(void) const
Definition: DDSolid.cc:377
virtual DDLogicalPart makeDDLogicalPart(const int copyNo) const override
virtual DDRotation makeDDRotation(const int copyNo) const override
const N & ddname() const
Definition: DDBase.h:80
DDRotationMatrix * changeRotMatrix(double rotZ=0.) const