CMS 3D CMS Logo

DiMuonV_cfg.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from fnmatch import fnmatch
3 import FWCore.ParameterSet.Config as cms
4 import FWCore.Utilities.FileUtils as FileUtils
5 from FWCore.ParameterSet.VarParsing import VarParsing
6 from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultMC_DoubleMuon_string
7 
8 import sys
9 import json
10 import os
11 
12 
15 process = cms.Process("DiMuonVertexValidation")
16 
17 
20 options = VarParsing()
21 options.register("config", "", VarParsing.multiplicity.singleton, VarParsing.varType.string , "AllInOne config")
22 
23 options.parseArguments()
24 
25 
28 if options.config == "":
29  config = {"validation": {},
30  "alignment": {}}
31 else:
32  with open(options.config, "r") as configFile:
33  config = json.load(configFile)
34 
35 isMC = config["validation"].get("ismc", True)
36 
37 
40 readFiles = []
41 
42 if "dataset" in config["validation"]:
43  with open(config["validation"]["dataset"], "r") as datafiles:
44  for fileName in datafiles.readlines():
45  readFiles.append(fileName.replace("\n", ""))
46 
47  process.source = cms.Source("PoolSource",
48  fileNames = cms.untracked.vstring(readFiles),
49  skipEvents = cms.untracked.uint32(0))
50 else:
51  process.source = cms.Source("PoolSource",
52  fileNames = cms.untracked.vstring(filesDefaultMC_DoubleMuon_string),
53  skipEvents = cms.untracked.uint32(0))
54 
55 
58 if "goodlumi" in config["validation"]:
59  if os.path.isfile(config["validation"]["goodlumi"]):
60  goodLumiSecs = cms.untracked.VLuminosityBlockRange(LumiList.LumiList(filename = config["validation"]["goodlumi"]).getCMSSWString().split(','))
61 
62  else:
63  print("Does not exist: {}. Continue without good lumi section file.")
64  goodLumiSecs = cms.untracked.VLuminosityBlockRange()
65 
66 else:
67  goodLumiSecs = cms.untracked.VLuminosityBlockRange()
68 
69 if isMC:
70  pass
71 else:
72  process.source.lumisToProcess = goodLumiSecs
73 
74 
77 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(config["validation"].get("maxevents", 100)))
78 
79 
82 process.options = cms.untracked.PSet(
83  wantSummary = cms.untracked.bool(False),
84  Rethrow = cms.untracked.vstring("ProductNotFound"),
85  fileMode = cms.untracked.string('NOMERGE'),
86 )
87 
88 
91 process.load('FWCore.MessageService.MessageLogger_cfi')
92 process.MessageLogger.cerr.enable = False
93 process.MessageLogger.TrackRefitter=dict()
94 process.MessageLogger.PrimaryVertexProducer=dict()
95 process.MessageLogger.DiMuonVertexValidation=dict()
96 process.MessageLogger.DiLeptonHelpCounts=dict()
97 process.MessageLogger.PlotsVsKinematics=dict()
98 process.MessageLogger.cout = cms.untracked.PSet(
99  enable = cms.untracked.bool(True),
100  threshold = cms.untracked.string("INFO"),
101  default = cms.untracked.PSet(limit = cms.untracked.int32(0)),
102  FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1),
103  reportEvery = cms.untracked.int32(100)
104  ),
105  DiMuonVertexValidation = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
106  DiLeptonHelpCounts = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
107  enableStatistics = cms.untracked.bool(True)
108  )
109 
110 
113 process.load('Configuration.StandardSequences.Services_cff')
114 process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
115 process.load('Configuration.StandardSequences.MagneticField_AutoFromDBCurrent_cff')
116 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
117 
118 
121 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
122 process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi')
123 process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi')
124 process.load('TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff')
125 
126 
129 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
130 
131 
134 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
135 from Configuration.AlCa.GlobalTag import GlobalTag
136 # default to remain in sycn with the default input sample
137 process.GlobalTag = GlobalTag(process.GlobalTag, config["alignment"].get("globaltag", "auto:phase1_2022_realistic"))
138 
139 
142 if "conditions" in config["alignment"]:
144 
145  for condition in config["alignment"]["conditions"]:
146  setattr(process, "conditionsIn{}".format(condition), poolDBESSource.clone(
147  connect = cms.string(str(config["alignment"]["conditions"][condition]["connect"])),
148  toGet = cms.VPSet(
149  cms.PSet(
150  record = cms.string(str(condition)),
151  tag = cms.string(str(config["alignment"]["conditions"][condition]["tag"]))
152  )
153  )
154  )
155  )
156 
157  setattr(process, "prefer_conditionsIn{}".format(condition), cms.ESPrefer("PoolDBESSource", "conditionsIn{}".format(condition)))
158 
159 
162 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
164 process.refittedMuons = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone(
165  src = config["validation"].get("muonTrackcollection", "ALCARECOTkAlDiMuon"), # ALCARECOTkAlDiMuon
166  TrajectoryInEvent = True,
167  NavigationSchool = '',
168  TTRHBuilder = config["validation"].get("tthrbuilder", "WithAngleAndTemplate"))
169 
170 
173 process.refittedVtxTracks = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone(
174  src = config["validation"].get("trackcollection", "generalTracks"), # ALCARECOTkAlDiMuonVertexTracks
175  TrajectoryInEvent = True,
176  NavigationSchool = '',
177  TTRHBuilder = config["validation"].get("tthrbuilder", "WithAngleAndTemplate"))
178 
179 
182 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices
183 process.offlinePrimaryVerticesFromRefittedTrks = offlinePrimaryVertices.clone()
184 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel = cms.InputTag("refittedVtxTracks")
185 
186 
189 process.seqRefitting = cms.Sequence(process.offlineBeamSpot +
190  process.refittedMuons +
191  process.refittedVtxTracks +
192  process.offlinePrimaryVerticesFromRefittedTrks)
193 
194 
197 process.TFileService = cms.Service("TFileService",
198  fileName = cms.string("{}/DiMuonVertexValidation.root".format(config.get("output", os.getcwd()))),
199  closeFileFast = cms.untracked.bool(True))
200 
201 
204 from Alignment.OfflineValidation.diMuonVertexValidation_cfi import diMuonVertexValidation
205 process.DiMuonVertexValidation = diMuonVertexValidation.clone(useReco = config["validation"].get("useReco",True),
206  vertices = 'offlinePrimaryVerticesFromRefittedTrks')
207 
208 
211 if (config["validation"].get("useReco",True)):
212  process.DiMuonVertexValidation.muons = 'muons'
213  process.DiMuonVertexValidation.tracks = 'refittedVtxTracks'
214 else:
215  process.DiMuonVertexValidation.muonTracks = cms.InputTag('refittedMuons')
216 
217 
220 process.p = cms.Path(process.seqRefitting +
221  process.offlinePrimaryVerticesFromRefittedTrks +
222  process.DiMuonVertexValidation)
223 
224 print("# Done")
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)