CMS 3D CMS Logo

CITKPFIsolationSumProducer.cc
Go to the documentation of this file.
1 #ifndef PhysicsTools_IsolationAlgos_CITKIsolationSumProducer_H
2 #define PhysicsTools_IsolationAlgos_CITKIsolationSumProducer_H
3 
7 
15 
20 
24 
25 #include <string>
26 #include <unordered_map>
27 
28 namespace edm {
29  class Event;
30 }
31 namespace edm {
32  class EventSetup;
33 }
34 
35 namespace citk {
37  public:
39 
41 
43 
44  void produce(edm::Event&, const edm::EventSetup&) final;
45 
46  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
47 
48  private:
49  // datamembers
50  static constexpr unsigned kNPFTypes = 8;
51  typedef std::unordered_map<std::string, int> TypeMap;
52  typedef std::vector<std::unique_ptr<IsolationConeDefinitionBase>> IsoTypes;
56  // indexed by pf candidate type
57  std::array<IsoTypes, kNPFTypes> _isolation_types;
58  std::array<std::vector<std::string>, kNPFTypes> _product_names;
59  };
60 } // namespace citk
61 
63 
65 
66 namespace citk {
68  : _typeMap({{"h+", 1}, {"h0", 5}, {"gamma", 4}, {"electron", 2}, {"muon", 3}, {"HFh", 6}, {"HFgamma", 7}}) {
69  _to_isolate = consumes<CandView>(c.getParameter<edm::InputTag>("srcToIsolate"));
70  _isolate_with = consumes<CandView>(c.getParameter<edm::InputTag>("srcForIsolationCone"));
71  const std::vector<edm::ParameterSet>& isoDefs = c.getParameterSetVector("isolationConeDefinitions");
72  for (const auto& isodef : isoDefs) {
73  const std::string& name = isodef.getParameter<std::string>("isolationAlgo");
74  const float coneSize = isodef.getParameter<double>("coneSize");
75  char buf[50];
76  sprintf(buf, "DR%.2f", coneSize);
77  std::string coneName(buf);
78  auto decimal = coneName.find('.');
79  if (decimal != std::string::npos)
80  coneName.erase(decimal, 1);
81  const std::string& isotype = isodef.getParameter<std::string>("isolateAgainst");
82  auto theisolator = CITKIsolationConeDefinitionFactory::get()->create(name, isodef);
83  theisolator->setConsumes(consumesCollector());
84  const auto thetype = _typeMap.find(isotype);
85  if (thetype == _typeMap.end()) {
86  throw cms::Exception("InvalidIsolationType") << "Isolation type: " << isotype << " is not available in the "
87  << "list of allowed isolations!.";
88  }
89  const std::string dash("-");
90  std::string pname = isotype + dash + coneName + dash + theisolator->additionalCode();
91  _product_names[thetype->second].emplace_back(pname);
92  produces<edm::ValueMap<float>>(pname);
93  _isolation_types[thetype->second].emplace_back(std::move(theisolator));
94  }
95  }
96 
98  for (const auto& isolators_for_type : _isolation_types) {
99  for (const auto& isolator : isolators_for_type) {
100  isolator->getEventSetupInfo(es);
101  }
102  }
103  }
104 
106  typedef std::unique_ptr<edm::ValueMap<float>> product_type;
107  typedef std::vector<float> product_values;
108  edm::Handle<CandView> to_isolate;
109  edm::Handle<CandView> isolate_with;
110  ev.getByToken(_to_isolate, to_isolate);
111  ev.getByToken(_isolate_with, isolate_with);
112  // the list of value vectors indexed as "to_isolate"
113  std::array<std::vector<product_values>, kNPFTypes> the_values;
114  // get extra event info and setup value cache
115  unsigned i = 0;
116  for (const auto& isolators_for_type : _isolation_types) {
117  the_values[i++].resize(isolators_for_type.size());
118  for (const auto& isolator : isolators_for_type) {
119  isolator->getEventInfo(ev);
120  }
121  }
122  reco::PFCandidate helper; // to translate pdg id to type
123  // loop over the candidates we are isolating and fill the values
124  for (size_t c = 0; c < to_isolate->size(); ++c) {
125  auto cand_to_isolate = to_isolate->ptrAt(c);
126  std::array<std::vector<float>, kNPFTypes> cand_values;
127  unsigned k = 0;
128  for (const auto& isolators_for_type : _isolation_types) {
129  cand_values[k].resize(isolators_for_type.size());
130  for (auto& value : cand_values[k])
131  value = 0.0;
132  ++k;
133  }
134  for (size_t ic = 0; ic < isolate_with->size(); ++ic) {
135  auto isocand = isolate_with->ptrAt(ic);
136  auto isotype = helper.translatePdgIdToType(isocand->pdgId());
137  const auto& isolations = _isolation_types[isotype];
138  for (unsigned i = 0; i < isolations.size(); ++i) {
139  if (isolations[i]->isInIsolationCone(cand_to_isolate, isocand)) {
140  cand_values[isotype][i] += isocand->pt();
141  }
142  }
143  }
144  // add this candidate to isolation value list
145  for (unsigned i = 0; i < kNPFTypes; ++i) {
146  for (unsigned j = 0; j < cand_values[i].size(); ++j) {
147  the_values[i][j].push_back(cand_values[i][j]);
148  }
149  }
150  }
151  // fill and put all products
152  for (unsigned i = 0; i < kNPFTypes; ++i) {
153  for (unsigned j = 0; j < the_values[i].size(); ++j) {
154  product_type the_product(new edm::ValueMap<float>);
155  edm::ValueMap<float>::Filler fillerprod(*the_product);
156  fillerprod.insert(to_isolate, the_values[i][j].begin(), the_values[i][j].end());
157  fillerprod.fill();
158  ev.put(std::move(the_product), _product_names[i][j]);
159  }
160  }
161  }
162 
163  // ParameterSet description for module
166  iDesc.setComment("isolation sum producer");
167 
168  iDesc.add<edm::InputTag>("srcToIsolate", edm::InputTag("no default"))
169  ->setComment("calculate isolation for this collection");
170  iDesc.add<edm::InputTag>("srcForIsolationCone", edm::InputTag("no default"))
171  ->setComment("collection for the isolation calculation: like particleFlow ");
172 
173  edm::ParameterSetDescription descIsoConeDefinitions;
174  descIsoConeDefinitions.add<std::string>("isolationAlgo", "no default");
175  descIsoConeDefinitions.add<double>("coneSize", 0.3);
176  descIsoConeDefinitions.add<std::string>("isolateAgainst", "no default");
177  descIsoConeDefinitions.add<std::vector<unsigned>>("miniAODVertexCodes", {2, 3});
178  descIsoConeDefinitions.addOptional<double>("VetoConeSizeBarrel", 0.0);
179  descIsoConeDefinitions.addOptional<double>("VetoConeSizeEndcaps", 0.0);
180  descIsoConeDefinitions.addOptional<int>("vertexIndex", 0);
181  descIsoConeDefinitions.addOptional<edm::InputTag>("particleBasedIsolation", edm::InputTag("no default"))
182  ->setComment("map for footprint removal that is used for photons");
183 
184  std::vector<edm::ParameterSet> isolationConeDefinitions;
185  edm::ParameterSet chargedHadrons, neutralHadrons, photons;
186  isolationConeDefinitions.push_back(chargedHadrons);
187  isolationConeDefinitions.push_back(neutralHadrons);
189  iDesc.addVPSet("isolationConeDefinitions", descIsoConeDefinitions, isolationConeDefinitions);
190 
191  descriptions.add("CITKPFIsolationSumProducer", iDesc);
192  }
193 } // namespace citk
194 
195 #endif
egmElectronIsolationPUPPI_cff.isolationConeDefinitions
isolationConeDefinitions
Definition: egmElectronIsolationPUPPI_cff.py:27
citk::PFIsolationSumProducer::_typeMap
const TypeMap _typeMap
Definition: CITKPFIsolationSumProducer.cc:54
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
mps_fire.i
i
Definition: mps_fire.py:428
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
PFCandidate.h
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::EDGetTokenT
Definition: EDGetToken.h:33
citk::PFIsolationSumProducer::CandView
edm::View< reco::Candidate > CandView
Definition: CITKPFIsolationSumProducer.cc:53
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
citk::PFIsolationSumProducer::kNPFTypes
static constexpr unsigned kNPFTypes
Definition: CITKPFIsolationSumProducer.cc:50
EDProducer.h
citk::PFIsolationSumProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: CITKPFIsolationSumProducer.cc:164
EventDependentAbsVeto.h
CITKPFIsolationSumProducer
citk::PFIsolationSumProducer CITKPFIsolationSumProducer
Definition: CITKPFIsolationSumProducer.cc:62
edm::Handle
Definition: AssociativeIterator.h:50
edm::ParameterSetDescription::addOptional
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:105
citk::PFIsolationSumProducer::_to_isolate
edm::EDGetTokenT< CandView > _to_isolate
Definition: CITKPFIsolationSumProducer.cc:55
citk
Definition: CITKIsolationConeDefinitionBase.h:16
CandidateFwd.h
citk::PFIsolationSumProducer::~PFIsolationSumProducer
~PFIsolationSumProducer() override
Definition: CITKPFIsolationSumProducer.cc:40
MakerMacros.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
MuonFwd.h
mps_fire.end
end
Definition: mps_fire.py:242
Event
dqmdumpme.k
k
Definition: dqmdumpme.py:60
unpackData-CaloStage2.pname
pname
Definition: unpackData-CaloStage2.py:76
IsoDeposit.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::View::size
size_type size() const
edm::View
Definition: CaloClusterFwd.h:14
citk::PFIsolationSumProducer::_isolate_with
edm::EDGetTokenT< CandView > _isolate_with
Definition: CITKPFIsolationSumProducer.cc:55
edm::ParameterSet
Definition: ParameterSet.h:47
edm::ParameterSetDescription::setComment
void setComment(std::string const &value)
Definition: ParameterSetDescription.cc:33
HLT_FULL_cff.coneSize
coneSize
Definition: HLT_FULL_cff.py:50845
Event.h
CITKIsolationConeDefinitionBase.h
edm::ParameterSetDescription::addVPSet
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
Definition: ParameterSetDescription.h:149
citk::PFIsolationSumProducer::TypeMap
std::unordered_map< std::string, int > TypeMap
Definition: CITKPFIsolationSumProducer.cc:51
PackedCandidate.h
helper
Definition: helper.py:1
citk::PFIsolationSumProducer::produce
void produce(edm::Event &, const edm::EventSetup &) final
Definition: CITKPFIsolationSumProducer.cc:105
citk::PFIsolationSumProducer::PFIsolationSumProducer
PFIsolationSumProducer(const edm::ParameterSet &)
Definition: CITKPFIsolationSumProducer.cc:67
value
Definition: value.py:1
edm::stream::EDProducer
Definition: EDProducer.h:38
BPHMonitor_cfi.photons
photons
Definition: BPHMonitor_cfi.py:91
edm::EventSetup
Definition: EventSetup.h:57
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
get
#define get
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
citk::PFIsolationSumProducer
Definition: CITKPFIsolationSumProducer.cc:36
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::ValueMap< float >
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
Exception
Definition: hltDiff.cc:246
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
citk::PFIsolationSumProducer::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
Definition: CITKPFIsolationSumProducer.cc:97
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
citk::PFIsolationSumProducer::IsoTypes
std::vector< std::unique_ptr< IsolationConeDefinitionBase > > IsoTypes
Definition: CITKPFIsolationSumProducer.cc:52
ConsumesCollector.h
Candidate.h
IsoDepositFwd.h
edm::helper::Filler
Definition: ValueMap.h:22
EventSetup
ParameterSet.h
OwnVector.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
citk::PFIsolationSumProducer::_product_names
std::array< std::vector< std::string >, kNPFTypes > _product_names
Definition: CITKPFIsolationSumProducer.cc:58
edm::View::ptrAt
Ptr< value_type > ptrAt(size_type i) const
edm::InputTag
Definition: InputTag.h:15
citk::PFIsolationSumProducer::_isolation_types
std::array< IsoTypes, kNPFTypes > _isolation_types
Definition: CITKPFIsolationSumProducer.cc:57