CMS 3D CMS Logo

SimCluster.h
Go to the documentation of this file.
1 #ifndef SimDataFormats_SimCluster_h
2 #define SimDataFormats_SimCluster_h
3 
10 #include <vector>
11 
15 
16 //
17 // Forward declarations
18 //
19 class SimTrack;
20 class EncodedEventId;
21 
33 class SimCluster {
34  friend std::ostream &operator<<(std::ostream &s, SimCluster const &tp);
35 
36 public:
37  typedef int Charge;
42 
45  typedef std::vector<SimTrack>::const_iterator g4t_iterator;
46 
47  SimCluster();
48 
49  SimCluster(const SimTrack &simtrk);
50  SimCluster(EncodedEventId eventID, uint32_t particleID); // for PU
51 
52  // destructor
53  ~SimCluster();
54 
59  int pdgId() const {
60  if (genParticles_.empty())
61  return g4Tracks_[0].type();
62  else
63  return (*genParticles_.begin())->pdgId();
64  }
65 
70  EncodedEventId eventId() const { return event_; }
71 
72  uint64_t particleId() const { return particleId_; }
73 
74  // Setters for G4 and reco::GenParticle
76  void addG4Track(const SimTrack &t) { g4Tracks_.push_back(t); }
80  g4t_iterator g4Track_begin() const { return g4Tracks_.begin(); }
81  g4t_iterator g4Track_end() const { return g4Tracks_.end(); }
82 
83  // Getters for Embd and Sim Tracks
85  // Only for clusters from the signal vertex
86  const std::vector<SimTrack> &g4Tracks() const { return g4Tracks_; }
87 
89  float charge() const { return g4Tracks_[0].charge(); }
91  int threeCharge() const { return lrintf(3.f * charge()); }
92 
95  const math::XYZTLorentzVectorF &p4() const { return theMomentum_; }
96 
98  math::XYZVectorF momentum() const { return p4().Vect(); }
99 
101  math::XYZVectorF boostToCM() const { return p4().BoostToCM(); }
102 
105  float p() const { return p4().P(); }
106 
108  float energy() const { return p4().E(); }
109 
111  float et() const { return p4().Et(); }
112 
114  float mass() const { return p4().M(); }
115 
117  float massSqr() const { return pow(mass(), 2); }
118 
120  float mt() const { return p4().Mt(); }
121 
124  float mtSqr() const { return p4().Mt2(); }
125 
128  float px() const { return p4().Px(); }
129 
132  float py() const { return p4().Py(); }
133 
136  float pz() const { return p4().Pz(); }
137 
140  float pt() const { return p4().Pt(); }
141 
144  float phi() const { return p4().Phi(); }
145 
148  float theta() const { return p4().Theta(); }
149 
152  float eta() const { return p4().Eta(); }
153 
156  float rapidity() const { return p4().Rapidity(); }
157 
159  float y() const { return rapidity(); }
160 
165  int status() const { return genParticles_.empty() ? -99 : (*genParticles_[0]).status(); }
166 
167  static const unsigned int longLivedTag;
168 
170  bool longLived() const { return status() & longLivedTag; }
171 
173  int numberOfSimHits() const { return nsimhits_; }
174 
176  int numberOfRecHits() const { return hits_.size(); }
177 
179  void addRecHitAndFraction(uint32_t hit, float fraction) {
180  hits_.emplace_back(hit);
181  fractions_.emplace_back(fraction);
182  }
183 
185  void addHitEnergy(float energy) { energies_.emplace_back(energy); }
186 
188  std::vector<std::pair<uint32_t, float>> hits_and_fractions() const {
189  std::vector<std::pair<uint32_t, float>> result;
190  for (size_t i = 0; i < hits_.size(); ++i) {
191  result.emplace_back(hits_[i], fractions_[i]);
192  }
193  return result;
194  }
195 
197  std::vector<std::pair<uint32_t, float>> barrel_hits_and_fractions() const {
198  std::vector<std::pair<uint32_t, float>> result;
199  for (size_t i = 0; i < hits_.size(); ++i) {
200  DetId detid(hits_[i]);
201  if (detid.subdetId() != EcalBarrel && detid.subdetId() != HcalBarrel && detid.subdetId() != HcalOuter)
202  continue;
203  result.emplace_back(hits_[i], fractions_[i]);
204  }
205  return result;
206  }
207 
209  std::vector<std::pair<uint32_t, float>> endcap_hits_and_fractions() const {
210  std::vector<std::pair<uint32_t, float>> result;
211  for (size_t i = 0; i < hits_.size(); ++i) {
212  DetId detid(hits_[i]);
213  if (detid.subdetId() == EcalBarrel || detid.subdetId() == HcalBarrel || detid.subdetId() == HcalOuter)
214  continue;
215  result.emplace_back(hits_[i], fractions_[i]);
216  }
217  return result;
218  }
219 
221  std::vector<std::pair<uint32_t, float>> hits_and_energies() const {
222  assert(hits_.size() == energies_.size());
223  std::vector<std::pair<uint32_t, float>> result;
224  result.reserve(hits_.size());
225  for (size_t i = 0; i < hits_.size(); ++i) {
226  result.emplace_back(hits_[i], energies_[i]);
227  }
228  return result;
229  }
230 
233  std::vector<uint32_t>().swap(hits_);
234  std::vector<float>().swap(fractions_);
235  }
236 
238  void clearHitsEnergy() { std::vector<float>().swap(energies_); }
239 
241  float simEnergy() const { return simhit_energy_; }
242 
244  void addSimHit(const PCaloHit &hit) {
245  simhit_energy_ += hit.energy();
246  ++nsimhits_;
247  }
248 
249 protected:
252 
253  uint32_t particleId_{0};
254  float simhit_energy_{0.f};
255  std::vector<uint32_t> hits_;
256  std::vector<float> fractions_;
257  std::vector<float> energies_;
258 
260 
262  std::vector<SimTrack> g4Tracks_;
264 };
265 
266 #endif // SimDataFormats_SimCluster_H
float phi() const
Momentum azimuthal angle. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:144
float pz() const
z coordinate of momentum vector. Note this is taken from the first SimTrack only. ...
Definition: SimCluster.h:136
float et() const
Transverse energy. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:111
bool empty() const
Is the RefVector empty.
Definition: RefVector.h:99
void addG4Track(const SimTrack &t)
Definition: SimCluster.h:76
math::XYZTLorentzVectorD LorentzVector
Lorentz vector.
Definition: SimCluster.h:38
int status() const
Status word.
Definition: SimCluster.h:165
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
std::vector< std::pair< uint32_t, float > > endcap_hits_and_fractions() const
Returns list of rechit IDs and fractions in the endcap for this SimCluster.
Definition: SimCluster.h:209
const math::XYZTLorentzVectorF & p4() const
Four-momentum Lorentz vector. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:95
float simhit_energy_
Definition: SimCluster.h:254
math::XYZVectorF boostToCM() const
Vector to boost to the particle centre of mass frame.
Definition: SimCluster.h:101
float massSqr() const
Mass squared. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:117
math::XYZVectorF momentum() const
spatial momentum vector
Definition: SimCluster.h:98
math::XYZPointD Point
point in the space
Definition: SimCluster.h:40
float eta() const
Momentum pseudorapidity. Note this is taken from the simtrack before the calorimeter.
Definition: SimCluster.h:152
math::XYZVectorD Vector
point in the space
Definition: SimCluster.h:41
g4t_iterator g4Track_begin() const
Definition: SimCluster.h:80
friend std::ostream & operator<<(std::ostream &s, SimCluster const &tp)
Definition: SimCluster.cc:31
EncodedEventId event_
Definition: SimCluster.h:251
std::vector< SimTrack >::const_iterator g4t_iterator
Definition: SimCluster.h:45
int Charge
electric charge type
Definition: SimCluster.h:37
void addGenParticle(const reco::GenParticleRef &ref)
Definition: SimCluster.h:75
uint64_t particleId() const
Definition: SimCluster.h:72
assert(be >=bs)
float mtSqr() const
Transverse mass squared. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:124
std::vector< std::pair< uint32_t, float > > hits_and_fractions() const
Returns list of rechit IDs and fractions for this SimCluster.
Definition: SimCluster.h:188
float y() const
Same as rapidity().
Definition: SimCluster.h:159
float simEnergy() const
returns the accumulated sim energy in the cluster
Definition: SimCluster.h:241
void addRecHitAndFraction(uint32_t hit, float fraction)
add rechit with fraction
Definition: SimCluster.h:179
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
float py() const
y coordinate of momentum vector. Note this is taken from the first SimTrack only. ...
Definition: SimCluster.h:132
uint64_t nsimhits_
Definition: SimCluster.h:250
int numberOfRecHits() const
Gives the total number of SimHits, in the cluster.
Definition: SimCluster.h:176
void clearHitsEnergy()
clear the energies list
Definition: SimCluster.h:238
std::vector< uint32_t > hits_
Definition: SimCluster.h:255
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
float charge() const
Electric charge. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:89
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
Monte Carlo truth information used for tracking validation.
Definition: SimCluster.h:33
float theta() const
Momentum polar angle. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:148
float mass() const
Mass. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:114
void clearHitsAndFractions()
clear the hits and fractions list
Definition: SimCluster.h:232
std::vector< std::pair< uint32_t, float > > barrel_hits_and_fractions() const
Returns list of rechit IDs and fractions in the barrel for this SimCluster.
Definition: SimCluster.h:197
reco::GenParticleRefVector::iterator genp_iterator
reference to reco::GenParticle
Definition: SimCluster.h:44
float pt() const
Transverse momentum. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:140
g4t_iterator g4Track_end() const
Definition: SimCluster.h:81
double f[11][100]
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float > > XYZVectorF
spatial vector with cartesian internal representation
Definition: Vector3D.h:16
int threeCharge() const
Gives charge in unit of quark charge (should be 3 times "charge()")
Definition: SimCluster.h:91
std::vector< float > fractions_
Definition: SimCluster.h:256
float px() const
x coordinate of momentum vector. Note this is taken from the first SimTrack only. ...
Definition: SimCluster.h:128
Definition: DetId.h:17
std::vector< SimTrack > g4Tracks_
references to G4 and reco::GenParticle tracks
Definition: SimCluster.h:262
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double > > XYZPointD
point in space with cartesian internal representation
Definition: Point3D.h:8
unsigned long long uint64_t
Definition: Time.h:13
const reco::GenParticleRefVector & genParticles() const
Definition: SimCluster.h:84
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
genp_iterator genParticle_end() const
Definition: SimCluster.h:79
int pdgId() const
PDG ID.
Definition: SimCluster.h:59
genp_iterator genParticle_begin() const
iterators
Definition: SimCluster.h:78
bool longLived() const
is long lived?
Definition: SimCluster.h:170
float energy() const
Energy. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:108
void addSimHit(const PCaloHit &hit)
add simhit&#39;s energy to cluster
Definition: SimCluster.h:244
uint32_t particleId_
Definition: SimCluster.h:253
float mt() const
Transverse mass. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:120
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
std::vector< std::pair< uint32_t, float > > hits_and_energies() const
Returns list of rechit IDs and energies for this SimCluster.
Definition: SimCluster.h:221
void addHitEnergy(float energy)
add rechit energy
Definition: SimCluster.h:185
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< float > > XYZTLorentzVectorF
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:22
reco::GenParticleRefVector genParticles_
Definition: SimCluster.h:263
float rapidity() const
Rapidity. Note this is taken from the simtrack before the calorimeter.
Definition: SimCluster.h:156
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
int numberOfSimHits() const
Gives the total number of SimHits, in the cluster.
Definition: SimCluster.h:173
float p() const
Magnitude of momentum vector. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:105
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
const std::vector< SimTrack > & g4Tracks() const
Definition: SimCluster.h:86
std::vector< float > energies_
Definition: SimCluster.h:257
static const unsigned int longLivedTag
long lived flag
Definition: SimCluster.h:167
math::XYZTLorentzVectorF theMomentum_
Definition: SimCluster.h:259
EncodedEventId eventId() const
Signal source, crossing number.
Definition: SimCluster.h:70
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: SimCluster.h:39