CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | Static Private Attributes
citk::PFIsolationSumProducer Class Reference
Inheritance diagram for citk::PFIsolationSumProducer:
edm::stream::EDProducer<>

Public Member Functions

void beginLuminosityBlock (const edm::LuminosityBlock &, const edm::EventSetup &) final
 
 PFIsolationSumProducer (const edm::ParameterSet &)
 
void produce (edm::Event &, const edm::EventSetup &) final
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Types

typedef edm::View< reco::CandidateCandView
 
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
 

Static Private Attributes

static constexpr unsigned kNPFTypes = 8
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 36 of file CITKPFIsolationSumProducer.cc.

Member Typedef Documentation

◆ CandView

Definition at line 51 of file CITKPFIsolationSumProducer.cc.

◆ IsoTypes

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

Definition at line 50 of file CITKPFIsolationSumProducer.cc.

◆ TypeMap

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

Definition at line 49 of file CITKPFIsolationSumProducer.cc.

Constructor & Destructor Documentation

◆ PFIsolationSumProducer()

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

Definition at line 65 of file CITKPFIsolationSumProducer.cc.

66  : _typeMap({{"h+", 1}, {"h0", 5}, {"gamma", 4}, {"electron", 2}, {"muon", 3}, {"HFh", 6}, {"HFgamma", 7}}) {
67  _to_isolate = consumes<CandView>(c.getParameter<edm::InputTag>("srcToIsolate"));
68  _isolate_with = consumes<CandView>(c.getParameter<edm::InputTag>("srcForIsolationCone"));
69  const std::vector<edm::ParameterSet>& isoDefs = c.getParameterSetVector("isolationConeDefinitions");
70  for (const auto& isodef : isoDefs) {
71  const std::string& name = isodef.getParameter<std::string>("isolationAlgo");
72  const float coneSize = isodef.getParameter<double>("coneSize");
73  char buf[50];
74  sprintf(buf, "DR%.2f", coneSize);
75  std::string coneName(buf);
76  auto decimal = coneName.find('.');
77  if (decimal != std::string::npos)
78  coneName.erase(decimal, 1);
79  const std::string& isotype = isodef.getParameter<std::string>("isolateAgainst");
80  auto theisolator = CITKIsolationConeDefinitionFactory::get()->create(name, isodef);
81  theisolator->setConsumes(consumesCollector());
82  const auto thetype = _typeMap.find(isotype);
83  if (thetype == _typeMap.end()) {
84  throw cms::Exception("InvalidIsolationType") << "Isolation type: " << isotype << " is not available in the "
85  << "list of allowed isolations!.";
86  }
87  const std::string dash("-");
88  std::string pname = isotype + dash + coneName + dash + theisolator->additionalCode();
89  _product_names[thetype->second].emplace_back(pname);
90  produces<edm::ValueMap<float>>(pname);
91  _isolation_types[thetype->second].emplace_back(std::move(theisolator));
92  }
93  }
std::array< IsoTypes, kNPFTypes > _isolation_types
edm::EDGetTokenT< CandView > _to_isolate
std::array< std::vector< std::string >, kNPFTypes > _product_names
#define get
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< CandView > _isolate_with

Member Function Documentation

◆ beginLuminosityBlock()

void citk::PFIsolationSumProducer::beginLuminosityBlock ( const edm::LuminosityBlock ,
const edm::EventSetup es 
)
final

Definition at line 95 of file CITKPFIsolationSumProducer.cc.

References _isolation_types.

95  {
96  for (const auto& isolators_for_type : _isolation_types) {
97  for (const auto& isolator : isolators_for_type) {
98  isolator->getEventSetupInfo(es);
99  }
100  }
101  }
std::array< IsoTypes, kNPFTypes > _isolation_types

◆ fillDescriptions()

void citk::PFIsolationSumProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 162 of file CITKPFIsolationSumProducer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addOptional(), edm::ParameterSetDescription::addVPSet(), ProducerED_cfi::InputTag, egmElectronIsolationPUPPI_cff::isolationConeDefinitions, BPHMonitor_cfi::photons, edm::ParameterSetDescription::setComment(), and AlCaHLTBitMon_QueryRunRegistry::string.

162  {
164  iDesc.setComment("isolation sum producer");
165 
166  iDesc.add<edm::InputTag>("srcToIsolate", edm::InputTag("no default"))
167  ->setComment("calculate isolation for this collection");
168  iDesc.add<edm::InputTag>("srcForIsolationCone", edm::InputTag("no default"))
169  ->setComment("collection for the isolation calculation: like particleFlow ");
170 
171  edm::ParameterSetDescription descIsoConeDefinitions;
172  descIsoConeDefinitions.add<std::string>("isolationAlgo", "no default");
173  descIsoConeDefinitions.add<double>("coneSize", 0.3);
174  descIsoConeDefinitions.add<std::string>("isolateAgainst", "no default");
175  descIsoConeDefinitions.add<std::vector<unsigned>>("miniAODVertexCodes", {2, 3});
176  descIsoConeDefinitions.addOptional<double>("VetoConeSizeBarrel", 0.0);
177  descIsoConeDefinitions.addOptional<double>("VetoConeSizeEndcaps", 0.0);
178  descIsoConeDefinitions.addOptional<int>("vertexIndex", 0);
179  descIsoConeDefinitions.addOptional<edm::InputTag>("particleBasedIsolation", edm::InputTag("no default"))
180  ->setComment("map for footprint removal that is used for photons");
181 
182  std::vector<edm::ParameterSet> isolationConeDefinitions;
183  edm::ParameterSet chargedHadrons, neutralHadrons, photons;
184  isolationConeDefinitions.push_back(chargedHadrons);
185  isolationConeDefinitions.push_back(neutralHadrons);
187  iDesc.addVPSet("isolationConeDefinitions", descIsoConeDefinitions, isolationConeDefinitions);
188 
189  descriptions.add("CITKPFIsolationSumProducer", iDesc);
190  }
void setComment(std::string const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ produce()

void citk::PFIsolationSumProducer::produce ( edm::Event ev,
const edm::EventSetup es 
)
final

Definition at line 103 of file CITKPFIsolationSumProducer.cc.

References _isolate_with, _isolation_types, _product_names, _to_isolate, HltBtagPostValidation_cff::c, makeMEIFBenchmarkPlots::ev, edm::helper::Filler< Map >::fill(), mps_fire::i, edm::helper::Filler< Map >::insert(), dqmiolumiharvest::j, dqmdumpme::k, kNPFTypes, eostools::move(), edm::View< T >::ptrAt(), and edm::View< T >::size().

103  {
104  typedef std::unique_ptr<edm::ValueMap<float>> product_type;
105  typedef std::vector<float> product_values;
106  edm::Handle<CandView> to_isolate;
107  edm::Handle<CandView> isolate_with;
108  ev.getByToken(_to_isolate, to_isolate);
109  ev.getByToken(_isolate_with, isolate_with);
110  // the list of value vectors indexed as "to_isolate"
111  std::array<std::vector<product_values>, kNPFTypes> the_values;
112  // get extra event info and setup value cache
113  unsigned i = 0;
114  for (const auto& isolators_for_type : _isolation_types) {
115  the_values[i++].resize(isolators_for_type.size());
116  for (const auto& isolator : isolators_for_type) {
117  isolator->getEventInfo(ev);
118  }
119  }
120  reco::PFCandidate helper; // to translate pdg id to type
121  // loop over the candidates we are isolating and fill the values
122  for (size_t c = 0; c < to_isolate->size(); ++c) {
123  auto cand_to_isolate = to_isolate->ptrAt(c);
124  std::array<std::vector<float>, kNPFTypes> cand_values;
125  unsigned k = 0;
126  for (const auto& isolators_for_type : _isolation_types) {
127  cand_values[k].resize(isolators_for_type.size());
128  for (auto& value : cand_values[k])
129  value = 0.0;
130  ++k;
131  }
132  for (size_t ic = 0; ic < isolate_with->size(); ++ic) {
133  auto isocand = isolate_with->ptrAt(ic);
134  auto isotype = helper.translatePdgIdToType(isocand->pdgId());
135  const auto& isolations = _isolation_types[isotype];
136  for (unsigned i = 0; i < isolations.size(); ++i) {
137  if (isolations[i]->isInIsolationCone(cand_to_isolate, isocand)) {
138  cand_values[isotype][i] += isocand->pt();
139  }
140  }
141  }
142  // add this candidate to isolation value list
143  for (unsigned i = 0; i < kNPFTypes; ++i) {
144  for (unsigned j = 0; j < cand_values[i].size(); ++j) {
145  the_values[i][j].push_back(cand_values[i][j]);
146  }
147  }
148  }
149  // fill and put all products
150  for (unsigned i = 0; i < kNPFTypes; ++i) {
151  for (unsigned j = 0; j < the_values[i].size(); ++j) {
152  product_type the_product(new edm::ValueMap<float>);
153  edm::ValueMap<float>::Filler fillerprod(*the_product);
154  fillerprod.insert(to_isolate, the_values[i][j].begin(), the_values[i][j].end());
155  fillerprod.fill();
156  ev.put(std::move(the_product), _product_names[i][j]);
157  }
158  }
159  }
Definition: helper.py:1
Ptr< value_type > ptrAt(size_type i) const
size_type size() const
std::array< IsoTypes, kNPFTypes > _isolation_types
edm::EDGetTokenT< CandView > _to_isolate
std::array< std::vector< std::string >, kNPFTypes > _product_names
Definition: value.py:1
TracksUtilities< TrackerTraits > helper
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< CandView > _isolate_with

Member Data Documentation

◆ _isolate_with

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

Definition at line 53 of file CITKPFIsolationSumProducer.cc.

Referenced by produce().

◆ _isolation_types

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

Definition at line 55 of file CITKPFIsolationSumProducer.cc.

Referenced by beginLuminosityBlock(), and produce().

◆ _product_names

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

Definition at line 56 of file CITKPFIsolationSumProducer.cc.

Referenced by produce().

◆ _to_isolate

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

Definition at line 53 of file CITKPFIsolationSumProducer.cc.

Referenced by produce().

◆ _typeMap

const TypeMap citk::PFIsolationSumProducer::_typeMap
private

Definition at line 52 of file CITKPFIsolationSumProducer.cc.

◆ kNPFTypes

constexpr unsigned citk::PFIsolationSumProducer::kNPFTypes = 8
staticprivate

Definition at line 48 of file CITKPFIsolationSumProducer.cc.

Referenced by produce().