CMS 3D CMS Logo

L1HPSPFTauProducer.cc
Go to the documentation of this file.
1 #include <vector>
2 #include <numeric>
3 
5 // FRAMEWORK HEADERS
10 
13 
17 // bitwise emulation headers
19 
21 public:
22  explicit L1HPSPFTauProducer(const edm::ParameterSet&);
23  ~L1HPSPFTauProducer() override{};
24  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
25 
26 private:
27  void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
28 
29  //various needed vars
30  int nTaus_;
31  bool HW_;
32  bool fUseJets_;
33  bool debug_;
34 
36  //jets
38  //functions
41 
42  static std::vector<l1HPSPFTauEmu::Particle> convertJetsToHW(std::vector<edm::Ptr<reco::CaloJet>>& edmJets);
43  static std::vector<l1HPSPFTauEmu::Particle> convertEDMToHW(std::vector<edm::Ptr<l1t::PFCandidate>>& edmParticles);
44  static std::vector<l1t::PFTau> convertHWToEDM(std::vector<l1HPSPFTauEmu::Tau> hwTaus);
45  //ADD
47 };
48 
50  : nTaus_(cfg.getParameter<int>("nTaus")),
51  HW_(cfg.getParameter<bool>("HW")),
52  fUseJets_(cfg.getParameter<bool>("useJets")),
53  debug_(cfg.getParameter<bool>("debug")),
54  tokenL1PFCands_(consumes(cfg.getParameter<edm::InputTag>("srcL1PFCands"))),
55  tokenL1PFJets_(consumes(cfg.getParameter<edm::InputTag>("srcL1PFJets"))),
56  tauToken_{produces()} {}
57 
60 
61  desc.add<edm::InputTag>("srcL1PFCands", edm::InputTag("l1tLayer1", "Puppi"));
62  desc.add<int>("nTaus", 16);
63  desc.add<bool>("HW", true);
64  desc.add<bool>("useJets", false);
65  desc.add<bool>("debug", false);
66  desc.add<edm::InputTag>("srcL1PFJets",
67  edm::InputTag("l1tPhase1JetCalibrator9x9trimmed", "Phase1L1TJetFromPfCandidates"));
68  descriptions.add("l1tHPSPFTauProducer", desc);
69 }
70 
72  auto l1PFCandidates = iEvent.getHandle(tokenL1PFCands_);
73  //add jets even if not used, for simplicity
74  auto l1PFJets = iEvent.getHandle(tokenL1PFJets_);
75  //
76 
77  //adding collection
78  std::vector<edm::Ptr<l1t::PFCandidate>> particles;
79  for (unsigned i = 0; i < (*l1PFCandidates).size(); i++) {
80  particles.push_back(edm::Ptr<l1t::PFCandidate>(l1PFCandidates, i));
81  }
82 
83  //get the jets
84  std::vector<edm::Ptr<reco::CaloJet>> jets;
85  for (unsigned int i = 0; i < (*l1PFJets).size(); i++) {
86  jets.push_back(edm::Ptr<reco::CaloJet>(l1PFJets, i));
87  //
88  }
89 
90  std::vector<l1t::PFTau> taus;
91 
93 
94  std::sort(taus.begin(), taus.end(), [](const l1t::PFTau& i, const l1t::PFTau& j) { return (i.pt() > j.pt()); });
95 
96  iEvent.emplace(tauToken_, std::move(taus));
97 }
98 
100  std::vector<edm::Ptr<reco::CaloJet>>& jwork) const {
101  //convert and call emulator
102 
103  using namespace l1HPSPFTauEmu;
104 
105  std::vector<Particle> particles = convertEDMToHW(work);
106 
107  std::vector<Particle> jets = convertJetsToHW(jwork);
108  //also need to pass the jet enabler
109 
110  bool jEnable = fUseJets_;
111 
112  std::vector<Tau> taus = emulateEvent(particles, jets, jEnable);
113 
114  return convertHWToEDM(taus);
115 }
116 
117 std::vector<l1HPSPFTauEmu::Particle> L1HPSPFTauProducer::convertJetsToHW(std::vector<edm::Ptr<reco::CaloJet>>& edmJets) {
118  using namespace l1HPSPFTauEmu;
119  std::vector<Particle> hwJets;
120  std::for_each(edmJets.begin(), edmJets.end(), [&](edm::Ptr<reco::CaloJet>& edmJet) {
122  jPart.hwPt = l1ct::Scales::makePtFromFloat(edmJet->pt());
123  jPart.hwEta = edmJet->eta() * etaphi_base;
124  jPart.hwPhi = edmJet->phi() * etaphi_base;
125  jPart.tempZ0 = 0.;
126  hwJets.push_back(jPart);
127  });
128  return hwJets;
129 }
130 
131 //conversion to and from HW bitwise
132 std::vector<l1HPSPFTauEmu::Particle> L1HPSPFTauProducer::convertEDMToHW(
133  std::vector<edm::Ptr<l1t::PFCandidate>>& edmParticles) {
134  using namespace l1HPSPFTauEmu;
135  std::vector<Particle> hwParticles;
136 
137  std::for_each(edmParticles.begin(), edmParticles.end(), [&](edm::Ptr<l1t::PFCandidate>& edmParticle) {
138  Particle hwPart;
139  hwPart.hwPt = l1ct::Scales::makePtFromFloat(edmParticle->pt());
140  hwPart.hwEta = edmParticle->eta() * etaphi_base;
141  hwPart.hwPhi = edmParticle->phi() * etaphi_base;
142  hwPart.pID = edmParticle->id();
143  if (edmParticle->z0()) {
144  hwPart.tempZ0 = edmParticle->z0() / dz_base;
145  }
146  hwParticles.push_back(hwPart);
147  });
148  return hwParticles;
149 }
150 
151 std::vector<l1t::PFTau> L1HPSPFTauProducer::convertHWToEDM(std::vector<l1HPSPFTauEmu::Tau> hwTaus) {
152  using namespace l1HPSPFTauEmu;
153  std::vector<l1t::PFTau> edmTaus;
154 
155  //empty array for the PFTau format, since it's used for PuppiTaus but not here
156  float tauArray[80] = {0};
157  std::for_each(hwTaus.begin(), hwTaus.end(), [&](Tau tau) {
158  l1gt::Tau gtTau = tau.toGT();
159  l1gt::PackedTau packTau = gtTau.pack();
160 
161  l1t::PFTau pTau(
163  l1ct::Scales::floatPt(tau.hwPt), float(tau.hwEta) / etaphi_base, float(tau.hwPhi) / etaphi_base, 0),
164  tauArray,
165  0,
166  0,
167  0,
168  tau.hwPt,
169  tau.hwEta,
170  tau.hwPhi);
171  pTau.set_encodedTau(packTau);
172  edmTaus.push_back(pTau);
173  });
174  return edmTaus;
175 }
176 
void set_encodedTau(l1gt::PackedTau encodedTau)
Definition: PFTau.h:75
edm::EDGetTokenT< std::vector< reco::CaloJet > > tokenL1PFJets_
pt_t makePtFromFloat(float pt)
Definition: datatypes.h:183
std::vector< Tau > emulateEvent(std::vector< Particle > &parts, std::vector< Particle > &jets, bool jEnable)
std::array< uint64_t, 2 > PackedTau
Definition: gt_datatypes.h:39
L1HPSPFTauProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
glbeta_t hwEta
Definition: puppi.h:13
float floatPt(pt_t pt)
Definition: datatypes.h:154
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
glbphi_t hwPhi
Definition: puppi.h:14
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
~L1HPSPFTauProducer() override
Definition: Tau.py:1
std::vector< l1t::PFTau > processEvent_HW(std::vector< edm::Ptr< l1t::PFCandidate >> &parts, std::vector< edm::Ptr< reco::CaloJet >> &jets) const
pt_t hwPt
Definition: puppi.h:12
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static std::vector< l1HPSPFTauEmu::Particle > convertEDMToHW(std::vector< edm::Ptr< l1t::PFCandidate >> &edmParticles)
edm::EDPutTokenT< l1t::PFTauCollection > tauToken_
HLT enums.
edm::EDGetTokenT< l1t::PFCandidateCollection > tokenL1PFCands_
static std::vector< l1t::PFTau > convertHWToEDM(std::vector< l1HPSPFTauEmu::Tau > hwTaus)
static std::vector< l1HPSPFTauEmu::Particle > convertJetsToHW(std::vector< edm::Ptr< reco::CaloJet >> &edmJets)
constexpr float dz_base
def move(src, dest)
Definition: eostools.py:511
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
constexpr float etaphi_base
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:38