CMS 3D CMS Logo

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