CMS 3D CMS Logo

PFRecoTauDiscriminationAgainstElectronDeadECAL.cc
Go to the documentation of this file.
1 
21 
33 
34 #include <TMath.h>
35 
36 using namespace reco;
37 
39 {
40  public:
43  moduleLabel_(cfg.getParameter<std::string>("@module_label")),
44  isFirstEvent_(true)
45  {
46  minStatus_ = cfg.getParameter<uint32_t>("minStatus");
47  dR_ = cfg.getParameter<double>("dR");
48 
49  verbosity_ = cfg.getParameter<int>("verbosity");
50  }
52 
53  void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override
54  {
55  updateBadTowers(es);
56  }
57 
58  double discriminate(const PFTauRef& pfTau) const override
59  {
60  if ( verbosity_ ) {
61  edm::LogPrint("PFTauAgainstEleDeadECAL") << "<PFRecoTauDiscriminationAgainstElectronDeadECAL::discriminate>:" ;
62  edm::LogPrint("PFTauAgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_ ;
63  edm::LogPrint("PFTauAgainstEleDeadECAL") << "#badTowers = " << badTowers_.size() ;
64  edm::LogPrint("PFTauAgainstEleDeadECAL") << "tau: Pt = " << pfTau->pt() << ", eta = " << pfTau->eta() << ", phi = " << pfTau->phi() ;
65  }
66  double discriminator = 1.;
67  for ( std::vector<towerInfo>::const_iterator badTower = badTowers_.begin();
68  badTower != badTowers_.end(); ++badTower ) {
69  if ( deltaR(badTower->eta_, badTower->phi_, pfTau->eta(), pfTau->phi()) < dR_ ) {
70  if ( verbosity_ ) {
71  edm::LogPrint("PFTauAgainstEleDeadECAL") << " matches badTower: eta = " << badTower->eta_ << ", phi = " << badTower->phi_ ;
72  }
73  discriminator = 0.;
74  }
75  }
76  if ( verbosity_ ) {
77  edm::LogPrint("PFTauAgainstEleDeadECAL") << "--> discriminator = " << discriminator ;
78  }
79  return discriminator;
80  }
81 
82  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
83 
84  private:
86  {
87  // NOTE: modified version of SUSY CAF code
88  // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc
89  const uint32_t channelStatusId = es.get<EcalChannelStatusRcd>().cacheIdentifier();
90  const uint32_t caloGeometryId = es.get<CaloGeometryRecord>().cacheIdentifier();
91  const uint32_t idealGeometryId = es.get<IdealGeometryRecord>().cacheIdentifier();
92 
93  if ( !isFirstEvent_ && channelStatusId == channelStatusId_cache_ && caloGeometryId == caloGeometryId_cache_ && idealGeometryId == idealGeometryId_cache_ ) return;
94 
95  edm::ESHandle<EcalChannelStatus> channelStatus;
96  es.get<EcalChannelStatusRcd>().get(channelStatus);
97  channelStatusId_cache_ = channelStatusId;
98 
99  edm::ESHandle<CaloGeometry> caloGeometry;
100  es.get<CaloGeometryRecord>().get(caloGeometry);
101  caloGeometryId_cache_ = caloGeometryId;
102 
104  es.get<IdealGeometryRecord>().get(ttMap);
105  idealGeometryId_cache_ = idealGeometryId;
106 
107  std::map<uint32_t,unsigned> nBadCrystals, maxStatus;
108  std::map<uint32_t,double> sumEta, sumPhi;
109 
110  loopXtals<EBDetId>(nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product());
111  loopXtals<EEDetId>(nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product());
112 
113  badTowers_.clear();
114  for ( std::map<uint32_t, unsigned>::const_iterator it = nBadCrystals.begin();
115  it != nBadCrystals.end(); ++it ) {
116  uint32_t key = it->first;
117  badTowers_.push_back(towerInfo(key, it->second, maxStatus[key], sumEta[key]/it->second, sumPhi[key]/it->second));
118  }
119 
120  isFirstEvent_ = false;
121  }
122 
123  template <class Id>
124  void loopXtals(std::map<uint32_t, unsigned>& nBadCrystals,
125  std::map<uint32_t, unsigned>& maxStatus,
126  std::map<uint32_t, double>& sumEta,
127  std::map<uint32_t, double>& sumPhi ,
128  const EcalChannelStatus* channelStatus,
129  const CaloGeometry* caloGeometry,
130  const EcalTrigTowerConstituentsMap* ttMap) const
131  {
132  // NOTE: modified version of SUSY CAF code
133  // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc
134  for ( int i = 0; i < Id::kSizeForDenseIndexing; ++i ) {
135  Id id = Id::unhashIndex(i);
136  if ( id == Id(0) ) continue;
137  EcalChannelStatusMap::const_iterator it = channelStatus->getMap().find(id.rawId());
138  unsigned status = ( it == channelStatus->end() ) ?
139  0 : (it->getStatusCode() & statusMask_);
140  if ( status >= minStatus_ ) {
141  const GlobalPoint& point = caloGeometry->getPosition(id);
142  uint32_t key = ttMap->towerOf(id);
143  maxStatus[key] = TMath::Max(status, maxStatus[key]);
144  ++nBadCrystals[key];
145  sumEta[key] += point.eta();
146  sumPhi[key] += point.phi();
147  }
148  }
149  }
150 
151  struct towerInfo
152  {
153  towerInfo(uint32_t id, unsigned nBad, unsigned maxStatus, double eta, double phi)
154  : id_(id),
155  nBad_(nBad),
156  maxStatus_(maxStatus),
157  eta_(eta),
158  phi_(phi)
159  {}
160  uint32_t id_;
161  unsigned nBad_;
162  unsigned maxStatus_;
163  double eta_;
164  double phi_;
165  };
166  typedef ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiE4D<double> > PolarLorentzVector;
167 
169  unsigned minStatus_;
170  double dR_;
171 
172  std::vector<towerInfo> badTowers_;
173  static const uint16_t statusMask_ = 0x1F;
174 
179 
181 };
182 
183 void
185  // pfRecoTauDiscriminationAgainstElectronDeadECAL
187  desc.add<int>("verbosity", 0);
188  {
189  edm::ParameterSetDescription pset_Prediscriminants;
190  pset_Prediscriminants.add<std::string>("BooleanOperator", "and");
191  {
193  psd1.add<double>("cut");
194  psd1.add<edm::InputTag>("Producer");
195  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);
196  }
197  {
198  // encountered this at
199  // RecoTauTag/Configuration/python/HPSPFTaus_cff.py
201  psd1.add<double>("cut");
202  psd1.add<edm::InputTag>("Producer");
203  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("decayMode", psd1);
204  }
205  desc.add<edm::ParameterSetDescription>("Prediscriminants", pset_Prediscriminants);
206  }
207  desc.add<double>("dR", 0.08);
208  desc.add<edm::InputTag>("PFTauProducer", edm::InputTag("pfTauProducer"));
209  desc.add<unsigned int>("minStatus", 12);
210  descriptions.add("pfRecoTauDiscriminationAgainstElectronDeadECAL", desc);
211 }
212 
T getParameter(std::string const &) const
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
const self & getMap() const
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiE4D< double > > PolarLorentzVector
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
EcalTrigTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:74
void loopXtals(std::map< uint32_t, unsigned > &nBadCrystals, std::map< uint32_t, unsigned > &maxStatus, std::map< uint32_t, double > &sumEta, std::map< uint32_t, double > &sumPhi, const EcalChannelStatus *channelStatus, const CaloGeometry *caloGeometry, const EcalTrigTowerConstituentsMap *ttMap) const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
T Max(T a, T b)
Definition: MathUtil.h:44
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< Item >::const_iterator const_iterator
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T eta() const
Definition: PV3DBase.h:76
fixed size matrix
T get() const
Definition: EventSetup.h:71
const_iterator find(uint32_t rawId) const
const_iterator end() const
towerInfo(uint32_t id, unsigned nBad, unsigned maxStatus, double eta, double phi)
T const * product() const
Definition: ESHandle.h:86
*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
void beginEvent(const edm::Event &evt, const edm::EventSetup &es) override