Ignore:
Timestamp:
10/24/14 15:31:20 (10 years ago)
Author:
dneise
Message:
new method DrsCalibrateTime::WriteToFits(char*) --> writes the calibration constants into a fits file
new constructor DrsCalibrateTime::DrsCalibrateTime(char) --> read the constants from the fits file back into the class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Mars_use_drstimefiles/mcore/DrsCalib.h

    r17757 r17995  
    947947    {
    948948    }
     949
     950    // DN: To be done:
     951    //      include also reading of fStat[i].second into the file
     952    //      not done, because it's not yet written into the file.
     953    DrsCalibrateTime(const char* fits_file_path) : fNumEntries(0), fNumSamples(0), fNumChannels(0)
     954    {
     955        fits drs_time_file(fits_file_path);
     956
     957        fNumSamples = drs_time_file.GetInt("NCHIPS");
     958        fNumChannels = drs_time_file.GetInt("NCELLS");
     959        fNumEntries = drs_time_file.GetInt("NENTRIES"); // the number of events, that were in the original file.
     960        InitSize(fNumChannels, fNumSamples);
     961       
     962        double *drs_sampling_time_deviations = new double[fNumChannels * fNumSamples];
     963        drs_time_file.SetPtrAddress("SamplingTimeDeviation", drs_sampling_time_deviations);
     964        drs_time_file.GetNextRow();
     965        for (size_t i=0; i<fNumChannels * fNumSamples; i++){
     966            fStat[i].first = drs_sampling_time_deviations[i];
     967        }
     968        drs_time_file.close();
     969        // if deleting drs_sampling_time_deviations, before closing the file,
     970        // I get a seg fault. So apparently fits accesses this array not only
     971        // in the call to GetNextRow() Why? is that so?
     972        delete[] drs_sampling_time_deviations;
     973        drs_sampling_time_deviations = NULL;
     974    }
     975
     976    // DN: To be done:
     977    //      include also writing of fStat[i].second into the file
     978    //      not done, because I don't know how.
     979    void WriteToFits(const char* fits_file_path)
     980    {
     981        ofits drstimeFile(fits_file_path);
     982        drstimeFile.SetDefaultKeys();
     983        drstimeFile.AddColumnDouble(
     984            fNumChannels*fNumSamples,
     985            "SamplingTimeDeviation", "nominal slices",
     986            "see following COMMENT."
     987        );
     988        drstimeFile.SetInt("NCHIPS", fNumChannels, "number of drs chips");
     989        drstimeFile.SetInt("NCELLS", fNumSamples, "number of cells of each chip");
     990        drstimeFile.SetInt("NENTRIES", fNumEntries, "number of events in raw file");
     991
     992        drstimeFile.AddComment(
     993    "The SamplingTimeDeviation specifies the deviation of the actual ");
     994        drstimeFile.AddComment(
     995    "sampling time of a certain cell, from its nominal sampling time.");
     996        drstimeFile.AddComment(
     997    "It is measured in nominal slices.");
     998        drstimeFile.AddComment(
     999    "In order to convert the sample index into the actual sampling time");
     1000        drstimeFile.AddComment(
     1001    "just do: ");
     1002        drstimeFile.AddComment(
     1003    "     cell_index + td(cell_index) - td(stop_cell_index)");
     1004        drstimeFile.AddComment(
     1005    "where td(i) refers to the SamplingTimeDeviation of cell i of the ");
     1006        drstimeFile.AddComment(
     1007    "current DRS4 chip.");
     1008        drstimeFile.AddComment(
     1009    "This gives you the actual sampling time of the cell measured in ");
     1010        drstimeFile.AddComment(
     1011    "nominal slices [nsl] with respect to the stop cells sampling time.");
     1012        drstimeFile.AddComment(
     1013    "Convert it to ns, simply by multiplication ");
     1014        drstimeFile.AddComment(
     1015    "with 0.5 ns/nsl.");
     1016        drstimeFile.AddComment(
     1017    "");
     1018
     1019        drstimeFile.AddComment(
     1020    "In FACT it became common practice to measure un-time-calibrated ");
     1021        drstimeFile.AddComment(
     1022    " DRS4 data in 'time slices' or simply 'samples', while ");
     1023        drstimeFile.AddComment(
     1024    " time-calibrated DRS4 data usually measured in ns. Since the method,");
     1025        drstimeFile.AddComment(
     1026    " that is emplyed to measure the DRS4 time calibration constants has ");
     1027        drstimeFile.AddComment(
     1028    " no possibility to assert the actual length of a slice is really half");
     1029        drstimeFile.AddComment(
     1030    " a nanosecond, this practice is not advisable.");
     1031        drstimeFile.AddComment(
     1032    " I propose instead to call un-time-calibrated data 'samples',");
     1033        drstimeFile.AddComment(
     1034    " since this is what they are. If one wants to stress the fact,");
     1035        drstimeFile.AddComment(
     1036    " that no drs time calibration has been applied one should refer to ");
     1037        drstimeFile.AddComment(
     1038    "'uncalibrated slices'. Since it *should* be common practice to apply");
     1039
     1040        drstimeFile.AddComment(
     1041    " the drs4 time calibration in all cases, I also propose to use the");
     1042        drstimeFile.AddComment(
     1043    " short term of 'slices' or 'sl'. If one wants to stress, that the");
     1044        drstimeFile.AddComment(
     1045    " drs4 time calibration has actually been applied to the data,");
     1046        drstimeFile.AddComment(
     1047    " the term 'calibrated slices' or 'nominal slices' or short 'nsl'.");
     1048
     1049        drstimeFile.WriteTableHeader("DRS_CELL_TIMES");
     1050
     1051        double *drs_sampling_time_deviations = new double[fNumChannels * fNumSamples];
     1052        for (size_t chip = 0; chip < fNumChannels; chip++){
     1053            for (size_t cell = 0; cell < fNumSamples; cell++){
     1054                drs_sampling_time_deviations[chip*fNumChannels + cell] =
     1055                    fStat[chip*fNumChannels + cell].first;
     1056            }
     1057        }
     1058
     1059        drstimeFile.WriteRow(drs_sampling_time_deviations, sizeof(double) * fNumChannels * fNumSamples);
     1060        drstimeFile.close();
     1061
     1062    }
     1063
    9491064    virtual ~DrsCalibrateTime()
    9501065    {
Note: See TracChangeset for help on using the changeset viewer.