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
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
unsigned long long cacheIdentifier() const
std::vector< reco::PFCluster > badAreasC_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
int init
Definition: HydjetWrapper.h:64
T y() const
Definition: PV3DBase.h:60
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const Item * getValues(DetId fId, bool throwOnFail=true) const
CaloGeometry const * getGeometry()
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< DetId > getAllChannels() const
T z() const
Definition: PV3DBase.h:61
edm::ESHandle< HcalChannelQuality > hQuality_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void produce(edm::Event &, const edm::EventSetup &) override
PFBadHcalPseudoClusterProducer(const edm::ParameterSet &)
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.
T get() const
Definition: EventSetup.h:73
virtual void init(const EventSetup &c)
uint32_t getValue() const
T x() const
Definition: PV3DBase.h:59
def move(src, dest)
Definition: eostools.py:511