CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
PFCandidateRecalibrator Class Reference
Inheritance diagram for PFCandidateRecalibrator:
edm::stream::EDProducer<>

Public Member Functions

 PFCandidateRecalibrator (const edm::ParameterSet &)
 
 ~PFCandidateRecalibrator () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

void beginRun (const edm::Run &iRun, edm::EventSetup const &iSetup) override
 
void endRun (const edm::Run &iRun, edm::EventSetup const &iSetup) override
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::vector< HEChannelbadChHE_
 
std::vector< HFChannelbadChHF_
 
const edm::ESGetToken< HcalRespCorrs, HcalRespCorrsRcdbuggedCondToken_
 
const edm::ESGetToken< CaloGeometry, CaloGeometryRecordcalogeomTokenEvent_
 
const edm::ESGetToken< CaloGeometry, CaloGeometryRecordcalogeomTokenRun_
 
const edm::ESGetToken< HcalDbService, HcalDbRecordgtCondToken_
 
edm::ESWatcher< HcalRecNumberingRecordhcalDbWatcher_
 
edm::ESWatcher< HcalRespCorrsRcdhcalRCWatcher_
 
const edm::ESGetToken< HcalTopology, HcalRecNumberingRecordhtopoToken_
 
float longFibreThr_
 
edm::EDGetTokenT< reco::PFCandidateCollectionpfcandidates_
 
float shortFibreThr_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 50 of file PFCandidateRecalibrator.cc.

Constructor & Destructor Documentation

◆ PFCandidateRecalibrator()

PFCandidateRecalibrator::PFCandidateRecalibrator ( const edm::ParameterSet iConfig)

Definition at line 80 of file PFCandidateRecalibrator.cc.

81  : pfcandidates_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfcandidates"))),
82  gtCondToken_(esConsumes<edm::Transition::BeginRun>()),
83  htopoToken_(esConsumes<edm::Transition::BeginRun>()),
84  buggedCondToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "bugged"))),
85  calogeomTokenRun_(esConsumes<edm::Transition::BeginRun>()),
87  shortFibreThr_(iConfig.getParameter<double>("shortFibreThr")),
88  longFibreThr_(iConfig.getParameter<double>("longFibreThr")) {
89  produces<reco::PFCandidateCollection>();
90  produces<reco::PFCandidateCollection>("discarded");
91  produces<edm::ValueMap<reco::PFCandidateRef>>();
92 }
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > calogeomTokenRun_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const edm::ESGetToken< HcalRespCorrs, HcalRespCorrsRcd > buggedCondToken_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > calogeomTokenEvent_
edm::EDGetTokenT< reco::PFCandidateCollection > pfcandidates_
const edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > htopoToken_
const edm::ESGetToken< HcalDbService, HcalDbRecord > gtCondToken_

◆ ~PFCandidateRecalibrator()

PFCandidateRecalibrator::~PFCandidateRecalibrator ( )
inlineoverride

Definition at line 53 of file PFCandidateRecalibrator.cc.

53 {};

Member Function Documentation

◆ beginRun()

void PFCandidateRecalibrator::beginRun ( const edm::Run iRun,
edm::EventSetup const &  iSetup 
)
overrideprivate

Definition at line 94 of file PFCandidateRecalibrator.cc.

References funct::abs(), badChHE_, badChHF_, buggedCondToken_, calogeomTokenRun_, edm::ESWatcher< T >::check(), HcalDetId::depth(), f, edm::EventSetup::getData(), HcalDbService::getHcalRespCorr(), HcalGeometry::getPosition(), CaloGeometry::getSubdetectorGeometry(), HcalGeometry::getValidDetIds(), HcalRespCorr::getValue(), HcalCondObjectContainer< Item >::getValues(), gtCondToken_, DetId::Hcal, hcalDbWatcher_, HcalEndcap, HcalForward, hcalRCWatcher_, htopoToken_, HcalDetId::ieta(), HcalDetId::iphi(), particleFlowDisplacedVertex_cfi::ratio, and HcalCondObjectContainerBase::setTopo().

94  {
95  if (hcalDbWatcher_.check(iSetup) || hcalRCWatcher_.check(iSetup)) {
96  //Get Calib Constants from current GT
97  HcalDbService const& gtCond = iSetup.getData(gtCondToken_);
98 
99  //Get Calib Constants from bugged tag
100  const HcalTopology& theHBHETopology = iSetup.getData(htopoToken_);
101 
102  HcalRespCorrs buggedRespCorrs = iSetup.getData(buggedCondToken_);
103  buggedRespCorrs.setTopo(&theHBHETopology);
104 
105  //access calogeometry
106  const CaloGeometry& cgeo = iSetup.getData(calogeomTokenRun_);
107  const HcalGeometry* hgeom = static_cast<const HcalGeometry*>(cgeo.getSubdetectorGeometry(DetId::Hcal, HcalForward));
108 
109  //reset the bad channel containers
110  badChHE_.clear();
111  badChHF_.clear();
112 
113  //fill bad cells HE (use eta, phi)
114  const std::vector<DetId>& cellsHE = hgeom->getValidDetIds(DetId::Detector::Hcal, HcalEndcap);
115  for (auto id : cellsHE) {
116  float currentRespCorr = gtCond.getHcalRespCorr(id)->getValue();
117  float buggedRespCorr = buggedRespCorrs.getValues(id)->getValue();
118  if (buggedRespCorr == 0.)
119  continue;
120 
121  float ratio = currentRespCorr / buggedRespCorr;
122  if (std::abs(ratio - 1.f) > 0.001) {
123  GlobalPoint pos = hgeom->getPosition(id);
124  badChHE_.push_back(HEChannel(pos.eta(), pos.phi(), ratio));
125  }
126  }
127 
128  //fill bad cells HF (use ieta, iphi)
129  auto const& cellsHF = hgeom->getValidDetIds(DetId::Detector::Hcal, HcalForward);
130  for (auto id : cellsHF) {
131  float currentRespCorr = gtCond.getHcalRespCorr(id)->getValue();
132  float buggedRespCorr = buggedRespCorrs.getValues(id)->getValue();
133  if (buggedRespCorr == 0.)
134  continue;
135 
136  float ratio = currentRespCorr / buggedRespCorr;
137  if (std::abs(ratio - 1.f) > 0.001) {
138  HcalDetId dummyId(id);
139  badChHF_.push_back(HFChannel(dummyId.ieta(), dummyId.iphi(), dummyId.depth(), ratio));
140  }
141  }
142  }
143 }
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > calogeomTokenRun_
const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const override
Get a list of valid detector ids (for the given subdetector)
Definition: HcalGeometry.cc:76
edm::ESWatcher< HcalRecNumberingRecord > hcalDbWatcher_
std::vector< HEChannel > badChHE_
const Item * getValues(DetId fId, bool throwOnFail=true) const
const edm::ESGetToken< HcalRespCorrs, HcalRespCorrsRcd > buggedCondToken_
const HcalRespCorr * getHcalRespCorr(const HcalGenericDetId &fId) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
edm::ESWatcher< HcalRespCorrsRcd > hcalRCWatcher_
float getValue() const
Definition: HcalRespCorr.h:19
std::vector< HFChannel > badChHF_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
const edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > htopoToken_
GlobalPoint getPosition(const DetId &id) const
const edm::ESGetToken< HcalDbService, HcalDbRecord > gtCondToken_
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
void setTopo(const HcalTopology *topo)

◆ endRun()

void PFCandidateRecalibrator::endRun ( const edm::Run iRun,
edm::EventSetup const &  iSetup 
)
overrideprivate

Definition at line 145 of file PFCandidateRecalibrator.cc.

145 {}

◆ fillDescriptions()

void PFCandidateRecalibrator::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 310 of file PFCandidateRecalibrator.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, and HLT_2022v14_cff::InputTag.

310  {
312 
313  desc.add<edm::InputTag>("pfcandidates", edm::InputTag("particleFlow"));
314  desc.add<double>("shortFibreThr", 1.4);
315  desc.add<double>("longFibreThr", 1.4);
316 
317  descriptions.add("pfCandidateRecalibrator", desc);
318 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ produce()

void PFCandidateRecalibrator::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 147 of file PFCandidateRecalibrator.cc.

References funct::abs(), badChHE_, badChHF_, calogeomTokenEvent_, filterCSVwithJSON::copy, reco::deltaR2(), trigObjTnPSource_cfi::filler, HcalGeometry::getClosestCell(), edm::EventSetup::getData(), CaloGeometry::getSubdetectorGeometry(), DetId::Hcal, HcalForward, mps_fire::i, iEvent, LogDebug, longFibreThr_, eostools::move(), packedPFCandidateRefMixer_cfi::pf, packedPFCandidateRefMixer_cfi::pf2pf, OniaPhotonConversionProducer_cfi::pfcandidates, pfcandidates_, and shortFibreThr_.

147  {
148  //access calogeometry
149  const CaloGeometry& cgeo = iSetup.getData(calogeomTokenEvent_);
150  const HcalGeometry* hgeom = static_cast<const HcalGeometry*>(cgeo.getSubdetectorGeometry(DetId::Hcal, HcalForward));
151 
152  //access PFCandidates
154  iEvent.getByToken(pfcandidates_, pfcandidates);
155 
156  int nPfCand = pfcandidates->size();
157  std::unique_ptr<reco::PFCandidateCollection> copy(new reco::PFCandidateCollection());
158  std::unique_ptr<reco::PFCandidateCollection> discarded(new reco::PFCandidateCollection());
159  copy->reserve(nPfCand);
160  std::vector<int> oldToNew(nPfCand), newToOld, badToOld;
161  newToOld.reserve(nPfCand);
162 
163  LogDebug("PFCandidateRecalibrator") << "NEW EV:";
164 
165  //loop over PFCandidates
166  int i = -1;
167  for (const reco::PFCandidate& pf : *pfcandidates) {
168  ++i;
169  float absEta = std::abs(pf.eta());
170 
171  //deal with HE
172  if (pf.particleId() == reco::PFCandidate::ParticleType::h0 &&
173  !badChHE_.empty() && //don't touch if no miscalibration is found
174  absEta > 1.4 && absEta < 3.) {
175  bool toKill = false;
176  for (auto const& badIt : badChHE_)
177  if (reco::deltaR2(pf.eta(), pf.phi(), badIt.eta, badIt.phi) < 0.07)
178  toKill = true;
179 
180  if (toKill) {
181  discarded->push_back(pf);
182  oldToNew[i] = (-discarded->size());
183  badToOld.push_back(i);
184  continue;
185  } else {
186  copy->push_back(pf);
187  oldToNew[i] = (copy->size());
188  newToOld.push_back(i);
189  }
190  }
191  //deal with HF
192  else if ((pf.particleId() == reco::PFCandidate::ParticleType::h_HF ||
193  pf.particleId() == reco::PFCandidate::ParticleType::egamma_HF) &&
194  !badChHF_.empty() && //don't touch if no miscalibration is found
195  absEta >= 3.) {
196  const math::XYZPointF& ecalPoint = pf.positionAtECALEntrance();
197  GlobalPoint ecalGPoint(ecalPoint.X(), ecalPoint.Y(), ecalPoint.Z());
198  HcalDetId closestDetId(hgeom->getClosestCell(ecalGPoint));
199 
200  if (closestDetId.subdet() == HcalForward) {
201  HcalDetId hDetId(closestDetId.subdet(), closestDetId.ieta(), closestDetId.iphi(), 1); //depth1
202 
203  //raw*calEnergy() is the same as *calEnergy() - no corrections are done for HF
204  float longE = pf.rawEcalEnergy() + pf.rawHcalEnergy() / 2.; //depth1
205  float shortE = pf.rawHcalEnergy() / 2.; //depth2
206 
207  float ecalEnergy = pf.rawEcalEnergy();
208  float hcalEnergy = pf.rawHcalEnergy();
209  float totEnergy = ecalEnergy + hcalEnergy;
210  float totEnergyOrig = totEnergy;
211 
212  bool toKill = false;
213 
214  for (auto const& badIt : badChHF_) {
215  if (hDetId.ieta() == badIt.ieta && hDetId.iphi() == badIt.iphi) {
216  LogDebug("PFCandidateRecalibrator")
217  << "==> orig en (tot,H,E): " << pf.energy() << " " << pf.rawHcalEnergy() << " " << pf.rawEcalEnergy();
218  if (badIt.depth == 1) //depth1
219  {
220  longE *= badIt.ratio;
221  ecalEnergy = ((longE - shortE) > 0.) ? (longE - shortE) : 0.;
222  totEnergy = ecalEnergy + hcalEnergy;
223  } else //depth2
224  {
225  shortE *= badIt.ratio;
226  hcalEnergy = 2 * shortE;
227  ecalEnergy = ((longE - shortE) > 0.) ? (longE - shortE) : 0.;
228  totEnergy = ecalEnergy + hcalEnergy;
229  }
230  //kill candidate if goes below thr
231  if ((pf.particleId() == reco::PFCandidate::ParticleType::h_HF && shortE < shortFibreThr_) ||
232  (pf.particleId() == reco::PFCandidate::ParticleType::egamma_HF && longE < longFibreThr_))
233  toKill = true;
234 
235  LogDebug("PFCandidateRecalibrator") << "====> ieta,iphi,depth: " << badIt.ieta << " " << badIt.iphi << " "
236  << badIt.depth << " corr: " << badIt.ratio;
237  LogDebug("PFCandidateRecalibrator")
238  << "====> recal en (tot,H,E): " << totEnergy << " " << hcalEnergy << " " << ecalEnergy;
239  }
240  }
241 
242  if (toKill) {
243  discarded->push_back(pf);
244  oldToNew[i] = (-discarded->size());
245  badToOld.push_back(i);
246 
247  LogDebug("PFCandidateRecalibrator") << "==> KILLED ";
248  } else {
249  copy->push_back(pf);
250  oldToNew[i] = (copy->size());
251  newToOld.push_back(i);
252 
253  copy->back().setHcalEnergy(hcalEnergy, hcalEnergy);
254  copy->back().setEcalEnergy(ecalEnergy, ecalEnergy);
255 
256  float scalingFactor = totEnergy / totEnergyOrig;
257  math::XYZTLorentzVector recalibP4 = pf.p4() * scalingFactor;
258  copy->back().setP4(recalibP4);
259 
260  LogDebug("PFCandidateRecalibrator") << "====> stored en (tot,H,E): " << copy->back().energy() << " "
261  << copy->back().hcalEnergy() << " " << copy->back().ecalEnergy();
262  }
263  } else {
264  copy->push_back(pf);
265  oldToNew[i] = (copy->size());
266  newToOld.push_back(i);
267  }
268  } else {
269  copy->push_back(pf);
270  oldToNew[i] = (copy->size());
271  newToOld.push_back(i);
272  }
273  }
274 
275  // Now we put things in the event
277  edm::OrphanHandle<reco::PFCandidateCollection> badpf = iEvent.put(std::move(discarded), "discarded");
278 
279  std::unique_ptr<edm::ValueMap<reco::PFCandidateRef>> pf2pf(new edm::ValueMap<reco::PFCandidateRef>());
281  std::vector<reco::PFCandidateRef> refs;
282  refs.reserve(nPfCand);
283 
284  // old to new
285  for (auto iOldToNew : oldToNew) {
286  if (iOldToNew > 0) {
287  refs.push_back(reco::PFCandidateRef(newpf, iOldToNew - 1));
288  } else {
289  refs.push_back(reco::PFCandidateRef(badpf, -iOldToNew - 1));
290  }
291  }
292  filler.insert(pfcandidates, refs.begin(), refs.end());
293  // new good to old
294  refs.clear();
295  for (int i : newToOld) {
296  refs.push_back(reco::PFCandidateRef(pfcandidates, i));
297  }
298  filler.insert(newpf, refs.begin(), refs.end());
299  // new bad to old
300  refs.clear();
301  for (int i : badToOld) {
302  refs.push_back(reco::PFCandidateRef(pfcandidates, i));
303  }
304  filler.insert(badpf, refs.begin(), refs.end());
305  // done
306  filler.fill();
307  iEvent.put(std::move(pf2pf));
308 }
DetId getClosestCell(const GlobalPoint &r) const override
std::vector< HEChannel > badChHE_
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
Definition: Point3D.h:10
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:224
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool getData(T &iHolder) const
Definition: EventSetup.h:122
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > calogeomTokenEvent_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
std::vector< HFChannel > badChHF_
edm::EDGetTokenT< reco::PFCandidateCollection > pfcandidates_
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)

Member Data Documentation

◆ badChHE_

std::vector<HEChannel> PFCandidateRecalibrator::badChHE_
private

Definition at line 73 of file PFCandidateRecalibrator.cc.

Referenced by beginRun(), and produce().

◆ badChHF_

std::vector<HFChannel> PFCandidateRecalibrator::badChHF_
private

Definition at line 74 of file PFCandidateRecalibrator.cc.

Referenced by beginRun(), and produce().

◆ buggedCondToken_

const edm::ESGetToken<HcalRespCorrs, HcalRespCorrsRcd> PFCandidateRecalibrator::buggedCondToken_
private

Definition at line 69 of file PFCandidateRecalibrator.cc.

Referenced by beginRun().

◆ calogeomTokenEvent_

const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> PFCandidateRecalibrator::calogeomTokenEvent_
private

Definition at line 71 of file PFCandidateRecalibrator.cc.

Referenced by produce().

◆ calogeomTokenRun_

const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> PFCandidateRecalibrator::calogeomTokenRun_
private

Definition at line 70 of file PFCandidateRecalibrator.cc.

Referenced by beginRun().

◆ gtCondToken_

const edm::ESGetToken<HcalDbService, HcalDbRecord> PFCandidateRecalibrator::gtCondToken_
private

Definition at line 67 of file PFCandidateRecalibrator.cc.

Referenced by beginRun().

◆ hcalDbWatcher_

edm::ESWatcher<HcalRecNumberingRecord> PFCandidateRecalibrator::hcalDbWatcher_
private

Definition at line 62 of file PFCandidateRecalibrator.cc.

Referenced by beginRun().

◆ hcalRCWatcher_

edm::ESWatcher<HcalRespCorrsRcd> PFCandidateRecalibrator::hcalRCWatcher_
private

Definition at line 63 of file PFCandidateRecalibrator.cc.

Referenced by beginRun().

◆ htopoToken_

const edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> PFCandidateRecalibrator::htopoToken_
private

Definition at line 68 of file PFCandidateRecalibrator.cc.

Referenced by beginRun().

◆ longFibreThr_

float PFCandidateRecalibrator::longFibreThr_
private

Definition at line 77 of file PFCandidateRecalibrator.cc.

Referenced by produce().

◆ pfcandidates_

edm::EDGetTokenT<reco::PFCandidateCollection> PFCandidateRecalibrator::pfcandidates_
private

Definition at line 65 of file PFCandidateRecalibrator.cc.

Referenced by produce().

◆ shortFibreThr_

float PFCandidateRecalibrator::shortFibreThr_
private

Definition at line 76 of file PFCandidateRecalibrator.cc.

Referenced by produce().