CMS 3D CMS Logo

primaryVertexValidationTemplates.py
Go to the documentation of this file.
1 PrimaryVertexValidationTemplate="""
2 isDA = .oO[isda]Oo.
3 isMC = .oO[ismc]Oo.
4 
5 ###################################################################
6 # Runs and events
7 ###################################################################
8 runboundary = .oO[runboundary]Oo.
9 isMultipleRuns=False
10 if(isinstance(runboundary, (list, tuple))):
11  isMultipleRuns=True
12  print "Multiple Runs are selected"
13 
14 if(isMultipleRuns):
15  process.source.firstRun = cms.untracked.uint32(int(runboundary[0]))
16 else:
17  process.source.firstRun = cms.untracked.uint32(int(runboundary))
18 
19 ###################################################################
20 # JSON Filtering
21 ###################################################################
22 if isMC:
23  print ">>>>>>>>>> testPVValidation_cfg.py: msg%-i: This is simulation!"
24  runboundary = 1
25 else:
26  print ">>>>>>>>>> testPVValidation_cfg.py: msg%-i: This is real dATA!"
27  if ('.oO[lumilist]Oo.'):
28  print ">>>>>>>>>> testPVValidation_cfg.py: msg%-i: JSON filtering with: .oO[lumilist]Oo. "
29  import FWCore.PythonUtilities.LumiList as LumiList
30  process.source.lumisToProcess = LumiList.LumiList(filename ='.oO[lumilist]Oo.').getVLuminosityBlockRange()
31 
32 ####################################################################
33 # Produce the Transient Track Record in the event
34 ####################################################################
35 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
36 
37 ####################################################################
38 # Load and Configure event selection
39 ####################################################################
40 process.primaryVertexFilter = cms.EDFilter("VertexSelector",
41  src = cms.InputTag(".oO[VertexCollection]Oo."),
42  cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"),
43  filter = cms.bool(True)
44  )
45 
46 process.noscraping = cms.EDFilter("FilterOutScraping",
47  applyfilter = cms.untracked.bool(True),
48  src = cms.untracked.InputTag(".oO[TrackCollection]Oo."),
49  debugOn = cms.untracked.bool(False),
50  numtrack = cms.untracked.uint32(10),
51  thresh = cms.untracked.double(0.25)
52  )
53 
54 
55 process.load("Alignment.CommonAlignment.filterOutLowPt_cfi")
56 process.filterOutLowPt.src = ".oO[TrackCollection]Oo."
57 process.filterOutLowPt.ptmin = .oO[ptCut]Oo.
58 process.filterOutLowPt.runControl = .oO[runControl]Oo.
59 if(isMultipleRuns):
60  process.filterOutLowPt.runControlNumber.extend((runboundary))
61 else:
62  process.filterOutLowPt.runControlNumber = [runboundary]
63 
64 if isMC:
65  process.goodvertexSkim = cms.Sequence(process.noscraping + process.filterOutLowPt)
66 else:
67  process.goodvertexSkim = cms.Sequence(process.primaryVertexFilter + process.noscraping + process.filterOutLowPt)
68 
69 ####################################################################
70 # Deterministic annealing clustering
71 ####################################################################
72 if isDA:
73  print ">>>>>>>>>> testPVValidation_cfg.py: msg%-i: Running DA Algorithm!"
74  process.PVValidation = cms.EDAnalyzer("PrimaryVertexValidation",
75  TrackCollectionTag = cms.InputTag("TrackRefitter"),
76  VertexCollectionTag = cms.InputTag(".oO[VertexCollection]Oo."),
77  Debug = cms.bool(False),
78  storeNtuple = cms.bool(False),
79  useTracksFromRecoVtx = cms.bool(False),
80  isLightNtuple = cms.bool(True),
81  askFirstLayerHit = cms.bool(False),
82  probePt = cms.untracked.double(.oO[ptCut]Oo.),
83  probeEta = cms.untracked.double(.oO[etaCut]Oo.),
84  doBPix = cms.untracked.bool(.oO[doBPix]Oo.),
85  doFPix = cms.untracked.bool(.oO[doFPix]Oo.),
86  numberOfBins = cms.untracked.int32(.oO[numberOfBins]Oo.),
87  runControl = cms.untracked.bool(.oO[runControl]Oo.),
88  runControlNumber = cms.untracked.vuint32(runboundary),
89 
90  TkFilterParameters = cms.PSet(algorithm=cms.string('filter'),
91  maxNormalizedChi2 = cms.double(5.0), # chi2ndof < 5
92  minPixelLayersWithHits = cms.int32(2), # PX hits > 2
93  minSiliconLayersWithHits = cms.int32(5), # TK hits > 5
94  maxD0Significance = cms.double(5.0), # fake cut (requiring 1 PXB hit)
95  minPt = cms.double(0.0), # better for softish events
96  maxEta = cms.double(5.0), # as per recommendation in PR #18330
97  trackQuality = cms.string("any")
98  ),
99 
100  ## MM 04.05.2017 (use settings as in: https://github.com/cms-sw/cmssw/pull/18330)
101  TkClusParameters=cms.PSet(algorithm=cms.string('DA_vect'),
102  TkDAClusParameters = cms.PSet(coolingFactor = cms.double(0.6), # moderate annealing speed
103  Tmin = cms.double(2.0), # end of vertex splitting
104  Tpurge = cms.double(2.0), # cleaning
105  Tstop = cms.double(0.5), # end of annealing
106  vertexSize = cms.double(0.006), # added in quadrature to track-z resolutions
107  d0CutOff = cms.double(3.), # downweight high IP tracks
108  dzCutOff = cms.double(3.), # outlier rejection after freeze-out (T<Tmin)
109  zmerge = cms.double(1e-2), # merge intermediat clusters separated by less than zmerge
110  uniquetrkweight = cms.double(0.8) # require at least two tracks with this weight at T=Tpurge
111  )
112  )
113  )
114 
115 ####################################################################
116 # GAP clustering
117 ####################################################################
118 else:
119  print ">>>>>>>>>> testPVValidation_cfg.py: msg%-i: Running GAP Algorithm!"
120  process.PVValidation = cms.EDAnalyzer("PrimaryVertexValidation",
121  TrackCollectionTag = cms.InputTag("TrackRefitter"),
122  VertexCollectionTag = cms.InputTag(".oO[VertexCollection]Oo."),
123  Debug = cms.bool(False),
124  isLightNtuple = cms.bool(True),
125  storeNtuple = cms.bool(False),
126  useTracksFromRecoVtx = cms.bool(False),
127  askFirstLayerHit = cms.bool(False),
128  probePt = cms.untracked.double(.oO[ptCut]Oo.),
129  probeEta = cms.untracked.double(.oO[etaCut]Oo.),
130  doBPix = cms.untracked.bool(.oO[doBPix]Oo.),
131  doFPix = cms.untracked.bool(.oO[doFPix]Oo.),
132  numberOfBins = cms.untracked.int32(.oO[numberOfBins]Oo.),
133  runControl = cms.untracked.bool(.oO[runControl]Oo.),
134  runControlNumber = cms.untracked.vuint32(int(.oO[runboundary]Oo.)),
135 
136  TkFilterParameters = cms.PSet(algorithm=cms.string('filter'),
137  maxNormalizedChi2 = cms.double(5.0), # chi2ndof < 20
138  minPixelLayersWithHits=cms.int32(2), # PX hits > 2
139  minSiliconLayersWithHits = cms.int32(5), # TK hits > 5
140  maxD0Significance = cms.double(5.0), # fake cut (requiring 1 PXB hit)
141  minPt = cms.double(0.0), # better for softish events
142  maxEta = cms.double(5.0), # as per recommendation in PR #18330
143  trackQuality = cms.string("any")
144  ),
145 
146  TkClusParameters = cms.PSet(algorithm = cms.string('gap'),
147  TkGapClusParameters = cms.PSet(zSeparation = cms.double(0.2) # 0.2 cm max separation betw. clusters
148  )
149  )
150  )
151 
152 """
153 
154 ####################################################################
155 ####################################################################
156 PVValidationPath="""
157 process.p = cms.Path(process.goodvertexSkim*
158  process.offlineBeamSpot*
159  process.TrackRefitter*
160  process.PVValidation)
161 """
162 
163 ####################################################################
164 ####################################################################
165 PVValidationScriptTemplate="""
166 #!/bin/bash
167 source /afs/cern.ch/cms/caf/setup.sh
168 eos='/afs/cern.ch/project/eos/installation/cms/bin/eos.select'
169 
170 echo -----------------------
171 echo Job started at `date`
172 echo -----------------------
173 
174 export theLabel=.oO[alignmentName]Oo.
175 export theDate=.oO[runboundary]Oo.
176 
177 cwd=`pwd`
178 cd .oO[CMSSW_BASE]Oo./src
179 export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
180 eval `scram runtime -sh`
181 cd $cwd
182 
183 rfmkdir -p .oO[datadir]Oo.
184 rfmkdir -p .oO[workingdir]Oo.
185 rfmkdir -p .oO[logdir]Oo.
186 rm -f .oO[logdir]Oo./*.stdout
187 rm -f .oO[logdir]Oo./*.stderr
188 
189 if [[ $HOSTNAME = lxplus[0-9]*[.a-z0-9]* ]] # check for interactive mode
190 then
191  rfmkdir -p .oO[workdir]Oo.
192  rm -f .oO[workdir]Oo./*
193  cd .oO[workdir]Oo.
194 else
195  mkdir -p $cwd/TkAllInOneTool
196  cd $cwd/TkAllInOneTool
197 fi
198 
199 .oO[CommandLine]Oo.
200 
201 ls -lh .
202 
203 $eos mkdir -p /store/caf/user/$USER/.oO[eosdir]Oo./plots/
204 for RootOutputFile in $(ls *root )
205 do
206  xrdcp -f ${RootOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./
207  rfcp ${RootOutputFile} .oO[workingdir]Oo.
208 done
209 
210 cp .oO[Alignment/OfflineValidation]Oo./macros/FitPVResiduals.C .
211 cp .oO[Alignment/OfflineValidation]Oo./macros/CMS_lumi.C .
212 cp .oO[Alignment/OfflineValidation]Oo./macros/CMS_lumi.h .
213 
214  if [[ .oO[pvvalidationreference]Oo. == *store* ]]; then xrdcp -f .oO[pvvalidationreference]Oo. PVValidation_reference.root; else ln -fs .oO[pvvalidationreference]Oo. ./PVValidation_reference.root; fi
215 
216 root -b -q "FitPVResiduals.C(\\"${PWD}/${RootOutputFile}=${theLabel},${PWD}/PVValidation_reference.root=Design simulation\\",true,true,\\"$theDate\\")"
217 
218 mkdir -p .oO[plotsdir]Oo.
219 for PngOutputFile in $(ls *png ); do
220  xrdcp -f ${PngOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
221  rfcp ${PngOutputFile} .oO[plotsdir]Oo.
222 done
223 
224 for PdfOutputFile in $(ls *pdf ); do
225  xrdcp -f ${PdfOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
226  rfcp ${PdfOutputFile} .oO[plotsdir]Oo.
227 done
228 
229 mkdir .oO[plotsdir]Oo./Biases/
230 mkdir .oO[plotsdir]Oo./Biases/dzPhi
231 mkdir .oO[plotsdir]Oo./Biases/dxyPhi
232 mkdir .oO[plotsdir]Oo./Biases/dzEta
233 mkdir .oO[plotsdir]Oo./Biases/dxyEta
234 mkdir .oO[plotsdir]Oo./Fit
235 mkdir .oO[plotsdir]Oo./dxyVsEta
236 mkdir .oO[plotsdir]Oo./dzVsEta
237 mkdir .oO[plotsdir]Oo./dxyVsPhi
238 mkdir .oO[plotsdir]Oo./dzVsPhi
239 mkdir .oO[plotsdir]Oo./dxyVsEtaNorm
240 mkdir .oO[plotsdir]Oo./dzVsEtaNorm
241 mkdir .oO[plotsdir]Oo./dxyVsPhiNorm
242 mkdir .oO[plotsdir]Oo./dzVsPhiNorm
243 
244 mv .oO[plotsdir]Oo./BiasesCanvas* .oO[plotsdir]Oo./Biases/
245 mv .oO[plotsdir]Oo./dzPhiBiasCanvas* .oO[plotsdir]Oo./Biases/dzPhi
246 mv .oO[plotsdir]Oo./dxyPhiBiasCanvas* .oO[plotsdir]Oo./Biases/dxyPhi
247 mv .oO[plotsdir]Oo./dzEtaBiasCanvas* .oO[plotsdir]Oo./Biases/dzEta
248 mv .oO[plotsdir]Oo./dxyEtaBiasCanvas* .oO[plotsdir]Oo./Biases/dxyEta
249 mv .oO[plotsdir]Oo./dzPhiTrendFit* .oO[plotsdir]Oo./Fit
250 mv .oO[plotsdir]Oo./dxyEtaTrendNorm* .oO[plotsdir]Oo./dxyVsEtaNorm
251 mv .oO[plotsdir]Oo./dzEtaTrendNorm* .oO[plotsdir]Oo./dzVsEtaNorm
252 mv .oO[plotsdir]Oo./dxyPhiTrendNorm* .oO[plotsdir]Oo./dxyVsPhiNorm
253 mv .oO[plotsdir]Oo./dzPhiTrendNorm* .oO[plotsdir]Oo./dzVsPhiNorm
254 mv .oO[plotsdir]Oo./dxyEtaTrend* .oO[plotsdir]Oo./dxyVsEta
255 mv .oO[plotsdir]Oo./dzEtaTrend* .oO[plotsdir]Oo./dzVsEta
256 mv .oO[plotsdir]Oo./dxyPhiTrend* .oO[plotsdir]Oo./dxyVsPhi
257 mv .oO[plotsdir]Oo./dzPhiTrend* .oO[plotsdir]Oo./dzVsPhi
258 
259 wget https://raw.githubusercontent.com/mmusich/PVToolScripts/master/PolishedScripts/index.php
260 
261 cp index.php .oO[plotsdir]Oo./Biases/
262 cp index.php .oO[plotsdir]Oo./Biases/dzPhi
263 cp index.php .oO[plotsdir]Oo./Biases/dxyPhi
264 cp index.php .oO[plotsdir]Oo./Biases/dzEta
265 cp index.php .oO[plotsdir]Oo./Biases/dxyEta
266 cp index.php .oO[plotsdir]Oo./Fit
267 cp index.php .oO[plotsdir]Oo./dxyVsEta
268 cp index.php .oO[plotsdir]Oo./dzVsEta
269 cp index.php .oO[plotsdir]Oo./dxyVsPhi
270 cp index.php .oO[plotsdir]Oo./dzVsPhi
271 cp index.php .oO[plotsdir]Oo./dxyVsEtaNorm
272 cp index.php .oO[plotsdir]Oo./dzVsEtaNorm
273 cp index.php .oO[plotsdir]Oo./dxyVsPhiNorm
274 cp index.php .oO[plotsdir]Oo./dzVsPhiNorm
275 
276 
277 echo -----------------------
278 echo Job ended at `date`
279 echo -----------------------
280 
281 """
282 
283 ######################################################################
284 ######################################################################
285 
286 PrimaryVertexPlotExecution="""
287 #make primary vertex validation plots
288 
289 rfcp .oO[plottingscriptpath]Oo. .
290 root -x -b -q .oO[plottingscriptname]Oo.++
291 
292 for PdfOutputFile in $(ls *pdf ); do
293  xrdcp -f ${PdfOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
294  rfcp ${PdfOutputFile} .oO[datadir]Oo./.oO[PlotsDirName]Oo.
295 done
296 
297 for PngOutputFile in $(ls *png ); do
298  xrdcp -f ${PngOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
299  rfcp ${PngOutputFile} .oO[datadir]Oo./.oO[PlotsDirName]Oo.
300 done
301 
302 """
303 
304 ######################################################################
305 ######################################################################
306 
307 PrimaryVertexPlotTemplate="""
308 /****************************************
309 This can be run directly in root, or you
310  can run ./TkAlMerge.sh in this directory
311 ****************************************/
312 
313 #include "Alignment/OfflineValidation/macros/FitPVResiduals.C"
314 
315 void TkAlPrimaryVertexValidationPlot()
316 {
317 
318  // initialize the plot y-axis ranges
319  thePlotLimits->init(.oO[m_dxyPhiMax]Oo., // mean of dxy vs Phi
320  .oO[m_dzPhiMax]Oo., // mean of dz vs Phi
321  .oO[m_dxyEtaMax]Oo., // mean of dxy vs Eta
322  .oO[m_dzEtaMax]Oo., // mean of dz vs Eta
323  .oO[m_dxyPhiNormMax]Oo., // mean of dxy vs Phi (norm)
324  .oO[m_dzPhiNormMax]Oo., // mean of dz vs Phi (norm)
325  .oO[m_dxyEtaNormMax]Oo., // mean of dxy vs Eta (norm)
326  .oO[m_dzEtaNormMax]Oo., // mean of dz vs Eta (norm)
327  .oO[w_dxyPhiMax]Oo., // width of dxy vs Phi
328  .oO[w_dzPhiMax]Oo., // width of dz vs Phi
329  .oO[w_dxyEtaMax]Oo., // width of dxy vs Eta
330  .oO[w_dzEtaMax]Oo., // width of dz vs Eta
331  .oO[w_dxyPhiNormMax]Oo., // width of dxy vs Phi (norm)
332  .oO[w_dzPhiNormMax]Oo., // width of dz vs Phi (norm)
333  .oO[w_dxyEtaNormMax]Oo., // width of dxy vs Eta (norm)
334  .oO[w_dzEtaNormMax]Oo. // width of dz vs Eta (norm)
335  );
336 
337  .oO[PlottingInstantiation]Oo.
338  FitPVResiduals("",.oO[stdResiduals]Oo.,.oO[doMaps]Oo.,"",.oO[autoLimits]Oo.);
339 }
340 """
341 
342