source: trunk/documents/UserDoc/DocBookUsersGuides/ForApplicationDeveloper/xml/Fundamentals/biasing.xml @ 1222

Last change on this file since 1222 was 1222, checked in by garnier, 15 years ago

CVS update

File size: 54.2 KB
Line 
1<!-- ******************************************************** -->
2<!--                                                          -->
3<!--  [History]                                               -->
4<!--    New section on Reverse MC: L. Desorgher, Dec-2009     -->
5<!--    Converted to DocBook: Katsuya Amako, Aug-2006         -->
6<!--    Changed by: Dennis Wright, 25-Jun-2002                -->
7<!--                                                          -->
8<!-- ******************************************************** -->
9
10
11<!-- ******************* Section (Level#1) ****************** -->
12<sect1 id="sect.EvtBias">
13<title>
14Event Biasing Techniques
15</title>
16
17<!-- ******************* Section (Level#2) ****************** -->
18<sect2 id="sect.EvtBias.ScorImpRoul">
19<title>
20Scoring, Geometrical Importance Sampling and Weight Roulette
21</title>
22
23<para>
24Geant4 provides event biasing techniques which may be used to save
25computing time in such applications as the simulation of radiation
26shielding. These are <emphasis>geometrical splitting
27</emphasis> and <emphasis>Russian roulette</emphasis> 
28(also called geometrical importance sampling), and
29<emphasis>weight roulette</emphasis>. Scoring is carried out by <emphasis>G4MultiFunctionalDetector</emphasis> (see <xref
30linkend="sect.Hits.G4Multi" /> and <xref linkend="sect.Hits.G4VPrim" />) using the standard Geant4 scoring technique.
31Biasing specific scorers have been implemented and are described within
32<emphasis>G4MultiFunctionDetector</emphasis> documentation. In this chapter, it is assumed that
33the reader is familiar with both the usage of Geant4 and the
34concepts of importance sampling. More detailed documentation may be
35found in the documents
36<ulink url="http://geant4.cern.ch/collaboration/working_groups/geometry/biasing/Sampling.html">
37'Scoring, geometrical importance sampling and weight roulette'
38</ulink>.
39A detailed description of different use-cases which employ the sampling
40and scoring techniques can be found in the document
41<ulink url="http://geant4.cern.ch/collaboration/working_groups/geometry/biasing/BiasScoreUseCases.html">
42'Use cases of importance sampling and scoring in Geant4'
43</ulink>.
44</para>
45
46<para>
47The purpose of importance sampling is to save computing time by
48sampling less often the particle histories entering "less
49important" geometry regions, and more often in more "important"
50regions. Given the same amount of computing time, an
51importance-sampled and an analogue-sampled simulation must show
52equal mean values, while the importance-sampled simulation will
53have a decreased variance.
54</para>
55
56<para>
57The implementation of scoring is independent of the implementation
58of importance sampling. However both share common concepts.
59<emphasis>Scoring and importance sampling apply to particle types chosen
60by the user</emphasis>, which should be borne in mind when interpreting the
61output of any biased simulation.
62</para>
63
64<para>
65Examples on how to use scoring and importance sampling may be found
66in <literal>examples/extended/biasing</literal>.
67</para>
68
69
70<!-- ******************* Section (Level#3) ****************** -->
71<sect3 id="sect.EvtBias.ScorImpRoul.Geom">
72<title>
73Geometries
74</title>
75
76<para>
77The kind of scoring referred to in this note and the importance
78sampling apply to spatial cells provided by the user.
79</para>
80
81<para>
82A <emphasis role="bold">cell</emphasis> is a physical volume (further specified
83by it's replica number, if the volume is a replica). Cells may be defined
84in two kinds of geometries:
85
86<orderedlist spacing="compact">
87  <listitem><para>
88    <emphasis role="bold">mass geometry</emphasis>: the geometry setup of the
89    experiment to be simulated. Physics processes apply to this geometry.
90  </para></listitem>
91  <listitem><para>
92    <emphasis role="bold">parallel-geometry</emphasis>: a geometry constructed
93    to define the physical volumes according to which scoring and/or importance
94    sampling is applied.
95  </para></listitem>
96</orderedlist>
97</para>
98
99<para>
100The user has the choice to score and/or sample by importance the
101particles of the chosen type, according to mass geometry or to
102parallel geometry. It is possible to utilize several parallel
103geometries in addition to the mass geometry. This provides the user
104with a lot of flexibility to define separate geometries for
105different particle types in order to apply scoring or/and
106importance sampling.
107</para>
108
109<para>
110<note>
111  Parallel geometries should be constructed using the implementation as
112  described in <xref linkend="sect.ParaGeom"/>.
113
114  There are a few conditions for parallel geometries:
115
116  <itemizedlist spacing="compact">
117  <listitem><para>
118    The world volume for parallel and mass geometries must be identical copies.
119  </para></listitem>
120  <listitem><para>
121    Scoring and importance cells must not share boundaries with the world volume.
122  </para></listitem>
123  </itemizedlist>
124</note>
125</para>
126
127</sect3>
128
129<!-- ******************* Section (Level#3) ****************** -->
130<sect3 id="sect.EvtBias.ScorImpRoul.ChgSamp">
131<title>
132Changing the Sampling
133</title>
134
135<para>
136Samplers are higher level tools which perform the necessary
137changes of the Geant4 sampling in order to apply importance
138sampling and weight roulette.
139</para>
140
141<para>
142Variance reduction (and scoring through the
143<emphasis>G4MultiFunctionalDetector</emphasis>)
144may be combined arbitrarily for chosen particle types and may be applied to the
145mass or to parallel geometries.
146</para>
147
148<para>
149The <literal>G4GeometrySampler</literal> can be applied equally to mass or
150parallel geometries with an abstract interface supplied by <literal>G4VSampler</literal>.
151<literal>G4VSampler</literal> provides
152<literal>Prepare...</literal> methods and a <literal>Configure</literal>
153method:
154
155<anchor id="anchor_EvtBias_G4VSampler" />
156<informalexample>
157<programlisting>
158 class G4VSampler
159 {
160   public: 
161    G4VSampler();
162    virtual ~G4VSampler();
163    virtual void PrepareImportanceSampling(G4VIStore *istore,
164                                           const G4VImportanceAlgorithm
165                                           *ialg = 0) = 0;
166    virtual void PrepareWeightRoulett(G4double wsurvive = 0.5,
167                                      G4double wlimit = 0.25,
168                                      G4double isource = 1) = 0;
169    virtual void PrepareWeightWindow(G4VWeightWindowStore *wwstore,
170                                     G4VWeightWindowAlgorithm *wwAlg = 0,
171                                     G4PlaceOfAction placeOfAction =
172                                     onBoundary) = 0;
173    virtual void Configure() = 0;
174    virtual void ClearSampling() = 0;
175    virtual G4bool IsConfigured() const = 0;
176 };
177</programlisting>
178</informalexample>
179</para>
180
181<para>
182The methods for setting up the desired combination need specific
183information:
184
185<itemizedlist spacing="compact">
186  <listitem><para>
187    Importance sampling: message <literal>PrepareImportanceSampling</literal>
188    with a
189    <link linkend="anchor_EvtBias_G4VIStore">
190    <literal>G4VIStore</literal></link>
191    and optionally a <literal>G4VImportanceAlgorithm</literal>
192  </para></listitem>
193  <listitem><para>
194    Weight window: message <literal>PrepareWeightWindow</literal> with the
195    arguments:
196    <itemizedlist spacing="compact">
197      <listitem><para>
198        <emphasis>*wwstore</emphasis>: a
199        <literal>G4VWeightWindowStore</literal> for retrieving the lower
200        weight bounds for the energy-space cells
201      </para></listitem>
202      <listitem><para>
203        <emphasis>*wwAlg</emphasis>: a
204        <literal>G4VWeightWindowAlgorithm</literal> if a customized algorithm
205        should be used
206      </para></listitem>
207      <listitem><para>
208        <emphasis>placeOfAction</emphasis>: a
209        <literal>G4PlaceOfAction</literal> specifying where to perform the
210        biasing
211      </para></listitem>
212    </itemizedlist>
213  </para></listitem>
214  <listitem><para>
215    Weight roulette: message <literal>PrepareWeightRoulett</literal> with the
216    optional parameters:
217    <itemizedlist spacing="compact">
218      <listitem><para>
219        <emphasis>wsurvive</emphasis>: survival weight
220      </para></listitem>
221      <listitem><para>
222        <emphasis>wlimit</emphasis>: minimal allowed
223        value of weight * source importance / cell importance
224      </para></listitem>
225      <listitem><para>
226        <emphasis>isource</emphasis>: importance of the source cell
227      </para></listitem>
228    </itemizedlist>
229  </para></listitem>
230</itemizedlist>
231</para>
232
233<para>
234Each object of a sampler class is responsible for one particle
235type. The particle type is given to the constructor of the sampler
236classes via the particle type name, e.g. "neutron". Depending on
237the specific purpose, the <literal>Configure()</literal> of a sampler will
238set up specialized processes (derived from <literal>G4VProcess</literal>) for
239transportation in the parallel geometry, importance
240sampling and weight roulette for the given particle type. When
241<literal>Configure()</literal> is invoked the sampler places the processes in
242the correct order independent of the order in which user invoked
243the <literal>Prepare...</literal> methods.
244</para>
245
246<para>
247<note>
248  <para>
249  <itemizedlist spacing="compact">
250  <listitem><para>
251    The <literal>Prepare...()</literal> functions may each only be invoked
252    once.
253  </para></listitem>
254  <listitem><para>
255    To configure the sampling the function <literal>Configure()</literal>
256    must be called <emphasis>after</emphasis> the
257    <literal>G4RunManager</literal> has been initialized and the PhysicsList has
258    been instantiated.
259  </para></listitem>
260  </itemizedlist>
261  </para>
262</note>
263</para>
264
265
266
267
268<para>
269The interface and framework are demonstrated in the
270<literal>examples/extended/biasing</literal> directory, with the main changes being to the
271G4GeometrySampler class and the fact that in the parallel case the WorldVolume
272is a copy of the Mass World.
273
274The parallel geometry now has to inherit from
275<emphasis>G4VUserParallelWorld</emphasis> which also has the <emphasis>GetWorld()</emphasis> method
276in order to retrieve a copy of the mass geometry WorldVolume.
277
278<informalexample>
279<programlisting>
280  class B02ImportanceDetectorConstruction : public G4VUserParallelWorld
281  ghostWorld = GetWorld();
282</programlisting>
283</informalexample>
284
285</para>
286
287<para>
288The constructor for <emphasis>G4GeometrySampler</emphasis> takes a pointer to
289the physical world volume and the particle type name (e.g. "neutron") as arguments.
290In a single mass geometry the sampler is created as follows:
291
292<informalexample>
293<programlisting>
294  G4GeometrySampler mgs(detector->GetWorldVolume(),"neutron");
295  mgs.SetParallel(false);
296</programlisting>
297</informalexample>
298
299
300Whilst the following lines of code are required in order to set up the sampler for the
301parallel geometry case:
302
303<informalexample>
304<programlisting>
305  G4VPhysicalVolume* ghostWorld = pdet->GetWorldVolume();
306
307  G4GeometrySampler pgs(ghostWorld,"neutron");
308
309  pgs.SetParallel(true);
310</programlisting>
311</informalexample>
312
313
314Also note that the preparation and configuration of the samplers has to be
315carried out <emphasis>after</emphasis> the instantiation of the UserPhysicsList
316and after the initialisation of the <emphasis>G4RunManager</emphasis>:
317
318<informalexample>
319<programlisting>
320  pgs.PrepareImportanceSampling(&amp;aIstore, 0);
321  pgs.Configure();
322</programlisting>
323</informalexample>
324
325Due to the fact that biasing is a process and has to be inserted after all the
326other processes have been created.
327</para>
328
329
330</sect3>
331
332<!-- ******************* Section (Level#3) ****************** -->
333<sect3 id="sect.EvtBias.ScorImpRoul.ImpSamp">
334<title>
335Importance Sampling
336</title>
337
338<para>
339Importance sampling acts on particles crossing boundaries
340between "importance cells". The action taken depends on the
341importance values assigned to the cells. In general a particle
342history is either split or Russian roulette is played if the
343importance increases or decreases, respectively. A weight assigned
344to the history is changed according to the action taken.
345</para>
346
347<para>
348The tools provided for importance sampling require the user to
349have a good understanding of the physics in the problem. This is
350because the user has to decide which particle types require
351importance sampled, define the cells, and assign importance values
352to the cells. If this is not done properly the results cannot be
353expected to describe a real experiment.
354</para>
355
356<para>
357The assignment of importance values to a cell is done using an
358importance store described below.
359</para>
360
361<para>
362An "importance store" with the interface <literal>G4VIStore</literal> is
363used to store importance values related to cells. In order to do
364importance sampling the user has to create an object (e.g. of class
365<literal>G4IStore</literal>) of type <literal>G4VIStore</literal>. The samplers may be
366given a <literal>G4VIStore</literal>. The user fills the store with cells and
367their importance values.
368</para>
369
370<para>
371An importance store has to be constructed with a reference to
372the world volume of the geometry used for importance sampling. This
373may be the world volume of the mass or of a parallel geometry.
374Importance stores derive from the interface <literal>G4VIStore</literal>:
375
376<anchor id="anchor_EvtBias_G4VIStore" />
377<informalexample>
378<programlisting>
379 class  G4VIStore
380 {
381   public:
382     G4VIStore();
383     virtual  ~G4VIStore();
384     virtual G4double GetImportance(const G4GeometryCell &amp;gCell) const = 0;
385     virtual G4bool IsKnown(const G4GeometryCell &amp;gCell) const = 0;
386     virtual const G4VPhysicalVolume &amp;GetWorldVolume() const = 0;
387 };
388</programlisting>
389</informalexample>
390</para>
391
392<para>
393A concrete implementation of an importance store is provided by
394the class <literal>G4VStore</literal>. The <emphasis>public</emphasis>
395part of the class is:
396
397<informalexample>
398<programlisting>
399 class G4IStore : public G4VIStore
400 {
401   public:
402     explicit G4IStore(const G4VPhysicalVolume &amp;worldvolume);
403     virtual ~G4IStore();
404     virtual G4double GetImportance(const G4GeometryCell &amp;gCell) const;
405     virtual G4bool IsKnown(const G4GeometryCell &amp;gCell) const;
406     virtual const G4VPhysicalVolume &amp;GetWorldVolume() const;
407     void AddImportanceGeometryCell(G4double importance,
408                              const G4GeometryCell &amp;gCell);
409     void AddImportanceGeometryCell(G4double importance,
410                              const G4VPhysicalVolume &amp;,
411                                    G4int aRepNum = 0);
412     void ChangeImportance(G4double importance,
413                           const G4GeometryCell &amp;gCell);
414     void ChangeImportance(G4double importance,
415                           const G4VPhysicalVolume &amp;,
416                                 G4int aRepNum = 0);
417     G4double GetImportance(const G4VPhysicalVolume &amp;,
418                                  G4int aRepNum = 0) const ;
419   private: .....
420 };
421</programlisting>
422</informalexample>
423</para>
424
425<para>
426The member function <literal>AddImportanceGeometryCell()</literal> enters
427a cell and an importance value into the importance store. The
428importance values may be returned either according to a physical
429volume and a replica number or according to a
430<literal>G4GeometryCell</literal>. The user must be aware of the
431interpretation of assigning importance values to a cell.
432If scoring is also implemented then this is attached to logical volumes, in
433which case the physical volume and replica number method should be used for
434assigning importance values. See <literal>examples/extended/biasing
435B01</literal> and <literal>B02</literal> for examples of this.
436</para>
437
438<para>
439<note>
440  <para>
441  <itemizedlist spacing="compact">
442  <listitem><para>
443    An importance value must be assigned to every cell.
444  </para></listitem>
445  </itemizedlist>
446  </para>
447</note>
448</para>
449
450<para>
451The different cases:
452
453<itemizedlist spacing="compact">
454  <listitem><para>
455    <emphasis>Cell is not in store</emphasis>
456    <para>
457    Not filling a certain cell in the store will cause an
458    exception.
459    </para>
460  </para></listitem>
461  <listitem><para>
462    <emphasis>Importance value = zero</emphasis>
463    <para>
464    Tracks of the chosen particle type will be killed.
465    </para>
466  </para></listitem>
467  <listitem><para>
468    <emphasis>importance values &gt; 0</emphasis>
469    <para>
470    Normal allowed values
471    </para>
472  </para></listitem>
473  <listitem><para>
474    <emphasis>Importance value smaller zero</emphasis>
475    <para>
476    Not allowed!
477    </para>
478  </para></listitem>
479</itemizedlist>
480</para>
481
482</sect3>
483
484<!-- ******************* Section (Level#3) ****************** -->
485<sect3 id="sect.EvtBias.ScorImpRoul.SampAlgor">
486<title>
487The Importance Sampling Algorithm
488</title>
489
490<para>
491Importance sampling supports using a customized importance
492sampling algorithm. To this end, the sampler interface
493<link linkend="anchor_EvtBias_G4VSampler">
494<literal>G4VSampler</literal></link>
495may be given a pointer to the interface
496<literal>G4VImportanceAlgorithm</literal>:
497
498<informalexample>
499<programlisting>     
500 class G4VImportanceAlgorithm
501 {
502   public: 
503     G4VImportanceAlgorithm();
504     virtual ~G4VImportanceAlgorithm();
505     virtual G4Nsplit_Weight Calculate(G4double ipre,
506                                       G4double ipost,
507                                       G4double init_w) const = 0;
508 };
509</programlisting>
510</informalexample>     
511</para>
512
513<para>
514The method <literal>Calculate()</literal> takes the arguments:
515
516<itemizedlist spacing="compact">
517  <listitem><para>
518    <emphasis>ipre, ipost</emphasis>: importance
519    of the previous cell and the importance of the current cell,
520    respectively.
521  </para></listitem>
522  <listitem><para>
523    <emphasis>init_w</emphasis>: the particles weight
524  </para></listitem>
525</itemizedlist>
526</para>
527
528<para>
529It returns the struct:
530
531<informalexample>
532<programlisting>     
533 class G4Nsplit_Weight
534 {
535   public:
536
537   G4int fN;
538   G4double fW;
539 };
540</programlisting>
541</informalexample>     
542
543<itemizedlist spacing="compact">
544  <listitem><para>
545    <emphasis>fN</emphasis>: the calculated
546    number of particles to exit the importance sampling
547  </para></listitem>
548  <listitem><para>
549    <emphasis>fW</emphasis>: the weight of the particles
550  </para></listitem>
551</itemizedlist>
552</para>
553
554<para>
555The user may have a customized algorithm used by providing a
556class inheriting from <literal>G4VImportanceAlgorithm</literal>.
557</para>
558
559<para>
560If no customized algorithm is given to the sampler the default
561importance sampling algorithm is used. This algorithm is
562implemented in <literal>G4ImportanceAlgorithm</literal>.
563</para>
564
565</sect3>
566
567<!-- ******************* Section (Level#3) ****************** -->
568<sect3 id="sect.EvtBias.ScorImpRoul.WeightWin">
569<title>
570The Weight Window Technique
571</title>
572
573<para>
574The weight window technique is a weight-based alternative to
575importance sampling:
576
577<itemizedlist spacing="compact">
578  <listitem><para>
579    applies splitting and Russian roulette depending on space
580    (cells) and energy
581  </para></listitem>
582  <listitem><para>
583    user defines weight windows in contrast to defining importance
584    values as in importance sampling
585  </para></listitem>
586</itemizedlist>
587</para>
588
589<para>
590In contrast to importance sampling this technique is not weight
591blind. Instead the technique is applied according to the particle
592weight with respect to the current energy-space cell.
593</para>
594
595<para>
596Therefore the technique is convenient to apply in combination
597with other variance reduction techniques such as cross-section
598biasing and implicit capture.
599</para>
600
601<para>
602A weight window may be specified for every cell and for several
603energy regions: <emphasis>space-energy cell</emphasis>.
604
605<figure id="fig.EvtBias.WeightWindow">
606<title>
607  Weight window concept
608</title>
609
610<mediaobject>
611 <imageobject role="fo">
612    <imagedata fileref="./AllResources/Fundamentals/wwconcept.jpg"
613               format="JPG" contentwidth="9.0cm" align="center" />
614  </imageobject>
615  <imageobject role="html">
616    <imagedata fileref="./AllResources/Fundamentals/wwconcept.jpg"
617               format="JPG" align="center" />
618  </imageobject>
619  <textobject>
620    <phrase>Weight window concept</phrase>
621  </textobject>
622</mediaobject>
623</figure>
624</para>
625
626<!-- ******* Bridgehead ******* -->
627<bridgehead renderas='sect4'>
628Weight window concept
629</bridgehead>
630
631<para>
632  The user specifies a <emphasis>lower weight bound W_L</emphasis> 
633  for every space-energy cell.
634
635  <itemizedlist spacing="compact">
636    <listitem><para>
637      The upper weight bound W_U and the survival weight W_S are
638      calculated as:
639      <para>
640      W_U = C_U <emphasis>W_L</emphasis> and
641      </para>
642      <para>
643      W_S = C_S <emphasis>W_L</emphasis>.
644      </para>
645    </para></listitem>
646    <listitem><para>
647      The user specifies C_S and C_U once for the whole problem.
648    </para></listitem>
649    <listitem><para>
650      The user may give different sets of energy bounds for every cell
651      or one set for all geometrical cells
652    </para></listitem>
653    <listitem><para>
654      Special case: if C_S = C_U = 1 for all energies then weight
655      window is equivalent to importance sampling
656    </para></listitem>
657    <listitem><para>
658      The user can choose to apply the technique: at boundaries, on
659      collisions or on boundaries and collisions
660    </para></listitem>
661  </itemizedlist>
662</para>
663
664<para>
665The energy-space cells are realized by <literal>G4GeometryCell</literal>
666as in importance sampling. The cells are stored in a weight window
667store defined by <literal>G4VWeightWindowStore</literal>:
668
669<informalexample>
670<programlisting>
671 class  G4VWeightWindowStore {
672  public: 
673    G4VWeightWindowStore();
674    virtual  ~G4VWeightWindowStore();
675    virtual G4double GetLowerWeitgh(const G4GeometryCell &amp;gCell,
676                                  G4double partEnergy) const = 0;
677    virtual G4bool IsKnown(const G4GeometryCell &amp;gCell) const = 0;
678    virtual const G4VPhysicalVolume &amp;GetWorldVolume() const = 0;
679 };
680</programlisting>
681</informalexample>
682</para>
683
684<para>
685A concrete implementation is provided:
686
687<informalexample>
688<programlisting>
689  class G4WeightWindowStore: public G4VWeightWindowStore {
690   public: 
691     explicit G4WeightWindowStore(const G4VPhysicalVolume &amp;worldvolume);
692     virtual ~G4WeightWindowStore();
693     virtual G4double GetLowerWeitgh(const G4GeometryCell &amp;gCell,
694                                     G4double partEnergy) const;
695     virtual G4bool IsKnown(const G4GeometryCell &amp;gCell) const;
696     virtual const G4VPhysicalVolume &amp;GetWorldVolume() const;
697     void AddLowerWeights(const G4GeometryCell &amp;gCell,
698                          const std::vector&lt;G4double&gt; &amp;lowerWeights);
699     void AddUpperEboundLowerWeightPairs(const G4GeometryCell &amp;gCell,
700                                         const G4UpperEnergyToLowerWeightMap&amp;
701                                         enWeMap);
702     void SetGeneralUpperEnergyBounds(const
703         std::set&lt;G4double, std::less&lt;G4double&gt; &gt; &amp; enBounds);
704 
705   private::
706   ... 
707  };
708</programlisting>
709</informalexample>
710</para>
711
712<para>
713The user may choose equal energy bounds for all cells. In this
714case a set of upper energy bounds must be given to the store using
715the method <literal>SetGeneralUpperEnergyBounds</literal>. If a general set
716of energy bounds have been set <literal>AddLowerWeights</literal> can be used
717to add the cells.
718</para>
719
720<para>
721Alternatively, the user may chose different energy regions for
722different cells. In this case the user must provide a mapping of
723upper energy bounds to lower weight bounds for every cell using the
724method <literal>AddUpperEboundLowerWeightPairs</literal>.
725</para>
726
727<para>
728Weight window algorithms implementing the interface class
729<literal>G4VWeightWindowAlgorithm</literal> can be used to define a
730customized algorithm:
731
732<informalexample>
733<programlisting>
734 class G4VWeightWindowAlgorithm {
735  public: 
736    G4VWeightWindowAlgorithm();
737    virtual ~G4VWeightWindowAlgorithm();
738    virtual G4Nsplit_Weight Calculate(G4double init_w,
739                                      G4double lowerWeightBound) const = 0;
740 };
741</programlisting>
742</informalexample>
743</para>
744
745<para>
746A concrete implementation is provided and used as a default:
747
748<informalexample>
749<programlisting>
750 class G4WeightWindowAlgorithm : public G4VWeightWindowAlgorithm {
751  public: 
752    G4WeightWindowAlgorithm(G4double upperLimitFaktor = 5,
753                            G4double survivalFaktor = 3,
754                            G4int maxNumberOfSplits = 5);
755    virtual ~G4WeightWindowAlgorithm();
756    virtual G4Nsplit_Weight Calculate(G4double init_w,
757                                      G4double lowerWeightBound) const;
758  private:
759   ...
760};
761</programlisting>
762</informalexample>
763</para>
764
765<para>
766The constructor takes three parameters which are used to:
767calculate the upper weight bound (upperLimitFaktor), calculate the
768survival weight (survivalFaktor), and introduce a maximal number
769(maxNumberOfSplits) of copies to be created in one go.
770</para>
771
772<para>
773In addition, the inverse of the maxNumberOfSplits is used to
774specify the minimum survival probability in case of Russian
775roulette.
776</para>
777
778</sect3>
779
780<!-- ******************* Section (Level#3) ****************** -->
781<sect3 id="sect.EvtBias.ScorImpRoul.WeigRoul">
782<title>
783The Weight Roulette Technique
784</title>
785
786<para>
787Weight roulette (also called weight cutoff) is usually applied
788if importance sampling and implicit capture are used together.
789Implicit capture is not described here but it is useful to note
790that this procedure reduces a particle weight in every collision
791instead of killing the particle with some probability.
792</para>
793
794<para>
795Together with importance sampling the weight of a particle may
796become so low that it does not change any result significantly.
797Hence tracking a very low weight particle is a waste of computing
798time. Weight roulette is applied in order to solve this
799problem.
800</para>
801
802<!-- ******* Bridgehead ******* -->
803<bridgehead renderas='sect4'>
804The weight roulette concept
805</bridgehead>
806
807<para>
808Weight roulette takes into account the importance "Ic" of the
809current cell and the importance "Is" of the cell in which the
810source is located, by using the ratio "R=Is/Ic".
811</para>
812
813<para>
814Weight roulette uses a relative minimal weight limit and a
815relative survival weight. When a particle falls below the weight
816limit Russian roulette is applied. If the particle survives,
817tracking will be continued and the particle weight will be set to
818the survival weight.
819</para>
820
821<para>
822The weight roulette uses the following parameters with their
823default values:
824
825<itemizedlist spacing="compact">
826  <listitem><para>
827    <emphasis>wsurvival</emphasis>: 0.5
828  </para></listitem>
829  <listitem><para>
830    <emphasis>wlimit</emphasis>: 0.25
831  </para></listitem>
832  <listitem><para>
833    <emphasis>isource</emphasis>: 1
834  </para></listitem>
835</itemizedlist>
836</para>
837
838<para>
839The following algorithm is applied:
840</para>
841
842<para>
843If a particle weight "w" is lower than R*wlimit:
844
845<itemizedlist spacing="compact">
846  <listitem><para>
847    the weight of the particle will be changed to "ws = wsurvival*R"
848  </para></listitem>
849  <listitem><para>
850    the probability for the particle to survive is "p = w/ws"
851  </para></listitem>
852</itemizedlist>
853</para>
854
855</sect3>
856</sect2>
857
858
859<!-- ******************* Section (Level#2) ****************** -->
860<sect2 id="sect.EvtBias.PhysBias">
861<title>
862Physics Based Biasing
863</title>
864
865<para>
866Geant4 supports physics based biasing through a number of general
867use, built in biasing techniques. A utility class,
868G4WrapperProcess, is also available to support user defined
869biasing.
870</para>
871
872<!-- ******************* Section (Level#3) ****************** -->
873<sect3 id="sect.EvtBias.PhysBias.BuiltInOpt">
874<title>
875Built in Biasing Options
876</title>
877
878<!-- ******************* Section (Level#4) ****************** -->
879<sect4 id="sect.EvtBias.PhysBias.BuiltInOpt.PrimPart">
880<title>
881Primary Particle Biasing
882</title>
883
884<para>
885Primary particle biasing can be used to increase the number of
886primary particles generated in a particular phase space region of
887interest. The weight of the primary particle is modified as
888appropriate. A general implementation is provided through the
889G4GeneralParticleSource class. It is possible to bias position,
890angular and energy distributions.
891</para>
892
893<para>
894G4GeneralParticleSource is a concrete implementation of
895G4VPrimaryGenerator. To use, instantiate G4GeneralParticleSource in
896the G4VUserPrimaryGeneratorAction class, as demonstrated below.
897
898<informalexample>
899<programlisting>
900   MyPrimaryGeneratorAction::MyPrimaryGeneratorAction() {
901      generator = new G4GeneralParticleSource;
902   }
903
904   void
905   MyPrimaryGeneratorAction::GeneratePrimaries(G4Event*anEvent){
906      generator-&gt;GeneratePrimaryVertex(anEvent);
907   }
908</programlisting>
909</informalexample>
910</para>
911
912<para>
913The biasing can be configured through interactive commands.
914Extensive documentation can be found in
915<ulink url="http://reat.space.qinetiq.com/gps/">
916Primary particle biasing</ulink>.  Examples are also distributed
917with the Geant4 distribution in
918<emphasis role="bold">examples/extended/eventgenerator/exgps</emphasis>.
919</para>
920
921</sect4>
922
923<!-- ******************* Section (Level#4) ****************** -->
924<sect4 id="sect.EvtBias.PhysBias.BuiltInOpt.RadDcy">
925<title>
926Radioactive Decay Biasing
927</title>
928
929<para>
930The G4RadioactiveDecay class simulates the decay of radioactive
931nuclei and implements the following biasing options:
932
933<itemizedlist spacing="compact">
934  <listitem><para>
935    Increase the sampling rate of radionuclides within observation
936    times through a user defined probability distribution function
937  </para></listitem>
938  <listitem><para>
939    Nuclear splitting, where the parent nuclide is split into a
940    user defined number of nuclides
941  </para></listitem>
942  <listitem><para>
943    Branching ratio biasing where branching ratios are sampled with
944    equal probability
945  </para></listitem>
946</itemizedlist>
947</para>
948
949<para>
950G4RadioactiveDecay is a process which must be registered with a
951process manager, as demonstrated below.
952
953<informalexample>
954<programlisting>
955   void MyPhysicsList::ConstructProcess()
956   {
957      ...
958      G4RadioactiveDecay* theRadioactiveDecay =
959         new  G4RadioactiveDecay();
960
961      G4ProcessManager* pmanager = ...
962      pmanager -&gt;AddProcess(theRadioactiveDecay);
963      ...
964   }
965</programlisting>
966</informalexample>
967</para>
968
969<para>
970The biasing can be controlled either in compiled code or through
971interactive commands. Extensive documentation can be found in
972
973<ulink url="http://reat.space.qinetiq.com/septimess/exrdm/">
974Radioactive decay biasing example
975</ulink>
976 and
977<ulink url="http://www.space.qinetiq.com/geant4/rdm.html">
978Radioactive decay biasing
979</ulink>.
980</para>
981
982<para>
983Radioactive decay biasing examples are also distributed with the Geant4
984distribution in
985<emphasis role="bold">examples/extended/radioactivedecay/exrdm</emphasis>.
986</para>
987
988</sect4>
989
990<!-- ******************* Section (Level#4) ****************** -->
991<sect4 id="sect.EvtBias.PhysBias.BuiltInOpt.HadLeadPar">
992<title>
993Hadronic Leading Particle Biasing
994</title>
995
996<para>
997One hadronic leading particle biasing technique is
998implemented in the G4HadLeadBias utility. This method keeps only
999the most important part of the event, as well as representative
1000tracks of each given particle type. So the track with the highest
1001energy as well as one of each of Baryon, pi0, mesons and leptons.
1002As usual, appropriate weights are assigned to the particles.
1003Setting the <emphasis role="bold">SwitchLeadBiasOn</emphasis> 
1004environmental variable will activate this utility.
1005</para>
1006
1007</sect4>
1008
1009<!-- ******************* Section (Level#4) ****************** -->
1010<sect4 id="sect.EvtBias.PhysBias.BuiltInOpt.HadCrsSect">
1011<title>
1012Hadronic Cross Section Biasing
1013</title>
1014
1015<para>
1016Cross section biasing artificially enhances/reduces the cross
1017section of a process. This may be useful for studying thin layer
1018interactions or thick layer shielding. The built in hadronic cross
1019section biasing applies to photon inelastic, electron nuclear and
1020positron nuclear processes.
1021</para>
1022
1023<para>
1024The biasing is controlled through the
1025<emphasis role="bold">BiasCrossSectionByFactor</emphasis> method
1026in G4HadronicProcess, as demonstrated below.
1027
1028<informalexample>
1029<programlisting>
1030   void MyPhysicsList::ConstructProcess()
1031   {
1032      ...
1033      G4ElectroNuclearReaction * theElectroReaction =
1034         new G4ElectroNuclearReaction;
1035
1036      G4ElectronNuclearProcess theElectronNuclearProcess;   
1037      theElectronNuclearProcess.RegisterMe(theElectroReaction);
1038      theElectronNuclearProcess.BiasCrossSectionByFactor(100);
1039 
1040      pManager-&gt;AddDiscreteProcess(&amp;theElectronNuclearProcess);
1041      ... 
1042   }
1043</programlisting>
1044</informalexample>
1045</para>
1046
1047</sect4>
1048</sect3>
1049
1050
1051<!-- ******************* Section (Level#3) ****************** -->
1052<sect3 id="sect.EvtBias.PhysBias.">
1053<title>
1054G4WrapperProcess
1055</title>
1056
1057<para>
1058G4WrapperProcess can be used to implement user defined event
1059biasing. G4WrapperProcess, which is a process itself, wraps an
1060existing process. By default, all function calls are forwared to
1061the wrapped process. It is a non-invasive way to modify the
1062behaviour of an existing process.
1063</para>
1064
1065<para>
1066To use this utility, first create a derived class inheriting
1067from G4WrapperProcess. Override the methods whose behaviour you
1068would like to modify, for example, PostStepDoIt, and register the
1069derived class in place of the process to be wrapped. Finally,
1070register the wrapped process with G4WrapperProcess. The code
1071snippets below demonstrate its use.
1072
1073<informalexample>
1074<programlisting>
1075   class MyWrapperProcess  : public G4WrapperProcess {
1076   ...
1077    G4VParticleChange* PostStepDoIt(const G4Track&amp; track,
1078                                    const G4Step&amp; step) {
1079       // Do something interesting
1080    }
1081   };
1082
1083
1084   void MyPhysicsList::ConstructProcess()
1085   {
1086   ...
1087      G4LowEnergyBremsstrahlung* bremProcess =
1088         new G4LowEnergyBremsstrahlung();
1089
1090      MyWrapperProcess* wrapper = new MyWrapperProcess();
1091      wrapper-&gt;RegisterProcess(bremProcess);
1092
1093      processManager-&gt;AddProcess(wrapper, -1, -1, 3);
1094   }
1095</programlisting>
1096</informalexample>
1097</para>
1098
1099</sect3>
1100
1101</sect2>
1102
1103<!-- ******************* Section (Level#2) ****************** -->
1104<sect2 id="sect.EvtBias.ReverseMC">
1105<title>
1106Adjoint/Reverse Monte Carlo
1107</title>
1108
1109<para>
1110Another powerful biasing technique available in Geant4 is the Reverse Monte Carlo (RMC) method,
1111also known as the Adjoint Monte Carlo method. In this method  particles are generated  on the external
1112boundary  of the sensitive  part of the  geometry and then are tracked backward in the geometry till they
1113reach  the external source surface,
1114or exceed an energy threshold. By this way the computing time is focused only on particle tracks
1115that are contributing to the tallies.
1116The RMC  method is much rapid than the Forward MC method when the sensitive part of the geometry is
1117small compared to the rest of the geometry and to the external source,  that has to be  extensive and
1118not beam like. At the moment the RMC method is implemented in Geant4 only for some electromagnetic
1119processes (see <xref linkend="sect.EvtBias.ReverseMC.InG4.Process" />). An example illustrating the use
1120of the Reverse MC method in Geant4 is distributed within the Geant4
1121toolkit in <emphasis role="bold">examples/extended/biasing/ReverseMC01</emphasis>.
1122</para>
1123
1124<!-- ******************* Section (Level#3) ****************** -->
1125<sect3 id="sect.EvtBias.ReverseMC.InG4">
1126<title>
1127Treatment of the  Reverse MC method in Geant4
1128</title>
1129
1130<para>
1131Different G4Adjoint classes have been implemented into the Geant4
1132toolkit in order to run an adjoint/reverse simulation in a Geant4 application.
1133This implementation is illustrated in  <xref linkend="fig.EvtBias.ReverseMC.InG4_1" />.
1134An adjoint run is divided in a serie of alternative adjoint and forward tracking  of adjoint and normal particles.
1135One Geant4 event treats one of this tracking phase.
1136</para>
1137
1138<figure id="fig.EvtBias.ReverseMC.InG4_1">
1139<title>
1140 Schematic view of an adjoint/reverse simulation in Geant4
1141</title>
1142<mediaobject>
1143  <imageobject role="fo">
1144    <imagedata fileref="./AllResources/Fundamentals/ReverseMC_tracking.png" 
1145               format="png"  align="center" />
1146  </imageobject>
1147  <imageobject role="html">
1148    <imagedata fileref="./AllResources/Fundamentals/ReverseMC_tracking.png" 
1149               format="png"  align="center" />
1150  </imageobject>
1151</mediaobject>
1152</figure>
1153
1154
1155<!-- ******************* Section (Level#4) ****************** -->
1156<sect4 id="sect.EvtBias.ReverseMC.InG4.AdjointTracking">
1157<title>
1158Adjoint tracking phase
1159</title>
1160
1161<para>
1162 Adjoint particles (adjoint_e-, adjoint_gamma,...) are generated  one by one on the so called adjoint source
1163with  random position,  energy (1/E distribution) and direction. The adjoint source is the
1164external surface of a user defined volume or of a user defined sphere. The adjoint
1165source should contain one or several sensitive volumes and should be small compared to the entire geometry.
1166The user can set the minimum and maximum energy of the adjoint source. After its
1167generation the adjoint primary  particle is tracked backward in the geometry till a user  defined
1168 external surface
1169(spherical or boundary of a volume) or is killed before if it reaches a user defined  upper energy limit that
1170represents the maximum energy of the external source. During the reverse tracking, reverse
1171processes take place where  the adjoint particle being tracked can be either scattered
1172or transformed in another type of adjoint particle. During the reverse tracking the
1173G4AdjointSimulationManager replaces the user defined primary, run, stepping, ... actions, by its own actions.
1174A reverse tracking phase corresponds to one Geant4 event.
1175</para>
1176
1177</sect4>
1178
1179<!-- ******************* Section (Level#4) ****************** -->
1180<sect4 id="sect.EvtBias.ReverseMC.InG4.ForwardTracking">
1181<title>
1182Forward tracking phase
1183</title>
1184
1185<para>
1186When an adjoint particle reaches the external surface its weight, type,  position,
1187and direction are registered and a  normal primary particle, with a type equivalent to the last generated primary
1188adjoint, is generated with the same energy, position but opposite direction  and is  tracked in the forward direction
1189in the sensitive region as in a forward MC simulation.
1190During this forward tracking phase the 
1191event, stacking, stepping, tracking actions defined by the user for his forward simulation are used.
1192By this clear separation between
1193adjoint and forward tracking phases, the code of the user developed for a forward simulation
1194should be only slightly  modified to adapt it for an adjoint simulation (see <xref linkend="sect.EvtBias.ReverseMC.UserCoding" />).
1195Indeed  the computation of the signals is done by the same actions
1196or classes that the one used in the forward simulation mode.   
1197A forward tracking phase corresponds to one G4 event.
1198</para>
1199
1200</sect4>
1201
1202<!-- ******************* Section (Level#4) ****************** -->
1203<sect4 id="sect.EvtBias.ReverseMC.InG4.Process">
1204<title>
1205Reverse processes
1206</title>
1207
1208<para>
1209During the reverse tracking, reverse processes act on the adjoint particles.
1210The reverse processes that are at the moment available in Geant4 are the:
1211<itemizedlist spacing="compact">
1212        <listitem><para>
1213        Reverse discrete  ionization for e-, proton and ions
1214        </para></listitem>
1215        <listitem><para>
1216        Continuous gain of energy by ionization and bremsstrahlung for e- and by ionization for protons and ions
1217        </para></listitem>
1218        <listitem><para>
1219        Reverse discrete e- bremsstrahlung
1220        </para></listitem>
1221        <listitem><para> 
1222        Reverse photo-electric effect
1223        </para></listitem>
1224        <listitem><para> 
1225        Reverse Compton scattering
1226        </para></listitem>
1227        <listitem><para>
1228        Approximated multiple scattering  (see comment in <xref linkend="sect.EvtBias.ReverseMC.Limitation.ReverseMS"/>)
1229        </para></listitem>
1230</itemizedlist>
1231It is important to note that the electromagnetic reverse processes are cut dependent
1232as their equivalent forward processes. The implementation of the reverse processes is based on
1233the forward processes implemented in the G4 standard electromagnetic package.               
1234</para>
1235
1236</sect4>
1237
1238<!-- ******************* Section (Level#4) ****************** -->
1239<sect4 id="sect.EvtBias.ReverseMC.InG4.RemarkOnNbEvents">
1240<title>
1241Nb of adjoint particle types and nb of G4 events of an adjoint simulation
1242</title>
1243
1244<para>
1245The list of type of adjoint and forward particles that are generated on the adjoint source
1246and considered in the simulation  is a function of the adjoint processes declared in the physics list.
1247For example if only the e- and gamma electromagnetic processes are considered,
1248only adjoint e- and adjoint gamma will be considered as primaries.
1249In this case an adjoint event will be divided in four G4 event consisting in  the reverse tracking of an adjoint e-,
1250the forward tracking of its equivalent forward e-, the reverse tracking of
1251an adjoint gamma, and the forward tracking of its equivalent forward gamma.
1252In this case a run of 100 adjoint events will consist into 400 Geant4 events.
1253If the proton ionization is also considered adjoint and forward protons are also generated as primaries
1254and 600 Geant4 events are processed for  100 adjoint events.
1255</para> 
1256
1257</sect4>
1258
1259</sect3>
1260
1261<!-- ******************* Section (Level#3) ****************** -->
1262<sect3 id="sect.EvtBias.ReverseMC.UserCoding">
1263<title>
1264How to update a G4 application  to use the reverse Monte Carlo mode
1265</title>
1266
1267<para>
1268Some modifications are needed  to an existing  Geant4 application in order to adapt
1269it for the use of the reverse simulation mode
1270(see also the G4 example <emphasis role="bold">examples/extended/biasing/ReverseMC01</emphasis>).
1271It consists into the:
1272
1273<itemizedlist spacing="compact">
1274        <listitem><para>
1275        Creation of  the adjoint simulation manager in the main code
1276        </para></listitem>
1277        <listitem><para>
1278        Optional declaration of user actions that will be used during the adjoint tracking phase
1279        </para></listitem>
1280        <listitem><para>
1281        Use of a special physics lists that combine the adjoint and forward processes
1282        </para></listitem>
1283        <listitem><para>
1284        Modification of the user analysis part of the code
1285        </para></listitem>
1286</itemizedlist>
1287</para>
1288
1289
1290<!-- ******************* Section (Level#4) ****************** -->
1291<sect4 id="sect.EvtBias.ReverseMC.UserCoding.Main">
1292<title>
1293Creation of   G4AdjointSimManager in the main
1294</title>
1295<para>
1296The class G4AdjointSimManager represents the manager  of an adjoint simulation.
1297This static class should be created somewhere in the main code. The way to do that is illustrated below
1298<informalexample>
1299<programlisting>
1300   int main(int argc,char** argv) {
1301      ...
1302      G4AdjointSimManager* theAdjointSimManager = G4AdjointSimManager::GetInstance();
1303      ...
1304   }
1305</programlisting>
1306</informalexample> 
1307By doing this  the G4 application  can be   run in the reverse  MC mode as well
1308 as in the forward MC mode. 
1309It is important to note that G4AdjointSimManager
1310is not a new G4RunManager and that the creation of G4RunManager in the main  and the declaration of the geometry,
1311 physics list,  and user actions to G4RunManager is still needed.
1312The   definition of  the adjoint and external sources and the start of an adjoint simulation can be controlled
1313by   G4UI  commands in the directory  <emphasis role="bold">/adjoint</emphasis>.
1314</para>
1315</sect4>
1316
1317
1318<!-- ******************* Section (Level#4) ****************** -->
1319<sect4 id="sect.EvtBias.ReverseMC.UserCoding.AdjointActions">
1320<title>
1321Optional declaration of adjoint user actions
1322</title>
1323<para>
1324During an adjoint  simulation the user stepping, tracking, stacking and event  actions declared to G4RunManager
1325 are used only during the G4 events dedicated to the forward tracking of normal particles in the sensitive region,
1326 while during the events where  adjoint particles are tracked backward the   following happen concerning these actions:
1327   
1328<itemizedlist spacing="compact">
1329<listitem><para>
1330The user stepping action is replaced by G4AdjointSteppingAction that is reponsible to stop an adjoint track when
1331it reaches the external source,  exceed the maximum energy of the external source, or cross the adjoint source surface.
1332If needed the user can declare its own stepping action  that will be called by  G4AdjointSteppingAction after the
1333check of stopping track conditions. This stepping action can be different that the stepping action used for the
1334forward simulation. It is declared to G4AdjointSimManager by the following lines of code :
1335       
1336<informalexample><programlisting>
1337   G4AdjointSimManager* theAdjointSimManager = G4AdjointSimManager::GetInstance();
1338   theAdjointSimManager-&gt;SetAdjointSteppingAction(aUserDefinedSteppingAction);
1339</programlisting></informalexample>
1340                 
1341</para></listitem>
1342
1343<listitem><para>
1344No stacking, tracking and event actions are considered by default. If needed the user can declare to G4AdjointSimManager
1345stacking, tracking and event actions that will be used only during the adjoint tracking phase.
1346The following lines of code show how to declare these adjoint actions to G4AdjointSimManager:
1347
1348<informalexample><programlisting>
1349   G4AdjointSimManager* theAdjointSimManager = G4AdjointSimManager::GetInstance();
1350   theAdjointSimManager-&gt;SetAdjointEventAction(aUserDefinedEventAction);
1351   theAdjointSimManager-&gt;SetAdjointStackingAction(aUserDefinedStackingAction);
1352   theAdjointSimManager-&gt;SetAdjointTrackingAction(aUserDefinedTrackingAction);
1353</programlisting></informalexample>
1354
1355</para></listitem>
1356       
1357</itemizedlist>
1358By default no user run action is considered in an adjoint simulation but if needed such action can be declared to
1359 G4AdjointSimManager as such:
1360<informalexample><programlisting>
1361   G4AdjointSimManager* theAdjointSimManager = G4AdjointSimManager::GetInstance();
1362   theAdjointSimManager-&gt;SetAdjointRunAction(aUserDefinedRunAction);
1363</programlisting></informalexample> 
1364
1365</para>
1366
1367</sect4>
1368
1369<!-- ******************* Section (Level#4) ****************** -->
1370<sect4 id="sect.EvtBias.ReverseMC.UserCoding.PhysicsList">
1371<title>
1372Physics list for reverse and forward electromagnetic processes
1373</title>
1374
1375<para>
1376To run an adjoint simulation a specific physics list should be used where existing G4 adjoint electromagnetic processes
1377and their forward equivalent have to be declared.
1378 An example of such physics list is provided by the class G4AdjointPhysicsLits in the  G4 example
1379 <emphasis role="bold">extended/biasing/ReverseMC01</emphasis>.
1380</para>
1381
1382</sect4>
1383
1384<!-- ******************* Section (Level#4) ****************** -->
1385<sect4 id="sect.EvtBias.ReverseMC.UserCoding.Analysis">
1386<title>
1387Modification in the analysis part of the code
1388</title>
1389
1390<para>
1391The  user code should be modified to  normalize the signals computed during the forward tracking phase to the weight of the last adjoint particle
1392that reaches the external surface.
1393This weight represents the  statistical weight  that the last full adjoint tracks (from the adjoint source
1394to the external source)  would have in a forward  simulation.   If multiplied by a signal  and registered in function of energy
1395and/or direction the simulation results will give an answer matrix of this signal.
1396 To normalize it to a given spectrum it has to be furthermore multiplied by a directional differential flux 
1397 corresponding to this spectrum
1398   
1399The weight, direction, position , kinetic energy and type of the last adjoint particle that reaches the
1400 external source, and that would represents the primary of a forward simulation,  can be   get from G4AdjointSimManager by using for example the following line of codes
1401<informalexample><programlisting>
1402   
1403   G4AdjointSimManager* theAdjointSimManager = G4AdjointSimManager::GetInstance();
1404   G4String particle_name = theAdjointSimManager-&gt;GetFwdParticleNameAtEndOfLastAdjointTrack();
1405   G4int PDGEncoding= theAdjointSimManager-&gt;GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack();
1406   G4double weight = theAdjointSimManager-&gt;GetWeightAtEndOfLastAdjointTrack();
1407   G4double Ekin  = theAdjointSimManager-&gt;GetEkinAtEndOfLastAdjointTrack();
1408   G4double Ekin_per_nuc=theAdjointSimManager-&gt;GetEkinNucAtEndOfLastAdjointTrack(); // in case of ions
1409   G4ThreeVector dir =  theAdjointSimManager-&gt;GetDirectionAtEndOfLastAdjointTrack();
1410   G4ThreeVector pos = theAdjointSimManager-&gt;GetPositionAtEndOfLastAdjointTrack();
1411   
1412</programlisting></informalexample> 
1413
1414</para>
1415
1416<para>
1417In order to have a code working for both forward and adjoint simulation mode, the extra code needed in user actions or analysis
1418manager  for the adjoint
1419simulation mode can be separated to the code needed only for the normal forward  simulation by using the following public method
1420of G4AdjointSimManager:
1421<informalexample><programlisting>
1422G4bool GetAdjointSimMode();
1423</programlisting></informalexample> 
1424that returns true if   an adjoint simulation is running and false if not.
1425
1426</para>
1427
1428<para>
1429The following   code example shows how  to normalize a detector signal and compute an answer matrix
1430in the case of an adjoint simulation.
1431 <example id="sect.EvtBias.ReverseMC.UserCoding.Analysis_1">
1432<title>
1433Normalization in the case of an adjoint simulation. The detector signal S computed during the forward tracking
1434phase is normalized to a primary source of e-  with a differential directional flux given by the function F.
1435An answer matrix of the signal is also computed. 
1436</title>
1437
1438<programlisting>
1439   
1440   G4double S = ...; // signal   in the sensitive volume computed during a forward tracking phase
1441
1442   //Normalization of the signal for an adjoint simulation
1443   G4AdjointSimManager* theAdjSimManager =    G4AdjointSimManager::GetInstance();
1444   if (theAdjSimManager->GetAdjointSimMode()) {
1445        G4double normalized_S=0.; //normalized to a given  e- primary spectrum
1446        G4double S_for_answer_matrix=0.; //for e- answer matrix
1447       
1448        if (theAdjSimManager->GetFwdParticleNameAtEndOfLastAdjointTrack() == "e-"){
1449            G4double ekin_prim = theAdjSimManager-&gt;GetEkinAtEndOfLastAdjointTrack();
1450            G4ThreeVector dir_prim =  theAdjointSimManager-&gt;GetDirectionAtEndOfLastAdjointTrack();
1451            G4double weight_prim = theAdjSimManager->GetWeightAtEndOfLastAdjointTrack();
1452            S_for_answer_matrix = S*weight_prim;
1453            normalized_S = S_for_answer_matrix*F(ekin_prim,dir); //F(ekin_prim,dir_prim) gives the differential directional flux of primary e-
1454        } 
1455       //follows the code where normalized_S  and S_for_answer_matrix are  registered or whatever
1456        ....
1457   }
1458   
1459   //analysis/normalization code for forward simulation
1460   else {
1461     ...
1462   }
1463   ...
1464</programlisting>
1465</example> 
1466
1467</para>
1468
1469</sect4>
1470
1471</sect3>
1472
1473<!-- ******************* Section (Level#3) ****************** -->
1474<sect3 id="sect.EvtBias.ReverseMC.Control">
1475<title>
1476Control of an adjoint simulation
1477</title>
1478
1479<para>
1480The G4UI  commands in the directory 
1481<ulink url="./AllResources/Control/UIcommands/_adjoint_.html">/adjoint</ulink>.
1482allow the user to :
1483<itemizedlist spacing="compact">
1484        <listitem><para>
1485        Define the adjoint source where adjoint primaries are generated
1486        </para></listitem>
1487        <listitem><para>
1488        Define the external source till which adjoint particles are  tracked
1489        </para></listitem>
1490        <listitem><para>
1491        Start an adjoint simulation
1492        </para></listitem>
1493</itemizedlist>
1494</para>
1495</sect3>
1496
1497<!-- ******************* Section (Level#3) ****************** -->
1498<sect3 id="sect.EvtBias.ReverseMC.Limitation">
1499<title>
1500Known issues in the Reverse MC mode 
1501</title>
1502
1503<!-- ******************* Section (Level#4) ****************** -->
1504<sect4 id="sect.EvtBias.ReverseMC.Limitation.Weight">
1505<title>
1506Occasional wrong high weight in the adjoint simulation
1507</title>
1508
1509<para>
1510In rare cases an adjoint track may get a wrong high weight when  reaching the external source.
1511While this happens not often it may corrupt the simulation results significantly. This happens
1512in some tracks where  both  reverse photo-electric and bremsstrahlung processes take place at low energy.
1513We still need some investigations to remove this problem  at the level of physical adjoint/reverse processes.
1514However  this problem can be solved  at the level of event actions or analysis in the user code by adding a test on the
1515normalized signal during an adjoint simulation. An example of such test has been implemented in the Geant4 example
1516<emphasis role="bold"> extended/biasing/ReverseMC01 </emphasis>.
1517In this implementation  an event is rejected when the relative error of the computed  normalized energy deposited
1518increases during one event by more than 50% while the computed precision  is already below 10%.
1519</para>
1520
1521</sect4>
1522
1523<!-- ******************* Section (Level#4) ****************** -->
1524<sect4 id="sect.EvtBias.ReverseMC.Limitation.ReverseBrem">
1525<title>
1526Reverse bremsstrahlung
1527</title> 
1528
1529<para>
1530A difference between the differential cross sections used in the adjoint and forward bremsstrahlung
1531 models is the source of a higher flux of >100 keV gamma in the reverse simulation compared to the forward simulation mode.
1532In principle the adjoint processes/models should make use of the direct differential cross section to sample
1533 the adjoint  secondaries and compute the adjoint cross section. However due to the way the effective differential cross section is
1534 considered in the forward model G4eBremsstrahlungModel this was not possible to achieve for the reverse bremsstrahlung.
1535Indeed the differential cross section used in G4AdjointeBremstrahlungModel  is obtained by the numerical derivation
1536over the cut energy of the direct cross section provided  by G4eBremsstrahlungModel.
1537This would be a correct procedure if the  distribution of secondary in   G4eBremsstrahlungModel 
1538would match this differential cross section. Unfortunately it is not the case as independent  parameterization are used
1539 in   G4eBremsstrahlungModel  for both the cross sections and the sampling of secondaries. (It means that in the forward case
1540 if one would integrate the effective differential cross section considered  in the simulation we would not find back
1541 the used cross section).
1542 In the future we plan to correct this problem by using an extra weight correction factor after the occurrence of a reverse
1543 bremsstrahlung. This weight factor should be the ratio between the differential CS used in the adjoint simulation and the
1544one effectively used in the forward processes. As it is impossible to have a simple and direct  access to the forward differential CS
1545 in G4eBremsstrahlungModel we  are investigating the feasibility to use  the differential CS considered in 
1546 G4Penelope models.
1547</para> 
1548
1549</sect4>
1550
1551<!-- ******************* Section (Level#4) ****************** -->
1552<sect4 id="sect.EvtBias.ReverseMC.Limitation.ReverseMS">
1553<title>
1554Reverse multiple scattering
1555</title> 
1556 
1557<para>
1558For the reverse multiple scattering  the same model is used than  in the forward case.
1559This approximation makes that the discrepancy between the adjoint and forward
1560simulation cases can get to a level of ~ 10-15% relative differences in the test cases that we have considered.
1561In the future we plan to improve   the adjoint multiple scattering models  by forcing the computation of
1562 multiple scattering effect at the end of an adjoint step.
1563</para>
1564 
1565</sect4>
1566
1567</sect3>
1568</sect2>
1569</sect1>
Note: See TracBrowser for help on using the repository browser.