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

Last change on this file was 1249, checked in by srkline, 2 years ago

minor changes - can't find the diff command in TortoiseSVN...

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