source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Testing_Data_Procs.ipf @ 1095

Last change on this file since 1095 was 1095, checked in by srkline, 4 years ago

Added two model functions for white beam smearing.

Many other small changes for processing of the back detector, shuffling of VSANS menu items, and consistent naming of V_ procedures.

File size: 10.3 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5
6//////// function to take VCALC information and
7// fill in the simulated information as needed to make a "fake" data file
8//
9// TODO:
10// -- identify all of the necessary bits to change
11// -- maybe want a panel to make it easier to decide what inputs to change in the file
12// -- decide if it's better to write wholesale, or as individual waves
13//
14Proc Copy_VCALC_to_VSANSFile(labelStr,intent,group_id)
15        String labelStr = "sample label"
16        String intent = "SAMPLE"
17        variable group_id = 75
18       
19        String fileName = V_DoSaveFileDialog("pick the file to write to")
20        print fileName
21//     
22        if(strlen(fileName) > 0)
23                writeVCALC_to_file(fileName,labelStr,intent,group_id)
24        endif
25End
26
27//
28// TODO -- fill this in as needed to get fake data that's different
29//
30Function writeVCALC_to_file(fileName,labelStr,intent,group_id)
31        String fileName,labelStr,intent
32        Variable group_id
33
34
35// the detectors, all 9 + the correct SDD (that accounts for the offset of T/B panels
36// the data itself (as INT32)
37// the front SDD (correct units)
38// the middle SDD (correct units)
39// the back SDD (correct units)
40        Variable ii,val,sumCts=0
41        String detStr
42        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
43                detStr = StringFromList(ii, ksDetectorListAll, ";")
44                Duplicate/O $("root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_"+detStr+":det_"+detStr) tmpData
45                Redimension/I tmpData
46                //
47                // before, NaN became ugly integer -- now it seems to show up as -1?
48                // then, the "fake" error becomes NaN
49                tmpData = (tmpData ==   2147483647) ? 0 : tmpData               //the NaN "mask" in the sim data (T/B only)shows up as an ugly integer
50                tmpData = (tmpData ==   -1) ? 0 : tmpData               //the NaN "mask" in the sim data (T/B only)shows up as -1
51                V_writeDetectorData(fileName,detStr,tmpData)
52               
53                val = VCALC_getSDD(detStr)              // make sure value is in cm
54                print val
55                V_writeDet_distance(fileName,detStr,val)
56               
57                val = VCALC_getTopBottomSDDSetback(detStr)              //val is in cm, as for data file
58                if(val != 0)
59                        V_writeDet_TBSetback(fileName,detStr,val)
60                endif
61               
62                // returns the total separation (assumed symmetric) in cm
63                val = VCALC_getPanelTranslation(detStr)         
64                // it's OK to call both of these. these functions check detStr for the correct value
65                if(cmpstr("T",detStr[1]) == 0 || cmpstr("B",detStr[1]) == 0)
66                        V_writeDet_VerticalOffset(fileName,detStr,val)          // T/B panels
67                else
68                        V_writeDet_LateralOffset(fileName,detStr,val)           //  L/R panels, or back detector
69                endif
70                // x and y pixel sizes for each detector should be correct in the "base" file - but if not...
71                //Function VCALC_getPixSizeX(type)              // returns the pixel X size, in [cm]
72                //Function VCALC_getPixSizeY(type)
73                V_writeDet_x_pixel_size(fileName,detStr,VCALC_getPixSizeX(detStr)*10)           // data file is expecting mm
74                V_writeDet_y_pixel_size(fileName,detStr,VCALC_getPixSizeY(detStr)*10)
75       
76                // write out the xCtr and yCtr (pixels) that was used in the q-calculation, done in VC_CalculateQFrontPanels()
77                if(kBCTR_CM)
78                //  -- now write out the beam center in cm, not pixels
79                        V_writeDet_beam_center_x(fileName,detStr,0)
80                        V_writeDet_beam_center_y(fileName,detStr,0)
81                else
82                        V_writeDet_beam_center_x(fileName,detStr,V_getDet_beam_center_x("VCALC",detStr))
83                        V_writeDet_beam_center_y(fileName,detStr,V_getDet_beam_center_y("VCALC",detStr))       
84                endif
85
86                if(cmpstr(detStr,"B") == 0)
87                        //always write out the center of the detector since this is dummy data
88                        V_writeDet_beam_center_x(fileName,detStr,V_getDet_beam_center_x("VCALC",detStr)/10)             //write out [cm]
89                        V_writeDet_beam_center_y(fileName,detStr,V_getDet_beam_center_y("VCALC",detStr)/10)     
90                       
91                        // write out the number of pixels x and y
92                        // patch n_pix_x and y
93                        V_writeDet_pixel_num_x(fileName,detStr,V_getDet_pixel_num_x("VCALC",detStr))
94                        V_writeDet_pixel_num_y(fileName,detStr,V_getDet_pixel_num_y("VCALC",detStr))                   
95                endif
96
97               
98               
99                // the calibration data for each detector (except B) is already correct in the "base" file
100                //V_writeDetTube_spatialCalib(fname,detStr,inW)
101                // and for "B"
102                //V_writeDet_cal_x(fname,detStr,inW)
103                //V_writeDet_cal_y(fname,detStr,inW)
104               
105                               
106                // the dead time for each detector is already correct in the "base" file
107                // V_writeDetector_deadtime(fname,detStr,inW)
108                // TODO: need a new, separate function to write the single deadtime value in/out of "B"
109               
110                // integrated count value on each detector bank
111                sumCts += sum(tmpData)
112                V_writeDet_IntegratedCount(fileName,detStr,sum(tmpData))
113
114        endfor
115
116       
117// writes out "perfect" detector calibration constants for all 8 tube banks
118        V_WritePerfectSpatialCalib(filename)
119// writes out "perfect" dead time constants for all 8 tube banks + back detector
120        V_WritePerfectDeadTime(filename)
121       
122//? other detector geometry - lateral separation?
123
124// the wavelength
125//      Variable lam = V_getWavelength("VCALC")         //doesn't work, the corresponding folder in VCALC has not been defined
126        V_writeWavelength(fileName,VCALC_getWavelength())
127
128       
129// fake the information about the count setup, so I have different numbers to read
130// count time = fake time of 100 s
131        V_writeCount_time(fileName,100)
132
133        // monitor count (= imon)
134                // returns the number of neutrons on the sample
135                //Function VCALC_getImon()
136                //
137                // divide the monitor count by 1e8 to get a number small enough to write in the field.
138        V_writeMonitorCount(fileName,VCALC_getImon()/1e8)
139
140        // total detector count (sum of everything)
141        V_writeDetector_counts(fileName,sumCts)
142
143        // sample description
144        V_writeSampleDescription(fileName,labelStr)
145       
146        // reduction intent
147        V_writeReductionIntent(fileName,intent)
148       
149        // reduction group_id
150        // TODO x- (file has been corected)skip for now. group_id is incorrectly written to the data file as a text value. trac ticket
151        //        has been written to fix in the future.
152        V_writeSample_GroupID(fileName,group_id)
153
154
155
156// ?? anything else that I'd like to see on the catalog - I could change them here to see different values
157// different collimation types?
158//
159
160
161
162        return(0)
163end
164
165
166
167// writes out "perfect" detector calibration constants for all 8 tube banks + back detector
168Function V_WritePerfectSpatialCalib(filename)
169        String filename
170       
171//      String fileName = V_DoSaveFileDialog("pick the file to write to")
172       
173        Make/O/D/N=(3,48) tmpCalib
174        // for the "tall" L/R banks
175        tmpCalib[0][] = -512
176        tmpCalib[1][] = 8
177        tmpCalib[2][] = 0
178       
179        V_writeDetTube_spatialCalib(filename,"FR",tmpCalib)
180        V_writeDetTube_spatialCalib(filename,"FL",tmpCalib)
181        V_writeDetTube_spatialCalib(filename,"MR",tmpCalib)
182        V_writeDetTube_spatialCalib(filename,"ML",tmpCalib)
183
184        // for the "short" T/B banks
185        tmpCalib[0][] = -256
186        tmpCalib[1][] = 4
187        tmpCalib[2][] = 0
188       
189        V_writeDetTube_spatialCalib(filename,"FT",tmpCalib)
190        V_writeDetTube_spatialCalib(filename,"FB",tmpCalib)
191        V_writeDetTube_spatialCalib(filename,"MT",tmpCalib)
192        V_writeDetTube_spatialCalib(filename,"MB",tmpCalib)
193       
194        KillWaves tmpCalib
195       
196        // and for the back detector "B"
197        Make/O/D/N=3 tmpCalib
198        tmpCalib[0] = 1
199        tmpCalib[1] = 1
200        tmpcalib[2] = 10000
201        V_writeDet_cal_x(filename,"B",tmpCalib)
202        V_writeDet_cal_y(filename,"B",tmpCalib)
203
204        KillWaves tmpCalib
205
206        return(0)
207end
208
209// TODO -- need a function to write out "bad" and "perfect" dead time values
210// to the HDF file
211//V_writeDetector_deadtime(fname,detStr,inW)
212//V_writeDetector_deadtime_B(fname,detStr,val)
213// simulated count rate per tube can be Å 10^8, so I need dt >> 10^-15 to completely cancel this out
214// (partly due to fake I(q), fake count time in file...)
215
216// writes out "perfect" dead time constants for all 8 tube banks + back detector
217Function V_WritePerfectDeadTime(filename)
218        String filename
219               
220        Make/O/D/N=(48) tmpDT
221        tmpDT = 1e-18
222        V_writeDetector_deadtime(filename,"FT",tmpDT)
223        V_writeDetector_deadtime(filename,"FB",tmpDT)
224        V_writeDetector_deadtime(filename,"FL",tmpDT)
225        V_writeDetector_deadtime(filename,"FR",tmpDT)
226        V_writeDetector_deadtime(filename,"MT",tmpDT)
227        V_writeDetector_deadtime(filename,"MB",tmpDT)
228        V_writeDetector_deadtime(filename,"ML",tmpDT)
229        V_writeDetector_deadtime(filename,"MR",tmpDT)
230
231
232        // and for the back detector "B", a single value, not a wave
233        V_writeDetector_deadtime_B(filename,"B",1e-20)
234
235        KillWaves tmpDT
236
237        return(0)
238end
239
240
241Function V_FakeBeamCenters()
242// fake beam center values
243        V_putDet_beam_center_x("RAW","B",75)
244        V_putDet_beam_center_y("RAW","B",75)
245
246        V_putDet_beam_center_x("RAW","MB",64)
247        V_putDet_beam_center_y("RAW","MB",55)
248        V_putDet_beam_center_x("RAW","MT",64)
249        V_putDet_beam_center_y("RAW","MT",-8.1)
250        V_putDet_beam_center_x("RAW","MR",-8.1)
251        V_putDet_beam_center_y("RAW","MR",64)
252        V_putDet_beam_center_x("RAW","ML",55)
253        V_putDet_beam_center_y("RAW","ML",64)
254
255        V_putDet_beam_center_x("RAW","FB",64)
256        V_putDet_beam_center_y("RAW","FB",55)
257        V_putDet_beam_center_x("RAW","FT",64)
258        V_putDet_beam_center_y("RAW","FT",-8.7)
259        V_putDet_beam_center_x("RAW","FR",-8.1)
260        V_putDet_beam_center_y("RAW","FR",64)
261        V_putDet_beam_center_x("RAW","FL",55)
262        V_putDet_beam_center_y("RAW","FL",64)
263       
264        return(0)
265end
266
267Function V_FakeScaleToCenter()
268
269        V_RescaleToBeamCenter("RAW","MB",64,55)
270        V_RescaleToBeamCenter("RAW","MT",64,-8.7)
271        V_RescaleToBeamCenter("RAW","MR",-8.1,64)
272        V_RescaleToBeamCenter("RAW","ML",55,64)
273        V_RescaleToBeamCenter("RAW","FL",55,64)
274        V_RescaleToBeamCenter("RAW","FR",-8.1,64)
275        V_RescaleToBeamCenter("RAW","FT",64,-8.7)
276        V_RescaleToBeamCenter("RAW","FB",64,55)
277       
278        return(0)
279End
280
281//
282// a few utilities to patch up the data files so that they are useable
283// even without the Back detector containing real data
284//
285// TODO
286//
287// Hopefully, the data files as generated from NICE will have a dummy for the back detector
288// if not, there's going to be a big mess
289//
290//              V_writeDetectorData(fileName,detStr,tmpData)
291//
292Function V_Write_BackDet_to_VSANSFile()
293       
294        String fileName = V_DoSaveFileDialog("pick the file to write to")
295        print fileName
296//     
297        String detStr = "B"
298       
299        if(strlen(fileName) > 0)
300                Wave detW = V_getDetectorDataW(filename,detStr)
301                detW = 1
302                V_writeDetectorData(fileName,detStr,detW)
303        endif
304End
305
306
307
308
309//////
310
311//
312// Function Profiling
313//
314// tests for where the speed bottlenecks are hiding
315//
316// in the built-in procedure, add the line:
317//#include <FunctionProfiling>
318// and check out the instructions in that file.
319//
320// essentially, create a function call with no parameters
321// and run that function as below:
322
323// RunFuncWithProfiling(yourFuncHere)
324
325//
326// function to profile can have no parameters, so hard-wire the file name
327Function V_ProfileFileLoad()
328        V_LoadHDF5Data("sans9999.nxs.ngv","RAW")
329End
330
331
332Function V_ProfileReduceOne()
333        V_ReduceOneButton("")
334End
335
336
337
338
Note: See TracBrowser for help on using the repository browser.