]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FASTSIM/AliFastDetector.cxx
Minor script fixes
[u/mrichter/AliRoot.git] / FASTSIM / AliFastDetector.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17 //
18 // Base class for fast simulation of a detctor
19 // or a system of subdetectors.
20 // The detector response is described by resolution and efficiency.
21 // Author:
22 // Andreas Morsch
23 // andreas.morsch@cern.ch
24
25 #include "AliFastDetector.h"
26 #include "AliFastResponse.h"
27 #include "AliGeometry.h"
28
29 #include <TList.h>
30 #include <TIterator.h>
31 #include <TString.h>
32
33 ClassImp(AliFastDetector)
34
35
36 AliFastDetector::AliFastDetector():
37     fSubdetectors(0),
38     fResponses(0),
39     fLnkD(0),
40     fLnkR(0),
41     fEfficiency(0),
42     fResolution(0),
43     fGeometry(0)
44 {
45 // Default Constructor
46     fName  = "FastDetector";
47     fTitle = "Fast Detector Base Class";
48 }
49
50 AliFastDetector::AliFastDetector(char* Name, char* Title):
51     TNamed(Name, Title),
52     fSubdetectors(0),
53     fResponses(0),
54     fLnkD(0),
55     fLnkR(0),
56     fEfficiency(0),
57     fResolution(0),
58     fGeometry(0)
59 {
60 // Constructor
61  }
62
63 AliFastDetector::AliFastDetector(const AliFastDetector & det)
64     :TNamed(det),
65     fSubdetectors(0),
66     fResponses(0),
67     fLnkD(0),
68     fLnkR(0),
69     fEfficiency(0),
70     fResolution(0),
71     fGeometry(0)
72 {
73 // Copy constructor
74     det.Copy(*this);
75 }
76
77 AliFastDetector::~AliFastDetector()
78 {
79 // Destructor
80     delete fSubdetectors;
81     delete fResponses;
82 }
83
84
85 void AliFastDetector::Init()
86 {
87 //
88 // Initialisation
89 //
90     TIter nextRes(fResponses);
91     AliFastResponse *res;
92     //
93     // Loop over responses  and initialize
94     while((res = (AliFastResponse*)nextRes())) {
95         res->Init();
96     }  
97
98     TIter nextDet(fSubdetectors);
99     AliFastDetector *det;
100     //
101     // Loop over subdetectors  and initialize
102     while((det = (AliFastDetector*)nextDet())) {
103         det->Init();
104     }  
105     //
106     TObject* obj;
107     
108     if ((obj = fResponses->FindObject("Efficiency")))
109     {
110
111         fEfficiency = (AliFastResponse*) obj;
112         printf("Detector %s provides Efficiency: %s\n",
113                fName.Data(), fEfficiency->GetTitle());
114     }
115     
116     if ((obj = fResponses->FindObject("Resolution"))) 
117     {
118         fResolution = (AliFastResponse*) obj;
119         printf("Detector %s provides Resolution: %s\n",
120                fName.Data(), fResolution->GetTitle());
121     }
122 }
123
124 Float_t AliFastDetector::EvaluateEfficiency(AliFastParticle* part)
125 {
126 //
127 //  Evaluate the efficiency for detecting particle part
128 //
129     TIter nextDet(fSubdetectors);
130     AliFastDetector *det;
131     //
132     // Loop over subdetectors  
133     Float_t eff = 1;
134     while((det = (AliFastDetector*)nextDet())) {
135         eff *= det->EvaluateEfficiency(part);
136     }  
137     return eff;
138 }
139
140 Bool_t  AliFastDetector::EvaluateAcceptance(AliFastParticle* part)
141 {
142     //
143     // Loop over subdetectors 
144     Bool_t acc = kFALSE;
145
146     if (fSubdetectors) {
147         TIter nextDet(fSubdetectors);
148         AliFastDetector *det;
149         while((det = (AliFastDetector*)nextDet()) && !acc) {
150             acc = (acc ||  det->EvaluateAcceptance(part));
151         }  
152     } else {
153         if (fGeometry)
154         acc = fGeometry->Impact((TParticle*) part);
155     }
156     
157     return acc;
158 }
159
160 void    AliFastDetector::EvaluateResponse(AliFastParticle* /*part*/)
161 {
162     ;
163 }
164
165 void AliFastDetector::
166 AddSubdetector(AliFastDetector *Detector, char* /*Name*/)
167 {
168 //
169 //  Add detector to list   
170      fSubdetectors->Add(Detector);
171 }
172
173
174
175 void AliFastDetector::
176 AddResponse(AliFastResponse *Response)
177 {
178 //
179 //  Add detector to list   
180      fResponses->Add(Response);
181 }
182
183
184 AliFastDetector*  AliFastDetector::FirstSubdetector()
185 {
186 // Iterator over generators: Initialisation
187     fLnkD = fSubdetectors->FirstLink();
188     if (fLnkD) {
189         return (AliFastDetector*) (fLnkD->GetObject());
190     } else {
191         return 0;
192     }
193 }
194
195 AliFastDetector*  AliFastDetector::NextSubdetector()
196 {
197 // Iterator over generators: Increment
198     fLnkD = fLnkD->Next();
199     if (fLnkD) {
200         return (AliFastDetector*) (fLnkD->GetObject());
201     } else {
202         return 0;
203     }
204 }
205
206
207 AliFastResponse*  AliFastDetector::FirstResponse()
208 {
209 // Iterator over generators: Initialisation
210     fLnkR = fResponses->FirstLink();
211     if (fLnkR) {
212         return (AliFastResponse*) (fLnkR->GetObject());
213     } else {
214         return 0;
215     }
216 }
217
218 AliFastResponse*  AliFastDetector::NextResponse()
219 {
220 // Iterator over generators: Increment
221     fLnkR = fLnkR->Next();
222     if (fLnkR) {
223         return (AliFastResponse*) (fLnkR->GetObject());
224     } else {
225         return 0;
226     }
227 }
228
229
230 AliFastDetector& AliFastDetector::operator=(const  AliFastDetector& rhs)
231 {
232 // Assignment operator
233     rhs.Copy(*this);
234     return *this;
235 }
236
237 void AliFastDetector::Copy(TObject&) const
238 {
239     //
240     // Copy 
241     //
242     Fatal("Copy","Not implemented!\n");
243 }
244