CMS 3D CMS Logo

gather_cfg.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import os
3 import FWCore.ParameterSet.Config as cms
4 
5 # for json support
6 try: # FUTURE: Python 2.6, prior to 2.6 requires simplejson
7  import json
8 except:
9  try:
10  import simplejson as json
11  except:
12  print("Please use lxplus or set an environment (for example crab) with json lib available")
13  sys.exit(1)
14 
15 inputfiles = os.environ["ALIGNMENT_INPUTFILES"].split(" ")
16 iteration = int(os.environ["ALIGNMENT_ITERATION"])
17 jobnumber = int(os.environ["ALIGNMENT_JOBNUMBER"])
18 mapplots = (os.environ["ALIGNMENT_MAPPLOTS"] == "True")
19 segdiffplots = (os.environ["ALIGNMENT_SEGDIFFPLOTS"] == "True")
20 curvatureplots = (os.environ["ALIGNMENT_CURVATUREPLOTS"] == "True")
21 
22 globaltag = os.environ["ALIGNMENT_GLOBALTAG"]
23 inputdb = os.environ["ALIGNMENT_INPUTDB"]
24 trackerconnect = os.environ["ALIGNMENT_TRACKERCONNECT"]
25 trackeralignment = os.environ["ALIGNMENT_TRACKERALIGNMENT"]
26 trackerAPEconnect = os.environ["ALIGNMENT_TRACKERAPECONNECT"]
27 trackerAPE = os.environ["ALIGNMENT_TRACKERAPE"]
28 trackerBowsconnect = os.environ["ALIGNMENT_TRACKERBOWSCONNECT"]
29 trackerBows = os.environ["ALIGNMENT_TRACKERBOWS"]
30 gprcdconnect = os.environ["ALIGNMENT_GPRCDCONNECT"]
31 gprcd = os.environ["ALIGNMENT_GPRCD"]
32 
33 iscosmics = (os.environ["ALIGNMENT_ISCOSMICS"] == "True")
34 station123params = os.environ["ALIGNMENT_STATION123PARAMS"]
35 station4params = os.environ["ALIGNMENT_STATION4PARAMS"]
36 cscparams = os.environ["ALIGNMENT_CSCPARAMS"]
37 minTrackPt = float(os.environ["ALIGNMENT_MINTRACKPT"])
38 maxTrackPt = float(os.environ["ALIGNMENT_MAXTRACKPT"])
39 minTrackP = float(os.environ["ALIGNMENT_MINTRACKP"])
40 maxTrackP = float(os.environ["ALIGNMENT_MAXTRACKP"])
41 minTrackerHits = int(os.environ["ALIGNMENT_MINTRACKERHITS"])
42 maxTrackerRedChi2 = float(os.environ["ALIGNMENT_MAXTRACKERREDCHI2"])
43 allowTIDTEC = (os.environ["ALIGNMENT_ALLOWTIDTEC"] == "True")
44 twoBin = (os.environ["ALIGNMENT_TWOBIN"] == "True")
45 weightAlignment = (os.environ["ALIGNMENT_WEIGHTALIGNMENT"] == "True")
46 minAlignmentHits = int(os.environ["ALIGNMENT_MINALIGNMENTHITS"])
47 combineME11 = (os.environ["ALIGNMENT_COMBINEME11"] == "True")
48 maxEvents = int(os.environ["ALIGNMENT_MAXEVENTS"])
49 skipEvents = int(os.environ["ALIGNMENT_SKIPEVENTS"])
50 maxResSlopeY = float(os.environ["ALIGNMENT_MAXRESSLOPEY"])
51 preFilter = (os.environ["ALIGNMENT_PREFILTER"] == "True")
52 muonCollectionTag = os.environ["ALIGNMENT_MUONCOLLECTIONTAG"]
53 maxDxy = float(os.environ["ALIGNMENT_MAXDXY"])
54 minNCrossedChambers = int(os.environ["ALIGNMENT_MINNCROSSEDCHAMBERS"])
55 
56 # optionally: create ntuples along with tmp files
57 createAlignNtuple = False
58 envNtuple = os.getenv("ALIGNMENT_CREATEALIGNNTUPLE")
59 if envNtuple is not None:
60  if envNtuple=='True': createAlignNtuple = True
61 
62 # optionally: create a ntuple with MapPlot plugin
63 createMapNtuple = False
64 envNtuple = os.getenv("ALIGNMENT_CREATEMAPNTUPLE")
65 if envNtuple is not None:
66  if envNtuple=='True': createMapNtuple = True
67 
68 # optionally do selective DT or CSC alignment
69 doDT = True
70 doCSC = True
71 envDT = os.getenv("ALIGNMENT_DO_DT")
72 envCSC = os.getenv("ALIGNMENT_DO_CSC")
73 if envDT is not None and envCSC is not None:
74  if envDT=='True' and envCSC=='False':
75  doDT = True
76  doCSC = False
77  if envDT=='False' and envCSC=='True':
78  doDT = False
79  doCSC = True
80 
81 # optionally use JSON file for good limi mask
82 good_lumis = []
83 json_file = os.getenv("ALIGNMENT_JSON")
84 #json_file = 'Cert_136035-144114_7TeV_StreamExpress_Collisions10_JSON.txt'
85 if json_file is not None and json_file != '':
86  jsonfile=file(json_file, 'r')
87  jsondict = json.load(jsonfile)
88  runs = sorted(jsondict.keys())
89  for run in runs:
90  blocks = sorted(jsondict[run])
91  prevblock = [-2,-2]
92  for lsrange in blocks:
93  if lsrange[0] == prevblock[1]+1:
94  #print "Run: ",run,"- This lumi starts at ", lsrange[0], " previous ended at ", prevblock[1]+1, " so I should merge"
95  prevblock[1] = lsrange[1]
96  good_lumis[-1] = str("%s:%s-%s:%s" % (run, prevblock[0], run, prevblock[1]))
97  else:
98  good_lumis.append(str("%s:%s-%s:%s" % (run, lsrange[0], run, lsrange[1])))
99  prevblock = lsrange
100 
101 
102 process = cms.Process("GATHER")
103 
104 process.load("Geometry.MuonNumbering.muonNumberingInitialization_cfi")
105 process.load("Geometry.DTGeometry.dtGeometry_cfi")
106 process.load("Geometry.RPCGeometry.rpcGeometry_cfi")
107 process.load("Geometry.CSCGeometry.cscGeometry_cfi")
108 process.load("Geometry.CommonDetUnit.bareGlobalTrackingGeometry_cfi")
109 
110 #add TrackDetectorAssociator lookup maps to the EventSetup
111 process.load("TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff")
114 
115 
116 process.load("Configuration.StandardSequences.Reconstruction_cff")
117 
118 process.MuonNumberingInitialization = cms.ESProducer("MuonNumberingInitialization")
119 process.MuonNumberingRecord = cms.ESSource( "EmptyESSource",
120  recordName = cms.string( "MuonNumberingRecord" ),
121  iovIsRunNotTime = cms.bool( True ),
122  firstValid = cms.vuint32( 1 )
123 )
124 
125 process.load("Configuration.StandardSequences.GeometryDB_cff")
126 process.load('Configuration.StandardSequences.MagneticField_cff')
127 
128 if len(good_lumis)>0:
129  process.source = cms.Source("PoolSource",
130  fileNames = cms.untracked.vstring(*inputfiles),
131  skipEvents = cms.untracked.uint32(skipEvents),
132  lumisToProcess = cms.untracked.VLuminosityBlockRange(*good_lumis))
133 else:
134  process.source = cms.Source("PoolSource",
135  fileNames = cms.untracked.vstring(*inputfiles),
136  skipEvents = cms.untracked.uint32(skipEvents))
137 
138 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(maxEvents))
139 #process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True) )
140 
141 
142 process.MessageLogger = cms.Service("MessageLogger",
143  destinations = cms.untracked.vstring("cout"),
144  cout = cms.untracked.PSet(threshold = cms.untracked.string("ERROR"),
145  ERROR = cms.untracked.PSet(limit = cms.untracked.int32(10))))
146 
147 process.load("Alignment.MuonAlignmentAlgorithms.MuonAlignmentFromReference_cff")
148 process.looper.ParameterBuilder.Selector.alignParams = cms.vstring("MuonDTChambers,%s,stations123" % station123params, "MuonDTChambers,%s,station4" % station4params, "MuonCSCChambers,%s" % cscparams)
149 # TODO : uncomment the line below when AlignmentProducer is updated:
150 #process.looper.muonCollectionTag = cms.InputTag(muonCollectionTag)
151 process.looper.algoConfig.writeTemporaryFile = "alignment%04d.tmp" % jobnumber
152 process.looper.algoConfig.doAlignment = False
153 process.looper.algoConfig.muonCollectionTag = cms.InputTag(muonCollectionTag)
154 process.looper.algoConfig.minTrackPt = minTrackPt
155 process.looper.algoConfig.maxTrackPt = maxTrackPt
156 process.looper.algoConfig.minTrackP = minTrackP
157 process.looper.algoConfig.maxTrackP = maxTrackP
158 process.looper.algoConfig.maxDxy = maxDxy
159 process.looper.algoConfig.minTrackerHits = minTrackerHits
160 process.looper.algoConfig.maxTrackerRedChi2 = maxTrackerRedChi2
161 process.looper.algoConfig.allowTIDTEC = allowTIDTEC
162 process.looper.algoConfig.minNCrossedChambers = minNCrossedChambers
163 process.looper.algoConfig.twoBin = twoBin
164 process.looper.algoConfig.weightAlignment = weightAlignment
165 process.looper.algoConfig.minAlignmentHits = minAlignmentHits
166 process.looper.algoConfig.combineME11 = combineME11
167 process.looper.algoConfig.maxResSlopeY = maxResSlopeY
168 #process.looper.algoConfig.createNtuple = createAlignNtuple
169 process.looper.algoConfig.minDT13Hits = 7
170 process.looper.algoConfig.doDT = doDT
171 process.looper.algoConfig.doCSC = doCSC
172 
173 process.looper.monitorConfig = cms.PSet(monitors = cms.untracked.vstring())
174 
175 if mapplots:
176  process.load("Alignment.CommonAlignmentMonitor.AlignmentMonitorMuonSystemMap1D_cfi")
177  process.looper.monitorConfig.monitors.append("AlignmentMonitorMuonSystemMap1D")
178  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D = process.AlignmentMonitorMuonSystemMap1D
179  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.muonCollectionTag = cms.InputTag(muonCollectionTag)
180  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minTrackPt = minTrackPt
181  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.maxTrackPt = maxTrackPt
182  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minTrackP = minTrackP
183  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.maxTrackP = maxTrackP
184  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.maxDxy = maxDxy
185  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minTrackerHits = minTrackerHits
186  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.maxTrackerRedChi2 = maxTrackerRedChi2
187  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.allowTIDTEC = allowTIDTEC
188  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minNCrossedChambers = process.looper.algoConfig.minNCrossedChambers
189  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minDT13Hits = process.looper.algoConfig.minDT13Hits
190  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minDT2Hits = process.looper.algoConfig.minDT2Hits
191  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.minCSCHits = process.looper.algoConfig.minCSCHits
192  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.doDT = doDT
193  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.doCSC = doCSC
194  process.looper.monitorConfig.AlignmentMonitorMuonSystemMap1D.createNtuple = createMapNtuple
195 
196 if segdiffplots:
197  process.load("Alignment.CommonAlignmentMonitor.AlignmentMonitorSegmentDifferences_cfi")
198  process.looper.monitorConfig.monitors.append("AlignmentMonitorSegmentDifferences")
199  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences = process.AlignmentMonitorSegmentDifferences
200  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.muonCollectionTag = cms.InputTag(muonCollectionTag)
201  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minTrackPt = minTrackPt
202  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minTrackP = minTrackP
203  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.maxDxy = maxDxy
204  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minTrackerHits = minTrackerHits
205  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.maxTrackerRedChi2 = maxTrackerRedChi2
206  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.allowTIDTEC = allowTIDTEC
207  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minNCrossedChambers = process.looper.algoConfig.minNCrossedChambers
208  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minDT13Hits = process.looper.algoConfig.minDT13Hits
209  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minDT2Hits = process.looper.algoConfig.minDT2Hits
210  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.minCSCHits = process.looper.algoConfig.minCSCHits
211  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.doDT = doDT
212  process.looper.monitorConfig.AlignmentMonitorSegmentDifferences.doCSC = doCSC
213 
214 if curvatureplots:
215  process.load("Alignment.CommonAlignmentMonitor.AlignmentMonitorMuonVsCurvature_cfi")
216  process.looper.monitorConfig.monitors.append("AlignmentMonitorMuonVsCurvature")
217  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature = process.AlignmentMonitorMuonVsCurvature
218  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.muonCollectionTag = cms.InputTag(muonCollectionTag)
219  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minTrackPt = minTrackPt
220  #process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minTrackP = minTrackP
221  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.maxDxy = maxDxy
222  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minTrackerHits = minTrackerHits
223  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.maxTrackerRedChi2 = maxTrackerRedChi2
224  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.allowTIDTEC = allowTIDTEC
225  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minNCrossedChambers = process.looper.algoConfig.minNCrossedChambers
226  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minDT13Hits = process.looper.algoConfig.minDT13Hits
227  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minDT2Hits = process.looper.algoConfig.minDT2Hits
228  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.minCSCHits = process.looper.algoConfig.minCSCHits
229  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.doDT = doDT
230  process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.doCSC = doCSC
231 
232 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
233 process.GlobalTag.globaltag = cms.string(globaltag)
234 process.looper.applyDbAlignment = True
235 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")
236 
237 process.load("Alignment.MuonAlignmentAlgorithms.MuonAlignmentPreFilter_cfi")
238 process.MuonAlignmentPreFilter.minTrackPt = minTrackPt
239 process.MuonAlignmentPreFilter.minTrackP = minTrackP
240 process.MuonAlignmentPreFilter.minTrackerHits = minTrackerHits
241 process.MuonAlignmentPreFilter.allowTIDTEC = allowTIDTEC
242 
243 if iscosmics:
244  process.MuonAlignmentPreFilter.tracksTag = cms.InputTag("ALCARECOMuAlGlobalCosmics:GlobalMuon")
245  if preFilter: process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentPreFilter * process.MuonAlignmentFromReferenceGlobalCosmicRefit)
246  else: process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentFromReferenceGlobalCosmicRefit)
247  process.looper.tjTkAssociationMapTag = cms.InputTag("MuonAlignmentFromReferenceGlobalCosmicRefit:Refitted")
248 else:
249  #process.MuonAlignmentPreFilter.tracksTag = cms.InputTag("ALCARECOMuAlCalIsolatedMu:GlobalMuon")
250  process.MuonAlignmentPreFilter.tracksTag = cms.InputTag("globalMuons")
251  process.MuonAlignmentFromReferenceGlobalMuonRefit.Tracks = cms.InputTag("globalMuons")
252  if preFilter: process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentPreFilter * process.MuonAlignmentFromReferenceGlobalMuonRefit)
253  else: process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentFromReferenceGlobalMuonRefit)
254  process.looper.tjTkAssociationMapTag = cms.InputTag("MuonAlignmentFromReferenceGlobalMuonRefit:Refitted")
255 
256 
257 if len(muonCollectionTag) > 0: # use Tracker Muons
258  process.Path = cms.Path(process.offlineBeamSpot * process.newmuons)
259 
260 
261 process.MuonAlignmentFromReferenceInputDB.connect = cms.string("sqlite_file:%s" % inputdb)
262 process.MuonAlignmentFromReferenceInputDB.toGet = cms.VPSet(cms.PSet(record = cms.string("DTAlignmentRcd"), tag = cms.string("DTAlignmentRcd")),
263  cms.PSet(record = cms.string("CSCAlignmentRcd"), tag = cms.string("CSCAlignmentRcd")))
264 
265 if trackerconnect != "":
267  process.TrackerAlignmentInputDB = cms.ESSource("PoolDBESSource",
268  CondDBSetup,
269  connect = cms.string(trackerconnect),
270  toGet = cms.VPSet(cms.PSet(record = cms.string("TrackerAlignmentRcd"), tag = cms.string(trackeralignment))))
271  process.es_prefer_TrackerAlignmentInputDB = cms.ESPrefer("PoolDBESSource", "TrackerAlignmentInputDB")
272 
273 if trackerAPEconnect != "":
275  process.TrackerAlignmentErrorInputDB = cms.ESSource("PoolDBESSource",
276  CondDBSetup,
277  connect = cms.string(trackerAPEconnect),
278  toGet = cms.VPSet(cms.PSet(cms.PSet(record = cms.string("TrackerAlignmentErrorExtendedRcd"), tag = cms.string(trackerAPE)))))
279  process.es_prefer_TrackerAlignmentErrorInputDB = cms.ESPrefer("PoolDBESSource", "TrackerAlignmentErrorInputDB")
280 
281 if trackerBowsconnect != "":
283  process.TrackerSurfaceDeformationInputDB = cms.ESSource("PoolDBESSource",
284  CondDBSetup,
285  connect = cms.string(trackerBowsconnect),
286  toGet = cms.VPSet(cms.PSet(cms.PSet(record = cms.string("TrackerSurfaceDeformationRcd"), tag = cms.string(trackerBows)))))
287  process.es_prefer_TrackerSurfaceDeformationInputDB = cms.ESPrefer("PoolDBESSource", "TrackerSurfaceDeformationInputDB")
288 
289 if gprcdconnect != "":
291  process.GlobalPositionInputDB = cms.ESSource("PoolDBESSource",
292  CondDBSetup,
293  connect = cms.string(gprcdconnect),
294  toGet = cms.VPSet(cms.PSet(record = cms.string("GlobalPositionRcd"), tag = cms.string(gprcd))))
295  process.es_prefer_GlobalPositionInputDB = cms.ESPrefer("PoolDBESSource", "GlobalPositionInputDB")
296 
297 
298 ## the following was needed for Nov 2010 alignment to pick up new lorentz angle and strip conditions for tracker
299 #process.poolDBESSourceLA = cms.ESSource("PoolDBESSource",
300 # BlobStreamerName = cms.untracked.string('TBufferBlobStreamingService'),
301 # DBParameters = cms.PSet(
302 # messageLevel = cms.untracked.int32(0),
303 # authenticationPath = cms.untracked.string('.')
304 # #messageLevel = cms.untracked.int32(2),
305 # #authenticationPath = cms.untracked.string('/path/to/authentication')
306 # ),
307 # timetype = cms.untracked.string('runnumber'),
308 # connect = cms.string('frontier://PromptProd/CMS_COND_31X_STRIP'),
309 # toGet = cms.VPSet(cms.PSet(
310 # record = cms.string('SiStripLorentzAngleRcd'),
311 # tag = cms.string('SiStripLorentzAngle_GR10_v2_offline')
312 # ))
313 #)
314 #process.es_prefer_LA = cms.ESPrefer('PoolDBESSource','poolDBESSourceLA')
315 #
316 #process.poolDBESSourceBP = cms.ESSource("PoolDBESSource",
317 # BlobStreamerName = cms.untracked.string('TBufferBlobStreamingService'),
318 # DBParameters = cms.PSet(
319 # messageLevel = cms.untracked.int32(0),
320 # authenticationPath = cms.untracked.string('.')
321 # #messageLevel = cms.untracked.int32(2),
322 # #authenticationPath = cms.untracked.string('/path/to/authentication')
323 # ),
324 # timetype = cms.untracked.string('runnumber'),
325 # connect = cms.string('frontier://PromptProd/CMS_COND_31X_STRIP'),
326 # toGet = cms.VPSet(cms.PSet(
327 # record = cms.string('SiStripConfObjectRcd'),
328 # tag = cms.string('SiStripShiftAndCrosstalk_GR10_v2_offline')
329 # ))
330 #)
331 #process.es_prefer_BP = cms.ESPrefer('PoolDBESSource','poolDBESSourceBP')
332 
333 
334 process.looper.saveToDB = False
335 process.looper.saveApeToDB = False
336 del process.PoolDBOutputService
337 
338 process.TFileService = cms.Service("TFileService", fileName = cms.string("plotting%03d.root" % jobnumber))
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
#define str(s)
double split
Definition: MVATrainer.cc:139