nargs="?", type=str, default="zz", help="Comma separated (no spaces) list of channels, or keyword indicated multiple channels", ) parser.add_argument("--listOnly", action="store_true", help="Print only run:lumi:event with no further info") parser.add_argument( "--zPlusL", "--zPlusl", action="store_true", help="Use the Z+l control region format instead of the 4l format" ) parser.add_argument("--doGen", action="store_true", help="Also make a file for the gen-level information") args = parser.parse_args() if args.zPlusL and args.channels == "zz": args.channels = "zl" channels = parseChannels(args.channels) inFiles = glob(args.input[0]) outStrings = [] outStringsGen = [] if args.listOnly: outTemp = "{run}:{lumi}:{event}:{channel}\n" infoGetter = getEventInfo elif args.zPlusL: outTemp = "{run}:{lumi}:{event}:{channel}:{m3l:.2f}:{mZ:.2f}:{ptL3:.2f}:" "{l3Tight}\n" infoGetter = getCandInfo3l args.doGen = False else:
def __init__(self, looseFilesData, tightFilesData, looseFilesMC, tightFilesMC, channels, outFile, intLumi=-1., fakeFactor=False): if looseFilesData: assert tightFilesData, "I can only make a fake rate from data with both a tight and loose ntuple" self.dataFiles = {'num' : tightFilesData, 'denom' : looseFilesData} else: assert len(tightFilesData)==0, "I can only make a fake rate from data with both a tight and loose ntuple" self.dataFiles = {} if looseFilesMC: assert tightFilesMC, "I can only make a fake rate from Monte Carlo with both a tight and loose ntuple" self.mcFiles = {'numMC' : tightFilesMC, 'denomMC' : looseFilesMC} else: assert len(tightFilesMC)==0, "I can only make a fake rate from Monte Carlo with both a tight and loose ntuple" self.mcFiles = {} self.hasData = bool(self.dataFiles) self.hasMC = bool(self.mcFiles) self.outFileName = outFile outFileBaseName = self.outFileName.split('/')[-1] self.outDir = self.outFileName.replace(outFileBaseName, '') self.intLumi = intLumi self.plotter = NtuplePlotter(channels, self.outDir, self.mcFiles, self.dataFiles, self.intLumi) self.channels = parseChannels(channels) assert len(self.channels) > 0 and \ all(len(ch) == 3 for ch in self.channels), \ "Invalid channel %s. Channels must have 3 objects."%channels self.WrappedHists = [ self.plotter.WrappedHist, self.plotter.WrappedHist2, self.plotter.WrappedHist3, ] self.WrappedStacks = [ self.plotter.WrappedStack, self.plotter.WrappedStack, self.plotter.WrappedHist3, # THistStack only goes up to 2-D ] self.histMakers = [ lambda *args, **kwargs: self.plotter.makeHist(*args, perUnitWidth=False, **kwargs), self.plotter.makeHist2, self.plotter.makeHist3, ] self.stackMakers = [ lambda *args, **kwargs: self.plotter.makeStack(*args, perUnitWidth=False, **kwargs), self.plotter.makeStack2, # THistStack same for 1- and 2-D self.plotter.makeStack3, ] self.extractHistFromStack = [ lambda s: self.WrappedHists[0](asrootpy(s.GetStack().Last()), category=s.getCategory(), variable=s.getVariable(), selection=s.getSelection()), lambda s: self.WrappedHists[1](asrootpy(s.GetStack().Last()), category=s.getCategory(), variable=s.getVariable(), selection=s.getSelection()), lambda s: s, # THistStack only goes up to 2-D ] self.outputs = [] self.fakeFactor = fakeFactor