Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-10 22:50:05

0001 from __future__ import print_function
0002 import os
0003 import sys
0004 try:
0005    ReleaseBase = os.path.join(os.environ['CMSSW_BASE'], "src")
0006    ReleaseVersion = os.environ['CMSSW_VERSION']
0007 except KeyError:
0008    print("CMSSW enviroment not set, please run cmsenv!")
0009    sys.exit()
0010 
0011 import FWCore.ParameterSet.Config as cms
0012 import FWCore.ParameterSet.VarParsing as VarParsing
0013 
0014 #options = VarParsing.VarParsing ('standard')
0015 options = VarParsing.VarParsing ()
0016 
0017 allowedOptions = {}
0018 
0019 options.register( 'maxEvents',
0020                    -1,
0021                    VarParsing.VarParsing.multiplicity.singleton,
0022                    VarParsing.VarParsing.varType.int,
0023                    "Specify events to run."
0024                 )
0025 
0026 options.register( 'eventType',
0027                   "ZTT",
0028                   VarParsing.VarParsing.multiplicity.singleton,
0029                   VarParsing.VarParsing.varType.string,
0030                   #"If true, generate and validate Z-TauTau (hadronic only) events. Otherwise, generate QCD FlatPt 15-3000 events."
0031                   "Specify the type of events to validate. (and generate, if using fast or fullsim)\
0032                         \n\t\tOptions:\
0033                         \n\t\t\tZTT\
0034                         \n\t\t\tQCD\
0035                         \n\t\t\tZEE\
0036                         \n\t\t\tZMM\
0037                         \n\t\t\tZTTFastSim\
0038                         \n\t\t\tZEEFastSim\
0039                         \n\t\t\tRealData          (Jets faking taus)\
0040                         \n\t\t\tRealMuonsData     (Iso Muons faking taus)\
0041                         \n\t\t\tRealElectronsData (Iso Electrons faking taus)\n"
0042                  )
0043 
0044 allowedOptions['eventType'] = [ 'ZTT', 'QCD', 'ZEE', 'ZMM', 'RealData', 'RealMuonsData', 'RealElectronsData','ZTTFastSim','ZEEFastSim']
0045 
0046 options.register( 'label',
0047                   "none",
0048                   VarParsing.VarParsing.multiplicity.singleton,
0049                   VarParsing.VarParsing.varType.string,
0050                   "Validation output files will be stored in folder Validation_<label>.  The root file will also use this label.\n"
0051                  )
0052 
0053 options.register( 'dataSource',
0054                   'recoFiles',
0055                   VarParsing.VarParsing.multiplicity.singleton,
0056                   VarParsing.VarParsing.varType.string,
0057                   "Specify where the data should come from. \n\t\tOptions: \
0058                         \n\t\t\trecoFiles:\t\t\tGet data from [sourceFile] (must have RECO)\
0059                         \n\t\t\trecoFiles+PFTau:\t\tGet reco data as above, and rerun PFTau with current tags \
0060                         \n\t\t\tdigiFiles:\t\t\tGet data from [sourceFile] (must have DIGI) and rerun RECO \
0061                         \n\t\t\tfastsim:\t\t\tRun FastSim \
0062                         \n\t\t\tfullsim:\t\t\tGen-Sim-Digi-Reco-Validate!\n"
0063                   )
0064 
0065 allowedOptions['dataSource'] = ['recoFiles', 'recoFiles+PFTau', 'fastsim', 'digiFiles', 'fullsim']
0066 
0067 options.register( 'sourceFile',
0068                   'none',
0069                   VarParsing.VarParsing.multiplicity.singleton,
0070                   VarParsing.VarParsing.varType.string,
0071                   "Specify a file containing events to read if using the recoFiles or digiFiles options. If left as none files will be taken from\
0072                         \n\t\t\trecoFiles:\t\t\tGet data from [sourceFile]EventSource_<eventType>_RECO_cff.py \
0073                         \n\t\t\tdigiFiles:\t\t\tGet data from EventSource_<eventType>_DIGI_cff.py \n"
0074                   )
0075 
0076 options.register( 'conditions',
0077                   'whatever',
0078                   VarParsing.VarParsing.multiplicity.singleton,
0079                   VarParsing.VarParsing.varType.string,
0080                   "Specify global tag for conditions.  If left as default ('whatever'), whatever is defined in Configuration.FrontierConditions_GlobalTag_cff will be taken\n"
0081                 )
0082 
0083 options.register( 'myModifications',
0084                   'none',
0085                   VarParsing.VarParsing.multiplicity.list,
0086                   VarParsing.VarParsing.varType.string,
0087                   "Specify one (or more) files to be loaded in the process. You can use this to modifiy cfi parameters from their defaults. See ExampleModification_cfi.py"
0088                   )
0089 
0090 options.register( 'batchNumber',
0091                   -1,
0092                   VarParsing.VarParsing.multiplicity.singleton,
0093                   VarParsing.VarParsing.varType.int,
0094                   "Run in batch mode: add batch number to output file, dont' compute efficiency, and change random seed.  If running from files, skipEvents will automatically be \
0095                    set."
0096                )
0097 
0098 options.register( 'writeEDMFile',
0099                   "",
0100                   VarParsing.VarParsing.multiplicity.singleton,
0101                   VarParsing.VarParsing.varType.string,
0102                   "Specify an (optional) output file.  Batch number and .root suffix will be appended. Event content will PFTau RECO content along with genParticles"
0103                )
0104 
0105 options.register( 'edmFileContents',
0106                   "AODSim",
0107                   VarParsing.VarParsing.multiplicity.list,
0108                   VarParsing.VarParsing.varType.string,
0109                   "Specify event content. Not yet implemented"
0110                 )
0111 
0112 options.register( 'gridJob',
0113                   False,
0114                   VarParsing.VarParsing.multiplicity.singleton,
0115                   VarParsing.VarParsing.varType.bool,
0116                   "Set to true makes some modifications to enable to run on grid. On the analysis has the same effect of running in batch, but has also other features."
0117                 )
0118 
0119 ################################
0120 #
0121 #        Batchmode options
0122 #
0123 ################################
0124 
0125 # add options for number of batchJobs
0126 options.register( 'nJobs',
0127                   0,
0128                   VarParsing.VarParsing.multiplicity.singleton,
0129                   VarParsing.VarParsing.varType.int,
0130                   "Number of jobs to submit to LXBatch. [Batchmode only]"
0131                 )
0132 
0133 options.register( 'copyToCastorDir',
0134                   "",
0135                   VarParsing.VarParsing.multiplicity.singleton,
0136                   VarParsing.VarParsing.varType.string,
0137                   "If writeEDMFile is specified, copy the edmOutputFile to castor.  Specify <home> to use your home dir. [Batchmode only]"
0138                 )
0139 
0140 options.register( 'lxbatchQueue',
0141                   '8nh',
0142                   VarParsing.VarParsing.multiplicity.singleton,
0143                   VarParsing.VarParsing.varType.string,
0144                   "LXBatch queue (8nm, 1nh, 8nh, 1nd, 1nw) [Batchmode only]"
0145                 )
0146 
0147 allowedOptions['lxbatchQueue'] = ['8nm', '1nh', '8nh', '1nd', '1nw']
0148 
0149 
0150 def checkOptionsForBadInput():
0151    # Sanity check
0152    for optionName, allowedValues in allowedOptions.items():
0153       if not getattr(options, optionName) in allowedValues:
0154          print("Bad input to option: %s" % optionName)
0155          sys.exit()
0156 
0157 def calledBycmsRun():
0158    ''' Returns true of this python3 file is being called via cmsRun '''
0159    if sys.argv[0].find('cmsRun') == -1:
0160       return False
0161    else:
0162       return True
0163 
0164 def CMSSWEnvironmentIsCurrent():
0165    ''' Make sure that our CMSSW environment doesn't point ot another release!'''
0166    if ReleaseBase != os.path.commonprefix([ReleaseBase, os.getcwd()]):
0167       return False
0168    else:
0169       return True
0170 
0171 def returnOptionsString():
0172    ''' format the options to be passed on the command line.  Used when submitting batch jobs'''
0173    outputString = ""
0174    for optionsName, optionValue in options.__dict__['_singletons'].items():
0175       outputString += " %s=%s" % (optionsName, optionValue)
0176 
0177    for optionsName, optionValues in options.__dict__['_lists'].items():
0178       for anOption in optionValues:
0179          outputString += " %s=%s" % (optionsName, anOption) 
0180    return outputString