/DetectorDescription/Parser/src/DDDividedTrd.cc

https://github.com/aivanov-cern/cmssw · C++ · 444 lines · 346 code · 61 blank · 37 comment · 51 complexity · b518da6733766dcdbc3ee4dd524b0013 MD5 · raw file

  1. //
  2. // ********************************************************************
  3. // 25.04.04 - M. Case ddd-ize G4ParameterisationTrd*
  4. // ********************************************************************
  5. #include "DetectorDescription/Parser/src/DDDividedTrd.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 "CLHEP/Units/GlobalSystemOfUnits.h"
  14. #include <cmath>
  15. #include <cstdlib>
  16. DDDividedTrdX::DDDividedTrdX( const DDDivision& div, DDCompactView* cpv )
  17. : DDDividedGeometryObject(div,cpv)
  18. {
  19. checkParametersValidity();
  20. setType( "DivisionTrdX" );
  21. DDTrap mtrd = (DDTrap)( div_.parent().solid() );
  22. if ( divisionType_ == DivWIDTH )
  23. {
  24. compNDiv_ = calculateNDiv( 2 * mtrd.x1(), div_.width(), div_.offset() );
  25. }
  26. else if( divisionType_ == DivNDIV )
  27. {
  28. compWidth_ = calculateWidth( 2*mtrd.x1(), div_.nReplicas(), div_.offset() );
  29. }
  30. DCOUT_V ('P', " DDDividedTrdX - ## divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << "\n Width " << compWidth_ << " = " << div_.width());
  31. }
  32. DDDividedTrdX::~DDDividedTrdX( void )
  33. {}
  34. double
  35. DDDividedTrdX::getMaxParameter( void ) const
  36. {
  37. DDTrap mtrd = (DDTrap)(div_.parent().solid());
  38. return 2 * mtrd.x1();
  39. }
  40. DDTranslation
  41. DDDividedTrdX::makeDDTranslation( const int copyNo ) const
  42. {
  43. DDTrap mtrd = (DDTrap)(div_.parent().solid());
  44. double mdx = mtrd.x1();
  45. //----- translation
  46. double posi = -mdx + div_.offset() + (copyNo+0.5)*compWidth_;
  47. DCOUT_V ('P', " DDDividedTrdX: " << copyNo << "\n Position: x=" << posi << " Axis= " << DDAxesNames::name(div_.axis()) << "\n");
  48. if( div_.axis() == x )
  49. {
  50. return DDTranslation(posi, 0.0, 0.0);
  51. }
  52. else
  53. {
  54. std::string s = "ERROR - DDDividedTrdX::makeDDTranslation()";
  55. s += "\n Axis is along ";
  56. s += DDAxesNames::name(div_.axis());
  57. s += " !\n" ;
  58. s += "DDDividedTrdX::makeDDTranslation()";
  59. s += " IllegalConstruct: Only axes along x are allowed !";
  60. throw cms::Exception("DDException") << s;
  61. }
  62. return DDTranslation();
  63. }
  64. DDRotation
  65. DDDividedTrdX::makeDDRotation( const int copyNo ) const
  66. {
  67. return DDRotation();
  68. }
  69. DDLogicalPart
  70. DDDividedTrdX::makeDDLogicalPart( const int copyNo ) const
  71. {
  72. DDTrap mtrd = (DDTrap)(div_.parent().solid());
  73. DDMaterial usemat = div_.parent().material();
  74. double pDy1 = mtrd.y1(); //GetYHalfLength1();
  75. double pDy2 = mtrd.y2(); //->GetYHalfLength2();
  76. double pDz = mtrd.halfZ(); //->GetZHalfLength();
  77. double pDx = compWidth_/2.;
  78. //trd.SetAllParameters ( pDx, pDx, pDy1, pDy2, pDz );
  79. DDName solname(div_.parent().ddname().name() + "_DIVCHILD"
  80. , div_.parent().ddname().ns());
  81. DDSolid dsol(solname);
  82. DDLogicalPart ddlp(solname);
  83. if (!dsol.isDefined().second)
  84. {
  85. dsol = DDSolidFactory::trap(solname
  86. , pDz
  87. , 0.*deg
  88. , 0.*deg
  89. , pDy1
  90. , pDx
  91. , pDx
  92. , 0.*deg
  93. , pDy2
  94. , pDx
  95. , pDx
  96. , 0.*deg);
  97. ddlp = DDLogicalPart(solname, usemat, dsol);
  98. }
  99. DCOUT_V ('P', "DDDividedTrdX::makeDDLogicalPart lp = " << ddlp);
  100. return ddlp;
  101. }
  102. void
  103. DDDividedTrdX::checkParametersValidity( void )
  104. {
  105. DDDividedGeometryObject::checkParametersValidity();
  106. DDTrap mtrd = (DDTrap)(div_.parent().solid());
  107. double mpDx1 = mtrd.x1(); //->GetXHalfLength1();
  108. double mpDx2 = mtrd.x2(); //->GetXHalfLength2();
  109. double mpDx3 = mtrd.x3();
  110. double mpDx4 = mtrd.x4();
  111. double mpTheta = mtrd.theta();
  112. double mpPhi = mtrd.phi();
  113. double mpAlpha1 = mtrd.alpha1();
  114. double mpAlpha2 = mtrd.alpha2();
  115. // double mpDy1 = mtrd.y1();
  116. // double mpDy2 = mtrd.y2();
  117. // double x1Tol = mpDx1 - mpDx2;
  118. // if (x1Tol < 0.0) x1Tol = x1Tol * -1.0;
  119. if ( fabs(mpDx1 - mpDx2) > tolerance() || fabs(mpDx3 - mpDx4) > tolerance()
  120. || fabs(mpDx1 - mpDx4) > tolerance())
  121. {
  122. std::string s = "ERROR - DDDividedTrdX::checkParametersValidity()";
  123. s+= "\n Making a division of a TRD along axis X,";
  124. s+= "\n while the X half lengths are not equal,";
  125. s+= "\n is not (yet) supported. It will result";
  126. s+= "\n in non-equal division solids.";
  127. throw cms::Exception("DDException") << s;
  128. }
  129. // if (fabs(mpDy1 - mpDy2) > tolerance())
  130. // {
  131. // std::string s = "ERROR - DDDividedTrdX::checkParametersValidity()";
  132. // s+= "\n Making a division of a TRD along axis X,";
  133. // s+= "\n while the Y half lengths are not equal,";
  134. // s+= "\n is not (yet) supported. It will result";
  135. // s+= "\n in non-equal division solids.";
  136. // throw cms::Exception("DDException") << s;
  137. // }
  138. // mec: we only have traps, not trds in DDD, so I added this check
  139. // to make sure it is only a trd (I think! :-))
  140. if (mpAlpha1 != 0.*deg || mpAlpha2 != 0.*deg || mpTheta != 0.*deg || mpPhi != 0.*deg)
  141. {
  142. std::string s = "ERROR - DDDividedTrdX::checkParametersValidity()";
  143. s+= "\n Making a division of a TRD along axis X,";
  144. s+= "\n while the theta, phi and aplhpa2 are not zero,";
  145. s+= "\n is not (yet) supported. It will result";
  146. s+= "\n in non-equal division solids.";
  147. throw cms::Exception("DDException") << s;
  148. }
  149. }
  150. DDDividedTrdY::DDDividedTrdY( const DDDivision& div, DDCompactView* cpv )
  151. : DDDividedGeometryObject( div, cpv )
  152. {
  153. checkParametersValidity();
  154. setType( "DivisionTrdY" );
  155. DDTrap mtrd = (DDTrap)(div_.parent().solid());
  156. if( divisionType_ == DivWIDTH )
  157. {
  158. compNDiv_ = calculateNDiv( 2 * mtrd.y1(), div_.width(), div_.offset() );
  159. }
  160. else if( divisionType_ == DivNDIV )
  161. {
  162. compWidth_ = calculateWidth( 2 * mtrd.y1(), div_.nReplicas(), div_.offset() );
  163. }
  164. DCOUT_V ('P', " DDDividedTrdY no divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << "\n width " << compWidth_ << " = " << div_.width() << std::endl);
  165. }
  166. DDDividedTrdY::~DDDividedTrdY( void )
  167. {}
  168. double
  169. DDDividedTrdY::getMaxParameter( void ) const
  170. {
  171. DDTrap mtrd = (DDTrap)(div_.parent().solid());
  172. return 2 * mtrd.y1();
  173. }
  174. DDTranslation
  175. DDDividedTrdY::makeDDTranslation( const int copyNo ) const
  176. {
  177. DDTrap mtrd = (DDTrap)(div_.parent().solid() );
  178. double mdy = mtrd.y1();
  179. //----- translation
  180. double posi = -mdy + div_.offset() + (copyNo+0.5)*compWidth_;
  181. DCOUT_V ('P', " DDDividedTrdY: " << copyNo << "\n Position: y=" << posi << " Axis= " << DDAxesNames::name(div_.axis()) << "\n");
  182. if( div_.axis() == y )
  183. {
  184. return DDTranslation(0.0, posi, 0.0);
  185. }
  186. else
  187. {
  188. std::string s = "ERROR - DDDividedTrdY::makeDDTranslation()";
  189. s += "\n Axis is along ";
  190. s += DDAxesNames::name(div_.axis());
  191. s += " !\n" ;
  192. s += "DDDividedTrdY::makeDDTranslation()";
  193. s += " IllegalConstruct: Only axes along y are allowed !";
  194. throw cms::Exception("DDException") << s;
  195. }
  196. return DDTranslation();
  197. }
  198. DDRotation
  199. DDDividedTrdY::makeDDRotation( const int copyNo ) const
  200. {
  201. return DDRotation();
  202. }
  203. DDLogicalPart
  204. DDDividedTrdY::makeDDLogicalPart( const int copyNo ) const
  205. {
  206. //---- The division along Y of a Trd will result a Trd, only
  207. //--- if Y at -Z and +Z are equal, else use the G4Trap version
  208. DDTrap mtrd = (DDTrap)(div_.parent().solid());
  209. DDMaterial usemat = div_.parent().material();
  210. double pDx1 = mtrd.x1(); //->GetXHalfLength1() at Y+;
  211. double pDx2 = mtrd.x2(); //->GetXHalfLength2() at Y+;
  212. double pDx3 = mtrd.x3(); //->GetXHalfLength1() at Y-;
  213. double pDx4 = mtrd.x4(); //->GetXHalfLength2() at Y-;
  214. double pDz = mtrd.halfZ(); //->GetZHalfLength();
  215. double pDy = compWidth_/2.;
  216. //trd.SetAllParameters ( pDx1, pDx2, pDy, pDy, pDz );
  217. DDName solname(div_.name() );
  218. DDSolid dsol(solname);
  219. DDLogicalPart ddlp(solname);
  220. if (!dsol.isDefined().second)
  221. {
  222. dsol = DDSolidFactory::trap(solname
  223. , pDz
  224. , 0.*deg
  225. , 0.*deg
  226. , pDy
  227. , pDx1
  228. , pDx2
  229. , 0*deg
  230. , pDy
  231. , pDx3
  232. , pDx4
  233. , 0.*deg);
  234. DDLogicalPart ddlp(solname, usemat, dsol);
  235. }
  236. DCOUT_V ('P', "DDDividedTrdY::makeDDLogicalPart lp = " << ddlp);
  237. return ddlp;
  238. }
  239. void
  240. DDDividedTrdY::checkParametersValidity( void )
  241. {
  242. DDDividedGeometryObject::checkParametersValidity();
  243. DDTrap mtrd = (DDTrap)(div_.parent().solid());
  244. double mpDy1 = mtrd.y1(); //->GetYHalfLength1();
  245. double mpDy2 = mtrd.y2(); //->GetYHalfLength2();
  246. double mpTheta = mtrd.theta();
  247. double mpPhi = mtrd.phi();
  248. double mpAlpha1 = mtrd.alpha1();
  249. double mpAlpha2 = mtrd.alpha2();
  250. if( fabs(mpDy1 - mpDy2) > tolerance() )
  251. {
  252. std::string s= "ERROR - DDDividedTrdY::checkParametersValidity()";
  253. s += "\n Making a division of a TRD along axis Y while";
  254. s += "\n the Y half lengths are not equal is not (yet)";
  255. s += "\n supported. It will result in non-equal";
  256. s += "\n division solids.";
  257. throw cms::Exception("DDException") << s;
  258. }
  259. // mec: we only have traps, not trds in DDD, so I added this check
  260. // to make sure it is only a trd (I think! :-))
  261. if (mpAlpha1 != 0.*deg || mpAlpha2 != 0.*deg || mpTheta != 0.*deg || mpPhi != 0.*deg)
  262. {
  263. std::string s = "ERROR - DDDividedTrdY::checkParametersValidity()";
  264. s+= "\n Making a division of a TRD along axis X,";
  265. s+= "\n while the theta, phi and aplhpa2 are not zero,";
  266. s+= "\n is not (yet) supported. It will result";
  267. s+= "\n in non-equal division solids.";
  268. throw cms::Exception("DDException") << s;
  269. }
  270. }
  271. DDDividedTrdZ::DDDividedTrdZ( const DDDivision& div, DDCompactView* cpv )
  272. : DDDividedGeometryObject( div, cpv )
  273. {
  274. checkParametersValidity();
  275. setType( "DivTrdZ" );
  276. DDTrap mtrd = (DDTrap)(div_.parent().solid());
  277. if ( divisionType_ == DivWIDTH )
  278. {
  279. compNDiv_ = calculateNDiv( 2*mtrd.halfZ(), div_.width(), div_.offset() );
  280. }
  281. else if( divisionType_ == DivNDIV )
  282. {
  283. compWidth_ = calculateWidth( 2*mtrd.halfZ(), div_.nReplicas(), div_.offset() );
  284. }
  285. DCOUT_V ('P', " DDDividedTrdY no divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << "\n width " << compWidth_ << " = " << div_.width() << std::endl);
  286. }
  287. DDDividedTrdZ::~DDDividedTrdZ( void )
  288. {}
  289. double
  290. DDDividedTrdZ::getMaxParameter( void ) const
  291. {
  292. DDTrap mtrd = (DDTrap)(div_.parent().solid());
  293. return 2 * mtrd.halfZ();
  294. }
  295. DDTranslation
  296. DDDividedTrdZ::makeDDTranslation( const int copyNo ) const
  297. {
  298. DDTrap mtrd = (DDTrap)(div_.parent().solid() );
  299. double mdz = mtrd.halfZ();
  300. //----- translation
  301. double posi = -mdz + div_.offset() + (copyNo+0.5)*compWidth_;
  302. DCOUT_V ('P', " DDDividedTrdZ: " << copyNo << "\n Position: z=" << posi << " Axis= " << DDAxesNames::name(div_.axis()) << "\n");
  303. if( div_.axis() == z )
  304. {
  305. return DDTranslation(0.0, 0.0, posi);
  306. }
  307. else
  308. {
  309. std::string s = "ERROR - DDDividedTrdZ::makeDDTranslation()";
  310. s += "\n Axis is along ";
  311. s += DDAxesNames::name(div_.axis());
  312. s += " !\n" ;
  313. s += "DDDividedTrdY::makeDDTranslation()";
  314. s += " IllegalConstruct: Only axes along z are allowed !";
  315. throw cms::Exception("DDException") << s;
  316. }
  317. return DDTranslation();
  318. }
  319. DDRotation
  320. DDDividedTrdZ::makeDDRotation( const int copyNo ) const
  321. {
  322. return DDRotation();
  323. }
  324. DDLogicalPart
  325. DDDividedTrdZ::makeDDLogicalPart ( const int copyNo ) const
  326. {
  327. //---- The division along Z of a Trd will result a Trd
  328. DDTrap mtrd = (DDTrap)(div_.parent().solid());
  329. DDMaterial usemat = div_.parent().material();
  330. double pDx1 = mtrd.x1(); //->GetXHalfLength1();
  331. //(mtrd->GetXHalfLength2() - mtrd->GetXHalfLength1() );
  332. double DDx = (mtrd.x2() - mtrd.x1() );
  333. double pDy1 = mtrd.y1(); // ->GetYHalfLength1();
  334. //(mtrd->GetYHalfLength2() - mtrd->GetYHalfLength1() );
  335. double DDy = (mtrd.y2() - mtrd.y1() );
  336. double pDz = compWidth_/2.;
  337. double zLength = 2*mtrd.halfZ(); //->GetZHalfLength();
  338. // trd.SetAllParameters ( pDx1+DDx*(div_.offset()+copyNo*compWidth_)/zLength,
  339. // pDx1+DDx*(div_.offset()+(copyNo+1)*compWidth_)/zLength,
  340. // pDy1+DDy*(div_.offset()+copyNo*compWidth_)/zLength,
  341. // pDy1+DDy*(div_.offset()+(copyNo+1)*compWidth_)/zLength, pDz );
  342. DDName solname(div_.parent().ddname().name() + "_DIVCHILD"
  343. + DDXMLElement::itostr(copyNo)
  344. , div_.parent().ddname().ns());
  345. DDSolid dsol =
  346. DDSolidFactory::trap(solname
  347. , pDz
  348. , 0.*deg
  349. , 0.*deg
  350. , pDy1+DDy*(div_.offset()+copyNo*compWidth_)/zLength
  351. , pDx1+DDx*(div_.offset()+copyNo*compWidth_)/zLength
  352. , pDx1+DDx*(div_.offset()+copyNo*compWidth_)/zLength
  353. , 0.*deg
  354. , pDy1+DDy*(div_.offset()+(copyNo+1)*compWidth_)/zLength
  355. , pDx1+DDx*(div_.offset()+(copyNo+1)*compWidth_)/zLength
  356. , pDx1+DDx*(div_.offset()+(copyNo+1)*compWidth_)/zLength
  357. , 0*deg
  358. );
  359. DDLogicalPart ddlp(solname, usemat, dsol);
  360. DCOUT_V ('P', "DDDividedTrdZ::makeDDLogicalPart lp = " << ddlp);
  361. return ddlp;
  362. }
  363. void
  364. DDDividedTrdZ::checkParametersValidity( void )
  365. {
  366. DDDividedGeometryObject::checkParametersValidity();
  367. DDTrap mtrd = (DDTrap)(div_.parent().solid());
  368. double mpTheta = mtrd.theta();
  369. double mpPhi = mtrd.phi();
  370. double mpAlpha1 = mtrd.alpha1();
  371. double mpAlpha2 = mtrd.alpha2();
  372. // mec: we only have traps, not trds in DDD, so I added this check
  373. // to make sure it is only a trd (I think! :-))
  374. if (mpAlpha1 != 0.*deg || mpAlpha2 != 0.*deg || mpTheta != 0.*deg || mpPhi != 0.*deg)
  375. {
  376. std::string s = "ERROR - DDDividedTrdZ::checkParametersValidity()";
  377. s+= "\n Making a division of a TRD along axis X,";
  378. s+= "\n while the theta, phi and aplhpa2 are not zero,";
  379. s+= "\n is not (yet) supported. It will result";
  380. s+= "\n in non-equal division solids.";
  381. throw cms::Exception("DDException") << s;
  382. }
  383. }