Ignore:
Timestamp:
09/09/04 17:51:57 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mhist/MHEffectiveOnTime.cc

    r4889 r4906  
    6363//
    6464MHEffectiveOnTime::MHEffectiveOnTime(const char *name, const char *title)
    65     : fPointPos(0), fTime(0), fParam(0), fIsFinalized(kFALSE), fInterval(60)
     65    : fPointPos(0), fTime(0), fParam(0), fIsFinalized(kFALSE), fInterval(60),
     66    fNameProjDeltaT(Form("DeltaT_%p", this)), fNameProjTheta(Form("Theta_%p", this))
    6667{
    6768    //
     
    7273
    7374    // Main histogram
    74     fHTimeDiff.SetXTitle("\\Delta t [s]");
    75     fHTimeDiff.SetYTitle("\\Theta [\\circ]");
    76     fHTimeDiff.UseCurrentStyle();
    77     fHTimeDiff.SetDirectory(NULL);
     75    fHDeltaT.SetName("DeltaT");
     76    fHDeltaT.SetXTitle("\\Delta t [s]");
     77    fHDeltaT.SetYTitle("\\Theta [\\circ]");
     78    fHDeltaT.UseCurrentStyle();
     79    fHDeltaT.SetDirectory(NULL);
    7880
    7981    // effective on time versus theta
    80     fHEffOn.SetName("EffOnTime");
    81     fHEffOn.SetTitle("Effective On Time T_{eff}");
    82     fHEffOn.SetXTitle("\\Theta [\\circ]");
    83     fHEffOn.SetYTitle("T_{eff} [s]");
    84     fHEffOn.UseCurrentStyle();
    85     fHEffOn.SetDirectory(NULL);
    86     fHEffOn.GetYaxis()->SetTitleOffset(1.2);
     82    fHEffOnTheta.SetName("EffOnTime");
     83    fHEffOnTheta.SetTitle("Effective On Time T_{eff}");
     84    fHEffOnTheta.SetXTitle("\\Theta [\\circ]");
     85    fHEffOnTheta.SetYTitle("T_{eff} [s]");
     86    fHEffOnTheta.UseCurrentStyle();
     87    fHEffOnTheta.SetDirectory(NULL);
     88    fHEffOnTheta.GetYaxis()->SetTitleOffset(1.2);
    8789    //fHEffOn.Sumw2();
     90
     91    // effective on time versus time
     92    fHEffOnTime.SetName("EffOnTime");
     93    fHEffOnTime.SetTitle("Effective On Time T_{eff}");
     94    fHEffOnTime.SetXTitle("Time");
     95    fHEffOnTime.SetYTitle("T_{eff} [s]");
     96    fHEffOnTime.UseCurrentStyle();
     97    fHEffOnTime.SetDirectory(NULL);
     98    fHEffOnTime.GetYaxis()->SetTitleOffset(1.2);
     99    fHEffOnTime.GetXaxis()->SetLabelSize(0.033);
     100    fHEffOnTime.GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
     101    fHEffOnTime.GetXaxis()->SetTimeDisplay(1);
     102    fHEffOnTime.Sumw2();
    88103
    89104    // chi2/NDF versus theta
     
    128143    // setup binning
    129144    MBinning btheta("BinningTheta");
    130     btheta.SetEdgesCos(51, 0, 60);
    131 
    132     MBinning btime("BinningTimeDiff");
     145    btheta.SetEdgesCos(101, 0, 60);
     146
     147    MBinning btime("BinningDeltaT");
    133148    btime.SetEdges(50, 0, 0.1);
    134149
    135     MH::SetBinning(&fHTimeDiff, &btime, &btheta);
    136 
    137     btheta.Apply(fHEffOn);
     150    MH::SetBinning(&fHDeltaT, &btime, &btheta);
     151
     152    btheta.Apply(fHEffOnTheta);
    138153    btheta.Apply(fHChi2);
    139154    btheta.Apply(fHLambda);
     
    141156    btheta.Apply(fHProb);
    142157}
    143 
    144 // FIXME: Just for a preliminary check
    145 static Double_t testval = 0;
    146 static Double_t testerr = 0;
    147158
    148159// --------------------------------------------------------------------------
     
    167178       return kFALSE;
    168179
    169    const MBinning* binsdtime = (MBinning*)plist->FindObject("BinningTimeDiff");
     180   const MBinning* binsdtime = (MBinning*)plist->FindObject("BinningDeltaT");
    170181   const MBinning* binstheta = (MBinning*)plist->FindObject("BinningTheta");
    171182   if (!binstheta || !binsdtime)
     
    173184   else
    174185   {
    175        SetBinning(&fHTimeDiff, binsdtime, binstheta);
    176 
    177        binstheta->Apply(fHEffOn);
     186       SetBinning(&fHDeltaT, binsdtime, binstheta);
     187
     188       binstheta->Apply(fHEffOnTheta);
    178189       binstheta->Apply(fHChi2);
    179190       binstheta->Apply(fHLambda);
     
    200211
    201212    // nbins = number of Theta bins
    202     const Int_t nbins = fHTimeDiff.GetNbinsY();
     213    const Int_t nbins = fHDeltaT.GetNbinsY();
    203214
    204215    TH1D *h=0;
     
    206217    {
    207218        //        TH1D &h = *hist->ProjectionX("Calc-theta", i, i);
    208         h = fHTimeDiff.ProjectionX(name, i, i, "E");
     219        h = fHDeltaT.ProjectionX(name, i, i, "E");
    209220
    210221        Double_t res[7];
     
    213224
    214225        // the effective on time is Nm/lambda
    215         fHEffOn.SetBinContent(i, res[0]);
    216         fHEffOn.SetBinError  (i, res[1]);
     226        fHEffOnTheta.SetBinContent(i, res[0]);
     227        fHEffOnTheta.SetBinError  (i, res[1]);
    217228
    218229        // plot chi2-probability of fit
     
    346357        TH1D *h0=0;
    347358
    348         padsave->cd(1);
    349         if ((h0 = (TH1D*)gPad->FindObject("TimeDiff")))
     359        padsave->GetPad(1)->cd(1);
     360        if ((h0 = (TH1D*)gPad->FindObject(fNameProjDeltaT)))
    350361        {
    351             h0 = fHTimeDiff.ProjectionX("TimeDiff", -1, 9999, "E");
     362            h0 = fHDeltaT.ProjectionX(fNameProjDeltaT, -1, 9999, "E");
    352363            if (h0->GetEntries()>0)
    353364                gPad->SetLogy();
    354365        }
    355366
    356         padsave->cd(2);
    357         if ((h0 = (TH1D*)gPad->FindObject("Theta")))
    358             fHTimeDiff.ProjectionY("Theta", -1, 9999, "E");
     367        padsave->GetPad(2)->cd(1);
     368        if ((h0 = (TH1D*)gPad->FindObject(fNameProjTheta)))
     369            fHDeltaT.ProjectionY(fNameProjTheta, -1, 9999, "E");
    359370
    360371        if (!fIsFinalized)
    361372            FitThetaBins();
    362373    }
    363     if (o==(TString)"paint")
     374
     375    TH1D *h=0;
     376    if (o==(TString)"theta")
     377        h = &fHEffOnTheta;
     378    if (o==(TString)"time")
     379        h = &fHEffOnTime;
     380
     381    if (h)
    364382    {
    365383        Double_t error = 0;
    366         for (int i=0; i<fHEffOn.GetXaxis()->GetNbins(); i++)
    367             error += fHEffOn.GetBinError(i);
    368 
    369         TLatex text(0.45, 0.94, Form("T_{eff} = %.1fs \\pm %.1fs", fHEffOn.Integral(), error));
     384        for (int i=0; i<h->GetXaxis()->GetNbins(); i++)
     385            error += h->GetBinError(i);
     386
     387        TLatex text(0.45, 0.94, Form("T_{eff} = %.1fs \\pm %.1fs", h->Integral(), error));
    370388        text.SetBit(TLatex::kTextNDC);
    371389        text.SetTextSize(0.04);
     
    386404    AppendPad("fit");
    387405
    388     pad->Divide(2,2);
     406    pad->Divide(2, 1, 0, 0);
    389407
    390408    TH1 *h;
     
    392410    pad->cd(1);
    393411    gPad->SetBorderMode(0);
    394     h = fHTimeDiff.ProjectionX("TimeDiff", -1, 9999, "E");
     412    gPad->Divide(1, 2, 0, 0);
     413    pad->GetPad(1)->cd(1);
     414    gPad->SetBorderMode(0);
     415    h = fHDeltaT.ProjectionX(fNameProjDeltaT, -1, 9999, "E");
    395416    h->SetTitle("Distribution of \\Delta t [s]");
    396417    h->SetXTitle("\\Delta t [s]");
     
    401422    h->Draw();
    402423
     424    pad->GetPad(1)->cd(2);
     425    gPad->SetBorderMode(0);
     426    fHEffOnTime.Draw();
     427    AppendPad("time");
     428
    403429    pad->cd(2);
    404430    gPad->SetBorderMode(0);
    405     h = fHTimeDiff.ProjectionY("Theta", -1, 9999, "E");
     431    gPad->Divide(1, 3, 0, 0);
     432
     433    pad->GetPad(2)->cd(1);
     434    gPad->SetBorderMode(0);
     435    h = fHDeltaT.ProjectionY(fNameProjTheta, -1, 9999, "E");
    406436    h->SetTitle("Distribution of  \\Theta [\\circ]");
    407437    h->SetXTitle("\\Theta [\\circ]");
     
    413443    h->Draw();
    414444
    415     pad->cd(3);
    416     gPad->SetBorderMode(0);
    417     fHEffOn.Draw();
    418     AppendPad("paint");
    419 
    420     pad->cd(4);
     445    pad->GetPad(2)->cd(2);
    421446    gPad->SetBorderMode(0);
    422447    fHProb.Draw();
     448
     449    pad->GetPad(2)->cd(3);
     450    gPad->SetBorderMode(0);
     451    fHEffOnTheta.Draw();
     452    AppendPad("theta");
     453}
     454
     455void MHEffectiveOnTime::FillTimeBin(Double_t val, Double_t err)
     456{
     457    // Get x-axis
     458    TAxis &x = *fHEffOnTime.GetXaxis();
     459
     460    // Get number of bins
     461    const Int_t n = x.GetNbins();
     462
     463    // Fill last bin with new values
     464    fHEffOnTime.SetBinContent(n, fParam->GetVal());
     465    fHEffOnTime.SetBinError(n, fParam->GetErr());
     466
     467    // Get time range of histogram, get bin width
     468    const Double_t lo = fHEffOnTime.GetXaxis()->GetXmin();
     469    const Double_t up = fHEffOnTime.GetXaxis()->GetXmax();
     470    const Double_t w  = fHEffOnTime.GetXaxis()->GetBinWidth(1);
     471
     472    // Enhance histogram by one bin
     473    MBinning bins;
     474    bins.SetEdges(n+2, lo, up+w);
     475    bins.Apply(fHEffOnTime);
     476
     477    // Transform overflow bin
     478    // fHEffOnTime.SetBinContent(n+2, fHEffOnTime.GetBinContent(n+1));
     479    // fHEffOnTime.SetBinError(n+2, fHEffOnTime.GetBinError(n+1));
    423480}
    424481
    425482void MHEffectiveOnTime::Calc()
    426483{
    427     TH1D *h = fHTimeDiff.ProjectionX("", -1, 99999, "E");
     484    TH1D *h = fHDeltaT.ProjectionX("", -1, 99999, "E");
    428485    h->SetDirectory(0);
    429486
     
    438495    const Double_t error = res[1];
    439496
    440     fParam->SetVal(val-fEffOnTime0, error-fEffOnErr0);
     497    fParam->SetVal(val>fEffOnTime0?val-fEffOnTime0:0, error-fEffOnErr0);
    441498    fParam->SetReadyToSave();
    442499
    443     testval += fParam->GetVal();
    444     testerr += fParam->GetErr();
     500    FillTimeBin(fParam->GetVal(), fParam->GetErr());
    445501
    446502    fEffOnTime0 = val;
     
    453509    *fLog << Form("T_{eff} = %.1fs \\pm %.1fs",
    454510                  fParam->GetVal(), fParam->GetErr());
    455     *fLog << Form("   %.1f %.1f   %.1f %.1f",
    456                   val, testval, error, testerr) << endl;
     511    *fLog << Form("   %.1f   %.1f",
     512                  val, error) << endl;
    457513
    458514    fTime->AddMilliSeconds(fInterval*1000);
     
    468524    if (!time)
    469525    {
    470         *fLog << err << "ERROR - MHEffectiveOnTimeTime::Fill without argument or container doesn't inherit from MTime... abort." << endl;
     526        *fLog << err << "ERROR - MHEffectiveOnTime::Fill without argument or container doesn't inherit from MTime... abort." << endl;
    471527        return kFALSE;
    472528    }
     
    483539        *fTime = *time;
    484540
     541        MBinning bins;
     542        bins.SetEdges(2, fTime->GetAxisTime(), fTime->GetAxisTime()+fInterval);
     543        bins.Apply(fHEffOnTime);
     544
    485545        // Make this just a ns before the first event
    486546        fTime->Minus1ns();
     
    493553    }
    494554
    495     fHTimeDiff.Fill(*time-fLastTime, fPointPos->GetZd(), w);
     555    fHDeltaT.Fill(*time-fLastTime, fPointPos->GetZd(), w);
    496556    fLastTime = *time;
    497557
Note: See TracChangeset for help on using the changeset viewer.