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

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

New dimensions added for the back detector. many functions neede to be updated to accomodate these changes. Beam center is handled in the same way (in cm, not pixels) as other panels even though this panel is like the 2D detectors on SANS.

Still missing is the real values for caibration, pixel size, dead time, etc. that are yet to be measured.

File size: 9.7 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_LateralOffset(fileName,detStr,val)           // T/B panels
67                else
68                        V_writeDet_VerticalOffset(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        V_writeMonitorCount(fileName,VCALC_getImon())
137
138        // total detector count (sum of everything)
139        V_writeDetector_counts(fileName,sumCts)
140
141        // sample description
142        V_writeSampleDescription(fileName,labelStr)
143       
144        // reduction intent
145        V_writeReductionIntent(fileName,intent)
146       
147        // reduction group_id
148        // TODO x- (file has been corected)skip for now. group_id is incorrectly written to the data file as a text value. trac ticket
149        //        has been written to fix in the future.
150        V_writeSample_GroupID(fileName,group_id)
151
152
153
154// ?? anything else that I'd like to see on the catalog - I could change them here to see different values
155// different collimation types?
156//
157
158
159
160        return(0)
161end
162
163
164
165// writes out "perfect" detector calibration constants for all 8 tube banks + back detector
166Function V_WritePerfectSpatialCalib(filename)
167        String filename
168       
169//      String fileName = V_DoSaveFileDialog("pick the file to write to")
170       
171        Make/O/D/N=(3,48) tmpCalib
172        // for the "tall" L/R banks
173        tmpCalib[0][] = -512
174        tmpCalib[1][] = 8
175        tmpCalib[2][] = 0
176       
177        V_writeDetTube_spatialCalib(filename,"FR",tmpCalib)
178        V_writeDetTube_spatialCalib(filename,"FL",tmpCalib)
179        V_writeDetTube_spatialCalib(filename,"MR",tmpCalib)
180        V_writeDetTube_spatialCalib(filename,"ML",tmpCalib)
181
182        // for the "short" T/B banks
183        tmpCalib[0][] = -256
184        tmpCalib[1][] = 4
185        tmpCalib[2][] = 0
186       
187        V_writeDetTube_spatialCalib(filename,"FT",tmpCalib)
188        V_writeDetTube_spatialCalib(filename,"FB",tmpCalib)
189        V_writeDetTube_spatialCalib(filename,"MT",tmpCalib)
190        V_writeDetTube_spatialCalib(filename,"MB",tmpCalib)
191       
192        KillWaves tmpCalib
193       
194        // and for the back detector "B"
195        Make/O/D/N=3 tmpCalib
196        tmpCalib[0] = 1
197        tmpCalib[1] = 1
198        tmpcalib[2] = 10000
199        V_writeDet_cal_x(filename,"B",tmpCalib)
200        V_writeDet_cal_y(filename,"B",tmpCalib)
201
202        KillWaves tmpCalib
203
204        return(0)
205end
206
207// TODO -- need a function to write out "bad" and "perfect" dead time values
208// to the HDF file
209//V_writeDetector_deadtime(fname,detStr,inW)
210//V_writeDetector_deadtime_B(fname,detStr,val)
211// simulated count rate per tube can be Å 10^8, so I need dt >> 10^-15 to completely cancel this out
212// (partly due to fake I(q), fake count time in file...)
213
214// writes out "perfect" dead time constants for all 8 tube banks + back detector
215Function V_WritePerfectDeadTime(filename)
216        String filename
217               
218        Make/O/D/N=(48) tmpDT
219        tmpDT = 1e-18
220        V_writeDetector_deadtime(filename,"FT",tmpDT)
221        V_writeDetector_deadtime(filename,"FB",tmpDT)
222        V_writeDetector_deadtime(filename,"FL",tmpDT)
223        V_writeDetector_deadtime(filename,"FR",tmpDT)
224        V_writeDetector_deadtime(filename,"MT",tmpDT)
225        V_writeDetector_deadtime(filename,"MB",tmpDT)
226        V_writeDetector_deadtime(filename,"ML",tmpDT)
227        V_writeDetector_deadtime(filename,"MR",tmpDT)
228
229
230        // and for the back detector "B", a single value, not a wave
231        V_writeDetector_deadtime_B(filename,"B",1e-20)
232
233        KillWaves tmpDT
234
235        return(0)
236end
237
238
239Function V_FakeBeamCenters()
240// fake beam center values
241        V_putDet_beam_center_x("RAW","B",75)
242        V_putDet_beam_center_y("RAW","B",75)
243
244        V_putDet_beam_center_x("RAW","MB",64)
245        V_putDet_beam_center_y("RAW","MB",55)
246        V_putDet_beam_center_x("RAW","MT",64)
247        V_putDet_beam_center_y("RAW","MT",-8.1)
248        V_putDet_beam_center_x("RAW","MR",-8.1)
249        V_putDet_beam_center_y("RAW","MR",64)
250        V_putDet_beam_center_x("RAW","ML",55)
251        V_putDet_beam_center_y("RAW","ML",64)
252
253        V_putDet_beam_center_x("RAW","FB",64)
254        V_putDet_beam_center_y("RAW","FB",55)
255        V_putDet_beam_center_x("RAW","FT",64)
256        V_putDet_beam_center_y("RAW","FT",-8.7)
257        V_putDet_beam_center_x("RAW","FR",-8.1)
258        V_putDet_beam_center_y("RAW","FR",64)
259        V_putDet_beam_center_x("RAW","FL",55)
260        V_putDet_beam_center_y("RAW","FL",64)
261       
262        return(0)
263end
264
265Function V_FakeScaleToCenter()
266
267        V_RescaleToBeamCenter("RAW","MB",64,55)
268        V_RescaleToBeamCenter("RAW","MT",64,-8.7)
269        V_RescaleToBeamCenter("RAW","MR",-8.1,64)
270        V_RescaleToBeamCenter("RAW","ML",55,64)
271        V_RescaleToBeamCenter("RAW","FL",55,64)
272        V_RescaleToBeamCenter("RAW","FR",-8.1,64)
273        V_RescaleToBeamCenter("RAW","FT",64,-8.7)
274        V_RescaleToBeamCenter("RAW","FB",64,55)
275       
276        return(0)
277End
278
279//
280// a few utilities to patch up the data files so that they are useable
281// even without the Back detector containing real data
282//
283// TODO
284//
285// Hopefully, the data files as generated from NICE will have a dummy for the back detector
286// if not, there's going to be a big mess
287//
288//              V_writeDetectorData(fileName,detStr,tmpData)
289//
290Function V_Write_BackDet_to_VSANSFile()
291       
292        String fileName = V_DoSaveFileDialog("pick the file to write to")
293        print fileName
294//     
295        String detStr = "B"
296       
297        if(strlen(fileName) > 0)
298                Wave detW = V_getDetectorDataW(filename,detStr)
299                detW = 1
300                V_writeDetectorData(fileName,detStr,detW)
301        endif
302End
303
Note: See TracBrowser for help on using the repository browser.