Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
import FWCore.ParameterSet.Config as cms
import FWCore.ParameterSet.VarParsing as VarParsing
import copy, sys, os

import Configuration.Geometry.defaultPhase2ConditionsEra_cff as _settings
GLOBAL_TAG, ERA = _settings.get_era_and_conditions(_settings.DEFAULT_VERSION)
process = cms.Process("Misaligner", ERA)

###################################################################
# Setup 'standard' options
###################################################################
options = VarParsing.VarParsing()

options.register('myScenario',
                 "MisalignmentScenario10MuPixelPhase2", # default value
                 VarParsing.VarParsing.multiplicity.singleton, # singleton or list
                 VarParsing.VarParsing.varType.string, # string, int, or float
                 "scenario to apply")

options.register('mySigma',
                 -1, # default value
                 VarParsing.VarParsing.multiplicity.singleton, # singleton or list
                 VarParsing.VarParsing.varType.float, # string, int, or float
                 "sigma for random misalignment in um")

options.register('inputDB',
                 None, # default value
                 VarParsing.VarParsing.multiplicity.singleton, # singleton or list
                 VarParsing.VarParsing.varType.string, # string, int, or float
                 "input database file to override GT (optional)")

options.parseArguments()

###################################################################
# Message logger service
###################################################################
process.load("FWCore.MessageService.MessageLogger_cfi")
process.MessageLogger.cout = cms.untracked.PSet(
    threshold = cms.untracked.string('INFO'),
    default = cms.untracked.PSet(
        limit = cms.untracked.int32(10000000)
    )
)
# replace MessageLogger.debugModules = { "*" }
# service = Tracer {}

###################################################################
# Ideal geometry producer and standard includes
###################################################################
process.load('Configuration.Geometry.GeometryExtendedRun4DefaultReco_cff')
process.trackerGeometry.applyAlignment = True

###################################################################
# Just state the Global Tag (and pick some run)
###################################################################
process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
from Configuration.AlCa.GlobalTag import GlobalTag
#process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic_T25', '') # using realistic Phase 2 geom
process.GlobalTag = GlobalTag(process.GlobalTag, GLOBAL_TAG, '') # using realistic Phase 2 geom
print("Using global tag:", process.GlobalTag.globaltag.value())

###################################################################
# This uses the object from the tag and applies the misalignment scenario on top of that object
###################################################################
process.load("Alignment.CommonAlignmentProducer.AlignmentProducer_cff")
process.AlignmentProducer.doMisalignmentScenario=True
process.AlignmentProducer.applyDbAlignment=True
process.AlignmentProducer.checkDbAlignmentValidity=False #otherwise error thrown for IOV dependent GTs
import Alignment.TrackerAlignment.Scenarios_cff as scenarios

if hasattr(scenarios, options.myScenario):
    print("Using scenario:", options.myScenario)
    print("    with sigma:", options.mySigma)
    print()
    process.AlignmentProducer.MisalignmentScenario = getattr(scenarios, options.myScenario)
else:
    print("----- Begin Fatal Exception -----------------------------------------------")
    print("Unrecognized",options.myScenario,"misalignment scenario !!!!")
    print("Aborting cmsRun now, please check your input")
    print("----- End Fatal Exception -------------------------------------------------")
    sys.exit(1)

sigma = options.mySigma
if sigma > 0:
    process.AlignmentProducer.MisalignmentScenario.scale = cms.double(0.0001*sigma) # shifts are in cm

# if options.inputDB is not None:
#     print("EXTENDING THE GLOBAL TAG!!!!")
#     process.GlobalTag.toGet.extend([
#             cms.PSet(
#                 connect = cms.string("sqlite_file:"+options.inputDB),
#                 record = cms.string("TrackerAlignmentRcd"),
#                 tag = cms.string("Alignments")
#                 ),
#             cms.PSet(
#                 connect = cms.string("sqlite_file:"+options.inputDB),
#                 record = cms.string("TrackerAlignmentErrorExtendedRcd"),
#                 tag = cms.string("AlignmentErrorsExtended")
#                 )
#             ])

process.AlignmentProducer.saveToDB=True
process.AlignmentProducer.saveApeToDB=True

###################################################################
# Output name
###################################################################
outputfilename = None
scenariolabel = str(options.myScenario)
if sigma > 0:
    scenariolabel = scenariolabel+str(sigma)
outputfilename = "geometry_"+str(scenariolabel)+"__from_"
if options.inputDB is None:
    outputfilename += process.GlobalTag.globaltag.value()+".db"
else:
    outputfilename += options.inputDB

###################################################################
# Source
###################################################################
process.source = cms.Source("EmptySource")
process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1))

###################################################################
# Database output service
###################################################################
from CondCore.CondDB.CondDB_cfi import *
process.PoolDBOutputService = cms.Service(
    "PoolDBOutputService",
    CondDB,
    timetype = cms.untracked.string("runnumber"),
    toPut = cms.VPSet(
        cms.PSet(
            record = cms.string("TrackerAlignmentRcd"),
            tag = cms.string("Alignments")
            ),
        cms.PSet(
            record = cms.string("TrackerAlignmentErrorExtendedRcd"),
            tag = cms.string("AlignmentErrorsExtended")
            ),
        )
    )
process.PoolDBOutputService.connect = "sqlite_file:"+outputfilename
process.PoolDBOutputService.DBParameters.messageLevel = 2