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

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

Minor changes to the function of the Beam Center panel so that it made sense, and would untimately allow writing the new center values to a data file on disk

Other cosetic changes to some of the panels

File size: 7.7 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//
31//
32
33
34/// TODO:
35// -- this is the basic renormalization that is done in PRODIV. see that file for all of the
36//    details of how it's used
37// -- update to VSANS file locations and data reads
38// -- expand this to do a basic renormalization of all 9 panels, and move the data into the
39//    appropriate locations for saving as a DIV file.
40//
41//
42
43
44// Basic function:
45// -- first, reduce the data (to the COR level?)
46// -- next, V_NormalizeDIV()
47// -- then Setup_VSANS_DIV_Struct()
48// -- next, V_CopyDIVToSave()
49// -- last, Save_VSANS_DIV_Nexus()
50
51
52
53
54//
55// Normalizes each panel independently
56// Normalizes in-place, replacing whatever was there
57//
58// type is the work folder where the (? corrected) data is currently
59//
60// TODO
61// -- data should be copied to some alternate work folder before this step
62//
63Function V_NormalizeDIV(type)
64        String type
65
66        Variable ii,totCts,pixelX,pixelY
67        String detStr
68
69        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
70                detStr = StringFromList(ii, ksDetectorListAll, ";")
71                Wave w = V_getDetectorDataW(type,detStr)
72                Wave w_err = V_getDetectorDataErrW(type,detStr)
73                pixelX = V_getDet_pixel_num_x(type,detStr)
74                pixelY = V_getDet_pixel_num_y(type,detStr)
75
76                totCts=sum(w,Inf,-Inf)          //sum all of the data
77               
78                w /= totCts
79                w *= pixelX*pixelY
80
81                w_err /= totCts
82                w_err *= pixelX*pixelY
83               
84        endfor
85       
86        return(0)
87End
88
89
90
91Function V_CopyDIVToSave(type)
92        String type
93       
94        Variable ii,totCts,pixelX,pixelY
95        String detStr
96        String topath = "root:VSANS_DIV_file:entry:instrument:detector_"
97        String fromPath = "root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"
98       
99       
100        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
101                detStr = StringFromList(ii, ksDetectorListAll, ";")
102
103                Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
104                Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
105               
106        endfor
107       
108        return(0)
109End
110
111
112
113
114
115// TODO
116// currently, there are no dummy fill values or attributes for the fake DIV file
117//
118Proc Setup_VSANS_DIV_Struct()
119
120        // lays out the tree and fills with dummy values
121        H_Setup_VSANS_DIV_Structure()
122       
123        // writes in the attributes
124//      H_Fill_VSANS_Attributes()
125       
126        // fill in with VCALC simulation bits
127//      H_Fill_VSANS_wSim()
128       
129End
130
131Proc Save_VSANS_DIV_Nexus(fileName)
132        String fileName="Test_VSANS_DIV_file"
133
134        // save as HDF5 (no attributes saved yet)
135        Save_VSANS_file("root:VSANS_DIV_file", fileName+".h5")
136       
137//      // read in a data file using the gateway-- reads from the home path
138//      H_HDF5Gate_Read_Raw(fileName+".h5")
139//     
140//      // after reading in a "partial" file using the gateway (to generate the xref)
141//      // Save the xref to disk (for later use)
142//      Save_HDF5___xref("root:"+fileName,"HDF5___xref")
143//     
144//      // after you've generated the HDF5___xref, load it in and copy it
145//      // to the necessary folder location.
146//      Copy_HDF5___xref("root:VSANS_DIV_file", "HDF5___xref")
147//     
148//      // writes out the contents of a data folder using the gateway
149//      H_HDF5Gate_Write_Raw("root:VSANS_DIV_file", fileName+".h5")
150//
151//      // re-load the data file using the gateway-- reads from the home path
152//      // now with attributes
153//      H_HDF5Gate_Read_Raw(fileName+".h5")
154       
155End
156
157////////////// fake DIV file tests
158//
159//
160//      Make/O/T/N=1    file_name       = "VSANS_DIV_test.h5"
161//
162// simple generation of a fake div file. for sans, nothing other than the creation date was written to the
163// file header. nothing more is needed (possibly)
164//
165// TODO -- I want to re-visit the propagation of errors in the DIV file. No errors are ever calculated/saved
166//   during the generation of the file, but there's no reason it couldn't. the idea is that the plex
167//   is counted so long that the errors are insignificant compared to the data errors, but that may not
168//   always be the case. A bit of math may prove this. or not. Plus, the situation for VSANS may be different.
169//
170//
171// TODO -- make the number of pixels GLOBAL
172// TODO -- there will be lots of work to do to develop the procedures necessary to actually generate the
173//      9 data sets to become the DIV file contents. More complexity here than for the simple SANS case.
174//
175Proc H_Setup_VSANS_DIV_Structure()
176       
177        NewDataFolder/O/S root:VSANS_DIV_file           
178
179        NewDataFolder/O/S root:VSANS_DIV_file:entry     
180                Make/O/T/N=1    title   = "This is a DIV file for VSANS: VSANS_DIV"
181                Make/O/T/N=1    start_date      = "2015-02-28T08:15:30-5:00"
182                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument         
183                        Make/O/T/N=1    name    = "NG3_VSANS"
184                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_B       
185                        Make/O/D/N=(150,150)    data    = 1 + (enoise(0.1))
186                        Make/O/D/N=(150,150)    linear_data_error       = 0.01*abs(gnoise(1))
187                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MR             
188                        Make/O/D/N=(48,128)     data
189                        data[][0] = 1+enoise(0.1)
190                        data[][] = data[p][0]
191                        Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
192                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_ML             
193                        Make/O/D/N=(48,128)     data
194                        data[][0] = 1+enoise(0.1)
195                        data[][] = data[p][0]
196                        Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
197                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MT             
198                        Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
199                        Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
200                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MB             
201                        Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
202                        Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
203                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FR             
204                        Make/O/D/N=(48,128)     data
205                        data[][0] = 1+enoise(0.1)
206                        data[][] = data[p][0]
207                        Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
208                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FL             
209                        Make/O/D/N=(48,128)     data
210                        data[][0] = 1+enoise(0.1)
211                        data[][] = data[p][0]
212                        Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
213                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FT             
214                        Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
215                        Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
216                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FB             
217                        Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
218                        Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
219               
220                // fake, empty folders so that the generic loaders can be used
221                NewDataFolder/O root:VSANS_DIV_file:entry:DAS_logs
222                NewDataFolder/O root:VSANS_DIV_file:entry:control
223                NewDataFolder/O root:VSANS_DIV_file:entry:reduction
224                NewDataFolder/O root:VSANS_DIV_file:entry:sample
225                NewDataFolder/O root:VSANS_DIV_file:entry:user
226
227                       
228        SetDataFolder root:
229
230End
Note: See TracBrowser for help on using the repository browser.