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

Last change on this file since 737 was 692, checked in by magicsol, 24 years ago
The pedestal member array has been changed from UChar_t to Float_t
File size: 13.3 KB
Line 
1/////////////////////////////////////////////////////////////////
2//
3// MFadc
4//
5//
6#include "MFadc.hxx"
7
8#include "MMcEvt.hxx"
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 all pedestals to 0
77 //
78
79 for ( i =0 ; i <CAMERA_PIXELS ; i++ ) {
80 pedestal[i] = 0.0 ;
81 }
82
83 //
84 // set tha values of FADC slices that would be read after trigger to zero
85 //
86
87 for (i=0; i <CAMERA_PIXELS; i++){
88 for (j=0; j<FADC_SLICES;j++){
89 output[i][j]=0;
90 }
91 }
92
93}
94
95MFadc::MFadc(Float_t ampl, Float_t fwhm) {
96 //
97 // Constructor overloaded II
98 //
99 // The procedure is the following:
100 // 1. some parameters of the trigger are set to default.
101 // this parameters of the trigger may be changed
102 // 3. Then the all signals are set to zero
103
104 fwhm_resp = fwhm ;
105 ampl_resp = ampl ;
106
107 //
108 // set up the response shape
109 //
110 Int_t i,j ;
111
112 Float_t sigma ;
113 Float_t x, x0 ;
114
115 sigma = fwhm_resp / 2.35 ;
116 x0 = 3*sigma ;
117
118 Float_t dX, dX2 ;
119
120 dX = WIDTH_FADC_TIMESLICE / SUBBINS ;
121 dX2 = dX/2. ;
122
123 for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) {
124
125 x = i * dX + dX2 ;
126
127 //
128 // the value 0.125 was introduced to normalize the things
129 //
130 sing_resp[i] = 0.125 *
131 ampl_resp * expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ;
132
133 }
134
135 //
136 // init the Random Generator for Electonic Noise
137 //
138
139 GenElec = new TRandom () ;
140
141 //
142 // set all the booleans used to FALSE, indicating that the pixel is not
143 // used in this event.
144 //
145
146 for ( i =0 ; i <CAMERA_PIXELS ; i++ ) {
147 used [i] = FALSE ;
148 }
149
150 //
151 // set all pedestals to 0
152 //
153
154 for ( i =0 ; i <CAMERA_PIXELS ; i++ ) {
155 pedestal[i] = 0.0 ;
156 }
157
158 //
159 // set tha values of FADC slices that would be read after trigger to zero
160 //
161
162 for (i=0; i <CAMERA_PIXELS; i++){
163 for (j=0; j<FADC_SLICES;j++){
164 output[i][j]=0;
165 }
166 }
167
168}
169
170void MFadc::Reset() {
171 //
172 // set all values of the signals to zero
173 //
174 Int_t i,j ;
175
176 for ( i =0 ; i <CAMERA_PIXELS ; i++ ) {
177 used [i] = FALSE ;
178 }
179 //
180 // set tha values of FADC slices that would be read after trigger to zero
181 //
182
183 for (i=0; i <CAMERA_PIXELS; i++){
184 for (j=0; j<FADC_SLICES;j++){
185 output[i][j]=0;
186 }
187 }
188}
189
190void MFadc::Fill( Int_t iPix, Float_t time, Float_t amplitude ) {
191
192 //
193 // fills the information about one single Phe in the Trigger class
194 //
195 // parameter is the number of the pixel and the time-difference to the
196 // first particle
197 //
198 //
199
200 Int_t i, ichan, ichanfadc ;
201
202 //
203 // first we have to check if the pixel iPix is used or not until now
204 // if this is the first use, reset all signal for that pixels
205 //
206 if ( iPix > CAMERA_PIXELS ) {
207 cout << " WARNING: MFadc::Fill() : iPix greater than CAMERA_PIXELS"
208 << endl ;
209 exit(987) ;
210 }
211
212 if ( used[iPix] == FALSE ) {
213 used [iPix] = TRUE ;
214
215 for (i=0; i < SLICES_MFADC; i++ ) {
216 sig[iPix][i] = 0. ;
217 }
218 }
219
220 //
221 // then select the time slice to use (ican)
222 //
223
224
225 if ( time < 0. ) {
226 cout << " WARNING! Fadc::Fill " << time << " below ZERO!! Very strange!!"
227 << endl ;
228 }
229 else if ( time < TOTAL_TRIGGER_TIME ) {
230 //
231 // determine the slices number assuming the WIDTH_RESPONSE_MFADC
232 //
233 ichan = (Int_t) ( time / ((Float_t) WIDTH_RESPONSE_MFADC ));
234
235 //
236 // putting the response slices in the right sig slices.
237 // Be carefull, because both slices have different widths.
238 //
239
240 for ( i = 0 ; i<RESPONSE_SLICES; i++ ) {
241 ichanfadc = (Int_t) ((ichan+i)/SUBBINS) ;
242 if ( (ichanfadc) < SLICES_MFADC ) {
243 sig[iPix][ichanfadc] += (amplitude * sing_resp[i] ) ;
244 }
245 }
246 }
247 else {
248 cout << " WARNING! Fadc::Fill " << time << " out of TriggerTimeRange "
249 << TOTAL_TRIGGER_TIME << endl ;
250 }
251
252}
253
254void MFadc::Set( Int_t iPix, Float_t resp[(Int_t) SLICES_MFADC]) {
255
256 //
257 // Sets the information about fadc reponse from a given array
258 //
259 // parameter is the number of the pixel and the values to be set
260 //
261 //
262
263 Int_t i ;
264
265 //
266 // first we have to check if the pixel iPix is used or not until now
267 // if this is the first use, reset all signal for that pixels
268 //
269 if ( iPix > CAMERA_PIXELS ) {
270 cout << " WARNING: MFadc::Fill() : iPix greater than CAMERA_PIXELS"
271 << endl ;
272 exit(987) ;
273 }
274
275 if ( used[iPix] == FALSE ) {
276 used [iPix] = TRUE ;
277
278 for (i=0; i < SLICES_MFADC; i++ ) {
279 sig[iPix][i] = 0. ;
280 }
281 }
282 for ( i = 0 ; i<SLICES_MFADC; i++ ) {
283 sig[iPix][i] = resp[i] ;
284 }
285
286}
287
288void MFadc::AddSignal( Int_t iPix, Float_t resp[(Int_t) SLICES_MFADC]) {
289
290 //
291 // Adds signals to the fadc reponse from a given array
292 //
293 // parameter is the number of the pixel and the values to be added
294 //
295 //
296
297 Int_t i ;
298
299 //
300 // first we have to check if the pixel iPix is used or not until now
301 // if this is the first use, reset all signal for that pixels
302 //
303 if ( iPix > CAMERA_PIXELS ) {
304 cout << " WARNING: MFadc::Fill() : iPix greater than CAMERA_PIXELS"
305 << endl ;
306 exit(987) ;
307 }
308
309 if ( used[iPix] == FALSE ) {
310 used [iPix] = TRUE ;
311
312 for (i=0; i < SLICES_MFADC; i++ ) {
313 sig[iPix][i] = 0. ;
314 }
315 }
316 for ( i = 0 ; i<SLICES_MFADC; i++ ) {
317 sig[iPix][i] += resp[i] ;
318 }
319
320}
321
322void MFadc::SetPedestals( Int_t ped) {
323 // It sets pedestal for each pixel flat randomly dstributed between 0 and ped
324 // It uses the instance of TRandom GenElec.
325
326 Int_t i;
327
328 for(i=0;i<CAMERA_PIXELS;i++){
329 pedestal[i]= (Float_t)(ped* GenElec->Rndm());
330 }
331}
332
333void MFadc::SetPedestals( Float_t ped[CAMERA_PIXELS]) {
334 // It sets pedestal for each pixel from ped array
335
336 Int_t i;
337
338 for(i=0;i<CAMERA_PIXELS;i++){
339 pedestal[i]= ped[i];
340 }
341}
342
343
344void MFadc::Baseline(){
345 //
346 // It simulates the AC behaviour
347
348 int i,j;
349 Float_t baseline;
350
351 for(j=0;j<CAMERA_PIXELS;j++){
352 baseline=0.0;
353 for(i=0;i<(Int_t) SLICES_MFADC;i++){
354 baseline=+sig[j][i];
355 }
356 baseline=baseline/SLICES_MFADC;
357 for(i=0;i<(Int_t) SLICES_MFADC;i++){
358 sig[j][i]=-baseline;
359 }
360 }
361}
362
363void MFadc::Pedestals(){
364 //
365 // It shifts the FADC contents their pedestal values
366 // It shifts the values in the analog signal,
367 // therefore it has to be done before getting FADC output
368 //
369
370 Int_t i, j;
371
372 for(i=0;i<CAMERA_PIXELS;i++)
373 for(j=0;j<SLICES_MFADC;j++)
374 sig[i][j]+=pedestal[i];
375}
376
377void MFadc::Offset(Float_t offset, Int_t pixel){
378 //
379 // It puts an offset in the FADC signal
380 //
381
382 int i,j;
383 float fdum;
384 TRandom *GenOff = new TRandom () ;
385
386 if (offset<0) {
387 // It cannot be, so the program assumes that
388 // it should generate random values for the offset.
389
390 if (pixel<0) {
391 // It does not exist, so all pixels will have the same offset
392
393 for(i=0;i<CAMERA_PIXELS;i++){
394 if (used[i]){
395 fdum=(10*GenOff->Rndm());
396 for(j=0;j<(Int_t) SLICES_MFADC;j++)
397 sig[i][j]=+fdum;
398 }
399 }
400 } else {
401 // The program will put the specifies offset to the pixel "pixel".
402
403 if (used[pixel]){
404 fdum=(10*GenOff->Rndm());
405 for(j=0;j<(Int_t) SLICES_MFADC;j++)
406 sig[pixel][j]=+fdum;
407 }
408
409 }
410 }else {
411 // The "offset" will be the offset for the FADC
412
413 if (pixel<0) {
414 // It does not exist, so all pixels will have the same offset
415
416 for(i=0;i<CAMERA_PIXELS;i++){
417 if (used[i]){
418 for(j=0;j<(Int_t) SLICES_MFADC;j++)
419 sig[i][j]=+offset;
420 }
421 }
422 } else {
423 // The program will put the specifies offset to the pixel "pixel".
424
425 if (used[pixel]){
426 for(j=0;j<(Int_t) SLICES_MFADC;j++)
427 sig[pixel][j]=+offset;
428 }
429 }
430 }
431}
432
433void MFadc::ElecNoise() {
434 //
435 //
436 //
437
438 for ( Int_t i = 0 ; i < CAMERA_PIXELS; i++) {
439 if ( used [i] == TRUE ) {
440 for ( Int_t is=0 ; is< SLICES_MFADC ; is++ ) {
441
442 sig[i][is] += GenElec->Gaus(0., 2.) ;
443
444 }
445 }
446 }
447}
448
449
450
451void MFadc::Scan() {
452
453
454 for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
455
456 if ( used[ip] == kTRUE ) {
457
458 printf ("Pid %3d", ip ) ;
459
460 for ( Int_t is=0 ; is < SLICES_MFADC; is++ ) {
461
462 if ( sig[ip][is] > 0. ) {
463 printf (" %4.1f/", sig[ip][is] ) ;
464 }
465 else {
466 printf ("----/" ) ;
467 }
468 }
469
470 printf ("\n");
471
472 }
473 }
474
475}
476
477void MFadc::Scan(Float_t time) {
478
479 //
480 // first of all we subtract from the time a offset (8 ns)
481 //
482
483 Float_t t ;
484
485 (0 > time - TIME_BEFORE_TRIGGER)? t=0: t=(time-TIME_BEFORE_TRIGGER) ; // to show also the start of the pulse before the trigger time
486
487 if ( t < 0. ) {
488 cout << " WARNING!! FROM MFADC::SCAN(t) " << endl ;
489 exit (776) ;
490 }
491
492 //
493 // calculate the first slice to write out
494 //
495
496 Int_t iFirstSlice ;
497
498 iFirstSlice = (Int_t) ( t / WIDTH_FADC_TIMESLICE ) ;
499
500 for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
501
502 if ( used[ip] == kTRUE ) {
503
504 printf ("Pid %3d", ip ) ;
505
506 for ( Int_t is=iFirstSlice ; is < (iFirstSlice+15); is++ ) {
507 printf (" %5.2f /", sig[ip][is] ) ;
508 }
509
510 printf ("\n");
511
512 }
513 }
514}
515
516void MFadc::GetResponse( Float_t *resp ) {
517 // ============================================================
518 //
519 // puts the standard response function into the array resp
520
521 for ( Int_t i=0; i< RESPONSE_SLICES; i++ ) {
522
523 resp[i] = sing_resp[i] ;
524 }
525}
526
527void MFadc::GetPedestals( Float_t *offset) {
528 // ============================================================
529 //
530 // puts the pedestal values into the array offset
531
532 for ( Int_t i=0; i< CAMERA_PIXELS; i++ ) {
533
534 offset[i] = pedestal[i] ;
535 }
536}
537
538void MFadc::TriggeredFadc(Float_t time) {
539
540 //
541 // first of all we subtract from the time a offset (8 ns)
542 //
543
544 Float_t t ;
545
546 (0>time-TIME_BEFORE_TRIGGER)? t=0: t=(time-TIME_BEFORE_TRIGGER) ; // to show also the start of the pulse before the trigger time
547
548 if ( t < 0. ) {
549 cout << " WARNING!! FROM MFADC::SCAN(t) " << endl ;
550 exit (776) ;
551 }
552
553 //
554 // calculate the first slice to write out
555 //
556
557 Int_t iFirstSlice ;
558 Int_t i;
559
560 iFirstSlice = (Int_t) ( t / WIDTH_FADC_TIMESLICE ) ;
561
562 for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
563
564 if ( used[ip] == kTRUE ) {
565 i=0;
566 for ( Int_t is=iFirstSlice ; is < (iFirstSlice+FADC_SLICES) ; is++ ) {
567 if (is< SLICES_MFADC && sig[ip][is]>0.0)
568 output[ip][i++]=(UChar_t) sig[ip][is];
569 else
570 output[ip][i++]= 0;
571 }
572
573 }
574 }
575}
576
577void MFadc::ShowSignal (MMcEvt *McEvt, Float_t trigTime) {
578 // ============================================================
579 //
580 // This method is used to book the histogramm to show the signal in
581 // a special gui frame (class MGTriggerSignal). After the look onto the
582 // signals for a better understanding of the things we will expect
583 // the gui frame and all histogramms will be destroyed.
584 //
585
586 //
587 // first of all create a list of the histograms to show
588 //
589 // take only that one with a entry
590
591 TH1F *hist ;
592 Char_t dumm[10];
593 Char_t name[256];
594
595 TObjArray *AList ;
596 AList = new TObjArray(10) ;
597
598 // the list of analog signal histograms
599 // at the beginning we initalise 10 elements
600 // but this array expand automaticly if neccessay
601
602 Int_t ic = 0 ;
603 for ( Int_t i=0 ; i < CAMERA_PIXELS; i++ ) {
604 if ( used [i] == TRUE ) {
605
606 sprintf (dumm, "FADC_%d", i ) ;
607 sprintf (name, "fadc signal %d", i ) ;
608
609 hist = new TH1F(dumm, name, SLICES_MFADC, 0., TOTAL_TRIGGER_TIME);
610 //
611 // fill the histogram
612 //
613
614 for (Int_t ibin=1; ibin <=SLICES_MFADC; ibin++) {
615 hist->SetBinContent (ibin, sig[i][ibin-1]) ;
616 }
617
618 // hist->SetMaximum( 5.);
619 // hist->SetMinimum(-10.);
620 hist->SetStats(kFALSE);
621
622 // hist->SetAxisRange(0., 80. ) ;
623
624 AList->Add(hist) ;
625
626 ic++ ;
627 }
628 }
629
630 //
631 // create the Gui Tool
632 //
633 //
634
635 new MGFadcSignal(McEvt,
636 AList,
637 trigTime,
638 gClient->GetRoot(),
639 gClient->GetRoot(),
640 400, 400 ) ;
641
642 //
643 // delete the List of histogramms
644 //
645 AList->Delete() ;
646
647 delete AList ;
648}
649
650UChar_t MFadc::GetFadcSignal(Int_t pixel, Int_t slice){
651
652 // It returns the analog signal for a given pixel and a given FADC
653 // time slice which would be read.
654
655 return (output[pixel][slice]);
656}
657
658
Note: See TracBrowser for help on using the repository browser.