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

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

multiple changes to improve the functionality of VCALC

more values are reported, and the IQ plot now accounts for a beam stop shadowing the low q region. Qmin and qmax values are reported for each panel. the beam intensity value is more realistic, with correct SSD values.

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