00001 import os
00002 import FWCore.ParameterSet.Config as cms
00003
00004
00005 try:
00006 import json
00007 except:
00008 try:
00009 import simplejson as json
00010 except:
00011 print "Please use lxplus or set an environment (for example crab) with json lib available"
00012 sys.exit(1)
00013
00014 inputfiles = os.environ["ALIGNMENT_INPUTFILES"].split(" ")
00015 iteration = int(os.environ["ALIGNMENT_ITERATION"])
00016 jobnumber = int(os.environ["ALIGNMENT_JOBNUMBER"])
00017 mapplots = (os.environ["ALIGNMENT_MAPPLOTS"] == "True")
00018 segdiffplots = (os.environ["ALIGNMENT_SEGDIFFPLOTS"] == "True")
00019 curvatureplots = (os.environ["ALIGNMENT_CURVATUREPLOTS"] == "True")
00020
00021 globaltag = os.environ["ALIGNMENT_GLOBALTAG"]
00022 inputdb = os.environ["ALIGNMENT_INPUTDB"]
00023 trackerconnect = os.environ["ALIGNMENT_TRACKERCONNECT"]
00024 trackeralignment = os.environ["ALIGNMENT_TRACKERALIGNMENT"]
00025 trackerAPEconnect = os.environ["ALIGNMENT_TRACKERAPECONNECT"]
00026 trackerAPE = os.environ["ALIGNMENT_TRACKERAPE"]
00027 trackerBowsconnect = os.environ["ALIGNMENT_TRACKERBOWSCONNECT"]
00028 trackerBows = os.environ["ALIGNMENT_TRACKERBOWS"]
00029 gprcdconnect = os.environ["ALIGNMENT_GPRCDCONNECT"]
00030 gprcd = os.environ["ALIGNMENT_GPRCD"]
00031
00032 iscosmics = (os.environ["ALIGNMENT_ISCOSMICS"] == "True")
00033 station123params = os.environ["ALIGNMENT_STATION123PARAMS"]
00034 station4params = os.environ["ALIGNMENT_STATION4PARAMS"]
00035 cscparams = os.environ["ALIGNMENT_CSCPARAMS"]
00036 minTrackPt = float(os.environ["ALIGNMENT_MINTRACKPT"])
00037 maxTrackPt = float(os.environ["ALIGNMENT_MAXTRACKPT"])
00038 minTrackP = float(os.environ["ALIGNMENT_MINTRACKP"])
00039 maxTrackP = float(os.environ["ALIGNMENT_MAXTRACKP"])
00040 minTrackerHits = int(os.environ["ALIGNMENT_MINTRACKERHITS"])
00041 maxTrackerRedChi2 = float(os.environ["ALIGNMENT_MAXTRACKERREDCHI2"])
00042 allowTIDTEC = (os.environ["ALIGNMENT_ALLOWTIDTEC"] == "True")
00043 twoBin = (os.environ["ALIGNMENT_TWOBIN"] == "True")
00044 weightAlignment = (os.environ["ALIGNMENT_WEIGHTALIGNMENT"] == "True")
00045 minAlignmentHits = int(os.environ["ALIGNMENT_MINALIGNMENTHITS"])
00046 combineME11 = (os.environ["ALIGNMENT_COMBINEME11"] == "True")
00047 maxEvents = int(os.environ["ALIGNMENT_MAXEVENTS"])
00048 skipEvents = int(os.environ["ALIGNMENT_SKIPEVENTS"])
00049 maxResSlopeY = float(os.environ["ALIGNMENT_MAXRESSLOPEY"])
00050 preFilter = (os.environ["ALIGNMENT_PREFILTER"] == "True")
00051 muonCollectionTag = os.environ["ALIGNMENT_MUONCOLLECTIONTAG"]
00052 maxDxy = float(os.environ["ALIGNMENT_MAXDXY"])
00053 minNCrossedChambers = int(os.environ["ALIGNMENT_MINNCROSSEDCHAMBERS"])
00054
00055
00056 createAlignNtuple = False
00057 envNtuple = os.getenv("ALIGNMENT_CREATEALIGNNTUPLE")
00058 if envNtuple is not None:
00059 if envNtuple=='True': createAlignNtuple = True
00060
00061
00062 createMapNtuple = False
00063 envNtuple = os.getenv("ALIGNMENT_CREATEMAPNTUPLE")
00064 if envNtuple is not None:
00065 if envNtuple=='True': createMapNtuple = True
00066
00067
00068 doDT = True
00069 doCSC = True
00070 envDT = os.getenv("ALIGNMENT_DO_DT")
00071 envCSC = os.getenv("ALIGNMENT_DO_CSC")
00072 if envDT is not None and envCSC is not None:
00073 if envDT=='True' and envCSC=='False':
00074 doDT = True
00075 doCSC = False
00076 if envDT=='False' and envCSC=='True':
00077 doDT = False
00078 doCSC = True
00079
00080
00081 good_lumis = []
00082 json_file = os.getenv("ALIGNMENT_JSON")
00083
00084 if json_file is not None and json_file != '':
00085 jsonfile=file(json_file, 'r')
00086 jsondict = json.load(jsonfile)
00087 runs = jsondict.keys()
00088 runs.sort()
00089 for run in runs:
00090 blocks = jsondict[run]
00091 blocks.sort()
00092 prevblock = [-2,-2]
00093 for lsrange in blocks:
00094 if lsrange[0] == prevblock[1]+1:
00095
00096 prevblock[1] = lsrange[1]
00097 good_lumis[-1] = str("%s:%s-%s:%s" % (run, prevblock[0], run, prevblock[1]))
00098 else:
00099 good_lumis.append(str("%s:%s-%s:%s" % (run, lsrange[0], run, lsrange[1])))
00100 prevblock = lsrange
00101
00102
00103 process = cms.Process("GATHER")
00104
00105 if len(good_lumis)>0:
00106 process.source = cms.Source("PoolSource",
00107 fileNames = cms.untracked.vstring(*inputfiles),
00108 skipEvents = cms.untracked.uint32(skipEvents),
00109 lumisToProcess = cms.untracked.VLuminosityBlockRange(*good_lumis))
00110 else:
00111 process.source = cms.Source("PoolSource",
00112 fileNames = cms.untracked.vstring(*inputfiles),
00113 skipEvents = cms.untracked.uint32(skipEvents))
00114
00115 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(maxEvents))
00116
00117
00118
00119 process.MessageLogger = cms.Service("MessageLogger",
00120 destinations = cms.untracked.vstring("cout"),
00121 cout = cms.untracked.PSet(threshold = cms.untracked.string("ERROR"),
00122 ERROR = cms.untracked.PSet(limit = cms.untracked.int32(10))))
00123
00124 process.load("Alignment.MuonAlignmentAlgorithms.MuonAlignmentFromReference_cff")
00125 process.looper.ParameterBuilder.Selector.alignParams = cms.vstring("MuonDTChambers,%s,stations123" % station123params, "MuonDTChambers,%s,station4" % station4params, "MuonCSCChambers,%s" % cscparams)
00126
00127
00128 process.looper.algoConfig.writeTemporaryFile = "Alignment%04d.tmp" % jobnumber
00129 process.looper.algoConfig.doAlignment = False
00130 process.looper.algoConfig.muonCollectionTag = cms.InputTag(muonCollectionTag)
00131 process.looper.algoConfig.minTrackPt = minTrackPt
00132 process.looper.algoConfig.maxTrackPt = maxTrackPt
00133 process.looper.algoConfig.minTrackP = minTrackP
00134 process.looper.algoConfig.maxTrackP = maxTrackP
00135 process.looper.algoConfig.maxDxy = maxDxy
00136 process.looper.algoConfig.minTrackerHits = minTrackerHits
00137 process.looper.algoConfig.maxTrackerRedChi2 = maxTrackerRedChi2
00138 process.looper.algoConfig.allowTIDTEC = allowTIDTEC
00139 process.looper.algoConfig.minNCrossedChambers = minNCrossedChambers
00140 process.looper.algoConfig.twoBin = twoBin
00141 process.looper.algoConfig.weightAlignment = weightAlignment
00142 process.looper.algoConfig.minAlignmentHits = minAlignmentHits
00143 process.looper.algoConfig.combineME11 = combineME11
00144 process.looper.algoConfig.maxResSlopeY = maxResSlopeY
00145
00146 process.looper.algoConfig.minDT13Hits = 7
00147 process.looper.algoConfig.doDT = doDT
00148 process.looper.algoConfig.doCSC = doCSC
00149
00150 process.looper.monitorConfig = cms.PSet(monitors = cms.untracked.vstring())
00151
00152 if mapplots:
00153 process.load("Alignment.CommonAlignmentMonitor.AlignmentMonitorMuonSystemMap1D_cfi")
00154 process.looper.monitorConfig.monitors.append("AlignmentMonitorMuonSystemMap1D")
00155 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D = process.AlignmentMonitorMuonSystemMap1D
00156 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.muonCollectionTag = cms.InputTag(muonCollectionTag)
00157 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minTrackPt = minTrackPt
00158 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.maxTrackPt = maxTrackPt
00159 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minTrackP = minTrackP
00160 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.maxTrackP = maxTrackP
00161 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.maxDxy = maxDxy
00162 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minTrackerHits = minTrackerHits
00163 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.maxTrackerRedChi2 = maxTrackerRedChi2
00164 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.allowTIDTEC = allowTIDTEC
00165 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minNCrossedChambers = process.looper.algoConfig.minNCrossedChambers
00166 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minDT13Hits = process.looper.algoConfig.minDT13Hits
00167 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minDT2Hits = process.looper.algoConfig.minDT2Hits
00168 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minCSCHits = process.looper.algoConfig.minCSCHits
00169 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.doDT = doDT
00170 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.doCSC = doCSC
00171 process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.createNtuple = createMapNtuple
00172
00173 if segdiffplots:
00174 process.load("Alignment.CommonAlignmentMonitor.AlignmentMonitorSegmentDifferences_cfi")
00175 process.looper.monitorConfig.monitors.append("AlignmentMonitorSegmentDifferences")
00176 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences = process.AlignmentMonitorSegmentDifferences
00177 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.muonCollectionTag = cms.InputTag(muonCollectionTag)
00178 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minTrackPt = minTrackPt
00179 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minTrackP = minTrackP
00180 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.maxDxy = maxDxy
00181 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minTrackerHits = minTrackerHits
00182 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.maxTrackerRedChi2 = maxTrackerRedChi2
00183 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.allowTIDTEC = allowTIDTEC
00184 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minNCrossedChambers = process.looper.algoConfig.minNCrossedChambers
00185 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minDT13Hits = process.looper.algoConfig.minDT13Hits
00186 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minDT2Hits = process.looper.algoConfig.minDT2Hits
00187 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minCSCHits = process.looper.algoConfig.minCSCHits
00188 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.doDT = doDT
00189 process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.doCSC = doCSC
00190
00191 if curvatureplots:
00192 process.load("Alignment.CommonAlignmentMonitor.AlignmentMonitorMuonVsCurvature_cfi")
00193 process.looper.monitorConfig.monitors.append("AlignmentMonitorMuonVsCurvature")
00194 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature = process.AlignmentMonitorMuonVsCurvature
00195 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.muonCollectionTag = cms.InputTag(muonCollectionTag)
00196 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minTrackPt = minTrackPt
00197
00198 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.maxDxy = maxDxy
00199 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minTrackerHits = minTrackerHits
00200 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.maxTrackerRedChi2 = maxTrackerRedChi2
00201 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.allowTIDTEC = allowTIDTEC
00202 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minNCrossedChambers = process.looper.algoConfig.minNCrossedChambers
00203 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minDT13Hits = process.looper.algoConfig.minDT13Hits
00204 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minDT2Hits = process.looper.algoConfig.minDT2Hits
00205 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minCSCHits = process.looper.algoConfig.minCSCHits
00206 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.doDT = doDT
00207 process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.doCSC = doCSC
00208
00209 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
00210 process.GlobalTag.globaltag = cms.string(globaltag)
00211 process.looper.applyDbAlignment = True
00212 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")
00213
00214 process.load("Alignment.MuonAlignmentAlgorithms.MuonAlignmentPreFilter_cfi")
00215 process.MuonAlignmentPreFilter.minTrackPt = minTrackPt
00216 process.MuonAlignmentPreFilter.minTrackP = minTrackP
00217 process.MuonAlignmentPreFilter.minTrackerHits = minTrackerHits
00218 process.MuonAlignmentPreFilter.allowTIDTEC = allowTIDTEC
00219
00220 if iscosmics:
00221 process.MuonAlignmentPreFilter.tracksTag = cms.InputTag("ALCARECOMuAlGlobalCosmics:GlobalMuon")
00222 if preFilter: process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentPreFilter * process.MuonAlignmentFromReferenceGlobalCosmicRefit)
00223 else: process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentFromReferenceGlobalCosmicRefit)
00224 process.looper.tjTkAssociationMapTag = cms.InputTag("MuonAlignmentFromReferenceGlobalCosmicRefit:Refitted")
00225 else:
00226 process.MuonAlignmentPreFilter.tracksTag = cms.InputTag("ALCARECOMuAlCalIsolatedMu:GlobalMuon")
00227
00228
00229 if preFilter: process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentPreFilter * process.MuonAlignmentFromReferenceGlobalMuonRefit)
00230 else: process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentFromReferenceGlobalMuonRefit)
00231 process.looper.tjTkAssociationMapTag = cms.InputTag("MuonAlignmentFromReferenceGlobalMuonRefit:Refitted")
00232
00233
00234 if len(muonCollectionTag) > 0:
00235 process.Path = cms.Path(process.offlineBeamSpot * process.newmuons)
00236
00237
00238 process.MuonAlignmentFromReferenceInputDB.connect = cms.string("sqlite_file:%s" % inputdb)
00239 process.MuonAlignmentFromReferenceInputDB.toGet = cms.VPSet(cms.PSet(record = cms.string("DTAlignmentRcd"), tag = cms.string("DTAlignmentRcd")),
00240 cms.PSet(record = cms.string("CSCAlignmentRcd"), tag = cms.string("CSCAlignmentRcd")))
00241
00242 if trackerconnect != "":
00243 from CondCore.DBCommon.CondDBSetup_cfi import *
00244 process.TrackerAlignmentInputDB = cms.ESSource("PoolDBESSource",
00245 CondDBSetup,
00246 connect = cms.string(trackerconnect),
00247 toGet = cms.VPSet(cms.PSet(record = cms.string("TrackerAlignmentRcd"), tag = cms.string(trackeralignment))))
00248 process.es_prefer_TrackerAlignmentInputDB = cms.ESPrefer("PoolDBESSource", "TrackerAlignmentInputDB")
00249
00250 if trackerAPEconnect != "":
00251 from CondCore.DBCommon.CondDBSetup_cfi import *
00252 process.TrackerAlignmentErrorInputDB = cms.ESSource("PoolDBESSource",
00253 CondDBSetup,
00254 connect = cms.string(trackerAPEconnect),
00255 toGet = cms.VPSet(cms.PSet(cms.PSet(record = cms.string("TrackerAlignmentErrorRcd"), tag = cms.string(trackerAPE)))))
00256 process.es_prefer_TrackerAlignmentErrorInputDB = cms.ESPrefer("PoolDBESSource", "TrackerAlignmentErrorInputDB")
00257
00258 if trackerBowsconnect != "":
00259 from CondCore.DBCommon.CondDBSetup_cfi import *
00260 process.TrackerSurfaceDeformationInputDB = cms.ESSource("PoolDBESSource",
00261 CondDBSetup,
00262 connect = cms.string(trackerBowsconnect),
00263 toGet = cms.VPSet(cms.PSet(cms.PSet(record = cms.string("TrackerSurfaceDeformationRcd"), tag = cms.string(trackerBows)))))
00264 process.es_prefer_TrackerSurfaceDeformationInputDB = cms.ESPrefer("PoolDBESSource", "TrackerSurfaceDeformationInputDB")
00265
00266 if gprcdconnect != "":
00267 from CondCore.DBCommon.CondDBSetup_cfi import *
00268 process.GlobalPositionInputDB = cms.ESSource("PoolDBESSource",
00269 CondDBSetup,
00270 connect = cms.string(gprcdconnect),
00271 toGet = cms.VPSet(cms.PSet(record = cms.string("GlobalPositionRcd"), tag = cms.string(gprcd))))
00272 process.es_prefer_GlobalPositionInputDB = cms.ESPrefer("PoolDBESSource", "GlobalPositionInputDB")
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 process.looper.saveToDB = False
00312 process.looper.saveApeToDB = False
00313 del process.PoolDBOutputService
00314
00315 process.TFileService = cms.Service("TFileService", fileName = cms.string("plotting%03d.root" % jobnumber))