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 */
12 
13 /* ROOT */
14 #include "Math/Vector3D.h"
15 
16 #include <unordered_map>
17 
18 namespace l1t {
19  template <class C>
20  class HGCalClusterT : public L1Candidate {
21  public:
22  typedef typename std::unordered_map<uint32_t, edm::Ptr<C>>::const_iterator const_iterator;
23 
24  public:
26  HGCalClusterT(const LorentzVector p4, int pt = 0, int eta = 0, int phi = 0)
27  : L1Candidate(p4, pt, eta, phi),
28  valid_(true),
29  detId_(0),
30  centre_(0, 0, 0),
31  centreProj_(0., 0., 0.),
32  mipPt_(0),
33  seedMipPt_(0),
34  sumPt_(0) {}
35 
36  HGCalClusterT(const edm::Ptr<C>& c, float fraction = 1.)
37  : valid_(true),
38  detId_(c->detId()),
39  centre_(0., 0., 0.),
40  centreProj_(0., 0., 0.),
41  mipPt_(0.),
42  seedMipPt_(0.),
43  sumPt_(0.) {
44  addConstituent(c, true, fraction);
45  }
46 
47  ~HGCalClusterT() override{};
48 
49  const std::unordered_map<uint32_t, edm::Ptr<C>>& constituents() const { return constituents_; }
50  const_iterator constituents_begin() const { return constituents_.begin(); }
51  const_iterator constituents_end() const { return constituents_.end(); }
52  unsigned size() const { return constituents_.size(); }
53 
54  void addConstituent(const edm::Ptr<C>& c, bool updateCentre = true, float fraction = 1.) {
55  double cMipt = c->mipPt() * fraction;
56 
57  if (constituents_.empty()) {
58  detId_ = DetId(c->detId());
59  seedMipPt_ = cMipt;
60  /* if the centre will not be dynamically calculated
61  the seed centre is considere as cluster centre */
62  if (!updateCentre) {
63  centre_ = c->position();
64  }
65  }
66  updateP4AndPosition(c, updateCentre, fraction);
67 
68  constituents_.emplace(c->detId(), c);
69  constituentsFraction_.emplace(c->detId(), fraction);
70  }
71 
72  void removeConstituent(const edm::Ptr<C>& c, bool updateCentre = true) {
73  /* remove the pointer to c from the std::vector */
74  double fraction = 0;
75  const auto& constituent_itr = constituents_.find(c->detId());
76  const auto& fraction_itr = constituentsFraction_.find(c->detId());
77  if (constituent_itr != constituents_.end()) {
78  // remove constituent and get its fraction in the cluster
79  fraction = fraction_itr->second;
80  constituents_.erase(constituent_itr);
81  constituentsFraction_.erase(fraction_itr);
82 
83  updateP4AndPosition(c, updateCentre, -fraction);
84  }
85  }
86 
87  bool valid() const { return valid_; }
88  void setValid(bool valid) { valid_ = valid; }
89 
90  double mipPt() const { return mipPt_; }
91  double seedMipPt() const { return seedMipPt_; }
92  uint32_t detId() const { return detId_.rawId(); }
93  void setDetId(uint32_t id) { detId_ = id; }
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  double hOverE() const {
104  double pt_em = 0.;
105  double pt_had = 0.;
106  double hOe = 0.;
107 
108  for (const auto& id_constituent : constituents()) {
109  DetId id(id_constituent.first);
110  auto id_fraction = constituentsFraction_.find(id_constituent.first);
111  double fraction = (id_fraction != constituentsFraction_.end() ? id_fraction->second : 1.);
112  if ((id.det() == DetId::HGCalEE) ||
113  (id.det() == DetId::HGCalTrigger &&
115  (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HFNose && HFNoseDetId(id).isEE()) ||
116  (id.det() == DetId::HGCalTrigger &&
118  HFNoseTriggerDetId(id).isEE())) {
119  pt_em += id_constituent.second->pt() * fraction;
120  } else if ((id.det() == DetId::HGCalHSi) || (id.det() == DetId::HGCalHSc) ||
121  (id.det() == DetId::HGCalTrigger &&
123  (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::HFNose &&
124  HFNoseDetId(id).isHE()) ||
125  (id.det() == DetId::HGCalTrigger &&
127  HFNoseTriggerDetId(id).isHSilicon())) {
128  pt_had += id_constituent.second->pt() * fraction;
129  }
130  }
131  if (pt_em > 0)
132  hOe = pt_had / pt_em;
133  else
134  hOe = -1.;
135  return hOe;
136  }
137 
138  uint32_t subdetId() const { return detId_.subdetId(); }
139 
140  //shower shape
141 
142  int showerLength() const { return showerLength_; }
143  int coreShowerLength() const { return coreShowerLength_; }
144  int firstLayer() const { return firstLayer_; }
145  int maxLayer() const { return maxLayer_; }
146  float eMax() const { return eMax_; }
147  float sigmaEtaEtaMax() const { return sigmaEtaEtaMax_; }
148  float sigmaPhiPhiMax() const { return sigmaPhiPhiMax_; }
149  float sigmaEtaEtaTot() const { return sigmaEtaEtaTot_; }
150  float sigmaPhiPhiTot() const { return sigmaPhiPhiTot_; }
151  float sigmaZZ() const { return sigmaZZ_; }
152  float sigmaRRTot() const { return sigmaRRTot_; }
153  float sigmaRRMax() const { return sigmaRRMax_; }
154  float sigmaRRMean() const { return sigmaRRMean_; }
155  float zBarycenter() const { return zBarycenter_; }
156  float layer10percent() const { return layer10percent_; }
157  float layer50percent() const { return layer50percent_; }
158  float layer90percent() const { return layer90percent_; }
161 
166  void eMax(float eMax) { eMax_ = eMax; }
174  void sigmaZZ(float sigmaZZ) { sigmaZZ_ = sigmaZZ; }
181 
182  /* operators */
183  bool operator<(const HGCalClusterT<C>& cl) const { return mipPt() < cl.mipPt(); }
184  bool operator>(const HGCalClusterT<C>& cl) const { return cl < *this; }
185  bool operator<=(const HGCalClusterT<C>& cl) const { return !(cl > *this); }
186  bool operator>=(const HGCalClusterT<C>& cl) const { return !(cl < *this); }
187 
188  private:
189  bool valid_ = false;
191 
192  std::unordered_map<uint32_t, edm::Ptr<C>> constituents_;
193  std::unordered_map<uint32_t, double> constituentsFraction_;
194 
196  GlobalPoint centreProj_; // centre projected onto the first HGCal layer
197 
198  double mipPt_ = 0.;
199  double seedMipPt_ = 0.;
200  double sumPt_ = 0.;
201 
202  //shower shape
203 
204  int showerLength_ = 0;
206  int firstLayer_ = 0;
207  int maxLayer_ = 0;
208  float eMax_ = 0.;
209  float sigmaEtaEtaMax_ = 0.;
210  float sigmaPhiPhiMax_ = 0.;
211  float sigmaRRMax_ = 0.;
212  float sigmaEtaEtaTot_ = 0.;
213  float sigmaPhiPhiTot_ = 0.;
214  float sigmaRRTot_ = 0.;
215  float sigmaRRMean_ = 0.;
216  float sigmaZZ_ = 0.;
217  float zBarycenter_ = 0.;
218  float layer10percent_ = 0.;
219  float layer50percent_ = 0.;
220  float layer90percent_ = 0.;
223 
224  void updateP4AndPosition(const edm::Ptr<C>& c, bool updateCentre = true, float fraction = 1.) {
225  double cMipt = c->mipPt() * fraction;
226  double cPt = c->pt() * fraction;
227  /* update cluster positions (IF requested) */
228  if (updateCentre) {
229  Basic3DVector<float> constituentCentre(c->position());
230  Basic3DVector<float> clusterCentre(centre_);
231 
232  clusterCentre = clusterCentre * mipPt_ + constituentCentre * cMipt;
233  if ((mipPt_ + cMipt) > 0) {
234  clusterCentre /= (mipPt_ + cMipt);
235  }
236  centre_ = GlobalPoint(clusterCentre);
237 
238  if (clusterCentre.z() != 0) {
239  centreProj_ = GlobalPoint(clusterCentre / std::abs(clusterCentre.z()));
240  }
241  }
242 
243  /* update cluster energies */
244  mipPt_ += cMipt;
245  sumPt_ += cPt;
246  int updatedPt = hwPt() + (int)(c->hwPt() * fraction);
247  setHwPt(updatedPt);
248 
249  math::PtEtaPhiMLorentzVector updatedP4(p4());
250  updatedP4 += (c->p4() * fraction);
251  setP4(updatedP4);
252  }
253  };
254 
255 } // namespace l1t
256 
257 #endif
float sigmaEtaEtaTot() const
void addConstituent(const edm::Ptr< C > &c, bool updateCentre=true, float fraction=1.)
Definition: HGCalClusterT.h:54
void layer90percent(float layer90percent)
float eMax() const
void sigmaRRTot(float sigmaRRTot)
void sigmaEtaEtaMax(float sigmaEtaEtaMax)
void showerLength(int showerLength)
float layer50percent() const
void firstLayer(int firstLayer)
double pt() const final
transverse momentum
bool operator>=(const HGCalClusterT< C > &cl) const
void setDetId(uint32_t id)
Definition: HGCalClusterT.h:93
const std::unordered_map< uint32_t, edm::Ptr< C > > & constituents() const
Definition: HGCalClusterT.h:49
void zBarycenter(float zBarycenter)
HGCalClusterT(const LorentzVector p4, int pt=0, int eta=0, int phi=0)
Definition: HGCalClusterT.h:26
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
int coreShowerLength() const
bool isHE(int etabin, int depth)
uint32_t detId() const
Definition: HGCalClusterT.h:92
uint32_t subdetId() const
std::unordered_map< uint32_t, edm::Ptr< C > > constituents_
delete x;
Definition: CaloConfig.h:22
const_iterator constituents_begin() const
Definition: HGCalClusterT.h:50
void setPt(double pt)
Definition: HGCalClusterT.h:94
float triggerCells90percent() const
const LorentzVector & p4() const final
four-momentum Lorentz vector
float sigmaPhiPhiTot() const
std::unordered_map< uint32_t, edm::Ptr< C > >::const_iterator const_iterator
Definition: HGCalClusterT.h:22
const GlobalPoint & centre() const
bool valid() const
Definition: HGCalClusterT.h:87
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
void triggerCells90percent(float triggerCells90percent)
void triggerCells67percent(float triggerCells67percent)
void sigmaRRMax(float sigmaRRMax)
bool operator>(const HGCalClusterT< C > &cl) const
bool isEE() const
consistency check : no bits left => no overhead
const GlobalPoint & position() const
Definition: HGCalClusterT.h:99
void removeConstituent(const edm::Ptr< C > &c, bool updateCentre=true)
Definition: HGCalClusterT.h:72
float sigmaPhiPhiMax() const
int firstLayer() const
float zBarycenter() const
~HGCalClusterT() override
Definition: HGCalClusterT.h:47
void updateP4AndPosition(const edm::Ptr< C > &c, bool updateCentre=true, float fraction=1.)
void sigmaPhiPhiMax(float sigmaPhiPhiMax)
GlobalPoint centreProj_
std::unordered_map< uint32_t, double > constituentsFraction_
HGCalTriggerSubdetector subdet() const
get the subdetector
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void sigmaZZ(float sigmaZZ)
unsigned size() const
Definition: HGCalClusterT.h:52
void sigmaPhiPhiTot(float sigmaPhiPhiTot)
double seedMipPt() const
Definition: HGCalClusterT.h:91
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
void eMax(float eMax)
float sigmaRRMax() const
GlobalPoint centre_
int showerLength() const
const GlobalPoint & position() const
double distance(const l1t::HGCalTriggerCell &tc) const
Definition: HGCalClusterT.h:97
double hOverE() const
Definition: DetId.h:17
int maxLayer() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
void layer10percent(float layer10percent)
HGCalClusterT(const edm::Ptr< C > &c, float fraction=1.)
Definition: HGCalClusterT.h:36
T z() const
Cartesian z coordinate.
int hwPt() const
Definition: L1Candidate.h:35
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
float sigmaRRTot() const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
bool isEE() const
consistency check : no bits left => no overhead
Definition: HFNoseDetId.h:105
float layer90percent() const
double mass() const final
mass
float sigmaRRMean() const
void layer50percent(float layer50percent)
void setHwPt(int pt)
Definition: L1Candidate.h:28
float sigmaZZ() const
float layer10percent() const
void maxLayer(int maxLayer)
float triggerCells67percent() const
float sigmaEtaEtaMax() const
double phi() const final
momentum azimuthal angle
double mipPt() const
Definition: HGCalClusterT.h:90
void sigmaEtaEtaTot(float sigmaEtaEtaTot)
void sigmaRRMean(float sigmaRRMean)
void setValid(bool valid)
Definition: HGCalClusterT.h:88
const_iterator constituents_end() const
Definition: HGCalClusterT.h:51
const GlobalPoint & centreProj() const
void setP4(const LorentzVector &p4) final
set 4-momentum
double sumPt() const
Definition: HGCalClusterT.h:95
void coreShowerLength(int coreShowerLength)
double eta() const final
momentum pseudorapidity