CMS 3D CMS Logo

AntiElectronDeadECAL.cc
Go to the documentation of this file.
2 
15 
17  : minStatus_(cfg.getParameter<uint32_t>("minStatus")),
18  dR2_(std::pow(cfg.getParameter<double>("dR"), 2)),
19  extrapolateToECalEntrance_(cfg.getParameter<bool>("extrapolateToECalEntrance")),
20  verbosity_(cfg.getParameter<int>("verbosity")),
21  channelStatusToken_(cc.esConsumes()),
22  caloGeometryToken_(cc.esConsumes()),
23  ttMapToken_(cc.esConsumes()),
24  positionAtECalEntrance_(PositionAtECalEntranceComputer(cc)),
25  isFirstEvent_(true) {}
26 
28 
30  updateBadTowers(es);
32 }
33 
34 namespace {
35  template <class Id>
36  void loopXtals(std::map<uint32_t, unsigned>& nBadCrystals,
37  std::map<uint32_t, unsigned>& maxStatus,
38  std::map<uint32_t, double>& sumEta,
39  std::map<uint32_t, double>& sumPhi,
40  const EcalChannelStatus* channelStatus,
41  const CaloGeometry* caloGeometry,
42  const EcalTrigTowerConstituentsMap* ttMap,
43  unsigned minStatus,
44  const uint16_t statusMask) {
45  // NOTE: modified version of SUSY CAF code
46  // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc
47  for (int i = 0; i < Id::kSizeForDenseIndexing; ++i) {
48  Id id = Id::unhashIndex(i);
49  if (id == Id(0))
50  continue;
51  EcalChannelStatusMap::const_iterator it = channelStatus->getMap().find(id.rawId());
52  unsigned status = (it == channelStatus->end()) ? 0 : (it->getStatusCode() & statusMask);
53  if (status >= minStatus) {
54  const GlobalPoint& point = caloGeometry->getPosition(id);
55  uint32_t key = ttMap->towerOf(id);
56  maxStatus[key] = std::max(status, maxStatus[key]);
57  ++nBadCrystals[key];
58  sumEta[key] += point.eta();
59  sumPhi[key] += point.phi();
60  }
61  }
62  }
63 } // namespace
64 
66  // NOTE: modified version of SUSY CAF code
67  // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc
68 
71  return;
72 
73  auto const& channelStatus = es.getData(channelStatusToken_);
74  auto const& caloGeometry = es.getData(caloGeometryToken_);
75  auto const& ttMap = es.getData(ttMapToken_);
76 
77  std::map<uint32_t, unsigned> nBadCrystals, maxStatus;
78  std::map<uint32_t, double> sumEta, sumPhi;
79 
80  loopXtals<EBDetId>(
81  nBadCrystals, maxStatus, sumEta, sumPhi, &channelStatus, &caloGeometry, &ttMap, minStatus_, statusMask_);
82  loopXtals<EEDetId>(
83  nBadCrystals, maxStatus, sumEta, sumPhi, &channelStatus, &caloGeometry, &ttMap, minStatus_, statusMask_);
84 
85  badTowers_.clear();
86  for (auto it : nBadCrystals) {
87  uint32_t key = it.first;
88  badTowers_.push_back(TowerInfo(key, it.second, maxStatus[key], sumEta[key] / it.second, sumPhi[key] / it.second));
89  }
90 
91  isFirstEvent_ = false;
92 }
93 
95  bool isNearBadTower = false;
96  double tau_eta = tau->eta();
97  double tau_phi = tau->phi();
98  const reco::Candidate* leadChargedHadron = nullptr;
100  const reco::PFTau* pfTau = dynamic_cast<const reco::PFTau*>(tau);
101  if (pfTau != nullptr) {
102  leadChargedHadron = pfTau->leadChargedHadrCand().isNonnull() ? pfTau->leadChargedHadrCand().get() : nullptr;
103  } else {
104  const pat::Tau* patTau = dynamic_cast<const pat::Tau*>(tau);
105  if (patTau != nullptr) {
106  leadChargedHadron = patTau->leadChargedHadrCand().isNonnull() ? patTau->leadChargedHadrCand().get() : nullptr;
107  }
108  }
109  }
110  if (leadChargedHadron != nullptr) {
111  bool success = false;
112  reco::Candidate::Point positionAtECalEntrance = positionAtECalEntrance_(leadChargedHadron, success);
113  if (success) {
114  tau_eta = positionAtECalEntrance.eta();
115  tau_phi = positionAtECalEntrance.phi();
116  }
117  }
118  if (verbosity_) {
119  edm::LogPrint("TauAgainstEleDeadECAL") << "<AntiElectronDeadECal::operator()>:";
120  edm::LogPrint("TauAgainstEleDeadECAL") << " #badTowers = " << badTowers_.size();
121  if (leadChargedHadron != nullptr) {
122  edm::LogPrint("TauAgainstEleDeadECAL")
123  << " leadChargedHadron (" << leadChargedHadron->pdgId() << "): Pt = " << leadChargedHadron->pt()
124  << ", eta at ECAL (vtx) = " << tau_eta << " (" << leadChargedHadron->eta() << ")"
125  << ", phi at ECAL (vtx) = " << tau_phi << " (" << leadChargedHadron->phi() << ")";
126  } else {
127  edm::LogPrint("TauAgainstEleDeadECAL")
128  << " tau: Pt = " << tau->pt() << ", eta at vtx = " << tau_eta << ", phi at vtx = " << tau_phi;
129  }
130  }
131  for (auto const& badTower : badTowers_) {
132  if (deltaR2(badTower.eta_, badTower.phi_, tau_eta, tau_phi) < dR2_) {
133  if (verbosity_) {
134  edm::LogPrint("TauAgainstEleDeadECAL")
135  << " matches badTower: eta = " << badTower.eta_ << ", phi = " << badTower.phi_;
136  }
137  isNearBadTower = true;
138  break;
139  }
140  }
141  return isNearBadTower;
142 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
PositionAtECalEntranceComputer positionAtECalEntrance_
edm::ESWatcher< CaloGeometryRecord > caloGeometryWatcher_
void beginEvent(const edm::EventSetup &)
const edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > ttMapToken_
virtual double pt() const =0
transverse momentum
const CandidatePtr & leadChargedHadrCand() const
Definition: PFTau.cc:63
const bool extrapolateToECalEntrance_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
edm::ESWatcher< IdealGeometryRecord > idealGeometryWatcher_
const edm::ESGetToken< EcalChannelStatus, EcalChannelStatusRcd > channelStatusToken_
void beginEvent(const edm::EventSetup &)
EcalTrigTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
std::vector< TowerInfo > badTowers_
edm::ESWatcher< EcalChannelStatusRcd > channelStatusWatcher_
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
bool operator()(const reco::Candidate *tau) const
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
void updateBadTowers(const edm::EventSetup &)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
const reco::CandidatePtr leadChargedHadrCand() const
Log< level::Warning, true > LogPrint
Analysis-level tau class.
Definition: Tau.h:53
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
const_iterator find(uint32_t rawId) const
AntiElectronDeadECAL(const edm::ParameterSet &, edm::ConsumesCollector &&)
virtual int pdgId() const =0
PDG identifier.
std::vector< Item >::const_iterator const_iterator
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
static const uint16_t statusMask_
math::XYZPoint Point
point in the space
Definition: Candidate.h:40
const_iterator end() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity