def add_mc_unbiased_sequence(self, decayDesc, arrow = '==>', toolList = ["TupleToolPropertime", "TupleToolKinematic", "TupleToolGeometry", "TupleToolEventInfo", "TupleToolPrimaries", "TupleToolPid", "TupleToolANNPID", "TupleToolTrackInfo", "TupleToolRecoStats",], mcToolList = ['TupleToolMCTruth', 'TupleToolMCBackgroundInfo', 'MCTupleToolPrompt'], L0List = [], HLT1List = [], HLT2List = [], strippingList = []) : decayDescCC = decayDesc.copy() decayDescCC.cc = True sel = build_mc_unbiased_selection(decayDesc, arrow) selseq = SelectionSequence(decayDesc.get_full_alias() + '_MCSeq', TopSelection = sel) seq = selseq.sequence() seq.Members.insert(0, CheckPV()) dtt = DecayTreeTuple(decayDesc.get_full_alias() + '_MCTuple', Decay = decayDesc.to_string(carets = True), Inputs = [sel.outputLocation()], ToolList = []) dtt.addBranches(decayDesc.branches()) headBranch = getattr(dtt, decayDesc.get_alias()) dtt.configure_tools(toolList = toolList, mcToolList = mcToolList, L0List = L0List, HLT1List = HLT1List, HLT2List = HLT2List, strippingList = strippingList, headBranch = headBranch) lokituple = headBranch.addTupleTool('LoKi::Hybrid::TupleTool') lokituple.Preambulo = ['from LoKiPhysMC.decorators import *', 'from LoKiPhysMC.functions import mcMatch'] mcmatch = 'switch(mcMatch({0!r}), 1, 0)'.format(decayDescCC.to_string(carets = False, arrow = '==>')) lokituple.Variables = {'mcMatch' : mcmatch} seq.Members.append(dtt) self.UserAlgorithms.append(seq) mcdtt = MCDecayTreeTuple(decayDesc.get_full_alias() + '_MCDecayTreeTuple') mcdtt.addBranches(decayDesc.branches()) mcdtt.Decay = decayDescCC.to_string(arrow = arrow, carets = True) mcdtt.ToolList += filter(lambda t : t.startswith('MC'), mcToolList) self.UserAlgorithms.append(mcdtt) return seq
def make_mc_unbiased_seq(desc, arrow = '==>', refitpvs = True) : '''Make a selection sequence for the given decay descriptor that has no cuts besides truth matching.''' desc = desc.copy() desc.clear_aliases() sel = build_mc_unbiased_selection(desc, arrow, refitpvs) selseq = SelectionSequence(desc.get_full_alias() + '_MCUnbiasedSeq', TopSelection = sel) seq = selseq.sequence() seq.Members.insert(0, CheckPV()) return seq, selseq
def name(self): return algorithm.name() def algorithm(self): return self._alg def outputLocation(self): return '' from Gaudi.Configuration import * from Configurables import DaVinci, SelDSTWriter from PhysSelPython.Wrappers import SelectionSequence from Configurables import CheckPV checkPV = EventSelection(CheckPV('TwoPV', MinPVs=1)) seqCheckPV = SelectionSequence('SeqPV', checkPV) conf = SelDSTWriter("SelDST") conf.OutputFileSuffix = "TestSimpleAlg" conf.SelectionSequences = [seqCheckPV] conf.ExtraItems = ['/Event/DAQ/RawEvent#1'] selDST0Seq = conf.sequence() # dv = DaVinci() dv.DataType = '2010' dv.InputType = 'SDST' dv.EvtMax = -1 dv.UserAlgorithms = [selDST0Seq]
def __init__( self, name, # the base name for the Line prescale=1, # prescale factor ODIN=None, # ODIN predicate L0DU=None, # L0DU predicate HLT=None, # HltDecReports predicate -> Deprecated since 2015 HLT1=None, # Hlt1DecReports predicate HLT2=None, # Hlt2DecReports predicate FILTER=None, # 'VOID'-predicate, e.g. Global Event Cut checkPV=True, # Check PV before running algos algos=None, # the list of stripping members selection=None, postscale=1, # postscale factor MaxCandidates="Override", # Maxumum number of candidates for CombineParticles MaxCombinations="Override", # Maxumum number of combinations for CombineParticles HDRLocation=None, # if None, defined by stream name EnableFlavourTagging=False, # If True, run FlavourTaggingTool to store FT info ExtraInfoTools=None, # Configuration of ExtraInfo tools, as a list of dictionaries (or None) ExtraInfoSelections=None, # Input selections for ExtraInfo tools. If None, use the top-level selection of the line ExtraInfoDaughters=None, # Daughter selections for which store ExtraInfo. If None, use only the top selection. ExtraInfoRecursionLevel=1, # Maximum depth in the decay tree to calculate ExtraInfo # Only used is ExtraInfoDaughters are given, otherwise is 0 RelatedInfoTools=None, # Configuration of Related Info tools, as a list of dictionaries (or None) RelatedInfoFilter=None, # Optional filter which can use RelatedInfo, added to the line sequence # after RelatedInfoTools RequiredRawEvents=None, # Possible list of RawEvent banks required by this line MDSTFlag=False, # Flag to ask the line to be written to MDST.DST stream **args): # other configuration parameters if algos and selection: raise Exception( 'only algos or selection can be set. You have set both.') if selection: if isConfigurable(selection): raise TypeError( 'StrippingLine selection cannot be Configurable type.') algos = [selection] if not algos: algos = [] ## 1) clone all arguments name = deepcopy(name) ODIN = deepcopy(ODIN) L0DU = deepcopy(L0DU) HLT = deepcopy(HLT) HLT1 = deepcopy(HLT1) HLT2 = deepcopy(HLT2) FILTER = deepcopy(FILTER) algos = deepcopy(algos) args = deepcopy(args) # 2) save all parameters (needed for the proper cloning) self._name = name if callable(prescale): prescale = prescale(self.name()) self._prescale = prescale self._ODIN = ODIN self._L0DU = L0DU self._HLT = HLT self._HLT1 = HLT1 self._HLT2 = HLT2 self._FILTER = FILTER self._checkPV = checkPV self._HDRLocation = HDRLocation self._EnableFlavourTagging = EnableFlavourTagging if callable(postscale): postscale = postscale(self.name()) self._postscale = postscale self._algos = algos self._args = args self.MaxCandidates = MaxCandidates self.MaxCombinations = MaxCombinations self.ExtraInfoTools = ExtraInfoTools self.ExtraInfoSelections = ExtraInfoSelections self.ExtraInfoDaughters = ExtraInfoDaughters self.ExtraInfoRecursionLevel = ExtraInfoRecursionLevel self.RelatedInfoTools = RelatedInfoTools self.RelatedInfoFilter = RelatedInfoFilter self._initialSelection = selection validRawBanks = [ "Trigger", "Muon", "Calo", "Rich", "Velo", "Tracker", "HC" ] # hard coded list, should really come from elsewhere.... if RequiredRawEvents != None: for bank in RequiredRawEvents: if bank not in validRawBanks: raise Exception("RawBank " + bank + " is not a known type") self.RequiredRawEvents = RequiredRawEvents self.MDSTFlag = MDSTFlag line = self.subname() self._appended = False # Configurable is not yet created self._configurable = None #start to contruct the sequence self._members = [] self._selection = None self.fullHDRLocation = None # if needed, check Primary Vertex before running all algos from Configurables import CheckPV if checkPV == True: check = CheckPV("checkPVmin1") check.MinPVs = 1 self._members.insert(0, check) elif isinstance(checkPV, int): check = CheckPV("checkPVmin%d" % checkPV) check.MinPVs = checkPV self._members.insert(0, check) elif isinstance(checkPV, tuple): if len(checkPV) == 2: check = CheckPV("checkPVmin%dmax%d" % checkPV) check.MinPVs = checkPV[0] check.MaxPVs = checkPV[1] self._members.insert(0, check) else: raise TypeError, "Wrong checkPV tuple length %d, should be 2" % len( checkPV) elif checkPV != False: raise TypeError, "Wrong checkPV argument type '%s'" % type( checkPV).__name__ # if needed, apply filter before running all algos if FILTER: if isinstance(FILTER, str): fltr = VOIDFilter(voidentryName(line), Code=FILTER) self._members.insert(0, fltr) elif isinstance(FILTER, (tuple, list)) and 2 == len(FILTER): fltr = VOIDFilter(voidentryName(line), Code=FILTER[0], Preambulo=FILTER[1]) self._members.insert(0, fltr) elif isinstance(FILTER, dict): fltr = VOIDFilter(voidentryName(line), **FILTER) self._members.insert(0, fltr) else: raise TypeError, "Wrong FILTER attribute: %s " % FILTER # bind members to line _boundMembers = bindMembers(line, algos) self._members += _boundMembers.members() self._outputloc = _boundMembers.outputLocation() self._selection = _boundMembers.selection() # register into the local storage of all created Lines _add_to_stripping_lines_(self)
_bsFilter.InputPlots.Histos = { "P/1000" : ('momentum',0,500) , "PT/1000" : ('pt_%1%',0,5,1000) , "M" : ('mass in MeV_%1%_%2%_%3%',5.2*Units.GeV,5.6*Units.GeV) } _bsFilter.addTool( PlotTool("OutputPlots") ) _bsFilter.OutputPlots.Histos = { "P/1000" : ('momentum',0,500) , "PT/1000" : ('pt_%1%',0,5,1000) , "M" : ('mass in MeV_%1%_%2%_%3%',5.2*Units.GeV,5.6*Units.GeV) } _bsFilter.OutputLevel = 1 BsFilterSel = Selection('HelloWorld', Algorithm = _bsFilter, RequiredSelections = [BsSel] ) from Configurables import CheckPV BsSeq = SelectionSequence('Bs', TopSelection = BsFilterSel, EventPreSelector = [CheckPV()]) seq = BsSeq.sequence() seq.RootInTES = "/Event/MicroDST/" seq.OutputLevel=4 dv=DaVinci() dv.EvtMax=-1 dv.DataType="MC09" dv.HistogramFile = "DVHistos_MDST.root" dv.Simulation=True dv.RedoMCLinks=False dv.UserAlgorithms = [seq] dv.InputType='MDST' # some necessary framework stuff #ecs = EventClockSvc()
@ Created by R. LAmbert @ date 2009-11-20 Mu selection for tests Long track muons with PT > 1 GeV """ __author__ = 'R. Lambert' __date__ = 'November 2009' __version__ = '$Revision: 1.3 $' import GaudiKernel.SystemOfUnits as Units from Gaudi.Configuration import * from Configurables import FilterDesktop, DaVinci from PhysSelPython.Wrappers import Selection, DataOnDemand, SelectionSequence from StandardParticles import StdLooseMuons as MyStdMuons MuForTests = FilterDesktop("_bachelorMu") MuForTests.Code = "((ISLONG) & (PT > 250.*MeV))" SelMuForTests = Selection("BachelorMuForTests", Algorithm=MuForTests, RequiredSelections=[MyStdMuons]) from Configurables import CheckPV checkPV = CheckPV('TestCheckPV') TestSequence = SelectionSequence("TestSeq", TopSelection=SelMuForTests, EventPreSelector=[checkPV]) dv = DaVinci() DaVinci().UserAlgorithms = [TestSequence.sequence()]