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

Last change on this file since 1248 was 1242, checked in by srkline, 3 years ago

updating the IgorVersion? pragma to v7.0 for all files to be consistent.

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