00001
00002
00003
00004
00005
00006
00007
00008 #include "Alignment/CocoaModel/interface/OptOMirror.h"
00009 #include "Alignment/CocoaModel/interface/LightRay.h"
00010 #include "Alignment/CocoaModel/interface/ALIPlane.h"
00011 #include "Alignment/CocoaModel/interface/Measurement.h"
00012 #include <iostream>
00013 #include <iomanip>
00014 #ifdef COCOA_VIS
00015 #include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
00016 #include "Alignment/CocoaVisMgr/interface/ALIColour.h"
00017 #endif
00018 #include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h"
00019 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
00020
00021
00022 void OptOMirror::defaultBehaviour( LightRay& lightray, Measurement& meas )
00023 {
00024 detailedDeviatesLightRay( lightray );
00025 }
00026
00027
00028
00029
00030
00031 void OptOMirror::detailedDeviatesLightRay( LightRay& lightray )
00032 {
00033 if (ALIUtils::debug >= 2) std::cout << "LR: DETAILED REFLECTION IN MIRROR " << name() << std::endl;
00034 if (ALIUtils::debug >= 3) ALIUtils::dump3v( centreGlob(), " centre Global ");
00035
00036
00037 ALIPlane plate = getPlate(1, 0);
00038 lightray.intersect( plate );
00039 CLHEP::Hep3Vector inters = lightray.point( );
00040
00041
00042
00043 CLHEP::Hep3Vector ZAxis = getZAxis();
00044 CLHEP::HepRotation rmt = rmGlob();
00045 ZAxis = rmt * ZAxis;
00046
00047 ALIdouble width = findExtraEntryValue("width");
00048 CLHEP::Hep3Vector plate_centre = centreGlob() - 0.5 * width * ZAxis;
00049
00050
00051
00052 ALIdouble distance = ( plate_centre - inters ).mag();
00053
00054
00055
00056 ALIdouble flatness = findExtraEntryValue("flatness");
00057
00058 flatness *= 632.E-9;
00059 ALIdouble length = 0.;
00060
00061 ALIdouble curvature_radius;
00062 ALIdouble angFlatness;
00063 if( flatness != 0) {
00064 length = findExtraEntryValueMustExist("length");
00065 curvature_radius = (flatness*flatness + length*length) / (2*flatness);
00066 angFlatness = asin( distance / curvature_radius);
00067 } else {
00068 curvature_radius = ALI_DBL_MAX;
00069 angFlatness = 0;
00070 }
00071
00072 if (ALIUtils::debug >= 3) {
00073 std::cout << " intersection with plate " << inters << std::endl;
00074 std::cout << " plate_centre " << plate_centre << std::endl;
00075 std::cout << " distance plate_centre - intersection " << distance << std::endl;
00076 std::cout << " flatness " << flatness << ", length " << length;
00077 std::cout << ", curvature radius " << curvature_radius << " angle of flatness " << angFlatness << std::endl;
00078 }
00079
00080
00081 CLHEP::Hep3Vector ipcV = inters - plate_centre;
00082 if( ipcV.mag() != 0) ipcV *= 1./ipcV.mag();
00083 CLHEP::HepRotation rtm = rmGlob();
00084 ipcV = rtm*ipcV;
00085 CLHEP::Hep3Vector rotationAxis = ipcV.cross(ZAxis);
00086
00087 CLHEP::Hep3Vector inters_normal = CLHEP::Hep3Vector(0.,0.,1.);
00088 inters_normal.rotate( angFlatness, rotationAxis );
00089 inters_normal = rmt * inters_normal;
00090
00091 if (ALIUtils::debug >= 2) {
00092 ALIUtils::dump3v( ipcV, " intersection - plate_centre std::vector ");
00093 std::cout << "rotation Axis " << rotationAxis << std::endl;
00094 std::cout << " plate normal at intersection point " << inters_normal << std::endl;
00095 }
00096
00097 ALIdouble cosang = -( inters_normal * lightray.direction() ) /
00098 inters_normal.mag() / lightray.direction().mag();
00099 CLHEP::Hep3Vector lrold = lightray.direction();
00100 lightray.setDirection( lightray.direction() + inters_normal*2*cosang );
00101
00102 if (ALIUtils::debug >= 2) {
00103 lightray.dumpData("Reflected in mirror");
00104 }
00105
00106 }
00107
00108
00109
00110
00111
00112 void OptOMirror::fastDeviatesLightRay( LightRay& lightray )
00113 {
00114 if (ALIUtils::debug >= 2) std::cout << "LR: FAST REFLECTION IN MIRROR " << name() << std::endl;
00115
00116
00117 ALIPlane plate = getPlate(1, 0);
00118
00119
00120 lightray.reflect( plate );
00121 if (ALIUtils::debug >= 2) {
00122 lightray.dumpData("Reflected in plate");
00123 }
00124
00125
00126
00127
00128 lightray.shiftAndDeviateWhileTraversing( this, 'R' );
00129 if (ALIUtils::debug >= 2) {
00130 lightray.dumpData("Deviated ");
00131 }
00132
00133 }
00134
00135
00136 void OptOMirror::detailedTraversesLightRay( LightRay& lightray )
00137 {
00138 if (ALIUtils::debug >= 2) std::cout << "LR: DETAILED TRAVERSE IN MIRROR " << name() << std::endl;
00139
00140
00141 ALIPlane plate = getPlate(1, 1);
00142
00143 ALIdouble width = findExtraEntryValue("width");
00144 if( width == 0 ) {
00145 if(ALIUtils::debug >= 3) lightray.dumpData("Traversed with 0 width");
00146 return;
00147 }
00148
00149
00150 ALIdouble refra_ind1 = 1.;
00151 ALIdouble refra_ind2 = findExtraEntryValue("refra_ind");
00152 lightray.refract( plate, refra_ind1, refra_ind2 );
00153 if (ALIUtils::debug >= 2) {
00154 lightray.dumpData("Refracted in first plate");
00155 }
00156
00157
00158 plate = getPlate(0, 1);
00159
00160 lightray.refract( plate, refra_ind2, refra_ind1 );
00161 if (ALIUtils::debug >= 2) {
00162 lightray.dumpData("Refracted in first plate");
00163 }
00164
00165 }
00166
00167
00168
00169 void OptOMirror::fastTraversesLightRay( LightRay& lightray )
00170 {
00171 if (ALIUtils::debug >= 2) std::cout << "LR: TRAVERSE MIRROR " << name() << std::endl;
00172
00173
00174 ALIPlane plate = getPlate(0, 0);
00175 lightray.intersect( plate );
00176 if (ALIUtils::debug >= 2) {
00177 lightray.dumpData("Intersected with plate");
00178 }
00179
00180 ALIdouble shiftX = findExtraEntryValue("shiftTX");
00181 ALIdouble shiftY = findExtraEntryValue("shiftTY");
00182 ALIdouble shift;
00183 ALIbool bb = findExtraEntryValueIfExists("shiftT", shift);
00184 if( bb ) {
00185 shiftX = shift;
00186 shiftY = shift;
00187 }
00188
00189 ALIdouble deviTX = findExtraEntryValue("deviTX");
00190 ALIdouble deviTY = findExtraEntryValue("deviTY");
00191 ALIdouble deviT;
00192 bb = findExtraEntryValueIfExists("deviT", deviT);
00193 if( bb ) {
00194 deviTX = deviT;
00195 deviTY = deviT;
00196 }
00197
00198
00199 lightray.shiftAndDeviateWhileTraversing( this, 'T' );
00200 if (ALIUtils::debug >= 2) {
00201 lightray.dumpData("Shifted and Deviated");
00202 }
00203
00204 }
00205
00206
00207
00208 #ifdef COCOA_VIS
00209
00210 void OptOMirror::fillIguana()
00211 {
00212 ALIdouble width;
00213 ALIbool wexists = findExtraEntryValueIfExists("width",width);
00214 if( !wexists ) width = 1.;
00215 ALIdouble length;
00216 wexists = findExtraEntryValueIfExists("length",length);
00217 if( !wexists ) length = 4.;
00218
00219 ALIColour* col = new ALIColour( 0., 0., 1., 0. );
00220 std::vector<ALIdouble> spar;
00221 spar.push_back(length);
00222 spar.push_back(length);
00223 spar.push_back(width);
00224 IgCocoaFileMgr::getInstance().addSolid( *this, "BOX", spar, col);
00225 }
00226 #endif
00227
00228
00229
00230 void OptOMirror::constructSolidShape()
00231 {
00232 ALIdouble go;
00233 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00234 gomgr->getGlobalOptionValue("VisScale", go );
00235
00236 theSolidShape = new CocoaSolidShapeBox( "Box", go*5.*cm/m, go*5.*cm/m, go*1.*cm/m );
00237 }