Ejemplo n.º 1
0
    def __init__(self, channels, baseCutSet, inFile, outfile='./results/output.root',
                 maxEvents=float("inf"), intLumi=10000, rowCleaner='',
                 cutModifiers=[], ntupleDir='ntuple'):
        '''
        channels:    list of strings or single string in the format (e.g.) eemm for
                         a 2e2mu final state. '4l', 'zz' and 'ZZ' turn into ['eeee' 'eemm' 'mmmm']
        cutSet:      string with the name of the cut template to use
        infile:      string of an input file name, with path
        outfile:     string of an output file name, with path
        maxEvents:   stop after this many events processed
        intLumi:     in output text file, report how many events we would expect for this integrated luminosity
        rowCleaner:  name of a module to clean out redundant rows. If an empty
                         string (or other False boolean), no cleaning is performed.
        '''
        self.cutSet = [baseCutSet]+cutModifiers
        CutClass = getCutClass(baseCutSet, *cutModifiers)

        self.cuts = CutClass()

        self.outFile = outfile

        self.cutOrder = self.cuts.getCutList()

        self.sample = inFile.split('/')[-1].replace('.root','')
        self.inFile = root_open(inFile)
        assert bool(inFile), 'No file %s'%self.inFile

        self.maxEvents = maxEvents
        # if we don't use all the events, we need to know how many we would have done in the whole thing
        if self.maxEvents < float('inf'):
            self.ntupleSize = {}

        self.channels = parseChannels(channels)

        self.ntuples = {}
        for channel in parseChannels(channels):
            try:
                nt = self.inFile.Get('/'.join([channel,ntupleDir]))
                # if not nt.GetEntries():
                #     raise DoesNotExist('')
                self.ntuples[channel] = nt
                nt.create_buffer()
            except DoesNotExist:
                print "Ntuple for channel %s is empty or not found! Skipping."%channel
                self.channels.remove(channel)
                continue

            if self.maxEvents < float('inf'):
                self.ntupleSize[channel] = self.ntuples[channel].GetEntries()

        self.results = NtupleCopier(self.outFile, **self.ntuples)

        self.prepareCutSummary()

        self.intLumi = intLumi

        self.cleanRows = bool(rowCleaner)
        if self.cleanRows:
            self.CleanerClass = getCleanerClass(rowCleaner)
Ejemplo n.º 2
0
                    help='Name of the text file to output.')
parser.add_argument('channels', nargs='?', type=str, default='zz',
                    help='Comma separated (no spaces) list of channels, or keyword "zz" for eeee,mmmm,eemm')
# parser.add_argument('--nThreads', type=int,  # just left to remind myself how if needed
#                     help='Maximum number of threads for simultaneous processing. If unspecified, python figures how many your machine can deal with automatically, to a maximum of 4.')

args = parser.parse_args()
        
if args.channels == 'zz':
    channels = ['eeee', 'eemm', 'mmmm']
else:
    channels = args.channels.split(',')
        
inFile = args.input[0]
        
cutter = getCutClass('BaseCuts2016', 'HZZ2016', 'ControlRegion_OS_3P1F')()

with root_open(inFile) as fin:
    with open(args.output, 'w') as fout:
        for channel in channels:
            print "\nChannel %s:"%channel
            ntuple = fin.Get(channel+'/ntuple')
            objects = getObjects(channel)
            needReorder = cutter.needReorder(channel)
        
            for n, row in enumerate(ntuple):
                if n % 500 == 0:
                    print "Processing row %d"%n
                obs = cutter.orderLeptons(row, channel, objects) if needReorder else objects
                z1MassVar = "%s_%s_MassFSR"%(obs[0], obs[1])
                z2MassVar = "%s_%s_MassFSR"%(obs[2], obs[3])
Ejemplo n.º 3
0
    default="zz",
    help='Comma separated (no spaces) list of channels, or keyword "zz" for eeee,mmmm,eemm',
)
# parser.add_argument('--nThreads', type=int,  # just left to remind myself how if needed
#                     help='Maximum number of threads for simultaneous processing. If unspecified, python figures how many your machine can deal with automatically, to a maximum of 4.')

args = parser.parse_args()

if args.channels == "zz":
    channels = ["eeee", "eemm", "mmmm"]
else:
    channels = args.channels.split(",")

inFile = args.input[0]

cutter = getCutClass("BaseCuts2016", "HZZ2016", "ControlRegion_SS")()

with root_open(inFile) as fin:
    with open(args.output, "w") as fout:
        for channel in channels:
            print "\nChannel %s:" % channel
            ntuple = fin.Get(channel + "/ntuple")
            objects = getObjects(channel)
            needReorder = cutter.needReorder(channel)

            for n, row in enumerate(ntuple):
                if n % 500 == 0:
                    print "Processing row %d" % n
                obs = cutter.orderLeptons(row, channel, objects) if needReorder else objects
                z1MassVar = "%s_%s_MassFSR" % (obs[0], obs[1])
                z2MassVar = "%s_%s_MassFSR" % (obs[2], obs[3])