CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | Static Private Attributes
citk::PFIsolationSumProducerForPUPPI Class Reference
Inheritance diagram for citk::PFIsolationSumProducerForPUPPI:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

virtual void beginLuminosityBlock (const edm::LuminosityBlock &, const edm::EventSetup &) overridefinal
 
 PFIsolationSumProducerForPUPPI (const edm::ParameterSet &)
 
virtual void produce (edm::Event &, const edm::EventSetup &) overridefinal
 
virtual ~PFIsolationSumProducerForPUPPI ()
 
- 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)
 
std::vector
< edm::ProductResolverIndex >
const & 
indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector
< ProductResolverIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Types

typedef edm::View
< reco::Candidate
CandView
 
typedef std::vector
< std::unique_ptr
< IsolationConeDefinitionBase > > 
IsoTypes
 
typedef std::unordered_map
< std::string, int > 
TypeMap
 

Private Attributes

edm::EDGetTokenT< CandView_isolate_with
 
std::array< IsoTypes, kNPFTypes_isolation_types
 
std::array< std::vector
< std::string >, kNPFTypes
_product_names
 
edm::EDGetTokenT< CandView_to_isolate
 
const TypeMap _typeMap
 
edm::Handle< edm::ValueMap
< float > > 
puppiValueMap
 
edm::EDGetTokenT
< edm::ValueMap< float > > 
puppiValueMapToken_
 
bool usePUPPINoLepton = false
 
bool useValueMapForPUPPI = true
 

Static Private Attributes

static unsigned kNPFTypes = 8
 

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
 
- 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 26 of file CITKPFIsolationSumProducerForPUPPI.cc.

Member Typedef Documentation

Definition at line 45 of file CITKPFIsolationSumProducerForPUPPI.cc.

typedef std::vector<std::unique_ptr<IsolationConeDefinitionBase> > citk::PFIsolationSumProducerForPUPPI::IsoTypes
private

Definition at line 44 of file CITKPFIsolationSumProducerForPUPPI.cc.

typedef std::unordered_map<std::string,int> citk::PFIsolationSumProducerForPUPPI::TypeMap
private

Definition at line 43 of file CITKPFIsolationSumProducerForPUPPI.cc.

Constructor & Destructor Documentation

citk::PFIsolationSumProducerForPUPPI::PFIsolationSumProducerForPUPPI ( const edm::ParameterSet c)

Definition at line 63 of file CITKPFIsolationSumProducerForPUPPI.cc.

63  :
64  _typeMap( { {"h+",1},
65  {"h0",5},
66  {"gamma",4},
67  {"electron",2},
68  {"muon",3},
69  {"HFh",6},
70  {"HFgamma",7} } ){
virtual citk::PFIsolationSumProducerForPUPPI::~PFIsolationSumProducerForPUPPI ( )
inlinevirtual

Definition at line 31 of file CITKPFIsolationSumProducerForPUPPI.cc.

31 {}

Member Function Documentation

void citk::PFIsolationSumProducerForPUPPI::beginLuminosityBlock ( const edm::LuminosityBlock ,
const edm::EventSetup es 
)
finaloverridevirtual

Reimplemented from edm::stream::EDProducerBase.

Definition at line 111 of file CITKPFIsolationSumProducerForPUPPI.cc.

References _isolation_types.

112  {
113  for( const auto& isolators_for_type : _isolation_types ) {
114  for( const auto& isolator : isolators_for_type ) {
115  isolator->getEventSetupInfo(es);
116  }
117  }
118  }
void citk::PFIsolationSumProducerForPUPPI::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 189 of file CITKPFIsolationSumProducerForPUPPI.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addOptional(), edm::ParameterSetDescription::addVPSet(), HLT_FULL_cff::InputTag, interactiveExample::photons, edm::ParameterSetDescription::setComment(), and AlCaHLTBitMon_QueryRunRegistry::string.

190 {
192  iDesc.setComment("PUPPI isolation sum producer");
193 
194  iDesc.add<edm::InputTag>("srcToIsolate", edm::InputTag("no default"))->setComment("calculate isolation for this collection");
195  iDesc.add<edm::InputTag>("srcForIsolationCone", edm::InputTag("no default"))->setComment("collection for the isolation calculation: like particleFlow ");
196  iDesc.add<edm::InputTag>("puppiValueMap", edm::InputTag("puppi"))->setComment("source for puppi, if left empty weight from packedCandidate is taken");
197 
198  edm::ParameterSetDescription descIsoConeDefinitions;
199  descIsoConeDefinitions.add<std::string>("isolationAlgo", "no default");
200  descIsoConeDefinitions.add<double>("coneSize", 0.3);
201  descIsoConeDefinitions.add<std::string>("isolateAgainst", "no default");
202  descIsoConeDefinitions.add<std::vector<unsigned>>("miniAODVertexCodes", {2,3});
203  descIsoConeDefinitions.addOptional<double>("VetoConeSizeBarrel", 0.0);
204  descIsoConeDefinitions.addOptional<double>("VetoConeSizeEndcaps", 0.0);
205  descIsoConeDefinitions.addOptional<int>("vertexIndex",0);
206  descIsoConeDefinitions.addOptional<edm::InputTag>("particleBasedIsolation",edm::InputTag("no default"))->setComment("map for footprint removal that is used for photons");
207 
208 
209  std::vector<edm::ParameterSet> isolationConeDefinitions;
210  edm::ParameterSet chargedHadrons, neutralHadrons,photons;
211  isolationConeDefinitions.push_back(chargedHadrons);
212  isolationConeDefinitions.push_back(neutralHadrons);
213  isolationConeDefinitions.push_back(photons);
214  iDesc.addVPSet("isolationConeDefinitions", descIsoConeDefinitions, isolationConeDefinitions);
215  iDesc.addOptional<bool>("usePUPPINoLepton",false);
216 
217  descriptions.add("CITKPFIsolationSumProducerForPUPPI", iDesc);
218 }
void setComment(std::string const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void citk::PFIsolationSumProducerForPUPPI::produce ( edm::Event ev,
const edm::EventSetup es 
)
finaloverridevirtual

Implements edm::stream::EDProducerBase.

Definition at line 121 of file CITKPFIsolationSumProducerForPUPPI.cc.

References _isolate_with, _isolation_types, _product_names, _to_isolate, begin, EnergyCorrector::c, end, edm::helper::Filler< Map >::fill(), edm::Event::getByToken(), i, edm::helper::Filler< Map >::insert(), j, relval_2017::k, kNPFTypes, eostools::move(), puppiValueMap, puppiValueMapToken_, edm::Event::put(), reco::PFCandidate::translatePdgIdToType(), usePUPPINoLepton, useValueMapForPUPPI, and relativeConstraints::value.

121  {
122  typedef std::unique_ptr<edm::ValueMap<float> > product_type;
123  typedef std::vector<float> product_values;
124  edm::Handle<CandView> to_isolate;
125  edm::Handle<CandView> isolate_with;
126  ev.getByToken(_to_isolate,to_isolate);
127  ev.getByToken(_isolate_with,isolate_with);
129 
130  // the list of value vectors indexed as "to_isolate"
131  std::array<std::vector<product_values>,kNPFTypes> the_values;
132  // get extra event info and setup value cache
133  unsigned i = 0;
134  for( const auto& isolators_for_type : _isolation_types ) {
135  the_values[i++].resize(isolators_for_type.size());
136  for( const auto& isolator : isolators_for_type ) {
137  isolator->getEventInfo(ev);
138  }
139  }
140  reco::PFCandidate helper; // to translate pdg id to type
141  // loop over the candidates we are isolating and fill the values
142  for( size_t c = 0; c < to_isolate->size(); ++c ) {
143  auto cand_to_isolate = to_isolate->ptrAt(c);
144  std::array<std::vector<float>,kNPFTypes> cand_values;
145  unsigned k = 0;
146  for( const auto& isolators_for_type : _isolation_types ) {
147  cand_values[k].resize(isolators_for_type.size());
148  for( auto& value : cand_values[k] ) value = 0.0;
149  ++k;
150  }
151  for( size_t ic = 0; ic < isolate_with->size(); ++ic ) {
152  auto isocand = isolate_with->ptrAt(ic);
153  edm::Ptr<pat::PackedCandidate> aspackedCandidate(isocand);
154  auto isotype = helper.translatePdgIdToType(isocand->pdgId());
155  const auto& isolations = _isolation_types[isotype];
156  for( unsigned i = 0; i < isolations.size(); ++ i ) {
157  if( isolations[i]->isInIsolationCone(cand_to_isolate,isocand) ) {
158  double puppiWeight = 0.;
159  if (!useValueMapForPUPPI && !usePUPPINoLepton) puppiWeight = aspackedCandidate -> puppiWeight(); // if miniAOD, take puppiWeight directly from the object
160  else if (!useValueMapForPUPPI && usePUPPINoLepton) puppiWeight = aspackedCandidate -> puppiWeightNoLep(); // if miniAOD, take puppiWeightNoLep directly from the object
161  else puppiWeight = (*puppiValueMap)[isocand]; // if AOD, take puppiWeight from the valueMap
162  if (puppiWeight > 0.)cand_values[isotype][i] += (isocand->pt())*puppiWeight; // this is basically the main change to Lindsey's code: scale pt with puppiWeight for candidates with puppiWeight > 0.
163  }
164  }
165  }
166  // add this candidate to isolation value list
167  for( unsigned i = 0; i < kNPFTypes; ++i ) {
168  for( unsigned j = 0; j < cand_values[i].size(); ++j ) {
169  the_values[i][j].push_back(cand_values[i][j]);
170  }
171  }
172  }
173  // fill and put all products
174  for( unsigned i = 0; i < kNPFTypes; ++ i ) {
175  for( unsigned j = 0; j < the_values[i].size(); ++j ) {
176  product_type the_product( new edm::ValueMap<float> );
177  edm::ValueMap<float>::Filler fillerprod(*the_product);
178  fillerprod.insert(to_isolate,
179  the_values[i][j].begin(),
180  the_values[i][j].end());
181  fillerprod.fill();
182  ev.put(std::move(the_product),_product_names[i][j]);
183  }
184  }
185  }
int i
Definition: DBlmapReader.cc:9
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
edm::Handle< edm::ValueMap< float > > puppiValueMap
std::array< std::vector< std::string >, kNPFTypes > _product_names
edm::EDGetTokenT< edm::ValueMap< float > > puppiValueMapToken_
def move
Definition: eostools.py:510
int j
Definition: DBlmapReader.cc:9
#define end
Definition: vmac.h:37
ParticleType translatePdgIdToType(int pdgid) const
Definition: PFCandidate.cc:229
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
#define begin
Definition: vmac.h:30

Member Data Documentation

edm::EDGetTokenT<CandView> citk::PFIsolationSumProducerForPUPPI::_isolate_with
private

Definition at line 47 of file CITKPFIsolationSumProducerForPUPPI.cc.

Referenced by produce().

std::array<IsoTypes,kNPFTypes> citk::PFIsolationSumProducerForPUPPI::_isolation_types
private

Definition at line 51 of file CITKPFIsolationSumProducerForPUPPI.cc.

Referenced by beginLuminosityBlock(), and produce().

std::array<std::vector<std::string>,kNPFTypes> citk::PFIsolationSumProducerForPUPPI::_product_names
private

Definition at line 52 of file CITKPFIsolationSumProducerForPUPPI.cc.

Referenced by produce().

edm::EDGetTokenT<CandView> citk::PFIsolationSumProducerForPUPPI::_to_isolate
private

Definition at line 47 of file CITKPFIsolationSumProducerForPUPPI.cc.

Referenced by produce().

const TypeMap citk::PFIsolationSumProducerForPUPPI::_typeMap
private

Definition at line 46 of file CITKPFIsolationSumProducerForPUPPI.cc.

unsigned citk::PFIsolationSumProducerForPUPPI::kNPFTypes = 8
staticprivate

Definition at line 42 of file CITKPFIsolationSumProducerForPUPPI.cc.

Referenced by produce().

edm::Handle<edm::ValueMap<float> > citk::PFIsolationSumProducerForPUPPI::puppiValueMap
private

Definition at line 49 of file CITKPFIsolationSumProducerForPUPPI.cc.

Referenced by produce().

edm::EDGetTokenT<edm::ValueMap<float> > citk::PFIsolationSumProducerForPUPPI::puppiValueMapToken_
private

Definition at line 48 of file CITKPFIsolationSumProducerForPUPPI.cc.

Referenced by produce().

bool citk::PFIsolationSumProducerForPUPPI::usePUPPINoLepton = false
private

Definition at line 54 of file CITKPFIsolationSumProducerForPUPPI.cc.

Referenced by produce().

bool citk::PFIsolationSumProducerForPUPPI::useValueMapForPUPPI = true
private

Definition at line 53 of file CITKPFIsolationSumProducerForPUPPI.cc.

Referenced by produce().