-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetector.cpp
More file actions
91 lines (76 loc) · 2 KB
/
Detector.cpp
File metadata and controls
91 lines (76 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Description: Defines the Detector class for particle detection modeling
// Author: Leo Feasby
// Date: 15/03/2024
#include "Detector.h"
#include <iostream>
Detector::Detector()
: detector_type("tracker"), status(false)
{}
Detector::Detector(const std::string& type)
: status(false)
{
// Validate detector type before setting
if (type == "tracker" || type == "calorimeter" || type == "muon chamber")
{
this->detector_type = type;
}
else
{
std::cerr << "Invalid detector type. Setting to default 'tracker'.\n";
this->detector_type = "tracker"; // Default to tracker if invalid
}
}
Detector::~Detector() {}
void Detector::set_detector_type(const std::string& type)
{
// Validate detector type as in constructor
if (type == "tracker" || type == "calorimeter" || type == "muon chamber")
{
this->detector_type = type;
}
else
{
std::cerr << "Invalid detector type. No change made.\n";
}
}
void Detector::set_status(bool status)
{
this->status = status;
}
std::string Detector::get_detector_type() const
{
return this->detector_type;
}
bool Detector::get_status() const
{
return this->status;
}
void Detector::turn_on()
{
this->status = true;
}
void Detector::turn_off()
{
this->status = false;
}
int Detector::detect_particle(const Lepton& particle) const
{
if (!status)
{
std::cout << "Detector is off.\n";
return 0;
}
if ((detector_type == "tracker" && (particle.get_particle_type() == "electron" || particle.get_particle_type() == "muon")) ||
(detector_type == "calorimeter" && particle.get_particle_type() == "electron") ||
(detector_type == "muon chamber" && particle.get_particle_type() == "muon"))
{
std::cout << particle.get_particle_type() << (particle.get_charge() == 1 ? " (antiparticle)" : "") << " was detected\n";
return 1;
}
return 0;
}
void Detector::print_info() const
{
std::cout << "Detector Type: " << this->detector_type
<< "\nStatus: " << (this->status ? "On" : "Off") << '\n';
}