1 | #include "MStarLight.hxx"
|
---|
2 |
|
---|
3 | using namespace std;
|
---|
4 |
|
---|
5 | MStarLight::MStarLight() {
|
---|
6 | //
|
---|
7 | // default constructor
|
---|
8 | //
|
---|
9 |
|
---|
10 | fBrightness = 0. ;
|
---|
11 | fTimeRange = TIMERANGE ;
|
---|
12 |
|
---|
13 | fBinsTrig = TRIGBINS ;
|
---|
14 | fTrigShape = 0. ;
|
---|
15 | fAmplTrig = 0. ;
|
---|
16 | fFwhmTrig = 0. ;
|
---|
17 |
|
---|
18 | fBinsFadc = FADCBINS ;
|
---|
19 | fFadcShape = 0. ;
|
---|
20 | fIntegFadc = 0. ;
|
---|
21 | fFwhmFadc = 0. ;
|
---|
22 |
|
---|
23 |
|
---|
24 | for (Int_t i= 0; i< TRIGBINS ; i++)
|
---|
25 | fTrig[i] = 0. ;
|
---|
26 |
|
---|
27 | for (Int_t i= 0; i<FADCBINS; i++)
|
---|
28 | fFadc[i] = 0. ;
|
---|
29 |
|
---|
30 | for (Int_t i= 0; i<40; i++)
|
---|
31 | fTrigResp[i] = 0. ;
|
---|
32 |
|
---|
33 | for (Int_t i= 0; i<45; i++)
|
---|
34 | fFadcResp[i] = 0. ;
|
---|
35 | }
|
---|
36 |
|
---|
37 | void MStarLight::Reset() {
|
---|
38 |
|
---|
39 |
|
---|
40 | fBrightness = 0. ;
|
---|
41 | fTimeRange = TIMERANGE ;
|
---|
42 |
|
---|
43 | fBinsTrig = TRIGBINS ;
|
---|
44 | fTrigShape = 0. ;
|
---|
45 | fAmplTrig = 0. ;
|
---|
46 | fFwhmTrig = 0. ;
|
---|
47 |
|
---|
48 | fBinsFadc = FADCBINS ;
|
---|
49 | fFadcShape = 0. ;
|
---|
50 | fIntegFadc = 0. ;
|
---|
51 | fFwhmFadc = 0. ;
|
---|
52 |
|
---|
53 |
|
---|
54 | for (Int_t i= 0; i< TRIGBINS ; i++)
|
---|
55 | fTrig[i] = 0. ;
|
---|
56 |
|
---|
57 | for (Int_t i= 0; i<FADCBINS; i++)
|
---|
58 | fFadc[i] = 0. ;
|
---|
59 |
|
---|
60 | for (Int_t i= 0; i<40; i++)
|
---|
61 | fTrigResp[i] = 0. ;
|
---|
62 |
|
---|
63 | for (Int_t i= 0; i<45; i++)
|
---|
64 | fFadcResp[i] = 0. ;
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 |
|
---|
69 | Float_t MStarLight::GetBrightness ()
|
---|
70 | {
|
---|
71 | return fBrightness ;
|
---|
72 | }
|
---|
73 |
|
---|
74 | void MStarLight::SetBrightness (Float_t in )
|
---|
75 | {
|
---|
76 | fBrightness = in ;
|
---|
77 | }
|
---|
78 |
|
---|
79 | Float_t MStarLight::GetAmplTrig ()
|
---|
80 | {
|
---|
81 | return fAmplTrig ;
|
---|
82 | }
|
---|
83 |
|
---|
84 | void MStarLight::SetAmplTrig (Float_t in )
|
---|
85 | {
|
---|
86 | fAmplTrig = in ;
|
---|
87 | }
|
---|
88 |
|
---|
89 | Float_t MStarLight::GetFwhmTrig ()
|
---|
90 | {
|
---|
91 | return fFwhmTrig ;
|
---|
92 | }
|
---|
93 |
|
---|
94 | void MStarLight::SetFwhmTrig (Float_t in )
|
---|
95 | {
|
---|
96 | fFwhmTrig = in ;
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | Float_t MStarLight::GetIntegFadc ()
|
---|
101 | {
|
---|
102 | return fIntegFadc ;
|
---|
103 | }
|
---|
104 |
|
---|
105 | void MStarLight::SetIntegFadc (Float_t in )
|
---|
106 | {
|
---|
107 | fIntegFadc = in ;
|
---|
108 | }
|
---|
109 |
|
---|
110 | Float_t MStarLight::GetFwhmFadc ()
|
---|
111 | {
|
---|
112 | return fFwhmFadc ;
|
---|
113 | }
|
---|
114 |
|
---|
115 | void MStarLight::SetFwhmFadc (Float_t in )
|
---|
116 | {
|
---|
117 | fFwhmFadc = in ;
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | void MStarLight::SetTrigResponse( Float_t *in ) {
|
---|
122 |
|
---|
123 | for (Int_t i= 0; i<40; i++)
|
---|
124 | fTrigResp[i] = in[i] ;
|
---|
125 |
|
---|
126 | }
|
---|
127 |
|
---|
128 | void MStarLight::SetFadcResponse( Float_t *in ) {
|
---|
129 |
|
---|
130 | for (Int_t i= 0; i<45; i++)
|
---|
131 | fFadcResp[i] = in[i] ;
|
---|
132 | }
|
---|
133 |
|
---|
134 | void MStarLight::FillResponse( Float_t ampl, Float_t time ) {
|
---|
135 |
|
---|
136 | // fill the trigger response
|
---|
137 |
|
---|
138 | Int_t startbin = (Int_t) (time * 4) ;
|
---|
139 |
|
---|
140 | Int_t icount = 0 ;
|
---|
141 | Int_t idata ;
|
---|
142 |
|
---|
143 | for ( Int_t i=startbin ; i<startbin+40 ; i++) {
|
---|
144 | //
|
---|
145 | if ( i < TRIGBINS )
|
---|
146 | idata = i ;
|
---|
147 | else if ( i >= TRIGBINS )
|
---|
148 | idata = i - TRIGBINS ;
|
---|
149 |
|
---|
150 | fTrig[idata] = fTrig[idata] + ampl * fTrigResp[icount] ;
|
---|
151 |
|
---|
152 | icount++ ;
|
---|
153 | }
|
---|
154 |
|
---|
155 | //
|
---|
156 | // fill the FADC content
|
---|
157 | //
|
---|
158 |
|
---|
159 | startbin = (Int_t) ( time / 0.6666666666 );
|
---|
160 |
|
---|
161 | Int_t ichanfadc = 0 ;
|
---|
162 |
|
---|
163 | //
|
---|
164 | // putting the response slices in the right sig slices.
|
---|
165 | // Be carefull, because both slices have different widths.
|
---|
166 | //
|
---|
167 |
|
---|
168 | //
|
---|
169 | // Changed, Jan 2004, A. Moralejo: now the FADC does not integrate all
|
---|
170 | // the signal within each FADC slice, but measures just the signal height
|
---|
171 | // at one point, like the real FADC does. By default, each FADC slice
|
---|
172 | // contains 5 bins of the response histogram(fFadcResp[45]). Warning:
|
---|
173 | // do not change this unless you do the corresponding modifications also
|
---|
174 | // in MFadc.cxx, or the signal and the noise photoelectrons will be treated
|
---|
175 | // differently!!
|
---|
176 | //
|
---|
177 |
|
---|
178 | for ( Int_t i = 0 ; i < 45; i += 5 ) {
|
---|
179 | ichanfadc = (Int_t) ((startbin+i)/5) ;
|
---|
180 |
|
---|
181 | if ( (ichanfadc) < FADCBINS )
|
---|
182 | idata = ichanfadc ;
|
---|
183 | else if ( ichanfadc >=FADCBINS )
|
---|
184 | idata = ichanfadc-FADCBINS ;
|
---|
185 |
|
---|
186 | fFadc[idata] += (ampl * fFadcResp[i] ) ;
|
---|
187 |
|
---|
188 | }
|
---|
189 |
|
---|
190 | }
|
---|
191 |
|
---|
192 | void MStarLight::ElecNoise ( Float_t noiseTrig, Float_t noiseFadc ) {
|
---|
193 | //
|
---|
194 | // putting some noise to the baseline
|
---|
195 | //
|
---|
196 |
|
---|
197 | TRandom2 wuerfel( (UInt_t) (noiseTrig*100) ) ;
|
---|
198 |
|
---|
199 | for (Int_t i=0; i< TRIGBINS ; i++ ) {
|
---|
200 | fTrig[i] += wuerfel.Gaus(0., noiseTrig ) ;
|
---|
201 | }
|
---|
202 |
|
---|
203 | for (Int_t i=0; i< FADCBINS ; i++ ) {
|
---|
204 | fFadc[i] += wuerfel.Gaus(0., noiseFadc ) ;
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|
208 | }
|
---|
209 |
|
---|
210 | Float_t MStarLight::GetTrig( Int_t i){
|
---|
211 | //------------------------------------------------------------------
|
---|
212 | //
|
---|
213 | // It gets the value of the simualted trigger in the i bin
|
---|
214 | //
|
---|
215 | return fTrig[i];
|
---|
216 | }
|
---|
217 |
|
---|
218 | Float_t MStarLight::GetFadc( Int_t i){
|
---|
219 | //------------------------------------------------------------------
|
---|
220 | //
|
---|
221 | // It gets the value of the simualted FADC signal in the i bin
|
---|
222 | //
|
---|
223 | return fFadc[i];
|
---|
224 | }
|
---|
225 |
|
---|
226 | void MStarLight::StoreHisto( char *filename) {
|
---|
227 |
|
---|
228 | Float_t baseline = 0. ;
|
---|
229 |
|
---|
230 |
|
---|
231 | // first the histogramms for trigger
|
---|
232 | //
|
---|
233 | // the calculated trigger signal before baseline
|
---|
234 | //
|
---|
235 |
|
---|
236 | TH1F trigresp ("trigresp", "Trigger Response", TRIGBINS, 0., TIMERANGE) ;
|
---|
237 |
|
---|
238 | for (Int_t i=0; i< TRIGBINS ; i++ ) {
|
---|
239 |
|
---|
240 | trigresp.SetBinContent(i, fTrig[i]) ;
|
---|
241 |
|
---|
242 | baseline = baseline + fTrig[i] ;
|
---|
243 | }
|
---|
244 |
|
---|
245 | baseline = baseline / TRIGBINS ;
|
---|
246 |
|
---|
247 | TH1F trigbase ("trigbase", "Response after Baseline shift",
|
---|
248 | TRIGBINS, 0., TIMERANGE) ;
|
---|
249 | for (Int_t i=0; i< TRIGBINS ; i++ ) {
|
---|
250 |
|
---|
251 | trigbase.SetBinContent(i, fTrig[i]-baseline ) ;
|
---|
252 |
|
---|
253 | }
|
---|
254 |
|
---|
255 | TH1F trigdist ("trigdist", "Noise on the baseline",
|
---|
256 | 1000, -25., 25. ) ;
|
---|
257 |
|
---|
258 | for (Int_t i=0; i< TRIGBINS ; i++ ) {
|
---|
259 |
|
---|
260 | trigdist.Fill( (Float_t) trigbase.GetBinContent(i) ) ;
|
---|
261 | }
|
---|
262 |
|
---|
263 |
|
---|
264 | //
|
---|
265 | // second the histograms for the fadc
|
---|
266 | //
|
---|
267 |
|
---|
268 |
|
---|
269 | TH1F fadcresp ("fadcresp", "Fadc Response", FADCBINS, 0., TIMERANGE) ;
|
---|
270 |
|
---|
271 | for (Int_t i=0; i< FADCBINS ; i++ ) {
|
---|
272 |
|
---|
273 | fadcresp.SetBinContent(i, fFadc[i]) ;
|
---|
274 |
|
---|
275 | baseline = baseline + fFadc[i] ;
|
---|
276 | }
|
---|
277 |
|
---|
278 | baseline = baseline / FADCBINS ;
|
---|
279 |
|
---|
280 | TH1F fadcbase ("fadcbase", "Fadc after Baseline shift",
|
---|
281 | FADCBINS, 0., TIMERANGE) ;
|
---|
282 | for (Int_t i=0; i< FADCBINS ; i++ ) {
|
---|
283 |
|
---|
284 | fadcbase.SetBinContent(i, fFadc[i]-baseline ) ;
|
---|
285 |
|
---|
286 | }
|
---|
287 |
|
---|
288 | TH1F fadcdist ("fadcdist", "Noise on fadc",
|
---|
289 | 1000, -100., 100. ) ;
|
---|
290 |
|
---|
291 | for (Int_t i=0; i< FADCBINS ; i++ ) {
|
---|
292 |
|
---|
293 | fadcdist.Fill( (Float_t) fadcbase.GetBinContent(i) ) ;
|
---|
294 | }
|
---|
295 |
|
---|
296 |
|
---|
297 |
|
---|
298 |
|
---|
299 | TFile outfile( filename, "UPDATE" ) ;
|
---|
300 |
|
---|
301 | trigresp.Write() ;
|
---|
302 | trigbase.Write() ;
|
---|
303 | trigdist.Write() ;
|
---|
304 |
|
---|
305 | fadcresp.Write() ;
|
---|
306 | fadcbase.Write() ;
|
---|
307 | fadcdist.Write() ;
|
---|
308 |
|
---|
309 |
|
---|
310 | outfile.Close() ;
|
---|
311 | }
|
---|
312 |
|
---|
313 | void MStarLight::WriteBinary( char *filename) {
|
---|
314 | //
|
---|
315 | // write the things to the binary file
|
---|
316 |
|
---|
317 | FILE *datei ;
|
---|
318 |
|
---|
319 | datei = fopen ( filename, "w" ) ;
|
---|
320 |
|
---|
321 | if ( ! datei ) {
|
---|
322 | cout << " ERROR: Can't open the file " << filename
|
---|
323 | << endl ;
|
---|
324 | exit (230) ;
|
---|
325 | }
|
---|
326 |
|
---|
327 | Float_t version = VERSIONSR;
|
---|
328 |
|
---|
329 | // write them out
|
---|
330 |
|
---|
331 | fwrite ( &version, sizeof(Float_t), 1, datei ) ;
|
---|
332 | fwrite ( &fBrightness, sizeof(Float_t), 1, datei ) ;
|
---|
333 | fwrite ( &fTimeRange , sizeof(Float_t), 1, datei ) ;
|
---|
334 |
|
---|
335 | fwrite ( &fBinsTrig , sizeof(Float_t), 1, datei ) ;
|
---|
336 | fwrite ( &fTrigShape , sizeof(Float_t), 1, datei ) ;
|
---|
337 | fwrite ( &fAmplTrig , sizeof(Float_t), 1, datei ) ;
|
---|
338 | fwrite ( &fFwhmTrig , sizeof(Float_t), 1, datei ) ;
|
---|
339 |
|
---|
340 | fwrite ( &fBinsFadc , sizeof(Float_t), 1, datei ) ;
|
---|
341 | fwrite ( &fFadcShape , sizeof(Float_t), 1, datei ) ;
|
---|
342 | fwrite ( &fIntegFadc , sizeof(Float_t), 1, datei ) ;
|
---|
343 | fwrite ( &fFwhmFadc , sizeof(Float_t), 1, datei ) ;
|
---|
344 |
|
---|
345 | fwrite ( &fTrig , sizeof(Float_t), TRIGBINS, datei ) ;
|
---|
346 |
|
---|
347 | // We want to store the FADC signal taking into account the AC
|
---|
348 | // coupling
|
---|
349 | //
|
---|
350 | // We calculate and substract the baseline
|
---|
351 | //
|
---|
352 |
|
---|
353 | Float_t baseline = 0. ;
|
---|
354 |
|
---|
355 | for (Int_t i=0; i< FADCBINS ; i++ ) {
|
---|
356 |
|
---|
357 | baseline = baseline + fFadc[i] ;
|
---|
358 | }
|
---|
359 |
|
---|
360 | baseline = baseline / FADCBINS ;
|
---|
361 |
|
---|
362 | for (Int_t i=0; i< FADCBINS ; i++ ) {
|
---|
363 |
|
---|
364 | fFadc[i]=fFadc[i]-baseline;
|
---|
365 |
|
---|
366 | }
|
---|
367 |
|
---|
368 | fwrite ( &fFadc , sizeof(Float_t), FADCBINS, datei ) ;
|
---|
369 |
|
---|
370 |
|
---|
371 | fclose ( datei ) ;
|
---|
372 |
|
---|
373 | }
|
---|
374 |
|
---|
375 | void MStarLight::ReadBinary( char *filename) {
|
---|
376 |
|
---|
377 | //
|
---|
378 | // read the things from the binary file
|
---|
379 |
|
---|
380 | FILE *datei ;
|
---|
381 |
|
---|
382 | datei = fopen ( filename, "r" ) ;
|
---|
383 |
|
---|
384 | if ( ! datei ) {
|
---|
385 | cout << " ERROR: Can't open the file " << filename
|
---|
386 | << endl ;
|
---|
387 | cout<< " The database for the NSB may be too small. "
|
---|
388 | << endl;
|
---|
389 | cout<< " See the How to Use of the Camera simulation for more information"
|
---|
390 | << endl;
|
---|
391 | exit (230) ;
|
---|
392 | }
|
---|
393 |
|
---|
394 | Float_t read_version;
|
---|
395 | Float_t current_version=VERSIONSR;
|
---|
396 |
|
---|
397 | // Check taht we read the right version of the Database
|
---|
398 | fread ( &read_version, sizeof(Float_t), 1, datei ) ;
|
---|
399 |
|
---|
400 | if(Int_t(read_version)!=Int_t(current_version)){
|
---|
401 | cout<<" ERROR: You are trying to read database VERSION "<<
|
---|
402 | read_version<<endl;
|
---|
403 | cout<<" You must generate a database for the current VERSION "<<
|
---|
404 | current_version<<endl;
|
---|
405 | cout<<" See the NSB database section in the Camera How to Use note."
|
---|
406 | <<endl;
|
---|
407 | exit (230);
|
---|
408 | }
|
---|
409 |
|
---|
410 | fread ( &fBrightness, sizeof(Float_t), 1, datei ) ;
|
---|
411 | fread ( &fTimeRange , sizeof(Float_t), 1, datei ) ;
|
---|
412 |
|
---|
413 |
|
---|
414 | fread ( &fBinsTrig , sizeof(Float_t), 1, datei ) ;
|
---|
415 | fread ( &fTrigShape , sizeof(Float_t), 1, datei ) ;
|
---|
416 | fread ( &fAmplTrig , sizeof(Float_t), 1, datei ) ;
|
---|
417 | fread ( &fFwhmTrig , sizeof(Float_t), 1, datei ) ;
|
---|
418 |
|
---|
419 | fread ( &fBinsFadc , sizeof(Float_t), 1, datei ) ;
|
---|
420 | fread ( &fFadcShape , sizeof(Float_t), 1, datei ) ;
|
---|
421 | fread ( &fIntegFadc , sizeof(Float_t), 1, datei ) ;
|
---|
422 | fread ( &fFwhmFadc , sizeof(Float_t), 1, datei ) ;
|
---|
423 |
|
---|
424 | fread ( &fTrig , sizeof(Float_t), TRIGBINS, datei ) ;
|
---|
425 |
|
---|
426 | fread ( &fFadc , sizeof(Float_t), FADCBINS, datei ) ;
|
---|
427 |
|
---|
428 |
|
---|
429 |
|
---|
430 | fclose ( datei ) ;
|
---|
431 | }
|
---|
432 |
|
---|
433 |
|
---|
434 |
|
---|
435 |
|
---|