Line data Source code
1 : #ifndef CRPROPA_OBSERVER_H 2 : #define CRPROPA_OBSERVER_H 3 : 4 : #include <fstream> 5 : #include <limits> 6 : #include <string> 7 : #include <vector> 8 : 9 : #include "../Candidate.h" 10 : #include "../Module.h" 11 : #include "../Referenced.h" 12 : #include "../Vector3.h" 13 : #include "../Geometry.h" 14 : 15 : namespace crpropa { 16 : 17 : enum DetectionState { 18 : DETECTED, VETO, NOTHING 19 : }; 20 : 21 : /** \addtogroup Observer 22 : * @{ 23 : */ 24 : 25 : 26 : /** 27 : @class ObserverFeature 28 : @brief Abstract base class for features of observers 29 : */ 30 1 : class ObserverFeature: public Referenced { 31 : protected: 32 : std::string description; 33 : public: 34 : virtual DetectionState checkDetection(Candidate *candidate) const; 35 : virtual void onDetection(Candidate *candidate) const; 36 : virtual std::string getDescription() const; 37 : }; 38 : 39 : 40 : /** 41 : @class Observer 42 : @brief General particle observer 43 : */ 44 : class Observer: public Module { 45 : std::string flagKey; 46 : std::string flagValue; 47 : private: 48 : std::vector<ref_ptr<ObserverFeature> > features; 49 : ref_ptr<Module> detectionAction; 50 : bool clone; 51 : bool makeInactive; 52 : public: 53 : /** Default observer constructor 54 : */ 55 : Observer(); 56 : /** Add a feature to the observer 57 : @param feature observer feature to be added to the Observer object 58 : */ 59 : void add(ObserverFeature *feature); 60 : /** Perform some specific actions upon detection of candidate 61 : @param action module that performs a given action when candidate is detected 62 : @param clone if true, clone candidate 63 : */ 64 : void onDetection(Module *action, bool clone = false); 65 : void process(Candidate *candidate) const; 66 : std::string getDescription() const; 67 : void setFlag(std::string key, std::string value); 68 : /** Determine whether candidate should be deactivated on detection 69 : @param deactivate if true, deactivate detected particles; if false, continue tracking them 70 : */ 71 : void setDeactivateOnDetection(bool deactivate); 72 : }; 73 : 74 : 75 : /** 76 : @class ObserverDetectAll 77 : @brief Detects all particles 78 : */ 79 2 : class ObserverDetectAll: public ObserverFeature { 80 : public: 81 : DetectionState checkDetection(Candidate *candidate) const; 82 : std::string getDescription() const; 83 : }; 84 : 85 : 86 : /** 87 : @class ObserverSurface 88 : @brief Detects particles crossing the boundaries of a defined surface (see, e.g., `Geometry` module) 89 : */ 90 : class ObserverSurface: public ObserverFeature { 91 : private: 92 : ref_ptr<Surface> surface; 93 : public: 94 : /** Constructor 95 : @param surface object with some specific geometric (see Geometry.h) 96 : */ 97 : ObserverSurface(Surface* surface); 98 : DetectionState checkDetection(Candidate *candidate) const; 99 : std::string getDescription() const; 100 : }; 101 : 102 : 103 : /** 104 : @class ObserverTracking 105 : @brief Tracks particles inside a sphere 106 : */ 107 : class ObserverTracking: public ObserverFeature { 108 : private: 109 : Vector3d center; 110 : double radius; 111 : double stepSize; 112 : public: 113 : /** Constructor 114 : @param center vector containing the coordinates of the center of the sphere 115 : @param radius radius of the sphere 116 : @param stepSize observer will keep track of particles at every step with this size 117 : */ 118 : ObserverTracking(Vector3d center, double radius, double stepSize = 0); 119 : DetectionState checkDetection(Candidate *candidate) const; 120 : std::string getDescription() const; 121 : }; 122 : 123 : 124 : /** 125 : @class Observer1D 126 : @brief Detects particles when reaching x = 0 127 : 128 : This module detects particles when reaching x = 0 and also limits the next step size to prevent candidates from overshooting. 129 : */ 130 3 : class Observer1D: public ObserverFeature { 131 : public: 132 : DetectionState checkDetection(Candidate *candidate) const; 133 : std::string getDescription() const; 134 : }; 135 : 136 : 137 : /** 138 : @class ObserverRedshiftWindow 139 : @brief Detects particles in a given redshift window 140 : 141 : When added to an observer, this feature generalizes it to four dimensions. 142 : The fourth dimension is the redshift, a proxy for time. This is particularly 143 : useful in "4D" studies, including either time-dependence (e.g. flaring objects), 144 : or in 3D studies including cosmological evolution. 145 : Note that redshifts should be assigned to sources when using this feature. 146 : This can be done with: SourceRedshift, SourceRedshift1D, SourceUniformRedshift, 147 : and SourceRedshiftEvolution. 148 : */ 149 : class ObserverRedshiftWindow: public ObserverFeature { 150 : private: 151 : double zmin, zmax; 152 : public: 153 : /** Constructor 154 : @param zmin lower bound of redshift interval 155 : @param zmax upper bound of redshift interval 156 : */ 157 : ObserverRedshiftWindow(double zmin = 0, double zmax = 0.1); 158 : DetectionState checkDetection(Candidate *candidate) const; 159 : std::string getDescription() const; 160 : }; 161 : 162 : 163 : /** 164 : @class ObserverInactiveVeto 165 : @brief Veto for inactive candidates 166 : */ 167 0 : class ObserverInactiveVeto: public ObserverFeature { 168 : public: 169 : DetectionState checkDetection(Candidate *candidate) const; 170 : std::string getDescription() const; 171 : }; 172 : 173 : 174 : /** 175 : @class ObserverNucleusVeto 176 : @brief Veto for nuclei (including protons and neutrons) 177 : */ 178 0 : class ObserverNucleusVeto: public ObserverFeature { 179 : public: 180 : DetectionState checkDetection(Candidate *candidate) const; 181 : std::string getDescription() const; 182 : }; 183 : 184 : 185 : /** 186 : @class ObserverNeutrinoVeto 187 : @brief Veto for neutrinos 188 : */ 189 0 : class ObserverNeutrinoVeto: public ObserverFeature { 190 : public: 191 : DetectionState checkDetection(Candidate *candidate) const; 192 : std::string getDescription() const; 193 : }; 194 : 195 : 196 : /** 197 : @class ObserverPhotonVeto 198 : @brief Veto for photons 199 : */ 200 0 : class ObserverPhotonVeto: public ObserverFeature { 201 : public: 202 : DetectionState checkDetection(Candidate *candidate) const; 203 : std::string getDescription() const; 204 : }; 205 : 206 : 207 : /** 208 : @class ObserverElectronVeto 209 : @brief Veto for electrons and positrons 210 : */ 211 0 : class ObserverElectronVeto: public ObserverFeature { 212 : public: 213 : DetectionState checkDetection(Candidate *candidate) const; 214 : std::string getDescription() const; 215 : }; 216 : 217 : 218 : /** 219 : @class ObserverParticleIdVeto 220 : @brief Custom veto for user-defined particle types 221 : Vetoes for more than one type of particle can be added by calling this 222 : feature multiple times. 223 : */ 224 : class ObserverParticleIdVeto: public ObserverFeature { 225 : private: 226 : int vetoParticleId; 227 : public: 228 : /** Constructor 229 : @param id id of the particle following the PDG numbering scheme 230 : */ 231 : ObserverParticleIdVeto(int id); 232 : DetectionState checkDetection(Candidate *candidate) const; 233 : std::string getDescription() const; 234 : }; 235 : 236 : 237 : /** 238 : @class ObserverTimeEvolution 239 : @brief Observes the time evolution of the candidates (phase-space elements) 240 : This observer is very useful if the time evolution of the particle density is needed. It detects all candidates in lin-spaced, log-spaced, or user-defined time intervals and limits the nextStep of candidates to prevent overshooting of detection intervals. 241 : */ 242 : class ObserverTimeEvolution: public ObserverFeature { 243 : private: 244 : std::vector<double> detList; 245 : public: 246 : /** Default constructor 247 : */ 248 : ObserverTimeEvolution(); 249 : /** Constructor 250 : @param min minimum time 251 : @param dist time interval for detection 252 : @param numb number of time intervals 253 : */ 254 : ObserverTimeEvolution(double min, double dist, double numb); 255 : /** Constructor 256 : @param min minimum time 257 : @param max maximum time 258 : @param numb number of time intervals 259 : @param log log (input: true) or lin (input: false) scaling between min and max with numb steps 260 : */ 261 : ObserverTimeEvolution(double min, double max, double numb, bool log); 262 : // Add a new time step to the detection time list of the observer 263 : void addTime(const double &position); 264 : // Using log or lin spacing of times in the range between min and 265 : // max for observing particles 266 : void addTimeRange(double min, double max, double numb, bool log = false); 267 : const std::vector<double>& getTimes() const; 268 : DetectionState checkDetection(Candidate *candidate) const; 269 : std::string getDescription() const; 270 : }; 271 : /** @} */ 272 : 273 : } 274 : 275 : #endif // CRPROPA_OBSERVER_H