File indexing completed on 2024-05-29 23:13:11
0001 #ifndef SimDataFormats_SimCluster_h
0002 #define SimDataFormats_SimCluster_h
0003
0004 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0005 #include "DataFormats/Math/interface/LorentzVector.h"
0006 #include "DataFormats/Math/interface/Point3D.h"
0007 #include "DataFormats/Math/interface/Vector3D.h"
0008 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
0009 #include "SimDataFormats/Track/interface/SimTrack.h"
0010 #include <vector>
0011
0012 #include "DataFormats/DetId/interface/DetId.h"
0013 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0014 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0015
0016
0017
0018
0019 class SimTrack;
0020 class EncodedEventId;
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 class SimCluster {
0034 friend std::ostream &operator<<(std::ostream &s, SimCluster const &tp);
0035
0036 public:
0037 typedef int Charge;
0038 typedef math::XYZTLorentzVectorD LorentzVector;
0039 typedef math::PtEtaPhiMLorentzVector PolarLorentzVector;
0040 typedef math::XYZPointD Point;
0041 typedef math::XYZVectorD Vector;
0042
0043
0044 typedef reco::GenParticleRefVector::iterator genp_iterator;
0045 typedef std::vector<SimTrack>::const_iterator g4t_iterator;
0046
0047 SimCluster();
0048
0049 SimCluster(const SimTrack &simtrk);
0050 SimCluster(EncodedEventId eventID, uint32_t particleID);
0051
0052
0053 ~SimCluster();
0054
0055
0056
0057
0058
0059 int pdgId() const {
0060 if (genParticles_.empty())
0061 return g4Tracks_[0].type();
0062 else
0063 return (*genParticles_.begin())->pdgId();
0064 }
0065
0066
0067
0068
0069
0070 EncodedEventId eventId() const { return event_; }
0071
0072 uint64_t particleId() const { return particleId_; }
0073
0074
0075 void addGenParticle(const reco::GenParticleRef &ref) { genParticles_.push_back(ref); }
0076 void addG4Track(const SimTrack &t) { g4Tracks_.push_back(t); }
0077
0078 genp_iterator genParticle_begin() const { return genParticles_.begin(); }
0079 genp_iterator genParticle_end() const { return genParticles_.end(); }
0080 g4t_iterator g4Track_begin() const { return g4Tracks_.begin(); }
0081 g4t_iterator g4Track_end() const { return g4Tracks_.end(); }
0082
0083
0084 const reco::GenParticleRefVector &genParticles() const { return genParticles_; }
0085
0086 const std::vector<SimTrack> &g4Tracks() const { return g4Tracks_; }
0087
0088
0089 float charge() const { return g4Tracks_[0].charge(); }
0090
0091 int threeCharge() const { return lrintf(3.f * charge()); }
0092
0093
0094
0095 const math::XYZTLorentzVectorF &p4() const { return theMomentum_; }
0096
0097
0098 math::XYZVectorF momentum() const { return p4().Vect(); }
0099
0100
0101 math::XYZVectorF boostToCM() const { return p4().BoostToCM(); }
0102
0103
0104
0105 float p() const { return p4().P(); }
0106
0107
0108 float energy() const { return p4().E(); }
0109
0110
0111 float et() const { return p4().Et(); }
0112
0113
0114 float mass() const { return p4().M(); }
0115
0116
0117 float massSqr() const { return pow(mass(), 2); }
0118
0119
0120 float mt() const { return p4().Mt(); }
0121
0122
0123
0124 float mtSqr() const { return p4().Mt2(); }
0125
0126
0127
0128 float px() const { return p4().Px(); }
0129
0130
0131
0132 float py() const { return p4().Py(); }
0133
0134
0135
0136 float pz() const { return p4().Pz(); }
0137
0138
0139
0140 float pt() const { return p4().Pt(); }
0141
0142
0143
0144 float phi() const { return p4().Phi(); }
0145
0146
0147
0148 float theta() const { return p4().Theta(); }
0149
0150
0151
0152 float eta() const { return p4().Eta(); }
0153
0154
0155
0156 float rapidity() const { return p4().Rapidity(); }
0157
0158
0159 float y() const { return rapidity(); }
0160
0161
0162
0163
0164
0165 int status() const { return genParticles_.empty() ? -99 : (*genParticles_[0]).status(); }
0166
0167 static const unsigned int longLivedTag;
0168
0169
0170 bool longLived() const { return status() & longLivedTag; }
0171
0172
0173 int numberOfSimHits() const { return nsimhits_; }
0174
0175
0176 int numberOfRecHits() const { return hits_.size(); }
0177
0178
0179 void addRecHitAndFraction(uint32_t hit, float fraction) {
0180 hits_.emplace_back(hit);
0181 fractions_.emplace_back(fraction);
0182 }
0183
0184
0185 void addHitEnergy(float energy) { energies_.emplace_back(energy); }
0186
0187
0188 std::vector<std::pair<uint32_t, float>> hits_and_fractions() const {
0189 std::vector<std::pair<uint32_t, float>> result;
0190 for (size_t i = 0; i < hits_.size(); ++i) {
0191 result.emplace_back(hits_[i], fractions_[i]);
0192 }
0193 return result;
0194 }
0195
0196
0197 std::vector<std::pair<uint32_t, float>> barrel_hits_and_fractions() const {
0198 std::vector<std::pair<uint32_t, float>> result;
0199 for (size_t i = 0; i < hits_.size(); ++i) {
0200 DetId detid(hits_[i]);
0201 if (detid.subdetId() != EcalBarrel && detid.subdetId() != HcalBarrel && detid.subdetId() != HcalOuter)
0202 continue;
0203 result.emplace_back(hits_[i], fractions_[i]);
0204 }
0205 return result;
0206 }
0207
0208
0209 std::vector<std::pair<uint32_t, float>> endcap_hits_and_fractions() const {
0210 std::vector<std::pair<uint32_t, float>> result;
0211 for (size_t i = 0; i < hits_.size(); ++i) {
0212 DetId detid(hits_[i]);
0213 if (detid.subdetId() == EcalBarrel || detid.subdetId() == HcalBarrel || detid.subdetId() == HcalOuter)
0214 continue;
0215 result.emplace_back(hits_[i], fractions_[i]);
0216 }
0217 return result;
0218 }
0219
0220
0221 std::vector<std::pair<uint32_t, float>> hits_and_energies() const {
0222 assert(hits_.size() == energies_.size());
0223 std::vector<std::pair<uint32_t, float>> result;
0224 result.reserve(hits_.size());
0225 for (size_t i = 0; i < hits_.size(); ++i) {
0226 result.emplace_back(hits_[i], energies_[i]);
0227 }
0228 return result;
0229 }
0230
0231
0232 void clearHitsAndFractions() {
0233 std::vector<uint32_t>().swap(hits_);
0234 std::vector<float>().swap(fractions_);
0235 }
0236
0237
0238 void clearHitsEnergy() { std::vector<float>().swap(energies_); }
0239
0240
0241 float simEnergy() const { return simhit_energy_; }
0242
0243
0244 void addSimHit(const PCaloHit &hit) {
0245 simhit_energy_ += hit.energy();
0246 ++nsimhits_;
0247 }
0248
0249 protected:
0250 uint64_t nsimhits_{0};
0251 EncodedEventId event_;
0252
0253 uint32_t particleId_{0};
0254 float simhit_energy_{0.f};
0255 std::vector<uint32_t> hits_;
0256 std::vector<float> fractions_;
0257 std::vector<float> energies_;
0258
0259 math::XYZTLorentzVectorF theMomentum_;
0260
0261
0262 std::vector<SimTrack> g4Tracks_;
0263 reco::GenParticleRefVector genParticles_;
0264 };
0265
0266 #endif