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 
50 //
51 // ObjectValidator
52 //
53 // determines if an ECAL hit, HCAL hit, or track is valid or not.
54 // Note that various objects need to be passed to the validator before use.
55 // ObjectValidatorAbs provides a base class in case you want to change the
56 // hit/track validation algorithms.
58 
60 public:
62  virtual ~ObjectValidatorAbs() {}
63 
64  virtual bool validHit(const HBHERecHit&) const = 0;
65  virtual bool validHit(const EcalRecHit&) const = 0;
66  virtual bool validTrack(const reco::Track&) const = 0;
67 };
68 
70 public:
71  explicit ObjectValidator(const edm::ParameterSet&);
73  double HESThreshold,
74  double HEDThreshold,
75  double EBThreshold,
76  double EEThreshold,
77  uint32_t HcalAcceptSeverityLevel,
78  uint32_t EcalAcceptSeverityLevel,
81  double MinValidTrackPt,
82  double MinValidTrackPtBarrel,
84  : HBThreshold_(HBThreshold),
85  HESThreshold_(HESThreshold),
86  HEDThreshold_(HEDThreshold),
87  EBThreshold_(EBThreshold),
88  EEThreshold_(EEThreshold),
89  HcalAcceptSeverityLevel_(HcalAcceptSeverityLevel),
90  EcalAcceptSeverityLevel_(EcalAcceptSeverityLevel),
91  UseHcalRecoveredHits_(UseHcalRecoveredHits),
92  UseEcalRecoveredHits_(UseEcalRecoveredHits),
93  MinValidTrackPt_(MinValidTrackPt),
94  MinValidTrackPtBarrel_(MinValidTrackPtBarrel),
95  MinValidTrackNHits_(MinValidTrackNHits),
96  theHcalChStatus_(nullptr),
97  theEcalChStatus_(nullptr),
98  theHcalSevLvlComputer_(nullptr),
99  theEcalSevLvlAlgo_(nullptr),
100  theEBRecHitCollection_(nullptr),
101  theEERecHitCollection_(nullptr) {}
102  ~ObjectValidator() override;
103 
104  inline void setHcalChannelQuality(const HcalChannelQuality* q) { theHcalChStatus_ = q; }
105  inline void setEcalChannelStatus(const EcalChannelStatus* q) { theEcalChStatus_ = q; }
106  inline void setHcalSeverityLevelComputer(const HcalSeverityLevelComputer* q) { theHcalSevLvlComputer_ = q; }
107  inline void setEcalSeverityLevelAlgo(const EcalSeverityLevelAlgo* q) { theEcalSevLvlAlgo_ = q; }
108  inline void setEBRecHitCollection(const EcalRecHitCollection* q) { theEBRecHitCollection_ = q; }
109  inline void setEERecHitCollection(const EcalRecHitCollection* q) { theEERecHitCollection_ = q; }
110 
111  bool validHit(const HBHERecHit&) const override;
112  bool validHit(const EcalRecHit&) const override;
113  bool validTrack(const reco::Track&) const override;
114 
115 private:
116  double HBThreshold_; // energy threshold for HB hits
117  double HESThreshold_; // energy threshold for 5-degree (phi) HE hits
118  double HEDThreshold_; // energy threshold for 10-degree (phi) HE hits
119  double EBThreshold_; // energy threshold for EB hits
120  double EEThreshold_; // energy threshold for EE hits
121 
122  uint32_t HcalAcceptSeverityLevel_; // severity level to accept HCAL hits
123  uint32_t EcalAcceptSeverityLevel_; // severity level to accept ECAL hits
124  bool UseHcalRecoveredHits_; // whether or not to use recovered HCAL hits
125  bool UseEcalRecoveredHits_; // whether or not to use recovered HCAL hits
126  bool UseAllCombinedRechits_; // whether to use all "Plan 1" combined rechits
127 
128  double MinValidTrackPt_; // minimum valid track pT
129  double MinValidTrackPtBarrel_; // minimum valid track pT in the Barrel
130  int MinValidTrackNHits_; // minimum number of hits needed for a valid track
131 
132  // for checking the status of ECAL and HCAL channels stored in the DB
135 
136  // calculator of severety level for ECAL and HCAL
139 
140  // needed to determine an ECAL channel's validity
143 };
144 
146 //
147 // PhysicsTower
148 //
149 // basic structure to hold information relevant at the tower level
150 // consists of hcal hits, ecal hits, and tracks
152 
153 struct PhysicsTower {
155  std::set<const HBHERecHit*> hcalhits;
156  std::set<const EcalRecHit*> ecalhits;
157  std::set<const reco::Track*> tracks;
158 };
159 
161 //
162 // PhysicsTowerOrganizer
163 //
164 // Organizers the PhysicsTowers into CaloTower (ieta,iphi) space.
165 // Also provides methods to find a towers nearest neighbors.
166 // For simplicity, merges the ieta=28 and ieta=29 towers together (calls them
167 // tower "28", collectively).
169 
171 public:
172  struct towercmp {
173  bool operator()(const PhysicsTower& lhs, const PhysicsTower& rhs) const { return (lhs.id < rhs.id); }
174  };
175 
177  const edm::EventSetup& evSetup,
178  const edm::Handle<HBHERecHitCollection>& hbhehitcoll_h,
179  const edm::Handle<EcalRecHitCollection>& ebhitcoll_h,
180  const edm::Handle<EcalRecHitCollection>& eehitcoll_h,
181  const edm::Handle<std::vector<reco::TrackExtrapolation> >& trackextrapcoll_h,
182  const ObjectValidatorAbs& objectvalidator,
183  const CaloTowerConstituentsMap& ctcm);
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()
199  PhysicsTower* findTower(const CaloTowerDetId& id);
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
std::set< const HBHERecHit * > hcalhits
std::map< const HBHERecHit *, const PhysicsTower * >::const_iterator hitmap_const_iterator
hitmap_const_iterator findHit(const HBHERecHit *hit) const
void setHcalChannelQuality(const HcalChannelQuality *q)
#define nullptr
neighbor_const_iterator findNeighbor(const PhysicsTower *twr) const
virtual bool validTrack(const reco::Track &) const =0
neighbor_const_iterator beginNeighbors(void) const
double hcalEnergyNeighborTowers_
hitmap_const_iterator endHits(void) const
std::map< const HBHERecHit *, const PhysicsTower * > hits_
void setHcalSeverityLevelComputer(const HcalSeverityLevelComputer *q)
double trackEnergyNeighborTowers_
std::set< const PhysicsTower * > neighbors_
int iEvent
Definition: GenABIO.cc:224
std::map< int, HBHEHitMap > rbxs_
const EcalChannelStatus * theEcalChStatus_
virtual bool validHit(const HBHERecHit &) const =0
const EcalRecHitCollection * theEERecHitCollection_
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:50
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
void setEcalSeverityLevelAlgo(const EcalSeverityLevelAlgo *q)
std::set< PhysicsTower, towercmp > towers_
void setEcalChannelStatus(const EcalChannelStatus *q)
double ecalEnergyNeighborTowers_
void setEERecHitCollection(const EcalRecHitCollection *q)
const EcalSeverityLevelAlgo * theEcalSevLvlAlgo_
std::set< const EcalRecHit * > ecalhits
bool operator()(const PhysicsTower &lhs, const PhysicsTower &rhs) const
std::set< const reco::Track * > tracks
std::vector< HBHEHitMap > monohits_
const HcalChannelQuality * theHcalChStatus_
const HcalFrontEndMap * hfemap_
const HcalSeverityLevelComputer * theHcalSevLvlComputer_
void setEBRecHitCollection(const EcalRecHitCollection *q)
neighbor_const_iterator endNeighbors(void) const
hitmap_const_iterator beginHits(void) const