90 auto outputTaus = std::make_unique<std::vector<pat::Tau>>();
91 outputTaus->reserve(inputTaus->size());
123 std::set<unsigned int> matched_taus;
125 for (
const auto&
jet : *
jets) {
135 std::pair<std::string, float> bestPnetTauScore(
"probtauundef", -1);
136 float sumOfPnetTauScores = 0;
137 std::vector<float> tauPerDMScores(5);
138 float plusChargeProb = 0;
141 sumOfPnetTauScores +=
score;
142 if (scoreName.find(
"taup") != std::string::npos)
143 plusChargeProb +=
score;
144 if (
score > bestPnetTauScore.second) {
145 bestPnetTauScore.second =
score;
146 bestPnetTauScore.first = scoreName;
148 if (scoreName.find(
"1h0p") != std::string::npos)
149 tauPerDMScores[0] +=
score;
150 else if (scoreName.find(
"1h1") !=
153 tauPerDMScores[1] +=
score;
154 else if (scoreName.find(
"1h2p") != std::string::npos)
155 tauPerDMScores[2] +=
score;
156 else if (scoreName.find(
"3h0p") != std::string::npos)
157 tauPerDMScores[3] +=
score;
158 else if (scoreName.find(
"3h1p") != std::string::npos)
159 tauPerDMScores[4] +=
score;
161 if (sumOfPnetTauScores > 0)
162 plusChargeProb /= sumOfPnetTauScores;
164 float sumOfPnetEleScores = 0, sumOfPnetMuScores = 0;
165 bool isTauScoreBest = (sumOfPnetTauScores > 0);
168 if (scoreName.find(
"ele") != std::string::npos)
169 sumOfPnetEleScores +=
score;
170 else if (scoreName.find(
"mu") != std::string::npos)
171 sumOfPnetMuScores +=
score;
172 if (
score > bestPnetTauScore.second)
173 isTauScoreBest =
false;
177 if (
jet.bDiscriminator(
pnetLabel_ +
":" + scoreName) > bestPnetTauScore.second)
178 isTauScoreBest =
false;
184 (1. - sumOfPnetEleScores -
188 (sumOfPnetTauScores + sumOfPnetEleScores);
190 sumOfPnetTauScores / (sumOfPnetTauScores + sumOfPnetMuScores);
195 bestPnetTauScore.first.find(
"tau") + 3;
196 const char q = (
pos < bestPnetTauScore.first.size()) ? bestPnetTauScore.first[
pos] :
'u';
200 }
else if (
q ==
'p') {
204 auto pNetDM =
tagToDM_.find(bestPnetTauScore.first.substr(
pos));
224 for (
const auto& inputTau : *inputTaus) {
226 if (matched_taus.count(tau_idx - 1) > 0)
231 matched_taus.insert(tau_idx - 1);
233 const size_t nTauIds = inputTau.tauIDs().size();
234 std::vector<pat::Tau::IdPair> tauIds(nTauIds + tauIds_pnet.size());
235 for (
size_t i = 0;
i < nTauIds; ++
i)
236 tauIds[
i] = inputTau.tauIDs()[
i];
237 for (
size_t i = 0;
i < tauIds_pnet.size(); ++
i)
238 tauIds[nTauIds +
i] = tauIds_pnet[
i];
239 outputTau.setTauIDs(tauIds);
241 outputTaus->push_back(outputTau);
257 reco::PFTau pfTauFromJet(bestCharge,
jet.correctedP4(
"Uncorrected"));
259 pfTauFromJet.
setPdgId(bestCharge < 0 ? 15 : -15);
261 pfTauFromJet.setDecayMode(
266 pfTauFromJet.setSignalConeSize(
267 std::clamp(3.6 /
jet.correctedP4(
"Uncorrected").pt(), 0.08, 0.12));
272 pat::Tau outputTauFromJet(pfTauFromJet);
274 std::vector<pat::Tau::IdPair> newtauIds(tauIds_minimal.size() + tauIds_pnet.size());
275 for (
size_t i = 0;
i < tauIds_minimal.size(); ++
i)
276 newtauIds[
i] = tauIds_minimal[
i];
277 for (
size_t i = 0;
i < tauIds_pnet.size(); ++
i)
278 newtauIds[tauIds_minimal.size() +
i] = tauIds_pnet[
i];
279 outputTauFromJet.setTauIDs(newtauIds);
284 outputTauFromJet.setGenJet(genJetTau);
287 outputTaus->push_back(outputTauFromJet);
292 if (matched_taus.size() < inputTaus->size()) {
293 for (
size_t iTau = 0; iTau < inputTaus->size(); ++iTau) {
294 if (matched_taus.count(iTau) > 0)
296 const pat::Tau& inputTau = inputTaus->at(iTau);
298 const size_t nTauIds = inputTau.
tauIDs().size();
299 std::vector<pat::Tau::IdPair> tauIds(nTauIds + tauIds_pnet.size());
300 for (
size_t i = 0;
i < nTauIds; ++
i)
302 for (
size_t i = 0;
i < tauIds_pnet.size(); ++
i) {
303 tauIds[nTauIds +
i] = tauIds_pnet[
i];
304 tauIds[nTauIds +
i].second =
307 outputTau.setTauIDs(tauIds);
308 outputTaus->push_back(outputTau);
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::string pnetPtCorrName_
const bool checkTauScoreIsBest_
std::vector< std::string > pnetTauScoreNames_
edm::EDGetTokenT< pat::JetCollection > jetsToken_
bool isNonnull() const
Checks for non-null.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const std::vector< IdPair > & tauIDs() const
U second(std::pair< T, U > const &p)
ALPAKA_FN_ACC static ALPAKA_FN_INLINE float dR2(Position4 pos1, Position4 pos2)
std::vector< std::string > pnetJetScoreNames_
const float chargeAssignmentProbMin_
Abs< T >::type abs(const T &t)
const std::map< std::string, int > tagToDM_
genJetMatch
switch on/off embedding of matched genJet's
Analysis-level tau class.
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
void fillTauFromJet(reco::PFTau &pfTau, const reco::JetBaseRef &jet)
edm::EDGetTokenT< pat::TauCollection > tausToken_
std::vector< std::string > pnetLepScoreNames_
const std::string pnetLabel_
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
void setPdgId(int pdgId) final