Skip to content

Commit 0ba7640

Browse files
committed
Update KJets
Functions, called getTag and getId, can also return unchecked.
1 parent ab8740d commit 0ba7640

File tree

3 files changed

+37
-35
lines changed

3 files changed

+37
-35
lines changed

DataFormats/interface/KJetMET.h

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,39 +40,41 @@ typedef std::vector<KBasicJet> KBasicJets;
4040

4141
struct KJetMetadata
4242
{
43-
std::vector<std::string> taggernames;
44-
std::vector<std::string> pujetidnames;
43+
std::vector<std::string> tagNames;
44+
std::vector<std::string> idNames;
4545
};
4646

4747
struct KJet : public KBasicJet
4848
{
49-
std::vector<float> taggers;
50-
unsigned int puJetID;
51-
52-
float getTagger(const std::string &name, const KJetMetadata *taggermetadata) const
53-
{
54-
for (unsigned int i = 0; i < taggermetadata->taggernames.size(); ++i)
55-
{
56-
if (taggermetadata->taggernames[i] == name)
57-
return taggers[i];
49+
std::vector<float> tags;
50+
unsigned int binaryIds;
51+
52+
float getTag(const std::string& name, const KJetMetadata *jetmetadata, bool check = true) const
53+
{
54+
for (unsigned int i = 0; i < jetmetadata->tagNames.size(); ++i)
55+
{
56+
if (jetmetadata->tagNames[i] == name)
57+
return tags[i];
5858
}
59-
std::cout << "Tagger " << name << " not available!" << std::endl;
59+
if (!check)
60+
return -999.;
61+
std::cout << "Tag \"" << name << "\" not available!" << std::endl;
6062
exit(1);
61-
}
62-
63-
bool getpuJetID(const std::string &name, const KJetMetadata *taggermetadata) const
64-
{
65-
for (unsigned int i = 0; i < taggermetadata->pujetidnames.size(); ++i)
66-
{
67-
if (taggermetadata->pujetidnames[i] == name)
68-
return puJetID & (1 << i);
69-
}
70-
std::cout << "PUJetID " << name << " not available!" << std::endl;
63+
}
64+
65+
bool getId(const std::string& name, const KJetMetadata *jetmetadata, bool check = true) const
66+
{
67+
for (unsigned int i = 0; i < jetmetadata->idNames.size(); ++i)
68+
{
69+
if (jetmetadata->idNames[i] == name)
70+
return binaryIds & (1 << i);
71+
}
72+
if (!check)
73+
return false;
74+
std::cout << "Binary ID \"" << name << "\" not available!" << std::endl;
7175
exit(1);
72-
}
73-
76+
}
7477
};
75-
7678
typedef std::vector<KJet> KJets;
7779

7880
struct KBasicMET : public KLV

DataFormats/test/KDebug.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ std::ostream &operator<<(std::ostream &os, const KBasicJet &jet)
7070
std::ostream &operator<<(std::ostream &os, const KJet &jet)
7171
{
7272
os << static_cast<const KBasicJet>(jet) << std::endl;
73-
os << "taggers: " << std::endl;
74-
for (size_t i = 0; i < jet.taggers.size(); ++i)
75-
os << jet.taggers[i] << " " << std::endl;
76-
return os << "\tpuJetId: " << jet.puJetID << std::endl;
73+
os << "tags: " << std::endl;
74+
for (size_t i = 0; i < jet.tags.size(); ++i)
75+
os << jet.tags[i] << " " << std::endl;
76+
return os << "\tIDs: " << std::bitset<8>(jet.binaryIds) << std::endl;
7777
}
7878

7979
std::ostream &operator<<(std::ostream &os, const KBasicTau &tau)

Producers/interface/KJetProducer.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class KJetProducer : public KBaseMultiLVProducer<reco::PFJetCollection, KJets>
2929
|| (tagger[i] == "puJetIDCutbasedMedium")
3030
|| (tagger[i] == "puJetIDCutbasedTight")
3131
|| (tagger[i] == "puJetIDMET") )
32-
names->pujetidnames.push_back(tagger[i]);
32+
names->idNames.push_back(tagger[i]);
3333
else
34-
names->taggernames.push_back(tagger[i]);
34+
names->tagNames.push_back(tagger[i]);
3535
}
3636
return KBaseMultiLVProducer<reco::PFJetCollection, KJets>::onLumi(lumiBlock, setup);
3737
}
@@ -121,9 +121,9 @@ class KJetProducer : public KBaseMultiLVProducer<reco::PFJetCollection, KJets>
121121
for (size_t i = 0; i < tagger.size(); ++i)
122122
{
123123
if ( (tagger[i] == "QGlikelihood") || (tagger[i] == "QGmlp"))
124-
out.taggers.push_back(getvalue( (*tagmap_qg[tagger[i]])[jetRef] ) );
124+
out.tags.push_back(getvalue( (*tagmap_qg[tagger[i]])[jetRef] ) );
125125
else if ((tagger[i] == "puJetIDFullDiscriminant") || (tagger[i] == "puJetIDCutbasedDiscriminant"))
126-
out.taggers.push_back(getsignedvalue( (*tagmap_pu[tagger[i]])[jetRef] ) );
126+
out.tags.push_back(getsignedvalue( (*tagmap_pu[tagger[i]])[jetRef] ) );
127127
else if (tagger[i] == "puJetIDFullLoose")
128128
puJetID.push_back(( (*puJetIDfull_Handle)[jetRef] & (1 << 2) ) != 0);
129129
else if (tagger[i] == "puJetIDFullMedium")
@@ -141,12 +141,12 @@ class KJetProducer : public KBaseMultiLVProducer<reco::PFJetCollection, KJets>
141141
else
142142
{
143143
const reco::JetTagCollection & tags = *(tagmap_b[tagger[i]].product());
144-
out.taggers.push_back(getvalue( tags[this->nCursor].second ) );
144+
out.tags.push_back(getvalue( tags[this->nCursor].second ) );
145145
}
146146
}
147147

148148
for (unsigned int i = 0; i < puJetID.size(); ++i)
149-
out.puJetID |= puJetID[i] << i;
149+
out.binaryIds |= puJetID[i] << i;
150150

151151
// PF variables:
152152
copyP4(in, out.p4);

0 commit comments

Comments
 (0)