94 auto outputTaus = std::make_unique<std::vector<pat::Tau>>();
95 outputTaus->reserve(inputTaus->size());
127 std::set<unsigned int> matched_taus;
129 for (
const auto&
jet : *
jets) {
139 std::pair<std::string, float> bestUtagTauScore(
"probtauundef", -1);
140 float sumOfUtagTauScores = 0;
141 std::vector<float> tauPerDMScores(5);
142 float plusChargeProb = 0;
145 sumOfUtagTauScores +=
score;
146 if (scoreName.find(
"taup") != std::string::npos)
147 plusChargeProb +=
score;
148 if (
score > bestUtagTauScore.second) {
149 bestUtagTauScore.second =
score;
150 bestUtagTauScore.first = scoreName;
152 if (scoreName.find(
"1h0p") != std::string::npos)
153 tauPerDMScores[0] +=
score;
154 else if (scoreName.find(
"1h1") !=
157 tauPerDMScores[1] +=
score;
158 else if (scoreName.find(
"1h2p") != std::string::npos)
159 tauPerDMScores[2] +=
score;
160 else if (scoreName.find(
"3h0p") != std::string::npos)
161 tauPerDMScores[3] +=
score;
162 else if (scoreName.find(
"3h1p") != std::string::npos)
163 tauPerDMScores[4] +=
score;
165 if (sumOfUtagTauScores > 0)
166 plusChargeProb /= sumOfUtagTauScores;
168 float sumOfUtagEleScores = 0, sumOfUtagMuScores = 0;
169 bool isTauScoreBest = (sumOfUtagTauScores > 0);
172 if (scoreName.find(
"ele") != std::string::npos)
173 sumOfUtagEleScores +=
score;
174 else if (scoreName.find(
"mu") != std::string::npos)
175 sumOfUtagMuScores +=
score;
176 if (
score > bestUtagTauScore.second)
177 isTauScoreBest =
false;
181 if (
jet.bDiscriminator(
UTagLabel_ +
":" + scoreName) > bestUtagTauScore.second)
182 isTauScoreBest =
false;
188 (1. - sumOfUtagEleScores -
192 (sumOfUtagTauScores + sumOfUtagEleScores);
194 sumOfUtagTauScores / (sumOfUtagTauScores + sumOfUtagMuScores);
199 bestUtagTauScore.first.find(
"tau") + 3;
200 const char q = (
pos < bestUtagTauScore.first.size()) ? bestUtagTauScore.first[
pos] :
'u';
204 }
else if (
q ==
'p') {
208 auto UtagDM =
tagToDM_.find(bestUtagTauScore.first.substr(
pos));
228 for (
const auto& inputTau : *inputTaus) {
230 if (matched_taus.count(tau_idx - 1) > 0)
235 matched_taus.insert(tau_idx - 1);
237 const size_t nTauIds = inputTau.tauIDs().size();
238 std::vector<pat::Tau::IdPair> tauIds(nTauIds + tauIds_utag.size());
239 for (
size_t i = 0;
i < nTauIds; ++
i)
240 tauIds[
i] = inputTau.tauIDs()[
i];
241 for (
size_t i = 0;
i < tauIds_utag.size(); ++
i) {
242 if ((tauIds_utag[
i].
first.find(
"PtCorr") != std::string::npos) &&
243 (inputTau.tauID(
"decayModeFindingNewDMs") == -1)) {
249 tauIds[nTauIds +
i].first = tauIds_utag[
i].first;
250 tauIds[nTauIds +
i].second = tauIds_utag[
i].second *
jet.correctedP4(
"Uncorrected").pt() / inputTau.pt();
252 tauIds[nTauIds +
i] = tauIds_utag[
i];
255 outputTau.setTauIDs(tauIds);
257 outputTaus->push_back(outputTau);
273 reco::PFTau pfTauFromJet(bestCharge,
jet.correctedP4(
"Uncorrected"));
275 pfTauFromJet.
setPdgId(bestCharge < 0 ? 15 : -15);
277 pfTauFromJet.setDecayMode(
282 pfTauFromJet.setSignalConeSize(
283 std::clamp(3.6 /
jet.correctedP4(
"Uncorrected").pt(), 0.08, 0.12));
288 pat::Tau outputTauFromJet(pfTauFromJet);
290 std::vector<pat::Tau::IdPair> newtauIds(tauIds_minimal.size() + tauIds_utag.size());
291 for (
size_t i = 0;
i < tauIds_minimal.size(); ++
i)
292 newtauIds[
i] = tauIds_minimal[
i];
293 for (
size_t i = 0;
i < tauIds_utag.size(); ++
i)
294 newtauIds[tauIds_minimal.size() +
i] = tauIds_utag[
i];
295 outputTauFromJet.setTauIDs(newtauIds);
300 outputTauFromJet.setGenJet(genJetTau);
303 outputTaus->push_back(outputTauFromJet);
308 if (matched_taus.size() < inputTaus->size()) {
309 for (
size_t iTau = 0; iTau < inputTaus->size(); ++iTau) {
310 if (matched_taus.count(iTau) > 0)
312 const pat::Tau& inputTau = inputTaus->at(iTau);
314 const size_t nTauIds = inputTau.
tauIDs().size();
315 std::vector<pat::Tau::IdPair> tauIds(nTauIds + tauIds_utag.size());
316 for (
size_t i = 0;
i < nTauIds; ++
i)
318 for (
size_t i = 0;
i < tauIds_utag.size(); ++
i) {
319 tauIds[nTauIds +
i] = tauIds_utag[
i];
320 tauIds[nTauIds +
i].second =
323 outputTau.setTauIDs(tauIds);
324 outputTaus->push_back(outputTau);
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
const bool checkTauScoreIsBest_
edm::EDGetTokenT< pat::JetCollection > jetsToken_
std::vector< std::string > utagTauScoreNames_
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)
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
std::vector< std::string > utagJetScoreNames_
Analysis-level tau class.
const std::string UTagLabel_
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
void fillTauFromJet(reco::PFTau &pfTau, const reco::JetBaseRef &jet)
edm::EDGetTokenT< pat::TauCollection > tausToken_
std::string UtagPtCorrName_
const std::string tagPrefix_
std::vector< std::string > utagLepScoreNames_
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
void setPdgId(int pdgId) final