CMS 3D CMS Logo

FixedGridRhoProducerFastjetFromRecHit.cc
Go to the documentation of this file.
1 /*
2 
3 Author: Swagata Mukherjee
4 
5 Date: November 2021
6 
7 This producer computes rho from ECAL and HCAL recHits.
8 The current plan is to use it in egamma and muon HLT, who currently use
9 the other producer called FixedGridRhoProducerFastjet.
10 At HLT, FixedGridRhoProducerFastjet takes calotowers as input and computes rho.
11 But calotowers are expected to be phased out sometime in Run3.
12 So this recHit-based rho producer, FixedGridRhoProducerFastjetFromRecHit, can be used as an alternative.
13 
14 */
15 
28 #include "fastjet/tools/GridMedianBackgroundEstimator.hh"
32 
34 public:
37  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
38 
39 private:
40  void produce(edm::Event &, const edm::EventSetup &) override;
41  std::array<double, 4> getHitP4(const DetId &detId, const double hitE, const CaloGeometry &caloGeometry) const;
42  bool passedHcalNoiseCut(const HBHERecHit &hit, const HcalPFCuts *) const;
44 
45  fastjet::GridMedianBackgroundEstimator bge_;
49 
52 
53  //Muon HLT currently use ECAL-only rho for ECAL isolation,
54  //and HCAL-only rho for HCAL isolation. So, this skipping option is needed.
55  const bool skipHCAL_;
56  const bool skipECAL_;
57 
60 
61  // following are needed to grab HCal thresholds from GT
63  const bool cutsFromDB_;
64  HcalPFCuts const *paramPF_ = nullptr;
65 };
66 
68  : bge_(iConfig.getParameter<double>("maxRapidity"), iConfig.getParameter<double>("gridSpacing")),
69  hbheRecHitsTag_(consumes(iConfig.getParameter<edm::InputTag>("hbheRecHitsTag"))),
70  ebRecHitsTag_(consumes(iConfig.getParameter<edm::InputTag>("ebRecHitsTag"))),
71  eeRecHitsTag_(consumes(iConfig.getParameter<edm::InputTag>("eeRecHitsTag"))),
72  eThresHB_(iConfig.getParameter<EgammaHcalIsolation::arrayHB>("eThresHB")),
73  eThresHE_(iConfig.getParameter<EgammaHcalIsolation::arrayHE>("eThresHE")),
74  skipHCAL_(iConfig.getParameter<bool>("skipHCAL")),
75  skipECAL_(iConfig.getParameter<bool>("skipECAL")),
76  ecalPFRecHitThresholdsToken_{esConsumes()},
77  caloGeometryToken_{esConsumes()},
78  cutsFromDB_(iConfig.getParameter<bool>("usePFThresholdsFromDB")) {
79  if (skipHCAL_ && skipECAL_) {
80  throw cms::Exception("FixedGridRhoProducerFastjetFromRecHit")
81  << "skipHCAL and skipECAL both can't be True. Please make at least one of them False.";
82  }
83  if (cutsFromDB_) {
84  hcalCutsToken_ = esConsumes<HcalPFCuts, HcalPFCutsRcd>(edm::ESInputTag("", "withTopo"));
85  }
86  produces<double>();
87 }
88 
91  //We use raw recHits and not the PF recHits, because in Phase1 muon and egamma HLT,
92  //PF recHit collection is regional, while the full raw recHit collection is available.
93  desc.add<edm::InputTag>("hbheRecHitsTag", edm::InputTag("hltHbhereco"));
94  desc.add<edm::InputTag>("ebRecHitsTag", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB"));
95  desc.add<edm::InputTag>("eeRecHitsTag", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE"));
96  desc.add<bool>("skipHCAL", false);
97  desc.add<bool>("skipECAL", false);
98  //eThresHB/HE are from RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHBHE_cfi.py
99  desc.add<std::vector<double> >("eThresHB", {0.1, 0.2, 0.3, 0.3});
100  desc.add<std::vector<double> >("eThresHE", {0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2});
101  desc.add<double>("maxRapidity", 2.5);
102  desc.add<double>("gridSpacing", 0.55);
103  desc.add<bool>("usePFThresholdsFromDB", true);
104  descriptions.addWithDefaultLabel(desc);
105 }
106 
108 
110  if (cutsFromDB_) {
111  paramPF_ = &iSetup.getData(hcalCutsToken_);
112  }
113 
114  std::vector<fastjet::PseudoJet> inputs;
115  auto const &thresholds = iSetup.getData(ecalPFRecHitThresholdsToken_);
116  auto const &caloGeometry = iSetup.getData(caloGeometryToken_);
117 
118  if (!skipHCAL_) {
119  auto const &hbheRecHits = iEvent.get(hbheRecHitsTag_);
120  inputs.reserve(inputs.size() + hbheRecHits.size());
121  for (const auto &hit : hbheRecHits) {
123  const auto &hitp4 = getHitP4(hit.id(), hit.energy(), caloGeometry);
124  inputs.emplace_back(fastjet::PseudoJet(hitp4[0], hitp4[1], hitp4[2], hitp4[3]));
125  }
126  }
127  }
128 
129  if (!skipECAL_) {
130  auto const &ebRecHits = iEvent.get(ebRecHitsTag_);
131  inputs.reserve(inputs.size() + ebRecHits.size());
132  for (const auto &hit : ebRecHits) {
134  const auto &hitp4 = getHitP4(hit.id(), hit.energy(), caloGeometry);
135  inputs.emplace_back(fastjet::PseudoJet(hitp4[0], hitp4[1], hitp4[2], hitp4[3]));
136  }
137  }
138 
139  auto const &eeRecHits = iEvent.get(eeRecHitsTag_);
140  inputs.reserve(inputs.size() + eeRecHits.size());
141  for (const auto &hit : eeRecHits) {
143  const auto &hitp4 = getHitP4(hit.id(), hit.energy(), caloGeometry);
144  inputs.emplace_back(fastjet::PseudoJet(hitp4[0], hitp4[1], hitp4[2], hitp4[3]));
145  }
146  }
147  }
148 
149  bge_.set_particles(inputs);
150  iEvent.put(std::make_unique<double>(bge_.rho()));
151 }
152 
154  const double hitE,
155  const CaloGeometry &caloGeometry) const {
157  const auto &gpPos = subDetGeom->getGeometry(detId)->repPos();
158  const double thispt = hitE / cosh(gpPos.eta());
159  const double thispx = thispt * cos(gpPos.phi());
160  const double thispy = thispt * sin(gpPos.phi());
161  const double thispz = thispt * sinh(gpPos.eta());
162  return std::array<double, 4>{{thispx, thispy, thispz, hitE}};
163 }
164 
165 //HCAL noise cleaning cuts.
167  const HcalPFCuts *hcalcuts) const {
168  if (hcalcuts != nullptr) { // using hcal cuts from DB
169  const HcalPFCut *item = hcalcuts->getValues(hit.id().rawId());
170  return (hit.energy() > item->noiseThreshold());
171  } else { // using hcal cuts from config file
172  const auto thisDetId = hit.id();
173  const auto thisDepth = thisDetId.depth();
174  return (thisDetId.subdet() == HcalBarrel && hit.energy() > eThresHB_[thisDepth - 1]) ||
175  (thisDetId.subdet() == HcalEndcap && hit.energy() > eThresHE_[thisDepth - 1]);
176  }
177 }
178 
179 //ECAL noise cleaning cuts using per-crystal PF-recHit thresholds.
181  const EcalPFRecHitThresholds &thresholds) const {
182  return (hit.energy() > thresholds[hit.detid()]);
183 }
184 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::EDGetTokenT< EcalRecHitCollection > ebRecHitsTag_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
constexpr SubDetector subDetGeom[21]
void produce(edm::Event &, const edm::EventSetup &) override
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
bool passedHcalNoiseCut(const HBHERecHit &hit, const HcalPFCuts *) const
const edm::ESGetToken< EcalPFRecHitThresholds, EcalPFRecHitThresholdsRcd > ecalPFRecHitThresholdsToken_
const Item * getValues(DetId fId, bool throwOnFail=true) const
int iEvent
Definition: GenABIO.cc:224
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::array< double, 4 > getHitP4(const DetId &detId, const double hitE, const CaloGeometry &caloGeometry) const
unsigned int id
const edm::EDGetTokenT< HBHERecHitCollection > hbheRecHitsTag_
Definition: DetId.h:17
edm::ESGetToken< HcalPFCuts, HcalPFCutsRcd > hcalCutsToken_
const edm::EDGetTokenT< EcalRecHitCollection > eeRecHitsTag_
FixedGridRhoProducerFastjetFromRecHit(const edm::ParameterSet &iConfig)
HLT enums.
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::array< double, 4 > arrayHB
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
bool passedEcalNoiseCut(const EcalRecHit &hit, const EcalPFRecHitThresholds &thresholds) const
std::array< double, 7 > arrayHE