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
Detector.cxx
Go to the documentation of this file.
1 
11 
12 #include <algorithm>
13 #include <functional>
14 #include <list>
15 #include <memory>
16 #include <vector>
17 
22 #include "eicsmear/smear/Smearer.h"
24 
25 namespace Smear {
26 
28 : useNM(false)
29 , useJB(false)
30 , useDA(false) {
31 }
32 
34 : TObject(other) {
35  useNM = other.useNM;
36  useJB = other.useJB;
37  useDA = other.useDA;
38  Devices = other.CopyDevices();
39 }
40 
42  if (this != &that) {
43  useNM = that.useNM;
44  useJB = that.useJB;
45  useDA = that.useDA;
46  Devices = that.CopyDevices();
47  } // if
48  return *this;
49 }
50 
53 }
54 
56  for (unsigned i(0); i < GetNDevices(); i++) {
57  delete Devices.at(i);
58  Devices.at(i) = NULL;
59  } // for
60  Devices.clear();
61 }
62 
64  Devices.push_back(dev.Clone());
65 }
66 
68  s.ToLower();
69  useNM = s.Contains("nm") || s.Contains("null");
70  useJB = s.Contains("jb") || s.Contains("jacquet");
71  useDA = s.Contains("da") || s.Contains("double");
72 }
73 
75  Smearer* smearer(NULL);
76  if (unsigned(n) < Devices.size()) {
77  smearer = Devices.at(n);
78  } // if
79  return smearer;
80 }
81 
83  if (!(useNM || useJB || useDA)) {
84  return;
85  } // if
86  // Need a bit of jiggery-pokery here, as the incident beam info isn't
87  // associated with the smeared event.
88  // So, get the beam info from the MC event, but replace the scattered
89  // electron with the smeared version.
90  // Then we can use the standard JB/DA algorithms on the smeared event.
91  const ParticleMCS* scattered = eventS->ScatteredLepton();
92  typedef std::auto_ptr<erhic::DisKinematics> KinPtr;
93  if (useNM && scattered) {
94  KinPtr kin(erhic::LeptonKinematicsComputer(*eventS).Calculate());
95  if (kin.get()) {
96  eventS->SetLeptonKinematics(*kin);
97  } // if
98  } else {
99  eventS->SetLeptonKinematics(
100  erhic::DisKinematics(-1., -1., -1., -1., -1.));
101  } // if
102  if (useJB) {
103  KinPtr kin(erhic::JacquetBlondelComputer(*eventS).Calculate());
104  if (kin.get()) {
105  eventS->SetJacquetBlondelKinematics(*kin);
106  } // if
107  } // if
108  if (useDA && scattered) {
109  KinPtr kin(erhic::DoubleAngleComputer(*eventS).Calculate());
110  if (kin.get()) {
111  eventS->SetDoubleAngleKinematics(*kin);
112  } // if
113  } // if
114 }
115 
116 std::list<Smearer*> Detector::Accept(const erhic::VirtualParticle& p) const {
117  std::list<Smearer*> devices;
118  // Only accept final-state particles, so skip the check against each
119  // devices for non-final-state particles.
120  if (p.GetStatus() == 1) {
121  std::vector<Smearer*>::const_iterator iter;
122  for (iter = Devices.begin(); iter != Devices.end(); ++iter) {
123  // Store each device that accepts the particle.
124  if ((*iter)->Accept.Is(p)) {
125  devices.push_back(*iter);
126  } // if
127  } // for
128  } // if
129  return devices;
130 }
131 
133  // Does the particle fall in the acceptance of any device?
134  // If so, we smear it, if not, we skip it (store a NULL pointer).
135  std::list<Smearer*> devices = Accept(prt);
136  ParticleMCS* prtOut(NULL);
137  if (!devices.empty()) {
138  // It passes through at least one device, so smear it.
139  // Devices in which it doesn't pass won't smear it.
140  prtOut = new ParticleMCS();
141  std::list<Smearer*>::iterator iter;
142  for (iter = devices.begin(); iter != devices.end(); ++iter) {
143  (*iter)->Smear(prt, *prtOut);
144  } // for
145  // Compute derived momentum components.
146  prtOut->px = prtOut->p * sin(prtOut->theta) * cos(prtOut->phi);
147  prtOut->py = prtOut->p * sin(prtOut->theta) * sin(prtOut->phi);
148  prtOut->pt = sqrt(pow(prtOut->px, 2.) + pow(prtOut->py, 2.));
149  prtOut->pz = prtOut->p * cos(prtOut->theta);
150  } // if
151  return prtOut;
152 }
153 
154 std::vector<Smearer*> Detector::CopyDevices() const {
155  std::vector<Smearer*> copies;
156  std::transform(Devices.begin(), Devices.end(),
157  std::back_inserter(copies),
158  std::bind2nd(std::mem_fun(&Smearer::Clone), ""));
159  return copies;
160 }
161 
162 void Detector::Print(Option_t* o) const {
163  for (unsigned i(0); i < GetNDevices(); ++i) {
164  Devices.at(i)->Print(o);
165  } // for
166 }
167 
168 } // namespace Smear
std::list< Smear::Smearer * > Accept(const erhic::VirtualParticle &) const
Definition: Detector.cxx:116
std::vector< Smear::Smearer * > CopyDevices() const
Definition: Detector.cxx:154
virtual Smearer * Clone(const char *="") const =0
virtual void SetLeptonKinematics(const DisKinematics &)
Definition: EventDis.cxx:61
Double32_t phi
Azimuthal angle.
Definition: ParticleMCS.h:180
virtual void SetJacquetBlondelKinematics(const DisKinematics &)
Definition: EventDis.cxx:69
ParticleMCS * Smear(const erhic::VirtualParticle &) const
Definition: Detector.cxx:132
virtual UShort_t GetStatus() const =0
virtual ~Detector()
Definition: Detector.cxx:51
virtual void SetDoubleAngleKinematics(const DisKinematics &)
Definition: EventDis.cxx:76
void DeleteAllDevices()
Definition: Detector.cxx:55
void AddDevice(Smearer &device)
Definition: Detector.cxx:63
Double32_t py
y component of particle momentum
Definition: ParticleMCS.h:174
Double32_t p
Total momentum of particle.
Definition: ParticleMCS.h:178
void FillEventKinematics(Event *event)
Definition: Detector.cxx:82
Smearer * GetDevice(int index)
Definition: Detector.cxx:74
Double32_t px
x component of particle momentum
Definition: ParticleMCS.h:173
virtual const ParticleMCS * ScatteredLepton() const
Definition: EventSmear.cxx:44
UInt_t GetNDevices() const
Definition: Detector.h:147
Double32_t pt
Transverse momentum of particle.
Definition: ParticleMCS.h:177
virtual void Print(Option_t *="") const
Definition: Detector.cxx:162
void SetEventKinematicsCalculator(TString)
Definition: Detector.cxx:67
Double32_t pz
z component of particle momentum
Definition: ParticleMCS.h:175
Abstract base class for a general particle.
Detector & operator=(const Detector &)
Definition: Detector.cxx:41
Double32_t theta
Polar angle.
Definition: ParticleMCS.h:179