Programming Notes for THaScaler

Programming Notes for THaScaler Class

Updated May 12, 2004.  R. Michaels, JLab

See always the README file (I try to keep that up-to-date).
To use the THaScaler class, you should only need to look at
THaScaler.h (header) to see the public interface.  All the
methods you need should be there.  

---------------------------------------------------------------
The basic steps to obtain scaler data:

   1. Make sure you have the scaler map file in your directory.
      See 'scaler.map' in /hana_scaler or ask Bob Michaels.

   2. Once in the life of the object, you must call the 
      THaScaler::Init() method with appropriate arguments.

         THaScaler scaler;
         scaler.Init("Left");  // Left spectrometer
      or
         scaler.Init("7-4-1999","Left");   // use scaler.map after
                                           // date = Apr 7, 1999.
      (If you don't have the date argument, it uses the most recent
       map, which for old data might not be what you want, a *very*
       common error -- see "comments about DATE" below).

   3. Each event, you must LoadData.  There are several ways to
      load data:  from a THaEvData object, directly from a CODA
      file, from a scaler history file, from online (directly from
      VME crates). 

         scaler.LoadData(evdata);  // evdata is a THaEvData object

      (IMPORTANT:  Loading from THaEvData only works if its THaCrateMap 
      is initialized correctly.  But there are several other ways
      to LoadData, see THaScaler.h).

   4. Now you may access data via the methods in THaScaler.h
      If you know the slot and channel, simply

         THaScaler scaler;
         data = scaler.GetScaler(slot, chan);       // Counts

                 - or -

         datarate = scaler.GetScalerRate(slot, chan);  // rate, Hz

      The rates are computed using the last two readings, normalized
      to a pulser clock.  
      There are a number of other access methods for detectors,
      beam current monitors, different helicities gated scalers, etc.

   5. Normally in THaAnalyzer, on calls THaScaler::PrintSummary() at 
      the end of analysis.


Comments about DATE in scaler.map:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      The most common mistake using THaScaler is to not initialize
      with the correct date.  Suppose your experiment ran in October
      of 2001.  You can do "grep DATE scaler.map" and might see:

         DATE 29 12 2003
         DATE 1 1 2003
         DATE 1 9 2002
         DATE 31 12 2001
         DATE 17 9 2001 
         DATE 15 5 2001
         DATE 1 1 2001
         DATE 1 11 2000
         DATE 1 9 2000
         DATE 6 11 1999
         DATE 20 8 1998

       Now you may do scaler->Init("18-9-2001","Left") to use the
       map from between 17-9-2001 and 31-12-2001 (day-month-year).
       The Init() method is overloaded, so that if you leave out
       the date field it will use the most recent DATE, which in
       this case is Dec 29, 2003 and might not be what you want.

---------------------------------------------------------------
There are two ways to implement scalers

   1. Inside the analyzer, see "simplest usage" at
      hallaweb.jlab.org/equipment/daq/THaScaler.html.    
      This is the preferred way now.

   2. Standalone codes that rapidly pick out scaler data and
      do some analysis.  See the *main* routines.  Use the
      flag STANDALONE=1 in Makefile.  

---------------------------------------------------------------
How to run standalone:

    Often scaler analyses can be done as an activity 
    seperate from physics event analysis. You may 
    therefore want to run simple standalone codes,
    e.g. the codes with the word "main" in their name.

    Examples of what is available:
    Test Executibles (compiled if STANDALONE=1)
    tscalfile -- Read a CODA file and print various scaler data.
    tscalasy  -- Read CODA file and compute helicity correl. charge asy
    tscalhist -- Read "End-Run-History" file (generated by DAQ) 
                 and print summaries of #triggers, charge, etc.
    tscalonl -- Read data from VME online and print scaler data.
    xscaler --  xscaler++  Scaler GUI.  
    tscalntup -- Read CODA file (evtype 140), fills an ntuple w/ stuff
    tscaldtime -- Reads CODA file, checks deadtime
    tscalroc11 -- To read the ROC11 scalers (from 'physics' triggers)
    tscalevt -- Analysis of ROC10/11 scalers.
    tscalring -- Similar to tscalroc11, but more detailed analysis.

Instructions:

  1. You need the event decoder library.  Compile it with
     STANDALONE=1 in Makefile.  The most recent event decoder
     ships with the Root/C++ analyzer , 
     or you can get it from www.jlab.org/~rom/hana_decode_2.2.tar 

  2. Put a copy of the event decoder library into the hana_scaler
     directory and compile the "main" routines there with
     STANDALONE=1 in Makefile.

    The directory structure of the C++ analyzer is normally

                  
           /analyzer
                    \
                     \
                      /hana_scaler
                     |
                     |
                      /hana_decode

    Here are explicit instructions on ifarml1 

        use gcc/3.2.3
        use root/3.05-07-gcc3.2.3
       (of course, you can use other versions but you
        must be CONSISTENT)

    Make the decoder:
       (assuming it is version 2.3)
       cp ~rom/public_html/hana_decode_2.3.tar .
       tar xvf hana_decode_2.3.tar
       cd hana_decode
       Before compiling I had to do 3 things:
       1) since there is no ET library I edited 
         haDecode_LinkDef.h to remove the THaEtClient line
       2) Edited Makefile to comment out the line 
          "export ONLINE_ET = 1".
       3) Make STANDALONE=1 in Makefile.

       /bin/rm *.o *.d ; make clean ; make
       Now one can run a test code (see README and all the
       *main*.C codes) like this
       ./tdecpr e94107_2090.dat.0 
       ./tstio 1
 
    Make the scaler package (from above step, "cd .." first).
       (assuming it is version 4.0)
       cp ~rom/public_html/hana_scaler_4.0.tar .
       tar xvf hana_scaler_4.0.tar
       cd hana_scaler
       (assuming you compiled hana_decode in ../hana_decode):
       cp ../hana_decode/libdc.a libdc_local.a
       Before compiling, edit Makefile and set STANDALONE=1.
       /bin/rm *.o *.d ; make clean ; make
       Or for example you can "make tscalntup" (see tscalntup_main.C)
       Then
      ./tscalntup e94107_2090.dat.0 Left

This page maintained by rom@jlab.org