CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
trackTools.py
Go to the documentation of this file.
2 
3 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
4 
6 
7  """ Create selected tracks and a candidate hypothesis on AOD:
8  """
9  _label='makeAODTrackCandidates'
10  _defaultParameters=dicttypes.SortedKeysDict()
11 
12  def __init__(self):
13  ConfigToolBase.__init__(self)
14  self.addParameter(self._defaultParameters,'label','TrackCands', "output collection will be <'patAOD'+label>")
15  self.addParameter(self._defaultParameters,'tracks',cms.InputTag('generalTracks'), 'input tracks')
16  self.addParameter(self._defaultParameters,'particleType','pi+', 'particle type (for mass)')
17  self.addParameter(self._defaultParameters,'candSelection','pt > 10', 'preselection cut on the candidates')
18 
19  self._parameters=copy.deepcopy(self._defaultParameters)
20  self._comment = ""
21 
23  return self._defaultParameters
24 
25  def __call__(self,process,
26  label = None,
27  tracks = None,
28  particleType = None,
29  candSelection = None) :
30  if label is None:
31  label=self._defaultParameters['label'].value
32  if tracks is None:
33  tracks=self._defaultParameters['tracks'].value
34  if particleType is None:
35  particleType=self._defaultParameters['particleType'].value
36  if candSelection is None:
37  candSelection=self._defaultParameters['candSelection'].value
38  self.setParameter('label',label)
39  self.setParameter('tracks',tracks)
40  self.setParameter('particleType',particleType)
41  self.setParameter('candSelection',candSelection)
42  self.apply(process)
43 
44  def toolCode(self, process):
45  label=self._parameters['label'].value
46  tracks=self._parameters['tracks'].value
47  particleType=self._parameters['particleType'].value
48  candSelection=self._parameters['candSelection'].value
49 
50  process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi");
51  ## add ChargedCandidateProducer from track
52  task = getPatAlgosToolsTask(process)
53  addToProcessAndTask('patAOD' + label + 'Unfiltered',
54  cms.EDProducer("ConcreteChargedCandidateProducer",
55  src = tracks,
56  particleType = cms.string(particleType)),
57  process, task)
58 
59  ## add CandViewSelector with preselection string
60  addToProcessAndTask('patAOD' + label,
61  cms.EDFilter("CandViewSelector",
62  src = cms.InputTag('patAOD' + label + 'Unfiltered'),
63  cut = cms.string(candSelection)),
64  process, task)
65 
66 makeAODTrackCandidates=MakeAODTrackCandidates()
67 
68 
70 
71  """ Create pat track candidates from AOD track collections:
72  """
73  _label='makePATTrackCandidates'
74  _defaultParameters=dicttypes.SortedKeysDict()
75 
76  def __init__(self):
77  ConfigToolBase.__init__(self)
78  self.addParameter(self._defaultParameters,'label','TrackCands', "output will be 'all/selectedLayer1'+label")
79  self.addParameter(self._defaultParameters,'input',cms.InputTag('patAODTrackCands'), 'name of the input collection')
80  self.addParameter(self._defaultParameters,'selection','pt > 10', 'selection on PAT Layer 1 objects')
81  self.addParameter(self._defaultParameters,'isolation',{'tracker':0.3, 'ecalTowers':0.3, 'hcalTowers':0.3}, "solation to use (as 'source': value of dR)\ntracker : as muon iso from tracks\necalTowers : as muon iso from calo tower\nhcalTowers : as muon iso from calo towers",allowedValues=['tracker','ecalTowers','hcalTowers'])
82  self.addParameter(self._defaultParameters,'isoDeposits',['tracker','ecalTowers','hcalTowers'], 'iso deposits')
83  self.addParameter(self._defaultParameters,'mcAs',None, "eplicate mc match as the one used by PAT on this AOD collection (None=no mc match); choose 'photon', 'electron', 'muon', 'tau','jet', 'met' as input string",Type=str, allowedValues=['photon', 'electron', 'muon', 'tau','jet', 'met', None], acceptNoneValue = True)
84 
85  self._parameters=copy.deepcopy(self._defaultParameters)
86  self._comment = ""
87 
89  return self._defaultParameters
90 
91  def __call__(self,process,
92  label = None,
93  input = None,
94  selection = None,
95  isolation = None,
96  isoDeposits = None,
97  mcAs = None) :
98  if label is None:
99  label=self._defaultParameters['label'].value
100  if input is None:
101  input=self._defaultParameters['input'].value
102  if selection is None:
103  selection=self._defaultParameters['selection'].value
104  if isolation is None:
105  isolation=self._defaultParameters['isolation'].value
106  if isoDeposits is None:
107  isoDeposits=self._defaultParameters['isoDeposits'].value
108  if mcAs is None:
109  mcAs=self._defaultParameters['mcAs'].value
110  self.setParameter('label',label)
111  self.setParameter('input',input)
112  self.setParameter('selection',selection)
113  self.setParameter('isolation',isolation)
114  self.setParameter('isoDeposits',isoDeposits)
115  self.setParameter('mcAs',mcAs,True)
116  self.apply(process)
117 
118  def toolCode(self, process):
119  label=self._parameters['label'].value
120  input=self._parameters['input'].value
121  selection=self._parameters['selection'].value
122  isolation=self._parameters['isolation'].value
123  isoDeposits=self._parameters['isoDeposits'].value
124  mcAs=self._parameters['mcAs'].value
125 
126  ## add patTracks to the process
127  from PhysicsTools.PatAlgos.producersLayer1.genericParticleProducer_cfi import patGenericParticles
128  task = getPatAlgosToolsTask(process)
129  addToProcessAndTask('pat' + label, patGenericParticles.clone(src = input), process, task)
130 
131  ## add selectedPatTracks to the process
132  addToProcessAndTask('selectedPat' + label,
133  cms.EDFilter("PATGenericParticleSelector",
134  src = cms.InputTag("pat"+label),
135  cut = cms.string(selection)),
136  process, task)
137  ## add cleanPatTracks to the process
138  from PhysicsTools.PatAlgos.cleaningLayer1.genericTrackCleaner_cfi import cleanPatTracks
139  addToProcessAndTask('cleanPat' + label,
140  cleanPatTracks.clone(src = cms.InputTag('selectedPat' + label)),
141  process, task)
142 
143  ## get them as variables, so we can put them in the sequences and/or configure them
144  l1cands = getattr(process, 'pat' + label)
145  selectedL1cands = getattr(process, 'selectedPat' + label)
146  cleanL1cands = getattr(process, 'cleanPat' + label)
147 
148  ### add them to the Summary Tables
149  #process.patCandidateSummary.candidates += [ cms.InputTag("allPat"+label) ]
150  #process.selectedPatCandidateSummary.candidates += [ cms.InputTag("selectedPat"+label) ]
151  #process.cleanPatCandidateSummary.candidates += [ cms.InputTag("cleanPat"+label) ]
152 
153  ## isolation: start with empty config
154  if(isolation or isoDeposits):
155  process.load("TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi")
156  process.load("TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi")
157  process.load("TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAny_cfi")
158  runIsoDeps = {'tracker':False, 'caloTowers':False}
159 
160  for source,deltaR in isolation.items():
161  ## loop items in isolation
162  if(source == 'tracker'):
163  runIsoDeps['tracker'] = True
164  l1cands.userIsolation.tracker = cms.PSet(
165  src = cms.InputTag('pat'+label+'IsoDepositTracks'),
166  deltaR = cms.double(deltaR),
167  )
168  elif(source == 'ecalTowers'):
169  runIsoDeps['caloTowers'] = True
170  l1cands.userIsolation.ecal = cms.PSet(
171  src = cms.InputTag('pat'+label+'IsoDepositCaloTowers', 'ecal'),
172  deltaR = cms.double(deltaR),
173  )
174  elif(source == 'hcalTowers'):
175  runIsoDeps['caloTowers'] = True
176  l1cands.userIsolation.hcal = cms.PSet(
177  src = cms.InputTag('pat'+label+'IsoDepositCaloTowers', 'hcal'),
178  deltaR = cms.double(deltaR),
179  )
180 
181  for source in isoDeposits:
182  ## loop items in isoDeposits
183  if(source == 'tracker'):
184  runIsoDeps['tracker'] = True
185  l1cands.isoDeposits.tracker = cms.InputTag('pat'+label+'IsoDepositTracks')
186  elif(source == 'ecalTowers'):
187  runIsoDeps['caloTowers'] = True
188  l1cands.isoDeposits.ecal = cms.InputTag('pat'+label+'IsoDepositCaloTowers', 'ecal')
189  elif(source == 'hcalTowers'):
190  runIsoDeps['caloTowers'] = True
191  l1cands.isoDeposits.hcal = cms.InputTag('pat'+label+'IsoDepositCaloTowers', 'hcal')
192 
193  for dep in [ dep for dep,runme in runIsoDeps.items() if runme == True ]:
194  if(dep == 'tracker'):
195  from RecoMuon.MuonIsolationProducers.trackExtractorBlocks_cff import MIsoTrackExtractorCtfBlock
196  addToProcessAndTask('pat'+label+'IsoDepositTracks',
197  cms.EDProducer("CandIsoDepositProducer",
198  src = input,
199  trackType = cms.string('best'),
200  MultipleDepositsFlag = cms.bool(False),
201  ExtractorPSet = cms.PSet( MIsoTrackExtractorCtfBlock )),
202  process, task)
203 
204 
205  elif(dep == 'caloTowers'):
206  from RecoMuon.MuonIsolationProducers.caloExtractorByAssociatorBlocks_cff import MIsoCaloExtractorByAssociatorTowersBlock
207  addToProcessAndTask('pat'+label+'IsoDepositCaloTowers',
208  cms.EDProducer("CandIsoDepositProducer",
209  src = input,
210  trackType = cms.string('best'),
211  MultipleDepositsFlag = cms.bool(True),
212  ExtractorPSet = cms.PSet( MIsoCaloExtractorByAssociatorTowersBlock )),
213  process, task)
214 
215  # ES
216  process.load( 'TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff' )
217  # MC
218  from PhysicsTools.PatAlgos.tools.helpers import MassSearchParamVisitor
219  if(not isinstance(mcAs, type(None))):
220  findMatch= []
221  findMatch.append(getattr(process, mcAs+'Match'))
222 
223  ## clone mc matchiong module of object mcAs and add it to the path
224  addToProcessAndTask('pat'+label+'MCMatch', findMatch[0].clone(src = input), process, task)
225 
226  l1cands.addGenMatch = True
227  l1cands.genParticleMatch = cms.InputTag('pat'+label+'MCMatch')
228 
229 
230 makePATTrackCandidates=MakePATTrackCandidates()
231 
232 
234  """ Create selected tracks and a candidate hypothesis on AOD:
235  """
236  _label='makeTrackCandidates'
237  _defaultParameters=dicttypes.SortedKeysDict()
238 
239  def __init__(self):
240  ConfigToolBase.__init__(self)
241  self.addParameter(self._defaultParameters,'label','TrackCands', "output collection will be <'patAOD'+label>")
242  self.addParameter(self._defaultParameters,'tracks',cms.InputTag('generalTracks'), 'input tracks')
243  self.addParameter(self._defaultParameters,'particleType','pi+', 'particle type (for mass)')
244  self.addParameter(self._defaultParameters,'preselection','pt > 10', 'preselection cut on the AOD candidates')
245  self.addParameter(self._defaultParameters,'selection','pt > 10', 'selection cut on the PAT candidates (for the selectedLayer1Candidate collection)')
246  self.addParameter(self._defaultParameters,'isolation',{'tracker':0.3, 'ecalTowers':0.3, 'hcalTowers':0.3}, "isolation to use (as 'source': value of dR)\ntracker : as muon iso from tracks\necalTowers : as muon iso from calo tower\nhcalTowers : as muon iso from calo towers",allowedValues=['tracker','ecalTowers','hcalTowers'])
247  self.addParameter(self._defaultParameters,'isoDeposits',['tracker','ecalTowers','hcalTowers'], 'iso deposits')
248  self.addParameter(self._defaultParameters,'mcAs',None, "eplicate mc match as the one used by PAT on this AOD collection (None=no mc match); choose 'photon', 'electron', 'muon', 'tau','jet', 'met' as input string",Type=str,allowedValues=['photon', 'electron', 'muon', 'tau','jet', 'met', None], acceptNoneValue = True)
249 
250  self._parameters=copy.deepcopy(self._defaultParameters)
251  self._comment = ""
252 
254  return self._defaultParameters
255 
256  def __call__(self,process,
257  label = None,
258  tracks = None,
259  particleType = None,
260  preselection = None,
261  selection = None,
262  isolation = None,
263  isoDeposits = None,
264  mcAs = None) :
265  if label is None:
266  label=self._defaultParameters['label'].value
267  if tracks is None:
268  tracks=self._defaultParameters['tracks'].value
269  if particleType is None:
270  particleType=self._defaultParameters['particleType'].value
271  if preselection is None:
272  preselection=self._defaultParameters['preselection'].value
273  if selection is None:
274  selection=self._defaultParameters['selection'].value
275  if isolation is None:
276  isolation=self._defaultParameters['isolation'].value
277  if isoDeposits is None:
278  isoDeposits=self._defaultParameters['isoDeposits'].value
279  if mcAs is None:
280  mcAs=self._defaultParameters['mcAs'].value
281  self.setParameter('label',label)
282  self.setParameter('tracks',tracks)
283  self.setParameter('particleType',particleType)
284  self.setParameter('preselection',preselection)
285  self.setParameter('selection',selection)
286  self.setParameter('isolation',isolation)
287  self.setParameter('isoDeposits',isoDeposits)
288  self.setParameter('mcAs',mcAs,True)
289  self.apply(process)
290 
291  def toolCode(self, process):
292  label=self._parameters['label'].value
293  tracks=self._parameters['tracks'].value
294  particleType=self._parameters['particleType'].value
295  preselection=self._parameters['preselection'].value
296  selection=self._parameters['selection'].value
297  isolation=self._parameters['isolation'].value
298  isoDeposits=self._parameters['isoDeposits'].value
299  mcAs=self._parameters['mcAs'].value
300 
301  makeAODTrackCandidates(process,
302  tracks = tracks,
303  particleType = particleType,
304  candSelection = preselection,
305  label = label
306  )
307  makePATTrackCandidates(process,
308  label = label,
309  input = cms.InputTag('patAOD' + label),
310  isolation = isolation,
311  isoDeposits = isoDeposits,
312  mcAs = mcAs,
313  selection = selection
314  )
315 
316 makeTrackCandidates=MakeTrackCandidates()
def getPatAlgosToolsTask
Definition: helpers.py:13
if(conf_.getParameter< bool >("UseStripCablingDB"))
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def addToProcessAndTask
Definition: helpers.py:28