Ignore:
Timestamp:
01/30/04 15:01:40 (21 years ago)
Author:
blanch
Message:
[A. Moralejo ]

Two main characteristics have been introduced to be closer to the actual
performance of MAGIC FADC:

- The instantaneous value is stored in the FADC slice instead of integral
 value.

- Signal of FADC can be shifted to put in the desired position.
File:
1 edited

Legend:

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

    r2452 r2985  
    1818#include "MGFadcSignal.hxx"
    1919
    20 MFadc::MFadc(Int_t pix, Float_t ampl, Float_t fwhm, Float_t amplout, Float_t fwhmout) {
     20MFadc::MFadc(Int_t pix, Float_t integral, Float_t fwhm, Float_t integralout, Float_t fwhmout, Float_t trigger_delay) {
    2121  //
    2222  //  Constructor overloaded II
    2323  // 
    2424  //  Input variables:
    25   //  1. ampl(out) = integration of the single phe response (outer pixels)
    26   //  2. fwhm(out) = width at half high of the single phe
    27   //  response(outer pixels)
     25  //  1. integral(out) = integration of the single phe response for inner
     26  // (outer) pixels.
     27  //  2. fwhm(out) = width at half high of the single phe response for
     28  // inner (outer) pixels.
     29  //
     30  // trigger_delay: shift of signals towards later times in FADC, in order
     31  // to center the signals in a good range. It acts as a sort of delay of
     32  // the signals (before being sent to the FADC) with respect to the trigger.
    2833  //
    2934  //  The procedure is the following:
     
    3136  //     this parameters of the trigger may be changed
    3237  //  3. Then the all signals are set to zero
     38
    3339  numpix=pix;
    3440 
    3541  fwhm_resp = fwhm;
    36   ampl_resp = ampl;
     42  integ_resp = integral;
    3743  fwhm_resp_outer = fwhmout;
    38   ampl_resp_outer = amplout;
     44  integ_resp_outer = integralout;
    3945
    4046  cout<< "[MFadc]  Setting up the MFadc with this values "<< endl ;
    4147  cout<< "[MFadc]    - Inner pixels :  "<< endl ;
    42   cout<< "[MFadc]       Response Are : "<<ampl<<" adc counts"<< endl ;
     48  cout<< "[MFadc]       Response Area : "<<integral<<" adc counts"<< endl ;
    4349  cout<< "[MFadc]       Response FWHM : "<<fwhm<<" ns"<< endl ;
    44   cout<< "[MFadc]    - Outer pixels :  "<< endl ;
    45   cout<< "[MFadc]       Response Are : "<<amplout<<" adc counts"<< endl ;
     50  cout<< "[MFadc]    - Inner pixels :  "<< endl ;
     51  cout<< "[MFadc]       Response Area : "<<integralout<<" adc counts"<< endl ;
    4652  cout<< "[MFadc]       Response FWHM : "<<fwhmout<<" ns"<< endl ;
    4753 
     
    5763  x0 = 3*sigma;
    5864 
     65  fadc_time_offset = trigger_delay-x0; // ns
     66
     67
    5968  Float_t   dX, dX2 ;
    6069
     
    7079    //
    7180    //   the value 1/(2*Pi*sigma^2) was introduced to normalize
    72     //   the area at the input value
    73     //
    74     sing_resp[i] = ampl_resp / sqrt(2*3.1415926*sigma*sigma)* 
     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)* 
    7585       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);
    7698
    7799  }
     
    90112    //
    91113    //   the value 1/(2*Pi*sigma^2) was introduced to normalize
    92     //   the area at the input value
    93     //
    94     sing_resp_outer[i] = ampl_resp_outer / sqrt(2*3.1415926*sigma*sigma)* 
     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)* 
    95118       expf(-0.5 * (x-x0)*(x-x0) / (sigma*sigma) ) ;
    96119
     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);
    97131  }
    98132
     
    119153    //
    120154    //  set all values of the signals to zero
    121     //  set tha values of FADC slices that would be read after trigger to zero
     155    //  set the values of FADC slices that would be read after trigger to zero
    122156    //
    123157    memset(used, 0, CAMERA_PIXELS*sizeof(Bool_t));
    124158    memset(output, 0, CAMERA_PIXELS*FADC_SLICES*sizeof(UChar_t));
    125159    memset(output_lowgain, 0, CAMERA_PIXELS*FADC_SLICES*sizeof(UChar_t));
     160    //
     161    // Added 15 01 2004, AM:
     162    //
     163    memset(sig, 0, (Int_t)(CAMERA_PIXELS*SLICES_MFADC*sizeof(Float_t)));
    126164}
    127165void MFadc::Fill( Int_t iPix, Float_t time,
    128166                  Float_t amplitude, Int_t isinner ) {
     167
     168    // AM, Jan 2004 : added delay to shift the signal peak to the desired
     169    // range in the FADC window (indicated through the trigger_delay command
     170    // in the camera input card.
     171
     172  time += fadc_time_offset;
    129173
    130174  if(isinner)
     
    169213  //
    170214
    171  
    172   if ( time < 0. ) {
    173     cout << "  WARNING! Fadc::Fill  " << time << "  below ZERO!! Very strange!!"
    174          << endl ;
    175   }
    176   else if ( time < TOTAL_TRIGGER_TIME ) {
     215  if ( time < TOTAL_TRIGGER_TIME+trigger_delay ) {
    177216    //
    178217    //   determine the slices number assuming the WIDTH_RESPONSE_MFADC
    179     //
     218    //   ichan marks the start of the pulse, in number of bins of width 
     219    //   WIDTH_RESPONSE_MFADC (2/3 of a ns), measured from the start of the
     220    //   FADC.
     221    //
     222
    180223    ichan = (Int_t) ( time / ((Float_t) WIDTH_RESPONSE_MFADC ));
    181224
     
    185228    //
    186229
    187     for ( i = 0 ; i<RESPONSE_SLICES; i++ ) {
     230    //
     231    // AM, Jan 2004: Replaced former FADC simulation (integration of signal)
     232    // with a more realistic one (measuring signal height at discrete points).
     233    //
     234
     235    // We take the pulse height in the middle of FADC slices, we start in the
     236    // first such point after the time "time" (=ichan in response bins). Each
     237    // FADC slice corresponds to SUBBINS response bins (SUBBINS=5 by default).
     238
     239    Int_t first_i =  Int_t(SUBBINS/2) - ichan%(Int_t)SUBBINS;
     240    first_i = first_i < 0 ? (Int_t)SUBBINS+first_i : first_i;
     241
     242
     243    for ( i = first_i ; i < (Int_t)RESPONSE_SLICES; i += (Int_t)SUBBINS) {     
    188244      ichanfadc = (Int_t) ((ichan+i)/SUBBINS) ;
     245      if ( ichanfadc < 0 )
     246          continue;
     247
     248      //
     249      // SLICES_MFADC is by default 48. sig[][] is not the true FADC, which
     250      // is filled from sig[][] in MFadc::TriggeredFadc()
     251      //
    189252      if ( (ichanfadc) < (Int_t)SLICES_MFADC ) { 
    190253        sig[iPix][ichanfadc] += (amplitude * sing_resp[i] )  ;
    191254      }
    192255    }
     256
    193257  }
    194258  else {
    195259    cout << "  WARNING!  Fadc::Fill " << time << "  out of TriggerTimeRange "
    196          << TOTAL_TRIGGER_TIME << endl ;
     260         << TOTAL_TRIGGER_TIME+trigger_delay << endl ;
    197261  }
    198262
     
    234298  //
    235299
    236  
    237   if ( time < 0. ) {
    238     cout << "  WARNING! Fadc::FillOuter  " << time << "  below ZERO!! Very strange!!"
    239          << endl ;
    240   }
    241   else if ( time < TOTAL_TRIGGER_TIME ) {
     300
     301  if ( time < TOTAL_TRIGGER_TIME+trigger_delay ) {
    242302    //
    243303    //   determine the slices number assuming the WIDTH_RESPONSE_MFADC
     
    250310    //
    251311
    252     for ( i = 0 ; i<RESPONSE_SLICES; i++ ) {
     312    //
     313    // AM, Jan 2004: Replaced former FADC simulation (integration of signal)
     314    // with a more realistic one (measuring signal height at discrete points).
     315    //
     316
     317    // We take the pulse height in the middle of FADC slices, we start in the
     318    // first such point after the time "time" (=ichan in response bins). Each
     319    // FADC slice corresponds to SUBBINS response bins (SUBBINS=5 by default).
     320
     321    Int_t first_i =  Int_t(SUBBINS/2) - ichan%(Int_t)SUBBINS;
     322    first_i = first_i < 0 ? (Int_t)SUBBINS+first_i : first_i;
     323
     324    for ( i = first_i ; i < (Int_t)RESPONSE_SLICES; i += (Int_t)SUBBINS) {
    253325      ichanfadc = (Int_t) ((ichan+i)/SUBBINS) ;
     326
     327      if ( ichanfadc < 0 )
     328          continue;
     329
    254330      if ( (ichanfadc) < (Int_t)SLICES_MFADC ) { 
    255331        sig[iPix][ichanfadc] += (amplitude * sing_resp_outer[i] )  ;
    256332      }
    257333    }
     334
    258335  }
    259336  else {
    260337    cout << "  WARNING!  Fadc::FillOuter " << time << "  out of TriggerTimeRange "
    261          << TOTAL_TRIGGER_TIME << endl ;
     338         << TOTAL_TRIGGER_TIME+trigger_delay << endl ;
    262339  }
    263340
     
    364441    baseline=0.0;
    365442    for(i=0;i<(Int_t) SLICES_MFADC;i++){
    366       baseline=+sig[j][i];
     443      baseline+=sig[j][i];
    367444    }
    368445    baseline=baseline/SLICES_MFADC;
     
    383460
    384461  for(i=0;i<numpix;i++)
    385     for(j=0;j<(Int_t)SLICES_MFADC;j++){
    386       if(used[i])
    387         sig[i][j]+=pedestal[i];
    388       else
    389         sig[i][j]=pedestal[i];
    390     }
     462    for(j=0;j<(Int_t)SLICES_MFADC;j++)
     463        sig[i][j]+=pedestal[i];
     464  //
     465  // AM 15 01 2003: Formerly the above operation was performed only
     466  // for pixels in which used[] was true. But to run camera with no noise
     467  // and get the right baseline on the pixels with no C-photons, we have
     468  // to do it for all pixels.
     469  //
     470
    391471
    392472}
     
    412492          fdum=(10*GenOff->Rndm());
    413493          for(j=0;j<(Int_t) SLICES_MFADC;j++)
    414             sig[i][j]=+fdum;
     494            sig[i][j]+=fdum;
    415495        }
    416496      }
     
    421501        fdum=(10*GenOff->Rndm());
    422502        for(j=0;j<(Int_t) SLICES_MFADC;j++)
    423           sig[pixel][j]=+fdum;
     503          sig[pixel][j]+=fdum;
    424504        }
    425505
     
    434514        if (used[i]){
    435515          for(j=0;j<(Int_t) SLICES_MFADC;j++)
    436             sig[i][j]=+offset;
     516            sig[i][j]+=offset;
    437517        }
    438518      }
     
    442522      if (used[pixel]){
    443523        for(j=0;j<(Int_t) SLICES_MFADC;j++)
    444           sig[pixel][j]=+offset;
     524          sig[pixel][j]+=offset;
    445525      }
    446526    }
     
    593673  Float_t t ;
    594674
    595   (0 > time - TIME_BEFORE_TRIGGER)? t=0: t=(time-TIME_BEFORE_TRIGGER) ; // to show also the start of the pulse before the trigger time
     675  (0 > time - TIME_BEFORE_TRIGGER)? t=trigger_delay: t=(time-TIME_BEFORE_TRIGGER+trigger_delay) ; // to show also the start of the pulse before the trigger time
    596676
    597677  if ( t < 0. ) {
     
    666746             ? 255
    667747             :UChar_t(pedestal[pix]+(sig[pix][is]-pedestal[pix])/factor+0.5));
     748
    668749      if(Int_t(value)+digital_noise[startslice+is]<0.0)
    669750         value=0;
     
    683764    }
    684765    sigma+=((Float_t)value-pedestal[pix])*((Float_t)value-pedestal[pix]);
    685   }
    686 
     766
     767  }
    687768
    688769  sigma=sqrt(sigma/(SLICES_MFADC-1));
     
    694775 
    695776  //
    696   //    first of all we subtract from the time a offset (8 ns)
    697   //
    698  
    699   Float_t t ;
    700 
    701   (0>time-TIME_BEFORE_TRIGGER)? t=0: t=(time-TIME_BEFORE_TRIGGER) ; // to show also the start of the pulse before the trigger time
    702 
    703   if ( t < 0. ) {
    704     cout << " WARNING!! FROM MFADC::SCAN(t) " << endl ;
    705     exit (776) ; 
    706   }
    707 
    708   //
    709   //  calculate the first slice to write out
     777  //  calculate the first slice to write out, according to trigger time:
    710778  //
    711779 
     
    713781  Int_t i;
    714782
    715   iFirstSlice = (Int_t) ( t /  WIDTH_FADC_TIMESLICE ) ;
     783  //
     784  // We had 0.5 for the correct rounding:
     785  //
     786  iFirstSlice = (Int_t) ( 0.5 + time /  WIDTH_FADC_TIMESLICE ) ;
    716787
    717788  for ( Int_t ip=0; ip<numpix; ip++ ) {
    718789   
    719     if ( used[ip] == kTRUE ) {
    720       i=0;
    721       for ( Int_t is=iFirstSlice ; is < (iFirstSlice+FADC_SLICES) ; is++ ) {
    722         if (is< (Int_t)SLICES_MFADC && sig[ip][is]>0.0)
     790      if ( used[ip] == kTRUE ) {
     791          i=0;
     792          for ( Int_t is=iFirstSlice ; is < (iFirstSlice+FADC_SLICES) ; is++ )
    723793          {
     794              if (is< (Int_t)SLICES_MFADC && sig[ip][is]>0.0)
     795              {
    724796           
    725             output[ip][i]=(sig[ip][is] > 255. ? 255 :(UChar_t) (sig[ip][is]+0.5));
    726             output_lowgain[ip][i]=
    727               (Int_t)(pedestal[ip]+(sig[ip][is]-pedestal[ip])/high2low_gain+0.5) > 255. ? 255 :
    728               (UChar_t)(pedestal[ip]+(sig[ip][is]-pedestal[ip])/high2low_gain+0.5);
    729             i++;
     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++;
    730802           
     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              }
    731819          }
    732         else if(sig[ip][is]>=0.0)
     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      {
     825          for ( Int_t i=0 ; i < FADC_SLICES ; i++ )
    733826          {
    734             output[ip][i]= (UChar_t)(pedestal[ip]+0.5);
    735             output_lowgain[ip][i]= (UChar_t)(pedestal[ip]+0.5);
    736             i++;
    737           }
    738         else
    739           {
    740             output[ip][i]= 0;
    741             if((pedestal[ip]+(sig[ip][is]-pedestal[ip])/high2low_gain)<0)
    742               output_lowgain[ip][i]= 0;
    743             else
    744               output_lowgain[ip][i]=(UChar_t)(pedestal[ip]+(sig[ip][is]-pedestal[ip])/high2low_gain+0.5);
    745             i++;
    746           }
     827              output[ip][i]= (UChar_t)(pedestal[ip]+0.5);
     828              output_lowgain[ip][i]= (UChar_t)(pedestal[ip]+0.5);
     829          }
    747830      }
    748     }
    749   } 
     831  }
     832
    750833}
    751834
     
    782865      sprintf (name, "fadc signal %d", i ) ;
    783866     
    784       hist = new TH1F(dumm, name, SLICES_MFADC, 0., TOTAL_TRIGGER_TIME);
     867      hist = new TH1F(dumm, name, SLICES_MFADC, trigger_delay, TOTAL_TRIGGER_TIME+trigger_delay);
    785868      //
    786869      //  fill the histogram
Note: See TracChangeset for help on using the changeset viewer.