source: trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.cxx@ 499

Last change on this file since 499 was 460, checked in by harald, 24 years ago
Some changes in the MFadc class were neccessary for the StarResponse program.
File size: 9.3 KB
Line 
1/////////////////////////////////////////////////////////////////
2//
3// MFadc
4//
5//
6#include "MFadc.hxx"
7
8#include "MMcEvt.h"
9
10#include "TROOT.h"
11#include <TApplication.h>
12#include <TVirtualX.h>
13#include <TGClient.h>
14
15#include "TH1.h"
16#include "TObjArray.h"
17
18#include "MGFadcSignal.hxx"
19
20MFadc::MFadc() {
21 //
22 // default constructor
23 //
24 // The procedure is the following:
25 // 1. some parameters of the trigger are set to default.
26 // this parameters of the trigger may be changed
27 // 3. Then the all signals are set to zero
28
29 fwhm_resp = MFADC_RESPONSE_FWHM ;
30 ampl_resp = MFADC_RESPONSE_AMPLITUDE ;
31
32 //
33 // set up the response shape
34 //
35 Int_t i,j ;
36
37 Float_t sigma ;
38 Float_t x, x0 ;
39
40 sigma = fwhm_resp / 2.35 ;
41 x0 = 3*sigma ;
42
43 Float_t dX, dX2 ;
44
45 dX = WIDTH_FADC_TIMESLICE / SUBBINS ;
46 dX2 = dX/2. ;
47
48 for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) {
49
50 x = i * dX + dX2 ;
51
52 //
53 // the value 0.125 was introduced to normalize the things
54 //
55 sing_resp[i] = 0.125 *
56 ampl_resp * expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ;
57
58 }
59
60 //
61 // init the Random Generator for Electonic Noise
62 //
63
64 GenElec = new TRandom () ;
65
66 //
67 // set all the booleans used to FALSE, indicating that the pixel is not
68 // used in this event.
69 //
70
71 for ( i =0 ; i <CAMERA_PIXELS ; i++ ) {
72 used [i] = FALSE ;
73 }
74
75 //
76 // set tha values of FADC slices that would be read after trigger to zero
77 //
78
79 for (i=0; i <CAMERA_PIXELS; i++){
80 for (j=0; j<FADC_SLICES;j++){
81 output[i][j]=0;
82 }
83 }
84
85}
86
87
88void MFadc::Reset() {
89 //
90 // set all values of the signals to zero
91 //
92 Int_t i,j ;
93
94 for ( i =0 ; i <CAMERA_PIXELS ; i++ ) {
95 used [i] = FALSE ;
96 }
97 //
98 // set tha values of FADC slices that would be read after trigger to zero
99 //
100
101 for (i=0; i <CAMERA_PIXELS; i++){
102 for (j=0; j<FADC_SLICES;j++){
103 output[i][j]=0;
104 }
105 }
106}
107
108
109void MFadc::Fill( Int_t iPix, Float_t time, Float_t amplitude ) {
110
111 //
112 // fills the information about one single Phe in the Trigger class
113 //
114 // parameter is the number of the pixel and the time-difference to the
115 // first particle
116 //
117 //
118
119 Int_t i, ichan, ichanfadc ;
120
121 //
122 // first we have to check if the pixel iPix is used or not until now
123 // if this is the first use, reset all signal for that pixels
124 //
125 if ( iPix > CAMERA_PIXELS ) {
126 cout << " WARNING: MFadc::Fill() : iPix greater than CAMERA_PIXELS"
127 << endl ;
128 exit(987) ;
129 }
130
131 if ( used[iPix] == FALSE ) {
132 used [iPix] = TRUE ;
133
134 for (i=0; i < SLICES_MFADC; i++ ) {
135 sig[iPix][i] = 0. ;
136 }
137 }
138
139 //
140 // then select the time slice to use (ican)
141 //
142
143
144 if ( time < 0. ) {
145 cout << " WARNING! Fadc::Fill " << time << " below ZERO!! Very strange!!"
146 << endl ;
147 }
148 else if ( time < TOTAL_TRIGGER_TIME ) {
149 //
150 // determine the slices number assuming the WIDTH_RESPONSE_MFADC
151 //
152 ichan = (Int_t) ( time / ((Float_t) WIDTH_RESPONSE_MFADC ));
153
154 //
155 // putting the response slices in the right sig slices.
156 // Be carefull, because both slices have different widths.
157 //
158
159 for ( i = 0 ; i<RESPONSE_SLICES; i++ ) {
160 ichanfadc = (Int_t) ((ichan+i)/SUBBINS) ;
161 if ( (ichanfadc) < SLICES_MFADC ) {
162 sig[iPix][ichanfadc] += (amplitude * sing_resp[i] ) ;
163 }
164 }
165 }
166 else {
167 cout << " WARNING! Fadc::Fill " << time << " out of TriggerTimeRange "
168 << TOTAL_TRIGGER_TIME << endl ;
169 }
170
171}
172
173void MFadc::Baseline(){
174 //
175 // It simulates the AC behaviour
176
177 int i,j;
178 Float_t baseline;
179
180 for(j=0;j<CAMERA_PIXELS;j++){
181 baseline=0.0;
182 for(i=0;i<(Int_t) SLICES_MFADC;i++){
183 baseline=+sig[j][i];
184 }
185 baseline=baseline/SLICES_MFADC;
186 for(i=0;i<(Int_t) SLICES_MFADC;i++){
187 sig[j][i]=-baseline;
188 }
189 }
190}
191
192void MFadc::Offset(Float_t offset, Int_t pixel){
193 //
194 // It puts an offset in the FADC signal
195 //
196
197 int i,j;
198 float fdum;
199 TRandom *GenOff = new TRandom () ;
200
201 if (offset<0) {
202 // It cannot be, so the program assumes that
203 // it should generate random values for the offset.
204
205 if (pixel<0) {
206 // It does not exist, so all pixels will have the same offset
207
208 for(i=0;i<CAMERA_PIXELS;i++){
209 if (used[i]){
210 fdum=(10*GenOff->Rndm());
211 for(j=0;j<(Int_t) SLICES_MFADC;j++)
212 sig[i][j]=+fdum;
213 }
214 }
215 } else {
216 // The program will put the specifies offset to the pixel "pixel".
217
218 if (used[pixel]){
219 fdum=(10*GenOff->Rndm());
220 for(j=0;j<(Int_t) SLICES_MFADC;j++)
221 sig[pixel][j]=+fdum;
222 }
223
224 }
225 }else {
226 // The "offset" will be the offset for the FADC
227
228 if (pixel<0) {
229 // It does not exist, so all pixels will have the same offset
230
231 for(i=0;i<CAMERA_PIXELS;i++){
232 if (used[i]){
233 for(j=0;j<(Int_t) SLICES_MFADC;j++)
234 sig[i][j]=+offset;
235 }
236 }
237 } else {
238 // The program will put the specifies offset to the pixel "pixel".
239
240 if (used[pixel]){
241 for(j=0;j<(Int_t) SLICES_MFADC;j++)
242 sig[pixel][j]=+offset;
243 }
244 }
245 }
246}
247
248void MFadc::ElecNoise() {
249 //
250 //
251 //
252
253 for ( Int_t i = 0 ; i < CAMERA_PIXELS; i++) {
254 if ( used [i] == TRUE ) {
255 for ( Int_t is=0 ; is< SLICES_MFADC ; is++ ) {
256
257 sig[i][is] += GenElec->Gaus(0., 2.) ;
258
259 }
260 }
261 }
262}
263
264
265
266void MFadc::Scan() {
267
268
269 for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
270
271 if ( used[ip] == kTRUE ) {
272
273 printf ("Pid %3d", ip ) ;
274
275 for ( Int_t is=0 ; is < SLICES_MFADC; is++ ) {
276
277 if ( sig[ip][is] > 0. ) {
278 printf (" %4.1f/", sig[ip][is] ) ;
279 }
280 else {
281 printf ("----/" ) ;
282 }
283 }
284
285 printf ("\n");
286
287 }
288 }
289
290}
291
292void MFadc::Scan(Float_t time) {
293
294 //
295 // first of all we subtract from the time a offset (8 ns)
296 //
297
298 Float_t t ;
299
300 (0 > time - TIME_BEFORE_TRIGGER)? t=0: t=(time-TIME_BEFORE_TRIGGER) ; // to show also the start of the pulse before the trigger time
301
302 if ( t < 0. ) {
303 cout << " WARNING!! FROM MFADC::SCAN(t) " << endl ;
304 exit (776) ;
305 }
306
307 //
308 // calculate the first slice to write out
309 //
310
311 Int_t iFirstSlice ;
312
313 iFirstSlice = (Int_t) ( t / WIDTH_FADC_TIMESLICE ) ;
314
315 for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
316
317 if ( used[ip] == kTRUE ) {
318
319 printf ("Pid %3d", ip ) ;
320
321 for ( Int_t is=iFirstSlice ; is < (iFirstSlice+15); is++ ) {
322 printf (" %5.2f /", sig[ip][is] ) ;
323 }
324
325 printf ("\n");
326
327 }
328 }
329}
330void MFadc::GetResponse( Float_t *resp ) {
331 // ============================================================
332 //
333 // puts the standard response function into the array resp
334
335 for ( Int_t i=0; i< RESPONSE_SLICES; i++ ) {
336
337 resp[i] = sing_resp[i] ;
338 }
339}
340
341void MFadc::TriggeredFadc(Float_t time) {
342
343 //
344 // first of all we subtract from the time a offset (8 ns)
345 //
346
347 Float_t t ;
348
349 (0>time-TIME_BEFORE_TRIGGER)? t=0: t=(time-TIME_BEFORE_TRIGGER) ; // to show also the start of the pulse before the trigger time
350
351 if ( t < 0. ) {
352 cout << " WARNING!! FROM MFADC::SCAN(t) " << endl ;
353 exit (776) ;
354 }
355
356 //
357 // calculate the first slice to write out
358 //
359
360 Int_t iFirstSlice ;
361 Int_t i;
362
363 iFirstSlice = (Int_t) ( t / WIDTH_FADC_TIMESLICE ) ;
364
365 for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
366
367 if ( used[ip] == kTRUE ) {
368 i=0;
369 for ( Int_t is=iFirstSlice ; is < (iFirstSlice+FADC_SLICES) ; is++ ) {
370 if (is< SLICES_MFADC)
371 output[ip][i++]=(UChar_t) sig[ip][is];
372 else
373 output[ip][i++]= 0;
374 }
375
376 }
377 }
378}
379
380void MFadc::ShowSignal (MMcEvt *McEvt, Float_t trigTime) {
381 // ============================================================
382 //
383 // This method is used to book the histogramm to show the signal in
384 // a special gui frame (class MGTriggerSignal). After the look onto the
385 // signals for a better understanding of the things we will expect
386 // the gui frame and all histogramms will be destroyed.
387 //
388
389 //
390 // first of all create a list of the histograms to show
391 //
392 // take only that one with a entry
393
394 TH1F *hist ;
395 Char_t dumm[10];
396 Char_t name[256];
397
398 TObjArray *AList ;
399 AList = new TObjArray(10) ;
400
401 // the list of analog signal histograms
402 // at the beginning we initalise 10 elements
403 // but this array expand automaticly if neccessay
404
405 Int_t ic = 0 ;
406 for ( Int_t i=0 ; i < CAMERA_PIXELS; i++ ) {
407 if ( used [i] == TRUE ) {
408
409 sprintf (dumm, "FADC_%d", i ) ;
410 sprintf (name, "fadc signal %d", i ) ;
411
412 hist = new TH1F(dumm, name, SLICES_MFADC, 0., TOTAL_TRIGGER_TIME);
413 //
414 // fill the histogram
415 //
416
417 for (Int_t ibin=1; ibin <=SLICES_MFADC; ibin++) {
418 hist->SetBinContent (ibin, sig[i][ibin-1]) ;
419 }
420
421 // hist->SetMaximum( 5.);
422 // hist->SetMinimum(-10.);
423 hist->SetStats(kFALSE);
424
425 // hist->SetAxisRange(0., 80. ) ;
426
427 AList->Add(hist) ;
428
429 ic++ ;
430 }
431 }
432
433 //
434 // create the Gui Tool
435 //
436 //
437
438 new MGFadcSignal(McEvt,
439 AList,
440 trigTime,
441 gClient->GetRoot(),
442 gClient->GetRoot(),
443 400, 400 ) ;
444
445 //
446 // delete the List of histogramms
447 //
448 AList->Delete() ;
449
450 delete AList ;
451}
452
453Float_t MFadc::GetFadcSignal(Int_t pixel, Int_t slice){
454
455 // It returns the analog signal for a given pixel and a given FADC
456 // time slice which would be read.
457
458 return (output[pixel][slice]);
459}
460
461
Note: See TracBrowser for help on using the repository browser.