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 */
10 
11 /* ROOT */
12 #include "Math/Vector3D.h"
13 
14 #include <unordered_map>
15 
16 namespace l1t
17 {
18  template <class C> class HGCalClusterT : public L1Candidate
19  {
20 
21  public:
22  typedef typename std::unordered_map<uint32_t, edm::Ptr<C>>::const_iterator const_iterator;
23 
24  public:
27  int pt=0,
28  int eta=0,
29  int phi=0
30  )
31  : L1Candidate(p4, pt, eta, phi),
32  valid_(true),
33  detId_(0),
34  centre_(0, 0, 0),
35  centreProj_(0., 0., 0.),
36  mipPt_(0),
37  seedMipPt_(0){}
38 
40  valid_(true),
41  detId_( c->detId() ),
42  centre_(0., 0., 0.),
43  centreProj_(0., 0., 0.),
44  mipPt_(0.),
45  seedMipPt_(0.)
46  {
47  addConstituent(c);
48  }
49 
50  ~HGCalClusterT() override {};
51 
52  const std::unordered_map<uint32_t, edm::Ptr<C>>& constituents() const { return constituents_; }
53  const_iterator constituents_begin() const { return constituents_.begin(); }
54  const_iterator constituents_end() const { return constituents_.end(); }
55  unsigned size() const { return constituents_.size(); }
56 
57 
58  void addConstituent( const edm::Ptr<C>& c, bool updateCentre=true, float fraction=1. )
59  {
60 
61  double cMipt = c->mipPt()*fraction;
62 
63  if( constituents_.empty() )
64  {
65  detId_ = HGCalDetId( c->detId() );
66  seedMipPt_ = cMipt;
67  /* if the centre will not be dynamically calculated
68  the seed centre is considere as cluster centre */
69  if( !updateCentre )
70  {
71  centre_ = c->position();
72  }
73  }
74  updateP4AndPosition(c, updateCentre, fraction);
75 
76 
77  constituents_.emplace( c->detId(), c );
78  constituentsFraction_.emplace( c->detId(), fraction );
79 
80  }
81 
82  void removeConstituent( const edm::Ptr<C>& c, bool updateCentre=true ){
83 
84  /* remove the pointer to c from the std::vector */
85  double fraction=0;
86  const auto& constituent_itr = constituents_.find(c->detId());
87  const auto& fraction_itr = constituentsFraction_.find(c->detId());
88  if(constituent_itr!=constituents_.end())
89  {
90  // remove constituent and get its fraction in the cluster
91  fraction = fraction_itr->second;
92  constituents_.erase(constituent_itr);
93  constituentsFraction_.erase(fraction_itr);
94 
95  updateP4AndPosition(c, updateCentre, -fraction);
96  }
97  }
98 
99  bool valid() const { return valid_; }
100  void setValid(bool valid) { valid_ = valid; }
101 
102  double mipPt() const { return mipPt_; }
103  double seedMipPt() const { return seedMipPt_; }
104  uint32_t detId() const { return detId_.rawId(); }
105 
106 
107  /* distance in 'cm' */
108  double distance( const l1t::HGCalTriggerCell &tc ) const { return ( tc.position() - centre_ ).mag(); }
109 
110  const GlobalPoint& position() const { return centre_; }
111  const GlobalPoint& centre() const { return centre_; }
112  const GlobalPoint& centreProj() const { return centreProj_; }
113 
114  // FIXME: will need to fix places where the shapes are directly accessed
115  // Right now keep shapes() getter as non-const
117  double hOverE() const
118  {
119  double pt_em = 0.;
120  double pt_had = 0.;
121  double hOe = 0.;
122 
123  for(const auto& constituent : constituents())
124  {
125  switch( constituent->subdetId() )
126  {
127  case HGCEE:
128  pt_em += constituent->pt();
129  break;
130  case HGCHEF:
131  pt_had += constituent->pt();
132  break;
133  case HGCHEB:
134  pt_had += constituent->pt();
135  break;
136  default:
137  break;
138  }
139  }
140  if(pt_em>0) hOe = pt_had / pt_em ;
141  else hOe = -1.;
142  return hOe;
143  }
144 
145  uint32_t subdetId() const {return detId_.subdetId();}
146  uint32_t layer() const {return detId_.layer();}
147  int32_t zside() const {return detId_.zside();}
148 
149 
150  //shower shape
151 
152  int showerLength() const { return showerLength_; }
153  int coreShowerLength() const { return coreShowerLength_; }
154  int firstLayer() const { return firstLayer_; }
155  int maxLayer() const { return maxLayer_; }
156  float eMax() const { return eMax_; }
157  float sigmaEtaEtaMax() const { return sigmaEtaEtaMax_; }
158  float sigmaPhiPhiMax() const { return sigmaPhiPhiMax_; }
159  float sigmaEtaEtaTot() const { return sigmaEtaEtaTot_; }
160  float sigmaPhiPhiTot() const { return sigmaPhiPhiTot_; }
161  float sigmaZZ() const { return sigmaZZ_; }
162  float sigmaRRTot() const { return sigmaRRTot_; }
163  float sigmaRRMax() const { return sigmaRRMax_; }
164  float sigmaRRMean() const { return sigmaRRMean_; }
165 
170  void eMax(float eMax) { eMax_ = eMax;}
178  void sigmaZZ(float sigmaZZ) { sigmaZZ_ = sigmaZZ;}
179 
180  /* operators */
181  bool operator<(const HGCalClusterT<C>& cl) const {return mipPt() < cl.mipPt();}
182  bool operator>(const HGCalClusterT<C>& cl) const { return cl<*this; }
183  bool operator<=(const HGCalClusterT<C>& cl) const { return !(cl>*this); }
184  bool operator>=(const HGCalClusterT<C>& cl) const { return !(cl<*this); }
185 
186 
187  private:
188 
189  bool valid_;
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_;
199  double seedMipPt_;
200 
201  //shower shape
202 
207  float eMax_;
210  float sigmaRRMax_;
213  float sigmaRRTot_;
215  float sigmaZZ_;
216 
218 
219 
220  void updateP4AndPosition(const edm::Ptr<C>& c, bool updateCentre=true, float fraction=1.)
221  {
222  double cMipt = c->mipPt()*fraction;
223  /* update cluster positions (IF requested) */
224  if( updateCentre ){
225  Basic3DVector<float> constituentCentre( c->position() );
226  Basic3DVector<float> clusterCentre( centre_ );
227 
228  clusterCentre = clusterCentre*mipPt_ + constituentCentre*cMipt;
229  if( (mipPt_ + cMipt ) > 0 )
230  {
231  clusterCentre /= ( mipPt_ + cMipt );
232  }
233  centre_ = GlobalPoint( clusterCentre );
234 
235  if( clusterCentre.z()!=0 )
236  {
237  centreProj_= GlobalPoint( clusterCentre / clusterCentre.z() );
238  }
239  }
240 
241  /* update cluster energies */
242  mipPt_ += cMipt;
243 
244  int updatedPt = hwPt() + (int)(c->hwPt()*fraction);
245  setHwPt( updatedPt );
246 
247  math::PtEtaPhiMLorentzVector updatedP4 ( p4() );
248  updatedP4 += (c->p4()*fraction);
249  setP4( updatedP4 );
250  }
251 
252  };
253 
254 }
255 
256 #endif
void addConstituent(const edm::Ptr< C > &c, bool updateCentre=true, float fraction=1.)
Definition: HGCalClusterT.h:58
double distance(const l1t::HGCalTriggerCell &tc) const
int maxLayer() const
void sigmaRRTot(float sigmaRRTot)
const_iterator constituents_end() const
Definition: HGCalClusterT.h:54
void sigmaEtaEtaMax(float sigmaEtaEtaMax)
double eta() const final
momentum pseudorapidity
void showerLength(int showerLength)
void firstLayer(int firstLayer)
float sigmaPhiPhiTot() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
unsigned size() const
Definition: HGCalClusterT.h:55
HGCalClusterT(const LorentzVector p4, int pt=0, int eta=0, int phi=0)
Definition: HGCalClusterT.h:26
double hOverE() const
float sigmaEtaEtaMax() const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
uint32_t subdetId() const
float sigmaRRTot() const
ClusterShapes shapes_
double pt() const final
transverse momentum
std::unordered_map< uint32_t, edm::Ptr< C > > constituents_
ClusterShapes & shapes()
delete x;
Definition: CaloConfig.h:22
const GlobalPoint & centreProj() const
float sigmaZZ() const
const GlobalPoint & position() const
std::unordered_map< uint32_t, edm::Ptr< C > >::const_iterator const_iterator
Definition: HGCalClusterT.h:22
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
void sigmaRRMax(float sigmaRRMax)
const_iterator constituents_begin() const
Definition: HGCalClusterT.h:53
void removeConstituent(const edm::Ptr< C > &c, bool updateCentre=true)
Definition: HGCalClusterT.h:82
int zside() const
get the z-side of the cell (1/-1)
Definition: HGCalDetId.h:51
int showerLength() const
T z() const
Cartesian z coordinate.
~HGCalClusterT() override
Definition: HGCalClusterT.h:50
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
bool valid() const
Definition: HGCalClusterT.h:99
std::unordered_map< uint32_t, double > constituentsFraction_
const GlobalPoint & centre() const
double mipPt() const
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
void eMax(float eMax)
HGCalClusterT(const edm::Ptr< C > &c)
Definition: HGCalClusterT.h:39
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
GlobalPoint centre_
uint32_t layer() const
float sigmaEtaEtaTot() const
float eMax() const
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
float sigmaRRMax() const
int32_t zside() 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)
void setP4(const LorentzVector &p4) final
set 4-momentum
int layer() const
get the layer #
Definition: HGCalDetId.h:48
void coreShowerLength(int coreShowerLength)
const std::unordered_map< uint32_t, edm::Ptr< C > > & constituents() const
Definition: HGCalClusterT.h:52