CMS 3D CMS Logo

HGCalClusterT.h
Go to the documentation of this file.
1 #ifndef DataFormats_L1Trigger_HGCalClusterT_h
2 #define DataFormats_L1Trigger_HGCalClusterT_h
3 
4 /* CMSSW */
13 
14 /* ROOT */
15 #include "Math/Vector3D.h"
16 
17 #include <unordered_map>
18 
19 namespace l1t {
20  template <class C>
21  class HGCalClusterT : public L1Candidate {
22  public:
23  typedef typename std::unordered_map<uint32_t, edm::Ptr<C>>::const_iterator const_iterator;
24 
25  public:
27  HGCalClusterT(const LorentzVector p4, int pt = 0, int eta = 0, int phi = 0)
28  : L1Candidate(p4, pt, eta, phi),
29  valid_(true),
30  detId_(0),
31  centre_(0, 0, 0),
32  centreProj_(0., 0., 0.),
33  mipPt_(0),
34  seedMipPt_(0),
35  sumPt_(0) {}
36 
37  HGCalClusterT(const edm::Ptr<C>& c, float fraction = 1.)
38  : valid_(true),
39  detId_(c->detId()),
40  centre_(0., 0., 0.),
41  centreProj_(0., 0., 0.),
42  mipPt_(0.),
43  seedMipPt_(0.),
44  sumPt_(0.) {
45  addConstituent(c, true, fraction);
46  }
47 
48  ~HGCalClusterT() override{};
49 
50  const std::unordered_map<uint32_t, edm::Ptr<C>>& constituents() const { return constituents_; }
51  const_iterator constituents_begin() const { return constituents_.begin(); }
52  const_iterator constituents_end() const { return constituents_.end(); }
53  unsigned size() const { return constituents_.size(); }
54 
55  void addConstituent(const edm::Ptr<C>& c, bool updateCentre = true, float fraction = 1.) {
56  double cMipt = c->mipPt() * fraction;
57 
58  if (constituents_.empty()) {
59  detId_ = DetId(c->detId());
60  seedMipPt_ = cMipt;
61  /* if the centre will not be dynamically calculated
62  the seed centre is considere as cluster centre */
63  if (!updateCentre) {
64  centre_ = c->position();
65  }
66  }
67  updateP4AndPosition(c, updateCentre, fraction);
68 
69  constituents_.emplace(c->detId(), c);
70  constituentsFraction_.emplace(c->detId(), fraction);
71  }
72 
73  void removeConstituent(const edm::Ptr<C>& c, bool updateCentre = true) {
74  /* remove the pointer to c from the std::vector */
75  double fraction = 0;
76  const auto& constituent_itr = constituents_.find(c->detId());
77  const auto& fraction_itr = constituentsFraction_.find(c->detId());
78  if (constituent_itr != constituents_.end()) {
79  // remove constituent and get its fraction in the cluster
80  fraction = fraction_itr->second;
81  constituents_.erase(constituent_itr);
82  constituentsFraction_.erase(fraction_itr);
83 
84  updateP4AndPosition(c, updateCentre, -fraction);
85  }
86  }
87 
88  bool valid() const { return valid_; }
89  void setValid(bool valid) { valid_ = valid; }
90 
91  double mipPt() const { return mipPt_; }
92  double seedMipPt() const { return seedMipPt_; }
93  uint32_t detId() const { return detId_.rawId(); }
94  void setPt(double pt) { setP4(math::PtEtaPhiMLorentzVector(pt, eta(), phi(), mass())); }
95  double sumPt() const { return sumPt_; }
96  /* distance in 'cm' */
97  double distance(const l1t::HGCalTriggerCell& tc) const { return (tc.position() - centre_).mag(); }
98 
99  const GlobalPoint& position() const { return centre_; }
100  const GlobalPoint& centre() const { return centre_; }
101  const GlobalPoint& centreProj() const { return centreProj_; }
102 
103  // FIXME: will need to fix places where the shapes are directly accessed
104  // Right now keep shapes() getter as non-const
105  ClusterShapes& shapes() { return shapes_; }
106  double hOverE() const {
107  double pt_em = 0.;
108  double pt_had = 0.;
109  double hOe = 0.;
110 
111  for (const auto& id_constituent : constituents()) {
112  DetId id(id_constituent.first);
113  auto id_fraction = constituentsFraction_.find(id_constituent.first);
114  double fraction = (id_fraction != constituentsFraction_.end() ? id_fraction->second : 1.);
115  if ((id.det() == DetId::Forward && id.subdetId() == HGCEE) || (id.det() == DetId::HGCalEE) ||
116  (id.det() == DetId::HGCalTrigger &&
118  pt_em += id_constituent.second->pt() * fraction;
119  } else if ((id.det() == DetId::Forward && id.subdetId() == HGCHEF) ||
120  (id.det() == DetId::Hcal && id.subdetId() == HcalEndcap) || (id.det() == DetId::HGCalHSi) ||
121  (id.det() == DetId::HGCalHSc) ||
122  (id.det() == DetId::HGCalTrigger &&
124  pt_had += id_constituent.second->pt() * fraction;
125  }
126  }
127  if (pt_em > 0)
128  hOe = pt_had / pt_em;
129  else
130  hOe = -1.;
131  return hOe;
132  }
133 
134  uint32_t subdetId() const { return detId_.subdetId(); }
135 
136  //shower shape
137 
138  int showerLength() const { return showerLength_; }
139  int coreShowerLength() const { return coreShowerLength_; }
140  int firstLayer() const { return firstLayer_; }
141  int maxLayer() const { return maxLayer_; }
142  float eMax() const { return eMax_; }
143  float sigmaEtaEtaMax() const { return sigmaEtaEtaMax_; }
144  float sigmaPhiPhiMax() const { return sigmaPhiPhiMax_; }
145  float sigmaEtaEtaTot() const { return sigmaEtaEtaTot_; }
146  float sigmaPhiPhiTot() const { return sigmaPhiPhiTot_; }
147  float sigmaZZ() const { return sigmaZZ_; }
148  float sigmaRRTot() const { return sigmaRRTot_; }
149  float sigmaRRMax() const { return sigmaRRMax_; }
150  float sigmaRRMean() const { return sigmaRRMean_; }
151 
156  void eMax(float eMax) { eMax_ = eMax; }
164  void sigmaZZ(float sigmaZZ) { sigmaZZ_ = sigmaZZ; }
165 
166  /* operators */
167  bool operator<(const HGCalClusterT<C>& cl) const { return mipPt() < cl.mipPt(); }
168  bool operator>(const HGCalClusterT<C>& cl) const { return cl < *this; }
169  bool operator<=(const HGCalClusterT<C>& cl) const { return !(cl > *this); }
170  bool operator>=(const HGCalClusterT<C>& cl) const { return !(cl < *this); }
171 
172  private:
173  bool valid_;
175 
176  std::unordered_map<uint32_t, edm::Ptr<C>> constituents_;
177  std::unordered_map<uint32_t, double> constituentsFraction_;
178 
180  GlobalPoint centreProj_; // centre projected onto the first HGCal layer
181 
182  double mipPt_;
183  double seedMipPt_;
184  double sumPt_;
185 
186  //shower shape
187 
192  float eMax_;
195  float sigmaRRMax_;
198  float sigmaRRTot_;
200  float sigmaZZ_;
201 
203 
204  void updateP4AndPosition(const edm::Ptr<C>& c, bool updateCentre = true, float fraction = 1.) {
205  double cMipt = c->mipPt() * fraction;
206  double cPt = c->pt() * fraction;
207  /* update cluster positions (IF requested) */
208  if (updateCentre) {
209  Basic3DVector<float> constituentCentre(c->position());
210  Basic3DVector<float> clusterCentre(centre_);
211 
212  clusterCentre = clusterCentre * mipPt_ + constituentCentre * cMipt;
213  if ((mipPt_ + cMipt) > 0) {
214  clusterCentre /= (mipPt_ + cMipt);
215  }
216  centre_ = GlobalPoint(clusterCentre);
217 
218  if (clusterCentre.z() != 0) {
219  centreProj_ = GlobalPoint(clusterCentre / clusterCentre.z());
220  }
221  }
222 
223  /* update cluster energies */
224  mipPt_ += cMipt;
225  sumPt_ += cPt;
226  int updatedPt = hwPt() + (int)(c->hwPt() * fraction);
227  setHwPt(updatedPt);
228 
229  math::PtEtaPhiMLorentzVector updatedP4(p4());
230  updatedP4 += (c->p4() * fraction);
231  setP4(updatedP4);
232  }
233  };
234 
235 } // namespace l1t
236 
237 #endif
void addConstituent(const edm::Ptr< C > &c, bool updateCentre=true, float fraction=1.)
Definition: HGCalClusterT.h:55
double distance(const l1t::HGCalTriggerCell &tc) const
Definition: HGCalClusterT.h:97
int maxLayer() const
void sigmaRRTot(float sigmaRRTot)
const_iterator constituents_end() const
Definition: HGCalClusterT.h:52
void sigmaEtaEtaMax(float sigmaEtaEtaMax)
double eta() const final
momentum pseudorapidity
void showerLength(int showerLength)
HGCalTriggerSubdetector subdet() const
get the subdetector
void firstLayer(int firstLayer)
float sigmaPhiPhiTot() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
unsigned size() const
Definition: HGCalClusterT.h:53
HGCalClusterT(const LorentzVector p4, int pt=0, int eta=0, int phi=0)
Definition: HGCalClusterT.h:27
double hOverE() const
float sigmaEtaEtaMax() const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
uint32_t subdetId() const
float sigmaRRTot() const
ClusterShapes shapes_
double pt() const final
transverse momentum
double sumPt() const
Definition: HGCalClusterT.h:95
std::unordered_map< uint32_t, edm::Ptr< C > > constituents_
ClusterShapes & shapes()
delete x;
Definition: CaloConfig.h:22
const GlobalPoint & centreProj() const
float sigmaZZ() const
void setPt(double pt)
Definition: HGCalClusterT.h:94
const GlobalPoint & position() const
std::unordered_map< uint32_t, edm::Ptr< C > >::const_iterator const_iterator
Definition: HGCalClusterT.h:23
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
void sigmaRRMax(float sigmaRRMax)
const_iterator constituents_begin() const
Definition: HGCalClusterT.h:51
void removeConstituent(const edm::Ptr< C > &c, bool updateCentre=true)
Definition: HGCalClusterT.h:73
int showerLength() const
T z() const
Cartesian z coordinate.
~HGCalClusterT() override
Definition: HGCalClusterT.h:48
void updateP4AndPosition(const edm::Ptr< C > &c, bool updateCentre=true, float fraction=1.)
bool operator>(const HGCalClusterT< C > &cl) const
void sigmaPhiPhiMax(float sigmaPhiPhiMax)
GlobalPoint centreProj_
double seedMipPt() const
Definition: HGCalClusterT.h:92
bool valid() const
Definition: HGCalClusterT.h:88
std::unordered_map< uint32_t, double > constituentsFraction_
const GlobalPoint & centre() const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
double mipPt() const
Definition: HGCalClusterT.h:91
void sigmaZZ(float sigmaZZ)
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
void sigmaPhiPhiTot(float sigmaPhiPhiTot)
uint32_t detId() const
Definition: HGCalClusterT.h:93
void eMax(float eMax)
GlobalPoint centre_
float sigmaEtaEtaTot() const
float eMax() const
Definition: DetId.h:18
HGCalClusterT(const edm::Ptr< C > &c, float fraction=1.)
Definition: HGCalClusterT.h:37
int coreShowerLength() const
int hwPt() const
Definition: L1Candidate.h:48
int firstLayer() const
float sigmaRRMean() const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
void setHwPt(int pt)
Definition: L1Candidate.h:41
const GlobalPoint & position() const
Definition: HGCalClusterT.h:99
float sigmaRRMax() const
void maxLayer(int maxLayer)
bool operator>=(const HGCalClusterT< C > &cl) const
float sigmaPhiPhiMax() const
void sigmaEtaEtaTot(float sigmaEtaEtaTot)
void sigmaRRMean(float sigmaRRMean)
double phi() const final
momentum azimuthal angle
void setValid(bool valid)
Definition: HGCalClusterT.h:89
void setP4(const LorentzVector &p4) final
set 4-momentum
void coreShowerLength(int coreShowerLength)
double mass() const final
mass
const std::unordered_map< uint32_t, edm::Ptr< C > > & constituents() const
Definition: HGCalClusterT.h:50