00001
00002
00003
00004
00005
00006
00007
00008 #include "Alignment/CocoaModel/interface/ALILine.h"
00009 #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h"
00010 #include "Alignment/CocoaModel/interface/ALIPlane.h"
00011 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
00012
00013
00014
00015
00016
00017 ALILine::ALILine( const CLHEP::Hep3Vector& point, const CLHEP::Hep3Vector& direction )
00018 {
00019 _point = point;
00020 _direction = direction* (1/direction.mag());
00021 if (ALIUtils::debug >= 9) ALIUtils::dump3v( _point, " ALILine point _point = ");
00022 if (ALIUtils::debug >= 9) ALIUtils::dump3v( _direction, " ALILine direction _direction = ");
00023 }
00024
00025
00026
00027
00028 CLHEP::Hep3Vector ALILine::intersect( const ALILine& l2, bool notParallel )
00029 {
00030
00031 if(ALIUtils::debug >= 3 ){
00032 std::cout << "***** ALILine::intersect (constructor) two lines: " << std::endl
00033 << " line1: " << *this << std::endl
00034 << " line2: " << l2 << std::endl;
00035 }
00036 CLHEP::Hep3Vector inters;
00037
00038 double acosvec = vec().dot(l2.vec()) / vec().mag() / l2.vec().mag();
00039
00040 if(ALIUtils::debug >= 5 ){
00041
00042 std::cout << "\t Determination of acosvec = vec().dot(l2.vec()) / vec().mag() / l2.vec().mag() "
00043 << std::endl << std::endl;
00044
00045 std::cout << "\t l2.vec() = " << l2.vec() << std::endl;
00046
00047 std::cout << "\t vec().mag() = " << vec().mag() << std::endl;
00048 std::cout << "\t l2.vec().mag() = " << l2.vec().mag() << std::endl << std::endl;
00049
00050 }
00051
00052 if(ALIUtils::debug >= 5 ) std::cout << " acosvec = " << acosvec << std::endl;
00053 if( 1 - fabs(acosvec) < 1E-8 ) {
00054 if( notParallel ) {
00055 std::cerr << " !!!EXITING ALILine::intersect: two lines are parallel"
00056 << std::endl;
00057 exit(1);
00058 } else {
00059 if(ALIUtils::debug >= 5 ) std::cout << " !!! ALILine::intersect: two lines are parallel (no errors)" << std::endl;
00060
00061 inters = CLHEP::Hep3Vector( ALI_DBL_MAX, ALI_DBL_MAX, ALI_DBL_MAX );
00062 }
00063 } else {
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 ALIdouble fact = ( vec().y() * l2.pt().x() - vec().x() * l2.pt().y()
00084 - vec().y() * pt().x() + vec().x() * pt().y() )
00085 / ( vec().x() * l2.vec().y() - vec().y() * l2.vec().x() );
00086
00087
00088
00089 if(ALIUtils::debug >= 2 ){
00090 std::cout << std::endl << std::endl << "*** START CALC OF FACT ***" << std::endl;
00091 std::cout << " ==================" << std::endl << std::endl;
00092 std::cout << "*** Determination of fact ->";
00093 std::cout << "\t fact = (" << vec().y() * l2.pt().x() - vec().x() * l2.pt().y()
00094 - vec().y() * pt().x() + vec().x() * pt().y() << "/";
00095
00096 std::cout << vec().x() * l2.vec().y() - vec().y() * l2.vec().x() << ") = " << fact << std::endl;
00097
00098 }
00099
00100
00101 ALIdouble old_fact_denominator = vec().x() * l2.vec().y() - vec().y() * l2.vec().x();
00102
00103 ALIdouble old_fact_denominator2 = 999;
00104
00105
00106 if(fabs(fact) > 1e8 || fabs(old_fact_denominator) < 1.e-10)
00107 {
00108
00109
00110
00111
00112
00113 if(ALIUtils::debug >= 2 && fabs(old_fact_denominator) < 1.e-10) std::cout << " ** Problem: old_fact_denominator -> " << old_fact_denominator << std::endl;
00114
00115 if(ALIUtils::debug >= 2 && fabs(fact) > 1e8) std::cout << " ** Problem: fact -> " << fact << std::endl;
00116
00117 if(ALIUtils::debug >= 2 && (vec().x() * l2.vec().y() - vec().y() * l2.vec().x()) == 0) std::cout << " ** Division by 0 !!! " << std::endl;
00118 if(ALIUtils::debug >= 2 ) std::cout << " ** Must rotate to yz plane for calculation (X-> Z) ";
00119
00120
00121 fact = ( -1 * vec().y() * l2.pt().z() + vec().z() * l2.pt().y()
00122 + vec().y() * pt().z() - vec().z() * pt().y() )
00123 / ( -1*vec().z() * l2.vec().y() + vec().y() * l2.vec().z() );
00124
00125 if(ALIUtils::debug >= 2 ) std::cout << "\t -- 1st Recalculation of fact in yz plane = " << fact << std::endl;
00126
00127 old_fact_denominator2 = -1*vec().z() * l2.vec().y() + vec().y() * l2.vec().z();
00128
00129
00130 if(fabs(-1*vec().z() * l2.vec().y() + vec().y() * l2.vec().z())< 1.e-10)
00131 {
00132
00133 if(ALIUtils::debug >= 2 ) std::cout << " ** Must rotate to xz plane for calculation (Y-> -Z) ";
00134 if(ALIUtils::debug >= 2 && fabs(old_fact_denominator2) < 1.e-10) std::cout << " ** Problem: old_fact_denominator2 -> " << old_fact_denominator2 << std::endl;
00135
00136
00137 fact = ( -1*vec().z() * l2.pt().x() + vec().x() * l2.pt().z()
00138 + vec().z() * pt().x() - vec().x() * pt().z() )
00139 / ( -1*vec().x() * l2.vec().z() + vec().z() * l2.vec().x() );
00140
00141 if(ALIUtils::debug >= 2 ) std::cout << "\t -- 2nd Recalculation of fact in xz plane = " << fact << std::endl;
00142
00143
00144 }
00145 else {
00146 if(ALIUtils::debug >= 2 ) std::cout << "*!* 2nd calculation sufficient" << std::endl;
00147 }
00148
00149 }
00150 else
00151 {
00152
00153 if(ALIUtils::debug >= 2 ) std::cout << "*!* Standard calculation - things are fine" << std::endl;
00154 if(ALIUtils::debug >= 2 ) std::cout << "\t ----> fact = ( " << vec().y() * l2.pt().x() - vec().x() *
00155 l2.pt().y() - vec().y() * pt().x() + vec().x() * pt().y() << " / " << vec().x() * l2.vec().y()
00156 - vec().y()* l2.vec().x() << " ) = " << fact << std::endl;
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 inters = l2.pt() + fact * l2.vec();
00171
00172 if(ALIUtils::debug >= 2 ){
00173 std::cout << "Determination of intersection = l2.pt() + fact * l2.vec()" << std::endl << std::endl;
00174 ALIUtils::dump3v( l2.pt(), "\t --> l2.pt() = ");
00175 std::cout << "\t --> fact = " << fact << std::endl;
00176 std::cout << "\t --> l2.vec() = " << l2.vec() << std::endl;
00177 ALIUtils::dump3v( inters, "***\t --> ALILine::intersection at: ");
00178 }
00179
00180 }
00181
00182 return inters;
00183
00184 }
00185
00186 std::ostream& operator<<(std::ostream& out, const ALILine& li)
00187 {
00188 out << " ALILine point " << li._point << std::endl;
00189 out << " ALILine direc " << li._direction;
00190
00191 return out;
00192 }
00193
00194
00195
00196
00197
00198
00199 CLHEP::Hep3Vector ALILine::intersect( const ALIPlane& plane, bool notParallel)
00200 {
00201 if(ALIUtils::debug >= 5) std::cout << "***** ALILine::intersect WITH PLANE" << std::endl;
00202 if(ALIUtils::debug >= 4) {
00203 ALIUtils::dump3v( plane.point(), "plane point");
00204 ALIUtils::dump3v( plane.normal(), "plane normal");
00205 }
00206
00207
00208 if( fabs( plane.normal()*_direction ) < 1.E-10 ) {
00209 std::cerr << " !!!! INTERSECTION NOT POSSIBLE: LightRay is perpendicular to plane " << std::endl;
00210 std::cerr << " plane.normal()*direction() = " << plane.normal()*_direction << std::endl;
00211 ALIUtils::dump3v( _direction, "LightRay direction ");
00212 ALIUtils::dump3v( plane.normal(), "plane normal ");
00213 exit(1);
00214 }
00215
00216
00217
00218
00219 CLHEP::Hep3Vector vtemp = plane.point() - _point;
00220 if(ALIUtils::debug >= 4) ALIUtils::dump3v( vtemp, "n_r = point - point_plane");
00221
00222 ALIdouble dtemp = _direction * plane.normal();
00223 if(ALIUtils::debug >= 4) std::cout << " lightray* plate normal" << dtemp << std::endl;
00224
00225 if ( dtemp != 0. ) {
00226 dtemp = (vtemp * plane.normal()) / dtemp;
00227 if(ALIUtils::debug >= 4) std::cout << " n_r*plate normal (dtemp) : " << dtemp << std::endl;
00228 if(ALIUtils::debug >= 4) std::cout << " Old vtemp : " << vtemp << std::endl;
00229 } else std::cerr << "!!! LightRay: Intersect With Plane: plane and light ray parallel: no intersection" << std::endl;
00230
00231 vtemp = _direction * dtemp;
00232 if(ALIUtils::debug >= 4) ALIUtils::dump3v( vtemp, "n_r scaled (vtemp) : ");
00233 if(ALIUtils::debug >= 4) ALIUtils::dump3v( dtemp, "dtemp analog to vtemp : ");
00234
00235 CLHEP::Hep3Vector inters = vtemp + _point;
00236 if(ALIUtils::debug >= 4) ALIUtils::dump3v( inters, "intersection point = vtemp + _point");
00237 if(ALIUtils::debug >= 4) ALIUtils::dump3v( vtemp, "vtemp = ");
00238 if(ALIUtils::debug >= 4) ALIUtils::dump3v( _point, "_point = ");
00239
00240 return inters;
00241 }
00242