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

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

Significant changes to the base READ of individual data fields from data files. Now, if the field requested is from a WORK file, and it does not exist, an error condition is returned (or a null wave). Calling procedures are responsible for handling errors. This prevents a string of open file dialogs if fields are missing from a file if they were never in the file to begin with (like sensor logs, polarization hardware, etc.)

New get/write calls were added for the updated temperature sensor fields.

group_ID is now only in the sample block, not the duplicated in the reduction block, and is correctly a number not a string.

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