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
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

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_
 
edm::ESWatcher< HcalRecNumberingRecordhcalDbWatcher_
 
edm::ESWatcher< HcalRespCorrsRcdhcalRCWatcher_
 
float longFibreThr_
 
edm::EDGetTokenT< reco::PFCandidateCollectionpfcandidates_
 
float shortFibreThr_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 48 of file PFCandidateRecalibrator.cc.

Constructor & Destructor Documentation

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

Definition at line 72 of file PFCandidateRecalibrator.cc.

73  : pfcandidates_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfcandidates"))),
74  shortFibreThr_(iConfig.getParameter<double>("shortFibreThr")),
75  longFibreThr_(iConfig.getParameter<double>("longFibreThr")) {
76  produces<reco::PFCandidateCollection>();
77  produces<reco::PFCandidateCollection>("discarded");
78  produces<edm::ValueMap<reco::PFCandidateRef>>();
79 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::PFCandidateCollection > pfcandidates_
PFCandidateRecalibrator::~PFCandidateRecalibrator ( )
inlineoverride

Definition at line 51 of file PFCandidateRecalibrator.cc.

References Ecal2004TBTDCRanges_v1_cff::endRun, and fillDescriptions().

51 {};

Member Function Documentation

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

Definition at line 81 of file PFCandidateRecalibrator.cc.

References funct::abs(), badChHE_, badChHF_, edm::ESWatcher< T >::check(), HcalDetId::depth(), PV3DBase< T, PVType, FrameType >::eta(), f, edm::EventSetup::get(), HcalDbService::getHcalRespCorr(), HcalGeometry::getPosition(), CaloGeometry::getSubdetectorGeometry(), HcalGeometry::getValidDetIds(), HcalRespCorr::getValue(), DetId::Hcal, hcalDbWatcher_, HcalEndcap, HcalForward, hcalRCWatcher_, HcalDetId::ieta(), HcalDetId::iphi(), PV3DBase< T, PVType, FrameType >::phi(), edm::ESHandle< T >::product(), particleFlowDisplacedVertex_cfi::ratio, and HcalCondObjectContainerBase::setTopo().

81  {
82  if (hcalDbWatcher_.check(iSetup) || hcalRCWatcher_.check(iSetup)) {
83  //Get Calib Constants from current GT
85  iSetup.get<HcalDbRecord>().get(gtCond);
86 
87  //Get Calib Constants from bugged tag
89  iSetup.get<HcalRecNumberingRecord>().get(htopo);
90  const HcalTopology* theHBHETopology = htopo.product();
91 
93  iSetup.get<HcalRespCorrsRcd>().get("bugged", buggedCond);
94  HcalRespCorrs buggedRespCorrs(*buggedCond.product());
95  buggedRespCorrs.setTopo(theHBHETopology);
96 
97  //access calogeometry
99  iSetup.get<CaloGeometryRecord>().get(calogeom);
100  const CaloGeometry* cgeo = calogeom.product();
101  const HcalGeometry* hgeom =
102  static_cast<const HcalGeometry*>(cgeo->getSubdetectorGeometry(DetId::Hcal, HcalForward));
103 
104  //reset the bad channel containers
105  badChHE_.clear();
106  badChHF_.clear();
107 
108  //fill bad cells HE (use eta, phi)
109  const std::vector<DetId>& cellsHE = hgeom->getValidDetIds(DetId::Detector::Hcal, HcalEndcap);
110  for (auto id : cellsHE) {
111  float currentRespCorr = gtCond->getHcalRespCorr(id)->getValue();
112  float buggedRespCorr = buggedRespCorrs.getValues(id)->getValue();
113  if (buggedRespCorr == 0.)
114  continue;
115 
116  float ratio = currentRespCorr / buggedRespCorr;
117  if (std::abs(ratio - 1.f) > 0.001) {
118  GlobalPoint pos = hgeom->getPosition(id);
119  badChHE_.push_back(HEChannel(pos.eta(), pos.phi(), ratio));
120  }
121  }
122 
123  //fill bad cells HF (use ieta, iphi)
124  auto const& cellsHF = hgeom->getValidDetIds(DetId::Detector::Hcal, HcalForward);
125  for (auto id : cellsHF) {
126  float currentRespCorr = gtCond->getHcalRespCorr(id)->getValue();
127  float buggedRespCorr = buggedRespCorrs.getValues(id)->getValue();
128  if (buggedRespCorr == 0.)
129  continue;
130 
131  float ratio = currentRespCorr / buggedRespCorr;
132  if (std::abs(ratio - 1.f) > 0.001) {
133  HcalDetId dummyId(id);
134  badChHF_.push_back(HFChannel(dummyId.ieta(), dummyId.iphi(), dummyId.depth(), ratio));
135  }
136  }
137  }
138 }
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
edm::ESWatcher< HcalRecNumberingRecord > hcalDbWatcher_
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:75
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
std::vector< HEChannel > badChHE_
const HcalRespCorr * getHcalRespCorr(const HcalGenericDetId &fId) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
GlobalPoint getPosition(const DetId &id) const
edm::ESWatcher< HcalRespCorrsRcd > hcalRCWatcher_
std::vector< HFChannel > badChHF_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
T eta() const
Definition: PV3DBase.h:73
float getValue() const
Definition: HcalRespCorr.h:19
T const * product() const
Definition: ESHandle.h:86
void setTopo(const HcalTopology *topo)
void PFCandidateRecalibrator::endRun ( const edm::Run iRun,
edm::EventSetup const &  iSetup 
)
overrideprivate

Definition at line 140 of file PFCandidateRecalibrator.cc.

140 {}
void PFCandidateRecalibrator::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 307 of file PFCandidateRecalibrator.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), DEFINE_FWK_MODULE, and HLT_2018_cff::InputTag.

307  {
309 
310  desc.add<edm::InputTag>("pfcandidates", edm::InputTag("particleFlow"));
311  desc.add<double>("shortFibreThr", 1.4);
312  desc.add<double>("longFibreThr", 1.4);
313 
314  descriptions.add("pfCandidateRecalibrator", desc);
315 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void PFCandidateRecalibrator::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 142 of file PFCandidateRecalibrator.cc.

References funct::abs(), badChHE_, badChHF_, filterCSVwithJSON::copy, reco::deltaR2(), edm::helper::Filler< Map >::fill(), trigObjTnPSource_cfi::filler, edm::EventSetup::get(), edm::Event::getByToken(), HcalGeometry::getClosestCell(), CaloGeometry::getSubdetectorGeometry(), DetId::Hcal, HcalForward, mps_fire::i, edm::helper::Filler< Map >::insert(), LogDebug, longFibreThr_, eostools::move(), packedPFCandidateRefMixer_cfi::pf, packedPFCandidateRefMixer_cfi::pf2pf, OniaPhotonConversionProducer_cfi::pfcandidates, pfcandidates_, edm::ESHandle< T >::product(), edm::Event::put(), and shortFibreThr_.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

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

Member Data Documentation

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

Definition at line 65 of file PFCandidateRecalibrator.cc.

Referenced by beginRun(), and produce().

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

Definition at line 66 of file PFCandidateRecalibrator.cc.

Referenced by beginRun(), and produce().

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

Definition at line 60 of file PFCandidateRecalibrator.cc.

Referenced by beginRun().

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

Definition at line 61 of file PFCandidateRecalibrator.cc.

Referenced by beginRun().

float PFCandidateRecalibrator::longFibreThr_
private

Definition at line 69 of file PFCandidateRecalibrator.cc.

Referenced by produce().

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

Definition at line 63 of file PFCandidateRecalibrator.cc.

Referenced by produce().

float PFCandidateRecalibrator::shortFibreThr_
private

Definition at line 68 of file PFCandidateRecalibrator.cc.

Referenced by produce().