CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
primaryVertexValidationTemplates.py
Go to the documentation of this file.
1 PrimaryVertexValidationTemplate="""
2 import FWCore.ParameterSet.Config as cms
3 import sys
4 
5 isDA = .oO[isda]Oo.
6 isMC = .oO[ismc]Oo.
7 
8 process = cms.Process("PrimaryVertexValidation")
9 
10 ###################################################################
11 # Event source and run selection
12 ###################################################################
13 .oO[datasetDefinition]Oo.
14 
15 ###################################################################
16 # Runs and events
17 ###################################################################
18 runboundary = .oO[runboundary]Oo.
19 process.source.firstRun = cms.untracked.uint32(int(runboundary))
20 
21 ###################################################################
22 # JSON Filtering
23 ###################################################################
24 if isMC:
25  print ">>>>>>>>>> testPVValidation_cfg.py: msg%-i: This is simulation!"
26  runboundary = 1
27 else:
28  print ">>>>>>>>>> testPVValidation_cfg.py: msg%-i: This is real dATA!"
29  if ('.oO[lumilist]Oo.'):
30  print ">>>>>>>>>> testPVValidation_cfg.py: msg%-i: JSON filtering with: .oO[lumilist]Oo. "
31  import FWCore.PythonUtilities.LumiList as LumiList
32  process.source.lumisToProcess = LumiList.LumiList(filename ='.oO[lumilist]Oo.').getVLuminosityBlockRange()
33 
34 ###################################################################
35 # Messages
36 ###################################################################
37 process.load("FWCore.MessageService.MessageLogger_cfi")
38 process.MessageLogger.destinations = ['cout', 'cerr']
39 process.MessageLogger.cerr.FwkReport.reportEvery = 1000
40 
41 ####################################################################
42 # Produce the Transient Track Record in the event
43 ####################################################################
44 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
45 
46 ####################################################################
47 # Get the Magnetic Field
48 ####################################################################
49 process.load("Configuration.StandardSequences..oO[magneticField]Oo._cff")
50 
51 ###################################################################
52 # Geometry load
53 ###################################################################
54 process.load("Configuration.Geometry.GeometryRecoDB_cff")
55 
56 ####################################################################
57 # Get the BeamSpot
58 ####################################################################
59 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
60 
61 ####################################################################
62 # Get the GlogalTag
63 ####################################################################
64 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
65 from Configuration.AlCa.GlobalTag import GlobalTag
66 process.GlobalTag = GlobalTag(process.GlobalTag, '.oO[GlobalTag]Oo.', '')
67 
68 .oO[condLoad]Oo.
69 
70 ####################################################################
71 # Load and Configure event selection
72 ####################################################################
73 process.primaryVertexFilter = cms.EDFilter("VertexSelector",
74  src = cms.InputTag(".oO[VertexCollection]Oo."),
75  cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"),
76  filter = cms.bool(True)
77  )
78 
79 process.noscraping = cms.EDFilter("FilterOutScraping",
80  applyfilter = cms.untracked.bool(True),
81  src = cms.untracked.InputTag(".oO[TrackCollection]Oo."),
82  debugOn = cms.untracked.bool(False),
83  numtrack = cms.untracked.uint32(10),
84  thresh = cms.untracked.double(0.25)
85  )
86 
87 
88 process.load("Alignment.CommonAlignment.filterOutLowPt_cfi")
89 process.filterOutLowPt.src = ".oO[TrackCollection]Oo."
90 process.filterOutLowPt.ptmin = .oO[ptCut]Oo.
91 process.filterOutLowPt.runControl = .oO[runControl]Oo.
92 process.filterOutLowPt.runControlNumber = [runboundary]
93 
94 if isMC:
95  process.goodvertexSkim = cms.Sequence(process.noscraping + process.filterOutLowPt)
96 else:
97  process.goodvertexSkim = cms.Sequence(process.primaryVertexFilter + process.noscraping + process.filterOutLowPt)
98 
99 ####################################################################
100 # Load and Configure Measurement Tracker Event
101 # (would be needed in case NavigationSchool is set != from null
102 ####################################################################
103 #process.load("RecoTracker.MeasurementDet.MeasurementTrackerEventProducer_cfi")
104 #process.MeasurementTrackerEvent.pixelClusterProducer = '.oO[TrackCollection]Oo.'
105 #process.MeasurementTrackerEvent.stripClusterProducer = '.oO[TrackCollection]Oo.'
106 #process.MeasurementTrackerEvent.inactivePixelDetectorLabels = cms.VInputTag()
107 #process.MeasurementTrackerEvent.inactiveStripDetectorLabels = cms.VInputTag()
108 
109 ####################################################################
110 # Load and Configure TrackRefitter
111 ####################################################################
112 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
113 import RecoTracker.TrackProducer.TrackRefitters_cff
114 process.TrackRefitter = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone()
115 process.TrackRefitter.src = ".oO[TrackCollection]Oo."
116 process.TrackRefitter.TrajectoryInEvent = True
117 process.TrackRefitter.NavigationSchool = ''
118 process.TrackRefitter.TTRHBuilder = "WithAngleAndTemplate"
119 
120 ####################################################################
121 # Output file
122 ####################################################################
123 process.TFileService = cms.Service("TFileService",
124  fileName=cms.string(".oO[outputFile]Oo.")
125  )
126 
127 ####################################################################
128 # Deterministic annealing clustering
129 ####################################################################
130 if isDA:
131  print ">>>>>>>>>> testPVValidation_cfg.py: msg%-i: Running DA Algorithm!"
132  process.PVValidation = cms.EDAnalyzer("PrimaryVertexValidation",
133  TrackCollectionTag = cms.InputTag("TrackRefitter"),
134  VertexCollectionTag = cms.InputTag(".oO[VertexCollection]Oo."),
135  Debug = cms.bool(False),
136  storeNtuple = cms.bool(False),
137  useTracksFromRecoVtx = cms.bool(False),
138  isLightNtuple = cms.bool(True),
139  askFirstLayerHit = cms.bool(False),
140  probePt = cms.untracked.double(.oO[ptCut]Oo.),
141  numberOfBins = cms.untracked.int32(.oO[numberOfBins]Oo.),
142  runControl = cms.untracked.bool(.oO[runControl]Oo.),
143  runControlNumber = cms.untracked.vuint32(int(.oO[runboundary]Oo.)),
144 
145  TkFilterParameters = cms.PSet(algorithm=cms.string('filter'),
146  maxNormalizedChi2 = cms.double(5.0), # chi2ndof < 5
147  minPixelLayersWithHits = cms.int32(2), # PX hits > 2
148  minSiliconLayersWithHits = cms.int32(5), # TK hits > 5
149  maxD0Significance = cms.double(5.0), # fake cut (requiring 1 PXB hit)
150  minPt = cms.double(0.0), # better for softish events
151  trackQuality = cms.string("any")
152  ),
153 
154  TkClusParameters=cms.PSet(algorithm=cms.string('DA'),
155  TkDAClusParameters = cms.PSet(coolingFactor = cms.double(0.8), # moderate annealing speed
156  Tmin = cms.double(4.), # end of annealing
157  vertexSize = cms.double(0.05), # ~ resolution / sqrt(Tmin)
158  d0CutOff = cms.double(3.), # downweight high IP tracks
159  dzCutOff = cms.double(4.) # outlier rejection after freeze-out (T<Tmin)
160  )
161  )
162  )
163 
164 ####################################################################
165 # GAP clustering
166 ####################################################################
167 else:
168  print ">>>>>>>>>> testPVValidation_cfg.py: msg%-i: Running GAP Algorithm!"
169  process.PVValidation = cms.EDAnalyzer("PrimaryVertexValidation",
170  TrackCollectionTag = cms.InputTag("TrackRefitter"),
171  VertexCollectionTag = cms.InputTag(".oO[VertexCollection]Oo."),
172  Debug = cms.bool(False),
173  isLightNtuple = cms.bool(True),
174  storeNtuple = cms.bool(False),
175  useTracksFromRecoVtx = cms.bool(False),
176  askFirstLayerHit = cms.bool(False),
177  probePt = cms.untracked.double(.oO[ptCut]Oo.),
178  numberOfBins = cms.untracked.int32(.oO[numberOfBins]Oo.),
179  runControl = cms.untracked.bool(.oO[runControl]Oo.),
180  runControlNumber = cms.untracked.vuint32(int(.oO[runboundary]Oo.)),
181 
182  TkFilterParameters = cms.PSet(algorithm=cms.string('filter'),
183  maxNormalizedChi2 = cms.double(5.0), # chi2ndof < 20
184  minPixelLayersWithHits=cms.int32(2), # PX hits > 2
185  minSiliconLayersWithHits = cms.int32(5), # TK hits > 5
186  maxD0Significance = cms.double(5.0), # fake cut (requiring 1 PXB hit)
187  minPt = cms.double(0.0), # better for softish events
188  trackQuality = cms.string("any")
189  ),
190 
191  TkClusParameters = cms.PSet(algorithm = cms.string('gap'),
192  TkGapClusParameters = cms.PSet(zSeparation = cms.double(0.2) # 0.2 cm max separation betw. clusters
193  )
194  )
195  )
196 
197 ####################################################################
198 # Path
199 ####################################################################
200 process.p = cms.Path(process.goodvertexSkim*
201  process.offlineBeamSpot*
202  #process.MeasurementTrackerEvent*
203  process.TrackRefitter*
204  process.PVValidation)
205 
206 """
207 
208 ####################################################################
209 ####################################################################
210 PVValidationScriptTemplate="""
211 #!/bin/bash
212 source /afs/cern.ch/cms/caf/setup.sh
213 eos='/afs/cern.ch/project/eos/installation/cms/bin/eos.select'
214 
215 echo -----------------------
216 echo Job started at `date`
217 echo -----------------------
218 
219 export theLabel=.oO[alignmentName]Oo.
220 export theDate=.oO[runboundary]Oo.
221 
222 cwd=`pwd`
223 cd .oO[CMSSW_BASE]Oo./src
224 export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
225 eval `scram runtime -sh`
226 cd $cwd
227 
228 rfmkdir -p .oO[datadir]Oo.
229 rfmkdir -p .oO[workingdir]Oo.
230 rfmkdir -p .oO[logdir]Oo.
231 rm -f .oO[logdir]Oo./*.stdout
232 rm -f .oO[logdir]Oo./*.stderr
233 
234 if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
235 then
236  rfmkdir -p .oO[workdir]Oo.
237  rm -f .oO[workdir]Oo./*
238  cd .oO[workdir]Oo.
239 else
240  mkdir -p $cwd/TkAllInOneTool
241  cd $cwd/TkAllInOneTool
242 fi
243 
244 .oO[CommandLine]Oo.
245 
246 ls -lh .
247 
248 $eos mkdir -p /store/caf/user/$USER/.oO[eosdir]Oo./plots/
249 for RootOutputFile in $(ls *root )
250 do
251  xrdcp -f ${RootOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./
252  rfcp ${RootOutputFile} .oO[workingdir]Oo.
253 done
254 
255 cp .oO[Alignment/OfflineValidation]Oo./macros/FitPVResiduals.C .
256 cp .oO[Alignment/OfflineValidation]Oo./macros/CMS_lumi.C .
257 cp .oO[Alignment/OfflineValidation]Oo./macros/CMS_lumi.h .
258 
259  if [[ .oO[pvvalidationreference]Oo. == *store* ]]; then xrdcp -f .oO[pvvalidationreference]Oo. PVValidation_reference.root; else ln -fs .oO[pvvalidationreference]Oo. ./PVValidation_reference.root; fi
260 
261 root -b -q "FitPVResiduals.C(\\"${PWD}/${RootOutputFile}=${theLabel},${PWD}/PVValidation_reference.root=Design simulation\\",true,true,\\"$theDate\\")"
262 
263 mkdir -p .oO[plotsdir]Oo.
264 for PngOutputFile in $(ls *png ); do
265  xrdcp -f ${PngOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
266  rfcp ${PngOutputFile} .oO[plotsdir]Oo.
267 done
268 
269 for PdfOutputFile in $(ls *pdf ); do
270  xrdcp -f ${PdfOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
271  rfcp ${PdfOutputFile} .oO[plotsdir]Oo.
272 done
273 
274 mkdir .oO[plotsdir]Oo./Biases/
275 mkdir .oO[plotsdir]Oo./Biases/dzPhi
276 mkdir .oO[plotsdir]Oo./Biases/dxyPhi
277 mkdir .oO[plotsdir]Oo./Biases/dzEta
278 mkdir .oO[plotsdir]Oo./Biases/dxyEta
279 mkdir .oO[plotsdir]Oo./Fit
280 mkdir .oO[plotsdir]Oo./dxyVsEta
281 mkdir .oO[plotsdir]Oo./dzVsEta
282 mkdir .oO[plotsdir]Oo./dxyVsPhi
283 mkdir .oO[plotsdir]Oo./dzVsPhi
284 mkdir .oO[plotsdir]Oo./dxyVsEtaNorm
285 mkdir .oO[plotsdir]Oo./dzVsEtaNorm
286 mkdir .oO[plotsdir]Oo./dxyVsPhiNorm
287 mkdir .oO[plotsdir]Oo./dzVsPhiNorm
288 
289 mv .oO[plotsdir]Oo./BiasesCanvas* .oO[plotsdir]Oo./Biases/
290 mv .oO[plotsdir]Oo./dzPhiBiasCanvas* .oO[plotsdir]Oo./Biases/dzPhi
291 mv .oO[plotsdir]Oo./dxyPhiBiasCanvas* .oO[plotsdir]Oo./Biases/dxyPhi
292 mv .oO[plotsdir]Oo./dzEtaBiasCanvas* .oO[plotsdir]Oo./Biases/dzEta
293 mv .oO[plotsdir]Oo./dxyEtaBiasCanvas* .oO[plotsdir]Oo./Biases/dxyEta
294 mv .oO[plotsdir]Oo./dzPhiTrendFit* .oO[plotsdir]Oo./Fit
295 mv .oO[plotsdir]Oo./dxyEtaTrendNorm* .oO[plotsdir]Oo./dxyVsEtaNorm
296 mv .oO[plotsdir]Oo./dzEtaTrendNorm* .oO[plotsdir]Oo./dzVsEtaNorm
297 mv .oO[plotsdir]Oo./dxyPhiTrendNorm* .oO[plotsdir]Oo./dxyVsPhiNorm
298 mv .oO[plotsdir]Oo./dzPhiTrendNorm* .oO[plotsdir]Oo./dzVsPhiNorm
299 mv .oO[plotsdir]Oo./dxyEtaTrend* .oO[plotsdir]Oo./dxyVsEta
300 mv .oO[plotsdir]Oo./dzEtaTrend* .oO[plotsdir]Oo./dzVsEta
301 mv .oO[plotsdir]Oo./dxyPhiTrend* .oO[plotsdir]Oo./dxyVsPhi
302 mv .oO[plotsdir]Oo./dzPhiTrend* .oO[plotsdir]Oo./dzVsPhi
303 
304 wget https://raw.githubusercontent.com/mmusich/PVToolScripts/master/PolishedScripts/index.php
305 
306 cp index.php .oO[plotsdir]Oo./Biases/
307 cp index.php .oO[plotsdir]Oo./Biases/dzPhi
308 cp index.php .oO[plotsdir]Oo./Biases/dxyPhi
309 cp index.php .oO[plotsdir]Oo./Biases/dzEta
310 cp index.php .oO[plotsdir]Oo./Biases/dxyEta
311 cp index.php .oO[plotsdir]Oo./Fit
312 cp index.php .oO[plotsdir]Oo./dxyVsEta
313 cp index.php .oO[plotsdir]Oo./dzVsEta
314 cp index.php .oO[plotsdir]Oo./dxyVsPhi
315 cp index.php .oO[plotsdir]Oo./dzVsPhi
316 cp index.php .oO[plotsdir]Oo./dxyVsEtaNorm
317 cp index.php .oO[plotsdir]Oo./dzVsEtaNorm
318 cp index.php .oO[plotsdir]Oo./dxyVsPhiNorm
319 cp index.php .oO[plotsdir]Oo./dzVsPhiNorm
320 
321 
322 echo -----------------------
323 echo Job ended at `date`
324 echo -----------------------
325 
326 """
327 
328 ######################################################################
329 ######################################################################
330 
331 PrimaryVertexPlotExecution="""
332 #make primary vertex validation plots
333 
334 cp .oO[Alignment/OfflineValidation]Oo./macros/CMS_lumi.C .
335 cp .oO[Alignment/OfflineValidation]Oo./macros/CMS_lumi.h .
336 rfcp .oO[PrimaryVertexPlotScriptPath]Oo. .
337 root -x -b -q TkAlPrimaryVertexValidationPlot.C++
338 
339 for PdfOutputFile in $(ls *pdf ); do
340  xrdcp -f ${PdfOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
341  rfcp ${PdfOutputFile} .oO[datadir]Oo.
342 done
343 
344 for PngOutputFile in $(ls *png ); do
345  xrdcp -f ${PngOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
346  rfcp ${PngOutputFile} .oO[datadir]Oo.
347 done
348 
349 """
350 
351 ######################################################################
352 ######################################################################
353 
354 PrimaryVertexPlotTemplate="""
355 /****************************************
356 This can be run directly in root, or you
357  can run ./TkAlMerge.sh in this directory
358 It can be run as is, or adjusted to fit
359  for misalignments or to only make
360  certain plots
361 ****************************************/
362 
363 #include "Alignment/OfflineValidation/macros/FitPVResiduals.C"
364 
365 void TkAlPrimaryVertexValidationPlot()
366 {
367 
368  thePlotLimits->init(.oO[m_dxyPhiMax]Oo.,
369  .oO[m_dzPhiMax]Oo.,
370  .oO[m_dxyEtaMax]Oo.,
371  .oO[m_dzEtaMax]Oo.,
372  .oO[m_dxyPhiNormMax]Oo.,
373  .oO[m_dzPhiNormMax]Oo.,
374  .oO[m_dxyEtaNormMax]Oo.,
375  .oO[m_dzEtaNormMax]Oo.,
376  .oO[w_dxyPhiMax]Oo.,
377  .oO[w_dzPhiMax]Oo.,
378  .oO[w_dxyEtaMax]Oo.,
379  .oO[w_dzEtaMax]Oo.,
380  .oO[w_dxyPhiNormMax]Oo.,
381  .oO[w_dzPhiNormMax]Oo.,
382  .oO[w_dxyEtaNormMax]Oo.,
383  .oO[w_dzEtaNormMax]Oo.
384  );
385 
386  FitPVResiduals(".oO[PrimaryVertexPlotInstantiation]Oo.",.oO[stdResiduals]Oo.,.oO[doMaps]Oo.,"",.oO[autoLimits]Oo.);
387 }
388 """
389 
390