CMS 3D CMS Logo

HBHEIsolatedNoiseAlgos.h
Go to the documentation of this file.
1 #ifndef __HBHE_ISOLATED_NOISE_ALGOS_H__
2 #define __HBHE_ISOLATED_NOISE_ALGOS_H__
3 
4 /*
5 Description: Isolation algorithms used to identify anomalous noise in the HB/HE.
6  These algorithms will be used to reflag HB/HE rechits as noise.
7 
8  There are 6 objects defined here:
9  1) ObjectValidatorAbs
10  2) ObjectValidator
11  3) PhysicsTower
12  4) PhysicsTowerOrganizer
13  5) HBHEHitMap
14  6) HBHEHitMapOrganizer
15  See comments below for details.
16 
17 Original Author: John Paul Chou (Brown University)
18  Thursday, September 2, 2010
19 */
20 
21 // system include files
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 // user include files
29 
37 
38 #include <vector>
39 #include <set>
40 #include <map>
41 
42 // forward declarations
43 class HBHERecHit;
44 class EcalRecHit;
45 class HcalChannelQuality;
48 class CaloGeometry;
49 
51 //
52 // ObjectValidator
53 //
54 // determines if an ECAL hit, HCAL hit, or track is valid or not.
55 // Note that various objects need to be passed to the validator before use.
56 // ObjectValidatorAbs provides a base class in case you want to change the
57 // hit/track validation algorithms.
59 
61 public:
63  virtual ~ObjectValidatorAbs() {}
64 
65  virtual bool validHit(const HBHERecHit&) const = 0;
66  virtual bool validHit(const EcalRecHit&) const = 0;
67  virtual bool validTrack(const reco::Track&) const = 0;
68 };
69 
71 public:
72  explicit ObjectValidator(const edm::ParameterSet&);
74  double HESThreshold,
75  double HEDThreshold,
76  double EBThreshold,
77  double EEThreshold,
78  uint32_t HcalAcceptSeverityLevel,
79  uint32_t EcalAcceptSeverityLevel,
82  double MinValidTrackPt,
83  double MinValidTrackPtBarrel,
97  theHcalChStatus_(nullptr),
98  theEcalChStatus_(nullptr),
99  theHcalSevLvlComputer_(nullptr),
100  theEcalSevLvlAlgo_(nullptr),
101  theEBRecHitCollection_(nullptr),
102  theEERecHitCollection_(nullptr) {}
103  ~ObjectValidator() override;
104 
111 
112  bool validHit(const HBHERecHit&) const override;
113  bool validHit(const EcalRecHit&) const override;
114  bool validTrack(const reco::Track&) const override;
115 
116 private:
117  double HBThreshold_; // energy threshold for HB hits
118  double HESThreshold_; // energy threshold for 5-degree (phi) HE hits
119  double HEDThreshold_; // energy threshold for 10-degree (phi) HE hits
120  double EBThreshold_; // energy threshold for EB hits
121  double EEThreshold_; // energy threshold for EE hits
122 
123  uint32_t HcalAcceptSeverityLevel_; // severity level to accept HCAL hits
124  uint32_t EcalAcceptSeverityLevel_; // severity level to accept ECAL hits
125  bool UseHcalRecoveredHits_; // whether or not to use recovered HCAL hits
126  bool UseEcalRecoveredHits_; // whether or not to use recovered HCAL hits
127  bool UseAllCombinedRechits_; // whether to use all "Plan 1" combined rechits
128 
129  double MinValidTrackPt_; // minimum valid track pT
130  double MinValidTrackPtBarrel_; // minimum valid track pT in the Barrel
131  int MinValidTrackNHits_; // minimum number of hits needed for a valid track
132 
133  // for checking the status of ECAL and HCAL channels stored in the DB
136 
137  // calculator of severety level for ECAL and HCAL
140 
141  // needed to determine an ECAL channel's validity
144 };
145 
147 //
148 // PhysicsTower
149 //
150 // basic structure to hold information relevant at the tower level
151 // consists of hcal hits, ecal hits, and tracks
153 
154 struct PhysicsTower {
156  std::set<const HBHERecHit*> hcalhits;
157  std::set<const EcalRecHit*> ecalhits;
158  std::set<const reco::Track*> tracks;
159 };
160 
162 //
163 // PhysicsTowerOrganizer
164 //
165 // Organizers the PhysicsTowers into CaloTower (ieta,iphi) space.
166 // Also provides methods to find a towers nearest neighbors.
167 // For simplicity, merges the ieta=28 and ieta=29 towers together (calls them
168 // tower "28", collectively).
170 
172 public:
173  struct towercmp {
174  bool operator()(const PhysicsTower& lhs, const PhysicsTower& rhs) const { return (lhs.id < rhs.id); }
175  };
176 
178  const edm::Handle<EcalRecHitCollection>& ebhitcoll_h,
179  const edm::Handle<EcalRecHitCollection>& eehitcoll_h,
180  const edm::Handle<std::vector<reco::TrackExtrapolation> >& trackextrapcoll_h,
181  const ObjectValidatorAbs& objectvalidator,
182  const CaloTowerConstituentsMap& ctcm,
183  const CaloGeometry& geo);
184 
186 
187  // find a PhysicsTower by some coordinate
188  inline const PhysicsTower* findTower(const CaloTowerDetId& id) const;
189  inline const PhysicsTower* findTower(int ieta, int iphi) const;
190 
191  // get the neighbors +/- 1 in eta-space or +/- 1 in phi-space
192  // (accounts for change in phi-segmentation starting with eta=21)
193  void findNeighbors(const CaloTowerDetId& id, std::set<const PhysicsTower*>& neighbors) const;
194  void findNeighbors(const PhysicsTower* twr, std::set<const PhysicsTower*>& neighbors) const;
195  void findNeighbors(int ieta, int iphi, std::set<const PhysicsTower*>& neighbors) const;
196 
197 private:
198  // the non-const, private version of findTower()
200  PhysicsTower* findTower(int ieta, int iphi);
201 
202  void insert_(CaloTowerDetId& id, const HBHERecHit* hit);
203  void insert_(CaloTowerDetId& id, const EcalRecHit* hit);
204  void insert_(CaloTowerDetId& id, const reco::Track* hit);
205 
206  std::set<PhysicsTower, towercmp> towers_;
207 };
208 
210 //
211 // HBHEHitMap
212 //
213 // Collection of HBHERecHits and their associated PhysicsTowers.
214 // Typically, these maps are organized into RBXs, HPDs, dihits, or monohits.
215 // From this one may calculate the hcal, ecal, and track energy associated
216 // with these hits.
217 //
218 // N.B. Many, of the operations can be computationally expensive and should be
219 // used with care.
221 
222 class HBHEHitMap {
223 public:
224  typedef std::map<const HBHERecHit*, const PhysicsTower*>::const_iterator hitmap_const_iterator;
225  typedef std::set<const PhysicsTower*>::const_iterator neighbor_const_iterator;
226 
227  struct twrinfo {
228  double hcalInMap;
229  double hcalOutOfMap;
230  double ecal;
231  double track;
232  };
233 
234  HBHEHitMap();
235  virtual ~HBHEHitMap() {}
236 
237  // energy of the hits in this collection
238  double hitEnergy(void) const;
239 
240  // energy of the hits in a region fiducial to tracks
241  double hitEnergyTrackFiducial(void) const;
242 
243  // number of hits in this collection
244  int nHits(void) const;
245 
246  // same as above, except for the HCAL hits, ECAL hits, and tracks in the same towers as the hits
247  // note that HCAL hits may be present in the same tower, but not be a part of the collection
248  double hcalEnergySameTowers(void) const;
249  double ecalEnergySameTowers(void) const;
250  double trackEnergySameTowers(void) const;
251  int nHcalHitsSameTowers(void) const;
252  int nEcalHitsSameTowers(void) const;
253  int nTracksSameTowers(void) const;
254  void hcalHitsSameTowers(std::set<const HBHERecHit*>& v) const;
255  void ecalHitsSameTowers(std::set<const EcalRecHit*>& v) const;
256  void tracksSameTowers(std::set<const reco::Track*>& v) const;
257 
258  // same as above except for the hits and tracks in the neighboring towers to the hits in the collection
259  double hcalEnergyNeighborTowers(void) const;
260  double ecalEnergyNeighborTowers(void) const;
261  double trackEnergyNeighborTowers(void) const;
262  int nHcalHitsNeighborTowers(void) const;
263  int nEcalHitsNeighborTowers(void) const;
264  int nTracksNeighborTowers(void) const;
265  void hcalHitsNeighborTowers(std::set<const HBHERecHit*>& v) const;
266  void ecalHitsNeighborTowers(std::set<const EcalRecHit*>& v) const;
267  void tracksNeighborTowers(std::set<const reco::Track*>& v) const;
268 
269  // gives the total energy due to hcal, ecal, and tracks tower-by-tower
270  // separates the hcal energy into that which is a hit in the collection, and that which is not
271  void byTowers(std::vector<twrinfo>& v) const;
272 
273  // find a hit in the hitmap
274  hitmap_const_iterator findHit(const HBHERecHit* hit) const { return hits_.find(hit); }
275 
276  // find a neighbor
277  neighbor_const_iterator findNeighbor(const PhysicsTower* twr) const { return neighbors_.find(twr); }
278 
279  // add a hit to the hitmap
280  void insert(const HBHERecHit* hit, const PhysicsTower* twr, std::set<const PhysicsTower*>& neighbors);
281 
282  // access to the private maps and sets
283  inline hitmap_const_iterator beginHits(void) const { return hits_.begin(); }
284  inline hitmap_const_iterator endHits(void) const { return hits_.end(); }
285 
286  inline neighbor_const_iterator beginNeighbors(void) const { return neighbors_.begin(); }
287  inline neighbor_const_iterator endNeighbors(void) const { return neighbors_.end(); }
288 
289 private:
290  std::map<const HBHERecHit*, const PhysicsTower*> hits_;
291  std::set<const PhysicsTower*> neighbors_;
292 
293  void calcHits_(void) const;
294  mutable double hitEnergy_;
295  mutable double hitEnergyTrkFid_;
296  mutable int nHits_;
297 
298  void calcHcalSameTowers_(void) const;
299  mutable double hcalEnergySameTowers_;
300  mutable int nHcalHitsSameTowers_;
301 
302  void calcEcalSameTowers_(void) const;
303  mutable double ecalEnergySameTowers_;
304  mutable int nEcalHitsSameTowers_;
305 
306  void calcTracksSameTowers_(void) const;
307  mutable double trackEnergySameTowers_;
308  mutable int nTracksSameTowers_;
309 
310  void calcHcalNeighborTowers_(void) const;
313 
314  void calcEcalNeighborTowers_(void) const;
317 
318  void calcTracksNeighborTowers_(void) const;
321 };
322 
324 //
325 // HBHEHitMapOrganizer
326 //
327 // Organizers the HBHEHitMaps into RBXs, HPDs, dihits, and monohits
329 
331 public:
333  const ObjectValidatorAbs& objvalidator,
334  const PhysicsTowerOrganizer& pto,
335  const HcalFrontEndMap* hfemap);
336 
337  virtual ~HBHEHitMapOrganizer() {}
338 
339  void getRBXs(std::vector<HBHEHitMap>& v, double energy) const;
340  void getHPDs(std::vector<HBHEHitMap>& v, double energy) const;
341  void getDiHits(std::vector<HBHEHitMap>& v, double energy) const;
342  void getMonoHits(std::vector<HBHEHitMap>& v, double energy) const;
343 
344 private:
346  std::map<int, HBHEHitMap> rbxs_, hpds_;
347  std::vector<HBHEHitMap> dihits_, monohits_;
348 
349  // helper functions
350  // finds all of the hits which are neighbors and in the same HPD as the reference hit
351  void getHPDNeighbors(const HBHERecHit* hit,
352  std::vector<const HBHERecHit*>& neighbors,
353  const PhysicsTowerOrganizer& pto);
354 };
355 
356 #endif
int nEcalHitsNeighborTowers(void) const
int nHcalHitsNeighborTowers(void) const
std::set< const HBHERecHit * > hcalhits
void calcHcalNeighborTowers_(void) const
void insert(const HBHERecHit *hit, const PhysicsTower *twr, std::set< const PhysicsTower *> &neighbors)
hitmap_const_iterator endHits(void) const
void getDiHits(std::vector< HBHEHitMap > &v, double energy) const
void calcHits_(void) const
std::map< const HBHERecHit *, const PhysicsTower * >::const_iterator hitmap_const_iterator
std::vector< HBHEHitMap > dihits_
void setHcalChannelQuality(const HcalChannelQuality *q)
PhysicsTowerOrganizer(const edm::Handle< HBHERecHitCollection > &hbhehitcoll_h, const edm::Handle< EcalRecHitCollection > &ebhitcoll_h, const edm::Handle< EcalRecHitCollection > &eehitcoll_h, const edm::Handle< std::vector< reco::TrackExtrapolation > > &trackextrapcoll_h, const ObjectValidatorAbs &objectvalidator, const CaloTowerConstituentsMap &ctcm, const CaloGeometry &geo)
HBHEHitMapOrganizer(const edm::Handle< HBHERecHitCollection > &hbhehitcoll_h, const ObjectValidatorAbs &objvalidator, const PhysicsTowerOrganizer &pto, const HcalFrontEndMap *hfemap)
double hitEnergyTrackFiducial(void) const
int nTracksSameTowers(void) const
void hcalHitsSameTowers(std::set< const HBHERecHit *> &v) const
void calcHcalSameTowers_(void) const
virtual bool validTrack(const reco::Track &) const =0
void byTowers(std::vector< twrinfo > &v) const
void tracksSameTowers(std::set< const reco::Track *> &v) const
double hcalEnergyNeighborTowers_
double hcalEnergySameTowers(void) const
hitmap_const_iterator findHit(const HBHERecHit *hit) const
ObjectValidator(const edm::ParameterSet &)
bool validHit(const HBHERecHit &) const override
std::map< const HBHERecHit *, const PhysicsTower * > hits_
void setHcalSeverityLevelComputer(const HcalSeverityLevelComputer *q)
double trackEnergyNeighborTowers_
void hcalHitsNeighborTowers(std::set< const HBHERecHit *> &v) const
double hcalEnergyNeighborTowers(void) const
double hitEnergy(void) const
std::set< const PhysicsTower * > neighbors_
void calcEcalSameTowers_(void) const
void ecalHitsNeighborTowers(std::set< const EcalRecHit *> &v) const
std::map< int, HBHEHitMap > rbxs_
int nHcalHitsSameTowers(void) const
const EcalChannelStatus * theEcalChStatus_
void ecalHitsSameTowers(std::set< const EcalRecHit *> &v) const
const EcalRecHitCollection * theEERecHitCollection_
bool operator()(const PhysicsTower &lhs, const PhysicsTower &rhs) const
void insert_(CaloTowerDetId &id, const HBHERecHit *hit)
neighbor_const_iterator findNeighbor(const PhysicsTower *twr) const
void calcTracksSameTowers_(void) const
neighbor_const_iterator endNeighbors(void) const
void getHPDNeighbors(const HBHERecHit *hit, std::vector< const HBHERecHit *> &neighbors, const PhysicsTowerOrganizer &pto)
const EcalRecHitCollection * theEBRecHitCollection_
ObjectValidator(double HBThreshold, double HESThreshold, double HEDThreshold, double EBThreshold, double EEThreshold, uint32_t HcalAcceptSeverityLevel, uint32_t EcalAcceptSeverityLevel, bool UseHcalRecoveredHits, bool UseEcalRecoveredHits, double MinValidTrackPt, double MinValidTrackPtBarrel, int MinValidTrackNHits)
std::set< const PhysicsTower * >::const_iterator neighbor_const_iterator
std::map< int, HBHEHitMap > hpds_
void setEcalSeverityLevelAlgo(const EcalSeverityLevelAlgo *q)
std::set< PhysicsTower, towercmp > towers_
void setEcalChannelStatus(const EcalChannelStatus *q)
neighbor_const_iterator beginNeighbors(void) const
const PhysicsTower * findTower(const CaloTowerDetId &id) const
void calcEcalNeighborTowers_(void) const
virtual bool validHit(const HBHERecHit &) const =0
double ecalEnergyNeighborTowers_
double ecalEnergySameTowers(void) const
void setEERecHitCollection(const EcalRecHitCollection *q)
int nTracksNeighborTowers(void) const
const EcalSeverityLevelAlgo * theEcalSevLvlAlgo_
void findNeighbors(const CaloTowerDetId &id, std::set< const PhysicsTower *> &neighbors) const
double trackEnergySameTowers(void) const
std::set< const EcalRecHit * > ecalhits
int nHits(void) const
void getMonoHits(std::vector< HBHEHitMap > &v, double energy) const
bool validTrack(const reco::Track &) const override
double ecalEnergyNeighborTowers(void) const
double trackEnergyNeighborTowers(void) const
void getRBXs(std::vector< HBHEHitMap > &v, double energy) const
void calcTracksNeighborTowers_(void) const
void getHPDs(std::vector< HBHEHitMap > &v, double energy) const
void tracksNeighborTowers(std::set< const reco::Track *> &v) const
std::set< const reco::Track * > tracks
std::vector< HBHEHitMap > monohits_
const HcalChannelQuality * theHcalChStatus_
const HcalFrontEndMap * hfemap_
void setEBRecHitCollection(const EcalRecHitCollection *q)
const HcalSeverityLevelComputer * theHcalSevLvlComputer_
hitmap_const_iterator beginHits(void) const
int nEcalHitsSameTowers(void) const