SONIC producer for MLPF - #28
Conversation
| #include "FWCore/Utilities/interface/StreamID.h" | ||
|
|
||
| #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" | ||
| //#include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" |
| #include "HeterogeneousCore/SonicTriton/interface/TritonEDProducer.h" | ||
| #include "HeterogeneousCore/SonicTriton/interface/TritonData.h" | ||
|
|
||
| // using namespace cms::Ort; |
| class SelectedElementsManager { | ||
| public: | ||
| static SelectedElementsManager &getInstance() { | ||
| static SelectedElementsManager instance; // Single instance for the program |
There was a problem hiding this comment.
why is this a singleton? it seems both unnecessary and probably thread-unsafe. if the goal is to persist the list of selected block elements between acquire and produce, just store it as a member variable of the producer class itself. (All Triton producers are stream producers, meaning there is one instance for each stream of events processed in parallel, and each instance will only get called by one thread at a time. https://twiki.cern.ch/twiki/bin/view/CMSPublic/FWMultithreadedFrameworkModuleTypes)
| const auto &gsfElectrons = iEvent.get(gsfElectrons_); | ||
|
|
||
| SelectedElementsManager::getInstance().fill(all_elements); // Fill data once | ||
| std::cout << "filled selected_elements." << std::endl; |
There was a problem hiding this comment.
cout is not allowed (not thread safe)
| vdata2 = inputs[0]; | ||
| data1.toServer(tdata1); | ||
| data2.toServer(tdata2); | ||
| std::cout << "check-point Producer-143_tensorsize_" << tensor_size << std::endl; |
| std::cout << "check-point pid-161_" << output_pid[0][0] << "__" << output_pid[0][1] << "__" << output_pid[0][2] | ||
| << std::endl; | ||
| std::cout << "check-point p4-162_" << output_p4[0][0] << "__" << output_p4[0][1] << "__" << output_p4[0][2] | ||
| << std::endl; |
| //a particle was predicted for this PFElement, otherwise it was a spectator | ||
| if (pred_pid != 0) { | ||
| //muons and charged hadrons should only come from tracks, otherwise we won't have track references to pass downstream | ||
| if (((pred_pid == 13) || (pred_pid == 211)) && elem->type() != reco::PFBlockElement::TRACK) { | ||
| pred_pid = 130; | ||
| } | ||
|
|
||
| float pred_charge = 0.0; | ||
| if (elem->type() == reco::PFBlockElement::TRACK) { | ||
| const auto *eltTrack = dynamic_cast<const reco::PFBlockElementTrack *>(elem); | ||
| //for now, just take the charge from the track | ||
| if (eltTrack->trackRef().isNonnull()) { | ||
| pred_charge = eltTrack->trackRef()->charge(); | ||
| } | ||
|
|
||
| //a track with no muon ref should not produce a muon candidate, instead we interpret it as a charged hadron here | ||
| if (pred_pid == 13 && eltTrack->muonRef().isNull()) { | ||
| pred_pid = 211; | ||
| } | ||
|
|
||
| //taus are reconstructed downstream based on other criteria, instead we interpret it as a charged hadron here | ||
| if (pred_pid == 15) { | ||
| pred_pid = 211; | ||
| } | ||
|
|
||
| //tracks from displaced vertices need reference debugging downstream as well, so we just treat them as neutrals for the moment | ||
| if ((pred_pid == 211) && (eltTrack->isLinkedToDisplacedVertex())) { | ||
| pred_pid = 130; | ||
| } | ||
| } |
There was a problem hiding this comment.
rather than duplicating this logic, it would be preferable to put it into a common function shared between the direct and SONIC producers
| float pred_pt = output_p4[0][ielem * NUM_OUTPUT_FEATURES_P4 + IDX_PT]; | ||
| pred_pt = exp(pred_pt) * inputs[0][ielem * NUM_ELEMENT_FEATURES + 1]; | ||
| float pred_eta = output_p4[0][ielem * NUM_OUTPUT_FEATURES_P4 + IDX_ETA]; | ||
| float pred_sin_phi = output_p4[0][ielem * NUM_OUTPUT_FEATURES_P4 + IDX_SIN_PHI]; | ||
| float pred_cos_phi = output_p4[0][ielem * NUM_OUTPUT_FEATURES_P4 + IDX_COS_PHI]; | ||
| float pred_e = output_p4[0][ielem * NUM_OUTPUT_FEATURES_P4 + IDX_ENERGY]; | ||
| pred_e = exp(pred_e) * inputs[0][ielem * NUM_ELEMENT_FEATURES + 5]; | ||
|
|
||
| auto cand = makeCandidate(pred_pid, pred_charge, pred_pt, pred_eta, pred_sin_phi, pred_cos_phi, pred_e); |
PR description:
This adds an MLPF SONIC producer. It is primarily just a slight update of jpata#70. It will also require adding the appropriate
config.pbtxtfile to https://github.com/cms-data/RecoParticleFlow-PFProducer.PR validation:
I tested this with the same tests done for the standard MLPF producer, as mentioned in cms-sw#50316:
(My testing was based on applying this to CMSSW_17_0_0_pre1, using a local copy of the
config.pbtxtfile.)