ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/DGele/PhysicsTools/PatAlgos/python/tools/trackTools.py
Revision: 1.2
Committed: Tue Oct 20 17:43:05 2009 UTC (15 years, 6 months ago) by dgele
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
State: FILE REMOVED
Error occurred while calculating annotation data.
Log Message:
remove

File Contents

# Content
1 import FWCore.ParameterSet.Config as cms
2
3 def makeAODTrackCandidates(process, label='TrackCands', ## output collection will be <'patAOD'+label>
4 tracks=cms.InputTag('generalTracks'), ## input tracks
5 particleType="pi+", ## particle type (for mass)
6 candSelection='pt > 10'): ## preselection cut on candidates
7 process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi");
8 setattr(process, 'patAOD' + label + 'Unfiltered',
9 cms.EDProducer("ConcreteChargedCandidateProducer",
10 src = tracks,
11 particleType = cms.string(particleType) ) )
12 setattr(process, 'patAOD' + label,
13 cms.EDFilter("CandViewSelector",
14 src = cms.InputTag('patAOD' + label + 'Unfiltered'),
15 cut = cms.string(candSelection) ) )
16 process.patAODCoreReco += getattr(process, 'patAOD' + label + 'Unfiltered') * getattr(process, 'patAOD' + label)
17
18 def makePATTrackCandidates(process,
19 label='TrackCands', # output will be 'allLayer1'+label , 'selectedLayer1' + label
20 input=cms.InputTag('patAODTrackCands'), # Name of input collection
21 selection='pt > 10', # Selection on PAT Layer 1 objects;
22 # The output will be 'selectedLayer1' + label
23 isolation={'tracker':0.3, # Isolations to use ('source':deltaR)
24 'ecalTowers':0.3, # 'tracker' => as muon track iso
25 'hcalTowers':0.3}, # 'ecalTowers', 'hcalTowers' => as muon iso from calo towers.
26 isodeposits=['tracker','ecalTowers','hcalTowers'],
27 mcAs=cms.InputTag("muons"), # Replicate MC match as the one used by PAT on this AOD collection (None = no mc match)
28 triggerAs=[]): # Replicate trigger match as all the ones used by PAT on these AOD collections (None = no trig.)
29 from PhysicsTools.PatAlgos.producersLayer1.genericParticleProducer_cfi import allLayer1GenericParticles
30 from PhysicsTools.PatAlgos.cleaningLayer1.genericTrackCleaner_cfi import cleanLayer1Tracks
31 # Define Modules
32 # producer
33 setattr(process, 'allLayer1' + label, allLayer1GenericParticles.clone(src = input))
34 # selector
35 setattr(process, 'selectedLayer1' + label,
36 cms.EDFilter("PATGenericParticleSelector",
37 src = cms.InputTag("allLayer1"+label),
38 cut = cms.string(selection)
39 )
40 )
41 # cleaner
42 setattr(process, 'cleanLayer1' + label, cleanLayer1Tracks.clone(src = cms.InputTag('selectedLayer1' + label)))
43 # Get them as variables, so we can put them in the sequences and/or configure them
44 l1cands = getattr(process, 'allLayer1' + label)
45 selectedL1cands = getattr(process, 'selectedLayer1' + label)
46 cleanL1cands = getattr(process, 'cleanLayer1' + label)
47 # Insert in sequence, after electrons
48 process.allLayer1Objects.replace(process.allLayer1Electrons, l1cands + process.allLayer1Electrons)
49 process.selectedLayer1Objects.replace(process.selectedLayer1Electrons, process.selectedLayer1Electrons + selectedL1cands)
50 process.cleanLayer1Objects.replace(process.cleanLayer1Electrons, process.cleanLayer1Electrons + cleanL1cands)
51 # Add to Summary Tables
52 process.aodSummary.candidates += [ input ]
53 process.allLayer1Summary.candidates += [ cms.InputTag("allLayer1"+label) ]
54 process.selectedLayer1Summary.candidates += [ cms.InputTag("selectedLayer1"+label) ]
55 process.cleanLayer1Summary.candidates += [ cms.InputTag("cleanLayer1"+label) ]
56
57 # Isolation: start with empty config
58 isoModules = []
59 runIsoDeps = { 'tracker':False, 'caloTowers':False }
60 for (source,deltaR) in isolation.items():
61 if source == 'tracker':
62 runIsoDeps['tracker'] = True
63 l1cands.isolation.tracker = cms.PSet(
64 src = cms.InputTag('pat'+label+'IsoDepositTracks'),
65 deltaR = cms.double(deltaR),
66 )
67 elif source == 'ecalTowers':
68 runIsoDeps['caloTowers'] = True
69 l1cands.isolation.ecal = cms.PSet(
70 src = cms.InputTag('pat'+label+'IsoDepositCaloTowers', 'ecal'),
71 deltaR = cms.double(deltaR),
72 )
73 elif source == 'hcalTowers':
74 runIsoDeps['caloTowers'] = True
75 l1cands.isolation.hcal = cms.PSet(
76 src = cms.InputTag('pat'+label+'IsoDepositCaloTowers', 'hcal'),
77 deltaR = cms.double(deltaR),
78 )
79 for source in isodeposits:
80 if source == 'tracker':
81 runIsoDeps['tracker'] = True
82 l1cands.isoDeposits.tracker = cms.InputTag('pat'+label+'IsoDepositTracks')
83 elif source == 'ecalTowers':
84 runIsoDeps['caloTowers'] = True
85 l1cands.isoDeposits.ecal = cms.InputTag('pat'+label+'IsoDepositCaloTowers', 'ecal')
86 elif source == 'hcalTowers':
87 runIsoDeps['caloTowers'] = True
88 l1cands.isoDeposits.hcal = cms.InputTag('pat'+label+'IsoDepositCaloTowers', 'hcal')
89 for dep in [ dep for dep,runme in runIsoDeps.items() if runme == True ]:
90 if dep == 'tracker':
91 from RecoMuon.MuonIsolationProducers.trackExtractorBlocks_cff import MIsoTrackExtractorCtfBlock
92 setattr(process, 'pat'+label+'IsoDepositTracks',
93 cms.EDProducer("CandIsoDepositProducer",
94 src = input,
95 trackType = cms.string('best'),
96 MultipleDepositsFlag = cms.bool(False),
97 ExtractorPSet = cms.PSet( MIsoTrackExtractorCtfBlock )
98 ) )
99 isoModules.append( getattr(process, 'pat'+label+'IsoDepositTracks') )
100 elif dep == 'caloTowers':
101 from RecoMuon.MuonIsolationProducers.caloExtractorByAssociatorBlocks_cff import MIsoCaloExtractorByAssociatorTowersBlock
102 setattr(process, 'pat'+label+'IsoDepositCaloTowers',
103 cms.EDProducer("CandIsoDepositProducer",
104 src = input,
105 trackType = cms.string('best'),
106 MultipleDepositsFlag = cms.bool(True),
107 ExtractorPSet = cms.PSet( MIsoCaloExtractorByAssociatorTowersBlock )
108 ) )
109 isoModules.append( getattr(process, 'pat'+label+'IsoDepositCaloTowers') )
110 for m in isoModules: process.patAODExtraReco += m
111 # MC and trigger
112 from PhysicsTools.PatAlgos.tools.jetTools import MassSearchParamVisitor;
113 if type(mcAs) != type(None): # otherwise it complains that 'None' is not a valid InputTag :-(
114 searchMC = MassSearchParamVisitor('src', mcAs);
115 process.patMCTruth.visit(searchMC)
116 modulesMC = searchMC.modules()
117 if len(modulesMC) != 1: raise RuntimeError, "Can't find MC-Truth match for '%s', or it's not unique."%(mcAs,)
118 setattr(process, 'pat'+label+'MCMatch', modulesMC[0].clone(src = input))
119 process.patMCTruth.replace( modulesMC[0], modulesMC[0] + getattr(process, 'pat'+label+'MCMatch'))
120 l1cands.addGenMatch = True
121 l1cands.genParticleMatch = cms.InputTag('pat'+label+'MCMatch')
122 if triggerAs != None and triggerAs != []:
123 modulesTR = []; labelsTR = []
124 for t in triggerAs:
125 searchTR = MassSearchParamVisitor('src', cms.InputTag(t));
126 process.patTrigMatch.visit(searchTR)
127 modulesTR += searchTR.modules()
128 if len(modulesTR) == 0: raise RuntimeError, "Can't find any trigger match among %s" % (triggerAs)
129 def ucfirst(x): return x[0].upper() + x[1:]
130 for m in modulesTR:
131 lbl = 'pat'+label+'TrigMatchAs' + ucfirst(m.label())
132 setattr(process, lbl, m.clone(src = input))
133 process.patTrigMatch.replace( m, m + getattr(process, lbl))
134 labelsTR.append (cms.InputTag(lbl))
135 l1cands.addTrigMatch = cms.bool(True)
136 l1cands.trigPrimMatch = cms.VInputTag(*labelsTR)
137
138 def makeTrackCandidates(process,
139 label='TrackCands', # output collection will be 'allLayer'+(0/1)+label , 'selectedLayer1' + label
140 tracks=cms.InputTag('generalTracks'), # input track collection
141 particleType="pi+", # particle type (for assigning a mass)
142 preselection='pt > 10', # preselection cut on candidates
143 selection='pt > 10', # Selection on PAT Layer 1 objects. The output will be 'selectedLayer1' + label
144 isolation={'tracker': 0.3, # Isolations to use ({'source':deltaR, ...}; use {} for none)
145 'ecalTowers':0.3, # 'tracker' => as muon track iso
146 'hcalTowers':0.3}, # 'ecalTowers', 'hcalTowers' => as muon iso from calo towers.
147 isodeposits=['tracker','ecalTowers','hcalTowers'], # IsoDeposits to save ([] for none)
148 mcAs=cms.InputTag("muons"), # Replicate MC match as the one used by PAT on this AOD collection (None = no mc match)
149 triggerAs=[]): # Replicate trigger match as all the ones used by PAT on these AOD collections ([] = none)
150 makeAODTrackCandidates(process, tracks=tracks, particleType=particleType, candSelection=preselection, label=label)
151 makePATTrackCandidates(process, label=label, input=cms.InputTag('patAOD' + label),
152 isolation=isolation, isodeposits=isodeposits, mcAs=mcAs, triggerAs=triggerAs, selection=selection)