32 template <
typename Cand
idateCastType,
typename TauCastType>
34 const size_t tau_index,
36 const std::vector<pat::Electron>*
electrons,
37 const std::vector<pat::Muon>*
muons,
41 const TauFunc& tau_funcs);
43 template <
typename Cand
idateCastType,
typename TauCastType>
45 const size_t tau_index,
49 const std::vector<pat::Electron>*
electrons,
50 const std::vector<pat::Muon>*
muons,
53 const TauFunc& tau_funcs,
55 std::vector<float>* p_egammaBlockInputs,
56 std::vector<float>* p_muonBlockInputs,
57 std::vector<float>* p_hadronBlockInputs,
58 std::vector<int64_t>* p_GridposInputs);
67 const std::vector<pat::Electron> electron_collection_default;
68 const std::vector<pat::Muon> muon_collection_default;
72 pfTauTransverseImpactParameters_default;
74 const std::vector<pat::Electron>* electron_collection;
75 const std::vector<pat::Muon>* muon_collection;
88 electron_collection = &electron_collection_default;
89 muon_collection = &muon_collection_default;
122 for (
size_t tau_index = 0; tau_index <
taus->size(); ++tau_index) {
124 bool passesPrediscriminants;
126 passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<reco::PFTauDiscriminator>>>(
129 passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<pat::PATTauDiscriminator>>>(
132 if (!passesPrediscriminants)
151 auto& input_tauBlock = iInput.at(
"input_tau");
152 auto& input_innerEgammaBlock = iInput.at(
"input_inner_egamma");
153 auto& input_outerEgammaBlock = iInput.at(
"input_outer_egamma");
154 auto& input_innerMuonBlock = iInput.at(
"input_inner_muon");
155 auto& input_outerMuonBlock = iInput.at(
"input_outer_muon");
156 auto& input_innerHadronBlock = iInput.at(
"input_inner_hadrons");
157 auto& input_outerHadronBlock = iInput.at(
"input_outer_hadrons");
162 auto data_tauBlock = input_tauBlock.allocate<
float>();
163 auto data_innerEgammaBlock = input_innerEgammaBlock.allocate<
float>();
164 auto data_outerEgammaBlock = input_outerEgammaBlock.allocate<
float>();
165 auto data_innerMuonBlock = input_innerMuonBlock.allocate<
float>();
166 auto data_outerMuonBlock = input_outerMuonBlock.allocate<
float>();
167 auto data_innerHadronBlock = input_innerHadronBlock.allocate<
float>();
168 auto data_outerHadronBlock = input_outerHadronBlock.allocate<
float>();
170 for (
unsigned itau_passed = 0; itau_passed <
tau_indices_.size(); ++itau_passed) {
184 prepareInputsV2<pat::PackedCandidate, pat::Tau>(
taus->at(tau_index),
196 input_tauBlock.toServer(data_tauBlock);
198 input_innerEgammaBlock.toServer(data_innerEgammaBlock);
199 input_innerMuonBlock.toServer(data_innerMuonBlock);
200 input_innerHadronBlock.toServer(data_innerHadronBlock);
202 input_outerEgammaBlock.toServer(data_outerEgammaBlock);
203 input_outerMuonBlock.toServer(data_outerMuonBlock);
204 input_outerHadronBlock.toServer(data_outerHadronBlock);
217 const auto& output_tauval = iOutput.at(
"main_output/Softmax");
218 const auto& outputs_tauval = output_tauval.fromServer<
float>();
223 for (
unsigned itau = 0; itau <
taus->size(); ++itau) {
225 pred_all[itau][
k] = (
k == 2) ? -1.
f : 2.
f;
228 for (
unsigned itau_passed = 0; itau_passed <
tau_indices_.size(); ++itau_passed) {
230 std::copy(outputs_tauval[itau_passed].begin(), outputs_tauval[itau_passed].
end(), pred_all[tau_index].begin());
233 for (
int i = 0;
i < 4; ++
i) {
234 std::cout <<
"tau index " << itau_passed <<
" k " <<
i <<
" pred " << pred_all[tau_index][
i] << std::endl;
241 template <
typename Cand
idateCastType,
typename TauCastType>
243 const size_t tau_index,
245 const std::vector<pat::Electron>*
electrons,
246 const std::vector<pat::Muon>*
muons,
250 const TauFunc& tau_funcs) {
254 auto tau_casted =
dynamic_cast<const TauCastType&
>(
tau);
258 fillGrids(tau_casted, pfCands, inner_grid, outer_grid);
263 createTauBlockInputs<CandidateCastType>(tau_casted, tau_index, tau_ref,
pv,
rho, tau_funcs, tauIter);
266 createConvFeatures<CandidateCastType>(tau_casted,
281 createConvFeatures<CandidateCastType>(tau_casted,
298 template <
typename Cand
idateCastType,
typename TauCastType>
300 const size_t tau_index,
304 const std::vector<pat::Electron>*
electrons,
305 const std::vector<pat::Muon>*
muons,
307 const CellGrid&
grid,
308 const TauFunc& tau_funcs,
310 std::vector<float>* p_egammaBlockInputs,
311 std::vector<float>* p_muonBlockInputs,
312 std::vector<float>* p_hadronBlockInputs,
313 std::vector<int64_t>* p_GridposInputs) {
316 int n_cell_oneside = is_inner ? dnn_inputs_v2::number_of_inner_cell : dnn_inputs_v2::number_of_outer_cell;
318 n_cells = is_inner ? (dnn_inputs_v2::number_of_inner_cell * dnn_inputs_v2::number_of_inner_cell)
319 : (dnn_inputs_v2::number_of_outer_cell * dnn_inputs_v2::number_of_outer_cell);
321 p_egammaBlockInputs->insert(
322 p_egammaBlockInputs->end(), n_cells * dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs, 0.);
323 std::vector<float>::iterator egammaIter = p_egammaBlockInputs->begin();
325 p_muonBlockInputs->insert(p_muonBlockInputs->end(), n_cells * dnn_inputs_v2::MuonBlockInputs::NumberOfInputs, 0.);
326 std::vector<float>::iterator muonIter = p_muonBlockInputs->begin();
328 p_hadronBlockInputs->insert(
329 p_hadronBlockInputs->end(), n_cells * dnn_inputs_v2::HadronBlockInputs::NumberOfInputs, 0.);
330 std::vector<float>::iterator hadronIter = p_hadronBlockInputs->begin();
336 std::cout <<
"processing ( eta = " <<
eta <<
", phi = " <<
phi <<
" )" << std::endl;
338 const CellIndex cell_index{
eta,
phi};
340 const auto cell_iter =
grid.find(cell_index);
341 if (cell_iter !=
grid.end()) {
343 std::cout <<
" creating inputs for ( eta = " <<
eta <<
", phi = " <<
phi <<
" ): idx = " <<
idx << std::endl;
345 const Cell& cell = cell_iter->second;
346 const int eta_index =
grid.getEtaTensorIndex(cell_index);
347 const int phi_index =
grid.getPhiTensorIndex(cell_index);
348 std::vector<float>::iterator egammaIterCell =
349 egammaIter + (eta_index * n_cell_oneside + phi_index) * dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs;
350 std::vector<float>::iterator muonIterCell =
351 muonIter + (eta_index * n_cell_oneside + phi_index) * dnn_inputs_v2::MuonBlockInputs::NumberOfInputs;
352 std::vector<float>::iterator hadronIterCell =
353 hadronIter + (eta_index * n_cell_oneside + phi_index) * dnn_inputs_v2::HadronBlockInputs::NumberOfInputs;
355 createEgammaBlockInputs<CandidateCastType>(
356 idx,
tau, tau_index, tau_ref,
pv,
rho,
electrons, pfCands, cell, tau_funcs, is_inner, egammaIterCell);
357 createMuonBlockInputs<CandidateCastType>(
358 idx,
tau, tau_index, tau_ref,
pv,
rho,
muons, pfCands, cell, tau_funcs, is_inner, muonIterCell);
359 createHadronsBlockInputs<CandidateCastType>(
360 idx,
tau, tau_index, tau_ref,
pv,
rho, pfCands, cell, tau_funcs, is_inner, hadronIterCell);
365 std::cout <<
" skipping creation of inputs, because ( eta = " <<
eta <<
", phi = " <<
phi 366 <<
" ) is not in the grid !!" << std::endl;
379 descriptions.
add(
"DeepTauIdSonicProducer",
desc);
edm::EDGetTokenT< std::vector< pat::Electron > > electrons_token_
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
std::vector< float > * p_egammaInnerBlockInputs
std::vector< float > * p_hadronOuterBlockInputs
edm::EDGetTokenT< double > rho_token_
DeepTauIdSonicProducer(edm::ParameterSet const &cfg)
std::map< BasicDiscriminator, size_t > basicDiscrIndexMap_
void produce(edm::Event &iEvent, edm::EventSetup const &iSetup, Output const &iOutput) override
std::vector< float > * p_tauBlockInputs
const std::vector< BasicDiscriminator > requiredBasicDiscriminators_
std::vector< float > * p_egammaOuterBlockInputs
pfTauTransverseImpactParameters
std::vector< float > * p_hadronInnerBlockInputs
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
uint8_t andPrediscriminants_
edm::EDGetTokenT< CandidateCollection > pfcandToken_
edm::EDGetTokenT< std::vector< pat::Muon > > muons_token_
static void fillDescriptionsHelper(edm::ParameterSetDescription &desc)
TritonClient ::Output Output
void createConvFeatures(const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, const std::vector< pat::Electron > *electrons, const std::vector< pat::Muon > *muons, const edm::View< reco::Candidate > &pfCands, const CellGrid &grid, const TauFunc &tau_funcs, bool is_inner, std::vector< float > *p_egammaBlockInputs, std::vector< float > *p_muonBlockInputs, std::vector< float > *p_hadronBlockInputs, std::vector< int64_t > *p_GridposInputs)
std::vector< float > * p_muonInnerBlockInputs
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminators_inputToken_
edm::EDGetTokenT< TauCollection > tausToken_
std::map< BasicDiscriminator, size_t > basicDiscrdR03IndexMap_
const std::vector< BasicDiscriminator > requiredBasicDiscriminatorsdR03_
#define DEFINE_FWK_MODULE(type)
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminatorsdR03_inputToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void acquire(edm::Event const &iEvent, edm::EventSetup const &iSetup, Input &iInput) override
TritonClient ::Input Input
const std::map< BasicDiscriminator, size_t > matchDiscriminatorIndices(edm::Event const &event, edm::EDGetTokenT< reco::TauDiscriminatorContainer > discriminatorContainerToken, std::vector< BasicDiscriminator > requiredDiscr)
void createOutputs(edm::Event &event, const PredType &pred, edm::Handle< TauCollection > taus)
std::vector< float > * p_muonOuterBlockInputs
const bool disable_CellIndex_workaround_
void loadPrediscriminants(edm::Event const &event, edm::Handle< TauCollection > const &taus)
std::vector< int64_t > * p_outerGridposInputs
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void fillGrids(const TauCastType &tau, const Collection &objects, CellGrid &inner_grid, CellGrid &outer_grid)
basicTauDiscriminatorsdR03
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
std::vector< int64_t > * p_innerGridposInputs
T const & const_reference
void prepareInputsV2(TauCollection::const_reference &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const std::vector< pat::Electron > *electrons, const std::vector< pat::Muon > *muons, const edm::View< reco::Candidate > &pfCands, const reco::Vertex &pv, double rho, const TauFunc &tau_funcs)
std::unique_ptr< TritonClient > client_
std::vector< size_t > tau_indices_
constexpr int NumberOfOutputs
edm::EDGetTokenT< edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > > pfTauTransverseImpactParameters_token_