Exemple #1
0
def category_vs_time(oMap={}, oMapBcn={}, iMap={}, iMapBcn={}, innerEvent={}):
    d = {}
    for oEntry, (evn, orn) in oMap.iteritems():
        bcn = oMapBcn[oEntry]
        time = utils.minutes(orn, bcn)
        if innerEvent.get(oEntry) is not None:
            d[time] = (3, evn, orn, bcn)
        else:
            d[time] = (2, evn, orn, bcn)

    iEntries = innerEvent.values()
    for iEntry, (evn, orn) in iMap.iteritems():
        if iEntry in iEntries:
            continue
        bcn = iMapBcn[iEntry]
        time = utils.minutes(orn, bcn)
        d[time] = (1, evn, orn, bcn)

    return d
Exemple #2
0
def category_vs_time(oMap={}, oMapBcn={}, iMap={}, iMapBcn={}, innerEvent={}):
    d = {}
    for oEntry, (evn, orn) in oMap.iteritems():
        bcn = oMapBcn[oEntry]
        time = utils.minutes(orn, bcn)
        if innerEvent.get(oEntry) is not None:
            d[time] = (3, evn, orn, bcn)
        else:
            d[time] = (2, evn, orn, bcn)

    iEntries = innerEvent.values()
    for iEntry, (evn, orn) in iMap.iteritems():
        if iEntry in iEntries:
            continue
        bcn = iMapBcn[iEntry]
        time = utils.minutes(orn, bcn)
        d[time] = (1, evn, orn, bcn)

    return d
Exemple #3
0
def oneFed(d={}, overview=True, headers=True, channelData=True, skip={}):
    if "fed" not in skip:
        print "   ".join([
            "  %3d" % d["FEDid"],
            "0x%07x" % d["EvN"],
            "0x%08x" % d["OrN"],
            "%4d" % d["BcN"],
            "%7.3f" % utils.minutes(d["OrN"]),
            "  %1x" % d["TTS"],
            "    %4d" % (d["nWord64"] * 8),
            "    %4d" % d["nBytesSW"],
            " 0x%04x" % d["CRC16"],
        ])
        if overview:
            htrOverview(d)

    if headers:
        htrData(d, channelData=channelData, skip=skip)
Exemple #4
0
def oneFedHcal(d={},
               patterns=False,
               dump=None,
               crateslots=[],
               nonMatchedQie=[],
               nonMatchedTp=[],
               printHeaders=None):
    h = d["header"]
    t = d["trailer"]
    if (not patterns) and (1 <= dump):
        fields = [
            " FEDid",
            "  EvN",
            "       OrN",
            "    BcN",
            "minutes",
            " TTS",
            " nBytesHW",
            "nBytesSW",
            #"CRC16",
            "nSkip16",
            "BcN12",
            "EvN8",
            "Blk8",
        ]

        if printHeaders:
            headers = "   ".join(fields)
            printer.blue("-" * len(headers))
            printer.blue(headers)

        sList = [
            " %4d" % h["FEDid"],
            "0x%07x" % h["EvN"],
            "0x%08x" % h["OrN"],
            "%4d" % h["BcN"],
            "%7.3f" % utils.minutes(h["OrN"], h["BcN"]),
            ("  %1x" % t["TTS"]) if "TTS" in t else "  - ",
            ("   %5d" % (t["nWord64"] * 8)) if "nWord64" in t else "    --  ",
            "   %5d" % d["nBytesSW"],
            #(" 0x%04x" % t["CRC16"]) if "CRC16" in t else "   - ",
            "%7d" % d["nWord16Skipped"],
        ]
        if h["uFoV"]:
            sList += [
                "   %4d" % t["BcN12"],
                "0x%02x" % t["EvN8"],
                "  %2d" % t["Blk_no8"],
            ]

        printer.blue("   ".join(sList))
        if 2 <= dump:
            htrOverview(h)

    printColumnHeaders = True
    for iBlock, block in sorted(d["htrBlocks"].iteritems()):
        if "patternData" in block:
            oneHtrPatterns(p=block, patterns=patterns, header=h, iBlock=iBlock)
        elif 3 <= dump:
            printColumnHeaders = oneHtr(
                p=block,
                printColumnHeaders=printColumnHeaders,
                dump=dump,
                crateslots=crateslots,
                utca=h["utca"],
                nonMatchedQie=nonMatchedQie,
                nonMatchedTp=nonMatchedTp,
            )
Exemple #5
0
def singleFedPlots(fedId=None, d={}, book={}, **other):
    book.fill(d["nWord16Skipped"],
              "nWord16Skipped_%d" % fedId,
              14,
              -0.5,
              13.5,
              title="FED %d;nWord16 skipped during unpacking;Events / bin" %
              fedId)

    h = d["header"]
    t = d["trailer"]
    if "TTS" in t:
        book.fill(t["TTS"],
                  "TTS_%d" % fedId,
                  16,
                  -0.5,
                  15.5,
                  title="FED %d;TTS state;Events / bin" % fedId)

    if "BcN" in h:
        book.fill(h["BcN"] / 100.0,
                  "BcN_%d" % fedId,
                  hw.nBx,
                  0,
                  hw.nBx / 100.0,
                  title="FED %d;BcN / 100;Events / bin" % fedId)

    msg = "FED %d" % fedId
    fedEvn = h.get("EvN")
    fedOrn = h.get("OrN")
    fedBcn = h.get("BcN")

    if fedEvn is None:
        printer.error("FED %d lacks EvN.  Keys: %s" % str(h.keys()))
        msg = ""
    else:
        msg = utils.coords(fedId, fedEvn, fedOrn, fedBcn)

    htrOverviewBits(h, book, fedId, msg=msg, warn=other["warn"])

    fedTime = utils.minutes(fedOrn, fedBcn)

    nBadHtrs, ErrF, caps, adcs, fracEvN, fracADC, fracTP = htrSummary(
        blocks=d["htrBlocks"].values(),
        book=book,
        fedId=fedId,
        fedEvn=fedEvn,
        fedOrn5=fedOrn & 0x1f,
        fedBcn=fedBcn,
        msg=msg,
        fedTime=fedTime,
        **other)

    errFSum = 0.0 + sum(ErrF.values())

    if errFSum:
        for code, n in ErrF.iteritems():
            title = "FED %d;frac. chan. with ErrF == %d;Events / bin" % (fedId,
                                                                         code)
            book.fill(n / errFSum,
                      "ErrF%d_%d" % (code, fedId),
                      44,
                      0.0,
                      1.1,
                      title=title)

        frac0 = ErrF[0] / errFSum
    else:
        frac0 = -999.  # dummy

    book.fillGraph((fedTime, frac0),
                   "frac0_vs_time_%d" % fedId,
                   title=("FED %d" % fedId) +
                   ";time (minutes);frac. chan. with ErrF == 0")

    if fracEvN is not None:
        book.fillGraph((fedTime, fracEvN),
                       "fracEvN_vs_time_%d" % fedId,
                       title=("FED %d" % fedId) +
                       ";time (minutes);frac. HTRs with EvN == FED's")

    if fracADC is not None:
        book.fillGraph(
            (fedTime, fracADC),
            "ADC_misMatch_vs_time_%d" % fedId,
            title=("FED %d" % fedId) +
            ";time (minutes);#splitline{(# ch. match. ADCs) /}{(# ch. match. + ch. mismatch.)}"
        )

    if fracTP is not None:
        book.fillGraph(
            (fedTime, fracTP),
            "TP_misMatch_vs_time_%d" % fedId,
            title=("FED %d" % fedId) +
            ";time (minutes);#splitline{(# match. TPs) /}{(# match. + mismatch. TPs)}"
        )

    book.fillGraph((fedTime, t["nWord64"] * 8.0 / 1024),
                   "kB_vs_time_%d" % fedId,
                   title=("FED %d" % fedId) + ";time (minutes);kB")

    book.fill(
        (fedBcn / 100.0, frac0),
        "frac0_vs_BcN_%d" % fedId, (hw.nBx, 6), (0.0, 0.0),
        (hw.nBx / 100.0, 1.2),
        title=";FED %d   (BcN / 100);frac. chan. with ErrF == 0;Events / bin" %
        fedId)

    capSum = 0.0 + sum(caps.values())
    if capSum:
        book.fill(max(caps.values()) / capSum,
                  "PopCapFrac_%d" % fedId,
                  44,
                  0.0,
                  1.1,
                  title=("FED %d" % fedId) +
                  ";frac. ErrF=0 chans w/most pop. capId;Events / bin")

    book.fill(nBadHtrs,
              "nBadHtrs_%d" % fedId,
              16,
              -0.5,
              15.5,
              title="FED %d; N bad HTRs;Events / bin" % fedId)
    return nBadHtrs, adcs
Exemple #6
0
def main():
    print(sys.argv)

    phi = 42.3583 * math.pi / 180
    lw = 0;

    a = Arguments(sys.argv)

    if a.has_errors():
        a.print_error()
        return

    if a.is_lat_given():
        phi = a.latitude * math.pi / 180

    if a.is_long_given():
        lw = a.longitude * math.pi / 180        

    if a.is_date_given():
        delta_t = a.date_arg - J2000_DATE
        d = delta_t.days - 1
        day_of_year = a.date_arg.timetuple().tm_yday - 1
        t0_utc = utils.t0_utc(d)
        lambda_s = orbit.lambda_s(t0_utc)
        cel_coords = celestial_coords.from_ecliptic_coords(lambda_s)
        delta = cel_coords[0]
        alpha = cel_coords[1]
        t_rise_utc = horizon_coords.t_rise_utc(cel_coords, phi, lw, t0_utc)
        t_set_utc = horizon_coords.t_set_utc(cel_coords, phi, lw, t0_utc)
        print_str = "day: " + str(day_of_year)
        print_str += ", sunrise: " + str(utils.hours(t_rise_utc)) + ":" + str(round(utils.minutes(t_rise_utc) + float(utils.seconds(t_rise_utc))/60, 3))
        print_str += ", sunset: " + str(utils.hours(t_set_utc)) + ":" + str(utils.minutes(t_set_utc)) + ":" + str(utils.seconds(t_set_utc))
        print(print_str) 
        return

    # Calculate rise set times for latitudes ranging from -65 to 65 degrees at 5 degree increments
    rs = [[]]
    for p in range(-13, 14):
        i = 0
        phi = (p * 5) * math.pi / 180
        rs.append([])
        while i < 366:
            delta_t = JAN_1_2012 - J2000_DATE + datetime.timedelta(1)*i
            d = delta_t.days
            t0_utc = utils.t0_utc(d)
            lambda_s = orbit.lambda_s(t0_utc)
            cel_coords = celestial_coords.from_ecliptic_coords(lambda_s)
            delta = cel_coords[0]
            alpha = cel_coords[1]
            t_rise_utc = horizon_coords.t_rise_utc(cel_coords, phi, lw, t0_utc)
            t_set_utc = horizon_coords.t_set_utc(cel_coords, phi, lw, t0_utc)
            date1 = J2000_DATE + delta_t
            
            rs_current = RiseSet(date1, t_rise_utc, t_set_utc)
            rs[p + 13].append(rs_current)
            day_of_year = date1.timetuple().tm_yday - 1
            print_str = str(rs_current.get_day_of_year())
            print_str += ", sunrise: " + str(utils.hours(t_rise_utc)) + ":" + str(round(utils.minutes(t_rise_utc) + float(utils.seconds(t_rise_utc))/60, 3))
            print_str += ", sunset: " + str(utils.hours(t_set_utc)) + ":" + str(round(utils.minutes(t_set_utc) + float(utils.seconds(t_set_utc))/60, 3))
            i = i + 1

    with open("rise_set_data.js", mode="w") as f:
        json.dump(rs, f, indent=2, cls=RiseSetUTCJsonEncoder)

    print("Calculated rise/set times, placed in rise_set_data.js.")
Exemple #7
0
def singleFedPlots(fedId=None, d={}, book={}, **other):
    book.fill(d["nWord16Skipped"], "nWord16Skipped_%d" % fedId, 14, -0.5, 13.5,
              title="FED %d;nWord16 skipped during unpacking;Events / bin" % fedId)

    h = d["header"]
    t = d["trailer"]
    if "TTS" in t:
        book.fill(t["TTS"], "TTS_%d" % fedId, 16, -0.5, 15.5,
                  title="FED %d;TTS state;Events / bin" % fedId)

    if "BcN" in h:
        book.fill(h["BcN"] / 100.0, "BcN_%d" % fedId, hw.nBx, 0, hw.nBx / 100.0,
                  title="FED %d;BcN / 100;Events / bin" % fedId)

    msg = "FED %d" % fedId
    fedEvn = h.get("EvN")
    fedOrn = h.get("OrN")
    fedBcn = h.get("BcN")

    if fedEvn is None:
        printer.error("FED %d lacks EvN.  Keys: %s" % str(h.keys()))
        msg = ""
    else:
        msg = utils.coords(fedId, fedEvn, fedOrn, fedBcn)

    htrOverviewBits(h, book, fedId, msg=msg, warn=other["warn"])

    fedTime = utils.minutes(fedOrn, fedBcn)

    nBadHtrs, ErrF, caps, adcs, fracEvN, fracADC, fracTP = htrSummary(blocks=d["htrBlocks"].values(),
                                                                      book=book,
                                                                      fedId=fedId,
                                                                      fedEvn=fedEvn,
                                                                      fedOrn5=fedOrn & 0x1f,
                                                                      fedBcn=fedBcn,
                                                                      msg=msg,
                                                                      fedTime=fedTime,
                                                                      **other)

    errFSum = 0.0 + sum(ErrF.values())

    if errFSum:
        for code, n in ErrF.iteritems():
            title = "FED %d;frac. chan. with ErrF == %d;Events / bin" % (fedId, code)
            book.fill(n/errFSum, "ErrF%d_%d" % (code, fedId), 44, 0.0, 1.1, title=title)

        frac0 = ErrF[0] / errFSum
    else:
        frac0 = -999.  # dummy

    book.fillGraph((fedTime, frac0), "frac0_vs_time_%d" % fedId,
                   title=("FED %d" % fedId) +
                   ";time (minutes);frac. chan. with ErrF == 0")

    if fracEvN is not None:
        book.fillGraph((fedTime, fracEvN), "fracEvN_vs_time_%d" % fedId,
                       title=("FED %d" % fedId) +
                       ";time (minutes);frac. HTRs with EvN == FED's")

    if fracADC is not None:
        book.fillGraph((fedTime, fracADC), "ADC_misMatch_vs_time_%d" % fedId,
                       title=("FED %d" % fedId) +
                       ";time (minutes);#splitline{(# ch. match. ADCs) /}{(# ch. match. + ch. mismatch.)}")

    if fracTP is not None:
        book.fillGraph((fedTime, fracTP), "TP_misMatch_vs_time_%d" % fedId,
                       title=("FED %d" % fedId) +
                       ";time (minutes);#splitline{(# match. TPs) /}{(# match. + mismatch. TPs)}")

    if "nWord64" in t:
        book.fillGraph((fedTime, t["nWord64"] * 8.0 / 1024), "kB_vs_time_%d" % fedId,
                       title=("FED %d" % fedId) +
                       ";time (minutes);kB")

    book.fill((fedBcn / 100.0, frac0), "frac0_vs_BcN_%d" % fedId,
              (hw.nBx, 6), (0.0, 0.0), (hw.nBx / 100.0, 1.2),
              title=";FED %d   (BcN / 100);frac. chan. with ErrF == 0;Events / bin" % fedId)

    capSum = 0.0+sum(caps.values())
    if capSum:
        book.fill(max(caps.values())/capSum, "PopCapFrac_%d" % fedId,
                  44, 0.0, 1.1,
                  title=("FED %d" % fedId) +
                  ";frac. ErrF=0 chans w/most pop. capId;Events / bin"
                  )

    book.fill(nBadHtrs, "nBadHtrs_%d" % fedId, 16, -0.5, 15.5,
              title="FED %d; N bad HTRs;Events / bin" % fedId)
    return nBadHtrs, adcs
Exemple #8
0
def graph(d={}):
    gr = r.TGraph()
    for i, key in enumerate(sorted(d.keys())):
        gr.SetPoint(i, utils.minutes(key), d[key])
    return gr
Exemple #9
0
def oneFedHcal(d={}, patterns=False, dump=None, crateslots=[],
               nonMatchedQie=[], nonMatchedTp=[],
               printHeaders=None):
    h = d["header"]
    t = d["trailer"]
    if (not patterns) and (1 <= dump):
        fields = [" FEDid",
                  "  EvN",
                  "       OrN",
                  "    BcN",
                  "minutes",
                  " TTS",
                  " nBytesHW",
                  "nBytesSW",
                  #"CRC16",
                  "nSkip16",
                  "BcN12",
                  "EvN8",
                  "Blk8",
                  ]

        if printHeaders:
            headers = "   ".join(fields)
            printer.blue("-" * len(headers))
            printer.blue(headers)

        sList = [" %4d" % h["FEDid"],
                 "0x%07x" % h["EvN"],
                 "0x%08x" % h["OrN"],
                 "%4d" % h["BcN"],
                 "%7.3f" % utils.minutes(h["OrN"], h["BcN"]),
                 ("  %1x" % t["TTS"]) if "TTS" in t else "  - ",
                 ("   %5d" % (t["nWord64"]*8)) if "nWord64" in t else "    --  ",
                 "   %5d" % d["nBytesSW"],
                 #(" 0x%04x" % t["CRC16"]) if "CRC16" in t else "   - ",
                 "%7d" % d["nWord16Skipped"],
                 ]
        if h["uFoV"]:
            sList += ["   %4d" % t["BcN12"],
                      "0x%02x" % t["EvN8"],
                      "  %2d" % t["Blk_no8"],
                      ]

        printer.blue("   ".join(sList))
        if 2 <= dump:
            htrOverview(h)

    printColumnHeaders = True
    for iBlock, block in sorted(d["htrBlocks"].iteritems()):
        if "patternData" in block:
            oneHtrPatterns(p=block,
                           patterns=patterns,
                           header=h,
                           iBlock=iBlock)
        elif 3 <= dump:
            printColumnHeaders = oneHtr(p=block,
                                        printColumnHeaders=printColumnHeaders,
                                        dump=dump,
                                        crateslots=crateslots,
                                        utca=h["utca"],
                                        nonMatchedQie=nonMatchedQie,
                                        nonMatchedTp=nonMatchedTp,
                                        )
Exemple #10
0
def oneFedHcal(d={}, dump=None, crateslots=[],
               nonMatchedQie=[], nonMatchedTp=[],
               printHeaders=None):
    h = d["header"]
    t = d["trailer"]
    if 1 <= dump:
        fields = [" FEDid",
                  "  EvN",
                  "       OrN",
                  "    BcN",
                  "minutes",
                  " TTS",
                  "nBytesHW(   SW)",
                  "type",
                  #"CRC16",
                  "nSkip16",
                  "BcN12",
                  "EvN8",
                  "Blk8",
                  ]

        if printHeaders:
            headers = "  ".join(fields)
            printer.blue("-" * len(headers))
            printer.blue(headers)

        sList = [" %4d" % h["FEDid"],
                 "0x%07x" % h["EvN"],
                 "0x%08x" % h["OrN"],
                 "%4d" % h["BcN"],
                 "%7.3f" % utils.minutes(h["OrN"], h["BcN"]),
                 ("  %1x" % t["TTS"]) if "TTS" in t else "  - ",
                 "    %5d(%5d)" % (t["nWord64"]*8 if "nWord64" in t else "  -1", d["nBytesSW"]),
                 "  %1d " % h["Evt_ty"],
                 #(" 0x%04x" % t["CRC16"]) if "CRC16" in t else "   - ",
                 "%7d" % d["nWord16Skipped"],
                 ]
        if h["uFoV"]:
            sList += [" %4d" % t["BcN12"],
                      "0x%02x" % t["EvN8"],
                      "  %2d" % t["Blk_no8"],
                      ]

        printer.blue("  ".join(sList))
        if 2 <= dump:
            htrOverview(h)

    if dump <= 2:
        return

    printColumnHeaders = True
    for iBlock, block in sorted(d["htrBlocks"].iteritems()):
        printColumnHeaders = oneHtr(iBlock=iBlock,
                                    p=block,
                                    printColumnHeaders=printColumnHeaders,
                                    dump=dump,
                                    crateslots=crateslots,
                                    utca=h["utca"],
                                    nonMatchedQie=nonMatchedQie,
                                    nonMatchedTp=nonMatchedTp,
                                   )