ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/additionalFiles/jetTools.py
(Generate patch)

Comparing UserCode/VHbbAnalysis/additionalFiles/jetTools.py (file contents):
Revision 1.2 by arizzi, Fri Mar 30 18:23:41 2012 UTC vs.
Revision 1.3 by arizzi, Wed May 9 19:53:55 2012 UTC

# Line 23 | Line 23 | class RunBTagging(ConfigToolBase):
23          self.addParameter(self._defaultParameters,'jetCollection',self._defaultValue, 'input jet collection',Type=cms.InputTag)
24          self.addParameter(self._defaultParameters,'label',self._defaultValue, 'postfix label to identify new sequence/modules', Type=str)
25          self.addParameter(self._defaultParameters,'postfix',"", "postfix of default sequence (do not confuse with 'label')")
26 +        self.addParameter(self._defaultParameters,'btagInfo',['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],"input btag info",allowedValues=['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],Type=list)
27 +        self.addParameter(self._defaultParameters,'btagdiscriminators',['jetBProbabilityBJetTags', 'jetProbabilityBJetTags','trackCountingHighPurBJetTags','trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],"input btag discriminators", allowedValues=['jetBProbabilityBJetTags', 'jetProbabilityBJetTags', 'trackCountingHighPurBJetTags', 'trackCountingHighEffBJetTags', 'simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],Type=list)
28          self._parameters=copy.deepcopy(self._defaultParameters)
29          self._comment = ""
30  
31      def getDefaultParameters(self):
32          return self._defaultParameters
33  
34 +
35      def __call__(self,process,
36 <                 jetCollection     = None,
37 <                 label             = None,
38 <                 postfix           = None) :
36 >                 jetCollection      = None,
37 >                 label              = None,
38 >                 postfix            = None,
39 >                 btagInfo           = None,
40 >                 btagdiscriminators = None) :
41 >
42 >
43 >
44          if  jetCollection is None:
45              jetCollection=self._defaultParameters['jetCollection'].value
46          if  label is None:
47              label=self._defaultParameters['label'].value
48 <        if postfix  is None:
48 >        if  postfix  is None:
49              postfix=self._defaultParameters['postfix'].value
50 +        if  btagInfo  is None:
51 +            btagInfo=self._defaultParameters['btagInfo'].value
52 +        if  btagdiscriminators is None:
53 +            btagdiscriminators=self._defaultParameters['btagdiscriminators'].value
54 +
55 +
56 +
57          self.setParameter('jetCollection',jetCollection)
58          self.setParameter('label',label)
59          self.setParameter('postfix',postfix)
60 +        self.setParameter('btagInfo',btagInfo)
61 +        self.setParameter('btagdiscriminators',btagdiscriminators)
62 +
63  
64          return self.apply(process)
65          
# Line 49 | Line 67 | class RunBTagging(ConfigToolBase):
67          jetCollection=self._parameters['jetCollection'].value
68          label=self._parameters['label'].value
69          postfix=self._parameters['postfix'].value
70 +        btagInfo=self._parameters['btagInfo'].value
71 +        btagdiscriminators=self._parameters['btagdiscriminators'].value
72 +
73  
74          if hasattr(process, "addAction"):
75              process.disableRecording()
# Line 89 | Line 110 | class RunBTagging(ConfigToolBase):
110          ipTILabel = 'impactParameterTagInfos'     + label + postfix
111          svTILabel = 'secondaryVertexTagInfos'     + label + postfix
112          ivfTILabel = 'inclusiveSecondaryVertexFinderTagInfos'     + label + postfix
113 <        #nvTILabel = ''     + label + postfix
113 >        nvTILabel = 'secondaryVertexNegativeTagInfos'     + label + postfix
114          seTILabel = 'softElectronTagInfos'        + label + postfix
115          smTILabel = 'softMuonTagInfos'            + label + postfix
116 <    
117 <        ## produce tag infos
118 <        setattr( process, ipTILabel, btag.impactParameterTagInfos.clone(jetTracks = cms.InputTag(jtaLabel)) )
119 <        setattr( process, svTILabel, btag.secondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
120 <        setattr( process, ivfTILabel, btag.inclusiveSecondaryVertexFinderTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
116 >
117 >
118 >        
119 >        #setattr( process, ipTILabel, btag.impactParameterTagInfos.clone(jetTracks = cms.InputTag(jtaLabel)) )
120 >        #setattr( process, svTILabel, btag.secondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
121          #setattr( process, nvTILabel, nbtag.secondaryVertexNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
122 <        setattr( process, seTILabel, btag.softElectronTagInfos.clone(jets = jetCollection) )
123 <        setattr( process, smTILabel, btag.softMuonTagInfos.clone(jets = jetCollection) )
122 >        #setattr( process, seTILabel, btag.softElectronTagInfos.clone(jets = jetCollection) )
123 >        #setattr( process, smTILabel, btag.softMuonTagInfos.clone(jets = jetCollection) )
124  
125          ## make VInputTag from strings
126          def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
127      
128          ## produce btags
129 <        setattr( process, 'jetBProbabilityBJetTags'+label+postfix, btag.jetBProbabilityBJetTags.clone(tagInfos = vit(ipTILabel)) )
130 <        setattr( process, 'jetProbabilityBJetTags'+label+postfix, btag.jetProbabilityBJetTags.clone (tagInfos = vit(ipTILabel)) )
131 <        setattr( process, 'trackCountingHighPurBJetTags'+label+postfix, btag.trackCountingHighPurBJetTags.clone(tagInfos = vit(ipTILabel)) )
132 <        setattr( process, 'trackCountingHighEffBJetTags'+label+postfix, btag.trackCountingHighEffBJetTags.clone(tagInfos = vit(ipTILabel)) )
133 <        setattr( process, 'simpleSecondaryVertexHighEffBJetTags'+label+postfix, btag.simpleSecondaryVertexHighEffBJetTags.clone(tagInfos = vit(svTILabel)) )
134 <        setattr( process, 'simpleSecondaryVertexHighPurBJetTags'+label+postfix, btag.simpleSecondaryVertexHighPurBJetTags.clone(tagInfos = vit(svTILabel)) )
135 <        #setattr( process, 'simpleSecondaryVertexNegativeBJetTags'+label+postfix, nbtag.simpleSecondaryVertexNegativeBJetTags.clone(tagInfos = vit(nvTILabel)) )
136 <        setattr( process, 'combinedSecondaryVertexBJetTags'+label+postfix, btag.combinedSecondaryVertexBJetTags.clone(tagInfos = vit(ipTILabel, svTILabel)) )
137 <        setattr( process, 'combinedInclusiveSecondaryVertexBJetTags'+label+postfix, btag.combinedInclusiveSecondaryVertexBJetTags.clone(tagInfos = vit(ipTILabel, ivfTILabel)) )
138 <        setattr( process, 'combinedMVABJetTags'+label+postfix, btag.combinedMVABJetTags.clone(tagInfos = vit(ipTILabel, ivfTILabel,smTILabel,seTILabel)) )
139 <        setattr( process, 'combinedSecondaryVertexMVABJetTags'+label+postfix, btag.combinedSecondaryVertexMVABJetTags.clone(tagInfos = vit(ipTILabel, svTILabel)) )
140 <        #setattr( process, 'softElectronByPtBJetTags'+label+postfix, btag.softElectronByPtBJetTags.clone(tagInfos = vit(seTILabel)) )
141 <        #setattr( process, 'softElectronByIP3dBJetTags'+label+postfix, btag.softElectronByIP3dBJetTags.clone(tagInfos = vit(seTILabel)) )
142 <        setattr( process, 'softMuonBJetTags'+label+postfix, btag.softMuonBJetTags.clone(tagInfos = vit(smTILabel)) )
143 <        setattr( process, 'softMuonByPtBJetTags'+label+postfix, btag.softMuonByPtBJetTags.clone(tagInfos = vit(smTILabel)) )
144 <        setattr( process, 'softMuonByIP3dBJetTags'+label+postfix, btag.softMuonByIP3dBJetTags.clone(tagInfos = vit(smTILabel)) )
145 <        
129 >        print      
130 >        print "The btaginfo below will be written to the jet collection in the PATtuple (default is all, see PatAlgos/PhysicsTools/python/tools/jetTools.py)"
131 >        print
132 >        for TagInfo in btagInfo:
133 >                print TagInfo
134 >
135 >                if TagInfo=='impactParameterTagInfos':
136 >                        setattr( process, ipTILabel, btag.impactParameterTagInfos.clone(jetTracks = cms.InputTag(jtaLabel)) )
137 >                if TagInfo=='secondaryVertexTagInfos':
138 >                        setattr( process, svTILabel, btag.secondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
139 >                if TagInfo=='softMuonTagInfos':
140 >                        setattr( process, smTILabel, btag.softMuonTagInfos.clone(jets = jetCollection) )
141 >                if TagInfo=='softElectronTagInfos':
142 >                        setattr( process, seTILabel, btag.softElectronTagInfos.clone(jets = jetCollection) )
143 >                if TagInfo=='secondaryVertexNegativeTagInfos':
144 >                        setattr( process, nvTILabel, btag.secondaryVertexNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
145 >                if TagInfo=='inclusiveSecondaryVertexFinderTagInfos':
146 >                        setattr( process, ivfTILabel, btag.inclusiveSecondaryVertexFinderTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
147 >
148 >        print
149 >        print "The bdiscriminators below will be written to the jet collection in the PATtuple (default is all, see PatAlgos/PhysicsTools/python/tools/jetTools.py)"
150 >        for tag in btagdiscriminators:
151 >                print  tag
152 >                if tag == 'jetBProbabilityBJetTags' or tag == 'jetProbabilityBJetTags' or tag == 'trackCountingHighPurBJetTags' or tag == 'trackCountingHighEffBJetTags' or tag == 'negativeTrackCountingHighEffJetTags' or  tag =='negativeTrackCountingHighPurJetTags' :
153 >                        tagInfo=getattr(btag,tag).clone(tagInfos = vit(ipTILabel))
154 >                        setattr(process, tag+label+postfix, tagInfo)
155 >
156 >                if tag == 'simpleSecondaryVertexHighEffBJetTags' or tag == 'simpleSecondaryVertexHighPurBJetTags':
157 > #                       tagInfo=getattr(btag,tag).clone(tagInfos = vit(ipTILabel,svTILabel))
158 >                        tagInfo=getattr(btag,tag).clone(tagInfos = vit(svTILabel))
159 >                        setattr(process, tag+label+postfix, tagInfo)
160 >
161 >                if tag == 'combinedSecondaryVertexBJetTags' or tag == 'combinedSecondaryVertexMVABJetTags':
162 >                        tagInfo=getattr(btag,tag).clone(tagInfos = vit(ipTILabel,svTILabel))
163 >                        setattr(process, tag+label+postfix, tagInfo)
164 >
165 >                if tag == 'softMuonBJetTags' or tag == 'softMuonByPtBJetTags' or tag == 'softMuonByIP3dBJetTags' :
166 >                        tagInfo=getattr(btag,tag).clone(tagInfos = vit(smTILabel))
167 >                        setattr(process, tag+label+postfix, tagInfo)
168 >
169 >                if tag == 'simpleSecondaryVertexNegativeHighEffBJetTags' or tag == 'simpleSecondaryVertexNegativeHighPurBJetTags':
170 >                        tagInfo=getattr(btag,tag).clone(tagInfos = vit(nvTILabel))
171 >                        setattr(process, tag+label+postfix, tagInfo)
172 >
173 >
174 >                if tag == 'combinedInclusiveSecondaryVertexBJetTags' :
175 >                        tagInfo=getattr(btag,tag).clone(tagInfos = vit(ipTILabel,ivfTILabel))
176 >                        setattr(process, tag+label+postfix, tagInfo)
177 >
178 >                if tag == 'combinedMVABJetTags' :
179 >                        tagInfo=getattr(btag,tag).clone(tagInfos = vit(ipTILabel, ivfTILabel,smTILabel,seTILabel))
180 >                        setattr(process, tag+label+postfix, tagInfo)
181 >            
182 >
183 >
184          ## define vector of (output) labels
185 <        labels = { 'jta'      : jtaLabel,
186 < #                   'tagInfos' : (ipTILabel,svTILabel,seTILabel,smTILabel),
187 <                   'tagInfos' : (ipTILabel,svTILabel,ivfTILabel,smTILabel,seTILabel),
188 <                   'jetTags'  : [ (x + label+postfix) for x in ('jetBProbabilityBJetTags',
189 <                                                                'jetProbabilityBJetTags',
190 <                                                                'trackCountingHighPurBJetTags',
191 <                                                                'trackCountingHighEffBJetTags',
192 <                                                                #'simpleSecondaryVertexNegativeBJetTags',
134 <                                                                'simpleSecondaryVertexHighEffBJetTags',
135 <                                                                'simpleSecondaryVertexHighPurBJetTags',
136 <                                                                'combinedSecondaryVertexBJetTags',
137 <                                                                'combinedInclusiveSecondaryVertexBJetTags',
138 <                                                                'combinedMVABJetTags',
139 <                                                                'combinedSecondaryVertexMVABJetTags',
140 <                                                                #'softElectronByPtBJetTags',
141 <                                                                #'softElectronByIP3dBJetTags',
142 <                                                                'softMuonBJetTags',
143 <                                                                'softMuonByPtBJetTags',
144 <                                                                'softMuonByIP3dBJetTags'
145 <                                                        )
146 <                                  ]
185 >        labels = { 'jta'      : jtaLabel,
186 >                   #'tagInfos' : (ipTILabel,svTILabel,seTILabel,smTILabel),
187 >                #'tagInfos' : (ipTILabel,svTILabel,smTILabel),
188 >                #'tagInfos' : [ for y in btagInfo],
189 >                 'tagInfos' : [(y + label + postfix) for y in btagInfo],
190 >                #'tagInfos' : (ipTILabel,svTILabel,smTILabel),
191 >                'jetTags'  : [ (x + label+postfix) for x in btagdiscriminators]
192 >
193                     }
194 <        
194 >
195 >
196 >
197 >
198          ## extend an existing sequence by otherLabels
199          def mkseq(process, firstlabel, *otherlabels):
200              seq = getattr(process, firstlabel)
# Line 157 | Line 206 | class RunBTagging(ConfigToolBase):
206          ## add b tags to the process
207          setattr( process, 'btaggingJetTags'+label+postfix,  mkseq(process, *(labels['jetTags'])  ) )
208          ## add a combined sequence to the process
209 <        seq = mkseq(process, 'btaggingTagInfos'+label+postfix, 'btaggingJetTags' + label + postfix)
209 >        seq = mkseq(process, 'btaggingTagInfos'+label+postfix, 'btaggingJetTags' + label + postfix)
210          setattr( process, 'btagging'+label+postfix, seq )
211          ## return the combined sequence and the labels defined above
212  
# Line 166 | Line 215 | class RunBTagging(ConfigToolBase):
215              action=self.__copy__()
216              process.addAction(action)
217          return (seq, labels)
218 <      
218 >
219   runBTagging=RunBTagging()
220  
221  
# Line 179 | Line 228 | class AddJetCollection(ConfigToolBase):
228      """
229      _label='addJetCollection'
230      _defaultParameters=dicttypes.SortedKeysDict()
231 +
232      def __init__(self):
233          ConfigToolBase.__init__(self)
234          self.addParameter(self._defaultParameters,'jetCollection',self._defaultValue,'Input jet collection', cms.InputTag)
235          self.addParameter(self._defaultParameters,'algoLabel',self._defaultValue, "label to indicate the jet algorithm (e.g.'AK5')",str)
236          self.addParameter(self._defaultParameters,'typeLabel',self._defaultValue, "label to indicate the type of constituents (e.g. 'Calo', 'Pflow', 'Jpt', ...)",str)
237 +        self.addParameter(self._defaultParameters,'btagInfo',['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],"input btag info",allowedValues=['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],Type=list)
238 + #        self.addParameter(self._defaultParameters,'btagInfo',['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos'],"input btag info",allowedValues=['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos'],Type=list)
239 + #        self.addParameter(self._defaultParameters,'btagdiscriminators',['jetBProbabilityBJetTags', 'jetProbabilityBJetTags','trackCountingHighPurBJetTags','trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags'],"input btag discriminators", allowedValues=['jetBProbabilityBJetTags', 'jetProbabilityBJetTags','trackCountingHighPurBJetTags', 'trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags'],Type=list)
240 +        self.addParameter(self._defaultParameters,'btagdiscriminators',['jetBProbabilityBJetTags', 'jetProbabilityBJetTags','trackCountingHighPurBJetTags','trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],"input btag discriminators", allowedValues=['jetBProbabilityBJetTags', 'jetProbabilityBJetTags', 'trackCountingHighPurBJetTags', 'trackCountingHighEffBJetTags', 'simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],Type=list)
241          self.addParameter(self._defaultParameters,'doJTA',True, "run b tagging sequence for new jet collection and add it to the new pat jet collection")
242 <        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)')        
242 >        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)')
243          self.addParameter(self._defaultParameters,'jetCorrLabel',None, "payload and list of new jet correction labels, such as (\'AK5Calo\',[\'L2Relative\', \'L3Absolute\'])", tuple,acceptNoneValue=True )
244          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. ")
245          self.addParameter(self._defaultParameters,'doL1Cleaning',True, "copy also the producer modules for cleanLayer1 will be set to 'True' automatically when doL1Counters is 'True'")
# Line 193 | Line 247 | class AddJetCollection(ConfigToolBase):
247          self.addParameter(self._defaultParameters,'genJetCollection',cms.InputTag("ak5GenJets"), "GenJet collection to match to")
248          self.addParameter(self._defaultParameters,'doJetID',True, "add jetId variables to the added jet collection?")
249          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")
250 <        self.addParameter(self._defaultParameters, 'outputModule', "out", "Output module label, empty label indicates no output, default: out")
251 <        
250 >        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)")
251 >        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)")
252 >        self.addParameter(self._defaultParameters, 'outputModules', ['out'], "output module labels, empty list of label indicates no output, default: ['out']")
253 >
254          self._parameters=copy.deepcopy(self._defaultParameters)
255          self._comment = ""
256 <        
256 >
257      def getDefaultParameters(self):
258          return self._defaultParameters
259  
260      def __call__(self,process,
261 +
262                   jetCollection      = None,
263                   algoLabel          = None,
264                   typeLabel          = None,
# Line 214 | Line 271 | class AddJetCollection(ConfigToolBase):
271                   genJetCollection   = None,
272                   doJetID            = None,
273                   jetIdLabel         = None,
274 <                 outputModule       = None):
275 <
274 >                 outputModule       = None,
275 >                 outputModules      = None,
276 >                 btagInfo           = None,
277 >                 btagdiscriminators = None
278 >                                      ):
279 >
280 >        ## stop processing if 'outputModule' exists and show the new alternative
281 >        if  not outputModule is None:
282 >            depricatedOptionOutputModule(self)
283          if jetCollection  is None:
284              jetCollection=self._defaultParameters['jetCollection'].value
285          if algoLabel is None:
# Line 240 | Line 304 | class AddJetCollection(ConfigToolBase):
304              doJetID=self._defaultParameters['doJetID'].value
305          if jetIdLabel  is None:
306              jetIdLabel=self._defaultParameters['jetIdLabel'].value
307 <        if outputModule is None:
308 <            outputModule=self._defaultParameters['outputModule'].value    
307 >        if outputModules is None:
308 >            outputModules=self._defaultParameters['outputModules'].value    
309 >        if  btagInfo is None:
310 >            btagInfo=self._defaultParameters['btagInfo'].value
311 >        if  btagdiscriminators is None:
312 >            btagdiscriminators=self._defaultParameters['btagdiscriminators'].value
313  
314          self.setParameter('jetCollection',jetCollection)
315          self.setParameter('algoLabel',algoLabel)
# Line 255 | Line 323 | class AddJetCollection(ConfigToolBase):
323          self.setParameter('genJetCollection',genJetCollection)
324          self.setParameter('doJetID',doJetID)
325          self.setParameter('jetIdLabel',jetIdLabel)
326 <        self.setParameter('outputModule',outputModule)
327 <  
326 >        self.setParameter('outputModules',outputModules)
327 >        self.setParameter('btagInfo',btagInfo)
328 >        self.setParameter('btagdiscriminators',btagdiscriminators)
329 >
330          self.apply(process)
331          
332      def toolCode(self, process):        
333 +
334          jetCollection=self._parameters['jetCollection'].value
335          algoLabel=self._parameters['algoLabel'].value
336          typeLabel=self._parameters['typeLabel'].value
# Line 272 | Line 343 | class AddJetCollection(ConfigToolBase):
343          genJetCollection=self._parameters['genJetCollection'].value
344          doJetID=self._parameters['doJetID'].value
345          jetIdLabel=self._parameters['jetIdLabel'].value
346 <        outputModule=self._parameters['outputModule'].value
346 >        outputModules=self._parameters['outputModules'].value
347 >        btagInfo=self._parameters['btagInfo'].value
348 >        btagdiscriminators=self._parameters['btagdiscriminators'].value
349 >
350  
351          ## create old module label from standardAlgo
352          ## and standardType and return
# Line 302 | Line 376 | class AddJetCollection(ConfigToolBase):
376              setattr( process, newLabel(hook), newModule)
377              ## add new module to default sequence
378              ## just behind the hookModule
379 <            process.patDefaultSequence.replace( hookModule, hookModule*newModule )        
379 >            process.patDefaultSequence.replace( hookModule, hookModule*newModule )
380  
381          ## add a clone of patJets
382          addClone(oldLabel(), jetSource = jetCollection)
# Line 363 | Line 437 | class AddJetCollection(ConfigToolBase):
437              ## define postfixLabel
438              postfixLabel=algoLabel+typeLabel
439              ## add b tagging sequence
440 <            (btagSeq, btagLabels) = runBTagging(process, jetCollection, postfixLabel)
440 >            (btagSeq, btagLabels) = runBTagging(process, jetCollection, postfixLabel,"", btagInfo,btagdiscriminators)
441              ## add b tagging sequence before running the allLayer1Jets modules
442              process.patDefaultSequence.replace(getattr(process,jtaLabel), getattr(process,jtaLabel)+btagSeq)
443              ## replace corresponding tags for pat jet production
# Line 374 | Line 448 | class AddJetCollection(ConfigToolBase):
448              ## switch general b tagging info switch off
449              l1Jets.addBTagInfo = False
450              ## adjust output
451 <            if outputModule is not '':                
452 <                getattr(process, outputModule).outputCommands.append("drop *_"+newLabel(oldLabel('selected'))+"_tagInfos_*")
451 >            if len(outputModules) > 0:
452 >                for outMod in outputModules:
453 >                    if hasattr(process,outMod):
454 >                        getattr(process,outMod).outputCommands.append("drop *_"+newLabel(oldLabel('selected'))+"_tagInfos_*")
455 >                    else:
456 >                        raise KeyError, "process has no OutModule named", outMod
457  
458          if (doJetID):
459              l1Jets.addJetID = cms.bool(True)
# Line 398 | Line 476 | class AddJetCollection(ConfigToolBase):
476              ## add clone of jetCorrFactors
477              addClone('patJetCorrFactors', src = jetCollection)
478              switchJetCorrLevels(process, jetCorrLabel = jetCorrLabel, postfix=algoLabel+typeLabel)
401            #getattr(process,newLabel('patJetCorrFactors')).payload = jetCorrLabel[0]
402            #getattr(process,newLabel('patJetCorrFactors')).levels = jetCorrLabel[1]
479              getattr(process, newLabel('patJets')).jetCorrFactorsSource = cms.VInputTag(  cms.InputTag(newLabel('patJetCorrFactors')) )
480          
481 <            ## switch type1MET corrections off for PFJets or JPTJets
482 <            if ( jetCollection.getModuleLabel().find('CaloJets')<0 ):
483 <                print '================================================='
484 <                print 'Type1MET corrections are switched off for other  '
485 <                print 'jet types but CaloJets. Users are recommened to  '
486 <                print 'use pfMET together with PFJets & tcMET together  '
487 <                print 'with JPT jets.                                   '
488 <                print '================================================='
481 >            ## find out type of jet collection, switch type1MET corrections off for JPTJets
482 >            jetCollType = ''
483 >            if   ( 'CaloJets' in jetCollection.getModuleLabel() ):
484 >                jetCollType = 'Calo'
485 >            elif ( 'PFJets' in jetCollection.getModuleLabel() or jetCollection.getModuleLabel().startswith('pfNo') or jetCollection.getModuleLabel() == 'particleFlow'):
486 >                jetCollType = 'PF'
487 >            else:
488 >                print '============================================='
489 >                print 'Type1MET corrections are switched off for    '
490 >                print 'JPT Jets. Users are recommened to use tcMET  '
491 >                print 'together with JPT jets.                      '
492 >                print '============================================='
493                  doType1MET=False
494  
495              ## add a clone of the type1MET correction for the new jet collection
496              if (doType1MET):
497 <                ## in case there is no jet correction service in the paths add it
498 <                ## as L2L3 if possible, as combined from L2 and L3 otherwise
499 <                if not hasattr( process, '%sL2L3' % (jetCollection.getModuleLabel().replace("Jets", "")) ):
500 <                    setattr( process, '%sL2L3' % (jetCollection.getModuleLabel().replace("Jets", "")),
501 <                             cms.ESSource("JetCorrectionServiceChain",
502 <                                          correctors = cms.vstring('%sL2Relative' % (jetCollection.getModuleLabel().replace("Jets", "")),
503 <                                                                   '%sL3Absolute' % (jetCollection.getModuleLabel().replace("Jets", ""))
504 <                                                                   )
505 <                                           )
506 <                             )                
507 <                ## add a clone of the type1MET correction
508 <                ## and the following muonMET correction
509 <                addClone('metJESCorAK5CaloJet', inputUncorJetsLabel = jetCollection.value(),
510 <                         corrector = cms.string('%sL2L3' % (jetCollection.getModuleLabel().replace("Jets", "")))
511 <                         )                    
512 <                addClone('metJESCorAK5CaloJetMuons', uncorMETInputTag = cms.InputTag(newLabel('metJESCorAK5CaloJet')))
513 <                addClone('patMETs', metSource = cms.InputTag(newLabel('metJESCorAK5CaloJetMuons')))
514 <                l1MET = getattr(process, newLabel('patMETs'))
515 <                ## add new met collections output to the pat summary
516 <                process.patCandidateSummary.candidates += [ cms.InputTag(newLabel('patMETs')) ]
497 >                ## create jet correctors for MET corrections
498 >                from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL1Fastjet, ak5PFL1Offset, ak5PFL2Relative, ak5PFL3Absolute, ak5PFResidual
499 >                setattr(process, jetCorrLabel[0]+'L1FastJet'   , ak5PFL1Fastjet.clone ( algorithm=jetCorrLabel[0]
500 >                                                                                      , srcRho=cms.InputTag(newLabel('kt6'+jetCollType+'Jets'),'rho') ) )
501 >                setattr(process, jetCorrLabel[0]+'L1Offset'    , ak5PFL1Offset.clone  ( algorithm=jetCorrLabel[0] ) )
502 >                setattr(process, jetCorrLabel[0]+'L2Relative'  , ak5PFL2Relative.clone( algorithm=jetCorrLabel[0] ) )
503 >                setattr(process, jetCorrLabel[0]+'L3Absolute'  , ak5PFL3Absolute.clone( algorithm=jetCorrLabel[0] ) )
504 >                setattr(process, jetCorrLabel[0]+'L2L3Residual', ak5PFResidual.clone  ( algorithm=jetCorrLabel[0] ) )
505 >                ## combinded corrections
506 >                setattr(process, jetCorrLabel[0]+'CombinedCorrector', cms.ESProducer( 'JetCorrectionESChain'
507 >                                                                                  , correctors = cms.vstring() ) )
508 >                
509 >                for corrLbl in jetCorrLabel[1]:
510 >                    if corrLbl != 'L1FastJet' and corrLbl != 'L1Offset' and corrLbl != 'L2Relative' and corrLbl != 'L3Absolute' and corrLbl != 'L2L3Residual':
511 >                        print '========================================='
512 >                        print ' Type1MET corrections are currently only  '
513 >                        print ' supported for the following corrections: '
514 >                        print '   - L1FastJet'
515 >                        print '   - L1Offset'
516 >                        print '   - L2Relative'
517 >                        print '   - L3Absolute'
518 >                        print '   - L2L3Residual'
519 >                        print ' But given was:'
520 >                        print '   -', corrLbl
521 >                        print '============================================='
522 >                        raise ValueError, 'unsupported JEC for TypeI MET correction: '+corrLbl
523 >                    else:
524 >                        getattr(process, jetCorrLabel[0]+'CombinedCorrector').correctors.append(jetCorrLabel[0]+corrLbl)
525 >
526 >                ## configuration of MET corrections
527 >                if jetCollType == 'Calo':
528 >                    from JetMETCorrections.Type1MET.caloMETCorrections_cff import caloJetMETcorr,caloType1CorrectedMet,caloType1p2CorrectedMet,produceCaloMETCorrections
529 >                    
530 >                    setattr(process,jetCorrLabel[0]+'JetMETcorr',   caloJetMETcorr.clone(srcMET       = "corMetGlobalMuons"))
531 >                    setattr(process,jetCorrLabel[0]+'Type1CorMet',  caloType1CorrectedMet.clone(src   = "corMetGlobalMuons"))
532 >                    setattr(process,jetCorrLabel[0]+'Type1p2CorMet',caloType1p2CorrectedMet.clone(src = "corMetGlobalMuons"))
533 >                    
534 >                    getattr(process,jetCorrLabel[0]+'JetMETcorr'   ).src          = cms.InputTag(jetCollection.getModuleLabel())
535 >                    if ('L1FastJet' in jetCorrLabel[1] or 'L1Fastjet' in jetCorrLabel[1]):
536 >                        getattr(process,jetCorrLabel[0]+'JetMETcorr'   ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1FastJet')
537 >                    elif ('L1Offset' in jetCorrLabel[1]):
538 >                        getattr(process,jetCorrLabel[0]+'JetMETcorr'   ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1Offset')
539 >                    else:
540 >                        getattr(process,jetCorrLabel[0]+'JetMETcorr'   ).offsetCorrLabel = cms.string('')
541 >                    getattr(process,jetCorrLabel[0]+'JetMETcorr'   ).jetCorrLabel = cms.string(jetCorrLabel[0]+'CombinedCorrector')
542 >
543 >                    getattr(process,jetCorrLabel[0]+'Type1CorMet'  ).srcType1Corrections = cms.VInputTag(
544 >                        cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'type1')
545 >                        )
546 >                    
547 >                    getattr(process,jetCorrLabel[0]+'Type1p2CorMet').srcType1Corrections = cms.VInputTag(
548 >                        cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'type1')
549 >                        )
550 >                    getattr(process,jetCorrLabel[0]+'Type1p2CorMet').srcUnclEnergySums = cms.VInputTag(
551 >                        cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'type2'),
552 >                        cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'offset'),
553 >                        cms.InputTag('muonCaloMETcorr')
554 >                        )
555 >
556 >                    ## add MET corrections to sequence
557 >                    addClone('patMETs', metSource = cms.InputTag(jetCorrLabel[0]+'Type1CorMet'))
558 >                    
559 >                    setattr(process,'produce'+jetCorrLabel[0]+'METCorrections',produceCaloMETCorrections.copy())
560 >                    getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'caloJetMETcorr'),         getattr(process,jetCorrLabel[0]+'JetMETcorr'))
561 >                    getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'caloType1CorrectedMet'),  getattr(process,jetCorrLabel[0]+'Type1CorMet'))
562 >                    getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'caloType1p2CorrectedMet'),getattr(process,jetCorrLabel[0]+'Type1p2CorMet'))
563 >                    process.patDefaultSequence.replace( getattr(process,newLabel('patMETs')),
564 >                                                        getattr(process,'produce'+jetCorrLabel[0]+'METCorrections')
565 >                                                        *getattr(process,newLabel('patMETs')) )                    
566 >                elif jetCollType == 'PF':
567 >                    from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfCandsNotInJet,pfJetMETcorr,pfCandMETcorr,pfType1CorrectedMet,pfType1p2CorrectedMet,producePFMETCorrections
568 >                    setattr(process,jetCorrLabel[0]+'CandsNotInJet',pfCandsNotInJet.clone(topCollection = jetCollection))
569 >                    setattr(process,jetCorrLabel[0]+'JetMETcorr',   pfJetMETcorr.clone(src              = jetCollection))
570 >                    setattr(process,jetCorrLabel[0]+'CandMETcorr',  pfCandMETcorr.clone(src             = cms.InputTag(jetCorrLabel[0]+'CandsNotInJet')))
571 >                    setattr(process,jetCorrLabel[0]+'Type1CorMet',  pfType1CorrectedMet.clone())
572 >                    setattr(process,jetCorrLabel[0]+'Type1p2CorMet',pfType1p2CorrectedMet.clone())
573 >
574 >                    if ('L1FastJet' in jetCorrLabel[1] or 'L1Fastjet' in jetCorrLabel[1]):
575 >                        getattr(process,jetCorrLabel[0]+'JetMETcorr'   ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1FastJet')
576 >                    elif ('L1Offset' in jetCorrLabel[1]):
577 >                        getattr(process,jetCorrLabel[0]+'JetMETcorr'   ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1Offset')
578 >                    else:
579 >                        getattr(process,jetCorrLabel[0]+'JetMETcorr'   ).offsetCorrLabel = cms.string('')
580 >                    getattr(process,jetCorrLabel[0]+'JetMETcorr').jetCorrLabel    = cms.string(jetCorrLabel[0]+'CombinedCorrector')
581 >
582 >                    getattr(process,jetCorrLabel[0]+'Type1CorMet').srcType1Corrections = cms.VInputTag(
583 >                        cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'type1')
584 >                        )
585 >                    getattr(process,jetCorrLabel[0]+'Type1p2CorMet').srcType1Corrections = cms.VInputTag(
586 >                        cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'type1')
587 >                        )
588 >                    getattr(process,jetCorrLabel[0]+'Type1p2CorMet').srcUnclEnergySums = cms.VInputTag(
589 >                        cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'type2'),
590 >                        cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'offset'),
591 >                        cms.InputTag(jetCorrLabel[0]+'CandMETcorr')                                    
592 >                        )
593 >
594 >                    ## add MET corrections to sequence
595 >                    addClone('patMETs', metSource = cms.InputTag(jetCorrLabel[0]+'Type1CorMet'), addMuonCorrections = False)
596 >                    setattr(process,'produce'+jetCorrLabel[0]+'METCorrections',producePFMETCorrections.copy())
597 >                    getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'pfCandsNotInJet'),      getattr(process,jetCorrLabel[0]+'CandsNotInJet'))
598 >                    getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'pfJetMETcorr'),         getattr(process,jetCorrLabel[0]+'JetMETcorr'))
599 >                    getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'pfCandMETcorr'),        getattr(process,jetCorrLabel[0]+'CandMETcorr'))
600 >                    getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'pfType1CorrectedMet'),  getattr(process,jetCorrLabel[0]+'Type1CorMet'))
601 >                    getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'pfType1p2CorrectedMet'),getattr(process,jetCorrLabel[0]+'Type1p2CorMet'))
602 >                    process.patDefaultSequence.replace( getattr(process,newLabel('patMETs')),
603 >                                                        getattr(process,'produce'+jetCorrLabel[0]+'METCorrections')
604 >                                                        *getattr(process,newLabel('patMETs')) )
605          else:
606              ## switch jetCorrFactors off
607              l1Jets.addJetCorrFactors = False
# Line 451 | Line 619 | class SwitchJetCollection(ConfigToolBase
619      def __init__(self):
620          ConfigToolBase.__init__(self)
621          self.addParameter(self._defaultParameters,'jetCollection',self._defaultValue,'Input jet collection', cms.InputTag)
622 <        self.addParameter(self._defaultParameters,'doJTA',True, "run b tagging sequence for new jet collection and add it to the new pat jet collection")
622 >        self.addParameter(self._defaultParameters,'btagInfo',['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],"input btag info",allowedValues=['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],Type=list)
623 >        self.addParameter(self._defaultParameters, 'btagdiscriminators',['jetBProbabilityBJetTags','jetProbabilityBJetTags','trackCountingHighPurBJetTags','trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],"input btag discriminators", allowedValues=['jetBProbabilityBJetTags', 'jetProbabilityBJetTags','trackCountingHighPurBJetTags', 'trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],Type=list)
624 >        self.addParameter(self._defaultParameters,'doJTA',True, "run b tagging sequence for new jet collection and add it to the new pat jet collection")
625          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)')
626          self.addParameter(self._defaultParameters,'jetCorrLabel',None, "payload and list of new jet correction labels, such as (\'AK5Calo\',[\'L2Relative\', \'L3Absolute\'])", tuple,acceptNoneValue=True )
627          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 colleection; at the moment it must be 'False' for non CaloJets otherwise the JetMET POG module crashes. ")
# Line 459 | Line 629 | class SwitchJetCollection(ConfigToolBase
629          self.addParameter(self._defaultParameters,'doJetID',True, "add jetId variables to the added jet collection")
630          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")
631          self.addParameter(self._defaultParameters,'postfix',"", "postfix of default sequence")
632 <        self.addParameter(self._defaultParameters, 'outputModule', "out", "Output module label, empty label indicates no output, default: out")
632 >        self.addParameter(self._defaultParameters, 'outputModules', ['out'], "Output module labels, empty list of label indicates no output, default: ['out']")
633          
634          self._parameters=copy.deepcopy(self._defaultParameters)
635          self._comment = ""
# Line 477 | Line 647 | class SwitchJetCollection(ConfigToolBase
647                   doJetID            = None,
648                   jetIdLabel         = None,
649                   postfix            = None,
650 <                 outputModule       = None):
651 <                
650 >                 outputModule       = None,
651 >                 outputModules      = None,
652 >                 btagInfo           = None,
653 >                 btagdiscriminators = None
654 >                                        ):      
655 >        
656 >
657 >
658 >        
659 >        ## stop processing if 'outputModule' exists and show the new alternative
660 >        if  not outputModule is None:
661 >            depricatedOptionOutputModule(self)
662          if jetCollection  is None:
663              jetCollection=self._defaultParameters['jetCollection'].value
664          if doJTA is None:
# Line 495 | Line 675 | class SwitchJetCollection(ConfigToolBase
675              doJetID=self._defaultParameters['doJetID'].value
676          if jetIdLabel  is None:
677              jetIdLabel=self._defaultParameters['jetIdLabel'].value
678 <        if outputModule is None:
679 <            outputModule=self._defaultParameters['outputModule'].value    
678 >        if outputModules is None:
679 >            outputModules=self._defaultParameters['outputModules'].value    
680          if postfix  is None:
681              postfix=self._defaultParameters['postfix'].value
682 +        if  btagInfo is None:
683 +             btagInfo=self._defaultParameters['btagInfo'].value
684 +        if  btagdiscriminators is None:
685 +             btagdiscriminators=self._defaultParameters['btagdiscriminators'].value
686 +
687 +
688 +
689  
690          self.setParameter('jetCollection',jetCollection)
691          self.setParameter('doJTA',doJTA)
# Line 508 | Line 695 | class SwitchJetCollection(ConfigToolBase
695          self.setParameter('genJetCollection',genJetCollection)
696          self.setParameter('doJetID',doJetID)
697          self.setParameter('jetIdLabel',jetIdLabel)
698 <        self.setParameter('outputModule',outputModule)
698 >        self.setParameter('outputModules',outputModules)
699          self.setParameter('postfix',postfix)
700 +        self.setParameter('btagInfo',btagInfo)
701 +        self.setParameter('btagdiscriminators',btagdiscriminators)
702          
703          self.apply(process)
704          
# Line 522 | Line 711 | class SwitchJetCollection(ConfigToolBase
711          genJetCollection=self._parameters['genJetCollection'].value
712          doJetID=self._parameters['doJetID'].value
713          jetIdLabel=self._parameters['jetIdLabel'].value
714 <        outputModule=self._parameters['outputModule'].value
714 >        outputModules=self._parameters['outputModules'].value
715          postfix=self._parameters['postfix'].value
716 +        btagInfo=self._parameters['btagInfo'].value
717 +        btagdiscriminators=self._parameters['btagdiscriminators'].value
718  
719          ## save label of old input jet collection
720          oldLabel = applyPostfix(process, "patJets", postfix).jetSource;
# Line 569 | Line 760 | class SwitchJetCollection(ConfigToolBase
760          if (doBTagging):
761              ## replace b tagging sequence; add postfix label 'AOD' as crab will
762              ## crash when confronted with empy labels
763 <            (btagSeq, btagLabels) = runBTagging(process, jetCollection, 'AOD',postfix)
764 <            ## add b tagging sequence before running the allLayer1Jets modules
763 >            ##(btagSeq, btagLabels) = runBTagging(process, jetCollection, 'AOD',postfix)
764 >            (btagSeq, btagLabels) = runBTagging(process, jetCollection,"AOD",postfix,btagInfo,btagdiscriminators)
765 >            ## add b tagging sequence before running the allLayer1Jets modules
766              getattr(process, "patDefaultSequence"+postfix).replace(
767                  getattr( process,"jetTracksAssociatorAtVertex"+postfix),
768                  getattr( process,"jetTracksAssociatorAtVertex"+postfix) + btagSeq
# Line 588 | Line 780 | class SwitchJetCollection(ConfigToolBase
780              ## jet production to 'False'
781              applyPostfix(process, "patJets", postfix).addBTagInfo = False
782              ## adjust output
783 <            if outputModule is not '':                
784 <                getattr(process, outputModule).outputCommands.append("drop *_selectedPatJets_tagInfos_*")
783 >            if len(outputModules) > 0:
784 >                for outMod in outputModules:
785 >                    if hasattr(process,outMod):
786 >                        getattr(process,outMod).outputCommands.append("drop *_selectedPatJets_tagInfos_*")
787 >                    else:
788 >                        raise KeyError, "process has no OutModule named", outMod
789  
790          if (doJetID):
791              jetIdLabelNew = jetIdLabel + 'JetID'
# Line 611 | Line 807 | class SwitchJetCollection(ConfigToolBase
807              ## switch JEC parameters to the new jet collection
808              applyPostfix(process, "patJetCorrFactors", postfix).src = jetCollection
809              switchJetCorrLevels(process, jetCorrLabel = jetCorrLabel, postfix=postfix)
614            #getattr( process, "patJetCorrFactors" + postfix).payload = jetCorrLabel[0]
615            #getattr( process, "patJetCorrFactors" + postfix).levels = jetCorrLabel[1]
810              getattr( process, "patJets" + postfix).jetCorrFactorsSource = cms.VInputTag( cms.InputTag("patJetCorrFactors" + postfix ) )  
811  
812 <            ## switch type1MET corrections off for PFJets or JPTJets
813 <            if ( jetCollection.getModuleLabel().find('CaloJets')<0 ):
814 <                print '================================================='
815 <                print 'Type1MET corrections are switched off for other  '
816 <                print 'jet types but CaloJets. Users are recommened to  '
817 <                print 'use pfMET together with PFJets & tcMET together  '
818 <                print 'with JPT jets.                                   '
819 <                print '================================================='
820 <                doType1MET=False
812 >            ## find out type of jet collection, switch type1MET corrections off for JPTJets
813 >            jetCollType = ''
814 >            if   ( 'CaloJets' in jetCollection.getModuleLabel() ):
815 >                jetCollType = 'Calo'
816 >            elif ( 'PFJets' in jetCollection.getModuleLabel() or jetCollection.getModuleLabel().startswith('pfNo') or jetCollection.getModuleLabel() == 'particleFlow'):
817 >                jetCollType = 'PF'
818 >            else:
819 >                print '============================================='
820 >                print 'Type1MET corrections are switched off for    '
821 >                print 'JPT Jets. Users are recommened to use tcMET  '
822 >                print 'together with JPT jets.                      '
823 >                print '============================================='
824 >                doType1MET=False
825  
826 <            ## redo the type1MET correction for the new jet collection
826 >            ## add a clone of the type1MET correction for the new jet collection
827              if (doType1MET):
828 <                ## in case there is no jet correction service in the paths add it
829 <                ## as L2L3 if possible, as combined from L2 and L3 otherwise
830 <                if not hasattr( process, '%sL2L3' % (jetCollection.getModuleLabel().replace("Jets", "")) ):
831 <                    setattr( process, '%sL2L3' % (jetCollection.getModuleLabel().replace("Jets", "")),
832 <                             cms.ESSource("JetCorrectionServiceChain",
833 <                                          correctors = cms.vstring('%sL2Relative' % (jetCollection.getModuleLabel().replace("Jets", "")),
834 <                                                                   '%sL3Absolute' % (jetCollection.getModuleLabel().replace("Jets", ""))
835 <                                                                   )
836 <                                          )
837 <                             )                
838 <                ## configure the type1MET correction the following muonMET
839 <                ## corrections have the metJESCorAK5CaloJet as input and
840 <                ## are automatically correct  
841 <                applyPostfix(process, "metJESCorAK5CaloJet", postfix).inputUncorJetsLabel = jetCollection.value()
842 <                applyPostfix(process, "metJESCorAK5CaloJet", postfix).corrector = '%sL2L3' % (jetCollection.getModuleLabel().replace("Jets", ""))                
828 >                ## create jet correctors for MET corrections
829 >                from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL1Fastjet, ak5PFL1Offset, ak5PFL2Relative, ak5PFL3Absolute, ak5PFResidual
830 >                setattr(process, jetCorrLabel[0]+'L1FastJet'   , ak5PFL1Fastjet.clone ( algorithm=jetCorrLabel[0]
831 >                                                                                      , srcRho=cms.InputTag('kt6'+jetCollType+'Jets','rho') ) )
832 >                setattr(process, jetCorrLabel[0]+'L1Offset'    , ak5PFL1Offset.clone  ( algorithm=jetCorrLabel[0] ) )
833 >                setattr(process, jetCorrLabel[0]+'L2Relative'  , ak5PFL2Relative.clone( algorithm=jetCorrLabel[0] ) )
834 >                setattr(process, jetCorrLabel[0]+'L3Absolute'  , ak5PFL3Absolute.clone( algorithm=jetCorrLabel[0] ) )
835 >                setattr(process, jetCorrLabel[0]+'L2L3Residual', ak5PFResidual.clone  ( algorithm=jetCorrLabel[0] ) )
836 >                ## combinded corrections
837 >                setattr(process, jetCorrLabel[0]+'CombinedCorrector', cms.ESProducer( 'JetCorrectionESChain'
838 >                                                                                  , correctors = cms.vstring() ) )
839 >                for corrLbl in jetCorrLabel[1]:
840 >                    if corrLbl != 'L1FastJet' and corrLbl != 'L1Offset' and corrLbl != 'L2Relative' and corrLbl != 'L3Absolute' and corrLbl != 'L2L3Residual':
841 >                        print '========================================='
842 >                        print ' Type1MET corrections are currently only  '
843 >                        print ' supported for the following corrections: '
844 >                        print '   - L1FastJet'
845 >                        print '   - L1Offset'
846 >                        print '   - L2Relative'
847 >                        print '   - L3Absolute'
848 >                        print '   - L2L3Residual'
849 >                        print ' But given was:'
850 >                        print '   -', corrLbl
851 >                        print '============================================='
852 >                        raise ValueError, 'unsupported JEC for TypeI MET correction: '+corrLbl
853 >                    else:
854 >                        getattr(process, jetCorrLabel[0]+'CombinedCorrector').correctors.append(jetCorrLabel[0]+corrLbl)
855 >
856 >                ## configuration of MET corrections
857 >                if jetCollType == 'Calo':
858 >                    from JetMETCorrections.Type1MET.caloMETCorrections_cff import caloJetMETcorr,caloType1CorrectedMet,caloType1p2CorrectedMet,produceCaloMETCorrections
859 >                    
860 >                    setattr(process,'caloJetMETcorr'+         postfix, caloJetMETcorr.clone(srcMET       = "corMetGlobalMuons"))
861 >                    setattr(process,'caloType1CorrectedMet'+  postfix, caloType1CorrectedMet.clone(src   = "corMetGlobalMuons"))
862 >                    setattr(process,'caloType1p2CorrectedMet'+postfix, caloType1p2CorrectedMet.clone(src = "corMetGlobalMuons"))
863 >                    
864 >                    getattr(process,'caloJetMETcorr'+postfix).src          = cms.InputTag(jetCollection.getModuleLabel())
865 >                    if ('L1FastJet' in jetCorrLabel[1] or 'L1Fastjet' in jetCorrLabel[1]):
866 >                        getattr(process,'caloJetMETcorr'+postfix   ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1FastJet')
867 >                    elif ('L1Offset' in jetCorrLabel[1]):
868 >                        getattr(process,'caloJetMETcorr'+postfix   ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1Offset')
869 >                    else:
870 >                        getattr(process,'caloJetMETcorr'+postfix   ).offsetCorrLabel = cms.string('')
871 >                    getattr(process,'caloJetMETcorr'+postfix   ).jetCorrLabel = cms.string(jetCorrLabel[0]+'CombinedCorrector')
872 >
873 >                    getattr(process,'caloType1CorrectedMet'+postfix  ).srcType1Corrections = cms.VInputTag(
874 >                        cms.InputTag('caloJetMETcorr'+postfix, 'type1')
875 >                        )
876 >                    
877 >                    getattr(process,'caloType1p2CorrectedMet'+postfix).srcType1Corrections = cms.VInputTag(
878 >                        cms.InputTag('caloJetMETcorr'+postfix, 'type1')
879 >                        )
880 >                    getattr(process,'caloType1p2CorrectedMet'+postfix).srcUnclEnergySums = cms.VInputTag(
881 >                        cms.InputTag('caloJetMETcorr'+postfix, 'type2'),
882 >                        cms.InputTag('caloJetMETcorr'+postfix, 'offset'),
883 >                        cms.InputTag('muonCaloMETcorr')
884 >                        )
885 >
886 >                    ## add MET corrections to sequence
887 >                    getattr(process, 'patMETs'+ postfix).metSource = cms.InputTag('caloType1CorrectedMet'+postfix)
888 >                    getattr(process,'produceCaloMETCorrections'+postfix)
889 >                    getattr(process,"patDefaultSequence"+postfix).replace( getattr(process,'patMETs'+postfix),
890 >                                                                           getattr(process,'produceCaloMETCorrections'+postfix)
891 >                                                                           *getattr(process,'patMETs'+postfix) )
892 >                elif jetCollType == 'PF':
893 >                    from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfCandsNotInJet,pfJetMETcorr,pfCandMETcorr,pfType1CorrectedMet,pfType1p2CorrectedMet,producePFMETCorrections
894 >                    setattr(process,'producePFMETCorrections'+postfix,producePFMETCorrections.copy())
895 >                    setattr(process,'pfCandsNotInJet'        +postfix,pfCandsNotInJet.clone(topCollection = jetCollection))
896 >                    setattr(process,'pfCandMETcorr'          +postfix,pfCandMETcorr.clone(src = cms.InputTag('pfCandsNotInJet'+postfix)))
897 >                    setattr(process,'pfJetMETcorr'           +postfix,pfJetMETcorr.clone(src = jetCollection))
898 >
899 >                    if ('L1FastJet' in jetCorrLabel[1] or 'L1Fastjet' in jetCorrLabel[1]):
900 >                        getattr(process,'pfJetMETcorr' +postfix).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1FastJet')
901 >                    elif ('L1Offset' in jetCorrLabel[1]):
902 >                        getattr(process,'pfJetMETcorr' +postfix).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1Offset')
903 >                    else:
904 >                        getattr(process,'pfJetMETcorr'+postfix).offsetCorrLabel = cms.string('')
905 >                    getattr(process,'pfJetMETcorr'+postfix).jetCorrLabel    = cms.string(jetCorrLabel[0]+'CombinedCorrector')
906 >
907 >                    getattr(process,'pfType1CorrectedMet'+postfix).srcCHSSums = cms.VInputTag(
908 >                        cms.InputTag("pfchsMETcorr"+postfix,"type0")
909 >                        )
910 >                    getattr(process,'pfType1CorrectedMet'+postfix).srcType1Corrections = cms.VInputTag(
911 >                        cms.InputTag('pfJetMETcorr'+postfix, 'type1')
912 >                        )
913 >
914 >                    getattr(process,'pfType1p2CorrectedMet'+postfix).srcCHSSums = cms.VInputTag(
915 >                        cms.InputTag("pfchsMETcorr"+postfix,"type0")
916 >                        )
917 >                    getattr(process,'pfType1p2CorrectedMet'+postfix).srcType1Corrections = cms.VInputTag(
918 >                        cms.InputTag('pfJetMETcorr'+postfix, 'type1')
919 >                        )
920 >                    getattr(process,'pfType1p2CorrectedMet'+postfix).srcUnclEnergySums = cms.VInputTag(
921 >                        cms.InputTag('pfJetMETcorr' +postfix, 'type2'),
922 >                        cms.InputTag('pfJetMETcorr' +postfix, 'offset'),
923 >                        cms.InputTag('pfCandMETcorr'+postfix)                                    
924 >                        )
925 >
926 >                    ## add MET corrections to sequence
927 >                    getattr(process, 'patMETs'+ postfix).metSource = cms.InputTag('pfType1CorrectedMet'+postfix)
928 >                    getattr(process, 'patMETs'+ postfix).addMuonCorrections = False
929 >                    getattr(process,'producePFMETCorrections'+postfix).remove(getattr(process,'kt6PFJets'))#,            getattr(process,'kt6PFJets'            +postfix))
930 >                    getattr(process,'producePFMETCorrections'+postfix).remove(getattr(process,'ak5PFJets'))#,            getattr(process,'ak5PFJets'            +postfix))
931 >                    getattr(process,'producePFMETCorrections'+postfix).replace(getattr(process,'pfCandsNotInJet'),      getattr(process,'pfCandsNotInJet'      +postfix))
932 >                    getattr(process,'producePFMETCorrections'+postfix).replace(getattr(process,'pfJetMETcorr'),         getattr(process,'pfJetMETcorr'         +postfix))
933 >                    getattr(process,'producePFMETCorrections'+postfix).replace(getattr(process,'pfCandMETcorr'),        getattr(process,'pfCandMETcorr'        +postfix))
934 >                    getattr(process,'producePFMETCorrections'+postfix).replace(getattr(process,'pfchsMETcorr'),         getattr(process,'pfchsMETcorr'         +postfix))
935 >                    getattr(process,'producePFMETCorrections'+postfix).replace(getattr(process,'pfType1CorrectedMet'),  getattr(process,'pfType1CorrectedMet'  +postfix))
936 >                    getattr(process,'producePFMETCorrections'+postfix).replace(getattr(process,'pfType1p2CorrectedMet'),getattr(process,'pfType1p2CorrectedMet'+postfix))
937 >
938 >                    getattr(process,"patDefaultSequence"+postfix).replace( getattr(process,'patMETs'+postfix),
939 >                                                                           getattr(process,'producePFMETCorrections'+postfix)
940 >                                                                           *getattr(process,'patMETs'+postfix) )
941 >
942 >            getattr(process,'patDefaultSequence'+postfix).replace(getattr(process,'patJetCorrFactors'+postfix),
943 >                                                                  getattr(process,'kt6PFJets'+postfix)
944 >                                                                  *getattr(process,'patJetCorrFactors'+postfix))
945          else:
946              ## remove the jetCorrFactors from the std sequence
947              process.patJetMETCorrections.remove(process.patJetCorrFactors)
# Line 651 | Line 951 | class SwitchJetCollection(ConfigToolBase
951              applyPostfix(process, "patJets", postfix).jetCorrFactorsSource=[]        
952  
953          ## adjust output when switching to PFJets
954 <        if (jetCollection.getModuleLabel().find('PFJets')>=0 ):
954 >        if ( 'PFJets' in jetCollection.getModuleLabel() or jetCollection.getModuleLabel().startswith("pfNo") or jetCollection.getModuleLabel() == 'particleFlow' ):
955              ## in this case we can omit caloTowers and should keep pfCandidates
956 <            if outputModule is not '':                
957 <                getattr(process, outputModule).outputCommands.append("keep *_selectedPatJets_pfCandidates_*")
958 <                getattr(process, outputModule).outputCommands.append("drop *_selectedPatJets_caloTowers_*")
956 >            if len(outputModules) > 0:
957 >                for outMod in outputModules:
958 >                    if hasattr(process,outMod):
959 >                        getattr(process, outMod).outputCommands.append("keep *_selectedPatJets_pfCandidates_*")
960 >                        getattr(process, outMod).outputCommands.append("drop *_selectedPatJets_caloTowers_*")
961 >                    else:
962 >                        raise KeyError, "process has no OutModule named", outMod
963  
964   switchJetCollection=SwitchJetCollection()
965  
# Line 710 | Line 1014 | class SetTagInfos(ConfigToolBase):
1014      _defaultParameters=dicttypes.SortedKeysDict()
1015      def __init__(self):
1016          ConfigToolBase.__init__(self)
1017 <        self.addParameter(self._defaultParameters,'coll',"allLayer1Jets","jet collection to set tag infos for")
1017 >        self.addParameter(self._defaultParameters,'coll',"patJets","jet collection to set tag infos for")
1018          self.addParameter(self._defaultParameters,'tagInfos',cms.vstring( ), "tag infos to set")
1019          self._parameters=copy.deepcopy(self._defaultParameters)
1020          self._comment = ""
# Line 751 | Line 1055 | class SetTagInfos(ConfigToolBase):
1055                          
1056   setTagInfos=SetTagInfos()
1057  
754
1058   class SwitchJetCorrLevels(ConfigToolBase):
1059  
1060      """ Switch from jet energy correction levels and do all necessary adjustments
# Line 769 | Line 1072 | class SwitchJetCorrLevels(ConfigToolBase
1072          return self._defaultParameters
1073  
1074      def __call__(self,process,
1075 <                 jetCorrLabel       = None,
1076 <                 postfix            = None) :
1077 <        if jetCorrLabel  is None:
1075 >                 jetCorrLabel = None,
1076 >                 postfix      = None) :
1077 >        if jetCorrLabel is None:
1078              jetCorrLabel=self._defaultParameters['jetCorrLabel'].value
1079 <        if postfix  is None:
1079 >        if postfix is None:
1080              postfix=self._defaultParameters['postfix'].value
1081  
1082          self.setParameter('jetCorrLabel',jetCorrLabel)
# Line 806 | Line 1109 | class SwitchJetCorrLevels(ConfigToolBase
1109                  if x == 'L1Offset':
1110                      if not error:
1111                          jetCorrFactorsModule.useNPV = True
1112 <                        primaryVertices = 'offlinePrimaryVertices'
1112 >                        jetCorrFactorsModule.primaryVertices = 'offlinePrimaryVertices'
1113                          ## we set this to True now as a L1 correction type should appear only once
1114                          ## otherwise levels is miss configured
1115                          error = True
# Line 818 | Line 1121 | class SwitchJetCorrLevels(ConfigToolBase
1121                  if x == 'L1FastJet':
1122                      if not error:
1123                          ## re-run jet algo to compute rho and jetArea for the L1Fastjet corrections
1124 <                        process.load("RecoJets.JetProducers.kt4PFJets_cfi")
1125 <                        process.kt6PFJets = process.kt4PFJets.clone(doAreaFastjet=True, doRhoFastjet=True, rParam=0.6)
1126 <                        process.patDefaultSequence.replace(jetCorrFactorsModule, process.kt6PFJets*jetCorrFactorsModule)
1124 >                        jetType=''
1125 >                        ## find out which jetType is used (PF or Calo)
1126 >                        if jetCorrLabel[0].count('PF') > 0:
1127 >                            ## only add module if it is not already part of the process
1128 >                            ## ATTENTION: this assumes that new jet collection are always added after existing ones !!!
1129 >                            if not hasattr(process,'kt6PFJets'+postfix):
1130 >                                from RecoJets.JetProducers.kt4PFJets_cfi import kt4PFJets
1131 >                                setattr(process,'kt6PFJets'+postfix, kt4PFJets.clone(doAreaFastjet=True, doRhoFastjet=True, rParam=0.6))
1132 >                            jetType='PF'
1133 >                        elif jetCorrLabel[0].count('Calo') > 0:
1134 >                            ## only add module if it is not already part of the process
1135 >                            ## ATTENTION: this assumes that new jet collection are always added after existing ones !!!
1136 >                            if not hasattr(process,'kt6CaloJets'+postfix):
1137 >                                from RecoJets.JetProducers.kt4CaloJets_cfi import kt4CaloJets
1138 >                                setattr(process,'kt6CaloJets'+postfix, kt4CaloJets.clone(doAreaFastjet=True, doRhoFastjet=True, rParam=0.6))
1139 >                            jetType='Calo'
1140 >                        else:
1141 >                            raise TypeError, "L1FastJet corrections are currently only supported for PF and Calo jets in PAT"
1142 >                        ## check if a modified patDefaultSequence exists and add kt6Jets there (needed for example for usePF2PAT)
1143 >                        if hasattr(process,'patDefaultSequence'+postfix):
1144 >                            if not contains(getattr(process,'patDefaultSequence'+postfix), 'kt6'+jetType+'Jets'+postfix):
1145 >                                getattr(process,'patDefaultSequence'+postfix).replace(jetCorrFactorsModule, getattr(process,'kt6'+jetType+'Jets'+postfix)*jetCorrFactorsModule)
1146 >                        ## if no modified patDefaultSequence exists add kt6Jets to ordinary sequence (needed for example for addJetCollection)
1147 >                        else:
1148 >                            if not contains(getattr(process,'patDefaultSequence'), 'kt6'+jetType+'Jets'+postfix):
1149 >                                getattr(process,'patDefaultSequence').replace(jetCorrFactorsModule, getattr(process,'kt6'+jetType+'Jets'+postfix)*jetCorrFactorsModule)
1150                          ## configure module
1151                          jetCorrFactorsModule.useRho = True
1152 <                        jetCorrFactorsModule.rho = cms.InputTag('kt6PFJets', 'rho')
1152 >                        jetCorrFactorsModule.rho = cms.InputTag('kt6'+jetType+'Jets'+postfix, 'rho')
1153                          ## we set this to True now as a L1 correction type should appear only once
1154                          ## otherwise levels is miss configured
1155                          error = True
# Line 833 | Line 1159 | class SwitchJetCorrLevels(ConfigToolBase
1159                          print jetCorrLabel[1]
1160                          
1161   switchJetCorrLevels=SwitchJetCorrLevels()
1162 +
1163 + def depricatedOptionOutputModule(obj):
1164 +    print "-------------------------------------------------------"
1165 +    print " Error: the option 'outputModule' is not supported"
1166 +    print "        anymore by:"
1167 +    print "                   ", obj._label
1168 +    print "        please use 'outputModules' now and specify the"
1169 +    print "        names of all needed OutModules in there"
1170 +    print "        (default: ['out'])"
1171 +    print "-------------------------------------------------------"
1172 +    raise KeyError, "unsupported option 'outputModule' used in '"+obj._label+"'"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines