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

Last change on this file since 738 was 626, checked in by magicsol, 24 years ago
Member functions needed to treat the MStarLight class described in MStarLight.hxx version 1.1
File size: 7.4 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 fwrite ( &fFadc , sizeof(Float_t), FADCBINS, datei ) ;
336
337
338
339 fclose ( datei ) ;
340
341}
342
343void MStarLight::ReadBinary( char *filename) {
344
345 //
346 // read the things from the binary file
347
348 FILE *datei ;
349
350 datei = fopen ( filename, "r" ) ;
351
352 if ( ! datei ) {
353 cout << " Error: Can't open the file " << filename
354 << endl ;
355 cout<< " The database for the NSB may be too small"
356 << endl;
357 exit (230) ;
358 }
359
360 fread ( &fBrightness, sizeof(Float_t), 1, datei ) ;
361 fread ( &fTimeRange , sizeof(Float_t), 1, datei ) ;
362
363
364 fread ( &fBinsTrig , sizeof(Float_t), 1, datei ) ;
365 fread ( &fTrigShape , sizeof(Float_t), 1, datei ) ;
366 fread ( &fAmplTrig , sizeof(Float_t), 1, datei ) ;
367 fread ( &fFwhmTrig , sizeof(Float_t), 1, datei ) ;
368
369 fread ( &fBinsFadc , sizeof(Float_t), 1, datei ) ;
370 fread ( &fFadcShape , sizeof(Float_t), 1, datei ) ;
371 fread ( &fAmplFadc , sizeof(Float_t), 1, datei ) ;
372 fread ( &fFwhmFadc , sizeof(Float_t), 1, datei ) ;
373
374 fread ( &fTrig , sizeof(Float_t), TRIGBINS, datei ) ;
375
376 fread ( &fFadc , sizeof(Float_t), FADCBINS, datei ) ;
377
378
379
380 fclose ( datei ) ;
381}
382
383
384
385
Note: See TracBrowser for help on using the repository browser.