Exemple #1
0
    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
Exemple #2
0
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 configure ( inputdata        ,    ## the list of input files  
                catalogs = []    ,    ## xml-catalogs (filled by GRID)
                castor   = False ,    ## use the direct access to castor/EOS ? 
                params   = {}    ) :

    ## configure  Track <--> MC relation table  
    import LoKiPhysMC.Track2MC_Configuration
    import LoKiMC.MC
    
    ## import DaVinci 
    from Configurables import DaVinci, GaudiSequencer
    ## delegate the actual configurtaion to DaVinci 
    dv = DaVinci ( DataType   = '2011' ,
                   InputType  = 'MDST',
                   Lumi = True,
                   Simulation = True,
                   DDDBtag="MC11-20111102",
                   CondDBtag="sim-20111111-vc-md100",
                   HistogramFile = "mcd02kpi_tracks7_histo.root",
                   TupleFile = "mcd02kpi_tracks7_ntuple.root",
                   PrintFreq = 1000)
    

    from Configurables import DecayTreeTuple, FilterDesktop, TupleToolGeometry, CombineParticles
    from Configurables import MCDecayTreeTuple, TupleToolMCTruth, MCTupleToolHierarchy
    from PhysSelPython.Wrappers import AutomaticData, Selection, SelectionSequence, DataOnDemand
    from Configurables import CheckPV
    

    # First using CombineParticle to create the D0
    ################################################################################
    #from StandardParticles import  StdAllNoPIDsPions, StdAllNoPIDsKaons
    _pions = DataOnDemand(Location='Phys/StdAllNoPIDsPions/Particles')
    _kaons = DataOnDemand(Location='Phys/StdAllNoPIDsKaons/Particles')

    _d2kpi = CombineParticles("d2kpi")
    _d2kpi.DecayDescriptor = "[D0 -> K- pi+]cc"
    _d2kpi.DaughtersCuts = { "K-"  : "(PT > 500.0) & (0.0 < PIDK)",
                             "pi+" : "(PT > 500.0) & (5.0 > PIDK)",
                             "K+"  : "(PT > 500.0) & (0.0 < PIDK)",
                             "pi-" : "(PT > 500.0) & (5.0 > PIDK) " }
    _d2kpi.MotherCut = "(VFASPF(VCHI2/VDOF)<10)"
    _d2kpi.CombinationCut = "(ADAMASS('D0') < 50.0)"
    _d2kpi.Preambulo = [ 
        "from LoKiPhysMC.decorators import *" ,
        "from PartProp.Nodes import CC"      ]
    #_d2kpi.ReFitPVs = True

    SelD2KPi = Selection( "SelD2KPi",
                          Algorithm= _d2kpi,
                          RequiredSelections=[_pions,_kaons] ) 
    
    SeqD2KPi = SelectionSequence('SeqD2KPi',TopSelection = SelD2KPi)

    
    # Now the CheckPV method to filter algorithms
    c = CheckPV("OnePV")
    c.MinPVs = 1

    # And a sequencer to put them together
    gseq = GaudiSequencer()
    gseq.Members = [ c, SeqD2KPi.sequence() ]
    
    ## define the input data
    setData  ( inputdata , catalogs , castor )
    
    ## get/create application manager
    gaudi = appMgr() 
    
    #
    ## modify/update the configuration:
    #
    
    ## (1) create the algorithm
    alg = TrackFilter( 'TrackFilter' )
    
    #seq = createSequencer()
    ## (2) replace the list of top level algorithm by
    #     new list, which contains only *THIS* algorithm
    gaudi.setAlgorithms( [ gseq, alg ] )
             
    return SUCCESS
Exemple #4
0
#DataOnDemandSvc().AlgMap["HltLikeL0/DecReports"] = L0DecReportsMaker( OutputLevel = 4 )
#DataOnDemandSvc().AlgMap["HltLikeL0/SelReports"] = L0SelReportsMaker( OutputLevel = 4 )

# User Algorithms
from Configurables import GaudiSequencer
userAlgos = GaudiSequencer("userAlgos")
userAlgos.Members = []
#userAlgos=[]
if  IsMC:
  from Configurables import TrackSmearState as SMEAR
  smear = SMEAR('StateSmear')
  userAlgos.Members.append(smear)
else:
  #
  from Configurables import CheckPV
  checkpv = CheckPV("CheckPV")
  checkpv.MinPVs = 1
  userAlgos.Members.append(checkpv)
  from Configurables import TrackScaleState as SCALER
  scaler = SCALER('StateScale')
  userAlgos.Members.append(scaler)  
userAlgos.Members.append(selSeq.sequence())
userAlgos.Members.append(tuple)
  
#from Configurables import HltSelReportsDecoder, HltVertexReportsDecoder, HltDecReportsDecoder
#userAlgos.Members.append( HltSelReportsDecoder() )
#userAlgos.Members.append( HltVertexReportsDecoder() )
#userAlgos.Members.append( HltDecReportsDecoder() )

from Configurables import EventTuple
etuple = EventTuple()
    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]
Exemple #6
0
    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()
Exemple #8
0
  @ 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()]