/Alignment/CocoaModel/src/OptOMirror.cc

https://github.com/abbasafsar/cmssw · C++ · 210 lines · 142 code · 26 blank · 42 comment · 24 complexity · 662ca7b4e39f9e1d8ac728812a10cade MD5 · raw file

  1. // COCOA class implementation file
  2. //Id: OptOMirror.cc
  3. //CAT: Model
  4. //
  5. // History: v1.0
  6. // Pedro Arce
  7. #include "Alignment/CocoaModel/interface/OptOMirror.h"
  8. #include "Alignment/CocoaModel/interface/LightRay.h"
  9. #include "Alignment/CocoaModel/interface/ALIPlane.h"
  10. #include "Alignment/CocoaModel/interface/Measurement.h"
  11. #include <iostream>
  12. #include <iomanip>
  13. #ifdef COCOA_VIS
  14. #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
  15. #include "Alignment/CocoaVisMgr/interface/ALIColour.h"
  16. #endif
  17. #include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h"
  18. #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
  19. using namespace CLHEP;
  20. //---------- Default behaviour: create a LightRay object
  21. void OptOMirror::defaultBehaviour(LightRay& lightray, Measurement& meas) { detailedDeviatesLightRay(lightray); }
  22. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  23. //@@ Detailed simulation of Reflection in Mirror
  24. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  25. void OptOMirror::detailedDeviatesLightRay(LightRay& lightray) {
  26. if (ALIUtils::debug >= 2)
  27. std::cout << "LR: DETAILED REFLECTION IN MIRROR " << name() << std::endl;
  28. if (ALIUtils::debug >= 3)
  29. ALIUtils::dump3v(centreGlob(), " centre Global ");
  30. //---------- Get forward plate and intersect lightray with it
  31. ALIPlane plate = getPlate(true, false);
  32. lightray.intersect(plate);
  33. CLHEP::Hep3Vector inters = lightray.point();
  34. //---------- Get centre of forward plate
  35. //----- Get Z axis
  36. CLHEP::Hep3Vector ZAxis = getZAxis();
  37. CLHEP::HepRotation rmt = rmGlob();
  38. ZAxis = rmt * ZAxis;
  39. //----- Get centre
  40. ALIdouble width = findExtraEntryValue("width");
  41. CLHEP::Hep3Vector plate_centre = centreGlob() - 0.5 * width * ZAxis;
  42. //- if(ALIUtils::debug >= 4) std::cout << " mirror width " << width << std::endl;
  43. //---------- Get the distance between the intersection point and the centre of the forward plate
  44. ALIdouble distance = (plate_centre - inters).mag();
  45. //---------- Get normal to mirror at intersection point
  46. //------- Get angle of mirror surface (angle between plate centre and intersection)
  47. ALIdouble flatness = findExtraEntryValue("flatness");
  48. //-- flatness is defined as number of 632 nm wavelengths
  49. flatness *= 632.E-9;
  50. ALIdouble length = 0.;
  51. ALIdouble curvature_radius;
  52. ALIdouble angFlatness;
  53. if (flatness != 0) {
  54. length = findExtraEntryValueMustExist("length");
  55. curvature_radius = (flatness * flatness + length * length) / (2 * flatness);
  56. angFlatness = asin(distance / curvature_radius);
  57. } else {
  58. curvature_radius = ALI_DBL_MAX;
  59. angFlatness = 0;
  60. }
  61. if (ALIUtils::debug >= 3) {
  62. std::cout << " intersection with plate " << inters << std::endl;
  63. std::cout << " plate_centre " << plate_centre << std::endl;
  64. std::cout << " distance plate_centre - intersection " << distance << std::endl;
  65. std::cout << " flatness " << flatness << ", length " << length;
  66. std::cout << ", curvature radius " << curvature_radius << " angle of flatness " << angFlatness << std::endl;
  67. }
  68. //----- Axis of rotation is perpendicular to Z Axis and to line plate_centre - intersection
  69. CLHEP::Hep3Vector ipcV = inters - plate_centre;
  70. if (ipcV.mag() != 0)
  71. ipcV *= 1. / ipcV.mag();
  72. CLHEP::HepRotation rtm = rmGlob();
  73. ipcV = rtm * ipcV;
  74. CLHEP::Hep3Vector rotationAxis = ipcV.cross(ZAxis);
  75. //----- normal is object normal rotated around this axis
  76. CLHEP::Hep3Vector inters_normal = CLHEP::Hep3Vector(0., 0., 1.);
  77. inters_normal.rotate(angFlatness, rotationAxis);
  78. inters_normal = rmt * inters_normal;
  79. if (ALIUtils::debug >= 2) {
  80. ALIUtils::dump3v(ipcV, " intersection - plate_centre std::vector ");
  81. std::cout << "rotation Axis " << rotationAxis << std::endl;
  82. std::cout << " plate normal at intersection point " << inters_normal << std::endl;
  83. }
  84. //---------- Reflect in plate
  85. ALIdouble cosang = -(inters_normal * lightray.direction()) / inters_normal.mag() / lightray.direction().mag();
  86. CLHEP::Hep3Vector lrold = lightray.direction();
  87. lightray.setDirection(lightray.direction() + inters_normal * 2 * cosang);
  88. if (ALIUtils::debug >= 2) {
  89. lightray.dumpData("Reflected in mirror");
  90. }
  91. }
  92. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  93. //@@ Fast simulation of Reflection in Mirror
  94. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  95. void OptOMirror::fastDeviatesLightRay(LightRay& lightray) {
  96. if (ALIUtils::debug >= 2)
  97. std::cout << "LR: FAST REFLECTION IN MIRROR " << name() << std::endl;
  98. //---------- Get forward plate
  99. ALIPlane plate = getPlate(true, false);
  100. //---------- Reflect in plate (including intersection with it)
  101. lightray.reflect(plate);
  102. if (ALIUtils::debug >= 2) {
  103. lightray.dumpData("Reflected in plate");
  104. }
  105. //---------- Deviate Lightray
  106. // ALIdouble deviX = findExtraEntryValue("deviX");
  107. // ALIdouble deviY = findExtraEntryValue("deviY");
  108. // lightray.shiftAndDeviateWhileTraversing( this, 0., 0., 0., deviX, deviY, 0.);
  109. lightray.shiftAndDeviateWhileTraversing(this, 'R');
  110. if (ALIUtils::debug >= 2) {
  111. lightray.dumpData("Deviated ");
  112. }
  113. }
  114. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  115. void OptOMirror::detailedTraversesLightRay(LightRay& lightray) {
  116. if (ALIUtils::debug >= 2)
  117. std::cout << "LR: DETAILED TRAVERSE IN MIRROR " << name() << std::endl;
  118. //---------- Get forward plate
  119. ALIPlane plate = getPlate(true, true);
  120. //---------- If width is 0, just keep the same point
  121. ALIdouble width = findExtraEntryValue("width");
  122. if (width == 0) {
  123. if (ALIUtils::debug >= 3)
  124. lightray.dumpData("Traversed with 0 width");
  125. return;
  126. }
  127. //---------- Refract while entering mirror
  128. ALIdouble refra_ind1 = 1.;
  129. ALIdouble refra_ind2 = findExtraEntryValue("refra_ind");
  130. lightray.refract(plate, refra_ind1, refra_ind2);
  131. if (ALIUtils::debug >= 2) {
  132. lightray.dumpData("Refracted in first plate");
  133. }
  134. //---------- Get backward plate
  135. plate = getPlate(false, true);
  136. //---------- Refract while exiting mirror
  137. lightray.refract(plate, refra_ind2, refra_ind1);
  138. if (ALIUtils::debug >= 2) {
  139. lightray.dumpData("Refracted in first plate");
  140. }
  141. }
  142. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  143. void OptOMirror::fastTraversesLightRay(LightRay& lightray) {
  144. if (ALIUtils::debug >= 2)
  145. std::cout << "LR: TRAVERSE MIRROR " << name() << std::endl;
  146. //---------- Get backward plate
  147. ALIPlane plate = getPlate(false, false);
  148. lightray.intersect(plate);
  149. if (ALIUtils::debug >= 2) {
  150. lightray.dumpData("Intersected with plate");
  151. }
  152. //---------- Shift and Deviate
  153. lightray.shiftAndDeviateWhileTraversing(this, 'T');
  154. if (ALIUtils::debug >= 2) {
  155. lightray.dumpData("Shifted and Deviated");
  156. }
  157. }
  158. #ifdef COCOA_VIS
  159. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  160. void OptOMirror::fillIguana() {
  161. ALIdouble width;
  162. ALIbool wexists = findExtraEntryValueIfExists("width", width);
  163. if (!wexists)
  164. width = 1.;
  165. ALIdouble length;
  166. wexists = findExtraEntryValueIfExists("length", length);
  167. if (!wexists)
  168. length = 4.;
  169. ALIColour* col = new ALIColour(0., 0., 1., 0.);
  170. std::vector<ALIdouble> spar;
  171. spar.push_back(length);
  172. spar.push_back(length);
  173. spar.push_back(width);
  174. IgCocoaFileMgr::getInstance().addSolid(*this, "BOX", spar, col);
  175. }
  176. #endif
  177. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  178. void OptOMirror::constructSolidShape() {
  179. ALIdouble go;
  180. GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
  181. gomgr->getGlobalOptionValue("VisScale", go);
  182. theSolidShape = new CocoaSolidShapeBox(
  183. "Box", go * 5. * cm / m, go * 5. * cm / m, go * 1. * cm / m); //COCOA internal units are meters
  184. }