Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Handling of data gaps during the livetime computation: Fermi data on-ground can have two different kinds of gaps: gaps in the Digi file or gaps in the Merit file. The former type can be the results of a copy/download problem from the spacecraft or the ground stations, while the latter can be caused by a problem during the reconstruction (the Recon step). Both of them can also result from problems during the merging of different chunks of data. Note that all these problems are usually temporary, and gaps are usually filled with a roll back of the appropriate processing steps. The old code used to try to compensate for those gaps, by subtracting the corresponding deadtime from the livetime of the affected bin(s). The new code instead isolates the time span affected by these problems in single bins, which will have zero livetime, and thus will generate bad time intervals which will be excluded by downstream software (like the Science Tools).
  • Sun coordinates: the new code now compute the Sun coordinates for each bin and saves them in the output FT2 file.
  • Exploit all the attitude information: the attitude information is issued by the spacecraft at 5 Hz, and it is formatted in ATT messages available on-ground in the so-called "Magic 7" files. The position information instead is issued by the spacecraft at 1 Hz. The old code used only those ATT messages issued contemporaneously to ORB messages, discarding the others. The new code instead keeps all the information. So when interpolation is needed, the old code have less information than the new one, slightly degrading the quality of the interpolations. The difference is anyway unimportant in most of the circumstances, leading to very small improvement in the quality of the interpolations and extrapolations of the satellite attidueattitude.
  • Check for proper input: the new code check that both the Digi file both the Merit file are ordered by event ID and time, and crashes throws an exception if this is not the case. Out of order events can result from merging or download problem.

Algorithms

Validation

Here I collect the results of the testing I performed, comparing the output generated by the old ft2Util code with the output generated by my code.

I used the version of the old code currently used in the PROD pipeline (v1r2p32), and I compiled my code and the old one against GlastRelease-v15r47p12gr21.

...

Output testing

Procedure

I selected 100 runs (from 323423607 to 323989797), then for each run I submitted a different jobs to the farm. Each job performed these steps:

...

Old code

New code

Gallery
includeandrea_05s.jpg
Gallery
includeio_05s.jpg

Gap handling

Procedure

I modified one Digi file and one Merit file deliberately inserting gaps, and I check if the code can find them and handle them correctly.

In particular, I downloaded from the data catalog a Digi and a Merit file for run 327356667 ("r0327356667_v001_digi.root" and "r0327356667_v120_merit.root"), and I select the events with 100000 < event ID < 700000 in both files. Then I inserted these gaps:

  • I removed from the Digi file "r0327356667_v001_digi.root" downloaded from the data catalog all events between 81.3 and 84.6 seconds from the time stamp of the first event in the file (a total of 2609 events removed). The last event before the gap has eventID = 145973 and the first event after the gap has eventID = 159384. I also overwritten the livetime counter making it equal to the elapsed time counter (thus, deadtime = 0). This is saved in "data/r0327356667_digi_gaps.root".
  • I removed from the Merit file the events with these IDs: 199996 (which is comprised between event 199993 and event 200002), 2000031 (which is comprised between event 200029 and event 200035), and all the events with 300544 < event ID < 300858. This is saved in "data/r0327356667_v001_merit_crashes.root".
  • I inserted by hand two fake gaps in the digi Gap file, excluding events in these ranges of event IDs: 129504-181395 and 273973-280562. This is saved in "data/r0327356667_v001_digiGap_2gaps.txt"

All the files with the gaps are available in the /data directory of the package, as well as the ROOT macros used to produce them. Note that they contain only the variables used in the FT2 code (to reduce their size).

The following is the output of the code used to produce the FT2 file with time bin of 1 s. As you can see, it finds all the gaps. There are a couple of "INTERPOLATION NEEDED" messages, which are expected, and correspond to the beginning and the end of the bad time intervals (which is also the beginning of the bin after the bad time interval):

Code Block


Input parameters: 
--------------------------------------------------
Desired start time for the FT2        :327356689.88605165482
Desired stop time for the FT2         :327356838.64119803905
Magic 7 file                          :../data/r0327356667_v001_magic7L1.txt
Output FT2 file                       :test.fits
Input Digi file                       :../data/r0327356667_digi_gaps.root
Input Merit file                      :../data/r0327356667_v001_merit_crashes.root
Input Digi Gap file                   :../data/r0327356667_v001_digiGap_2gaps.txt
Overwrite an existing FT2 file        :yes
Data quality flag                     :2
LAT configuration                     :1
Template for the FT2 file             :/afs/slac/g/glast/ground/glastsoft/AUTO_GLAST/arch/os/SCONS_BUILDS/Optimized/ScienceTools/09-25-01/fitsGen/data/ft2.tpl
Version number for the FT2 file       :1


Configuration: 
(from file /a/wain006/g.glast.u55/giacomov/ft2/users/giacomov/ft2Util_2/v0r0p0/data/configuration.rc)
--------------------------------------------------
packageName                           :ft2Util_2
packageVersion                        :v0r0p0
packageAuthor                         :G.Vianello
packageAuthorEmail                    :giacomov@slac.stanford.edu
JulianDateMissionStart                :211845067200
NULL_TIME_DIFFERENCE                  :1e-06
sweepEventsDelayEnd                   :20000
ticksPerCommand                       :196
RollOver                              :33554432
nominalTicksToSecond                  :5e-08
Rx                                    :-170
Ry                                    :-173
Rz                                    :-491
magic7ReadPadding                     :30
verify                                :yes
deadPad                               :1
Magic 7 file ../data/r0327356667_v001_magic7L1.txt opened

Magic 7 content:
--------------------------------------------------
N. of ATT messages                    :1044
Time of the first ATT message (MET)   :327356660
Time of the last ATT message (MET)    :327356868.6
N. of ORB messages                    :209
Time of the first ORB message (MET)   :327356660.6
Time of the last ORB message (MET)    :327356868.6

First concurrent ORB and ATT messages at time (MET):   327356660.6

INFO: Ft2::Ft2():: There are 29 time bins before the requested start covered by the Magic7 file which are not needed

Rebuilding Digi index... done
Building Merit index... done

Livetime::Livetime(): the input Digi file lacks a sweep event at the beginning. This means it does not span an entire run.
Livetime input:
--------------------------------------------------
N. of Digi events                     :110325
Time of the first Digi event (MET)    :327356689.88605
ID of the first Digi event            :100001
Time of the last Digi event (MET)     :327356838.6412
ID of the last Digi event             :699997
N. of Merit events                    :112874
Time of the first Merit event (MET)   :327356689.88605
Time of the last Merit event (MET)    :327356838.6412
Sweep events at the beginning:        :0
Sweep events at the end:              :0

Rebuilding Digi index... done
Building Merit index... done


Gap file ../data/r0327356667_v001_digiGap_2gaps.txt parsed:
--------------------------------------------------
N. of gaps for this run               :2
gaps:
327356697.132590115070343 - 327356709.861321747303009
327356732.6005374193191528 - 327356734.2353370785713196


Checking Merit and Digi for errors or gaps: 

    0 % completed
   10 % completed
GapHandler: gap in the Merit file between event 199993 and event 200002
You lost 1 event (these events are contained in a bad time interval, which will be excluded by downstream software)

GapHandler: gap in the Merit file between event 200029 and event 200035
You lost 1 event (these events are contained in a bad time interval, which will be excluded by downstream software)

   20 % completed
   30 % completed
GapHandler: gap in the Merit file between event 300544 and event 300858
You lost 58 event (these events are contained in a bad time interval, which will be excluded by downstream software)

   40 % completed
   50 % completed
GapHandler: gap in the Digi file between event 429501 and event 442840
You lost 2609 event (these events are contained in a bad time interval, which will be excluded by downstream software)

   60 % completed
   70 % completed
   80 % completed
   90 % completed

WARNING: There are gaps either in the Merit either in the Digi file (or both).


Bad time intervals:
327356697.132590115070343 - 327356709.861321747303009
327356732.6005374193191528 - 327356734.2353370785713196
327356714.4137212038040161 - 327356714.4157781600952148
327356714.4220960736274719 - 327356714.423194944858551
327356739.1916109323501587 - 327356739.2655935287475586
327356771.1854096651077271 - 327356774.4867381453514099

Now parse the file and compute the quantities to be saved in the FT2 file:
---------------------------------------------------------------------------
    0 % completed
WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356689.88605


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356689.88605
Performing SLERP between 327356689.8 and 327356690 to get attitude at time 327356689.88605 (fraction: 0.43025824011911 s )

WARNING: Magic7::getMode(): no ORB message at time 327356689.88605 . Returning the last known mode (5), reported in the ORB message at time 327356689.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356689.88605 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356689.6

WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356697.13259


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356697.13259
Performing SLERP between 327356697 and 327356697.2 to get attitude at time 327356697.13259 (fraction: 0.66295061486665 s )

WARNING: Magic7::getMode(): no ORB message at time 327356697.13259 . Returning the last known mode (5), reported in the ORB message at time 327356696.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356697.13259 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356696.6

WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356709.86132


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356709.86132
Performing SLERP between 327356709.8 and 327356710 to get attitude at time 327356709.86132 (fraction: 0.3066086951857 s )

WARNING: Magic7::getMode(): no ORB message at time 327356709.86132 . Returning the last known mode (5), reported in the ORB message at time 327356709.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356709.86132 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356709.6

WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356714.41372


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356714.41372
Performing SLERP between 327356714.4 and 327356714.6 to get attitude at time 327356714.41372 (fraction: 0.068606121872396 s )

WARNING: Magic7::getMode(): no ORB message at time 327356714.41372 . Returning the last known mode (5), reported in the ORB message at time 327356713.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356714.41372 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356713.6

   10 % completed
WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356714.41578


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356714.41578
Performing SLERP between 327356714.4 and 327356714.6 to get attitude at time 327356714.41578 (fraction: 0.078890900876307 s )

WARNING: Magic7::getMode(): no ORB message at time 327356714.41578 . Returning the last known mode (5), reported in the ORB message at time 327356713.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356714.41578 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356713.6

WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356714.4221


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356714.4221
Performing SLERP between 327356714.4 and 327356714.6 to get attitude at time 327356714.4221 (fraction: 0.11048046100605 s )

WARNING: Magic7::getMode(): no ORB message at time 327356714.4221 . Returning the last known mode (5), reported in the ORB message at time 327356713.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356714.4221 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356713.6

WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356714.42319


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356714.42319
Performing SLERP between 327356714.4 and 327356714.6 to get attitude at time 327356714.42319 (fraction: 0.11597481585149 s )

WARNING: Magic7::getMode(): no ORB message at time 327356714.42319 . Returning the last known mode (5), reported in the ORB message at time 327356713.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356714.42319 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356713.6

   21 % completed
WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356732.60054


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356732.60054
Performing SLERP between 327356732.6 and 327356732.8 to get attitude at time 327356732.60054 (fraction: 0.002686977546631 s )

WARNING: Magic7::getMode(): no ORB message at time 327356732.60054 . Returning the last known mode (5), reported in the ORB message at time 327356732.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356732.60054 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356732.6

WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356734.23534


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356734.23534
Performing SLERP between 327356734.2 and 327356734.4 to get attitude at time 327356734.23534 (fraction: 0.17668546299252 s )

WARNING: Magic7::getMode(): no ORB message at time 327356734.23534 . Returning the last known mode (5), reported in the ORB message at time 327356733.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356734.23534 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356733.6

WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356739.19161


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356739.19161
Performing SLERP between 327356739 and 327356739.2 to get attitude at time 327356739.19161 (fraction: 0.9580547188553 s )

WARNING: Magic7::getMode(): no ORB message at time 327356739.19161 . Returning the last known mode (5), reported in the ORB message at time 327356738.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356739.19161 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356738.6

   31 % completed
WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356739.26559


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356739.26559
Performing SLERP between 327356739.2 and 327356739.4 to get attitude at time 327356739.26559 (fraction: 0.32796772289084 s )

WARNING: Magic7::getMode(): no ORB message at time 327356739.26559 . Returning the last known mode (5), reported in the ORB message at time 327356738.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356739.26559 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356738.6

   41 % completed
   52 % completed
WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356771.18541


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356771.18541
Performing SLERP between 327356771 and 327356771.2 to get attitude at time 327356771.18541 (fraction: 0.92704838079502 s )

WARNING: Magic7::getMode(): no ORB message at time 327356771.18541 . Returning the last known mode (5), reported in the ORB message at time 327356770.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356771.18541 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356770.6

WARNING: Magic7::getPosition(): interpolation needed to get position at time 327356774.48674


----------------------
INTERPOLATIONS NEEDED

Magic7::getQuaternion(): interpolation needed to get quaternion at time 327356774.48674
Performing SLERP between 327356774.4 and 327356774.6 to get attitude at time 327356774.48674 (fraction: 0.43369074256641 s )

WARNING: Magic7::getMode(): no ORB message at time 327356774.48674 . Returning the last known mode (5), reported in the ORB message at time 327356773.6


WARNING: Magic7::getInSAA():  no ORB message at time 327356774.48674 . Returning the last known value for the in_SAA flag (0), reported in the ORB message at time 327356773.6

   62 % completed
   72 % completed
   83 % completed
   93 % completed
FT2 time bins:
--------------------------------------------------
N. of bins                            :145
Beginning (MET)                       :327356689.88605
End (MET)                             :327356838.6412

This is a plot of the livetime in the output FT2 file:

Image Added

As you can see, most bins have livetime = 1. The bin corresponding to the gaps have livetime = 0, while the bins surrounding the gaps have 1 < livetime < 0.

This is a table summarizing the gap and the corresponding bin in the FT2 file:

Event before and after the gap

Corresponding time interval
directly read from the
original Digi file

FT2 file start-stop

Livetime in the FT2 file

Gap type

129504 - 181395

327356697.1325891 - 327356709.8613227

327356697.1325901 - 327356709.8613217

0.000000

Gap from the Digi gap file

273973 - 280562

327356732.6005364 - 327356734.2353380

327356732.6005374 - 327356734.2353370

0.000000

Gap from the Digi gap file

199993 - 200002

327356714.4137201 - 327356714.4157791

327356714.4137212 - 327356714.4157781

0.000000

Gap in the Merit

200029 - 200035

327356714.4220950 - 327356714.4231959

327356714.4220960 - 327356714.4231949

0.000000

Gap in the Merit

300544 - 300858

327356739.1916099 - 327356739.2655945

327356739.1916109 - 327356739.2655935

0.000000

Gap in the Merit

429501 - 442840

327356771.1854086 - 327356774.4867391

327356771.1854096 - 327356774.4867381

0.000000

Gap in the Digi

As you can see, everything is right.

Now, using mergeFT2.exe to rebin the FT2 file gives this:

Code Block

./mergeFT2.exe -inputFT2 test.fits -outputFT2 test_30s.fits -clobber yes                             

Input parameters: 
---------------------------------------------
Input FT2 file                             : test.fits
Output FT2 file                            : test_30s.fits
Overwrite an existing FT2 file             : yes          
File version                               : 1            
Time step for the output FT2 file          : 30           


* Entry number 1:
  WARNING: livetime=0 at 327356697.13259. Stopping there. 
  327356689.88605 ........ 327356697.13259                
  Elapsed time 7.24654, Livetime = 7.24654 (100 %)        

* Entry number 2:
  Starting from livetime=0 at 327356709.86132
  327356697.13259 . 327356709.86132          
  Elapsed time 12.7287, Livetime = 0 (0 %)   

* Entry number 3:
  WARNING: livetime=0 at 327356714.41372. Stopping there. 
  327356709.86132 ..... 327356714.41372                   
  Elapsed time 4.5524, Livetime = 4.5524 (100 %)          

* Entry number 4:
  Starting from livetime=0 at 327356714.41578
  327356714.41372 . 327356714.41578          
  Elapsed time 0.00205696, Livetime = 0 (0 %)

* Entry number 5:
  WARNING: livetime=0 at 327356714.4221. Stopping there. 
  327356714.41578 . 327356714.4221                       
  Elapsed time 0.00631791, Livetime = 0.00631792 (100 %) 

* Entry number 6:
  Starting from livetime=0 at 327356714.42319
   327356714.4221 . 327356714.42319          
  Elapsed time 0.00109887, Livetime = 0 (0 %)

* Entry number 7:
  WARNING: livetime=0 at 327356732.60054. Stopping there. 
  327356714.42319 .................... 327356732.60054    
  Elapsed time 18.1773, Livetime = 18.1773 (100 %)        

* Entry number 8:
  Starting from livetime=0 at 327356734.23534
  327356732.60054 . 327356734.23534          
  Elapsed time 1.6348, Livetime = 0 (0 %)    

* Entry number 9:
  WARNING: livetime=0 at 327356739.19161. Stopping there. 
  327356734.23534 ...... 327356739.19161                  
  Elapsed time 4.95627, Livetime = 4.95627 (100 %)        

* Entry number 10:
  Starting from livetime=0 at 327356739.26559
  327356739.19161 . 327356739.26559          
  Elapsed time 0.0739826, Livetime = 0 (0 %) 

* Entry number 11:
  327356739.26559 .............................. 327356768.6
  Elapsed time 29.3344, Livetime = 29.3344 (100 %)

* Entry number 12:
  WARNING: livetime=0 at 327356771.18541. Stopping there.
      327356768.6 ... 327356771.18541
  Elapsed time 2.58541, Livetime = 2.58541 (100 %)

* Entry number 13:
  Starting from livetime=0 at 327356774.48674
  327356771.18541 . 327356774.48674
  Elapsed time 3.30133, Livetime = 0 (0 %)

* Entry number 14:
  327356774.48674 .............................. 327356803.6
  Elapsed time 29.1133, Livetime = 29.1133 (100 %)

* Entry number 15:
      327356803.6 .............................. 327356833.6
  Elapsed time 30, Livetime = 30 (100 %)

* Entry number 16:
      327356833.6 ...... 327356838.6412
  Elapsed time 5.0412, Livetime = 5.0412 (100 %)

As you can see the code stops when it encounter bins with livetime=0, and keep them isolated. Thus, even if the target bin time is 30 s, there is only one bin that long (# 15). The others are prematurely stopped because of the gaps.