eic-smear  1.0.3
A collection of ROOT classes for Monte Carlo events and a fast-smearing code simulating detector effects for the Electron-Ion Collider task force
ParticleIdentifier.cxx
Go to the documentation of this file.
1 
11 
12 #include <algorithm>
13 #include <iostream>
14 #include <vector>
15 
16 #include "eicsmear/erhic/EventMC.h"
17 
18 // =============================================================================
19 // Constructor
20 // =============================================================================
21 ParticleIdentifier::ParticleIdentifier(const int leptonBeamPdgCode)
22 : mChargedCurrent(false)
23 , mLeptonBeamPdgCode(leptonBeamPdgCode)
24 , mScatteredPdgCode(leptonBeamPdgCode)
25 { }
26 
27 // =============================================================================
28 // Identify the lepton beam particle
29 // =============================================================================
31  const erhic::VirtualParticle& particle) const {
32  // Test against status 201 for SOPHIA events
33  return (21 == particle.GetStatus() || 201 == particle.GetStatus()) &&
34  GetLeptonBeamPdgCode() == particle.Id() &&
35  particle.GetParentIndex() == 0;
36 }
37 
38 // =============================================================================
39 // Identify the scattered lepton
40 // =============================================================================
42  const erhic::VirtualParticle& particle) const {
43  return 1 == particle.GetStatus() && mScatteredPdgCode == particle.Id();
44 }
45 
46 // =============================================================================
47 // Return true if the particle matches any of the following:
48 // - Outgoing electron with KS 21 - we instead pick up the
49 // repeat entry, when KS < 21.
50 // - Repeat of incoming nucleon.
51 // - Intermediate gluon.
52 // - Intermediate quark.
53 // =============================================================================
55  const erhic::VirtualParticle& particle) const {
56  int kI1 = particle.GetStatus();
57  int pdgCode = particle.Id();
58  int parent = particle.GetParentIndex();
59  // Remove duplicate outgoing electron, info is picked up later when KS < 21
60  if (21 == kI1 && pdgCode == GetLeptonBeamPdgCode() && parent == 1) {
61  return true;
62  } // if
63  // Remove repeat of incoming nucelon
64  if (21 == kI1 && (pdgCode == 2112 || pdgCode == 2212) && parent == 2) {
65  return true;
66  } // if
67  // Remove intermediate gluons
68  if (21 == kI1 && pdgCode == 21) {
69  return true;
70  } // if
71  // Remove intermediate (anti)quarks
72  if (21 == kI1 && ::abs(pdgCode) < 10) {
73  return true;
74  } // if
75  return false;
76 }
77 
78 // =============================================================================
79 // Identify the virtual photon based on its PDG code and PYTHIA K(I,1)
80 // =============================================================================
82  const erhic::VirtualParticle& particle) const {
83  const int pdg = abs(particle.Id());
84  return pdg > 21 && pdg < 25 && 21 == particle.GetStatus();
85 }
86 
87 // =============================================================================
88 // Identify the nucleon beam particle
89 // =============================================================================
91  const erhic::VirtualParticle& particle) const {
92  // Test against status 201 for SOPHIA events
93  return (21 == particle.GetStatus() || 201 == particle.GetStatus()) &&
94  (2112 == particle.Id() || 2212 == particle.Id()) &&
95  particle.GetParentIndex() == 0;
96 }
97 
98 // =============================================================================
99 // beam electron (11) --> scattered nu_e (12)
100 // beam positron (-11) --> scattered nu_e_bar (-12)
101 // =============================================================================
103  if (!mChargedCurrent) {
104  return beamType;
105  } // if
106  int sign = beamType / abs(beamType);
107  return sign * (abs(beamType) + 1);
108 }
109 
110 // =============================================================================
111 // =============================================================================
113  mLeptonBeamPdgCode = pdgCode;
114  if (mChargedCurrent) {
115  mScatteredPdgCode = DetermineScatteredType(pdgCode);
116  } else {
117  mScatteredPdgCode = pdgCode;
118  } // if
119 }
120 
122  // If charged current status is changed we need to update
123  // the expected scattered lepton type. But we need to call
124  // DetermineScatteredType() *after* updating mChargedCurrent.
125  bool changed = !mChargedCurrent && cc;
126  mChargedCurrent = cc;
127  if (changed) {
128  mScatteredPdgCode = DetermineScatteredType(mLeptonBeamPdgCode);
129  } // if
130  return cc;
131 }
132 
133 // =============================================================================
134 // Identify the beams from an event and store their properties in a
135 // BeamParticles object.
136 // See BeamParticles.h for the quantities stored.
137 // Returns true if all beams are found, false if not.
138 // =============================================================================
140  BeamParticles& beams) {
141  beams.Reset();
142  std::vector<const erhic::VirtualParticle*> particles;
143  bool foundAll = IdentifyBeams(event, particles);
144  if (particles.at(0)) {
145  beams.SetBeamLepton(particles.at(0)->Get4Vector());
146  } // if
147  if (particles.at(1)) {
148  beams.SetBeamHadron(particles.at(1)->Get4Vector());
149  } // if
150  if (particles.at(2)) {
151  beams.SetBoson(particles.at(2)->Get4Vector());
152  } // if
153  if (particles.at(3)) {
154  beams.SetScatteredLepton(particles.at(3)->Get4Vector());
155  } // if
156  return foundAll;
157 }
158 
159 // =============================================================================
160 // =============================================================================
162  std::vector<const erhic::VirtualParticle*>& beams) {
163  // Initialise a vector with four NULL pointers,
164  // one beam particle of interest.
165  const erhic::VirtualParticle* const null(NULL);
166  beams.assign(4, null);
167  // Configure the particle finder.
168  ParticleIdentifier finder;
169  if (event.GetTrack(0)) {
170  finder.SetLeptonBeamPdgCode(event.GetTrack(0)->Id());
171  } // if
172  // Count leptons so we don't overwrite the beam and scattered lepton with
173  // subsequent leptons of the same type.
174  int leptonCount(0);
175  // Set to true once we find the first virtual photon, so we can skip
176  // subsequent virtual photons.
177  bool foundExchangeBoson(false);
178  bool foundAll(false);
179  for (unsigned n(0); n < event.GetNTracks(); ++n) {
180  const erhic::VirtualParticle* particle = event.GetTrack(n);
181  if (!particle) {
182  continue;
183  } // if
184  // Test for beam lepton/hadron, exchange boson and scattered lepton.
185  if (finder.isBeamNucleon(*particle)) {
186  beams.at(1) = particle;
187  } else if (finder.isBeamLepton(*particle) && 0 == leptonCount) {
188  beams.at(0) = particle;
189  ++leptonCount;
190  } else if (finder.isScatteredLepton(*particle) && 1 == leptonCount) {
191  beams.at(3) = particle;
192  // Protect against additional KS == 1 leptons following this
193  ++leptonCount;
194  } else if (finder.IsVirtualPhoton(*particle) && !foundExchangeBoson) {
195  beams.at(2) = particle;
196  foundExchangeBoson = true;
197  // Check for charged current events, in which the scattered lepton
198  // ID will not be the same as the incident lepton ID.
199  finder.SetChargedCurrent(abs(particle->Id()) == 24);
200  } // if
201  // Break out if we've found all four beams (should happen at/near the
202  // start of the event record, so checking the other particles is a
203  // waste of time).
204  foundAll = std::find(beams.begin(), beams.end(), null) == beams.end();
205  if (foundAll) {
206  break;
207  } // if
208  } // for
209  return foundAll;
210 }
virtual int GetLeptonBeamPdgCode() const
virtual bool isBeamLepton(const erhic::VirtualParticle &) const
virtual UShort_t GetParentIndex() const =0
virtual UShort_t GetStatus() const =0
Abstract base class for a physics event.
Definition: VirtualEvent.h:25
virtual const VirtualParticle * GetTrack(UInt_t) const =0
virtual bool isScatteredLepton(const erhic::VirtualParticle &) const
virtual void SetLeptonBeamPdgCode(int pdg)
virtual bool isBeamNucleon(const erhic::VirtualParticle &) const
virtual bool SkipParticle(const erhic::VirtualParticle &) const
virtual bool SetChargedCurrent(bool isChargedCurrent)
Int_t DetermineScatteredType(Int_t)
virtual Pid Id() const =0
virtual bool IsVirtualPhoton(const erhic::VirtualParticle &) const
Abstract base class for a general particle.
static bool IdentifyBeams(const erhic::VirtualEvent &, BeamParticles &)
ParticleIdentifier(const int leptonPdg=~unsigned(0)/2)