source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_DIVUtils.ipf @ 1061

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

Added USANS loader/initializer

Updated units of distance for q-calculation (SDD)

status display bug fixed

File size: 8.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3//
4// ********
5// TODO -- this is an incomplete DIV file. need to identify how to generate a real DIV file
6//     for the different detectors, and how to fill it into a file.
7//    Not sure how it will be measured in practice on VSANS.
8//
9//   JAN 2017
10//
11// TODO:
12// -- complete the description of the steps needed...
13// Data needs to be reduced to the "COR" level - that means that the
14// PLEX data has been added to work files, and the empty and blocked beam have been
15// subtracted off.
16// -- but what detector corrections should/ should not be done?
17// -- non-linear corrections are not needed, since this will strictly be a per-pixel correction
18// -- solid angle?
19// -- dead time?
20// -- efficiency?
21// -- large angle transmission?
22//
23// we may need to think more carefully about some of these since the front carriage may need to be
24// closer than the nominal 4m distance on SANS that was deemed far enough back to be "safe" from
25// the high angle issues.
26//
27// -- what about the T/B panels? Since a large chunk of these detectors may be obscured,
28//   the normalization will be way off -- and the "active" area will end up much larger
29//   than it should be - since the wings of the detector are mostly zero...
30//   ? Can I apply a mask, or will the detectors be set in a different configuration?
31//
32//
33
34
35/// TODO:
36// -- this is the basic renormalization that is done in PRODIV. see that file for all of the
37//    details of how it's used
38// -- update to VSANS file locations and data reads
39// -- expand this to do a basic renormalization of all 9 panels, and move the data into the
40//    appropriate locations for saving as a DIV file.
41// x- (YES, done) what about error propogation? Can I store the error in the data file?
42//    Makes a difference if the DIV is not collected for long "enough".
43// x- then I need to be able to read the error in (done)
44//
45
46
47// Basic function:
48// -- first, reduce the data (to the COR level?)
49// -- next, V_NormalizeDIV()
50// -- then Setup_VSANS_DIV_Struct()
51// -- next, V_CopyDIVToSave() -or- V_CopyDIVToSave_OnePanel()
52// -- last, Save_VSANS_DIV_Nexus()
53//
54
55
56
57//
58// Normalizes each panel independently
59// Normalizes in-place, replacing whatever was there
60//
61// type is the work folder where the (? corrected) data is currently
62//
63// TODO
64// -- data should be copied to some alternate work folder before this step
65// -- for T/B detectors, this may not work as intended if the whole detector is not illuminated.
66//    How to handle? A mask?
67// x- is this the correct calculation of the error? (YES) It should be correct up to this point since the
68//    standard reduction has been used, but now the normalization step is a multiplication
69//    by a constant (w/no error). Be sure this error transformation is correct. (YES - this is correct, and is
70//    what is done in SANS)
71//
72Function V_NormalizeDIV(type)
73        String type
74
75        Variable ii,totCts,pixelX,pixelY
76        String detStr
77
78        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
79                detStr = StringFromList(ii, ksDetectorListAll, ";")
80                Wave w = V_getDetectorDataW(type,detStr)
81                Wave w_err = V_getDetectorDataErrW(type,detStr)
82                pixelX = V_getDet_pixel_num_x(type,detStr)
83                pixelY = V_getDet_pixel_num_y(type,detStr)
84
85                totCts = sum(w,Inf,-Inf)                //sum all of the data
86               
87                w /= totCts
88                w *= pixelX*pixelY
89
90                w_err /= totCts
91                w_err *= pixelX*pixelY
92               
93        endfor
94       
95        return(0)
96End
97
98
99// copies an entire work folder, all 9 detectors (at COR level)
100// to the DIV structure to write out
101//
102Function V_CopyDIVToSave(type)
103        String type
104       
105        Variable ii,totCts,pixelX,pixelY
106        String detStr
107        String topath = "root:VSANS_DIV_file:entry:instrument:detector_"
108        String fromPath = "root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"
109       
110       
111        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
112                detStr = StringFromList(ii, ksDetectorListAll, ";")
113
114                Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
115                Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
116               
117        endfor
118       
119        return(0)
120End
121
122//
123// copies only the specified panel from a work folder, (at COR level)
124// to the DIV structure to write out
125//
126// used to replace a single panel, or to fill in carriage by carriage.
127//
128Function V_CopyDIVToSave_OnePanel(type,detStr)
129        String type,detStr
130       
131        Variable ii,totCts,pixelX,pixelY
132        String topath = "root:VSANS_DIV_file:entry:instrument:detector_"
133        String fromPath = "root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"
134       
135       
136                Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
137                Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
138                       
139        return(0)
140End
141
142
143
144
145// TODO
146// currently, there are no dummy fill values or attributes for the fake DIV file
147//
148Proc Setup_VSANS_DIV_Struct()
149
150        // lays out the tree and fills with dummy values
151        H_Setup_VSANS_DIV_Structure()
152       
153        // writes in the attributes
154//      H_Fill_VSANS_Attributes()
155       
156        // fill in with VCALC simulation bits
157//      H_Fill_VSANS_wSim()
158       
159End
160
161Proc Save_VSANS_DIV_Nexus(fileName)
162        String fileName="Test_VSANS_DIV_file"
163
164        // save as HDF5 (no attributes saved yet)
165        Save_VSANS_file("root:VSANS_DIV_file", fileName+".h5")
166       
167//      // read in a data file using the gateway-- reads from the home path
168//      H_HDF5Gate_Read_Raw(fileName+".h5")
169//     
170//      // after reading in a "partial" file using the gateway (to generate the xref)
171//      // Save the xref to disk (for later use)
172//      Save_HDF5___xref("root:"+fileName,"HDF5___xref")
173//     
174//      // after you've generated the HDF5___xref, load it in and copy it
175//      // to the necessary folder location.
176//      Copy_HDF5___xref("root:VSANS_DIV_file", "HDF5___xref")
177//     
178//      // writes out the contents of a data folder using the gateway
179//      H_HDF5Gate_Write_Raw("root:VSANS_DIV_file", fileName+".h5")
180//
181//      // re-load the data file using the gateway-- reads from the home path
182//      // now with attributes
183//      H_HDF5Gate_Read_Raw(fileName+".h5")
184       
185End
186
187////////////// fake DIV file tests
188//
189//
190//      Make/O/T/N=1    file_name       = "VSANS_DIV_test.h5"
191//
192// simple generation of a fake div file. for sans, nothing other than the creation date was written to the
193// file header. nothing more is needed (possibly)
194//
195// TODO -- I want to re-visit the propagation of errors in the DIV file. No errors are ever calculated/saved
196//   during the generation of the file, but there's no reason it couldn't. the idea is that the plex
197//   is counted so long that the errors are insignificant compared to the data errors, but that may not
198//   always be the case. A bit of math may prove this. or not. Plus, the situation for VSANS may be different.
199//
200//
201// TODO -- make the number of pixels GLOBAL
202//
203Proc H_Setup_VSANS_DIV_Structure()
204       
205        NewDataFolder/O/S root:VSANS_DIV_file           
206
207        NewDataFolder/O/S root:VSANS_DIV_file:entry     
208                Make/O/T/N=1    title   = "This is a DIV file for VSANS: VSANS_DIV"
209                Make/O/T/N=1    start_date      = "2015-02-28T08:15:30-5:00"
210                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument         
211                        Make/O/T/N=1    name    = "NG3_VSANS"
212                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_B       
213                        Make/O/D/N=(150,150)    data    = 1 + (enoise(0.1))
214                        Make/O/D/N=(150,150)    linear_data_error       = 0.01*abs(gnoise(1))
215                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MR             
216                        Make/O/D/N=(48,128)     data
217                        data[][0] = 1+enoise(0.1)
218                        data[][] = data[p][0]
219                        Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
220                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_ML             
221                        Make/O/D/N=(48,128)     data
222                        data[][0] = 1+enoise(0.1)
223                        data[][] = data[p][0]
224                        Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
225                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MT             
226                        Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
227                        Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
228                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MB             
229                        Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
230                        Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
231                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FR             
232                        Make/O/D/N=(48,128)     data
233                        data[][0] = 1+enoise(0.1)
234                        data[][] = data[p][0]
235                        Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
236                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FL             
237                        Make/O/D/N=(48,128)     data
238                        data[][0] = 1+enoise(0.1)
239                        data[][] = data[p][0]
240                        Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
241                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FT             
242                        Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
243                        Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
244                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FB             
245                        Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
246                        Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
247               
248                // fake, empty folders so that the generic loaders can be used
249                NewDataFolder/O root:VSANS_DIV_file:entry:DAS_logs
250                NewDataFolder/O root:VSANS_DIV_file:entry:control
251                NewDataFolder/O root:VSANS_DIV_file:entry:reduction
252                NewDataFolder/O root:VSANS_DIV_file:entry:sample
253                NewDataFolder/O root:VSANS_DIV_file:entry:user
254
255                       
256        SetDataFolder root:
257
258End
Note: See TracBrowser for help on using the repository browser.