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

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