Ignore:
Timestamp:
Mar 11, 2016 3:36:43 PM (7 years ago)
Author:
srkline
Message:

lots of changes to 1D averaging and the plotting routines, detector corrections, and basic reads

File:
1 edited

Legend:

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

    r982 r984  
    8686// 
    8787// TODO 
     88// -- UNITS!!!! currently this is mm, which certainly doesn't match anything else!!! 
    8889// -- verify the direction of the tubes and indexing 
    8990// -- be sure I'm working in the right data folder 
     
    9495// -- do I want to make the distance array 3D to keep the x and y dims together? Calculate them all right now? 
    9596// -- what else do I need to pass to the function? (fname=folder? detStr?) 
    96 // 
     97// -- need a separate block or function to handle "B" detector which will be ? different 
    9798// 
    9899// 
     
    107108        Variable dimX,dimY 
    108109        dimX = DimSize(dataW,0) 
    109         dimY = DimSize(dataw,1) 
     110        dimY = DimSize(dataW,1) 
    110111        if(dimX > dimY) 
    111112                orientation = "horizontal" 
     
    126127        if(cmpstr(orientation,"vertical")==0) 
    127128                //      this is data dimensioned as (Ntubes,Npix) 
     129                data_realDistX[][] = tube_width*p 
    128130                data_realDistY[][] = coefW[0][p] + coefW[1][p]*q + coefW[2][p]*q*q 
    129  
    130                 data_realDistX[][] = tube_width*p 
    131                  
     131         
    132132        elseif(cmpstr(orientation,"horizontal")==0) 
    133133                //      this is data (horizontal) dimensioned as (Npix,Ntubes) 
    134134                data_realDistX[][] = coefW[0][q] + coefW[1][q]*p + coefW[2][q]*p*p 
    135          
    136135                data_realDistY[][] = tube_width*q 
    137136 
     
    142141        return(0) 
    143142end 
     143 
     144// TODO: 
     145// -- the cal_x and y coefficients are totally fake 
     146// -- the wave assignment may not be correct.. so beware 
     147// 
     148// 
     149Function NonLinearCorrection_B(folder,detStr,destPath) 
     150        String folder,detStr,destPath 
     151 
     152        if(cmpstr(detStr,"B") != 0) 
     153                return(0) 
     154        endif 
     155         
     156        // do I count on the orientation as an input, or do I just figure it out on my own? 
     157        Variable dimX,dimY 
     158         
     159        Wave dataW = V_getDetectorDataW(folder,detStr) 
     160         
     161        dimX = DimSize(dataW,0) 
     162        dimY = DimSize(dataW,1) 
     163 
     164        // make a wave of the same dimensions, in the same data folder for the distance 
     165        // ?? or a 3D wave? 
     166        Make/O/D/N=(dimX,dimY) $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistX") 
     167        Make/O/D/N=(dimX,dimY) $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistY") 
     168        Wave data_realDistX = $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistX") 
     169        Wave data_realDistY = $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistY") 
     170         
     171         
     172        Wave cal_x = V_getDet_cal_x(folder,detStr) 
     173        Wave cal_y = V_getDet_cal_y(folder,detStr) 
     174         
     175        data_realDistX[][] = cal_x[0]*p 
     176        data_realDistY[][] = cal_y[0]*q 
     177         
     178        return(0) 
     179end 
     180 
     181 
     182// 
     183// 
     184// TODO 
     185// -- VERIFY the calculations 
     186// -- verify where this needs to be done (if the beam center is changed) 
     187// -- then the q-calculation needs to be re-done 
     188// -- the position along the tube length is referenced to tube[0], for no particular reason 
     189//    It may be better to take an average? but [0] is an ASSUMPTION 
     190// -- distance along tube is simple interpolation, or do I use the coefficients to 
     191//    calculate the actual value 
     192// 
     193// -- distance in the lateral direction is based on tube width, which is well known 
     194// 
     195// 
     196Function ConvertBeamCtr_to_mm(folder,detStr,destPath) 
     197        String folder,detStr,destPath 
     198         
     199        Wave data_realDistX = $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistX") 
     200        Wave data_realDistY = $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistY")         
     201 
     202        String orientation 
     203        Variable dimX,dimY,xCtr,yCtr 
     204        dimX = DimSize(data_realDistX,0) 
     205        dimY = DimSize(data_realDistX,1) 
     206        if(dimX > dimY) 
     207                orientation = "horizontal" 
     208        else 
     209                orientation = "vertical" 
     210        endif 
     211         
     212        xCtr = V_getDet_beam_center_x(folder,detStr) 
     213        yCtr = V_getDet_beam_center_y(folder,detStr)     
     214         
     215        Make/O/D/N=1 $(destPath + ":entry:entry:instrument:detector_"+detStr+":beam_center_x_mm") 
     216        Make/O/D/N=1 $(destPath + ":entry:entry:instrument:detector_"+detStr+":beam_center_y_mm") 
     217        WAVE x_mm = $(destPath + ":entry:entry:instrument:detector_"+detStr+":beam_center_x_mm") 
     218        WAVE y_mm = $(destPath + ":entry:entry:instrument:detector_"+detStr+":beam_center_y_mm") 
     219 
     220        Variable tube_width = V_getDet_tubeWidth(folder,detStr) 
     221 
     222// 
     223        if(cmpstr(orientation,"vertical")==0) 
     224                //      this is data dimensioned as (Ntubes,Npix) 
     225//              data_realDistX[][] = tube_width*p 
     226//              data_realDistY[][] = coefW[0][p] + coefW[1][p]*q + coefW[2][p]*q*q 
     227                x_mm[0] = tube_width*xCtr 
     228                y_mm[0] = data_realDistY[0][yCtr] 
     229        else 
     230                //      this is data (horizontal) dimensioned as (Npix,Ntubes) 
     231//              data_realDistX[][] = coefW[0][q] + coefW[1][q]*p + coefW[2][q]*p*p 
     232//              data_realDistY[][] = tube_width*q 
     233                x_mm[0] = data_realDistX[xCtr][0] 
     234                y_mm[0] = tube_width*yCtr 
     235        endif 
     236                 
     237        return(0) 
     238end 
     239 
     240 
     241// 
     242// 
     243// TODO 
     244// -- VERIFY the calculations 
     245// -- verify where this needs to be done (if the beam center is changed) 
     246// -- then the q-calculation needs to be re-done 
     247// -- the position along the tube length is referenced to tube[0], for no particular reason 
     248//    It may be better to take an average? but [0] is an ASSUMPTION 
     249// -- distance along tube is simple interpolation 
     250// 
     251// -- distance in the lateral direction is based on tube width, which is well known 
     252// 
     253// 
     254Function ConvertBeamCtr_to_mmB(folder,detStr,destPath) 
     255        String folder,detStr,destPath 
     256         
     257        Wave data_realDistX = $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistX") 
     258        Wave data_realDistY = $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistY")         
     259         
     260        Variable xCtr,yCtr 
     261        xCtr = V_getDet_beam_center_x(folder,detStr) 
     262        yCtr = V_getDet_beam_center_y(folder,detStr)     
     263         
     264        Make/O/D/N=1 $(destPath + ":entry:entry:instrument:detector_"+detStr+":beam_center_x_mm") 
     265        Make/O/D/N=1 $(destPath + ":entry:entry:instrument:detector_"+detStr+":beam_center_y_mm") 
     266        WAVE x_mm = $(destPath + ":entry:entry:instrument:detector_"+detStr+":beam_center_x_mm") 
     267        WAVE y_mm = $(destPath + ":entry:entry:instrument:detector_"+detStr+":beam_center_y_mm") 
     268 
     269        x_mm[0] = data_realDistX[xCtr][0] 
     270        y_mm[0] = data_realDistY[0][yCtr] 
     271                 
     272        return(0) 
     273end 
     274 
     275 
     276 
     277 
    144278 
    145279 
     
    226360        endfor 
    227361         
     362        // now fake calibration for "B" 
     363        Wave cal_x = V_getDet_cal_x("RAW","B") 
     364        Wave cal_y = V_getDet_cal_y("RAW","B") 
     365         
     366        cal_x = 1               // mm, ignore the other 2 values 
     367        cal_y = 1               // mm 
    228368        return(0) 
    229369End 
    230370 
    231  
    232  
     371// 
     372// data_realDistX, Y must be previously generated from running NonLinearCorrection() 
     373// 
     374// call with: 
     375// fname as the WORK folder, "RAW" 
     376// detStr = detector String, "FL" 
     377// destPath = path to destination WORK folder ("root:Packages:NIST:VSANS:"+folder) 
     378// 
    233379Function V_Detector_CalcQVals(fname,detStr,destPath) 
    234380        String fname,detStr,destPath 
     
    240386        orientation = V_getDet_tubeOrientation(fname,detStr) 
    241387        sdd = V_getDet_distance(fname,detStr) 
    242         xCtr = V_getDet_beam_center_x(fname,detStr) 
    243         yCtr = V_getDet_beam_center_y(fname,detStr) 
     388        sdd/=100                // sdd reported in cm, pass in m 
     389        // this is the ctr in pixels 
     390//      xCtr = V_getDet_beam_center_x(fname,detStr) 
     391//      yCtr = V_getDet_beam_center_y(fname,detStr) 
     392        // this is ctr in mm 
     393        xCtr = V_getDet_beam_center_x_mm(fname,detStr) 
     394        yCtr = V_getDet_beam_center_y_mm(fname,detStr) 
    244395        lambda = V_getWavelength(fname) 
    245396        Wave data_realDistX = $(destPath + ":entry:entry:instrument:detector_"+detStr+":data_realDistX") 
     
    271422// TODO: 
    272423// -- verify the calculation (accuracy - in all input conditions) 
    273 // -- verify the units of everything here, it's currently all jumbled an wrong... 
     424// -- verify the units of everything here, it's currently all jumbled and wrong... and repeated 
    274425// -- the input data_realDistX and Y are essentially lookup tables of the real space distance corresponding 
    275426//    to each pixel 
     
    287438                 
    288439        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 
     440        dx = (distX[xaxval][yaxval] - xctr)             //delta x in mm 
     441        dy = (distY[xaxval][yaxval] - yctr)             //delta y in mm 
    291442        dist = sqrt(dx^2 + dy^2) 
    292443         
     444        dist /= 10  // convert mm to cm 
     445         
    293446        two_theta = atan(dist/sdd) 
    294447 
     
    301454// TODO: 
    302455// -- verify the calculation (accuracy - in all input conditions) 
    303 // -- verify the units of everything here, it's currently all jumbled an wrong... 
     456// -- verify the units of everything here, it's currently all jumbled and wrong... and repeated 
    304457// -- the input data_realDistX and Y are essentially lookup tables of the real space distance corresponding 
    305458//    to each pixel 
     
    317470         
    318471        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 
     472        dx = (distX[xaxval][yaxval] - xctr)             //delta x in mm 
     473        dy = (distY[xaxval][yaxval] - yctr)             //delta y in mm 
    321474        phi = V_FindPhi(dx,dy) 
    322475         
    323476        //get scattering angle to project onto flat detector => Qr = qval*cos(theta) 
    324477        dist = sqrt(dx^2 + dy^2) 
     478        dist /= 10  // convert mm to cm 
     479 
    325480        two_theta = atan(dist/sdd) 
    326481 
     
    333488// TODO: 
    334489// -- verify the calculation (accuracy - in all input conditions) 
    335 // -- verify the units of everything here, it's currently all jumbled an wrong... 
     490// -- verify the units of everything here, it's currently all jumbled and wrong... and repeated 
    336491// -- the input data_realDistX and Y are essentially lookup tables of the real space distance corresponding 
    337492//    to each pixel 
     
    349504         
    350505        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 
     506        dx = (distX[xaxval][yaxval] - xctr)             //delta x in mm 
     507        dy = (distY[xaxval][yaxval] - yctr)             //delta y in mm 
    353508        phi = V_FindPhi(dx,dy) 
    354509         
    355510        //get scattering angle to project onto flat detector => Qr = qval*cos(theta) 
    356511        dist = sqrt(dx^2 + dy^2) 
     512        dist /= 10  // convert mm to cm 
     513 
    357514        two_theta = atan(dist/sdd) 
    358515 
     
    365522// TODO: 
    366523// -- verify the calculation (accuracy - in all input conditions) 
    367 // -- verify the units of everything here, it's currently all jumbled an wrong... 
     524// -- verify the units of everything here, it's currently all jumbled and wrong... and repeated 
    368525// -- the input data_realDistX and Y are essentially lookup tables of the real space distance corresponding 
    369526//    to each pixel 
     
    382539         
    383540        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 
     541        dx = (distX[xaxval][yaxval] - xctr)             //delta x in mm 
     542        dy = (distY[xaxval][yaxval] - yctr)             //delta y in mm 
    386543         
    387544        //get scattering angle to project onto flat detector => Qr = qval*cos(theta) 
    388545        dist = sqrt(dx^2 + dy^2) 
     546        dist /= 10  // convert mm to cm 
     547 
    389548        two_theta = atan(dist/sdd) 
    390549 
Note: See TracChangeset for help on using the changeset viewer.