CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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_
 
edm::ESWatcher
< HcalRecNumberingRecord
hcalDbWatcher_
 
edm::ESWatcher< HcalRespCorrsRcdhcalRCWatcher_
 
float longFibreThr_
 
edm::EDGetTokenT
< reco::PFCandidateCollection
pfcandidates_
 
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 ( const edm::ParameterSet iConfig)

Definition at line 74 of file PFCandidateRecalibrator.cc.

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

Definition at line 53 of file PFCandidateRecalibrator.cc.

53 {};

Member Function Documentation

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

Definition at line 83 of file PFCandidateRecalibrator.cc.

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

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

Definition at line 142 of file PFCandidateRecalibrator.cc.

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

Definition at line 309 of file PFCandidateRecalibrator.cc.

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

309  {
311 
312  desc.add<edm::InputTag>("pfcandidates", edm::InputTag("particleFlow"));
313  desc.add<double>("shortFibreThr", 1.4);
314  desc.add<double>("longFibreThr", 1.4);
315 
316  descriptions.add("pfCandidateRecalibrator", desc);
317 }
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 144 of file PFCandidateRecalibrator.cc.

References funct::abs(), badChHE_, badChHF_, filterCSVwithJSON::copy, reco::deltaR2(), edm::helper::Filler< Map >::fill(), 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(), pfcandidates_, edm::ESHandle< class >::product(), edm::Event::put(), and shortFibreThr_.

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

Member Data Documentation

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

Definition at line 67 of file PFCandidateRecalibrator.cc.

Referenced by beginRun(), and produce().

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

Definition at line 68 of file PFCandidateRecalibrator.cc.

Referenced by beginRun(), and produce().

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

Definition at line 62 of file PFCandidateRecalibrator.cc.

Referenced by beginRun().

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

Definition at line 63 of file PFCandidateRecalibrator.cc.

Referenced by beginRun().

float PFCandidateRecalibrator::longFibreThr_
private

Definition at line 71 of file PFCandidateRecalibrator.cc.

Referenced by produce().

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

Definition at line 65 of file PFCandidateRecalibrator.cc.

Referenced by produce().

float PFCandidateRecalibrator::shortFibreThr_
private

Definition at line 70 of file PFCandidateRecalibrator.cc.

Referenced by produce().