CMS 3D CMS Logo

Public Member Functions | Private Attributes | Static Private Attributes

cmsswVersionTools::AddJetCollection35X Class Reference

Inherits FWCore::GuiBrowsers::ConfigToolBase::ConfigToolBase.

List of all members.

Public Member Functions

def __call__
def __init__
def getDefaultParameters
def toolCode

Private Attributes

 _comment
 _parameters

Static Private Attributes

tuple _defaultParameters = dicttypes.SortedKeysDict()
string _label = 'addJetCollection35X'

Detailed Description

------------------------------------------------------------------
Add a new collection of jets. Takes the configuration from the
already configured standard jet collection as starting point;
replaces before calling addJetCollection will also affect the
new jet collections. This is a re-implementation to run the
36X version of PAT on 35X input samples.
------------------------------------------------------------------

Definition at line 261 of file cmsswVersionTools.py.


Constructor & Destructor Documentation

def cmsswVersionTools::AddJetCollection35X::__init__ (   self)

Definition at line 274 of file cmsswVersionTools.py.

00275                       :
00276         ConfigToolBase.__init__(self)
00277         self.addParameter(self._defaultParameters,'jetCollection',self._defaultValue,'Input jet collection', cms.InputTag)
00278         self.addParameter(self._defaultParameters,'algoLabel',self._defaultValue, "label to indicate the jet algorithm (e.g.'AK5')",str)
00279         self.addParameter(self._defaultParameters,'typeLabel',self._defaultValue, "label to indicate the type of constituents (e.g. 'Calo', 'Pflow', 'Jpt', ...)",str)
00280         self.addParameter(self._defaultParameters,'doJTA',True, "run b tagging sequence for new jet collection and add it to the new pat jet collection")
00281         self.addParameter(self._defaultParameters,'doBTagging',True, 'run JetTracksAssociation and JetCharge and add it to the new pat jet collection (will autom. be true if doBTagging is set to true)')
00282         self.addParameter(self._defaultParameters,'jetCorrLabel',None, "algorithm and type of JEC; use 'None' for no JEC; examples are ('AK5','Calo'), ('SC7','Calo'), ('KT4','PF')", tuple,acceptNoneValue=True)
00283         self.addParameter(self._defaultParameters,'doType1MET',True, "if jetCorrLabel is not 'None', set this to 'True' to redo the Type1 MET correction for the new jet colllection; at the moment it must be 'False' for non CaloJets otherwise the JetMET POG module crashes. ")
00284         self.addParameter(self._defaultParameters,'doL1Cleaning',True, "copy also the producer modules for cleanLayer1 will be set to 'True' automatically when doL1Counters is 'True'")
00285         self.addParameter(self._defaultParameters,'doL1Counters',False, "copy also the filter modules that accept/reject the event looking at the number of jets")
00286         self.addParameter(self._defaultParameters,'genJetCollection',cms.InputTag("ak5GenJets"), "GenJet collection to match to")
00287         self.addParameter(self._defaultParameters,'doJetID',True, "add jetId variables to the added jet collection?")
00288         self.addParameter(self._defaultParameters,'jetIdLabel',"ak5", " specify the label prefix of the xxxJetID object; in general it is the jet collection tag like ak5, kt4 sc5, aso. For more information have a look to SWGuidePATTools#add_JetCollection")
00289         self.addParameter(self._defaultParameters,'standardAlgo',"AK5", "standard algorithm label of the collection from which the clones for the new jet collection will be taken from (note that this jet collection has to be available in the event before hand)")
00290         self.addParameter(self._defaultParameters,'standardType',"Calo", "standard constituent type label of the collection from which the clones for the new jet collection will be taken from (note that this jet collection has to be available in the event before hand)")
00291 
00292         self._parameters=copy.deepcopy(self._defaultParameters)
00293         self._comment = ""


Member Function Documentation

def cmsswVersionTools::AddJetCollection35X::__call__ (   self,
  process,
  jetCollection = None,
  algoLabel = None,
  typeLabel = None,
  doJTA = None,
  doBTagging = None,
  jetCorrLabel = None,
  doType1MET = None,
  doL1Cleaning = None,
  doL1Counters = None,
  genJetCollection = None,
  doJetID = None,
  jetIdLabel = None,
  standardAlgo = None,
  standardType = None 
)

Definition at line 297 of file cmsswVersionTools.py.

00312                                            :
00313 
00314         if jetCollection  is None:
00315             jetCollection=self._defaultParameters['jetCollection'].value
00316         if algoLabel is None:
00317             algoLabel=self._defaultParameters['algoLabel'].value
00318         if typeLabel is None:
00319             typeLabel=self._defaultParameters['typeLabel'].value
00320         if doJTA is None:
00321             doJTA=self._defaultParameters['doJTA'].value
00322         if doBTagging is None:
00323             doBTagging=self._defaultParameters['doBTagging'].value
00324         if jetCorrLabel  is None:
00325             jetCorrLabel=self._defaultParameters['jetCorrLabel'].value
00326         if doType1MET  is None:
00327             doType1MET=self._defaultParameters['doType1MET'].value
00328         if doL1Cleaning is None:
00329             doL1Cleaning=self._defaultParameters['doL1Cleaning'].value
00330         if doL1Counters  is None:
00331             doL1Counters=self._defaultParameters['doL1Counters'].value
00332         if genJetCollection  is None:
00333             genJetCollection=self._defaultParameters['genJetCollection'].value
00334         if doJetID  is None:
00335             doJetID=self._defaultParameters['doJetID'].value
00336         if jetIdLabel  is None:
00337             jetIdLabel=self._defaultParameters['jetIdLabel'].value
00338         if standardAlgo is None:
00339             standardAlgo=self._defaultParameters['standardAlgo'].value
00340         if standardType is None:
00341             standardType=self._defaultParameters['standardType'].value
00342 
00343         self.setParameter('jetCollection',jetCollection)
00344         self.setParameter('algoLabel',algoLabel)
00345         self.setParameter('typeLabel',typeLabel)
00346         self.setParameter('doJTA',doJTA)
00347         self.setParameter('doBTagging',doBTagging)
00348         self.setParameter('jetCorrLabel',jetCorrLabel)
00349         self.setParameter('doType1MET',doType1MET)
00350         self.setParameter('doL1Cleaning',doL1Cleaning)
00351         self.setParameter('doL1Counters',doL1Counters)
00352         self.setParameter('genJetCollection',genJetCollection)
00353         self.setParameter('doJetID',doJetID)
00354         self.setParameter('jetIdLabel',jetIdLabel)
00355         self.setParameter('standardAlgo',standardAlgo)
00356         self.setParameter('standardType',standardType)
00357 
00358         self.apply(process)

def cmsswVersionTools::AddJetCollection35X::getDefaultParameters (   self)

Definition at line 294 of file cmsswVersionTools.py.

00295                                   :
00296         return self._defaultParameters

def cmsswVersionTools::AddJetCollection35X::toolCode (   self,
  process 
)

Definition at line 359 of file cmsswVersionTools.py.

00360                                :
00361         jetCollection=self._parameters['jetCollection'].value
00362         algoLabel=self._parameters['algoLabel'].value
00363         typeLabel=self._parameters['typeLabel'].value
00364         doJTA=self._parameters['doJTA'].value
00365         doBTagging=self._parameters['doBTagging'].value
00366         jetCorrLabel=self._parameters['jetCorrLabel'].value
00367         doType1MET =self._parameters['doType1MET'].value
00368         doL1Cleaning=self._parameters['doL1Cleaning'].value
00369         doL1Counters=self._parameters['doL1Counters'].value
00370         genJetCollection=self._parameters['genJetCollection'].value
00371         doJetID=self._parameters['doJetID'].value
00372         jetIdLabel=self._parameters['jetIdLabel'].value
00373         standardAlgo=self._parameters['standardAlgo'].value
00374         standardType=self._parameters['standardType'].value
00375 
00376         ## define common label for pre pat jet
00377         ## creation steps in makePatJets
00378         #label=standardAlgo+standardType
00379 
00380         ## create old module label from standardAlgo
00381         ## and standardType and return
00382         def oldLabel(prefix=''):
00383             return jetCollectionString(prefix, '', '')
00384 
00385         ## create new module label from old module
00386         ## label and return
00387         def newLabel(oldLabel):
00388             newLabel=oldLabel
00389             if(oldLabel.find(standardAlgo)>=0 and oldLabel.find(standardType)>=0):
00390                 oldLabel=oldLabel.replace(standardAlgo, algoLabel).replace(standardType, typeLabel)
00391             else:
00392                 oldLabel=oldLabel+algoLabel+typeLabel
00393             return oldLabel
00394 
00395         ## clone module and add it to the patDefaultSequence
00396         def addClone(hook, **replaceStatements):
00397             ## create a clone of the hook with corresponding
00398             ## parameter replacements
00399             newModule = getattr(process, hook).clone(**replaceStatements)
00400             ## add the module to the sequence
00401             addModuleToSequence(hook, newModule)
00402 
00403         ## add module to the patDefaultSequence
00404         def addModuleToSequence(hook, newModule):
00405             hookModule = getattr(process, hook)
00406             ## add the new module with standardAlgo &
00407             ## standardType replaced in module label
00408             setattr( process, newLabel(hook), newModule)
00409             ## add new module to default sequence
00410             ## just behind the hookModule
00411             process.patDefaultSequence.replace( hookModule, hookModule*newModule )
00412 
00413         print "*********************************************************************"
00414         print "NOTE TO USER: when running on 35X sample with 36X s/w versions you   "
00415         print "              need to adapt for different event contents. The        "
00416         print "              adaptations need to be made:                           "
00417         print "                                                                     "
00418         print "               - re-configuration of secondary vertex tag discrimi-  "
00419         print "                 nator information.                                  "
00420         print "                                                                     "
00421         print "               - take out soft electron tagger information, which    "
00422         print "                 is not available on 35X.                            "
00423         print "*********************************************************************"
00424 
00425         ## add a clone of patJets
00426         addClone(oldLabel(), jetSource = jetCollection)
00427         ## add a clone of selectedPatJets
00428         addClone(oldLabel('selected'), src=cms.InputTag(newLabel(oldLabel())))
00429         ## add a clone of cleanPatJets
00430         if( doL1Cleaning ):
00431             addClone(oldLabel('clean'), src=cms.InputTag(newLabel(oldLabel('selected'))))
00432         ## add a clone of countPatJets
00433         if( doL1Counters ):
00434             if( doL1Cleaning ):
00435                 addClone(oldLabel('count'), src=cms.InputTag(newLabel(oldLabel('clean'))))
00436             else:
00437                 addClone(oldLabel('count'), src=cms.InputTag(newLabel(oldLabel('selected'))))
00438 
00439         ## get attributes of new module
00440         l1Jets = getattr(process, newLabel(oldLabel()))
00441 
00442         ## add a clone of gen jet matching
00443         addClone('patJetPartonMatch', src = jetCollection)
00444         addClone('patJetGenJetMatch', src = jetCollection, matched = genJetCollection)
00445 
00446         ## add a clone of parton and flavour associations
00447         addClone('patJetPartonAssociation', jets = jetCollection)
00448         addClone('patJetFlavourAssociation', srcByReference = cms.InputTag(newLabel('patJetPartonAssociation')))
00449 
00450         ## fix label for input tag
00451         def fixInputTag(x): x.setModuleLabel(newLabel(x.moduleLabel))
00452         ## fix label for vector of input tags
00453         def fixVInputTag(x): x[0].setModuleLabel(newLabel(x[0].moduleLabel))
00454 
00455         ## provide allLayer1Jet inputs with individual labels
00456         fixInputTag(l1Jets.genJetMatch)
00457         fixInputTag(l1Jets.genPartonMatch)
00458         fixInputTag(l1Jets.JetPartonMapSource)
00459 
00460         ## make VInputTag from strings
00461         def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
00462 
00463         if (doJTA or doBTagging):
00464             ## add clone of jet track association
00465             process.load("RecoJets.JetAssociationProducers.ak5JTA_cff")
00466             from RecoJets.JetAssociationProducers.ak5JTA_cff import ak5JetTracksAssociatorAtVertex
00467             ## add jet track association module to processes
00468             jtaLabel = 'jetTracksAssociatorAtVertex'+algoLabel+typeLabel
00469             setattr( process, jtaLabel, ak5JetTracksAssociatorAtVertex.clone(jets = jetCollection) )
00470             process.makePatJets.replace(process.patJetCharge, getattr(process,jtaLabel)+process.patJetCharge)
00471             l1Jets.trackAssociationSource = cms.InputTag(jtaLabel)
00472             addClone('patJetCharge', src=cms.InputTag(jtaLabel)),
00473             fixInputTag(l1Jets.jetChargeSource)
00474         else:
00475             ## switch embedding of track association and jet
00476             ## charge estimate to 'False'
00477             l1Jets.addAssociatedTracks = False
00478             l1Jets.addJetCharge = False
00479 
00480         if (doBTagging):
00481             ## define postfixLabel
00482             postfixLabel=algoLabel+typeLabel
00483             ## add b tagging sequence
00484             (btagSeq, btagLabels) = runBTagging35X(process, jetCollection, postfixLabel)
00485             ## add b tagging sequence before running the allLayer1Jets modules
00486             process.makePatJets.replace(getattr(process,jtaLabel), getattr(process,jtaLabel)+btagSeq)
00487             ## replace corresponding tags for pat jet production
00488             l1Jets.trackAssociationSource = cms.InputTag(btagLabels['jta'])
00489             l1Jets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] )
00490             l1Jets.discriminatorSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags']  ] )
00491         else:
00492             ## switch general b tagging info switch off
00493             l1Jets.addBTagInfo = False
00494 
00495         if (doJetID):
00496             l1Jets.addJetID = cms.bool(True)
00497             jetIdLabelNew = jetIdLabel + 'JetID'
00498             l1Jets.jetIDMap = cms.InputTag( jetIdLabelNew )
00499         else :
00500             l1Jets.addJetID = cms.bool(False)
00501 
00502         if (jetCorrLabel != None):
00503             ## add clone of jet energy corrections;
00504             ## catch a couple of exceptions first
00505             if (jetCorrLabel == False ):
00506                 raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to 'None', not 'False'"
00507             if (jetCorrLabel == "None"):
00508                 raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)"
00509             ## check for the correct format
00510             if type(jetCorrLabel) != type(('AK5','Calo')):
00511                 raise ValueError, "In addJetCollection 'jetCorrLabel' must be 'None', or of type ('Algo','Type')"
00512 
00513             ## add clone of jetCorrFactors
00514             addClone('patJetCorrFactors', jetSource = jetCollection)
00515             switchJECParameters( getattr(process,newLabel('patJetCorrFactors')), jetCorrLabel[0], jetCorrLabel[1], oldAlgo='AK5',oldType='Calo' )
00516             fixVInputTag(l1Jets.jetCorrFactorsSource)
00517 
00518             ## switch type1MET corrections off for PFJets
00519             if( jetCollection.__str__().find('PFJets')>=0 ):
00520                 print '================================================='
00521                 print 'Type1MET corrections are switched off for PFJets.'
00522                 print 'of type %s%s.' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1])
00523                 print 'Users are recommened to use pfMET together with  '
00524                 print 'PFJets.'
00525                 print '================================================='
00526                 doType1MET=False
00527 
00528             ## add a clone of the type1MET correction for the new jet collection
00529             if (doType1MET):
00530                 ## in case there is no jet correction service in the paths add it
00531                 ## as L2L3 if possible, as combined from L2 and L3 otherwise
00532                 if not hasattr( process, '%s%sL2L3' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1]) ):
00533                     setattr( process, '%s%sL2L3' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1]),
00534                              cms.ESSource("JetCorrectionServiceChain",
00535                                           correctors = cms.vstring('%s%sL2Relative' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1]),
00536                                                                    '%s%sL3Absolute' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1])
00537                                                                    )
00538                                           )
00539                              )
00540                 ## add a clone of the type1MET correction
00541                 ## and the following muonMET correction
00542                 addClone('metJESCorAK5CaloJet', inputUncorJetsLabel = jetCollection.value(),
00543                          corrector = cms.string('%s%sL2L3' % (jetCorrLabel[0].swapcase(), jetCorrLabel[1]))
00544                          )
00545                 addClone('metJESCorAK5CaloJetMuons', uncorMETInputTag = cms.InputTag(newLabel('metJESCorAK5CaloJet')))
00546                 addClone('patMETs', metSource = cms.InputTag(newLabel('metJESCorAK5CaloJetMuons')))
00547                 l1MET = getattr(process, newLabel('patMETs'))
00548                 ## add new met collections output to the pat summary
00549                 process.patCandidateSummary.candidates += [ cms.InputTag(newLabel('patMETs')) ]
00550         else:
00551             ## switch jetCorrFactors off
00552             l1Jets.addJetCorrFactors = False
00553 
00554 
00555 
00556 addJetCollection35X=AddJetCollection35X()
00557 


Member Data Documentation

Definition at line 274 of file cmsswVersionTools.py.

tuple cmsswVersionTools::AddJetCollection35X::_defaultParameters = dicttypes.SortedKeysDict() [static, private]

Definition at line 273 of file cmsswVersionTools.py.

string cmsswVersionTools::AddJetCollection35X::_label = 'addJetCollection35X' [static, private]

Definition at line 272 of file cmsswVersionTools.py.

Definition at line 274 of file cmsswVersionTools.py.