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
Smear::Detector::FillEventKinematics
void FillEventKinematics(Event *event)
Calculate event-wise smeared kinematics for an event which has already had its particles smeared and ...
Definition: Detector.cxx:82
erhic::EventDis::SetLeptonKinematics
virtual void SetLeptonKinematics(const DisKinematics &)
Set the kinematics computed from the scattered lepton.
Definition: EventDis.cxx:61
Smear::ParticleMCS::p
Double32_t p
Total momentum of particle.
Definition: ParticleMCS.h:178
Smear
Definition: Acceptance.cxx:16
Smear::ParticleMCS::pt
Double32_t pt
Transverse momentum of particle.
Definition: ParticleMCS.h:177
Smear::Detector::DeleteAllDevices
void DeleteAllDevices()
Delete all devices in the detector.
Definition: Detector.cxx:55
Smear::Detector::Accept
std::list< Smear::Smearer * > Accept(const erhic::VirtualParticle &) const
Returns the list of devices in this detector that accept a particle.
Definition: Detector.cxx:116
Smear::ParticleMCS::pz
Double32_t pz
z component of particle momentum
Definition: ParticleMCS.h:175
erhic::DisKinematics
A collection of DIS kinematic variables.
Definition: Kinematics.h:31
Smear::Event
Definition: smear/EventSmear.h:29
ParticleMCS.h
Smear::ParticleMCS::phi
Double32_t phi
Azimuthal angle.
Definition: ParticleMCS.h:180
EventDis.h
erhic::LeptonKinematicsComputer
Computes DIS event kinematics from the scattered lepton.
Definition: Kinematics.h:64
erhic::JacquetBlondelComputer
Computes DIS event kinematics from final-state hadrons using the Jacquet-Blondel method.
Definition: Kinematics.h:86
Smear::ParticleMCS::py
Double32_t py
y component of particle momentum
Definition: ParticleMCS.h:174
Smear::Detector::Detector
Detector()
Default contructor.
Definition: Detector.cxx:27
erhic::DoubleAngleComputer::Calculate
virtual DisKinematics * Calculate()
Definition: Kinematics.cxx:455
erhic::VirtualParticle::GetStatus
virtual UShort_t GetStatus() const =0
A general "status" code for the particle (definition depends on implementation).
Smear::Detector::GetNDevices
UInt_t GetNDevices() const
Returns the number of devices in the detector.
Definition: Detector.h:147
erhic::EventDis::SetDoubleAngleKinematics
virtual void SetDoubleAngleKinematics(const DisKinematics &)
Set the kinematics computed from the double-angle method.
Definition: EventDis.cxx:76
Smear::Detector::Print
virtual void Print(Option_t *="") const
Print information about all smearers to standard output.
Definition: Detector.cxx:162
Smear::Detector
The detector structure.
Definition: Detector.h:44
VirtualParticle.h
erhic::VirtualParticle
Abstract base class for a general particle.
Definition: VirtualParticle.h:23
EventSmear.h
Smearer.h
Smear::Smearer
Abstract base class for objects performing smearing.
Definition: Smearer.h:33
Smear::Detector::useJB
bool useJB
Definition: Detector.h:140
Smear::Detector::~Detector
virtual ~Detector()
Destructor.
Definition: Detector.cxx:51
erhic::EventDis::SetJacquetBlondelKinematics
virtual void SetJacquetBlondelKinematics(const DisKinematics &)
Set the kinematics computed from the Jacquet-Blondel method.
Definition: EventDis.cxx:69
Smear::ParticleMCS
A smeared Monte Carlo particle.
Definition: ParticleMCS.h:27
erhic::LeptonKinematicsComputer::Calculate
virtual DisKinematics * Calculate()
Definition: Kinematics.cxx:253
Smear::ParticleMCS::theta
Double32_t theta
Polar angle.
Definition: ParticleMCS.h:179
erhic::JacquetBlondelComputer::Calculate
virtual DisKinematics * Calculate()
Definition: Kinematics.cxx:332
Smear::Detector::Devices
std::vector< Smearer * > Devices
Definition: Detector.h:142
Smear::Detector::SetEventKinematicsCalculator
void SetEventKinematicsCalculator(TString)
Set the method for calculating event kinematics if FillEventKinematics is used.
Definition: Detector.cxx:67
Smear::Detector::useDA
bool useDA
Definition: Detector.h:141
Smear::Detector::AddDevice
void AddDevice(Smearer &device)
Adds a copy of the smearing device to this detector.
Definition: Detector.cxx:63
Smear::Detector::Smear
ParticleMCS * Smear(const erhic::VirtualParticle &) const
Detector level particle smearing.
Definition: Detector.cxx:132
erhic::DoubleAngleComputer
Computes DIS event kinematics from a mixture of hadronic and lepton variables using the double-angle ...
Definition: Kinematics.h:117
Smear::Detector::operator=
Detector & operator=(const Detector &)
Assignment operator.
Definition: Detector.cxx:41
Smear::Event::ScatteredLepton
virtual const ParticleMCS * ScatteredLepton() const
Returns a pointer to the lepton beam particle after scattering.
Definition: smear/EventSmear.cxx:44
Smear::Detector::CopyDevices
std::vector< Smear::Smearer * > CopyDevices() const
Returns pointers to new copies of all devices.
Definition: Detector.cxx:154
Smear::Smearer::Clone
virtual Smearer * Clone(const char *="") const =0
Inherited from TObject.
Smear::Detector::useNM
bool useNM
Definition: Detector.h:139
Smear::Detector::GetDevice
Smearer * GetDevice(int index)
Return a pointer to device number n from the detector.
Definition: Detector.cxx:74
Smear::ParticleMCS::px
Double32_t px
x component of particle momentum
Definition: ParticleMCS.h:173
Detector.h
Kinematics.h