EGS Brachy
An egs++ user code for rapid brachytherapy calculations
Loading...
Searching...
No Matches
/Users/marc/Developer/EGSnrc/HEN_HOUSE/user_codes/egs_brachy/egs_brachy/latch.cpp
Go to the documentation of this file.
1/*
2################################################################################
3#
4# egs_brachy latch.cpp
5# Copyright (C) 2016 Rowan Thomson, Dave Rogers, Randle Taylor, and Marc
6# Chamberland
7#
8# This file is part of egs_brachy
9#
10# egs_brachy is free software: you can redistribute it and/or modify it
11# under the terms of the GNU Affero General Public License as published
12# by the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# egs_brachy is distributed in the hope that it will be useful, but
16# WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18# Affero General Public License for more details:
19# <http://www.gnu.org/licenses/>.
20#
21################################################################################
22#
23# When egs_brachy is used for publications, please cite our paper:
24# M. J. P. Chamberland, R. E. P. Taylor, D. W. O. Rogers, and R. M. Thomson,
25# egs brachy: a versatile and fast Monte Carlo code for brachytherapy,
26# Phys. Med. Biol. 61, 8214-8231 (2016).
27#
28################################################################################
29#
30# Author: Randle Taylor, 2016
31#
32# Contributors: Marc Chamberland
33# Dave Rogers
34# Rowan Thomson
35#
36################################################################################
37*/
38
44#include "latch.h"
45
46void Latch::setFlag(Flag flag, EGS_Particle *p) {
47 setFlag(flag, p->latch);
48}
49
50void Latch::setFlag(Flag flag, int &latch) {
51 latch |= (1 << flag);
52}
53
54void Latch::unsetFlag(Flag flag, EGS_Particle *p) {
55 unsetFlag(flag, p->latch);
56}
57
58void Latch::unsetFlag(Flag flag, int &latch) {
59 latch &= ~(1 << flag);
60}
61
62bool Latch::checkFlag(Flag flag, EGS_Particle *p) {
63 return checkFlag(flag, p->latch);
64}
65
66bool Latch::checkFlag(Flag flag, int latch) {
67 return latch & (1 << flag);
68}
69
70void Latch::update(EB_Message message, void *particle) {
71
72 if (message == PARTICLE_ESCAPED_SOURCE) {
73 EGS_Particle *p = static_cast<EGS_Particle *>(particle);
75 setPrimary(p);
76 }
77
78}
79
80void Latch::addScatter(EGS_Particle *p) {
81 addScatter(p->latch);
82}
83
84void Latch::setPrimary(EGS_Particle *p) {
85 setPrimary(p->latch);
86}
87
88void Latch::setPrimary(int &latch) {
89 setFlag(PRIM_PARTICLE, latch);
90}
91
92void Latch::addScatter(int &latch) {
93 if (checkFlag(PRIM_PARTICLE, latch)) {
95 setFlag(SSCAT_PARTICLE, latch);
96 } else if (checkFlag(SSCAT_PARTICLE, latch)) {
98 setFlag(MSCAT_PARTICLE, latch);
99 } else {
100 setFlag(SSCAT_PARTICLE, latch);
101 }
102}
103
104
105bool Latch::isPrimary(int latch) {
106 return checkFlag(PRIM_PARTICLE, latch);
107}
108
109bool Latch::isPrimary(EGS_Particle *p) {
110 return isPrimary(p->latch);
111}
112
113bool Latch::isSingleScat(int latch) {
114 return checkFlag(SSCAT_PARTICLE, latch) && !checkFlag(MSCAT_PARTICLE, latch);
115}
116
117bool Latch::isSingleScat(EGS_Particle *p) {
118 return isSingleScat(p->latch);
119}
120
121bool Latch::isMultScat(int latch) {
122 return checkFlag(MSCAT_PARTICLE, latch);
123}
124
125bool Latch::isMultScat(EGS_Particle *p) {
126 return isMultScat(p->latch);
127}
128
129/*bool Latch::inSource(EGS_Particle *p){
130 return checkFlag(IN_SOURCE, p);
131}
132*/
133
134bool Latch::hasEscaped(EGS_Particle *p) {
135 return checkFlag(ESCAPED_SOURCE, p);
136}
137
static bool hasEscaped(EGS_Particle *p)
True if particle is currently in a source.
Definition latch.cpp:134
static void setPrimary(int &latch)
Definition latch.cpp:88
static bool isMultScat(int latch)
Definition latch.cpp:121
static bool checkFlag(Flag flag, EGS_Particle *p)
Check whether flag is set on particle p.
Definition latch.cpp:62
static void addScatter(EGS_Particle *p)
Definition latch.cpp:80
Flag
Definition latch.h:53
@ PRIM_PARTICLE
Definition latch.h:60
@ MSCAT_PARTICLE
Definition latch.h:62
@ SSCAT_PARTICLE
Definition latch.h:61
@ ESCAPED_SOURCE
Definition latch.h:56
static bool isPrimary(int latch)
Definition latch.cpp:105
static bool isSingleScat(int latch)
Definition latch.cpp:113
static void unsetFlag(Flag flag, EGS_Particle *p)
Unset flag on input particle p.
Definition latch.cpp:54
void update(EB_Message message, void *particle)
listen to events and delegate to appropriate handler
Definition latch.cpp:70
static void setFlag(Flag flag, EGS_Particle *p)
Set flag on input particle p.
Definition latch.cpp:46
handle particles latch bits for egs_brachy
EB_Message
Definition pubsub.h:54
@ PARTICLE_ESCAPED_SOURCE
Definition pubsub.h:61