Ignore:
Timestamp:
Jul 3, 2018 2:30:41 PM (4 years ago)
Author:
srkline
Message:

Many changes:

Made the VCALC panel aware of all of the binning options
Corrected the behavior of the VCALC preset conditions
Adjusted how the Slit data is binned so that there are not duplicated q-values in the output

Made Absolute scaling aware of the back detector. Now the ABS String in the protocol has a second
set of scaling constants tagged with "_B" for the back detector. There is an added button
on the protocol panel to set the second set of constants. For the back detector, the read noise
is subtracted by reading it from the empty beam file (shifting over to the right by one box width)
All of the associated abs procedures are now aware of this.
More error checking needs to be added.

Back detector image is now shifted upon loading of the data. the default mask takes this into account
and masks out the padded (zero) regions.

in the protocol, DIV and MSK do not use grep any longer. it was just way too slow. Now it depends on

the file name having DIV or MASK respectively.



Raw data files can now be added together, in the usual way from the protocol panel.



File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_WorkFolderUtils.ipf

    r1106 r1109  
    107107                // need to do this the hard way, duplicate/O recursively 
    108108                // see V_CopyToWorkFolder() 
    109                  
     109 
     110                // gFileList is above "entry" which is my additions 
     111                SVAR fileList_dest = $("root:Packages:NIST:VSANS:"+toStr+":gFileList") 
     112                SVAR fileList_tmp = $("root:Packages:NIST:VSANS:"+fromStr+":gFileList") 
     113                fileList_dest = fileList_tmp 
     114         
    110115                // everything on the top level 
    111116                V_DuplicateDataFolder($(fromDF+":entry"),fromStr,toStr,0,"",0)  //no recursion here 
     
    402407        // for S = 1 in eq (7), this corresponds to one sigma error bars 
    403408        Duplicate/O linear_data linear_data_error 
    404         linear_data_error = 1 + sqrt(linear_data + 0.75)                                 
     409        linear_data_error = 1 + sqrt(linear_data + 0.75) 
     410         
     411        Duplicate/O linear_data_error data_error                         
    405412        // 
    406413         
     
    435442        else 
    436443                //yes, add RAW to the current work folder contents 
    437                 Abort "Adding RAW data files is currently unsupported" 
     444                //Abort "Adding RAW data files is currently unsupported" 
    438445                err = V_Add_raw_to_work(newtype) 
    439446        endif 
     
    778785        NVAR doEfficiency = root:Packages:NIST:VSANS:Globals:gDoDetectorEffCor 
    779786 
    780 // 
    781 ///// these lines are if files are added together, not done (yet) for VSANS 
    782 // 
    783 //update totals to put in the work header (at the end of the function) 
    784 //      total_mon += realsread[0] 
    785 // 
    786 //      total_det += dscale*realsread[2] 
    787 // 
    788 //      total_trn += realsread[39] 
    789 //      total_rtime += integersread[2] 
    790 //      total_numruns +=1 
    791 //       
    792  
    793787//       
    794788        //reset the current displaytype to "newtype" 
     
    801795End 
    802796 
    803  
     797// 
    804798//will "ADD" the current contents of the RAW folder to the newType work folder 
    805 //and will ADD the RAW contents to the existing content of the newType folder 
     799// 
    806800// - used when adding multiple runs together 
    807 //(the function Raw_to_work(type) makes a fresh workfile) 
     801//(the function V_Raw_to_work(type) makes a fresh workfile) 
    808802// 
    809803//the current display type is updated to newType (global) 
     
    811805        String newType 
    812806         
    813         // NEW OCT 2014 
    814         // this corrects for adding raw data files with different attenuation    
    815         // does nothing if the attenuation of RAW and destination are the same 
    816         NVAR doAdjustRAW_Atten = root:Packages:NIST:gDoAdjustRAW_Atten 
    817         if(doAdjustRAW_Atten) 
    818                 V_Adjust_RAW_Attenuation(newType) 
    819         endif 
    820          
    821807        String destPath="" 
    822          
    823808        // if the desired workfile doesn't exist, let the user know, and just make a new one 
    824         if(WaveExists($("root:Packages:NIST:"+newType + ":data")) == 0) 
     809        if(WaveExists($("root:Packages:NIST:VSANS:"+newType + ":entry:instrument:detector_FL:data")) == 0) 
    825810                Print "There is no old work file to add to - a new one will be created" 
    826                 //call Raw_to_work(), then return from this function 
     811                //call V_Raw_to_work(), then return from this function 
    827812                V_Raw_to_Work(newType) 
    828813                Return(0)               //does not generate an error - a single file was converted to work.newtype 
    829814        Endif 
    830          
    831         NVAR pixelsX = root:myGlobals:gNPixelsX 
    832         NVAR pixelsY = root:myGlobals:gNPixelsY 
    833          
     815 
     816 
     817        // convert the RAW data to a WORK file. 
     818        // this will do all of the necessary corrections to the data 
     819        // put this in some separate work folder that can be cleaned out at the end (ADJ) 
     820        String tmpType="ADJ" 
     821        V_Raw_to_Work(tmpType) 
     822                         
    834823        //now make references to data in newType folder 
    835         DestPath="root:Packages:NIST:"+newType   
    836         WAVE data=$(destPath +":linear_data")                   // these wave references point to the EXISTING work data 
    837         WAVE data_copy=$(destPath +":data")                     // these wave references point to the EXISTING work data 
    838         WAVE dest_data_err=$(destPath +":linear_data_error")                    // these wave references point to the EXISTING work data 
    839         WAVE/T textread=$(destPath + ":textread") 
    840         WAVE integersread=$(destPath + ":integersread") 
    841         WAVE realsread=$(destPath + ":realsread") 
    842          
    843         Variable deadTime,defmon,total_mon,total_det,total_trn,total_numruns,total_rtime 
    844         Variable ii,jj,itim,cntrate,dscale,scale,uscale,wrk_beamx,wrk_beamy,xshift,yshift 
    845  
    846  
    847         defmon=1e8                      //default monitor counts 
    848          
    849         //Yes, add to previous run(s) in work, that does exist 
    850         //use the actual monitor count run.savmon rather than the normalized monitor count 
    851         //in run.moncnt and unscale the work data 
    852          
    853         total_mon = realsread[1]        //saved monitor count 
    854         uscale = total_mon/defmon               //unscaling factor 
    855         total_det = uscale*realsread[2]         //unscaled detector count 
    856         total_trn = uscale*realsread[39]        //unscaled trans det count 
    857         total_numruns = integersread[3] //number of runs in workfile 
    858         total_rtime = integersread[2]           //total counting time in workfile 
    859         //retrieve workfile beamcenter 
    860         wrk_beamx = realsread[16] 
    861         wrk_beamy = realsread[17] 
    862         //unscale the workfile data in "newType" 
    863         // 
    864         //check for log-scaling and adjust if necessary 
    865         // should not be needed now - using display flag instead 
    866 //      ConvertFolderToLinearScale(newType) 
    867         // 
    868         //then unscale the data array 
    869         data *= uscale 
    870         dest_data_err *= uscale 
    871          
    872         //DetCorr() has not been applied to the data in RAW , do it now in a local reference to the raw data 
    873         WAVE raw_data = $"root:Packages:NIST:RAW:linear_data" 
    874         WAVE raw_data_err = $"root:Packages:NIST:RAW:linear_data_error" 
    875         WAVE raw_reals =  $"root:Packages:NIST:RAW:realsread" 
    876         WAVE/T raw_text = $"root:Packages:NIST:RAW:textread" 
    877         WAVE raw_ints = $"root:Packages:NIST:RAW:integersread" 
    878          
    879         //check for log-scaling of the raw data - make sure it's linear 
    880         // should not be needed now - using display flag instead 
    881 //      ConvertFolderToLinearScale("RAW") 
    882          
    883         // switches to control what is done, don't do the transmission correction for the BGD measurement 
    884         NVAR doEfficiency = root:Packages:NIST:gDoDetectorEffCor 
    885         NVAR gDoTrans = root:Packages:NIST:gDoTransmissionCor 
    886         Variable doTrans = gDoTrans 
    887         if(cmpstr("BGD",newtype) == 0) 
    888                 doTrans = 0             //skip the trans correction for the BGD file but don't change the value of the global 
    889         endif    
    890          
    891         V_DetCorr(raw_data,raw_data_err,raw_reals,doEfficiency,doTrans) //applies correction to raw_data, and overwrites it 
    892          
    893         //deadtime corrections to raw data 
    894         // TODO - do the tube correction for dead time now 
    895         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 
    896         itim = raw_ints[2] 
    897         cntrate = sum(raw_data,-inf,inf)/itim           //080802 use data sum, rather than scaler value 
    898         dscale = 1/(1-deadTime*cntrate) 
    899  
    900 #if (exists("ILL_D22")==6) 
    901         Variable tubeSum 
    902         // for D22 detector might need to use cntrate/128 as it is the tube response 
    903         for(ii=0;ii<pixelsX;ii+=1) 
    904                 //sum the counts in each tube 
    905                 tubeSum = 0 
    906                 for(jj=0;jj<pixelsY;jj+=1) 
    907                         tubeSum += data[jj][ii] 
    908                 endfor 
    909                 // countrate in tube ii 
    910                 cntrate = tubeSum/itim 
    911                 // deadtime scaling in tube ii 
    912                 dscale = 1/(1-deadTime*cntrate) 
    913                 // multiply data[ii][] by the dead time 
    914                 raw_data[][ii] *= dscale 
    915                 raw_data_err[][ii] *= dscale 
     824        DestPath="root:Packages:NIST:VSANS:"+newType     
     825 
     826 
     827///////////////// 
     828//fields that need to be added together 
     829// entry block 
     830        // collection_time              V_getCollectionTime(fname)              V_putCollectionTime(fname,val) 
     831 
     832// instrument block 
     833        // beam_monitor_norm 
     834                // data (this will be 1e8)                              V_getBeamMonNormData(fname)             V_putBeamMonNormData(fname,val) 
     835                // saved_count (this is the original monitor count)  V_getBeamMonNormSaved_count(fname)         V_putBeamMonNormSaved_count(fname,val) 
     836 
     837        // for each detector 
     838        // data         V_getDetectorDataW(fname,detStr) 
     839        // integrated_count             V_getDet_IntegratedCount(fname,detStr)   V_putDet_IntegratedCount(fname,detStr,val) 
     840        // linear_data           V_getDetectorLinearDataW(fname,detStr) 
     841        // RECALCULATE (or add properly) linear_data_error              V_getDetectorDataErrW(fname,detStr) 
     842 
     843 
     844// control block (these may not actually be used?) 
     845        // count_time                           V_getCount_time(fname)                                          V_putCount_time(fname,val) 
     846        // detector_counts              V_getDetector_counts(fname)                             V_putDetector_counts(fname,val) 
     847        // monitor_counts               V_getControlMonitorCount(fname)         V_putControlMonitorCount(fname,val) 
     848 
     849// sample block - nothing 
     850// reduction block - nothing 
     851// user block - nothing 
     852 
     853// ?? need to add the file name to a list of what was actually added - so it will be saved with I(q) 
     854// 
     855//////////////////// 
     856 
     857//      total_mon = realsread[1]        //saved monitor count 
     858//      uscale = total_mon/defmon               //unscaling factor 
     859//      total_det = uscale*realsread[2]         //unscaled detector count 
     860//      total_trn = uscale*realsread[39]        //unscaled trans det count 
     861//      total_numruns = integersread[3] //number of runs in workfile 
     862//      total_rtime = integersread[2]           //total counting time in workfile 
     863         
     864 
     865        String detStr 
     866         
     867        Variable saved_mon_dest,scale_dest,saved_mon_tmp,scale_tmp 
     868        Variable collection_time_dest,collection_time_tmp,count_time_dest,count_time_tmp 
     869        Variable detCount_dest,detCount_tmp,det_integrated_ct_dest,det_integrated_ct_tmp 
     870        Variable ii,new_scale,defMon 
     871         
     872        defMon=1e8                      //default monitor counts 
     873 
     874        // find the scaling factors, one for each folder 
     875        saved_mon_dest = V_getBeamMonNormSaved_count(newType) 
     876        scale_dest = saved_mon_dest/defMon              //un-scaling factor 
     877         
     878        saved_mon_tmp = V_getBeamMonNormSaved_count(tmpType) 
     879        scale_tmp = saved_mon_dest/defMon                       //un-scaling factor 
     880 
     881        new_scale = defMon / (saved_mon_dest+saved_mon_tmp) 
     882         
     883         
     884        // get the count time for each (two locations) 
     885        collection_time_dest = V_getCollectionTime(newType) 
     886        collection_time_tmp = V_getCollectionTime(tmpType) 
     887         
     888        count_time_dest = V_getCount_time(newType) 
     889        count_time_tmp = V_getCount_time(tmpType) 
     890         
     891        detCount_dest = V_getDetector_counts(newType) 
     892        detCount_tmp = V_getDetector_counts(tmpType) 
     893 
     894// update the fields that are not in the detector blocks 
     895// in entry 
     896        V_putCollectionTime(newType,collection_time_dest+collection_time_tmp) 
     897 
     898// in control block 
     899        V_putCount_time(newType,count_time_dest+count_time_tmp) 
     900        V_putDetector_counts(newType,detCount_dest+detCount_tmp) 
     901        V_putControlMonitorCount(newType,saved_mon_dest+saved_mon_tmp) 
     902 
     903 
     904// now loop over all of the detector panels 
     905        // data 
     906        // data_err 
     907        // integrated count 
     908        // linear_data 
     909        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1) 
     910                detStr = StringFromList(ii, ksDetectorListAll, ";") 
     911                 
     912                Wave data_dest = V_getDetectorDataW(newType,detStr) 
     913                Wave data_err_dest = V_getDetectorDataErrW(newType,detStr) 
     914                Wave linear_data_dest = V_getDetectorLinearDataW(newType,detStr) 
     915                det_integrated_ct_dest = V_getDet_IntegratedCount(newType,detStr) 
     916 
     917                Wave data_tmp = V_getDetectorDataW(tmpType,detStr) 
     918                Wave data_err_tmp = V_getDetectorDataErrW(tmpType,detStr) 
     919                Wave linear_data_tmp = V_getDetectorLinearDataW(tmpType,detStr) 
     920                det_integrated_ct_tmp = V_getDet_IntegratedCount(tmpType,detStr) 
     921                 
     922                // unscale the data arrays 
     923                data_dest *= scale_dest 
     924                data_err_dest *= scale_dest 
     925                linear_data_dest *= scale_dest 
     926                 
     927                data_tmp *= scale_tmp 
     928                data_err_tmp *= scale_tmp 
     929                linear_data_tmp *= scale_tmp 
     930                                 
     931                // add them together, the dest is a wave so it is automatically changed in the "dest" folder 
     932                V_putDet_IntegratedCount(tmpType,detStr,det_integrated_ct_dest+det_integrated_ct_tmp) 
     933                data_dest += data_tmp 
     934                data_err_dest = sqrt(data_err_dest^2 + data_err_tmp^2)          // add in quadrature 
     935                linear_data_dest += linear_data_tmp 
     936                 
     937                // now rescale the data_dest to the monitor counts 
     938                data_dest *= new_scale 
     939                data_err_dest *= new_scale 
     940                linear_data_dest *= new_scale 
     941                 
    916942        endfor 
    917 #else 
    918         // dead time correction on all other RAW data, including NCNR 
    919         raw_data *= dscale 
    920         raw_data_err *= dscale 
    921 #endif 
    922  
    923         //update totals by adding RAW values to the local ones (write to work header at end of function) 
    924         total_mon += raw_reals[0] 
    925  
    926         total_det += dscale*raw_reals[2] 
    927  
    928         total_trn += raw_reals[39] 
    929         total_rtime += raw_ints[2] 
    930         total_numruns +=1 
    931          
    932         //do the beamcenter shifting if there is a mismatch 
    933         //and then add the two data sets together, changing "data" since it is the workfile data 
    934         xshift = raw_reals[16] - wrk_beamx 
    935         yshift = raw_reals[17] - wrk_beamy 
    936          
    937         If((xshift != 0) || (yshift != 0)) 
    938                 DoAlert 1,"Do you want to ignore the beam center mismatch?" 
    939                 if(V_flag==1) 
    940                         xshift=0 
    941                         yshift=0 
    942                 endif 
    943         endif 
    944          
    945         If((xshift == 0) && (yshift == 0))              //no shift, just add them 
    946                 data += raw_data                //deadtime correction has already been done to the raw data 
    947                 dest_data_err = sqrt(dest_data_err^2 + raw_data_err^2)                  // error of the sum 
    948         Endif 
    949          
    950         //scale the data to the default montor counts 
    951         scale = defmon/total_mon 
    952         data *= scale 
    953         dest_data_err *= scale 
    954          
    955         // keep "data" and linear_data in sync in the destination folder 
    956         data_copy = data 
    957          
    958         //all is done, except for the bookkeeping of updating the header info in the work folder 
    959         textread[1] = date() + " " + time()             //date + time stamp 
    960         integersread[3] = total_numruns                                         //numruns = more than one 
    961         realsread[1] = total_mon                        //save the true monitor count 
    962         realsread[0] = defmon                                   //monitor ct = defmon 
    963         integersread[2] = total_rtime                   // total counting time 
    964         realsread[2] = scale*total_det                  //scaled detector counts 
    965         realsread[39] = scale*total_trn                 //scaled transmission counts 
     943 
    966944         
    967945        //Add the added raw filename to the list of files in the workfile 
    968         String newfile = ";" + raw_text[0] 
    969         SVAR oldList = $(destPath + ":fileList") 
    970         String/G $(destPath + ":fileList") = oldList + newfile 
     946        SVAR fileList_dest = $("root:Packages:NIST:VSANS:"+newType+":gFileList") 
     947        SVAR fileList_tmp = $("root:Packages:NIST:VSANS:"+tmpType+":gFileList") 
     948         
     949        fileList_dest += ";" + fileList_tmp 
    971950         
    972951        //reset the current display type to "newtype" 
Note: See TracChangeset for help on using the changeset viewer.