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()) {
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));
260 currentJECLevel(
level);
261 currentJECFlavor(flavor);
267 for (std::vector<pat::JetCorrFactors>::const_iterator corrFactor = jec_.begin(); corrFactor != jec_.end();
269 if (corrFactor->jecSet() ==
set) {
270 return (corrFactor - jec_.begin());
276 const std::vector<std::string> Jet::availableJECSets()
const {
277 std::vector<std::string> sets;
278 for (std::vector<pat::JetCorrFactors>::const_iterator corrFactor = jec_.begin(); corrFactor != jec_.end();
280 sets.push_back(corrFactor->jecSet());
284 const std::vector<std::string> Jet::availableJECLevels(
const int&
set)
const {
285 return set >= 0 ? jec_.at(
set).correctionLabels() : std::vector<std::string>();
291 for (
unsigned int idx = 0;
idx < jec_.size(); ++
idx) {
292 if (
set.
empty() || jec_.at(
idx).jecSet() ==
set) {
293 if (jec_[
idx].jecLevel(
level) >= 0) {
294 return jecFactor(jec_[
idx].jecLevel(
level), jec_[
idx].jecFlavor(flavor),
idx);
296 throw cms::Exception(
"InvalidRequest") <<
"This JEC level " <<
level <<
" does not exist. \n";
300 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n" 301 <<
"for a jet energy correction set with label " <<
set <<
"\n";
307 if (!jecSetsAvailable()) {
308 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n";
310 if (!jecSetAvailable(
set)) {
311 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n" 312 <<
"for a jet energy correction set with index " <<
set <<
"\n";
314 return jec_.at(
set).correction(
level, flavor) /
315 jec_.at(currentJECSet_).correction(currentJECLevel_, currentJECFlavor_);
323 for (
unsigned int idx = 0;
idx < jec_.size(); ++
idx) {
324 if (
set.
empty() || jec_.at(
idx).jecSet() ==
set) {
325 if (jec_[
idx].jecLevel(
level) >= 0) {
326 return correctedJet(jec_[
idx].jecLevel(
level), jec_[
idx].jecFlavor(flavor),
idx);
328 throw cms::Exception(
"InvalidRequest") <<
"This JEC level " <<
level <<
" does not exist. \n";
332 throw cms::Exception(
"InvalidRequest") <<
"This JEC set " <<
set <<
" does not exist. \n";
338 Jet correctedJet(*
this);
340 correctedJet.setP4(jecFactor(
level, flavor,
set) *
p4());
342 correctedJet.currentJECSet(
set);
343 correctedJet.currentJECLevel(
level);
344 correctedJet.currentJECFlavor(flavor);
350 const std::vector<std::pair<std::string, float>>& Jet::getPairDiscri()
const {
return pairDiscriVector_; }
353 float Jet::bDiscriminator(
const std::string& aLabel)
const {
355 for (
int i = (
int(pairDiscriVector_.size()) - 1);
i >= 0;
i--) {
356 if (pairDiscriVector_[
i].
first == aLabel) {
365 for (
int i = (
int(tagInfoLabels_.size()) - 1);
i >= 0;
i--) {
366 if (tagInfoLabels_[
i] ==
label) {
367 if (!tagInfosFwdPtr_.empty())
368 return tagInfosFwdPtr_[
i].
get();
369 else if (!tagInfos_.empty())
370 return &tagInfos_[
i];
378 return tagInfoByTypeOrLabel<reco::CandIPTagInfo>(
label);
382 return tagInfoByTypeOrLabel<reco::TrackIPTagInfo>(
label);
386 return tagInfoByTypeOrLabel<reco::CandSoftLeptonTagInfo>(
label);
390 return tagInfoByTypeOrLabel<reco::SoftLeptonTagInfo>(
label);
394 return tagInfoByTypeOrLabel<reco::CandSecondaryVertexTagInfo>(
label);
398 return tagInfoByTypeOrLabel<reco::SecondaryVertexTagInfo>(
label);
402 return tagInfoByTypeOrLabel<reco::BoostedDoubleSVTagInfo>(
label);
406 return tagInfoByTypeOrLabel<reco::PixelClusterTagInfo>(
label);
411 if (
idx == std::string::npos) {
412 tagInfoLabels_.push_back(
label);
414 tagInfoLabels_.push_back(
label.substr(0,
idx));
416 tagInfosFwdPtr_.push_back(
info);
420 float Jet::jetCharge()
const {
return jetCharge_; }
432 caloTowersFwdPtr_.push_back(
tower);
434 embeddedCaloTowers_ =
true;
435 caloTowersTemp_.reset();
442 pfCandidatesFwdPtr_.push_back(
cand);
444 embeddedPFCandidates_ =
true;
445 pfCandidatesTemp_.reset();
452 void Jet::setPartonFlavour(
int partonFl) { jetFlavourInfo_.setPartonFlavour(partonFl); }
455 void Jet::setHadronFlavour(
int hadronFl) { jetFlavourInfo_.setHadronFlavour(hadronFl); }
458 void Jet::setJetFlavourInfo(
const reco::JetFlavourInfo& jetFlavourInfo) { jetFlavourInfo_ = jetFlavourInfo; }
461 void Jet::addBDiscriminatorPair(
const std::pair<std::string, float>& thePair) { pairDiscriVector_.push_back(thePair); }
464 void Jet::setJetCharge(
float jetCharge) { jetCharge_ = jetCharge; }
467 void Jet::cacheCaloTowers()
const {
470 std::unique_ptr<std::vector<CaloTowerPtr>> caloTowersTemp{
new std::vector<CaloTowerPtr>{}};
471 if (embeddedCaloTowers_) {
473 if (!caloTowersFwdPtr_.empty()) {
474 caloTowersTemp->reserve(caloTowersFwdPtr_.size());
475 for (CaloTowerFwdPtrVector::const_iterator ibegin = caloTowersFwdPtr_.begin(),
476 iend = caloTowersFwdPtr_.end(),
480 caloTowersTemp->emplace_back(icalo->ptr());
484 else if (!caloTowers_.empty()) {
485 caloTowersTemp->reserve(caloTowers_.size());
489 caloTowersTemp->emplace_back(&caloTowers_, icalo - ibegin);
496 caloTowersTemp->reserve(nDaughters);
497 for (
unsigned fIndex = 0; fIndex < nDaughters; ++fIndex) {
501 caloTowersTemp->emplace_back(
dau.id(), caloTower,
dau.key());
503 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
507 caloTowersTemp_.set(
std::move(caloTowersTemp));
511 void Jet::cachePFCandidates()
const {
512 std::unique_ptr<std::vector<reco::PFCandidatePtr>> pfCandidatesTemp{
new std::vector<reco::PFCandidatePtr>{}};
514 if (embeddedPFCandidates_) {
516 if (!pfCandidatesFwdPtr_.empty()) {
517 pfCandidatesTemp->reserve(pfCandidatesFwdPtr_.size());
518 for (PFCandidateFwdPtrCollection::const_iterator ibegin = pfCandidatesFwdPtr_.begin(),
519 iend = pfCandidatesFwdPtr_.end(),
523 pfCandidatesTemp->emplace_back(ipf->ptr());
527 else if (!pfCandidates_.empty()) {
528 pfCandidatesTemp->reserve(pfCandidates_.size());
529 for (reco::PFCandidateCollection::const_iterator ibegin = pfCandidates_.begin(),
530 iend = pfCandidates_.end(),
534 pfCandidatesTemp->emplace_back(&pfCandidates_, ipf - ibegin);
541 pfCandidatesTemp->reserve(nDaughters);
542 for (
unsigned fIndex = 0; fIndex < nDaughters; ++fIndex) {
546 pfCandidatesTemp->emplace_back(
dau.id(), pfCandidate,
dau.key());
548 throw cms::Exception(
"Invalid Constituent") <<
"PFJet constituent is not of PFCandidate type";
553 pfCandidatesTemp_.set(
std::move(pfCandidatesTemp));
557 void Jet::cacheDaughters()
const {
559 std::unique_ptr<std::vector<reco::CandidatePtr>> daughtersTemp{
new std::vector<reco::CandidatePtr>{}};
566 daughtersTemp->insert(daughtersTemp->end(), sjdaus.begin(), sjdaus.end());
569 daughtersTemp->push_back(
dau);
571 daughtersTemp_.set(
std::move(daughtersTemp));
576 if (
index < subjetCollections_.size())
577 return subjetCollections_[
index];
579 throw cms::Exception(
"OutOfRange") <<
"Index " <<
index <<
" is out of range" << std::endl;
585 auto found =
find(subjetLabels_.begin(), subjetLabels_.end(),
label);
586 if (
found != subjetLabels_.end()) {
588 return subjetCollections_[
index];
591 <<
"Label " <<
label <<
" does not match any subjet collection" << std::endl;
597 subjetCollections_.push_back(
pieces);
598 subjetLabels_.push_back(
label);
virtual CandidatePtr daughterPtr(size_type i) const
reference to daughter at given position
Jets made from CaloTowers.
virtual void scaleEnergy(double fScale)
scale energy of the jet
bool isNonnull() const
Checks for non-null.
Base class for all types of Jets.
std::vector< CaloTower >::const_iterator const_iterator
virtual const daughters & daughterPtrVector() const
references to daughtes
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
T get() const
get a component
Jets made from PFObjects.
const LorentzVector & p4() const final
four-momentum Lorentz vector
const Specific & getSpecific() const
daughters dau
collection of references to daughters
Container::value_type value_type
std::ostream & operator<<(std::ostream &, BeamSpot beam)
Jets made from CaloJets corrected for ZSP and tracks.
std::vector< edm::Ptr< pat::Jet > > JetPtrCollection
Class storing the jet flavour information.
Jets made from MC generator particles.
const edm::RefToBase< reco::Jet > & getCaloJetRef() const
~Jet() override
Destructor.
edm::Ptr< Candidate > Constituent
std::vector< CandidatePtr > daughters
collection of references to daughters
size_t numberOfDaughters() const override
number of daughters
auto const & tracks
cannot be loose
const Specific & getSpecific() const
block accessors
std::vector< edm::FwdPtr< CaloTower > > CaloTowerFwdPtrCollection
std::vector< edm::FwdPtr< reco::PFCandidate > > PFCandidateFwdPtrCollection
Analysis-level calorimeter jet class.
Particle reconstructed by the particle flow algorithm.
Jet()
Default constructor.
Templated PAT object container.
edm::Ptr< CaloTower > CaloTowerPtr
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
Log< level::Warning, false > LogWarning
edm::Ptr< PFCandidate > PFCandidatePtr
persistent Ptr to a PFCandidate
value_type const * get() const
static std::string const source
void setP4(const LorentzVector &p4) final
set 4-momentum