Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "Alignment/CocoaModel/interface/DeviationsFromFileSensor2D.h"
00009 #include "Alignment/CocoaUtilities/interface/ALIFileIn.h"
00010 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
00011 #include <cstdlib>
00012
00013 enum directions{ xdir = 0, ydir = 1};
00014
00015 ALIbool DeviationsFromFileSensor2D::theApply = true;
00016
00017
00018
00019 void DeviationsFromFileSensor2D::readFile( ALIFileIn& ifdevi )
00020 {
00021 verbose = ALIUtils::debug;
00022
00023 if( verbose >= 3) std::cout << "DeviationsFromFileSensor2D::readFile " << this << ifdevi.name() << std::endl;
00024
00025 theScanSenseX = 0;
00026 theScanSenseY = 0;
00027
00028 ALIuint nl = 1;
00029
00030 ALIdouble oldposX=0, oldposY=0;
00031 vd vcol;
00032 std::vector<ALIstring> wl;
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 for(;;) {
00046 ifdevi.getWordsInLine( wl );
00047 if(ifdevi.eof() ) break;
00048
00049 DeviationSensor2D* dev = new DeviationSensor2D();
00050 dev->fillData( wl );
00051
00052 if(verbose >= 5) {
00053 ALIUtils::dumpVS( wl, "deviation sensor2D", std::cout );
00054 }
00055
00056
00057 if(nl == 2) {
00058
00059 firstScanDir = ydir;
00060 if(verbose >= 3) std::cout << "firstScanDir " << firstScanDir << " " << dev->posX() << " " << oldposX << " " << dev->posY() << " " << oldposY << std::endl;
00061 if( fabs( dev->posX() - oldposX ) > fabs( dev->posY() - oldposY ) ) {
00062 std::cerr << "!!!EXITING first scan direction has to be Y for the moment " << ifdevi.name() << std::endl;
00063 firstScanDir = xdir;
00064 exit(1);
00065 }
00066
00067 if(firstScanDir == ydir ){
00068 if( dev->posY() > oldposY ) {
00069 theScanSenseY = +1;
00070 } else {
00071 theScanSenseY = -1;
00072 }
00073 if( verbose >= 3 ) std::cout << " theScanSenseY " << theScanSenseY << std::endl;
00074 }else {
00075 if( dev->posX() > oldposX ) {
00076 theScanSenseX = +1;
00077 } else {
00078 theScanSenseX = -1;
00079 }
00080 if( verbose >= 3 ) std::cout << " theScanSenseX " << theScanSenseX << std::endl;
00081 }
00082 }
00083
00084
00085
00086
00087 if( ( firstScanDir == ydir && ( dev->posY() - oldposY)*theScanSenseY < 0 )
00088 || ( firstScanDir == xdir && ( dev->posX() - oldposX)*theScanSenseX < 0 )) {
00089 theDeviations.push_back( vcol );
00090 vcol.clear();
00091
00092
00093
00094 if( theScanSenseY == 0 ) {
00095 if( dev->posY() > oldposY ) {
00096 theScanSenseY = +1;
00097 } else {
00098 theScanSenseY = -1;
00099 }
00100 }
00101 if( theScanSenseX == 0 ) {
00102 if( dev->posX() > oldposX ) {
00103 theScanSenseX = +1;
00104 } else {
00105 theScanSenseX = -1;
00106 }
00107 }
00108 if( verbose >= 3 ) std::cout << " theScanSenseX " << theScanSenseX << " theScanSenseY " << theScanSenseY << std::endl;
00109 }
00110
00111 oldposX = dev->posX();
00112 oldposY = dev->posY();
00113
00114
00115 vcol.push_back( dev );
00116 nl++;
00117 }
00118 theDeviations.push_back( vcol );
00119
00120
00121 ALIdouble dvsiz = ( sqrt( ALIdouble(nl-1) ) );
00122
00123 ALIuint vsiz = ALIuint(dvsiz);
00124 if( vsiz != dvsiz ) {
00125 if( ALIUtils::debug >= 0) std::cerr << "!!WARNING: error reading deviation file: number of X points <> number of Y points : Number of points in X " << dvsiz << " nl " << nl-1 << " file " << ifdevi.name() << std::endl;
00126
00127 }
00128 theNPoints = vsiz;
00129
00130 if(verbose >= 4 ) {
00131 std::cout << " Filling deviation from file: " << ifdevi.name() << " theNPoints " << theNPoints << std::endl;
00132 }
00133
00134 }
00135
00136
00137
00138 std::pair< ALIdouble, ALIdouble > DeviationsFromFileSensor2D::getDevis( ALIdouble intersX, ALIdouble intersY )
00139 {
00140
00141
00142 if(verbose >= 4) std::cout << " entering getdevis " << intersX << " " <<intersY << " " << this << std::endl;
00143 vvd::iterator vvdite;
00144 vd::iterator vdite;
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 unsigned int* yrows = new unsigned int[ theNPoints ];
00158
00159 unsigned int ii = 0;
00160 ALIbool insideMatrix = 0;
00161 for( vvdite = theDeviations.begin(); vvdite != (theDeviations.end()-1); vvdite++ ){
00162 for( vdite = (*vvdite).begin(); vdite != ((*vvdite).end()-1); vdite++ ){
00163 if( verbose >= 5 ) std::cout << " check posy " << (*(vdite))->posY() << " " << (*(vdite+1))->posY() << " " << (*(vdite)) << std::endl;
00164
00165
00166
00167
00168 if( (intersY - (*(vdite))->posY() )*theScanSenseY > 0
00169 && (intersY - (*(vdite+1))->posY() )*theScanSenseY < 0 ) {
00170
00171 yrows[ii] = vdite - (*vvdite).begin();
00172 if( verbose >= 3 ) std::cout << intersY << " DeviationsFromFileSensor2D yrows " << ii << " " << yrows[ii] << " : " << (*(vdite))->posY() << std::endl;
00173 insideMatrix = 1;
00174 break;
00175 }
00176 }
00177 ii++;
00178 }
00179 if(insideMatrix == 0) {
00180 std::cerr << "!!EXITING intersection in Y outside matrix of deviations from file " << intersY << std::endl;
00181 exit(1);
00182 }
00183 insideMatrix = 0;
00184
00185 vd thePoints;
00186 thePoints.clear();
00187
00188 unsigned int rn;
00189 DeviationSensor2D *dev1,*dev2;
00190 for( ii = 0; ii < theNPoints-1; ii++) {
00191 rn = yrows[ii];
00192
00193 dev1 = (*(theDeviations.begin()+ii))[ rn ];
00194 rn = yrows[ii+1];
00195 dev2 = (*(theDeviations.begin()+ii+1))[ rn ];
00196 if( (intersX - dev1->posX() )*theScanSenseX > 0
00197 && (intersX - dev2->posX() )*theScanSenseX < 0) {
00198 thePoints.push_back( dev1 );
00199 thePoints.push_back( dev2 );
00200 insideMatrix = 1;
00201 if( verbose >= 3 ) std::cout << " column up " << ii << " " << dev1->posX() << " " << dev2->posX() << " : " << intersX << std::endl;
00202 }
00203
00204 rn = yrows[ii] + 1;
00205 if(rn == theNPoints) rn = theNPoints-1;
00206 dev1 = (*(theDeviations.begin()+ii))[ rn ];
00207 rn = yrows[ii+1] + 1;
00208 if(rn == theNPoints) rn = theNPoints-1;
00209 dev2 = (*(theDeviations.begin()+ii+1))[ rn ];
00210 if( (intersX - dev1->posX() )*theScanSenseX > 0
00211 && (intersX - dev2->posX() )*theScanSenseX < 0) {
00212 thePoints.push_back( dev1 );
00213 thePoints.push_back( dev2 );
00214 if( verbose >= 3 ) std::cout << " column down " << ii << " " << dev1->posX() << " " << dev2->posX() << " : " << intersX << std::endl;
00215 }
00216
00217 if( thePoints.size() == 4 ) break;
00218
00219 }
00220
00221 if(insideMatrix == 0) {
00222 std::cerr << "!!EXITING intersection in X outside matrix of deviations from file " << intersX << std::endl;
00223 exit(1);
00224 }
00225
00226
00227
00228
00229 ALIdouble dist, disttot=0, deviX=0, deviY=0;
00230
00231 if( verbose >= 4) std::cout << " thepoints size " << thePoints.size() << std::endl;
00232
00233 for( ii = 0; ii < 4; ii++) {
00234 dist = sqrt( pow(thePoints[ii]->posX() - intersX, 2 ) + pow(thePoints[ii]->posY() - intersY, 2 ) );
00235 disttot += 1./dist;
00236 deviX += thePoints[ii]->devX()/dist;
00237 deviY += thePoints[ii]->devY()/dist;
00238 if( verbose >= 4 ) {
00239
00240 std::cout << ii << " distances: " << dist << " " << deviX << " " << deviY << " devX " << thePoints[ii]->devX() << " devY " << thePoints[ii]->devY() << std::endl;
00241 }
00242 }
00243 deviX /= disttot;
00244 deviY /= disttot;
00245
00246
00247 deviX += theOffsetX;
00248 deviY += theOffsetY;
00249 if( verbose >= 4 ) {
00250 std::cout << " devisX/Y: " << deviX << " " << deviY
00251 << " intersX/Y " << intersX << " " << intersY << std::endl;
00252 }
00253
00254
00255 deviX *= -1;
00256 deviY *= -1;
00257 return std::pair< ALIdouble, ALIdouble>( deviX*1.e-6, deviY*1e-6 );
00258
00259 }
00260