CMS 3D CMS Logo

DDDividedPolycone.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 geant_units::operators;
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  DDSolid ddpolycone;
104  DDMaterial usemat(div_.parent().material());
105 
106  DDPolycone msol = (DDPolycone)(div_.parent().solid());
107  std::vector<double> localrMaxVec = msol.rMaxVec();
108  std::vector<double> localrMinVec = msol.rMinVec();
109  std::vector<double> localzVec = msol.zVec();
110 
111  int nZplanes = localzVec.size();
112 
113  std::vector<double> newrMinVec;
114  std::vector<double> newrMaxVec;
115 
116  double width = 0.;
117  for(int ii = 0; ii < nZplanes; ++ii)
118  {
119  width = calculateWidth( localrMaxVec[ii]
120  - localrMinVec[ii], compNDiv_, div_.offset() );
121  newrMinVec.emplace_back(localrMinVec[ii]+div_.offset()+width*copyNo);
122  newrMaxVec.emplace_back(localrMinVec[ii]+div_.offset()+width*(copyNo+1));
123  }
124  DDName solname( div_.parent().ddname().name() + "_DIVCHILD" + std::to_string(copyNo),
125  div_.parent().ddname().ns());
126 
127  ddpolycone = DDSolidFactory::polycone( solname,
128  msol.startPhi(),
129  msol.deltaPhi(),
130  localzVec,
131  newrMinVec,
132  newrMaxVec );
133 
134  DDLogicalPart ddlp = DDLogicalPart( solname, usemat, ddpolycone );
135  return ddlp;
136 }
137 
140 {
142  DDPolycone msol = (DDPolycone)(div_.parent().solid());
143  setType( "DivisionPolyconePhi" );
144  // this is the g4. what do we keep??? I think it is deltaPhi
145  // double deltaPhi = msol->GetEndPhi() - msol->GetStartPhi();
146  if( divisionType_ == DivWIDTH )
147  {
148  //If you divide a tube of 360 degrees the offset displaces the starting angle, but you still fill the 360 degrees
149  if( msol.deltaPhi() == 360._deg ) {
150  compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), 0. );
151  }else {
153  }
154  }
155  else if( divisionType_ == DivNDIV )
156  {
157  if( msol.deltaPhi() == 360._deg ) {
158  compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), 0. );
159  }else {
161  }
162  }
163 }
164 
165 void
167 {
169 }
170 
171 double
173 {
174  DDPolycone msol = (DDPolycone)(div_.parent().solid());
175  return msol.deltaPhi();
176 }
177 
179 DDDividedPolyconePhi::makeDDRotation( const int copyNo ) const
180 {
181  DDRotation myddrot; // sets to identity.
182  double posi = ( copyNo - 1 ) * compWidth_;
183  // how to name the rotation??
184  // i do not like this
185  DDName ddrotname( div_.parent().ddname().name() + "_DIVCHILD_ROT" + std::to_string( copyNo ),
186  div_.parent().ddname().ns());
187  myddrot = DDrot( ddrotname, changeRotMatrix( posi ));
188 
189  return myddrot;
190 }
191 
194 {
195  DDTranslation translation;
196  return translation;
197 }
198 
201 {
202  DDSolid ddpolycone;
203  DDMaterial usemat(div_.parent().material());
204 
205  DDPolycone msol = (DDPolycone)(div_.parent().solid());
206  std::vector<double> localrMaxVec = msol.rMaxVec();
207  std::vector<double> localrMinVec = msol.rMinVec();
208  std::vector<double> localzVec = msol.zVec();
209 
210  DDName solname( div_.parent().ddname().name() + "_DIVCHILD",
211  div_.parent().ddname().ns());
212  DDSolid sol( solname );
213  if( !sol.isDefined().second )
214  {
215  ddpolycone = DDSolidFactory::polycone( solname,
216  msol.startPhi()+div_.offset(),
217  compWidth_,
218  localzVec,
219  localrMinVec,
220  localrMaxVec );
221  }
222  DDLogicalPart ddlp( solname );
223  if( !ddlp.isDefined().second )
224  {
225  ddlp = DDLogicalPart( solname, usemat, ddpolycone );
226  }
227 
228  return ddlp;
229 }
230 
233 {
235  DDPolycone msol = (DDPolycone)(div_.parent().solid());
236  std::vector<double> localrMaxVec = msol.rMaxVec();
237  std::vector<double> localrMinVec = msol.rMinVec();
238  std::vector<double> localzVec = msol.zVec();
239 
240  if( divisionType_ == DivWIDTH )
241  {
242  compNDiv_ =
243  calculateNDiv( localzVec[localzVec.size() - 1]
244  - localzVec[0] , div_.width(), div_.offset() );
245  }
246  else if( divisionType_ == DivNDIV )
247  {
248  compWidth_ =
249  calculateNDiv( localzVec[localzVec.size()-1]
250  - localzVec[0] , div_.nReplicas(), div_.offset() );
251  }
252 }
253 
254 void
256 {
258 
259  DDPolycone msol = (DDPolycone)(div_.parent().solid());
260  std::vector<double> localzVec = msol.zVec();
261  // CHANGE FROM G4 a polycone can be divided in Z by specifying
262  // nReplicas IF they happen to coincide with the number of
263  // z plans.
264  size_t tempNDiv = div_.nReplicas();
265  if (tempNDiv == 0)
266  tempNDiv = calculateNDiv( localzVec[localzVec.size() - 1] - localzVec[0]
267  , div_.width()
268  , div_.offset() );
269  if ((msol.zVec().size() - 1) != tempNDiv)
270  {
271  std::string s = "ERROR - DDDividedPolyconeZ::checkParametersValidity()";
272  s += "\n\tDivision along Z will be done splitting in the defined";
273  s += "\n\tz_planes, i.e, the number of division would be :";
274  s += "\n\t" + std::to_string( msol.zVec().size() - 1 );
275  s += "\n\tinstead of " + std::to_string(tempNDiv) + " !\n";
276 
277  throw cms::Exception("DDException") << s;
278  }
279 }
280 
281 double
283 {
284  DDPolycone msol = (DDPolycone)(div_.parent().solid());
285  std::vector<double> localzVec = msol.zVec();
286 
287  return (localzVec[ localzVec.size() - 1] - localzVec[0]);
288 }
289 
291 DDDividedPolyconeZ::makeDDRotation( const int copyNo ) const
292 {
293  DDRotation myddrot; // sets to identity.
294  return myddrot;
295 }
296 
298 DDDividedPolyconeZ::makeDDTranslation( const int copyNo ) const
299 {
300  DDTranslation translation;
301  DDPolycone msol = (DDPolycone)(div_.parent().solid());
302  std::vector<double> localzVec = msol.zVec();
303  double posi = (localzVec[copyNo] + localzVec[copyNo+1]) / 2;
304  translation.SetZ(posi);
305  return translation;
306 }
307 
309 DDDividedPolyconeZ::makeDDLogicalPart( const int copyNo ) const
310 {
311  DDSolid ddpolycone;
312  DDMaterial usemat(div_.parent().material());
313 
314  DDPolycone msol = (DDPolycone)(div_.parent().solid());
315  std::vector<double> localrMaxVec = msol.rMaxVec();
316  std::vector<double> localrMinVec = msol.rMinVec();
317  std::vector<double> localzVec = msol.zVec();
318 
319  DDName solname( div_.parent().ddname().name() + "_DIVCHILD" + std::to_string(copyNo),
320  div_.parent().ddname().ns());
321  ddpolycone = DDSolidFactory::cons( solname,
322  compWidth_ / 2,
323  localrMinVec[copyNo],
324  localrMaxVec[copyNo],
325  localrMinVec[copyNo+1],
326  localrMaxVec[copyNo+1],
327  msol.startPhi(),
328  msol.deltaPhi());
329 
330  DDLogicalPart ddlp = DDLogicalPart( solname, usemat, ddpolycone );
331 
332  return ddlp;
333 }
void checkParametersValidity() override
void checkParametersValidity() override
int nReplicas() const
Definition: DDDivision.cc:75
DDLogicalPart makeDDLogicalPart(int copyNo) const override
DDDividedPolyconeRho(const DDDivision &div, DDCompactView *cpv)
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:43
std::vector< double > rMaxVec(void) const
Definition: DDSolid.cc:379
DDRotation makeDDRotation(int copyNo) const override
double offset() const
Definition: DDDivision.cc:87
static DDSolid cons(const DDName &name, double zhalf, double rInMinusZ, double rOutMinusZ, double rInPlusZ, double rOutPlusZ, double phiFrom, double deltaPhi)
Definition: DDSolid.cc:838
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:713
int calculateNDiv(double motherDim, double width, double offset) const
DDRotation makeDDRotation(int copyNo) 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
double getMaxParameter() const override
double calculateWidth(double motherDim, int nDiv, double offset) const
double getMaxParameter() const override
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
DDTranslation makeDDTranslation(int copyNo) const override
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
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
DDTranslation makeDDTranslation(int copyNo) const override
double getMaxParameter() const override
DDLogicalPart makeDDLogicalPart(int copyNo) const override
std::vector< double > rMinVec(void) const
Definition: DDSolid.cc:371
void checkParametersValidity() override
double deltaPhi(void) const
Definition: DDSolid.cc:353
DDTranslation makeDDTranslation(int copyNo) const 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
virtual void setType(const std::string &type)
ii
Definition: cuy.py:590
DDDividedPolyconeZ(const DDDivision &div, DDCompactView *cpv)
std::unique_ptr< DDRotationMatrix > changeRotMatrix(double rotZ=0.) const
DDDividedPolyconePhi(const DDDivision &div, DDCompactView *cpv)
double width() const
Definition: DDDivision.cc:81
const DDLogicalPart & parent() const
Definition: DDDivision.cc:93
const std::string & name() const
Returns the name.
Definition: DDName.cc:53
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
DDLogicalPart makeDDLogicalPart(int copyNo) const override
std::vector< double > zVec(void) const
Definition: DDSolid.cc:363
DDRotation makeDDRotation(int copyNo) const override
const N & ddname() const
Definition: DDBase.h:76