- Timestamp:
- Feb 10, 2016 3:19:54 PM (7 years ago)
- Location:
- sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/Nexus_VSANS_Write.ipf
r963 r979 202 202 203 203 ////////////// fake DIV file tests 204 204 // 205 205 // 206 206 // Make/O/T/N=1 file_name = "VSANS_DIV_test.h5" … … 209 209 // file header. nothing more is needed (possibly) 210 210 // 211 // TODO -- I want to re-visit the prop agation of errors in the DIV file. No errors are ever calculated/saved211 // TODO -- I want to re-visit the propogation of errors in the DIV file. No errors are ever calculated/saved 212 212 // during the generation of the file, but there's no reason it couldn't. the idea is that the plex 213 213 // is counted so long that the errors are insignificant compared to the data errors, but that may not … … 215 215 // 216 216 // 217 //218 217 // TODO -- make the number of pixels GLOBAL 219 218 // … … 222 221 NewDataFolder/O/S root:VSANS_DIV_file 223 222 224 NewDataFolder/O/S root:VSANS_DIV_file:entry 1225 Make/O/T/N=1 title = " title of entry1"223 NewDataFolder/O/S root:VSANS_DIV_file:entry 224 Make/O/T/N=1 title = "This is a fake DIV file for VSANS" 226 225 Make/O/T/N=1 start_date = "2015-02-28T08:15:30-5:00" 227 NewDataFolder/O/S root:VSANS_DIV_file:entry 1:instrument228 Make/O/T/N=1 name = "NG B30mSANS"229 NewDataFolder/O/S root:VSANS_DIV_file:entry 1:data_B230 Make/O/ I/N=(320,320) data = trunc(abs(gnoise(p+q)))226 NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument 227 Make/O/T/N=1 name = "NG3_VSANS" 228 NewDataFolder/O/S root:VSANS_DIV_file:entry:data_B 229 Make/O/D/N=(320,320) data = abs(gnoise(p+q)) 231 230 Make/O/D/N=(320,320) error = 0.01*abs(gnoise(p+q)) 232 NewDataFolder/O/S root:VSANS_DIV_file:entry 1:data_MR233 Make/O/ I/N=(48,256) data = trunc(abs(gnoise(p+q)))234 Make/O/D/N=(48,256) error = 0.01*abs(gnoise(p+q)) 235 NewDataFolder/O/S root:VSANS_DIV_file:entry 1:data_ML236 Make/O/ I/N=(48,256) data = trunc(abs(gnoise(p+q)))237 Make/O/D/N=(48,256) error = 0.01*abs(gnoise(p+q)) 238 NewDataFolder/O/S root:VSANS_DIV_file:entry 1:data_MT239 Make/O/ I/N=(128,48) data = trunc(abs(gnoise(p+q)))240 Make/O/D/N=(128,48) error = 0.01*abs(gnoise(p+q)) 241 NewDataFolder/O/S root:VSANS_DIV_file:entry 1:data_MB242 Make/O/ I/N=(128,48) data = trunc(abs(gnoise(p+q)))243 Make/O/D/N=(128,48) error = 0.01*abs(gnoise(p+q)) 244 NewDataFolder/O/S root:VSANS_DIV_file:entry 1:data_FR245 Make/O/ I/N=(48,256) data = trunc(abs(gnoise(p+q)))246 Make/O/D/N=(48,256) error = 0.01*abs(gnoise(p+q)) 247 NewDataFolder/O/S root:VSANS_DIV_file:entry 1:data_FL248 Make/O/ I/N=(48,256) data = trunc(abs(gnoise(p+q)))249 Make/O/D/N=(48,256) error = 0.01*abs(gnoise(p+q)) 250 NewDataFolder/O/S root:VSANS_DIV_file:entry 1:data_FT251 Make/O/ I/N=(128,48) data = trunc(abs(gnoise(p+q)))252 Make/O/D/N=(128,48) error = 0.01*abs(gnoise(p+q)) 253 NewDataFolder/O/S root:VSANS_DIV_file:entry 1:data_FB254 Make/O/ I/N=(128,48) data = trunc(abs(gnoise(p+q)))231 NewDataFolder/O/S root:VSANS_DIV_file:entry:data_MR 232 Make/O/D/N=(48,256) data = abs(gnoise(p+q)) 233 Make/O/D/N=(48,256) error = 0.01*abs(gnoise(p+q)) 234 NewDataFolder/O/S root:VSANS_DIV_file:entry:data_ML 235 Make/O/D/N=(48,256) data = abs(gnoise(p+q)) 236 Make/O/D/N=(48,256) error = 0.01*abs(gnoise(p+q)) 237 NewDataFolder/O/S root:VSANS_DIV_file:entry:data_MT 238 Make/O/D/N=(128,48) data = abs(gnoise(p+q)) 239 Make/O/D/N=(128,48) error = 0.01*abs(gnoise(p+q)) 240 NewDataFolder/O/S root:VSANS_DIV_file:entry:data_MB 241 Make/O/D/N=(128,48) data = abs(gnoise(p+q)) 242 Make/O/D/N=(128,48) error = 0.01*abs(gnoise(p+q)) 243 NewDataFolder/O/S root:VSANS_DIV_file:entry:data_FR 244 Make/O/D/N=(48,256) data = abs(gnoise(p+q)) 245 Make/O/D/N=(48,256) error = 0.01*abs(gnoise(p+q)) 246 NewDataFolder/O/S root:VSANS_DIV_file:entry:data_FL 247 Make/O/D/N=(48,256) data = abs(gnoise(p+q)) 248 Make/O/D/N=(48,256) error = 0.01*abs(gnoise(p+q)) 249 NewDataFolder/O/S root:VSANS_DIV_file:entry:data_FT 250 Make/O/D/N=(128,48) data = abs(gnoise(p+q)) 251 Make/O/D/N=(128,48) error = 0.01*abs(gnoise(p+q)) 252 NewDataFolder/O/S root:VSANS_DIV_file:entry:data_FB 253 Make/O/D/N=(128,48) data = abs(gnoise(p+q)) 255 254 Make/O/D/N=(128,48) error = 0.01*abs(gnoise(p+q)) 256 255 -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/VC_VCALCPanel_MockUp.ipf
r978 r979 692 692 693 693 // detector resolution (xy for each bank!) 694 Variable/G gMiddle_L_pixelX = 0.8 694 Variable/G gMiddle_L_pixelX = 0.84 // (cm) these tubes are vertical 695 695 Variable/G gMiddle_L_pixelY = 0.8 // (cm) 696 Variable/G gMiddle_R_pixelX = 0.8 696 Variable/G gMiddle_R_pixelX = 0.84 // (cm) 697 697 Variable/G gMiddle_R_pixelY = 0.8 // (cm) 698 698 … … 700 700 Variable/G gMiddle_T_pixelY = 0.84 // (cm) 701 701 Variable/G gMiddle_B_pixelX = 0.4 // (cm) 702 Variable/G gMiddle_B_pixelY = 0.8 702 Variable/G gMiddle_B_pixelY = 0.84 // (cm) 703 703 704 704 // number of pixels in each bank (this can be modified at acquisition time, so it must be adjustable here) -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/VSANS_Includes.ipf
r975 r979 31 31 // for fitting data to generate tube corrections 32 32 #include "V_TubeAdjustments" 33 #include "V_DetectorCorrections" 33 34 34 35 // for ISO time in Nexus files … … 49 50 // start of raw data display panel 50 51 #include "V_Test_RAW_Panel" // rename this later when it's done 51 //#include "V_WorkFileUtils" // not ready to add yet 52 #include "V_Utilities_General" // -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_DetectorCorrections.ipf
r975 r979 1 1 #pragma rtGlobals=3 // Use modern global access method and strict wave access. 2 3 2 #pragma version=1.0 3 #pragma IgorVersion=6.1 4 5 6 7 // 4 8 // functions to apply corrections to the detector panels 5 9 // 10 // these are meant to be called by the procedures that convert "raw" data to 11 // "adjusted" or corrected data sets 12 // 6 13 // may be relocated in the future 7 14 // 8 15 9 16 … … 28 35 // -- calculate + return the error contribution? 29 36 // 30 Function DeadTimeCorrectionTubes(dataW,dtW,orientation,ctTime) 31 Wave dataW,dtW 37 Function DeadTimeCorrectionTubes(dataW,data_errW,dtW,ctTime) 38 Wave dataW,data_errW,dtW 39 Variable ctTime 40 41 // do I count on the orientation as an input, or do I just figure it out on my own? 32 42 String orientation 33 Variable ctTime 34 35 // do I count on the orientation as an input, or do I just figure it out on my own? 43 Variable dimX,dimY 44 dimX = DimSize(dataW,0) 45 dimY = DimSize(dataw,1) 46 if(dimX > dimY) 47 orientation = "horizontal" 48 else 49 orientation = "vertical" 50 endif 36 51 37 52 // sum the counts in each tube and divide by time for total cr per tube … … 65 80 ///// 66 81 // 67 //68 82 // non-linear corrections to the tube pixels 69 83 // - returns the distance in mm (although this may change) 70 //71 84 // 72 85 // c0,c1,c2,pix … … 85 98 return(dist) 86 99 End 87 100 // 88 101 //// 102 103 104 105 106 107 //////////// 108 // TODO: all of below is untested code 109 // copied from SANS 110 // 111 // 112 // TODO : 113 // -- DoAlert 0,"This has not yet been updated for VSANS" 114 // 115 //performs solid angle and non-linear detector corrections to raw data as it is "added" to a work folder 116 //function is called by Raw_to_work() and Add_raw_to_work() functions 117 //works on the actual data array, assumes that is is already on LINEAR scale 118 // 119 Function DetCorr(data,data_err,realsread,doEfficiency,doTrans) 120 Wave data,data_err,realsread 121 Variable doEfficiency,doTrans 122 123 DoAlert 0,"This has not yet been updated for VSANS" 124 125 Variable xcenter,ycenter,x0,y0,sx,sx3,sy,sy3,xx0,yy0 126 Variable ii,jj,dtdist,dtdis2 127 Variable xi,xd,yd,rad,ratio,domega,xy 128 Variable lambda,trans,trans_err,lat_err,tmp_err,lat_corr 129 130 // Print "...doing jacobian and non-linear corrections" 131 132 NVAR pixelsX = root:myGlobals:gNPixelsX 133 NVAR pixelsY = root:myGlobals:gNPixelsY 134 135 //set up values to send to auxiliary trig functions 136 xcenter = pixelsX/2 + 0.5 // == 64.5 for 128x128 Ordela 137 ycenter = pixelsY/2 + 0.5 // == 64.5 for 128x128 Ordela 138 139 x0 = realsread[16] 140 y0 = realsread[17] 141 sx = realsread[10] 142 sx3 = realsread[11] 143 sy = realsread[13] 144 sy3 = realsread[14] 145 146 dtdist = 1000*realsread[18] //sdd in mm 147 dtdis2 = dtdist^2 148 149 lambda = realsRead[26] 150 trans = RealsRead[4] 151 trans_err = RealsRead[41] //new, March 2011 152 153 154 //waves to contain repeated function calls 155 Make/O/N=(pixelsX) fyy,xx,yy //Assumes square detector !!! 156 ii=0 157 do 158 xi = ii 159 // fyy[ii] = dc_fy(ii+1,sy,sy3,ycenter) 160 // xx[ii] = dc_fxn(ii+1,sx,sx3,xcenter) 161 // yy[ii] = dc_fym(ii+1,sy,sy3,ycenter) 162 ii+=1 163 while(ii<pixelsX) 164 165 Make/O/N=(pixelsX,pixelsY) SolidAngle // testing only 166 167 ii=0 168 do 169 xi = ii 170 // xd = dc_fx(ii+1,sx,sx3,xcenter)-xx0 171 jj=0 172 do 173 yd = fyy[jj]-yy0 174 //rad is the distance of pixel ij from the sample 175 //domega is the ratio of the solid angle of pixel ij versus center pixel 176 // product xy = 1 for a detector with a linear spatial response (modern Ordela) 177 // solid angle calculated, dW^3 >=1, so multiply data to raise measured values to correct values. 178 rad = sqrt(dtdis2 + xd^2 + yd^2) 179 domega = rad/dtdist 180 ratio = domega^3 181 xy = xx[ii]*yy[jj] 182 183 data[ii][jj] *= xy*ratio 184 185 solidAngle[ii][jj] = xy*ratio //testing only 186 data_err[ii][jj] *= xy*ratio //error propagation assumes that SA and Jacobian are exact, so simply scale error 187 188 189 // correction factor for detector efficiency JBG memo det_eff_cor2.doc 3/20/07 190 // correction inserted 11/2007 SRK 191 // large angle detector efficiency is >= 1 and will "bump up" the measured value at the highest angles 192 // so divide here to get the correct answer (5/22/08 SRK) 193 if(doEfficiency) 194 data[ii][jj] /= DetEffCorr(lambda,dtdist,xd,yd) 195 data_err[ii][jj] /= DetEffCorr(lambda,dtdist,xd,yd) 196 // solidAngle[ii][jj] /= DetEffCorr(lambda,dtdist,xd,yd) //testing only 197 endif 198 199 // large angle transmission calculation is <= 1 and will "bump down" the measured value at the highest angles 200 // so divide here to get the correct answer 201 if(doTrans) 202 203 if(trans<0.1 && ii==0 && jj==0) 204 Print "***transmission is less than 0.1*** and is a significant correction" 205 endif 206 207 if(trans==0) 208 if(ii==0 && jj==0) 209 Print "***transmission is ZERO*** and has been reset to 1.0 for the averaging calculation" 210 endif 211 trans = 1 212 endif 213 214 // pass in the transmission error, and the error in the correction is returned as the last parameter 215 lat_corr = LargeAngleTransmissionCorr(trans,dtdist,xd,yd,trans_err,lat_err) //moved from 1D avg SRK 11/2007 216 data[ii][jj] /= lat_corr //divide by the correction factor 217 // 218 // 219 // 220 // relative errors add in quadrature 221 tmp_err = (data_err[ii][jj]/lat_corr)^2 + (lat_err/lat_corr)^2*data[ii][jj]*data[ii][jj]/lat_corr^2 222 tmp_err = sqrt(tmp_err) 223 224 data_err[ii][jj] = tmp_err 225 226 // solidAngle[ii][jj] = lat_err 227 228 229 //solidAngle[ii][jj] = LargeAngleTransmissionCorr(trans,dtdist,xd,yd) //testing only 230 endif 231 232 jj+=1 233 while(jj<pixelsX) 234 ii+=1 235 while(ii<pixelsX) 236 237 //clean up waves 238 239 Return(0) 240 End 241 242 243 244 //distances passed in are in mm 245 // dtdist is SDD 246 // xd and yd are distances from the beam center to the current pixel 247 // 248 // TODO: 249 // -- DoAlert 0,"This has not yet been updated for VSANS" 250 // 251 Function DetEffCorr(lambda,dtdist,xd,yd) 252 Variable lambda,dtdist,xd,yd 253 254 DoAlert 0,"This has not yet been updated for VSANS" 255 256 Variable theta,cosT,ff,stAl,stHe 257 258 theta = atan( (sqrt(xd^2 + yd^2))/dtdist ) 259 cosT = cos(theta) 260 261 stAl = 0.00967*lambda*0.8 //dimensionless, constants from JGB memo 262 stHe = 0.146*lambda*2.5 263 264 ff = exp(-stAl/cosT)*(1-exp(-stHe/cosT)) / ( exp(-stAl)*(1-exp(-stHe)) ) 265 266 return(ff) 267 End 268 269 // DIVIDE the intensity by this correction to get the right answer 270 // TODO: 271 // -- DoAlert 0,"This has not yet been updated for VSANS" 272 // 273 // 274 Function LargeAngleTransmissionCorr(trans,dtdist,xd,yd,trans_err,err) 275 Variable trans,dtdist,xd,yd,trans_err,&err 276 277 DoAlert 0,"This has not yet been updated for VSANS" 278 279 //angle dependent transmission correction 280 Variable uval,arg,cos_th,correction,theta 281 282 ////this section is the trans_correct() VAX routine 283 // if(trans<0.1) 284 // Print "***transmission is less than 0.1*** and is a significant correction" 285 // endif 286 // if(trans==0) 287 // Print "***transmission is ZERO*** and has been reset to 1.0 for the averaging calculation" 288 // trans = 1 289 // endif 290 291 theta = atan( (sqrt(xd^2 + yd^2))/dtdist ) //theta at the input pixel 292 293 //optical thickness 294 uval = -ln(trans) //use natural logarithm 295 cos_th = cos(theta) 296 arg = (1-cos_th)/cos_th 297 298 // a Taylor series around uval*arg=0 only needs about 4 terms for very good accuracy 299 // correction= 1 - 0.5*uval*arg + (uval*arg)^2/6 - (uval*arg)^3/24 + (uval*arg)^4/120 300 // OR 301 if((uval<0.01) || (cos_th>0.99)) 302 //small arg, approx correction 303 correction= 1-0.5*uval*arg 304 else 305 //large arg, exact correction 306 correction = (1-exp(-uval*arg))/(uval*arg) 307 endif 308 309 Variable tmp 310 311 if(trans == 1) 312 err = 0 //no correction, no error 313 else 314 //sigT, calculated from the Taylor expansion 315 tmp = (1/trans)*(arg/2-arg^2/3*uval+arg^3/8*uval^2-arg^4/30*uval^3) 316 tmp *= tmp 317 tmp *= trans_err^2 318 tmp = sqrt(tmp) //sigT 319 320 err = tmp 321 endif 322 323 // Printf "trans error = %g\r",trans_err 324 // Printf "correction = %g +/- %g\r", correction, err 325 326 //end of transmission/pathlength correction 327 328 return(correction) 329 end 330 331 332 // 333 // TODO: 334 // -- DoAlert 0,"This has not yet been updated for VSANS" 335 // 336 //test procedure, not called anymore 337 Proc AbsoluteScaling(type,c0,c1,c2,c3,c4,c5) 338 String type 339 Variable c0=1,c1=0.1,c2=0.95,c3=0.1,c4=1,c5=32.0 340 Prompt type,"WORK data type",popup,"CAL;COR;SAM" 341 Prompt c0, "Sample Transmission" 342 Prompt c1, "Sample Thickness (cm)" 343 Prompt c2, "Standard Transmission" 344 Prompt c3, "Standard Thickness (cm)" 345 Prompt c4, "I(0) from standard fit (normalized to 1E8 monitor cts)" 346 Prompt c5, "Standard Cross-Section (cm-1)" 347 348 Variable err 349 //call the function to do the math 350 //data from "type" will be scaled and deposited in ABS 351 err = Absolute_Scale(type,c0,c1,c2,c3,c4,c5) 352 353 if(err) 354 Abort "Error in Absolute_Scale()" 355 endif 356 357 //contents are always dumped to ABS 358 type = "ABS" 359 360 String newTitle = "WORK_"+type 361 DoWindow/F SANS_Data 362 DoWindow/T SANS_Data, newTitle 363 KillStrings/Z newTitle 364 365 //need to update the display with "data" from the correct dataFolder 366 //reset the current displaytype to "type" 367 String/G root:myGlobals:gDataDisplayType=Type 368 369 fRawWindowHook() 370 371 End 372 373 // 374 // TODO: 375 // -- DoAlert 0,"This has not yet been updated for VSANS" 376 // 377 //s_ is the standard 378 //w_ is the "work" file 379 //both are work files and should already be normalized to 10^8 monitor counts 380 Function Absolute_Scale(type,w_trans,w_thick,s_trans,s_thick,s_izero,s_cross,kappa_err) 381 String type 382 Variable w_trans,w_thick,s_trans,s_thick,s_izero,s_cross,kappa_err 383 384 DoAlert 0,"This has not yet been updated for VSANS" 385 386 //convert the "type" data to absolute scale using the given standard information 387 //copying the "type" waves to ABS 388 389 //check for existence of data, rescale to linear if needed 390 String destPath 391 //check for "type" 392 if(WaveExists($("root:Packages:NIST:"+Type + ":data")) == 0) 393 Print "There is no work file in "+type+"--Aborting" 394 Return(1) //error condition 395 Endif 396 //check for log-scaling of the "type" data and adjust if necessary 397 destPath = "root:Packages:NIST:"+Type 398 NVAR gIsLogScale = $(destPath + ":gIsLogScale") 399 if(gIsLogScale) 400 Duplicate/O $(destPath + ":linear_data") $(destPath + ":data")//back to linear scale 401 Variable/G $(destPath + ":gIsLogScale")=0 //the "type" data is not logscale anymore 402 endif 403 404 //copy "oldtype" information to ABS 405 //overwriting out the old contents of the ABS folder (/O option in Duplicate) 406 //copy over the waves data,vlegend,text,integers,reals(read) 407 408 String oldType= "root:Packages:NIST:"+type //this is where the data to be absoluted is 409 //copy from current dir (type) to ABS, defined by destPath 410 Duplicate/O $(oldType + ":data"),$"root:Packages:NIST:ABS:data" 411 Duplicate/O $(oldType + ":linear_data"),$"root:Packages:NIST:ABS:linear_data" 412 Duplicate/O $(oldType + ":linear_data_error"),$"root:Packages:NIST:ABS:linear_data_error" 413 // Duplicate/O $(oldType + ":vlegend"),$"root:Packages:NIST:ABS:vlegend" 414 Duplicate/O $(oldType + ":textread"),$"root:Packages:NIST:ABS:textread" 415 Duplicate/O $(oldType + ":integersread"),$"root:Packages:NIST:ABS:integersread" 416 Duplicate/O $(oldType + ":realsread"),$"root:Packages:NIST:ABS:realsread" 417 //need to save a copy of filelist string too (from the current type folder) 418 SVAR oldFileList = $(oldType + ":fileList") 419 //need to copy filelist string too 420 String/G $"root:Packages:NIST:ABS:fileList" = oldFileList 421 422 //now switch to ABS folder 423 //make appropriate wave references 424 WAVE data=$"root:Packages:NIST:ABS:linear_data" // these wave references point to the "type" data in ABS 425 WAVE data_err=$"root:Packages:NIST:ABS:linear_data_error" // these wave references point to the "type" data in ABS 426 WAVE data_copy=$"root:Packages:NIST:ABS:data" // just for display 427 WAVE/T textread=$"root:Packages:NIST:ABS:textread" //that are to be directly operated on 428 WAVE integersread=$"root:Packages:NIST:ABS:integersread" 429 WAVE realsread=$"root:Packages:NIST:ABS:realsread" 430 Variable/G $"root:Packages:NIST:ABS:gIsLogscale"=0 //make new flag in ABS folder, data is linear scale 431 432 //do the actual absolute scaling here, modifying the data in ABS 433 Variable defmon = 1e8,w_moncount,s1,s2,s3,s4 434 435 w_moncount = realsread[0] //monitor count in "type" 436 if(w_moncount == 0) 437 //zero monitor counts will give divide by zero --- 438 DoAlert 0,"Total monitor count in data file is zero. No rescaling of data" 439 Return(1) //report error 440 Endif 441 442 //calculate scale factor 443 Variable scale,trans_err 444 s1 = defmon/realsread[0] //[0] is monitor count (s1 should be 1) 445 s2 = s_thick/w_thick 446 s3 = s_trans/w_trans 447 s4 = s_cross/s_izero 448 449 // kappa comes in as s_izero, so be sure to use 1/kappa_err 450 451 data *= s1*s2*s3*s4 452 453 scale = s1*s2*s3*s4 454 trans_err = realsRead[41] 455 456 // print scale 457 // print data[0][0] 458 459 data_err = sqrt(scale^2*data_err^2 + scale^2*data^2*(kappa_err^2/s_izero^2 +trans_err^2/w_trans^2)) 460 461 // print data_err[0][0] 462 463 // keep "data" in sync with linear_data 464 data_copy = data 465 466 //********* 15APR02 467 // DO NOt correct for atenuators here - the COR step already does this, putting all of the data one equal 468 // footing (zero atten) before doing the subtraction. 469 // 470 //Print "ABS data multiplied by ",s1*s2*s3*s4/attenFactor 471 472 //update the ABS header information 473 textread[1] = date() + " " + time() //date + time stamp 474 475 Return (0) //no error 476 End 477 478 479 // 480 // TODO: 481 // -- DoAlert 0,"This has not yet been updated for VSANS" 482 // 483 // 484 // match the attenuation of the RAW data to the "type" data 485 // so that they can be properly added 486 // 487 // are the attenuator numbers the same? if so exit 488 // 489 // if not, find the attenuator number for type 490 // - find both attenuation factors 491 // 492 // rescale the raw data to match the ratio of the two attenuation factors 493 // -- adjust the detector count (rw) 494 // -- the linear data 495 // 496 // 497 Function Adjust_RAW_Attenuation(type) 498 String type 499 500 DoAlert 0,"This has not yet been updated for VSANS" 501 502 WAVE rw=$("root:Packages:NIST:RAW:realsread") 503 WAVE linear_data=$("root:Packages:NIST:RAW:linear_data") 504 WAVE data=$("root:Packages:NIST:RAW:data") 505 WAVE data_err=$("root:Packages:NIST:RAW:linear_data_error") 506 WAVE/T tw = $("root:Packages:NIST:RAW:textRead") 507 508 WAVE dest_reals=$("root:Packages:NIST:"+type+":realsread") 509 510 Variable dest_atten,raw_atten,tol 511 Variable lambda,raw_atten_err,raw_AttenFactor,dest_attenFactor,dest_atten_err 512 String fileStr 513 514 dest_atten = dest_reals[3] 515 raw_atten = rw[3] 516 517 tol = 0.1 // within 0.1 atten units is OK 518 if(abs(dest_atten - raw_atten) < tol ) 519 return(0) 520 endif 521 522 fileStr = tw[3] 523 lambda = rw[26] 524 // TODO access correct values 525 raw_AttenFactor = 1//AttenuationFactor(fileStr,lambda,raw_atten,raw_atten_err) 526 dest_AttenFactor = 1//AttenuationFactor(fileStr,lambda,dest_atten,dest_atten_err) 527 528 rw[2] *= dest_AttenFactor/raw_AttenFactor 529 linear_data *= dest_AttenFactor/raw_AttenFactor 530 531 // to keep "data" and linear_data in sync 532 data = linear_data 533 534 return(0) 535 End 536 537 // 538 // TODO: 539 // -- DoAlert 0,"This has not yet been updated for VSANS" 540 // 541 //************************ 542 //unused testing procedure, may not be up-to-date with other procedures 543 //check before re-implementing 544 // 545 Proc DIV_a_Workfile(type) 546 String type 547 Prompt type,"WORK data type",popup,"COR;SAM;EMP;BGD" 548 549 //macro will take whatever is in SELECTED folder and DIVide it by the current 550 //contents of the DIV folder - the function will check for existence 551 //before proceeding 552 553 Variable err 554 err = Divide_work(type) //returns err = 1 if data doesn't exist in specified folders 555 556 if(err) 557 Abort "error in Divide_work" 558 endif 559 560 //contents are always dumped to CAL 561 type = "CAL" 562 563 String newTitle = "WORK_"+type 564 DoWindow/F SANS_Data 565 DoWindow/T SANS_Data, newTitle 566 KillStrings/Z newTitle 567 568 //need to update the display with "data" from the correct dataFolder 569 //reset the current displaytype to "type" 570 String/G root:myGlobals:gDataDisplayType=Type 571 572 fRawWindowHook() 573 574 End 575 576 // 577 // TODO: 578 // -- DoAlert 0,"This has not yet been updated for VSANS" 579 // 580 //function will divide the contents of "type" folder with the contents of 581 //the DIV folder 582 // all data is converted to linear scale for the calculation 583 // 584 Function Divide_work(type) 585 String type 586 587 DoAlert 0,"This has not yet been updated for VSANS" 588 589 //check for existence of data in type and DIV 590 // if the desired workfile doesn't exist, let the user know, and abort 591 String destPath="" 592 593 if(WaveExists($("root:Packages:NIST:"+Type + ":data")) == 0) 594 Print "There is no work file in "+type+"--Aborting" 595 Return(1) //error condition 596 Endif 597 //check for DIV 598 // if the DIV workfile doesn't exist, let the user know,and abort 599 600 if(WaveExists($"root:Packages:NIST:DIV:data") == 0) 601 Print "There is no work file in DIV --Aborting" 602 Return(1) //error condition 603 Endif 604 //files exist, proceed 605 606 //check for log-scaling of the "DIV" data and adjust if necessary 607 // should not be needed now - using display flag instead 608 // ConvertFolderToLinearScale("DIV") 609 610 //copy type information to CAL, wiping out the old contents of the CAL folder first 611 612 //destPath = "root:Packages:NIST:CAL" 613 //SetDataFolder destPath 614 //KillWaves/A/Z //get rid of the old data in CAL folder 615 616 //check for log-scaling of the "type" data and adjust if necessary 617 // should not be needed now - using display flag instead 618 // ConvertFolderToLinearScale(type) 619 //then continue 620 621 //copy from current dir (type)=destPath to CAL, overwriting CAL contents 622 destPath = "root:Packages:NIST:" + type 623 Duplicate/O $(destPath + ":data"),$"root:Packages:NIST:CAL:data" 624 Duplicate/O $(destPath + ":linear_data"),$"root:Packages:NIST:CAL:linear_data" 625 Duplicate/O $(destPath + ":linear_data_error"),$"root:Packages:NIST:CAL:linear_data_error" 626 // Duplicate/O $(destPath + ":vlegend"),$"root:Packages:NIST:CAL:vlegend" 627 Duplicate/O $(destPath + ":textread"),$"root:Packages:NIST:CAL:textread" 628 Duplicate/O $(destPath + ":integersread"),$"root:Packages:NIST:CAL:integersread" 629 Duplicate/O $(destPath + ":realsread"),$"root:Packages:NIST:CAL:realsread" 630 //need to save a copy of filelist string too (from the current type folder) 631 SVAR oldFileList = $(destPath + ":fileList") 632 633 //now switch to reference waves in CAL folder 634 destPath = "root:Packages:NIST:CAL" 635 //make appropriate wave references 636 Wave data=$(destPath + ":linear_data") // these wave references point to the data in CAL 637 // Wave data_err=$(destPath + ":linear_data_err") // these wave references point to the data in CAL 638 Wave data_copy=$(destPath + ":data") // these wave references point to the data in CAL 639 Wave/t textread=$(destPath + ":textread") //that are to be directly operated on 640 Wave integersread=$(destPath + ":integersread") 641 Wave realsread=$(destPath + ":realsread") 642 Variable/G $(destPath + ":gIsLogScale")=0 //make new flag in CAL folder, data is linear scale 643 //need to copy filelist string too 644 String/G $(destPath + ":fileList") = oldFileList 645 646 Wave div_data = $"root:Packages:NIST:DIV:data" //hard-wired in.... 647 //do the division, changing data in CAL 648 data /= div_data 649 650 // data_err /= div_data 651 652 // keep "data" in sync with linear_data 653 data_copy = data 654 655 //update CAL header 656 textread[1] = date() + " " + time() //date + time stamp 657 658 Return(0) 659 End 660 661 662 ////////////////////////// -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_HDF5_RW_Utils.ipf
r978 r979 94 94 // det_mt[][20] = 50 95 95 det_MT *= 10 96 det_MT += 2 96 97 97 98 SetDataFolder root:Packages:NIST:VSANS:RAW:entry:entry:instrument:detector_MB … … 101 102 SetScale/I y -ctr,-ctr-48,"",det_MB 102 103 det_MB *= 5 104 det_MB += 2 103 105 104 106 ctr=30 … … 109 111 SetScale/I y -npix/2,npix/2,"",det_ML 110 112 det_ML *= 2 111 113 det_ML += 2 114 112 115 SetDataFolder root:Packages:NIST:VSANS:RAW:entry:entry:instrument:detector_MR 113 116 Wave det_MR=data … … 115 118 SetScale/I x ctr,ctr+48,"",det_MR 116 119 SetScale/I y -npix/2,npix/2,"",det_MR 120 det_MR +=2 117 121 118 122 ctr=30 -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_HDF5_Read.ipf
r970 r979 1055 1055 End 1056 1056 1057 // converging_slits (data folder) 1058 Function/S V_getConvSlitStatus(fname) 1059 String fname 1060 1061 String path = "entry:instrument:converging_slits:status" 1062 Variable num=60 1063 return(V_getStringFromHDF5(fname,path,num)) 1064 End 1065 1057 // converging_slits (not used) 1066 1058 1067 1059 ////// INSTRUMENT/DETECTORS … … 1176 1168 // TODO -- write this function to return a WAVE with the data 1177 1169 // either as a wave reference, or as an input parameter 1178 Function V_getDetectorData(fname,detStr,outW) 1179 String fname,detStr 1180 Wave outW 1170 Function/WAVE V_getDetectorDataW(fname,detStr) 1171 String fname,detStr 1181 1172 1182 1173 String path = "entry:instrument:detector_"+detStr+":data" 1183 1174 WAVE w = V_getRealWaveFromHDF5(fname,path) 1184 1175 1185 outW = w 1186 return(0) 1187 End 1188 1176 return w 1177 End 1178 1179 // TODO -- write this function to return a WAVE with the data 1180 // either as a wave reference, or as an input parameter 1181 Function/WAVE V_getDetectorDataErrW(fname,detStr) 1182 String fname,detStr 1183 1184 String path = "entry:instrument:detector_"+detStr+":linear_data_error" 1185 WAVE w = V_getRealWaveFromHDF5(fname,path) 1186 1187 return w 1188 End 1189 1189 1190 1190 // TODO -- write this function to return a WAVE with the data … … 1192 1192 // ALSO -- the "B" deadtime will be a single value (probably) 1193 1193 // but the tube banks will be 1D arrays of values, one per tube 1194 Function V_getDetector_deadtime(fname,detStr,outW) 1195 String fname,detStr 1196 Wave outW 1194 Function/WAVE V_getDetector_deadtime(fname,detStr) 1195 String fname,detStr 1197 1196 1198 1197 String path = "entry:instrument:detector_"+detStr+":dead_time" 1199 1198 WAVE w = V_getRealWaveFromHDF5(fname,path) 1200 1199 1201 outW = w 1202 return(0) 1200 return w 1203 1201 End 1204 1202 -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_HDF5_Write.ipf
r970 r979 2740 2740 Make/O/D/N=1 wTmpWrite 2741 2741 // Make/O/R/N=1 wTmpWrite 2742 String groupName = "/entry/instrument/beam_ monitor_norm"2742 String groupName = "/entry/instrument/beam_stop" 2743 2743 String varName = "distance_to_detector" 2744 2744 wTmpWrite[0] = val … … 2913 2913 End 2914 2914 2915 // converging_slits (data folder) 2916 Function V_writeConvSlitStatus(fname,str) 2917 String fname,str 2918 2919 // String path = "entry:instrument:converging_slits:status" 2920 2921 Make/O/T/N=1 tmpTW 2922 String groupName = "/entry/instrument/converging_slits" // 2923 String varName = "status" 2924 tmpTW[0] = str // 2925 2926 variable err 2927 err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW) 2928 if(err) 2929 Print "HDF write err = ",err 2930 endif 2931 2932 // now be sure to kill the data folder to force a re-read of the data next time this file is read in 2933 err = V_KillNamedDataFolder(fname) 2934 if(err) 2935 Print "DataFolder kill err = ",err 2936 endif 2937 2938 return(err) 2939 End 2915 // converging_slits (not used) 2916 2940 2917 2941 2918 -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_MainPanel.ipf
r976 r979 24 24 String ctrlName 25 25 26 PickPath()26 V_PickPath() 27 27 // read in DEFAULT.MASK, if it exists, otherwise, do nothing 28 28 // 29 PathInfo catPathName30 if(V_flag==1)31 String str = S_Path + "DEFAULT.MASK"32 Variable refnum33 Open/R/Z=1 refnum as str34 if(strlen(S_filename) != 0)35 Close refnum //file can be found OK36 ReadMCID_MASK(str)37 else38 // file not found, close just in case39 Close/A40 endif41 endif29 // PathInfo catPathName 30 // if(V_flag==1) 31 // String str = S_Path + "DEFAULT.MASK" 32 // Variable refnum 33 // Open/R/Z=1 refnum as str 34 // if(strlen(S_filename) != 0) 35 // Close refnum //file can be found OK 36 // ReadMCID_MASK(str) 37 // else 38 // // file not found, close just in case 39 // Close/A 40 // endif 41 // endif 42 42 End 43 43 … … 55 55 56 56 Variable err= V_LoadHDF5Data("","RAW") // load the data into RawVSANS storage folder (why am I doing this?) 57 Print "Load err = "+num2str(err) 57 58 if(!err) 58 59 String hdfDF = root:file_name // last file loaded, may not be the safest way to pass … … 301 302 PauseUpdate; Silent 1 // building window... 302 303 NewPanel /W=(500,60,924,320) /K=2 as "VSANS Reduction Controls" 303 ModifyPanel cbRGB=(4 7748,57192,54093)304 ModifyPanel cbRGB=(49694,61514,27679) 304 305 ModifyPanel fixedSize=1 305 306 ////// -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Test_RAW_Panel.ipf
r978 r979 33 33 String type 34 34 35 DoWindow VSANS_Data 35 DoWindow/F VSANS_Data 36 Print V_flag 36 37 if(V_flag==0) 37 38 … … 48 49 // what isn't automatically picked up? What is "stale" on the display? 49 50 String/G root:Packages:NIST:VSANS:Globals:gCurDispType = type 50 DoWindow/T VSANS_Data,type + " VSANS_Data"51 // DoWindow/T VSANS_Data,type + " VSANS_Data" 51 52 end 52 53 … … 80 81 NewPanel /W=(37,45,1038,719) /N=VSANS_Data 81 82 ShowTools/A 82 83 ModifyPanel cbRGB=(65535,60076,49151) 84 83 85 String curFolder = root:Packages:NIST:VSANS:Globals:gCurDispType 84 86 DoWindow/T VSANS_Data,curFolder + " VSANS_Data" -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_VSANS_Preferences.ipf
r977 r979 66 66 67 67 // flags to turn detector corrections on/off for testing (you should leave these ON) 68 val = NumVarOrDefault("root:Packages:NIST:VSANS:Globals:gDoDetectorEffCorr", 1 ) 69 Variable/G root:Packages:NIST:VSANS:Globals:gDoDetectorEffCorr = 1 70 71 val = NumVarOrDefault("root:Packages:NIST:VSANS:Globals:gDoTransmissionCorr", 1 ) 72 Variable/G root:Packages:NIST:VSANS:Globals:gDoTransmissionCorr = 1 68 val = NumVarOrDefault("root:Packages:NIST:VSANS:Globals:gDoDetectorEffCor", 1 ) 69 Variable/G root:Packages:NIST:VSANS:Globals:gDoDetectorEffCor = 1 70 71 val = NumVarOrDefault("root:Packages:NIST:VSANS:Globals:gDoTransmissionCor", 1 ) 72 Variable/G root:Packages:NIST:VSANS:Globals:gDoTransmissionCor = 1 73 74 val = NumVarOrDefault("root:Packages:NIST:VSANS:Globals:gDoDIVCor", 1 ) 75 Variable/G root:Packages:NIST:VSANS:Globals:gDoDIVCor = 1 76 77 val = NumVarOrDefault("root:Packages:NIST:VSANS:Globals:gDoDeadTimeCor", 1 ) 78 Variable/G root:Packages:NIST:VSANS:Globals:gDoDeadTimeCor = 1 79 80 val = NumVarOrDefault("root:Packages:NIST:VSANS:Globals:gDoSolidAngleCor", 1 ) 81 Variable/G root:Packages:NIST:VSANS:Globals:gDoSolidAngleCor = 1 82 83 val = NumVarOrDefault("root:Packages:NIST:VSANS:Globals:gDoNonLinearCor", 1 ) 84 Variable/G root:Packages:NIST:VSANS:Globals:gDoNonLinearCor = 1 85 86 val = NumVarOrDefault("root:Packages:NIST:VSANS:Globals:gDoTubeShadowCor", 1 ) 87 Variable/G root:Packages:NIST:VSANS:Globals:gDoTubeShadowCor = 1 88 89 73 90 74 91 // flag to allow adding raw data files with different attenuation (normally not done) … … 141 158 End 142 159 160 Function V_DoDIVCorPref(ctrlName,checked) : CheckBoxControl 161 String ctrlName 162 Variable checked 163 164 NVAR gVal = root:Packages:NIST:VSANS:Globals:gDoDIVCor 165 gVal = checked 166 End 167 168 Function V_DoDeadTimeCorPref(ctrlName,checked) : CheckBoxControl 169 String ctrlName 170 Variable checked 171 172 NVAR gVal = root:Packages:NIST:VSANS:Globals:gDoDeadTimeCor 173 gVal = checked 174 End 175 176 Function V_DoSolidAngleCorPref(ctrlName,checked) : CheckBoxControl 177 String ctrlName 178 Variable checked 179 180 NVAR gVal = root:Packages:NIST:VSANS:Globals:gDoSolidAngleCor 181 gVal = checked 182 End 183 184 Function V_DoNonLinearCorPref(ctrlName,checked) : CheckBoxControl 185 String ctrlName 186 Variable checked 187 188 NVAR gVal = root:Packages:NIST:VSANS:Globals:gDoNonLinearCor 189 gVal = checked 190 End 191 192 Function V_DoTubeShadowCorPref(ctrlName,checked) : CheckBoxControl 193 String ctrlName 194 Variable checked 195 196 NVAR gVal = root:Packages:NIST:VSANS:Globals:gDoTubeShadowCor 197 gVal = checked 198 End 199 143 200 Function V_PrefDoneButtonProc(ctrlName) : ButtonControl 144 201 String ctrlName … … 146 203 DoWindow/K VSANSPref_Panel 147 204 End 205 148 206 149 207 Proc VSANSPref_Panel() … … 151 209 NewPanel /W=(646,208,1070,468)/K=2 as "VSANS Preference Panel" 152 210 DoWindow/C VSANSPref_Panel 153 ModifyPanel cbRGB=(4 9694,61514,27679)211 ModifyPanel cbRGB=(47748,57192,54093) 154 212 SetDrawLayer UserBack 155 213 ModifyPanel fixedSize=1 … … 161 219 TabControl PrefTab,tabLabel(1)="VSANS",tabLabel(2)="Analysis" 162 220 TabControl PrefTab,value=1 163 TabControl PrefTab labelBack=(4 9694,61514,27679)221 TabControl PrefTab labelBack=(47748,57192,54093) 164 222 165 223 //on tab(0) - General … … 185 243 SetVariable PrefCtrl_1e,pos={21,195},size={200,15},title="# Phi Steps (annular avg)" 186 244 SetVariable PrefCtrl_1e,limits={1,360,1},value= root:Packages:NIST:VSANS:Globals:gNPhiSteps 187 CheckBox PrefCtrl_1f title="Do Transmssion Correction?",size={140,14},value=root:Packages:NIST:VSANS:Globals:gDoTransmissionCor r,proc=V_DoTransCorrPref245 CheckBox PrefCtrl_1f title="Do Transmssion Correction?",size={140,14},value=root:Packages:NIST:VSANS:Globals:gDoTransmissionCor,proc=V_DoTransCorrPref 188 246 CheckBox PrefCtrl_1f pos={255,100},help={"TURN OFF ONLY FOR DEBUGGING. This corrects the data for angle dependent transmssion."} 189 247 CheckBox PrefCtrl_1g title="Do Efficiency Correction?",size={140,14},proc=V_DoEfficiencyCorrPref 190 CheckBox PrefCtrl_1g value=root:Packages:NIST:VSANS:Globals:gDoDetectorEffCor r,pos={255,120},help={"TURN OFF ONLY FOR DEBUGGING. This corrects the data for angle dependent detector efficiency."}248 CheckBox PrefCtrl_1g value=root:Packages:NIST:VSANS:Globals:gDoDetectorEffCor,pos={255,120},help={"TURN OFF ONLY FOR DEBUGGING. This corrects the data for angle dependent detector efficiency."} 191 249 // CheckBox PrefCtrl_1h title="Adjust RAW attenuation?",size={140,14},proc=V_DoRawAttenAdjPref 192 250 // CheckBox PrefCtrl_1h value=root:Packages:NIST:VSANS:Globals:gDoAdjustRAW_Atten,pos={255,140},help={"This is normally not done"} 193 251 252 CheckBox PrefCtrl_1i title="Do DIV Correction?",size={140,14},proc=V_DoDIVCorPref 253 CheckBox PrefCtrl_1i value=root:Packages:NIST:VSANS:Globals:gDoDIVCor,pos={255,140},help={"TURN OFF ONLY FOR DEBUGGING."} 254 CheckBox PrefCtrl_1j title="Do DeadTime Correction?",size={140,14},proc=V_DoDeadTimeCorPref 255 CheckBox PrefCtrl_1j value=root:Packages:NIST:VSANS:Globals:gDoDeadTimeCor,pos={255,160},help={"TURN OFF ONLY FOR DEBUGGING."} 256 CheckBox PrefCtrl_1k title="Do Solid Angle Correction?",size={140,14},proc=V_DoSolidAngleCorPref 257 CheckBox PrefCtrl_1k value=root:Packages:NIST:VSANS:Globals:gDoSolidAngleCor,pos={255,180},help={"TURN OFF ONLY FOR DEBUGGING."} 258 CheckBox PrefCtrl_1l title="Do Non-linear Correction?",size={140,14},proc=V_DoNonLinearCorPref 259 CheckBox PrefCtrl_1l value=root:Packages:NIST:VSANS:Globals:gDoNonLinearCor,pos={255,200},help={"TURN OFF ONLY FOR DEBUGGING."} 260 CheckBox PrefCtrl_1m title="Do Tube Shadow Correction?",size={140,14},proc=V_DoTubeShadowCorPref 261 CheckBox PrefCtrl_1m value=root:Packages:NIST:VSANS:Globals:gDoTubeShadowCor,pos={255,220},help={"TURN OFF ONLY FOR DEBUGGING."} 262 194 263 // CheckBox PrefCtrl_1a,disable=1 195 264 // CheckBox PrefCtrl_1b,disable=1 -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_WorkFolderUtils.ipf
r976 r979 1 1 #pragma rtGlobals=3 // Use modern global access method and strict wave access. 2 #pragma version=1.0 3 #pragma IgorVersion=6.1 4 5 //******************* 6 // Vers 1.0 JAN2016 7 // 8 //******************* 9 // VSANS Utility procedures for handling of workfiles (each is housed in a separate datafolder) 10 // 11 // - adding RAW data to a workfile 12 // -- this conversion applies the detector corrections 13 // 14 // - copying workfiles to another folder 15 // 16 // - absolute scaling 17 // 18 // - (no) the WorkFile Math panel for simple image math (not done - maybe in the future?) 19 // - 20 // - (no) adding work.drk data without normalizing to monitor counts (the case not currently handled) 21 //*************************** 2 22 3 23 // … … 6 26 // 7 27 // 8 28 Strconstant ksDetectorListNoB = "FT;FB;FL;FR;MT;MB;ML;MR;" 29 Strconstant ksDetectorListAll = "FT;FB;FL;FR;MT;MB;ML;MR;B;" 9 30 10 31 … … 16 37 Prompt oldType,"Source WORK data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;" 17 38 Prompt newType,"Destination WORK data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;" 18 // Prompt oldType,"Source WORK data type",popup,"AAA;BBB;CCC;DDD;EEE;FFF;GGG;" 19 // Prompt newType,"Destination WORK data type",popup,"AAA;BBB;CCC;DDD;EEE;FFF;GGG;" 20 21 // data folder "old" will be copied to "new" (and will overwrite) 39 40 // data folder "old" will be copied to "new" (either kills/copies or will overwrite) 22 41 CopyHDFToWorkFolder(oldtype,newtype) 23 42 End … … 58 77 59 78 // copy the folders 60 KillDataFolder/Z toDF //DuplicateDataFolder will not overwrite, so Kill79 KillDataFolder/Z $toDF //DuplicateDataFolder will not overwrite, so Kill 61 80 62 81 if(V_flag == 0) // kill DF was OK 63 DuplicateDataFolder $ fromDF,$toDF82 DuplicateDataFolder $("root:Packages:NIST:VSANS:"+fromStr),$("root:Packages:NIST:VSANS:"+toStr) 64 83 65 84 // I can delete these if they came along with RAW … … 112 131 // 113 132 // 114 Proc V_Copy ToWorkFolder(dataFolderStr, fromStr, toStr, level, sNBName, recurse)133 Proc V_CopyWorkFolderTest(dataFolderStr, fromStr, toStr, level, sNBName, recurse) 115 134 String dataFolderStr="root:Packages:NIST:VSANS:RAW" 116 135 String fromStr = "RAW" … … 266 285 return(0) 267 286 End 287 288 289 290 291 292 ///////////////////// 293 294 295 296 297 // 298 //Entry procedure from main panel 299 // 300 Proc AddFolder(oldType,newType) 301 String oldType,newType 302 Prompt oldType,"Source WORK data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;" 303 Prompt newType,"Destination WORK data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;" 304 305 // data folder "RAW" will be copied to "new" (either kills/copies or will overwrite) 306 Variable err = Raw_to_work(newType) 307 // CopyHDFToWorkFolder(oldtype,newtype) 308 End 309 310 311 312 //testing procedure 313 Proc Add_to_Workfile(newtype, doadd) 314 String newtype,doadd 315 Prompt newtype,"WORK data type",popup,"SAM;EMP;BGD;ADJ;" 316 Prompt doadd,"Add to current WORK contents?",popup,"No;Yes;" 317 318 //macro will take whatever is in RAW folder and "ADD" it to the folder specified 319 //in the popup menu 320 321 //"add" = yes/no, don't add to previous runs 322 //switch here - two separate functions to avoid (my) confusion 323 Variable err// = Raw_to_work(newtype) 324 if(cmpstr(doadd,"No")==0) 325 //don't add to prev work contents, copy RAW contents to work and convert 326 err = Raw_to_work(newtype) 327 else 328 //yes, add RAW to the current work folder contents 329 err = Add_raw_to_work(newtype) 330 endif 331 332 String newTitle = "WORK_"+newtype 333 DoWindow/F VSANS_Data 334 DoWindow/T VSANS_Data, newTitle 335 KillStrings/Z newTitle 336 337 //need to update the display with "data" from the correct dataFolder 338 UpdateDisplayInformation(newtype) 339 340 End 341 342 343 // 344 //will copy the current contents of the RAW folder to the newType work folder 345 //and do the geometric corrections and normalization to monitor counts 346 //(the function Add_Raw_to_work(type) adds multiple runs together) 347 // 348 //the current display type is updated to newType (global) 349 // 350 Function Raw_to_work(newType) 351 String newType 352 353 Variable deadTime,defmon,total_mon,total_det,total_trn,total_numruns,total_rtime 354 Variable ii,jj,itim,cntrate,dscale,scale,uscale 355 String destPath 356 357 String fname = newType 358 String detStr 359 Variable ctTime 360 361 //initialize values before normalization 362 total_mon=0 363 total_det=0 364 total_trn=0 365 total_numruns=0 366 total_rtime=0 367 368 //Not adding multiple runs, so wipe out the old contents of the work folder and 369 // replace with the contents of raw 370 371 destPath = "root:Packages:NIST:VSANS:" + newType 372 373 //copy from current dir (RAW) to work, defined by newType 374 CopyHDFToWorkFolder("RAW",newType) 375 376 // now work with the waves from the destination folder. 377 Variable/G $(destPath + ":gIsLogscale")=0 //overwite flag in newType folder, data converted (above) to linear scale 378 // String/G $(destPath + ":fileList") = textread[0] //a list of names of the files in the work file (1) //02JUL13 379 380 // apply corrections --- 381 // switches to control what is done, don't do the transmission correction for the BGD measurement 382 // start with the DIV correction, before conversion to mm 383 // then do all of the other corrections, order doesn't matter. 384 // rescaling to default monitor counts however, must be LAST. 385 386 // each correction must loop over each detector. tedious. 387 388 // (1) DIV correction 389 // do this in terms of pixels. 390 // TODO : This must also exist at the time the first work folder is generated. 391 // So it must be in the user folder at the start of the experiment, and defined. 392 NVAR gDoDIVCor = root:Packages:NIST:VSANS:Globals:gDoDIVCor 393 if (gDoDIVCor == 1) 394 // need extra check here for file existence 395 // if not in DIV folder, load. 396 // if unable to load, skip correction and report error (Alert?) 397 for(ii=0;ii<8;ii+=1) 398 detStr = StringFromList(ii, ksDetectorListNoB, ";") 399 Wave w = V_getDetectorDataW(fname,detStr) 400 Wave w_err = V_getDetectorDataErrW(fname,detStr) 401 Wave w_dt = V_getDetector_deadtime(fname,detStr) 402 Print "Doing DIV correction for "+ detStr 403 // DIVCorrection(fill this in) 404 405 endfor 406 else 407 Print "DIV correction not done" // not an error since correction was unchecked 408 endif 409 410 // (2) non-linear correction 411 NVAR gDoNonLinearCor = root:Packages:NIST:VSANS:Globals:gDoNonLinearCor 412 // generate a distance matrix for each of the detectors 413 if (gDoNonLinearCor == 1) 414 for(ii=0;ii<8;ii+=1) 415 detStr = StringFromList(ii, ksDetectorListNoB, ";") 416 Wave w = V_getDetectorDataW(fname,detStr) 417 Wave w_err = V_getDetectorDataErrW(fname,detStr) 418 Wave w_dt = V_getDetector_deadtime(fname,detStr) 419 Print "Doing Non-linear correction for "+ detStr 420 // NonLinearCorrection(fill this in) 421 422 endfor 423 else 424 Print "Non-linear correction not done" 425 endif 426 427 // (3) solid angle correction 428 NVAR gDoSolidAngleCor = root:Packages:NIST:VSANS:Globals:gDoSolidAngleCor 429 if (gDoSolidAngleCor == 1) 430 for(ii=0;ii<8;ii+=1) 431 detStr = StringFromList(ii, ksDetectorListNoB, ";") 432 Wave w = V_getDetectorDataW(fname,detStr) 433 Wave w_err = V_getDetectorDataErrW(fname,detStr) 434 Wave w_dt = V_getDetector_deadtime(fname,detStr) 435 Print "Doing Solid Angle correction for "+ detStr 436 // SolidAngleCorrection(fill this in) 437 438 endfor 439 else 440 Print "Solid Angle correction not done" 441 endif 442 443 // (4) dead time correction 444 // TODO: -- remove the hard-wired test 445 // -- test for correct operation 446 // -- loop over all of the detectors 447 // -- B detector is a special case 448 NVAR gDoDeadTimeCor = root:Packages:NIST:VSANS:Globals:gDoDeadTimeCor 449 ctTime = V_getCount_time(fname) 450 if (gDoDeadTimeCor == 1) 451 for(ii=0;ii<8;ii+=1) 452 detStr = StringFromList(ii, ksDetectorListNoB, ";") 453 Wave w = V_getDetectorDataW(fname,detStr) 454 Wave w_err = V_getDetectorDataErrW(fname,detStr) 455 Wave w_dt = V_getDetector_deadtime(fname,detStr) 456 Print "Doing DeadTime correction for "+ detStr 457 // DeadTimeCorrectionTubes(w,w_err,w_dt,ctTime) 458 //deadtime corrections 459 // itim = integersread[2] 460 // cntrate = sum(data,-inf,inf)/itim //use sum of detector counts rather than scaler value 461 // //TODO - do correct dead time correction for tubes 462 // deadtime = 1//DetectorDeadtime(textread[3],textread[9],dateAndTimeStr=textRead[1],dtime=realsRead[48]) //pick the correct deadtime 463 // dscale = 1/(1-deadTime*cntrate) 464 // 465 466 // dead time correction 467 // data *= dscale //deadtime correction for everyone else, including NCNR 468 // data_err *= dscale 469 470 endfor 471 else 472 Print "Dead Time correction not done" 473 endif 474 475 // (5) angle-dependent tube shadowing 476 NVAR gDoTubeShadowCor = root:Packages:NIST:VSANS:Globals:gDoTubeShadowCor 477 if (gDoTubeShadowCor == 1) 478 479 else 480 Print "Tube shadowing correction not done" 481 endif 482 483 // (6) angle dependent transmission correction 484 NVAR gDoTrans = root:Packages:NIST:VSANS:Globals:gDoTransmissionCor 485 if (gDoTrans == 1) 486 for(ii=0;ii<8;ii+=1) 487 detStr = StringFromList(ii, ksDetectorListNoB, ";") 488 Wave w = V_getDetectorDataW(fname,detStr) 489 Wave w_err = V_getDetectorDataErrW(fname,detStr) 490 Wave w_dt = V_getDetector_deadtime(fname,detStr) 491 Print "Doing Large-angle transmission correction for "+ detStr 492 // TransmissionCorrection(fill this in) 493 494 endfor 495 else 496 Print "Sample Transmission correction not done" 497 endif 498 499 // (7) normalize to default monitor counts 500 // TODO -- each detector is rescaled separately, but the rescaling factor is global (only one monitor!) 501 // TODO -- but there are TWO monitors - so how to switch? 502 // TODO -- what do I really need to save? 503 defmon=1e8 //default monitor counts 504 for(ii=0;ii<8;ii+=1) 505 detStr = StringFromList(ii, ksDetectorListNoB, ";") 506 Wave w = V_getDetectorDataW(fname,detStr) 507 Wave w_err = V_getDetectorDataErrW(fname,detStr) 508 Variable monCt = V_getBeamMonNormData(fname) 509 Print "Doing monitor normalization for "+ detStr 510 // MonitorNormalization(fill this in) 511 //scale the data to the default montor counts 512 scale = defmon/monCt 513 w *= scale 514 w_err *= scale //assumes total monitor count is so large there is essentially no error 515 516 // V_getBeamMonNormSaved_count() 517 // save the true monitor counts? save the scaling factor? 518 String path = "entry:instrument:beam_monitor_norm:saved_count" 519 Wave/Z savW = $("root:Packages:NIST:VSANS:"+fname+":entry:"+path) 520 savW[0] = scale 521 endfor 522 523 524 // (not done) angle dependent efficiency correction 525 NVAR doEfficiency = root:Packages:NIST:VSANS:Globals:gDoDetectorEffCor 526 527 528 // this function, in the past did the non-linear, solid angle, transmission, and efficiency corrections all at once 529 // DetCorr(data,data_err,realsread,doEfficiency,doTrans) //the parameters are waves, and will be changed by the function 530 531 532 533 //update totals to put in the work header (at the end of the function) 534 // total_mon += realsread[0] 535 // 536 // total_det += dscale*realsread[2] 537 // 538 // total_trn += realsread[39] 539 // total_rtime += integersread[2] 540 // total_numruns +=1 541 // 542 543 //all is done, except for the bookkeeping, updating the header information in the work folder 544 545 // integersread[3] = total_numruns //numruns = 1 546 // realsread[1] = total_mon //save the true monitor count 547 // realsread[0] = defmon //monitor ct = defmon 548 // realsread[2] = scale*total_det //scaled detector counts 549 // 550 //reset the current displaytype to "newtype" 551 String/G root:myGlobals:gDataDisplayType=newType 552 553 //return to root folder (redundant) 554 SetDataFolder root: 555 556 Return(0) 557 End 558 559 560 //will "ADD" the current contents of the RAW folder to the newType work folder 561 //and will ADD the RAW contents to the existing content of the newType folder 562 // - used when adding multiple runs together 563 //(the function Raw_to_work(type) makes a fresh workfile) 564 // 565 //the current display type is updated to newType (global) 566 Function Add_raw_to_work(newType) 567 String newType 568 569 // NEW OCT 2014 570 // this corrects for adding raw data files with different attenuation 571 // does nothing if the attenuation of RAW and destination are the same 572 NVAR doAdjustRAW_Atten = root:Packages:NIST:gDoAdjustRAW_Atten 573 if(doAdjustRAW_Atten) 574 Adjust_RAW_Attenuation(newType) 575 endif 576 577 String destPath="" 578 579 // if the desired workfile doesn't exist, let the user know, and just make a new one 580 if(WaveExists($("root:Packages:NIST:"+newType + ":data")) == 0) 581 Print "There is no old work file to add to - a new one will be created" 582 //call Raw_to_work(), then return from this function 583 Raw_to_Work(newType) 584 Return(0) //does not generate an error - a single file was converted to work.newtype 585 Endif 586 587 NVAR pixelsX = root:myGlobals:gNPixelsX 588 NVAR pixelsY = root:myGlobals:gNPixelsY 589 590 //now make references to data in newType folder 591 DestPath="root:Packages:NIST:"+newType 592 WAVE data=$(destPath +":linear_data") // these wave references point to the EXISTING work data 593 WAVE data_copy=$(destPath +":data") // these wave references point to the EXISTING work data 594 WAVE dest_data_err=$(destPath +":linear_data_error") // these wave references point to the EXISTING work data 595 WAVE/T textread=$(destPath + ":textread") 596 WAVE integersread=$(destPath + ":integersread") 597 WAVE realsread=$(destPath + ":realsread") 598 599 Variable deadTime,defmon,total_mon,total_det,total_trn,total_numruns,total_rtime 600 Variable ii,jj,itim,cntrate,dscale,scale,uscale,wrk_beamx,wrk_beamy,xshift,yshift 601 602 603 defmon=1e8 //default monitor counts 604 605 //Yes, add to previous run(s) in work, that does exist 606 //use the actual monitor count run.savmon rather than the normalized monitor count 607 //in run.moncnt and unscale the work data 608 609 total_mon = realsread[1] //saved monitor count 610 uscale = total_mon/defmon //unscaling factor 611 total_det = uscale*realsread[2] //unscaled detector count 612 total_trn = uscale*realsread[39] //unscaled trans det count 613 total_numruns = integersread[3] //number of runs in workfile 614 total_rtime = integersread[2] //total counting time in workfile 615 //retrieve workfile beamcenter 616 wrk_beamx = realsread[16] 617 wrk_beamy = realsread[17] 618 //unscale the workfile data in "newType" 619 // 620 //check for log-scaling and adjust if necessary 621 // should not be needed now - using display flag instead 622 // ConvertFolderToLinearScale(newType) 623 // 624 //then unscale the data array 625 data *= uscale 626 dest_data_err *= uscale 627 628 //DetCorr() has not been applied to the data in RAW , do it now in a local reference to the raw data 629 WAVE raw_data = $"root:Packages:NIST:RAW:linear_data" 630 WAVE raw_data_err = $"root:Packages:NIST:RAW:linear_data_error" 631 WAVE raw_reals = $"root:Packages:NIST:RAW:realsread" 632 WAVE/T raw_text = $"root:Packages:NIST:RAW:textread" 633 WAVE raw_ints = $"root:Packages:NIST:RAW:integersread" 634 635 //check for log-scaling of the raw data - make sure it's linear 636 // should not be needed now - using display flag instead 637 // ConvertFolderToLinearScale("RAW") 638 639 // switches to control what is done, don't do the transmission correction for the BGD measurement 640 NVAR doEfficiency = root:Packages:NIST:gDoDetectorEffCorr 641 NVAR gDoTrans = root:Packages:NIST:gDoTransmissionCorr 642 Variable doTrans = gDoTrans 643 if(cmpstr("BGD",newtype) == 0) 644 doTrans = 0 //skip the trans correction for the BGD file but don't change the value of the global 645 endif 646 647 DetCorr(raw_data,raw_data_err,raw_reals,doEfficiency,doTrans) //applies correction to raw_data, and overwrites it 648 649 //deadtime corrections to raw data 650 // TODO - do the tube correction for dead time now 651 deadTime = 1//DetectorDeadtime(raw_text[3],raw_text[9],dateAndTimeStr=raw_text[1],dtime=raw_reals[48]) //pick the correct detector deadtime, switch on date too 652 itim = raw_ints[2] 653 cntrate = sum(raw_data,-inf,inf)/itim //080802 use data sum, rather than scaler value 654 dscale = 1/(1-deadTime*cntrate) 655 656 #if (exists("ILL_D22")==6) 657 Variable tubeSum 658 // for D22 detector might need to use cntrate/128 as it is the tube response 659 for(ii=0;ii<pixelsX;ii+=1) 660 //sum the counts in each tube 661 tubeSum = 0 662 for(jj=0;jj<pixelsY;jj+=1) 663 tubeSum += data[jj][ii] 664 endfor 665 // countrate in tube ii 666 cntrate = tubeSum/itim 667 // deadtime scaling in tube ii 668 dscale = 1/(1-deadTime*cntrate) 669 // multiply data[ii][] by the dead time 670 raw_data[][ii] *= dscale 671 raw_data_err[][ii] *= dscale 672 endfor 673 #else 674 // dead time correction on all other RAW data, including NCNR 675 raw_data *= dscale 676 raw_data_err *= dscale 677 #endif 678 679 //update totals by adding RAW values to the local ones (write to work header at end of function) 680 total_mon += raw_reals[0] 681 682 total_det += dscale*raw_reals[2] 683 684 total_trn += raw_reals[39] 685 total_rtime += raw_ints[2] 686 total_numruns +=1 687 688 //do the beamcenter shifting if there is a mismatch 689 //and then add the two data sets together, changing "data" since it is the workfile data 690 xshift = raw_reals[16] - wrk_beamx 691 yshift = raw_reals[17] - wrk_beamy 692 693 If((xshift != 0) || (yshift != 0)) 694 DoAlert 1,"Do you want to ignore the beam center mismatch?" 695 if(V_flag==1) 696 xshift=0 697 yshift=0 698 endif 699 endif 700 701 If((xshift == 0) && (yshift == 0)) //no shift, just add them 702 data += raw_data //deadtime correction has already been done to the raw data 703 dest_data_err = sqrt(dest_data_err^2 + raw_data_err^2) // error of the sum 704 Endif 705 706 //scale the data to the default montor counts 707 scale = defmon/total_mon 708 data *= scale 709 dest_data_err *= scale 710 711 // keep "data" and linear_data in sync in the destination folder 712 data_copy = data 713 714 //all is done, except for the bookkeeping of updating the header info in the work folder 715 textread[1] = date() + " " + time() //date + time stamp 716 integersread[3] = total_numruns //numruns = more than one 717 realsread[1] = total_mon //save the true monitor count 718 realsread[0] = defmon //monitor ct = defmon 719 integersread[2] = total_rtime // total counting time 720 realsread[2] = scale*total_det //scaled detector counts 721 realsread[39] = scale*total_trn //scaled transmission counts 722 723 //Add the added raw filename to the list of files in the workfile 724 String newfile = ";" + raw_text[0] 725 SVAR oldList = $(destPath + ":fileList") 726 String/G $(destPath + ":fileList") = oldList + newfile 727 728 //reset the current displaytype to "newtype" 729 String/G root:myGlobals:gDataDisplayType=newType 730 731 //return to root folder (redundant) 732 SetDataFolder root: 733 734 Return(0) 735 End 736 737 738 //used for adding DRK (beam shutter CLOSED) data to a workfile 739 //force the monitor count to 1, since it's irrelevant 740 // run data through normal "add" step, then unscale default monitor counts 741 //to get the data back on a simple time basis 742 // 743 Function Raw_to_Work_NoNorm(type) 744 String type 745 746 WAVE reals=$("root:Packages:NIST:RAW:realsread") 747 reals[1]=1 //true monitor counts, still in raw 748 Raw_to_work(type) 749 //data is now in "type" folder 750 WAVE data=$("root:Packages:NIST:"+type+":linear_data") 751 WAVE data_copy=$("root:Packages:NIST:"+type+":data") 752 WAVE data_err=$("root:Packages:NIST:"+type+":linear_data_error") 753 WAVE new_reals=$("root:Packages:NIST:"+type+":realsread") 754 755 Variable norm_mon,tot_mon,scale 756 757 norm_mon = new_reals[0] //should be 1e8 758 tot_mon = new_reals[1] //should be 1 759 scale= norm_mon/tot_mon 760 761 data /= scale //unscale the data 762 data_err /= scale 763 764 // to keep "data" and linear_data in sync 765 data_copy = data 766 767 return(0) 768 End 769 770 //used for adding DRK (beam shutter CLOSED) data to a workfile 771 //force the monitor count to 1, since it's irrelevant 772 // run data through normal "add" step, then unscale default monitor counts 773 //to get the data back on a simple time basis 774 // 775 Function Add_Raw_to_Work_NoNorm(type) 776 String type 777 778 WAVE reals=$("root:Packages:NIST:RAW:realsread") 779 reals[1]=1 //true monitor counts, still in raw 780 Add_Raw_to_work(type) 781 //data is now in "type" folder 782 WAVE data=$("root:Packages:NIST:"+type+":linear_data") 783 WAVE data_copy=$("root:Packages:NIST:"+type+":data") 784 WAVE data_err=$("root:Packages:NIST:"+type+":linear_data_error") 785 WAVE new_reals=$("root:Packages:NIST:"+type+":realsread") 786 787 Variable norm_mon,tot_mon,scale 788 789 norm_mon = new_reals[0] //should be 1e8 790 tot_mon = new_reals[1] //should be equal to the number of runs (1 count per run) 791 scale= norm_mon/tot_mon 792 793 data /= scale //unscale the data 794 data_err /= scale 795 796 // to keep "data" and linear_data in sync 797 data_copy = data 798 799 return(0) 800 End 801
Note: See TracChangeset
for help on using the changeset viewer.