CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 JetSubstructurePacker (const edm::ParameterSet &)
 
 ~JetSubstructurePacker ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

virtual 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, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

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") ),
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_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< edm::InputTag > algoTags_
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2pc_
std::vector< std::string > algoLabels_
JetSubstructurePacker::~JetSubstructurePacker ( )

Definition at line 22 of file JetSubstructurePacker.cc.

23 {
24 }

Member Function Documentation

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

Implements edm::stream::EDProducerBase.

Definition at line 29 of file JetSubstructurePacker.cc.

References algoLabels_, algoTags_, algoTokens_, reco::deltaR(), distMax_, HLT_25ns10e33_v2_cff::dRMin, spr::find(), fixDaughters_, edm::Event::getByToken(), i, cmsHarvester::index, jetToken_, pc2pf_, pf2pc_, edm::Event::put(), and edm::refToPtr().

30 {
31 
32  std::auto_ptr< std::vector<pat::Jet> > outputs( new 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 
55  // Loop over the substructure collections
56  unsigned int index = 0;
57  for ( auto const & ialgoHandle : algoHandles ) {
58  std::vector< edm::Ptr<pat::Jet> > nextSubjets;
59  float dRMin = distMax_;
60 
61  for ( auto const & jjet : *ialgoHandle ) {
62 
63  if ( reco::deltaR( ijet, jjet ) < dRMin ) {
64  for ( size_t ida = 0; ida < jjet.numberOfDaughters(); ++ida ) {
65 
66  reco::CandidatePtr candPtr = jjet.daughterPtr( ida);
67  nextSubjets.push_back( edm::Ptr<pat::Jet> ( candPtr ) );
68  }
69  break;
70  }
71 
72  }
73 
74  outputs->back().addSubjets( nextSubjets, algoLabels_[index] );
75  ++index;
76  }
77 
78  // fix daughters
79  if (fixDaughters_) {
80  std::vector<reco::CandidatePtr> daughtersInSubjets;
81  std::vector<reco::CandidatePtr> daughtersNew;
82  const std::vector<reco::CandidatePtr> & jdaus = outputs->back().daughterPtrVector();
83  //std::cout << "Jet with pt " << outputs->back().pt() << ", " << outputs->back().numberOfDaughters() << " daughters, " << outputs->back().subjets().size() << ", subjets" << std::endl;
84  for ( const edm::Ptr<pat::Jet> & subjet : outputs->back().subjets()) {
85  const std::vector<reco::CandidatePtr> & sjdaus = subjet->daughterPtrVector();
86 
87  // check that the subjet does not contain any extra constituents not contained in the jet
88  bool skipSubjet = false;
89  for (const reco::CandidatePtr & dau : sjdaus) {
90  reco::CandidatePtr rekeyed = edm::refToPtr((*pc2pf)[dau]);
91  if (std::find(jdaus.begin(), jdaus.end(), rekeyed) == jdaus.end()) {
92  skipSubjet = true;
93  break;
94  }
95  }
96  if (skipSubjet) continue;
97 
98  daughtersInSubjets.insert(daughtersInSubjets.end(), sjdaus.begin(), sjdaus.end());
99  daughtersNew.push_back( reco::CandidatePtr(subjet) );
100  //std::cout << " found " << subjet->numberOfDaughters() << " daughters in a subjet" << std::endl;
101  }
102  //if (!daughtersInSubjets.empty()) std::cout << " subjet daughters are from collection " << daughtersInSubjets.front().id() << std::endl;
103  //std::cout << " in total, " << daughtersInSubjets.size() << " daughters from subjets" << std::endl;
104  for (const reco::CandidatePtr & dau : jdaus) {
105  //if (!pf2pc->contains(dau.id())) {
106  // std::cout << " daughter from collection " << dau.id() << " not in the value map!" << std::endl;
107  // std::cout << " map expects collection " << pf2pc->ids().front().first << std::endl;
108  // continue;
109  //}
110  reco::CandidatePtr rekeyed = edm::refToPtr((*pf2pc)[dau]);
111  if (std::find(daughtersInSubjets.begin(), daughtersInSubjets.end(), rekeyed) == daughtersInSubjets.end()) {
112  daughtersNew.push_back( rekeyed );
113  }
114  }
115  //std::cout << " in total, " << daughtersNew.size() << " daughters including subjets" << std::endl;
116  //if (daughtersNew.size() + daughtersInSubjets.size() - outputs->back().subjets().size() == outputs->back().numberOfDaughters()) {
117  // std::cout << " it all adds up to the original number of daughters" << std::endl;
118  //}
119  outputs->back().clearDaughters();
120  for (const auto & dau : daughtersNew) outputs->back().addDaughter(dau);
121  }
122  }
123 
124  iEvent.put(outputs);
125 
126 }
int i
Definition: DBlmapReader.cc:9
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:462
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:7
edm::EDGetTokenT< edm::View< pat::Jet > > jetToken_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
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_

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().