source: trunk/MagicSoft/Simulation/Detector/StarResponse/MStarLight.cxx@ 2978

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