Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify jet constituent access in MiniAOD #22914

Merged
merged 8 commits into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DataFormats/PatCandidates/interface/Jet.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ namespace pat {
// ---- Jet Substructure ----
std::vector< pat::JetPtrCollection> subjetCollections_;
std::vector< std::string> subjetLabels_;
edm::AtomicPtrCache<std::vector< reco::CandidatePtr > > daughtersTemp_;

// ---- MC info ----

Expand Down Expand Up @@ -637,6 +638,7 @@ namespace pat {
/// cache calo towers
void cacheCaloTowers() const;
void cachePFCandidates() const;
void cacheDaughters() const;

};
}
Expand Down
25 changes: 23 additions & 2 deletions DataFormats/PatCandidates/src/Jet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ const reco::Candidate * Jet::daughter(size_t i) const {
else return reco::Jet::daughter(i);
}
}
if ( !subjetCollections_.empty() ) {
if ( !daughtersTemp_.isSet() ) cacheDaughters();
return daughtersTemp_->at(i).get();
}
return reco::Jet::daughter(i);
}

Expand All @@ -221,6 +225,10 @@ size_t Jet::numberOfDaughters() const {
else return reco::Jet::numberOfDaughters();
}
}
if ( !subjetCollections_.empty() ) {
if ( !daughtersTemp_.isSet() ) cacheDaughters();
return daughtersTemp_->size();
}
return reco::Jet::numberOfDaughters();
}

Expand Down Expand Up @@ -584,8 +592,21 @@ void Jet::cachePFCandidates() const {
// Set the cache
pfCandidatesTemp_.set(std::move(pfCandidatesTemp));
}



/// method to cache the daughters to allow "user-friendly" access
void Jet::cacheDaughters() const {
// Jets in MiniAOD produced via JetSubstructurePacker contain a mixture of subjets and particles as daughters
std::unique_ptr<std::vector<reco::CandidatePtr>> daughtersTemp{ new std::vector<reco::CandidatePtr>{}};
const std::vector<reco::CandidatePtr> & jdaus = daughterPtrVector();
for (const reco::CandidatePtr & dau : jdaus) {
if (dau->isJet()) {
const std::vector<reco::CandidatePtr> & sjdaus = edm::Ptr<pat::Jet>(dau)->daughterPtrVector();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer

  const pat::Jet *subjet = dynamic_cast<const pat::Jet *>(&*dau);
  if (subjet) { ... 

or perhaps with reco::Jet instead of pat::Jet?
there's no guarantee that isJet() will return true only a pat::Jet object (and there may be overheads in doing the cast using edm::Ptr, which is unnecessary since you're not writing it to a file)

daughtersTemp->insert(daughtersTemp->end(), sjdaus.begin(), sjdaus.end());
} else
daughtersTemp->push_back( dau );
}
daughtersTemp_.set(std::move(daughtersTemp));
}


/// Access to subjet list
Expand Down
1 change: 1 addition & 0 deletions DataFormats/PatCandidates/src/classes_def_objects.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
</ioread>

<class name="pat::Jet" ClassVersion="16">
<field name="daughtersTemp_" transient="true"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add the following around L250:

  <ioread sourceClass = "pat::Jet" version="[1-]" targetClass="pat::Jet" source="" target="caloTowersTemp_">
    <![CDATA[caloTowersTemp_.reset();]]>
  </ioread>
  <ioread sourceClass = "pat::Jet" version="[1-]" targetClass="pat::Jet" source="" target="pfCandidatesTemp_">
    <![CDATA[pfCandidatesTemp_.reset();]]>
  </ioread>
  <ioread sourceClass = "pat::Jet" version="[1-]" targetClass="pat::Jet" source="" target="daughtersTemp_">
    <![CDATA[daughtersTemp_.reset();]]>
  </ioread>

this appropriately resets the cache pointers when pat::Jets are loaded

<version ClassVersion="16" checksum="4069285947"/>
<version ClassVersion="15" checksum="727883729"/>
<version ClassVersion="14" checksum="1304049301"/>
Expand Down