Project

General

Profile

Adding Detectors » History » Version 3

Ole Hansen, 03/05/2018 03:29 PM

1 1 Ole Hansen
h1. Adding and removing a detector
2
3
Suppose you have just written a new detector class and want to try it out. The easiest way to do so is via the "@AddDetector()@":http://hallaweb.jlab.org/podd/html/THaApparatus.html#THaApparatus:AddDetector method of the apparatus class. For example, your script could do the following:
4 2 Ole Hansen
<pre><code class="cplusplus">
5 1 Ole Hansen
// Instantiate the Right Arm HRS apparatus and add it to the list of
6
// apparatuses to be analyzed
7
THaApparatus* HRSR = new THaHRS("R","Electron HRS");
8
gHaApps->Add( HRSR );
9
10
// Create an instance of the new hyper scintillator detector
11
THaDetector* hs = new THaHyperScintillator("hs","Hyper Scintillator");
12
13
// Add this detector to the Right Arm HRS
14
HRSR->AddDetector( hs );
15
16
// ... do your analysis
17 2 Ole Hansen
</code></pre>
18 1 Ole Hansen
That's it! No need to compile anything (except your new detector class, of course). This looks awfully simple, in fact too good to be true! Welcome to the power of object-oriented programming.
19
20
Of course, you must add appropriate database entires for your detector, unless you have hardcoded everything (urgh).
21
22
A detector added to an apparatus in this way will work like any other detector associated with the apparatus in the sense that its standard processing methods will be called in the correct order and with the correct arguments. That is, @Decode()@ and @CoarseProcess()@/@FineProcess()@ or @CoarseTrack()@/@FineTrack()@ will be called as expected. The new detector may even call methods of other detectors within the same apparatus and access any global physics variables available, within the same restrictions that apply to detectors instantiated in the apparatus's constructor.
23
24
There is no real limitation to using this method as compared to instantiating a detector in the apparatus's constructor. It should work with any detector objects, including tracking detectors. However, @AddDetector()@ should not be used to add detectors whose methods or global physics variables are to be used by any default detectors of the apparatus. The reason is simply that other detectors should not rely on detectors being present that are defined "manually" by the user in the steering script. It is easy to forget to define such a detector or to comment out the instantiation. Of course, well-written code should test for the detector's presence and should not crash, but correct behavior is not guaranteed in that case. In brief, detectors that other detectors need to be present should be instantiated in the apparatus's constructor.
25
26
How to clean up? Normally, no need to bother. In a simple analysis session, you will probably exit ROOT after the analysis anyway and everything will be automatically deleted. If you do want to clean up yourself:
27 2 Ole Hansen
<pre><code class="cplusplus">
28 1 Ole Hansen
// Be careful not to delete the detector before deleting the apparatus!
29
// Otherwise the analyzer will crash - guaranteed.
30
// Exiting ROOT will do this automatically anyway, so usually don't 
31
// bother with it.
32
gHaApps->Delete();  // Deletes only default detectors of the apparatuses.
33
delete hs;
34 2 Ole Hansen
</code></pre>
35 1 Ole Hansen
To make a detector more permanent, you could add its instantiation to the apparatus's constructor. For example:
36 2 Ole Hansen
<pre><code class="cplusplus">
37 1 Ole Hansen
void THaMyHRS::THaMyHRS( const char* name, const char* description ) :
38
  THaHRS( name, description )
39
{
40
  // Constructor. Defines the standard detectors for MyHRS.
41
  // NB: The standard HRS detectors (VDC, S1, S2) are defined
42
  // in the THaHRS constructor.
43
44
  AddDetector( new THaHyperScintllator("hs","Hyp Scint"));
45
}
46 2 Ole Hansen
</code></pre>
47 1 Ole Hansen
However, writing a new apparatus inheriting from "@THaHRS@":http://hallaweb.jlab.org/podd/html/THaHRS.html just to add your own detectors is not really necessary unless you need to do special processing that requires the presence of those detectors.
48
49
How about removing a detector from a standard apparatus? This is not as trivial. Of course, one could provide a @RemoveDetector()@ method. However, for the reasons mentioned above, this could cause trouble if other detectors or parts of the analysis algorithm (e.g. beta calculation) depend on the presence of the detector you want to remove. Because of this, there is no support for simple removal of a detector in the present version of the analyzer.