Ignore:
Timestamp:
Feb 25, 2016 4:30:38 PM (7 years ago)
Author:
srkline
Message:

more changes and additons to display VSANS data

adding functions for IvsQ plotting

coverted much of VCALC to have similar folder structure as HDF to allow re-use of the Q-binning procedures from VCALC with real data in work files.

re-working the beam center finder to get it to work with work file data rather then only VCALC.

new plotting routines for the panels to rescale to the beam center (still in pixels, though)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_DetectorCorrections.ipf

    r981 r982  
    9292// -- do I want this to return a wave? 
    9393// -- do I need to write a separate function that returns the distance wave for later calculations? 
    94 // -- do I want to make the distance array 2D to keep the x and y dims together? Calculate them all right now? 
     94// -- do I want to make the distance array 3D to keep the x and y dims together? Calculate them all right now? 
    9595// -- what else do I need to pass to the function? (fname=folder? detStr?) 
    9696// 
    9797// 
    9898// 
    99 Function NonLinearCorrection(dataW,data_errW,coefW) 
    100         Wave dataW,data_errW,coefW 
    101          
     99Function NonLinearCorrection(dataW,coefW,tube_width,detStr,destPath) 
     100        Wave dataW,coefW 
     101        Variable tube_width 
     102        String detStr,destPath 
     103         
     104          
    102105        // do I count on the orientation as an input, or do I just figure it out on my own? 
    103106        String orientation 
     
    112115 
    113116        // make a wave of the same dimensions, in the same data folder for the distance 
    114         // ?? or a 2D wave? 
     117        // ?? or a 3D wave? 
     118        Make/O/D/N=(dimX,dimY) $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistX") 
     119        Make/O/D/N=(dimX,dimY) $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistY") 
     120        Wave data_realDistX = $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistX") 
     121        Wave data_realDistY = $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistY") 
    115122         
    116123        // then per tube, do the quadratic calculation to get the real space distance along the tube 
     
    119126        if(cmpstr(orientation,"vertical")==0) 
    120127                //      this is data dimensioned as (Ntubes,Npix) 
    121                  
    122  
     128                data_realDistY[][] = coefW[0][p] + coefW[1][p]*q + coefW[2][p]*q*q 
     129 
     130                data_realDistX[][] = tube_width*p 
     131                 
    123132        elseif(cmpstr(orientation,"horizontal")==0) 
    124133                //      this is data (horizontal) dimensioned as (Npix,Ntubes) 
    125  
    126          
     134                data_realDistX[][] = coefW[0][q] + coefW[1][q]*p + coefW[2][q]*p*p 
     135         
     136                data_realDistY[][] = tube_width*q 
     137 
    127138        else             
    128139                DoAlert 0,"Orientation not correctly passed in NonLinearCorrection(). No correction done." 
     
    165176        // -- only for the tube, not the Back det 
    166177         
    167         DoAlert 0, "re-do this and do a better job of filling the fake data" 
     178        DoAlert 0, "re-do this and do a better job of filling the fake calibration data" 
    168179         
    169180        fMakeFakeCalibrationWaves() 
     
    200211                //      this is vertical tube data dimensioned as (Ntubes,Npix) 
    201212                        pixSize = 8                     //V_getDet_y_pixel_size(fname,detStr) 
     213                         
    202214                elseif(cmpstr(orientation,"horizontal")==0) 
    203215                //      this is data (horizontal) dimensioned as (Npix,Ntubes) 
    204216                        pixSize = 4                     //V_getDet_x_pixel_size(fname,detStr) 
     217                         
    205218                else             
    206219                        DoAlert 0,"Orientation not correctly passed in NonLinearCorrection(). No correction done." 
    207220                endif 
    208221                 
    209                 calib[0][] = -64 
     222                calib[0][] = -(128/2)*pixSize                   //approx (n/2)*pixSixe 
    210223                calib[1][] = pixSize 
    211224                calib[2][] = 2e-4 
     
    215228        return(0) 
    216229End 
     230 
     231 
     232 
     233Function V_Detector_CalcQVals(fname,detStr,destPath) 
     234        String fname,detStr,destPath 
     235 
     236        String orientation 
     237        Variable xCtr,yCtr,lambda,sdd 
     238         
     239// get all of the geometry information   
     240        orientation = V_getDet_tubeOrientation(fname,detStr) 
     241        sdd = V_getDet_distance(fname,detStr) 
     242        xCtr = V_getDet_beam_center_x(fname,detStr) 
     243        yCtr = V_getDet_beam_center_y(fname,detStr) 
     244        lambda = V_getWavelength(fname) 
     245        Wave data_realDistX = $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistX") 
     246        Wave data_realDistY = $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistY") 
     247 
     248// make the new waves 
     249        Duplicate/O data_realDistX $(destPath + ":entry:entry:instrument:detector_"+detStr+":qTot_"+detStr) 
     250        Duplicate/O data_realDistX $(destPath + ":entry:entry:instrument:detector_"+detStr+":qx_"+detStr) 
     251        Duplicate/O data_realDistX $(destPath + ":entry:entry:instrument:detector_"+detStr+":qy_"+detStr) 
     252        Duplicate/O data_realDistX $(destPath + ":entry:entry:instrument:detector_"+detStr+":qz_"+detStr) 
     253        Wave qTot = $(destPath + ":entry:entry:instrument:detector_"+detStr+":qTot_"+detStr) 
     254        Wave qx = $(destPath + ":entry:entry:instrument:detector_"+detStr+":qx_"+detStr) 
     255        Wave qy = $(destPath + ":entry:entry:instrument:detector_"+detStr+":qy_"+detStr) 
     256        Wave qz = $(destPath + ":entry:entry:instrument:detector_"+detStr+":qz_"+detStr) 
     257 
     258// calculate all of the q-values 
     259        qTot = V_CalcQval(p,q,xCtr,yCtr,sdd,lambda,data_realDistX,data_realDistY) 
     260        qx = V_CalcQX(p,q,xCtr,yCtr,sdd,lambda,data_realDistX,data_realDistY) 
     261        qy = V_CalcQY(p,q,xCtr,yCtr,sdd,lambda,data_realDistX,data_realDistY) 
     262        qz = V_CalcQZ(p,q,xCtr,yCtr,sdd,lambda,data_realDistX,data_realDistY) 
     263         
     264         
     265        return(0) 
     266End 
     267 
     268 
     269//function to calculate the overall q-value, given all of the necesary trig inputs 
     270// 
     271// TODO: 
     272// -- verify the calculation (accuracy - in all input conditions) 
     273// -- verify the units of everything here, it's currently all jumbled an wrong... 
     274// -- the input data_realDistX and Y are essentially lookup tables of the real space distance corresponding 
     275//    to each pixel 
     276// 
     277//sdd is in meters 
     278//wavelength is in Angstroms 
     279// 
     280//returned magnitude of Q is in 1/Angstroms 
     281// 
     282Function V_CalcQval(xaxval,yaxval,xctr,yctr,sdd,lam,distX,distY) 
     283        Variable xaxval,yaxval,xctr,yctr,sdd,lam 
     284        Wave distX,distY 
     285         
     286        Variable dx,dy,qval,two_theta,dist 
     287                 
     288        sdd *=100               //convert to cm 
     289        dx = (distX[xaxval][yaxval] - xctr)             //delta x in cm 
     290        dy = (distY[xaxval][yaxval] - yctr)             //delta y in cm 
     291        dist = sqrt(dx^2 + dy^2) 
     292         
     293        two_theta = atan(dist/sdd) 
     294 
     295        qval = 4*Pi/lam*sin(two_theta/2) 
     296         
     297        return qval 
     298End 
     299 
     300//calculates just the q-value in the x-direction on the detector 
     301// TODO: 
     302// -- verify the calculation (accuracy - in all input conditions) 
     303// -- verify the units of everything here, it's currently all jumbled an wrong... 
     304// -- the input data_realDistX and Y are essentially lookup tables of the real space distance corresponding 
     305//    to each pixel 
     306// 
     307// 
     308// this properly accounts for qz 
     309// 
     310Function V_CalcQX(xaxval,yaxval,xctr,yctr,sdd,lam,distX,distY) 
     311        Variable xaxval,yaxval,xctr,yctr,sdd,lam 
     312        Wave distX,distY 
     313 
     314        Variable qx,qval,phi,dx,dy,dist,two_theta 
     315         
     316        qval = V_CalcQval(xaxval,yaxval,xctr,yctr,sdd,lam,distX,distY) 
     317         
     318        sdd *=100               //convert to cm 
     319        dx = (distX[xaxval][yaxval] - xctr)             //delta x in cm 
     320        dy = (distY[xaxval][yaxval] - yctr)             //delta y in cm 
     321        phi = V_FindPhi(dx,dy) 
     322         
     323        //get scattering angle to project onto flat detector => Qr = qval*cos(theta) 
     324        dist = sqrt(dx^2 + dy^2) 
     325        two_theta = atan(dist/sdd) 
     326 
     327        qx = qval*cos(two_theta/2)*cos(phi) 
     328         
     329        return qx 
     330End 
     331 
     332//calculates just the q-value in the y-direction on the detector 
     333// TODO: 
     334// -- verify the calculation (accuracy - in all input conditions) 
     335// -- verify the units of everything here, it's currently all jumbled an wrong... 
     336// -- the input data_realDistX and Y are essentially lookup tables of the real space distance corresponding 
     337//    to each pixel 
     338// 
     339// 
     340// this properly accounts for qz 
     341// 
     342Function V_CalcQY(xaxval,yaxval,xctr,yctr,sdd,lam,distX,distY) 
     343        Variable xaxval,yaxval,xctr,yctr,sdd,lam 
     344        Wave distX,distY 
     345 
     346        Variable qy,qval,phi,dx,dy,dist,two_theta 
     347         
     348        qval = V_CalcQval(xaxval,yaxval,xctr,yctr,sdd,lam,distX,distY) 
     349         
     350        sdd *=100               //convert to cm 
     351        dx = (distX[xaxval][yaxval] - xctr)             //delta x in cm 
     352        dy = (distY[xaxval][yaxval] - yctr)             //delta y in cm 
     353        phi = V_FindPhi(dx,dy) 
     354         
     355        //get scattering angle to project onto flat detector => Qr = qval*cos(theta) 
     356        dist = sqrt(dx^2 + dy^2) 
     357        two_theta = atan(dist/sdd) 
     358 
     359        qy = qval*cos(two_theta/2)*sin(phi) 
     360         
     361        return qy 
     362End 
     363 
     364//calculates just the q-value in the z-direction on the detector 
     365// TODO: 
     366// -- verify the calculation (accuracy - in all input conditions) 
     367// -- verify the units of everything here, it's currently all jumbled an wrong... 
     368// -- the input data_realDistX and Y are essentially lookup tables of the real space distance corresponding 
     369//    to each pixel 
     370// 
     371// not actually used for anything, but here for completeness if anyone asks 
     372// 
     373// this properly accounts for qz 
     374// 
     375Function V_CalcQZ(xaxval,yaxval,xctr,yctr,sdd,lam,distX,distY) 
     376        Variable xaxval,yaxval,xctr,yctr,sdd,lam 
     377        Wave distX,distY 
     378 
     379        Variable qz,qval,phi,dx,dy,dist,two_theta 
     380         
     381        qval = V_CalcQval(xaxval,yaxval,xctr,yctr,sdd,lam,distX,distY) 
     382         
     383        sdd *=100               //convert to cm 
     384        dx = (distX[xaxval][yaxval] - xctr)             //delta x in cm 
     385        dy = (distY[xaxval][yaxval] - yctr)             //delta y in cm 
     386         
     387        //get scattering angle to project onto flat detector => Qr = qval*cos(theta) 
     388        dist = sqrt(dx^2 + dy^2) 
     389        two_theta = atan(dist/sdd) 
     390 
     391        qz = qval*sin(two_theta/2) 
     392         
     393        return qz 
     394End 
     395 
    217396 
    218397 
Note: See TracChangeset for help on using the changeset viewer.