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
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()) {
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
L1TPFCaloProducer::hcalDigis_
std::vector< edm::EDGetTokenT< HcalTrigPrimDigiCollection > > hcalDigis_
Definition: L1TPFCaloProducer.cc:40
CaloTower.h
L1TPFCaloProducer::resol_
l1tpf::ParametricResolution resol_
Definition: L1TPFCaloProducer.cc:54
CaloTPGTranscoder
Definition: CaloTPGTranscoder.h:24
HLT_FULL_cff.towers
towers
Definition: HLT_FULL_cff.py:36362
ParametricResolution.h
L1TPFCaloProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: L1TPFCaloProducer.cc:129
electrons_cff.bool
bool
Definition: electrons_cff.py:366
CaloTools.h
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
L1TPFCaloProducer::readHcalHGCTowers_
void readHcalHGCTowers_(edm::Event &event, const edm::EventSetup &)
Definition: L1TPFCaloProducer.cc:281
ESHandle.h
L1TPFCaloProducer::ecalCands_
std::vector< edm::EDGetTokenT< reco::CandidateView > > ecalCands_
Definition: L1TPFCaloProducer.cc:37
ESInputTag
deltaPhi.h
edm
HLT enums.
Definition: AlignableModifier.h:19
L1TPFCaloProducer::SimpleHGCTC::et
float et
Definition: L1TPFCaloProducer.cc:62
L1TPFCaloProducer::phase2barrelTowers_
std::vector< edm::EDGetTokenT< l1tp2::CaloTowerCollection > > phase2barrelTowers_
Definition: L1TPFCaloProducer.cc:43
L1TPFCaloProducer::hcalDigisBarrel_
bool hcalDigisBarrel_
Definition: L1TPFCaloProducer.cc:42
EDProducer.h
l1tpf_calo
Definition: CaloClusterer.h:21
l1tpf::corrector::valid
bool valid() const
Definition: corrector.h:35
L1TPFCaloProducer::ecalClusterer_
l1tpf_calo::SingleCaloClusterer ecalClusterer_
Definition: L1TPFCaloProducer.cc:51
L1TPFCaloProducer::hadCorrector_
l1tpf::corrector hadCorrector_
Definition: L1TPFCaloProducer.cc:49
CaloTPGTranscoder.h
edm::Handle
Definition: AssociativeIterator.h:50
L1TPFCaloProducer::hcalHGCTowers_
std::vector< edm::EDGetTokenT< l1t::HGCalTowerBxCollection > > hcalHGCTowers_
Definition: L1TPFCaloProducer.cc:44
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
l1tpf_calo::makeCaloLinker
std::unique_ptr< SimpleCaloLinkerBase > makeCaloLinker(const edm::ParameterSet &pset, const SingleCaloClusterer &ecal, const SingleCaloClusterer &hcal)
Definition: CaloClusterer.cc:627
FileInPath.h
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
MakerMacros.h
l1tpf::ParametricResolution
Definition: ParametricResolution.h:10
l1tpf::corrector
Definition: corrector.h:15
l1tpf_calo::Cluster
Definition: CaloClusterer.h:160
l1t::CaloTools::towerPhi
static float towerPhi(int ieta, int iphi)
Definition: CaloTools.cc:208
l1tpf::corrector::correctedPt
float correctedPt(float et, float emEt, float eta) const
Definition: corrector.cc:137
l1tpf_calo::SingleCaloClusterer::add
void add(const reco::Candidate &c)
Definition: CaloClusterer.h:185
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
HcalDigiCollections.h
L1TPFCaloProducer::hcCorrector_
l1tpf::corrector hcCorrector_
Definition: L1TPFCaloProducer.cc:48
L1TPFCaloProducer::readPhase2BarrelCaloTowers_
void readPhase2BarrelCaloTowers_(edm::Event &event, const edm::EventSetup &)
Definition: L1TPFCaloProducer.cc:261
L1TPFCaloProducer::hcalCands_
std::vector< edm::EDGetTokenT< reco::CandidateView > > hcalCands_
Definition: L1TPFCaloProducer.cc:38
BXVector::begin
const_iterator begin(int bx) const
l1tpf_calo::SingleCaloClusterer::fetchCells
std::unique_ptr< l1t::PFClusterCollection > fetchCells(bool unclusteredOnly=false, float ptMin=0.) const
Definition: CaloClusterer.cc:368
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalTrigTowerDetId.h
L1TPFCaloProducer::hcalDigisHF_
bool hcalDigisHF_
Definition: L1TPFCaloProducer.cc:42
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
BXVector::end
const_iterator end(int bx) const
edm::ParameterSet
Definition: ParameterSet.h:47
L1TPFCaloProducer::hcalHGCTowersHadOnly_
bool hcalHGCTowersHadOnly_
Definition: L1TPFCaloProducer.cc:45
Event.h
l1tpf_calo::SingleCaloClusterer::clear
void clear()
Definition: CaloClusterer.cc:195
ParameterSet
Definition: Functions.h:16
L1TPFCaloProducer
Definition: L1TPFCaloProducer.cc:31
L1TPFCaloProducer::SimpleHGCTC::SimpleHGCTC
SimpleHGCTC(float aet, float aeta, float aphi)
Definition: L1TPFCaloProducer.cc:63
CaloTPGRecord
Definition: CaloTPGRecord.h:26
HGCalTower.h
L1TPFCaloProducer::SimpleHGCTC::eta
float eta
Definition: L1TPFCaloProducer.cc:62
l1tpf_calo::CombinedCluster
Definition: CaloClusterer.h:170
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
L1TPFCaloProducer::SimpleHGCTC
Definition: L1TPFCaloProducer.cc:61
edm::stream::EDProducer
Definition: EDProducer.h:38
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
edm::EventSetup
Definition: EventSetup.h:58
CaloTPGRecord.h
edm::ESGetToken< CaloTPGTranscoder, CaloTPGRecord >
l1tpf_calo::SingleCaloClusterer::run
void run()
Definition: CaloClusterer.cc:201
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
reco::Candidate
Definition: Candidate.h:27
L1TPFCaloProducer::ecalOnly_
bool ecalOnly_
Definition: L1TPFCaloProducer.cc:36
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
l1t::CaloTools::towerEta
static float towerEta(int ieta)
Definition: CaloTools.cc:201
l1tpf_calo::SingleCaloClusterer::correct
void correct(const Corrector &corrector)
Definition: CaloClusterer.h:205
Frameworkfwd.h
l1t::PFCluster
Definition: PFCluster.h:10
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
L1TPFCaloProducer::SimpleHGCTC::phi
float phi
Definition: L1TPFCaloProducer.cc:62
l1tpf_calo::SingleCaloClusterer
Definition: CaloClusterer.h:180
L1TPFCaloProducer::emCorrector_
l1tpf::corrector emCorrector_
Definition: L1TPFCaloProducer.cc:47
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
event
Definition: event.py:1
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
L1TPFCaloProducer::hcalClusterer_
l1tpf_calo::SingleCaloClusterer hcalClusterer_
Definition: L1TPFCaloProducer.cc:51
edm::Event
Definition: Event.h:73
L1TPFCaloProducer::L1TPFCaloProducer
L1TPFCaloProducer(const edm::ParameterSet &)
Definition: L1TPFCaloProducer.cc:70
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::Log
Definition: MessageLogger.h:70
corrector.h
l1tpf_calo::SingleCaloClusterer::fetch
std::unique_ptr< l1t::PFClusterCollection > fetch(float ptMin=0.) const
Definition: CaloClusterer.cc:385
L1TPFCaloProducer::debug_
bool debug_
Definition: L1TPFCaloProducer.cc:36
L1TPFCaloProducer::readHcalDigis_
void readHcalDigis_(edm::Event &event, const edm::EventSetup &)
Definition: L1TPFCaloProducer.cc:237
L1TPFCaloProducer::decoderTag_
edm::ESGetToken< CaloTPGTranscoder, CaloTPGRecord > decoderTag_
Definition: L1TPFCaloProducer.cc:41
CaloClusterer.h
HcalTrigTowerDetId
Definition: HcalTrigTowerDetId.h:14
L1TPFCaloProducer::caloLinker_
std::unique_ptr< l1tpf_calo::SimpleCaloLinkerBase > caloLinker_
Definition: L1TPFCaloProducer.cc:52
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316