CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1TPFCaloProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <algorithm>
4 
5 // user include files
13 
19 
21 
23 
25 
29 
30 //--------------------------------------------------------------------------------------------------
32 public:
33  explicit L1TPFCaloProducer(const edm::ParameterSet &);
34 
35 private:
37  std::vector<edm::EDGetTokenT<reco::CandidateView>> ecalCands_;
38  std::vector<edm::EDGetTokenT<reco::CandidateView>> hcalCands_;
39 
40  std::vector<edm::EDGetTokenT<HcalTrigPrimDigiCollection>> hcalDigis_;
43  std::vector<edm::EDGetTokenT<l1tp2::CaloTowerCollection>> phase2barrelTowers_;
44  std::vector<edm::EDGetTokenT<l1t::HGCalTowerBxCollection>> hcalHGCTowers_;
46 
50 
52  std::unique_ptr<l1tpf_calo::SimpleCaloLinkerBase> caloLinker_;
53 
55 
56  void produce(edm::Event &, const edm::EventSetup &) override;
57 
61  struct SimpleHGCTC {
62  float et, eta, phi;
63  SimpleHGCTC(float aet, float aeta, float aphi) : et(aet), eta(aeta), phi(aphi) {}
64  };
65 };
66 
67 //
68 // constructors and destructor
69 //
71  : ecalOnly_(iConfig.existsAs<bool>("ecalOnly") ? iConfig.getParameter<bool>("ecalOnly") : false),
72  debug_(iConfig.getUntrackedParameter<int>("debug", 0)),
73  decoderTag_(esConsumes<CaloTPGTranscoder, CaloTPGRecord>(edm::ESInputTag("", ""))),
74  emCorrector_(iConfig.getParameter<std::string>("emCorrector"), -1, debug_),
75  hcCorrector_(iConfig.getParameter<std::string>("hcCorrector"), -1, debug_),
76  hadCorrector_(iConfig.getParameter<std::string>("hadCorrector"),
77  iConfig.getParameter<double>("hadCorrectorEmfMax"),
78  debug_),
79  ecalClusterer_(iConfig.getParameter<edm::ParameterSet>("ecalClusterer")),
80  hcalClusterer_(iConfig.getParameter<edm::ParameterSet>("hcalClusterer")),
81  caloLinker_(l1tpf_calo::makeCaloLinker(
82  iConfig.getParameter<edm::ParameterSet>("linker"), ecalClusterer_, hcalClusterer_)),
83  resol_(iConfig.getParameter<edm::ParameterSet>("resol")) {
84  produces<l1t::PFClusterCollection>("ecalCells");
85 
86  produces<l1t::PFClusterCollection>("emCalibrated");
87  produces<l1t::PFClusterCollection>("emUncalibrated");
88 
89  for (auto &tag : iConfig.getParameter<std::vector<edm::InputTag>>("ecalCandidates")) {
90  ecalCands_.push_back(consumes<reco::CandidateView>(tag));
91  }
92 
93  if (ecalOnly_)
94  return;
95 
96  produces<l1t::PFClusterCollection>("hcalCells");
97 
98  produces<l1t::PFClusterCollection>("hcalUnclustered");
99  produces<l1t::PFClusterCollection>("hcalUncalibrated");
100  produces<l1t::PFClusterCollection>("hcalCalibrated");
101 
102  produces<l1t::PFClusterCollection>("uncalibrated");
103  produces<l1t::PFClusterCollection>("calibrated");
104 
105  for (auto &tag : iConfig.getParameter<std::vector<edm::InputTag>>("hcalCandidates")) {
106  hcalCands_.push_back(consumes<reco::CandidateView>(tag));
107  }
108 
109  for (auto &tag : iConfig.getParameter<std::vector<edm::InputTag>>("hcalDigis")) {
110  hcalDigis_.push_back(consumes<HcalTrigPrimDigiCollection>(tag));
111  }
112  if (!hcalDigis_.empty()) {
113  hcalDigisBarrel_ = iConfig.getParameter<bool>("hcalDigisBarrel");
114  hcalDigisHF_ = iConfig.getParameter<bool>("hcalDigisHF");
115  }
116 
117  for (auto &tag : iConfig.getParameter<std::vector<edm::InputTag>>("phase2barrelCaloTowers")) {
118  phase2barrelTowers_.push_back(consumes<l1tp2::CaloTowerCollection>(tag));
119  }
120 
121  for (auto &tag : iConfig.getParameter<std::vector<edm::InputTag>>("hcalHGCTowers")) {
122  hcalHGCTowers_.push_back(consumes<l1t::HGCalTowerBxCollection>(tag));
123  }
124  if (!hcalHGCTowers_.empty())
125  hcalHGCTowersHadOnly_ = iConfig.getParameter<bool>("hcalHGCTowersHadOnly");
126 }
127 
128 // ------------ method called to produce the data ------------
132  for (const auto &token : ecalCands_) {
133  iEvent.getByToken(token, ecals);
134  for (const reco::Candidate &it : *ecals) {
135  if (debug_)
136  edm::LogWarning("L1TPFCaloProducer")
137  << "adding ECal input pt " << it.pt() << ", eta " << it.eta() << ", phi " << it.phi() << "\n";
138  ecalClusterer_.add(it);
139  }
140  }
141 
143  if (!ecalOnly_) {
145  for (const auto &token : hcalCands_) {
146  iEvent.getByToken(token, hcals);
147  for (const reco::Candidate &it : *hcals) {
148  if (debug_)
149  edm::LogWarning("L1TPFCaloProducer")
150  << "adding HCal cand input pt " << it.pt() << ", eta " << it.eta() << ", phi " << it.phi() << "\n";
151  hcalClusterer_.add(it);
152  }
153  }
154  if (!hcalDigis_.empty()) {
155  readHcalDigis_(iEvent, iSetup);
156  }
157  if (!phase2barrelTowers_.empty()) {
158  readPhase2BarrelCaloTowers_(iEvent, iSetup);
159  }
160  if (!hcalHGCTowers_.empty()) {
161  readHcalHGCTowers_(iEvent, iSetup);
162  }
163  }
164 
167 
168  auto ecalCellsH = iEvent.put(ecalClusterer_.fetchCells(), "ecalCells");
169 
170  iEvent.put(ecalClusterer_.fetch(ecalCellsH), "emUncalibrated");
171 
172  if (emCorrector_.valid()) {
174  [&](const l1tpf_calo::Cluster &c) -> float { return emCorrector_.correctedPt(0., c.et, std::abs(c.eta)); });
175  }
176 
177  std::unique_ptr<l1t::PFClusterCollection> corrEcal = ecalClusterer_.fetch(ecalCellsH);
178 
179  if (debug_) {
180  for (const l1t::PFCluster &it : *corrEcal) {
181  edm::LogWarning("L1TPFCaloProducer")
182  << "corrected ECal cluster pt " << it.pt() << ", eta " << it.eta() << ", phi " << it.phi() << "\n";
183  }
184  }
185 
186  auto ecalClustH = iEvent.put(std::move(corrEcal), "emCalibrated");
187 
188  if (ecalOnly_) {
190  return;
191  }
192 
194 
195  auto hcalCellsH = iEvent.put(hcalClusterer_.fetchCells(), "hcalCells");
196 
197  // this we put separately for debugging
198  iEvent.put(hcalClusterer_.fetchCells(/*unclustered=*/true), "hcalUnclustered");
199 
200  iEvent.put(hcalClusterer_.fetch(hcalCellsH), "hcalUncalibrated");
201 
202  if (hcCorrector_.valid()) {
204  [&](const l1tpf_calo::Cluster &c) -> float { return hcCorrector_.correctedPt(c.et, 0., std::abs(c.eta)); });
205  }
206 
207  auto hcalClustH = iEvent.put(hcalClusterer_.fetch(hcalCellsH), "hcalCalibrated");
208 
209  // Calorimeter linking
210  caloLinker_->run();
211 
212  iEvent.put(caloLinker_->fetch(ecalClustH, hcalClustH), "uncalibrated");
213 
214  if (hadCorrector_.valid()) {
215  caloLinker_->correct([&](const l1tpf_calo::CombinedCluster &c) -> float {
216  if (debug_)
217  edm::LogWarning("L1TPFCaloProducer") << "raw linked cluster pt " << c.et << ", eta " << c.eta << ", phi "
218  << c.phi << ", emPt " << c.ecal_et << "\n";
219  return hadCorrector_.correctedPt(c.et, c.ecal_et, std::abs(c.eta));
220  });
221  }
222 
223  std::unique_ptr<l1t::PFClusterCollection> clusters = caloLinker_->fetch(ecalClustH, hcalClustH);
224  for (l1t::PFCluster &c : *clusters) {
225  c.setPtError(resol_(c.pt(), std::abs(c.eta())));
226  if (debug_)
227  edm::LogWarning("L1TPFCaloProducer") << "calibrated linked cluster pt " << c.pt() << ", eta " << c.eta()
228  << ", phi " << c.phi() << ", emPt " << c.emEt() << "\n";
229  }
230  iEvent.put(std::move(clusters), "calibrated");
231 
234  caloLinker_->clear();
235 }
236 
238  const auto &decoder = iSetup.getData(decoderTag_);
240  for (const auto &token : hcalDigis_) {
241  iEvent.getByToken(token, hcalTPs);
242  for (const auto &itr : *hcalTPs) {
243  HcalTrigTowerDetId id = itr.id();
244  double et = decoder.hcaletValue(itr.id(), itr.t0());
245  if (et <= 0)
246  continue;
247  float towerEta = l1t::CaloTools::towerEta(id.ieta());
248  float towerPhi = l1t::CaloTools::towerPhi(id.ieta(), id.iphi());
249  if (!hcalDigisBarrel_ && std::abs(towerEta) < 2) // |eta| < 2 => barrel (there's no HE in Phase2)
250  continue;
251  if (!hcalDigisHF_ && std::abs(towerEta) > 2) // |eta| > 2 => HF
252  continue;
253  if (debug_)
254  edm::LogWarning("L1TPFCaloProducer")
255  << "adding HCal digi input pt " << et << ", eta " << towerEta << ", phi " << towerPhi << "\n";
256  hcalClusterer_.add(et, towerEta, towerPhi);
257  }
258  }
259 }
260 
263  for (const auto &token : phase2barrelTowers_) {
264  event.getByToken(token, towers);
265  for (const auto &t : *towers) {
266  // sanity check from https://github.com/cms-l1t-offline/cmssw/blob/l1t-phase2-v3.0.2/L1Trigger/L1CaloTrigger/plugins/L1TowerCalibrator.cc#L259-L263
267  if ((int)t.towerIEta() == -1016 && (int)t.towerIPhi() == -962)
268  continue;
269  if (debug_ && (t.hcalTowerEt() > 0 || t.ecalTowerEt() > 0)) {
270  edm::LogWarning("L1TPFCaloProducer")
271  << "adding phase2 L1 CaloTower eta " << t.towerEta() << " phi " << t.towerPhi() << " ieta "
272  << t.towerIEta() << " iphi " << t.towerIPhi() << " ecal " << t.ecalTowerEt() << " hcal "
273  << t.hcalTowerEt() << "\n";
274  }
275  hcalClusterer_.add(t.hcalTowerEt(), t.towerEta(), t.towerPhi());
276  ecalClusterer_.add(t.ecalTowerEt(), t.towerEta(), t.towerPhi());
277  }
278  }
279 }
280 
283 
284  for (const auto &token : hcalHGCTowers_) {
285  iEvent.getByToken(token, hgcTowers);
286  for (auto it = hgcTowers->begin(0), ed = hgcTowers->end(0); it != ed; ++it) {
287  if (debug_)
288  edm::LogWarning("L1TPFCaloProducer")
289  << "adding HGC Tower hadEt " << it->etHad() << ", emEt " << it->etEm() << ", pt " << it->pt() << ", eta "
290  << it->eta() << ", phi " << it->phi() << "\n";
291  hcalClusterer_.add(it->etHad(), it->eta(), it->phi());
293  ecalClusterer_.add(it->etEm(), it->eta(), it->phi());
294  }
295  }
296 }
297 
298 //define this as a plug-in
static float towerEta(int ieta)
Definition: CaloTools.cc:201
std::vector< edm::EDGetTokenT< HcalTrigPrimDigiCollection > > hcalDigis_
bool valid() const
Definition: corrector.h:35
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::EventSetup & c
l1tpf_calo::SingleCaloClusterer hcalClusterer_
void readHcalDigis_(edm::Event &event, const edm::EventSetup &)
static float towerPhi(int ieta, int iphi)
Definition: CaloTools.cc:208
l1tpf::corrector hadCorrector_
float correctedPt(float et, float emEt, float eta) const
Definition: corrector.cc:137
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::unique_ptr< l1t::PFClusterCollection > fetchCells(bool unclusteredOnly=false, float ptMin=0.) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
l1tpf_calo::SingleCaloClusterer ecalClusterer_
void readHcalHGCTowers_(edm::Event &event, const edm::EventSetup &)
std::vector< edm::EDGetTokenT< reco::CandidateView > > ecalCands_
std::vector< edm::EDGetTokenT< l1t::HGCalTowerBxCollection > > hcalHGCTowers_
std::unique_ptr< SimpleCaloLinkerBase > makeCaloLinker(const edm::ParameterSet &pset, const SingleCaloClusterer &ecal, const SingleCaloClusterer &hcal)
SimpleHGCTC(float aet, float aeta, float aphi)
void add(const reco::Candidate &c)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
int iEvent
Definition: GenABIO.cc:224
void readPhase2BarrelCaloTowers_(edm::Event &event, const edm::EventSetup &)
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unique_ptr< l1t::PFClusterCollection > fetch(float ptMin=0.) const
l1tpf::corrector hcCorrector_
void correct(const Corrector &corrector)
std::vector< edm::EDGetTokenT< reco::CandidateView > > hcalCands_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
L1TPFCaloProducer(const edm::ParameterSet &)
l1tpf::corrector emCorrector_
std::unique_ptr< l1tpf_calo::SimpleCaloLinkerBase > caloLinker_
Log< level::Warning, false > LogWarning
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
l1tpf::ParametricResolution resol_
std::vector< edm::EDGetTokenT< l1tp2::CaloTowerCollection > > phase2barrelTowers_
void produce(edm::Event &, const edm::EventSetup &) override
edm::ESGetToken< CaloTPGTranscoder, CaloTPGRecord > decoderTag_