Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-15 22:40:10

0001 from __future__ import print_function
0002 import os
0003 
0004 import FWCore.ParameterSet.Config as cms
0005 
0006 
0007 
0008 
0009 ##
0010 ## Setup command line options
0011 ##
0012 import FWCore.ParameterSet.VarParsing as VarParsing
0013 import sys
0014 options = VarParsing.VarParsing ('standard')
0015 options.register('sample', 'data1', VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string, "Input sample")
0016 options.register('globalTag', "None", VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string, "Custom global tag")
0017 options.register('measurementName', "workingArea", VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string, "Folder in which to store results")
0018 options.register('fileNumber', 1, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int, "Input file number")
0019 options.register('iterNumber', 0, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int, "Iteration number")
0020 options.register('lastIter', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.bool, "Last iteration")
0021 options.register('alignRcd','', VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string, "AlignmentRcd")
0022 options.register('conditions',"None", VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string, "File with conditions")
0023 options.register('cosmics', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.bool, "Cosmic data set")
0024 # get and parse the command line arguments
0025 options.parseArguments()   
0026 
0027 print("Input sample: ", options.sample)
0028 print("Input file number", options.fileNumber)
0029 print("Iteration number: ", options.iterNumber)
0030 print("Last iteration: ", options.lastIter)
0031 print("AlignmentRcd: ", options.alignRcd)
0032 
0033 
0034 
0035 ##
0036 ## Process definition
0037 ##
0038 process = cms.Process("ApeEstimator")
0039 
0040 
0041 process.load("Configuration.Geometry.GeometryRecoDB_cff")
0042 process.load("Configuration.StandardSequences.Services_cff")
0043 process.load("Configuration.StandardSequences.MagneticField_cff")
0044 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
0045 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0046 from Configuration.AlCa.GlobalTag import GlobalTag
0047 from CondCore.CondDB.CondDB_cfi import *
0048 
0049 ##
0050 ## Message Logger
0051 ##
0052 process.load("FWCore.MessageService.MessageLogger_cfi")
0053 process.MessageLogger.SectorBuilder=dict()
0054 process.MessageLogger.ResidualErrorBinning=dict()
0055 process.MessageLogger.HitSelector=dict()
0056 process.MessageLogger.CalculateAPE=dict()
0057 process.MessageLogger.ApeEstimator=dict()
0058 process.MessageLogger.TrackRefitter=dict()
0059 process.MessageLogger.AlignmentTrackSelector=dict()
0060 process.MessageLogger.cerr.threshold = 'WARNING'
0061 process.MessageLogger.cerr.INFO.limit = 0
0062 process.MessageLogger.cerr.default.limit = -1
0063 process.MessageLogger.cerr.SectorBuilder = cms.untracked.PSet(limit = cms.untracked.int32(-1))
0064 process.MessageLogger.cerr.HitSelector = cms.untracked.PSet(limit = cms.untracked.int32(-1))
0065 process.MessageLogger.cerr.CalculateAPE = cms.untracked.PSet(limit = cms.untracked.int32(-1))
0066 process.MessageLogger.cerr.ApeEstimator = cms.untracked.PSet(limit = cms.untracked.int32(-1))
0067 process.MessageLogger.cerr.AlignmentTrackSelector = cms.untracked.PSet(limit = cms.untracked.int32(-1))
0068 process.MessageLogger.cerr.FwkReport.reportEvery = 1000 ## really show only every 1000th
0069 
0070 
0071 ##
0072 ## Process options
0073 ##
0074 process.options = cms.untracked.PSet(
0075     wantSummary = cms.untracked.bool(True),
0076 )
0077 
0078 
0079 
0080 ##
0081 ## Input sample definition
0082 ##
0083 isData1 = isData2 = False
0084 isData = False
0085 isQcd = isWlnu = isZmumu = isZtautau = isZmumu10 = isZmumu20 = isZmumu50 = False
0086 isMc = False
0087 isParticleGunMuon = isParticleGunPion = False
0088 isParticleGun = False
0089 if options.sample == 'data1':
0090     isData = True
0091 elif options.sample == 'data2':
0092     isData = True
0093 elif options.sample == 'data3':
0094     isData = True
0095 elif options.sample == 'data4':
0096     isData = True
0097 elif options.sample == 'qcd':
0098     isMc = True
0099 elif options.sample == 'wlnu':
0100     isMc = True
0101 elif options.sample == 'zmumu':
0102     isMc = True
0103 elif options.sample == 'ztautau':
0104     isMc = True
0105 elif options.sample == 'zmumu10':
0106     isMc = True
0107 elif options.sample == 'zmumu20':
0108     isMc = True
0109 elif options.sample == 'zmumu50':
0110     isMc = True
0111 elif "MC" in options.sample:
0112     isMc = True
0113     print(options.sample)
0114 else:
0115     print('ERROR --- incorrect data sammple: ', options.sample)
0116     exit(8888)
0117 
0118 
0119 ##
0120 ## Input Files
0121 ##
0122 readFiles = cms.untracked.vstring()
0123 process.source = cms.Source ("PoolSource",
0124     fileNames = readFiles
0125 )
0126 readFiles.extend( [
0127     'file:reco.root',
0128 ] )
0129 
0130 
0131 
0132 ##
0133 ## Number of Events (should be after input file)
0134 ##
0135 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.maxEvents) ) # maxEvents is included in options by default
0136 
0137 
0138 
0139 ##
0140 ## Check run and event numbers for Dublicates --- only for real data
0141 ##
0142 process.source.duplicateCheckMode = cms.untracked.string("checkEachRealDataFile")
0143 #process.source.duplicateCheckMode = cms.untracked.string("checkAllFilesOpened")   # default value
0144 
0145 
0146 ##
0147 ## Whole Refitter Sequence
0148 ##
0149 process.load("Alignment.APEEstimation.TrackRefitter_38T_cff")
0150 
0151 if options.globalTag != "None":
0152     process.GlobalTag = GlobalTag(process.GlobalTag, options.globalTag, '')
0153 elif isParticleGun:
0154     process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_design', '')
0155 elif isMc:
0156     #~ process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase1_2018_design', '')
0157     process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase1_2018_realistic', '')
0158 elif isData:
0159     process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_data', '')
0160 
0161 if options.conditions != "None":
0162     import importlib
0163     mod = importlib.import_module("Alignment.APEEstimation.conditions.{}".format(options.conditions))
0164     mod.applyConditions(process)
0165 
0166 ## Alignment and APE
0167 ##
0168 ## Choose Alignment (w/o touching APE)
0169 if options.alignRcd=='fromConditions':
0170     pass # Alignment is read from the conditions file in this case
0171 elif options.alignRcd=='design':
0172     pass
0173 elif options.alignRcd == 'globalTag':
0174     pass
0175 elif options.alignRcd == 'useStartGlobalTagForAllConditions':
0176     pass
0177 elif options.alignRcd == '':
0178     pass
0179 else:
0180     print('ERROR --- incorrect alignment: ', options.alignRcd)
0181     exit(8888)
0182 
0183 ## APE
0184 if options.iterNumber!=0:
0185     CondDBAlignmentError = CondDB.clone(connect = cms.string('sqlite_file:'+os.environ['CMSSW_BASE']+'/src/Alignment/APEEstimation/hists/'+options.measurementName+'/apeObjects/apeIter'+str(options.iterNumber-1)+'.db'))
0186     process.myTrackerAlignmentErr = cms.ESSource("PoolDBESSource",
0187         CondDBAlignmentError,
0188         timetype = cms.string("runnumber"),
0189         toGet = cms.VPSet(
0190             cms.PSet(
0191                 record = cms.string('TrackerAlignmentErrorExtendedRcd'),
0192                 tag = cms.string('APEs')
0193             )
0194         )
0195     )
0196     process.es_prefer_trackerAlignmentErr = cms.ESPrefer("PoolDBESSource","myTrackerAlignmentErr")
0197 
0198 
0199 ##
0200 ## Beamspot (Use correct Beamspot for simulated Vertex smearing of ParticleGun)
0201 ##
0202 if isParticleGun:
0203     process.load("Alignment.APEEstimation.BeamspotForParticleGun_cff")
0204 
0205 
0206 ##
0207 ## Trigger Selection
0208 ##
0209 process.load("Alignment.APEEstimation.TriggerSelection_cff")
0210 
0211 
0212 ##
0213 ## ApeEstimator
0214 ##
0215 from Alignment.APEEstimation.ApeEstimator_cff import *
0216 process.ApeEstimator1 = ApeEstimator.clone(
0217     tjTkAssociationMapTag = "TrackRefitterForApeEstimator",
0218     applyTrackCuts = False,
0219     analyzerMode = False,
0220     calculateApe = True,
0221     Sectors = RecentSectors,
0222 )
0223 
0224 process.ApeEstimator2 = process.ApeEstimator1.clone(
0225   Sectors = ValidationSectors,
0226   analyzerMode = True,
0227   calculateApe = False,
0228 )
0229 process.ApeEstimator3 = process.ApeEstimator2.clone(
0230     zoomHists = False,
0231 )
0232 
0233 process.ApeEstimatorSequence = cms.Sequence(process.ApeEstimator1)
0234 if options.iterNumber==0:
0235   process.ApeEstimatorSequence *= process.ApeEstimator2
0236   process.ApeEstimatorSequence *= process.ApeEstimator3
0237 elif options.lastIter == True:
0238   process.ApeEstimatorSequence *= process.ApeEstimator2
0239 
0240 
0241 
0242 ##
0243 ## Output File Configuration
0244 ##
0245 process.TFileService = cms.Service("TFileService",
0246     fileName = cms.string(os.environ['CMSSW_BASE'] + '/src/Alignment/APEEstimation/hists/'+options.measurementName+'/'+options.sample+str(options.fileNumber)+'.root'),
0247     closeFileFast = cms.untracked.bool(True)
0248 )
0249 
0250 
0251 
0252 ##
0253 ## Path
0254 ##
0255 
0256 if not options.cosmics:
0257     process.p = cms.Path(
0258         #process.TriggerSelectionSequence* # You want to use this if you want to select for triggers
0259         process.RefitterHighPuritySequence*
0260         process.ApeEstimatorSequence
0261     )
0262 else:
0263     process.p = cms.Path(
0264         process.RefitterNoPuritySequence* # this sequence doesn't include high purity track criteria
0265         process.ApeEstimatorSequence
0266     )
0267 
0268 
0269