22 #include <unordered_map>
43 typedef std::unordered_map<std::
string,
int>
TypeMap;
74 consumes<CandView>(
c.getParameter<
edm::InputTag>(
"srcForIsolationCone"));
76 puppiValueMapToken_ = mayConsume<edm::ValueMap<float>>(
c.getParameter<
edm::InputTag>(
"puppiValueMap"));
80 const std::vector<edm::ParameterSet>&
isoDefs =
81 c.getParameterSetVector(
"isolationConeDefinitions");
82 for(
const auto& isodef : isoDefs ) {
85 const float coneSize = isodef.getParameter<
double>(
"coneSize");
87 std::sprintf(buf,
"DR%.2f",coneSize);
89 auto decimal = coneName.find(
'.');
90 if( decimal != std::string::npos ) coneName.erase(decimal,1);
95 theisolator->setConsumes(consumesCollector());
96 const auto thetype = _typeMap.find(isotype);
97 if( thetype == _typeMap.end() ) {
99 <<
"Isolation type: " << isotype <<
" is not available in the "
100 <<
"list of allowed isolations!.";
102 _isolation_types[thetype->second].emplace_back(theisolator);
104 std::string pname = isotype+dash+coneName+dash+theisolator->additionalCode();
105 _product_names[thetype->second].emplace_back(pname);
106 produces<edm::ValueMap<float> >(
pname);
114 for(
const auto& isolator : isolators_for_type ) {
115 isolator->getEventSetupInfo(es);
122 typedef std::unique_ptr<edm::ValueMap<float> > product_type;
123 typedef std::vector<float> product_values;
131 std::array<std::vector<product_values>,
kNPFTypes> the_values;
135 the_values[i++].resize(isolators_for_type.size());
136 for(
const auto& isolator : isolators_for_type ) {
137 isolator->getEventInfo(ev);
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;
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;
151 for(
size_t ic = 0; ic < isolate_with->size(); ++ic ) {
152 auto isocand = isolate_with->ptrAt(ic);
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.;
161 else puppiWeight = (*puppiValueMap)[isocand];
162 if (puppiWeight > 0.)cand_values[isotype][
i] += (isocand->pt())*puppiWeight;
168 for(
unsigned j = 0;
j < cand_values[
i].size(); ++
j ) {
169 the_values[
i][
j].push_back(cand_values[i][
j]);
175 for(
unsigned j = 0;
j < the_values[
i].size(); ++
j ) {
178 fillerprod.
insert(to_isolate,
180 the_values[i][
j].
end());
192 iDesc.
setComment(
"PUPPI isolation sum producer");
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");
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);
209 std::vector<edm::ParameterSet> isolationConeDefinitions;
211 isolationConeDefinitions.push_back(chargedHadrons);
212 isolationConeDefinitions.push_back(neutralHadrons);
213 isolationConeDefinitions.push_back(photons);
214 iDesc.
addVPSet(
"isolationConeDefinitions", descIsoConeDefinitions, isolationConeDefinitions);
217 descriptions.
add(
"CITKPFIsolationSumProducerForPUPPI", iDesc);
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
const std::vector< edm::ParameterSet > & isoDefs
edm::Handle< edm::ValueMap< float > > puppiValueMap
std::array< std::vector< std::string >, kNPFTypes > _product_names
void insert(const H &h, I begin, I end)
edm::EDGetTokenT< edm::ValueMap< float > > puppiValueMapToken_
std::unordered_map< std::string, int > TypeMap
void setComment(std::string const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
PFIsolationSumProducerForPUPPI(const edm::ParameterSet &)
virtual ~PFIsolationSumProducerForPUPPI()
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) overridefinal
edm::EDGetTokenT< CandView > _to_isolate
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ParticleType translatePdgIdToType(int pdgid) const
Particle reconstructed by the particle flow algorithm.
std::vector< std::unique_ptr< IsolationConeDefinitionBase > > IsoTypes
virtual void produce(edm::Event &, const edm::EventSetup &) overridefinal
edm::EDGetTokenT< CandView > _isolate_with
volatile std::atomic< bool > shutdown_flag false
std::array< IsoTypes, kNPFTypes > _isolation_types
T get(const Candidate &c)
static unsigned kNPFTypes