Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:02

0001 from PhysicsTools.PatAlgos.tools.ConfigToolBase import *
0002 
0003 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
0004 
0005 class MakeAODTrackCandidates(ConfigToolBase):
0006 
0007     """ Create selected tracks and a candidate hypothesis on AOD:
0008     """
0009     _label='makeAODTrackCandidates'
0010     _defaultParameters=dicttypes.SortedKeysDict()
0011 
0012     def __init__(self):
0013         ConfigToolBase.__init__(self)
0014         self.addParameter(self._defaultParameters,'label','TrackCands', "output collection will be <'patAOD'+label>")
0015         self.addParameter(self._defaultParameters,'tracks',cms.InputTag('generalTracks'), 'input tracks')
0016         self.addParameter(self._defaultParameters,'particleType','pi+', 'particle type (for mass)')
0017         self.addParameter(self._defaultParameters,'candSelection','pt > 10', 'preselection cut on the candidates')
0018 
0019         self._parameters=copy.deepcopy(self._defaultParameters)
0020         self._comment = ""
0021 
0022     def getDefaultParameters(self):
0023         return self._defaultParameters
0024 
0025     def __call__(self,process,
0026                  label         = None,
0027                  tracks        = None,
0028                  particleType  = None,
0029                  candSelection = None) :
0030         if label  is None:
0031             label=self._defaultParameters['label'].value
0032         if  tracks is None:
0033             tracks=self._defaultParameters['tracks'].value
0034         if  particleType is None:
0035             particleType=self._defaultParameters['particleType'].value
0036         if  candSelection is None:
0037             candSelection=self._defaultParameters['candSelection'].value
0038         self.setParameter('label',label)
0039         self.setParameter('tracks',tracks)
0040         self.setParameter('particleType',particleType)
0041         self.setParameter('candSelection',candSelection)
0042         self.apply(process)
0043 
0044     def toolCode(self, process):
0045         label=self._parameters['label'].value
0046         tracks=self._parameters['tracks'].value
0047         particleType=self._parameters['particleType'].value
0048         candSelection=self._parameters['candSelection'].value
0049 
0050         process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi");
0051         ## add ChargedCandidateProducer from track
0052         task = getPatAlgosToolsTask(process)
0053         addToProcessAndTask('patAOD' + label + 'Unfiltered',
0054                             cms.EDProducer("ConcreteChargedCandidateProducer",
0055                                            src  = tracks,
0056                                            particleType = cms.string(particleType)),
0057                             process, task)
0058 
0059         ## add CandViewSelector with preselection string
0060         addToProcessAndTask('patAOD' + label,
0061                             cms.EDFilter("CandViewSelector",
0062                                          src = cms.InputTag('patAOD' + label + 'Unfiltered'),
0063                                          cut = cms.string(candSelection)),
0064                             process, task)
0065 
0066 makeAODTrackCandidates=MakeAODTrackCandidates()
0067 
0068 
0069 class MakePATTrackCandidates(ConfigToolBase):
0070 
0071     """ Create pat track candidates from AOD track collections:
0072     """
0073     _label='makePATTrackCandidates'
0074     _defaultParameters=dicttypes.SortedKeysDict()
0075 
0076     def __init__(self):
0077         ConfigToolBase.__init__(self)
0078         self.addParameter(self._defaultParameters,'label','TrackCands', "output will be 'all/selectedLayer1'+label")
0079         self.addParameter(self._defaultParameters,'input',cms.InputTag('patAODTrackCands'), 'name of the input collection')
0080         self.addParameter(self._defaultParameters,'selection','pt > 10', 'selection on PAT Layer 1 objects')
0081         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'])
0082         self.addParameter(self._defaultParameters,'isoDeposits',['tracker','ecalTowers','hcalTowers'], 'iso deposits')
0083         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)
0084 
0085         self._parameters=copy.deepcopy(self._defaultParameters)
0086         self._comment = ""
0087 
0088     def getDefaultParameters(self):
0089         return self._defaultParameters
0090 
0091     def __call__(self,process,
0092                  label       = None,
0093                  input       = None,
0094                  selection   = None,
0095                  isolation   = None,
0096                  isoDeposits = None,
0097                  mcAs        = None) :
0098         if label  is None:
0099             label=self._defaultParameters['label'].value
0100         if input is None:
0101             input=self._defaultParameters['input'].value
0102         if selection is None:
0103             selection=self._defaultParameters['selection'].value
0104         if isolation is None:
0105             isolation=self._defaultParameters['isolation'].value
0106         if isoDeposits is None:
0107             isoDeposits=self._defaultParameters['isoDeposits'].value
0108         if mcAs is None:
0109             mcAs=self._defaultParameters['mcAs'].value
0110         self.setParameter('label',label)
0111         self.setParameter('input',input)
0112         self.setParameter('selection',selection)
0113         self.setParameter('isolation',isolation)
0114         self.setParameter('isoDeposits',isoDeposits)
0115         self.setParameter('mcAs',mcAs,True)
0116         self.apply(process)
0117 
0118     def toolCode(self, process):
0119         label=self._parameters['label'].value
0120         input=self._parameters['input'].value
0121         selection=self._parameters['selection'].value
0122         isolation=self._parameters['isolation'].value
0123         isoDeposits=self._parameters['isoDeposits'].value
0124         mcAs=self._parameters['mcAs'].value
0125 
0126         ## add patTracks to the process
0127         from PhysicsTools.PatAlgos.producersLayer1.genericParticleProducer_cfi import patGenericParticles
0128         task = getPatAlgosToolsTask(process)
0129         addToProcessAndTask('pat' + label, patGenericParticles.clone(src = input), process, task)
0130 
0131         ## add selectedPatTracks to the process
0132         addToProcessAndTask('selectedPat' + label,
0133                             cms.EDFilter("PATGenericParticleSelector",
0134                                          src = cms.InputTag("pat"+label),
0135                                          cut = cms.string(selection)),
0136                             process, task)
0137         ## add cleanPatTracks to the process
0138         from PhysicsTools.PatAlgos.cleaningLayer1.genericTrackCleaner_cfi import cleanPatTracks
0139         addToProcessAndTask('cleanPat' + label,
0140                             cleanPatTracks.clone(src = cms.InputTag('selectedPat' + label)),
0141                             process, task)
0142 
0143         ## get them as variables, so we can put them in the sequences and/or configure them
0144         l1cands         = getattr(process, 'pat' + label)
0145         selectedL1cands = getattr(process, 'selectedPat' + label)
0146         cleanL1cands    = getattr(process, 'cleanPat' + label)
0147 
0148         ### add them to the Summary Tables
0149         #process.patCandidateSummary.candidates += [ cms.InputTag("allPat"+label) ]
0150         #process.selectedPatCandidateSummary.candidates += [ cms.InputTag("selectedPat"+label) ]
0151         #process.cleanPatCandidateSummary.candidates += [ cms.InputTag("cleanPat"+label) ]
0152 
0153         ## isolation: start with empty config
0154         if(isolation or isoDeposits):
0155             process.load("TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi")
0156             process.load("TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi")
0157             process.load("TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAny_cfi")
0158         runIsoDeps = {'tracker':False, 'caloTowers':False}
0159 
0160         for source,deltaR in isolation.items():
0161             ## loop items in isolation
0162             if(source == 'tracker'):
0163                 runIsoDeps['tracker'] = True
0164                 l1cands.userIsolation.tracker = cms.PSet(
0165                     src    = cms.InputTag('pat'+label+'IsoDepositTracks'),
0166                     deltaR = cms.double(deltaR),
0167                     )
0168             elif(source == 'ecalTowers'):
0169                 runIsoDeps['caloTowers'] = True
0170                 l1cands.userIsolation.ecal = cms.PSet(
0171                     src    = cms.InputTag('pat'+label+'IsoDepositCaloTowers', 'ecal'),
0172                     deltaR = cms.double(deltaR),
0173                     )
0174             elif(source == 'hcalTowers'):
0175                 runIsoDeps['caloTowers'] = True
0176                 l1cands.userIsolation.hcal = cms.PSet(
0177                     src    = cms.InputTag('pat'+label+'IsoDepositCaloTowers', 'hcal'),
0178                     deltaR = cms.double(deltaR),
0179                     )
0180 
0181         for source in isoDeposits:
0182             ## loop items in isoDeposits
0183             if(source == 'tracker'):
0184                 runIsoDeps['tracker'] = True
0185                 l1cands.isoDeposits.tracker = cms.InputTag('pat'+label+'IsoDepositTracks')
0186             elif(source == 'ecalTowers'):
0187                 runIsoDeps['caloTowers'] = True
0188                 l1cands.isoDeposits.ecal = cms.InputTag('pat'+label+'IsoDepositCaloTowers', 'ecal')
0189             elif(source == 'hcalTowers'):
0190                 runIsoDeps['caloTowers'] = True
0191                 l1cands.isoDeposits.hcal = cms.InputTag('pat'+label+'IsoDepositCaloTowers', 'hcal')
0192 
0193         for dep in [ dep for dep,runme in runIsoDeps.items() if runme == True ]:
0194             if(dep == 'tracker'):
0195                 from RecoMuon.MuonIsolationProducers.trackExtractorBlocks_cff import MIsoTrackExtractorCtfBlock
0196                 addToProcessAndTask('pat'+label+'IsoDepositTracks',
0197                                     cms.EDProducer("CandIsoDepositProducer",
0198                                                    src                  = input,
0199                                                    trackType            = cms.string('best'),
0200                                                    MultipleDepositsFlag = cms.bool(False),
0201                                                    ExtractorPSet        = cms.PSet( MIsoTrackExtractorCtfBlock )),
0202                                     process, task)
0203 
0204 
0205             elif(dep == 'caloTowers'):
0206                 from RecoMuon.MuonIsolationProducers.caloExtractorByAssociatorBlocks_cff import MIsoCaloExtractorByAssociatorTowersBlock
0207                 addToProcessAndTask('pat'+label+'IsoDepositCaloTowers',
0208                                     cms.EDProducer("CandIsoDepositProducer",
0209                                                    src                  = input,
0210                                                    trackType            = cms.string('best'),
0211                                                    MultipleDepositsFlag = cms.bool(True),
0212                                                    ExtractorPSet        = cms.PSet( MIsoCaloExtractorByAssociatorTowersBlock )),
0213                                     process, task)
0214 
0215         # ES
0216         process.load( 'TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff' )
0217         # MC
0218         from PhysicsTools.PatAlgos.tools.helpers import MassSearchParamVisitor
0219         if(not isinstance(mcAs, type(None))):
0220             findMatch= []
0221             findMatch.append(getattr(process, mcAs+'Match'))
0222 
0223             ## clone mc matchiong module of object mcAs and add it to the path
0224             addToProcessAndTask('pat'+label+'MCMatch', findMatch[0].clone(src = input), process, task)
0225 
0226             l1cands.addGenMatch = True
0227             l1cands.genParticleMatch = cms.InputTag('pat'+label+'MCMatch')
0228 
0229 
0230 makePATTrackCandidates=MakePATTrackCandidates()
0231 
0232 
0233 class MakeTrackCandidates(ConfigToolBase):
0234     """ Create selected tracks and a candidate hypothesis on AOD:
0235     """
0236     _label='makeTrackCandidates'
0237     _defaultParameters=dicttypes.SortedKeysDict()
0238 
0239     def __init__(self):
0240         ConfigToolBase.__init__(self)
0241         self.addParameter(self._defaultParameters,'label','TrackCands', "output collection will be <'patAOD'+label>")
0242         self.addParameter(self._defaultParameters,'tracks',cms.InputTag('generalTracks'), 'input tracks')
0243         self.addParameter(self._defaultParameters,'particleType','pi+', 'particle type (for mass)')
0244         self.addParameter(self._defaultParameters,'preselection','pt > 10', 'preselection cut on the AOD candidates')
0245         self.addParameter(self._defaultParameters,'selection','pt > 10', 'selection cut on the PAT candidates (for the selectedLayer1Candidate collection)')
0246         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'])
0247         self.addParameter(self._defaultParameters,'isoDeposits',['tracker','ecalTowers','hcalTowers'], 'iso deposits')
0248         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)
0249 
0250         self._parameters=copy.deepcopy(self._defaultParameters)
0251         self._comment = ""
0252 
0253     def getDefaultParameters(self):
0254         return self._defaultParameters
0255 
0256     def __call__(self,process,
0257                  label        = None,
0258                  tracks       = None,
0259                  particleType = None,
0260                  preselection = None,
0261                  selection    = None,
0262                  isolation    = None,
0263                  isoDeposits  = None,
0264                  mcAs         = None) :
0265         if label  is None:
0266             label=self._defaultParameters['label'].value
0267         if tracks is None:
0268             tracks=self._defaultParameters['tracks'].value
0269         if particleType is None:
0270             particleType=self._defaultParameters['particleType'].value
0271         if preselection is None:
0272             preselection=self._defaultParameters['preselection'].value
0273         if selection is None:
0274             selection=self._defaultParameters['selection'].value
0275         if isolation is None:
0276             isolation=self._defaultParameters['isolation'].value
0277         if isoDeposits is None:
0278             isoDeposits=self._defaultParameters['isoDeposits'].value
0279         if mcAs is None:
0280             mcAs=self._defaultParameters['mcAs'].value
0281         self.setParameter('label',label)
0282         self.setParameter('tracks',tracks)
0283         self.setParameter('particleType',particleType)
0284         self.setParameter('preselection',preselection)
0285         self.setParameter('selection',selection)
0286         self.setParameter('isolation',isolation)
0287         self.setParameter('isoDeposits',isoDeposits)
0288         self.setParameter('mcAs',mcAs,True)
0289         self.apply(process)
0290 
0291     def toolCode(self, process):
0292         label=self._parameters['label'].value
0293         tracks=self._parameters['tracks'].value
0294         particleType=self._parameters['particleType'].value
0295         preselection=self._parameters['preselection'].value
0296         selection=self._parameters['selection'].value
0297         isolation=self._parameters['isolation'].value
0298         isoDeposits=self._parameters['isoDeposits'].value
0299         mcAs=self._parameters['mcAs'].value
0300 
0301         makeAODTrackCandidates(process,
0302                                tracks        = tracks,
0303                                particleType  = particleType,
0304                                candSelection = preselection,
0305                                label         = label
0306                                )
0307         makePATTrackCandidates(process,
0308                                label         = label,
0309                                input         = cms.InputTag('patAOD' + label),
0310                                isolation     = isolation,
0311                                isoDeposits   = isoDeposits,
0312                                mcAs          = mcAs,
0313                                selection     = selection
0314                                )
0315 
0316 makeTrackCandidates=MakeTrackCandidates()