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