source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_DetectorCorrections.ipf @ 981

Last change on this file since 981 was 981, checked in by srkline, 7 years ago

more changes, filling in functionality of the initial data correction

File size: 21.0 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2#pragma version=1.0
3#pragma IgorVersion=6.1
4
5
6
7//
8// functions to apply corrections to the detector panels
9//
10// these are meant to be called by the procedures that convert "raw" data to
11// "adjusted" or corrected data sets
12//
13// may be relocated in the future
14//
15
16
17
18//
19// detector dead time
20//
21// input is the data array (N tubes x M pixels)
22// input of N x 1 array of dead time values
23//
24// output is the corrected counts in data, overwriting the input data
25//
26// Note that the equation in Roe (eqn 2.15, p. 63) looks different, but it is really the
27// same old equation, just written in a more complex form.
28//
29// TODO
30// -- verify the direction of the tubes and indexing
31// x- decide on the appropriate functional form for the tubes
32// x- need count time as input
33// -- be sure I'm working in the right data folder
34// -- clean up when done
35// -- calculate + return the error contribution?
36//
37Function DeadTimeCorrectionTubes(dataW,data_errW,dtW,ctTime)
38        Wave dataW,data_errW,dtW
39        Variable ctTime
40       
41        // do I count on the orientation as an input, or do I just figure it out on my own?
42        String orientation
43        Variable dimX,dimY
44        dimX = DimSize(dataW,0)
45        dimY = DimSize(dataw,1)
46        if(dimX > dimY)
47                orientation = "horizontal"
48        else
49                orientation = "vertical"
50        endif
51       
52        // sum the counts in each tube and divide by time for total cr per tube
53        Variable npt
54       
55        if(cmpstr(orientation,"vertical")==0)
56                //      this is data dimensioned as (Ntubes,Npix)
57               
58                MatrixOp/O sumTubes = sumRows(dataW)            // n x 1 result
59                sumTubes /= ctTime              //now count rate per tube
60               
61                dataW[][] = dataW[p][q]/(1-sumTubes[p][0]*dtW[p])               //correct the data
62
63        elseif(cmpstr(orientation,"horizontal")==0)
64        //      this is data (horizontal) dimensioned as (Npix,Ntubes)
65
66                MatrixOp/O sumTubes = sumCols(dataW)            // 1 x m result
67                sumTubes /= ctTime
68               
69                dataW[][] = dataW[p][q]/(1-sumTubes[0][q]*dtW[q])
70       
71        else           
72                DoAlert 0,"Orientation not correctly passed in DeadTimeCorrectionTubes(). No correction done."
73        endif
74       
75        return(0)
76end
77
78//
79// Non-linear data correction
80//
81// input is the data array (N tubes x M pixels)
82// input of N x M array of quadratic coefficients
83//
84// output is wave of corrected real space distance corresponding to each pixel of the data
85//
86//
87// TODO
88// -- verify the direction of the tubes and indexing
89// -- be sure I'm working in the right data folder
90// -- clean up when done
91// -- calculate + return the error contribution?
92// -- do I want this to return a wave?
93// -- 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?
95// -- what else do I need to pass to the function? (fname=folder? detStr?)
96//
97//
98//
99Function NonLinearCorrection(dataW,data_errW,coefW)
100        Wave dataW,data_errW,coefW
101       
102        // do I count on the orientation as an input, or do I just figure it out on my own?
103        String orientation
104        Variable dimX,dimY
105        dimX = DimSize(dataW,0)
106        dimY = DimSize(dataw,1)
107        if(dimX > dimY)
108                orientation = "horizontal"
109        else
110                orientation = "vertical"
111        endif
112
113        // make a wave of the same dimensions, in the same data folder for the distance
114        // ?? or a 2D wave?
115       
116        // then per tube, do the quadratic calculation to get the real space distance along the tube
117        // the distance perpendicular to the tube is n*(8.4mm) per tube index
118       
119        if(cmpstr(orientation,"vertical")==0)
120                //      this is data dimensioned as (Ntubes,Npix)
121               
122
123        elseif(cmpstr(orientation,"horizontal")==0)
124                //      this is data (horizontal) dimensioned as (Npix,Ntubes)
125
126       
127        else           
128                DoAlert 0,"Orientation not correctly passed in NonLinearCorrection(). No correction done."
129        endif
130       
131        return(0)
132end
133
134
135/////
136//
137// non-linear corrections to the tube pixels
138// - returns the distance in mm (although this may change)
139//
140// c0,c1,c2,pix
141// c0-c2 are the fit coefficients
142// pix is the test pixel
143//
144// returns the distance in mm (relative to ctr pixel)
145// ctr is the center pixel, as defined when fitting to quadratic was done
146//
147Function V_TubePixel_to_mm(c0,c1,c2,pix)
148        Variable c0,c1,c2,pix
149       
150        Variable dist
151        dist = c0 + c1*pix + c2*pix*pix
152       
153        return(dist)
154End
155//
156////
157
158// TODO
159// get rid of this in the real data
160//
161// TESTING ONLY
162Macro MakeFakeCalibrationWaves()
163        // make these in the RAW data folder, before converting to a work folder
164        // - then they will be "found" by get()
165        // -- only for the tube, not the Back det
166       
167        DoAlert 0, "re-do this and do a better job of filling the fake data"
168       
169        fMakeFakeCalibrationWaves()
170End
171
172
173
174// TODO
175// get rid of this in the real data
176//
177// TESTING ONLY
178//
179// orientation does not matter, there are 48 tubes in each bank
180// so dimension (3,48) for everything.
181//
182// -- but the orientation does indicate TB vs LR, which has implications for
183//  the (fictional) dimension of the pixel along the tube axis, at least as far
184// as for making the fake coefficients.
185//
186Function fMakeFakeCalibrationWaves()
187
188        Variable ii,pixSize
189        String detStr,fname="RAW",orientation
190       
191        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1)
192                detStr = StringFromList(ii, ksDetectorListNoB, ";")
193//              Wave w = V_getDetectorDataW(fname,detStr)
194                Make/O/D/N=(3,48) $("root:Packages:NIST:VSANS:RAW:entry:entry:instrument:detector_"+detStr+":spatial_calibration")
195                Wave calib = $("root:Packages:NIST:VSANS:RAW:entry:entry:instrument:detector_"+detStr+":spatial_calibration")
196                // !!!! this overwrites what is there
197
198                orientation = V_getDet_tubeOrientation(fname,detStr)
199                if(cmpstr(orientation,"vertical")==0)
200                //      this is vertical tube data dimensioned as (Ntubes,Npix)
201                        pixSize = 8                     //V_getDet_y_pixel_size(fname,detStr)
202                elseif(cmpstr(orientation,"horizontal")==0)
203                //      this is data (horizontal) dimensioned as (Npix,Ntubes)
204                        pixSize = 4                     //V_getDet_x_pixel_size(fname,detStr)
205                else           
206                        DoAlert 0,"Orientation not correctly passed in NonLinearCorrection(). No correction done."
207                endif
208               
209                calib[0][] = -64
210                calib[1][] = pixSize
211                calib[2][] = 2e-4
212               
213        endfor
214       
215        return(0)
216End
217
218
219////////////
220// TODO: all of below is untested code
221//   copied from SANS
222//
223//
224// TODO :
225//   -- DoAlert 0,"This has not yet been updated for VSANS"
226//
227//performs solid angle and non-linear detector corrections to raw data as it is "added" to a work folder
228//function is called by Raw_to_work() and Add_raw_to_work() functions
229//works on the actual data array, assumes that is is already on LINEAR scale
230//
231Function DetCorr(data,data_err,realsread,doEfficiency,doTrans)
232        Wave data,data_err,realsread
233        Variable doEfficiency,doTrans
234
235        DoAlert 0,"This has not yet been updated for VSANS"
236       
237        Variable xcenter,ycenter,x0,y0,sx,sx3,sy,sy3,xx0,yy0
238        Variable ii,jj,dtdist,dtdis2
239        Variable xi,xd,yd,rad,ratio,domega,xy
240        Variable lambda,trans,trans_err,lat_err,tmp_err,lat_corr
241       
242//      Print "...doing jacobian and non-linear corrections"
243
244        NVAR pixelsX = root:myGlobals:gNPixelsX
245        NVAR pixelsY = root:myGlobals:gNPixelsY
246       
247        //set up values to send to auxiliary trig functions
248        xcenter = pixelsX/2 + 0.5               // == 64.5 for 128x128 Ordela
249        ycenter = pixelsY/2 + 0.5               // == 64.5 for 128x128 Ordela
250
251        x0 = realsread[16]
252        y0 = realsread[17]
253        sx = realsread[10]
254        sx3 = realsread[11]
255        sy = realsread[13]
256        sy3 = realsread[14]
257       
258        dtdist = 1000*realsread[18]     //sdd in mm
259        dtdis2 = dtdist^2
260       
261        lambda = realsRead[26]
262        trans = RealsRead[4]
263        trans_err = RealsRead[41]               //new, March 2011
264       
265
266        //waves to contain repeated function calls
267        Make/O/N=(pixelsX) fyy,xx,yy            //Assumes square detector !!!
268        ii=0
269        do
270                xi = ii
271//              fyy[ii] = dc_fy(ii+1,sy,sy3,ycenter)
272//              xx[ii] = dc_fxn(ii+1,sx,sx3,xcenter)
273//              yy[ii] = dc_fym(ii+1,sy,sy3,ycenter)
274                ii+=1
275        while(ii<pixelsX)
276       
277        Make/O/N=(pixelsX,pixelsY) SolidAngle           // testing only
278       
279        ii=0
280        do
281                xi = ii
282//              xd = dc_fx(ii+1,sx,sx3,xcenter)-xx0
283                jj=0
284                do
285                        yd = fyy[jj]-yy0
286                        //rad is the distance of pixel ij from the sample
287                        //domega is the ratio of the solid angle of pixel ij versus center pixel
288                        // product xy = 1 for a detector with a linear spatial response (modern Ordela)
289                        // solid angle calculated, dW^3 >=1, so multiply data to raise measured values to correct values.
290                        rad = sqrt(dtdis2 + xd^2 + yd^2)
291                        domega = rad/dtdist
292                        ratio = domega^3
293                        xy = xx[ii]*yy[jj]
294                       
295                        data[ii][jj] *= xy*ratio
296                       
297                        solidAngle[ii][jj] = xy*ratio           //testing only 
298                        data_err[ii][jj] *= xy*ratio                    //error propagation assumes that SA and Jacobian are exact, so simply scale error
299                       
300                       
301                        // correction factor for detector efficiency JBG memo det_eff_cor2.doc 3/20/07
302                        // correction inserted 11/2007 SRK
303                        // large angle detector efficiency is >= 1 and will "bump up" the measured value at the highest angles
304                        // so divide here to get the correct answer (5/22/08 SRK)
305                        if(doEfficiency)
306                                data[ii][jj] /= DetEffCorr(lambda,dtdist,xd,yd)
307                                data_err[ii][jj] /= DetEffCorr(lambda,dtdist,xd,yd)
308//                              solidAngle[ii][jj] /= DetEffCorr(lambda,dtdist,xd,yd)           //testing only
309                        endif
310                       
311                        // large angle transmission calculation is <= 1 and will "bump down" the measured value at the highest angles
312                        // so divide here to get the correct answer
313                        if(doTrans)
314                       
315                                if(trans<0.1 && ii==0 && jj==0)
316                                        Print "***transmission is less than 0.1*** and is a significant correction"
317                                endif
318                               
319                                if(trans==0)
320                                        if(ii==0 && jj==0)
321                                                Print "***transmission is ZERO*** and has been reset to 1.0 for the averaging calculation"
322                                        endif
323                                        trans = 1
324                                endif
325                               
326                                // pass in the transmission error, and the error in the correction is returned as the last parameter
327                                lat_corr = LargeAngleTransmissionCorr(trans,dtdist,xd,yd,trans_err,lat_err)             //moved from 1D avg SRK 11/2007
328                                data[ii][jj] /= lat_corr                        //divide by the correction factor
329                                //
330                                //
331                                //
332                                // relative errors add in quadrature
333                                tmp_err = (data_err[ii][jj]/lat_corr)^2 + (lat_err/lat_corr)^2*data[ii][jj]*data[ii][jj]/lat_corr^2
334                                tmp_err = sqrt(tmp_err)
335                               
336                                data_err[ii][jj] = tmp_err
337                               
338//                              solidAngle[ii][jj] = lat_err
339
340                               
341                                //solidAngle[ii][jj] = LargeAngleTransmissionCorr(trans,dtdist,xd,yd)           //testing only
342                        endif
343                       
344                        jj+=1
345                while(jj<pixelsX)
346                ii+=1
347        while(ii<pixelsX)
348       
349        //clean up waves
350       
351        Return(0)
352End
353
354
355
356//distances passed in are in mm
357// dtdist is SDD
358// xd and yd are distances from the beam center to the current pixel
359//
360// TODO:
361//   --         DoAlert 0,"This has not yet been updated for VSANS"
362//
363Function DetEffCorr(lambda,dtdist,xd,yd)
364        Variable lambda,dtdist,xd,yd
365
366        DoAlert 0,"This has not yet been updated for VSANS"
367       
368        Variable theta,cosT,ff,stAl,stHe
369       
370        theta = atan( (sqrt(xd^2 + yd^2))/dtdist )
371        cosT = cos(theta)
372       
373        stAl = 0.00967*lambda*0.8               //dimensionless, constants from JGB memo
374        stHe = 0.146*lambda*2.5
375       
376        ff = exp(-stAl/cosT)*(1-exp(-stHe/cosT)) / ( exp(-stAl)*(1-exp(-stHe)) )
377               
378        return(ff)
379End
380
381// DIVIDE the intensity by this correction to get the right answer
382// TODO:
383//   --         DoAlert 0,"This has not yet been updated for VSANS"
384//
385//
386Function LargeAngleTransmissionCorr(trans,dtdist,xd,yd,trans_err,err)
387        Variable trans,dtdist,xd,yd,trans_err,&err
388
389        DoAlert 0,"This has not yet been updated for VSANS"
390       
391        //angle dependent transmission correction
392        Variable uval,arg,cos_th,correction,theta
393       
394        ////this section is the trans_correct() VAX routine
395//      if(trans<0.1)
396//              Print "***transmission is less than 0.1*** and is a significant correction"
397//      endif
398//      if(trans==0)
399//              Print "***transmission is ZERO*** and has been reset to 1.0 for the averaging calculation"
400//              trans = 1
401//      endif
402       
403        theta = atan( (sqrt(xd^2 + yd^2))/dtdist )              //theta at the input pixel
404       
405        //optical thickness
406        uval = -ln(trans)               //use natural logarithm
407        cos_th = cos(theta)
408        arg = (1-cos_th)/cos_th
409       
410        // a Taylor series around uval*arg=0 only needs about 4 terms for very good accuracy
411        //                      correction= 1 - 0.5*uval*arg + (uval*arg)^2/6 - (uval*arg)^3/24 + (uval*arg)^4/120
412        // OR
413        if((uval<0.01) || (cos_th>0.99))       
414                //small arg, approx correction
415                correction= 1-0.5*uval*arg
416        else
417                //large arg, exact correction
418                correction = (1-exp(-uval*arg))/(uval*arg)
419        endif
420
421        Variable tmp
422       
423        if(trans == 1)
424                err = 0         //no correction, no error
425        else
426                //sigT, calculated from the Taylor expansion
427                tmp = (1/trans)*(arg/2-arg^2/3*uval+arg^3/8*uval^2-arg^4/30*uval^3)
428                tmp *= tmp
429                tmp *= trans_err^2
430                tmp = sqrt(tmp)         //sigT
431               
432                err = tmp
433        endif
434       
435//      Printf "trans error = %g\r",trans_err
436//      Printf "correction = %g +/- %g\r", correction, err
437       
438        //end of transmission/pathlength correction
439
440        return(correction)
441end
442
443
444//
445// TODO:
446//   --         DoAlert 0,"This has not yet been updated for VSANS"
447//
448//test procedure, not called anymore
449Proc AbsoluteScaling(type,c0,c1,c2,c3,c4,c5)
450        String type
451        Variable c0=1,c1=0.1,c2=0.95,c3=0.1,c4=1,c5=32.0
452        Prompt type,"WORK data type",popup,"CAL;COR;SAM"
453        Prompt c0, "Sample Transmission"
454        Prompt c1, "Sample Thickness (cm)"
455        Prompt c2, "Standard Transmission"
456        Prompt c3, "Standard Thickness (cm)"
457        Prompt c4, "I(0) from standard fit (normalized to 1E8 monitor cts)"
458        Prompt c5, "Standard Cross-Section (cm-1)"
459
460        Variable err
461        //call the function to do the math
462        //data from "type" will be scaled and deposited in ABS
463        err = Absolute_Scale(type,c0,c1,c2,c3,c4,c5)
464       
465        if(err)
466                Abort "Error in Absolute_Scale()"
467        endif
468       
469        //contents are always dumped to ABS
470        type = "ABS"
471       
472        String newTitle = "WORK_"+type
473        DoWindow/F SANS_Data
474        DoWindow/T SANS_Data, newTitle
475        KillStrings/Z newTitle
476       
477        //need to update the display with "data" from the correct dataFolder
478        //reset the current displaytype to "type"
479        String/G root:myGlobals:gDataDisplayType=Type
480       
481        fRawWindowHook()
482       
483End
484
485//
486// TODO:
487//   --         DoAlert 0,"This has not yet been updated for VSANS"
488//
489//s_ is the standard
490//w_ is the "work" file
491//both are work files and should already be normalized to 10^8 monitor counts
492Function Absolute_Scale(type,w_trans,w_thick,s_trans,s_thick,s_izero,s_cross,kappa_err)
493        String type
494        Variable w_trans,w_thick,s_trans,s_thick,s_izero,s_cross,kappa_err
495
496        DoAlert 0,"This has not yet been updated for VSANS"
497               
498        //convert the "type" data to absolute scale using the given standard information
499        //copying the "type" waves to ABS
500       
501        //check for existence of data, rescale to linear if needed
502        String destPath
503        //check for "type"
504        if(WaveExists($("root:Packages:NIST:"+Type + ":data")) == 0)
505                Print "There is no work file in "+type+"--Aborting"
506                Return(1)               //error condition
507        Endif
508        //check for log-scaling of the "type" data and adjust if necessary
509        destPath = "root:Packages:NIST:"+Type
510        NVAR gIsLogScale = $(destPath + ":gIsLogScale")
511        if(gIsLogScale)
512                Duplicate/O $(destPath + ":linear_data") $(destPath + ":data")//back to linear scale
513                Variable/G $(destPath + ":gIsLogScale")=0       //the "type" data is not logscale anymore
514        endif
515       
516        //copy "oldtype" information to ABS
517        //overwriting out the old contents of the ABS folder (/O option in Duplicate)
518        //copy over the waves data,vlegend,text,integers,reals(read)
519
520        String oldType= "root:Packages:NIST:"+type              //this is where the data to be absoluted is
521        //copy from current dir (type) to ABS, defined by destPath
522        Duplicate/O $(oldType + ":data"),$"root:Packages:NIST:ABS:data"
523        Duplicate/O $(oldType + ":linear_data"),$"root:Packages:NIST:ABS:linear_data"
524        Duplicate/O $(oldType + ":linear_data_error"),$"root:Packages:NIST:ABS:linear_data_error"
525//      Duplicate/O $(oldType + ":vlegend"),$"root:Packages:NIST:ABS:vlegend"
526        Duplicate/O $(oldType + ":textread"),$"root:Packages:NIST:ABS:textread"
527        Duplicate/O $(oldType + ":integersread"),$"root:Packages:NIST:ABS:integersread"
528        Duplicate/O $(oldType + ":realsread"),$"root:Packages:NIST:ABS:realsread"
529        //need to save a copy of filelist string too (from the current type folder)
530        SVAR oldFileList = $(oldType + ":fileList")
531        //need to copy filelist string too
532        String/G $"root:Packages:NIST:ABS:fileList" = oldFileList
533       
534        //now switch to ABS folder
535        //make appropriate wave references
536        WAVE data=$"root:Packages:NIST:ABS:linear_data"                                 // these wave references point to the "type" data in ABS
537        WAVE data_err=$"root:Packages:NIST:ABS:linear_data_error"                                       // these wave references point to the "type" data in ABS
538        WAVE data_copy=$"root:Packages:NIST:ABS:data"                                   // just for display
539        WAVE/T textread=$"root:Packages:NIST:ABS:textread"                      //that are to be directly operated on
540        WAVE integersread=$"root:Packages:NIST:ABS:integersread"
541        WAVE realsread=$"root:Packages:NIST:ABS:realsread"
542        Variable/G $"root:Packages:NIST:ABS:gIsLogscale"=0                      //make new flag in ABS folder, data is linear scale
543       
544        //do the actual absolute scaling here, modifying the data in ABS
545        Variable defmon = 1e8,w_moncount,s1,s2,s3,s4
546       
547        w_moncount = realsread[0]               //monitor count in "type"
548        if(w_moncount == 0)
549                //zero monitor counts will give divide by zero ---
550                DoAlert 0,"Total monitor count in data file is zero. No rescaling of data"
551                Return(1)               //report error
552        Endif
553       
554        //calculate scale factor
555        Variable scale,trans_err
556        s1 = defmon/realsread[0]                //[0] is monitor count (s1 should be 1)
557        s2 = s_thick/w_thick
558        s3 = s_trans/w_trans
559        s4 = s_cross/s_izero
560       
561        // kappa comes in as s_izero, so be sure to use 1/kappa_err
562       
563        data *= s1*s2*s3*s4
564       
565        scale = s1*s2*s3*s4
566        trans_err = realsRead[41]
567       
568//      print scale
569//      print data[0][0]
570       
571        data_err = sqrt(scale^2*data_err^2 + scale^2*data^2*(kappa_err^2/s_izero^2 +trans_err^2/w_trans^2))
572
573//      print data_err[0][0]
574       
575// keep "data" in sync with linear_data
576        data_copy = data
577       
578        //********* 15APR02
579        // DO NOt correct for atenuators here - the COR step already does this, putting all of the data one equal
580        // footing (zero atten) before doing the subtraction.
581        //
582        //Print "ABS data multiplied by  ",s1*s2*s3*s4/attenFactor
583       
584        //update the ABS header information
585        textread[1] = date() + " " + time()             //date + time stamp
586       
587        Return (0) //no error
588End
589
590
591//
592// TODO:
593//   --         DoAlert 0,"This has not yet been updated for VSANS"
594//
595//
596// match the attenuation of the RAW data to the "type" data
597// so that they can be properly added
598//
599// are the attenuator numbers the same? if so exit
600//
601// if not, find the attenuator number for type
602// - find both attenuation factors
603//
604// rescale the raw data to match the ratio of the two attenuation factors
605// -- adjust the detector count (rw)
606// -- the linear data
607//
608//
609Function Adjust_RAW_Attenuation(type)
610        String type
611
612        DoAlert 0,"This has not yet been updated for VSANS"
613       
614        WAVE rw=$("root:Packages:NIST:RAW:realsread")
615        WAVE linear_data=$("root:Packages:NIST:RAW:linear_data")
616        WAVE data=$("root:Packages:NIST:RAW:data")
617        WAVE data_err=$("root:Packages:NIST:RAW:linear_data_error")
618        WAVE/T tw = $("root:Packages:NIST:RAW:textRead")
619       
620        WAVE dest_reals=$("root:Packages:NIST:"+type+":realsread")
621
622        Variable dest_atten,raw_atten,tol
623        Variable lambda,raw_atten_err,raw_AttenFactor,dest_attenFactor,dest_atten_err
624        String fileStr
625
626        dest_atten = dest_reals[3]
627        raw_atten = rw[3]
628       
629        tol = 0.1               // within 0.1 atten units is OK
630        if(abs(dest_atten - raw_atten) < tol )
631                return(0)
632        endif
633
634        fileStr = tw[3]
635        lambda = rw[26]
636        // TODO access correct values
637        raw_AttenFactor = 1//AttenuationFactor(fileStr,lambda,raw_atten,raw_atten_err)
638        dest_AttenFactor = 1//AttenuationFactor(fileStr,lambda,dest_atten,dest_atten_err)
639               
640        rw[2] *= dest_AttenFactor/raw_AttenFactor
641        linear_data *= dest_AttenFactor/raw_AttenFactor
642       
643        // to keep "data" and linear_data in sync
644        data = linear_data
645       
646        return(0)
647End
648
649//
650// TODO:
651//   --         DoAlert 0,"This has not yet been updated for VSANS"
652//
653//************************
654//unused testing procedure, may not be up-to-date with other procedures
655//check before re-implementing
656//
657Macro DIV_a_Workfile(type)
658        String type
659        Prompt type,"WORK data type",popup,"SAM;EMP;BGD;ADJ;"
660       
661        //macro will take whatever is in SELECTED folder and DIVide it by the current
662        //contents of the DIV folder - the function will check for existence
663        //before proceeding
664
665//DoAlert 0,"This has not yet been updated for VSANS"
666       
667        Variable err
668        err = DIVCorrection(type)               //returns err = 1 if data doesn't exist in specified folders
669       
670        if(err)
671                Abort "error in DIVCorrection()"
672        endif
673       
674        //contents are NOT always dumped to CAL, but are in the new type folder
675       
676        String newTitle = "WORK_"+type
677        DoWindow/F VSANS_Data
678        DoWindow/T VSANS_Data, newTitle
679        KillStrings/Z newTitle
680       
681        //need to update the display with "data" from the correct dataFolder
682        //reset the current displaytype to "type"
683        String/G root:Packages:NIST:VSANS:Globals:gCurDispType=Type
684       
685        UpdateDisplayInformation(type)
686       
687End
688
689
690//
691// TODO:
692//   --         DoAlert 0,"This has not yet been updated for VSANS"
693//
694//function will divide the contents of "workType" folder with the contents of
695//the DIV folder + detStr
696// all data is linear scale for the calculation
697//
698Function DIVCorrection(data,data_err,detStr,workType)
699        Wave data,data_err
700        String detStr,workType
701       
702        //check for existence of data in type and DIV
703        // if the desired data doesn't exist, let the user know, and abort
704        String destPath=""
705
706        if(WaveExists(data) == 0)
707                Print "The data wave does not exist in DIVCorrection()"
708                Return(1)               //error condition
709        Endif
710       
711        //check for DIV
712        // if the DIV workfile doesn't exist, let the user know,and abort
713
714        WAVE/Z div_data = $("root:Packages:NIST:VSANS:DIV:entry:entry:instrument:detector_"+detStr+":data")
715        if(WaveExists(div_data) == 0)
716                Print "The DIV wave does not exist in DIVCorrection()"
717                Return(1)               //error condition
718        Endif
719        //files exist, proceed
720
721        data /= div_data
722       
723//      data_err /= div_data
724       
725        Return(0)
726End
727
728
729//////////////////////////
Note: See TracBrowser for help on using the repository browser.