def addWeights(seq, pdfMap={'CT14nlo': 20}, pref=""):

    from AthenaCommon.AppMgr import ToolSvc
    from ReweightUtils.ReweightUtilsConf import *

    #Load standard generator event weight
    mcEventWeightNom = McEventWeight(name=pref + "mcWNom")
    ToolSvc += mcEventWeightNom

    sumOfWeightsTool = SumOfWeightsTool(name=pref + "PDFSumWeightsTool")
    sumOfWeightsTool.CutBookKeeperContainterName = "PDFSumOfWeights"
    sumOfWeightsTool.CutBookKeeperNamePrefix = ""
    sumOfWeightsTool.maxMuBins = 1

    #Load a potential generator variation event weight
    listTools = [mcEventWeightNom]
    for p in pdfMap:
        pdfName = p
        pdfN = pdfMap[p]

        pdfWeight = []
        product = []
        provTools = []
        for i in range(0, pdfN + 1):
            pdfWeight.append(None)
            product.append(None)
            provTools.append(None)

            pdfWeight[i] = PDFWeight(name=pref + "pdfOnlyWeight" + pdfName +
                                     "_" + str(i),
                                     PDFName=pdfName,
                                     index=i)
            ToolSvc += pdfWeight[i]

            #Multiplies event weights
            product[i] = WeightsAgregator(name=pref + pdfName + "_" + str(i))
            product[i].Ingredients = [mcEventWeightNom, pdfWeight[i]]
            ToolSvc += product[i]

            listTools.append(product[i])

    sumOfWeightsTool.WeightTools = listTools
    seq += sumOfWeightsTool

    from OutputStreamAthenaPool.MultipleStreamManager import MSMgr
    MSMgr.AddMetaDataItemToAllStreams("xAOD::CutBookkeeperContainer#*")
    MSMgr.AddMetaDataItemToAllStreams("xAOD::CutBookkeeperAuxContainer#*")
Beispiel #2
0
    #if primDPD.WriteSkimDecisions():
    #    MSMgr.WriteSkimDecisionsOfAllStreams()
    #    pass

    #Configure CutFlowSvc and common metadata
    if rec.doFileMetaData():

        #Exception for DPD pass-through mode
        if rec.doDPD.passThroughMode:
            svcMgr.CutFlowSvc.InputStream="Virtual"
            pass

        if rec.DPDMakerScripts()!=[] and not rec.doDPD.passThroughMode :
            #Explicitely add file metadata from input and from transient store

            MSMgr.AddMetaDataItemToAllStreams( "LumiBlockCollection#*" )
            MSMgr.AddMetaDataItemToAllStreams( "xAOD::CutBookkeeperContainer#*" )
            MSMgr.AddMetaDataItemToAllStreams( "xAOD::CutBookkeeperAuxContainer#*" )
            MSMgr.AddMetaDataItemToAllStreams( "IOVMetaDataContainer#*" )
            pass
        pass
    pass



###################
## Common Utils  ##
###################

#include("RecExCommon/RecoUtils.py")
Beispiel #3
0
def CreateCutFlowSvc(svcName="CutFlowSvc",
                     athFile=None,
                     seq=None,
                     addAlgInPlace=False,
                     addMetaDataToAllOutputFiles=True,
                     SGkey="CutBookkeepers"):
    """
    Helper to create the CutFlowSvc, extract the needed information from
    the input file, and also schedule all the needed stuff.
    """
    # Create a message logger
    from AthenaCommon.Logging import logging
    msg = logging.getLogger("Create" + svcName)

    # Get the service manager
    from AthenaCommon.AppMgr import ServiceMgr as svcMgr

    # Determine current input stream name
    inputStreamName = GetCurrentStreamName(msg=msg, athFile=athFile)
    msg.debug("CreateCutFlowSvc: Have inputStreamName = %s" %
              (inputStreamName))

    # Create the CutFlowSvc instance(s)
    import AthenaCommon.CfgMgr as CfgMgr
    if not hasattr(svcMgr, "CutFlowSvc"): svcMgr += CfgMgr.CutFlowSvc()
    svcMgr.CutFlowSvc.InputStream = inputStreamName
    #if not hasattr(svcMgr,"FileCutFlowSvc"): svcMgr += CfgMgr.FileCutFlowSvc()
    #svcMgr.FileCutFlowSvc.InputStream   = inputStreamName

    # Make sure MetaDataSvc is ready
    if not hasattr(svcMgr, 'MetaDataSvc'):
        from EventSelectorAthenaPool.EventSelectorAthenaPoolConf import MetaDataSvc
        svcMgr += MetaDataSvc("MetaDataSvc")

    # Add BookkeeperTools
    from EventBookkeeperTools.EventBookkeeperToolsConf import BookkeeperTool

    # Standard event bookkeepers
    inname = "CutBookkeepers"
    outname = "FileBookkeepers"
    cutflowtool = BookkeeperTool(outname,
                                 InputCollName=inname,
                                 OutputCollName=outname)
    svcMgr.ToolSvc += cutflowtool

    # Add tool to MetaDataSvc
    svcMgr.MetaDataSvc.MetaDataTools += [cutflowtool]

    # Add pdf sum of weights counts if appropriate
    from AthenaCommon.GlobalFlags import globalflags
    if globalflags.DataSource() == 'geant4':
        #from PyUtils import AthFile
        #afc = AthFile.fopen( svcMgr.EventSelector.InputCollections[0] )

        # PDF
        name = "PDFSumOfWeights"
        pdfweighttool = BookkeeperTool(name,
                                       OutputCollName=name,
                                       InputCollName=name)
        svcMgr.ToolSvc += pdfweighttool

        # Add tool to MetaDataSvc
        svcMgr.MetaDataSvc.MetaDataTools += [pdfweighttool]

    # Check if we have a sequence given
    if not seq:
        # Fetch the AthAlgSeq, i.e., one of the existing master sequences where one should attach all algorithms
        seq = CfgMgr.AthSequencer("AthAlgSeq")
        pass

    # First of all, schedule EventCounterAlg
    if not hasattr(seq, "AllExecutedEvents"):
        if not seq.isLocked():
            if addAlgInPlace:
                msg.debug(
                    "Adding EventCounterAlg with name AllExecutedEvents to sequence with name %s"
                    % seq.getName())
                seq += CfgMgr.EventCounterAlg("AllExecutedEvents")
                pass
            else:
                # Need to schedule it after the xAODMaker::EventInfoCnvAlg such that xAOD::EventInfo is present
                index = 0
                if hasattr(seq, "xAODMaker::EventInfoCnvAlg"):
                    for alg in seq:
                        index += 1
                        if alg.getName() == "xAODMaker::EventInfoCnvAlg": break
                        pass
                    pass
                msg.debug(
                    "Adding EventCounterAlg with name AllExecutedEvents to sequence with name %s at position %i"
                    % (seq.getName(), index))
                seq.insert(index, CfgMgr.EventCounterAlg("AllExecutedEvents"))
                pass
            pass
        else:
            msg.info(
                "Could NOT add EventCounterAlg with name AllExecutedEvents to locked sequence with name %s"
                % seq.getName())
            pass
        pass

    # If wanted, add the meta-data to all output files
    if addMetaDataToAllOutputFiles:
        msg.debug(
            "Adding CutBookkeepers the the output meta data of all output streams"
        )
        from OutputStreamAthenaPool.MultipleStreamManager import MSMgr
        # Explicitely add file metadata from input and from transient store,
        # but only the ones that we always create.
        MSMgr.AddMetaDataItemToAllStreams("xAOD::CutBookkeeperContainer#" +
                                          SGkey)
        MSMgr.AddMetaDataItemToAllStreams("xAOD::CutBookkeeperAuxContainer#" +
                                          SGkey + "Aux.*")
        MSMgr.AddMetaDataItemToAllStreams(
            "xAOD::CutBookkeeperContainer#Incomplete" + SGkey)
        MSMgr.AddMetaDataItemToAllStreams(
            "xAOD::CutBookkeeperAuxContainer#Incomplete" + SGkey + "Aux.*")
        SGkey = "FileBookkeepers"
        MSMgr.AddMetaDataItemToAllStreams("xAOD::CutBookkeeperContainer#" +
                                          SGkey)
        MSMgr.AddMetaDataItemToAllStreams("xAOD::CutBookkeeperAuxContainer#" +
                                          SGkey + "Aux.*")
        MSMgr.AddMetaDataItemToAllStreams(
            "xAOD::CutBookkeeperContainer#Incomplete" + SGkey)
        MSMgr.AddMetaDataItemToAllStreams(
            "xAOD::CutBookkeeperAuxContainer#Incomplete" + SGkey + "Aux.*")
        pass

    return
Beispiel #4
0
def CreateCutFlowSvc( svcName="CutFlowSvc", seq=None, addMetaDataToAllOutputFiles=True ):
    """
    Helper to create the CutFlowSvc, extract the needed information from
    the input file, and also schedule all the needed stuff.
    """
    # Create a message logger
    from AthenaCommon.Logging import logging
    msg = logging.getLogger( "Create"+svcName )

    # Get the service manager
    from AthenaCommon.AppMgr import ServiceMgr as svcMgr

    # Determine current input stream name
    inputStreamName = GetCurrentStreamName( msg=msg )
    msg.debug("CreateCutFlowSvc: Have inputStreamName = %s" % (inputStreamName) )

    # Create the CutFlowSvc instance
    import AthenaCommon.CfgMgr as CfgMgr
    if not hasattr(svcMgr,"CutFlowSvc"): svcMgr += CfgMgr.CutFlowSvc()
    svcMgr.CutFlowSvc.InputStream   = inputStreamName

    # Make sure MetaDataSvc is ready
    if not hasattr(svcMgr,'MetaDataSvc'):
      from AthenaServices.AthenaServicesConf import MetaDataSvc
      svcMgr += MetaDataSvc( "MetaDataSvc" )

    # Add BookkeeperTools
    from EventBookkeeperTools.EventBookkeeperToolsConf import BookkeeperTool

    # Standard event bookkeepers
    primary_name = "CutBookkeepers"
    cutflowtool = BookkeeperTool(primary_name + "Tool",
                                 InputCollName = primary_name,
                                 OutputCollName= primary_name)
    svcMgr.ToolSvc += cutflowtool

    # Add tool to MetaDataSvc
    svcMgr.MetaDataSvc.MetaDataTools += [cutflowtool]

    # Check if we have a sequence given
    if not seq :
        # Fetch the AthAlgSeq, i.e., one of the existing master sequences where one should attach all algorithms
        seq = CfgMgr.AthSequencer("AthAlgSeq")
        pass

    # First of all, schedule EventCounterAlg
    if not hasattr(seq,"AllExecutedEvents"):
        if not seq.isLocked():
            # Need to schedule it after the xAODMaker::EventInfoCnvAlg such that xAOD::EventInfo is present
            index = 0
            if hasattr( seq, "xAODMaker::EventInfoCnvAlg" ):
                for alg in seq:
                    index += 1
                    if alg.getName() == "xAODMaker::EventInfoCnvAlg": break
                    pass
                pass
            msg.debug("Adding EventCounterAlg with name AllExecutedEvents to sequence with name %s at position %i" % (seq.getName(),index))
            seq.insert( index, CfgMgr.EventCounterAlg("AllExecutedEvents") )
            pass
        else :
            msg.info("Could NOT add EventCounterAlg with name AllExecutedEvents to locked sequence with name %s" % seq.getName())
            pass
        pass

    # If wanted, add the meta-data to all output files
    if addMetaDataToAllOutputFiles:
        msg.debug("Adding CutBookkeepers the the output meta data of all output streams")
        from OutputStreamAthenaPool.MultipleStreamManager import MSMgr
        # Explicitely add file metadata from input and from transient store,
        # but only the ones that we always create.
        MSMgr.AddMetaDataItemToAllStreams( "xAOD::CutBookkeeperContainer#"+primary_name )
        MSMgr.AddMetaDataItemToAllStreams( "xAOD::CutBookkeeperAuxContainer#"+primary_name+"Aux.*" )
        MSMgr.AddMetaDataItemToAllStreams( "xAOD::CutBookkeeperContainer#Incomplete"+primary_name )
        MSMgr.AddMetaDataItemToAllStreams( "xAOD::CutBookkeeperAuxContainer#Incomplete"+primary_name+"Aux.*" )
        pass

    return
Beispiel #5
0
        #Exception for DPD pass-through mode
        if rec.doDPD.passThroughMode:
            svcMgr.CutFlowSvc.SkimmingCycle=0
            svcMgr.CutFlowSvc.InputStream="Virtual"
            pass

        if rec.DPDMakerScripts()!=[] and not rec.doDPD.passThroughMode :
            # #Create a separate EventBookkeeper list to persistify skimming cycle info
            # from EventBookkeeperTools.BookkeepingInfoWriter import CutCycleWriter
            # topSequence += CutCycleWriter("CutCycleWriter",
            #                               OutputName   = "ProcessingCycle",
            #                               CurrentCycle = currentCycle)


            #Explicitely add file metadata from input and from transient store
            MSMgr.AddMetaDataItemToAllStreams(inputFileSummary['metadata_itemsList'])
            MSMgr.AddMetaDataItemToAllStreams( "LumiBlockCollection#*" )
            MSMgr.AddMetaDataItemToAllStreams( "xAOD::CutBookkeeperContainer#*" )
            MSMgr.AddMetaDataItemToAllStreams( "xAOD::CutBookkeeperAuxContainer#*" )
            #MSMgr.AddMetaDataItemToAllStreams( "EventBookkeeperCollection#*" )
            MSMgr.AddMetaDataItemToAllStreams( "IOVMetaDataContainer#*" )
            pass
        pass
    pass



###################
## Common Utils  ##
###################