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

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

many changes to the VCALC code and a few changes to the main code to get the units consistent, and centimeters everywhere possible. The real space distance array and the non-linear calibrations are still defined and calculated in mm. This can hopefully be changed in the future. Some constants in the data file will need to be updated to cm, such as the T/B setback, which has been confirmed to be 41.0 cm

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