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

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