Ignore:
Timestamp:
03/02/07 12:15:34 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mraw/MRawEvtData.cc

    r6253 r8353  
    1818!   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2004
     20!   Copyright: MAGIC Software Development, 2000-2007
    2121!
    2222!
     
    4747//
    4848//
     49//   Version 6
     50//   ------------------
     51//    - The data can now be stoe in a single array keeping he full
     52//      compatibility
     53//
    4954//   Version 5 (0.8.5):
    5055//   ------------------
     
    6873//
    6974/////////////////////////////////////////////////////////////////////////////
    70 
    7175#include "MRawEvtData.h"
    7276
     
    141145UShort_t MRawEvtData::GetNumHiGainSamples() const
    142146{
     147    // If value<0 we are reading old MC files which don't have the
     148    // value set so far. So we use the old methid to determin the
     149    // numbers and calculate them from the length of the arrays.
    143150    return fHiGainPixId->GetSize() ? fHiGainFadcSamples->GetSize()/fHiGainPixId->GetSize() : 0;
    144151}
     
    150157UShort_t MRawEvtData::GetNumLoGainSamples() const
    151158{
     159    // If value<0 we are reading old MC files which don't have the
     160    // value set so far. So we use the old methid to determin the
     161    // numbers and calculate them from the length of the arrays.
    152162    return fLoGainPixId->GetSize() ? fLoGainFadcSamples->GetSize()/fLoGainPixId->GetSize() : 0;
    153163}
     
    159169UShort_t MRawEvtData::GetNumPixels() const
    160170{
    161     return fHiGainPixId->GetSize();
    162 }
    163 
     171    return fHiGainPixId ? fHiGainPixId->GetSize() : 0;
     172}
    164173
    165174// --------------------------------------------------------------------------
     
    180189    const UShort_t nLoSamp = GetNumLoGainSamples();
    181190
    182     const UShort_t nHiPix = fHiGainPixId->GetSize();;
    183     const UShort_t nLoPix = fLoGainPixId->GetSize();;
    184 
    185191    fLog->unsetf(ios::showbase);
    186192
    187193    *fLog << dec << all;
    188194    *fLog << GetDescriptor() << ": " << endl;
    189     *fLog << "HiGain: " << nHiPix << " Pixels with " << (Int_t)nHiSamp << " Samples" << endl;
    190     *fLog << "LoGain: " << nLoPix << " Pixels with " << (Int_t)nLoSamp << " Samples";
     195    *fLog << GetNumPixels() << " Pixels with " << (Int_t)nHiSamp << "/" << (Int_t)nLoSamp << " samples" << endl;
    191196
    192197    TString str(opt);
    193198    Int_t manip = str.Contains("dec", TString::kIgnoreCase);
    194199
    195     Int_t l=0;
    196     for (int i=0; i<nHiPix; i++)
    197     {
    198         const UShort_t idx = (*fHiGainPixId)[i];
    199 
    200         *fLog << endl;
    201         *fLog << " " << setfill(' ') << setw(3) << dec << i << " - " << setw(3);
    202         *fLog << dec << idx << " ";
    203 
    204         if (fABFlags->GetSize())
    205         {
    206             *fLog << "<" << hex << setfill('0') << setw(2);
    207             *fLog << ((Int_t)(*fABFlags)[idx/8]&0xff) << "> ";
    208         }
    209 
    210         *fLog << (manip?dec:hex) << (manip ? setfill(' ') : setfill('0'));
     200    MRawEvtPixelIter pixel(const_cast<MRawEvtData*>(this));
     201    Int_t i = 0;
     202    while (pixel.Next())
     203    {
     204        const UShort_t idx = pixel.GetPixelId();
     205
     206        *fLog << endl << dec << setfill(' ');
     207        *fLog << " " << setw(3) << i++ << " - " << setw(3) << idx << " ";
     208
     209        if (pixel.IsABFlagValid())
     210            *fLog << "<" << (pixel.HasABFlag()?"B":"A") << "> ";
     211
     212        *fLog << (manip?dec:hex) << setfill(manip?' ':'0');
     213
     214        const Byte_t *hi = pixel.GetHiGainSamples();
     215        const Byte_t *lo = pixel.GetLoGainSamples();
    211216
    212217        for (int j=0; j<nHiSamp; j++)
    213218        {
    214219            *fLog << setw(manip?3:2);
    215             *fLog << ((UShort_t)(*fHiGainFadcSamples)[j+i*nHiSamp]&0xff);
     220            *fLog << ((UShort_t)hi[j]&0xff);
    216221            if (manip)
    217222                *fLog << ' ';
    218223        }
    219224
    220         if (!(l<nLoPix && (*fLoGainPixId)[l]==idx))
    221             continue;
    222 
    223         if (manip)
    224             *fLog << "/ ";
    225 
    226225        for (int j=0; j<nLoSamp; j++)
    227226        {
    228227            *fLog << setw(manip?3:2);
    229             *fLog << ((UShort_t)(*fLoGainFadcSamples)[j+i*nLoSamp]&0xff);
     228            *fLog << ((UShort_t)lo[j]&0xff);
    230229            if (manip)
    231230                *fLog << ' ';
    232231        }
    233         l++;
    234     }
    235     *fLog << endl;
     232    }
     233    *fLog << dec << endl;
    236234}
    237235
     
    292290        for (int i=0; i<nh; i++)
    293291            graphhi->SetPoint(graphhi->GetN(), i, higains[i]);
     292        for (int i=0; i<nl; i++)
     293            graphhi->SetPoint(graphhi->GetN(), i+nh, logains[i]);
    294294
    295295        graphhi->SetMaximum(256);
     
    305305        histhi->SetXTitle("Time/FADC Slices");
    306306        histhi->SetYTitle("Signal/FADC Units");
    307 
    308         if (nl>0)
    309         {
    310             TGraph *graphlo = new TGraph;
    311 
    312             for (int i=0; i<nl; i++)
    313                 graphlo->SetPoint(graphlo->GetN(), i, logains[i]);
    314 
    315             graphlo->SetMaximum(256);
    316             graphlo->SetMinimum(0);
    317             graphlo->SetLineColor(kBlue);
    318 
    319             graphlo->SetBit(kCanDelete);
    320             graphlo->Draw("C*");
    321 
    322             TH1F *histlo = graphlo->GetHistogram();
    323 
    324             histlo->SetXTitle("Time/FADC Slices");
    325             histlo->SetYTitle("Signal/FADC Units");
    326         }
    327307
    328308        return;
     
    342322        for (int i=0; i<nh; i++)
    343323            histh->Fill(i, higains[i]);
     324        for (int i=0; i<nl; i++)
     325            histh->Fill(i, logains[i]);
    344326        histh->SetBit(kCanDelete);
    345327        histh->Draw(same ? "same" : "");
    346328
    347         if (nl>0)
    348         {
    349             TH1F *histl = new TH1F(name+";2", "FADC Samples", nl, -0.5, nl-.5);
    350             histl->SetLineColor(kBlue);
    351             histl->SetDirectory(NULL);
    352             for (int i=0; i<nl; i++)
    353                 histl->Fill(i, logains[i]);
    354             histl->SetBit(kCanDelete);
    355             histl->Draw("same");
    356         }
    357329        return;
    358330    }
     
    368340void MRawEvtData::InitArrays(UShort_t numconnected, UShort_t maxid)
    369341{
    370     const Int_t numhi = fRunHeader ? fRunHeader->GetNumSamplesHiGain() : 0;
    371     const Int_t numlo = fRunHeader ? fRunHeader->GetNumSamplesLoGain() : 0;
     342    // fRunHeader should not be set only in the constructor!
     343    const Int_t numhi = fRunHeader ? fRunHeader->GetNumSamplesHiGain() : -1;
     344    const Int_t numlo = fRunHeader ? fRunHeader->GetNumSamplesLoGain() : -1;
    372345
    373346    fHiGainPixId       = new MArrayS(numconnected);
    374     fLoGainPixId       = new MArrayS(numconnected);
    375     fHiGainFadcSamples = new MArrayB(numconnected*numhi);
    376     fLoGainFadcSamples = new MArrayB(numconnected*numlo);
     347    fLoGainPixId       = new MArrayS(0);
     348    fHiGainFadcSamples = new MArrayB(numconnected*(numhi+numlo));
     349    fLoGainFadcSamples = new MArrayB(0);
    377350
    378351    fABFlags           = new MArrayB(maxid==0 ? 0 : maxid/8+1);
     
    416389//  This is to fill the data of one pixel to the MRawEvtHeader Class.
    417390//  The parameters are the pixelnumber and the FADC_SLICES values of ADCs
    418 //  Add to lo gains if lflag = 1
    419 //
     391//
     392void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data)
     393{
     394    const Int_t n = fRunHeader->GetNumSamples();
     395    if (data->GetSize()!=n)
     396    {
     397        *fLog << err << "RawEvtData::AddPixel: Error, number of samples in ";
     398        *fLog << "TArrayC " << data->GetSize() << " doesn't match current number " << n << endl;
     399        return;
     400    }
     401
     402    //
     403    // enhance pixel array by one
     404    //
     405    fHiGainPixId->Set(fHiGainPixId->GetSize()+1);
     406
     407    //
     408    // add the number of the new pixel to the array as last entry
     409    //
     410    fHiGainPixId->AddAt(nOfPixel, fHiGainPixId->GetSize()-1);
     411
     412    //
     413    // enhance the array by the number of new samples
     414    //
     415    fHiGainFadcSamples->Set(fHiGainFadcSamples->GetSize()+n);
     416
     417    //
     418    // add the new slices as last entries to array
     419    //
     420    fHiGainFadcSamples->AddAt((Byte_t*)data->GetArray(), fHiGainFadcSamples->GetSize()-n, n);
     421}
     422/*
    420423void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag)
    421424{
     
    456459    arrsam->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
    457460}
    458 
    459 void MRawEvtData::ReadPixel(istream &fin, Int_t npix, Bool_t ab)
    460 {
    461     Byte_t *poshi = fHiGainFadcSamples->GetArray() + fConnectedPixels*fRunHeader->GetNumSamplesHiGain();
    462     Byte_t *poslo = fLoGainFadcSamples->GetArray() + fConnectedPixels*fRunHeader->GetNumSamplesLoGain();
     461*/
     462
     463void MRawEvtData::ReadPixel(istream &fin, Int_t npix)
     464{
     465    // number of samples
     466    const UInt_t ns = fRunHeader->GetNumSamples();
     467
     468    // position in higain array
     469    Byte_t *pos = fHiGainFadcSamples->GetArray() + fConnectedPixels*ns;
     470
     471    // bytes per sample
     472    const Int_t bps = fRunHeader->GetNumBytesPerSample();
     473
     474    // Number of bytes
     475    const Int_t nb = ns*bps;
     476
     477    // Set pixel index
     478    fHiGainPixId->AddAt(npix, fConnectedPixels++);
    463479
    464480    // Read data for one pixel
    465     fin.read((char*)poshi, fRunHeader->GetNumSamplesHiGain());
    466     fHiGainPixId->AddAt(npix, fConnectedPixels);
    467 
    468     if (poslo)
    469     {
    470         fin.read((char*)poslo, fRunHeader->GetNumSamplesLoGain());
    471         // FIXME: Not implemented in the raw files yet
    472         //if (IsLoGainOn(i, j))
    473         //{
    474         fLoGainPixId->AddAt(npix, fConnectedPixels);
    475         //}
    476     }
    477 
     481    if (bps==1)
     482    {
     483        fin.read((char*)pos, nb);
     484        return;
     485    }
     486
     487    // Read data for one pixel
     488    Byte_t arr[nb];
     489    fin.read((char*)arr, nb);
     490
     491    for (Byte_t *p=arr+bps-1; p<arr+nb; p+=bps)
     492        *pos++ = *p;
     493}
     494
     495void MRawEvtData::SetABFlag(Int_t npix, Bool_t ab)
     496{
    478497    if (ab)
    479498        SETBIT((*fABFlags)[npix/8], npix%8);
    480499    else
    481500        CLRBIT((*fABFlags)[npix/8], npix%8);
    482 
    483     fConnectedPixels++;
    484501}
    485502
Note: See TracChangeset for help on using the changeset viewer.