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:
25  std::vector<edm::ParameterSet> linkConfigs_;
26  const unsigned int nInputFramesPerBX_;
30  std::vector<std::vector<uint32_t>> outputRegions_;
31  const unsigned int tmuxFactor_ = 6; // not really configurable in current architecture
32 
33  std::unordered_map<const l1t::PFCandidate *, l1t::PFClusterRef> clusterRefMap_;
34  std::unordered_map<const l1t::PFCandidate *, l1t::PFTrackRef> trackRefMap_;
35  std::unordered_map<const l1t::PFCandidate *, l1t::PFCandidate::MuonRef> muonRefMap_;
36 
37  void produce(edm::Event &, const edm::EventSetup &) override;
38  void hwToEdm_(const std::vector<l1ct::PuppiObjEmu> &hwOut, std::vector<l1t::PFCandidate> &edmOut) const;
39  void setRefs_(l1t::PFCandidate &pf, const l1ct::PuppiObjEmu &p) const;
40 };
41 
43  : config_(iConfig),
44  token_(consumes<l1t::PFCandidateRegionalOutput>(iConfig.getParameter<edm::InputTag>("RegionalPuppiCands"))),
45  linkConfigs_(iConfig.getParameter<std::vector<edm::ParameterSet>>("linkConfigs")),
46  nInputFramesPerBX_(iConfig.getParameter<uint32_t>("nInputFramesPerBX")),
47  emulator_(iConfig),
48  input_(linkConfigs_) {
49  produces<l1t::PFCandidateCollection>("Puppi");
50  produces<l1t::PFCandidateCollection>("TruncatedPuppi");
51 }
52 
54 
56  clusterRefMap_.clear();
57  trackRefMap_.clear();
58  muonRefMap_.clear();
59 
60  auto deregColl = std::make_unique<l1t::PFCandidateCollection>();
61  auto truncColl = std::make_unique<l1t::PFCandidateCollection>();
62 
64 
65  iEvent.getByToken(token_, src);
66 
67  std::vector<l1ct::OutputRegion> outputRegions;
68  std::vector<l1ct::PuppiObjEmu> hwOut;
69  std::vector<l1t::PFCandidate> edmOut;
70  std::vector<l1ct::PuppiObjEmu> hwTruncOut;
71  std::vector<l1t::PFCandidate> edmTruncOut;
72 
73  LogDebug("DeregionizerProducer") << "\nRegional Puppi Candidates";
74  for (unsigned int iReg = 0, nReg = src->nRegions(); iReg < nReg; ++iReg) {
75  l1ct::OutputRegion tempOutputRegion;
76 
77  auto region = src->region(iReg);
78  float eta = src->eta(iReg);
79  float phi = src->phi(iReg);
80  LogDebug("DeregionizerProducer") << "\nRegion " << iReg << "\n"
81  << "Eta = " << eta << " and Phi = " << phi << "\n"
82  << "###########";
83  for (int i = 0, n = region.size(); i < n; ++i) {
84  l1ct::PuppiObjEmu tempPuppi;
85  const l1t::PFCandidate &cand = region[i];
86  clusterRefMap_[&cand] = cand.pfCluster();
87  trackRefMap_[&cand] = cand.pfTrack();
88  muonRefMap_[&cand] = cand.muon();
89 
90  tempPuppi.initFromBits(cand.encodedPuppi64());
91  tempPuppi.srcCand = &cand;
92  tempOutputRegion.puppi.push_back(tempPuppi);
93  LogDebug("DeregionizerProducer") << "pt[" << i << "] = " << tempOutputRegion.puppi.back().hwPt << ", eta[" << i
94  << "] = " << tempOutputRegion.puppi.back().floatEta() << ", phi[" << i
95  << "] = " << tempOutputRegion.puppi.back().floatPhi();
96  }
97  outputRegions.push_back(tempOutputRegion);
98  }
99 
100  std::vector<std::vector<std::vector<l1ct::PuppiObjEmu>>> layer2In = input_.orderInputs(outputRegions);
101 
102  emulator_.run(layer2In, hwOut, hwTruncOut);
103 
104  DeregionizerProducer::hwToEdm_(hwOut, edmOut);
105  DeregionizerProducer::hwToEdm_(hwTruncOut, edmTruncOut);
106 
107  deregColl->swap(edmOut);
108  truncColl->swap(edmTruncOut);
109 
110  iEvent.put(std::move(deregColl), "Puppi");
111  iEvent.put(std::move(truncColl), "TruncatedPuppi");
112 }
113 
114 void DeregionizerProducer::hwToEdm_(const std::vector<l1ct::PuppiObjEmu> &hwOut,
115  std::vector<l1t::PFCandidate> &edmOut) const {
116  for (const auto &hwPuppi : hwOut) {
118  float mass = 0.13f;
119  if (hwPuppi.hwId.charged()) {
120  if (hwPuppi.hwId.isMuon()) {
122  mass = 0.105;
123  } else if (hwPuppi.hwId.isElectron()) {
125  mass = 0.005;
126  } else
128  } else {
129  type = hwPuppi.hwId.isPhoton() ? l1t::PFCandidate::Photon : l1t::PFCandidate::NeutralHadron;
130  mass = hwPuppi.hwId.isPhoton() ? 0.0 : 0.5;
131  }
132  reco::Particle::PolarLorentzVector p4(hwPuppi.floatPt(), hwPuppi.floatEta(), hwPuppi.floatPhi(), mass);
133  edmOut.emplace_back(
134  type, hwPuppi.intCharge(), p4, hwPuppi.floatPuppiW(), hwPuppi.intPt(), hwPuppi.intEta(), hwPuppi.intPhi());
135  if (hwPuppi.hwId.charged()) {
136  edmOut.back().setZ0(hwPuppi.floatZ0());
137  edmOut.back().setDxy(hwPuppi.floatDxy());
138  edmOut.back().setHwZ0(hwPuppi.hwZ0());
139  edmOut.back().setHwDxy(hwPuppi.hwDxy());
140  edmOut.back().setHwTkQuality(hwPuppi.hwTkQuality());
141  } else {
142  edmOut.back().setHwPuppiWeight(hwPuppi.hwPuppiW());
143  edmOut.back().setHwEmID(hwPuppi.hwEmID());
144  }
145  edmOut.back().setEncodedPuppi64(hwPuppi.pack().to_uint64());
146  setRefs_(edmOut.back(), hwPuppi);
147  }
148 }
149 
151  if (p.srcCand) {
152  auto match = clusterRefMap_.find(p.srcCand);
153  if (match == clusterRefMap_.end()) {
154  throw cms::Exception("CorruptData") << "Invalid cluster pointer in PF candidate id " << p.intId() << " pt "
155  << p.floatPt() << " eta " << p.floatEta() << " phi " << p.floatPhi();
156  }
157  pf.setPFCluster(match->second);
158  }
159  if (p.srcCand) {
160  auto match = trackRefMap_.find(p.srcCand);
161  if (match == trackRefMap_.end()) {
162  throw cms::Exception("CorruptData") << "Invalid track pointer in PF candidate id " << p.intId() << " pt "
163  << p.floatPt() << " eta " << p.floatEta() << " phi " << p.floatPhi();
164  }
165  pf.setPFTrack(match->second);
166  }
167  if (p.srcCand) {
168  auto match = muonRefMap_.find(p.srcCand);
169  if (match == muonRefMap_.end()) {
170  throw cms::Exception("CorruptData") << "Invalid muon pointer in PF candidate id " << p.intId() << " pt "
171  << p.floatPt() << " eta " << p.floatEta() << " phi " << p.floatPhi();
172  }
173  pf.setMuon(match->second);
174  }
175 }
176 
179  desc.add<edm::InputTag>("RegionalPuppiCands", edm::InputTag("l1tLayer1", "PuppiRegional"));
180  desc.add<unsigned int>("nPuppiFinalBuffer", 128);
181  desc.add<unsigned int>("nPuppiPerClk", 6);
182  desc.add<unsigned int>("nPuppiFirstBuffers", 12);
183  desc.add<unsigned int>("nPuppiSecondBuffers", 32);
184  desc.add<unsigned int>("nPuppiThirdBuffers", 64);
185  desc.add<unsigned int>("nInputFramesPerBX", 9);
186  edm::ParameterSetDescription linkConfigDummyValidator;
187  linkConfigDummyValidator.setAllowAnything();
188  desc.addVPSet("linkConfigs", linkConfigDummyValidator);
189  descriptions.add("DeregionizerProducer", desc);
190 }
191 
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< std::vector< std::vector< l1ct::PuppiObjEmu > > > orderInputs(const std::vector< l1ct::OutputRegion > &inputRegions) const
const unsigned int tmuxFactor_
l1ct::DeregionizerEmulator emulator_
void setAllowAnything()
allow any parameter label/value pairs
delete x;
Definition: CaloConfig.h:22
std::vector< uint32_t > nOutputFramesPerBX_
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::vector< uint32_t > nPuppiFramesPerRegion_
std::unordered_map< const l1t::PFCandidate *, l1t::PFTrackRef > trackRefMap_
void setRefs_(l1t::PFCandidate &pf, const l1ct::PuppiObjEmu &p) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< std::vector< uint32_t > > outputRegions_
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:89
void initFromBits(const ap_uint< BITWIDTH > &src)
Definition: puppi.h:171
const unsigned int nInputFramesPerBX_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< edm::ParameterSet > linkConfigs_
HLT enums.
l1ct::DeregionizerInput input_
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
std::vector< uint32_t > nPuppiPerRegion_
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
std::vector< uint32_t > nLinksPuppi_
DeregionizerProducer(const edm::ParameterSet &)
std::unordered_map< const l1t::PFCandidate *, l1t::PFClusterRef > clusterRefMap_
def move(src, dest)
Definition: eostools.py:511
std::vector< uint32_t > boardOrder_
void run(std::vector< std::vector< std::vector< l1ct::PuppiObjEmu >>> in, std::vector< l1ct::PuppiObjEmu > &out, std::vector< l1ct::PuppiObjEmu > &truncated)
#define LogDebug(id)