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

Last change on this file since 443 was 443, checked in by magicsol, 24 years ago
Baseline and offset functions have been implemented
File size: 9.0 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[i][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}
330
331void MFadc::TriggeredFadc(Float_t time) {
332
333 //
334 // first of all we subtract from the time a offset (8 ns)
335 //
336
337 Float_t t ;
338
339 (0>time-TIME_BEFORE_TRIGGER)? t=0: t=(time-TIME_BEFORE_TRIGGER) ; // to show also the start of the pulse before the trigger time
340
341 if ( t < 0. ) {
342 cout << " WARNING!! FROM MFADC::SCAN(t) " << endl ;
343 exit (776) ;
344 }
345
346 //
347 // calculate the first slice to write out
348 //
349
350 Int_t iFirstSlice ;
351 Int_t i;
352
353 iFirstSlice = (Int_t) ( t / WIDTH_FADC_TIMESLICE ) ;
354
355 for ( Int_t ip=0; ip<CAMERA_PIXELS; ip++ ) {
356
357 if ( used[ip] == kTRUE ) {
358 i=0;
359 for ( Int_t is=iFirstSlice ; is < (iFirstSlice+FADC_SLICES) ; is++ ) {
360 if (is< SLICES_MFADC)
361 output[ip][i++]=(UChar_t) sig[ip][is];
362 else
363 output[ip][i++]= 0;
364 }
365
366 }
367 }
368}
369
370void MFadc::ShowSignal (MMcEvt *McEvt, Float_t trigTime) {
371 // ============================================================
372 //
373 // This method is used to book the histogramm to show the signal in
374 // a special gui frame (class MGTriggerSignal). After the look onto the
375 // signals for a better understanding of the things we will expect
376 // the gui frame and all histogramms will be destroyed.
377 //
378
379 //
380 // first of all create a list of the histograms to show
381 //
382 // take only that one with a entry
383
384 TH1F *hist ;
385 Char_t dumm[10];
386 Char_t name[256];
387
388 TObjArray *AList ;
389 AList = new TObjArray(10) ;
390
391 // the list of analog signal histograms
392 // at the beginning we initalise 10 elements
393 // but this array expand automaticly if neccessay
394
395 Int_t ic = 0 ;
396 for ( Int_t i=0 ; i < CAMERA_PIXELS; i++ ) {
397 if ( used [i] == TRUE ) {
398
399 sprintf (dumm, "FADC_%d", i ) ;
400 sprintf (name, "fadc signal %d", i ) ;
401
402 hist = new TH1F(dumm, name, SLICES_MFADC, 0., TOTAL_TRIGGER_TIME);
403 //
404 // fill the histogram
405 //
406
407 for (Int_t ibin=1; ibin <=SLICES_MFADC; ibin++) {
408 hist->SetBinContent (ibin, sig[i][ibin-1]) ;
409 }
410
411 // hist->SetMaximum( 5.);
412 // hist->SetMinimum(-10.);
413 hist->SetStats(kFALSE);
414
415 // hist->SetAxisRange(0., 80. ) ;
416
417 AList->Add(hist) ;
418
419 ic++ ;
420 }
421 }
422
423 //
424 // create the Gui Tool
425 //
426 //
427
428 new MGFadcSignal(McEvt,
429 AList,
430 trigTime,
431 gClient->GetRoot(),
432 gClient->GetRoot(),
433 400, 400 ) ;
434
435 //
436 // delete the List of histogramms
437 //
438 AList->Delete() ;
439
440 delete AList ;
441}
442
443Float_t MFadc::GetFadcSignal(Int_t pixel, Int_t slice){
444
445 // It returns the analog signal for a given pixel and a given FADC
446 // time slice which would be read.
447
448 return (output[pixel][slice]);
449}
450
451
Note: See TracBrowser for help on using the repository browser.