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

Last change on this file since 1067 was 1066, checked in by blanch, 23 years ago
Several changes to speed up the camera program have been done and some memory leakage due to an undeleted pointer has been solved
File size: 11.5 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() {
331 //
332 //
333 //
334
335 for ( Int_t i = 0 ; i < CAMERA_PIXELS; i++) {
336 if ( used [i] == TRUE ) {
337 for ( Int_t is=0 ; is< (Int_t)SLICES_MFADC ; is++ ) {
338
339 sig[i][is] += GenElec->Gaus(0., 2.) ;
340
341 }
342 }
343 }
344}
345
346
347
348void MFadc::Scan() {
349
350
351 for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
352
353 if ( used[ip] == kTRUE ) {
354
355 printf ("Pid %3d", ip ) ;
356
357 for ( Int_t is=0 ; is < (Int_t)SLICES_MFADC; is++ ) {
358
359 if ( sig[ip][is] > 0. ) {
360 printf (" %4.1f/", sig[ip][is] ) ;
361 }
362 else {
363 printf ("----/" ) ;
364 }
365 }
366
367 printf ("\n");
368
369 }
370 }
371
372}
373
374void MFadc::Scan(Float_t time) {
375
376 //
377 // first of all we subtract from the time a offset (8 ns)
378 //
379
380 Float_t t ;
381
382 (0 > time - TIME_BEFORE_TRIGGER)? t=0: t=(time-TIME_BEFORE_TRIGGER) ; // to show also the start of the pulse before the trigger time
383
384 if ( t < 0. ) {
385 cout << " WARNING!! FROM MFADC::SCAN(t) " << endl ;
386 exit (776) ;
387 }
388
389 //
390 // calculate the first slice to write out
391 //
392
393 Int_t iFirstSlice ;
394
395 iFirstSlice = (Int_t) ( t / WIDTH_FADC_TIMESLICE ) ;
396
397 for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
398
399 if ( used[ip] == kTRUE ) {
400
401 printf ("Pid %3d", ip ) ;
402
403 for ( Int_t is=iFirstSlice ; is < (iFirstSlice+15); is++ ) {
404 printf (" %5.2f /", sig[ip][is] ) ;
405 }
406
407 printf ("\n");
408
409 }
410 }
411}
412
413void MFadc::GetResponse( Float_t *resp ) {
414 // ============================================================
415 //
416 // puts the standard response function into the array resp
417
418 for ( Int_t i=0; i< RESPONSE_SLICES; i++ ) {
419
420 resp[i] = sing_resp[i] ;
421 }
422}
423
424void MFadc::GetPedestals( Float_t *offset) {
425 // ============================================================
426 //
427 // puts the pedestal values into the array offset
428
429 for ( Int_t i=0; i< CAMERA_PIXELS; i++ ) {
430
431 offset[i] = pedestal[i] ;
432 }
433}
434
435void MFadc::TriggeredFadc(Float_t time) {
436
437 //
438 // first of all we subtract from the time a offset (8 ns)
439 //
440
441 Float_t t ;
442
443 (0>time-TIME_BEFORE_TRIGGER)? t=0: t=(time-TIME_BEFORE_TRIGGER) ; // to show also the start of the pulse before the trigger time
444
445 if ( t < 0. ) {
446 cout << " WARNING!! FROM MFADC::SCAN(t) " << endl ;
447 exit (776) ;
448 }
449
450 //
451 // calculate the first slice to write out
452 //
453
454 Int_t iFirstSlice ;
455 Int_t i;
456
457 iFirstSlice = (Int_t) ( t / WIDTH_FADC_TIMESLICE ) ;
458
459 for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
460
461 if ( used[ip] == kTRUE ) {
462 i=0;
463 for ( Int_t is=iFirstSlice ; is < (iFirstSlice+FADC_SLICES) ; is++ ) {
464 if (is< (Int_t)SLICES_MFADC && sig[ip][is]>0.0)
465 output[ip][i++]=(UChar_t) sig[ip][is];
466 else
467 output[ip][i++]= 0;
468 }
469
470 }
471 }
472}
473
474void MFadc::ShowSignal (MMcEvt *McEvt, Float_t trigTime) {
475 // ============================================================
476 //
477 // This method is used to book the histogramm to show the signal in
478 // a special gui frame (class MGTriggerSignal). After the look onto the
479 // signals for a better understanding of the things we will expect
480 // the gui frame and all histogramms will be destroyed.
481 //
482
483 //
484 // first of all create a list of the histograms to show
485 //
486 // take only that one with a entry
487
488 TH1F *hist ;
489 Char_t dumm[10];
490 Char_t name[256];
491
492 TObjArray *AList ;
493 AList = new TObjArray(10) ;
494
495 // the list of analog signal histograms
496 // at the beginning we initalise 10 elements
497 // but this array expand automaticly if neccessay
498
499 Int_t ic = 0 ;
500 for ( Int_t i=0 ; i < CAMERA_PIXELS; i++ ) {
501 if ( used [i] == TRUE ) {
502
503 sprintf (dumm, "FADC_%d", i ) ;
504 sprintf (name, "fadc signal %d", i ) ;
505
506 hist = new TH1F(dumm, name, SLICES_MFADC, 0., TOTAL_TRIGGER_TIME);
507 //
508 // fill the histogram
509 //
510
511 for (Int_t ibin=1; ibin <=(Int_t)SLICES_MFADC; ibin++) {
512 hist->SetBinContent (ibin, sig[i][ibin-1]) ;
513 }
514
515 // hist->SetMaximum( 5.);
516 // hist->SetMinimum(-10.);
517 hist->SetStats(kFALSE);
518
519 // hist->SetAxisRange(0., 80. ) ;
520
521 AList->Add(hist) ;
522
523 ic++ ;
524 }
525 }
526
527 //
528 // create the Gui Tool
529 //
530 //
531
532 new MGFadcSignal(McEvt,
533 AList,
534 trigTime,
535 gClient->GetRoot(),
536 gClient->GetRoot(),
537 400, 400 ) ;
538
539 //
540 // delete the List of histogramms
541 //
542 AList->Delete() ;
543
544 delete AList ;
545}
546
547UChar_t MFadc::GetFadcSignal(Int_t pixel, Int_t slice){
548
549 // It returns the analog signal for a given pixel and a given FADC
550 // time slice which would be read.
551
552 return (output[pixel][slice]);
553}
554
555
Note: See TracBrowser for help on using the repository browser.