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 
22 // system include files
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 // user include files
30 
38 
39 #include <vector>
40 #include <set>
41 #include <map>
42 
43 // forward declarations
44 class HBHERecHit;
45 class EcalRecHit;
46 class HcalChannelQuality;
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 {
62  public:
64  virtual ~ObjectValidatorAbs() {}
65 
66  virtual bool validHit(const HBHERecHit&) const = 0;
67  virtual bool validHit(const EcalRecHit&) const = 0;
68  virtual bool validTrack(const reco::Track&) const = 0;
69 };
70 
72 {
73  public:
74  explicit ObjectValidator(const edm::ParameterSet&);
78  HBThreshold_(HBThreshold),
79  HESThreshold_(HESThreshold),
80  HEDThreshold_(HEDThreshold),
81  EBThreshold_(EBThreshold),
82  EEThreshold_(EEThreshold),
83  HcalAcceptSeverityLevel_(HcalAcceptSeverityLevel),
84  EcalAcceptSeverityLevel_(EcalAcceptSeverityLevel),
85  UseHcalRecoveredHits_(UseHcalRecoveredHits),
86  UseEcalRecoveredHits_(UseEcalRecoveredHits),
87  MinValidTrackPt_(MinValidTrackPt),
88  MinValidTrackPtBarrel_(MinValidTrackPtBarrel),
89  MinValidTrackNHits_(MinValidTrackNHits),
90  theHcalChStatus_(nullptr),
91  theEcalChStatus_(nullptr),
92  theHcalSevLvlComputer_(nullptr),
93  theEcalSevLvlAlgo_(nullptr),
94  theEBRecHitCollection_(nullptr),
95  theEERecHitCollection_(nullptr) {}
96  ~ObjectValidator() override;
97 
98  inline void setHcalChannelQuality(const HcalChannelQuality* q) { theHcalChStatus_=q; }
99  inline void setEcalChannelStatus(const EcalChannelStatus* q) { theEcalChStatus_=q; }
100  inline void setHcalSeverityLevelComputer(const HcalSeverityLevelComputer* q) { theHcalSevLvlComputer_=q; }
101  inline void setEcalSeverityLevelAlgo(const EcalSeverityLevelAlgo* q) { theEcalSevLvlAlgo_=q; }
102  inline void setEBRecHitCollection(const EcalRecHitCollection* q) { theEBRecHitCollection_=q; }
103  inline void setEERecHitCollection(const EcalRecHitCollection* q) { theEERecHitCollection_=q; }
104 
105 
106  bool validHit(const HBHERecHit&) const override;
107  bool validHit(const EcalRecHit&) const override;
108  bool validTrack(const reco::Track&) const override;
109 
110  private:
111 
112  double HBThreshold_; // energy threshold for HB hits
113  double HESThreshold_; // energy threshold for 5-degree (phi) HE hits
114  double HEDThreshold_; // energy threshold for 10-degree (phi) HE hits
115  double EBThreshold_; // energy threshold for EB hits
116  double EEThreshold_; // energy threshold for EE hits
117 
118  uint32_t HcalAcceptSeverityLevel_; // severity level to accept HCAL hits
119  uint32_t EcalAcceptSeverityLevel_; // severity level to accept ECAL hits
120  bool UseHcalRecoveredHits_; // whether or not to use recovered HCAL hits
121  bool UseEcalRecoveredHits_; // whether or not to use recovered HCAL hits
122  bool UseAllCombinedRechits_; // whether to use all "Plan 1" combined rechits
123 
124  double MinValidTrackPt_; // minimum valid track pT
125  double MinValidTrackPtBarrel_; // minimum valid track pT in the Barrel
126  int MinValidTrackNHits_; // minimum number of hits needed for a valid track
127 
128  // for checking the status of ECAL and HCAL channels stored in the DB
131 
132  // calculator of severety level for ECAL and HCAL
135 
136  // needed to determine an ECAL channel's validity
139 };
140 
141 
143 //
144 // PhysicsTower
145 //
146 // basic structure to hold information relevant at the tower level
147 // consists of hcal hits, ecal hits, and tracks
149 
150 struct PhysicsTower {
152  std::set<const HBHERecHit*> hcalhits;
153  std::set<const EcalRecHit*> ecalhits;
154  std::set<const reco::Track*> tracks;
155 };
156 
158 //
159 // PhysicsTowerOrganizer
160 //
161 // Organizers the PhysicsTowers into CaloTower (ieta,iphi) space.
162 // Also provides methods to find a towers nearest neighbors.
163 // For simplicity, merges the ieta=28 and ieta=29 towers together (calls them
164 // tower "28", collectively).
166 
168  public:
169  struct towercmp {
170  bool operator() (const PhysicsTower& lhs, const PhysicsTower& rhs) const {
171  return (lhs.id < rhs.id);
172  }
173  };
174 
176  const edm::EventSetup& evSetup,
177  const edm::Handle<HBHERecHitCollection>& hbhehitcoll_h,
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 
185 
186  // find a PhysicsTower by some coordinate
187  inline const PhysicsTower* findTower(const CaloTowerDetId& id) const;
188  inline const PhysicsTower* findTower(int ieta, int iphi) const;
189 
190  // get the neighbors +/- 1 in eta-space or +/- 1 in phi-space
191  // (accounts for change in phi-segmentation starting with eta=21)
192  void findNeighbors(const CaloTowerDetId& id, std::set<const PhysicsTower*>& neighbors) const;
193  void findNeighbors(const PhysicsTower* twr, std::set<const PhysicsTower*>& neighbors) const;
194  void findNeighbors(int ieta, int iphi, std::set<const PhysicsTower*>& neighbors) const;
195 
196  private:
197  // the non-const, private version of findTower()
198  PhysicsTower* findTower(const CaloTowerDetId& id);
199  PhysicsTower* findTower(int ieta, int iphi);
200 
201  void insert_(CaloTowerDetId& id, const HBHERecHit* hit);
202  void insert_(CaloTowerDetId& id, const EcalRecHit* hit);
203  void insert_(CaloTowerDetId& id, const reco::Track* hit);
204 
205  std::set<PhysicsTower, towercmp> towers_;
206 
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 
223 class HBHEHitMap {
224 
225  public:
226 
227  typedef std::map<const HBHERecHit*, const PhysicsTower*>::const_iterator hitmap_const_iterator;
228  typedef std::set<const PhysicsTower*>::const_iterator neighbor_const_iterator;
229 
230  struct twrinfo {
231  double hcalInMap;
232  double hcalOutOfMap;
233  double ecal;
234  double track;
235  };
236 
237  HBHEHitMap();
238  virtual ~HBHEHitMap() {}
239 
240  // energy of the hits in this collection
241  double hitEnergy(void) const;
242 
243  // energy of the hits in a region fiducial to tracks
244  double hitEnergyTrackFiducial(void) const;
245 
246  // number of hits in this collection
247  int nHits(void) const;
248 
249  // same as above, except for the HCAL hits, ECAL hits, and tracks in the same towers as the hits
250  // note that HCAL hits may be present in the same tower, but not be a part of the collection
251  double hcalEnergySameTowers(void) const;
252  double ecalEnergySameTowers(void) const;
253  double trackEnergySameTowers(void) const;
254  int nHcalHitsSameTowers(void) const;
255  int nEcalHitsSameTowers(void) const;
256  int nTracksSameTowers(void) const;
257  void hcalHitsSameTowers(std::set<const HBHERecHit*>& v) const;
258  void ecalHitsSameTowers(std::set<const EcalRecHit*>& v) const;
259  void tracksSameTowers(std::set<const reco::Track*>& v) const;
260 
261  // same as above except for the hits and tracks in the neighboring towers to the hits in the collection
262  double hcalEnergyNeighborTowers(void) const;
263  double ecalEnergyNeighborTowers(void) const;
264  double trackEnergyNeighborTowers(void) const;
265  int nHcalHitsNeighborTowers(void) const;
266  int nEcalHitsNeighborTowers(void) const;
267  int nTracksNeighborTowers(void) const;
268  void hcalHitsNeighborTowers(std::set<const HBHERecHit*>& v) const;
269  void ecalHitsNeighborTowers(std::set<const EcalRecHit*>& v) const;
270  void tracksNeighborTowers(std::set<const reco::Track*>& v) const;
271 
272  // gives the total energy due to hcal, ecal, and tracks tower-by-tower
273  // separates the hcal energy into that which is a hit in the collection, and that which is not
274  void byTowers(std::vector<twrinfo>& v) const;
275 
276  // find a hit in the hitmap
277  hitmap_const_iterator findHit(const HBHERecHit* hit) const { return hits_.find(hit); }
278 
279  // find a neighbor
280  neighbor_const_iterator findNeighbor(const PhysicsTower* twr) const { return neighbors_.find(twr); }
281 
282  // add a hit to the hitmap
283  void insert(const HBHERecHit* hit, const PhysicsTower* twr, std::set<const PhysicsTower*>& neighbors);
284 
285  // access to the private maps and sets
286  inline hitmap_const_iterator beginHits(void) const { return hits_.begin(); }
287  inline hitmap_const_iterator endHits(void) const { return hits_.end(); }
288 
289  inline neighbor_const_iterator beginNeighbors(void) const { return neighbors_.begin(); }
290  inline neighbor_const_iterator endNeighbors(void) const { return neighbors_.end(); }
291 
292  private:
293  std::map<const HBHERecHit*, const PhysicsTower*> hits_;
294  std::set<const PhysicsTower*> neighbors_;
295 
296  void calcHits_(void) const;
297  mutable double hitEnergy_;
298  mutable double hitEnergyTrkFid_;
299  mutable int nHits_;
300 
301  void calcHcalSameTowers_(void) const;
302  mutable double hcalEnergySameTowers_;
303  mutable int nHcalHitsSameTowers_;
304 
305  void calcEcalSameTowers_(void) const;
306  mutable double ecalEnergySameTowers_;
307  mutable int nEcalHitsSameTowers_;
308 
309  void calcTracksSameTowers_(void) const;
310  mutable double trackEnergySameTowers_;
311  mutable int nTracksSameTowers_;
312 
313  void calcHcalNeighborTowers_(void) const;
316 
317  void calcEcalNeighborTowers_(void) const;
320 
321  void calcTracksNeighborTowers_(void) const;
324 
325 };
326 
328 //
329 // HBHEHitMapOrganizer
330 //
331 // Organizers the HBHEHitMaps into RBXs, HPDs, dihits, and monohits
333 
335 {
336  public:
338  const ObjectValidatorAbs& objvalidator,
339  const PhysicsTowerOrganizer& pto,
340  const HcalFrontEndMap* hfemap);
341 
342  virtual ~HBHEHitMapOrganizer() {}
343 
344  void getRBXs(std::vector<HBHEHitMap>& v, double energy) const;
345  void getHPDs(std::vector<HBHEHitMap>& v, double energy) const;
346  void getDiHits(std::vector<HBHEHitMap>& v, double energy) const;
347  void getMonoHits(std::vector<HBHEHitMap>& v, double energy) const;
348 
349  private:
350 
352  std::map<int, HBHEHitMap> rbxs_, hpds_;
353  std::vector<HBHEHitMap> dihits_, monohits_;
354 
355  // helper functions
356  // finds all of the hits which are neighbors and in the same HPD as the reference hit
357  void getHPDNeighbors(const HBHERecHit* hit, std::vector<const HBHERecHit*>& neighbors, const PhysicsTowerOrganizer& pto);
358 
359 };
360 
361 
362 #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)
neighbor_const_iterator findNeighbor(const PhysicsTower *twr) const
HEDThreshold
GeV, Oprimized on 10% occupancy.
virtual bool validTrack(const reco::Track &) const =0
neighbor_const_iterator beginNeighbors(void) const
double hcalEnergyNeighborTowers_
#define nullptr
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:230
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:49
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
std::set< const reco::Track * > tracks
std::vector< HBHEHitMap > monohits_
const HcalChannelQuality * theHcalChStatus_
EEThreshold
GeV, Oprimized on 10% occupancy.
const HcalFrontEndMap * hfemap_
const HcalSeverityLevelComputer * theHcalSevLvlComputer_
void setEBRecHitCollection(const EcalRecHitCollection *q)
neighbor_const_iterator endNeighbors(void) const
HESThreshold
GeV, ORCA value w/o selective readout.
hitmap_const_iterator beginHits(void) const