CMS 3D CMS Logo

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