CMS 3D CMS Logo

PV_cfg.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 import FWCore.PythonUtilities.LumiList as LumiList
3 from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultData_MinBias2018B
4 
5 from FWCore.ParameterSet.VarParsing import VarParsing
6 
7 from Alignment.OfflineValidation.TkAlAllInOneTool.utils import _byteify
8 import json
9 import os
10 
11 
12 process = cms.Process("PrimaryVertexValidation")
13 
14 
15 options = VarParsing()
16 options.register("config", "", VarParsing.multiplicity.singleton, VarParsing.varType.string , "AllInOne config")
17 
18 options.parseArguments()
19 
20 
21 if options.config == "":
22  config = {"validation": {},
23  "alignment": {}}
24 else:
25  with open(options.config, "r") as configFile:
26  config = json.load(configFile)
27 
28 isDA = config["validation"].get("isda", True)
29 isMC = config["validation"].get("ismc", True)
30 
31 runboundary = config["validation"].get("runboundary", 1)
32 
33 
34 readFiles = []
35 
36 if "dataset" in config["validation"]:
37  with open(config["validation"]["dataset"], "r") as datafiles:
38  for fileName in datafiles.readlines():
39  readFiles.append(fileName.replace("\n", ""))
40 
41  process.source = cms.Source("PoolSource",
42  fileNames = cms.untracked.vstring(readFiles),
43  skipEvents = cms.untracked.uint32(0)
44  )
45 else:
46  print(">>>>>>>>>> PV_cfg.py: msg%-i: config not specified! Loading default dataset -> filesDefaultData_MinBias2018B!")
47  process.source = cms.Source("PoolSource",
48  fileNames = filesDefaultData_MinBias2018B,
49  skipEvents = cms.untracked.uint32(0)
50  )
51 
52 
53 if "goodlumi" in config["validation"]:
54  if os.path.isfile(config["validation"]["goodlumi"]):
55  goodLumiSecs = cms.untracked.VLuminosityBlockRange(LumiList.LumiList(filename = config["validation"]["goodlumi"]).getCMSSWString().split(','))
56 
57  else:
58  print("Does not exist: {}. Continue without good lumi section file.")
59  goodLumiSecs = cms.untracked.VLuminosityBlockRange()
60 
61 else:
62  goodLumiSecs = cms.untracked.VLuminosityBlockRange()
63 
64 if isMC:
65  print(">>>>>>>>>> PV_cfg.py: msg%-i: This is simulation!")
66  runboundary = 1
67 else:
68  process.source.lumisToProcess = goodLumiSecs
69 
70 isMultipleRuns=False
71 if(isinstance(runboundary, (list, tuple))):
72  isMultipleRuns=True
73  print("Multiple Runs are selected")
74 if(isMultipleRuns):
75  process.source.firstRun = cms.untracked.uint32(runboundary[0])
76 else:
77  process.source.firstRun = cms.untracked.uint32(runboundary)
78 
79 
80 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(config["validation"].get("maxevents", 1)))
81 
82 
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 process.load("FWCore.MessageLogger.MessageLogger_cfi")
90 process.MessageLogger = cms.Service("MessageLogger",
91  destinations = cms.untracked.vstring('cerr'),
92  cerr = cms.untracked.PSet(threshold = cms.untracked.string('INFO'))
93  )
94 
95 
96 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
97 process.load("Configuration.Geometry.GeometryRecoDB_cff") #or process.load("Configuration.Geometry.GeometryDB_cff")?????
98 process.load('Configuration.StandardSequences.Services_cff')
99 process.load("Configuration.StandardSequences.MagneticField_cff")
100 
101 
104 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
105 
106 
109 import Alignment.CommonAlignment.tools.trackselectionRefitting as trackselRefit
110 process.seqTrackselRefit = trackselRefit.getSequence(process,
111  config["validation"].get("trackcollection", "ALCARECOTkAlMinBias"),
112  isPVValidation=True,
113  TTRHBuilder=config["validation"].get("tthrbuilder", "WithAngleAndTemplate"),
114  usePixelQualityFlag=config["validation"].get("usePixelQualityFlag", True),
115  openMassWindow=False,
116  cosmicsDecoMode=True,
117  cosmicsZeroTesla=config["validation"].get("cosmicsZeroTesla", False),
118  momentumConstraint=None,
119  cosmicTrackSplitting=False,
120  use_d0cut=False,
121  )
122 
123 #Global tag
124 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
125 from Configuration.AlCa.GlobalTag import GlobalTag
126 process.GlobalTag = GlobalTag(process.GlobalTag, config["alignment"].get("globaltag", "auto:phase1_2017_realistic"))
127 
128 
129 if "conditions" in config["alignment"]:
131 
132  for condition in config["alignment"]["conditions"]:
133  setattr(process, "conditionsIn{}".format(condition), poolDBESSource.clone(
134  connect = cms.string(str(config["alignment"]["conditions"][condition]["connect"])),
135  toGet = cms.VPSet(
136  cms.PSet(
137  record = cms.string(str(condition)),
138  tag = cms.string(str(config["alignment"]["conditions"][condition]["tag"]))
139  )
140  )
141  )
142  )
143 
144  setattr(process, "prefer_conditionsIn{}".format(condition), cms.ESPrefer("PoolDBESSource", "conditionsIn{}".format(condition)))
145 
146 
149 process.primaryVertexFilter = cms.EDFilter("VertexSelector",
150  src = cms.InputTag(config["validation"].get("vertexcollection", "offlinePrimaryVertices")),
151  cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"),
152  filter = cms.bool(True)
153  )
154 
155 process.noscraping = cms.EDFilter("FilterOutScraping",
156  applyfilter = cms.untracked.bool(True),
157  src = cms.untracked.InputTag(config["validation"].get("trackcollection", "ALCARECOTkAlMinBias")),
158  debugOn = cms.untracked.bool(False),
159  numtrack = cms.untracked.uint32(10),
160  thresh = cms.untracked.double(0.25)
161  )
162 
163 process.load("Alignment.CommonAlignment.filterOutLowPt_cfi")
164 process.filterOutLowPt.src = cms.untracked.InputTag(config["validation"].get("trackcollection", "ALCARECOTkAlMinBias"))
165 process.filterOutLowPt.ptmin = cms.untracked.double(config["validation"].get("ptCut", 3.))
166 process.filterOutLowPt.runControl = False
167 if(isMultipleRuns):
168  process.filterOutLowPt.runControlNumber.extend((runboundary))
169 else:
170  process.filterOutLowPt.runControlNumber = [runboundary]
171 
172 if isMC:
173  process.goodvertexSkim = cms.Sequence(process.noscraping + process.filterOutLowPt)
174 else:
175  process.goodvertexSkim = cms.Sequence(process.primaryVertexFilter + process.noscraping + process.filterOutLowPt)
176 
177 
178 
181 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices
182 
183 FilteringParams = offlinePrimaryVertices.TkFilterParameters.clone(
184  maxNormalizedChi2 = 5.0, # chi2ndof < 5
185  maxD0Significance = 5.0, # fake cut (requiring 1 PXB hit)
186  maxEta = 5.0, # as per recommendation in PR #18330
187 )
188 
189 
190 from RecoVertex.PrimaryVertexProducer.TkClusParameters_cff import DA_vectParameters
191 DAClusterizationParams = DA_vectParameters.clone()
192 
193 GapClusterizationParams = cms.PSet(algorithm = cms.string('gap'),
194  TkGapClusParameters = cms.PSet(zSeparation = cms.double(0.2)) # 0.2 cm max separation betw. clusters
195  )
196 
197 
201  if da:
202  print(">>>>>>>>>> testPVValidation_cfg.py: msg%-i: Running DA Algorithm!")
203  return DAClusterizationParams
204  else:
205  print(">>>>>>>>>> testPVValidation_cfg.py: msg%-i: Running GAP Algorithm!")
206  return GapClusterizationParams
207 
208 
211 process.PVValidation = cms.EDAnalyzer("PrimaryVertexValidation",
212  TrackCollectionTag = cms.InputTag("FinalTrackRefitter"),
213  VertexCollectionTag = cms.InputTag(config["validation"].get("vertexcollection", "offlinePrimaryVertices")),
214  Debug = cms.bool(False),
215  storeNtuple = cms.bool(False),
216  useTracksFromRecoVtx = cms.bool(False),
217  isLightNtuple = cms.bool(True),
218  askFirstLayerHit = cms.bool(False),
219  forceBeamSpot = cms.untracked.bool(config["validation"].get("forceBeamSpot", False)),
220  probePt = cms.untracked.double(config["validation"].get("ptCut", 3)),
221  probeEta = cms.untracked.double(config["validation"].get("etaCut", 2.5)),
222  minPt = cms.untracked.double(config["validation"].get("minPt", 1.)),
223  maxPt = cms.untracked.double(config["validation"].get("maxPt", 30.)),
224  doBPix = cms.untracked.bool(config["validation"].get("doBPix", True)),
225  doFPix = cms.untracked.bool(config["validation"].get("doFPix", True)),
226  numberOfBins = cms.untracked.int32(config["validation"].get("numberOfBins", 48)),
227  runControl = cms.untracked.bool(config["validation"].get("runControl", False)),
228  runControlNumber = cms.untracked.vuint32(runboundary),
229  TkFilterParameters = FilteringParams,
230  TkClusParameters = switchClusterizerParameters(isDA)
231  )
232 
233 
236 process.TFileService = cms.Service("TFileService",
237  fileName = cms.string("{}/PVValidation_{}_{}.root".format(config.get("output", os.getcwd()), config["alignment"].get("name", ""), config["validation"].get("IOV", 1.))),
238  closeFileFast = cms.untracked.bool(True),
239  )
240 
241 
244 process.p = cms.Path(process.goodvertexSkim*process.seqTrackselRefit*process.PVValidation)
245 
246 print("Done")
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)
def switchClusterizerParameters(da)
Deterministic annealing clustering or Gap clustering.
Definition: PV_cfg.py:200