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);
71 out << std::setiosflags(std::ios::fixed);
72 out << std::setprecision(3);
73 out <<
" E/pT/eta/phi "
86 specificCalo_.push_back( (static_cast<const reco::CaloJet&>(source)).getSpecific() );
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_.size() > 0 ) {
116 return (fIndex < caloTowersFwdPtr_.size() ?
121 if ( caloTowers_.size() > 0 ) {
122 return (fIndex < caloTowers_.size() ?
132 if (caloTower != 0) {
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_.size() > 0 ) cacheCaloTowers();
148 return *caloTowersTemp_;
155 if (embeddedPFCandidates_) {
157 if ( pfCandidatesFwdPtr_.size() > 0 ) {
158 return (fIndex < pfCandidatesFwdPtr_.size() ?
163 if ( pfCandidates_.size() > 0 ) {
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_.size() > 0 ) cachePFCandidates();
188 return *pfCandidatesTemp_;
192 if (isCaloJet() || isJPTJet() ) {
193 if ( embeddedCaloTowers_ ) {
194 if ( caloTowersFwdPtr_.size() > 0 )
return caloTowersFwdPtr_[i].
get();
195 else if ( caloTowers_.size() > 0 )
return &caloTowers_[i];
200 if ( embeddedPFCandidates_ ) {
201 if ( pfCandidatesFwdPtr_.size() > 0 )
return pfCandidatesFwdPtr_[i].
get();
202 else if ( pfCandidates_.size() > 0 )
return &pfCandidates_[i];
210 if (isCaloJet() || isJPTJet()) {
211 if ( embeddedCaloTowers_ ) {
212 if ( caloTowersFwdPtr_.size() > 0 )
return caloTowersFwdPtr_.size();
213 else if ( caloTowers_.size() > 0 )
return caloTowers_.size();
218 if ( embeddedPFCandidates_ ) {
219 if ( pfCandidatesFwdPtr_.size() > 0 )
return pfCandidatesFwdPtr_.size();
220 else if ( pfCandidates_.size() > 0 )
return pfCandidates_.size();
229 if (genJet_.size())
return &(genJet_.front());
230 else if ( genJetRef_.size() )
return genJetRef_[0].
get();
231 else return genJetFwdRef_.
get();
235 int Jet::partonFlavour()
const {
236 return jetFlavourInfo_.getPartonFlavour();
240 int Jet::hadronFlavour()
const {
241 return jetFlavourInfo_.getHadronFlavour();
246 return jetFlavourInfo_;
255 currentJECLevel(level);
256 currentJECFlavor(flavor);
257 setP4(jec_[set].correction(level, flavor)*
p4());
263 for(std::vector<pat::JetCorrFactors>::const_iterator corrFactor=jec_.begin(); corrFactor!=jec_.end(); ++corrFactor)
264 if( corrFactor->jecSet()==set ){
return (corrFactor-jec_.begin()); }
269 const std::vector<std::string> Jet::availableJECSets()
const
271 std::vector<std::string> sets;
272 for(std::vector<pat::JetCorrFactors>::const_iterator corrFactor=jec_.begin(); corrFactor!=jec_.end(); ++corrFactor)
273 sets.push_back(corrFactor->jecSet());
277 const std::vector<std::string> Jet::availableJECLevels(
const int& set)
const
279 return set>=0 ? jec_.at(set).correctionLabels() : std::vector<std::string>();
286 for(
unsigned int idx=0;
idx<jec_.size(); ++
idx){
287 if(set.empty() || jec_.at(
idx).jecSet()==set){
288 if(jec_[
idx].jecLevel(level)>=0){
289 return jecFactor(jec_[
idx].jecLevel(level), jec_[
idx].jecFlavor(flavor),
idx);
292 throw cms::Exception(
"InvalidRequest") <<
"This JEC level " << level <<
" does not exist. \n";
296 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n"
297 <<
"for a jet energy correction set with label " << set <<
"\n";
302 float Jet::jecFactor(
const unsigned int& level,
const JetCorrFactors::Flavor& flavor,
const unsigned int& set)
const
304 if(!jecSetsAvailable()){
305 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n";
307 if(!jecSetAvailable(set)){
308 throw cms::Exception(
"InvalidRequest") <<
"This jet does not carry any jet energy correction factor information \n"
309 <<
"for a jet energy correction set with index " << set <<
"\n";
311 return jec_.at(set).correction(level, flavor)/jec_.at(currentJECSet_).correction(currentJECLevel_, currentJECFlavor_);
320 for(
unsigned int idx=0;
idx<jec_.size(); ++
idx){
321 if(set.empty() || jec_.at(
idx).jecSet()==set){
322 if(jec_[
idx].jecLevel(level)>=0){
323 return correctedJet(jec_[
idx].jecLevel(level), jec_[
idx].jecFlavor(flavor),
idx);
326 throw cms::Exception(
"InvalidRequest") <<
"This JEC level " << level <<
" does not exist. \n";
330 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); correctedJet.currentJECLevel(level); correctedJet.currentJECFlavor(flavor);
348 const std::vector<std::pair<std::string, float> > & Jet::getPairDiscri()
const {
349 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){
357 discriminator = pairDiscriVector_[
i].second;
365 for(
int i=(
int(tagInfoLabels_.size())-1); i>=0; i--){
366 if (tagInfoLabels_[i] == label) {
367 if ( tagInfosFwdPtr_.size() > 0 )
return tagInfosFwdPtr_[i].
get();
368 else if ( tagInfos_.size() > 0 )
return & tagInfos_[i];
377 Jet::tagInfoCandIP(
const std::string &label)
const {
378 return tagInfoByTypeOrLabel<reco::CandIPTagInfo>(
label);
382 Jet::tagInfoTrackIP(
const std::string &label)
const {
383 return tagInfoByTypeOrLabel<reco::TrackIPTagInfo>(
label);
387 Jet::tagInfoCandSoftLepton(
const std::string &label)
const {
388 return tagInfoByTypeOrLabel<reco::CandSoftLeptonTagInfo>(
label);
392 Jet::tagInfoSoftLepton(
const std::string &label)
const {
393 return tagInfoByTypeOrLabel<reco::SoftLeptonTagInfo>(
label);
397 Jet::tagInfoCandSecondaryVertex(
const std::string &label)
const {
398 return tagInfoByTypeOrLabel<reco::CandSecondaryVertexTagInfo>(
label);
402 Jet::tagInfoSecondaryVertex(
const std::string &label)
const {
403 return tagInfoByTypeOrLabel<reco::SecondaryVertexTagInfo>(
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);
421 float Jet::jetCharge()
const {
427 return associatedTracks_;
432 associatedTracks_ =
tracks;
437 caloTowersFwdPtr_.reserve(caloTowers.size());
438 for(
auto const& tower : caloTowers) {
439 caloTowersFwdPtr_.push_back( tower );
441 embeddedCaloTowers_ =
true;
442 caloTowersTemp_.reset();
448 pfCandidatesFwdPtr_.reserve(pfCandidates.size());
449 for(
auto const& cand : pfCandidates) {
450 pfCandidatesFwdPtr_.push_back(cand);
452 embeddedPFCandidates_ =
true;
453 pfCandidatesTemp_.reset();
466 void Jet::setPartonFlavour(
int partonFl) {
467 jetFlavourInfo_.setPartonFlavour(partonFl);
471 void Jet::setHadronFlavour(
int hadronFl) {
472 jetFlavourInfo_.setHadronFlavour(hadronFl);
477 jetFlavourInfo_ = jetFlavourInfo;
481 void Jet::addBDiscriminatorPair(
const std::pair<std::string, float> & thePair) {
482 pairDiscriVector_.push_back(thePair);
486 void Jet::setJetCharge(
float jetCharge) {
487 jetCharge_ = jetCharge;
493 void Jet::cacheCaloTowers()
const {
496 std::unique_ptr<std::vector<CaloTowerPtr>> caloTowersTemp{
new std::vector<CaloTowerPtr>{}};
497 if ( embeddedCaloTowers_ ) {
499 if ( caloTowersFwdPtr_.size() > 0 ) {
500 caloTowersTemp->reserve(caloTowersFwdPtr_.size());
501 for ( CaloTowerFwdPtrVector::const_iterator ibegin=caloTowersFwdPtr_.begin(),
502 iend = caloTowersFwdPtr_.end(),
504 icalo != iend; ++icalo ) {
505 caloTowersTemp->emplace_back( icalo->ptr() );
509 else if ( caloTowers_.size() > 0 ) {
510 caloTowersTemp->reserve(caloTowers_.size());
512 iend = caloTowers_.end(),
514 icalo != iend; ++icalo ) {
515 caloTowersTemp->emplace_back( &caloTowers_, icalo - ibegin );
522 caloTowersTemp->reserve(nDaughters);
523 for (
unsigned fIndex = 0; fIndex < nDaughters; ++fIndex ) {
527 caloTowersTemp->emplace_back( dau.id(), caloTower,dau.key() );
530 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
534 caloTowersTemp_.set(
std::move(caloTowersTemp));
538 void Jet::cachePFCandidates()
const {
540 std::unique_ptr<std::vector<reco::PFCandidatePtr>> pfCandidatesTemp{
new std::vector<reco::PFCandidatePtr>{}};
542 if ( embeddedPFCandidates_ ) {
544 if ( pfCandidatesFwdPtr_.size() > 0 ) {
545 pfCandidatesTemp->reserve(pfCandidatesFwdPtr_.size());
546 for ( PFCandidateFwdPtrCollection::const_iterator ibegin=pfCandidatesFwdPtr_.begin(),
547 iend = pfCandidatesFwdPtr_.end(),
549 ipf != iend; ++ipf ) {
550 pfCandidatesTemp->emplace_back( ipf->ptr() );
554 else if ( pfCandidates_.size() > 0 ) {
555 pfCandidatesTemp->reserve(pfCandidates_.size());
556 for ( reco::PFCandidateCollection::const_iterator ibegin=pfCandidates_.begin(),
557 iend = pfCandidates_.end(),
559 ipf != iend; ++ipf ) {
560 pfCandidatesTemp->emplace_back( &pfCandidates_, ipf - ibegin );
567 pfCandidatesTemp->reserve(nDaughters);
568 for (
unsigned fIndex = 0; fIndex < nDaughters; ++fIndex ) {
572 pfCandidatesTemp->emplace_back( dau.id(), pfCandidate,dau.key() );
575 throw cms::Exception(
"Invalid Constituent") <<
"PFJet constituent is not of PFCandidate type";
580 pfCandidatesTemp_.set(
std::move(pfCandidatesTemp));
588 if ( index < subjetCollections_.size() )
589 return subjetCollections_[index];
591 throw cms::Exception(
"OutOfRange") <<
"Index " << index <<
" is out of range" << std::endl;
598 auto found =
find( subjetLabels_.begin(), subjetLabels_.end(),
label );
599 if (
found != subjetLabels_.end() ){
601 return subjetCollections_[
index];
604 throw cms::Exception(
"SubjetsNotFound") <<
"Label " << label <<
" does not match any subjet collection" << std::endl;
610 subjetCollections_.push_back( pieces );
611 subjetLabels_.push_back( label );
value_type const * get() const
Jets made from CaloTowers.
virtual double energy() const final
energy
CandidatePtr daughterPtr(size_type i) const
reference to daughter at given position
const Specific & getSpecific() const
block accessors
Base class for all types of Jets.
std::vector< CaloTower >::const_iterator const_iterator
virtual double phi() const final
momentum azimuthal angle
virtual ~Jet()
Destructor.
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.
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
daughters dau
collection of references to daughters
virtual size_t numberOfDaughters() const
number of daughters
Container::value_type value_type
std::ostream & operator<<(std::ostream &, BeamSpot beam)
Jets made from CaloJets corrected for ZSP and tracks.
edm::Ptr< CaloTower > CaloTowerPtr
std::vector< edm::Ptr< pat::Jet > > JetPtrCollection
Class storing the jet flavour information.
T get() const
get a component
Jets made from MC generator particles.
edm::Ptr< Candidate > Constituent
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
std::vector< edm::FwdPtr< CaloTower > > CaloTowerFwdPtrCollection
std::vector< edm::FwdPtr< reco::PFCandidate > > PFCandidateFwdPtrCollection
virtual void setP4(const LorentzVector &p4) final
set 4-momentum
Analysis-level calorimeter jet class.
Particle reconstructed by the particle flow algorithm.
Jet()
Default constructor.
Templated PAT object container.
virtual double eta() const final
momentum pseudorapidity
volatile std::atomic< bool > shutdown_flag false
edm::Ptr< PFCandidate > PFCandidatePtr
persistent Ptr to a PFCandidate
static std::string const source
virtual const LorentzVector & p4() const final
four-momentum Lorentz vector
virtual const Candidate * daughter(size_type) const
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
virtual double pt() const final
transverse momentum
const Specific & getSpecific() const