CMS 3D CMS Logo

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 = ".oO[ttrhbuilder]Oo."
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  probeEta = cms.untracked.double(.oO[etaCut]Oo.),
142  doBPix = cms.untracked.bool(.oO[doBPix]Oo.),
143  doFPix = cms.untracked.bool(.oO[doFPix]Oo.),
144  numberOfBins = cms.untracked.int32(.oO[numberOfBins]Oo.),
145  runControl = cms.untracked.bool(.oO[runControl]Oo.),
146  runControlNumber = cms.untracked.vuint32(int(.oO[runboundary]Oo.)),
147 
148  TkFilterParameters = cms.PSet(algorithm=cms.string('filter'),
149  maxNormalizedChi2 = cms.double(5.0), # chi2ndof < 5
150  minPixelLayersWithHits = cms.int32(2), # PX hits > 2
151  minSiliconLayersWithHits = cms.int32(5), # TK hits > 5
152  maxD0Significance = cms.double(5.0), # fake cut (requiring 1 PXB hit)
153  minPt = cms.double(0.0), # better for softish events
154  trackQuality = cms.string("any")
155  ),
156 
157  TkClusParameters=cms.PSet(algorithm=cms.string('DA'),
158  TkDAClusParameters = cms.PSet(coolingFactor = cms.double(0.8), # moderate annealing speed
159  Tmin = cms.double(4.), # end of annealing
160  vertexSize = cms.double(0.05), # ~ resolution / sqrt(Tmin)
161  d0CutOff = cms.double(3.), # downweight high IP tracks
162  dzCutOff = cms.double(4.) # outlier rejection after freeze-out (T<Tmin)
163  )
164  )
165  )
166 
167 ####################################################################
168 # GAP clustering
169 ####################################################################
170 else:
171  print ">>>>>>>>>> testPVValidation_cfg.py: msg%-i: Running GAP Algorithm!"
172  process.PVValidation = cms.EDAnalyzer("PrimaryVertexValidation",
173  TrackCollectionTag = cms.InputTag("TrackRefitter"),
174  VertexCollectionTag = cms.InputTag(".oO[VertexCollection]Oo."),
175  Debug = cms.bool(False),
176  isLightNtuple = cms.bool(True),
177  storeNtuple = cms.bool(False),
178  useTracksFromRecoVtx = cms.bool(False),
179  askFirstLayerHit = cms.bool(False),
180  probePt = cms.untracked.double(.oO[ptCut]Oo.),
181  probeEta = cms.untracked.double(.oO[etaCut]Oo.),
182  doBPix = cms.untracked.bool(.oO[doBPix]Oo.),
183  doFPix = cms.untracked.bool(.oO[doFPix]Oo.),
184  numberOfBins = cms.untracked.int32(.oO[numberOfBins]Oo.),
185  runControl = cms.untracked.bool(.oO[runControl]Oo.),
186  runControlNumber = cms.untracked.vuint32(int(.oO[runboundary]Oo.)),
187 
188  TkFilterParameters = cms.PSet(algorithm=cms.string('filter'),
189  maxNormalizedChi2 = cms.double(5.0), # chi2ndof < 20
190  minPixelLayersWithHits=cms.int32(2), # PX hits > 2
191  minSiliconLayersWithHits = cms.int32(5), # TK hits > 5
192  maxD0Significance = cms.double(5.0), # fake cut (requiring 1 PXB hit)
193  minPt = cms.double(0.0), # better for softish events
194  trackQuality = cms.string("any")
195  ),
196 
197  TkClusParameters = cms.PSet(algorithm = cms.string('gap'),
198  TkGapClusParameters = cms.PSet(zSeparation = cms.double(0.2) # 0.2 cm max separation betw. clusters
199  )
200  )
201  )
202 
203 ####################################################################
204 # Path
205 ####################################################################
206 process.p = cms.Path(process.goodvertexSkim*
207  process.offlineBeamSpot*
208  #process.MeasurementTrackerEvent*
209  process.TrackRefitter*
210  process.PVValidation)
211 
212 """
213 
214 ####################################################################
215 ####################################################################
216 PVValidationScriptTemplate="""
217 #!/bin/bash
218 source /afs/cern.ch/cms/caf/setup.sh
219 eos='/afs/cern.ch/project/eos/installation/cms/bin/eos.select'
220 
221 echo -----------------------
222 echo Job started at `date`
223 echo -----------------------
224 
225 export theLabel=.oO[alignmentName]Oo.
226 export theDate=.oO[runboundary]Oo.
227 
228 cwd=`pwd`
229 cd .oO[CMSSW_BASE]Oo./src
230 export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
231 eval `scram runtime -sh`
232 cd $cwd
233 
234 rfmkdir -p .oO[datadir]Oo.
235 rfmkdir -p .oO[workingdir]Oo.
236 rfmkdir -p .oO[logdir]Oo.
237 rm -f .oO[logdir]Oo./*.stdout
238 rm -f .oO[logdir]Oo./*.stderr
239 
240 if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
241 then
242  rfmkdir -p .oO[workdir]Oo.
243  rm -f .oO[workdir]Oo./*
244  cd .oO[workdir]Oo.
245 else
246  mkdir -p $cwd/TkAllInOneTool
247  cd $cwd/TkAllInOneTool
248 fi
249 
250 .oO[CommandLine]Oo.
251 
252 ls -lh .
253 
254 $eos mkdir -p /store/caf/user/$USER/.oO[eosdir]Oo./plots/
255 for RootOutputFile in $(ls *root )
256 do
257  xrdcp -f ${RootOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./
258  rfcp ${RootOutputFile} .oO[workingdir]Oo.
259 done
260 
261 cp .oO[Alignment/OfflineValidation]Oo./macros/FitPVResiduals.C .
262 cp .oO[Alignment/OfflineValidation]Oo./macros/CMS_lumi.C .
263 cp .oO[Alignment/OfflineValidation]Oo./macros/CMS_lumi.h .
264 
265  if [[ .oO[pvvalidationreference]Oo. == *store* ]]; then xrdcp -f .oO[pvvalidationreference]Oo. PVValidation_reference.root; else ln -fs .oO[pvvalidationreference]Oo. ./PVValidation_reference.root; fi
266 
267 root -b -q "FitPVResiduals.C(\\"${PWD}/${RootOutputFile}=${theLabel},${PWD}/PVValidation_reference.root=Design simulation\\",true,true,\\"$theDate\\")"
268 
269 mkdir -p .oO[plotsdir]Oo.
270 for PngOutputFile in $(ls *png ); do
271  xrdcp -f ${PngOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
272  rfcp ${PngOutputFile} .oO[plotsdir]Oo.
273 done
274 
275 for PdfOutputFile in $(ls *pdf ); do
276  xrdcp -f ${PdfOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
277  rfcp ${PdfOutputFile} .oO[plotsdir]Oo.
278 done
279 
280 mkdir .oO[plotsdir]Oo./Biases/
281 mkdir .oO[plotsdir]Oo./Biases/dzPhi
282 mkdir .oO[plotsdir]Oo./Biases/dxyPhi
283 mkdir .oO[plotsdir]Oo./Biases/dzEta
284 mkdir .oO[plotsdir]Oo./Biases/dxyEta
285 mkdir .oO[plotsdir]Oo./Fit
286 mkdir .oO[plotsdir]Oo./dxyVsEta
287 mkdir .oO[plotsdir]Oo./dzVsEta
288 mkdir .oO[plotsdir]Oo./dxyVsPhi
289 mkdir .oO[plotsdir]Oo./dzVsPhi
290 mkdir .oO[plotsdir]Oo./dxyVsEtaNorm
291 mkdir .oO[plotsdir]Oo./dzVsEtaNorm
292 mkdir .oO[plotsdir]Oo./dxyVsPhiNorm
293 mkdir .oO[plotsdir]Oo./dzVsPhiNorm
294 
295 mv .oO[plotsdir]Oo./BiasesCanvas* .oO[plotsdir]Oo./Biases/
296 mv .oO[plotsdir]Oo./dzPhiBiasCanvas* .oO[plotsdir]Oo./Biases/dzPhi
297 mv .oO[plotsdir]Oo./dxyPhiBiasCanvas* .oO[plotsdir]Oo./Biases/dxyPhi
298 mv .oO[plotsdir]Oo./dzEtaBiasCanvas* .oO[plotsdir]Oo./Biases/dzEta
299 mv .oO[plotsdir]Oo./dxyEtaBiasCanvas* .oO[plotsdir]Oo./Biases/dxyEta
300 mv .oO[plotsdir]Oo./dzPhiTrendFit* .oO[plotsdir]Oo./Fit
301 mv .oO[plotsdir]Oo./dxyEtaTrendNorm* .oO[plotsdir]Oo./dxyVsEtaNorm
302 mv .oO[plotsdir]Oo./dzEtaTrendNorm* .oO[plotsdir]Oo./dzVsEtaNorm
303 mv .oO[plotsdir]Oo./dxyPhiTrendNorm* .oO[plotsdir]Oo./dxyVsPhiNorm
304 mv .oO[plotsdir]Oo./dzPhiTrendNorm* .oO[plotsdir]Oo./dzVsPhiNorm
305 mv .oO[plotsdir]Oo./dxyEtaTrend* .oO[plotsdir]Oo./dxyVsEta
306 mv .oO[plotsdir]Oo./dzEtaTrend* .oO[plotsdir]Oo./dzVsEta
307 mv .oO[plotsdir]Oo./dxyPhiTrend* .oO[plotsdir]Oo./dxyVsPhi
308 mv .oO[plotsdir]Oo./dzPhiTrend* .oO[plotsdir]Oo./dzVsPhi
309 
310 wget https://raw.githubusercontent.com/mmusich/PVToolScripts/master/PolishedScripts/index.php
311 
312 cp index.php .oO[plotsdir]Oo./Biases/
313 cp index.php .oO[plotsdir]Oo./Biases/dzPhi
314 cp index.php .oO[plotsdir]Oo./Biases/dxyPhi
315 cp index.php .oO[plotsdir]Oo./Biases/dzEta
316 cp index.php .oO[plotsdir]Oo./Biases/dxyEta
317 cp index.php .oO[plotsdir]Oo./Fit
318 cp index.php .oO[plotsdir]Oo./dxyVsEta
319 cp index.php .oO[plotsdir]Oo./dzVsEta
320 cp index.php .oO[plotsdir]Oo./dxyVsPhi
321 cp index.php .oO[plotsdir]Oo./dzVsPhi
322 cp index.php .oO[plotsdir]Oo./dxyVsEtaNorm
323 cp index.php .oO[plotsdir]Oo./dzVsEtaNorm
324 cp index.php .oO[plotsdir]Oo./dxyVsPhiNorm
325 cp index.php .oO[plotsdir]Oo./dzVsPhiNorm
326 
327 
328 echo -----------------------
329 echo Job ended at `date`
330 echo -----------------------
331 
332 """
333 
334 ######################################################################
335 ######################################################################
336 
337 PrimaryVertexPlotExecution="""
338 #make primary vertex validation plots
339 
340 cp .oO[Alignment/OfflineValidation]Oo./macros/CMS_lumi.C .
341 cp .oO[Alignment/OfflineValidation]Oo./macros/CMS_lumi.h .
342 rfcp .oO[PrimaryVertexPlotScriptPath]Oo. .
343 root -x -b -q TkAlPrimaryVertexValidationPlot.C++
344 
345 for PdfOutputFile in $(ls *pdf ); do
346  xrdcp -f ${PdfOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
347  rfcp ${PdfOutputFile} .oO[datadir]Oo.
348 done
349 
350 for PngOutputFile in $(ls *png ); do
351  xrdcp -f ${PngOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
352  rfcp ${PngOutputFile} .oO[datadir]Oo.
353 done
354 
355 """
356 
357 ######################################################################
358 ######################################################################
359 
360 PrimaryVertexPlotTemplate="""
361 /****************************************
362 This can be run directly in root, or you
363  can run ./TkAlMerge.sh in this directory
364 It can be run as is, or adjusted to fit
365  for misalignments or to only make
366  certain plots
367 ****************************************/
368 
369 #include "Alignment/OfflineValidation/macros/FitPVResiduals.C"
370 
371 void TkAlPrimaryVertexValidationPlot()
372 {
373 
374  // initialize the plot y-axis ranges
375  thePlotLimits->init(.oO[m_dxyPhiMax]Oo., // mean of dxy vs Phi
376  .oO[m_dzPhiMax]Oo., // mean of dz vs Phi
377  .oO[m_dxyEtaMax]Oo., // mean of dxy vs Eta
378  .oO[m_dzEtaMax]Oo., // mean of dz vs Eta
379  .oO[m_dxyPhiNormMax]Oo., // mean of dxy vs Phi (norm)
380  .oO[m_dzPhiNormMax]Oo., // mean of dz vs Phi (norm)
381  .oO[m_dxyEtaNormMax]Oo., // mean of dxy vs Eta (norm)
382  .oO[m_dzEtaNormMax]Oo., // mean of dz vs Eta (norm)
383  .oO[w_dxyPhiMax]Oo., // width of dxy vs Phi
384  .oO[w_dzPhiMax]Oo., // width of dz vs Phi
385  .oO[w_dxyEtaMax]Oo., // width of dxy vs Eta
386  .oO[w_dzEtaMax]Oo., // width of dz vs Eta
387  .oO[w_dxyPhiNormMax]Oo., // width of dxy vs Phi (norm)
388  .oO[w_dzPhiNormMax]Oo., // width of dz vs Phi (norm)
389  .oO[w_dxyEtaNormMax]Oo., // width of dxy vs Eta (norm)
390  .oO[w_dzEtaNormMax]Oo. // width of dz vs Eta (norm)
391  );
392 
393  .oO[PrimaryVertexPlotInstantiation]Oo.
394  FitPVResiduals("",.oO[stdResiduals]Oo.,.oO[doMaps]Oo.,"",.oO[autoLimits]Oo.);
395 }
396 """
397 
398