Ntuples in Postprocessing

The CROWN Ntuples can be used by any Postprocessing framework. Some things have to be kept in mind, in order to ensure an easy processing. Most important difference is, that only quantities affected by a shift are recalculated. This means the prostprocessing framework must be able to use a mixture of the original and the shifted quantities, when applying shifts. In order to make this step a bit easier, the information, which quantities are affected by a shift, is stored in the Ntuple.

Quantity mapping

To read the mapping from a NTuple, the python function listed below may be used. Two types of mapping are available, depending on the actual usecase. In the first, the mapping is sorted by shift; in the second the mapping is sorted by quantity.

import ROOT as r
import glob, os

def load_crown_mapping(filename, by_shift=False, by_quantity=False):
    data = {}
    r.gInterpreter.GenerateDictionary("map<string,vector<string> >", "map")
    f = r.TFile.Open(filename)
    if by_shift and not by_quantity:
        name = "shift_quantities_map"
    elif by_quantity and not by_shift:
        name = "quantities_shift_map"
    else:
        print("Choose either by_shift or by_quantity, not both or none")
        return data
    print("Reading data")
    m = f.Get(name)
    for x, yy in m:
        data[x] = []
        for y in yy:
            data[x].append(y)
    f.Close()
    print("Cleaning up autogenerated files")
    # cleanup autogenerated files
    for f in glob.glob("AutoDict_*"):
        os.remove(f)
    return data

# print(load_crown_mapping("path/to/testfile.root", by_quantity=True))