Ignore:
Timestamp:
11/29/04 19:03:54 (20 years ago)
Author:
gaug
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mjobs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mjobs/MJPedestal.cc

    r5428 r5506  
    3131#include "MJPedestal.h"
    3232
     33#include "MLog.h"
     34#include "MLogManip.h"
     35
     36#include "MTaskEnv.h"
     37#include "MSequence.h"
     38#include "MRunIter.h"
     39#include "MParList.h"
     40#include "MTaskList.h"
     41#include "MEvtLoop.h"
     42#include "MExtractor.h"
     43
     44#include "MStatusDisplay.h"
     45
     46#include "MGeomCam.h"
     47#include "MHCamera.h"
     48#include "MPedestalCam.h"
     49#include "MPedestalPix.h"
     50#include "MBadPixelsCam.h"
     51
     52#include "MCalibrationPedCam.h"
     53#include "MCalibrationPix.h"
     54#include "MHPedestalCam.h"
     55#include "MHPedestalPix.h"
     56#include "MFillH.h"
     57
     58
     59#include "MReadMarsFile.h"
     60#include "MRawFileRead.h"
     61#include "MGeomApply.h"
     62#include "MBadPixelsMerge.h"
     63#include "MPedCalcPedRun.h"
     64#include "MPedCalcFromLoGain.h"
     65
    3366#include <TF1.h>
    3467#include <TEnv.h>
     
    4073#include <TSystem.h>
    4174#include <TLegend.h>
    42 
    43 #include "MLog.h"
    44 #include "MLogManip.h"
    45 
    46 #include "MTaskEnv.h"
    47 #include "MSequence.h"
    48 #include "MRunIter.h"
    49 #include "MParList.h"
    50 #include "MTaskList.h"
    51 #include "MEvtLoop.h"
    52 #include "MExtractor.h"
    53 
    54 #include "MStatusDisplay.h"
    55 
    56 #include "MGeomCam.h"
    57 #include "MHCamera.h"
    58 #include "MPedestalCam.h"
    59 #include "MBadPixelsCam.h"
    60 
    61 #include "MReadMarsFile.h"
    62 #include "MRawFileRead.h"
    63 #include "MGeomApply.h"
    64 #include "MBadPixelsMerge.h"
    65 #include "MPedCalcPedRun.h"
    66 #include "MPedCalcFromLoGain.h"
     75#include <TPad.h>
    6776
    6877ClassImp(MJPedestal);
     
    8594const Float_t  MJPedestal::fgRefPedRmsGalacticOuter      = 4.2;
    8695
     96const TString  MJPedestal::fgNameExtractorCam = "ExtractorResolution";
    8797// --------------------------------------------------------------------------
    8898//
     
    95105// - fExtractType to kUsePedRun
    96106// - fStorage to Normal Storage
     107// - fExtractorResolution to kFALSE
     108// - fNameExtractorCam to "ExtractorResolution"
    97109//
    98110MJPedestal::MJPedestal(const char *name, const char *title)
     
    105117    SetNormalStorage();
    106118    SetUsePedRun();
     119    SetPathIn("");
     120    SetExtractorResolution(kFALSE);
     121    SetNameExtractorCam();
    107122}
    108123
     
    142157
    143158    TFile file(fname, "READ");
    144     if (fPedestalCam.Read()<=0)
    145     {
    146         *fLog << err << "Unable to read MPedestalCam from " << fname << endl;
     159    if (fPedestalCamIn.Read()<=0)
     160    {
     161        *fLog << err << "Unable to read incoming MPedestalCam from " << fname << endl;
     162        return kFALSE;
     163    }
     164
     165    if (fPedestalCamOut.Read()<=0)
     166    {
     167        *fLog << err << "Unable to read outgoing MPedestalCam from " << fname << endl;
    147168        return kFALSE;
    148169    }
     
    167188MExtractor *MJPedestal::ReadCalibration() const
    168189{
    169     const TString fname = Form("%s/calib%06d.root", fPathIn.Data(), fSequence.GetSequence());
     190    const TString fname = Form("%s/calib%06d.root",fPathIn.Data(), fSequence.GetSequence());
    170191
    171192    *fLog << inf << "Reading from file: " << fname << endl;
     
    213234    // Get container from list
    214235    //
    215     MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
     236    MGeomCam           &geomcam   = *(MGeomCam*)plist.FindObject("MGeomCam");
     237    MCalibrationPedCam &calpedcam = *(MCalibrationPedCam*)plist.FindObject("MCalibrationPedCam");
    216238
    217239    //
    218240    // Create container to display
    219241    //
    220     MHCamera disp0(geomcam, "MPedestalCam;ped", "Mean Pedestal");
    221     MHCamera disp1(geomcam, "MPedestalCam;RMS", "Pedestal RMS");
    222 
    223     disp0.SetCamContent(fPedestalCam, 0);
    224     disp0.SetCamError  (fPedestalCam, 1);
    225 
    226     disp1.SetCamContent(fPedestalCam, 2);
    227     disp1.SetCamError  (fPedestalCam, 3);
     242    MHCamera disp0 (geomcam, "MPedestalCam;ped", "Mean Pedestal");
     243    MHCamera disp1 (geomcam, "MPedestalCam;RMS", "Pedestal RMS");
     244    MHCamera disp2 (geomcam, "MCalibPedCam;histmean", "Mean Pedestal (Hist.)");
     245    MHCamera disp3 (geomcam, "MCalibPedCam;histsigma", "Pedestal RMS (Hist.)");
     246    MHCamera disp4 (geomcam, "MCalibPedCam;ped", "Mean Pedestal");
     247    MHCamera disp5 (geomcam, "MCalibPedCam;RMS", "Pedestal RMS");
     248    MHCamera disp6 (geomcam, "MCalibDiffCam;ped", "Diff. Mean Pedestal (Hist.)");
     249    MHCamera disp7 (geomcam, "MCalibDiffCam;RMS", "Diff. Pedestal RMS (Hist.)");
     250    MHCamera disp8 (geomcam, "MCalibDiffCam;ped", "Diff. Mean Pedestal");
     251    MHCamera disp9 (geomcam, "MCalibDiffCam;AbsRMS", "Diff. Abs. Pedestal RMS");
     252    MHCamera disp10(geomcam, "MCalibDiffCam;RelRMS", "Diff. Rel. Pedestal RMS");
     253
     254    disp0.SetCamContent(fPedestalCamOut, 0);
     255    disp0.SetCamError  (fPedestalCamOut, 1);
     256
     257    disp1.SetCamContent(fPedestalCamOut, 2);
     258    disp1.SetCamError  (fPedestalCamOut, 3);
     259
     260    if (fExtractType == kUseHists)
     261      {
     262        disp2.SetCamContent(calpedcam, 0);
     263        disp2.SetCamError  (calpedcam, 1);
     264
     265        disp3.SetCamContent(calpedcam, 2);
     266        disp3.SetCamError  (calpedcam, 3);
     267
     268        disp4.SetCamContent(calpedcam, 5);
     269        disp4.SetCamError  (calpedcam, 6);
     270
     271        disp5.SetCamContent(calpedcam, 7);
     272        disp5.SetCamError  (calpedcam, 8);
     273
     274        for (UInt_t i=0;i<geomcam.GetNumPixels();i++)
     275          {
     276
     277            MPedestalPix    &ped  = fPedestalCamOut[i];
     278            MCalibrationPix &hist = calpedcam [i];
     279            MBadPixelsPix &bad  = fBadPixels[i];
     280
     281            if (bad.IsUnsuitable())
     282              continue;
     283
     284            disp6.Fill(i,ped.GetPedestal()-hist.GetHiGainMean());
     285            disp6.SetUsed(i);
     286
     287            disp7.Fill(i,hist.GetHiGainSigma()-ped.GetPedestalRms());
     288            if (TMath::Abs(ped.GetPedestalRms()-hist.GetHiGainSigma()) < 4.0)
     289              disp7.SetUsed(i);
     290
     291            disp8.Fill(i,ped.GetPedestal()-hist.GetLoGainMean());
     292            disp8.SetUsed(i);
     293
     294            disp9.Fill(i,hist.GetLoGainSigma()-ped.GetPedestalRms());
     295            if (TMath::Abs(hist.GetLoGainSigma() - ped.GetPedestalRms()) < 4.0)
     296              disp9.SetUsed(i);
     297          }
     298      }
     299   
     300    if (fExtractorResolution)
     301      {
     302        for (UInt_t i=0;i<geomcam.GetNumPixels();i++)
     303          {
     304
     305            MPedestalPix &pedo  = fPedestalCamOut[i];
     306            MPedestalPix &pedi  = fPedestalCamIn[i];
     307            MBadPixelsPix &bad  = fBadPixels[i];
     308
     309            if (bad.IsUnsuitable())
     310              continue;
     311
     312            const Float_t diff = pedo.GetPedestalRms()-pedi.GetPedestalRms();
     313            const Float_t sum  = 0.5*(pedo.GetPedestalRms()+pedi.GetPedestalRms());
     314
     315            disp9.Fill(i,pedo.GetPedestalRms()-pedi.GetPedestalRms());
     316            if (pedo.IsValid() && pedi.IsValid())
     317              disp9.SetUsed(i);
     318
     319            disp10.Fill(i,sum == 0. ? 0. : diff/sum);
     320            if (pedo.IsValid() && pedi.IsValid() && sum != 0.)
     321              disp10.SetUsed(i);
     322          }
     323      }
    228324
    229325    disp0.SetYTitle("Pedestal [counts/slice]");
    230326    disp1.SetYTitle("RMS [counts/slice]");
     327    disp2.SetYTitle("Hist. Mean  [counts/slice]");
     328    disp3.SetYTitle("Hist. Sigma [counts/slice]");
     329    disp4.SetYTitle("Calc. Mean  [counts/slice]");
     330    disp5.SetYTitle("Calc. RMS   [counts/slice]");
     331    disp6.SetYTitle("Diff. Mean  [counts/slice]");
     332    disp7.SetYTitle("Diff. RMS   [counts/slice]");
     333    disp8.SetYTitle("Diff. Mean  [counts/slice]");
     334    disp9.SetYTitle("Abs. Diff. RMS   [counts/slice]");
     335    disp10.SetYTitle("Rel. Diff. RMS   [1]");
    231336
    232337    //
    233338    // Display data
    234339    //
    235     TCanvas &c3 = fDisplay->AddTab("Pedestals");
    236     c3.Divide(2,3);
    237 
    238     if (fDisplayType != kDataCheckDisplay)
    239     {
     340    if (fDisplayType != kDataCheckDisplay && fExtractType != kUseHists && !fExtractorResolution)
     341    {
     342      TCanvas &c3 = fDisplay->AddTab("Pedestals");
     343      c3.Divide(2,3);
     344
     345      disp0.CamDraw(c3, 1, 2, 1);
     346      disp1.CamDraw(c3, 2, 2, 6);
     347      return;
     348    }
     349
     350    if (fExtractorResolution)
     351      {
     352
     353        TCanvas &c3 = fDisplay->AddTab("Extr.Res.");
     354        c3.Divide(2,3);
     355       
    240356        disp0.CamDraw(c3, 1, 2, 1);
    241357        disp1.CamDraw(c3, 2, 2, 6);
     358
     359        TCanvas &c13 = fDisplay->AddTab("Diff.(Extr.-Pedestal)");
     360        c13.Divide(2,3);
     361       
     362        disp9.CamDraw(c13, 1, 2, 5);
     363        disp10.CamDraw(c13, 2, 2, 5);
    242364        return;
    243     }
     365      }
     366
     367    if (fExtractType == kUseHists)
     368      {
     369
     370        TCanvas &c3 = fDisplay->AddTab("Extractor Hist.");
     371        c3.Divide(2,3);
     372
     373        disp2.CamDraw(c3, 1, 2, 1);
     374        disp3.CamDraw(c3, 2, 2, 5);
     375
     376        TCanvas &c4 = fDisplay->AddTab("Extractor Calc.");
     377        c4.Divide(2,3);
     378       
     379        disp4.CamDraw(c4, 1, 2, 1);
     380        disp5.CamDraw(c4, 2, 2, 5);
     381
     382
     383        TCanvas &c5 = fDisplay->AddTab("Difference Hist.");
     384        c5.Divide(2,3);
     385       
     386        disp6.CamDraw(c5, 1, 2, 1);
     387        disp7.CamDraw(c5, 2, 2, 5);
     388
     389        TCanvas &c6 = fDisplay->AddTab("Difference Calc.");
     390        c6.Divide(2,3);
     391       
     392        disp8.CamDraw(c6, 1, 2, 1);
     393        disp9.CamDraw(c6, 2, 2, 5);
     394        return;
     395      }
     396
     397    TCanvas &c3 = fDisplay->AddTab(fExtractorResolution ? "Extr.Res." : "Pedestals");
     398    c3.Divide(2,3);
    244399
    245400    c3.cd(1);
     
    386541            }
    387542            leg2->Draw();
     543            delete leg2;
    388544        }
    389     }
    390 }
     545
     546    }
     547
     548}
     549
    391550
    392551void  MJPedestal::DisplayReferenceLines(MHCamera *cam, const Int_t what) const
     
    440599  leg->AddEntry(l3, "Closed Lids","l");
    441600  leg->Draw();
     601  delete leg;
    442602}
    443603
     
    525685Bool_t MJPedestal::CheckEnvLocal()
    526686{
    527     SetDataCheck(GetEnv("DataCheck", fDataCheck));
    528 
    529     if (HasEnv("DataCheckDisplay"))
    530         fDisplayType = GetEnv("DataCheckDisplay", kFALSE) ? kDataCheckDisplay : kNormalDisplay;
    531 
    532     if (HasEnv("UseData"))
    533         fExtractType = GetEnv("UseData",kFALSE) ? kUseData : kUsePedRun;
    534 
    535     if (HasEnv("UseExtractor"))
    536         if (GetEnv("UseExtractor",kFALSE))
    537             fExtractType = kUseExtractor;
    538 
    539     SetNoStorage(GetEnv("DisableOutput", IsNoStorage()));
    540 
    541     return kTRUE;
     687
     688  SetDataCheck(GetEnv("DataCheck", fDataCheck));
     689 
     690  if (HasEnv("DataCheckDisplay"))
     691    fDisplayType = GetEnv("DataCheckDisplay", kFALSE) ? kDataCheckDisplay : kNormalDisplay;
     692 
     693  if (HasEnv("UseData"))
     694    fExtractType = GetEnv("UseData",kFALSE) ? kUseData : kUsePedRun;
     695 
     696  if (HasEnv("UseHists"))
     697    if (GetEnv("UseHists",kFALSE))
     698      fExtractType = kUseHists;
     699
     700  SetExtractorResolution(GetEnv("ExtractorResolution", fExtractorResolution));
     701  SetNameExtractorCam(GetEnv("NameExtractorCam", fNameExtractorCam));
     702 
     703  SetNoStorage(GetEnv("DisableOutput", IsNoStorage()));
     704 
     705  return kTRUE;
    542706}
    543707
     
    575739    }
    576740
    577     if (fPedestalCam.Write()<=0)
     741    if (fPedestalCamOut.Write()<=0)
    578742    {
    579743        *fLog << err << "Unable to write MPedestalCam to " << oname << endl;
     
    677841
    678842    // Setup Tasklist
    679     plist.AddToList(&fPedestalCam);
     843    plist.AddToList(&fPedestalCamOut);
    680844    plist.AddToList(&fBadPixels);
    681 
     845   
    682846    MGeomApply      geomapl;
    683847    MBadPixelsMerge merge(&fBadPixels);
    684848
    685849    MPedCalcPedRun     pedcalc;
     850    pedcalc.SetPedestalUpdate(kFALSE);
    686851    MPedCalcFromLoGain pedlogain;
     852    pedlogain.SetPedestalUpdate(kFALSE);
     853
     854    MHPedestalCam      hpedcam;
     855    hpedcam.SetRenorm(kTRUE);
     856   
     857    MFillH fillped(&hpedcam, "MExtractedSignalCam");
     858    fillped.SetBit(MFillH::kDoNotDisplay);
     859
     860    tlist.AddToList(&geomapl);
     861    tlist.AddToList(&merge);
    687862
    688863    if (!fPathIn.IsNull())
     
    702877    {
    703878    case kUseData:
    704         taskenv.SetDefault(&pedlogain);
    705         if (!fExtractor)
    706             break;
     879      taskenv.SetDefault(&pedlogain);
     880      if (!fExtractor)
     881        break;
     882      tlist.AddToList(&taskenv);
     883      if (fExtractorResolution && fExtractor->InheritsFrom("MExtractTimeAndCharge"))
     884        {
     885          plist.AddToList(&fPedestalCamIn);
     886          fPedestalCamOut.SetName(fNameExtractorCam.Data());
     887          pedlogain.SetNamePedestalCamOut(fNameExtractorCam.Data());
     888          pedlogain.SetExtractor((MExtractTimeAndCharge*)fExtractor);
     889        }
     890      else
    707891        pedlogain.SetExtractWindow(15, (Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples()));
    708         pedlogain.SetPedestalUpdate(kFALSE);
     892      break;
     893
     894    case kUsePedRun:
     895      taskenv.SetDefault(&pedcalc);
     896      if (!fExtractor)
    709897        break;
    710 
    711     case kUsePedRun:
    712         taskenv.SetDefault(&pedcalc);
    713         if (!fExtractor)
    714             break;
    715         pedcalc.SetWindowSize((Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples()));
    716         pedcalc.SetRange(fExtractor->GetHiGainFirst(), fExtractor->GetHiGainLast());
    717         break;
    718 
    719     case kUseExtractor:
    720         if (!fExtractor)
     898      tlist.AddToList(&taskenv);
     899      if (fExtractorResolution && fExtractor->InheritsFrom("MExtractTimeAndCharge"))
    721900        {
    722             *fLog << err << GetDescriptor();
    723             *fLog << "Extraction Type kUseExtractor is chosen, but no extractor has been handed over" << endl;
    724             return kFALSE;
     901          plist.AddToList(&fPedestalCamIn);
     902          fPedestalCamOut.SetName(fNameExtractorCam.Data());
     903          pedcalc.SetNamePedestalCamOut(fNameExtractorCam.Data());
     904          pedcalc.SetExtractor((MExtractTimeAndCharge*)fExtractor);
    725905        }
    726         taskenv.SetDefault(fExtractor);
    727         if (fExtractor->IsNoiseCalculation())
    728             break;
    729 
     906      else
     907        pedcalc.SetExtractWindow(fExtractor->GetHiGainFirst(),TMath::Nint(fExtractor->GetNumHiGainSamples()));
     908      break;
     909     
     910    case kUseHists:
     911      if (!fExtractor)
     912        {
     913          *fLog << err << GetDescriptor();
     914          *fLog << ": Extraction Type kUseExtractor is chosen, but no extractor has been handed over"
     915                << endl;
     916          return kFALSE;
     917        }
     918     
     919      plist.AddToList(&hpedcam);
     920      tlist.AddToList(fExtractor);
     921      tlist.AddToList(&fillped);
     922
     923      break;
     924    }
     925
     926    //
     927    // Check that the extractor has the bit Noise Calculation() set which
     928    // means that the each "sliding" of the sliding window is not applied
     929    //
     930    if (fExtractorResolution && !fExtractor->IsNoiseCalculation())
     931      {
    730932        *fLog << warn << GetDescriptor();
    731         *fLog <<"Extraction type is kUseExtractor, but extractor has kNoiseCalculation not set... set." << endl;
     933        *fLog <<": Extraction type is kUseExtractor, but extractor has kNoiseCalculation not set... set."
     934              << endl;
    732935        fExtractor->SetNoiseCalculation();
    733         return kFALSE;
    734     }
    735 
     936      }
     937   
    736938    if (!fPathIn.IsNull())
    737939    {
    738         delete fExtractor;
    739         fExtractor = 0;
    740     }
    741 
    742     tlist.AddToList(&geomapl);
    743     tlist.AddToList(&merge);
    744     tlist.AddToList(&taskenv);
     940      delete fExtractor;
     941      fExtractor = 0;
     942    }
    745943
    746944    //
  • trunk/MagicSoft/Mars/mjobs/MJPedestal.h

    r5387 r5506  
    4141  static const Float_t  fgRefPedRmsGalacticOuter;      //! Ref. line ped. RMS for galactic source - outer pixels     
    4242   
     43  static const TString  fgNameExtractorCam;            //! "ExtractorResolution"
     44
    4345  MRunIter   *fRuns;                                   // Used pedestal runs
    4446  MExtractor *fExtractor;                              // Signal extractor, used to find the nr. of used FADC slices
    4547 
    46   MPedestalCam  fPedestalCam;                          // Created pedestal results
     48  MPedestalCam  fPedestalCamIn;                        // Handed over pedestal results
     49  MPedestalCam  fPedestalCamOut;                       // Created pedestal results
    4750  MBadPixelsCam fBadPixels;                            // Bad Pixels
     51
     52  TString fNameExtractorCam;                           // Name of the outgoing MPedestalCam if fExtractorResolution
    4853 
    4954  enum Display_t {kDataCheckDisplay, kNormalDisplay};  // Possible Display types
     
    5560  Bool_t fDataCheck;                                   // Flag if the data check is run on raw data
    5661
    57   enum Extract_t {kUseData, kUsePedRun, kUseExtractor}; // Possible flags for the extraction of the pedestal
     62  enum Extract_t {kUseData, kUsePedRun, kUseHists };  // Possible flags for the extraction of the pedestal
    5863  Extract_t fExtractType;                              // Chosen extractor type
     64
     65  Bool_t fExtractorResolution;                         // Flag if the extractor is used to calculate the pedestals
    5966 
    6067  MExtractor *ReadCalibration() const;
     
    7683  MJPedestal(const char *name=NULL, const char *title=NULL);
    7784
    78   MPedestalCam &GetPedestalCam()            { return fPedestalCam; }
     85  MPedestalCam &GetPedestalCam()            { return fPedestalCamOut; }
    7986  const MBadPixelsCam &GetBadPixels() const { return fBadPixels;   }
    8087 
     
    8289  const Bool_t IsDataCheck()    const { return fDataCheck; }
    8390  const Bool_t IsUseData()      const { return fExtractType == kUseData;   }
    84   const Bool_t IsUseExtractor() const { return fExtractType == kUseExtractor;   }
    85   const Bool_t IsUsePedRun()    const { return fExtractType == kUsePedRun;   }
    8691 
    8792  Bool_t Process    ();
     
    8994 
    9095  void SetBadPixels(const MBadPixelsCam &bad) { bad.Copy(fBadPixels); }
     96  void SetPedestals(const MPedestalCam  &ped) { ped.Copy(fPedestalCamIn); } 
    9197  void SetExtractor(MExtractor* ext)          { fExtractor = ext;     }
    9298  void SetInput(MRunIter  *iter)              { fRuns      = iter;    }
    93   void SetUseData()                           { fExtractType = kUseData;      }
    94   void SetUseExtractor()                      { fExtractType = kUseExtractor; }
    95   void SetUsePedRun()                         { fExtractType = kUsePedRun;    }
     99  void SetUseData()                           { fExtractType = kUseData;   }
     100  void SetUseHists()                          { fExtractType = kUseHists; }
     101  void SetUsePedRun()                         { fExtractType = kUsePedRun; }
    96102  void SetDataCheck(const Bool_t b=kTRUE)     { fDataCheck = b; b ? SetDataCheckDisplay() : SetNormalDisplay(); }
    97103  void SetDataCheckDisplay()                  { fDisplayType = kDataCheckDisplay; }
    98104  void SetNormalDisplay()                     { fDisplayType = kNormalDisplay;    }
     105  void SetExtractorResolution(const Bool_t b=kTRUE) { fExtractorResolution = b;  }
     106  void SetNameExtractorCam( const char* name= fgNameExtractorCam.Data())  { fNameExtractorCam = name;  }
    99107 
    100   void SetPedContainerName(const char *name)  { fPedestalCam.SetName(name); }
    101108 
    102109  // Storage
Note: See TracChangeset for help on using the changeset viewer.