Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-19 04:58:01

0001 import FWCore.ParameterSet.Config as cms
0002 import os
0003 import json
0004 
0005 process = cms.Process("READ")
0006 
0007 # import of standard configurations
0008 process.load('Configuration.StandardSequences.Services_cff')
0009 process.load('Configuration.EventContent.EventContent_cff')
0010 process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
0011 process.load('Configuration.StandardSequences.MagneticField_AutoFromDBCurrent_cff')
0012 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
0013 
0014 import FWCore.ParameterSet.VarParsing as VarParsing
0015 from Configuration.AlCa.GlobalTag import GlobalTag
0016 
0017 options = VarParsing.VarParsing()
0018 options.register('lumisPerRun',
0019                 1,
0020                 VarParsing.VarParsing.multiplicity.singleton,
0021                 VarParsing.VarParsing.varType.int,
0022                 "the number of lumis to be processed per-run.")
0023 options.register('firstRun',
0024                 290550,
0025                 VarParsing.VarParsing.multiplicity.singleton,
0026                 VarParsing.VarParsing.varType.int,
0027                 "the first run number be processed")
0028 options.register('lastRun',
0029                 325175,
0030                 VarParsing.VarParsing.multiplicity.singleton,
0031                 VarParsing.VarParsing.varType.int,
0032                 "the run number to stop at")
0033 options.register('config',
0034                  default = None,
0035                  mult    = VarParsing.VarParsing.multiplicity.singleton,
0036                  mytype  = VarParsing.VarParsing.varType.string,
0037                  info    = 'JSON config with information about the GT, Alignments, etc.')
0038 options.register('unitTest',
0039                  False, # default value
0040                  VarParsing.VarParsing.multiplicity.singleton, # singleton or list
0041                  VarParsing.VarParsing.varType.bool, # string, int, or float
0042                  "is it a unit test?")
0043 
0044 defaultFirstRun    = options.firstRun
0045 defaultLastRun     = options.lastRun
0046 defaultLumisPerRun = options.lumisPerRun
0047 
0048 options.parseArguments()
0049 
0050 if(options.config is None):
0051     configuration = {
0052         "alignments": {
0053             "prompt": {
0054                 "globaltag": "140X_dataRun3_Prompt_v4",
0055                 "conditions": {"TrackerAlignmentRcd": {"tag":"TrackerAlignment_PCL_byRun_v2_express"}}
0056             },
0057             "EOY": {
0058                 "conditions": {"TrackerAlignmentRcd": {"tag":"TrackerAlignment_v24_offline"}}
0059             },
0060             "rereco": {
0061                 "conditions": {"TrackerAlignmentRcd": {"tag":"TrackerAlignment_v29_offline"}}
0062             }
0063         },
0064         "validation": {}
0065     }
0066 else:
0067     # Load configuration from file
0068     with open(options.config) as f:
0069         configuration = json.load(f)
0070 
0071 # The priority for the options is:
0072 # 1. Value specified on command line
0073 # 2. Value in the config
0074 # 3. Default value in the parser
0075 if(options.firstRun != defaultFirstRun):
0076     firstRun = options.firstRun
0077 else:
0078     firstRun = configuration["validation"].get('firstRun', defaultFirstRun)
0079 
0080 if(options.lastRun != defaultLastRun):
0081     lastRun = options.lastRun
0082 else:
0083     lastRun = configuration["validation"].get('lastRun', defaultLastRun)
0084 
0085 if(options.lumisPerRun != defaultLumisPerRun):
0086     lumisPerRun = options.lumisPerRun
0087 else:
0088     lumisPerRun = configuration["validation"].get('lumisPerRun', defaultLumisPerRun)
0089 
0090 process.load("FWCore.MessageService.MessageLogger_cfi")
0091 
0092 # Test that the configuration is complete
0093 if(lastRun < firstRun):
0094     raise ValueError("The last run is smaller than the first")
0095 
0096 process.MessageLogger.cerr.FwkReport.reportEvery = lumisPerRun*1000   # do not clog output with I/O
0097 
0098 if options.unitTest:
0099     numberOfRuns = 10
0100 else:
0101     numberOfRuns = lastRun - firstRun + 1
0102 
0103 print("INFO: Runs: {:d} - {:d} --> number of runs: {:d}".format(firstRun, lastRun, numberOfRuns))
0104 
0105 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.lumisPerRun*numberOfRuns) )
0106 
0107 ####################################################################
0108 # Empty source 
0109 ####################################################################
0110 #import FWCore.PythonUtilities.LumiList as LumiList
0111 #DCSJson='/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions16/13TeV/DCSOnly/json_DCSONLY.txt'
0112 
0113 process.source = cms.Source("EmptySource",
0114                             firstRun = cms.untracked.uint32(firstRun),
0115                             firstLuminosityBlock = cms.untracked.uint32(1),           # probe one LS after the other
0116                             numberEventsInLuminosityBlock = cms.untracked.uint32(1),  # probe one event per LS
0117                             numberEventsInRun = cms.untracked.uint32(lumisPerRun),           # a number of events > the number of LS possible in a real run (5000 s ~ 32 h)
0118                             )
0119 
0120 ####################################################################
0121 # Load and configure analyzer
0122 ####################################################################
0123 bcLabels_ = cms.untracked.vstring("")
0124 bsLabels_ = cms.untracked.vstring("")
0125 
0126 alignments = configuration.get('alignments', None) # NOTE: aligments is plural
0127 if alignments is None:
0128     align = configuration['alignment'] # NOTE: alignment is singular
0129     label = configuration['alignment'].get('label', align['title'].split()[0])
0130     alignments = {label: align}
0131 
0132 for label, align in alignments.items():
0133     if(align.get('globaltag')):
0134         if(len(process.GlobalTag.globaltag.value()) > 0):
0135             if(process.GlobalTag.globaltag.value() != align['globaltag']):
0136                 print('ERROR: another GT has already been specified: "{}". Ignoring GT "{}" from alignment "{}"'.format(
0137                     process.GlobalTag.globaltag.value(), align['globaltag'], label))
0138         else:
0139             # Assign this GlobalTag to the process
0140             process.GlobalTag = GlobalTag(process.GlobalTag, align['globaltag'])
0141             print('INFO: GlobalTag:', process.GlobalTag.globaltag.value())
0142 
0143     conditions = align.get('conditions')
0144     if(conditions is None):
0145         print('INFO: No conditions specified for alignment "{}": skipping'.format(label))
0146         continue
0147 
0148     bcLabels_.append(label)
0149     print(f'TrackerAlignment: {label=} {align=}')
0150 
0151     for record, condition in conditions.items():
0152         condition.setdefault('connect', 'frontier://FrontierProd/CMS_CONDITIONS')
0153         if  (record == 'TrackerAlignmentRcd'):
0154             condition.setdefault('tag', 'Alignments')
0155         elif(record == 'TrackerSurfaceDeformationRcd'):
0156             condition.setdefault('tag', 'Deformations')
0157         elif(record == 'TrackerAlignmentErrorsExtendedRcd'): # Errors should not affect the barycentre
0158             condition.setdefault('tag', 'AlignmentErrors')
0159 
0160         process.GlobalTag.toGet.append(
0161             cms.PSet(
0162                 record  = cms.string(record),
0163                 label   = cms.untracked.string(label),
0164                 tag     = cms.string(condition['tag']),
0165                 connect = cms.string(condition['connect'])
0166             )
0167         )
0168 
0169 
0170 for label, beamspot in configuration['validation'].get("beamspots", {}).items() :
0171     bsLabels_.append(label)
0172     print(f'BeamSpot        : {label=} {beamspot=}')
0173 
0174     process.GlobalTag.toGet.append(
0175         cms.PSet(
0176             record = cms.string("BeamSpotObjectsRcd"),
0177             label = cms.untracked.string(label),
0178             tag = cms.string(beamspot["tag"]),
0179             connect = cms.string(beamspot.get("connect", "frontier://FrontierProd/CMS_CONDITIONS"))
0180         )
0181     )
0182 
0183 
0184 from Alignment.OfflineValidation.pixelBaryCentreAnalyzer_cfi import pixelBaryCentreAnalyzer as _pixelBaryCentreAnalyzer
0185 
0186 process.PixelBaryCentreAnalyzer = _pixelBaryCentreAnalyzer.clone(
0187     usePixelQuality = False,
0188     tkAlignLabels = bcLabels_,
0189     beamSpotLabels = bsLabels_
0190 )
0191 
0192 process.PixelBaryCentreAnalyzerWithPixelQuality = _pixelBaryCentreAnalyzer.clone(
0193     usePixelQuality = True,
0194     tkAlignLabels = bcLabels_,
0195     beamSpotLabels = bsLabels_
0196 )
0197 
0198 ####################################################################
0199 # Output file
0200 ####################################################################
0201 outfile = os.path.join(configuration.get("output", os.getcwd()), 'PixelBaryCentre.root')
0202 
0203 process.TFileService = cms.Service("TFileService",
0204                                    fileName=cms.string(outfile)
0205                                    ) 
0206 print('INFO: output in', outfile)
0207 
0208 # Put module in path:
0209 process.p = cms.Path(process.PixelBaryCentreAnalyzer
0210 #*process.PixelBaryCentreAnalyzerWithPixelQuality
0211 )