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

Last change on this file since 1908 was 1079, checked in by blanch, 23 years ago
Now the fadc signal from NSB is stored after substracting the baseline (AC coupling)
File size: 7.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 fAmplFadc = 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 fAmplFadc = 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::GetAmplFadc ()
99{
100 return fAmplFadc ;
101}
102
103void MStarLight::SetAmplFadc (Float_t in )
104{
105 fAmplFadc = 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}
132
133void MStarLight::FillResponse( Float_t ampl, Float_t time ) {
134
135 // fill the trigger response
136
137 Int_t startbin = (Int_t) (time * 4) ;
138
139 Int_t icount = 0 ;
140 Int_t idata ;
141
142 for ( Int_t i=startbin ; i<startbin+40 ; i++) {
143 //
144 if ( i < TRIGBINS )
145 idata = i ;
146 else if ( i >= TRIGBINS )
147 idata = i - TRIGBINS ;
148
149 fTrig[idata] = fTrig[idata] + ampl * fTrigResp[icount] ;
150
151 icount++ ;
152 }
153
154 //
155 // fill the FADC content
156 //
157 //
158 //
159
160 startbin = (Int_t) ( time / 0.6666666666 );
161
162 Int_t ichanfadc = 0 ;
163
164 //
165 // putting the response slices in the right sig slices.
166 // Be carefull, because both slices have different widths.
167 //
168
169 for ( Int_t i = 0 ; i< 45; i++ ) {
170 ichanfadc = (Int_t) ((startbin+i)/5) ;
171
172 if ( (ichanfadc) < FADCBINS )
173 idata = ichanfadc ;
174 else if ( ichanfadc >=FADCBINS )
175 idata = ichanfadc-FADCBINS ;
176
177 fFadc[idata] += (ampl * fFadcResp[i] ) ;
178
179 }
180
181}
182
183void MStarLight::ElecNoise ( Float_t noiseTrig, Float_t noiseFadc ) {
184 //
185 // putting some noise to the baseline
186 //
187
188 TRandom2 wuerfel( (UInt_t) (noiseTrig*100) ) ;
189
190 for (Int_t i=0; i< TRIGBINS ; i++ ) {
191 fTrig[i] += wuerfel.Gaus(0., noiseTrig ) ;
192 }
193
194 for (Int_t i=0; i< FADCBINS ; i++ ) {
195 fFadc[i] += wuerfel.Gaus(0., noiseFadc ) ;
196 }
197
198
199}
200
201Float_t MStarLight::GetTrig( Int_t i){
202 //------------------------------------------------------------------
203 //
204 // It gets the value of the simualted trigger in the i bin
205 //
206 return fTrig[i];
207}
208
209Float_t MStarLight::GetFadc( Int_t i){
210 //------------------------------------------------------------------
211 //
212 // It gets the value of the simualted FADC signal in the i bin
213 //
214 return fFadc[i];
215}
216
217void MStarLight::StoreHisto( char *filename) {
218
219 Float_t baseline = 0. ;
220
221
222 // first the histogramms for trigger
223 //
224 // the calculated trigger signal before baseline
225 //
226
227 TH1F trigresp ("trigresp", "Trigger Response", TRIGBINS, 0., TIMERANGE) ;
228
229 for (Int_t i=0; i< TRIGBINS ; i++ ) {
230
231 trigresp.SetBinContent(i, fTrig[i]) ;
232
233 baseline = baseline + fTrig[i] ;
234 }
235
236 baseline = baseline / TRIGBINS ;
237
238 TH1F trigbase ("trigbase", "Response after Baseline shift",
239 TRIGBINS, 0., TIMERANGE) ;
240 for (Int_t i=0; i< TRIGBINS ; i++ ) {
241
242 trigbase.SetBinContent(i, fTrig[i]-baseline ) ;
243
244 }
245
246 TH1F trigdist ("trigdist", "Noise on the baseline",
247 1000, -25., 25. ) ;
248
249 for (Int_t i=0; i< TRIGBINS ; i++ ) {
250
251 trigdist.Fill( (Float_t) trigbase.GetBinContent(i) ) ;
252 }
253
254
255 //
256 // second the histograms for the fadc
257 //
258
259
260 TH1F fadcresp ("fadcresp", "Fadc Response", FADCBINS, 0., TIMERANGE) ;
261
262 for (Int_t i=0; i< FADCBINS ; i++ ) {
263
264 fadcresp.SetBinContent(i, fFadc[i]) ;
265
266 baseline = baseline + fFadc[i] ;
267 }
268
269 baseline = baseline / FADCBINS ;
270
271 TH1F fadcbase ("fadcbase", "Fadc after Baseline shift",
272 FADCBINS, 0., TIMERANGE) ;
273 for (Int_t i=0; i< FADCBINS ; i++ ) {
274
275 fadcbase.SetBinContent(i, fFadc[i]-baseline ) ;
276
277 }
278
279 TH1F fadcdist ("fadcdist", "Noise on fadc",
280 1000, -100., 100. ) ;
281
282 for (Int_t i=0; i< FADCBINS ; i++ ) {
283
284 fadcdist.Fill( (Float_t) fadcbase.GetBinContent(i) ) ;
285 }
286
287
288
289
290 TFile outfile( filename, "UPDATE" ) ;
291
292 trigresp.Write() ;
293 trigbase.Write() ;
294 trigdist.Write() ;
295
296 fadcresp.Write() ;
297 fadcbase.Write() ;
298 fadcdist.Write() ;
299
300
301 outfile.Close() ;
302}
303
304void MStarLight::WriteBinary( char *filename) {
305 //
306 // write the things to the binary file
307
308 FILE *datei ;
309
310 datei = fopen ( filename, "w" ) ;
311
312 if ( ! datei ) {
313 cout << " Error: Can't open the file " << filename
314 << endl ;
315 exit (230) ;
316 }
317
318 // write them out
319
320 fwrite ( &fBrightness, sizeof(Float_t), 1, datei ) ;
321 fwrite ( &fTimeRange , sizeof(Float_t), 1, datei ) ;
322
323 fwrite ( &fBinsTrig , sizeof(Float_t), 1, datei ) ;
324 fwrite ( &fTrigShape , sizeof(Float_t), 1, datei ) ;
325 fwrite ( &fAmplTrig , sizeof(Float_t), 1, datei ) ;
326 fwrite ( &fFwhmTrig , sizeof(Float_t), 1, datei ) ;
327
328 fwrite ( &fBinsFadc , sizeof(Float_t), 1, datei ) ;
329 fwrite ( &fFadcShape , sizeof(Float_t), 1, datei ) ;
330 fwrite ( &fAmplFadc , sizeof(Float_t), 1, datei ) ;
331 fwrite ( &fFwhmFadc , sizeof(Float_t), 1, datei ) ;
332
333 fwrite ( &fTrig , sizeof(Float_t), TRIGBINS, datei ) ;
334
335 // We want to store the FADC signal taking into account the AC
336 // coupling
337 //
338 // We calculate and substract the baseline
339 //
340
341 Float_t baseline = 0. ;
342
343 for (Int_t i=0; i< FADCBINS ; i++ ) {
344
345 baseline = baseline + fFadc[i] ;
346 }
347
348 baseline = baseline / FADCBINS ;
349
350 for (Int_t i=0; i< FADCBINS ; i++ ) {
351
352 fFadc[i]=fFadc[i]-baseline;
353
354 }
355
356 fwrite ( &fFadc , sizeof(Float_t), FADCBINS, datei ) ;
357
358
359 fclose ( datei ) ;
360
361}
362
363void MStarLight::ReadBinary( char *filename) {
364
365 //
366 // read the things from the binary file
367
368 FILE *datei ;
369
370 datei = fopen ( filename, "r" ) ;
371
372 if ( ! datei ) {
373 cout << " Error: Can't open the file " << filename
374 << endl ;
375 cout<< " The database for the NSB may be too small"
376 << endl;
377 exit (230) ;
378 }
379
380 fread ( &fBrightness, sizeof(Float_t), 1, datei ) ;
381 fread ( &fTimeRange , sizeof(Float_t), 1, datei ) ;
382
383
384 fread ( &fBinsTrig , sizeof(Float_t), 1, datei ) ;
385 fread ( &fTrigShape , sizeof(Float_t), 1, datei ) ;
386 fread ( &fAmplTrig , sizeof(Float_t), 1, datei ) ;
387 fread ( &fFwhmTrig , sizeof(Float_t), 1, datei ) ;
388
389 fread ( &fBinsFadc , sizeof(Float_t), 1, datei ) ;
390 fread ( &fFadcShape , sizeof(Float_t), 1, datei ) ;
391 fread ( &fAmplFadc , sizeof(Float_t), 1, datei ) ;
392 fread ( &fFwhmFadc , sizeof(Float_t), 1, datei ) ;
393
394 fread ( &fTrig , sizeof(Float_t), TRIGBINS, datei ) ;
395
396 fread ( &fFadc , sizeof(Float_t), FADCBINS, datei ) ;
397
398
399
400 fclose ( datei ) ;
401}
402
403
404
405
Note: See TracBrowser for help on using the repository browser.