CMS 3D CMS Logo

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