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 # Imports of parameters
72 ####################################################################
73 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices
74 ## modify the parameters which differ
75 FilteringParams = offlinePrimaryVertices.TkFilterParameters.clone(
76  maxNormalizedChi2 = 5.0, # chi2ndof < 5
77  maxD0Significance = 5.0, # fake cut (requiring 1 PXB hit)
78  maxEta = 5.0, # as per recommendation in PR #18330
79 )
80 
81 ## MM 04.05.2017 (use settings as in: https://github.com/cms-sw/cmssw/pull/18330)
82 from RecoVertex.PrimaryVertexProducer.TkClusParameters_cff import DA_vectParameters
83 DAClusterizationParams = DA_vectParameters.clone()
84 
85 GapClusterizationParams = cms.PSet(algorithm = cms.string('gap'),
86  TkGapClusParameters = cms.PSet(zSeparation = cms.double(0.2)) # 0.2 cm max separation betw. clusters
87  )
88 
89 ####################################################################
90 # Deterministic annealing clustering or Gap clustering
91 ####################################################################
92 def switchClusterizerParameters(da):
93  if da:
94  print(">>>>>>>>>> testPVValidation_cfg.py: msg%-i: Running DA Algorithm!")
95  return DAClusterizationParams
96  else:
97  print(">>>>>>>>>> testPVValidation_cfg.py: msg%-i: Running GAP Algorithm!")
98  return GapClusterizationParams
99 
100 # Use compressions settings of TFile
101 # see https://root.cern.ch/root/html534/TFile.html#TFile:SetCompressionSettings
102 # settings = 100 * algorithm + level
103 # level is from 1 (small) to 9 (large compression)
104 # algo: 1 (ZLIB), 2 (LMZA)
105 # see more about compression & performance: https://root.cern.ch/root/html534/guides/users-guide/InputOutput.html#compression-and-performance
106 compressionSettings = 207
107 
108 ####################################################################
109 # Configure the PVValidation Analyzer module
110 ####################################################################
111 process.PVValidation = cms.EDAnalyzer("PrimaryVertexValidation",
112  compressionSettings = cms.untracked.int32(compressionSettings),
113  TrackCollectionTag = cms.InputTag("FinalTrackRefitter"),
114  VertexCollectionTag = cms.InputTag(".oO[VertexCollection]Oo."),
115  Debug = cms.bool(False),
116  storeNtuple = cms.bool(False),
117  useTracksFromRecoVtx = cms.bool(False),
118  isLightNtuple = cms.bool(True),
119  askFirstLayerHit = cms.bool(False),
120  forceBeamSpot = cms.untracked.bool(.oO[forceBeamSpot]Oo.),
121  probePt = cms.untracked.double(.oO[ptCut]Oo.),
122  probeEta = cms.untracked.double(.oO[etaCut]Oo.),
123  doBPix = cms.untracked.bool(.oO[doBPix]Oo.),
124  doFPix = cms.untracked.bool(.oO[doFPix]Oo.),
125  numberOfBins = cms.untracked.int32(.oO[numberOfBins]Oo.),
126  runControl = cms.untracked.bool(.oO[runControl]Oo.),
127  runControlNumber = cms.untracked.vuint32(runboundary),
128  TkFilterParameters = FilteringParams,
129  TkClusParameters = switchClusterizerParameters(isDA)
130  )
131 """
132 
133 
135 PVValidationPath="""
136 process.p = cms.Path(process.goodvertexSkim*
137  process.seqTrackselRefit*
138  process.PVValidation)
139 """
140 
141 
143 PVValidationScriptTemplate="""#!/bin/bash
144 source /afs/cern.ch/cms/caf/setup.sh
145 export X509_USER_PROXY=.oO[scriptsdir]Oo./.user_proxy
146 
147 echo -----------------------
148 echo Job started at `date`
149 echo -----------------------
150 
151 export theLabel=.oO[alignmentName]Oo.
152 export theDate=.oO[runboundary]Oo.
153 
154 cwd=`pwd`
155 cd .oO[CMSSW_BASE]Oo./src
156 export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
157 eval `scram runtime -sh`
158 cd $cwd
159 
160 mkdir -p .oO[datadir]Oo.
161 mkdir -p .oO[workingdir]Oo.
162 mkdir -p .oO[logdir]Oo.
163 rm -f .oO[logdir]Oo./*.stdout
164 rm -f .oO[logdir]Oo./*.stderr
165 
166 if [[ $HOSTNAME = lxplus[0-9]*[.a-z0-9]* ]] # check for interactive mode
167 then
168  mkdir -p .oO[workdir]Oo.
169  rm -f .oO[workdir]Oo./*
170  cd .oO[workdir]Oo.
171 else
172  mkdir -p $cwd/TkAllInOneTool
173  cd $cwd/TkAllInOneTool
174 fi
175 
176 .oO[CommandLine]Oo.
177 
178 ls -lh .
179 
180 eos mkdir -p /store/group/alca_trackeralign/AlignmentValidation/.oO[eosdir]Oo./plots/
181 for RootOutputFile in $(ls *root )
182 do
183  xrdcp -f ${RootOutputFile} root://eoscms//eos/cms/store/group/alca_trackeralign/AlignmentValidation/.oO[eosdir]Oo./${RootOutputFile}
184  cp ${RootOutputFile} .oO[workingdir]Oo.
185 done
186 
187 cp .oO[Alignment/OfflineValidation]Oo./macros/FitPVResiduals.C .
188 cp .oO[Alignment/OfflineValidation]Oo./macros/CMS_lumi.C .
189 cp .oO[Alignment/OfflineValidation]Oo./macros/CMS_lumi.h .
190 
191  if [[ .oO[pvvalidationreference]Oo. == *store* ]]; then xrdcp -f .oO[pvvalidationreference]Oo. PVValidation_reference.root; else ln -fs .oO[pvvalidationreference]Oo. ./PVValidation_reference.root; fi
192 
193 echo "I am going to produce the comparison with IDEAL geometry of ${RootOutputFile}"
194 root -b -q "FitPVResiduals.C++g(\\"${PWD}/${RootOutputFile}=${theLabel},${PWD}/PVValidation_reference.root=Design simulation\\",true,true,\\"$theDate\\")"
195 
196 mkdir -p .oO[plotsdir]Oo.
197 for PngOutputFile in $(ls *png ); do
198  xrdcp -f ${PngOutputFile} root://eoscms//eos/cms/store/group/alca_trackeralign/AlignmentValidation/.oO[eosdir]Oo./plots/${PngOutputFile}
199  cp ${PngOutputFile} .oO[plotsdir]Oo.
200 done
201 
202 for PdfOutputFile in $(ls *pdf ); do
203  xrdcp -f ${PdfOutputFile} root://eoscms//eos/cms/store/group/alca_trackeralign/AlignmentValidation/.oO[eosdir]Oo./plots/${PdfOutputFile}
204  cp ${PdfOutputFile} .oO[plotsdir]Oo.
205 done
206 
207 mkdir .oO[plotsdir]Oo./Biases/
208 mkdir .oO[plotsdir]Oo./Biases/dzPhi
209 mkdir .oO[plotsdir]Oo./Biases/dxyPhi
210 mkdir .oO[plotsdir]Oo./Biases/dzEta
211 mkdir .oO[plotsdir]Oo./Biases/dxyEta
212 mkdir .oO[plotsdir]Oo./Fit
213 mkdir .oO[plotsdir]Oo./dxyVsEta
214 mkdir .oO[plotsdir]Oo./dzVsEta
215 mkdir .oO[plotsdir]Oo./dxyVsPhi
216 mkdir .oO[plotsdir]Oo./dzVsPhi
217 mkdir .oO[plotsdir]Oo./dxyVsEtaNorm
218 mkdir .oO[plotsdir]Oo./dzVsEtaNorm
219 mkdir .oO[plotsdir]Oo./dxyVsPhiNorm
220 mkdir .oO[plotsdir]Oo./dzVsPhiNorm
221 
222 mv .oO[plotsdir]Oo./BiasesCanvas* .oO[plotsdir]Oo./Biases/
223 mv .oO[plotsdir]Oo./dzPhiBiasCanvas* .oO[plotsdir]Oo./Biases/dzPhi
224 mv .oO[plotsdir]Oo./dxyPhiBiasCanvas* .oO[plotsdir]Oo./Biases/dxyPhi
225 mv .oO[plotsdir]Oo./dzEtaBiasCanvas* .oO[plotsdir]Oo./Biases/dzEta
226 mv .oO[plotsdir]Oo./dxyEtaBiasCanvas* .oO[plotsdir]Oo./Biases/dxyEta
227 mv .oO[plotsdir]Oo./dzPhiTrendFit* .oO[plotsdir]Oo./Fit
228 mv .oO[plotsdir]Oo./dxyEtaTrendNorm* .oO[plotsdir]Oo./dxyVsEtaNorm
229 mv .oO[plotsdir]Oo./dzEtaTrendNorm* .oO[plotsdir]Oo./dzVsEtaNorm
230 mv .oO[plotsdir]Oo./dxyPhiTrendNorm* .oO[plotsdir]Oo./dxyVsPhiNorm
231 mv .oO[plotsdir]Oo./dzPhiTrendNorm* .oO[plotsdir]Oo./dzVsPhiNorm
232 mv .oO[plotsdir]Oo./dxyEtaTrend* .oO[plotsdir]Oo./dxyVsEta
233 mv .oO[plotsdir]Oo./dzEtaTrend* .oO[plotsdir]Oo./dzVsEta
234 mv .oO[plotsdir]Oo./dxyPhiTrend* .oO[plotsdir]Oo./dxyVsPhi
235 mv .oO[plotsdir]Oo./dzPhiTrend* .oO[plotsdir]Oo./dzVsPhi
236 
237 wget https://raw.githubusercontent.com/mmusich/PVToolScripts/master/PolishedScripts/index.php
238 
239 cp index.php .oO[plotsdir]Oo./Biases/
240 cp index.php .oO[plotsdir]Oo./Biases/dzPhi
241 cp index.php .oO[plotsdir]Oo./Biases/dxyPhi
242 cp index.php .oO[plotsdir]Oo./Biases/dzEta
243 cp index.php .oO[plotsdir]Oo./Biases/dxyEta
244 cp index.php .oO[plotsdir]Oo./Fit
245 cp index.php .oO[plotsdir]Oo./dxyVsEta
246 cp index.php .oO[plotsdir]Oo./dzVsEta
247 cp index.php .oO[plotsdir]Oo./dxyVsPhi
248 cp index.php .oO[plotsdir]Oo./dzVsPhi
249 cp index.php .oO[plotsdir]Oo./dxyVsEtaNorm
250 cp index.php .oO[plotsdir]Oo./dzVsEtaNorm
251 cp index.php .oO[plotsdir]Oo./dxyVsPhiNorm
252 cp index.php .oO[plotsdir]Oo./dzVsPhiNorm
253 
254 
255 echo -----------------------
256 echo Job ended at `date`
257 echo -----------------------
258 
259 """
260 
261 
263 
264 PrimaryVertexPlotExecution="""
265 #make primary vertex validation plots
266 
267 cp .oO[plottingscriptpath]Oo. .
268 root -x -b -q .oO[plottingscriptname]Oo.++
269 
270 for PdfOutputFile in $(ls *pdf ); do
271  xrdcp -f ${PdfOutputFile} root://eoscms//eos/cms/store/group/alca_trackeralign/AlignmentValidation/.oO[eosdir]Oo./plots/${PdfOutputFile}
272  cp ${PdfOutputFile} .oO[datadir]Oo./.oO[PlotsDirName]Oo.
273 done
274 
275 for PngOutputFile in $(ls *png ); do
276  xrdcp -f ${PngOutputFile} root://eoscms//eos/cms/store/group/alca_trackeralign/AlignmentValidation/.oO[eosdir]Oo./plots/${PngOutputFile}
277  cp ${PngOutputFile} .oO[datadir]Oo./.oO[PlotsDirName]Oo.
278 done
279 
280 """
281 
282 
284 
285 PrimaryVertexPlotTemplate="""
286 /****************************************
287 This can be run directly in root, or you
288  can run ./TkAlMerge.sh in this directory
289 ****************************************/
290 
291 #include "Alignment/OfflineValidation/macros/FitPVResiduals.C"
292 
293 void TkAlPrimaryVertexValidationPlot()
294 {
295 
296  // initialize the plot y-axis ranges
297  thePlotLimits->init(.oO[m_dxyPhiMax]Oo., // mean of dxy vs Phi
298  .oO[m_dzPhiMax]Oo., // mean of dz vs Phi
299  .oO[m_dxyEtaMax]Oo., // mean of dxy vs Eta
300  .oO[m_dzEtaMax]Oo., // mean of dz vs Eta
301  .oO[m_dxyPhiNormMax]Oo., // mean of dxy vs Phi (norm)
302  .oO[m_dzPhiNormMax]Oo., // mean of dz vs Phi (norm)
303  .oO[m_dxyEtaNormMax]Oo., // mean of dxy vs Eta (norm)
304  .oO[m_dzEtaNormMax]Oo., // mean of dz vs Eta (norm)
305  .oO[w_dxyPhiMax]Oo., // width of dxy vs Phi
306  .oO[w_dzPhiMax]Oo., // width of dz vs Phi
307  .oO[w_dxyEtaMax]Oo., // width of dxy vs Eta
308  .oO[w_dzEtaMax]Oo., // width of dz vs Eta
309  .oO[w_dxyPhiNormMax]Oo., // width of dxy vs Phi (norm)
310  .oO[w_dzPhiNormMax]Oo., // width of dz vs Phi (norm)
311  .oO[w_dxyEtaNormMax]Oo., // width of dxy vs Eta (norm)
312  .oO[w_dzEtaNormMax]Oo. // width of dz vs Eta (norm)
313  );
314 
315  .oO[PlottingInstantiation]Oo.
316  FitPVResiduals("",.oO[stdResiduals]Oo.,.oO[doMaps]Oo.,"",.oO[autoLimits]Oo.);
317 }
318 """
319 
320