Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:46

0001 #ifndef __HBHE_ISOLATED_NOISE_ALGOS_H__
0002 #define __HBHE_ISOLATED_NOISE_ALGOS_H__
0003 
0004 /*
0005 Description: Isolation algorithms used to identify anomalous noise in the HB/HE.
0006              These algorithms will be used to reflag HB/HE rechits as noise.
0007 
0008              There are 6 objects defined here:
0009              1) ObjectValidatorAbs
0010              2) ObjectValidator
0011          3) PhysicsTower
0012          4) PhysicsTowerOrganizer
0013          5) HBHEHitMap
0014          6) HBHEHitMapOrganizer
0015          See comments below for details.
0016 
0017 Original Author: John Paul Chou (Brown University)
0018                  Thursday, September 2, 2010
0019 */
0020 
0021 // system include files
0022 #include <memory>
0023 #include <string>
0024 #include <vector>
0025 
0026 // user include files
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 
0030 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
0031 #include "CondFormats/HcalObjects/interface/HcalFrontEndMap.h"
0032 #include "Geometry/CaloTopology/interface/CaloTowerConstituentsMap.h"
0033 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0034 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0035 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0036 #include "DataFormats/JetReco/interface/TrackExtrapolation.h"
0037 
0038 #include <vector>
0039 #include <set>
0040 #include <map>
0041 
0042 // forward declarations
0043 class HBHERecHit;
0044 class EcalRecHit;
0045 class HcalChannelQuality;
0046 class HcalSeverityLevelComputer;
0047 class EcalSeverityLevelAlgo;
0048 class CaloGeometry;
0049 
0050 //////////////////////////////////////////////////////////////////////////////
0051 //
0052 // ObjectValidator
0053 //
0054 // determines if an ECAL hit, HCAL hit, or track is valid or not.
0055 // Note that various objects need to be passed to the validator before use.
0056 // ObjectValidatorAbs provides a base class in case you want to change the
0057 // hit/track validation algorithms.
0058 //////////////////////////////////////////////////////////////////////////////
0059 
0060 class ObjectValidatorAbs {
0061 public:
0062   ObjectValidatorAbs() {}
0063   virtual ~ObjectValidatorAbs() {}
0064 
0065   virtual bool validHit(const HBHERecHit&) const = 0;
0066   virtual bool validHit(const EcalRecHit&) const = 0;
0067   virtual bool validTrack(const reco::Track&) const = 0;
0068 };
0069 
0070 class ObjectValidator : public ObjectValidatorAbs {
0071 public:
0072   explicit ObjectValidator(const edm::ParameterSet&);
0073   ObjectValidator(double HBThreshold,
0074                   double HESThreshold,
0075                   double HEDThreshold,
0076                   double EBThreshold,
0077                   double EEThreshold,
0078                   uint32_t HcalAcceptSeverityLevel,
0079                   uint32_t EcalAcceptSeverityLevel,
0080                   bool UseHcalRecoveredHits,
0081                   bool UseEcalRecoveredHits,
0082                   double MinValidTrackPt,
0083                   double MinValidTrackPtBarrel,
0084                   int MinValidTrackNHits)
0085       : HBThreshold_(HBThreshold),
0086         HESThreshold_(HESThreshold),
0087         HEDThreshold_(HEDThreshold),
0088         EBThreshold_(EBThreshold),
0089         EEThreshold_(EEThreshold),
0090         HcalAcceptSeverityLevel_(HcalAcceptSeverityLevel),
0091         EcalAcceptSeverityLevel_(EcalAcceptSeverityLevel),
0092         UseHcalRecoveredHits_(UseHcalRecoveredHits),
0093         UseEcalRecoveredHits_(UseEcalRecoveredHits),
0094         MinValidTrackPt_(MinValidTrackPt),
0095         MinValidTrackPtBarrel_(MinValidTrackPtBarrel),
0096         MinValidTrackNHits_(MinValidTrackNHits),
0097         theHcalChStatus_(nullptr),
0098         theEcalChStatus_(nullptr),
0099         theHcalSevLvlComputer_(nullptr),
0100         theEcalSevLvlAlgo_(nullptr),
0101         theEBRecHitCollection_(nullptr),
0102         theEERecHitCollection_(nullptr) {}
0103   ~ObjectValidator() override;
0104 
0105   inline void setHcalChannelQuality(const HcalChannelQuality* q) { theHcalChStatus_ = q; }
0106   inline void setEcalChannelStatus(const EcalChannelStatus* q) { theEcalChStatus_ = q; }
0107   inline void setHcalSeverityLevelComputer(const HcalSeverityLevelComputer* q) { theHcalSevLvlComputer_ = q; }
0108   inline void setEcalSeverityLevelAlgo(const EcalSeverityLevelAlgo* q) { theEcalSevLvlAlgo_ = q; }
0109   inline void setEBRecHitCollection(const EcalRecHitCollection* q) { theEBRecHitCollection_ = q; }
0110   inline void setEERecHitCollection(const EcalRecHitCollection* q) { theEERecHitCollection_ = q; }
0111 
0112   bool validHit(const HBHERecHit&) const override;
0113   bool validHit(const EcalRecHit&) const override;
0114   bool validTrack(const reco::Track&) const override;
0115 
0116 private:
0117   double HBThreshold_;   // energy threshold for HB hits
0118   double HESThreshold_;  // energy threshold for 5-degree (phi) HE hits
0119   double HEDThreshold_;  // energy threshold for 10-degree (phi) HE hits
0120   double EBThreshold_;   // energy threshold for EB hits
0121   double EEThreshold_;   // energy threshold for EE hits
0122 
0123   uint32_t HcalAcceptSeverityLevel_;  // severity level to accept HCAL hits
0124   uint32_t EcalAcceptSeverityLevel_;  // severity level to accept ECAL hits
0125   bool UseHcalRecoveredHits_;         // whether or not to use recovered HCAL hits
0126   bool UseEcalRecoveredHits_;         // whether or not to use recovered HCAL hits
0127   bool UseAllCombinedRechits_;        // whether to use all "Plan 1" combined rechits
0128 
0129   double MinValidTrackPt_;        // minimum valid track pT
0130   double MinValidTrackPtBarrel_;  // minimum valid track pT in the Barrel
0131   int MinValidTrackNHits_;        // minimum number of hits needed for a valid track
0132 
0133   // for checking the status of ECAL and HCAL channels stored in the DB
0134   const HcalChannelQuality* theHcalChStatus_;
0135   const EcalChannelStatus* theEcalChStatus_;
0136 
0137   // calculator of severety level for ECAL and HCAL
0138   const HcalSeverityLevelComputer* theHcalSevLvlComputer_;
0139   const EcalSeverityLevelAlgo* theEcalSevLvlAlgo_;
0140 
0141   // needed to determine an ECAL channel's validity
0142   const EcalRecHitCollection* theEBRecHitCollection_;
0143   const EcalRecHitCollection* theEERecHitCollection_;
0144 };
0145 
0146 //////////////////////////////////////////////////////////////////////////////
0147 //
0148 // PhysicsTower
0149 //
0150 // basic structure to hold information relevant at the tower level
0151 // consists of hcal hits, ecal hits, and tracks
0152 //////////////////////////////////////////////////////////////////////////////
0153 
0154 struct PhysicsTower {
0155   CaloTowerDetId id;
0156   std::set<const HBHERecHit*> hcalhits;
0157   std::set<const EcalRecHit*> ecalhits;
0158   std::set<const reco::Track*> tracks;
0159 };
0160 
0161 //////////////////////////////////////////////////////////////////////////////
0162 //
0163 // PhysicsTowerOrganizer
0164 //
0165 // Organizers the PhysicsTowers into CaloTower (ieta,iphi) space.
0166 // Also provides methods to find a towers nearest neighbors.
0167 // For simplicity, merges the ieta=28 and ieta=29 towers together (calls them
0168 // tower "28", collectively).
0169 //////////////////////////////////////////////////////////////////////////////
0170 
0171 class PhysicsTowerOrganizer {
0172 public:
0173   struct towercmp {
0174     bool operator()(const PhysicsTower& lhs, const PhysicsTower& rhs) const { return (lhs.id < rhs.id); }
0175   };
0176 
0177   PhysicsTowerOrganizer(const edm::Handle<HBHERecHitCollection>& hbhehitcoll_h,
0178                         const edm::Handle<EcalRecHitCollection>& ebhitcoll_h,
0179                         const edm::Handle<EcalRecHitCollection>& eehitcoll_h,
0180                         const edm::Handle<std::vector<reco::TrackExtrapolation> >& trackextrapcoll_h,
0181                         const ObjectValidatorAbs& objectvalidator,
0182                         const CaloTowerConstituentsMap& ctcm,
0183                         const CaloGeometry& geo);
0184 
0185   virtual ~PhysicsTowerOrganizer() {}
0186 
0187   // find a PhysicsTower by some coordinate
0188   inline const PhysicsTower* findTower(const CaloTowerDetId& id) const;
0189   inline const PhysicsTower* findTower(int ieta, int iphi) const;
0190 
0191   // get the neighbors +/- 1 in eta-space or +/- 1 in phi-space
0192   // (accounts for change in phi-segmentation starting with eta=21)
0193   void findNeighbors(const CaloTowerDetId& id, std::set<const PhysicsTower*>& neighbors) const;
0194   void findNeighbors(const PhysicsTower* twr, std::set<const PhysicsTower*>& neighbors) const;
0195   void findNeighbors(int ieta, int iphi, std::set<const PhysicsTower*>& neighbors) const;
0196 
0197 private:
0198   // the non-const, private version of findTower()
0199   PhysicsTower* findTower(const CaloTowerDetId& id);
0200   PhysicsTower* findTower(int ieta, int iphi);
0201 
0202   void insert_(CaloTowerDetId& id, const HBHERecHit* hit);
0203   void insert_(CaloTowerDetId& id, const EcalRecHit* hit);
0204   void insert_(CaloTowerDetId& id, const reco::Track* hit);
0205 
0206   std::set<PhysicsTower, towercmp> towers_;
0207 };
0208 
0209 //////////////////////////////////////////////////////////////////////////////
0210 //
0211 // HBHEHitMap
0212 //
0213 // Collection of HBHERecHits and their associated PhysicsTowers.
0214 // Typically, these maps are organized into RBXs, HPDs, dihits, or monohits.
0215 // From this one may calculate the hcal, ecal, and track energy associated
0216 // with these hits.
0217 //
0218 // N.B. Many, of the operations can be computationally expensive and should be
0219 // used with care.
0220 //////////////////////////////////////////////////////////////////////////////
0221 
0222 class HBHEHitMap {
0223 public:
0224   typedef std::map<const HBHERecHit*, const PhysicsTower*>::const_iterator hitmap_const_iterator;
0225   typedef std::set<const PhysicsTower*>::const_iterator neighbor_const_iterator;
0226 
0227   struct twrinfo {
0228     double hcalInMap;
0229     double hcalOutOfMap;
0230     double ecal;
0231     double track;
0232   };
0233 
0234   HBHEHitMap();
0235   virtual ~HBHEHitMap() {}
0236 
0237   // energy of the hits in this collection
0238   double hitEnergy(void) const;
0239 
0240   // energy of the hits in a region fiducial to tracks
0241   double hitEnergyTrackFiducial(void) const;
0242 
0243   // number of hits in this collection
0244   int nHits(void) const;
0245 
0246   // same as above, except for the HCAL hits, ECAL hits, and tracks in the same towers as the hits
0247   // note that HCAL hits may be present in the same tower, but not be a part of the collection
0248   double hcalEnergySameTowers(void) const;
0249   double ecalEnergySameTowers(void) const;
0250   double trackEnergySameTowers(void) const;
0251   int nHcalHitsSameTowers(void) const;
0252   int nEcalHitsSameTowers(void) const;
0253   int nTracksSameTowers(void) const;
0254   void hcalHitsSameTowers(std::set<const HBHERecHit*>& v) const;
0255   void ecalHitsSameTowers(std::set<const EcalRecHit*>& v) const;
0256   void tracksSameTowers(std::set<const reco::Track*>& v) const;
0257 
0258   // same as above except for the hits and tracks in the neighboring towers to the hits in the collection
0259   double hcalEnergyNeighborTowers(void) const;
0260   double ecalEnergyNeighborTowers(void) const;
0261   double trackEnergyNeighborTowers(void) const;
0262   int nHcalHitsNeighborTowers(void) const;
0263   int nEcalHitsNeighborTowers(void) const;
0264   int nTracksNeighborTowers(void) const;
0265   void hcalHitsNeighborTowers(std::set<const HBHERecHit*>& v) const;
0266   void ecalHitsNeighborTowers(std::set<const EcalRecHit*>& v) const;
0267   void tracksNeighborTowers(std::set<const reco::Track*>& v) const;
0268 
0269   // gives the total energy due to hcal, ecal, and tracks tower-by-tower
0270   // separates the hcal energy into that which is a hit in the collection, and that which is not
0271   void byTowers(std::vector<twrinfo>& v) const;
0272 
0273   // find a hit in the hitmap
0274   hitmap_const_iterator findHit(const HBHERecHit* hit) const { return hits_.find(hit); }
0275 
0276   // find a neighbor
0277   neighbor_const_iterator findNeighbor(const PhysicsTower* twr) const { return neighbors_.find(twr); }
0278 
0279   // add a hit to the hitmap
0280   void insert(const HBHERecHit* hit, const PhysicsTower* twr, std::set<const PhysicsTower*>& neighbors);
0281 
0282   // access to the private maps and sets
0283   inline hitmap_const_iterator beginHits(void) const { return hits_.begin(); }
0284   inline hitmap_const_iterator endHits(void) const { return hits_.end(); }
0285 
0286   inline neighbor_const_iterator beginNeighbors(void) const { return neighbors_.begin(); }
0287   inline neighbor_const_iterator endNeighbors(void) const { return neighbors_.end(); }
0288 
0289 private:
0290   std::map<const HBHERecHit*, const PhysicsTower*> hits_;
0291   std::set<const PhysicsTower*> neighbors_;
0292 
0293   void calcHits_(void) const;
0294   mutable double hitEnergy_;
0295   mutable double hitEnergyTrkFid_;
0296   mutable int nHits_;
0297 
0298   void calcHcalSameTowers_(void) const;
0299   mutable double hcalEnergySameTowers_;
0300   mutable int nHcalHitsSameTowers_;
0301 
0302   void calcEcalSameTowers_(void) const;
0303   mutable double ecalEnergySameTowers_;
0304   mutable int nEcalHitsSameTowers_;
0305 
0306   void calcTracksSameTowers_(void) const;
0307   mutable double trackEnergySameTowers_;
0308   mutable int nTracksSameTowers_;
0309 
0310   void calcHcalNeighborTowers_(void) const;
0311   mutable double hcalEnergyNeighborTowers_;
0312   mutable int nHcalHitsNeighborTowers_;
0313 
0314   void calcEcalNeighborTowers_(void) const;
0315   mutable double ecalEnergyNeighborTowers_;
0316   mutable int nEcalHitsNeighborTowers_;
0317 
0318   void calcTracksNeighborTowers_(void) const;
0319   mutable double trackEnergyNeighborTowers_;
0320   mutable int nTracksNeighborTowers_;
0321 };
0322 
0323 //////////////////////////////////////////////////////////////////////////////
0324 //
0325 // HBHEHitMapOrganizer
0326 //
0327 // Organizers the HBHEHitMaps into RBXs, HPDs, dihits, and monohits
0328 //////////////////////////////////////////////////////////////////////////////
0329 
0330 class HBHEHitMapOrganizer {
0331 public:
0332   HBHEHitMapOrganizer(const edm::Handle<HBHERecHitCollection>& hbhehitcoll_h,
0333                       const ObjectValidatorAbs& objvalidator,
0334                       const PhysicsTowerOrganizer& pto,
0335                       const HcalFrontEndMap* hfemap);
0336 
0337   virtual ~HBHEHitMapOrganizer() {}
0338 
0339   void getRBXs(std::vector<HBHEHitMap>& v, double energy) const;
0340   void getHPDs(std::vector<HBHEHitMap>& v, double energy) const;
0341   void getDiHits(std::vector<HBHEHitMap>& v, double energy) const;
0342   void getMonoHits(std::vector<HBHEHitMap>& v, double energy) const;
0343 
0344 private:
0345   const HcalFrontEndMap* hfemap_;
0346   std::map<int, HBHEHitMap> rbxs_, hpds_;
0347   std::vector<HBHEHitMap> dihits_, monohits_;
0348 
0349   // helper functions
0350   // finds all of the hits which are neighbors and in the same HPD as the reference hit
0351   void getHPDNeighbors(const HBHERecHit* hit,
0352                        std::vector<const HBHERecHit*>& neighbors,
0353                        const PhysicsTowerOrganizer& pto);
0354 };
0355 
0356 #endif