CMS 3D CMS Logo

Zmumu_cfg.py
Go to the documentation of this file.
1 import math
2 import json
3 import os
4 from sys import version_info
5 
6 import FWCore.ParameterSet.Config as cms
7 import FWCore.PythonUtilities.LumiList as LumiList
8 from FWCore.ParameterSet.VarParsing import VarParsing
9 from Alignment.OfflineValidation.TkAlAllInOneTool.utils import _byteify
10 from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultMC_DoubleMuonAlCa_string
11 
12 
15 process = cms.Process("TkAlignmentDiMuonValidation")
16 
17 
20 options = VarParsing()
21 options.register("config", "", VarParsing.multiplicity.singleton, VarParsing.varType.string , "AllInOne config")
22 options.parseArguments()
23 
24 
25 valiMode = "StandAlone"
26 
27 
30 if options.config == "":
31  config = {"validation": {},
32  "alignment": {}}
33 else:
34  with open(options.config, "r") as configFile:
35  if version_info.major == 2:
36  config = _byteify(json.load(configFile, object_hook=_byteify),ignore_dicts=True)
37  else:
38  config = json.load(configFile)
39 
40 
43 readFiles = []
44 
45 if "dataset" in config["validation"]:
46  with open(config["validation"]["dataset"], "r") as datafiles:
47  for fileName in datafiles.readlines():
48  readFiles.append(fileName.replace("\n", ""))
49 else:
50  readFiles = filesDefaultMC_DoubleMuonAlCa_string
51 
52 
55 if "goodlumi" in config["validation"]:
56  if os.path.isfile(config["validation"]["goodlumi"]):
57  goodLumiSecs = cms.untracked.VLuminosityBlockRange(LumiList.LumiList(filename = config["validation"]["goodlumi"]).getCMSSWString().split(','))
58 
59  else:
60  print("Does not exist: {}. Continue without good lumi section file.")
61  goodLumiSecs = cms.untracked.VLuminosityBlockRange()
62 
63 else:
64  goodLumiSecs = cms.untracked.VLuminosityBlockRange()
65 
66 
69 process.source = cms.Source("PoolSource",
70  fileNames = cms.untracked.vstring(readFiles),
71  lumisToProcess = goodLumiSecs,
72  skipEvents = cms.untracked.uint32(0)
73  )
74 process.maxEvents = cms.untracked.PSet(
75  input = cms.untracked.int32(config["validation"].get("maxevents", 2000000))
76 )
77 
78 
81 process.options = cms.untracked.PSet(
82  wantSummary = cms.untracked.bool(False),
83  Rethrow = cms.untracked.vstring("ProductNotFound"),
84  fileMode = cms.untracked.string('NOMERGE'),
85 )
86 
87 
90 process.load("FWCore.MessageService.MessageLogger_cfi")
91 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
92 process.load("Configuration.StandardSequences.Services_cff")
93 process.load("Configuration.StandardSequences.GeometryRecoDB_cff")
94 process.load("Configuration.StandardSequences.MagneticField_cff")
95 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
96 
97 
100 process.load("FWCore.MessageLogger.MessageLogger_cfi")
101 process.MessageLogger.cerr.FwkReport.reportEvery = 1000
102 
103 
106 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
108 process.TrackRefitter = process.TrackRefitterP5.clone(
109  src = config["validation"].get("trackcollection", "ALCARECOTkAlZMuMu"),
110  TrajectoryInEvent = True,
111  TTRHBuilder = config["validation"].get("tthrbuilder", "WithAngleAndTemplate"),
112  NavigationSchool = "",
113 )
114 
115 
118 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
119 from Configuration.AlCa.GlobalTag import GlobalTag
120 process.GlobalTag = GlobalTag(process.GlobalTag, config["alignment"].get("globaltag", "auto:phase1_2024_realistic"))
121 
122 
126 if "conditions" in config["alignment"]:
128  for condition in config["alignment"]["conditions"]:
129  setattr(process, "conditionsIn{}".format(condition), poolDBESSource.clone(
130  connect = cms.string(str(config["alignment"]["conditions"][condition]["connect"])),
131  toGet = cms.VPSet(cms.PSet(record = cms.string(str(condition)),
132  tag = cms.string(str(config["alignment"]["conditions"][condition]["tag"]))
133  )
134  )
135  )
136  )
137 
138  setattr(process, "prefer_conditionsIn{}".format(condition), cms.ESPrefer("PoolDBESSource", "conditionsIn{}".format(condition)))
139 
140 
143 from Alignment.OfflineValidation.diMuonValidation_cfi import diMuonValidation as _diMuonValidation
144 process.DiMuonMassValidation = _diMuonValidation.clone(
145  TkTag = 'TrackRefitter',
146  # mu mu mass
147  Pair_mass_min = 80.,
148  Pair_mass_max = 120.,
149  Pair_mass_nbins = 80,
150  Pair_etaminpos = -2.4,
151  Pair_etamaxpos = 2.4,
152  Pair_etaminneg = -2.4,
153  Pair_etamaxneg = 2.4,
154  # cosTheta CS
155  Variable_CosThetaCS_xmin = -1.,
156  Variable_CosThetaCS_xmax = 1.,
157  Variable_CosThetaCS_nbins = 20,
158  # DeltaEta
159  Variable_DeltaEta_xmin = -4.8,
160  Variable_DeltaEta_xmax = 4.8,
161  Variable_DeltaEta_nbins = 20,
162  # EtaMinus
163  Variable_EtaMinus_xmin = -2.4,
164  Variable_EtaMinus_xmax = 2.4,
165  Variable_EtaMinus_nbins = 12,
166  # EtaPlus
167  Variable_EtaPlus_xmin = -2.4,
168  Variable_EtaPlus_xmax = 2.4,
169  Variable_EtaPlus_nbins = 12,
170  # Phi CS
171  Variable_PhiCS_xmin = -math.pi/2.,
172  Variable_PhiCS_xmax = math.pi/2.,
173  Variable_PhiCS_nbins = 20,
174  # Phi Minus
175  Variable_PhiMinus_xmin = -math.pi,
176  Variable_PhiMinus_xmax = math.pi,
177  Variable_PhiMinus_nbins = 16,
178  # Phi Plus
179  Variable_PhiPlus_xmin = -math.pi,
180  Variable_PhiPlus_xmax = math.pi,
181  Variable_PhiPlus_nbins = 16,
182  # mu mu pT
183  Variable_PairPt_xmin = 0.,
184  Variable_PairPt_xmax = 100.,
185  Variable_PairPt_nbins = 100)
186 
187 
190 if valiMode == "StandAlone":
191  # Output file
192  process.TFileService = cms.Service("TFileService",
193  fileName = cms.string("{}/Zmumu.root".format(config.get("output", os.getcwd()))),
194  closeFileFast = cms.untracked.bool(True),
195  )
196 
197 process.p = cms.Path(process.offlineBeamSpot*process.TrackRefitter*process.DiMuonMassValidation)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def _byteify(data, ignore_dicts=False)
Definition: utils.py:20
#define str(s)