Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-17 01:40:52

0001 #! /usr/bin/env cmsRun
0002 # Author: Izaak Neutelings (March 2020)
0003 from __future__ import print_function
0004 #import os
0005 import os, shlex, shutil, getpass
0006 #import subprocess
0007 import FWCore.ParameterSet.Config as cms
0008 from Configuration.StandardSequences.Eras import eras
0009 
0010 # SETTINGS
0011 run       = 313000 # select the geometry for Phase-I pixels
0012 era       = eras.Run2_2017 
0013 verbose   = False #or True
0014 threshold = 'INFO' if verbose else 'WARNING'
0015 print(">>> run = %s"%run)
0016 
0017 # LOAD PROCESS
0018 process = cms.Process("SiPixelVCalDB",era)
0019 process.load("FWCore.MessageService.MessageLogger_cfi")
0020 process.load("Configuration.StandardSequences.GeometryDB_cff")
0021 #process.load("Configuration.StandardSequences.GeometryIdeal_cff")
0022 #process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0023 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0024 #process.load("CalibTracker.Configuration.TrackerAlignment.TrackerAlignment_Fake_cff")
0025 #process.load("Geometry.CMSCommonData.cmsIdealGeometryXML_cfi")
0026 #process.load("Geometry.TrackerGeometryBuilder.trackerGeometry_cfi")
0027 #process.load("Geometry.TrackerNumberingBuilder.trackerNumberingGeometry_cfi")
0028 process.load("CondTools.SiPixel.SiPixelGainCalibrationService_cfi")
0029 #process.load("CondCore.CondDB.CondDB_cfi") # deprecated
0030 process.load("CondCore.CondDB.CondDB_cfi")
0031 
0032 # GLOBAL TAG
0033 from Configuration.AlCa.GlobalTag import GlobalTag
0034 #from Configuration.AlCa.autoCond import autoCond
0035 #from Configuration.AlCa.autoCond import autoCond
0036 #process.GlobalTag.globaltag = "auto:run2_data" 
0037 #process.GlobalTag.globaltag = autoCond['run2_design']
0038 # In case you of conditions missing, or if you want to test a specific GT
0039 #process.GlobalTag.globaltag = 'PRE_DES72_V6'
0040 process.GlobalTag = GlobalTag(process.GlobalTag,'auto:run2_data','')
0041 #process.GlobalTag = GlobalTag(process.GlobalTag,autoCond['run2_design'],'')
0042 #process.GlobalTag.globaltag = autoCond['run2_design']
0043 print(">>> globaltag = '%s'"%(process.GlobalTag.globaltag))
0044 
0045 # BASIC SETTING
0046 process.source = cms.Source("EmptyIOVSource",
0047     firstValue = cms.uint64(run),
0048     lastValue = cms.uint64(run),
0049     #firstRun = cms.untracked.uint32(run),
0050     timetype = cms.string('runnumber'),
0051     interval = cms.uint64(1),
0052 )
0053 process.maxEvents = cms.untracked.PSet(
0054     input = cms.untracked.int32(1)
0055 )
0056 
0057 # MESSAGER
0058 process.MessageLogger.cerr.enable = False
0059 process.MessageLogger.cout = dict(enable = True, threshold = threshold)
0060 
0061 # BACK UP DATABASE FILE
0062 user = getpass.getuser()
0063 #try:
0064 #    user = os.environ["USER"]
0065 #except KeyError:
0066 #    user = subprocess.call('whoami')
0067 #    # user = commands.getoutput('whoami') 
0068 #file = "/tmp/" + user + "/SiPixelVCal.db"
0069 file = "siPixelVCal.db"
0070 sqlfile = "sqlite_file:" + file
0071 print(">>> Uploading as user %s into file %s, i.e. %s"%(user,file,sqlfile))
0072 if os.path.exists("siPixelVCal.db"):
0073   oldfile = file.replace(".db","_old.db")
0074   print(">>> Backing up locally existing '%s' -> '%s'"%(file,oldfile))
0075   shutil.move(file,oldfile)
0076 
0077 # DATABASE CONNNECTION AND INPUT TAGS
0078 process.PoolDBOutputService = cms.Service("PoolDBOutputService",
0079     BlobStreamerName = cms.untracked.string('TBufferBlobStreamingService'),
0080     DBParameters = cms.PSet(
0081         authenticationPath = cms.untracked.string('.'),
0082         connectionRetrialPeriod = cms.untracked.int32(10),
0083         idleConnectionCleanupPeriod = cms.untracked.int32(10),
0084         messageLevel = cms.untracked.int32(1),
0085         enablePoolAutomaticCleanUp = cms.untracked.bool(False),
0086         enableConnectionSharing = cms.untracked.bool(True),
0087         connectionRetrialTimeOut = cms.untracked.int32(60),
0088         connectionTimeOut = cms.untracked.int32(0),
0089         enableReadOnlySessionOnUpdateConnection = cms.untracked.bool(False)
0090     ),
0091     timetype = cms.untracked.string('runnumber'),
0092     connect = cms.string(sqlfile),
0093     toPut = cms.VPSet(
0094         cms.PSet(
0095             record = cms.string('SiPixelVCalRcd'),
0096             tag = cms.string('SiPixelVCal_v1')
0097         ),
0098         #cms.PSet(
0099         #    record = cms.string('SiPixelVCalSimRcd'),
0100         #    tag = cms.string('SiPixelVCalSim_v1')
0101         #),
0102     )
0103 )
0104 
0105 # VCAL -> NUMBER OF ELECTRONS DB OBJECT
0106 # https://github.com/cms-analysis/DPGAnalysis-SiPixelTools/blob/1232a8c0ef3abe7b78c757887138089706e0499a/GainCalibration/test/vcal-irradiation-factors.txt
0107 # https://github.com/cms-sw/cmssw/blob/master/DataFormats/SiPixelDetId/src/PixelEndcapName.cc
0108 slope      = 47.
0109 slope_L1   = 50.
0110 offset     = -60.
0111 offset_L1  = -670.
0112 corrs_bpix = { 1: 1.110, 2: 1.036, 3: 1.023, 4: 1.011 }
0113 corrs_fpix = { 1: 1.1275, 2: 1.1275, 3: 1.1275 }
0114 layers     = [1,2,3,4]
0115 nladders   = { 1: 12, 2: 28, 3: 44, 4: 64, }
0116 sides      = [1,2]   # 1=minus, 2=plus
0117 disks      = [1,2,3] # 1, 2, 3
0118 rings      = [1,2]   # 1=lower, 2=upper
0119 bpixpars   = cms.untracked.VPSet()
0120 fpixpars   = cms.untracked.VPSet()
0121 print(">>> %8s %8s %10s %10s %10s"%('layer','ladder','slope','offset','corr'))
0122 for layer in layers:
0123   for ladder in range(1,nladders[layer]+1):
0124     corr     = corrs_bpix[layer]
0125     slope_   = (slope_L1 if layer==1 else slope)*corr
0126     offset_  = (offset_L1 if layer==1 else offset)
0127     print(">>> %8d %8d %10.4f %10.3f %10.4f"%(layer,ladder,slope_,offset_,corr))
0128     bpixpars.append(cms.PSet(
0129       layer  = cms.int32(layer),
0130       ladder = cms.int32(ladder),
0131       slope  = cms.double(slope_),
0132       offset = cms.double(offset_),
0133     ))
0134 print(">>> %8s %8s %8s %10s %10s %10s"%('side','disk','ring','slope','offset','corr'))
0135 for side in sides:
0136   for disk in disks:
0137     for ring in rings:
0138       corr     = corrs_fpix[ring]
0139       slope_   = slope*corr
0140       offset_  = offset
0141       print(">>> %8d %8d %8d %10.4f %10.3f %10.4f"%(side,disk,ring,slope_,offset_,corr))
0142       fpixpars.append(cms.PSet(
0143         side   = cms.int32(side),
0144         disk   = cms.int32(disk),
0145         ring   = cms.int32(ring),
0146         slope  = cms.double(slope_),
0147         offset = cms.double(offset_),
0148       ))
0149 
0150 # DB CREATOR
0151 process.SiPixelVCal = cms.EDAnalyzer("SiPixelVCalDB",
0152     BPixParameters = bpixpars,
0153     FPixParameters = fpixpars,
0154     record = cms.untracked.string('SiPixelVCalRcd'),
0155 )
0156 process.p = cms.Path(process.SiPixelVCal)