44 thresh_Barrel_ = iConfig.
getParameter<
double>(
"thresh_Barrel");
45 thresh_Endcap_ = iConfig.
getParameter<
double>(
"thresh_Endcap");
48 navigation_HF_ = iConfig.
getParameter<
bool>(
"navigation_HF");
49 weight_HFem_ = iConfig.
getParameter<
double>(
"weight_HFem");
50 weight_HFhad_ = iConfig.
getParameter<
double>(
"weight_HFhad");
54 HCAL_Calib_29 = iConfig.
getParameter<
double>(
"HCAL_Calib_29");
55 HF_Calib_29 = iConfig.
getParameter<
double>(
"HF_Calib_29");
57 shortFibre_Cut = iConfig.
getParameter<
double>(
"ShortFibre_Cut");
58 longFibre_Fraction = iConfig.
getParameter<
double>(
"LongFibre_Fraction");
60 longFibre_Cut = iConfig.
getParameter<
double>(
"LongFibre_Cut");
61 shortFibre_Fraction = iConfig.
getParameter<
double>(
"ShortFibre_Fraction");
63 applyLongShortDPG_ = iConfig.
getParameter<
bool>(
"ApplyLongShortDPG");
65 longShortFibre_Cut = iConfig.
getParameter<
double>(
"LongShortFibre_Cut");
66 minShortTiming_Cut = iConfig.
getParameter<
double>(
"MinShortTiming_Cut");
67 maxShortTiming_Cut = iConfig.
getParameter<
double>(
"MaxShortTiming_Cut");
68 minLongTiming_Cut = iConfig.
getParameter<
double>(
"MinLongTiming_Cut");
69 maxLongTiming_Cut = iConfig.
getParameter<
double>(
"MaxLongTiming_Cut");
71 applyTimeDPG_ = iConfig.
getParameter<
bool>(
"ApplyTimeDPG");
72 applyPulseDPG_ = iConfig.
getParameter<
bool>(
"ApplyPulseDPG");
73 HcalMaxAllowedHFLongShortSev_ = iConfig.
getParameter<
int>(
"HcalMaxAllowedHFLongShortSev");
74 HcalMaxAllowedHFDigiTimeSev_ = iConfig.
getParameter<
int>(
"HcalMaxAllowedHFDigiTimeSev");
75 HcalMaxAllowedHFInTimeWindowSev_ = iConfig.
getParameter<
int>(
"HcalMaxAllowedHFInTimeWindowSev");
76 HcalMaxAllowedChannelStatusSev_ = iConfig.
getParameter<
int>(
"HcalMaxAllowedChannelStatusSev");
78 ECAL_Compensate_ = iConfig.
getParameter<
bool>(
"ECAL_Compensate");
79 ECAL_Threshold_ = iConfig.
getParameter<
double>(
"ECAL_Threshold");
80 ECAL_Compensation_ = iConfig.
getParameter<
double>(
"ECAL_Compensation");
81 ECAL_Dead_Code_ = iConfig.
getParameter<
unsigned int>(
"ECAL_Dead_Code");
99 produces<reco::PFRecHitCollection>();
100 produces<reco::PFRecHitCollection>(
"Cleaned");
101 produces<reco::PFRecHitCollection>(
"HFHAD").setBranchAlias(
"HFHADRecHits");
102 produces<reco::PFRecHitCollection>(
"HFEM").setBranchAlias(
"HFEMRecHits");
107 navigator_->beginEvent(iSetup);
126 theHcalTopology = hcalTopology.
product();
128 auto rechits = std::make_unique<std::vector<reco::PFRecHit>>();
129 auto rechitsCleaned = std::make_unique<std::vector<reco::PFRecHit>>();
130 auto HFHADRecHits = std::make_unique<std::vector<reco::PFRecHit>>();
131 auto HFEMRecHits = std::make_unique<std::vector<reco::PFRecHit>>();
143 for (
auto const& ct : *caloTowers) {
150 double energy = ct.hadEnergy();
152 double energyEM = ct.emEnergy();
154 if ((energy + energyEM) < 1
e-9)
158 const std::vector<DetId>&
hits = ct.constituents();
159 const std::vector<DetId>& allConstituents = theTowerConstituentsMap->constituentsOf(ct.id());
161 bool foundHCALConstituent =
false;
165 for (
auto hit : hits) {
167 foundHCALConstituent =
true;
169 if (theHcalTopology->getMergePositionFlag() && detid.
subdet() ==
HcalEndcap) {
170 detid = theHcalTopology->idFront(detid);
173 if (ECAL_Compensate_ && energy > ECAL_Threshold_) {
174 for (
auto allConstituent : allConstituents) {
177 auto chIt = theEcalChStatus->find(allConstituent);
178 unsigned int dbStatus = chIt != theEcalChStatus->end() ? chIt->getStatusCode() : 0;
179 if (dbStatus > ECAL_Dead_Code_)
193 double rescaleFactor = alive > 0. ? 1. + ECAL_Compensation_ * dead / alive : 1.;
205 if (foundHCALConstituent) {
209 if (energy < thresh_Barrel_)
211 if (rescaleFactor > 1.) {
213 pfrhCleaned->
setTime(rescaleFactor);
214 energy *= rescaleFactor;
220 if (energy < thresh_Endcap_)
223 if (HCAL_Calib_ &&
abs(detid.
ieta()) == 29)
224 energy *= HCAL_Calib_29;
225 if (rescaleFactor > 1.) {
226 pfrhCleaned = createHcalRecHit(detid, energy,
PFLayer::HCAL_ENDCAP, hcalEndcapGeometry, ct.id());
227 pfrhCleaned->
setTime(rescaleFactor);
228 energy *= rescaleFactor;
239 double energyemHF = weight_HFem_ * energyEM;
240 double energyhadHF = weight_HFhad_ *
energy;
242 if ((energyemHF + energyhadHF) < thresh_HF_)
246 double longFibre = energyemHF + energyhadHF / 2.;
247 double shortFibre = energyhadHF / 2.;
253 auto theLongHit = hfHandle->
find(theLongDetId);
254 auto theShortHit = hfHandle->
find(theShortDetId);
256 double theLongHitEnergy = 0.;
257 double theShortHitEnergy = 0.;
258 bool flagShortDPG =
false;
259 bool flagLongDPG =
false;
260 bool flagShortTimeDPG =
false;
261 bool flagLongTimeDPG =
false;
262 bool flagShortPulseDPG =
false;
263 bool flagLongPulseDPG =
false;
265 if (theLongHit != hfHandle->
end()) {
266 int theLongFlag = theLongHit->flags();
267 theLongHitEnergy = theLongHit->energy();
269 theLongDetId, theLongFlag & hcalHFLongShortFlagValue_, 0) >
270 HcalMaxAllowedHFLongShortSev_);
272 theLongDetId, theLongFlag & hcalHFInTimeWindowFlagValue_, 0) >
273 HcalMaxAllowedHFInTimeWindowSev_);
275 theLongDetId, theLongFlag & hcalHFDigiTimeFlagValue_, 0) >
276 HcalMaxAllowedHFDigiTimeSev_);
283 if (theShortHit != hfHandle->
end()) {
284 int theShortFlag = theShortHit->flags();
285 theShortHitEnergy = theShortHit->energy();
287 theShortDetId, theShortFlag & hcalHFLongShortFlagValue_, 0) >
288 HcalMaxAllowedHFLongShortSev_);
290 theShortDetId, theShortFlag & hcalHFInTimeWindowFlagValue_, 0) >
291 HcalMaxAllowedHFInTimeWindowSev_);
292 flagShortPulseDPG = applyPulseDPG_ && (hcalSevLvlComputer->
getSeverityLevel(
293 theShortDetId, theShortFlag & hcalHFDigiTimeFlagValue_, 0) >
294 HcalMaxAllowedHFDigiTimeSev_);
301 if (theShortHitEnergy > longShortFibre_Cut &&
302 (theShortHit->time() < minShortTiming_Cut || theShortHit->time() > maxShortTiming_Cut ||
303 flagShortTimeDPG || flagShortPulseDPG)) {
305 pfrhHFHADCleaned = createHcalRecHit(detid, theShortHitEnergy,
PFLayer::HF_HAD, hcalEndcapGeometry, ct.id());
306 pfrhHFHADCleaned->
setTime(theShortHit->time());
319 shortFibre -= theShortHitEnergy;
320 theShortHitEnergy = 0.;
323 if (theLongHitEnergy > longShortFibre_Cut &&
324 (theLongHit->time() < minLongTiming_Cut || theLongHit->time() > maxLongTiming_Cut || flagLongTimeDPG ||
327 pfrhHFEMCleaned = createHcalRecHit(detid, theLongHitEnergy,
PFLayer::HF_EM, hcalEndcapGeometry, ct.id());
328 pfrhHFEMCleaned->
setTime(theLongHit->time());
341 longFibre -= theLongHitEnergy;
342 theLongHitEnergy = 0.;
346 if (theShortHitEnergy > shortFibre_Cut &&
347 (theLongHitEnergy / theShortHitEnergy < longFibre_Fraction || flagShortDPG)) {
351 unsigned theStatusValue = theStatus->
getValue();
352 int theSeverityLevel = hcalSevLvlComputer->
getSeverityLevel(detid, 0, theStatusValue);
355 if (theSeverityLevel <= HcalMaxAllowedChannelStatusSev_) {
358 createHcalRecHit(detid, theShortHitEnergy,
PFLayer::HF_HAD, hcalEndcapGeometry, ct.id());
359 pfrhHFHADCleaned->
setTime(theShortHit->time());
373 shortFibre -= theShortHitEnergy;
374 theShortHitEnergy = 0.;
378 if (theLongHitEnergy > longFibre_Cut &&
379 (theShortHitEnergy / theLongHitEnergy < shortFibre_Fraction || flagLongDPG)) {
383 unsigned theStatusValue = theStatus->
getValue();
385 int theSeverityLevel = hcalSevLvlComputer->
getSeverityLevel(detid, 0, theStatusValue);
388 if (theSeverityLevel <= HcalMaxAllowedChannelStatusSev_) {
390 pfrhHFEMCleaned = createHcalRecHit(detid, theLongHitEnergy,
PFLayer::HF_EM, hcalEndcapGeometry, ct.id());
391 pfrhHFEMCleaned->
setTime(theLongHit->time());
405 longFibre -= theLongHitEnergy;
406 theLongHitEnergy = 0.;
412 if (
abs(ieta) == 29) {
415 if (theLongHitEnergy > shortFibre_Cut / 2.) {
417 createHcalRecHit(detid, theLongHitEnergy,
PFLayer::HF_EM, hcalEndcapGeometry, ct.id());
418 pfrhHFEMCleaned29->
setTime(theLongHit->time());
426 longFibre -= theLongHitEnergy;
427 theLongHitEnergy = 0.;
430 if (theShortHitEnergy > shortFibre_Cut / 2.) {
432 createHcalRecHit(detid, theShortHitEnergy,
PFLayer::HF_HAD, hcalEndcapGeometry, ct.id());
433 pfrhHFHADCleaned29->
setTime(theShortHit->time());
441 shortFibre -= theShortHitEnergy;
442 theShortHitEnergy = 0.;
448 else if (
abs(ieta) == 30) {
449 int ieta29 = ieta > 0 ? 29 : -29;
452 auto theLongHit29 = hfHandle->
find(theLongDetId29);
453 auto theShortHit29 = hfHandle->
find(theShortDetId29);
455 double theLongHitEnergy29 = 0.;
456 double theShortHitEnergy29 = 0.;
457 bool flagShortDPG29 =
false;
458 bool flagLongDPG29 =
false;
459 bool flagShortTimeDPG29 =
false;
460 bool flagLongTimeDPG29 =
false;
461 bool flagShortPulseDPG29 =
false;
462 bool flagLongPulseDPG29 =
false;
464 if (theLongHit29 != hfHandle->
end()) {
465 int theLongFlag29 = theLongHit29->flags();
466 theLongHitEnergy29 = theLongHit29->energy();
467 flagLongDPG29 = applyLongShortDPG_ && (hcalSevLvlComputer->
getSeverityLevel(
468 theLongDetId29, theLongFlag29 & hcalHFLongShortFlagValue_, 0) >
469 HcalMaxAllowedHFLongShortSev_);
472 theLongFlag29 & hcalHFInTimeWindowFlagValue_,
473 0) > HcalMaxAllowedHFInTimeWindowSev_);
474 flagLongPulseDPG29 = applyPulseDPG_ && (hcalSevLvlComputer->
getSeverityLevel(
475 theLongDetId29, theLongFlag29 & hcalHFDigiTimeFlagValue_, 0) >
476 HcalMaxAllowedHFDigiTimeSev_);
483 if (theShortHit29 != hfHandle->
end()) {
484 int theShortFlag29 = theShortHit29->flags();
485 theShortHitEnergy29 = theShortHit29->energy();
487 applyLongShortDPG_ &&
489 theShortDetId29, theShortFlag29 & hcalHFLongShortFlagValue_, 0) > HcalMaxAllowedHFLongShortSev_);
492 theShortFlag29 & hcalHFInTimeWindowFlagValue_,
493 0) > HcalMaxAllowedHFInTimeWindowSev_);
496 (hcalSevLvlComputer->
getSeverityLevel(theShortDetId29, theShortFlag29 & hcalHFDigiTimeFlagValue_, 0) >
497 HcalMaxAllowedHFDigiTimeSev_);
504 if (theLongHitEnergy29 > longShortFibre_Cut &&
505 (theLongHit29->time() < minLongTiming_Cut || theLongHit29->time() > maxLongTiming_Cut ||
506 flagLongTimeDPG29 || flagLongPulseDPG29)) {
509 createHcalRecHit(detid, theLongHitEnergy29,
PFLayer::HF_EM, hcalEndcapGeometry, ct.id());
510 pfrhHFEMCleaned29->
setTime(theLongHit29->time());
523 longFibre -= theLongHitEnergy29;
524 theLongHitEnergy29 = 0;
527 if (theShortHitEnergy29 > longShortFibre_Cut &&
528 (theShortHit29->time() < minShortTiming_Cut || theShortHit29->time() > maxShortTiming_Cut ||
529 flagShortTimeDPG29 || flagShortPulseDPG29)) {
532 createHcalRecHit(detid, theShortHitEnergy29,
PFLayer::HF_HAD, hcalEndcapGeometry, ct.id());
533 pfrhHFHADCleaned29->
setTime(theShortHit29->time());
546 shortFibre -= theShortHitEnergy29;
547 theShortHitEnergy29 = 0;
551 if (theShortHitEnergy29 > shortFibre_Cut &&
552 (theLongHitEnergy29 / theShortHitEnergy29 < 2. * longFibre_Fraction || flagShortDPG29)) {
556 unsigned theStatusValue = theStatus->
getValue();
558 int theSeverityLevel = hcalSevLvlComputer->
getSeverityLevel(detid, 0, theStatusValue);
561 if (theSeverityLevel <= HcalMaxAllowedChannelStatusSev_) {
564 createHcalRecHit(detid, theShortHitEnergy29,
PFLayer::HF_HAD, hcalEndcapGeometry, ct.id());
565 pfrhHFHADCleaned29->
setTime(theShortHit29->time());
579 shortFibre -= theShortHitEnergy29;
580 theShortHitEnergy29 = 0.;
585 if (theLongHitEnergy29 > longFibre_Cut &&
586 (theShortHitEnergy29 / theLongHitEnergy29 < shortFibre_Fraction || flagLongDPG29)) {
589 const HcalChannelStatus* theStatus = theHcalChStatus->getValues(theShortDetId29);
590 unsigned theStatusValue = theStatus->
getValue();
591 int theSeverityLevel = hcalSevLvlComputer->
getSeverityLevel(detid, 0, theStatusValue);
594 if (theSeverityLevel <= HcalMaxAllowedChannelStatusSev_) {
597 createHcalRecHit(detid, theLongHitEnergy29,
PFLayer::HF_EM, hcalEndcapGeometry, ct.id());
598 pfrhHFEMCleaned29->
setTime(theLongHit29->time());
612 longFibre -= theLongHitEnergy29;
613 theLongHitEnergy29 = 0.;
619 if (theLongHitEnergy29 >
std::max(theLongHitEnergy, shortFibre_Cut / 2)) {
621 createHcalRecHit(detid, theLongHitEnergy29,
PFLayer::HF_EM, hcalEndcapGeometry, ct.id());
622 pfrhHFEMCleaned29->
setTime(theLongHit29->time());
630 longFibre -= theLongHitEnergy29;
631 theLongHitEnergy29 = 0.;
634 if (theShortHitEnergy29 >
std::max(theShortHitEnergy, shortFibre_Cut / 2.)) {
636 createHcalRecHit(detid, theShortHitEnergy29,
PFLayer::HF_HAD, hcalEndcapGeometry, ct.id());
637 pfrhHFHADCleaned29->
setTime(theShortHit29->time());
645 shortFibre -= theShortHitEnergy29;
646 theShortHitEnergy29 = 0.;
651 energyhadHF = 2. * shortFibre;
652 energyemHF = longFibre - shortFibre;
657 if (energyemHF < thresh_HF_) {
658 energyhadHF += energyemHF;
663 if (HF_Calib_ &&
abs(detid.
ieta()) <= 32) {
664 energyhadHF *= HF_Calib_29;
665 energyemHF *= HF_Calib_29;
669 if (energyemHF > thresh_HF_ || energyhadHF > thresh_HF_) {
670 pfrhHFEM = createHcalRecHit(detid, energyemHF,
PFLayer::HF_EM, hcalEndcapGeometry, ct.id());
671 pfrhHFHAD = createHcalRecHit(detid, energyhadHF,
PFLayer::HF_HAD, hcalEndcapGeometry, ct.id());
676 LogError(
"PFCTRecHitProducerHCAL") <<
"CaloTower constituent: unknown layer : " << detid.
subdet() << endl;
684 rechitsCleaned->push_back(*pfrhCleaned);
688 HFEMRecHits->push_back(*pfrhHFEM);
692 HFHADRecHits->push_back(*pfrhHFHAD);
695 if (pfrhHFEMCleaned) {
696 rechitsCleaned->push_back(*pfrhHFEMCleaned);
697 delete pfrhHFEMCleaned;
699 if (pfrhHFHADCleaned) {
700 rechitsCleaned->push_back(*pfrhHFHADCleaned);
701 delete pfrhHFHADCleaned;
703 if (pfrhHFEMCleaned29) {
704 rechitsCleaned->push_back(*pfrhHFEMCleaned29);
705 delete pfrhHFEMCleaned29;
707 if (pfrhHFHADCleaned29) {
708 rechitsCleaned->push_back(*pfrhHFHADCleaned29);
709 delete pfrhHFHADCleaned29;
719 for (
unsigned int i = 0;
i <
rechits->size(); ++
i) {
723 if (navigation_HF_) {
726 for (
unsigned int i = 0;
i < HFEMRecHits->size(); ++
i) {
727 navigator_->associateNeighbours(HFEMRecHits->at(
i), HFEMRecHits, refProdEM);
732 for (
unsigned int i = 0;
i < HFHADRecHits->size(); ++
i) {
733 navigator_->associateNeighbours(HFHADRecHits->at(
i), HFHADRecHits, refProdHAD);
751 theHcalChStatus = hcalChStatus.
product();
756 theEcalChStatus = ecalChStatus.
product();
760 theTowerConstituentsMap = cttopo.
product();
768 std::shared_ptr<const CaloCellGeometry> thisCell = geom->
getGeometry(detid);
771 <<
"warning detid " << detid.
rawId() <<
" not found in layer " << layer << endl;
780 thisCell = zp->forPF();
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void beginLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &es) override
HcalSubdetector subdet() const
get the subdetector
bool getByToken(EDGetToken token, Handle< PROD > &result) const
PFCTRecHitProducer(const edm::ParameterSet &)
constexpr uint32_t rawId() const
get the raw id
std::vector< CaloTower >::const_iterator const_iterator
~PFCTRecHitProducer() override
std::vector< PFRecHit > PFRecHitCollection
collection of PFRecHit objects
reco::PFRecHit * createHcalRecHit(const DetId &detid, double energy, PFLayer::Layer layer, const CaloSubdetectorGeometry *geom, const CaloTowerDetId &newDetId)
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
int ieta() const
get the cell ieta
Abs< T >::type abs(const T &t)
void setTime(double time)
RefProd< PROD > getRefBeforePut()
const_iterator end() const
int iphi() const
get the cell iphi
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
int getSeverityLevel(const DetId &myid, const uint32_t &myflag, const uint32_t &mystatus) const
iterator find(key_type k)
uint32_t getValue() const
T const * product() const
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override