/DetectorDescription/Parser/src/DDDividedCons.cc

https://github.com/aivanov-cern/cmssw · C++ · 323 lines · 260 code · 46 blank · 17 comment · 22 complexity · 2bf37b7ce7832c84cd52e880d5a090f2 MD5 · raw file

  1. //
  2. // ********************************************************************
  3. // 25.04.04 - M. Case ddd-ize G4ParameterisationCons*
  4. // ********************************************************************
  5. #include "DetectorDescription/Parser/src/DDDividedCons.h"
  6. #include "DetectorDescription/Parser/src/DDXMLElement.h"
  7. #include "DetectorDescription/Core/interface/DDLogicalPart.h"
  8. #include "DetectorDescription/Core/interface/DDName.h"
  9. #include "DetectorDescription/Core/interface/DDAxes.h"
  10. #include "DetectorDescription/Core/interface/DDSolid.h"
  11. #include "DetectorDescription/Core/interface/DDMaterial.h"
  12. #include "DetectorDescription/Base/interface/DDdebug.h"
  13. #include "DetectorDescription/Base/interface/DDRotationMatrix.h"
  14. #include "CLHEP/Units/GlobalSystemOfUnits.h"
  15. DDDividedConsRho::DDDividedConsRho( const DDDivision& div, DDCompactView* cpv )
  16. : DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
  17. {
  18. checkParametersValidity();
  19. setType( "DivisionConsRho" );
  20. DDCons msol = (DDCons)(div_.parent().solid());
  21. if( msol.rInPlusZ() == 0. )
  22. {
  23. std::cout << "WARNING - DDDividedConsRho, rOutMinusZ = 0. "
  24. << std::endl
  25. << " Width is calculated as that of rOutMinusZ !"
  26. << std::endl;
  27. }
  28. if( divisionType_ == DivWIDTH )
  29. {
  30. compNDiv_ = calculateNDiv( msol.rOutMinusZ()
  31. - msol.rInMinusZ(), div_.width(), div_.offset() );
  32. }
  33. else if( divisionType_ == DivNDIV )
  34. {
  35. DDCons msol = (DDCons)(div_.parent().solid());
  36. compWidth_ = calculateWidth( msol.rOutMinusZ() - msol.rInMinusZ()
  37. , div_.nReplicas()
  38. , div_.offset() );
  39. }
  40. DCOUT_V( 'P', " DDDividedConsRho - no divisions " << compNDiv_ << " = " << div_.nReplicas()
  41. << "\n Offset " << div_.offset()
  42. << "\n Width " << compWidth_ << " = " << div_.width()
  43. << "\n DivType " << divisionType_);
  44. }
  45. DDDividedConsRho::~DDDividedConsRho( void )
  46. {}
  47. double
  48. DDDividedConsRho::getMaxParameter( void ) const
  49. {
  50. DDCons msol = (DDCons)(div_.parent().solid());
  51. return msol.rOutMinusZ() - msol.rInMinusZ();
  52. }
  53. DDRotation
  54. DDDividedConsRho::makeDDRotation( const int copyNo ) const
  55. {
  56. DDRotation myddrot; // sets to identity.
  57. DCOUT_V ('P', "DDDividedConsRho::makeDDRotation : " << myddrot);
  58. return myddrot;
  59. }
  60. DDTranslation
  61. DDDividedConsRho::makeDDTranslation( const int copyNo ) const
  62. {
  63. //----- translation
  64. DDTranslation translation;
  65. DCOUT_V ('P', " DDDividedConsRho " << "\n\t Position: " << translation << " - Width: " << compWidth_ << " - Axis " << DDAxesNames::name(div_.axis()));
  66. return translation;
  67. }
  68. DDLogicalPart
  69. DDDividedConsRho::makeDDLogicalPart( const int copyNo ) const
  70. {
  71. DDName solname(div_.parent().ddname().name() + "_DIVCHILD"
  72. + DDXMLElement::itostr(copyNo)
  73. , div_.parent().ddname().ns());
  74. DDSolid ddcons(solname);
  75. DDMaterial usemat(div_.parent().material());
  76. DDCons msol = (DDCons)(div_.parent().solid());
  77. double pRMin1 = msol.rInMinusZ() + div_.offset() + compWidth_ * copyNo;
  78. double pRMax1 = msol.rInMinusZ() + div_.offset() + compWidth_ * (copyNo+1);
  79. //width at Z Plus
  80. //- double compWidth_Plus =
  81. // compWidth_ * ( msol.rOutPlusZ()/ msol.rInPlusZ())
  82. //- / ( msol.rOutMinusZ() - msol.rInMinusZ());
  83. double compWidth_Plus = calculateWidth( msol.rOutPlusZ()
  84. - msol.rInPlusZ(), compNDiv_, div_.offset() );
  85. double pRMin2 = msol.rInPlusZ()
  86. + div_.offset() + compWidth_Plus * copyNo;
  87. double pRMax2 = msol.rInPlusZ()
  88. + div_.offset() + compWidth_Plus * (copyNo+1);
  89. double pDz = msol.zhalf();
  90. double pSPhi = msol.phiFrom();
  91. double pDPhi = msol.deltaPhi();
  92. ddcons = DDSolidFactory::cons(DDName(solname), pDz, pRMin1, pRMax1
  93. , pRMin2, pRMax2, pSPhi, pDPhi);
  94. DDLogicalPart ddlp = DDLogicalPart(solname, usemat, ddcons);
  95. DCOUT_V( 'P', " DDDividedConsRho::makeDDLogicalPart() lp:" << ddlp );
  96. return ddlp;
  97. }
  98. //--------------------------------------------------------------------------
  99. //--------------------------------------------------------------------------
  100. DDDividedConsPhi::DDDividedConsPhi( const DDDivision& div, DDCompactView* cpv )
  101. : DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
  102. {
  103. checkParametersValidity();
  104. setType( "DivisionConsPhi" );
  105. DDCons msol = (DDCons)(div_.parent().solid());
  106. if( divisionType_ == DivWIDTH )
  107. {
  108. DDCons msol = (DDCons)(div_.parent().solid());
  109. //If you divide a tube of 360 degrees the offset displaces the starting angle, but you still fill the 360 degrees
  110. if( msol.deltaPhi() == 360.*deg )
  111. {
  112. compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), 0. );
  113. }
  114. else
  115. {
  116. compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), div_.offset() );
  117. }
  118. }
  119. else if( divisionType_ == DivNDIV )
  120. {
  121. DDCons msol = (DDCons)(div_.parent().solid());
  122. if( msol.deltaPhi() == 360.*deg )
  123. {
  124. compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), 0. );
  125. }
  126. else
  127. {
  128. compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), div_.offset() );
  129. }
  130. }
  131. DCOUT_V( 'P', " DDDividedConsPhi - no divisions " << compNDiv_ << " = " << div_.nReplicas()
  132. << "\n Offset " << div_.offset()
  133. << "\n Width " << compWidth_ << " = " << div_.width()
  134. << "\n DivType " << divisionType_);
  135. }
  136. DDDividedConsPhi::~DDDividedConsPhi( void )
  137. {}
  138. double
  139. DDDividedConsPhi::getMaxParameter( void ) const
  140. {
  141. DDCons msol = (DDCons)(div_.parent().solid());
  142. return msol.deltaPhi();
  143. }
  144. DDRotation
  145. DDDividedConsPhi::makeDDRotation( const int copyNo ) const
  146. {
  147. DDRotation myddrot; // sets to identity.
  148. double posi = ( copyNo - 1 ) * compWidth_;
  149. DDRotationMatrix* rotMat = changeRotMatrix( posi );
  150. // how to name the rotation??
  151. // i hate this crap :-)
  152. DDName ddrotname(div_.parent().ddname().name() + "_DIVCHILD_ROT" + DDXMLElement::itostr(copyNo)
  153. , div_.parent().ddname().ns());
  154. myddrot = DDrot(ddrotname, rotMat);
  155. DCOUT_V ('P', "DDDividedConsPhi::makeDDRotation : " << myddrot);
  156. return myddrot;
  157. }
  158. DDTranslation
  159. DDDividedConsPhi::makeDDTranslation( const int copyNo ) const
  160. {
  161. //----- translation
  162. DDTranslation translation;
  163. DCOUT_V( 'P', " DDDividedConsPhi " << "\n\t Position: " << translation
  164. << " - Width: " << compWidth_
  165. << " - Axis " << DDAxesNames::name(div_.axis()));
  166. return translation;
  167. }
  168. DDLogicalPart
  169. DDDividedConsPhi::makeDDLogicalPart( const int copyNo ) const
  170. {
  171. DDName solname(div_.parent().ddname().name() + "_DIVCHILD"
  172. , div_.parent().ddname().ns());
  173. DDSolid ddcons(solname);
  174. DDMaterial usemat(div_.parent().material());
  175. DDCons msol = (DDCons)(div_.parent().solid());
  176. if (!ddcons.isDefined().second)
  177. {
  178. double pRMin1 = msol.rInMinusZ();
  179. double pRMax1 = msol.rOutMinusZ();
  180. double pRMin2 = msol.rInPlusZ();
  181. double pRMax2 = msol.rOutPlusZ();
  182. double pDz = msol.zhalf();
  183. //- already rotated double pSPhi = div_.offset() + copyNo*compWidth_;
  184. double pSPhi = div_.offset() + msol.phiFrom();
  185. double pDPhi = compWidth_;
  186. ddcons = DDSolidFactory::cons(DDName(solname), pDz, pRMin1, pRMax1
  187. , pRMin2, pRMax2, pSPhi, pDPhi);
  188. }
  189. DDLogicalPart ddlp = DDLogicalPart(solname, usemat, ddcons);
  190. DCOUT_V ('P', " DDDividedConsPhi::makeDDLogicalPart() lp:" << ddlp);
  191. return ddlp;
  192. }
  193. DDDividedConsZ::DDDividedConsZ( const DDDivision& div, DDCompactView* cpv )
  194. : DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
  195. {
  196. checkParametersValidity();
  197. DDCons msol = (DDCons)(div_.parent().solid());
  198. setType( "DivisionConsZ" );
  199. if( divisionType_ == DivWIDTH )
  200. {
  201. DDCons msol = (DDCons)(div_.parent().solid());
  202. compNDiv_ = calculateNDiv( 2*msol.zhalf()
  203. , div_.width(), div_.offset() );
  204. }
  205. else if( divisionType_ == DivNDIV )
  206. {
  207. DDCons msol = (DDCons)(div_.parent().solid());
  208. compWidth_ = calculateWidth( 2*msol.zhalf()
  209. , div_.nReplicas(), div_.offset() );
  210. }
  211. DCOUT_V( 'P', " DDDividedConsZ - no divisions " << compNDiv_ << " = " << div_.nReplicas()
  212. << "\n Offset " << div_.offset()
  213. << "\n Width " << compWidth_ << " = " << div_.width()
  214. << "\n DivType " << divisionType_ );
  215. }
  216. DDDividedConsZ::~DDDividedConsZ( void )
  217. {}
  218. double
  219. DDDividedConsZ::getMaxParameter( void ) const
  220. {
  221. DDCons msol = (DDCons)(div_.parent().solid());
  222. return 2*msol.zhalf();
  223. }
  224. DDRotation
  225. DDDividedConsZ::makeDDRotation( const int copyNo ) const
  226. {
  227. DDRotation myddrot; // sets to identity.
  228. DCOUT_V ('P', "DDDividedConsZ::makeDDRotation : " << myddrot);
  229. return myddrot;
  230. }
  231. DDTranslation
  232. DDDividedConsZ::makeDDTranslation( const int copyNo ) const
  233. {
  234. //----- translation
  235. DDTranslation translation;
  236. DDCons motherCons = (DDCons)(div_.parent().solid());
  237. double posi = - motherCons.zhalf() + div_.offset()
  238. + compWidth_/2 + copyNo*compWidth_;
  239. translation.SetZ(posi);
  240. DCOUT_V ('P', " DDDividedConsZ " << "\n\t Position: " << translation << " - Width: " << compWidth_ << " - Axis " << DDAxesNames::name(div_.axis()));
  241. return translation;
  242. }
  243. DDLogicalPart
  244. DDDividedConsZ::makeDDLogicalPart( const int copyNo ) const
  245. {
  246. DDName solname(div_.parent().ddname().name() + "_DIVCHILD" + DDXMLElement::itostr(copyNo)
  247. , div_.parent().ddname().ns());
  248. DDSolid ddcons(solname);
  249. DDMaterial usemat(div_.parent().material());
  250. DDCons msol = (DDCons)(div_.parent().solid());
  251. double mHalfLength = msol.zhalf();
  252. double aRInner = (msol.rInPlusZ()
  253. - msol.rInMinusZ()) / (2*mHalfLength);
  254. double bRInner = (msol.rInPlusZ()
  255. + msol.rInMinusZ()) / 2;
  256. double aROuter = (msol.rOutPlusZ()
  257. - msol.rOutMinusZ()) / (2*mHalfLength);
  258. double bROuter = (msol.rOutPlusZ()
  259. + msol.rOutMinusZ()) / 2;
  260. double xMinusZ = -mHalfLength + div_.offset() + compWidth_*copyNo;
  261. double xPlusZ = -mHalfLength + div_.offset() + compWidth_*(copyNo+1);
  262. double pDz = compWidth_ / 2.;
  263. double pSPhi = msol.phiFrom();
  264. double pDPhi = msol.deltaPhi();
  265. ddcons = DDSolidFactory::cons(DDName(solname)
  266. , pDz
  267. , aRInner * xMinusZ + bRInner
  268. , aROuter * xMinusZ + bROuter
  269. , aRInner * xPlusZ + bRInner
  270. , aROuter * xPlusZ + bROuter
  271. , pSPhi
  272. , pDPhi
  273. );
  274. DDLogicalPart ddlp = DDLogicalPart(solname, usemat, ddcons);
  275. DCOUT_V( 'P', " DDDividedConsZ::makeDDLogicalPart() lp:" << ddlp );
  276. return ddlp;
  277. }