CMS 3D CMS Logo

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