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

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