22 #include <unordered_map> 39 typedef std::unordered_map<std::string, int>
TypeMap;
40 typedef std::vector<std::unique_ptr<IsolationConeDefinitionBase>>
IsoTypes;
61 : _typeMap({{
"h+", 1}, {
"h0", 5}, {
"gamma", 4}, {
"electron", 2}, {
"muon", 3}, {
"HFh", 6}, {
"HFgamma", 7}}) {
62 _to_isolate = consumes<CandView>(
c.getParameter<
edm::InputTag>(
"srcToIsolate"));
63 _isolate_with = consumes<CandView>(
c.getParameter<
edm::InputTag>(
"srcForIsolationCone"));
65 puppiValueMapToken_ = mayConsume<edm::ValueMap<float>>(
67 useValueMapForPUPPI =
true;
69 useValueMapForPUPPI =
false;
72 const std::vector<edm::ParameterSet>& isoDefs =
c.getParameterSetVector(
"isolationConeDefinitions");
73 for (
const auto& isodef : isoDefs) {
75 const float coneSize = isodef.getParameter<
double>(
"coneSize");
79 auto decimal = coneName.find(
'.');
80 if (decimal != std::string::npos)
81 coneName.erase(decimal, 1);
84 theisolator->setConsumes(consumesCollector());
85 const auto thetype = _typeMap.find(isotype);
86 if (thetype == _typeMap.end()) {
87 throw cms::Exception(
"InvalidIsolationType") <<
"Isolation type: " << isotype <<
" is not available in the " 88 <<
"list of allowed isolations!.";
91 std::string pname = isotype + dash + coneName + dash + theisolator->additionalCode();
92 _product_names[thetype->second].emplace_back(
pname);
93 produces<edm::ValueMap<float>>(
pname);
94 _isolation_types[thetype->second].emplace_back(
std::move(theisolator));
100 for (
const auto& isolator : isolators_for_type) {
101 isolator->getEventSetupInfo(es);
107 typedef std::unique_ptr<edm::ValueMap<float>> product_type;
108 typedef std::vector<float> product_values;
117 std::array<std::vector<product_values>,
kNPFTypes> the_values;
121 the_values[
i++].resize(isolators_for_type.size());
122 for (
const auto& isolator : isolators_for_type) {
123 isolator->getEventInfo(
ev);
128 for (
size_t c = 0;
c < to_isolate->
size(); ++
c) {
129 auto cand_to_isolate = to_isolate->
ptrAt(
c);
130 std::array<std::vector<float>,
kNPFTypes> cand_values;
133 cand_values[
k].resize(isolators_for_type.size());
134 for (
auto&
value : cand_values[
k])
138 for (
size_t ic = 0; ic < isolate_with->
size(); ++ic) {
139 auto isocand = isolate_with->
ptrAt(ic);
141 auto isotype =
helper.translatePdgIdToType(isocand->pdgId());
143 for (
unsigned i = 0;
i < isolations.size(); ++
i) {
144 if (isolations[
i]->isInIsolationCone(cand_to_isolate, isocand)) {
145 double puppiWeight = 0.;
154 puppiWeight = (*puppiValueMap)[isocand];
155 if (puppiWeight > 0.)
156 cand_values[isotype][
i] +=
164 for (
unsigned j = 0;
j < cand_values[
i].size(); ++
j) {
165 the_values[
i][
j].push_back(cand_values[
i][
j]);
171 for (
unsigned j = 0;
j < the_values[
i].size(); ++
j) {
174 fillerprod.
insert(to_isolate, the_values[
i][
j].begin(), the_values[
i][
j].end());
184 iDesc.
setComment(
"PUPPI isolation sum producer");
187 ->setComment(
"calculate isolation for this collection");
189 ->setComment(
"collection for the isolation calculation: like particleFlow ");
191 ->setComment(
"source for puppi, if left empty weight from packedCandidate is taken");
194 descIsoConeDefinitions.
add<
std::string>(
"isolationAlgo",
"no default");
195 descIsoConeDefinitions.
add<
double>(
"coneSize", 0.3);
196 descIsoConeDefinitions.
add<
std::string>(
"isolateAgainst",
"no default");
197 descIsoConeDefinitions.
add<std::vector<unsigned>>(
"miniAODVertexCodes", {2, 3});
198 descIsoConeDefinitions.
addOptional<
double>(
"VetoConeSizeBarrel", 0.0);
199 descIsoConeDefinitions.
addOptional<
double>(
"VetoConeSizeEndcaps", 0.0);
200 descIsoConeDefinitions.
addOptional<
double>(
"VetoThreshold", 0.0);
201 descIsoConeDefinitions.
addOptional<
double>(
"VetoConeSize", 0.0);
202 descIsoConeDefinitions.
addOptional<
int>(
"vertexIndex", 0);
204 ->setComment(
"map for footprint removal that is used for photons");
212 iDesc.
add<
bool>(
"usePUPPINoLepton",
false);
214 descriptions.
add(
"CITKPFIsolationSumProducerForPUPPI", iDesc);
float puppiWeight() const
std::unordered_map< std::string, int > TypeMap
citk::PFIsolationSumProducerForPUPPI CITKPFIsolationSumProducerForPUPPI
float puppiWeightNoLep() const
Weight from full PUPPI.
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
Ptr< value_type > ptrAt(size_type i) const
void produce(edm::Event &, const edm::EventSetup &) final
edm::Handle< edm::ValueMap< float > > puppiValueMap
void insert(const H &h, I begin, I end)
std::array< std::vector< std::string >, kNPFTypes > _product_names
edm::EDGetTokenT< edm::ValueMap< float > > puppiValueMapToken_
void setComment(std::string const &value)
bool isNull() const
Checks for null.
edm::View< reco::Candidate > CandView
std::array< IsoTypes, kNPFTypes > _isolation_types
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
#define DEFINE_FWK_MODULE(type)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
PFIsolationSumProducerForPUPPI(const edm::ParameterSet &)
edm::EDGetTokenT< CandView > _to_isolate
TracksUtilities< TrackerTraits > helper
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Particle reconstructed by the particle flow algorithm.
std::vector< std::unique_ptr< IsolationConeDefinitionBase > > IsoTypes
static constexpr unsigned kNPFTypes
edm::EDGetTokenT< CandView > _isolate_with