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