CMS 3D CMS Logo

PFBadHcalPseudoClusterProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <iostream>
3 #include <memory>
4 
5 // user include files
8 
12 
16 
20 
22 
31 
33 
34 using namespace std;
35 using namespace edm;
36 
37 //
38 // class declaration
39 //
40 
42 public:
45 
46  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
47 
48 private:
49  virtual void init(const EventSetup& c);
50  void produce(edm::Event&, const edm::EventSetup&) override;
51 
52  bool enabled_;
53  bool debug_;
54 
57  unsigned long long cacheId_quality_, cacheId_geom_;
58  std::vector<reco::PFCluster> badAreasC_;
59  std::vector<reco::PFRecHit> badAreasRH_;
60 
63 };
64 
66  : enabled_(ps.getParameter<bool>("enable")),
67  debug_(ps.getUntrackedParameter<bool>("debug", false)),
68  cacheId_quality_(0),
69  cacheId_geom_(0),
70  hQualityToken_(esConsumes(edm::ESInputTag("", "withTopo"))),
71  hGeomToken_(esConsumes()) {
72  produces<std::vector<reco::PFCluster>>();
73  produces<std::vector<reco::PFRecHit>>("hits");
74 }
75 
77 
79  badAreasC_.clear();
80  badAreasRH_.clear();
81 
83  const HcalChannelQuality& chanquality = *hQuality_;
84 
85  hGeom_ = iSetup.getHandle(hGeomToken_);
86  const CaloGeometry& caloGeom = *hGeom_;
89 
90  int statusMask = ((1 << HcalChannelStatus::HcalCellOff) | (1 << HcalChannelStatus::HcalCellMask) |
92  // histogram the number of bad depths at each ieta, iphi
93  std::map<std::pair<int, int>, int> good, bads;
94  std::map<std::pair<int, int>, std::pair<int, HcalSubdetector>> minDepths;
95  for (const DetId& i : chanquality.getAllChannels()) {
96  if (i.det() != DetId::Hcal)
97  continue; // not an hcal cell
98  HcalDetId id = HcalDetId(i);
99  if (id.subdet() != HcalBarrel && id.subdet() != HcalEndcap)
100  continue; // we don't deal with HO and HF here
101  int status = chanquality.getValues(id)->getValue();
102  auto tower = std::make_pair(id.ieta(), id.iphi());
103  if (status & statusMask) {
104  bads[tower]++;
105  if (debug_)
106  std::cout << "Channel " << i() << " (subdet " << id.subdet() << ", zside " << id.zside() << ", ieta "
107  << id.ieta() << ", iphi " << id.iphi() << " depth " << id.depth() << " has status " << status
108  << " masked " << (status & statusMask) << std::endl;
109  } else {
110  good[tower]++;
111  }
112  auto& minD = minDepths[tower];
113  if (minD.second == HcalEmpty || minD.first > id.depth()) {
114  minD.first = id.depth();
115  minD.second = id.subdet();
116  }
117  }
118 
119  const float dummyEnergy = 1e-5; // non-zero, but small (even if it shouldn't ever be used)
120  for (const auto& rec : bads) {
121  int ieta = rec.first.first, iphi = rec.first.second, nbad = rec.second, ngood = good[rec.first];
122  auto minDepth = minDepths[rec.first];
123  bool barrel = minDepth.second == HcalBarrel;
124  HcalDetId id(minDepth.second, ieta, iphi, minDepth.first);
125  bool isBad = (nbad > 0 && nbad >= ngood);
126  if (debug_)
127  std::cout << "At ieta " << id.ieta() << ", iphi " << id.iphi() << " I have " << nbad << " bad depths, " << ngood
128  << " good depths. First depth is in " << (barrel ? "HB" : "HE") << " depth " << minDepth.first << "; "
129  << (isBad ? " MARK BAD" : " ignore") << std::endl;
130  if (!isBad)
131  continue;
133  // make a PF RecHit
134  std::shared_ptr<const CaloCellGeometry> thisCell = (barrel ? hbGeom : heGeom)->getGeometry(id);
135  const GlobalPoint& pos = thisCell->getPosition();
136  badAreasRH_.emplace_back(thisCell, id(), layer, dummyEnergy);
137  // make a PF cluster (but can't add the rechit, as for that I need an edm::Ref)
138  badAreasC_.emplace_back(layer, dummyEnergy, pos.x(), pos.y(), pos.z());
140  }
141 
142  cacheId_quality_ = iSetup.get<HcalChannelQualityRcd>().cacheIdentifier();
143  cacheId_geom_ = iSetup.get<CaloGeometryRecord>().cacheIdentifier();
144 }
145 
146 // ------------ method called to produce the data ------------
148  if (enabled_) {
150  cacheId_geom_ != iSetup.get<CaloGeometryRecord>().cacheIdentifier()) {
151  init(iSetup);
152  }
153  }
154 
155  auto outRH = std::make_unique<std::vector<reco::PFRecHit>>(badAreasRH_);
156  auto rhHandle = iEvent.put(std::move(outRH), "hits");
157 
158  auto outC = std::make_unique<std::vector<reco::PFCluster>>(badAreasC_);
159 
160  // now we go set references
161  for (unsigned int i = 0, n = rhHandle->size(); i < n; ++i) {
162  (*outC)[i].addRecHitFraction(reco::PFRecHitFraction(reco::PFRecHitRef(rhHandle, i), 1.0));
163  }
164 
165  iEvent.put(std::move(outC));
166 }
167 
170  desc.add<bool>("enable", true)
171  ->setComment("activate the module (if false, it doesn't check the DB and produces an empty collection)");
172  desc.addUntracked<bool>("debug", false);
173  descriptions.add("particleFlowBadHcalPseudoCluster", desc);
174 }
175 
176 //define this as a plug-in
ConfigurationDescriptions.h
good
const auto good
min quality of good
Definition: CAHitNtupletGeneratorKernelsImpl.h:760
init
int init
Definition: HydjetWrapper.h:64
PFBadHcalPseudoClusterProducer::hQuality_
edm::ESHandle< HcalChannelQuality > hQuality_
Definition: PFBadHcalPseudoClusterProducer.cc:55
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
edm::ESInputTag
Definition: ESInputTag.h:87
PFBadHcalPseudoClusterProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PFBadHcalPseudoClusterProducer.cc:147
Reference_intrackfit_cff.barrel
list barrel
Definition: Reference_intrackfit_cff.py:37
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
ESHandle.h
reco::PFRecHitFraction
Fraction of a PFRecHit (rechits can be shared between several PFCluster's)
Definition: PFRecHitFraction.h:18
HcalChannelQualityRcd
Definition: HcalChannelQualityRcd.h:8
mps_update.status
status
Definition: mps_update.py:68
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
DetId::Hcal
Definition: DetId.h:28
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
hgcalTowerProducer_cfi.tower
tower
Definition: hgcalTowerProducer_cfi.py:4
PFLayer::HCAL_ENDCAP
Definition: PFLayer.h:37
CaloGeometry::getSubdetectorGeometry
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
EDProducer.h
HcalChannelQuality
Definition: HcalChannelQuality.h:17
PFBadHcalPseudoClusterProducer::badAreasRH_
std::vector< reco::PFRecHit > badAreasRH_
Definition: PFBadHcalPseudoClusterProducer.cc:59
HcalBarrel
Definition: HcalAssistant.h:33
HcalEmpty
Definition: HcalAssistant.h:32
HcalChannelStatus::HcalCellMask
Definition: HcalChannelStatus.h:18
HcalCondObjectContainer::getValues
const Item * getValues(DetId fId, bool throwOnFail=true) const
Definition: HcalCondObjectContainer.h:159
PFBadHcalPseudoClusterProducer::debug_
bool debug_
Definition: PFBadHcalPseudoClusterProducer.cc:53
PFRecHit.h
edm::Ref< PFRecHitCollection >
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
PFBadHcalPseudoClusterProducer::hQualityToken_
edm::ESGetToken< HcalChannelQuality, HcalChannelQualityRcd > hQualityToken_
Definition: PFBadHcalPseudoClusterProducer.cc:61
DetId
Definition: DetId.h:17
MakerMacros.h
PFBadHcalPseudoClusterProducer::cacheId_quality_
unsigned long long cacheId_quality_
Definition: PFBadHcalPseudoClusterProducer.cc:57
CaloGeometry
Definition: CaloGeometry.h:21
HcalChannelStatus::HcalCellOff
Definition: HcalChannelStatus.h:17
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
PFBadHcalPseudoClusterProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PFBadHcalPseudoClusterProducer.cc:168
PFBadHcalPseudoClusterProducer::init
virtual void init(const EventSetup &c)
Definition: PFBadHcalPseudoClusterProducer.cc:78
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
PFLayer::HCAL_BARREL1
Definition: PFLayer.h:35
edm::ESHandle< HcalChannelQuality >
PFCluster.h
reco::CaloCluster::badHcalMarker
Definition: CaloCluster.h:50
PFBadHcalPseudoClusterProducer::cacheId_geom_
unsigned long long cacheId_geom_
Definition: PFBadHcalPseudoClusterProducer.cc:57
PFBadHcalPseudoClusterProducer::enabled_
bool enabled_
Definition: PFBadHcalPseudoClusterProducer.cc:52
Point3DBase< float, GlobalTag >
ParameterSetDescription.h
PFBadHcalPseudoClusterProducer::hGeom_
edm::ESHandle< CaloGeometry > hGeom_
Definition: PFBadHcalPseudoClusterProducer.cc:56
CaloGeometryRecord.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
PFLayer::Layer
Layer
layer definition
Definition: PFLayer.h:29
HcalChannelStatus::getValue
uint32_t getValue() const
Definition: HcalChannelStatus.h:60
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
CaloSubdetectorGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
HcalDetId.h
HcalCondObjectContainer::getAllChannels
std::vector< DetId > getAllChannels() const
Definition: HcalCondObjectContainer.h:312
PFBadHcalPseudoClusterProducer::badAreasC_
std::vector< reco::PFCluster > badAreasC_
Definition: PFBadHcalPseudoClusterProducer.cc:58
HcalDetId
Definition: HcalDetId.h:12
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
HcalCondObjectContainer.h
HcalChannelStatus.h
edm::ESGetToken< HcalChannelQuality, HcalChannelQualityRcd >
HcalChannelQualityRcd.h
PFRecHitFraction.h
HcalChannelQuality.h
HcalTopology.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
PFBadHcalPseudoClusterProducer::~PFBadHcalPseudoClusterProducer
~PFBadHcalPseudoClusterProducer() override
Definition: PFBadHcalPseudoClusterProducer.cc:76
HcalChannelStatus::HcalCellDead
Definition: HcalChannelStatus.h:20
HcalEndcap
Definition: HcalAssistant.h:34
Frameworkfwd.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
PFBadHcalPseudoClusterProducer::PFBadHcalPseudoClusterProducer
PFBadHcalPseudoClusterProducer(const edm::ParameterSet &)
Definition: PFBadHcalPseudoClusterProducer.cc:65
CaloGeometry.h
EventSetup.h
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
PFBadHcalPseudoClusterProducer::hGeomToken_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > hGeomToken_
Definition: PFBadHcalPseudoClusterProducer.cc:62
edm::eventsetup::EventSetupRecord::cacheIdentifier
unsigned long long cacheIdentifier() const
Definition: EventSetupRecord.h:187
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
PFBadHcalPseudoClusterProducer
Definition: PFBadHcalPseudoClusterProducer.cc:41
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37