Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10_6_X] feat: allow for not sorting during PATJetUpdater call #32298

Merged
merged 2 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion PhysicsTools/PatAlgos/plugins/PATJetUpdater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ PATJetUpdater::PATJetUpdater(const edm::ParameterSet& iConfig) :
{
// initialize configurables
jetsToken_ = consumes<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>( "jetSource" ));
sort_ = iConfig.getParameter<bool>( "sort" );
addJetCorrFactors_ = iConfig.getParameter<bool>( "addJetCorrFactors" );
if( addJetCorrFactors_ ) {
jetCorrFactorsTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "jetCorrFactorsSource" ), [this](edm::InputTag const & tag){return mayConsume<edm::ValueMap<JetCorrFactors> >(tag);});
Expand Down Expand Up @@ -208,7 +209,9 @@ void PATJetUpdater::produce(edm::Event & iEvent, const edm::EventSetup & iSetup)
}

// sort jets in pt
std::sort(patJets->begin(), patJets->end(), pTComparator_);
if (sort_) {
std::sort(patJets->begin(), patJets->end(), pTComparator_);
}

// put genEvt in Event
iEvent.put(std::move(patJets));
Expand All @@ -226,6 +229,9 @@ void PATJetUpdater::fillDescriptions(edm::ConfigurationDescriptions & descriptio
// input source
iDesc.add<edm::InputTag>("jetSource", edm::InputTag("no default"))->setComment("input collection");

// sort inputs (by pt)
iDesc.add<bool>("sort", true);

// tag info
iDesc.add<bool>("addTagInfos", true);
std::vector<edm::InputTag> emptyVInputTags;
Expand Down
3 changes: 2 additions & 1 deletion PhysicsTools/PatAlgos/plugins/PATJetUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ namespace pat {

// configurables
edm::EDGetTokenT<edm::View<reco::Jet> > jetsToken_;
bool addJetCorrFactors_;
bool sort_;
bool addJetCorrFactors_;
std::vector<edm::EDGetTokenT<edm::ValueMap<JetCorrFactors> > > jetCorrFactorsTokens_;

bool addBTagInfo_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
userFunctions = cms.vstring(),
userFunctionLabels = cms.vstring()
),
# sort
sort = cms.bool(True),
# jet energy corrections
addJetCorrFactors = cms.bool(True),
jetCorrFactorsSource = cms.VInputTag(cms.InputTag("updatedPatJetCorrFactors") ),
Expand Down
16 changes: 13 additions & 3 deletions PhysicsTools/PatAlgos/python/tools/jetTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,7 @@ def __init__(self):
self.addParameter(self._defaultParameters,'groomedFatJets', cms.InputTag(''), "Groomed fat jet collection used for secondary vertex clustering", cms.InputTag)
self.addParameter(self._defaultParameters,'algo', 'AK', "Jet algorithm of the input collection from which the new patJet collection should be created")
self.addParameter(self._defaultParameters,'rParam', 0.4, "Jet size (distance parameter R used in jet clustering)")
self.addParameter(self._defaultParameters,'sortByPt', True, "Set to False to not modify incoming jet order")
self.addParameter(self._defaultParameters,'printWarning', True, "To be use as False in production to reduce log size")
self.addParameter(self._defaultParameters,'jetCorrections',None, "Add all relevant information about jet energy corrections that you want to be added to your new patJet \
collection. The format has to be given in a python tuple of type: (\'AK4Calo\',[\'L2Relative\', \'L3Absolute\'], patMet). Here the first argument corresponds to the payload \
Expand Down Expand Up @@ -1520,7 +1521,7 @@ def getDefaultParameters(self):
"""
return self._defaultParameters

def __call__(self,process,labelName=None,postfix=None,btagPrefix=None,jetSource=None,pfCandidates=None,explicitJTA=None,pvSource=None,svSource=None,elSource=None,muSource=None,runIVF=None,tightBTagNTkHits=None,loadStdRecoBTag=None,svClustering=None,fatJets=None,groomedFatJets=None,algo=None,rParam=None,printWarning=None,jetCorrections=None,btagDiscriminators=None,btagInfos=None):
def __call__(self,process,labelName=None,postfix=None,btagPrefix=None,jetSource=None,pfCandidates=None,explicitJTA=None,pvSource=None,svSource=None,elSource=None,muSource=None,runIVF=None,tightBTagNTkHits=None,loadStdRecoBTag=None,svClustering=None,fatJets=None,groomedFatJets=None,algo=None,rParam=None,sortByPt=None,printWarning=None,jetCorrections=None,btagDiscriminators=None,btagInfos=None):
"""
Function call wrapper. This will check the parameters and call the actual implementation that
can be found in toolCode via the base class function apply.
Expand Down Expand Up @@ -1579,6 +1580,9 @@ def __call__(self,process,labelName=None,postfix=None,btagPrefix=None,jetSource=
if rParam is None:
rParam=self._defaultParameters['rParam'].value
self.setParameter('rParam', rParam)
if sortByPt is None:
sortByPt=self._defaultParameters['sortByPt'].value
self.setParameter('sortByPt', sortByPt)
if printWarning is None:
printWarning=self._defaultParameters['printWarning'].value
self.setParameter('printWarning', printWarning)
Expand Down Expand Up @@ -1616,6 +1620,7 @@ def toolCode(self, process):
groomedFatJets=self._parameters['groomedFatJets'].value
algo=self._parameters['algo'].value
rParam=self._parameters['rParam'].value
sortByPt=self._parameters['sortByPt'].value
printWarning=self._parameters['printWarning'].value
jetCorrections=self._parameters['jetCorrections'].value
btagDiscriminators=list(self._parameters['btagDiscriminators'].value)
Expand Down Expand Up @@ -1648,6 +1653,8 @@ def toolCode(self, process):

## add new updatedPatJets to process (keep instance for later further modifications)
from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cfi import updatedPatJets
if not sortByPt: # default is True
updatedPatJets.sort = cms.bool(False)
if 'updatedPatJets'+_labelName+postfix in knownModules :
_newPatJets=getattr(process, 'updatedPatJets'+_labelName+postfix)
_newPatJets.jetSource=jetSource
Expand Down Expand Up @@ -1714,9 +1721,12 @@ def toolCode(self, process):
_newPatJets.addTagInfos = False

## add jet correction factors if required by user
if (jetCorrections != None or bTagging):
if (jetCorrections is not None or bTagging):
## check the jet corrections format
checkJetCorrectionsFormat(jetCorrections)
if jetCorrections is None and bTagging:
raise ValueError("Passing jetCorrections = None while running bTagging is likely not intended.")
else:
checkJetCorrectionsFormat(jetCorrections)
## reset MET corrrection
if jetCorrections[2].lower() != 'none' and jetCorrections[2] != '':
sys.stderr.write("-------------------------------------------------------------------\n")
Expand Down