source: trunk/documents/UserDoc/DocBookUsersGuides/ForApplicationDeveloper/xml/Detector/hit.xml @ 905

Last change on this file since 905 was 904, checked in by garnier, 16 years ago

ajout de la doc

File size: 40.6 KB
Line 
1<!-- ******************************************************** -->
2<!--                                                          -->
3<!--  [History]                                               -->
4<!--    Converted to DocBook: Katsuya Amako, Aug-2006         -->
5<!--    Changed by: Katsuya Amako, 21-Sep-1998                -->
6<!--    Proof read by: Joe Chuma,  30-Jun-1999                -->
7<!--    Changed by: Dennis Wright, 29-Nov-2001                -->
8<!--    Changed by: Makoto Asai,   30-Nov-2005                -->
9<!--                                                          -->
10<!-- ******************************************************** -->
11
12<!-- ******************* Section (Level#1) ****************** -->
13<sect1 id="sect.Hits">
14<title>
15Hits
16</title>
17
18
19<!-- ******************* Section (Level#2) ****************** -->
20<sect2 id="sect.Hits.Hit">
21<title>
22Hit
23</title>
24
25<para>
26A hit is a snapshot of the physical interaction of a track in the
27sensitive region of a detector. In it you can store information
28associated with a <emphasis>G4Step</emphasis> object. This information can be
29
30<itemizedlist spacing="compact">
31  <listitem><para>
32    the position and time of the step,
33  </para></listitem>
34  <listitem><para>
35    the momentum and energy of the track,
36  </para></listitem>
37  <listitem><para>
38    the energy deposition of the step,
39  </para></listitem>
40  <listitem><para>
41    geometrical information,
42  </para></listitem>
43</itemizedlist>
44
45or any combination of the above.
46</para>
47
48<!-- ******* Bridgehead ******* -->
49<bridgehead renderas='sect4'>
50G4VHit
51</bridgehead>
52
53<para>
54<emphasis>G4VHit</emphasis> is an abstract base class which represents a hit.
55You must inherit this base class and derive your own concrete hit
56class(es). The member data of your concrete hit class can be, and
57should be, your choice.
58</para>
59
60<para>
61<emphasis>G4VHit</emphasis> has two virtual methods, <literal>Draw()</literal> and
62<literal>Print()</literal>. To draw or print out your concrete hits, these
63methods should be implemented. How to define the drawing method is
64described in <xref linkend="sect.VisPlylMrkTxt" />.
65</para>
66
67<!-- ******* Bridgehead ******* -->
68<bridgehead renderas='sect4'>
69G4THitsCollection
70</bridgehead>
71
72<para>
73<emphasis>G4VHit</emphasis> is an abstract class from which you derive your
74own concrete classes. During the processing of a given event,
75represented by a <emphasis>G4Event</emphasis> object, many objects of the hit
76class will be produced, collected and associated with the event.
77Therefore, for each concrete hit class you must also prepare a
78concrete class derived from <emphasis>G4VHitsCollection</emphasis>, an abstract
79class which represents a vector collection of user defined
80hits.
81</para>
82
83<para>
84<emphasis>G4THitsCollection</emphasis> is a template class derived from
85<emphasis>G4VHitsCollection</emphasis>, and the concrete hit collection class of
86a particular <emphasis>G4VHit</emphasis> concrete class can be instantiated from
87this template class. Each object of a hit collection must have a
88unique name for each event.
89</para>
90
91<para>
92<emphasis>G4Event</emphasis> has a <emphasis>G4HCofThisEvent</emphasis> class
93object, that is a container class of collections of hits. Hit collections are
94stored by their pointers, whose type is that of the base class.
95</para>
96
97<!-- ******* Bridgehead ******* -->
98<bridgehead renderas='sect4'>
99An example of a concrete hit class
100</bridgehead>
101
102<para>
103<xref linkend="programlist_Hits_1" /> shows an example of a concrete hit class.
104
105<example id="programlist_Hits_1">
106<title>
107An example of a concrete hit class.
108</title>
109
110<programlisting>
111#ifndef ExN04TrackerHit_h
112#define ExN04TrackerHit_h 1
113
114#include "G4VHit.hh"
115#include "G4THitsCollection.hh"
116#include "G4Allocator.hh"
117#include "G4ThreeVector.hh"
118
119class ExN04TrackerHit : public G4VHit
120{
121  public:
122
123      ExN04TrackerHit();
124      ~ExN04TrackerHit();
125      ExN04TrackerHit(const ExN04TrackerHit &amp;right);
126      const ExN04TrackerHit&amp; operator=(const ExN04TrackerHit &amp;right);
127      int operator==(const ExN04TrackerHit &amp;right) const;
128
129      inline void * operator new(size_t);
130      inline void operator delete(void *aHit);
131
132      void Draw() const;
133      void Print() const;
134
135  private:
136      G4double edep;
137      G4ThreeVector pos;
138
139  public:
140      inline void SetEdep(G4double de)
141      { edep = de; }
142      inline G4double GetEdep() const
143      { return edep; }
144      inline void SetPos(G4ThreeVector xyz)
145      { pos = xyz; }
146      inline G4ThreeVector GetPos() const
147      { return pos; }
148
149};
150
151typedef G4THitsCollection&lt;ExN04TrackerHit&gt; ExN04TrackerHitsCollection;
152
153extern G4Allocator&lt;ExN04TrackerHit&gt; ExN04TrackerHitAllocator;
154
155inline void* ExN04TrackerHit::operator new(size_t)
156{
157  void *aHit;
158  aHit = (void *) ExN04TrackerHitAllocator.MallocSingle();
159  return aHit;
160}
161
162inline void ExN04TrackerHit::operator delete(void *aHit)
163{
164  ExN04TrackerHitAllocator.FreeSingle((ExN04TrackerHit*) aHit);
165}
166
167#endif
168</programlisting>
169</example>
170</para>
171
172<para>
173<emphasis>G4Allocator</emphasis> is a class for fast allocation of objects to
174the heap through the paging mechanism. For details of
175<emphasis>G4Allocator</emphasis>, refer to <xref linkend="sect.GeneManage" />.
176Use of <emphasis>G4Allocator</emphasis>
177is not mandatory, but it is recommended, especially for users who
178are not familiar with the C++ memory allocation mechanism or
179alternative tools of memory allocation. On the other hand, note
180that <emphasis>G4Allocator</emphasis> is to be used
181<emphasis role="bold">only</emphasis> for the concrete
182class that is <emphasis role="bold">not</emphasis> used as a base
183class of any other classes.
184For example, do <emphasis role="bold">not</emphasis> use the
185<emphasis>G4Trajectory</emphasis> class as a
186base class for a customized trajectory class, since
187<emphasis>G4Trajectory</emphasis> uses <emphasis>G4Allocator</emphasis>.
188</para>
189
190<!-- ******* Bridgehead ******* -->
191<bridgehead renderas='sect4'>
192G4THitsMap
193</bridgehead>
194
195<para>
196<emphasis>G4THitsMap</emphasis> is an alternative to
197<emphasis>G4THitsCollection</emphasis>.
198<emphasis>G4THitsMap</emphasis> does not demand <emphasis>G4VHit</emphasis>,
199but instead any variable which can be mapped with an integer key. Typically the key
200is a copy number of the volume, and the mapped value could for
201example be a double, such as the energy deposition in a volume.
202<emphasis>G4THitsMap</emphasis> is convenient for applications which do not need
203to output event-by-event data but instead just accumulate them. All
204the <emphasis>G4VPrimitiveScorer</emphasis> classes discussed in
205<xref linkend="sect.Hits.G4Multi" /> use <emphasis>G4THitsMap</emphasis>.
206</para>
207
208<para>
209<emphasis>G4THitsMap</emphasis> is derived from the
210<emphasis>G4VHitsCollection</emphasis>
211abstract base class and all objects of this class are also stored
212in <emphasis>G4HCofThisEvent</emphasis> at the end of an event. How to access a
213<emphasis>G4THitsMap</emphasis> object is discussed in the
214following section (<xref linkend="sect.Hits.G4Multi" />).
215</para>
216
217</sect2>
218
219
220<!-- ******************* Section (Level#2) ****************** -->
221<sect2 id="sect.Hits.SensDet">
222<title>
223Sensitive detector
224</title>
225
226<!-- ******* Bridgehead ******* -->
227<bridgehead renderas='sect4'>
228G4VSensitiveDetector
229</bridgehead>
230
231<para>
232<emphasis>G4VSensitiveDetector</emphasis> is an abstract base class which
233represents a detector. The principal mandate of a sensitive
234detector is the construction of hit objects using information from
235steps along a particle track. The <literal>ProcessHits()</literal> method of
236<emphasis>G4VSensitiveDetector</emphasis> performs this task using
237<emphasis>G4Step</emphasis>
238objects as input. In the case of a "Readout" geometry (see
239<xref linkend="sect.Hits.ReadGeom" />), objects of the
240<emphasis>G4TouchableHistory</emphasis> class may be used as an optional input.
241</para>
242
243<para>
244Your concrete detector class should be instantiated with the
245unique name of your detector. The name can be associated with one
246or more global names with "/" as a delimiter for categorizing your
247detectors. For example
248
249<informalexample>
250<programlisting>
251     myEMcal = new MyEMcal("/myDet/myCal/myEMcal");
252</programlisting>
253</informalexample> 
254
255where <literal>myEMcal</literal> is the name of your detector. The pointer to
256your sensitive detector must be set to one or more
257<emphasis>G4LogicalVolume</emphasis> objects to set the sensitivity of these
258volumes. The pointer should also be registered to
259<emphasis>G4SDManager</emphasis>, as described in
260<xref linkend="sect.Hits.G4SDMan" />.
261</para>
262
263<para>
264<emphasis>G4VSensitiveDetector</emphasis> has three major virtual methods.
265
266<variablelist><title></title>
267  <varlistentry>
268    <term>
269      <literal>ProcessHits()</literal>
270    </term>
271    <listitem><para>
272      This method is invoked by <emphasis>G4SteppingManager</emphasis> when a step
273      is composed in the <emphasis>G4LogicalVolume</emphasis> which has the pointer
274      to this sensitive detector. The first argument of this method is a
275      <emphasis>G4Step</emphasis> object of the current step. The second argument is a
276      <emphasis>G4TouchableHistory</emphasis> object for the ``Readout geometry''
277      described in the next section. The second argument is <literal>NULL</literal>
278      if ``Readout geometry'' is not assigned to this sensitive detector.
279      In this method, one or more <emphasis>G4VHit</emphasis> objects should be
280      constructed if the current step is meaningful for your
281      detector.
282    </para></listitem>
283  </varlistentry>
284  <varlistentry>
285    <term>
286      <literal>Initialize()</literal>
287    </term>
288    <listitem><para>
289      This method is invoked at the beginning of each event. The
290      argument of this method is an object of the <emphasis>G4HCofThisEvent</emphasis>
291      class. Hit collections, where hits produced in this particular
292      event are stored, can be associated with the <emphasis>G4HCofThisEvent</emphasis>
293      object in this method. The hit collections associated with the
294      <emphasis>G4HCofThisEvent</emphasis> object during this method can be used for
295      ``during the event processing'' digitization.
296    </para></listitem>
297  </varlistentry>
298  <varlistentry>
299    <term>
300      <literal>EndOfEvent()</literal>
301    </term>
302    <listitem><para>
303      This method is invoked at the end of each event. The argument
304      of this method is the same object as the previous method. Hit
305      collections occasionally created in your sensitive detector can be
306      associated with the <emphasis>G4HCofThisEvent</emphasis> object.
307    </para></listitem>
308  </varlistentry>
309</variablelist>
310</para>
311
312</sect2>
313
314
315<!-- ******************* Section (Level#2) ****************** -->
316<sect2 id="sect.Hits.ReadGeom">
317<title>
318Readout geometry
319</title>
320
321<para>
322This section describes how a ``Readout geometry'' can be defined. A
323Readout geometry is a virtual, parallel geometry for obtaining the
324channel number.
325</para>
326
327<para>
328As an example, the accordion calorimeter of <emphasis role="bold">ATLAS</emphasis> 
329has a complicated tracking geometry, however the readout can be done by
330simple cylindrical sectors divided by theta, phi, and depth. Tracks
331will be traced in the tracking geometry, the ``real'' one, and the
332sensitive detector will have its own readout geometry Geant4 will
333message to find to which ``readout'' cell the current hit
334belongs.
335
336<figure id="fig.Hits_1">
337<title>
338Association of tracking and readout geometry.
339</title>
340<mediaobject>
341  <imageobject role="fo">
342    <imagedata fileref="./AllResources/Detector/hit.src/RO.gif"
343               format="JPG" contentwidth="10.0cm" align="center" />
344  </imageobject>
345  <imageobject role="html">
346    <imagedata fileref="./AllResources/Detector/hit.src/RO.gif"
347               format="JPG" align="center" />
348  </imageobject>
349</mediaobject>
350</figure>
351</para>
352
353<para>
354<xref linkend="fig.Hits_1" /> shows how this association is done in Geant4.
355The first step is to associate a sensitive detector to a volume of the
356tracking geometry, in the usual way (see
357<xref linkend="sect.Hits.SensDet" />). The next step is to associate your
358<emphasis>G4VReadoutGeometry</emphasis> object to the sensitive detector.
359</para>
360
361<para>
362At tracking time, the base class <emphasis>G4VReadoutGeometry</emphasis> will
363provide to your sensitive detector code the
364<emphasis>G4TouchableHistory</emphasis> in the Readout geometry at the beginning
365of the step position (position of <emphasis>PreStepPoint</emphasis> of
366<emphasis>G4Step</emphasis>) and at this position only.
367</para>
368
369<para>
370This <emphasis>G4TouchableHistory</emphasis> is given to your sensitive
371detector code through the <emphasis>G4VSensitiveDetector</emphasis> virtual
372method:
373
374<informalexample>
375<programlisting>
376        G4bool processHits(G4Step* aStep, G4TouchableHistory* ROhist);
377</programlisting>
378</informalexample>
379
380by the <literal>ROhist</literal> argument.
381</para>
382
383<para>
384Thus, you will be able to use information from both the
385<emphasis>G4Step</emphasis> and the <emphasis>G4TouchableHistory</emphasis> 
386coming from your
387Readout geometry. Note that since the association is done through a
388sensitive detector object, it is perfectly possible to have several
389Readout geometries in parallel.
390</para>
391
392
393<!-- ******* Bridgehead ******* -->
394<bridgehead renderas='sect4'>
395Definition of a virtual geometry setup
396</bridgehead>
397
398<para>
399The base class for the implementation of a Readout geometry is
400<emphasis>G4VReadoutGeometry</emphasis>. This class has a single pure virtual
401protected method:
402
403<informalexample>
404<programlisting>
405        virtual G4VPhysicalVolume* build() = 0;
406</programlisting>
407</informalexample>
408
409which you must override in your concrete class. The
410<emphasis>G4VPhysicalVolume</emphasis> pointer you will have to return is of the
411physical world of the Readout geometry.
412</para>
413
414<para>
415The step by step procedure for constructing a Readout geometry is:
416
417<itemizedlist spacing="compact">
418  <listitem><para>
419    inherit from <emphasis>G4VReadoutGeometry</emphasis> to define a
420    <emphasis>MyROGeom</emphasis> class;
421  </para></listitem>
422  <listitem><para>
423    implement the Readout geometry in the <literal>build()</literal> method,
424    returning the physical world of this geometry.
425    <para>
426    The world is specified in the same way as for the detector
427    construction: a physical volume with no mother. The axis system of
428    this world is the same as the one of the world for tracking.
429    </para>
430    <para>
431    In this geometry you need to declare the sensitive parts in the
432    same way as in the tracking geometry: by setting a
433    non-<literal>NULL</literal> <emphasis>G4VSensitiveDetector</emphasis> 
434    pointer in, say, the
435    relevant <emphasis>G4LogicalVolume</emphasis> objects. This sensitive class needs
436    to be there, but will not be used.
437    </para>
438    <para>
439    You will also need to assign well defined materials to the
440    volumes you place in this geometry, but these materials are
441    irrelevant since they will not be seen by the tracking. It is
442    foreseen to allow the setting of a <literal>NULL</literal> pointer in this
443    case of the parallel geometry.
444    </para>
445  </para></listitem>
446  <listitem><para>
447    in the <literal>construct()</literal> method of your concrete
448    <emphasis>G4VUserDetectorConstruction</emphasis> class:
449    <para>
450    <itemizedlist spacing="compact">
451      <listitem><para>
452        instantiate your Readout geometry:
453        <informalexample>
454        <programlisting>
455        MyROGeom* ROgeom = new MyROGeom("ROName");
456        </programlisting>
457        </informalexample>           
458      </para></listitem>
459      <listitem><para>
460        build it:
461        <informalexample>
462        <programlisting>
463        ROgeom-&gt;buildROGeometry();
464        </programlisting>
465        </informalexample>
466        That will invoke your <literal>build()</literal> method.
467      </para></listitem>
468      <listitem><para>
469        Instantiate the sensitive detector which will receive the
470        <literal>ROGeom</literal> pointer, <literal>MySensitive</literal>,
471        and add this sensitive to the <emphasis>G4SDManager</emphasis>.
472        Associate this sensitive to
473        the volume(s) of the tracking geometry as usual.
474      </para></listitem>
475      <listitem><para>
476        Associate the sensitive to the Readout geometry:
477        <informalexample>
478        <programlisting>
479        MySensitive-&gt;SetROgeometry(ROgeom);
480        </programlisting>
481        </informalexample>           
482      </para></listitem>
483    </itemizedlist>
484    </para>
485  </para></listitem>
486</itemizedlist>
487</para>
488
489</sect2>
490
491
492<!-- ******************* Section (Level#2) ****************** -->
493<sect2 id="sect.Hits.G4SDMan">
494<title>
495G4SDManager
496</title>
497
498<para>
499<emphasis>G4SDManager</emphasis> is the singleton manager class for sensitive
500detectors.
501</para>
502
503<!-- ******* Bridgehead ******* -->
504<bridgehead renderas='sect4'>
505Activation/inactivation of sensitive detectors
506</bridgehead>
507
508<para>
509The user interface commands <literal>activate</literal> and
510<literal>inactivate</literal> are available to control your sensitive
511detectors. For example:
512
513<informalexample>
514<programlisting>
515/hits/activate detector_name
516/hits/inactivate detector_name
517</programlisting>
518</informalexample>
519
520where <literal>detector_name</literal> can be the detector name or the
521category name.
522</para>
523
524<para>
525For example, if your EM calorimeter is named
526
527<informalexample>
528<programlisting>
529/myDet/myCal/myEMcal
530/hits/inactivate myCal
531</programlisting>
532</informalexample>
533
534will inactivate all detectors belonging to the <literal>myCal</literal>
535category.
536</para>
537
538<!-- ******* Bridgehead ******* -->
539<bridgehead renderas='sect4'>
540Access to the hit collections
541</bridgehead>
542
543
544<para>Hit collections are accessed for various cases.
545
546<itemizedlist spacing="compact">
547  <listitem><para>
548    Digitization
549  </para></listitem>
550  <listitem><para>
551    Event filtering in <emphasis>G4VUserStackingAction</emphasis>
552  </para></listitem>
553  <listitem><para>
554    ``End of event'' simple analysis
555  </para></listitem>
556  <listitem><para>
557    Drawing / printing hits
558  </para></listitem>
559</itemizedlist>
560</para>
561
562<para>
563The following is an example of how to access the hit collection
564of a particular concrete type:
565
566<informalexample>
567<programlisting>
568  G4SDManager* fSDM = G4SDManager::GetSDMpointer();
569  G4RunManager* fRM = G4RunManager::GetRunManager();
570  G4int collectionID = fSDM-&gt;GetCollectionID("collection_name");
571  const G4Event* currentEvent = fRM-&gt;GetCurrentEvent();
572  G4HCofThisEvent* HCofEvent = currentEvent-&gt;GetHCofThisEvent();
573  <emphasis>MyHitsCollection</emphasis>* myCollection = (<emphasis>MyHitsCollection</emphasis>*)(HC0fEvent-&gt;GetHC(collectionID));
574</programlisting>
575</informalexample> 
576</para>
577
578</sect2>
579
580
581<!-- ******************* Section (Level#2) ****************** -->
582<sect2 id="sect.Hits.G4Multi">
583<title>
584<emphasis>G4MultiFunctionalDetector</emphasis> and
585<emphasis>G4VPrimitiveScorer</emphasis>
586</title>
587 
588<para>
589<emphasis>G4MultiFunctionalDetector</emphasis> is a concrete class derived from
590<emphasis>G4VSensitiveDetector</emphasis>. Instead of implementing a
591user-specific detector class, <emphasis>G4MultiFunctionalDetector</emphasis>
592allows the user to register <emphasis>G4VPrimitiveScorer</emphasis> classes to
593build up the sensitivity. <emphasis>G4MultiFunctionalDetector</emphasis> should
594be instantiated in the users detector construction with its unique
595name and should be assigned to one or more <emphasis>G4LogicalVolume</emphasis>s.
596</para>
597
598<para>
599<emphasis>G4VPrimitiveScorer</emphasis> is an abstract base class representing
600a class to be registered to <emphasis>G4MultiFunctionalDetector</emphasis> that
601creates a <emphasis>G4THitsMap</emphasis> object of one physics quantity for an
602event. Geant4 provides many concrete primitive scorer classes
603listed in <xref linkend="sect.Hits.G4VPrim" />, and the user can
604also implement his/her own primitive scorers. Each primitive scorer
605object must be instantiated with a name that must be unique among
606primitive scorers registered in a <emphasis>G4MultiFunctionalDetector</emphasis>.
607Please note that a primitive scorer object must <emphasis role="bold">not</emphasis> be
608shared by more than one <emphasis>G4MultiFunctionalDetector</emphasis>
609object.
610</para>
611
612<para>As mentioned in <xref linkend="sect.Hits.Hit" />,
613each <emphasis>G4VPrimitiveScorer</emphasis> generates one
614<emphasis>G4THitsMap</emphasis> object
615per event. The name of the map object is the same as the name of
616the primitive scorer. Each of the concrete primitive scorers listed
617in <xref linkend="sect.Hits.G4VPrim" /> generates a
618<emphasis>G4THitsMap&lt;G4double&gt;</emphasis> that maps a
619<emphasis>G4double</emphasis> value
620to its key integer number. By default, the key is taken as the copy
621number of the <emphasis>G4LogicalVolume</emphasis> to which
622<emphasis>G4MultiFunctionalDetector</emphasis> is assigned. In case the logical
623volume is uniquely placed in its mother volume and the mother is
624replicated, the copy number of its mother volume can be taken by
625setting the second argument of the <emphasis>G4VPrimitiveScorer</emphasis>
626constructor, "<emphasis>depth</emphasis>" to 1, i.e. one level up. Furthermore,
627in case the key must consider more than one copy number of a
628different geometry hierarchy, the user can derive his/her own
629primitive scorer from the provided concrete class and implement the
630<emphasis>GetIndex(G4Step*)</emphasis> virtual method to return the unique
631key.
632</para>
633
634<para>
635<xref linkend="programlist_Hits_2" /> shows an example of primitive sensitivity
636class definitions.
637
638<example id="programlist_Hits_2">
639<title>
640An example of defining primitive sensitivity classes taken from
641<emphasis>ExN07DetectorConstruction</emphasis>.
642</title>
643<programlisting>
644void ExN07DetectorConstruction::SetupDetectors()
645{
646  G4String filterName, particleName;
647 
648  G4SDParticleFilter* gammaFilter =
649    new G4SDParticleFilter(filterName="gammaFilter",particleName="gamma");
650  G4SDParticleFilter* electronFilter =
651    new G4SDParticleFilter(filterName="electronFilter",particleName="e-");
652  G4SDParticleFilter* positronFilter =
653    new G4SDParticleFilter(filterName="positronFilter",particleName="e+");
654  G4SDParticleFilter* epFilter = new G4SDParticleFilter(filterName="epFilter");
655  epFilter-&gt;add(particleName="e-");
656  epFilter-&gt;add(particleName="e+");
657   
658   
659  for(G4int i=0;i&lt;3;i++)
660  {
661   for(G4int j=0;j&lt;2;j++)
662   {
663    // Loop counter j = 0 : absorber
664    //                = 1 : gap
665    G4String detName = calName[i];
666    if(j==0)
667    { detName += "_abs"; }
668    else
669    { detName += "_gap"; }
670    G4MultiFunctionalDetector* det = new G4MultiFunctionalDetector(detName);
671 
672    //  The second argument in each primitive means the "level" of geometrical hierarchy,
673    // the copy number of that level is used as the key of the G4THitsMap.
674    //  For absorber (j = 0), the copy number of its own physical volume is used.
675    //  For gap (j = 1), the copy number of its mother physical volume is used, since there
676    // is only one physical volume of gap is placed with respect to its mother.
677    G4VPrimitiveScorer* primitive;
678    primitive = new G4PSEnergyDeposit("eDep",j);
679    det-&gt;RegisterPrimitive(primitive);
680    primitive = new G4PSNofSecondary("nGamma",j);
681    primitive-&gt;SetFilter(gammaFilter);
682    det-&gt;RegisterPrimitive(primitive);
683    primitive = new G4PSNofSecondary("nElectron",j);
684    primitive-&gt;SetFilter(electronFilter);
685    det-&gt;RegisterPrimitive(primitive);
686    primitive = new G4PSNofSecondary("nPositron",j);
687    primitive-&gt;SetFilter(positronFilter);
688    det-&gt;RegisterPrimitive(primitive);
689    primitive = new G4PSMinKinEAtGeneration("minEkinGamma",j);
690    primitive-&gt;SetFilter(gammaFilter);
691    det-&gt;RegisterPrimitive(primitive);
692    primitive = new G4PSMinKinEAtGeneration("minEkinElectron",j);
693    primitive-&gt;SetFilter(electronFilter);
694    det-&gt;RegisterPrimitive(primitive);
695    primitive = new G4PSMinKinEAtGeneration("minEkinPositron",j);
696    primitive-&gt;SetFilter(positronFilter);
697    det-&gt;RegisterPrimitive(primitive);
698    primitive = new G4PSTrackLength("trackLength",j);
699    primitive-&gt;SetFilter(epFilter);
700    det-&gt;RegisterPrimitive(primitive);
701    primitive = new G4PSNofStep("nStep",j);
702    primitive-&gt;SetFilter(epFilter);
703    det-&gt;RegisterPrimitive(primitive);
704 
705    G4SDManager::GetSDMpointer()-&gt;AddNewDetector(det);
706    if(j==0)
707    { layerLogical[i]-&gt;SetSensitiveDetector(det); }
708    else
709    { gapLogical[i]-&gt;SetSensitiveDetector(det); }
710   }
711  }
712}
713</programlisting>
714</example>
715</para>
716
717<para>
718Each <emphasis>G4THitsMap</emphasis> object can be accessed from
719<emphasis>G4HCofThisEvent</emphasis> with a unique collection ID number. This ID
720number can be obtained from <emphasis>G4SDManager::GetCollectionID()</emphasis>
721with a name of <emphasis>G4MultiFunctionalDetector</emphasis> and
722<emphasis>G4VPrimitiveScorer</emphasis> connected with a slush ("/").
723<emphasis>G4THitsMap</emphasis> has a [] operator taking the key value as an
724argument and returning <emphasis role="bold">the pointer</emphasis> of the value.
725Please note that the [] operator returns
726<emphasis role="bold">the pointer</emphasis> of the value. If
727you get zero from the [] operator, it does <emphasis role="bold">not</emphasis> mean the
728value is zero, but that the provided key does not exist. The value
729itself is accessible with an astarisk ("*"). It is advised to check
730the validity of the returned pointer before accessing the value.
731<emphasis>G4THitsMap</emphasis> also has a += operator in order to accumulate
732event data into run data. <xref linkend="programlist_Hits_3" /> shows the use of
733<emphasis>G4THitsMap</emphasis>.
734
735<example id="programlist_Hits_3">
736<title>
737An example of accessing to <emphasis>G4THitsMap</emphasis> objects.
738</title>
739
740<programlisting>
741#include "ExN07Run.hh"
742#include "G4Event.hh"
743#include "G4HCofThisEvent.hh"
744#include "G4SDManager.hh"
745
746ExN07Run::ExN07Run()
747{
748  G4String detName[6] = {"Calor-A_abs","Calor-A_gap","Calor-B_abs","Calor-B_gap",
749                         "Calor-C_abs","Calor-C_gap"};
750  G4String primNameSum[6] = {"eDep","nGamma","nElectron","nPositron","trackLength","nStep"};
751  G4String primNameMin[3] = {"minEkinGamma","minEkinElectron","minEkinPositron"};
752
753  G4SDManager* SDMan = G4SDManager::GetSDMpointer();
754  G4String fullName;
755  for(size_t i=0;i&lt;6;i++)
756  {
757    for(size_t j=0;j&lt;6;j++)
758    {
759      fullName = detName[i]+"/"+primNameSum[j];
760      colIDSum[i][j] = SDMan-&gt;GetCollectionID(fullName);
761    }
762    for(size_t k=0;k&lt;3;k++)
763    {
764      fullName = detName[i]+"/"+primNameMin[k];
765      colIDMin[i][k] = SDMan-&gt;GetCollectionID(fullName);
766    }
767  }
768}
769
770
771void ExN07Run::RecordEvent(const G4Event* evt)
772{
773  G4HCofThisEvent* HCE = evt-&gt;GetHCofThisEvent();
774  if(!HCE) return;
775  numberOfEvent++;
776  for(size_t i=0;i&lt;6;i++)
777  {
778    for(size_t j=0;j&lt;6;j++)
779    {
780      G4THitsMap&lt;G4double&gt;* evtMap = (G4THitsMap&lt;G4double&gt;*)(HCE-&gt;GetHC(colIDSum[i][j]));
781      mapSum[i][j] += *evtMap;
782    }
783    for(size_t k=0;k&lt;3;k++)
784    {
785      G4THitsMap&lt;G4double&gt;* evtMap = (G4THitsMap&lt;G4double&gt;*)(HCE-&gt;GetHC(colIDMin[i][k]));
786      std::map&lt;G4int,G4double*&gt;::iterator itr = evtMap-&gt;GetMap()-&gt;begin();
787      for(; itr != evtMap-&gt;GetMap()-&gt;end(); itr++)
788      {
789        G4int key = (itr-&gt;first);
790        G4double val = *(itr-&gt;second);
791        G4double* mapP = mapMin[i][k][key];
792        if( mapP &amp;&amp; (val&gt;*mapP) ) continue;
793        mapMin[i][k].set(key,val);
794      }
795    }
796  }
797}
798</programlisting>
799</example>
800</para>
801
802</sect2>
803
804
805<!-- ******************* Section (Level#2) ****************** -->
806<sect2 id="sect.Hits.G4VPrim">
807<title>
808Concrete classes of <emphasis>G4VPrimitiveScorer</emphasis>
809</title>
810
811<para>
812With Geant4 version 8.0, several concrete primitive scorer classes
813are provided, all of which are derived from the
814<emphasis>G4VPrimitiveScorer</emphasis> abstract base class and which are to be
815registered to <emphasis>G4MultiFunctionalDetector</emphasis>. Each of them
816contains one <emphasis>G4THitsMap</emphasis> object and scores a simple double
817value for each key.
818</para>
819
820<!-- ******* Bridgehead ******* -->
821<bridgehead renderas='sect4'>
822Track length scorers
823</bridgehead>
824
825<para>
826<variablelist><title></title>
827  <varlistentry>
828    <term>
829      G4PSTrackLength
830    </term>
831    <listitem><para>
832      The track length is defined as the sum of step lengths of the
833      particles inside the cell. Bt default, the track weight is not
834      taken into account, but could be used as a multiplier of each step
835      length if the <emphasis>Weighted()</emphasis> method of this class object is
836      invoked.
837    </para></listitem>
838  </varlistentry>
839  <varlistentry>
840    <term>
841      G4PSPassageTrackLength
842    </term>
843    <listitem><para>
844      The passage track length is the same as the track length in
845      <emphasis>G4PSTrackLength</emphasis>, except that only tracks which pass
846      through the volume are taken into account. It means newly-generated or
847      stopped tracks inside the cell are excluded from the calculation.
848      By default, the track weight is not taken into account, but could
849      be used as a multiplier of each step length if the
850      <emphasis>Weighted()</emphasis> method of this class object is invoked.
851    </para></listitem>
852  </varlistentry>
853</variablelist>
854</para>
855
856
857<!-- ******* Bridgehead ******* -->
858<bridgehead renderas='sect4'>
859<emphasis role="bold">Deposited energy scorers</emphasis>
860</bridgehead>
861
862<para>
863<variablelist><title></title>
864  <varlistentry>
865    <term>
866      G4PSEnergyDeposit
867    </term>
868    <listitem><para>
869      This scorer stores a sum of particles' energy deposits at each
870      step in the cell. The particle weight is multiplied at each
871      step.
872    </para></listitem>
873  </varlistentry>
874  <varlistentry>
875    <term>
876      G4PSDoseDeposit
877    </term>
878    <listitem><para>
879      In some cases, dose is a more convenient way to evaluate the
880      effect of energy deposit in a cell than simple deposited energy.
881      The dose deposit is defined by the sum of energy deposits at each
882      step in a cell divided by the mass of the cell. The mass is
883      calculated from the density and volume of the cell taken from the
884      methods of <emphasis>G4VSolid</emphasis> and
885      <emphasis>G4LogicalVolume</emphasis>. The particle
886      weight is multiplied at each step.
887    </para></listitem>
888  </varlistentry>
889</variablelist>
890</para>
891
892<!-- ******* Bridgehead ******* -->
893<bridgehead renderas='sect4'>
894<emphasis role="bold">Current and flux scorers</emphasis>
895</bridgehead>
896
897<para>
898There are two different definitions of a particle's flow for a
899given geometry. One is a current and the other is a flux. In our
900scorers, the current is simply defined as the number of particles
901(with the particle's weight) at a certain surface or volume, while
902the flux takes the particle's injection angle to the geometry into
903account. The current and flux are usually defined at a surface, but
904volume current and volume flux are also provided.
905</para>
906
907<para>
908<variablelist><title></title>
909  <varlistentry>
910    <term>
911      G4PSFlatSurfaceCurrent
912    </term>
913    <listitem><para>
914      Flat surface current is a surface based scorer. The present
915      implementation is limited to scoring only at the -Z surface of a
916      <emphasis>G4Box</emphasis> solid. The quantity is defined by the number
917      of tracks that reach the surface. The user must choose a direction of the
918      particle to be scored. The choices are fCurrent_In, fCurrent_Out,
919      or fCurrent_InOut, one of which must be entered as the second
920      argument of the constructor. Here, fCurrent_In scores incoming
921      particles to the cell, while fCurrent_Out scores only outgoing
922      particles from the cell. fCurrent_InOut scores both directions. The
923      current is multiplied by particle weight and is normalized for a
924      unit area.
925    </para></listitem>
926  </varlistentry>
927  <varlistentry>
928    <term>
929      G4PSSphereSurfaceCurrent
930    </term>
931    <listitem><para>
932      Sphere surface current is a surface based scorer, and similar
933      to the G4PSFlatSurfaceCurrent. The only difference is that the
934      surface is defined at the <emphasis role="bold">inner surface</emphasis> 
935      of a G4Sphere solid.
936    </para></listitem>
937  </varlistentry>
938  <varlistentry>
939    <term>
940      G4PSPassageCurrent
941    </term>
942    <listitem><para>
943      Passage current is a volume-based scorer. The current is
944      defined by the number of tracks that pass through the volume. A
945      particle weight is applied at the exit point. A passage current is
946      defined for a volume.
947    </para></listitem>
948  </varlistentry>
949  <varlistentry>
950    <term>
951      G4PSFlatSurfaceFlux
952    </term>
953    <listitem><para>
954      Flat surface flux is a surface based flux scorer. The surface
955      flux is defined by the number of tracks that reach the surface. The
956      expression of surface flux is given by the sum of W/cos(t)/A, where
957      W, t and A represent particle weight, injection angle of particle
958      with respect to the surface normal, and area of the surface. The
959      user must enter one of the particle directions, fFlux_In,
960      fFlux_Out, or fFlux_InOut in the constructor. Here, fFlux_In scores
961      incoming particles to the cell, while fFlux_Out scores outgoing
962      particles from the cell. fFlux_InOut scores both directions.
963    </para></listitem>
964  </varlistentry>
965  <varlistentry>
966    <term>
967      G4PSCellFlux
968    </term>
969    <listitem><para>
970      Cell flux is a volume based flux scorer. The cell flux is
971      defined by a track length (L) of the particle inside a volume
972      divided by the volume (V) of this cell. The track length is
973      calculated by a sum of the step lengths in the cell. The expression
974      for cell flux is given by the sum of (W*L)/V, where W is a particle
975      weight, and is multiplied by the track length at each step.
976    </para></listitem>
977  </varlistentry>
978  <varlistentry>
979    <term>
980      G4PSPassageCellFlux
981    </term>
982    <listitem><para>
983      Passage cell flux is a volume based scorer similar to
984      <emphasis>G4PSCellFlux</emphasis>. The only difference is that tracks
985      which pass through a cell are taken into account. It means generated or
986      stopped tracks inside the volume are excluded from the
987      calculation.
988    </para></listitem>
989  </varlistentry>
990</variablelist>
991</para>
992
993<!-- ******* Bridgehead ******* -->
994<bridgehead renderas='sect4'>
995<emphasis role="bold">Other scorers</emphasis>
996</bridgehead>
997
998<para>
999<variablelist><title></title>
1000  <varlistentry>
1001    <term>
1002      G4PSMinKinEAtGeneration
1003    </term>
1004    <listitem><para>
1005      This scorer records the minimum kinetic energy of secondary
1006      particles at their production point in the volume in an event. This
1007      primitive scorer does not integrate the quantity, but records the
1008      minimum quantity.
1009    </para></listitem>
1010  </varlistentry>
1011  <varlistentry>
1012    <term>
1013      G4PSNofSecondary
1014    </term>
1015    <listitem><para>
1016      This class scores the number of secondary particles generated
1017      in the volume. The weight of the secondary track is taken into
1018      account.
1019    </para></listitem>
1020  </varlistentry>
1021  <varlistentry>
1022    <term>
1023      G4PSNofStep
1024    </term>
1025    <listitem><para>
1026      This class scores the number of steps in the cell. A particle
1027      weight is not applied.
1028    </para></listitem>
1029  </varlistentry>
1030  <varlistentry>
1031    <term>
1032      G4PSCellCharge
1033    </term>
1034    <listitem><para>
1035      This class scored the total charge of particles which has stoped
1036      in the volume.
1037    </para></listitem>
1038  </varlistentry>
1039</variablelist>
1040</para>
1041
1042</sect2>
1043
1044
1045<!-- ******************* Section (Level#2) ****************** -->
1046<sect2 id="sect.Hits.G4VSDFil">
1047<title>
1048<emphasis>G4VSDFilter</emphasis> and its derived classes
1049</title>
1050
1051<para>
1052<emphasis>G4VSDFilter</emphasis> is an abstract class that represents a track
1053filter to be associated with <emphasis>G4VSensitiveDetector</emphasis> or
1054<emphasis>G4VPrimitiveScorer</emphasis>. It defines a virtual method
1055
1056<informalexample>
1057<programlisting>
1058  <emphasis>G4bool Accept(const G4Step*)</emphasis>
1059</programlisting>
1060</informalexample>
1061
1062that should return <emphasis>true</emphasis> if this particular step should be
1063scored by the <emphasis>G4VSensitiveDetector</emphasis> or
1064<emphasis>G4VPrimitiveScorer</emphasis>.
1065</para>
1066
1067<para>
1068While the user can implement his/her own filter class, Geant4
1069version 8.0 provides the following concrete filter classes:
1070
1071<variablelist><title></title>
1072  <varlistentry>
1073    <term>
1074      G4SDChargedFilter
1075    </term>
1076    <listitem><para>
1077      All charged particles are accepted.
1078    </para></listitem>
1079  </varlistentry>
1080  <varlistentry>
1081    <term>
1082      G4SDNeutralFilter
1083    </term>
1084    <listitem><para>
1085      All neutral particles are accepted.
1086    </para></listitem>
1087  </varlistentry>
1088  <varlistentry>
1089    <term>
1090      G4SDParticleFilter
1091    </term>
1092    <listitem><para>
1093      Particle species which are registered to this filter object by
1094      <emphasis>Add("particle_name")</emphasis> are accepted. More than one
1095      species can be registered.
1096    </para></listitem>
1097  </varlistentry>
1098  <varlistentry>
1099    <term>
1100      G4SDKineticEnergyFilter
1101    </term>
1102    <listitem><para>
1103      A track with kinetic energy greater than or equal to EKmin and
1104      smaller than EKmin is accepted. EKmin and EKmax should be defined
1105      as arguments of the constructor. The default values of EKmin and
1106      EKmax are zero and DBL_MAX.
1107    </para></listitem>
1108  </varlistentry>
1109  <varlistentry>
1110    <term>
1111      G4SDParticleWithEnergyFilter
1112    </term>
1113    <listitem><para>
1114      Combination of <emphasis>G4SDParticleFilter</emphasis> and
1115      <emphasis>G4SDParticleWithEnergyFilter</emphasis>.
1116    </para></listitem>
1117  </varlistentry>
1118</variablelist>
1119</para>
1120
1121<para>
1122The use of the <emphasis>G4SDParticleFilter</emphasis> class is demonstrated
1123in <xref linkend="programlist_Hits_2" />, where filters which accept gamma,
1124electron, positron and electron/positron are defined.
1125</para>
1126
1127
1128</sect2>
1129
1130
1131<!-- ******************* Section (Level#2) ****************** -->
1132<sect2 id="sect.EvtBias.ScorImpRoul.Scor">
1133<title>
1134Scoring for Event Biasing
1135</title>
1136
1137<para>
1138Scoring for Event Biasing (described in <xref linkend="sect.EvtBias" />) is a
1139very specific use case whereby particle weights and fluxes through importance
1140cells are required.  The goals of the scoring technique are to:
1141
1142<itemizedlist spacing="compact">
1143  <listitem><para>
1144    appraise particle quantities related to special regions or
1145    surfaces,
1146  </para></listitem>
1147  <listitem><para>
1148    be applicable to all "cells" (physical volumes or replicas) of
1149    a given geometry,
1150  </para></listitem>
1151  <listitem><para>
1152    be customizable.
1153  </para></listitem>
1154</itemizedlist>
1155</para>
1156
1157<para>
1158Standard scoring must be provided for quantities such as tracks
1159entering a cell, average weight of entering tracks, energy of
1160entering tracks, and collisions inside the cell.
1161</para>
1162
1163<para>
1164A number of scorers have been created for this specific appliction:
1165</para>
1166
1167<para>
1168<variablelist><title></title>
1169  <varlistentry>
1170    <term>
1171      G4PSNofCollision
1172    </term>
1173    <listitem><para>
1174    This scorer records the number of collisions that occur within a scored volume/cell.
1175    There is the additional possibility to take into account the track weight
1176    whilst scoring the number of collisions, via the following command:
1177<informalexample>
1178<programlisting>
1179  G4PSNofCollision*   scorer1 = new G4PSNofCollision(psName="CollWeight"); 
1180  scorer1->Weighted(true);
1181</programlisting>
1182</informalexample>
1183      </para></listitem>
1184  </varlistentry>
1185  <varlistentry>
1186    <term>
1187      G4PSPopulation
1188    </term>
1189    <listitem><para>
1190      This scores the number of tracks within in a given cell per event.
1191   </para></listitem>
1192  </varlistentry>
1193  <varlistentry>
1194    <term>
1195      G4PSTrackLength
1196    </term>
1197    <listitem><para>
1198      The track lengths within a cell are measured and if, additionally, the result is desired
1199      to be weighted then the following code has to be implemented:
1200<informalexample>
1201<programlisting>
1202  G4PSTrackLength* scorer5 = new G4PSTrackLength(psName="SLW"); 
1203  scorer5->Weighted(true);
1204</programlisting>
1205</informalexample>
1206  Further if the energy track flux is required then the following should be
1207  implemented:
1208<informalexample>
1209<programlisting>
1210  G4PSTrackLength* scorer6 = new G4PSTrackLength(psName="SLWE"); 
1211  scorer6->Weighted(true);
1212  scorer6->MultiplyKineticEnergy(true);
1213  MFDet->RegisterPrimitive(scorer6);
1214</programlisting>
1215</informalexample>
1216
1217     Alternatively to measure the flux per unit velocity then:
1218<informalexample>
1219<programlisting>
1220  G4PSTrackLength* scorer7 = new G4PSTrackLength(psName="SLW_V"); 
1221  scorer7->Weighted(true);
1222  scorer7->DivideByVelocity(true);
1223  MFDet->RegisterPrimitive(scorer7);
1224</programlisting>
1225</informalexample>
1226
1227   Finally to measure the flux energy per unit velocity then:
1228<informalexample>
1229<programlisting>
1230  G4PSTrackLength* scorer8 = new G4PSTrackLength(psName="SLWE_V"); 
1231  scorer8->Weighted(true);
1232  scorer8->MultiplyKineticEnergy(true);
1233  scorer8->DivideByVelocity(true);
1234  MFDet->RegisterPrimitive(scorer8);
1235</programlisting>
1236</informalexample>
1237    </para></listitem>
1238  </varlistentry>
1239</variablelist>
1240</para>
1241
1242
1243</sect2>
1244
1245</sect1>
Note: See TracBrowser for help on using the repository browser.