CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
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:133
const edm::EventSetup & c
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > hGeomToken_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
uint16_t *__restrict__ id
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ESGetToken< HcalChannelQuality, HcalChannelQualityRcd > hQualityToken_
int init
Definition: HydjetWrapper.h:64
T y() const
Definition: PV3DBase.h:60
list status
Definition: mps_update.py:107
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
constexpr std::array< uint8_t, layerIndexSize > layer
int iEvent
Definition: GenABIO.cc:224
std::vector< DetId > getAllChannels() const
T z() const
Definition: PV3DBase.h:61
def move
Definition: eostools.py:511
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)
auto const good
min quality of good
void add(std::string const &label, ParameterSetDescription const &psetDescription)
T get() const
Definition: EventSetup.h:88
tuple cout
Definition: gather_cfg.py:144
virtual void init(const EventSetup &c)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
uint32_t getValue() const
T x() const
Definition: PV3DBase.h:59
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283