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_2_X] Fall17 V2 Photon ID and PhotonIDValueMapProducer speedup #25372
Merged
cmsbuild
merged 13 commits into
cms-sw:CMSSW_10_2_X
from
guitargeek:PhotonIDValueMapProducer_10_2_X
Dec 12, 2018
+887
−741
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4559f4e
Cutbased photonID Fall17 V2
swagata87 4bba6c7
update phoID v2 cutbased
swagata87 cc33f78
Fall17_94X_v2 MVA Photon ID
guitargeek b3ea443
fix worst charged iso variable
guitargeek 7326dcd
Renamed cut based ID and put in MiniAOD
guitargeek fde7b8e
Backporting #25293
guitargeek e78ff2d
Attempt to improve PhotonIDValueMapProducer
guitargeek fedf904
cache AOD/miniAOD values to speed up repeated computations
slava77devel 9b56f8a
Cleaned imports in Spring15 phtoton MVA cfg
guitargeek 3cef419
Sync PhotonIDValueMapProducer with master plus MultiToken and Utils
guitargeek 74d39e1
Photon Fall17 V2 IDs only for run2_miniAOD_devel
guitargeek 99daa85
Make list of photon IDs a PSet which is toModify
guitargeek 6457cd0
Add missing paranthesis
guitargeek File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
#ifndef RecoEgamma_EgammaTools_MultiToken_H | ||
#define RecoEgamma_EgammaTools_MultiToken_H | ||
|
||
#include "DataFormats/Common/interface/Handle.h" | ||
#include "FWCore/Framework/interface/ConsumesCollector.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/Utilities/interface/EDGetToken.h" | ||
#include "FWCore/Utilities/interface/Exception.h" | ||
#include "FWCore/Utilities/interface/InputTag.h" | ||
|
||
/* | ||
* This class is a wrapper around a vector of EDM tokens, of which at least one | ||
* is expected to yield a valid handle. | ||
* | ||
* The first time you call getValidHandle() or getHandle(), it will go over all | ||
* tokens and try to get a valid handle. If no token yields a valid handle, it | ||
* will either throw and exception or return the last non-valid handle. | ||
* | ||
* Once it found a valid handle, it will remember which token was used to get | ||
* it and therefore doesn't need to loop over all tokens from there on. | ||
* | ||
* Example use case: auto-detection of AOD vs. MiniAOD. | ||
* | ||
* Created by Jonas Rembser on August 3, 2018. | ||
*/ | ||
|
||
#include <memory> | ||
|
||
template <typename T> | ||
class MultiTokenT { | ||
|
||
using GoodIndexType = std::shared_ptr<std::atomic<int>>; | ||
|
||
public: | ||
|
||
template <typename ... Tags> | ||
MultiTokenT(edm::ConsumesCollector && cc, Tags ... tags) | ||
: isMaster_(true) | ||
, tokens_({cc.mayConsume<T>(edm::InputTag(tags))...}) | ||
, goodIndex_(std::make_shared<std::atomic<int>>(-1)) | ||
{} | ||
|
||
// Constructor which gets the input tags from a config to create the tokens plus master token | ||
template <typename S, typename ... Tags> | ||
MultiTokenT(const MultiTokenT<S>& master, edm::ConsumesCollector && cc, Tags ... tags) | ||
: isMaster_(false) | ||
, tokens_({cc.mayConsume<T>(edm::InputTag(tags))...}) | ||
, goodIndex_(master.getGoodTokenIndexPtr()) | ||
{} | ||
|
||
// Constructor which gets the input tags from a config to create the tokens | ||
template <typename ... Tags> | ||
MultiTokenT(edm::ConsumesCollector && cc, const edm::ParameterSet& pset, Tags && ... tags) | ||
: isMaster_(true) | ||
, tokens_({cc.mayConsume<T>(pset.getParameter<edm::InputTag>(tags))...}) | ||
, goodIndex_(std::make_shared<std::atomic<int>>(-1)) | ||
{} | ||
|
||
// Constructor which gets the input tags from a config to create the tokens plus master token | ||
template <typename S, typename ... Tags> | ||
MultiTokenT(const MultiTokenT<S>& master, edm::ConsumesCollector && cc, const edm::ParameterSet& pset, Tags && ... tags) | ||
: isMaster_(false) | ||
, tokens_({cc.mayConsume<T>(pset.getParameter<edm::InputTag>(tags))...}) | ||
, goodIndex_(master.getGoodTokenIndexPtr()) | ||
{} | ||
|
||
// Get a handle on the event data, non-valid handle is allowed | ||
edm::Handle<T> getHandle(const edm::Event& iEvent) const | ||
{ | ||
edm::Handle<T> handle; | ||
|
||
// If we already know which token works, take that one | ||
if (*goodIndex_ >= 0) { | ||
iEvent.getByToken(tokens_[*goodIndex_], handle); | ||
return handle; | ||
} | ||
|
||
if (!isMaster_) { | ||
throw cms::Exception("MultiTokenTException") << | ||
"Trying to get a handle from a depending MultiToken before the master!"; | ||
} | ||
|
||
// If not, set the good token index parallel to getting the handle | ||
handle = getInitialHandle(iEvent); | ||
|
||
if (*goodIndex_ == -1) { | ||
*goodIndex_ = tokens_.size() - 1; | ||
} | ||
return handle; | ||
} | ||
|
||
// Get a handle on the event data, | ||
// throw exception if no token yields a valid handle | ||
edm::Handle<T> getValidHandle(const edm::Event& iEvent) const | ||
{ | ||
edm::Handle<T> handle; | ||
|
||
// If we already know which token works, take that one | ||
if (*goodIndex_ >= 0) { | ||
iEvent.getByToken(tokens_[*goodIndex_], handle); | ||
if (!handle.isValid()) | ||
throw cms::Exception("MultiTokenTException") << | ||
"Token gave valid handle previously but not anymore!"; | ||
return handle; | ||
} | ||
|
||
if (!isMaster_) { | ||
throw cms::Exception("MultiTokenTException") << | ||
"Trying to get a handle from a depending MultiToken before the master!"; | ||
} | ||
|
||
// If not, set the good token index parallel to getting the handle | ||
handle = getInitialHandle(iEvent); | ||
|
||
if (*goodIndex_ == -1) { | ||
throw cms::Exception("MultiTokenTException") << "Neither handle is valid!"; | ||
} | ||
return handle; | ||
} | ||
|
||
// get the good token | ||
edm::EDGetTokenT<T> get(const edm::Event& iEvent) const | ||
{ | ||
// If we already know which token works, take that index | ||
if (*goodIndex_ >= 0) | ||
return tokens_[*goodIndex_]; | ||
|
||
// If this is not a master MultiToken, just return what it got | ||
if (!isMaster_) { | ||
throw cms::Exception("MultiTokenTException") << | ||
"Trying to get a handle from a depending MultiToken before the master!"; | ||
} | ||
|
||
// Find which token is the good one by trying to get a handle | ||
edm::Handle<T> handle; | ||
for (auto token:tokens_ ) { | ||
iEvent.getByToken(token, handle); | ||
if (handle.isValid()) { | ||
return token; | ||
} | ||
} | ||
|
||
throw cms::Exception("MultiTokenTException") << "Neither token is valid!"; | ||
} | ||
|
||
int getGoodTokenIndex() const | ||
{ | ||
return *goodIndex_; | ||
} | ||
|
||
GoodIndexType getGoodTokenIndexPtr() const | ||
{ | ||
return goodIndex_; | ||
} | ||
|
||
private: | ||
|
||
edm::Handle<T> getInitialHandle(const edm::Event& iEvent) const | ||
{ | ||
// Try to retrieve the collection from the event. If we fail to | ||
// retrieve the collection with one name, we next look for the one with | ||
// the other name and so on. | ||
edm::Handle<T> handle; | ||
for (size_t i = 0; i < tokens_.size(); ++i) { | ||
iEvent.getByToken(tokens_[i], handle); | ||
if (handle.isValid()) { | ||
*goodIndex_ = i; | ||
return handle; | ||
} | ||
} | ||
return handle; | ||
} | ||
|
||
const bool isMaster_; | ||
const std::vector<edm::EDGetTokenT<T>> tokens_; | ||
const GoodIndexType goodIndex_; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef RecoEgamma_EgammaTools_Utils_H | ||
#define RecoEgamma_EgammaTools_Utils_H | ||
|
||
#include "DataFormats/Common/interface/Handle.h" | ||
#include "DataFormats/Common/interface/ValueMap.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
template<typename ValueType, class HandleType> | ||
void writeValueMap(edm::Event &iEvent, | ||
const edm::Handle<HandleType>& handle, | ||
const std::vector<ValueType>& values, | ||
const std::string& label) | ||
{ | ||
auto valMap = std::make_unique<edm::ValueMap<ValueType>>(); | ||
typename edm::ValueMap<ValueType>::Filler filler(*valMap); | ||
filler.insert(handle, values.begin(), values.end()); | ||
filler.fill(); | ||
iEvent.put(std::move(valMap),label); | ||
} | ||
|
||
#endif |
9 changes: 9 additions & 0 deletions
9
...onIdentification/data/Fall17/effAreaPhotons_cone03_pfChargedHadrons_90percentBased_V2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# The constants are based on 90% contours of isolation. | ||
# |eta| min |eta| max effective area | ||
0.0000 1.0000 0.0112 | ||
1.0000 1.4790 0.0108 | ||
1.4790 2.0000 0.0106 | ||
2.0000 2.2000 0.01002 | ||
2.2000 2.3000 0.0098 | ||
2.3000 2.4000 0.0089 | ||
2.4000 5.0000 0.0087 |
9 changes: 9 additions & 0 deletions
9
...onIdentification/data/Fall17/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased_V2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# The constants are based on 90% contours of isolation. | ||
# |eta| min |eta| max effective area | ||
0.0000 1.0000 0.0668 | ||
1.0000 1.4790 0.1054 | ||
1.4790 2.0000 0.0786 | ||
2.0000 2.2000 0.0233 | ||
2.2000 2.3000 0.0078 | ||
2.3000 2.4000 0.0028 | ||
2.4000 5.0000 0.0137 |
9 changes: 9 additions & 0 deletions
9
...ma/PhotonIdentification/data/Fall17/effAreaPhotons_cone03_pfPhotons_90percentBased_V2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# The constants are based on 90% contours of isolation. | ||
# |eta| min |eta| max effective area | ||
0.0000 1.0000 0.1113 | ||
1.0000 1.4790 0.0953 | ||
1.4790 2.0000 0.0619 | ||
2.0000 2.2000 0.0837 | ||
2.2000 2.3000 0.1070 | ||
2.3000 2.4000 0.1212 | ||
2.4000 5.0000 0.1466 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parenthesis missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I saw that too now after I tried to test locally... thanks. Sorry for these mistakes happening in a rush.
Everything compiles now (no syntax errors in Python configurations) and my local matrix tests run. Maybe it's better to wait for these before asking the bot, which takes much longer.