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_;
279 currentJECLevel(level);
280 currentJECFlavor(flavor);
281 setP4(jec_[
set].correction(level, flavor)*
p4());
287 for(std::vector<pat::JetCorrFactors>::const_iterator corrFactor=jec_.begin(); corrFactor!=jec_.end(); ++corrFactor)
288 if( corrFactor->jecSet()==set ){
return (corrFactor-jec_.begin()); }
293 const std::vector<std::string> Jet::availableJECSets()
const 295 std::vector<std::string> sets;
296 for(std::vector<pat::JetCorrFactors>::const_iterator corrFactor=jec_.begin(); corrFactor!=jec_.end(); ++corrFactor)
297 sets.push_back(corrFactor->jecSet());
301 const std::vector<std::string> Jet::availableJECLevels(
const int&
set)
const 303 return set>=0 ? jec_.at(
set).correctionLabels() : std::vector<std::string>();
310 for(
unsigned int idx=0;
idx<jec_.size(); ++
idx){
311 if(
set.
empty() || jec_.at(
idx).jecSet()==
set){
312 if(jec_[
idx].jecLevel(level)>=0){
313 return jecFactor(jec_[
idx].jecLevel(level), jec_[
idx].jecFlavor(flavor),
idx);
316 throw cms::Exception(
"InvalidRequest") <<
"This JEC level " << level <<
" does not exist. \n";
320 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n" 321 <<
"for a jet energy correction set with label " <<
set <<
"\n";
326 float Jet::jecFactor(
const unsigned int& level,
const JetCorrFactors::Flavor& flavor,
const unsigned int&
set)
const 328 if(!jecSetsAvailable()){
329 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n";
331 if(!jecSetAvailable(
set)){
332 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n" 333 <<
"for a jet energy correction set with index " <<
set <<
"\n";
335 return jec_.at(
set).correction(level, flavor)/jec_.at(currentJECSet_).correction(currentJECLevel_, currentJECFlavor_);
344 for(
unsigned int idx=0;
idx<jec_.size(); ++
idx){
345 if(
set.
empty() || jec_.at(
idx).jecSet()==
set){
346 if(jec_[
idx].jecLevel(level)>=0){
347 return correctedJet(jec_[
idx].jecLevel(level), jec_[
idx].jecFlavor(flavor),
idx);
350 throw cms::Exception(
"InvalidRequest") <<
"This JEC level " << level <<
" does not exist. \n";
354 throw cms::Exception(
"InvalidRequest") <<
"This JEC set " <<
set <<
" does not exist. \n";
361 Jet correctedJet(*
this);
363 correctedJet.
setP4(jecFactor(level, flavor,
set)*
p4());
365 correctedJet.currentJECSet(
set); correctedJet.currentJECLevel(level); correctedJet.currentJECFlavor(flavor);
372 const std::vector<std::pair<std::string, float> > & Jet::getPairDiscri()
const {
373 return pairDiscriVector_;
377 float Jet::bDiscriminator(
const std::string & aLabel)
const {
379 for(
int i=(
int(pairDiscriVector_.size())-1); i>=0; i--){
380 if(pairDiscriVector_[i].
first == aLabel){
381 discriminator = pairDiscriVector_[
i].second;
389 for(
int i=(
int(tagInfoLabels_.size())-1); i>=0; i--){
390 if (tagInfoLabels_[i] == label) {
391 if ( !tagInfosFwdPtr_.empty() )
return tagInfosFwdPtr_[i].
get();
392 else if ( !tagInfos_.empty() )
return & tagInfos_[i];
401 Jet::tagInfoCandIP(
const std::string &label)
const {
402 return tagInfoByTypeOrLabel<reco::CandIPTagInfo>(
label);
406 Jet::tagInfoTrackIP(
const std::string &label)
const {
407 return tagInfoByTypeOrLabel<reco::TrackIPTagInfo>(
label);
411 Jet::tagInfoCandSoftLepton(
const std::string &label)
const {
412 return tagInfoByTypeOrLabel<reco::CandSoftLeptonTagInfo>(
label);
416 Jet::tagInfoSoftLepton(
const std::string &label)
const {
417 return tagInfoByTypeOrLabel<reco::SoftLeptonTagInfo>(
label);
421 Jet::tagInfoCandSecondaryVertex(
const std::string &label)
const {
422 return tagInfoByTypeOrLabel<reco::CandSecondaryVertexTagInfo>(
label);
426 Jet::tagInfoSecondaryVertex(
const std::string &label)
const {
427 return tagInfoByTypeOrLabel<reco::SecondaryVertexTagInfo>(
label);
431 Jet::tagInfoBoostedDoubleSV(
const std::string &label)
const {
432 return tagInfoByTypeOrLabel<reco::BoostedDoubleSVTagInfo>(
label);
439 if (idx == std::string::npos) {
440 tagInfoLabels_.push_back(label);
442 tagInfoLabels_.push_back(label.substr(0,idx));
444 tagInfosFwdPtr_.push_back(info);
450 float Jet::jetCharge()
const {
456 return associatedTracks_;
461 associatedTracks_ =
tracks;
466 caloTowersFwdPtr_.reserve(caloTowers.size());
467 for(
auto const& tower : caloTowers) {
468 caloTowersFwdPtr_.push_back( tower );
470 embeddedCaloTowers_ =
true;
471 caloTowersTemp_.reset();
477 pfCandidatesFwdPtr_.reserve(pfCandidates.size());
478 for(
auto const&
cand : pfCandidates) {
479 pfCandidatesFwdPtr_.push_back(
cand);
481 embeddedPFCandidates_ =
true;
482 pfCandidatesTemp_.reset();
495 void Jet::setPartonFlavour(
int partonFl) {
496 jetFlavourInfo_.setPartonFlavour(partonFl);
500 void Jet::setHadronFlavour(
int hadronFl) {
501 jetFlavourInfo_.setHadronFlavour(hadronFl);
506 jetFlavourInfo_ = jetFlavourInfo;
510 void Jet::addBDiscriminatorPair(
const std::pair<std::string, float> & thePair) {
511 pairDiscriVector_.push_back(thePair);
515 void Jet::setJetCharge(
float jetCharge) {
516 jetCharge_ = jetCharge;
522 void Jet::cacheCaloTowers()
const {
525 std::unique_ptr<std::vector<CaloTowerPtr>> caloTowersTemp{
new std::vector<CaloTowerPtr>{}};
526 if ( embeddedCaloTowers_ ) {
528 if ( !caloTowersFwdPtr_.empty() ) {
529 caloTowersTemp->reserve(caloTowersFwdPtr_.size());
530 for ( CaloTowerFwdPtrVector::const_iterator ibegin=caloTowersFwdPtr_.begin(),
531 iend = caloTowersFwdPtr_.end(),
533 icalo != iend; ++icalo ) {
534 caloTowersTemp->emplace_back( icalo->ptr() );
538 else if ( !caloTowers_.empty() ) {
539 caloTowersTemp->reserve(caloTowers_.size());
541 iend = caloTowers_.end(),
543 icalo != iend; ++icalo ) {
544 caloTowersTemp->emplace_back( &caloTowers_, icalo - ibegin );
551 caloTowersTemp->reserve(nDaughters);
552 for (
unsigned fIndex = 0; fIndex < nDaughters; ++fIndex ) {
556 caloTowersTemp->emplace_back( dau.id(), caloTower,dau.key() );
559 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
563 caloTowersTemp_.set(
std::move(caloTowersTemp));
567 void Jet::cachePFCandidates()
const {
569 std::unique_ptr<std::vector<reco::PFCandidatePtr>> pfCandidatesTemp{
new std::vector<reco::PFCandidatePtr>{}};
571 if ( embeddedPFCandidates_ ) {
573 if ( !pfCandidatesFwdPtr_.empty() ) {
574 pfCandidatesTemp->reserve(pfCandidatesFwdPtr_.size());
575 for ( PFCandidateFwdPtrCollection::const_iterator ibegin=pfCandidatesFwdPtr_.begin(),
576 iend = pfCandidatesFwdPtr_.end(),
578 ipf != iend; ++ipf ) {
579 pfCandidatesTemp->emplace_back( ipf->ptr() );
583 else if ( !pfCandidates_.empty() ) {
584 pfCandidatesTemp->reserve(pfCandidates_.size());
585 for ( reco::PFCandidateCollection::const_iterator ibegin=pfCandidates_.begin(),
586 iend = pfCandidates_.end(),
588 ipf != iend; ++ipf ) {
589 pfCandidatesTemp->emplace_back( &pfCandidates_, ipf - ibegin );
596 pfCandidatesTemp->reserve(nDaughters);
597 for (
unsigned fIndex = 0; fIndex < nDaughters; ++fIndex ) {
601 pfCandidatesTemp->emplace_back( dau.id(), pfCandidate,dau.key() );
604 throw cms::Exception(
"Invalid Constituent") <<
"PFJet constituent is not of PFCandidate type";
609 pfCandidatesTemp_.set(
std::move(pfCandidatesTemp));
613 void Jet::cacheDaughters()
const {
615 std::unique_ptr<std::vector<reco::CandidatePtr>> daughtersTemp{
new std::vector<reco::CandidatePtr>{}};
622 daughtersTemp->insert(daughtersTemp->end(), sjdaus.begin(), sjdaus.end());
625 daughtersTemp->push_back(
dau );
627 daughtersTemp_.set(
std::move(daughtersTemp));
633 if ( index < subjetCollections_.size() )
634 return subjetCollections_[index];
636 throw cms::Exception(
"OutOfRange") <<
"Index " << index <<
" is out of range" << std::endl;
643 auto found =
find( subjetLabels_.begin(), subjetLabels_.end(),
label );
644 if (
found != subjetLabels_.end() ){
646 return subjetCollections_[
index];
649 throw cms::Exception(
"SubjetsNotFound") <<
"Label " << label <<
" does not match any subjet collection" << std::endl;
655 subjetCollections_.push_back( pieces );
656 subjetLabels_.push_back( label );
value_type const * get() const
double eta() const final
momentum pseudorapidity
Jets made from CaloTowers.
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