Ignore:
Timestamp:
11/14/11 16:05:08 (13 years ago)
Author:
neise
Message:
tried to prepare for all ROIs and added a lot of comments
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/rootmacros/DrsCalibration.C

    r12508 r12511  
    4242        vector<int16_t> StartCellVector
    4343){
    44         // TODO this should be a parameter...
    45 //      const int NumberOfPixel = 1440;
     44        // In order to minimize mem free and alloc actions
     45        // the destination vector is only resized, if it is way too big
     46        // or too small
     47        size_t DestinationLength = RegionOfInterest-LeaveOutRight-LeaveOutLeft;
     48        if ( destination.size() < DestinationLength || destination.size() > 2 * DestinationLength ){
     49                destination.resize( DestinationLength );
     50        }
    4651
    47 //      if ( RegionOfInterest < drs_triggeroffsetmean.size()/NumberOfPixel ){
    48 //              cerr << "Error in applyDrsCalibration: ROI of data is:" << RegionOfInterest << endl;
    49 //              cerr << "While ROI of 'TriggerOffset' is:" << drs_triggeroffsetmean.size()/NumberOfPixel << endl;
    50 //              cerr << "Data ROI must be <= ROI of TriggerOffset. Aborting..." << endl;
    51 //              return 0
    52 //      }
     52        // the vector drs_triggeroffsetmean is not 1440 * 1024 entries long
     53        // but has hopefully the length 1440 * RegionOfInterest (or longer)
     54        if ( drs_triggeroffsetmean.size() < 1440*RegionOfInterest ){
     55                return 0;
     56        }
    5357
     58        //      We do not entirely know how the calibration constants, which are saved in a filename.drs.fits file
     59        // were calculated, so it is not fully clear how they should be applied to the raw data for calibration.
     60        // apparently the calibration constants were transformed to the unit mV, which means we have to do the same to
     61        // the raw data prior to apply the calibration
     62        //
     63        // on the FAD board, there is a 12bit ADC, with a 2.0V range, so the factor between ADC units and mV is
     64        // ADC2mV = 2000/4096. = 0.48828125 (numerically exact)
     65        //
     66        // from the schematic of the FAD we learned, that the voltage at the ADC
     67        // should be 1907.35 mV when the calibration DAC is set to 50000.
     68        //
     69        // One would further assume that the calibration constants are calculated like this:
    5470
    55         destination.clear();
     71        // The DRS Offset of each bin in each channel is the mean value in this very bin,
     72        // obtained from so called DRS pedestal data
     73        // Its value is about -1820 ADC units or -910mV
     74
     75        // In order to obtain the DRS Gain of each bin of each channel
     76        // again data is takes, with the calibration DAC set to 50000
     77        // This is called DRS calibration data.
     78        // We assume the DRS Offset is already subtracted from the DRS calibration data
     79        // so the typical value is assumed to be ~3600 ADC units oder ~1800mV
     80        // As mentioned before, the value *should* be 1907.35 mV
     81        // So one might assume that the Gain is a number, which actually converts ~3600 ADC units into 1907.35mV for each bin of each channel.
     82        // So that the calibration procedure looks like this
     83        // TrueValue = (RawValue - Offset) * Gain
     84        // The numerical value of Gain would differ slightly from the theoretical value of 2000/4096.
     85        // But this is apparently not the case.
     86        // The Gain, as it is stored in the DRS calibration file of FACT++ has numerical values
     87        // around +1800.
     88        // So it seems one should calibrate like this:
     89        // TrueValue = (RawValue - Offset) / Gain * 1907.35
     90
     91        // When these calibrations are done, one ends up with a quite nice calibrated voltage.
     92        // But it turns out that, if one returns the first measurement, and calculates the mean voltages
     93        // in each bin of the now *logical* DRS pipeline, the mean voltage is not zero, but slightly varies
     94        // So one can store these systematical deviations from zero in the logical pipeline as well, and subtract them.
     95        // The remaining question is, when to subtract them.
     96        // I assume, in the process of measuring this third calibration constant, the first two
     97        // calibrations are already applied to the raw data.
     98
     99        // So the calculation of the calibrated volatage from some raw voltage works like this:
     100        // assume the raw voltage is the s'th sample in channel c. While the Trigger made the DRS stopp in its t'th cell.
     101        // note, that the DRS pipeline is always 1024 bins long. This is constant of the DRS4 chip.
     102
     103        // TrueValue[c][s] = ( RawValue[c][s] - Offset[c][ (c+t)%1024 ] ) / Gain[c][ (c+t)%1024 ] * 1907.35 - TriggerOffset[c][s]
     104       
     105       
     106       
     107
    56108        const float dconv = 2000/4096.0;
    57         float vraw, vcal;
    58         unsigned int pixel_pt;
    59         unsigned int slice_pt;
    60         unsigned int cal_pt;
    61         unsigned int drs_cal_offset;
     109        float vraw;
     110//      float vcal;
     111//      unsigned int pixel_pt;
     112//      unsigned int slice_pt;
     113//      unsigned int cal_pt;
     114//      unsigned int drs_cal_offset;
    62115
    63         pixel_pt = pixel * RegionOfInterest;
     116        if ( RegionOfInterest != AllPixelDataVector.size()/1440 ){
     117                cout << "RegionOfInterest != AllPixelDataVector.size()/1440 .. this makes no sense ... I guess ... aborting" << endl;
     118                return 0;
     119        }
    64120
    65 //      unsigned int pixel_pt_TriggerOffset = pixel * drs_triggeroffsetmean.size()/NumberOfPixel;
    66 //      unsigned int slice_pti_TriggerOffset;
     121        int Offset_offset = pixel * drs_basemean.size()/1440;
     122        int Gain_offset = pixel * drs_gainmean.size()/1440;
     123        int TriggerOffset_offset = pixel * drs_triggeroffsetmean.size()/1440;
     124        int Data_offset = pixel * RegionOfInterest;
     125       
     126        for ( unsigned int sl = LeaveOutLeft; sl < RegionOfInterest-LeaveOutRight ; sl++){
     127                vraw = AllPixelDataVector[ Data_offset + sl ] * dconv;
     128                vraw -= drs_basemean[ Offset_offset + (sl + StartCellVector[pixel])%1024 ];
     129                vraw /= drs_gainmean[ Gain_offset + (sl + StartCellVector[pixel])%1024 ];
     130                vraw *= 1907.35;
     131                vraw -= drs_triggeroffsetmean[ TriggerOffset_offset + sl ];
    67132
    68         for ( unsigned int sl = LeaveOutLeft; sl < RegionOfInterest-LeaveOutRight ; sl++){
    69                 slice_pt = pixel_pt + sl;
    70                 //slice_pt_TriggerOffset =  pixel_pt_TriggerOffset + sl;       
    71                 drs_cal_offset = ( sl + StartCellVector[ pixel ] ) % 1024;
    72                 cal_pt    = pixel_pt + drs_cal_offset;
     133//              slice_pt = pixel_pt + sl;
     134//              drs_cal_offset = ( sl + StartCellVector[ pixel ] ) % RegionOfInterest;
     135//              cal_pt    = pixel_pt + drs_cal_offset;
     136//              vraw = AllPixelDataVector[ slice_pt ] * dconv;
     137//              vcal = ( vraw - drs_basemean[ cal_pt ] - drs_triggeroffsetmean[ slice_pt ] ) / drs_gainmean[ cal_pt ]*1907.35;
     138//              destination.push_back(vcal);
    73139
    74                 vraw = AllPixelDataVector[ slice_pt ] * dconv;
    75                 vcal = ( vraw - drs_basemean[ cal_pt ] - drs_triggeroffsetmean[ slice_pt ] ) / drs_gainmean[ cal_pt ]*1907.35;
    76 
    77                 destination.push_back(vcal);
     140                destination[sl-LeaveOutLeft] = vraw;
    78141        }
    79142
Note: See TracChangeset for help on using the changeset viewer.