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  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(
159  process,
160  "prefer_conditionsIn{}".format(condition),
161  cms.ESPrefer("PoolDBESSource", "conditionsIn{}".format(condition))
162  )
163 
164 
167 
168 process.FittingSmootherRKP5.EstimateCut = -1
169 process.AlignmentTrackSelector.minHitsPerSubDet.inPIXEL = 2
170 # Use compressions settings of TFile
171 # see https://root.cern.ch/root/html534/TFile.html#TFile:SetCompressionSet tings
172 # settings = 100 * algorithm + level
173 # level is from 1 (small) to 9 (large compression)
174 # algo: 1 (ZLIB), 2 (LMZA)
175 # see more about compression & performance: https://root.cern.ch/root/html534/guides/users-guide/InputOutput.html#compression-and-performance
176 compressionSettings = 207
177 process.cosmicValidation = cms.EDAnalyzer(
178  "CosmicSplitterValidation",
179  compressionSettings = cms.untracked.int32(compressionSettings),
180  ifSplitMuons = cms.bool(False),
181  checkIfGolden = cms.bool(False),
182  splitTracks = cms.InputTag("FinalTrackRefitter","","splitter"),
183  splitGlobalMuons = cms.InputTag("muons","","splitter"),
184  originalTracks = cms.InputTag("FirstTrackRefitter","","splitter"),
185  originalGlobalMuons = cms.InputTag("muons","","Rec")
186 )
187 
188 
191 process.TFileService = cms.Service("TFileService",
192  fileName = cms.string("{}/MTSValidation_{}_{}.root".format(config.get("output", os.getcwd()), config["alignment"].get("name", ""), config["validation"].get("IOV", 1.))),
193  closeFileFast = cms.untracked.bool(True),
194  )
195 
196 
199 process.p = cms.Path(process.seqTrackselRefit*process.cosmicValidation)
200 
201 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)