CMS 3D CMS Logo

MTS_cfg.py
Go to the documentation of this file.
1 import json
2 import yaml
3 import os
4 import FWCore.ParameterSet.Config as cms
5 import FWCore.PythonUtilities.LumiList as LumiList
6 from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultData_Cosmics_string
7 from FWCore.ParameterSet.VarParsing import VarParsing
8 from Alignment.OfflineValidation.TkAlAllInOneTool.utils import _byteify
9 import pdb
10 
11 
14 process = cms.Process("splitter")
15 
16 
19 options = VarParsing()
20 options.register("config", "", VarParsing.multiplicity.singleton, VarParsing.varType.string , "AllInOne config")
21 options.parseArguments()
22 
23 
26 if options.config == "":
27  config = {"validation": {},
28  "alignment": {}}
29 else:
30  with open(options.config, "r") as configFile:
31  if options.config.endswith(".json"):
32  config = json.load(configFile)
33  elif options.config.endswith(".yaml"):
34  config = yaml.safe_load(configFile)
35 
36 
39 readFiles = []
40 
41 if "dataset" in config["validation"]:
42  with open(config["validation"]["dataset"], "r") as datafiles:
43  for fileName in datafiles.readlines():
44  readFiles.append(fileName.replace("\n", ""))
45 
46  process.source = cms.Source("PoolSource",
47  fileNames = cms.untracked.vstring(readFiles),
48  skipEvents = cms.untracked.uint32(0)
49  )
50 else:
51  print(">>>>>>>>>> MTS_cfg.py: msg%-i: dataset not specified! Loading default file -> filesDefaultData_Cosmics_string!")
52  process.source = cms.Source("PoolSource",
53  fileNames = cms.untracked.vstring(filesDefaultData_Cosmics_string),
54  skipEvents = cms.untracked.uint32(0)
55  )
56 
57 
60 if "goodlumi" in config["validation"]:
61  if os.path.isfile(config["validation"]["goodlumi"]):
62  goodLumiSecs = cms.untracked.VLuminosityBlockRange(LumiList.LumiList(filename = config["validation"]["goodlumi"]).getCMSSWString().split(','))
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 
73 runboundary = config["validation"].get("runboundary", 1)
74 isMultipleRuns=False
75 if(isinstance(runboundary, (list, tuple))):
76  isMultipleRuns=True
77  print("Multiple Runs are selected")
78 if(isMultipleRuns):
79  process.source.firstRun = cms.untracked.uint32(runboundary[0])
80 else:
81  process.source.firstRun = cms.untracked.uint32(runboundary)
82 
83 
86 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(config["validation"].get("maxevents", 1)))
87 
88 
91 process.options = cms.untracked.PSet(
92  wantSummary = cms.untracked.bool(False),
93  Rethrow = cms.untracked.vstring("ProductNotFound"), # make this exception fatal
94  fileMode = cms.untracked.string('NOMERGE'), # no ordering needed, but calls endRun/beginRun etc. at file boundaries
95 )
96 
97 
100 process.load("FWCore.MessageLogger.MessageLogger_cfi")
101 process.MessageLogger.cerr.FwkReport.reportEvery = 1000
102 process.MessageLogger.cout.enableStatistics = cms.untracked.bool(True)
103 
104 
107 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
108 process.load("Configuration.Geometry.GeometryDB_cff")
109 process.load('Configuration.StandardSequences.Services_cff')
110 process.load("Configuration.StandardSequences.MagneticField_cff")
111 
112 
115 import Alignment.CommonAlignment.tools.trackselectionRefitting as trackselRefit
116 process.seqTrackselRefit = trackselRefit.getSequence(
117  process,
118  config["validation"].get("trackcollection", "ALCARECOTkAlCosmicsCTF0T"),
119  isPVValidation = False,
120  TTRHBuilder = config["validation"].get("tthrbuilder", "WithAngleAndTemplate"),
121  usePixelQualityFlag=config["validation"].get("usePixelQualityFlag", True),
122  openMassWindow = False,
123  cosmicsDecoMode = True,
124  cosmicsZeroTesla=config["validation"].get("cosmicsZeroTesla", False),
125  momentumConstraint = None,
126  cosmicTrackSplitting = True,
127  use_d0cut = False
128 )
129 
130 
133 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
134 from Configuration.AlCa.GlobalTag import GlobalTag
135 process.GlobalTag = GlobalTag(process.GlobalTag, config["alignment"].get("globaltag", "124X_dataRun3_Prompt_v10"))
136 
137 
140 if "conditions" in config["alignment"]:
142 
143  for condition in config["alignment"]["conditions"]:
144  setattr(
145  process,
146  "conditionsIn{}".format(condition),
147  poolDBESSource.clone(
148  # FIXME%START
149  connect = cms.string("sqlite_file:" + str(config["alignment"]["conditions"][condition]["connect"]) if "alignments_MP.db" in str(config["alignment"]["conditions"][condition]["connect"]) else str(config["alignment"]["conditions"][condition]["connect"])),
150  #FIXME%END
151  toGet = cms.VPSet(
152  cms.PSet(
153  record = cms.string(str(condition)),
154  tag = cms.string(str(config["alignment"]["conditions"][condition]["tag"]))
155  )
156  )
157  )
158  )
159 
160  setattr(
161  process,
162  "prefer_conditionsIn{}".format(condition),
163  cms.ESPrefer("PoolDBESSource", "conditionsIn{}".format(condition))
164  )
165 
166 
169 
170 process.FittingSmootherRKP5.EstimateCut = -1
171 process.AlignmentTrackSelector.minHitsPerSubDet.inPIXEL = 2
172 # Use compressions settings of TFile
173 # see https://root.cern.ch/root/html534/TFile.html#TFile:SetCompressionSet tings
174 # settings = 100 * algorithm + level
175 # level is from 1 (small) to 9 (large compression)
176 # algo: 1 (ZLIB), 2 (LMZA)
177 # see more about compression & performance: https://root.cern.ch/root/html534/guides/users-guide/InputOutput.html#compression-and-performance
178 compressionSettings = 207
179 process.cosmicValidation = cms.EDAnalyzer(
180  "CosmicSplitterValidation",
181  compressionSettings = cms.untracked.int32(compressionSettings),
182  ifSplitMuons = cms.bool(False),
183  checkIfGolden = cms.bool(False),
184  splitTracks = cms.InputTag("FinalTrackRefitter","","splitter"),
185  splitGlobalMuons = cms.InputTag("muons","","splitter"),
186  originalTracks = cms.InputTag("FirstTrackRefitter","","splitter"),
187  originalGlobalMuons = cms.InputTag("muons","","Rec")
188 )
189 
190 
193 process.TFileService = cms.Service("TFileService",
194  fileName = cms.string("{}/MTSValidation_{}_{}.root".format(config.get("output", os.getcwd()), config["alignment"].get("name", ""), config["validation"].get("IOV", 1.))),
195  closeFileFast = cms.untracked.bool(True),
196  )
197 
198 
201 process.p = cms.Path(process.seqTrackselRefit*process.cosmicValidation)
202 
203 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)