-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Updating SONIC ParticleNet Producer and Config Files #43138
Changes from 1 commit
6855d27
ac56ba8
a9244c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -49,7 +49,14 @@ class ParticleNetSonicJetTagsProducer : public TritonEDProducer<> { | |||
std::unordered_map<std::string, PreprocessParams> prep_info_map_; // preprocessing info for each input group | ||||
bool debug_ = false; | ||||
bool skippedInference_ = false; | ||||
constexpr static unsigned numParticleGroups_ = 3; | ||||
std::vector<bool> emptyJets_; | ||||
unsigned numParticleGroups_ = 0; | ||||
unsigned numVertexGroups_ = 0; | ||||
unsigned numLostTrackGroups_ = 0; | ||||
bool countedInputs = false; | ||||
std::string particleNameExample_; | ||||
std::string vertexNameExample_; | ||||
std::string losttrackNameExample_; | ||||
}; | ||||
|
||||
ParticleNetSonicJetTagsProducer::ParticleNetSonicJetTagsProducer(const edm::ParameterSet &iConfig) | ||||
|
@@ -86,6 +93,8 @@ ParticleNetSonicJetTagsProducer::ParticleNetSonicJetTagsProducer(const edm::Para | |||
for (const auto &flav_name : flav_names_) { | ||||
produces<JetTagCollection>(flav_name); | ||||
} | ||||
|
||||
emptyJets_.clear(); | ||||
} | ||||
|
||||
ParticleNetSonicJetTagsProducer::~ParticleNetSonicJetTagsProducer() {} | ||||
|
@@ -131,26 +140,74 @@ void ParticleNetSonicJetTagsProducer::acquire(edm::Event const &iEvent, edm::Eve | |||
iEvent.getByToken(src_, tag_infos); | ||||
client_->setBatchSize(tag_infos->size()); | ||||
skippedInference_ = false; | ||||
|
||||
emptyJets_.clear(); | ||||
|
||||
if (!countedInputs) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason this can't be done in the constructor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Kevin, do you mean moving this to the ParticleNetConstructor function here
I need the emptyJets_ vector to be cleared for every event, which is why I added it here, instead of just the call at line 97, which you said was not needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment was about initializing the constants that happens in this if block. (Indeed the clear() call should happen in acquire().) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh I see what you mean. Yes, moved that block into the constructor |
||||
int model_input_size = input_names_.size(); | ||||
for (int n = 0; n < model_input_size; n++) { | ||||
if (prep_info_map_.at(input_names_.at(n)).var_names.at(0).find("pf") != std::string::npos) { | ||||
if (numParticleGroups_ == 0) { | ||||
particleNameExample_ = prep_info_map_.at(input_names_.at(n)).var_names.at(0); | ||||
} | ||||
numParticleGroups_++; | ||||
} else if (prep_info_map_.at(input_names_.at(n)).var_names.at(0).find("sv") != std::string::npos) { | ||||
if (numVertexGroups_ == 0) { | ||||
vertexNameExample_ = prep_info_map_.at(input_names_.at(n)).var_names.at(0); | ||||
} | ||||
numVertexGroups_++; | ||||
} else if (prep_info_map_.at(input_names_.at(n)).var_names.at(0).find("lt") != std::string::npos) { | ||||
if (numLostTrackGroups_ == 0) { | ||||
losttrackNameExample_ = prep_info_map_.at(input_names_.at(n)).var_names.at(0); | ||||
} | ||||
numLostTrackGroups_++; | ||||
} | ||||
} | ||||
|
||||
countedInputs = true; | ||||
} | ||||
|
||||
if (!tag_infos->empty()) { | ||||
unsigned int maxParticles = 0; | ||||
unsigned int maxVertices = 0; | ||||
unsigned int maxLT = 0; | ||||
unsigned int numParticles; | ||||
unsigned int numVertices; | ||||
rappoccio marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
for (unsigned jet_n = 0; jet_n < tag_infos->size(); ++jet_n) { | ||||
maxParticles = std::max(maxParticles, | ||||
static_cast<unsigned int>(((*tag_infos)[jet_n]).features().get("pfcand_etarel").size())); | ||||
maxVertices = | ||||
std::max(maxVertices, static_cast<unsigned int>(((*tag_infos)[jet_n]).features().get("sv_etarel").size())); | ||||
numParticles = static_cast<unsigned int>(((*tag_infos)[jet_n]).features().get(particleNameExample_).size()); | ||||
numVertices = static_cast<unsigned int>(((*tag_infos)[jet_n]).features().get(vertexNameExample_).size()); | ||||
maxParticles = std::max(maxParticles, numParticles); | ||||
maxVertices = std::max(maxVertices, numVertices); | ||||
|
||||
if (numParticles == 0 && numVertices == 0) { | ||||
emptyJets_.push_back(true); | ||||
} else { | ||||
emptyJets_.push_back(false); | ||||
} | ||||
|
||||
if (!(losttrackNameExample_.empty()) && numParticles > 0) { | ||||
maxLT = std::max(maxLT, | ||||
static_cast<unsigned int>(((*tag_infos)[jet_n]).features().get(losttrackNameExample_).size())); | ||||
} | ||||
} | ||||
if (maxParticles == 0 && maxVertices == 0) { | ||||
|
||||
if (maxParticles == 0 && maxVertices == 0 && maxLT == 0) { | ||||
client_->setBatchSize(0); | ||||
skippedInference_ = true; | ||||
return; | ||||
} | ||||
|
||||
unsigned int minPartFromJSON = prep_info_map_.at(input_names_[0]).min_length; | ||||
unsigned int maxPartFromJSON = prep_info_map_.at(input_names_[0]).max_length; | ||||
unsigned int minVertFromJSON = prep_info_map_.at(input_names_[3]).min_length; | ||||
unsigned int maxVertFromJSON = prep_info_map_.at(input_names_[3]).max_length; | ||||
unsigned int minVertFromJSON = prep_info_map_.at(input_names_[numParticleGroups_]).min_length; | ||||
unsigned int maxVertFromJSON = prep_info_map_.at(input_names_[numParticleGroups_]).max_length; | ||||
maxParticles = std::clamp(maxParticles, minPartFromJSON, maxPartFromJSON); | ||||
maxVertices = std::clamp(maxVertices, minVertFromJSON, maxVertFromJSON); | ||||
if (!(losttrackNameExample_.empty())) { | ||||
unsigned int minLTFromJSON = prep_info_map_.at(input_names_[numParticleGroups_ + numVertexGroups_]).min_length; | ||||
unsigned int maxLTFromJSON = prep_info_map_.at(input_names_[numParticleGroups_ + numVertexGroups_]).max_length; | ||||
maxLT = std::clamp(maxLT, minLTFromJSON, maxLTFromJSON); | ||||
} | ||||
|
||||
for (unsigned igroup = 0; igroup < input_names_.size(); ++igroup) { | ||||
const auto &group_name = input_names_[igroup]; | ||||
|
@@ -159,9 +216,12 @@ void ParticleNetSonicJetTagsProducer::acquire(edm::Event const &iEvent, edm::Eve | |||
if (igroup < numParticleGroups_) { | ||||
input.setShape(1, maxParticles); | ||||
target = maxParticles; | ||||
} else { | ||||
} else if (igroup < (numParticleGroups_ + numVertexGroups_)) { | ||||
input.setShape(1, maxVertices); | ||||
target = maxVertices; | ||||
} else { | ||||
input.setShape(1, maxLT); | ||||
target = maxLT; | ||||
} | ||||
auto tdata = input.allocate<float>(true); | ||||
for (unsigned jet_n = 0; jet_n < tag_infos->size(); ++jet_n) { | ||||
|
@@ -172,7 +232,13 @@ void ParticleNetSonicJetTagsProducer::acquire(edm::Event const &iEvent, edm::Eve | |||
// transform/pad | ||||
for (unsigned i = 0; i < prep_params.var_names.size(); ++i) { | ||||
const auto &varname = prep_params.var_names[i]; | ||||
const auto &raw_value = taginfo.features().get(varname); | ||||
std::vector<float> bare(0); | ||||
std::vector<float> raw_value; | ||||
if (!emptyJets_.at(jet_n)) { | ||||
raw_value = taginfo.features().get(varname); | ||||
} else { | ||||
raw_value = bare; | ||||
} | ||||
const auto &info = prep_params.info(varname); | ||||
int insize = center_norm_pad_halfRagged(raw_value, | ||||
info.center, | ||||
|
@@ -234,7 +300,11 @@ void ParticleNetSonicJetTagsProducer::produce(edm::Event &iEvent, | |||
const auto &taginfo = (*tag_infos)[jet_n]; | ||||
const auto &jet_ref = tag_infos->at(jet_n).jet(); | ||||
|
||||
if (!taginfo.features().empty()) { | ||||
if (emptyJets_.at(jet_n)) { | ||||
for (std::size_t flav_n = 0; flav_n < flav_names_.size(); flav_n++) { | ||||
(*(output_tags[flav_n]))[jet_ref] = 0.; | ||||
} | ||||
} else if (!taginfo.features().empty()) { | ||||
for (std::size_t flav_n = 0; flav_n < flav_names_.size(); flav_n++) { | ||||
(*(output_tags[flav_n]))[jet_ref] = outputs_from_server[jet_n][flav_n]; | ||||
} | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
) | ||
) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete unnecessary change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deleted |
||
pfMassDecorrelatedParticleNetJetTags = boostedJetONNXJetTagsProducer.clone( | ||
src = 'pfParticleNetTagInfos', | ||
preprocess_json = 'RecoBTag/Combined/data/ParticleNetAK8/MD-2prong/V01/preprocess.json', | ||
|
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.
should not be necessary; vectors are initialized to empty by default
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.
deleted