forked from Christinaw97/SUSYBSMAnalysis-HSCP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHSCParticleProducerAnalyzer_cfg_mc_miniAOD.py
386 lines (321 loc) · 16.3 KB
/
HSCParticleProducerAnalyzer_cfg_mc_miniAOD.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
import sys, os
import FWCore.ParameterSet.Config as cms
from FWCore.ParameterSet.VarParsing import VarParsing
options = VarParsing('analysis')
# defaults
options.outputFile = 'Histos.root'
options.maxEvents = -1 # -1 means all events
options.register('GTAG', '106X_upgrade2018_realistic_v16_L1v1',
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
"Global Tag"
)
options.register('SAMPLE', 'isData',
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
"Sample Type. Use: isSignal or isBckg or isData"
)
options.register('isSkimmedSample', False,
VarParsing.multiplicity.singleton,
VarParsing.varType.bool,
"is sample Skimmed? True or False"
)
options.register('LUMITOPROCESS', 'Cert_294927-306462_13TeV_UL2017_Collisions17_GoldenJSON.txt',
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
"Lumi to process"
)
options.parseArguments()
process = cms.Process("HSCPAnalysis")
#diventano var parsing
#The following parameters need to be provided
#isSignal, isBckg, isData, isSkimmedSample, GTAG, InputFileList
isSignal = False
isBckg = False
isData = True
#isSkimmedSample = False
## print configuration:
print('\nCMSSW version : {}'.format(os.environ['CMSSW_VERSION']))
print('Global Tag : {}'.format(options.GTAG))
if options.SAMPLE=='isData':
print('Lumi File : {}'.format(options.LUMITOPROCESS))
print('Sample Type : {}'.format(options.SAMPLE))
print('is skimmed : {}'.format(options.isSkimmedSample))
print('Output File : {}'.format(options.outputFile))
print('Input Files : {}\n'.format(options.inputFiles))
process.load("FWCore.MessageService.MessageLogger_cfi")
process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
process.load('Configuration.StandardSequences.MagneticField_cff')
process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_condDBv2_cff')
process.load('Configuration.StandardSequences.Services_cff')
process.options = cms.untracked.PSet(
#wantSummary = cms.untracked.bool(True),
#SkipEvent = cms.untracked.vstring('ProductNotFound'),
)
process.MessageLogger.cerr.FwkReport.reportEvery = 1000
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.maxEvents) )
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring("file:DYJetsToLL_0J_TuneCP5_13TeV.root"),
inputCommands = cms.untracked.vstring("keep *", "drop *_MEtoEDMConverter_*_*")
)
#if(options.SAMPLE=='isSignal'): process.source.duplicateCheckMode = cms.untracked.string("noDuplicateCheck")
#The duplicateCheckMode works only if we submit with Condor - not with Crab - checks process history, run number, lumi number
process.source.duplicateCheckMode = cms.untracked.string("checkAllFilesOpened")
from Configuration.AlCa.GlobalTag_condDBv2 import GlobalTag
process.GlobalTag = GlobalTag(process.GlobalTag, options.GTAG, '')
process.HSCPTuplePath = cms.Path()
#J: should I add something like: process.HSCPTuplePath += process.source.duplicateCheckMode ?
########################################################################
#Run the Skim sequence if necessary
if(not options.isSkimmedSample):
process.nEventsBefSkim = cms.EDProducer("EventCountProducer")
process.load('HLTrigger.HLTfilters.hltHighLevel_cfi')
process.HSCPTrigger = process.hltHighLevel.clone()
process.HSCPTrigger.TriggerResultsTag = cms.InputTag( "TriggerResults", "", "HLT" )
process.HSCPTrigger.andOr = cms.bool( True ) #OR
process.HSCPTrigger.throw = cms.bool( False )
if(options.SAMPLE=='isData'):
process.HSCPTrigger.HLTPaths = [ #check triggers
"HLT_PFMET120_PFMHT120_IDTight_v*",
"HLT_Mu50_v*",
"HLT_PFHT500_PFMET100_PFMHT100_IDTight_v*",
"HLT_PFMETNoMu120_PFMHTNoMu120_IDTight_PFHT60_v*",
"HLT_MET105_IsoTrk50_v*",
]
elif(options.SAMPLE=='isBckg'):
#to be updated to Run2 Triggers, in the meanwhile keep all of them to study trigger efficiency
process.HSCPTrigger.HLTPaths = [
"HLT_PFMET120_PFMHT120_IDTight_v*", #check triggers
"HLT_Mu50_v*",
"HLT_PFHT500_PFMET100_PFMHT100_IDTight_v*",
"HLT_PFMETNoMu120_PFMHTNoMu120_IDTight_PFHT60_v*",
"HLT_MET105_IsoTrk50_v*",
]
else:
#do not apply trigger filter on signal
process.HSCPTrigger.HLTPaths = ["*"]
process.HSCPTuplePath += process.nEventsBefSkim + process.HSCPTrigger
########################################################################
#Run the HSCP EDM-tuple Sequence on skimmed sample
process.nEventsBefEDM = cms.EDProducer("EventCountProducer")
####################################################################################
# Save Isolation info around tracks
####################################################################################
from TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff import *
from TrackingTools.TrackAssociator.default_cfi import *
process.TrackAssociatorParametersForHSCPIsol = TrackAssociatorParameterBlock.TrackAssociatorParameters.clone()
process.TrackAssociatorParametersForHSCPIsol.useHO = cms.bool(False)
process.TrackAssociatorParametersForHSCPIsol.CSCSegmentCollectionLabel = cms.InputTag("cscSegments")
process.TrackAssociatorParametersForHSCPIsol.DTRecSegment4DCollectionLabel = cms.InputTag("dt4DSegments")
process.TrackAssociatorParametersForHSCPIsol.EERecHitCollectionLabel = cms.InputTag("reducedEcalRecHitsEE")
process.TrackAssociatorParametersForHSCPIsol.EBRecHitCollectionLabel = cms.InputTag("reducedEcalRecHitsEB")
process.TrackAssociatorParametersForHSCPIsol.HBHERecHitCollectionLabel = cms.InputTag("reducedHcalRecHits", "hbhereco")
process.TrackAssociatorParametersForHSCPIsol.HORecHitCollectionLabel = cms.InputTag("reducedHcalRecHits", "horeco")
process.HSCPIsolation = cms.EDProducer("ProduceIsolationMap",
inputCollection = cms.InputTag("tracksFromMuons"),
IsolationConeDR = cms.vdouble(0.1, 0.3, 0.5),
TkIsolationPtCut = cms.vdouble(10, 10, 10),
Label = cms.vstring('R01', 'R03', 'R05'),
TKLabel = cms.InputTag("tracksFromMuons"),
TrackAssociatorParameters=process.TrackAssociatorParametersForHSCPIsol,
CandidateMinPt = cms.double(10),
)
####################################################################################
# Save muon segments in a compressed format
####################################################################################
process.MuonSegmentProducer = cms.EDProducer("MuonSegmentProducer",
CSCSegments = cms.InputTag("cscSegments"),
DTSegments = cms.InputTag("dt4DSegments"),
)
####################################################################################
# HSCParticle Producer
####################################################################################
#ALL THIS IS NEEDED BY ECAL BETA CALCULATOR (TrackAssociator)
from TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff import *
from TrackingTools.TrackAssociator.default_cfi import *
from TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi import *
from TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi import *
from TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAny_cfi import *
from SUSYBSMAnalysis.HSCP.HSCPSelections_cff import *
process.HSCParticleProducer = cms.EDFilter("HSCParticleProducerFromMiniAOD",
TrackAssociatorParameterBlock, #Needed for ECAL/Track Matching
#DOES THE PRODUCER ACT AS AN EDFILTER?
filter = cms.bool(True),
#WHAT (BETA) INFORMATION TO COMPUTE
useBetaFromTk = cms.bool(True), #does nothing because we have all the info saved in EDM format
useBetaFromMuon = cms.bool(True), #does nothing because we have all the info saved in EDM format
useBetaFromRpc = cms.bool(False), #must be updated for AOD
useBetaFromEcal = cms.bool(False), #must be updated for AOD and 74X
#TAG OF THE REQUIRED INPUT COLLECTION (ONLY ACTIVATED CALCULATOR)
tracks = cms.InputTag("tracksFromMuons"),
tracksIsolation = cms.InputTag("tracksFromMuons"),
muons = cms.InputTag("slimmedMuons"),
MTmuons = cms.InputTag("slimmedMuons"),
EBRecHitCollection = cms.InputTag("ecalRecHit:EcalRecHitsEB"),
EERecHitCollection = cms.InputTag("ecalRecHit:EcalRecHitsEE"),
rpcRecHits = cms.InputTag("rpcRecHits"),
#TRACK SELECTION FOR THE HSCP SEED
minMuP = cms.double(20),
minTkP = cms.double(20),
maxTkChi2 = cms.double(20),
minTkHits = cms.uint32(3),
minSAMuPt = cms.double(70),
minMTMuPt = cms.double(70),
#MUON/TRACK MATCHING THRESHOLDS (ONLY IF NO MUON INNER TRACK)
minDR = cms.double(0.1),
maxInvPtDiff = cms.double(0.005),
minMTDR = cms.double(0.3),
#SELECTION ON THE PRODUCED HSCP CANDIDATES (WILL STORE ONLY INTERESTING CANDIDATES)
SelectionParameters = cms.VPSet(
HSCPSelectionDefault,
HSCPSelectionMTMuonOnly,
HSCPSelectionSAMuonOnly,
),
)
####################################################################################
# HSCParticle Selector (Just an Example of what we can do)
####################################################################################
process.HSCParticleSelector = cms.EDFilter("process.HSCParticleSelector",
source = cms.InputTag("HSCParticleProducer"),
filter = cms.bool(True),
SelectionParameters = cms.VPSet(
HSCPSelectionHighdEdx, #THE OR OF THE TWO SELECTION WILL BE APPLIED
HSCPSelectionHighTOF,
),
)
####################################################################################
# HSCP Candidate Sequence
####################################################################################
process.HSCParticleProducerSeq = cms.Sequence(
#process.HSCPIsolation *
#process.MuonSegmentProducer *
process.HSCParticleProducer
)
process.HSCPTuplePath += process.nEventsBefEDM + process.HSCParticleProducerSeq
########################################################################
# Only for MC samples, save skimmed genParticles
if(options.SAMPLE=='isSignal' or options.SAMPLE=='isBckg'):
process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
process.genParticlesSkimmed = cms.EDFilter("GenParticleSelector",
filter = cms.bool(False),
src = cms.InputTag("genParticles"),
cut = cms.string('pt > 5.0'),
stableOnly = cms.bool(True)
)
process.HSCPTuplePath += process.genParticlesSkimmed
########################################################################
#make the pool output
process.Out = cms.OutputModule("PoolOutputModule",
outputCommands = cms.untracked.vstring(
"drop *",
"keep EventAux_*_*_*",
"keep LumiSummary_*_*_*",
"keep edmMergeableCounter_*_*_*",
"keep GenRunInfoProduct_*_*_*",
"keep GenEventInfoProduct_generator_*_*",
"keep *_genParticlesSkimmed_*_*",
"keep *_genParticlePlusGeant_*_*",
"keep *_offlinePrimaryVertices_*_*",
"keep recoTracks_tracksFromMuons_*_*",
"keep recoTracks_standAloneMuons_*_*",
"keep recoTrackExtras_standAloneMuons_*_*",
"keep TrackingRecHitsOwned_standAloneMuons_*_*",
"keep recoTracks_globalMuons_*_*",
"keep recoTrackExtras_globalMuons_*_*",
"keep recoMuons_muons_*_*",
"keep recoMuonTimeExtraedmValueMap_muons_*_*",
"keep edmTriggerResults_TriggerResults_*_*",
"keep *_ak4PFJetsCHS__*",
"keep recoPFMETs_pfMet__*",
"keep *_HSCParticleProducer_*_*",
"keep *_HSCPIsolation*_*_*",
"keep *_dedxHitInfo*_*_*",
"keep triggerTriggerEvent_hltTriggerSummaryAOD_*_*",
"keep *_offlineBeamSpot_*_*",
"keep *_MuonSegmentProducer_*_*",
"keep *_g4SimHits_StoppedParticles*_*",
"keep PileupSummaryInfos_addPileupInfo_*_*",
"keep *_dt4DSegments__*",
"keep *_cscSegments__*",
"keep *_scalersRawToDigi_*_*",
"keep *_caloMet_*_*",
),
fileName = cms.untracked.string(options.outputFile),
SelectEvents = cms.untracked.PSet(
SelectEvents = cms.vstring('*')
),
)
if(options.SAMPLE=='isData' and len(options.LUMITOPROCESS)>0):
import FWCore.PythonUtilities.LumiList as LumiList
#process.source.lumisToProcess = LumiList.LumiList(filename = options.LUMITOPROCESS).getVLuminosityBlockRange()
#process.source.lumisToProcess = LumiList.LumiList(url = https://cms-service-dqm.web.cern.ch/cms-service-dqm/CAF/certification/Collisions17/13TeV/ReReco/Cert_294927-306462_13TeV_EOY2017ReReco_Collisions17_JSON.txt).getVLuminosityBlockRange()
if(options.SAMPLE=='isBckg' or options.SAMPLE=='isData'):
process.Out.SelectEvents.SelectEvents = cms.vstring('HSCPTuplePath') #take just the skimmed ones
process.Out.outputCommands.extend(["drop triggerTriggerEvent_hltTriggerSummaryAOD_*_*"])
else:
process.Out.SelectEvents = cms.untracked.PSet()
########################################################################
process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
process.load("RecoTracker.MeasurementDet.MeasurementTrackerEventProducer_cfi")
process.tracksFromMuons = cms.EDProducer("TrackProducerFromPatMuons",
src = cms.InputTag("slimmedMuons"),
innerTrackOnly = cms.bool(True),
)
import RecoTracker.TrackProducer.TrackRefitter_cfi
process.myRefittedTracks = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone()
process.myRefittedTracks.src= 'tracksFromMuons'
process.myRefittedTracks.NavigationSchool = ''
process.myRefittedTracks.Fitter = 'FlexibleKFFittingSmoother'
process.myRefittedTracks.TTRHBuilder = "WithAngleAndTemplate"
# run the EDAnalyzer
process.load("SUSYBSMAnalysis.Analyzer.HSCParticleAnalyzer_cff")
### set your configirattion here (default: python/HSCParticleAnalyzer_cff.py)
#process.analyzer.SampleTxtFile=options.sampleTxtFile
process.analyzer.TypeMode=1
process.analyzer.SampleType=0
process.analyzer.saveTree=0 #all saved
process.analyzer.saveGenTree=0
process.analyzer.DeDxCalibration="Data13TeVGains_v2.root"
process.analyzer.DeDxTemplate="dEdxTemplate_harm2_SO_in_noC_CCC_MG_2017B.root"
process.analyzer.Geometry="CMS_GeomTree.root"
process.analyzer.TimeOffset="MuonTimeOffset.txt"
process.analyzer.trajInputLabel = cms.untracked.InputTag('myRefittedTracks')
process.analyzer.probQCut = cms.untracked.double(1.0)
process.analyzer.muonDtSegmentCollection = cms.InputTag("slimmedMuons")
process.analyzer.DataTier = cms.string('MiniAOD')
process.analyzer.offlinePrimaryVerticesCollection = cms.InputTag("offlineSlimmedPrimaryVertices")
process.analyzer.dedxCollection = cms.InputTag("isolatedTracks")
process.analyzer.refittedStandAloneMuonsCollection = cms.InputTag("tracksFromMuons")
process.TFileService = cms.Service("TFileService",
fileName = cms.string(options.outputFile)
)
###process.analyzer.OutputFile = 'Data_2017_UL'
process.analysis = cms.Path(process.analyzer)
#process.p = cms.Path(process.analyzer*process.dump)
#process.analyzer = cms.EDAnalyzer('Analyzer')
#process.prodAnalysis = cms.Path(process.HSCPTuplePath*process.analyzer)
import RecoTracker.TrackProducer.TrackRefitter_cfi
process.TrackRefitter_step = cms.Path(
process.offlineBeamSpot*
# process.MeasurementTrackerEvent*
process.tracksFromMuons*
process.myRefittedTracks
)
process.load('Configuration.StandardSequences.EndOfProcess_cff')
process.endjob_step = cms.EndPath(process.endOfProcess)
process.HSCPTuplePath += process.analyzer
########################################################################
process.tsk = cms.Task()
for mod in process.producers_().itervalues():
process.tsk.add(mod)
for mod in process.filters_().itervalues():
process.tsk.add(mod)
#schedule the sequence
process.endPath1 = cms.EndPath(process.Out)
process.schedule = cms.Schedule(process.TrackRefitter_step, process.HSCPTuplePath, process.endjob_step)
#process.schedule = cms.Schedule(process.prodAnalysis, process.endjob_step)
#process.schedule = cms.Schedule(process.HSCPTuplePath, process.analysis, process.endjob_step)
#process.schedule = cms.Schedule(process.HSCPTuplePath, process.endPath1)
# process task? in 9.4