Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:16

0001 ///
0002 /// \class l1t::CaloTools
0003 ///
0004 /// Description: A collection of useful functions for the Calorimeter that are of generic interest
0005 ///
0006 /// Implementation:
0007 ///   currently implimented as a static class rather than a namespace, open to re-writing it as namespace
0008 ///
0009 /// \author: Sam Harper - RAL
0010 ///
0011 
0012 //
0013 
0014 #ifndef L1Trigger_L1TCommon_CaloTools_h
0015 #define L1Trigger_L1TCommon_CaloTools_h
0016 
0017 #include "DataFormats/L1TCalorimeter/interface/CaloTower.h"
0018 #include "DataFormats/L1TCalorimeter/interface/CaloCluster.h"
0019 
0020 #include "DataFormats/L1Trigger/interface/EGamma.h"
0021 #include "DataFormats/L1Trigger/interface/Tau.h"
0022 #include "DataFormats/L1Trigger/interface/Jet.h"
0023 #include "DataFormats/L1Trigger/interface/EtSum.h"
0024 
0025 #include "DataFormats/Math/interface/LorentzVector.h"
0026 
0027 namespace l1t {
0028 
0029   class CaloTools {
0030     //class is not designed to be instanced
0031   private:
0032     CaloTools() {}
0033     ~CaloTools() {}
0034 
0035   public:
0036     //temporary location of these key parameters, probably should be read in from a database
0037     //they are private to stop people using them as they will change (naming is invalid for a start)
0038     static const int kHBHEEnd = 28;
0039     static const int kHFBegin = 29;
0040     static const int kHFEnd = 41;
0041     static const int kHFPhiSeg = 1;              // to be deprecated!
0042     static const int kHFNrPhi = 72 / kHFPhiSeg;  // to be deprecated!
0043     static const int kHBHENrPhi = 72;            // to be deprecated!
0044     static const int kNPhi = 72;
0045     static const int kNrTowers = ((kHFEnd - kHFBegin + 1) * kHFNrPhi + kHBHEEnd * kHBHENrPhi) * 2;
0046     static const int kNrHBHETowers = kHBHEEnd * kHBHENrPhi * 2;
0047 
0048     // These are the saturation codes sent from Layer 1 as the tower pT to Layer 2
0049     // 509 = Layer 1 received saturated HCAL TP
0050     // 510 = Layer 1 received saturated ECAL TP
0051     // 511 = Layer 1 received both saturated ECAL & HCAL TPs
0052     static const int kSatHcal = 509;
0053     static const int kSatEcal = 510;
0054     static const int kSatTower = 511;
0055 
0056     // Jet saturation value
0057     static const int kSatJet = 65535;
0058 
0059   public:
0060     enum SubDet { ECAL = 0x1, HCAL = 0x2, CALO = 0x3 };  //CALO is a short cut for ECAL|HCAL
0061 
0062     static bool insertTower(std::vector<l1t::CaloTower>& towers, const l1t::CaloTower& tower);
0063 
0064     static const l1t::CaloTower& getTower(const std::vector<l1t::CaloTower>& towers, int iEta, int iPhi);
0065     static const l1t::CaloCluster& getCluster(const std::vector<l1t::CaloCluster>& clusters, int iEta, int iPhi);
0066 
0067     //returns a hash suitable for indexing a vector, returns caloTowerHashMax if invalid iEta,iPhi
0068     static size_t caloTowerHash(int iEta, int iPhi);
0069 
0070     //returns maximum size of hash, for vector allocation
0071     static size_t caloTowerHashMax();
0072 
0073     //checks if the iEta, iPhi is valid (ie -28->28, 1->72; |29|->|32|,1-72, %4=1)
0074     static bool isValidIEtaIPhi(int iEta, int iPhi);
0075 
0076     //returns the hw Et sum of of a rectangle bounded by iEta-localEtaMin,iEta+localEtaMax,iPhi-localPhiMin,iPhi-localPhiMax (inclusive)
0077     //sum is either ECAL, HCAL or CALO (ECAL+HCAL) Et
0078     static int calHwEtSum(int iEta,
0079                           int iPhi,
0080                           const std::vector<l1t::CaloTower>& towers,
0081                           int localEtaMin,
0082                           int localEtaMax,
0083                           int localPhiMin,
0084                           int localPhiMax,
0085                           SubDet etMode = CALO);
0086     static int calHwEtSum(int iEta,
0087                           int iPhi,
0088                           const std::vector<l1t::CaloTower>& towers,
0089                           int localEtaMin,
0090                           int localEtaMax,
0091                           int localPhiMin,
0092                           int localPhiMax,
0093                           int iEtaAbsMax,
0094                           SubDet etMode = CALO);
0095 
0096     //returns the number of towers with minHwEt<=hwEt<=maxHwEt and iEtaMin<=iEta<=iEtaMax and iPhiMin<=iPhi<=iPhiMax
0097     //hwEt is either ECAL, HCAL or CALO (ECAL+HCAL) Et
0098     static size_t calNrTowers(int iEtaMin,
0099                               int iEtaMax,
0100                               int iPhiMin,
0101                               int iPhiMax,
0102                               const std::vector<l1t::CaloTower>& towers,
0103                               int minHwEt,
0104                               int maxHwEt,
0105                               SubDet etMode = CALO);
0106 
0107     // physical eta/phi position and sizes of trigger towers
0108     static float towerEta(int ieta);
0109     static float towerPhi(int ieta, int iphi);
0110     static float towerEtaSize(int ieta);
0111     static float towerPhiSize(int ieta);
0112 
0113     // conversion to other index systems
0114     static int mpEta(int ieta);            // convert to internal MP numbering
0115     static int caloEta(int ietaMP);        // convert from internal MP to Calo ieta
0116     static int regionEta(int ieta);        // RCT region
0117     static int bin16Eta(int ieta);         // gives the eta bin label
0118     static int gtEta(int ieta);            // GT eta scale
0119     static int gtPhi(int ieta, int iphi);  // GT phi scale
0120 
0121     // integer divide for HI asymmetry
0122     static unsigned int gloriousDivision(uint32_t aNumerator, uint32_t aDenominator);
0123 
0124     // conversion methods
0125     static math::PtEtaPhiMLorentzVector p4Demux(l1t::L1Candidate*);
0126     static l1t::EGamma egP4Demux(l1t::EGamma&);
0127     static l1t::Tau tauP4Demux(l1t::Tau&);
0128     static l1t::Jet jetP4Demux(l1t::Jet&);
0129     static l1t::EtSum etSumP4Demux(l1t::EtSum&);
0130 
0131     static math::PtEtaPhiMLorentzVector p4MP(l1t::L1Candidate*);
0132     static l1t::EGamma egP4MP(l1t::EGamma&);
0133     static l1t::Tau tauP4MP(l1t::Tau&);
0134     static l1t::Jet jetP4MP(l1t::Jet&);
0135     static l1t::EtSum etSumP4MP(l1t::EtSum&);
0136 
0137     static const int64_t cos_coeff[72];
0138     static const int64_t sin_coeff[72];
0139 
0140     // mapping between sums in emulator and data
0141     static const int emul_to_data_sum_index_map[31];
0142 
0143   private:
0144     // trigger tower eta boundaries
0145     static std::pair<float, float> towerEtaBounds(int ieta);
0146 
0147     static const l1t::CaloTower
0148         nullTower_;  //to return when we need to return a tower which was not found/invalid rather than throwing an exception
0149     static const l1t::CaloCluster
0150         nullCluster_;  //to return when we need to return a cluster which was not found/invalid rather than throwing an exception
0151 
0152     static const float kGTEtaLSB;
0153     static const float kGTPhiLSB;
0154     static const float kGTEtLSB;
0155   };
0156 
0157 }  // namespace l1t
0158 
0159 #endif