File indexing completed on 2024-09-28 07:02:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "eicsmear/erhic/ParticleIdentifier.h"
0011
0012 #include <algorithm>
0013 #include <iostream>
0014 #include <vector>
0015 #include <string>
0016
0017 #include <TParticlePDG.h>
0018 #include <TDatabasePDG.h>
0019
0020 #include "eicsmear/erhic/EventMC.h"
0021
0022 using std::string;
0023 using std::cout;
0024 using std::cerr;
0025 using std::endl;
0026
0027
0028
0029
0030
0031 ParticleIdentifier::ParticleIdentifier(const int leptonBeamPdgCode)
0032 : mChargedCurrent(false)
0033 , mLeptonBeamPdgCode(leptonBeamPdgCode)
0034 , mScatteredPdgCode(leptonBeamPdgCode)
0035 { }
0036
0037
0038
0039
0040 bool ParticleIdentifier::isBeamLepton(
0041 const erhic::VirtualParticle& particle) const {
0042
0043 if ( particle.GetParentIndex() != 0 ) return false;
0044
0045 if ( particle.Id() != GetLeptonBeamPdgCode() ) return false;
0046
0047 switch (particle.GetStatus()){
0048 case 21 : return true;
0049 case 201 : return true;
0050 case 4: return true;
0051 }
0052 return false;
0053 }
0054
0055
0056
0057
0058 bool ParticleIdentifier::isScatteredLepton(const erhic::VirtualParticle& particle) const {
0059 auto pdgl = TDatabasePDG::Instance()->GetParticle( particle.Id() );
0060
0061 return ( particle.GetStatus() == 1 && string(pdgl->ParticleClass()) == "Lepton" );
0062
0063
0064 }
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074 bool ParticleIdentifier::SkipParticle(
0075 const erhic::VirtualParticle& particle) const {
0076 int kI1 = particle.GetStatus();
0077 int pdgCode = particle.Id();
0078 int parent = particle.GetParentIndex();
0079
0080 if (21 == kI1 && pdgCode == GetLeptonBeamPdgCode() && parent == 1) {
0081 return true;
0082 }
0083
0084 if (21 == kI1 && (pdgCode == 2112 || pdgCode == 2212) && parent == 2) {
0085 return true;
0086 }
0087
0088 if (21 == kI1 && pdgCode == 21) {
0089 return true;
0090 }
0091
0092 if (21 == kI1 && ::abs(pdgCode) < 10) {
0093 return true;
0094 }
0095 return false;
0096 }
0097
0098
0099
0100
0101 bool ParticleIdentifier::IsVirtualPhoton(
0102 const erhic::VirtualParticle& particle) const {
0103 const int pdg = abs(particle.Id());
0104 auto status = particle.GetStatus();
0105
0106 if ( particle.GetStatus() == 0 && status ==0 ) return true;
0107
0108 if (pdg<22) return false;
0109 if (pdg>24) return false;
0110 if ( status == 21 ) return true;
0111 if ( status == 13 ) return true;
0112 return false;
0113 }
0114
0115
0116
0117
0118 bool ParticleIdentifier::isBeamNucleon(
0119 const erhic::VirtualParticle& particle) const {
0120
0121 if ( particle.GetParentIndex() != 0 ) return false;
0122
0123 if ( particle.Id() != 2112 && particle.Id() != 2212
0124 && abs(particle.Id()) < 1000000000 ) return false;
0125
0126 switch (particle.GetStatus()){
0127 case 21 : return true;
0128 case 201 : return true;
0129 case 4: return true;
0130 }
0131
0132 return false;
0133 }
0134
0135
0136
0137
0138
0139 Int_t ParticleIdentifier::DetermineScatteredType(Int_t beamType) {
0140 if (!mChargedCurrent) {
0141 return beamType;
0142 }
0143 int sign = beamType / abs(beamType);
0144 return sign * (abs(beamType) + 1);
0145 }
0146
0147
0148
0149 void ParticleIdentifier::SetLeptonBeamPdgCode(const int pdgCode) {
0150 mLeptonBeamPdgCode = pdgCode;
0151 if (mChargedCurrent) {
0152 mScatteredPdgCode = DetermineScatteredType(pdgCode);
0153 } else {
0154 mScatteredPdgCode = pdgCode;
0155 }
0156 }
0157
0158 bool ParticleIdentifier::SetChargedCurrent(bool cc) {
0159
0160
0161
0162 bool changed = !mChargedCurrent && cc;
0163 mChargedCurrent = cc;
0164 if (changed) {
0165 mScatteredPdgCode = DetermineScatteredType(mLeptonBeamPdgCode);
0166 }
0167 return cc;
0168 }
0169
0170
0171
0172
0173
0174
0175
0176 bool ParticleIdentifier::IdentifyBeams(const erhic::VirtualEvent& event,
0177 BeamParticles& beams) {
0178 beams.Reset();
0179 std::vector<const erhic::VirtualParticle*> particles;
0180 bool foundAll = IdentifyBeams(event, particles);
0181 if (particles.at(0)) {
0182 beams.SetBeamLepton(particles.at(0)->Get4Vector());
0183 }
0184 if (particles.at(1)) {
0185 beams.SetBeamHadron(particles.at(1)->Get4Vector());
0186 }
0187 if (particles.at(2)) {
0188 beams.SetBoson(particles.at(2)->Get4Vector());
0189 }
0190 if (particles.at(3)) {
0191 beams.SetScatteredLepton(particles.at(3)->Get4Vector());
0192 }
0193 return foundAll;
0194 }
0195
0196
0197
0198 bool ParticleIdentifier::IdentifyBeams(const erhic::VirtualEvent& event,
0199 std::vector<const erhic::VirtualParticle*>& beams) {
0200
0201
0202 const erhic::VirtualParticle* const null(NULL);
0203 beams.assign(4, null);
0204
0205 ParticleIdentifier finder;
0206 if (event.GetTrack(0)) {
0207 finder.SetLeptonBeamPdgCode(event.GetTrack(0)->Id());
0208 }
0209
0210
0211 int leptonCount(0);
0212
0213
0214 bool foundExchangeBoson(false);
0215 bool foundAll(false);
0216 for (unsigned n(0); n < event.GetNTracks(); ++n) {
0217 const erhic::VirtualParticle* particle = event.GetTrack(n);
0218 if (!particle) {
0219 continue;
0220 }
0221
0222 if (finder.isBeamNucleon(*particle)) {
0223
0224 beams.at(1) = particle;
0225 } else if (finder.isBeamLepton(*particle) && 0 == leptonCount) {
0226
0227 beams.at(0) = particle;
0228 ++leptonCount;
0229 } else if (finder.isScatteredLepton(*particle) && 1 == leptonCount) {
0230
0231 beams.at(3) = particle;
0232
0233 ++leptonCount;
0234 } else if (finder.IsVirtualPhoton(*particle) && !foundExchangeBoson) {
0235
0236 beams.at(2) = particle;
0237 foundExchangeBoson = true;
0238
0239
0240 finder.SetChargedCurrent(abs(particle->Id()) == 24);
0241 }
0242
0243
0244
0245 foundAll = std::find(beams.begin(), beams.end(), null) == beams.end();
0246 if (foundAll) {
0247 break;
0248 }
0249 }
0250 return foundAll;
0251 }