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 };
61 
63  : enabled_(ps.getParameter<bool>("enable")),
64  debug_(ps.getUntrackedParameter<bool>("debug", false)),
65  cacheId_quality_(0),
66  cacheId_geom_(0) {
67  produces<std::vector<reco::PFCluster>>();
68  produces<std::vector<reco::PFRecHit>>("hits");
69 }
70 
72 
74  badAreasC_.clear();
75  badAreasRH_.clear();
76 
78  iSetup.get<HcalChannelQualityRcd>().get("withTopo", hQuality_);
79  const HcalChannelQuality& chanquality = *hQuality_;
80 
82  iSetup.get<CaloGeometryRecord>().get(hGeom_);
83  const CaloGeometry& caloGeom = *hGeom_;
86 
87  int statusMask = ((1 << HcalChannelStatus::HcalCellOff) | (1 << HcalChannelStatus::HcalCellMask) |
89  // histogram the number of bad depths at each ieta, iphi
90  std::map<std::pair<int, int>, int> good, bads;
91  std::map<std::pair<int, int>, std::pair<int, HcalSubdetector>> minDepths;
92  for (const DetId& i : chanquality.getAllChannels()) {
93  if (i.det() != DetId::Hcal)
94  continue; // not an hcal cell
95  HcalDetId id = HcalDetId(i);
96  if (id.subdet() != HcalBarrel && id.subdet() != HcalEndcap)
97  continue; // we don't deal with HO and HF here
98  int status = chanquality.getValues(id)->getValue();
99  auto tower = std::make_pair(id.ieta(), id.iphi());
100  if (status & statusMask) {
101  bads[tower]++;
102  if (debug_)
103  std::cout << "Channel " << i() << " (subdet " << id.subdet() << ", zside " << id.zside() << ", ieta "
104  << id.ieta() << ", iphi " << id.iphi() << " depth " << id.depth() << " has status " << status
105  << " masked " << (status & statusMask) << std::endl;
106  } else {
107  good[tower]++;
108  }
109  auto& minD = minDepths[tower];
110  if (minD.second == HcalEmpty || minD.first > id.depth()) {
111  minD.first = id.depth();
112  minD.second = id.subdet();
113  }
114  }
115 
116  const float dummyEnergy = 1e-5; // non-zero, but small (even if it shouldn't ever be used)
117  for (const auto& rec : bads) {
118  int ieta = rec.first.first, iphi = rec.first.second, nbad = rec.second, ngood = good[rec.first];
119  auto minDepth = minDepths[rec.first];
120  bool barrel = minDepth.second == HcalBarrel;
121  HcalDetId id(minDepth.second, ieta, iphi, minDepth.first);
122  bool isBad = (nbad > 0 && nbad >= ngood);
123  if (debug_)
124  std::cout << "At ieta " << id.ieta() << ", iphi " << id.iphi() << " I have " << nbad << " bad depths, " << ngood
125  << " good depths. First depth is in " << (barrel ? "HB" : "HE") << " depth " << minDepth.first << "; "
126  << (isBad ? " MARK BAD" : " ignore") << std::endl;
127  if (!isBad)
128  continue;
130  // make a PF RecHit
131  std::shared_ptr<const CaloCellGeometry> thisCell = (barrel ? hbGeom : heGeom)->getGeometry(id);
132  const GlobalPoint& pos = thisCell->getPosition();
133  badAreasRH_.emplace_back(thisCell, id(), layer, dummyEnergy);
134  // make a PF cluster (but can't add the rechit, as for that I need an edm::Ref)
135  badAreasC_.emplace_back(layer, dummyEnergy, pos.x(), pos.y(), pos.z());
137  }
138 
139  cacheId_quality_ = iSetup.get<HcalChannelQualityRcd>().cacheIdentifier();
140  cacheId_geom_ = iSetup.get<CaloGeometryRecord>().cacheIdentifier();
141 }
142 
143 // ------------ method called to produce the data ------------
145  if (enabled_) {
147  cacheId_geom_ != iSetup.get<CaloGeometryRecord>().cacheIdentifier()) {
148  init(iSetup);
149  }
150  }
151 
152  auto outRH = std::make_unique<std::vector<reco::PFRecHit>>(badAreasRH_);
153  auto rhHandle = iEvent.put(std::move(outRH), "hits");
154 
155  auto outC = std::make_unique<std::vector<reco::PFCluster>>(badAreasC_);
156 
157  // now we go set references
158  for (unsigned int i = 0, n = rhHandle->size(); i < n; ++i) {
159  (*outC)[i].addRecHitFraction(reco::PFRecHitFraction(reco::PFRecHitRef(rhHandle, i), 1.0));
160  }
161 
162  iEvent.put(std::move(outC));
163 }
164 
167  desc.add<bool>("enable", false)
168  ->setComment("activate the module (if false, it doesn't check the DB and produces an empty collection)");
169  desc.addUntracked<bool>("debug", false);
170  descriptions.add("particleFlowBadHcalPseudoCluster", desc);
171 }
172 
173 //define this as a plug-in
ConfigurationDescriptions.h
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
PFBadHcalPseudoClusterProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PFBadHcalPseudoClusterProducer.cc:144
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:69
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
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:165
PFBadHcalPseudoClusterProducer::init
virtual void init(const EventSetup &c)
Definition: PFBadHcalPseudoClusterProducer.cc:73
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::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
HcalCondObjectContainer.h
get
#define get
HcalChannelStatus.h
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:71
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:62
CaloGeometry.h
EventSetup.h
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
edm::eventsetup::EventSetupRecord::cacheIdentifier
unsigned long long cacheIdentifier() const
Definition: EventSetupRecord.h:187
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::Event
Definition: Event.h:73
PFBadHcalPseudoClusterProducer
Definition: PFBadHcalPseudoClusterProducer.cc:41
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37