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() ?
130 Constituent dau = daughterPtr (fIndex);
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() ?
172 Constituent dau = daughterPtr (fIndex);
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 {
354 float discriminator = -1000.;
355 const std::string & theLabel = ((aLabel ==
"" || aLabel ==
"default")) ?
"trackCountingHighEffBJetTags" : aLabel;
356 for(
unsigned int i=0; i!=pairDiscriVector_.size(); i++){
357 if(pairDiscriVector_[i].
first == theLabel){
358 discriminator = pairDiscriVector_[
i].second;
361 return discriminator;
365 std::vector<std::string>::const_iterator it =
std::find(tagInfoLabels_.begin(), tagInfoLabels_.end(),
label);
366 if (it != tagInfoLabels_.end()) {
367 if ( tagInfosFwdPtr_.size() > 0 )
return tagInfosFwdPtr_[it - tagInfoLabels_.begin()].get();
368 else if ( tagInfos_.size() > 0 )
return & tagInfos_[it - tagInfoLabels_.begin()];
376 Jet::tagInfoCandIP(
const std::string &label)
const {
377 return tagInfoByTypeOrLabel<reco::CandIPTagInfo>(
label);
381 Jet::tagInfoTrackIP(
const std::string &label)
const {
382 return tagInfoByTypeOrLabel<reco::TrackIPTagInfo>(
label);
386 Jet::tagInfoCandSoftLepton(
const std::string &label)
const {
387 return tagInfoByTypeOrLabel<reco::CandSoftLeptonTagInfo>(
label);
391 Jet::tagInfoSoftLepton(
const std::string &label)
const {
392 return tagInfoByTypeOrLabel<reco::SoftLeptonTagInfo>(
label);
396 Jet::tagInfoCandSecondaryVertex(
const std::string &label)
const {
397 return tagInfoByTypeOrLabel<reco::CandSecondaryVertexTagInfo>(
label);
401 Jet::tagInfoSecondaryVertex(
const std::string &label)
const {
402 return tagInfoByTypeOrLabel<reco::SecondaryVertexTagInfo>(
label);
409 if (idx == std::string::npos) {
410 tagInfoLabels_.push_back(label);
412 tagInfoLabels_.push_back(label.substr(0,idx));
414 tagInfosFwdPtr_.push_back(info);
420 float Jet::jetCharge()
const {
426 return associatedTracks_;
431 associatedTracks_ =
tracks;
436 caloTowersFwdPtr_.reserve(caloTowers.size());
437 for(
auto const& tower : caloTowers) {
438 caloTowersFwdPtr_.push_back( tower );
440 embeddedCaloTowers_ =
true;
441 caloTowersTemp_.reset();
447 pfCandidatesFwdPtr_.reserve(pfCandidates.size());
448 for(
auto const& cand : pfCandidates) {
449 pfCandidatesFwdPtr_.push_back(cand);
451 embeddedPFCandidates_ =
true;
452 pfCandidatesTemp_.reset();
465 void Jet::setPartonFlavour(
int partonFl) {
466 jetFlavourInfo_.setPartonFlavour(partonFl);
470 void Jet::setHadronFlavour(
int hadronFl) {
471 jetFlavourInfo_.setHadronFlavour(hadronFl);
476 jetFlavourInfo_ = jetFlavourInfo;
480 void Jet::addBDiscriminatorPair(
const std::pair<std::string, float> & thePair) {
481 pairDiscriVector_.push_back(thePair);
485 void Jet::setJetCharge(
float jetCharge) {
486 jetCharge_ = jetCharge;
492 void Jet::cacheCaloTowers()
const {
495 std::unique_ptr<std::vector<CaloTowerPtr>> caloTowersTemp{
new std::vector<CaloTowerPtr>{}};
496 if ( embeddedCaloTowers_ ) {
498 if ( caloTowersFwdPtr_.size() > 0 ) {
499 caloTowersTemp->reserve(caloTowersFwdPtr_.size());
500 for ( CaloTowerFwdPtrVector::const_iterator ibegin=caloTowersFwdPtr_.begin(),
501 iend = caloTowersFwdPtr_.end(),
503 icalo != iend; ++icalo ) {
504 caloTowersTemp->emplace_back( icalo->ptr() );
508 else if ( caloTowers_.size() > 0 ) {
509 caloTowersTemp->reserve(caloTowers_.size());
511 iend = caloTowers_.end(),
513 icalo != iend; ++icalo ) {
514 caloTowersTemp->emplace_back( &caloTowers_, icalo - ibegin );
521 caloTowersTemp->reserve(nDaughters);
522 for (
unsigned fIndex = 0; fIndex < nDaughters; ++fIndex ) {
523 Constituent
const & dau = daughterPtr (fIndex);
526 caloTowersTemp->emplace_back( dau.id(), caloTower,dau.key() );
529 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
533 caloTowersTemp_.set(std::move(caloTowersTemp));
537 void Jet::cachePFCandidates()
const {
539 std::unique_ptr<std::vector<reco::PFCandidatePtr>> pfCandidatesTemp{
new std::vector<reco::PFCandidatePtr>{}};
541 if ( embeddedPFCandidates_ ) {
543 if ( pfCandidatesFwdPtr_.size() > 0 ) {
544 pfCandidatesTemp->reserve(pfCandidatesFwdPtr_.size());
545 for ( PFCandidateFwdPtrCollection::const_iterator ibegin=pfCandidatesFwdPtr_.begin(),
546 iend = pfCandidatesFwdPtr_.end(),
548 ipf != iend; ++ipf ) {
549 pfCandidatesTemp->emplace_back( ipf->ptr() );
553 else if ( pfCandidates_.size() > 0 ) {
554 pfCandidatesTemp->reserve(pfCandidates_.size());
555 for ( reco::PFCandidateCollection::const_iterator ibegin=pfCandidates_.begin(),
556 iend = pfCandidates_.end(),
558 ipf != iend; ++ipf ) {
559 pfCandidatesTemp->emplace_back( &pfCandidates_, ipf - ibegin );
566 pfCandidatesTemp->reserve(nDaughters);
567 for (
unsigned fIndex = 0; fIndex < nDaughters; ++fIndex ) {
568 Constituent
const & dau = daughterPtr (fIndex);
571 pfCandidatesTemp->emplace_back( dau.id(), pfCandidate,dau.key() );
574 throw cms::Exception(
"Invalid Constituent") <<
"PFJet constituent is not of PFCandidate type";
579 pfCandidatesTemp_.set(std::move(pfCandidatesTemp));
587 if ( index < subjetCollections_.size() )
588 return subjetCollections_[index];
590 throw cms::Exception(
"OutOfRange") <<
"Index " << index <<
" is out of range" << std::endl;
597 auto found =
find( subjetLabels_.begin(), subjetLabels_.end(),
label );
598 if (
found != subjetLabels_.end() ){
600 return subjetCollections_[
index];
603 throw cms::Exception(
"SubjetsNotFound") <<
"Label " << label <<
" does not match any subjet collection" << std::endl;
609 subjetCollections_.push_back( pieces );
610 subjetLabels_.push_back( label );
value_type const * get() const
Jets made from CaloTowers.
const Specific & getSpecific() const
block accessors
Base class for all types of Jets.
std::vector< CaloTower >::const_iterator const_iterator
virtual void setP4(const LorentzVector &p4)
set 4-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 double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
virtual size_t numberOfDaughters() const
number of daughters
virtual double energy() const
energy
virtual size_t numberOfDaughters() const
number of daughters
virtual const Candidate * daughter(size_type) const
return daughter at a given position (throws an exception)
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.
Container::value_type value_type
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
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.
Templated PAT object container.
volatile std::atomic< bool > shutdown_flag false
edm::Ptr< PFCandidate > PFCandidatePtr
persistent Ptr to a PFCandidate
virtual double phi() const
momentum azimuthal angle
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
static std::string const source
virtual const Candidate * daughter(size_type) const
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
const Specific & getSpecific() const