CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
JetSubstructurePacker Class Reference

#include <JetSubstructurePacker.h>

Inheritance diagram for JetSubstructurePacker:
edm::stream::EDProducer<>

Public Member Functions

 JetSubstructurePacker (const edm::ParameterSet &)
 
 ~JetSubstructurePacker () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Private Member Functions

void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::vector< std::string > algoLabels_
 
std::vector< edm::InputTagalgoTags_
 
std::vector< edm::EDGetTokenT< edm::View< pat::Jet > > > algoTokens_
 
float distMax_
 
bool fixDaughters_
 
edm::EDGetTokenT< edm::View< pat::Jet > > jetToken_
 
edm::EDGetTokenT< edm::Association< reco::PFCandidateCollection > > pc2pf_
 
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 36 of file JetSubstructurePacker.h.

Constructor & Destructor Documentation

JetSubstructurePacker::JetSubstructurePacker ( const edm::ParameterSet iConfig)
explicit

Definition at line 5 of file JetSubstructurePacker.cc.

References algoTags_, algoTokens_, fixDaughters_, edm::ParameterSet::getParameter(), pc2pf_, pf2pc_, GlobalPosition_Frontier_DevDB_cff::tag, and edm::vector_transform().

5  :
6  distMax_( iConfig.getParameter<double>("distMax") ),
7  jetToken_(consumes<edm::View<pat::Jet> >( iConfig.getParameter<edm::InputTag>("jetSrc") )),
8  algoLabels_( iConfig.getParameter< std::vector<std::string> > ("algoLabels") ),
9  algoTags_ (iConfig.getParameter<std::vector<edm::InputTag> > ( "algoTags" )),
10  fixDaughters_(iConfig.getParameter<bool>("fixDaughters"))
11 {
12  algoTokens_ =edm::vector_transform(algoTags_, [this](edm::InputTag const & tag){return consumes< edm::View<pat::Jet> >(tag);});
13  if (fixDaughters_) {
14  pf2pc_ = consumes<edm::Association<pat::PackedCandidateCollection> >(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
15  pc2pf_ = consumes<edm::Association<reco::PFCandidateCollection > >(iConfig.getParameter<edm::InputTag>("packedPFCandidates"));
16  }
17  //register products
18  produces<std::vector<pat::Jet> > ();
19 }
T getParameter(std::string const &) const
std::vector< edm::EDGetTokenT< edm::View< pat::Jet > > > algoTokens_
edm::EDGetTokenT< edm::Association< reco::PFCandidateCollection > > pc2pf_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
edm::EDGetTokenT< edm::View< pat::Jet > > jetToken_
std::vector< edm::InputTag > algoTags_
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
std::vector< std::string > algoLabels_
JetSubstructurePacker::~JetSubstructurePacker ( )
override

Definition at line 22 of file JetSubstructurePacker.cc.

23 {
24 }

Member Function Documentation

void JetSubstructurePacker::produce ( edm::Event iEvent,
const edm::EventSetup  
)
overrideprivate

Definition at line 29 of file JetSubstructurePacker.cc.

References algoLabels_, algoTags_, algoTokens_, DEFINE_FWK_MODULE, reco::deltaR(), distMax_, allElectronIsolations_cfi::dRMin, spr::find(), fixDaughters_, edm::Event::getByToken(), mps_fire::i, jetToken_, eostools::move(), PatBasicFWLiteJetAnalyzer_Selector_cfg::outputs, pc2pf_, pf2pc_, edm::Event::put(), and edm::refToPtr().

30 {
31 
32  auto outputs = std::make_unique<std::vector<pat::Jet>>();
33 
35  std::vector< edm::Handle< edm::View<pat::Jet> > > algoHandles;
36 
39  if (fixDaughters_) {
40  iEvent.getByToken(pf2pc_,pf2pc);
41  iEvent.getByToken(pc2pf_,pc2pf);
42  }
43 
44  iEvent.getByToken( jetToken_, jetHandle );
45  algoHandles.resize( algoTags_.size() );
46  for ( size_t i = 0; i < algoTags_.size(); ++i ) {
47  iEvent.getByToken( algoTokens_[i], algoHandles[i] );
48  }
49 
50  // Loop over the input jets that will be modified.
51  for ( auto const & ijet : *jetHandle ) {
52  // Copy the jet.
53  outputs->push_back( ijet );
54  // Loop over the substructure collections
55  unsigned int index = 0;
56 
57  for ( auto const & ialgoHandle : algoHandles ) {
58  std::vector< edm::Ptr<pat::Jet> > nextSubjets;
59  float dRMin = distMax_;
60  for ( auto const & jjet : *ialgoHandle ) {
61  if ( reco::deltaR( ijet, jjet ) < dRMin ) {
62  for ( auto const & userfloatstr : jjet.userFloatNames() ) {
63  outputs->back().addUserFloat( userfloatstr, jjet.userFloat(userfloatstr) );
64  }
65  for ( auto const & userintstr : jjet.userIntNames() ) {
66  outputs->back().addUserInt( userintstr, jjet.userInt(userintstr) );
67  }
68  for ( auto const & usercandstr : jjet.userCandNames() ) {
69  outputs->back().addUserCand( usercandstr, jjet.userCand(usercandstr) );
70  }
71  for ( size_t ida = 0; ida < jjet.numberOfDaughters(); ++ida ) {
72  reco::CandidatePtr candPtr = jjet.daughterPtr( ida);
73  nextSubjets.push_back( edm::Ptr<pat::Jet> ( candPtr ) );
74  }
75  break;
76  }
77  }
78  outputs->back().addSubjets( nextSubjets, algoLabels_[index] );
79  ++index;
80  }
81 
82  // fix daughters
83  if (fixDaughters_) {
84 
85  std::vector<reco::CandidatePtr> daughtersInSubjets;
86  std::vector<reco::CandidatePtr> daughtersNew;
87  const std::vector<reco::CandidatePtr> & jdausPF = outputs->back().daughterPtrVector();
88  std::vector<reco::CandidatePtr> jdaus;
89  jdaus.reserve( jdausPF.size() );
90  // Convert the daughters to packed candidates. This is easier than ref-navigating through PUPPI or CHS to particleFlow.
91  for ( auto const & jdau : jdausPF ) {
92  jdaus.push_back( edm::refToPtr((*pf2pc)[jdau]) );
93  }
94 
95  for ( const edm::Ptr<pat::Jet> & subjet : outputs->back().subjets()) {
96  const std::vector<reco::CandidatePtr> & sjdaus = subjet->daughterPtrVector();
97  // check that the subjet does not contain any extra constituents not contained in the jet
98  bool skipSubjet = false;
99  for (const reco::CandidatePtr & dau : sjdaus) {
100  if (std::find(jdaus.begin(), jdaus.end(), dau) == jdaus.end()) {
101  skipSubjet = true;
102  break;
103  }
104  }
105  if (skipSubjet) continue;
106 
107  daughtersInSubjets.insert(daughtersInSubjets.end(), sjdaus.begin(), sjdaus.end());
108  daughtersNew.push_back( reco::CandidatePtr(subjet) );
109  }
110  for (const reco::CandidatePtr & dau : jdaus) {
111  if (std::find(daughtersInSubjets.begin(), daughtersInSubjets.end(), dau) == daughtersInSubjets.end()) {
112  daughtersNew.push_back( dau );
113  }
114  }
115  outputs->back().clearDaughters();
116  for (const auto & dau : daughtersNew) outputs->back().addDaughter(dau);
117  }
118  }
119 
120  iEvent.put(std::move(outputs));
121 
122 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
std::vector< edm::EDGetTokenT< edm::View< pat::Jet > > > algoTokens_
edm::EDGetTokenT< edm::Association< reco::PFCandidateCollection > > pc2pf_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
edm::EDGetTokenT< edm::View< pat::Jet > > jetToken_
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
std::vector< edm::InputTag > algoTags_
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
std::vector< std::string > algoLabels_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

std::vector<std::string> JetSubstructurePacker::algoLabels_
private

Definition at line 50 of file JetSubstructurePacker.h.

Referenced by produce().

std::vector<edm::InputTag> JetSubstructurePacker::algoTags_
private

Definition at line 51 of file JetSubstructurePacker.h.

Referenced by JetSubstructurePacker(), and produce().

std::vector< edm::EDGetTokenT< edm::View<pat::Jet> > > JetSubstructurePacker::algoTokens_
private

Definition at line 52 of file JetSubstructurePacker.h.

Referenced by JetSubstructurePacker(), and produce().

float JetSubstructurePacker::distMax_
private

Definition at line 48 of file JetSubstructurePacker.h.

Referenced by produce().

bool JetSubstructurePacker::fixDaughters_
private

Definition at line 53 of file JetSubstructurePacker.h.

Referenced by JetSubstructurePacker(), and produce().

edm::EDGetTokenT<edm::View<pat::Jet> > JetSubstructurePacker::jetToken_
private

Definition at line 49 of file JetSubstructurePacker.h.

Referenced by produce().

edm::EDGetTokenT<edm::Association<reco::PFCandidateCollection > > JetSubstructurePacker::pc2pf_
private

Definition at line 55 of file JetSubstructurePacker.h.

Referenced by JetSubstructurePacker(), and produce().

edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection> > JetSubstructurePacker::pf2pc_
private

Definition at line 54 of file JetSubstructurePacker.h.

Referenced by JetSubstructurePacker(), and produce().