Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef __L1Trigger_L1THGCal_HGCalTriggerTools_h__
0002 #define __L1Trigger_L1THGCal_HGCalTriggerTools_h__
0003 
0004 /** \class HGCalTriggerTools
0005  *  Tools for handling HGCal trigger det-ID: in the current version
0006  *  of trhe HGCAL simulation only HGCalDetId for the TriggerCells (TC)
0007  *  are used and not HcalDetId as in the offline!
0008  *  As a consequence the class assumes that only DetIds of the first kind are used in the getTC* methods
0009  *  NOTE: this uses the trigger geometry hence would give wrong results
0010  *  when used for offline reco!!!!
0011  *
0012  *  \author G. Cerminara (CERN), heavily "inspired" by HGCalRechHitTools ;)
0013  */
0014 
0015 #include <array>
0016 #include <cmath>
0017 #include <vector>
0018 #include "DataFormats/L1Trigger/interface/BXVector.h"
0019 
0020 #include "DataFormats/DetId/interface/DetId.h"
0021 #include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
0022 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0023 #include "FWCore/Utilities/interface/ESGetToken.h"
0024 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0025 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0026 #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"
0027 
0028 namespace edm {
0029   class EventSetup;
0030 }
0031 
0032 class HGCalTriggerTools {
0033 public:
0034   HGCalTriggerTools() : geom_(nullptr), eeLayers_(0), fhLayers_(0), bhLayers_(0), noseLayers_(0), totalLayers_(0) {}
0035   ~HGCalTriggerTools() {}
0036 
0037   void setGeometry(const HGCalTriggerGeometryBase* const);
0038   void eventSetup(const edm::EventSetup&,
0039                   const edm::ESGetToken<
0040                       HGCalTriggerGeometryBase,
0041                       CaloGeometryRecord>&);  // Kept for backward compatibility: used in L1Trigger/L1CaloTrigger/test
0042   GlobalPoint getTCPosition(const DetId& id) const;
0043   unsigned layers(ForwardSubdetector type) const;
0044   unsigned layers(DetId::Detector type) const;
0045   unsigned layer(const DetId&) const;
0046   unsigned layerWithOffset(const DetId&) const;
0047   bool isEm(const DetId&) const;
0048   bool isHad(const DetId& id) const { return !isEm(id); }
0049   bool isSilicon(const DetId&) const;
0050   bool isScintillator(const DetId& id) const { return !isSilicon(id); }
0051   bool isNose(const DetId&) const;
0052   int zside(const DetId&) const;
0053   int thicknessIndex(const DetId&) const;
0054 
0055   unsigned lastLayerEE(bool nose = false) const { return (nose ? HFNoseDetId::HFNoseLayerEEmax : eeLayers_); }
0056   unsigned lastLayerFH() const { return eeLayers_ + fhLayers_; }
0057   unsigned lastLayerBH() const { return totalLayers_; }
0058   unsigned lastLayerNose() const { return noseLayers_; }
0059   unsigned lastLayer(bool nose = false) const { return nose ? noseLayers_ : totalLayers_; }
0060 
0061   // 4-vector helper functions using GlobalPoint
0062   float getEta(const GlobalPoint& position, const float& vertex_z = 0.) const;
0063   float getPhi(const GlobalPoint& position) const;
0064   float getPt(const GlobalPoint& position, const float& hitEnergy, const float& vertex_z = 0.) const;
0065 
0066   // 4-vector helper functions using DetId
0067   float getTCEta(const DetId& id, const float& vertex_z = 0.) const;
0068   float getTCPhi(const DetId& id) const;
0069   float getTCPt(const DetId& id, const float& hitEnergy, const float& vertex_z = 0.) const;
0070 
0071   inline const HGCalTriggerGeometryBase* getTriggerGeometry() const { return geom_; };
0072 
0073   float getLayerZ(const unsigned& layerWithOffset) const;
0074   float getLayerZ(const int& subdet, const unsigned& layer) const;
0075 
0076   template <typename T>
0077   std::vector<T> bxVectorToVector(const BXVector<T>& inputBXVector) {
0078     std::vector<T> outputVector;
0079     // loop over collection for a given bx and put the objects into a std::vector
0080     outputVector.insert(outputVector.end(), inputBXVector.begin(0), inputBXVector.end(0));
0081     return outputVector;
0082   }
0083 
0084   DetId simToReco(const DetId&, const HGCalTopology&) const;
0085   unsigned triggerLayer(const unsigned id) const { return geom_->triggerLayer(id); }
0086 
0087   static constexpr unsigned kScintillatorPseudoThicknessIndex_ = 3;
0088 
0089   enum SubDetectorType {
0090     hgcal_silicon_CEE,
0091     hgcal_silicon_CEH,
0092     hgcal_scintillator,
0093   };
0094   SubDetectorType getSubDetectorType(const DetId& id) const;
0095 
0096 private:
0097   const HGCalTriggerGeometryBase* geom_;
0098   unsigned eeLayers_;
0099   unsigned fhLayers_;
0100   unsigned bhLayers_;
0101   unsigned noseLayers_;
0102   unsigned totalLayers_;
0103 };
0104 
0105 #endif