CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFRecoTauDiscriminationAgainstElectronDeadECAL.cc
Go to the documentation of this file.
1 
32 
33 #include <TMath.h>
34 
35 using namespace reco;
36 
38 {
39  public:
42  moduleLabel_(cfg.getParameter<std::string>("@module_label")),
43  isFirstEvent_(true)
44  {
45  minStatus_ = cfg.getParameter<uint32_t>("minStatus");
46  dR_ = cfg.getParameter<double>("dR");
47  }
49 
50  void beginEvent(const edm::Event& evt, const edm::EventSetup& es)
51  {
52  updateBadTowers(es);
53  }
54 
55  double discriminate(const PFTauRef& pfTau)
56  {
57  //std::cout << "<PFRecoTauDiscriminationAgainstElectronDeadECAL::discriminate>:" << std::endl;
58  //std::cout << " moduleLabel = " << moduleLabel_ << std::endl;
59  //std::cout << " #badTowers = " << badTowers_.size() << std::endl;
60  double discriminator = 1.;
61  for ( std::vector<towerInfo>::const_iterator badTower = badTowers_.begin();
62  badTower != badTowers_.end(); ++badTower ) {
63  if ( deltaR(badTower->eta_, badTower->phi_, pfTau->eta(), pfTau->phi()) < dR_ ) discriminator = 0.;
64  }
65  //std::cout << "--> discriminator = " << discriminator << std::endl;
66  return discriminator;
67  }
68 
69  private:
71  {
72  // NOTE: modified version of SUSY CAF code
73  // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc
74  const uint32_t channelStatusId = es.get<EcalChannelStatusRcd>().cacheIdentifier();
75  const uint32_t caloGeometryId = es.get<CaloGeometryRecord>().cacheIdentifier();
76  const uint32_t idealGeometryId = es.get<IdealGeometryRecord>().cacheIdentifier();
77 
78  if ( channelStatusId == channelStatusId_cache_ && caloGeometryId == caloGeometryId_cache_ && idealGeometryId == idealGeometryId_cache_ && !isFirstEvent_ ) return;
79 
80  edm::ESHandle<EcalChannelStatus> channelStatus;
81  es.get<EcalChannelStatusRcd>().get(channelStatus);
82  channelStatusId_cache_ = channelStatusId;
83 
84  edm::ESHandle<CaloGeometry> caloGeometry;
85  es.get<CaloGeometryRecord>().get(caloGeometry);
86  caloGeometryId_cache_ = caloGeometryId;
87 
89  es.get<IdealGeometryRecord>().get(ttMap);
90  idealGeometryId_cache_ = idealGeometryId;
91 
92  std::map<uint32_t,unsigned> nBadCrystals, maxStatus;
93  std::map<uint32_t,double> sumEta, sumPhi;
94 
95  loopXtals<EBDetId>(nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product());
96  loopXtals<EEDetId>(nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product());
97 
98  badTowers_.clear();
99  for ( std::map<uint32_t, unsigned>::const_iterator it = nBadCrystals.begin();
100  it != nBadCrystals.end(); ++it ) {
101  uint32_t key = it->first;
102  badTowers_.push_back(towerInfo(key, it->second, maxStatus[key], sumEta[key]/it->second, sumPhi[key]/it->second));
103  }
104 
105  isFirstEvent_ = false;
106  }
107 
108  template <class Id>
109  void loopXtals(std::map<uint32_t, unsigned>& nBadCrystals,
110  std::map<uint32_t, unsigned>& maxStatus,
111  std::map<uint32_t, double>& sumEta,
112  std::map<uint32_t, double>& sumPhi ,
113  const EcalChannelStatus* channelStatus,
114  const CaloGeometry* caloGeometry,
115  const EcalTrigTowerConstituentsMap* ttMap) const
116  {
117  // NOTE: modified version of SUSY CAF code
118  // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc
119  for ( int i = 0; i < Id::kSizeForDenseIndexing; ++i ) {
120  Id id = Id::unhashIndex(i);
121  if ( id == Id(0) ) continue;
122  EcalChannelStatusMap::const_iterator it = channelStatus->getMap().find(id.rawId());
123  unsigned status = ( it == channelStatus->end() ) ?
124  0 : (it->getStatusCode() & statusMask_);
125  if ( status >= minStatus_ ) {
126  const GlobalPoint& point = caloGeometry->getPosition(id);
127  uint32_t key = ttMap->towerOf(id);
128  maxStatus[key] = TMath::Max(status, maxStatus[key]);
129  ++nBadCrystals[key];
130  sumEta[key] += point.eta();
131  sumPhi[key] += point.phi();
132  }
133  }
134  }
135 
136  struct towerInfo
137  {
138  towerInfo(uint32_t id, unsigned nBad, unsigned maxStatus, double eta, double phi)
139  : id_(id),
140  nBad_(nBad),
141  maxStatus_(maxStatus),
142  eta_(eta),
143  phi_(phi)
144  {}
145  uint32_t id_;
146  unsigned nBad_;
147  unsigned maxStatus_;
148  double eta_;
149  double phi_;
150  };
151  typedef ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiE4D<double> > PolarLorentzVector;
152 
153  std::string moduleLabel_;
154  unsigned minStatus_;
155  double dR_;
156 
157  std::vector<towerInfo> badTowers_;
158  static const uint16_t statusMask_ = 0x1F;
159 
164 };
165 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
const self & getMap() const
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiE4D< double > > PolarLorentzVector
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
T eta() const
EcalTrigTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
double deltaR(double eta1, double phi1, double eta2, double phi2)
Definition: deltaR.h:19
const GlobalPoint & getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:68
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
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
const T & get() const
Definition: EventSetup.h:55
std::vector< Item >::const_iterator const_iterator
T const * product() const
Definition: ESHandle.h:62
void beginEvent(const edm::Event &evt, const edm::EventSetup &es)
T eta() const
Definition: PV3DBase.h:75
list key
Definition: combine.py:13
const_iterator find(uint32_t rawId) const
const_iterator end() const
tuple status
Definition: ntuplemaker.py:245
towerInfo(uint32_t id, unsigned nBad, unsigned maxStatus, double eta, double phi)
*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
Definition: DDAxes.h:10