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 process.source.lumisToProcess = goodLumiSecs
70 
71 
74 runboundary = config["validation"].get("runboundary", 1)
75 isMultipleRuns=False
76 if(isinstance(runboundary, (list, tuple))):
77  isMultipleRuns=True
78  print("Multiple Runs are selected")
79 if(isMultipleRuns):
80  process.source.firstRun = cms.untracked.uint32(runboundary[0])
81 else:
82  process.source.firstRun = cms.untracked.uint32(runboundary)
83 
84 
87 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(config["validation"].get("maxevents", 1)))
88 
89 
92 process.options = cms.untracked.PSet(
93  wantSummary = cms.untracked.bool(False),
94  Rethrow = cms.untracked.vstring("ProductNotFound"), # make this exception fatal
95  fileMode = cms.untracked.string('NOMERGE'), # no ordering needed, but calls endRun/beginRun etc. at file boundaries
96 )
97 
98 
101 process.load("FWCore.MessageLogger.MessageLogger_cfi")
102 process.MessageLogger.cerr.FwkReport.reportEvery = 1000
103 process.MessageLogger.cout.enableStatistics = cms.untracked.bool(True)
104 
105 
108 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
109 process.load("Configuration.Geometry.GeometryDB_cff")
110 process.load('Configuration.StandardSequences.Services_cff')
111 process.load("Configuration.StandardSequences.MagneticField_cff")
112 
113 
116 import Alignment.CommonAlignment.tools.trackselectionRefitting as trackselRefit
117 process.seqTrackselRefit = trackselRefit.getSequence(
118  process,
119  config["validation"].get("trackcollection", "ALCARECOTkAlCosmicsCTF0T"),
120  isPVValidation = False,
121  TTRHBuilder = config["validation"].get("tthrbuilder", "WithAngleAndTemplate"),
122  usePixelQualityFlag=config["validation"].get("usePixelQualityFlag", True),
123  openMassWindow = False,
124  cosmicsDecoMode = True,
125  cosmicsZeroTesla=config["validation"].get("cosmicsZeroTesla", False),
126  momentumConstraint = None,
127  cosmicTrackSplitting = True,
128  use_d0cut = False
129 )
130 
131 
134 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
135 from Configuration.AlCa.GlobalTag import GlobalTag
136 process.GlobalTag = GlobalTag(process.GlobalTag, config["alignment"].get("globaltag", "124X_dataRun3_Prompt_v10"))
137 
138 
141 if "conditions" in config["alignment"]:
143 
144  for condition in config["alignment"]["conditions"]:
145  setattr(
146  process,
147  "conditionsIn{}".format(condition),
148  poolDBESSource.clone(
149  connect = cms.string(str(config["alignment"]["conditions"][condition]["connect"])),
150  toGet = cms.VPSet(
151  cms.PSet(
152  record = cms.string(str(condition)),
153  tag = cms.string(str(config["alignment"]["conditions"][condition]["tag"]))
154  )
155  )
156  )
157  )
158 
159  setattr(
160  process,
161  "prefer_conditionsIn{}".format(condition),
162  cms.ESPrefer("PoolDBESSource", "conditionsIn{}".format(condition))
163  )
164 
165 
168 
169 process.FittingSmootherRKP5.EstimateCut = -1
170 process.AlignmentTrackSelector.minHitsPerSubDet.inPIXEL = 2
171 # Use compressions settings of TFile
172 # see https://root.cern.ch/root/html534/TFile.html#TFile:SetCompressionSet tings
173 # settings = 100 * algorithm + level
174 # level is from 1 (small) to 9 (large compression)
175 # algo: 1 (ZLIB), 2 (LMZA)
176 # see more about compression & performance: https://root.cern.ch/root/html534/guides/users-guide/InputOutput.html#compression-and-performance
177 compressionSettings = 207
178 process.cosmicValidation = cms.EDAnalyzer(
179  "CosmicSplitterValidation",
180  compressionSettings = cms.untracked.int32(compressionSettings),
181  ifSplitMuons = cms.bool(False),
182  checkIfGolden = cms.bool(False),
183  splitTracks = cms.InputTag("FinalTrackRefitter","","splitter"),
184  splitGlobalMuons = cms.InputTag("muons","","splitter"),
185  originalTracks = cms.InputTag("FirstTrackRefitter","","splitter"),
186  originalGlobalMuons = cms.InputTag("muons","","Rec")
187 )
188 
189 
192 process.TFileService = cms.Service("TFileService",
193  fileName = cms.string("{}/MTSValidation_{}_{}.root".format(config.get("output", os.getcwd()), config["alignment"].get("name", ""), config["validation"].get("IOV", 1.))),
194  closeFileFast = cms.untracked.bool(True),
195  )
196 
197 
200 process.p = cms.Path(process.seqTrackselRefit*process.cosmicValidation)
201 
202 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)