test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
zMuMuValidationTemplates.py
Go to the documentation of this file.
1 ZMuMuValidationTemplate="""
2 import FWCore.ParameterSet.Config as cms
3 
4 process = cms.Process("ONLYHISTOS")
5 
6 
7 # Messages
8 process.load("FWCore.MessageService.MessageLogger_cfi")
9 process.MessageLogger.destinations = ['cout', 'cerr']
10 process.MessageLogger.cerr.FwkReport.reportEvery = 5000
11 
12 
13 ########### DATA FILES ####################################
14 .oO[datasetDefinition]Oo.
15 # process.load("Alignment.OfflineValidation..oO[dataset]Oo._cff")
16 
17 #process.load("Geometry.CMSCommonData.cmsIdealGeometryXML_cfi")
18 #process.load("Geometry.CommonDetUnit.globalTrackingGeometry_cfi")
19 process.load("RecoMuon.DetLayers.muonDetLayerGeometry_cfi")
20 process.load("Geometry.MuonNumbering.muonNumberingInitialization_cfi")
21 process.load("RecoMuon.TrackingTools.MuonServiceProxy_cff")
22 
23 ########### standard includes ##############################
24 process.load("Configuration.StandardSequences..oO[magneticField]Oo._cff")
25 process.load("Configuration.StandardSequences.Reconstruction_cff")
26 process.load("Configuration.Geometry.GeometryRecoDB_cff")
27 
28 
29 ########### DATABASE conditions ############################
30 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
31 process.GlobalTag.globaltag = ".oO[GlobalTag]Oo."
32 
33 .oO[condLoad]Oo.
34 
35 ########### TRACK REFITTER #################################
36 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
37 process.TrackRefitter.src = 'ALCARECOTkAlZMuMu'
38 process.TrackRefitter.TrajectoryInEvent = True
39 process.TrackRefitter.TTRHBuilder = "WithAngleAndTemplate"
40 process.TrackRefitter.NavigationSchool = ""
41 
42 ###### MuSclFit SETTINGS ##############################################
43 
44 
45 ### MuScleFit specific configuration
46 
47 process.looper = cms.Looper(
48  "MuScleFit",
49  # Only used when reading events from a root tree
50  MaxEventsFromRootTree = cms.int32(-1),
51 
52  # Specify a file if you want to read events from a root tree in a local file.
53  # In this case the input source should be an empty source with 0 events.
54 
55  InputRootTreeFileName = cms.string(""),
56 
57  # Specify the file name where you want to save a root tree with the muon pairs.
58  # Leave empty if no file should be written.
59 
60  OutputRootTreeFileName = cms.string(""),
61 
62 
63  # Choose the kind of muons you want to run on
64  # -------------------------------------------
65  MuonLabel = cms.InputTag("TrackRefitter"),
66 
67 
68  #MuonType = cms.int32(11),
69  MuonType = cms.int32(5),
70 
71  # This line allows to switch to PAT muons. Default is false.
72  # Note that the onia selection works only with onia patTuples.
73  PATmuons = cms.untracked.bool(False),
74 
75  # ---------------- #
76  # Select resonance #
77  # ---------------- #
78  # The resonances are to be specified in this order:
79  # Z0, Y(3S), Y(2S), Y(1S), Psi(2S), J/Psi
80  # -------------------------------------------------
81  resfind = cms.vint32(1, 0, 0, 0, 0, 0),
82 
83  # Likelihood settings
84  # -------------------
85  maxLoopNumber = cms.untracked.int32(1),
86  # Select which fits to do in which loop (0 = do not, 1 = do)
87  doResolFit = cms.vint32(0),
88  doScaleFit = cms.vint32(0),
89  doBackgroundFit = cms.vint32(0),
90  doCrossSectionFit = cms.vint32(0),
91 
92  # Use the probability file or not. If not it will perform a simpler selection taking the muon pair with
93  # invariant mass closer to the pdf value and will crash if some fit is attempted.
94  UseProbsFile = cms.untracked.bool(False),
95 
96  # False = use also MC information
97  speedup = cms.bool(True),
98  # Set this to false if you do not want to use simTracks.
99  # (Note that this is skipped anyway if speedup == True).
100  compareToSimTracks = cms.bool(False),
101 
102  # Output settings
103  # ---------------
104  OutputFileName = cms.untracked.string("zmumuHisto.root"),
105 
106  # BiasType=0 means no bias to muon momenta
107  # ----------------------------------------
108  BiasType = cms.int32(0),
109  parBias = cms.vdouble(),
110 
111  # SmearType=0 means no smearing applied to muon momenta
112  # -----------------------------------------------------
113  SmearType = cms.int32(0),
114  parSmear = cms.vdouble(),
115 
116  ### taken from J/Psi #########################
117 # ResolFitType = cms.int32(14),
118 # parResol = cms.vdouble(0.007,0.015, -0.00077, 0.0063, 0.0018, 0.0164),
119 # parResolFix = cms.vint32(0, 0, 0,0, 0,0),
120 # parResolOrder = cms.vint32(0, 0, 0, 0, 0, 0),
121  ResolFitType = cms.int32(0),
122  parResol = cms.vdouble(0),
123  parResolFix = cms.vint32(0),
124  parResolOrder = cms.vint32(0),
125 
126 
127  # -------------------- #
128  # Scale fit parameters #
129  # -------------------- #
130 
131  # -----------------------------------------------------------------------------------
132 # ScaleFitType = cms.int32(18),
133 # parScaleOrder = cms.vint32(0, 0, 0, 0),
134 # parScaleFix = cms.vint32(0, 0, 0, 0),
135 # parScale = cms.vdouble(1, 1, 1, 1),
136  ScaleFitType = cms.int32(0),
137  parScaleOrder = cms.vint32(0),
138  parScaleFix = cms.vint32(0),
139  parScale = cms.vdouble(0),
140 
141 
142 
143  # ---------------------------- #
144  # Cross section fit parameters #
145  # ---------------------------- #
146  # Note that the cross section fit works differently than the others, it
147  # fits ratios of parameters. Fix and Order should not be used as is, they
148  # are there mainly for compatibility.
149  parCrossSectionOrder = cms.vint32(0, 0, 0, 0, 0, 0),
150  parCrossSectionFix = cms.vint32(0, 0, 0, 0, 0, 0),
151  parCrossSection = cms.vdouble(1.233, 2.07, 6.33, 13.9, 2.169, 127.2),
152 
153  # ------------------------- #
154  # Background fit parameters #
155  # ------------------------- #
156 
157  # Window factors for: Z, Upsilons and (J/Psi,Psi2S) regions
158  LeftWindowBorder = cms.vdouble(70., 8., 1.391495),
159  RightWindowBorder = cms.vdouble(110., 12., 5.391495),
160 
161  # The two parameters of BgrFitType=2 are respectively:
162  # bgr fraction, (negative of) bgr exp. slope, bgr constant
163  # --------------------------------------------------------
164  # The function types for resonances in a region must be the same
165  BgrFitType = cms.vint32(2, 2, 2), # regions
166  # These empty parameters should be used when there is no background
167  parBgr = cms.vdouble(0., 0., 0., 0., 0., 0.,
168  0., 0., 0., 0., 0., 0., 0.,0., 0.,0., 0.,0.),
169  parBgrFix = cms.vint32(0, 0, 0, 0, 0, 0,
170  # The rest of the parameters is used for the resonance regions. They are automatically fixed in the code
171  # because they are never used to fit the background, but only after the rescaling.
172  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
173  parBgrOrder = cms.vint32(0, 0, 0, 0, 0, 0,
174  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
175 
176 
177  # ----------------------- #
178 
179  # Set Minuit fit strategy
180  FitStrategy = cms.int32(1),
181 
182 
183  # Fit accuracy and debug parameters
184  StartWithSimplex = cms.bool(True),
185  ComputeMinosErrors = cms.bool(False),
186  MinimumShapePlots = cms.bool(True),
187 
188  ########## TO BE ENABLED ################################
189  # Set the cuts on muons to be used in the fit
190  MinMuonPt = cms.untracked.double(0.),
191  MaxMuonPt = cms.untracked.double(1000.),
192  MinMuonEtaFirstRange = cms.untracked.double(.oO[etaminneg]Oo.),
193  MaxMuonEtaFirstRange = cms.untracked.double(.oO[etamaxneg]Oo.),
194  MinMuonEtaSecondRange = cms.untracked.double(.oO[etaminpos]Oo.),
195  MaxMuonEtaSecondRange = cms.untracked.double(.oO[etamaxpos]Oo.),
196  PileUpSummaryInfo = cms.untracked.InputTag("addPileupInfo"),
197  PrimaryVertexCollection = cms.untracked.InputTag("offlinePrimaryVertices"),
198 
199  # The following parameters can be used to filter events
200  TriggerResultsLabel = cms.untracked.string("TriggerResults"),
201  TriggerResultsProcess = cms.untracked.string("HLT"),
202  TriggerPath = cms.untracked.vstring(""),
203  # Negate the result of the trigger
204  NegateTrigger = cms.untracked.bool(False),
205  debug = cms.untracked.int32(0),
206 )
207 
208 ###### FINAL SEQUENCE ##############################################
209 
210 process.p = cms.Path(
211  process.offlineBeamSpot*process.TrackRefitter
212  )
213 
214 """
215 
216 
217 ####################################################################
218 ####################################################################
219 zMuMuScriptTemplate="""
220 #!/bin/bash
221 source /afs/cern.ch/cms/caf/setup.sh
222 eos='/afs/cern.ch/project/eos/installation/cms/bin/eos.select'
223 
224 echo -----------------------
225 echo Job started at `date`
226 echo -----------------------
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 
251 .oO[CommandLine]Oo.
252 
253 ls -lh .
254 
255 cp .oO[CMSSW_BASE]Oo./src/MuonAnalysis/MomentumScaleCalibration/test/Macros/RooFit/CompareBiasZValidation.cc .
256 cp .oO[CMSSW_BASE]Oo./src/MuonAnalysis/MomentumScaleCalibration/test/Macros/RooFit/Legend.h .
257 cp .oO[CMSSW_BASE]Oo./src/MuonAnalysis/MomentumScaleCalibration/test/Macros/RooFit/FitMassSlices.cc .
258 cp .oO[CMSSW_BASE]Oo./src/MuonAnalysis/MomentumScaleCalibration/test/Macros/RooFit/FitSlices.cc .
259 cp .oO[CMSSW_BASE]Oo./src/MuonAnalysis/MomentumScaleCalibration/test/Macros/RooFit/FitXslices.cc .
260 cp .oO[CMSSW_BASE]Oo./src/MuonAnalysis/MomentumScaleCalibration/test/Macros/RooFit/FitWithRooFit.cc .
261 cp .oO[CMSSW_BASE]Oo./src/MuonAnalysis/MomentumScaleCalibration/test/Macros/RooFit/FitMass1D.cc .
262 
263 root -q -b -l "CompareBiasZValidation.cc+(.oO[rebinphi]Oo., .oO[rebinetadiff]Oo., .oO[rebineta]Oo., .oO[rebinpt]Oo.)"
264 
265 cp .oO[CMSSW_BASE]Oo./src/MuonAnalysis/MomentumScaleCalibration/test/Macros/RooFit/tdrstyle.C .
266 cp .oO[CMSSW_BASE]Oo./src/MuonAnalysis/MomentumScaleCalibration/test/Macros/RooFit/MultiHistoOverlap_.oO[resonance]Oo..C .
267 
268 if [[ .oO[zmumureference]Oo. == *store* ]]; then xrdcp -f .oO[zmumureference]Oo. BiasCheck_Reference.root; else ln -fs .oO[zmumureference]Oo. ./BiasCheck_Reference.root; fi
269 root -q -b -l MultiHistoOverlap_.oO[resonance]Oo..C
270 
271 $eos mkdir -p /store/caf/user/$USER/.oO[eosdir]Oo./plots/
272 for RootOutputFile in $(ls *root )
273 do
274  xrdcp -f ${RootOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./
275  rfcp ${RootOutputFile} .oO[workingdir]Oo.
276 done
277 
278 mkdir -p .oO[plotsdir]Oo.
279 for PngOutputFile in $(ls *png ); do
280  xrdcp -f ${PngOutputFile} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./plots/
281  rfcp ${PngOutputFile} .oO[plotsdir]Oo.
282 done
283 
284 
285 echo -----------------------
286 echo Job ended at `date`
287 echo -----------------------
288 
289 """
290 
291 ######################################################################
292 ######################################################################
293 
294 mergeZmumuPlotsExecution="""
295 #merge Z->mumu histograms
296 
297 rfcp .oO[mergeZmumuPlotsScriptPath]Oo. .
298 root -l -x -b -q TkAlMergeZmumuPlots.C++
299 
300 """
301 
302 ######################################################################
303 ######################################################################
304 
305 mergeZmumuPlotsTemplate="""
306 #include ".oO[CMSSW_BASE]Oo./src/MuonAnalysis/MomentumScaleCalibration/test/Macros/RooFit/MultiHistoOverlapAll_Z.C"
307 #include <sstream>
308 #include <vector>
309 
310 template <typename T> string separatebycommas(vector<T> v)
311 {
312  if (v.size()==0) return "";
313  stringstream s;
314  s << v[0];
315  for (unsigned int i = 1; i < v.size(); i++)
316  s << "," << v[i];
317  return s.str();
318 }
319 
320 void TkAlMergeZmumuPlots()
321 {
322  vector<string> filenames; vector<string> titles; vector<int> colors; vector<int> linestyles;
323 
324  .oO[mergeZmumuPlotsInstantiation]Oo.
325 
326  MultiHistoOverlapAll_Z(separatebycommas(filenames), separatebycommas(titles), separatebycommas(colors), separatebycommas(linestyles), ".oO[datadir]Oo./ZMuMuPlots", .oO[switchONfit]Oo.);
327 }
328 """