Exemple #1
0
    def __apply_configuration__(self) :

        from Configurables import ( GaudiSequencer, CombineParticles )
        from PhysSelPython.Wrappers import Selection, SelectionSequence, DataOnDemand

        if not self.isPropertySet("Sequencer") :
            raise RuntimeError("ERROR : Sequence not set")
        seq = self.getProp("Sequencer")

        if self.getProp("RunSelection") :

            # STD particles
            from StandardParticles import StdLooseMuons

            # J/psi -> mu mu
            JPsiMuMuName               = self.__sel_name__
            JPsiMuMu                   = CombineParticles(JPsiMuMuName)
            JPsiMuMu.DecayDescriptor   = "J/psi(1S) -> mu+ mu- "
            JPsiMuMu.CombinationCut    = "(ADAMASS('J/psi(1S)') < 150*MeV)"
            JPsiMuMu.MotherCut         = "(ADMASS('J/psi(1S)') < 130*MeV) & (VFASPF(VCHI2/VDOF)<6) & (PT > 2500*MeV)"
            JPsiMuMu.DaughtersCuts     = {"mu+" : "(PT>1400*MeV)"\
                                          "& (P>5*GeV)"\
                                          "& (TRCHI2DOF<2.0)"\
                                          "& (PPINFO(LHCb.ProtoParticle.MuonBkgLL,-10000)<-2.5)"\
                                          "& (PPINFO(LHCb.ProtoParticle.MuonMuLL,-10000)>-10)"}
            self.setOptions(JPsiMuMu)
            JPsiMuMuSel = Selection( JPsiMuMuName+'Sel',
                                     Algorithm = JPsiMuMu,
                                     RequiredSelections = [StdLooseMuons] )

            # Selection Sequence
            selSeq = SelectionSequence( self.__sel_name__+'Seq', TopSelection = JPsiMuMuSel )

            # Run the selection sequence.
            seq.Members += [selSeq.sequence()]

        # Particle Monitoring plots
        if self.getProp("RunMonitors") :

            from Configurables import ( ParticleMonitor )
            plotter =  ParticleMonitor(self.__sel_name__+"Plots")
            if self.getProp("RunSelection") : 
                plotter.Inputs      = [ 'Phys/'+self.__sel_name__+'Sel' ]
            else:
                musel = "(PT>1400*MeV) & (P>5*GeV) & (TRCHI2DOF<2.0) & "\
                        "(PPINFO(LHCb.ProtoParticle.MuonBkgLL,-10000)<-2.5) & "\
                        "(PPINFO(LHCb.ProtoParticle.MuonMuLL,-10000)>-10)"
                _code = "( ( INTREE( ('mu+'==ID) & "+musel+" ) ) | ( INTREE( ('mu-'==ID) & "+musel+" ) ) )"
                from Configurables import FilterDesktop
                filter = FilterDesktop( name = self.__sel_name__+"RICHFiltered",
                                        Code = _code,
                                        Inputs = self.getProp("Candidates") )
                plotter.Inputs = [ 'Phys/'+filter.name() ]
                seq.Members += [filter]
            plotter.PeakCut     = "(ADMASS('J/psi(1S)')<20*MeV)" # Considering sigma = 13
            plotter.SideBandCut = "(ADMASS('J/psi(1S)')>20*MeV)" # Considering sigma = 13
            plotter.PlotTools   = self.getProp("PlotTools") 
            self.setOptions(plotter)
            seq.Members += [plotter]

        # Make a DST ?
        if self.getProp("MakeSelDST"):

            # Prescale
            from Configurables import DeterministicPrescaler
            scaler = DeterministicPrescaler( self.__sel_name__+'PreScale',
                                             AcceptFraction = self.getProp("DSTPreScaleFraction") )
            seq.Members += [scaler]
            # Write the DST
            MyDSTWriter = SelDSTWriter( self.__sel_name__+"DST",
                                        SelectionSequences = [ selSeq ],
                                        OutputPrefix = self.__sel_name__ )
            seq.Members += [MyDSTWriter.sequence()]

        # MC Performance checking ?
        if self.getProp("MCChecks") :

            from Configurables import ParticleEffPurMoni
            mcPerf = ParticleEffPurMoni(JPsiMuMuName+"MCPerf")
            mcPerf.Inputs = ['Phys/'+self.__sel_name__+'Sel']
            self.setOptions(mcPerf)
            seq.Members += [mcPerf]

        # Ntuple ?
        if self.getProp("MakeNTuple") :

            from Configurables import ( DecayTreeTuple,
                                        TupleToolDecay,
                                        LoKi__Hybrid__FilterCriterion,
                                        LoKi__Hybrid__TupleTool,
                                        TupleToolMCBackgroundInfo,
                                        BackgroundCategory,
                                        TupleToolTrigger,
                                        TupleToolMCTruth,
                                        MCTupleToolKinematic,
                                        MCTupleToolHierarchy,
                                        TupleToolVtxIsoln,
                                        TupleToolP2VV
                                        )
            
            JPsiMuMuTree = DecayTreeTuple( JPsiMuMuName + 'Tuple')
            JPsiMuMuTree.Inputs = [ 'Phys/'+JPsiMuMuName]
            JPsiMuMuTree.Decay = 'J/psi(1S) ->  ^mu+ ^mu- '
            
            # set some names for ntuple branchs
            MyBranch_jpsi  = "jpsi"
            MyBranch_mup   = "mup"
            MyBranch_mum   = "mum"
            
            # label the branches for the particle tools
            JPsiMuMuTree.Branches = {
                MyBranch_jpsi  : "J/psi(1S) : J/psi(1S) ->  mu+ mu- ",
                MyBranch_mup   : "J/psi(1S) ->  ^mu+ mu- ",
                MyBranch_mum   : "J/psi(1S) ->  mu+ ^mu- ",
                }
            
            JPsiMuMuTree.ToolList = [
                "TupleToolEventInfo"
                , "TupleToolGeneration"
                , "TupleToolMCTruth"
                , "TupleToolMCBackgroundInfo"
                , "MCTupleToolKinematic"
                , "TupleToolPrimaries"
                , "TupleToolVtxIsoln"
                , "TupleToolTrackInfo"
                , "TupleToolPid"
                , "TupleToolGeometry"
                , "TupleToolKinematic"
                , "TupleToolPropertime"
                , "TupleToolPid"
                , "TupleToolPrimaries"
                , "TupleToolTrigger"
                ]
            
            JPsiMuMuTree.addTool(BackgroundCategory())
            JPsiMuMuTree.BackgroundCategory.SoftPhotonCut = 2000
            JPsiMuMuTree.OutputLevel = INFO
            JPsiMuMuTree.addTool(TupleToolTrigger())
            JPsiMuMuTree.TupleToolTrigger.VerboseL0 = True
            JPsiMuMuTree.addTool(TupleToolMCTruth())
            JPsiMuMuTree.TupleToolMCTruth.addTool(MCTupleToolKinematic())
            JPsiMuMuTree.TupleToolMCTruth.addTool(MCTupleToolHierarchy())
            JPsiMuMuTree.TupleToolMCTruth.ToolList = [
                "MCTupleToolKinematic" ,
                "MCTupleToolHierarchy"
                ]
            JPsiMuMuTree.TupleToolMCTruth.MCTupleToolKinematic.StoreKineticInfo = True
            JPsiMuMuTree.TupleToolMCTruth.MCTupleToolKinematic.StoreVertexInfo = True
            JPsiMuMuTree.TupleToolMCTruth.MCTupleToolKinematic.StorePropertimeInfo = False
            JPsiMuMuTree.addTool(TupleToolVtxIsoln( OutputLevel = 6 ))
            JPsiMuMuTree.TupleToolVtxIsoln.IP = 2.0
            JPsiMuMuTree.TupleToolVtxIsoln.InputParticles = [ "Phys/StdLooseMuons"]
            
            seq.Members += [JPsiMuMuTree]
            
            JPsiMuMuTree.NTupleLUN = "JPSIMUMU"
            
            from Configurables import NTupleSvc
            NTupleSvc().Output = ["JPSIMUMU DATAFILE='JpsiMuMu_Presel.root'  TYP='ROOT'  OPT='NEW'"]
sstream = StrippingStream("TestStream")
sstream.appendLines(B2XMuMuLines)
sstream.OutputLevel = 2
sc.appendStream(sstream)

#---------------------------
# Run fixing XmumuLine
#---------------------------
from Configurables import PromptNeutrinoTupleTool

stripping_line = 'B2XMuMu_Line'
stream = 'AllStreams'

tuple = DecayTreeTuple('PromptNeutrinoTupleTool')
tuple.OutputLevel = INFO

tuple.Inputs = ['/Event/{0}/Phys/{1}/Particles'.format(stream, stripping_line)]
tuple.Decay = "[B+  -> ^( J/psi(1S)  -> ^mu-  ^mu+ ) ^pi+]CC"
tuple.Branches = {
    "B": "[B+ -> ( J/psi(1S)  -> mu-  mu+ ) pi+ ]CC",
    "Jpsi": "[B+ -> ^(J/psi(1S)  -> mu-  mu+) pi+]CC",
    "mu_prim": "[B+ -> (J/psi(1S) -> mu- ^mu+) pi+]CC",
    "mu_sec": "[B+ -> (J/psi(1S) -> ^mu- mu+) pi+]CC",
    "pi": "[B+ -> (J/psi(1S) -> mu- mu+) ^pi+]CC",
}

tuple.ToolList = [
    "TupleToolKinematic",
    "TupleToolPid",
    "TupleToolGeometry",
Exemple #3
0
def decay_tree_tuple(name, decay, mothers, intermediate, daughters, inputs,
                     mc):
    """Return a configured DecayTreeTuple instance.

    A DecayTreeTuple is configured with the given decay descriptor.
    The mothers dictionary is used to give exclusive tools to vertices, and it
    should be, as daughters, a dictionary of tuple branch names to branch
    descriptors.
    A typical method call might look like
        decay_tree_tuple(
            'TupleDstToD0pi_D0ToKpi',
            '[D*(2010)+ -> K- pi+]CC',
            {
                'Dst': '[D*(2010) -> (D0 -> K- pi+) pi+]CC',
                'D0': '[D*(2010) -> ^(D0 -> K- pi+) pi+]CC'
            },
            {
                'D0_K': '[D*(2010) -> (D0 -> ^K- pi+) pi+]CC',
                'D0_pi': '[D*(2010) -> (D0 -> K- ^pi+) pi+]CC',
                'Dst_pi': '[D*(2010) -> (D0 -> K- pi+) ^pi+]CC'
            },
            'Phys/StrippingLineName/Particles'
        )
    Keyword arguments:
    name -- TDirectory the DecayTreeTuple TTree will be saved in
    decay -- Decay descriptor
    mothers -- Branch descriptors to be added to the tuple as mothers;
               decaying particles
    daughters -- Branch descriptors to be added to the tuple as daughters;
                 final state particles
    inputs -- str of list of str, as the value of DecayTreeTuple.Inputs
    mc -- Extra MC information is included if True
    """

    # Define tuple tools to add
    tools = [
        "TupleToolPropertime",
        'TupleToolEventInfo',
    ]

    # Extra variables, added using LoKi hybrid tuple tools
    basic_loki_vars = {
        'ETA': 'ETA',
        'PHI': 'PHI',
        'PT': 'PT',
        'ID': 'ID',
        'P': 'P',
        'Loki_BPVIPCHI2': 'BPVIPCHI2()',
        'Loki_MIPCHI2DV': 'MIPCHI2DV(PRIMARY)',
    }
    intermediate_loki_vars = {
        'Loki_AM34': 'LoKi.Particles.PFunA(AM34)',
        'Loki_AM4': 'LoKi.Particles.PFunA(AM4)',
        'Loki_BPVDIRA': "BPVDIRA",
        'Loki_acosBPVDIRA': "acos(BPVDIRA)",
    }
    daughter_loki_vars = {
        'PIDK': 'PIDK',
        'PIDe': 'PIDe',
        'PIDmu': 'PIDmu',
        'PIDp': 'PIDp',
        'Loki_TRACKCHI2NDOF': 'TRCHI2DOF',
        'Loki_TRACKGHOSTPROB': 'TRGHOSTPROB',
    }
    mother_loki_vars = {
        'M': 'M',
        'Loki_BPVVDCHI2': 'BPVVDCHI2',
        'Loki_BPVIPCHI2': 'BPVIPCHI2()',
        'Loki_DOCAMAX': 'DOCAMAX',
        'Loki_AMAXDOCA': "LoKi.Particles.PFunA(AMAXDOCA(''))",
        'Loki_AMINDOCA': "LoKi.Particles.PFunA(AMINDOCA(''))",
        'Loki_DOCACHI2MAX': 'DOCACHI2MAX',
        'Loki_VCHI2NDOF': 'VFASPF(VCHI2/VDOF)',
        'Loki_VX': 'VFASPF(VX)',
        'Loki_VY': 'VFASPF(VY)',
        'Loki_VZ': 'VFASPF(VZ)',
        'Loki_SUMPT': 'SUMTREE(PT,  ISBASIC)',
        'Loki_BPVLTIME': "BPVLTIME()",
    }

    # Template DecayTreeTuple
    t = DecayTreeTuple(name)

    # Providing str will throw an exception, so wrap it in a list
    try:
        t.Inputs = inputs
    except ValueError:
        t.Inputs = [inputs]
    t.Decay = decay
    # Merge the mother and daughter dictionaries
    t.addBranches(
        dict(mothers.items() + intermediate.items() + daughters.items()))
    # Tools for all branches
    t.ToolList = tools
    # Verbose reconstruction information
    t.addTupleTool('TupleToolANNPID').ANNPIDTunes = ["MC15TuneV1"]
    # t.addTupleTool('TupleToolRecoStats')
    # MC truth information
    if mc:
        if has_turbo_inputs(t):
            print 'Adding MC truth information for Turbo'
            from TeslaTools import TeslaTruthUtils
            relations = TeslaTruthUtils.getRelLoc("")
            print 'relations = {}'.format(relations)
            toollist = ['MCTupleToolPrompt']
            rels = [relations]

            MCTruth = TupleToolMCTruth()
            #MCTruth.OutputLevel = 1
            MCTruth = t.addTupleTool('TupleToolMCTruth')
            MCTruth.ToolList = toollist
            MCTruth.addTool(DaVinciSmartAssociator)
            MCTruth.DaVinciSmartAssociator.RedoNeutral = False
            MCTruth.DaVinciSmartAssociator.addTool(P2MCPFromProtoP)
            MCTruth.DaVinciSmartAssociator.P2MCPFromProtoP.Locations = rels
            MCTruth.addTool(MCMatchObjP2MCRelator)
            MCTruth.MCMatchObjP2MCRelator.RelTableLocations = rels

            MCTruth.DaVinciSmartAssociator.addTool(BackgroundCategory)
            MCTruth.DaVinciSmartAssociator.BackgroundCategory.addTool(
                P2MCPFromProtoP)
            MCTruth.DaVinciSmartAssociator.BackgroundCategory.vetoNeutralRedo = True
            MCTruth.DaVinciSmartAssociator.BackgroundCategory.P2MCPFromProtoP.Locations = rels

            bkgcat = t.addTupleTool('TupleToolMCBackgroundInfo')
            bkgcat.addTool(BackgroundCategory)
            bkgcat.OutputLevel = 10
            bkgcat.BackgroundCategory.vetoNeutralRedo = True
            bkgcat.BackgroundCategory.addTool(P2MCPFromProtoP)
            bkgcat.BackgroundCategory.P2MCPFromProtoP.Locations = rels

            t.OutputLevel = 10
        else:
            print 'Adding MC truth information'
            t.addTupleTool('TupleToolMCTruth')
            t.addTupleTool('TupleToolMCBackgroundInfo')
    # Extra information from LoKi
    hybrid_tt = t.addTupleTool('LoKi::Hybrid::TupleTool/basicLoKiTT')
    hybrid_tt.Variables = basic_loki_vars
    hybrid_tt.Preambulo = ['from LoKiTracks.decorators import TrIDC']

    # Add mother-specific varaibles to each mother branch
    for mother in mothers:
        branch = getattr(t, mother)
        branch.addTupleTool('LoKi::Hybrid::TupleTool/{0}LoKiTT'.format(
            mother)).Variables = mother_loki_vars
        # For some unknown reason this doesn't work with Turbo candidates, so
        # the information for them has to be added to every branch
        DictTuple = branch.addTupleTool(LoKi__Hybrid__Dict2Tuple,
                                        name="DTFTuple")
        DictTuple.addTool(DTFDict, name="DTF")
        DictTuple.Source = "LoKi::Hybrid::DTFDict/DTF"
        DictTuple.NumVar = 6 * (len(mothers) + len(intermediate) +
                                len(daughters))

        # configure the DecayTreeFitter in the usual way
        DictTuple.DTF.constrainToOriginVertex = True
        DictTuple.DTF.daughtersToConstrain = ['D0']
        DictTuple.DTF.addTool(LoKi__Hybrid__DictOfFunctors, name="dict")
        DictTuple.DTF.Source = "LoKi::Hybrid::DictOfFunctors/dict"
        DictTuple.DTF.dict.Variables = {
            "DTFDict_{}_PT".format(mother): "PT",
            "DTFDict_{}_ETA".format(mother): "ETA",
            "DTFDict_{}_PHI".format(mother): "PHI",
            "DTFDict_{}_P".format(mother): "P",
            "DTFDict_{}_M".format(mother): "M",
        }
        for part, decay in intermediate.items() + daughters.items():
            DictTuple.DTF.dict.Variables["DTFDict_{}_PT".format(
                part)] = "CHILD(PT,'{}')".format(decay)
            DictTuple.DTF.dict.Variables["DTFDict_{}_ETA".format(
                part)] = "CHILD(ETA,'{}')".format(decay)
            DictTuple.DTF.dict.Variables["DTFDict_{}_PHI".format(
                part)] = "CHILD(PHI,'{}')".format(decay)
            DictTuple.DTF.dict.Variables["DTFDict_{}_P".format(
                part)] = "CHILD(P,'{}')".format(decay)
            DictTuple.DTF.dict.Variables["DTFDict_{}_M".format(
                part)] = "CHILD(M,'{}')".format(decay)

    # Add intermediate-specific varaibles to each mother branch
    mom_int = mother_loki_vars.copy()
    mom_int.update(intermediate_loki_vars)
    for mother in intermediate:
        branch = getattr(t, mother)
        branch.addTupleTool('LoKi::Hybrid::TupleTool/{0}LoKiTT'.format(
            mother)).Variables = mom_int
        # For some unknown reason this doesn't work with Turbo candidates, so
        # the information for them has to be added to every branch

    for daughter in daughters:
        branch = getattr(t, daughter)
        branch.addTupleTool('LoKi::Hybrid::TupleTool/{0}LoKiTT'.format(
            daughter)).Variables = daughter_loki_vars

    return t