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

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

extensive changes to accomodate 1x1 binning of the HighRes? detector. It is implemented as a global flag. Currently only 4x4 and 1x1 are allowed. 1x1 has never been tested in reality, only simulated data - so my assumed dimensions may not be correct. look for TODOHIGHRES in the file for places that may need to be updated for different file dimensions. Testing of the simulated data is proving to be excruciatingly slow, but passable for a test. Speed optimization will be needed if this is the final solution. Memory management will also be an issue since every "copy" of the highRes matrix is enormous. Carry as few of these around as possible in the future to keep the experiment size to something reasonable.

File size: 10.6 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_VerticalOffset(fileName,detStr,val)          // T/B panels
67                else
68                        V_writeDet_LateralOffset(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                        // the back detector always has its beam center in pixels
89                        V_writeDet_beam_center_x(fileName,detStr,V_getDet_beam_center_x("VCALC",detStr))
90                        V_writeDet_beam_center_y(fileName,detStr,V_getDet_beam_center_y("VCALC",detStr))       
91                       
92                        // write out the number of pixels x and y
93                        // patch n_pix_x and y
94                        V_writeDet_pixel_num_x(fileName,detStr,V_getDet_pixel_num_x("VCALC",detStr))
95                        V_writeDet_pixel_num_y(fileName,detStr,V_getDet_pixel_num_y("VCALC",detStr))                   
96                endif
97
98               
99               
100                // the calibration data for each detector (except B) is already correct in the "base" file
101                //V_writeDetTube_spatialCalib(fname,detStr,inW)
102                // and for "B"
103                //V_writeDet_cal_x(fname,detStr,inW)
104                //V_writeDet_cal_y(fname,detStr,inW)
105               
106                               
107                // the dead time for each detector is already correct in the "base" file
108                // V_writeDetector_deadtime(fname,detStr,inW)
109                // TODO: need a new, separate function to write the single deadtime value in/out of "B"
110               
111                // integrated count value on each detector bank
112                sumCts += sum(tmpData)
113                V_writeDet_IntegratedCount(fileName,detStr,sum(tmpData))
114
115        endfor
116
117       
118// writes out "perfect" detector calibration constants for all 8 tube banks + back detector
119        V_WritePerfectSpatialCalib(filename)
120// writes out "perfect" dead time constants for all 8 tube banks + back detector
121        V_WritePerfectDeadTime(filename)
122       
123//? other detector geometry - lateral separation?
124
125// the wavelength
126//      Variable lam = V_getWavelength("VCALC")         //doesn't work, the corresponding folder in VCALC has not been defined
127        V_writeWavelength(fileName,VCALC_getWavelength())
128
129       
130// fake the information about the count setup, so I have different numbers to read
131// count time = fake time of 100 s
132        V_writeCount_time(fileName,100)
133
134        // monitor count (= imon)
135                // returns the number of neutrons on the sample
136                //Function VCALC_getImon()
137                //
138                // divide the monitor count by 1e8 to get a number small enough to write in the field.
139        V_writeBeamMonNormData(fileName,VCALC_getImon()/1e8)
140
141        // total detector count (sum of everything)
142        V_writeDetector_counts(fileName,sumCts)
143
144        // sample description
145        V_writeSampleDescription(fileName,labelStr)
146       
147        // reduction intent
148        V_writeReductionIntent(fileName,intent)
149       
150        // reduction group_id
151        // TODO x- (file has been corected)skip for now. group_id is incorrectly written to the data file as a text value. trac ticket
152        //        has been written to fix in the future.
153        V_writeSample_GroupID(fileName,group_id)
154
155
156
157// ?? anything else that I'd like to see on the catalog - I could change them here to see different values
158// different collimation types?
159//
160
161
162
163        return(0)
164end
165
166
167
168// writes out "perfect" detector calibration constants for all 8 tube banks + back detector
169Function V_WritePerfectSpatialCalib(filename)
170        String filename
171       
172//      String fileName = V_DoSaveFileDialog("pick the file to write to")
173       
174        Make/O/D/N=(3,48) tmpCalib
175        // for the "tall" L/R banks
176        tmpCalib[0][] = -512
177        tmpCalib[1][] = 8
178        tmpCalib[2][] = 0
179       
180        V_writeDetTube_spatialCalib(filename,"FR",tmpCalib)
181        V_writeDetTube_spatialCalib(filename,"FL",tmpCalib)
182        V_writeDetTube_spatialCalib(filename,"MR",tmpCalib)
183        V_writeDetTube_spatialCalib(filename,"ML",tmpCalib)
184
185        // for the "short" T/B banks
186        tmpCalib[0][] = -256
187        tmpCalib[1][] = 4
188        tmpCalib[2][] = 0
189       
190        V_writeDetTube_spatialCalib(filename,"FT",tmpCalib)
191        V_writeDetTube_spatialCalib(filename,"FB",tmpCalib)
192        V_writeDetTube_spatialCalib(filename,"MT",tmpCalib)
193        V_writeDetTube_spatialCalib(filename,"MB",tmpCalib)
194       
195        KillWaves tmpCalib
196       
197        // and for the back detector "B"
198        NVAR gHighResBinning = root:Packages:NIST:VSANS:Globals:gHighResBinning
199        Variable tmpPix
200        if(gHighResBinning == 1)
201                tmpPix = 0.00845                //[cm]
202        else
203                //binning 4x4 assumed
204                tmpPix = 0.034
205        endif
206       
207        Make/O/D/N=3 tmpCalib
208        tmpCalib[0] = tmpPix
209        tmpCalib[1] = 1
210        tmpcalib[2] = 10000
211        V_writeDet_cal_x(filename,"B",tmpCalib)
212        V_writeDet_cal_y(filename,"B",tmpCalib)
213
214        KillWaves tmpCalib
215
216        return(0)
217end
218
219// TODO -- need a function to write out "bad" and "perfect" dead time values
220// to the HDF file
221//V_writeDetector_deadtime(fname,detStr,inW)
222//V_writeDetector_deadtime_B(fname,detStr,val)
223// simulated count rate per tube can be Å 10^8, so I need dt >> 10^-15 to completely cancel this out
224// (partly due to fake I(q), fake count time in file...)
225
226// writes out "perfect" dead time constants for all 8 tube banks + back detector
227Function V_WritePerfectDeadTime(filename)
228        String filename
229               
230        Make/O/D/N=(48) tmpDT
231        tmpDT = 1e-18
232        V_writeDetector_deadtime(filename,"FT",tmpDT)
233        V_writeDetector_deadtime(filename,"FB",tmpDT)
234        V_writeDetector_deadtime(filename,"FL",tmpDT)
235        V_writeDetector_deadtime(filename,"FR",tmpDT)
236        V_writeDetector_deadtime(filename,"MT",tmpDT)
237        V_writeDetector_deadtime(filename,"MB",tmpDT)
238        V_writeDetector_deadtime(filename,"ML",tmpDT)
239        V_writeDetector_deadtime(filename,"MR",tmpDT)
240
241
242        // and for the back detector "B", a single value, not a wave
243        V_writeDetector_deadtime_B(filename,"B",1e-20)
244
245        KillWaves tmpDT
246
247        return(0)
248end
249
250
251Function V_FakeBeamCenters()
252// fake beam center values
253        V_putDet_beam_center_x("RAW","B",75)
254        V_putDet_beam_center_y("RAW","B",75)
255
256        V_putDet_beam_center_x("RAW","MB",64)
257        V_putDet_beam_center_y("RAW","MB",55)
258        V_putDet_beam_center_x("RAW","MT",64)
259        V_putDet_beam_center_y("RAW","MT",-8.1)
260        V_putDet_beam_center_x("RAW","MR",-8.1)
261        V_putDet_beam_center_y("RAW","MR",64)
262        V_putDet_beam_center_x("RAW","ML",55)
263        V_putDet_beam_center_y("RAW","ML",64)
264
265        V_putDet_beam_center_x("RAW","FB",64)
266        V_putDet_beam_center_y("RAW","FB",55)
267        V_putDet_beam_center_x("RAW","FT",64)
268        V_putDet_beam_center_y("RAW","FT",-8.7)
269        V_putDet_beam_center_x("RAW","FR",-8.1)
270        V_putDet_beam_center_y("RAW","FR",64)
271        V_putDet_beam_center_x("RAW","FL",55)
272        V_putDet_beam_center_y("RAW","FL",64)
273       
274        return(0)
275end
276
277Function V_FakeScaleToCenter()
278
279        V_RescaleToBeamCenter("RAW","MB",64,55)
280        V_RescaleToBeamCenter("RAW","MT",64,-8.7)
281        V_RescaleToBeamCenter("RAW","MR",-8.1,64)
282        V_RescaleToBeamCenter("RAW","ML",55,64)
283        V_RescaleToBeamCenter("RAW","FL",55,64)
284        V_RescaleToBeamCenter("RAW","FR",-8.1,64)
285        V_RescaleToBeamCenter("RAW","FT",64,-8.7)
286        V_RescaleToBeamCenter("RAW","FB",64,55)
287       
288        return(0)
289End
290
291//
292// a few utilities to patch up the data files so that they are useable
293// even without the Back detector containing real data
294//
295// TODO
296//
297// Hopefully, the data files as generated from NICE will have a dummy for the back detector
298// if not, there's going to be a big mess
299//
300//              V_writeDetectorData(fileName,detStr,tmpData)
301//
302Function V_Write_BackDet_to_VSANSFile()
303       
304        String fileName = V_DoSaveFileDialog("pick the file to write to")
305        print fileName
306//     
307        String detStr = "B"
308       
309        if(strlen(fileName) > 0)
310                Wave detW = V_getDetectorDataW(filename,detStr)
311                detW = 1
312                V_writeDetectorData(fileName,detStr,detW)
313        endif
314End
315
316
317
318
319//////
320
321//
322// Function Profiling
323//
324// tests for where the speed bottlenecks are hiding
325//
326// in the built-in procedure, add the line:
327//#include <FunctionProfiling>
328// and check out the instructions in that file.
329//
330// essentially, create a function call with no parameters
331// and run that function as below:
332
333// RunFuncWithProfiling(yourFuncHere)
334
335//
336// function to profile can have no parameters, so hard-wire the file name
337Function V_ProfileFileLoad()
338        V_LoadHDF5Data("sans9999.nxs.ngv","RAW")
339End
340
341
342Function V_ProfileReduceOne()
343        V_ReduceOneButton("")
344End
345
346
347
348
Note: See TracBrowser for help on using the repository browser.