def checkBackgrounds(): logger.info( "Checking backgrounds." ) from StopsDilepton.samples.helpers import fromHeppySample from CMGTools.RootTools.samples.samples_13TeV_RunIIFall15MiniAODv2 import samples from StopsDilepton.tools.user import cmg_directory for s in samples: try: sample = fromHeppySample(s.name, data_path = cmg_directory) logger.info( "Background sample %s found with %i files", sample.name, len(sample.files) ) except helpers.EmptySampleError: logger.info( "Background sample %s empty.", s.name) except: logger.info( "Could not load sample %s.", s.name )
def checkBackgrounds(): logger.info("Checking backgrounds.") from StopsDilepton.samples.helpers import fromHeppySample from CMGTools.RootTools.samples.samples_13TeV_RunIIFall15MiniAODv2 import samples from StopsDilepton.tools.user import cmg_directory for s in samples: try: sample = fromHeppySample(s.name, data_path=cmg_directory) logger.info("Background sample %s found with %i files", sample.name, len(sample.files)) except helpers.EmptySampleError: logger.info("Background sample %s empty.", s.name) except: logger.info("Could not load sample %s.", s.name)
help="Name of the processing era" ) return argParser options = get_parser().parse_args() # Logging import StopsDilepton.tools.logger as logger logger = logger.get_logger(options.logLevel, logFile = None ) import RootTools.core.logger as logger_rt logger_rt = logger_rt.get_logger(options.logLevel, logFile = None ) #Samples: Load samples from StopsDilepton.samples.helpers import fromHeppySample samples = [ fromHeppySample(s, data_path = options.dataDir, maxN = None) for s in options.samples ] xSection = samples[0].heppy.xSection #Samples: combine if more than one if len(samples)>1: sample_name = samples[0].name+"_comb" logger.info( "Combining samples %s to %s.", ",".join(s.name for s in samples), sample_name ) sample = Sample.combine(sample_name, samples, maxN = maxN) # Clean up for s in samples: sample.clear() elif len(samples)==1: sample = samples[0] else: raise ValueError( "Need at least one sample. Got %r",samples )
trigger = "HLT_ee_DZ" elif args.mode=="muEle": leptonSelectionString = "&&".join([looseMuIDString()+"==1", looseEleIDString()+"==1"]) trigger = "HLT_mue" else: raise ValueError( "Mode %s not known"%args.mode ) # Extra requirements on data #dataFilterCut = "(Flag_HBHENoiseIsoFilter&&Flag_HBHENoiseFilter&&Flag_CSCTightHaloFilter&&Flag_goodVertices&&Flag_eeBadScFilter&&Flag_EcalDeadCellTriggerPrimitiveFilter)" filterCut = "(Flag_HBHENoiseIsoFilter&&Flag_HBHENoiseFilter&&Flag_CSCTightHaloFilter&&Flag_goodVertices&&Flag_eeBadScFilter&&Flag_EcalDeadCellTriggerPrimitiveFilter)" import StopsDilepton.tools.user as user from StopsDilepton.samples.helpers import fromHeppySample maxN = 5 if args.small else -1 TTJets = fromHeppySample("TTJets", data_path = user.cmg_directory, maxN = maxN) DYJetsToLL_M50 = fromHeppySample("DYJetsToLL_M50", data_path = user.cmg_directory, maxN = maxN) TToLeptons_tch_amcatnlo = fromHeppySample("TToLeptons_tch_amcatnlo", data_path = user.cmg_directory, maxN = maxN) TBarToLeptons_tch_powheg = fromHeppySample("TBarToLeptons_tch_powheg", data_path = user.cmg_directory, maxN = maxN) #TToLeptons_sch_amcatnlo = fromHeppySample("TToLeptons_sch_amcatnlo", data_path = user.cmg_directory, maxN = maxN) TBar_tWch = fromHeppySample("TBar_tWch", data_path = user.cmg_directory, maxN = maxN) T_tWch = fromHeppySample("T_tWch", data_path = user.cmg_directory, maxN = maxN) if not args.noData: if args.mode=="doubleMu": data_sample = fromHeppySample("DoubleMuon_Run2015D_16Dec", data_path = '/scratch/rschoefbeck/cmgTuples/763', maxN = maxN) elif args.mode=="doubleEle": data_sample = fromHeppySample("DoubleEG_Run2015D_16Dec", data_path = '/scratch/rschoefbeck/cmgTuples/763', maxN = maxN) elif args.mode=="muEle":
import RootTools.core.logger as logger_rt logger_rt = logger_rt.get_logger(args.logLevel, logFile = None ) lumiScale = 10. maxN = -1 evtNr = -1 #evtNr = 19956300 # event 9, e matched to gamma #evtNr = 55481323 # event 24, tautoE 205 GeV extra neutrino data_directory = "/afs/hephy.at/data/rschoefbeck02/cmgTuples/" from StopsDilepton.samples.helpers import fromHeppySample if args.mode=="doubleMu": sample = Sample.fromDirectory(name="DoubleMuon_Run2015D", treeName="Events", texName="DoubleMuon (Run2015D)", directory=os.path.join( data_directory, 'postProcessed_Fall15_mAODv2/dilep/DoubleMuon_Run2015D_16Dec') ) cmg_sample = fromHeppySample("DoubleMuon_Run2015D_16Dec", data_path ="/scratch/rschoefbeck/cmgTuples/763/", maxN = -1) SFZCut = "( isMuMu==1&&abs(dl_mass-91.2)>=15 )" elif args.mode=="doubleEle": sample = Sample.fromDirectory(name="DoubleEG_Run2015D", treeName="Events", texName="DoubleEG (Run2015D)", directory=os.path.join( data_directory, 'postProcessed_Fall15_mAODv2/dilep/DoubleEG_Run2015D_16Dec') ) cmg_sample = fromHeppySample("DoubleEG_Run2015D_16Dec", data_path ="/scratch/rschoefbeck/cmgTuples/763/", maxN = -1) SFZCut = "( isEE==1&&abs(dl_mass-91.2)>=15 )" elif args.mode=="muEle": sample = Sample.fromDirectory(name="MuonEG_Run2015D", treeName="Events", texName="MuonEG (Run2015D)", directory=os.path.join( data_directory, 'postProcessed_Fall15_mAODv2/dilep/MuonEG_Run2015D_16Dec') ) cmg_sample = fromHeppySample("MuonEG_Run2015D_16Dec", data_path ="/scratch/rschoefbeck/cmgTuples/763/", maxN = -1) SFZCut = "( isEMu==1 )" def bold(s): return '\033[1m'+s+'\033[0m' def vecPtSum(objs, subtract=[]): px = sum([o['pt']*cos(o['phi']) for o in objs])
leptonSelectionString = "&&".join( [looseMuIDString() + "==1", looseEleIDString() + "==1"]) trigger = "HLT_mue" else: raise ValueError("Mode %s not known" % args.mode) # Extra requirements on data #dataFilterCut = "(Flag_HBHENoiseIsoFilter&&Flag_HBHENoiseFilter&&Flag_CSCTightHaloFilter&&Flag_goodVertices&&Flag_eeBadScFilter&&Flag_EcalDeadCellTriggerPrimitiveFilter)" filterCut = "(Flag_HBHENoiseIsoFilter&&Flag_HBHENoiseFilter&&Flag_CSCTightHaloFilter&&Flag_goodVertices&&Flag_eeBadScFilter&&Flag_EcalDeadCellTriggerPrimitiveFilter)" import StopsDilepton.tools.user as user from StopsDilepton.samples.helpers import fromHeppySample maxN = 5 if args.small else -1 TTJets = fromHeppySample("TTJets", data_path=user.cmg_directory, maxN=maxN) DYJetsToLL_M50 = fromHeppySample("DYJetsToLL_M50", data_path=user.cmg_directory, maxN=maxN) TToLeptons_tch_amcatnlo = fromHeppySample("TToLeptons_tch_amcatnlo", data_path=user.cmg_directory, maxN=maxN) TBarToLeptons_tch_powheg = fromHeppySample("TBarToLeptons_tch_powheg", data_path=user.cmg_directory, maxN=maxN) #TToLeptons_sch_amcatnlo = fromHeppySample("TToLeptons_sch_amcatnlo", data_path = user.cmg_directory, maxN = maxN) TBar_tWch = fromHeppySample("TBar_tWch", data_path=user.cmg_directory, maxN=maxN) T_tWch = fromHeppySample("T_tWch", data_path=user.cmg_directory, maxN=maxN)
#evtNr = 19956300 # event 9, e matched to gamma #evtNr = 55481323 # event 24, tautoE 205 GeV extra neutrino data_directory = "/afs/hephy.at/data/rschoefbeck02/cmgTuples/" from StopsDilepton.samples.helpers import fromHeppySample if args.mode == "doubleMu": sample = Sample.fromDirectory( name="DoubleMuon_Run2015D", treeName="Events", texName="DoubleMuon (Run2015D)", directory=os.path.join( data_directory, 'postProcessed_Fall15_mAODv2/dilep/DoubleMuon_Run2015D_16Dec')) cmg_sample = fromHeppySample( "DoubleMuon_Run2015D_16Dec", data_path="/scratch/rschoefbeck/cmgTuples/763/", maxN=-1) SFZCut = "( isMuMu==1&&abs(dl_mass-91.2)>=15 )" elif args.mode == "doubleEle": sample = Sample.fromDirectory( name="DoubleEG_Run2015D", treeName="Events", texName="DoubleEG (Run2015D)", directory=os.path.join( data_directory, 'postProcessed_Fall15_mAODv2/dilep/DoubleEG_Run2015D_16Dec')) cmg_sample = fromHeppySample( "DoubleEG_Run2015D_16Dec", data_path="/scratch/rschoefbeck/cmgTuples/763/", maxN=-1) SFZCut = "( isEE==1&&abs(dl_mass-91.2)>=15 )"
#Samples: Load samples maxN = 2 if options.runSmallSample else None if options.T2tt: from StopsDilepton.samples.cmgTuples_Signals_Spring15_mAODv2_25ns_0l import T2tt from StopsDilepton.samples.helpers import getT2ttSignalWeight samples = filter( lambda s:s.name in options.samples, T2tt) logger.info( "T2tt signal samples to be processed: %s", ",".join(s.name for s in samples) ) # FIXME I'm forcing ==1 signal sample because I don't have a good idea how to construct a sample name from the complicated T2tt_x_y_z_... names assert len(samples)==1, "Can only process one T2tt sample at a time." samples[0].files = samples[0].files[:maxN] logger.debug( "Fetching signal weights..." ) signalWeight = getT2ttSignalWeight( samples[0], lumi = targetLumi ) logger.debug("Done fetching signal weights.") elif options.TTDM: from StopsDilepton.samples.helpers import fromHeppySample samples = [ fromHeppySample(s, data_path = "/data/rschoefbeck/cmgTuples/TTBar_DM/", \ module = "CMGTools.StopsDilepton.TTbarDMJets_signals_RunIISpring15MiniAODv2", maxN = maxN)\ for s in options.samples ] else: from StopsDilepton.samples.helpers import fromHeppySample samples = [ fromHeppySample(s, data_path = options.dataDir, maxN = maxN) for s in options.samples ] isData = False not in [s.isData for s in samples] isMC = True not in [s.isData for s in samples] if options.T2tt: xSection = None else: # Check that all samples which are concatenated have the same x-section. assert isData or len(set([s.heppy.xSection for s in samples]))==1, "Not all samples have the same xSection: %s !"%(",".join([s.name for s in samples])) assert isMC or len(samples)==1, "Don't concatenate data samples"
return argParser options = get_parser().parse_args() # Logging import StopsDilepton.tools.logger as logger logger = logger.get_logger(options.logLevel, logFile=None) import RootTools.core.logger as logger_rt logger_rt = logger_rt.get_logger(options.logLevel, logFile=None) #Samples: Load samples from StopsDilepton.samples.helpers import fromHeppySample samples = [ fromHeppySample(s, data_path=options.dataDir, maxN=None) for s in options.samples ] xSection = samples[0].heppy.xSection #Samples: combine if more than one if len(samples) > 1: sample_name = samples[0].name + "_comb" logger.info("Combining samples %s to %s.", ",".join(s.name for s in samples), sample_name) sample = Sample.combine(sample_name, samples, maxN=maxN) # Clean up for s in samples: sample.clear() elif len(samples) == 1:
maxN = 2 if options.runSmallSample else None if options.T2tt: from StopsDilepton.samples.cmgTuples_Signals_Spring15_mAODv2_25ns_0l import T2tt from StopsDilepton.samples.helpers import getT2ttSignalWeight samples = filter(lambda s: s.name in options.samples, T2tt) logger.info("T2tt signal samples to be processed: %s", ",".join(s.name for s in samples)) # FIXME I'm forcing ==1 signal sample because I don't have a good idea how to construct a sample name from the complicated T2tt_x_y_z_... names assert len(samples) == 1, "Can only process one T2tt sample at a time." samples[0].files = samples[0].files[:maxN] logger.debug("Fetching signal weights...") signalWeight = getT2ttSignalWeight(samples[0], lumi=targetLumi) logger.debug("Done fetching signal weights.") elif options.TTDM: from StopsDilepton.samples.helpers import fromHeppySample samples = [ fromHeppySample(s, data_path = "/data/rschoefbeck/cmgTuples/TTBar_DM/", \ module = "CMGTools.StopsDilepton.TTbarDMJets_signals_RunIISpring15MiniAODv2", maxN = maxN)\ for s in options.samples ] else: from StopsDilepton.samples.helpers import fromHeppySample samples = [ fromHeppySample(s, data_path=options.dataDir, maxN=maxN) for s in options.samples ] isData = False not in [s.isData for s in samples] isMC = True not in [s.isData for s in samples] if options.T2tt: xSection = None else: # Check that all samples which are concatenated have the same x-section.
reader.setEventList( event_list ) logger.info( "Found %i events in sample %s", event_list.GetN(), sample.name ) positions = {} reader.start() while reader.run(): positions[( reader.data.run, reader.data.lumi, reader.data.evt )] = reader.position - 1 selected_events = "||".join([ "run==%i&&lumi==%i&&evt==%i" % e for e in positions.keys() ] ) logger.info( "Constructing event selection: %s", selected_events ) # original cmg sample from StopsDilepton.samples.helpers import fromHeppySample if dilep: cmg_samples = [ fromHeppySample(s, data_path = user.cmg_directory, maxN = -1) for s in ["TTJets_DiLepton", "TTJets_DiLepton_ext"] ] cmg_sample = Sample.combine("cmg_sample", cmg_samples, maxN = -1) else: cmg_samples = [ fromHeppySample(s, data_path = user.cmg_directory, maxN = -1) for s in ["TTJets_SingleLeptonFromTbar", "TTJets_SingleLeptonFromT", "TTJets_SingleLeptonFromTbar_ext", "TTJets_SingleLeptonFromT_ext"] ] cmg_sample = Sample.combine("cmg_sample", cmg_samples, maxN = -1) cmg_reader = cmg_sample.treeReader( \ variables = common_variables + cmg_variables, #selectionString = ) cmg_reader.activateAllBranches() logger.info( "Now get event list in cmg sample.") cmg_event_list = cmg_sample.getEventList( selected_events ) logger.info( "Done.") cmg_reader.setEventList( cmg_event_list )
action='store', ) args = argParser.parse_args() # Logging import StopsDilepton.tools.logger as logger logger = logger.get_logger(args.logLevel, logFile = None ) import RootTools.core.logger as logger_rt logger_rt = logger_rt.get_logger(args.logLevel, logFile = None ) import StopsDilepton.tools.user as user from StopsDilepton.samples.helpers import fromHeppySample maxN = 5 TTJets = fromHeppySample("TTJets", data_path = user.cmg_directory, maxN = maxN) DYJetsToLL_M50 = fromHeppySample("DYJetsToLL_M50", data_path = user.cmg_directory, maxN = maxN) QCD_Pt300to470_Mu5 = fromHeppySample("QCD_Pt300to470_Mu5", data_path = user.cmg_directory, maxN = maxN) from StopsDilepton.samples.color import color TTJets.color = color.TTJets DYJetsToLL_M50.color = color.DY QCD_Pt300to470_Mu5.color = color.QCD samples = [TTJets, QCD_Pt300to470_Mu5] from StopsDilepton.tools.user import plot_directory plot_path = os.path.join(plot_directory, 'etc') for iso in ["miniRelIso", "relIso03", "relIso04"]: histos={}
action='store', ) args = argParser.parse_args() # Logging import StopsDilepton.tools.logger as logger logger = logger.get_logger(args.logLevel, logFile=None) import RootTools.core.logger as logger_rt logger_rt = logger_rt.get_logger(args.logLevel, logFile=None) import StopsDilepton.tools.user as user from StopsDilepton.samples.helpers import fromHeppySample maxN = 5 TTJets = fromHeppySample("TTJets", data_path=user.cmg_directory, maxN=maxN) DYJetsToLL_M50 = fromHeppySample("DYJetsToLL_M50", data_path=user.cmg_directory, maxN=maxN) QCD_Pt300to470_Mu5 = fromHeppySample("QCD_Pt300to470_Mu5", data_path=user.cmg_directory, maxN=maxN) from StopsDilepton.samples.color import color TTJets.color = color.TTJets DYJetsToLL_M50.color = color.DY QCD_Pt300to470_Mu5.color = color.QCD samples = [TTJets, QCD_Pt300to470_Mu5] from StopsDilepton.tools.user import plot_directory