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  auto thisCell = (barrel ? hbGeom : heGeom)->getGeometry(id);
135  const GlobalPoint& pos = thisCell->getPosition();
136  badAreasRH_.emplace_back(std::move(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
std::vector< reco::PFCluster > badAreasC_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > hGeomToken_
edm::ESGetToken< HcalChannelQuality, HcalChannelQualityRcd > hQualityToken_
int init
Definition: HydjetWrapper.h:66
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
unsigned long long cacheIdentifier() const
const Item * getValues(DetId fId, bool throwOnFail=true) const
int iEvent
Definition: GenABIO.cc:224
T get() const
Definition: EventSetup.h:79
std::vector< DetId > getAllChannels() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ESHandle< HcalChannelQuality > hQuality_
void produce(edm::Event &, const edm::EventSetup &) override
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
PFBadHcalPseudoClusterProducer(const edm::ParameterSet &)
uint32_t getValue() const
Layer
layer definition
Definition: PFLayer.h:29
Definition: DetId.h:17
std::vector< reco::PFRecHit > badAreasRH_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
virtual void init(const EventSetup &c)
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
def move(src, dest)
Definition: eostools.py:511