Ignore:
Timestamp:
09/16/04 16:56:48 (20 years ago)
Author:
moralejo
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Simulation/Detector/include-MFadc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.cxx

    r2998 r5079  
    1818#include "MGFadcSignal.hxx"
    1919
    20 MFadc::MFadc(Int_t pix, Float_t integral, Float_t fwhm, Float_t integralout, Float_t fwhmout, Float_t trigger_delay) {
     20MFadc::MFadc(Int_t pix, Int_t shape, Float_t integral, Float_t fwhm, Int_t shapeout, Float_t integralout, Float_t fwhmout, Float_t trigger_delay) {
    2121  //
    2222  //  Constructor overloaded II
     
    4343  fwhm_resp_outer = fwhmout;
    4444  integ_resp_outer = integralout;
    45 
    46   cout<< "[MFadc]  Setting up the MFadc with this values "<< endl ;
    47   cout<< "[MFadc]    - Inner pixels :  "<< endl ;
    48   cout<< "[MFadc]       Response Area : "<<integral<<" adc counts"<< endl ;
    49   cout<< "[MFadc]       Response FWHM : "<<fwhm<<" ns"<< endl ;
    50   cout<< "[MFadc]    - Inner pixels :  "<< endl ;
    51   cout<< "[MFadc]       Response Area : "<<integralout<<" adc counts"<< endl ;
    52   cout<< "[MFadc]       Response FWHM : "<<fwhmout<<" ns"<< endl ;
     45  shape_resp=shape;
     46  shape_resp_outer=shapeout;
     47
     48    cout<< "[MFadc]  Setting up the MFadc with this values "<< endl ;
     49    cout<< "[MFadc]    - Inner pixels :  "<< endl ;
     50  switch(shape_resp){
     51  case 0:
     52    cout<< "[MFadc]       Pulse shape   : Gaussian ("<<shape_resp<<")"<< endl ;
     53    cout<< "[MFadc]       Response Area : "<<integ_resp<<" adc counts"<< endl ;
     54    cout<< "[MFadc]       Response FWHM : "<<fwhm_resp<<" ns"<< endl ;
     55    break;
     56  case 1:
     57    cout<< "[MFadc]       Pulse shape   : From Pulpo ("<<shape_resp<<")"<< endl ;
     58    cout<< "[MFadc]       Response Area : "<<integ_resp<<" adc counts"<< endl ;
     59    break;
     60  default:
     61    cout<< "[MFadc]       Pulse shape unknown"<<endl;
     62  }
     63  cout<< "[MFadc]    - Outer pixels :  "<< endl ;
     64  switch(shape_resp_outer){
     65  case 0:
     66    cout<< "[MFadc]       Pulse shape   : Gaussian ("<<shape_resp_outer<<")"<<endl;
     67    cout<< "[MFadc]       Response Area : "<<integ_resp_outer<<" adc counts"<<endl;
     68    cout<< "[MFadc]       Response FWHM : "<<fwhm_resp_outer<<" ns"<< endl ;
     69    break;
     70  case 1:
     71    cout<< "[MFadc]       Pulse shape   : From Pulpo ("<<shape_resp_outer<<")"<<endl;
     72    cout<< "[MFadc]       Response Area : "<<integ_resp_outer<<" adc counts"<< endl ;
     73    break;
     74  default:
     75    cout<< "[MFadc]       Pulse shape unknown ("<<shape_resp_outer<<")"<<endl;
     76  }
     77
    5378 
    5479  //
     
    5984  Float_t   sigma ;
    6085  Float_t   x, x0 ;
    61 
    62   sigma = fwhm_resp / 2.35 ;
    63   x0 = 3*sigma;
    64  
    65   fadc_time_offset = trigger_delay-x0; // ns
    66 
    67 
    6886  Float_t   dX, dX2 ;
    6987
    70   dX  = WIDTH_FADC_TIMESLICE / SUBBINS ;
     88  Float_t   response_sum_inner, response_sum_outer;
     89  response_sum_inner = 0.;
     90  response_sum_outer = 0.;
     91
     92  dX  = WIDTH_FADC_TIMESLICE / SUBBINS ;   // Units: ns
    7193  dX2 = dX/2. ;
    7294
    73 
    74  
     95  switch(shape_resp){
     96
     97  case 0:
     98    sigma = fwhm_resp / 2.35 ;
     99    x0 = 3*sigma;
     100    fadc_time_offset = trigger_delay-x0; // ns
     101 
     102    for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) { 
     103
     104      x = i * dX + dX2 ;
     105     
     106      sing_resp[i] = expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ;
     107
     108      response_sum_inner += sing_resp[i];
     109    }
     110
     111    break;
     112  case 1:
     113    float p1,p2,p3,p4,p5,p6,p7;
     114    float d;
     115    float zed_slices;
     116    // Parameters values extracted from fitting a real FADC response
     117    // gaussian electronic pulse passed through the whole chain from
     118    // transmitter boards to FADC.
     119    p1 = 2.066;
     120    p2 = 1.568;
     121    p3 = 3; // This sets the peak of the pulse at x ~ 3 ADC slices
     122            // It is just a safe value so that the pulse is well contained.
     123    p4 = 0.00282;
     124    p5 = 0.04093;
     125    p6 = 0.2411;
     126    p7 = -0.009442;
     127    // Define the time before trigger to read FADC signal when it
     128    //  has to be written
     129    fadc_time_offset = trigger_delay-p3*WIDTH_FADC_TIMESLICE; // ns
     130
     131    for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) { 
     132      x = i * dX + dX2;
     133
     134      // x has to be converted from ns to units FADC slices:
     135      zed_slices=x/WIDTH_FADC_TIMESLICE-p3;
     136      d=(zed_slices>0)?0.5:-0.5;
     137
     138      sing_resp[i] =  (p1*exp(-p2*(exp(-p2*zed_slices)+zed_slices))+p4+
     139                       p5*exp(-p2*(exp(-p2*zed_slices)+p6*zed_slices))+p7*d);
     140
     141      response_sum_inner += sing_resp[i];
     142    }
     143
     144    break;
     145  default:
     146    cout<<"[MFadc] MFadc::MFadc : Shape of FADC pulse for inner pixel unknown."
     147        <<endl;
     148    cout<<"[MFadc] MFadc::MFadc : Exiting Camera ..."
     149        <<endl;
     150    exit(1);
     151  }
     152
     153  // Response for outer pixels
     154
     155  switch(shape_resp_outer){
     156
     157  case 0:
     158    sigma = fwhm_resp_outer / 2.35 ;
     159    x0 = 3*sigma ;
     160    fadc_time_offset = trigger_delay-x0; // ns
     161   
     162    for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) { 
     163     
     164      x = i * dX + dX2 ;
     165     
     166      //
     167      //   the value 1/sqrt(2*Pi*sigma^2) was introduced to normalize
     168      //   the area at the input value After this, the integral
     169      //   of the response will be integ_resp.
     170      //
     171      sing_resp_outer[i] = expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ;
     172      response_sum_outer += sing_resp_outer[i];
     173    }
     174    break;
     175  case 1:
     176    float p1,p2,p3,p4,p5,p6,p7;
     177    float d;
     178    float zed_slices;
     179    // Parameters values extracted from fitting a real FADC response
     180    // gaussian electronic pulse passed through the whole chain from
     181    // transmitter boards to FADC.
     182    p1 = 2.066;
     183    p2 = 1.568;
     184    p3 = 3; // This sets the peak of the pulse at x ~ 3 ADC slices
     185               // It is just a safe value so that the pulse is well contained.
     186    p4 = 0.00282;
     187    p5 = 0.04093;
     188    p6 = 0.2411;
     189    p7 = -0.009442;
     190    // Define the time before trigger to read FADC signal when it
     191    //  has to be written
     192    fadc_time_offset = trigger_delay-p3*WIDTH_FADC_TIMESLICE; // ns
     193
     194    for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) { 
     195      x = i * dX + dX2;
     196
     197      zed_slices=x/WIDTH_FADC_TIMESLICE-p3;
     198      d=(zed_slices>0)?0.5:-0.5;
     199
     200      sing_resp_outer[i] = (p1*exp(-p2*(exp(-p2*zed_slices)+zed_slices))+p4+
     201                            p5*exp(-p2*(exp(-p2*zed_slices)+p6*zed_slices))+p7*d);
     202      response_sum_outer += sing_resp_outer[i];
     203      }
     204    break;
     205  default:
     206    cout<<"[MFadc] MFadc::MFadc : Shape of FADC pulse for inner pixel unknown."
     207        <<endl;
     208    cout<<"[MFadc] MFadc::MFadc : Exiting Camera ..."
     209        <<endl;
     210    exit(1);
     211  }
     212
     213  //   
     214  // Normalize responses to values set trhough input card: (= set gain of electronic chain)
     215  // Take into account that only 1 of every SUBBINS bins of sing_resp[] will be "sampled" by
     216  // the FADC, so we have to correct for this to get the right "FADC integral" (=integ_resp)
     217  // per photoelectron:
     218  //
     219
    75220  for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) { 
    76 
    77     x = i * dX + dX2 ;
    78    
    79     //
    80     //   the value 1/(2*Pi*sigma^2) was introduced to normalize
    81     //   the area at the input value. After this, the integral
    82     //   of the response will be integ_resp.
    83     //
    84     sing_resp[i] = integ_resp / sqrt(2*3.1415926*sigma*sigma)* 
    85        expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ;
    86 
    87     //   
    88     //   The integral of the response above would be the sum of all
    89     //   sing_resp[i] values times the bin width WIDTH_RESPONSE_MFADC,
    90     //   and it would now equal "integ_resp".
    91     //   We want however that our actual measurement, the sum of FADC
    92     //   slices contents, is equal to integ_resp. Since in each FADC
    93     //   slice we will put the content of just one response bin, and
    94     //   there are a number SUBBINS of such response bins within 1 FADC
    95     //   slice, the needed factor is then:
    96     //
    97     sing_resp[i] *= (WIDTH_RESPONSE_MFADC*SUBBINS);
    98 
    99   }
    100 
    101 
    102   sigma = fwhm_resp_outer / 2.35 ;
    103   x0 = 3*sigma ;
    104  
    105   dX  = WIDTH_FADC_TIMESLICE / SUBBINS ;
    106   dX2 = dX/2. ;
    107  
    108   for (i=0; i< RESPONSE_SLICES_MFADC ; i++ ) { 
    109 
    110     x = i * dX + dX2 ;
    111    
    112     //
    113     //   the value 1/(2*Pi*sigma^2) was introduced to normalize
    114     //   the area at the input value After this, the integral
    115     //   of the response will be integ_resp.
    116     //
    117     sing_resp_outer[i] = integ_resp_outer / sqrt(2*3.1415926*sigma*sigma)* 
    118        expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ;
    119 
    120     //   
    121     //   The integral of the response above would be the sum of all
    122     //   sing_resp[i] values times the bin width WIDTH_RESPONSE_MFADC,
    123     //   and it would now equal "integ_resp".
    124     //   We want however that our actual measurement, the sum of FADC
    125     //   slices contents, is equal to integ_resp. Since in each FADC
    126     //   slice we will put the content of just one response bin, and
    127     //   there are a number SUBBINS of such response bins within 1 FADC
    128     //   slice, the needed factor is then:
    129     // 
    130     sing_resp_outer[i] *= (WIDTH_RESPONSE_MFADC*SUBBINS);
    131   }
     221      sing_resp[i] *= integ_resp / response_sum_inner * SUBBINS;
     222      sing_resp_outer[i] *= integ_resp_outer / response_sum_outer * SUBBINS;
     223  }
    132224
    133225  //
     
    156248    //
    157249    memset(used, 0, CAMERA_PIXELS*sizeof(Bool_t));
    158     memset(output, 0, CAMERA_PIXELS*FADC_SLICES*sizeof(UChar_t));
    159     memset(output_lowgain, 0, CAMERA_PIXELS*FADC_SLICES*sizeof(UChar_t));
     250    memset(output, 0, CAMERA_PIXELS*FADC_SLICES*sizeof(Float_t));
     251    memset(output_lowgain, 0, CAMERA_PIXELS*FADC_SLICES*sizeof(Float_t));
    160252    //
    161253    // Added 15 01 2004, AM:
     
    380472  // Adds signals to the fadc reponse from a given array
    381473  //
    382   // parameter is the number of the pixel and the values to be added
     474  // parameters are the number of the pixel and the values to be added
    383475  //
    384476  //
     
    529621}
    530622
    531 void MFadc::SetElecNoise(Float_t value){
     623void MFadc::SetElecNoise(Float_t value1, Float_t value2, UInt_t n_in_pix){
    532624
    533625  UInt_t i;
    534626 
     627  fInnerPixelsNum = n_in_pix;
     628
    535629  cout<<"MFadc::SetElecNoise ... generating database for electronic noise."
    536630      <<endl;
    537631
    538632  for (i=0;i<(UInt_t (SLICES_MFADC))*1001;i++){
    539     noise[i]=GenElec->Gaus(0., value  );
    540       }
     633    noise[i]=GenElec->Gaus(0., value1 );
     634    noise_outer[i]=GenElec->Gaus(0., value2 );
     635  }
    541636
    542637  cout<<"MFadc::SetElecNoise ... done"<<endl;
     
    544639}
    545640
    546 void MFadc::ElecNoise(Float_t value) {
     641void MFadc::ElecNoise() {
    547642  // ============================================================
    548643  //
    549   //    adds the noise due to optronic and electronic
    550   //    to the signal
     644  //    adds the noise due to optronics and electronics
     645  //    to the signal. This is noise which comes before the FADC,
     646  //    so it will be later scaled down in the low gain branch.
    551647  //
    552648  UInt_t startslice;
    553649
    554     for ( Int_t i = 0 ; i < numpix; i++) {
    555         //
    556         //  but at the beginning we must check if this pixel is
    557         //  hitted the first time
    558         //
    559 
    560       startslice=GenElec->Integer(((Int_t)SLICES_MFADC)*1000);
    561 
    562         if ( used[i] == FALSE ) {
    563             used [i] = TRUE ;
    564            
    565             memcpy( (Float_t*)&sig[i][0],
     650  for ( Int_t i = 0 ; i < numpix; i++) {
     651    //
     652    //  but at the beginning we must check if this pixel is
     653    //  hitted the first time
     654    //
     655
     656    startslice=GenElec->Integer(((Int_t)SLICES_MFADC)*1000);
     657
     658    if ( used[i] == FALSE )
     659    {
     660        used [i] = TRUE ;
     661        if (i < fInnerPixelsNum)
     662            memcpy( (Float_t*)&sig[i][0],
    566663                    (Float_t*)&noise[startslice],
    567664                    ((Int_t) SLICES_MFADC)*sizeof(Float_t));
    568      
    569           for ( Int_t is=0 ; is< (Int_t)SLICES_MFADC ; is++ ) {
    570 
    571           }
    572         }
    573         //     
    574         //  Then the noise is introduced for each time slice
    575         //
    576665        else
    577           for ( Int_t is=0 ; is< (Int_t)SLICES_MFADC ; is++ ) {
    578            
    579             sig[i][is] += noise[startslice+is] ;
    580            
    581           }
    582     }
     666            memcpy( (Float_t*)&sig[i][0],
     667                    (Float_t*)&noise_outer[startslice],
     668                    ((Int_t) SLICES_MFADC)*sizeof(Float_t));
     669    }
     670
     671    //     
     672    //  If pixel already in use, the noise is added each time slice
     673    //
     674    else
     675    {
     676        if (i < fInnerPixelsNum)
     677            for ( Int_t is=0 ; is< (Int_t)SLICES_MFADC ; is++ )
     678                sig[i][is] += noise[startslice+is];
     679        else
     680            for ( Int_t is=0 ; is< (Int_t)SLICES_MFADC ; is++ )
     681                sig[i][is] += noise_outer[startslice+is];
     682    }
     683  }
    583684}
    584685
     
    603704  // ============================================================
    604705  //
    605   //    adds the noise due to optronic and electronic
    606   //    to the signal
     706  //    adds the noise due to FADC electronics to the signal. This
     707  //    noise affects equally the high and low gain branches, that is,
     708  //    it is not scaled down in the low gain branch.
    607709  //
    608710  UInt_t startslice;
    609711
    610     for ( Int_t i = 0 ; i < numpix; i++) {
    611 
    612       if ( used[i] == TRUE ) {
    613         startslice=GenElec->Integer((Int_t) SLICES_MFADC*999);
    614         //     
    615         //  Then the noise is introduced for each time slice
    616         //
    617         for ( Int_t is=0 ; is< FADC_SLICES; is++ ) {
    618          
    619           if(digital_noise[startslice+is]+Int_t(output[i][is])<0)
    620              output[i][is] = 0;
    621           else
    622             output[i][is] =
    623               (digital_noise[startslice+is]+Int_t(output[i][is])>255 ?
    624                255 :
    625                UChar_t(digital_noise[startslice+is]+Int_t(output[i][is])));
    626           if(digital_noise[startslice+FADC_SLICES+is]+Int_t(output_lowgain[i][is])<0)
    627             output_lowgain[i][is] = 0;
    628           else
    629             output_lowgain[i][is] =
    630               (digital_noise[startslice+FADC_SLICES+is]
    631                +Int_t(output_lowgain[i][is])>255?
    632                255:
    633                UChar_t(digital_noise[startslice+FADC_SLICES+is]
    634                        +Int_t(output_lowgain[i][is])));
     712  for ( Int_t i = 0 ; i < numpix; i++)
     713    {
     714      if ( used[i] == FALSE )
     715        continue;
     716
     717      startslice=GenElec->Integer((Int_t) SLICES_MFADC*999);
     718      //     
     719      //  Then the noise is introduced for each time slice
     720      //
     721      for ( Int_t is=0 ; is< FADC_SLICES; is++ )
     722        {
     723          output[i][is] += digital_noise[startslice+is];
     724          output_lowgain[i][is] += digital_noise[startslice+FADC_SLICES+is];
    635725        }
    636       }
    637     }
    638 }
    639 
     726    }
     727}
    640728
    641729void MFadc::Scan() {
     
    726814}
    727815
    728 Float_t MFadc::GetPedestalNoise( Int_t pix, Int_t ishigh) {
    729   // ============================================================
    730   //
    731   //    computes the pedestal sigma for channel pix
    732 
    733   Float_t sigma=0;
     816//===========================================================================
     817//
     818// Next function generates one pure noise event for pixel "pix", then adds
     819// up the readouts of a number n_slices of its FADC slices, this being the
     820// return value.
     821//
     822Float_t MFadc::AddNoiseInSlices( Int_t pix, Int_t ishigh, Int_t n_slices) {
     823
     824  Float_t sum=0;
     825  Float_t fvalue = 0.;
    734826  UChar_t value=0;
    735827 
     
    737829  UInt_t startslice;
    738830
     831  //
     832  // If we deal with low gain, we have to scale the values in sig[][] by
     833  // the gain ratio (high2low_gain), since "sig" contains here the noise
     834  // produce before the receiver boards (for instance NSB noise)
     835  //
    739836  factor=(ishigh?1.0:high2low_gain);
    740837
     838  //
     839  // Get at random a point in the FADC presimulated digital noise:
     840  //
    741841  startslice=GenElec->Integer((Int_t) SLICES_MFADC*999);
    742842
    743   for ( Int_t is=0; is <  (Int_t)SLICES_MFADC ; is++ ) {
    744     if (pedestal[pix]+(sig[pix][is]-pedestal[pix])/factor>0.0){
    745       value=(pedestal[pix]+(sig[pix][is]-pedestal[pix])/factor > 255.
    746              ? 255
    747              :UChar_t(pedestal[pix]+(sig[pix][is]-pedestal[pix])/factor+0.5));
    748 
    749       if(Int_t(value)+digital_noise[startslice+is]<0.0)
    750          value=0;
    751       else
    752         value=(Int_t(value)+digital_noise[startslice+is]>255
    753                ?255
    754                :UChar_t(Int_t(value)+digital_noise[startslice+is]));
    755     }
    756     else {
    757       value= 0;
    758       if(Int_t(value)+digital_noise[startslice+is]<0.0)
    759          value=0;
    760       else
    761         value=(Int_t(value)+digital_noise[startslice+is]>255
    762                ?255
    763                :UChar_t(Int_t(value)+digital_noise[startslice+is]));
    764     }
    765     sigma+=((Float_t)value-pedestal[pix])*((Float_t)value-pedestal[pix]);
    766 
    767   }
    768 
    769   sigma=sqrt(sigma/(SLICES_MFADC-1));
    770 
    771   return sigma;
    772 }
     843  for ( Int_t is=0; is < n_slices ; is++ )
     844    {
     845        fvalue = pedestal[pix]+(sig[pix][is]-pedestal[pix])/factor;
     846        fvalue += digital_noise[startslice+is];
     847
     848        fvalue = fvalue < 0? fvalue-0.5 : fvalue+0.5;
     849
     850        value = fvalue < 0.? (UChar_t) 0 :
     851          (fvalue > 255.? 255 : (UChar_t) fvalue);
     852
     853
     854      // Add up slices:
     855      sum += value - pedestal[pix];
     856    }
     857
     858  return sum;
     859}
     860
     861//=======================================================================
    773862
    774863void MFadc::TriggeredFadc(Float_t time) {
     
    786875  iFirstSlice = (Int_t) ( 0.5 + time /  WIDTH_FADC_TIMESLICE ) ;
    787876
    788   for ( Int_t ip=0; ip<numpix; ip++ ) {
    789    
    790       if ( used[ip] == kTRUE ) {
    791           i=0;
    792           for ( Int_t is=iFirstSlice ; is < (iFirstSlice+FADC_SLICES) ; is++ )
    793           {
    794               if (is< (Int_t)SLICES_MFADC && sig[ip][is]>0.0)
    795               {
    796            
    797                   output[ip][i]=(sig[ip][is] > 255. ? 255 :(UChar_t) (sig[ip][is]+0.5));
    798                   output_lowgain[ip][i]=
    799                       (Int_t)(pedestal[ip]+(sig[ip][is]-pedestal[ip])/high2low_gain+0.5) > 255. ? 255 :
    800                       (UChar_t)(pedestal[ip]+(sig[ip][is]-pedestal[ip])/high2low_gain+0.5);
    801                   i++;
    802            
    803               }
    804               else if(sig[ip][is]>=0.0)
    805               {
    806                   output[ip][i]= (UChar_t)(pedestal[ip]+0.5);
    807                   output_lowgain[ip][i]= (UChar_t)(pedestal[ip]+0.5);
    808                   i++;
    809               }
    810               else
    811               {
    812                   output[ip][i]= 0;
    813                   if((pedestal[ip]+(sig[ip][is]-pedestal[ip])/high2low_gain)<0)
    814                       output_lowgain[ip][i]= 0;
    815                   else
    816                       output_lowgain[ip][i]=(UChar_t)(pedestal[ip]+(sig[ip][is]-pedestal[ip])/high2low_gain+0.5);
    817                   i++;
    818               }
    819           }
    820       }
    821       else 
    822           // Pixels with no C-photons in the case that camera is run with
    823           // no noise (nor NSB neither electronic)
    824       {
     877
     878  for ( Int_t ip=0; ip<numpix; ip++ )
     879    {
     880
     881      if ( used[ip] == kFALSE)
     882        // Pixels with no C-photons, in the case that camera is being run with
     883        // no noise (nor NSB neither electronic). We then set the mean pedestal as
     884        // signal, since when analyzing the camera output file, MARS will subtract
     885        // it anyway!
     886        {
    825887          for ( Int_t i=0 ; i < FADC_SLICES ; i++ )
    826           {
    827               output[ip][i]= (UChar_t)(pedestal[ip]+0.5);
    828               output_lowgain[ip][i]= (UChar_t)(pedestal[ip]+0.5);
    829           }
    830       }
    831   }
    832 
    833 }
     888            {
     889              output[ip][i]= pedestal[ip];
     890              output_lowgain[ip][i]= pedestal[ip];
     891            }
     892          continue;
     893        }
     894
     895      i=0;
     896      for ( Int_t is=iFirstSlice ; is < (iFirstSlice+FADC_SLICES) ; is++ )
     897        {
     898          if (is < (Int_t)SLICES_MFADC)
     899            {
     900              output[ip][i] = sig[ip][is];
     901
     902              // Low gain is scaled down by the factor high2low_gain:
     903              output_lowgain[ip][i]= pedestal[ip] + (sig[ip][is]-pedestal[ip])/high2low_gain;
     904            }
     905          else // We are beyond the simulated signal history in sig[][]! Put just mean pedestal!
     906            {
     907              output[ip][i] = pedestal[ip];
     908              output_lowgain[ip][i]= pedestal[ip];
     909            }
     910          i++;
     911        }
     912    }
     913}
     914
    834915
    835916void MFadc::ShowSignal (MMcEvt *McEvt, Float_t trigTime) {
     
    856937  // the list of analog signal histograms
    857938  // at the beginning we initalise 10 elements
    858   // but this array expand automaticly if neccessay
     939  // but this array expand automatically if neccessay
    859940 
    860941  Int_t ic = 0 ;
     
    865946      sprintf (name, "fadc signal %d", i ) ;
    866947     
    867       hist = new TH1F(dumm, name, SLICES_MFADC, fadc_time_offset, TOTAL_TRIGGER_TIME+fadc_time_offset);
     948      hist = new TH1F(dumm, name, (Int_t)SLICES_MFADC, fadc_time_offset, TOTAL_TRIGGER_TIME+fadc_time_offset);
    868949      //
    869950      //  fill the histogram
     
    911992  //  time slice which would be read.
    912993
    913   return (output[pixel][slice]);
     994  //  Since May 1 2004, we do the rounding and the truncation to the range
     995  //  0-255 counts here. (A. Moralejo)
     996
     997  Float_t out = output[pixel][slice] > 0. ?
     998    output[pixel][slice]+0.5 : output[pixel][slice]-0.5;
     999  // (add or subtract 0.5 for correct rounding)
     1000
     1001  return (out < 0.? (UChar_t) 0 :
     1002          (out > 255.? (UChar_t) 255 :
     1003           (UChar_t) out));
    9141004}
    9151005
     
    9181008 
    9191009   //  It returns the analog signal for a given pixel and a given FADC
    920    //  time slice which would be read.
     1010   //  time slice which would be read. Same comment as above.
    9211011 
    922    return (output_lowgain[pixel][slice]);
    923 }
    924 
    925 
    926 
     1012  Float_t outlow = output_lowgain[pixel][slice] > 0. ?
     1013    output_lowgain[pixel][slice]+0.5 :
     1014    output_lowgain[pixel][slice]-0.5;
     1015  // (add or subtract 0.5 for correct rounding)
     1016
     1017  return (outlow < 0.? (UChar_t) 0 :
     1018          (outlow > 255.? (UChar_t) 255 :
     1019           (UChar_t) outlow));
     1020}
     1021
     1022
     1023
  • trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.hxx

    r2986 r5079  
    4949 private:
    5050  Int_t numpix;
     51  Int_t fInnerPixelsNum; // number of inner (small) pixels.
    5152  //
    5253  //    then for all pixels the shape of all the analog signals
     
    5556  Float_t  pedestal[CAMERA_PIXELS] ;  //  Pedestal of FADCs
    5657
    57   Float_t  sig[CAMERA_PIXELS][(Int_t) SLICES_MFADC] ; //  the analog signal for pixels
     58  Float_t  sig[CAMERA_PIXELS][(Int_t) SLICES_MFADC] ; //  the analog signal for pixels, in bins of width
     59                                                      //  equal to the FADC slice: 50/15 ns, but with a
     60                                                      //  total of SLICES_MFADC (=48 now) bins.
    5861  Float_t noise[((Int_t) SLICES_MFADC)*1001];
     62  Float_t noise_outer[((Int_t) SLICES_MFADC)*1001];
    5963  Int_t digital_noise[((Int_t) SLICES_MFADC)*1001];
    6064
    61   UChar_t  output[CAMERA_PIXELS][FADC_SLICES];  //  the analog signal for pixels that is read after a trigger occurs (high gain).
    62 
    63   UChar_t  output_lowgain[CAMERA_PIXELS][FADC_SLICES]; //  analog signal, low gain.
     65  Float_t  output[CAMERA_PIXELS][FADC_SLICES];  //  the analog signal for pixels that is read after a trigger
     66                                                //  occurs (high gain). Only 15 (=FADC_SLICES) bins
     67
     68  Float_t  output_lowgain[CAMERA_PIXELS][FADC_SLICES]; //  analog signal, low gain.
     69
    6470  Float_t high2low_gain;
    6571  //
    6672  //    first the data for the response function
    6773  //
     74  Int_t shape_resp ;                      // index shape of the phe_response function
     75                                          // = 0 --> Gaussian
     76                                          // = 1 --> Pulpo set-up
    6877  Float_t fwhm_resp ;                      // fwhm of the phe_response function (in ns)
    6978  Float_t integ_resp ;                      // area below curve of the phe_response function (in counts * ns)
     
    7382  //    We may end up with a different reponse for the outer pixels
    7483  //
     84  Int_t shape_resp_outer ;                      // index shape of the phe_response function
     85                                          // = 0 --> Gaussian
     86                                          // = 1 --> Pulpo set-up
    7587  Float_t fwhm_resp_outer ;                      // fwhm of the phe_response function (in ns)
    7688  Float_t integ_resp_outer ;                      // area below curve of the phe_response function (in counts * ns)
     
    90102
    91103  MFadc(Int_t pix=577,
     104        Int_t shape=0,
    92105        Float_t ampl=MFADC_RESPONSE_INTEGRAL,
    93106        Float_t fwhm=MFADC_RESPONSE_FWHM,
     107        Int_t shapeout=0,
    94108        Float_t amplout=MFADC_RESPONSE_INTEGRAL,
    95109        Float_t fwhmout=MFADC_RESPONSE_FWHM,
     
    114128  void SetPedestals( Float_t *ped);
    115129
     130  void SetShape( Int_t inner, Int_t outer){
     131    shape_resp=inner;
     132    shape_resp_outer=outer;
     133  }
     134
    116135  void SetFwhm( Float_t fwhm){
    117136    fwhm_resp=fwhm;
     
    136155  void Offset( Float_t, Int_t );
    137156
    138   void SetElecNoise(Float_t value=2.0);
    139 
    140   void ElecNoise(Float_t value=2.0) ;
     157  void SetElecNoise(Float_t value1=2.0, Float_t value2=2.0, UInt_t ninpix=CAMERA_PIXELS);
     158
     159  void ElecNoise();
    141160
    142161  void SetDigitalNoise(Float_t value=2.0);
     
    154173  Float_t GetPedestalNoise (Int_t pix, Int_t ishigh);
    155174
     175  Float_t AddNoiseInSlices( Int_t pix, Int_t ishigh, Int_t n_slices);
     176
    156177  void TriggeredFadc(Float_t time);
    157178
     
    163184
    164185  void SetHigh2LowGain(Float_t h2l) {high2low_gain=h2l;}
     186
     187  Float_t GetShape() {
     188    return shape_resp;
     189  }
    165190
    166191  Float_t GetIntegral() {
Note: See TracChangeset for help on using the changeset viewer.