CMS 3D CMS Logo

PixelBaryCentreAnalyzer_cfg.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 import os
3 import json
4 
5 process = cms.Process("READ")
6 
7 # import of standard configurations
8 process.load('Configuration.StandardSequences.Services_cff')
9 process.load('Configuration.EventContent.EventContent_cff')
10 process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
11 process.load('Configuration.StandardSequences.MagneticField_AutoFromDBCurrent_cff')
12 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
13 
14 import FWCore.ParameterSet.VarParsing as VarParsing
15 from Configuration.AlCa.GlobalTag import GlobalTag
16 
18 options.register('lumisPerRun',
19  1,
20  VarParsing.VarParsing.multiplicity.singleton,
21  VarParsing.VarParsing.varType.int,
22  "the number of lumis to be processed per-run.")
23 options.register('firstRun',
24  290550,
25  VarParsing.VarParsing.multiplicity.singleton,
26  VarParsing.VarParsing.varType.int,
27  "the first run number be processed")
28 options.register('lastRun',
29  325175,
30  VarParsing.VarParsing.multiplicity.singleton,
31  VarParsing.VarParsing.varType.int,
32  "the run number to stop at")
33 options.register('config',
34  default = None,
35  mult = VarParsing.VarParsing.multiplicity.singleton,
36  mytype = VarParsing.VarParsing.varType.string,
37  info = 'JSON config with information about the GT, Alignments, etc.')
38 options.register('unitTest',
39  False, # default value
40  VarParsing.VarParsing.multiplicity.singleton, # singleton or list
41  VarParsing.VarParsing.varType.bool, # string, int, or float
42  "is it a unit test?")
43 
44 defaultFirstRun = options.firstRun
45 defaultLastRun = options.lastRun
46 defaultLumisPerRun = options.lumisPerRun
47 
48 options.parseArguments()
49 
50 if(options.config is None):
51  configuration = {
52  "alignments": {
53  "prompt": {
54  "globaltag": "140X_dataRun3_Prompt_v4",
55  "conditions": {"TrackerAlignmentRcd": {"tag":"TrackerAlignment_PCL_byRun_v2_express"}}
56  },
57  "EOY": {
58  "conditions": {"TrackerAlignmentRcd": {"tag":"TrackerAlignment_v24_offline"}}
59  },
60  "rereco": {
61  "conditions": {"TrackerAlignmentRcd": {"tag":"TrackerAlignment_v29_offline"}}
62  }
63  },
64  "validation": {}
65  }
66 else:
67  # Load configuration from file
68  with open(options.config) as f:
69  configuration = json.load(f)
70 
71 # The priority for the options is:
72 # 1. Value specified on command line
73 # 2. Value in the config
74 # 3. Default value in the parser
75 if(options.firstRun != defaultFirstRun):
76  firstRun = options.firstRun
77 else:
78  firstRun = configuration["validation"].get('firstRun', defaultFirstRun)
79 
80 if(options.lastRun != defaultLastRun):
81  lastRun = options.lastRun
82 else:
83  lastRun = configuration["validation"].get('lastRun', defaultLastRun)
84 
85 if(options.lumisPerRun != defaultLumisPerRun):
86  lumisPerRun = options.lumisPerRun
87 else:
88  lumisPerRun = configuration["validation"].get('lumisPerRun', defaultLumisPerRun)
89 
90 process.load("FWCore.MessageService.MessageLogger_cfi")
91 
92 # Test that the configuration is complete
93 if(lastRun < firstRun):
94  raise ValueError("The last run is smaller than the first")
95 
96 process.MessageLogger.cerr.FwkReport.reportEvery = lumisPerRun*1000 # do not clog output with I/O
97 
98 if options.unitTest:
99  numberOfRuns = 10
100 else:
101  numberOfRuns = lastRun - firstRun + 1
102 
103 print("INFO: Runs: {:d} - {:d} --> number of runs: {:d}".format(firstRun, lastRun, numberOfRuns))
104 
105 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.lumisPerRun*numberOfRuns) )
106 
107 
112 
113 process.source = cms.Source("EmptySource",
114  firstRun = cms.untracked.uint32(firstRun),
115  firstLuminosityBlock = cms.untracked.uint32(1), # probe one LS after the other
116  numberEventsInLuminosityBlock = cms.untracked.uint32(1), # probe one event per LS
117  numberEventsInRun = cms.untracked.uint32(lumisPerRun), # a number of events > the number of LS possible in a real run (5000 s ~ 32 h)
118  )
119 
120 
123 bcLabels_ = cms.untracked.vstring("")
124 bsLabels_ = cms.untracked.vstring("")
125 
126 alignments = configuration.get('alignments', None) # NOTE: aligments is plural
127 if alignments is None:
128  align = configuration['alignment'] # NOTE: alignment is singular
129  label = configuration['alignment'].get('label', align['title'].split()[0])
130  alignments = {label: align}
131 
132 for label, align in alignments.items():
133  if(align.get('globaltag')):
134  if(len(process.GlobalTag.globaltag.value()) > 0):
135  if(process.GlobalTag.globaltag.value() != align['globaltag']):
136  print('ERROR: another GT has already been specified: "{}". Ignoring GT "{}" from alignment "{}"'.format(
137  process.GlobalTag.globaltag.value(), align['globaltag'], label))
138  else:
139  # Assign this GlobalTag to the process
140  process.GlobalTag = GlobalTag(process.GlobalTag, align['globaltag'])
141  print('INFO: GlobalTag:', process.GlobalTag.globaltag.value())
142 
143  conditions = align.get('conditions')
144  if(conditions is None):
145  print('INFO: No conditions specified for alignment "{}": skipping'.format(label))
146  continue
147 
148  bcLabels_.append(label)
149  print(f'TrackerAlignment: {label=} {align=}')
150 
151  for record, condition in conditions.items():
152  condition.setdefault('connect', 'frontier://FrontierProd/CMS_CONDITIONS')
153  if (record == 'TrackerAlignmentRcd'):
154  condition.setdefault('tag', 'Alignments')
155  elif(record == 'TrackerSurfaceDeformationRcd'):
156  condition.setdefault('tag', 'Deformations')
157  elif(record == 'TrackerAlignmentErrorsExtendedRcd'): # Errors should not affect the barycentre
158  condition.setdefault('tag', 'AlignmentErrors')
159 
160  process.GlobalTag.toGet.append(
161  cms.PSet(
162  record = cms.string(record),
163  label = cms.untracked.string(label),
164  tag = cms.string(condition['tag']),
165  connect = cms.string(condition['connect'])
166  )
167  )
168 
169 
170 for label, beamspot in configuration['validation'].get("beamspots", {}).items() :
171  bsLabels_.append(label)
172  print(f'BeamSpot : {label=} {beamspot=}')
173 
174  process.GlobalTag.toGet.append(
175  cms.PSet(
176  record = cms.string("BeamSpotObjectsRcd"),
177  label = cms.untracked.string(label),
178  tag = cms.string(beamspot["tag"]),
179  connect = cms.string(beamspot.get("connect", "frontier://FrontierProd/CMS_CONDITIONS"))
180  )
181  )
182 
183 
184 from Alignment.OfflineValidation.pixelBaryCentreAnalyzer_cfi import pixelBaryCentreAnalyzer as _pixelBaryCentreAnalyzer
185 
186 process.PixelBaryCentreAnalyzer = _pixelBaryCentreAnalyzer.clone(
187  usePixelQuality = False,
188  tkAlignLabels = bcLabels_,
189  beamSpotLabels = bsLabels_
190 )
191 
192 process.PixelBaryCentreAnalyzerWithPixelQuality = _pixelBaryCentreAnalyzer.clone(
193  usePixelQuality = True,
194  tkAlignLabels = bcLabels_,
195  beamSpotLabels = bsLabels_
196 )
197 
198 
201 outfile = os.path.join(configuration.get("output", os.getcwd()), 'PixelBaryCentre.root')
202 
203 process.TFileService = cms.Service("TFileService",
204  fileName=cms.string(outfile)
205  )
206 print('INFO: output in', outfile)
207 
208 # Put module in path:
209 process.p = cms.Path(process.PixelBaryCentreAnalyzer
210 #*process.PixelBaryCentreAnalyzerWithPixelQuality
211 )
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
if(threadIdxLocalY==0 &&threadIdxLocalX==0)