File indexing completed on 2024-04-06 11:56:04
0001
0002
0003
0004
0005
0006
0007
0008 #include "Alignment/CocoaModel/interface/OptOOpticalSquare.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
0025
0026
0027
0028 void OptOOpticalSquare::detailedDeviatesLightRay(LightRay& lightray) {
0029 if (ALIUtils::debug >= 2)
0030 std::cout << "LR: DETAILED DEVIATION IN OPTICAL SQUARE " << name() << std::endl;
0031
0032 calculateFaces(true);
0033
0034
0035
0036 const ALIdouble refra_ind = findExtraEntryValueMustExist("refra_ind");
0037 const ALIdouble refra_ind0 = 1.;
0038
0039 ALIint ii;
0040 for (ii = 0; ii < 4; ii++) {
0041 if (ii == 0) {
0042 if (ALIUtils::debug >= 3)
0043 std::cout << "## OPTOOPTICALSQUARE: refract in face " << ii << std::endl;
0044 lightray.refract(ALIPlane(faceP[ii], faceV[ii]), refra_ind0, refra_ind);
0045 } else if (ii == 3) {
0046
0047 lightray.refract(ALIPlane(faceP[ii], faceV[ii]), refra_ind, refra_ind0);
0048 } else {
0049 lightray.reflect(ALIPlane(faceP[ii], faceV[ii]));
0050 }
0051 if (ALIUtils::debug >= 3) {
0052 lightray.dumpData("After face ");
0053 }
0054 }
0055
0056
0057
0058 }
0059
0060
0061
0062
0063
0064 void OptOOpticalSquare::detailedTraversesLightRay(LightRay& lightray) {
0065 if (ALIUtils::debug >= 2)
0066 std::cout << "LR: DETAILED TRAVERSES OPTICAL SQUARE " << name() << std::endl;
0067
0068 calculateFaces(true);
0069 const ALIdouble refra_ind = findExtraEntryValueMustExist("refra_ind");
0070 const ALIdouble refra_ind0 = 1.;
0071
0072 lightray.refract(ALIPlane(faceP[0], faceV[0]), refra_ind0, refra_ind);
0073 lightray.refract(ALIPlane(faceP[4], faceV[4]), refra_ind, refra_ind0);
0074 }
0075
0076
0077
0078
0079
0080
0081 void OptOOpticalSquare::fastDeviatesLightRay(LightRay& lightray) {
0082 if (ALIUtils::debug >= 2)
0083 std::cout << "LR: FAST DEVIATION IN OPTICAL SQUARE " << name() << std::endl;
0084
0085 calculateFaces(false);
0086
0087
0088 lightray.reflect(ALIPlane(faceP[1], faceV[1]));
0089 if (ALIUtils::debug >= 3) {
0090 lightray.dumpData("After face 1");
0091 }
0092 lightray.reflect(ALIPlane(faceP[2], faceV[2]));
0093 if (ALIUtils::debug >= 3) {
0094 lightray.dumpData("After face 2");
0095 }
0096 lightray.intersect(ALIPlane(faceP[3], faceV[3]));
0097 if (ALIUtils::debug >= 3) {
0098 lightray.dumpData("intersected at face 3");
0099 }
0100
0101
0102 lightray.shiftAndDeviateWhileTraversing(this, 'R');
0103
0104
0105
0106
0107
0108
0109
0110 if (ALIUtils::debug >= 2) {
0111
0112
0113 lightray.dumpData("Deviated ");
0114 }
0115 }
0116
0117
0118
0119
0120
0121
0122
0123 void OptOOpticalSquare::fastTraversesLightRay(LightRay& lightray) {
0124
0125
0126 calculateFaces(false);
0127
0128 lightray.intersect(ALIPlane(faceP[1], faceV[1]));
0129
0130 lightray.shiftAndDeviateWhileTraversing(this, 'T');
0131
0132
0133
0134
0135
0136
0137 if (ALIUtils::debug >= 2) {
0138 lightray.dumpData("Shifted and Deviated");
0139 }
0140 }
0141
0142
0143
0144
0145
0146 void OptOOpticalSquare::calculateFaces(ALIbool isDetailed) {
0147 ALIint numberOfFaces = 5;
0148
0149
0150 CLHEP::Hep3Vector opto_centre = centreGlob();
0151 if (ALIUtils::debug >= 3)
0152 std::cout << "opto_centre " << opto_centre << std::endl;
0153 const ALIdouble hlen1 = findExtraEntryValueMustExist("length1") / 2.;
0154 const ALIdouble hlen2 = findExtraEntryValueMustExist("length2") / 2.;
0155 ALIdouble ang = 67.5 * acos(0.) / 90.;
0156
0157
0158 faceP[0] = CLHEP::Hep3Vector(0, 0, -hlen1);
0159 faceV[0] = CLHEP::Hep3Vector(0, 0, -1);
0160 faceP[1] = CLHEP::Hep3Vector(0, hlen1 - hlen2 * sin(ang), hlen1 + hlen2 * cos(ang));
0161 faceV[1] = CLHEP::Hep3Vector(0, cos(ang), sin(ang));
0162
0163 faceP[2] = CLHEP::Hep3Vector(0, -hlen1 - hlen2 * cos(ang), -hlen1 + hlen2 * sin(ang));
0164 faceV[2] = CLHEP::Hep3Vector(0, -sin(ang), -cos(ang));
0165 faceP[3] = CLHEP::Hep3Vector(0, hlen1, 0);
0166 faceV[3] = CLHEP::Hep3Vector(0, 1, 0);
0167
0168
0169 faceP[4] = CLHEP::Hep3Vector(0, 0, hlen1 + 2 * hlen2 * cos(ang));
0170 faceV[4] = CLHEP::Hep3Vector(0, 0, 1);
0171
0172
0173 CLHEP::HepRotation rmt = rmGlob();
0174 ALIint ii;
0175 if (ALIUtils::debug >= 3) {
0176 std::cout << " optical_square centre" << opto_centre << std::endl;
0177 }
0178 for (ii = 0; ii < numberOfFaces; ii++) {
0179 faceP[ii] = rmt * faceP[ii];
0180 faceP[ii] += opto_centre;
0181 faceV[ii] = rmt * faceV[ii];
0182 if (ALIUtils::debug >= 3) {
0183 std::cout << "point at face " << ii << ": " << faceP[ii] << std::endl;
0184 std::cout << "normal at face " << ii << ": " << faceV[ii] << std::endl;
0185 }
0186 }
0187
0188
0189 if (isDetailed) {
0190 ALIdouble wedge, wedgeX, wedgeY;
0191 const ALIbool wxy = findExtraEntryValueIfExists("wedge", wedge);
0192 if (!wxy) {
0193 wedgeX = findExtraEntryValue("wedgeX");
0194 wedgeY = findExtraEntryValue("wedgeY");
0195 } else {
0196 wedgeX = wedge;
0197 wedgeY = wedge;
0198 }
0199
0200
0201 if (ALIUtils::debug >= 4)
0202 std::cout << "OptOOpticalSquare calculateFaces: wedgeX " << wedgeX << " wedgeY " << wedgeY << std::endl;
0203 CLHEP::Hep3Vector Axis1(1., 0., 0.);
0204 Axis1 = rmt * Axis1;
0205 if (ALIUtils::debug >= 4) {
0206 ALIUtils::dump3v(faceV[1], "faceV[1] before wedge");
0207 ALIUtils::dump3v(faceV[2], "faceV[2] before wedge");
0208 }
0209 faceV[1].rotate(0.5 * wedgeX, Axis1);
0210 if (ALIUtils::debug >= 4)
0211 ALIUtils::dump3v(Axis1, " Axis1 in faceV[1] ");
0212 faceV[2].rotate(-0.5 * wedgeX, Axis1);
0213 if (ALIUtils::debug >= 4) {
0214 ALIUtils::dump3v(Axis1, " Axis1 in faceV[2] ");
0215 ALIUtils::dump3v(faceV[1], "faceV[1] after wedge X");
0216 ALIUtils::dump3v(faceV[2], "faceV[2] after wedge X");
0217 }
0218
0219
0220 CLHEP::Hep3Vector Axis2 = Axis1;
0221 Axis2 = Axis2.cross(faceV[1]);
0222 faceV[1].rotate(0.5 * wedgeY, Axis2);
0223 if (ALIUtils::debug >= 4)
0224 ALIUtils::dump3v(Axis2, " Axis2 in faceV[1] ");
0225 Axis2 = Axis1;
0226 Axis2 = Axis2.cross(faceV[2]);
0227 faceV[2].rotate(-0.5 * wedgeY, Axis2);
0228 if (ALIUtils::debug >= 4) {
0229 ALIUtils::dump3v(Axis2, " Axis2 in faceV[2] ");
0230 ALIUtils::dump3v(faceV[1], "faceV[1] after wedge Y");
0231 ALIUtils::dump3v(faceV[2], "faceV[2] after wedge Y");
0232 }
0233 }
0234 }
0235
0236 #ifdef COCOA_VIS
0237
0238 void OptOOpticalSquare::fillIguana() {
0239 ALIColour* col = new ALIColour(0., 0., 1., 0.);
0240 ALIdouble length1;
0241 ALIbool wexists = findExtraEntryValueIfExists("length1", length1);
0242 if (!wexists)
0243 length1 = 4.;
0244 ALIdouble length2;
0245 wexists = findExtraEntryValueIfExists("length2", length2);
0246 if (!wexists)
0247 length2 = 4.;
0248
0249 std::vector<ALIdouble> spar;
0250 spar.push_back(length1);
0251 spar.push_back(length2);
0252 IgCocoaFileMgr::getInstance().addSolid(*this, "OPTSQR", spar, col);
0253 }
0254 #endif
0255
0256
0257 void OptOOpticalSquare::constructSolidShape() {
0258 ALIdouble go;
0259 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0260 gomgr->getGlobalOptionValue("VisScale", go);
0261
0262 theSolidShape = new CocoaSolidShapeBox(
0263 "Box", go * 5. * cm / m, go * 5. * cm / m, go * 5. * cm / m);
0264 }