CMS 3D CMS Logo

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