File indexing completed on 2024-04-06 11:56:03
0001
0002
0003
0004
0005
0006
0007
0008 #include "Alignment/CocoaModel/interface/OptOMirror.h"
0009 #include "Alignment/CocoaModel/interface/LightRay.h"
0010 #include "Alignment/CocoaModel/interface/ALIPlane.h"
0011 #include "Alignment/CocoaModel/interface/Measurement.h"
0012 #include <iostream>
0013 #include <iomanip>
0014 #ifdef COCOA_VIS
0015 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
0016 #include "Alignment/CocoaVisMgr/interface/ALIColour.h"
0017 #endif
0018 #include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h"
0019 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
0020
0021 using namespace CLHEP;
0022
0023
0024 void OptOMirror::defaultBehaviour(LightRay& lightray, Measurement& meas) { detailedDeviatesLightRay(lightray); }
0025
0026
0027
0028
0029 void OptOMirror::detailedDeviatesLightRay(LightRay& lightray) {
0030 if (ALIUtils::debug >= 2)
0031 std::cout << "LR: DETAILED REFLECTION IN MIRROR " << name() << std::endl;
0032 if (ALIUtils::debug >= 3)
0033 ALIUtils::dump3v(centreGlob(), " centre Global ");
0034
0035
0036 ALIPlane plate = getPlate(true, false);
0037 lightray.intersect(plate);
0038 CLHEP::Hep3Vector inters = lightray.point();
0039
0040
0041
0042 CLHEP::Hep3Vector ZAxis = getZAxis();
0043 CLHEP::HepRotation rmt = rmGlob();
0044 ZAxis = rmt * ZAxis;
0045
0046 ALIdouble width = findExtraEntryValue("width");
0047 CLHEP::Hep3Vector plate_centre = centreGlob() - 0.5 * width * ZAxis;
0048
0049
0050
0051 ALIdouble distance = (plate_centre - inters).mag();
0052
0053
0054
0055 ALIdouble flatness = findExtraEntryValue("flatness");
0056
0057 flatness *= 632.E-9;
0058 ALIdouble length = 0.;
0059
0060 ALIdouble curvature_radius;
0061 ALIdouble angFlatness;
0062 if (flatness != 0) {
0063 length = findExtraEntryValueMustExist("length");
0064 curvature_radius = (flatness * flatness + length * length) / (2 * flatness);
0065 angFlatness = asin(distance / curvature_radius);
0066 } else {
0067 curvature_radius = ALI_DBL_MAX;
0068 angFlatness = 0;
0069 }
0070
0071 if (ALIUtils::debug >= 3) {
0072 std::cout << " intersection with plate " << inters << std::endl;
0073 std::cout << " plate_centre " << plate_centre << std::endl;
0074 std::cout << " distance plate_centre - intersection " << distance << std::endl;
0075 std::cout << " flatness " << flatness << ", length " << length;
0076 std::cout << ", curvature radius " << curvature_radius << " angle of flatness " << angFlatness << std::endl;
0077 }
0078
0079
0080 CLHEP::Hep3Vector ipcV = inters - plate_centre;
0081 if (ipcV.mag() != 0)
0082 ipcV *= 1. / ipcV.mag();
0083 CLHEP::HepRotation rtm = rmGlob();
0084 ipcV = rtm * ipcV;
0085 CLHEP::Hep3Vector rotationAxis = ipcV.cross(ZAxis);
0086
0087 CLHEP::Hep3Vector inters_normal = CLHEP::Hep3Vector(0., 0., 1.);
0088 inters_normal.rotate(angFlatness, rotationAxis);
0089 inters_normal = rmt * inters_normal;
0090
0091 if (ALIUtils::debug >= 2) {
0092 ALIUtils::dump3v(ipcV, " intersection - plate_centre std::vector ");
0093 std::cout << "rotation Axis " << rotationAxis << std::endl;
0094 std::cout << " plate normal at intersection point " << inters_normal << std::endl;
0095 }
0096
0097 ALIdouble cosang = -(inters_normal * lightray.direction()) / inters_normal.mag() / lightray.direction().mag();
0098 CLHEP::Hep3Vector lrold = lightray.direction();
0099 lightray.setDirection(lightray.direction() + inters_normal * 2 * cosang);
0100
0101 if (ALIUtils::debug >= 2) {
0102 lightray.dumpData("Reflected in mirror");
0103 }
0104 }
0105
0106
0107
0108
0109 void OptOMirror::fastDeviatesLightRay(LightRay& lightray) {
0110 if (ALIUtils::debug >= 2)
0111 std::cout << "LR: FAST REFLECTION IN MIRROR " << name() << std::endl;
0112
0113
0114 ALIPlane plate = getPlate(true, false);
0115
0116
0117 lightray.reflect(plate);
0118 if (ALIUtils::debug >= 2) {
0119 lightray.dumpData("Reflected in plate");
0120 }
0121
0122
0123
0124
0125 lightray.shiftAndDeviateWhileTraversing(this, 'R');
0126 if (ALIUtils::debug >= 2) {
0127 lightray.dumpData("Deviated ");
0128 }
0129 }
0130
0131
0132 void OptOMirror::detailedTraversesLightRay(LightRay& lightray) {
0133 if (ALIUtils::debug >= 2)
0134 std::cout << "LR: DETAILED TRAVERSE IN MIRROR " << name() << std::endl;
0135
0136
0137 ALIPlane plate = getPlate(true, true);
0138
0139 ALIdouble width = findExtraEntryValue("width");
0140 if (width == 0) {
0141 if (ALIUtils::debug >= 3)
0142 lightray.dumpData("Traversed with 0 width");
0143 return;
0144 }
0145
0146
0147 ALIdouble refra_ind1 = 1.;
0148 ALIdouble refra_ind2 = findExtraEntryValue("refra_ind");
0149 lightray.refract(plate, refra_ind1, refra_ind2);
0150 if (ALIUtils::debug >= 2) {
0151 lightray.dumpData("Refracted in first plate");
0152 }
0153
0154
0155 plate = getPlate(false, true);
0156
0157 lightray.refract(plate, refra_ind2, refra_ind1);
0158 if (ALIUtils::debug >= 2) {
0159 lightray.dumpData("Refracted in first plate");
0160 }
0161 }
0162
0163
0164 void OptOMirror::fastTraversesLightRay(LightRay& lightray) {
0165 if (ALIUtils::debug >= 2)
0166 std::cout << "LR: TRAVERSE MIRROR " << name() << std::endl;
0167
0168
0169 ALIPlane plate = getPlate(false, false);
0170 lightray.intersect(plate);
0171 if (ALIUtils::debug >= 2) {
0172 lightray.dumpData("Intersected with plate");
0173 }
0174
0175 lightray.shiftAndDeviateWhileTraversing(this, 'T');
0176 if (ALIUtils::debug >= 2) {
0177 lightray.dumpData("Shifted and Deviated");
0178 }
0179 }
0180
0181 #ifdef COCOA_VIS
0182
0183 void OptOMirror::fillIguana() {
0184 ALIdouble width;
0185 ALIbool wexists = findExtraEntryValueIfExists("width", width);
0186 if (!wexists)
0187 width = 1.;
0188 ALIdouble length;
0189 wexists = findExtraEntryValueIfExists("length", length);
0190 if (!wexists)
0191 length = 4.;
0192
0193 ALIColour* col = new ALIColour(0., 0., 1., 0.);
0194 std::vector<ALIdouble> spar;
0195 spar.push_back(length);
0196 spar.push_back(length);
0197 spar.push_back(width);
0198 IgCocoaFileMgr::getInstance().addSolid(*this, "BOX", spar, col);
0199 }
0200 #endif
0201
0202
0203 void OptOMirror::constructSolidShape() {
0204 ALIdouble go;
0205 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0206 gomgr->getGlobalOptionValue("VisScale", go);
0207
0208 theSolidShape = new CocoaSolidShapeBox(
0209 "Box", go * 5. * cm / m, go * 5. * cm / m, go * 1. * cm / m);
0210 }