Skip to content

Commit

Permalink
feat: allow for not sorting during PATJetUpdater call
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejnovak committed Nov 26, 2020
1 parent 6c149b2 commit 74b0314
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 7 additions & 1 deletion PhysicsTools/PatAlgos/plugins/PATJetUpdater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ PATJetUpdater::PATJetUpdater(const edm::ParameterSet& iConfig)
: useUserData_(iConfig.exists("userData")), printWarning_(iConfig.getParameter<bool>("printWarning")) {
// 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(
Expand Down Expand Up @@ -216,7 +217,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 @@ -232,6 +235,9 @@ void PATJetUpdater::fillDescriptions(edm::ConfigurationDescriptions& description
// 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
1 change: 1 addition & 0 deletions PhysicsTools/PatAlgos/plugins/PATJetUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace pat {
private:
// configurables
edm::EDGetTokenT<edm::View<reco::Jet> > jetsToken_;
bool sort_;
bool addJetCorrFactors_;
std::vector<edm::EDGetTokenT<edm::ValueMap<JetCorrFactors> > > jetCorrFactorsTokens_;

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 @@ -1558,6 +1558,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 @@ -1591,7 +1592,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 @@ -1650,6 +1651,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 @@ -1687,6 +1691,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 @@ -1719,6 +1724,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 @@ -1785,9 +1792,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

0 comments on commit 74b0314

Please sign in to comment.