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

Last change on this file since 1055 was 1055, checked in by srkline, 5 years ago

LOTS of changes to accommodate the beam center being reported in cm rather than pixels. Required a lot of changes to VCALC (to fill in simulated data), and in the reading and interpreting of data for display, and most importantly, the calculation of q.

There may still be a few residual bugs with this. I am still re-testing with new sample data sets.

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