- Timestamp:
- 03/01/05 20:06:47 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.cxx
r6588 r6692 60 60 61 61 for (Int_t i = 0; i < CAMERA_PIXELS; i++) 62 sig[i] = new Float_t[fSlices_mFadc]; 62 { 63 sig[i] = new Float_t[fSlices_mFadc]; 64 sig_LG[i] = new Float_t[fSlices_mFadc]; 65 } 63 66 64 67 noise = new Float_t[fSlices_mFadc*1001]; … … 125 128 sing_resp_outer = new Float_t[fResponseSlicesFadc]; 126 129 130 sing_resp_lowgain = new Float_t[fResponseSlicesFadc]; 131 sing_resp_outer_lowgain = new Float_t[fResponseSlicesFadc]; 132 133 134 // Parameters for real pulse shaped as measured with the Pulpo device: 135 fPulseParameters[0] = 2.066; 136 fPulseParameters[1] = 1.568; 137 fPulseParameters[2] = 3; // This will set the peak of the pulse at x ~ 3*3.3 = 10 ns 138 // It is just a safe value so that the pulse is well contained. 139 fPulseParameters[3] = 0.00282; 140 fPulseParameters[4] = 0.04093; 141 fPulseParameters[5] = 0.2411; 142 fPulseParameters[6] = -0.009442; 143 144 // Now for the low gain: 145 fPulseParametersLG[0] = 0.7; 146 fPulseParametersLG[1] = 0.88; 147 fPulseParametersLG[2] = 3.4; 148 fPulseParametersLG[3] = 0.00282; 149 fPulseParametersLG[4] = 0.04093; 150 fPulseParametersLG[5] = 0.2411; 151 fPulseParametersLG[6] = -0.009442; 152 127 153 Int_t i ; 128 154 … … 132 158 133 159 Float_t response_sum_inner, response_sum_outer; 160 Float_t response_sum_inner_LG, response_sum_outer_LG; 161 134 162 response_sum_inner = 0.; 135 163 response_sum_outer = 0.; 164 response_sum_inner_LG = 0.; 165 response_sum_outer_LG = 0.; 136 166 137 167 dX = 1. / fFadcSlicesPerNanosec / SUBBINS ; // Units: ns … … 144 174 x0 = 3*sigma; 145 175 fadc_time_offset = trigger_delay-x0; // ns 146 176 147 177 for (i = 0; i < fResponseSlicesFadc ; i++ ) 148 178 { … … 150 180 151 181 sing_resp[i] = (Float_t)(expf(-0.5*(x-x0)*(x-x0)/(sigma*sigma))); 152 182 sing_resp_lowgain[i] = sing_resp[i]; 183 184 // Use the same pulse for high and low gain in case of gaussian shape 185 // FIXME: it would be nice to be able to choose a different shape for 186 // high and low gain: 153 187 response_sum_inner += sing_resp[i]; 188 response_sum_inner_LG += sing_resp_lowgain[i]; 154 189 } 155 190 156 191 break; 157 192 case 1: 158 float p 1,p2,p3,p4,p5,p6,p7;193 float p0,p1,p2,p3,p4,p5,p6; 159 194 float d; 160 195 float zed_slices; … … 162 197 // gaussian electronic pulse passed through the whole chain from 163 198 // transmitter boards to FADC. 164 p1 = 2.066; 165 p2 = 1.568; 166 p3 = 3; // This will set the peak of the pulse at x ~ 3*3.3 = 10 ns 167 // It is just a safe value so that the pulse is well contained. 168 p4 = 0.00282; 169 p5 = 0.04093; 170 p6 = 0.2411; 171 p7 = -0.009442; 199 p0 = fPulseParameters[0]; 200 p1 = fPulseParameters[1]; 201 p2 = fPulseParameters[2]; 202 p3 = fPulseParameters[3]; 203 p4 = fPulseParameters[4]; 204 p5 = fPulseParameters[5]; 205 p6 = fPulseParameters[6]; 206 207 float p0_LG, p1_LG, p2_LG, p3_LG, p4_LG, p5_LG, p6_LG; 208 p0_LG = fPulseParametersLG[0]; 209 p1_LG = fPulseParametersLG[1]; 210 p2_LG = fPulseParametersLG[2]; 211 p3_LG = fPulseParametersLG[3]; 212 p4_LG = fPulseParametersLG[4]; 213 p5_LG = fPulseParametersLG[5]; 214 p6_LG = fPulseParametersLG[6]; 215 172 216 173 217 // Now define the time before trigger to read FADC signal when it … … 181 225 // frequency we are simulating! 182 226 183 fadc_time_offset = trigger_delay - p 3/ FADC_SLICES_PER_NSEC; // ns227 fadc_time_offset = trigger_delay - p2 / FADC_SLICES_PER_NSEC; // ns 184 228 185 229 for (i=0; i< fResponseSlicesFadc ; i++ ) … … 191 235 // are using another sampling frequency!): 192 236 // 193 zed_slices = x * FADC_SLICES_PER_NSEC - p3; 194 d=(zed_slices>0)?0.5:-0.5; 195 196 sing_resp[i] = (Float_t) (p1*exp(-p2*(exp(-p2*zed_slices)+zed_slices))+ 197 p4+p5*exp(-p2*(exp(-p2*zed_slices)+ 198 p6*zed_slices))+p7*d); 237 zed_slices = x * FADC_SLICES_PER_NSEC - p2; 238 d = (zed_slices>0)? 0.5 : -0.5; 239 240 sing_resp[i] = (Float_t) (p0*exp(-p1*(exp(-p1*zed_slices)+zed_slices))+ 241 p3+p4*exp(-p1*(exp(-p1*zed_slices)+ 242 p5*zed_slices))+p6*d); 243 244 zed_slices = x * FADC_SLICES_PER_NSEC - p2_LG; 245 d = (zed_slices>0)? 0.5 : -0.5; 246 sing_resp_lowgain[i] = (Float_t) (p0_LG*exp(-p1_LG*(exp(-p1_LG*zed_slices)+zed_slices))+ 247 p3+p4*exp(-p1_LG*(exp(-p1_LG*zed_slices)+ 248 p5*zed_slices))+p6*d); 199 249 200 250 response_sum_inner += sing_resp[i]; 251 response_sum_inner_LG += sing_resp_lowgain[i]; 201 252 } 202 253 … … 234 285 break; 235 286 case 1: 236 float p 1,p2,p3,p4,p5,p6,p7;287 float p0,p1,p2,p3,p4,p5,p6; 237 288 float d; 238 289 float zed_slices; … … 240 291 // gaussian electronic pulse passed through the whole chain from 241 292 // transmitter boards to FADC. 242 p1 = 2.066; 243 p2 = 1.568; 244 p3 = 3; // This sets the peak of the pulse at x ~ 3*3.3 = 10 nanosec 245 // It is just a safe value so that the pulse is well contained. 246 p4 = 0.00282; 247 p5 = 0.04093; 248 p6 = 0.2411; 249 p7 = -0.009442; 293 294 p0 = fPulseParameters[0]; 295 p1 = fPulseParameters[1]; 296 p2 = fPulseParameters[2]; 297 p3 = fPulseParameters[3]; 298 p4 = fPulseParameters[4]; 299 p5 = fPulseParameters[5]; 300 p6 = fPulseParameters[6]; 301 302 float p0_LG, p1_LG, p2_LG, p3_LG, p4_LG, p5_LG, p6_LG; 303 p0_LG = fPulseParametersLG[0]; 304 p1_LG = fPulseParametersLG[1]; 305 p2_LG = fPulseParametersLG[2]; 306 p3_LG = fPulseParametersLG[3]; 307 p4_LG = fPulseParametersLG[4]; 308 p5_LG = fPulseParametersLG[5]; 309 p6_LG = fPulseParametersLG[6]; 250 310 251 311 // Now define the time before trigger to read FADC signal when it … … 259 319 // frequency we are simulating! 260 320 261 fadc_time_offset = trigger_delay - p 3/ FADC_SLICES_PER_NSEC; // ns321 fadc_time_offset = trigger_delay - p2 / FADC_SLICES_PER_NSEC; // ns 262 322 263 323 for (i=0; i< fResponseSlicesFadc ; i++ ) … … 269 329 // are using another sampling frequency!): 270 330 // 271 zed_slices = x * FADC_SLICES_PER_NSEC - p3; 272 d=(zed_slices>0)?0.5:-0.5; 273 274 sing_resp_outer[i] = (Float_t) (p1*exp(-p2*(exp(-p2*zed_slices)+ 275 zed_slices))+p4+ 276 p5*exp(-p2*(exp(-p2*zed_slices)+ 277 p6*zed_slices))+p7*d); 331 zed_slices = x * FADC_SLICES_PER_NSEC - p2; 332 d = (zed_slices>0)? 0.5 : -0.5; 333 334 sing_resp_outer[i] = (Float_t) (p0*exp(-p1*(exp(-p1*zed_slices)+ 335 zed_slices))+p3+ 336 p4*exp(-p1*(exp(-p1*zed_slices)+ 337 p5*zed_slices))+p6*d); 338 339 zed_slices = x * FADC_SLICES_PER_NSEC - p2_LG; 340 d = (zed_slices>0)? 0.5 : -0.5; 341 sing_resp_outer_lowgain[i] = (Float_t) (p0_LG*exp(-p1_LG*(exp(-p1_LG*zed_slices)+zed_slices))+ 342 p3+p4*exp(-p1_LG*(exp(-p1_LG*zed_slices)+ 343 p5*zed_slices))+p6*d); 344 278 345 response_sum_outer += sing_resp_outer[i]; 346 response_sum_outer_LG += sing_resp_outer_lowgain[i]; 279 347 } 280 348 break; … … 288 356 289 357 // 290 // Normalize responses to values set t rhough input card: (= set gain of electronic chain)358 // Normalize responses to values set through input card: (= set gain of electronic chain) 291 359 // Take into account that only 1 of every SUBBINS bins of sing_resp[] will be "sampled" by 292 360 // the FADC, so we have to correct for this to get the right "FADC integral" (=integ_resp) … … 294 362 // 295 363 296 for (i =0; i< fResponseSlicesFadc ; i++ )364 for (i = 0; i < fResponseSlicesFadc ; i++ ) 297 365 { 298 366 sing_resp[i] *= integ_resp / response_sum_inner * SUBBINS; 299 367 sing_resp_outer[i] *= integ_resp_outer / response_sum_outer * SUBBINS; 300 } 301 302 // 303 // init the Random Generator for Electonic Noise 368 369 // The low gain will be further scaled down later; for now we normalize it with to same 370 // integral as the high gain. 371 sing_resp_lowgain[i] *= integ_resp / response_sum_inner_LG * SUBBINS; 372 sing_resp_outer_lowgain[i] *= integ_resp_outer / response_sum_outer_LG * SUBBINS; 373 } 374 375 // 376 // init the Random Generator for Electronic Noise 304 377 // 305 378 … … 333 406 334 407 // 335 // Added 15 01 2004, AM:408 336 409 // 337 410 for (Int_t i = 0; i < CAMERA_PIXELS; i++) 338 memset(sig[i], 0, (Int_t)(fSlices_mFadc*sizeof(Float_t))); 411 { 412 memset(sig[i], 0, (Int_t)(fSlices_mFadc*sizeof(Float_t))); // Added 15 01 2004, AM 413 memset(sig_LG[i], 0, (Int_t)(fSlices_mFadc*sizeof(Float_t))); // Added 01 03 2005, AM 414 } 339 415 } 340 416 void MFadc::Fill( Int_t iPix, Float_t time, … … 385 461 used [iPix] = TRUE; 386 462 387 for (i=0; i < (Int_t) fSlices_mFadc; i++ ) 388 sig[iPix][i] = 0.; 463 for (i=0; i < (Int_t) fSlices_mFadc; i++ ) 464 { 465 sig[iPix][i] = 0.; 466 sig_LG[iPix][i] = 0.; 467 } 389 468 } 390 469 … … 429 508 430 509 // 431 // fSlices_mFadc is by default 48. sig[][] is not the true FADC, which432 // isfilled (from sig[][]) in MFadc::TriggeredFadc()510 // fSlices_mFadc is by default 48. sig[][] is not the final FADC output; that 511 // will be later filled (from sig[][]) in MFadc::TriggeredFadc() 433 512 // 434 if ( (ichanfadc) < (Int_t) fSlices_mFadc ) 435 sig[iPix][ichanfadc] += (amplitude * sing_resp[i] ); 513 if ( (ichanfadc) < (Int_t) fSlices_mFadc ) 514 { 515 sig[iPix][ichanfadc] += (amplitude * sing_resp[i] ); 516 sig_LG[iPix][ichanfadc] += (amplitude * sing_resp_lowgain[i] ); 517 } 436 518 } 437 438 519 } 439 520 else … … 466 547 467 548 for (i=0; i < (Int_t) fSlices_mFadc; i++) 468 sig[iPix][i] = 0.; 549 { 550 sig[iPix][i] = 0.; 551 sig_LG[iPix][i] = 0.; 552 } 469 553 } 470 554 … … 485 569 486 570 if ( (ichanfadc) < (Int_t)fSlices_mFadc ) 487 sig[iPix][ichanfadc] += (amplitude * sing_resp_outer[i] ); 571 { 572 sig[iPix][ichanfadc] += (amplitude * sing_resp_outer[i] ); 573 sig_LG[iPix][ichanfadc] += (amplitude * sing_resp_outer_lowgain[i] ); 574 } 575 488 576 } 489 577 … … 496 584 } 497 585 498 void MFadc:: Set( Int_t iPix, Float_t *resp) {499 500 // 501 // Sets the information aboutfadc reponse from a given array502 // 503 // parameter is the number of the pixel and the values to be set504 // 586 void MFadc::AddSignal( Int_t iPix, Float_t *resp) { 587 588 // 589 // Adds signals to the fadc reponse from a given array 590 // Parameters are the number of the pixel and the values to be added 591 // With add the signal equally to the high and low gain branch. The low 592 // gain branch is not yet scaled down!! 505 593 // 506 594 … … 511 599 // if this is the first use, reset all signal for that pixels 512 600 // 513 if ( iPix > numpix ) { 514 cout << " WARNING: MFadc::Fill() : iPix greater than CAMERA_PIXELS" 515 << endl ; 516 exit(987) ; 517 } 518 519 if ( used[iPix] == FALSE ) { 520 used [iPix] = TRUE ; 601 if ( iPix > numpix ) 602 { 603 cout << " WARNING: MFadc::Fill() : iPix greater than CAMERA_PIXELS" 604 << endl ; 605 exit(987) ; 606 } 607 608 if ( used[iPix] == FALSE ) 609 { 610 used [iPix] = TRUE ; 521 611 522 for (i=0; i < (Int_t)fSlices_mFadc; i++ ) { 523 sig[iPix][i] = 0. ; 524 } 525 } 526 for ( i = 0 ; i<(Int_t)fSlices_mFadc; i++ ) { 527 sig[iPix][i] = resp[i] ; 528 } 529 530 } 531 532 void MFadc::AddSignal( Int_t iPix, Float_t *resp) { 533 534 // 535 // Adds signals to the fadc reponse from a given array 536 // 537 // parameters are the number of the pixel and the values to be added 538 // 539 // 540 541 Int_t i ; 542 543 // 544 // first we have to check if the pixel iPix is used or not until now 545 // if this is the first use, reset all signal for that pixels 546 // 547 if ( iPix > numpix ) { 548 cout << " WARNING: MFadc::Fill() : iPix greater than CAMERA_PIXELS" 549 << endl ; 550 exit(987) ; 551 } 552 553 if ( used[iPix] == FALSE ) { 554 used [iPix] = TRUE ; 555 556 for (i=0; i < (Int_t)fSlices_mFadc; i++ ) { 557 sig[iPix][i] = 0. ; 558 } 559 } 560 for ( i = 0 ; i<(Int_t)fSlices_mFadc; i++ ) { 561 sig[iPix][i] += resp[i] ; 562 } 612 for (i=0; i < (Int_t)fSlices_mFadc; i++ ) 613 { 614 sig[iPix][i] = 0. ; 615 sig_LG[iPix][i] = 0. ; 616 } 617 } 618 for ( i = 0 ; i<(Int_t)fSlices_mFadc; i++ ) 619 { 620 sig[iPix][i] += resp[i] ; 621 sig_LG[iPix][i] += resp[i] ; 622 } 563 623 564 624 } … … 584 644 } 585 645 } 586 587 588 void MFadc::Baseline(){ 589 // 590 // It simulates the AC behaviour 591 592 int i,j; 593 Float_t baseline; 594 595 for(j=0;j<numpix;j++){ 596 baseline=0.0; 597 for(i=0;i<(Int_t) fSlices_mFadc;i++){ 598 baseline+=sig[j][i]; 599 } 600 baseline=baseline/fSlices_mFadc; 601 for(i=0;i<(Int_t) fSlices_mFadc;i++){ 602 sig[j][i]=-baseline; 603 } 604 } 605 } 646 606 647 607 648 void MFadc::Pedestals(){ … … 616 657 for(i=0;i<numpix;i++) 617 658 for(j=0;j<(Int_t)fSlices_mFadc;j++) 618 sig[i][j]+=pedestal[i]; 659 { 660 sig[i][j] += pedestal[i]; 661 sig_LG[i][j] += pedestal[i]; 662 } 663 619 664 // 620 665 // AM 15 01 2003: Formerly the above operation was performed only … … 625 670 } 626 671 627 void MFadc::Offset(Float_t offset, Int_t pixel){628 //629 // It puts an offset in the FADC signal630 //631 632 int i,j;633 float fdum;634 TRandom *GenOff = new TRandom () ;635 636 if (offset<0) {637 // It cannot be, so the program assumes that638 // it should generate random values for the offset.639 640 if (pixel<0) {641 // It does not exist, so all pixels will have the same offset642 643 for(i=0;i<numpix;i++){644 if (used[i]){645 fdum=(10*GenOff->Rndm());646 for(j=0;j<(Int_t) fSlices_mFadc;j++)647 sig[i][j]+=fdum;648 }649 }650 } else {651 // The program will put the specifies offset to the pixel "pixel".652 653 if (used[pixel]){654 fdum=(10*GenOff->Rndm());655 for(j=0;j<(Int_t) fSlices_mFadc;j++)656 sig[pixel][j]+=fdum;657 }658 659 }660 }else {661 // The "offset" will be the offset for the FADC662 663 if (pixel<0) {664 // It does not exist, so all pixels will have the same offset665 666 for(i=0;i<numpix;i++){667 if (used[i]){668 for(j=0;j<(Int_t) fSlices_mFadc;j++)669 sig[i][j]+=offset;670 }671 }672 } else {673 // The program will put the specifies offset to the pixel "pixel".674 675 if (used[pixel]){676 for(j=0;j<(Int_t) fSlices_mFadc;j++)677 sig[pixel][j]+=offset;678 }679 }680 }681 delete GenOff;682 }683 672 684 673 void MFadc::SetElecNoise(Float_t value1, Float_t value2, UInt_t n_in_pix){ … … 716 705 // 717 706 718 startslice =GenElec->Integer(((Int_t)fSlices_mFadc)*1000);707 startslice = GenElec->Integer(((Int_t)fSlices_mFadc)*1000); 719 708 720 709 if ( used[i] == FALSE ) … … 722 711 used [i] = TRUE ; 723 712 if (i < fInnerPixelsNum) 713 { 724 714 memcpy( (Float_t*)&sig[i][0], 725 715 (Float_t*)&noise[startslice], 726 716 ((Int_t) fSlices_mFadc)*sizeof(Float_t)); 717 memcpy( (Float_t*)&sig_LG[i][0], 718 (Float_t*)&noise[startslice], 719 ((Int_t) fSlices_mFadc)*sizeof(Float_t)); 720 } 721 727 722 else 723 { 728 724 memcpy( (Float_t*)&sig[i][0], 729 725 (Float_t*)&noise_outer[startslice], 730 726 ((Int_t) fSlices_mFadc)*sizeof(Float_t)); 727 memcpy( (Float_t*)&sig_LG[i][0], 728 (Float_t*)&noise_outer[startslice], 729 ((Int_t) fSlices_mFadc)*sizeof(Float_t)); 730 } 731 731 } 732 732 … … 737 737 { 738 738 if (i < fInnerPixelsNum) 739 for ( Int_t is=0 ; is< (Int_t)fSlices_mFadc ; is++ ) 739 for ( Int_t is = 0 ; is < (Int_t)fSlices_mFadc ; is++ ) 740 { 740 741 sig[i][is] += noise[startslice+is]; 742 sig_LG[i][is] += noise[startslice+is]; 743 } 741 744 else 742 for ( Int_t is=0 ; is< (Int_t)fSlices_mFadc ; is++ ) 745 for ( Int_t is = 0 ; is < (Int_t)fSlices_mFadc ; is++ ) 746 { 743 747 sig[i][is] += noise_outer[startslice+is]; 748 sig_LG[i][is] += noise_outer[startslice+is]; 749 } 744 750 } 745 751 } … … 888 894 Float_t MFadc::AddNoiseInSlices( Int_t pix, Int_t ishigh, Int_t n_slices) { 889 895 890 Float_t sum =0;896 Float_t sum = 0; 891 897 Float_t fvalue = 0.; 892 UChar_t value=0; 893 894 Float_t factor; 898 UChar_t value = 0; 895 899 UInt_t startslice; 896 900 897 901 // 898 // If we deal with low gain, we have to scale the values in sig[][] by899 // the gain ratio (high2low_gain), since "sig" contains here the noise900 // produced before the receiver boards (for instance NSB noise)901 //902 factor=(ishigh?1.0:high2low_gain);903 904 //905 902 // Get at random a point in the FADC presimulated digital noise: 906 903 // … … 909 906 for ( Int_t is=0; is < n_slices ; is++ ) 910 907 { 911 fvalue = pedestal[pix]+(sig[pix][is]-pedestal[pix])/factor; 912 fvalue += digital_noise[startslice+is]; 913 914 fvalue = fvalue < 0? fvalue-0.5 : fvalue+0.5; 915 916 value = fvalue < 0.? (UChar_t) 0 : 917 (fvalue > 255.? 255 : (UChar_t) fvalue); 918 908 if (ishigh) 909 fvalue = sig[pix][is]; 910 else 911 // If we deal with low gain, we have to scale the values in sig_LG[][] by 912 // the gain ratio (high2low_gain), since "sig_LG" contains at this point the 913 // noise produced before the receiver boards (for instance NSB noise). 914 // 915 fvalue = pedestal[pix]+(sig_LG[pix][is]-pedestal[pix]) / high2low_gain; 916 917 fvalue += digital_noise[startslice+is]; // We add the noise intrinsic to FADC 918 919 fvalue = fvalue < 0? fvalue-0.5 : fvalue+0.5; 920 921 value = fvalue < 0.? (UChar_t) 0 : 922 (fvalue > 255.? 255 : (UChar_t) fvalue); 919 923 920 924 // Add up slices: … … 933 937 // is NOT done here (it is already done in MFadc::Fill). This procedure only 934 938 // selects which FADC slices to write out, out of those contained in the sig[][] 935 // a rray.939 // and sig_LG[][] arrays. 936 940 // 937 941 … … 998 1002 if (switch_i > 0 && (i+fFadcSlices) >= switch_i) 999 1003 output_lowgain[ip][i] = pedestal[ip] + 1000 (sig [ip][is-(fHi2LoGainPeak-fFadcSlices)]-pedestal[ip])/high2low_gain;1004 (sig_LG[ip][is-(fHi2LoGainPeak-fFadcSlices)]-pedestal[ip])/high2low_gain; 1001 1005 // Once the shift occurs, low gain is filled with the high 1002 1006 // gain signal scaled down by the factor high2low_gain … … 1010 1014 else // We are beyond the simulated signal history in sig[][]! Put just mean pedestal! 1011 1015 { 1012 output_lowgain[ip][i] = pedestal[ip];1016 output_lowgain[ip][i] = pedestal[ip]; 1013 1017 } 1014 1018 i++;
Note:
See TracChangeset
for help on using the changeset viewer.