14 embeddedCaloTowers_(
false),
15 embeddedPFCandidates_(
false),
23 embeddedCaloTowers_(
false),
24 embeddedPFCandidates_(
false),
27 tryImportSpecific(aJet);
33 embeddedCaloTowers_(
false),
34 embeddedPFCandidates_(
false),
37 tryImportSpecific(*aJetRef);
43 embeddedCaloTowers_(
false),
44 embeddedPFCandidates_(
false),
47 tryImportSpecific(*aJetRef);
69 out <<
"\tpat::Jet: ";
70 out << std::setiosflags(std::ios::right);
72 out << std::setprecision(3);
73 out <<
" E/pT/eta/phi " 86 specificCalo_.push_back( (static_cast<const reco::CaloJet&>(source)).
getSpecific() );
94 if ( caloJet !=
nullptr ) {
98 edm::LogWarning(
"OptionalProductNotFound") <<
" in pat::Jet, Attempted to add Calo Specifics to JPT Jets, but failed." 99 <<
" Jet ID for JPT Jets will not be available for you." << std::endl;
102 specificPF_.push_back( (static_cast<const reco::PFJet&>(source)).
getSpecific() );
112 CaloTowerPtr Jet::getCaloConstituent (
unsigned fIndex)
const {
113 if (embeddedCaloTowers_) {
115 if ( !caloTowersFwdPtr_.empty() ) {
116 return (fIndex < caloTowersFwdPtr_.size() ?
121 if ( !caloTowers_.empty() ) {
122 return (fIndex < caloTowers_.size() ?
132 if (caloTower !=
nullptr) {
136 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
146 std::vector<CaloTowerPtr>
const & Jet::getCaloConstituents ()
const {
147 if ( !caloTowersTemp_.isSet() || !caloTowers_.empty() ) cacheCaloTowers();
148 return *caloTowersTemp_;
155 if (embeddedPFCandidates_) {
157 if ( !pfCandidatesFwdPtr_.empty() ) {
158 return (fIndex < pfCandidatesFwdPtr_.size() ?
163 if ( !pfCandidates_.empty() ) {
164 return (fIndex < pfCandidates_.size() ?
178 throw cms::Exception(
"Invalid Constituent") <<
"PFJet constituent is not of PFCandidate type";
186 std::vector<reco::PFCandidatePtr>
const & Jet::getPFConstituents ()
const {
187 if ( !pfCandidatesTemp_.isSet() || !pfCandidates_.empty() ) cachePFCandidates();
188 return *pfCandidatesTemp_;
192 if (isCaloJet() || isJPTJet() ) {
193 if ( embeddedCaloTowers_ ) {
194 if ( !caloTowersFwdPtr_.empty() )
return caloTowersFwdPtr_[i].
get();
195 else if ( !caloTowers_.empty() )
return &caloTowers_[i];
200 if ( embeddedPFCandidates_ ) {
201 if ( !pfCandidatesFwdPtr_.empty() )
return pfCandidatesFwdPtr_[i].
get();
202 else if ( !pfCandidates_.empty() )
return &pfCandidates_[i];
206 if ( !subjetCollections_.empty() ) {
207 if ( !daughtersTemp_.isSet() ) cacheDaughters();
208 return daughtersTemp_->at(i).get();
214 if ( !subjetCollections_.empty() ) {
215 if ( !daughtersTemp_.isSet() ) cacheDaughters();
216 return daughtersTemp_->at(i);
222 if ( !subjetCollections_.empty() ) {
223 if ( !daughtersTemp_.isSet() ) cacheDaughters();
224 return *daughtersTemp_;
230 if (isCaloJet() || isJPTJet()) {
231 if ( embeddedCaloTowers_ ) {
232 if ( !caloTowersFwdPtr_.empty() )
return caloTowersFwdPtr_.size();
233 else if ( !caloTowers_.empty() )
return caloTowers_.size();
238 if ( embeddedPFCandidates_ ) {
239 if ( !pfCandidatesFwdPtr_.empty() )
return pfCandidatesFwdPtr_.size();
240 else if ( !pfCandidates_.empty() )
return pfCandidates_.size();
244 if ( !subjetCollections_.empty() ) {
245 if ( !daughtersTemp_.isSet() ) cacheDaughters();
246 return daughtersTemp_->size();
253 if (!genJet_.empty())
return &(genJet_.front());
254 else if ( !genJetRef_.empty() )
return genJetRef_[0].
get();
255 else return genJetFwdRef_.
get();
260 return jetFlavourInfo_.getPartonFlavour();
265 return jetFlavourInfo_.getHadronFlavour();
270 return jetFlavourInfo_;
277 if (jecSetsAvailable()) {
279 jec_[0].insertFactor(0, std::make_pair(level, factors));
288 currentJECLevel(level);
289 currentJECFlavor(flavor);
290 setP4(jec_[
set].correction(level, flavor)*
p4());
296 for(std::vector<pat::JetCorrFactors>::const_iterator corrFactor=jec_.begin(); corrFactor!=jec_.end(); ++corrFactor)
297 if( corrFactor->jecSet()==set ){
return (corrFactor-jec_.begin()); }
302 const std::vector<std::string> Jet::availableJECSets()
const 304 std::vector<std::string> sets;
305 for(std::vector<pat::JetCorrFactors>::const_iterator corrFactor=jec_.begin(); corrFactor!=jec_.end(); ++corrFactor)
306 sets.push_back(corrFactor->jecSet());
310 const std::vector<std::string> Jet::availableJECLevels(
const int&
set)
const 312 return set>=0 ? jec_.at(
set).correctionLabels() : std::vector<std::string>();
319 for(
unsigned int idx=0;
idx<jec_.size(); ++
idx){
320 if(
set.
empty() || jec_.at(
idx).jecSet()==
set){
321 if(jec_[
idx].jecLevel(level)>=0){
322 return jecFactor(jec_[
idx].jecLevel(level), jec_[
idx].jecFlavor(flavor),
idx);
325 throw cms::Exception(
"InvalidRequest") <<
"This JEC level " << level <<
" does not exist. \n";
329 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n" 330 <<
"for a jet energy correction set with label " <<
set <<
"\n";
335 float Jet::jecFactor(
const unsigned int& level,
const JetCorrFactors::Flavor& flavor,
const unsigned int&
set)
const 337 if(!jecSetsAvailable()){
338 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n";
340 if(!jecSetAvailable(
set)){
341 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n" 342 <<
"for a jet energy correction set with index " <<
set <<
"\n";
344 return jec_.at(
set).correction(level, flavor)/jec_.at(currentJECSet_).correction(currentJECLevel_, currentJECFlavor_);
353 for(
unsigned int idx=0;
idx<jec_.size(); ++
idx){
354 if(
set.
empty() || jec_.at(
idx).jecSet()==
set){
355 if(jec_[
idx].jecLevel(level)>=0){
356 return correctedJet(jec_[
idx].jecLevel(level), jec_[
idx].jecFlavor(flavor),
idx);
359 throw cms::Exception(
"InvalidRequest") <<
"This JEC level " << level <<
" does not exist. \n";
363 throw cms::Exception(
"InvalidRequest") <<
"This JEC set " <<
set <<
" does not exist. \n";
370 Jet correctedJet(*
this);
372 correctedJet.
setP4(jecFactor(level, flavor,
set)*
p4());
374 correctedJet.currentJECSet(
set); correctedJet.currentJECLevel(level); correctedJet.currentJECFlavor(flavor);
381 const std::vector<std::pair<std::string, float> > & Jet::getPairDiscri()
const {
382 return pairDiscriVector_;
386 float Jet::bDiscriminator(
const std::string & aLabel)
const {
388 for(
int i=(
int(pairDiscriVector_.size())-1); i>=0; i--){
389 if(pairDiscriVector_[i].
first == aLabel){
390 discriminator = pairDiscriVector_[
i].second;
398 for(
int i=(
int(tagInfoLabels_.size())-1); i>=0; i--){
399 if (tagInfoLabels_[i] == label) {
400 if ( !tagInfosFwdPtr_.empty() )
return tagInfosFwdPtr_[i].
get();
401 else if ( !tagInfos_.empty() )
return & tagInfos_[i];
410 Jet::tagInfoCandIP(
const std::string &label)
const {
411 return tagInfoByTypeOrLabel<reco::CandIPTagInfo>(
label);
415 Jet::tagInfoTrackIP(
const std::string &label)
const {
416 return tagInfoByTypeOrLabel<reco::TrackIPTagInfo>(
label);
420 Jet::tagInfoCandSoftLepton(
const std::string &label)
const {
421 return tagInfoByTypeOrLabel<reco::CandSoftLeptonTagInfo>(
label);
425 Jet::tagInfoSoftLepton(
const std::string &label)
const {
426 return tagInfoByTypeOrLabel<reco::SoftLeptonTagInfo>(
label);
430 Jet::tagInfoCandSecondaryVertex(
const std::string &label)
const {
431 return tagInfoByTypeOrLabel<reco::CandSecondaryVertexTagInfo>(
label);
435 Jet::tagInfoSecondaryVertex(
const std::string &label)
const {
436 return tagInfoByTypeOrLabel<reco::SecondaryVertexTagInfo>(
label);
440 Jet::tagInfoBoostedDoubleSV(
const std::string &label)
const {
441 return tagInfoByTypeOrLabel<reco::BoostedDoubleSVTagInfo>(
label);
448 if (idx == std::string::npos) {
449 tagInfoLabels_.push_back(label);
451 tagInfoLabels_.push_back(label.substr(0,idx));
453 tagInfosFwdPtr_.push_back(info);
459 float Jet::jetCharge()
const {
465 return associatedTracks_;
470 associatedTracks_ =
tracks;
475 caloTowersFwdPtr_.reserve(caloTowers.size());
476 for(
auto const& tower : caloTowers) {
477 caloTowersFwdPtr_.push_back( tower );
479 embeddedCaloTowers_ =
true;
480 caloTowersTemp_.reset();
486 pfCandidatesFwdPtr_.reserve(pfCandidates.size());
487 for(
auto const&
cand : pfCandidates) {
488 pfCandidatesFwdPtr_.push_back(
cand);
490 embeddedPFCandidates_ =
true;
491 pfCandidatesTemp_.reset();
504 void Jet::setPartonFlavour(
int partonFl) {
505 jetFlavourInfo_.setPartonFlavour(partonFl);
509 void Jet::setHadronFlavour(
int hadronFl) {
510 jetFlavourInfo_.setHadronFlavour(hadronFl);
515 jetFlavourInfo_ = jetFlavourInfo;
519 void Jet::addBDiscriminatorPair(
const std::pair<std::string, float> & thePair) {
520 pairDiscriVector_.push_back(thePair);
524 void Jet::setJetCharge(
float jetCharge) {
525 jetCharge_ = jetCharge;
531 void Jet::cacheCaloTowers()
const {
534 std::unique_ptr<std::vector<CaloTowerPtr>> caloTowersTemp{
new std::vector<CaloTowerPtr>{}};
535 if ( embeddedCaloTowers_ ) {
537 if ( !caloTowersFwdPtr_.empty() ) {
538 caloTowersTemp->reserve(caloTowersFwdPtr_.size());
539 for ( CaloTowerFwdPtrVector::const_iterator ibegin=caloTowersFwdPtr_.begin(),
540 iend = caloTowersFwdPtr_.end(),
542 icalo != iend; ++icalo ) {
543 caloTowersTemp->emplace_back( icalo->ptr() );
547 else if ( !caloTowers_.empty() ) {
548 caloTowersTemp->reserve(caloTowers_.size());
550 iend = caloTowers_.end(),
552 icalo != iend; ++icalo ) {
553 caloTowersTemp->emplace_back( &caloTowers_, icalo - ibegin );
560 caloTowersTemp->reserve(nDaughters);
561 for (
unsigned fIndex = 0; fIndex < nDaughters; ++fIndex ) {
565 caloTowersTemp->emplace_back( dau.id(), caloTower,dau.key() );
568 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
572 caloTowersTemp_.set(
std::move(caloTowersTemp));
576 void Jet::cachePFCandidates()
const {
578 std::unique_ptr<std::vector<reco::PFCandidatePtr>> pfCandidatesTemp{
new std::vector<reco::PFCandidatePtr>{}};
580 if ( embeddedPFCandidates_ ) {
582 if ( !pfCandidatesFwdPtr_.empty() ) {
583 pfCandidatesTemp->reserve(pfCandidatesFwdPtr_.size());
584 for ( PFCandidateFwdPtrCollection::const_iterator ibegin=pfCandidatesFwdPtr_.begin(),
585 iend = pfCandidatesFwdPtr_.end(),
587 ipf != iend; ++ipf ) {
588 pfCandidatesTemp->emplace_back( ipf->ptr() );
592 else if ( !pfCandidates_.empty() ) {
593 pfCandidatesTemp->reserve(pfCandidates_.size());
594 for ( reco::PFCandidateCollection::const_iterator ibegin=pfCandidates_.begin(),
595 iend = pfCandidates_.end(),
597 ipf != iend; ++ipf ) {
598 pfCandidatesTemp->emplace_back( &pfCandidates_, ipf - ibegin );
605 pfCandidatesTemp->reserve(nDaughters);
606 for (
unsigned fIndex = 0; fIndex < nDaughters; ++fIndex ) {
610 pfCandidatesTemp->emplace_back( dau.id(), pfCandidate,dau.key() );
613 throw cms::Exception(
"Invalid Constituent") <<
"PFJet constituent is not of PFCandidate type";
618 pfCandidatesTemp_.set(
std::move(pfCandidatesTemp));
622 void Jet::cacheDaughters()
const {
624 std::unique_ptr<std::vector<reco::CandidatePtr>> daughtersTemp{
new std::vector<reco::CandidatePtr>{}};
631 daughtersTemp->insert(daughtersTemp->end(), sjdaus.begin(), sjdaus.end());
634 daughtersTemp->push_back(
dau );
636 daughtersTemp_.set(
std::move(daughtersTemp));
642 if ( index < subjetCollections_.size() )
643 return subjetCollections_[index];
645 throw cms::Exception(
"OutOfRange") <<
"Index " << index <<
" is out of range" << std::endl;
652 auto found =
find( subjetLabels_.begin(), subjetLabels_.end(),
label );
653 if (
found != subjetLabels_.end() ){
655 return subjetCollections_[
index];
658 throw cms::Exception(
"SubjetsNotFound") <<
"Label " << label <<
" does not match any subjet collection" << std::endl;
664 subjetCollections_.push_back( pieces );
665 subjetLabels_.push_back( label );
value_type const * get() const
double eta() const final
momentum pseudorapidity
Jets made from CaloTowers.
virtual void scaleEnergy(double fScale)
scale energy of the jet
const Specific & getSpecific() const
block accessors
Base class for all types of Jets.
std::vector< CaloTower >::const_iterator const_iterator
double pt() const final
transverse momentum
bool isNonnull() const
Checks for non-null.
const edm::RefToBase< reco::Jet > & getCaloJetRef() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Jets made from PFObjects.
virtual const daughters & daughterPtrVector() const
references to daughtes
size_t numberOfDaughters() const override
number of daughters
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.
double energy() const final
energy
T get() const
get a component
Jets made from MC generator particles.
const LorentzVector & p4() const final
four-momentum Lorentz vector
~Jet() override
Destructor.
edm::Ptr< Candidate > Constituent
std::vector< CandidatePtr > daughters
collection of references to daughters
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
virtual CandidatePtr daughterPtr(size_type i) const
reference to daughter at given position
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
edm::Ptr< PFCandidate > PFCandidatePtr
persistent Ptr to a PFCandidate
double phi() const final
momentum azimuthal angle
static std::string const source
void setP4(const LorentzVector &p4) final
set 4-momentum
const Specific & getSpecific() const
const Specific & getSpecific() const