18 tryImportSpecific(aJet);
24 tryImportSpecific(*aJetRef);
30 tryImportSpecific(*aJetRef);
45 out <<
"\tpat::Jet: ";
46 out << std::setiosflags(std::ios::right);
48 out << std::setprecision(3);
49 out <<
" E/pT/eta/phi " <<
obj.energy() <<
"/" <<
obj.pt() <<
"/" <<
obj.eta() <<
"/" <<
obj.phi();
57 specificCalo_.push_back((static_cast<const reco::CaloJet&>(
source)).getSpecific());
65 if (caloJet !=
nullptr) {
69 <<
" in pat::Jet, Attempted to add Calo Specifics to JPT Jets, but failed."
70 <<
" Jet ID for JPT Jets will not be available for you." << std::endl;
73 specificPF_.push_back((static_cast<const reco::PFJet&>(
source)).getSpecific());
82 CaloTowerPtr Jet::getCaloConstituent(
unsigned fIndex)
const {
83 if (embeddedCaloTowers_) {
85 if (!caloTowersFwdPtr_.empty()) {
86 return (fIndex < caloTowersFwdPtr_.size() ? caloTowersFwdPtr_[fIndex].ptr() :
CaloTowerPtr());
90 if (!caloTowers_.empty()) {
98 const CaloTower* caloTower = dynamic_cast<const CaloTower*>(
dau.get());
99 if (caloTower !=
nullptr) {
102 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
109 std::vector<CaloTowerPtr>
const& Jet::getCaloConstituents()
const {
110 if (!caloTowersTemp_.isSet() || !caloTowers_.empty())
112 return *caloTowersTemp_;
118 if (embeddedPFCandidates_) {
120 if (!pfCandidatesFwdPtr_.empty()) {
121 return (fIndex < pfCandidatesFwdPtr_.size() ? pfCandidatesFwdPtr_[fIndex].ptr() :
reco::PFCandidatePtr());
125 if (!pfCandidates_.empty()) {
137 throw cms::Exception(
"Invalid Constituent") <<
"PFJet constituent is not of PFCandidate type";
144 std::vector<reco::PFCandidatePtr>
const& Jet::getPFConstituents()
const {
145 if (!pfCandidatesTemp_.isSet() || !pfCandidates_.empty())
147 return *pfCandidatesTemp_;
151 if (isCaloJet() || isJPTJet()) {
152 if (embeddedCaloTowers_) {
153 if (!caloTowersFwdPtr_.empty())
154 return caloTowersFwdPtr_[
i].
get();
155 else if (!caloTowers_.empty())
156 return &caloTowers_[
i];
162 if (embeddedPFCandidates_) {
163 if (!pfCandidatesFwdPtr_.empty())
164 return pfCandidatesFwdPtr_[
i].
get();
165 else if (!pfCandidates_.empty())
166 return &pfCandidates_[
i];
171 if (!subjetCollections_.empty()) {
172 if (!daughtersTemp_.isSet())
174 return daughtersTemp_->at(
i).get();
180 if (!subjetCollections_.empty()) {
181 if (!daughtersTemp_.isSet())
183 return daughtersTemp_->at(
i);
189 if (!subjetCollections_.empty()) {
190 if (!daughtersTemp_.isSet())
192 return *daughtersTemp_;
198 if (isCaloJet() || isJPTJet()) {
199 if (embeddedCaloTowers_) {
200 if (!caloTowersFwdPtr_.empty())
201 return caloTowersFwdPtr_.size();
202 else if (!caloTowers_.empty())
203 return caloTowers_.size();
209 if (embeddedPFCandidates_) {
210 if (!pfCandidatesFwdPtr_.empty())
211 return pfCandidatesFwdPtr_.size();
212 else if (!pfCandidates_.empty())
213 return pfCandidates_.size();
218 if (!subjetCollections_.empty()) {
219 if (!daughtersTemp_.isSet())
221 return daughtersTemp_->size();
228 if (!genJet_.empty())
229 return &(genJet_.front());
230 else if (!genJetRef_.empty())
231 return genJetRef_[0].
get();
233 return genJetFwdRef_.get();
249 if (jecSetsAvailable()) {
251 jec_[0].insertFactor(0, std::make_pair(
level, factors));
259 currentJECLevel(
level);
260 currentJECFlavor(flavor);
266 for (std::vector<pat::JetCorrFactors>::const_iterator corrFactor = jec_.begin(); corrFactor != jec_.end();
268 if (corrFactor->jecSet() == set) {
269 return (corrFactor - jec_.begin());
275 const std::vector<std::string> Jet::availableJECSets()
const {
276 std::vector<std::string> sets;
277 for (std::vector<pat::JetCorrFactors>::const_iterator corrFactor = jec_.begin(); corrFactor != jec_.end();
279 sets.push_back(corrFactor->jecSet());
283 const std::vector<std::string> Jet::availableJECLevels(
const int& set)
const {
284 return set >= 0 ? jec_.at(set).correctionLabels() : std::vector<std::string>();
290 for (
unsigned int idx = 0;
idx < jec_.size(); ++
idx) {
291 if (set.empty() || jec_.at(
idx).jecSet() == set) {
292 if (jec_[
idx].jecLevel(
level) >= 0) {
293 return jecFactor(jec_[
idx].jecLevel(
level), jec_[
idx].jecFlavor(flavor),
idx);
295 throw cms::Exception(
"InvalidRequest") <<
"This JEC level " <<
level <<
" does not exist. \n";
299 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n"
300 <<
"for a jet energy correction set with label " << set <<
"\n";
306 if (!jecSetsAvailable()) {
307 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n";
309 if (!jecSetAvailable(set)) {
310 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n"
311 <<
"for a jet energy correction set with index " << set <<
"\n";
313 return jec_.at(set).correction(
level, flavor) /
314 jec_.at(currentJECSet_).correction(currentJECLevel_, currentJECFlavor_);
322 for (
unsigned int idx = 0;
idx < jec_.size(); ++
idx) {
323 if (set.empty() || jec_.at(
idx).jecSet() == set) {
324 if (jec_[
idx].jecLevel(
level) >= 0) {
325 return correctedJet(jec_[
idx].jecLevel(
level), jec_[
idx].jecFlavor(flavor),
idx);
327 throw cms::Exception(
"InvalidRequest") <<
"This JEC level " <<
level <<
" does not exist. \n";
331 throw cms::Exception(
"InvalidRequest") <<
"This JEC set " << set <<
" does not exist. \n";
337 Jet correctedJet(*
this);
339 correctedJet.setP4(jecFactor(
level, flavor, set) *
p4());
341 correctedJet.currentJECSet(set);
342 correctedJet.currentJECLevel(
level);
343 correctedJet.currentJECFlavor(flavor);
349 const std::vector<std::pair<std::string, float>>& Jet::getPairDiscri()
const {
return pairDiscriVector_; }
352 float Jet::bDiscriminator(
const std::string& aLabel)
const {
354 for (
int i = (
int(pairDiscriVector_.size()) - 1);
i >= 0;
i--) {
355 if (pairDiscriVector_[
i].
first == aLabel) {
364 for (
int i = (
int(tagInfoLabels_.size()) - 1);
i >= 0;
i--) {
365 if (tagInfoLabels_[
i] ==
label) {
366 if (!tagInfosFwdPtr_.empty())
367 return tagInfosFwdPtr_[
i].
get();
368 else if (!tagInfos_.empty())
369 return &tagInfos_[
i];
377 return tagInfoByTypeOrLabel<reco::CandIPTagInfo>(
label);
381 return tagInfoByTypeOrLabel<reco::TrackIPTagInfo>(
label);
385 return tagInfoByTypeOrLabel<reco::CandSoftLeptonTagInfo>(
label);
389 return tagInfoByTypeOrLabel<reco::SoftLeptonTagInfo>(
label);
393 return tagInfoByTypeOrLabel<reco::CandSecondaryVertexTagInfo>(
label);
397 return tagInfoByTypeOrLabel<reco::SecondaryVertexTagInfo>(
label);
401 return tagInfoByTypeOrLabel<reco::BoostedDoubleSVTagInfo>(
label);
405 return tagInfoByTypeOrLabel<reco::PixelClusterTagInfo>(
label);
410 if (
idx == std::string::npos) {
411 tagInfoLabels_.push_back(
label);
413 tagInfoLabels_.push_back(
label.substr(0,
idx));
415 tagInfosFwdPtr_.push_back(
info);
419 float Jet::jetCharge()
const {
return jetCharge_; }
431 caloTowersFwdPtr_.push_back(
tower);
433 embeddedCaloTowers_ =
true;
434 caloTowersTemp_.reset();
441 pfCandidatesFwdPtr_.push_back(
cand);
443 embeddedPFCandidates_ =
true;
444 pfCandidatesTemp_.reset();
451 void Jet::setPartonFlavour(
int partonFl) { jetFlavourInfo_.setPartonFlavour(partonFl); }
454 void Jet::setHadronFlavour(
int hadronFl) { jetFlavourInfo_.setHadronFlavour(hadronFl); }
457 void Jet::setJetFlavourInfo(
const reco::JetFlavourInfo& jetFlavourInfo) { jetFlavourInfo_ = jetFlavourInfo; }
460 void Jet::addBDiscriminatorPair(
const std::pair<std::string, float>& thePair) { pairDiscriVector_.push_back(thePair); }
463 void Jet::setJetCharge(
float jetCharge) { jetCharge_ = jetCharge; }
466 void Jet::cacheCaloTowers()
const {
469 std::unique_ptr<std::vector<CaloTowerPtr>> caloTowersTemp{
new std::vector<CaloTowerPtr>{}};
470 if (embeddedCaloTowers_) {
472 if (!caloTowersFwdPtr_.empty()) {
473 caloTowersTemp->reserve(caloTowersFwdPtr_.size());
474 for (CaloTowerFwdPtrVector::const_iterator ibegin = caloTowersFwdPtr_.begin(),
475 iend = caloTowersFwdPtr_.end(),
479 caloTowersTemp->emplace_back(icalo->ptr());
483 else if (!caloTowers_.empty()) {
484 caloTowersTemp->reserve(caloTowers_.size());
488 caloTowersTemp->emplace_back(&caloTowers_, icalo - ibegin);
495 caloTowersTemp->reserve(nDaughters);
496 for (
unsigned fIndex = 0; fIndex < nDaughters; ++fIndex) {
498 const CaloTower* caloTower = dynamic_cast<const CaloTower*>(
dau.get());
500 caloTowersTemp->emplace_back(
dau.id(), caloTower,
dau.key());
502 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
506 caloTowersTemp_.set(
std::move(caloTowersTemp));
510 void Jet::cachePFCandidates()
const {
511 std::unique_ptr<std::vector<reco::PFCandidatePtr>> pfCandidatesTemp{
new std::vector<reco::PFCandidatePtr>{}};
513 if (embeddedPFCandidates_) {
515 if (!pfCandidatesFwdPtr_.empty()) {
516 pfCandidatesTemp->reserve(pfCandidatesFwdPtr_.size());
517 for (PFCandidateFwdPtrCollection::const_iterator ibegin = pfCandidatesFwdPtr_.begin(),
518 iend = pfCandidatesFwdPtr_.end(),
522 pfCandidatesTemp->emplace_back(ipf->ptr());
526 else if (!pfCandidates_.empty()) {
527 pfCandidatesTemp->reserve(pfCandidates_.size());
528 for (reco::PFCandidateCollection::const_iterator ibegin = pfCandidates_.begin(),
529 iend = pfCandidates_.end(),
533 pfCandidatesTemp->emplace_back(&pfCandidates_, ipf - ibegin);
540 pfCandidatesTemp->reserve(nDaughters);
541 for (
unsigned fIndex = 0; fIndex < nDaughters; ++fIndex) {
545 pfCandidatesTemp->emplace_back(
dau.id(), pfCandidate,
dau.key());
547 throw cms::Exception(
"Invalid Constituent") <<
"PFJet constituent is not of PFCandidate type";
552 pfCandidatesTemp_.set(
std::move(pfCandidatesTemp));
556 void Jet::cacheDaughters()
const {
558 std::unique_ptr<std::vector<reco::CandidatePtr>> daughtersTemp{
new std::vector<reco::CandidatePtr>{}};
562 const reco::Jet* subjet = dynamic_cast<const reco::Jet*>(&*
dau);
565 daughtersTemp->insert(daughtersTemp->end(), sjdaus.begin(), sjdaus.end());
568 daughtersTemp->push_back(
dau);
570 daughtersTemp_.set(
std::move(daughtersTemp));
575 if (
index < subjetCollections_.size())
576 return subjetCollections_[
index];
578 throw cms::Exception(
"OutOfRange") <<
"Index " <<
index <<
" is out of range" << std::endl;
584 auto found =
find(subjetLabels_.begin(), subjetLabels_.end(),
label);
585 if (
found != subjetLabels_.end()) {
587 return subjetCollections_[
index];
590 <<
"Label " <<
label <<
" does not match any subjet collection" << std::endl;
596 subjetCollections_.push_back(
pieces);
597 subjetLabels_.push_back(
label);