Ignore:
Timestamp:
07/13/05 19:06:26 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mpedestal
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc

    r7070 r7188  
    175175
    176176const TString MExtractPedestal::fgNamePedestalCam = "MPedestalCam";
     177const TString MExtractPedestal::fgNameRawEvtData  = "MRawEvtData";
    177178const UInt_t  MExtractPedestal::fgNumDump = 500;
    178179
     
    191192MExtractPedestal::MExtractPedestal(const char *name, const char *title)
    192193    : fGeom(NULL), fPedestalsIn(NULL), fPedestalsInter(NULL), fPedestalsOut(NULL),
    193       fExtractor(NULL), fExtractWinFirst(0), fExtractWinSize(0)
     194      fExtractor(NULL), fExtractWinFirst(0), fExtractWinSize(0), fUseSpecialPixels(kFALSE)
    194195{
    195196    fName  = name  ? name  : "MExtractPedestal";
     
    207208    SetNamePedestalCamIn();
    208209    SetNamePedestalCamOut();
     210    SetNamePedestalCamInter();
     211    SetNameRawEvtData();
    209212    SetNumDump();
    210213
     
    311314
    312315  Clear();
    313  
     316
     317  fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber(fNameRawEvtData));
     318  if (!fRawEvt)
     319      if (!fUseSpecialPixels)
     320      {
     321          *fLog << err << AddSerialNumber(fNameRawEvtData) << " not found... aborting." << endl;
     322          return kFALSE;
     323      }
     324
     325
    314326  fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
    315327  if (!fRawEvt)
     
    372384Int_t MExtractPedestal::Process()
    373385{
     386    //
     387    // Necessary check for extraction of special pixels
     388    // together with data which does not yet have them
     389    //
     390    if (fSumx.GetSize()==0)
     391        return kTRUE;
     392
    374393    if (fExtractor)
    375394        fExtractor->SetNoiseCalculation(fRandomCalculation);
     
    405424Bool_t MExtractPedestal::ReInit(MParList *pList)
    406425{
    407   // If the size is not yet set, set the size
    408   if (fSumx.GetSize()==0)
    409   {
    410       const Int_t npixels  = fPedestalsOut->GetSize();
    411       const Int_t areas    = fPedestalsOut->GetNumAverageArea();
    412       const Int_t sectors  = fPedestalsOut->GetNumAverageSector();
    413 
    414       fSumx.  Set(npixels);
    415       fSumx2. Set(npixels);
    416       fSumAB0.Set(npixels);
    417       fSumAB1.Set(npixels);
    418 
    419       fAreaSumx.  Set(areas);
    420       fAreaSumx2. Set(areas);
    421       fAreaSumAB0.Set(areas);
    422       fAreaSumAB1.Set(areas);
    423       fAreaFilled.Set(areas);
    424       fAreaValid .Set(areas);
    425 
    426       fSectorSumx.  Set(sectors);
    427       fSectorSumx2. Set(sectors);
    428       fSectorSumAB0.Set(sectors);
    429       fSectorSumAB1.Set(sectors);
    430       fSectorFilled.Set(sectors);
    431       fSectorValid .Set(sectors);
    432 
    433       for (Int_t i=0; i<npixels; i++)
    434       {
    435           const UInt_t aidx   = (*fGeom)[i].GetAidx();
    436           const UInt_t sector = (*fGeom)[i].GetSector();
    437 
    438           fAreaValid  [aidx]  ++;
    439           fSectorValid[sector]++;
    440       }
    441   }
    442 
    443   if (fExtractor)
    444   {
    445       if (!((MTask*)fExtractor)->ReInit(pList))
    446           return kFALSE;
    447 
    448       SetExtractWindow(fExtractor->GetHiGainFirst(), (Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples()));
    449   }
    450 
    451   return kTRUE;
     426    // Necessary check for special pixels which might not yet have existed
     427    if (!fRawEvt)
     428    {
     429        if (fRunHeader->GetFormatVersion() > 3)
     430            return kTRUE;
     431
     432        *fLog << err << "ERROR - " << fNameRawEvtData << " [MRawEvtData] has not ";
     433        *fLog << "been found and format version > 3... abort." << endl;
     434        return kFALSE;
     435    }
     436
     437    // If the size is not yet set, set the size
     438    if (fSumx.GetSize()==0)
     439    {
     440        // Initialize the normal pixels (size of MPedestalCam already set by MGeomApply)
     441        const Int_t npixels  = fPedestalsOut->GetSize();
     442
     443        fSumx.  Set(npixels);
     444        fSumx2. Set(npixels);
     445        fSumAB0.Set(npixels);
     446        fSumAB1.Set(npixels);
     447
     448        if (fUseSpecialPixels)
     449        {
     450            // Initialize size of MPedestalCam in case of special pixels (not done by MGeomApply)
     451            const UShort_t nspecial = fRunHeader->GetNumSpecialPixels();
     452            if (nspecial == 0)
     453            {
     454                *fLog << warn << "WARNING - Number of special pixels is 0." << endl;
     455                return kTRUE;
     456            }
     457
     458            fPedestalsOut->InitSize((UInt_t)nspecial);
     459        }
     460        else
     461        {
     462            // Initialize the averaged areas and sectors (do not exist for special pixels)
     463            const Int_t areas    = fPedestalsOut->GetNumAverageArea();
     464            const Int_t sectors  = fPedestalsOut->GetNumAverageSector();
     465
     466            fAreaSumx.  Set(areas);
     467            fAreaSumx2. Set(areas);
     468            fAreaSumAB0.Set(areas);
     469            fAreaSumAB1.Set(areas);
     470            fAreaFilled.Set(areas);
     471            fAreaValid .Set(areas);
     472
     473            fSectorSumx.  Set(sectors);
     474            fSectorSumx2. Set(sectors);
     475            fSectorSumAB0.Set(sectors);
     476            fSectorSumAB1.Set(sectors);
     477            fSectorFilled.Set(sectors);
     478            fSectorValid .Set(sectors);
     479
     480            for (Int_t i=0; i<npixels; i++)
     481            {
     482                const UInt_t aidx   = (*fGeom)[i].GetAidx();
     483                const UInt_t sector = (*fGeom)[i].GetSector();
     484
     485                fAreaValid  [aidx]  ++;
     486                fSectorValid[sector]++;
     487            }
     488        }
     489    }
     490
     491    if (fExtractor)
     492    {
     493        if (!((MTask*)fExtractor)->ReInit(pList))
     494            return kFALSE;
     495
     496        SetExtractWindow(fExtractor->GetHiGainFirst(), (Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples()));
     497    }
     498
     499    return kTRUE;
    452500}
    453501
    454502Int_t MExtractPedestal::PostProcess()
    455503{
    456   fPedestalsIn = NULL;
    457   return fExtractor ? fExtractor->CallPostProcess() : kTRUE;
     504    fPedestalsIn = NULL;
     505    return fExtractor ? fExtractor->CallPostProcess() : kTRUE;
    458506}
    459507
     
    486534    }
    487535
     536    // find resource for fUseSpecialPixels
     537    if (IsEnvDefined(env, prefix, "UseSpecialPixels", print))
     538    {
     539        SetUseSpecialPixels(GetEnvValue(env, prefix, "UseSpecialPixels", fUseSpecialPixels));
     540        rc = kTRUE;
     541    }
     542
    488543    // find resource for numeventsdump
    489544    if (IsEnvDefined(env, prefix, "NumEventsDump", print))
     
    577632void MExtractPedestal::CalcPixResults(const UInt_t nevts, const UInt_t pixid)
    578633{
    579     const Float_t sum  = fSumx[pixid];
    580     const Float_t sum2 = fSumx2[pixid];
     634    const Double_t sum  = fSumx[pixid];
     635    const Double_t sum2 = fSumx2[pixid];
    581636
    582637    // 1. Calculate the mean of the sums:
    583     Float_t ped        = sum/nevts;
     638    Double_t ped = sum/nevts;
    584639
    585640    // 2. Calculate the Variance of the sums:
    586     Float_t var = (sum2-sum*sum/nevts)/(nevts-1.);
     641    Double_t var = (sum2-sum*sum/nevts)/(nevts-1.);
    587642
    588643    // 3. Calculate the amplitude of the 150MHz "AB" noise
    589     Float_t abOffs = (fSumAB0[pixid] - fSumAB1[pixid]) / nevts;
     644    Double_t abOffs = (fSumAB0[pixid] - fSumAB1[pixid]) / nevts;
    590645
    591646    // 4. Scale the mean, variance and AB-noise to the number of slices:
     
    595650
    596651    // 5. Calculate the RMS from the Variance:
    597     const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
     652    const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
    598653
    599654    (*fPedestalsOut)[pixid].Set(ped, rms, abOffs, nevts);
     
    612667void MExtractPedestal::CalcAreaResults(const UInt_t nevts, const UInt_t napix, const UInt_t aidx)
    613668{
    614     const Float_t sum  = fAreaSumx[aidx];
    615     const Float_t sum2 = fAreaSumx2[aidx];
     669    const Double_t sum  = fAreaSumx[aidx];
     670    const Double_t sum2 = fAreaSumx2[aidx];
    616671
    617672    // 1. Calculate the mean of the sums:
    618     Float_t ped        = sum/nevts;
     673    Double_t ped = sum/nevts;
    619674
    620675    // 2. Calculate the Variance of the sums:
    621     Float_t var = (sum2-sum*sum/nevts)/(nevts-1.);
     676    Double_t var = (sum2/napix-sum*sum/nevts)/(nevts-1.);
    622677
    623678    // 3. Calculate the amplitude of the 150MHz "AB" noise
    624     Float_t abOffs = (fAreaSumAB0[aidx] - fAreaSumAB1[aidx]) / nevts;
     679    Double_t abOffs = (fAreaSumAB0[aidx] - fAreaSumAB1[aidx]) / nevts;
    625680
    626681    // 4. Scale the mean, variance and AB-noise to the number of slices:
     
    635690
    636691    // 6. Calculate the RMS from the Variance:
    637     const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
     692    const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
    638693
    639694    fPedestalsOut->GetAverageArea(aidx).Set(ped, rms, abOffs, nevts);
     
    652707void MExtractPedestal::CalcSectorResults(const UInt_t nevts, const UInt_t nspix, const UInt_t sector)
    653708{
    654     const Float_t sum  = fSectorSumx[sector];
    655     const Float_t sum2 = fSectorSumx2[sector];
     709    const Double_t sum  = fSectorSumx[sector];
     710    const Double_t sum2 = fSectorSumx2[sector];
    656711
    657712    // 1. Calculate the mean of the sums:
    658     Float_t ped        = sum/nevts;
     713    Double_t ped        = sum/nevts;
    659714
    660715    // 2. Calculate the Variance of the sums:
    661     Float_t var = (sum2-sum*sum/nevts)/(nevts-1.);
     716    Double_t var = (sum2/nspix-sum*sum/nevts)/(nevts-1.);
    662717
    663718    // 3. Calculate the amplitude of the 150MHz "AB" noise
    664     Float_t abOffs = (fSectorSumAB0[sector] - fSectorSumAB1[sector]) / nevts;
     719    Double_t abOffs = (fSectorSumAB0[sector] - fSectorSumAB1[sector]) / nevts;
    665720
    666721    // 4. Scale the mean, variance and AB-noise to the number of slices:
     
    675730
    676731    // 6. Calculate the RMS from the Variance:
    677     const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
     732    const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
    678733
    679734    fPedestalsOut->GetAverageSector(sector).Set(ped, rms, abOffs, nevts);
     
    688743    *fLog << "Intermediate Storage is       " << (fIntermediateStorage?"on":"off") << endl;
    689744    *fLog << "Pedestal Update is            " << (fPedestalUpdate?"on":"off") << endl;
     745    *fLog << "Special pixel mode            " << (fUseSpecialPixels?"on":"off") << endl;
    690746    if (fPedestalUpdate)
    691747    {
  • trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.h

    r6913 r7188  
    2525private:
    2626  static const TString  fgNamePedestalCam;  //! "MPedestalCam"
     27  static const TString  fgNameRawEvtData;   //! "MRawEvtData"
    2728  static const UInt_t   fgNumDump;          //!
    2829
    2930  TString fNamePedestalCamIn;        // Name of the incoming 'MPedestalCam' container
    3031  TString fNamePedestalCamOut;       // Name of the outgoing 'MPedestalCam' container
    31   TString fNamePedestalCamInter;     // Name of the intermediate 'MPedestalCam' container 
     32  TString fNamePedestalCamInter;     // Name of the intermediate 'MPedestalCam' container
     33  TString fNameRawEvtData;           // Name of MRawEvtData
    3234
    3335  Bool_t  fRandomCalculation;        // Is pedestalextraction by extractor random?
     
    5557 
    5658  Bool_t  fPedestalUpdate;           // Flag if the pedestal shall be updated after every fNumEventsDump
     59  Bool_t  fUseSpecialPixels;         // Flag if the special pixels shall be treated
    5760
    5861  MArrayD fSumx;                     // sum of values
     
    103106
    104107  // names
    105   void SetNamePedestalCamIn   (const char *name=fgNamePedestalCam.Data()) { fNamePedestalCamIn    = name; }
    106   void SetNamePedestalCamInter(const char *name=fgNamePedestalCam.Data()) { fNamePedestalCamInter = name; } 
    107   void SetNamePedestalCamOut  (const char *name=fgNamePedestalCam.Data()) { fNamePedestalCamOut   = name; }
     108  void SetNamePedestalCamIn   (const char *name=fgNamePedestalCam) { fNamePedestalCamIn    = name; }
     109  void SetNamePedestalCamInter(const char *name=fgNamePedestalCam) { fNamePedestalCamInter = name; }
     110  void SetNamePedestalCamOut  (const char *name=fgNamePedestalCam) { fNamePedestalCamOut   = name; }
     111  void SetNameRawEvtData      (const char *name=fgNameRawEvtData)  { fNameRawEvtData       = name; }
    108112
    109113  // pointers
     
    115119  // flags
    116120  void SetIntermediateStorage (Bool_t b=kTRUE) { fIntermediateStorage = b; }
     121  void SetUseSpecialPixels    (Bool_t b=kTRUE) { fUseSpecialPixels    = b; }
    117122  void SetPedestalUpdate      (Bool_t b=kTRUE) { fPedestalUpdate      = b; }
    118123  void SetRandomCalculation   (Bool_t b=kTRUE) { fRandomCalculation   = b; }
  • trunk/MagicSoft/Mars/mpedestal/MMcPedestalCopy.cc

    r3803 r7188  
    7979Bool_t MMcPedestalCopy::CheckRunType(MParList *pList) const
    8080{
    81     const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
     81    const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
    8282    if (!run)
    8383    {
    84         *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
     84      *fLog << warn << dbginf << "Warning - cannot check file type, "
     85            << AddSerialNumber("MRawRunHeader") << " not found." << endl;
    8586        return kTRUE;
    8687    }
     
    138139      }
    139140
    140     MMcRunHeader *mcrun = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
     141    MMcRunHeader *mcrun = (MMcRunHeader*)pList->FindObject(AddSerialNumber("MMcRunHeader"));
    141142    if (!mcrun)
    142         *fLog << warn << dbginf << "MMcRunHeader not found... assuming camera<0.7" << endl;
     143      *fLog << warn << dbginf << AddSerialNumber("MMcRunHeader")
     144            << " not found... assuming camera<0.7" << endl;
    143145
    144146    const int num = pedcam->GetSize();
  • trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc

    r7130 r7188  
    276276 
    277277  //
    278   // In the other case, produce the MPedestalCam to be use the subsequent (non-pedestal) events
     278  // In the other case, produce the MPedestalCam to be use the subsequent
     279  // (non-pedestal) events
    279280  //
    280281  *fLog << inf << "Finalizing pedestal calculations..." << flush;
     
    299300Int_t MPedCalcPedRun::Calc()
    300301{
    301 
    302302  if (fIsNotPedRun && !IsPedBitSet())
    303303    return kTRUE;
     
    317317  while (pixel.Next())
    318318  {
    319       const UInt_t idx    = pixel.GetPixelId();
    320       const UInt_t aidx   = (*fGeom)[idx].GetAidx();
    321       const UInt_t sector = (*fGeom)[idx].GetSector();     
     319      const UInt_t idx = pixel.GetPixelId();
    322320
    323321      Float_t sum = 0.;
     
    330328        CalcSums(pixel, sum, ab0, ab1);
    331329
    332       fSumx[idx]           += sum;
     330      fSumx[idx] += sum;
     331
     332      if (fIntermediateStorage)
     333        (*fPedestalsInter)[idx].Set(sum,0.,0.,fUsedEvents);
     334
     335      const Float_t sqrsum = sum*sum;
     336
     337      fSumx2[idx]  += sqrsum;
     338      fSumAB0[idx] += ab0;
     339      fSumAB1[idx] += ab1;
     340
     341      if (fUseSpecialPixels)
     342        continue;
     343
     344      const UInt_t aidx   = (*fGeom)[idx].GetAidx();
     345      const UInt_t sector = (*fGeom)[idx].GetSector();     
     346
    333347      fAreaSumx[aidx]      += sum;
    334348      fSectorSumx[sector]  += sum;
    335349
    336       if (fIntermediateStorage)
    337         (*fPedestalsInter)[idx].Set(sum,0.,0.,fUsedEvents);
    338 
    339       const Float_t sqrsum   = sum*sum;
    340       fSumx2[idx]           += sqrsum;
    341       fAreaSumx2[aidx]      += sqrsum;
    342       fSectorSumx2[sector]  += sqrsum;
    343 
    344       fSumAB0[idx]         += ab0;
    345       fSumAB1[idx]         += ab1;
     350      fAreaSumx2[aidx]     += sqrsum;
     351      fSectorSumx2[sector] += sqrsum;
    346352
    347353      fAreaSumAB0[aidx]    += ab0;
     
    422428}
    423429
    424 
    425430// --------------------------------------------------------------------------
    426431//
     
    429434Int_t MPedCalcPedRun::Finalize()
    430435{
    431 
    432   if (fUsedEvents == 0)
     436    if (fUsedEvents == 0)
     437        return kTRUE;
     438
     439    //
     440    // Necessary check for extraction of special pixels
     441    // together with data which does not yet have them
     442    //
     443    if (fSumx.GetSize()==0)
     444        return kTRUE;
     445
     446    MRawEvtPixelIter pixel(fRawEvt);
     447    while (pixel.Next())
     448        CalcPixResults(fUsedEvents, pixel.GetPixelId());
     449
     450    if (!fUseSpecialPixels)
     451    {
     452
     453        //
     454        // Loop over the (two) area indices to get the averaged pedestal per aidx
     455        //
     456        for (UInt_t aidx=0; aidx<fAreaValid.GetSize(); aidx++)
     457            if (fAreaValid[aidx]>0)
     458                CalcAreaResults(fUsedEvents, fAreaValid[aidx], aidx);
     459
     460        //
     461        // Loop over the (six) sector indices to get the averaged pedestal per sector
     462        //
     463        for (UInt_t sector=0; sector<fSectorValid.GetSize(); sector++)
     464            if (fSectorValid[sector]>0)
     465                CalcSectorResults(fUsedEvents, fSectorValid[sector], sector);
     466    }
     467
     468    fPedestalsOut->SetTotalEntries(fUsedEvents*fExtractWinSize);
     469    fPedestalsOut->SetReadyToSave();
     470
    433471    return kTRUE;
    434  
    435   MRawEvtPixelIter pixel(fRawEvt);
    436   while (pixel.Next())
    437     CalcPixResults(fUsedEvents, pixel.GetPixelId());
    438  
    439   //
    440   // Loop over the (two) area indices to get the averaged pedestal per aidx
    441   //
    442   for (UInt_t aidx=0; aidx<fAreaValid.GetSize(); aidx++)
    443     if (fAreaValid[aidx]>0)
    444       CalcAreaResults(fUsedEvents, fAreaValid[aidx], aidx);
    445  
    446   //
    447   // Loop over the (six) sector indices to get the averaged pedestal per sector
    448   //
    449   for (UInt_t sector=0; sector<fSectorValid.GetSize(); sector++)
    450     if (fSectorValid[sector]>0)
    451       CalcSectorResults(fUsedEvents, fSectorValid[sector], sector);
    452  
    453   fPedestalsOut->SetTotalEntries(fUsedEvents*fExtractWinSize);
    454   fPedestalsOut->SetReadyToSave();
    455  
    456   return kTRUE;
    457472}
    458473
    459474Int_t MPedCalcPedRun::PostProcess()
    460475{
    461   if (!Finalize())
    462     return kFALSE;
    463  
    464   return MExtractPedestal::PostProcess();
     476    if (!fRawEvt)
     477        return kTRUE;
     478
     479    if (!Finalize())
     480        return kFALSE;
     481
     482    return MExtractPedestal::PostProcess();
    465483}
    466484
     
    485503void MPedCalcPedRun::Print(Option_t *o) const
    486504{
    487 
    488505    MExtractPedestal::Print(o);
    489506
  • trunk/MagicSoft/Mars/mpedestal/MPedestalCam.cc

    r5558 r7188  
    276276}
    277277
     278void MPedestalCam::PrintArr(const TCollection &list) const
     279{
     280    Int_t id = 0;
     281
     282    TIter Next(&list);
     283    MPedestalPix *pix = 0;
     284
     285    while ((pix=(MPedestalPix*)Next()))
     286        *fLog << Form("Nr.: %4i  Pedestal: %5.2f    RMS: %5.2f    ABOffset: %5.2f ",
     287                      id++, pix->GetPedestal(), pix->GetPedestalRms(), pix->GetPedestalABoffset()) << endl;
     288}
     289
    278290void MPedestalCam::Print(Option_t *o) const
    279291{
    280292    *fLog << all << GetDescriptor() << ":" << endl;
    281     int id = 0;
    282 
    283     TIter Next(fArray);
    284     MPedestalPix *pix;
    285     while ((pix=(MPedestalPix*)Next()))
    286     {
    287         id++;
    288 
    289         if (!pix->IsValid())
    290             continue;
    291 
    292         *fLog << id-1 << ": ";
    293         *fLog << pix->GetPedestal() << " " << pix->GetPedestalRms() << endl;
    294     }
     293    *fLog << "Pixels:" << endl;   
     294    *fLog << endl;
     295
     296    PrintArr(*fArray);
     297
     298    *fLog << endl;
     299    *fLog << "Event-by-event averaged areas:" << endl;   
     300    *fLog << endl;
     301
     302    PrintArr(*fAverageAreas);
     303
     304    *fLog << endl;
     305    *fLog << "Event-by-event averaged sectors:" << endl;
     306    *fLog << endl;
     307
     308    PrintArr(*fAverageSectors);
    295309}
    296310
  • trunk/MagicSoft/Mars/mpedestal/MPedestalCam.h

    r5558 r7188  
    2424
    2525  UInt_t fTotalEntries;  // Total number of times, the Process was executed (to estimate the error of pedestal)
     26
     27  void PrintArr(const TCollection &list) const;
    2628
    2729public:
Note: See TracChangeset for help on using the changeset viewer.