CMS 3D CMS Logo

DeregionizerProducer.cc
Go to the documentation of this file.
1 #include <unordered_map>
2 
10 
12 
15 
17 public:
18  explicit DeregionizerProducer(const edm::ParameterSet &);
19  ~DeregionizerProducer() override;
20  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
21 
22 private:
26 
27  std::unordered_map<const l1t::PFCandidate *, l1t::PFClusterRef> clusterRefMap_;
28  std::unordered_map<const l1t::PFCandidate *, l1t::PFTrackRef> trackRefMap_;
29  std::unordered_map<const l1t::PFCandidate *, l1t::PFCandidate::MuonRef> muonRefMap_;
30 
31  void produce(edm::Event &, const edm::EventSetup &) override;
32  void hwToEdm_(const std::vector<l1ct::PuppiObjEmu> &hwOut, std::vector<l1t::PFCandidate> &edmOut) const;
33  void setRefs_(l1t::PFCandidate &pf, const l1ct::PuppiObjEmu &p) const;
34 };
35 
37  : config_(iConfig),
38  token_(consumes<l1t::PFCandidateRegionalOutput>(iConfig.getParameter<edm::InputTag>("RegionalPuppiCands"))),
39  emulator_(iConfig) {
40  produces<l1t::PFCandidateCollection>("Puppi");
41  produces<l1t::PFCandidateCollection>("TruncatedPuppi");
42 }
43 
45 
47  clusterRefMap_.clear();
48  trackRefMap_.clear();
49  muonRefMap_.clear();
50 
51  auto deregColl = std::make_unique<l1t::PFCandidateCollection>();
52  auto truncColl = std::make_unique<l1t::PFCandidateCollection>();
53 
55 
56  iEvent.getByToken(token_, src);
57 
58  std::vector<float> regionEtas, regionPhis;
59  std::vector<l1ct::OutputRegion> outputRegions;
60  std::vector<l1ct::PuppiObjEmu> hwOut;
61  std::vector<l1t::PFCandidate> edmOut;
62  std::vector<l1ct::PuppiObjEmu> hwTruncOut;
63  std::vector<l1t::PFCandidate> edmTruncOut;
64 
65  LogDebug("DeregionizerProducer") << "\nRegional Puppi Candidates";
66  for (unsigned int iReg = 0, nReg = src->nRegions(); iReg < nReg; ++iReg) {
67  l1ct::OutputRegion tempOutputRegion;
68 
69  auto region = src->region(iReg);
70  float eta = src->eta(iReg);
71  float phi = src->phi(iReg);
72  LogDebug("DeregionizerProducer") << "\nRegion " << iReg << "\n"
73  << "Eta = " << eta << " and Phi = " << phi << "\n"
74  << "###########";
75  for (int i = 0, n = region.size(); i < n; ++i) {
76  l1ct::PuppiObjEmu tempPuppi;
77  const l1t::PFCandidate &cand = region[i];
78  clusterRefMap_[&cand] = cand.pfCluster();
79  trackRefMap_[&cand] = cand.pfTrack();
80  muonRefMap_[&cand] = cand.muon();
81 
82  tempPuppi.initFromBits(cand.encodedPuppi64());
83  tempPuppi.srcCand = &cand;
84  tempOutputRegion.puppi.push_back(tempPuppi);
85  LogDebug("DeregionizerProducer") << "pt[" << i << "] = " << tempOutputRegion.puppi.back().hwPt << ", eta[" << i
86  << "] = " << tempOutputRegion.puppi.back().floatEta() << ", phi[" << i
87  << "] = " << tempOutputRegion.puppi.back().floatPhi();
88  }
89  if (!tempOutputRegion.puppi.empty()) {
90  regionEtas.push_back(eta);
91  regionPhis.push_back(phi);
92  outputRegions.push_back(tempOutputRegion);
93  }
94  }
95 
97 
98  emulator_.run(in, hwOut, hwTruncOut);
99 
100  DeregionizerProducer::hwToEdm_(hwOut, edmOut);
101  DeregionizerProducer::hwToEdm_(hwTruncOut, edmTruncOut);
102 
103  deregColl->swap(edmOut);
104  truncColl->swap(edmTruncOut);
105 
106  iEvent.put(std::move(deregColl), "Puppi");
107  iEvent.put(std::move(truncColl), "TruncatedPuppi");
108 }
109 
110 void DeregionizerProducer::hwToEdm_(const std::vector<l1ct::PuppiObjEmu> &hwOut,
111  std::vector<l1t::PFCandidate> &edmOut) const {
112  for (const auto &hwPuppi : hwOut) {
114  float mass = 0.13f;
115  if (hwPuppi.hwId.charged()) {
116  if (hwPuppi.hwId.isMuon()) {
118  mass = 0.105;
119  } else if (hwPuppi.hwId.isElectron()) {
121  mass = 0.005;
122  } else
124  } else {
125  type = hwPuppi.hwId.isPhoton() ? l1t::PFCandidate::Photon : l1t::PFCandidate::NeutralHadron;
126  mass = hwPuppi.hwId.isPhoton() ? 0.0 : 0.5;
127  }
128  reco::Particle::PolarLorentzVector p4(hwPuppi.floatPt(), hwPuppi.floatEta(), hwPuppi.floatPhi(), mass);
129  edmOut.emplace_back(
130  type, hwPuppi.intCharge(), p4, hwPuppi.floatPuppiW(), hwPuppi.intPt(), hwPuppi.intEta(), hwPuppi.intPhi());
131  if (hwPuppi.hwId.charged()) {
132  edmOut.back().setZ0(hwPuppi.floatZ0());
133  edmOut.back().setDxy(hwPuppi.floatDxy());
134  edmOut.back().setHwZ0(hwPuppi.hwZ0());
135  edmOut.back().setHwDxy(hwPuppi.hwDxy());
136  edmOut.back().setHwTkQuality(hwPuppi.hwTkQuality());
137  } else {
138  edmOut.back().setHwPuppiWeight(hwPuppi.hwPuppiW());
139  edmOut.back().setHwEmID(hwPuppi.hwEmID());
140  }
141  edmOut.back().setEncodedPuppi64(hwPuppi.pack().to_uint64());
142  setRefs_(edmOut.back(), hwPuppi);
143  }
144 }
145 
147  if (p.srcCand) {
148  auto match = clusterRefMap_.find(p.srcCand);
149  if (match == clusterRefMap_.end()) {
150  throw cms::Exception("CorruptData") << "Invalid cluster pointer in PF candidate id " << p.intId() << " pt "
151  << p.floatPt() << " eta " << p.floatEta() << " phi " << p.floatPhi();
152  }
153  pf.setPFCluster(match->second);
154  }
155  if (p.srcCand) {
156  auto match = trackRefMap_.find(p.srcCand);
157  if (match == trackRefMap_.end()) {
158  throw cms::Exception("CorruptData") << "Invalid track pointer in PF candidate id " << p.intId() << " pt "
159  << p.floatPt() << " eta " << p.floatEta() << " phi " << p.floatPhi();
160  }
161  pf.setPFTrack(match->second);
162  }
163  if (p.srcCand) {
164  auto match = muonRefMap_.find(p.srcCand);
165  if (match == muonRefMap_.end()) {
166  throw cms::Exception("CorruptData") << "Invalid muon pointer in PF candidate id " << p.intId() << " pt "
167  << p.floatPt() << " eta " << p.floatEta() << " phi " << p.floatPhi();
168  }
169  pf.setMuon(match->second);
170  }
171 }
172 
174  // DeregionizerProducer
176  desc.add<edm::InputTag>("RegionalPuppiCands", edm::InputTag("l1tLayer1", "PuppiRegional"));
177  desc.add<unsigned int>("nPuppiFinalBuffer", 128);
178  desc.add<unsigned int>("nPuppiPerClk", 6);
179  desc.add<unsigned int>("nPuppiFirstBuffers", 12);
180  desc.add<unsigned int>("nPuppiSecondBuffers", 32);
181  desc.add<unsigned int>("nPuppiThirdBuffers", 64);
182  descriptions.add("DeregionizerProducer", desc);
183  // or use the following to generate the label from the module's C++ type
184  //descriptions.addWithDefaultLabel(desc);
185 }
186 
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
l1ct::DeregionizerEmulator emulator_
delete x;
Definition: CaloConfig.h:22
const l1t::PFCandidate * srcCand
void produce(edm::Event &, const edm::EventSetup &) override
std::unordered_map< const l1t::PFCandidate *, l1t::PFCandidate::MuonRef > muonRefMap_
std::vector< PuppiObjEmu > puppi
int iEvent
Definition: GenABIO.cc:224
std::unordered_map< const l1t::PFCandidate *, l1t::PFTrackRef > trackRefMap_
void run(const DeregionizerInput in, std::vector< l1ct::PuppiObjEmu > &out, std::vector< l1ct::PuppiObjEmu > &truncated)
void setRefs_(l1t::PFCandidate &pf, const l1ct::PuppiObjEmu &p) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ParameterSet config_
edm::EDGetTokenT< l1t::PFCandidateRegionalOutput > token_
void hwToEdm_(const std::vector< l1ct::PuppiObjEmu > &hwOut, std::vector< l1t::PFCandidate > &edmOut) const
l1t::RegionalOutput< l1t::PFCandidateCollection > PFCandidateRegionalOutput
Definition: PFCandidate.h:85
void initFromBits(const ap_uint< BITWIDTH > &src)
Definition: puppi.h:171
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
DeregionizerProducer(const edm::ParameterSet &)
std::unordered_map< const l1t::PFCandidate *, l1t::PFClusterRef > clusterRefMap_
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)