Changeset 4920 for trunk/MagicSoft


Ignore:
Timestamp:
09/10/04 14:06:46 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MTime.cc

    r4889 r4920  
    570570}
    571571
     572void MTime::Plus1ns()
     573{
     574    fNanoSec++;
     575
     576    if (fNanoSec<1000000)
     577        return;
     578
     579    fNanoSec = 0;
     580    fTime += 1;
     581
     582    if ((Long_t)fTime<(Long_t)kDay*13)
     583        return;
     584
     585    fTime = 11*kDay;
     586    fMjd++;
     587}   
     588
    572589void MTime::Minus1ns()
    573590{
  • trunk/MagicSoft/Mars/mbase/MTime.h

    r4889 r4920  
    128128    void AddMilliSeconds(UInt_t ms);
    129129    void Minus1ns();
     130    void Plus1ns();
    130131    void SetMean(const MTime &t0, const MTime &t1);
    131132    void SetMean(Double_t t0, Double_t t1);
  • trunk/MagicSoft/Mars/mhbase/MBinning.cc

    r4891 r4920  
    7272
    7373}
     74
    7475void MBinning::SetEdges(const TAxis &axe)
    7576{
    76     const TArrayD &arr = *((TAxis&)axe).GetXbins();
     77    const TArrayD &arr = *axe.GetXbins();
    7778    if (arr.GetSize()>0)
    7879    {
     
    8283
    8384    SetEdges(axe.GetNbins(), axe.GetXmin(), axe.GetXmax());
     85}
     86
     87void MBinning::AddEdge(Axis_t up)
     88{
     89    const Int_t n = fEdges.GetSize();
     90
     91    if (up<=fEdges[n-1])
     92    {
     93        *fLog << warn << dbginf << "WARNING - New upper edge not greater than old upper edge... ignored." << endl;
     94        return;
     95    }
     96
     97    fEdges.Set(n+1);
     98    fEdges[n] = up;
     99
     100    fType = kIsUserArray;
    84101}
    85102
     
    111128void MBinning::SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up)
    112129{
    113     const Double_t binsize = (up-lo)/nbins;
     130    const Double_t binsize = nbins<=0 ? 0 : (up-lo)/nbins;
    114131    fEdges.Set(nbins+1);
    115132    for (int i=0; i<=nbins; i++)
    116             fEdges[i] = binsize*i + lo;
     133        fEdges[i] = binsize*i + lo;
    117134
    118135    fType = kIsLinear;
  • trunk/MagicSoft/Mars/mhbase/MBinning.h

    r4891 r4920  
    7979    Double_t *GetEdges() const { return (Double_t*)fEdges.GetArray(); }
    8080
     81    void AddEdge(Axis_t up);
     82
    8183    Bool_t IsLinear() const { return fType==kIsLinear; }
    8284    Bool_t IsLogarithmic() const { return fType==kIsLogarithmic; }
  • trunk/MagicSoft/Mars/mhist/HistLinkDef.h

    r4841 r4920  
    1515#pragma link C++ class MHEnergyTime+;
    1616#pragma link C++ class MHEnergyTheta+;
     17#pragma link C++ class MHEffectiveOnTime+;
    1718#pragma link C++ class MHAlphaEnergyTime+;
    1819#pragma link C++ class MHAlphaEnergyTheta+;
  • trunk/MagicSoft/Mars/mhist/MHEffectiveOnTime.cc

    r4906 r4920  
    6363//
    6464MHEffectiveOnTime::MHEffectiveOnTime(const char *name, const char *title)
    65     : fPointPos(0), fTime(0), fParam(0), fIsFinalized(kFALSE), fInterval(60),
    66     fNameProjDeltaT(Form("DeltaT_%p", this)), fNameProjTheta(Form("Theta_%p", this))
     65    : fPointPos(0), fTime(0), fParam(0), fIsFinalized(kFALSE),
     66    fNumEvents(200*60), fNameProjDeltaT(Form("DeltaT_%p", this)),
     67    fNameProjTheta(Form("Theta_%p", this))
    6768{
    6869    //
     
    7374
    7475    // Main histogram
    75     fHDeltaT.SetName("DeltaT");
    76     fHDeltaT.SetXTitle("\\Delta t [s]");
    77     fHDeltaT.SetYTitle("\\Theta [\\circ]");
    78     fHDeltaT.UseCurrentStyle();
    79     fHDeltaT.SetDirectory(NULL);
     76    fH2DeltaT.SetName("DeltaT");
     77    fH2DeltaT.SetXTitle("\\Delta t [s]");
     78    fH2DeltaT.SetYTitle("\\Theta [\\circ]");
     79    fH2DeltaT.SetZTitle("Count");
     80    fH2DeltaT.UseCurrentStyle();
     81    fH2DeltaT.SetDirectory(NULL);
     82
     83    // Main histogram
     84    fH1DeltaT.SetName("DeltaT");
     85    fH1DeltaT.SetXTitle("\\Delta t [s]");
     86    fH1DeltaT.SetYTitle("Counts");
     87    fH1DeltaT.UseCurrentStyle();
     88    fH1DeltaT.SetDirectory(NULL);
    8089
    8190    // effective on time versus theta
    82     fHEffOnTheta.SetName("EffOnTime");
     91    fHEffOnTheta.SetName("EffOnTheta");
    8392    fHEffOnTheta.SetTitle("Effective On Time T_{eff}");
    8493    fHEffOnTheta.SetXTitle("\\Theta [\\circ]");
     
    102111    fHEffOnTime.Sumw2();
    103112
    104     // chi2/NDF versus theta
    105     fHChi2.SetName("Chi2/NDF");
    106     fHChi2.SetTitle("\\chi^{2}/NDF of Effective On Time Fit");
    107     fHChi2.SetXTitle("\\Theta [\\circ]");
    108     fHChi2.SetYTitle("\\chi^{2}/NDF");
    109     fHChi2.UseCurrentStyle();
    110     fHChi2.SetDirectory(NULL);
    111     fHChi2.GetYaxis()->SetTitleOffset(1.2);
    112     //fHChi2.Sumw2();
    113 
    114113    // chi2 probability
    115     fHProb.SetName("Prob");
    116     fHProb.SetTitle("\\chi^{2} Probability of Fit");
    117     fHProb.SetXTitle("\\Theta [\\circ]");
    118     fHProb.SetYTitle("p [%]");
    119     fHProb.UseCurrentStyle();
    120     fHProb.SetDirectory(NULL);
    121     fHProb.GetYaxis()->SetTitleOffset(1.2);
    122     fHProb.SetMaximum(101);
    123     //fHChi2.Sumw2();
     114    fHProbTheta.SetName("ProbTheta");
     115    fHProbTheta.SetTitle("\\chi^{2} Probability of Fit");
     116    fHProbTheta.SetXTitle("\\Theta [\\circ]");
     117    fHProbTheta.SetYTitle("p [%]");
     118    fHProbTheta.UseCurrentStyle();
     119    fHProbTheta.SetDirectory(NULL);
     120    fHProbTheta.GetYaxis()->SetTitleOffset(1.2);
     121    fHProbTheta.SetMaximum(101);
     122
     123    // chi2 probability
     124    fHProbTime.SetName("ProbTime");
     125    fHProbTime.SetTitle("\\chi^{2} Probability of Fit");
     126    fHProbTime.SetXTitle("Time");
     127    fHProbTime.SetYTitle("p [%]");
     128    fHProbTime.UseCurrentStyle();
     129    fHProbTime.SetDirectory(NULL);
     130    fHProbTime.GetYaxis()->SetTitleOffset(1.2);
     131    fHProbTime.GetXaxis()->SetLabelSize(0.033);
     132    fHProbTime.GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
     133    fHProbTime.GetXaxis()->SetTimeDisplay(1);
     134    fHProbTime.SetMaximum(101);
    124135
    125136    // lambda versus theta
     
    141152    //fHN0del.Sumw2();
    142153
     154    // chi2/NDF versus theta
     155    /*
     156     fHChi2.SetName("Chi2/NDF");
     157     fHChi2.SetTitle("\\chi^{2}/NDF of Effective On Time Fit");
     158     fHChi2.SetXTitle("\\Theta [\\circ]");
     159     fHChi2.SetYTitle("\\chi^{2}/NDF");
     160     fHChi2.UseCurrentStyle();
     161     fHChi2.SetDirectory(NULL);
     162     fHChi2.GetYaxis()->SetTitleOffset(1.2);
     163     //fHChi2.Sumw2();
     164     */
     165
    143166    // setup binning
    144167    MBinning btheta("BinningTheta");
     
    148171    btime.SetEdges(50, 0, 0.1);
    149172
    150     MH::SetBinning(&fHDeltaT, &btime, &btheta);
     173    MH::SetBinning(&fH2DeltaT, &btime, &btheta);
     174
     175    btime.Apply(fH1DeltaT);
    151176
    152177    btheta.Apply(fHEffOnTheta);
    153     btheta.Apply(fHChi2);
    154178    btheta.Apply(fHLambda);
    155179    btheta.Apply(fHN0);
    156     btheta.Apply(fHProb);
     180    btheta.Apply(fHProbTheta);
     181    //btheta.Apply(fHChi2);
    157182}
    158183
     
    180205   const MBinning* binsdtime = (MBinning*)plist->FindObject("BinningDeltaT");
    181206   const MBinning* binstheta = (MBinning*)plist->FindObject("BinningTheta");
    182    if (!binstheta || !binsdtime)
    183        *fLog << warn << dbginf << "At least one MBinning not found... ignored." << endl;
    184    else
     207   if (binsdtime)
     208       binsdtime->Apply(fH1DeltaT);
     209   if (binstheta)
    185210   {
    186        SetBinning(&fHDeltaT, binsdtime, binstheta);
    187 
    188211       binstheta->Apply(fHEffOnTheta);
    189        binstheta->Apply(fHChi2);
    190212       binstheta->Apply(fHLambda);
    191213       binstheta->Apply(fHN0);
    192        binstheta->Apply(fHProb);
     214       binstheta->Apply(fHProbTheta);
     215       //binstheta->Apply(fHChi2);
    193216   }
     217   if (binstheta && binsdtime)
     218       SetBinning(&fH2DeltaT, binsdtime, binstheta);
    194219
    195220   return kTRUE;
    196221}
    197222
    198 Bool_t MHEffectiveOnTime::Finalize()
    199 {
    200     FitThetaBins();
    201     Calc();
    202 
    203     fIsFinalized = kTRUE;
    204 
    205     return kTRUE;
    206 }
    207 
    208 void MHEffectiveOnTime::FitThetaBins()
    209 {
    210     const TString name = Form("CalcTheta%d", (UInt_t)gRandom->Uniform(999999999));
    211 
    212     // nbins = number of Theta bins
    213     const Int_t nbins = fHDeltaT.GetNbinsY();
    214 
    215     TH1D *h=0;
    216     for (int i=1; i<=nbins; i++)
    217     {
    218         //        TH1D &h = *hist->ProjectionX("Calc-theta", i, i);
    219         h = fHDeltaT.ProjectionX(name, i, i, "E");
    220 
    221         Double_t res[7];
    222         if (!FitH(h, res))
    223             continue;
    224 
    225         // the effective on time is Nm/lambda
    226         fHEffOnTheta.SetBinContent(i, res[0]);
    227         fHEffOnTheta.SetBinError  (i, res[1]);
    228 
    229         // plot chi2-probability of fit
    230         fHProb.SetBinContent(i, res[2]);
    231 
    232         // plot chi2/NDF of fit
    233         fHChi2.SetBinContent(i, res[3]);
    234 
    235         // lambda of fit
    236         fHLambda.SetBinContent(i, res[4]);
    237         fHLambda.SetBinError  (i, res[5]);
    238 
    239         // N0 of fit
    240         fHN0.SetBinContent(i, res[6]);
    241 
    242         // Rdead (from fit) is the fraction from real time lost by the dead time
    243         //fHRdead.SetBinContent(i, Rdead);
    244         //fHRdead.SetBinError  (i,dRdead);
    245     }
    246 
    247     // Histogram is reused via gROOT->FindObject()
    248     // Need to be deleted only once
    249     if (h)
    250         delete h;
    251 }
    252 
    253 Bool_t MHEffectiveOnTime::FitH(TH1D *h, Double_t *res) const
     223Bool_t MHEffectiveOnTime::FitH(TH1D *h, Double_t *res, Bool_t paint) const
    254224{
    255225    const Double_t Nm = h->Integral();
     
    296266
    297267    // was fit successful ?
    298     if (NDF<=0 || chi2>=2.5*NDF)
     268    const Bool_t ok = NDF>0 && chi2<2.5*NDF;
     269
     270    if (paint)
     271    {
     272        func.SetLineWidth(2);
     273        func.SetLineColor(ok ? kGreen : kRed);
     274        func.Paint("same");
     275    }
     276
     277    if (!ok)
    299278        return kFALSE;
    300279
     
    332311
    333312    // plot chi2/NDF of fit
    334     res[3] = NDF ? chi2/NDF : 0.0;
     313    //res[3] = NDF ? chi2/NDF : 0.0;
    335314
    336315    // lambda of fit
    337     res[4] = lambda;
    338     res[5] = dl;
     316    res[3] = lambda;
     317    res[4] = dl;
    339318
    340319    // N0 of fit
    341     res[6] = N0;
     320    res[5] = N0;
    342321
    343322    // Rdead (from fit) is the fraction from real time lost by the dead time
     
    348327}
    349328
     329void MHEffectiveOnTime::FitThetaBins()
     330{
     331    const TString name = Form("CalcTheta%d", (UInt_t)gRandom->Uniform(999999999));
     332
     333    // nbins = number of Theta bins
     334    const Int_t nbins = fH2DeltaT.GetNbinsY();
     335
     336    TH1D *h=0;
     337    for (int i=1; i<=nbins; i++)
     338    {
     339        //        TH1D &h = *hist->ProjectionX("Calc-theta", i, i);
     340        h = fH2DeltaT.ProjectionX(name, i, i, "E");
     341
     342        Double_t res[6];
     343        if (!FitH(h, res))
     344            continue;
     345
     346        // the effective on time is Nm/lambda
     347        fHEffOnTheta.SetBinContent(i, res[0]);
     348        fHEffOnTheta.SetBinError  (i, res[1]);
     349
     350        // plot chi2-probability of fit
     351        fHProbTheta.SetBinContent(i, res[2]);
     352
     353        // plot chi2/NDF of fit
     354        //fHChi2.SetBinContent(i, res[3]);
     355
     356        // lambda of fit
     357        fHLambda.SetBinContent(i, res[3]);
     358        fHLambda.SetBinError  (i, res[4]);
     359
     360        // N0 of fit
     361        fHN0.SetBinContent(i, res[5]);
     362
     363        // Rdead (from fit) is the fraction from real time lost by the dead time
     364        //fHRdead.SetBinContent(i, Rdead);
     365        //fHRdead.SetBinError  (i,dRdead);
     366    }
     367
     368    // Histogram is reused via gROOT->FindObject()
     369    // Need to be deleted only once
     370    if (h)
     371        delete h;
     372}
     373
     374void MHEffectiveOnTime::FitTimeBin()
     375{
     376    //
     377    // Fit histogram
     378    //
     379    Double_t res[6];
     380    if (!FitH(&fH1DeltaT, res))
     381        return;
     382
     383    // Reset Histogram
     384    fH1DeltaT.Reset();
     385
     386    //
     387    // Prepare Histogram
     388    //
     389
     390    // Get x-axis
     391    TAxis &x = *fHEffOnTime.GetXaxis();
     392
     393    // Get number of bins
     394    const Int_t n = x.GetNbins();
     395
     396    // Enhance binning
     397    MBinning bins;
     398    bins.SetEdges(x);
     399    bins.AddEdge(fLastTime.GetAxisTime());
     400    bins.Apply(fHEffOnTime);
     401    bins.Apply(fHProbTime);
     402
     403    //
     404    // Fill histogram
     405    //
     406    fHEffOnTime.SetBinContent(n, res[0]);
     407    fHEffOnTime.SetBinError(n, res[1]);
     408
     409    fHProbTime.SetBinContent(n, res[2]);
     410
     411    //
     412    // Now prepare output
     413    //
     414    fParam->SetVal(res[0], res[1]);
     415    fParam->SetReadyToSave();
     416
     417    *fTime = fLastTime;
     418
     419    // Include the current event
     420    fTime->Plus1ns();
     421
     422    *fLog << fLastTime << ":  Val=" << res[0] << "  Err=" << res[1] << endl;
     423}
     424
     425// --------------------------------------------------------------------------
     426//
     427//  Fill the histogram
     428//
     429Bool_t MHEffectiveOnTime::Fill(const MParContainer *par, const Stat_t w)
     430{
     431    const MTime *time = dynamic_cast<const MTime*>(par);
     432    if (!time)
     433    {
     434        *fLog << err << "ERROR - MHEffectiveOnTime::Fill without argument or container doesn't inherit from MTime... abort." << endl;
     435        return kFALSE;
     436    }
     437
     438    if (fLastTime==MTime())
     439    {
     440        MBinning bins;
     441        bins.SetEdges(2, time->GetAxisTime()-fNumEvents/200, time->GetAxisTime());
     442        bins.Apply(fHEffOnTime);
     443        bins.Apply(fHProbTime);
     444
     445        fParam->SetVal(0, 0);
     446        fParam->SetReadyToSave();
     447
     448        *fTime = *time;
     449
     450        // Make this 1ns before the first event!
     451        fTime->Minus1ns();
     452    }
     453
     454    const Double_t dt = *time-fLastTime;
     455
     456    fH2DeltaT.Fill(dt, fPointPos->GetZd(), w);
     457    fH1DeltaT.Fill(dt, w);
     458
     459    fLastTime = *time;
     460
     461    if (fH1DeltaT.GetEntries()>=fNumEvents)
     462        FitTimeBin();
     463
     464    return kTRUE;
     465}
     466
     467Bool_t MHEffectiveOnTime::Finalize()
     468{
     469    FitThetaBins();
     470    FitTimeBin();
     471
     472    fIsFinalized = kTRUE;
     473
     474    return kTRUE;
     475}
     476
     477void MHEffectiveOnTime::PaintText(Double_t val, Double_t error) const
     478{
     479    TLatex text(0.45, 0.94, Form("T_{eff} = %.1fs \\pm %.1fs", val, error));
     480    text.SetBit(TLatex::kTextNDC);
     481    text.SetTextSize(0.04);
     482    text.Paint();
     483}
     484
    350485void MHEffectiveOnTime::Paint(Option_t *opt)
    351486{
    352     TVirtualPad *padsave = gPad;
     487    TH1D *h=0;
    353488
    354489    TString o(opt);
    355490    if (o==(TString)"fit")
    356491    {
    357         TH1D *h0=0;
    358 
    359         padsave->GetPad(1)->cd(1);
    360         if ((h0 = (TH1D*)gPad->FindObject(fNameProjDeltaT)))
     492        TVirtualPad *pad = gPad;
     493
     494        pad->GetPad(1)->cd(1);
     495        if ((h = (TH1D*)gPad->FindObject(fNameProjDeltaT)))
    361496        {
    362             h0 = fHDeltaT.ProjectionX(fNameProjDeltaT, -1, 9999, "E");
    363             if (h0->GetEntries()>0)
     497            h = fH2DeltaT.ProjectionX(fNameProjDeltaT, -1, 9999, "E");
     498            if (h->GetEntries()>0)
    364499                gPad->SetLogy();
    365500        }
    366501
    367         padsave->GetPad(2)->cd(1);
    368         if ((h0 = (TH1D*)gPad->FindObject(fNameProjTheta)))
    369             fHDeltaT.ProjectionY(fNameProjTheta, -1, 9999, "E");
     502        pad->GetPad(2)->cd(1);
     503        if ((h = (TH1D*)gPad->FindObject(fNameProjTheta)))
     504            fH2DeltaT.ProjectionY(fNameProjTheta, -1, 9999, "E");
    370505
    371506        if (!fIsFinalized)
    372507            FitThetaBins();
     508        return;
    373509    }
    374 
    375     TH1D *h=0;
     510    if (o==(TString)"paint")
     511    {
     512        if ((h = (TH1D*)gPad->FindObject(fNameProjDeltaT)))
     513        {
     514            Double_t res[6];
     515            if (FitH(h, res, kTRUE))
     516                PaintText(res[0], res[1]);
     517        }
     518        return;
     519    }
     520
     521    h=0;
    376522    if (o==(TString)"theta")
    377523        h = &fHEffOnTheta;
     
    379525        h = &fHEffOnTime;
    380526
    381     if (h)
    382     {
    383         Double_t error = 0;
    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));
    388         text.SetBit(TLatex::kTextNDC);
    389         text.SetTextSize(0.04);
    390         text.Paint();
    391     }
    392     gPad = padsave;
     527    if (!h)
     528        return;
     529
     530    Double_t error = 0;
     531    for (int i=0; i<h->GetXaxis()->GetNbins(); i++)
     532        error += h->GetBinError(i);
     533
     534    PaintText(h->Integral(), error);
    393535}
    394536
     
    410552    pad->cd(1);
    411553    gPad->SetBorderMode(0);
    412     gPad->Divide(1, 2, 0, 0);
     554    gPad->Divide(1, 3, 0, 0);
    413555    pad->GetPad(1)->cd(1);
    414556    gPad->SetBorderMode(0);
    415     h = fHDeltaT.ProjectionX(fNameProjDeltaT, -1, 9999, "E");
     557    h = fH2DeltaT.ProjectionX(fNameProjDeltaT, -1, 9999, "E");
    416558    h->SetTitle("Distribution of \\Delta t [s]");
    417559    h->SetXTitle("\\Delta t [s]");
     
    421563    h->SetBit(kCanDelete);
    422564    h->Draw();
     565    AppendPad("paint");
    423566
    424567    pad->GetPad(1)->cd(2);
     568    gPad->SetBorderMode(0);
     569    fHProbTime.Draw();
     570
     571    pad->GetPad(1)->cd(3);
    425572    gPad->SetBorderMode(0);
    426573    fHEffOnTime.Draw();
     
    433580    pad->GetPad(2)->cd(1);
    434581    gPad->SetBorderMode(0);
    435     h = fHDeltaT.ProjectionY(fNameProjTheta, -1, 9999, "E");
     582    h = fH2DeltaT.ProjectionY(fNameProjTheta, -1, 9999, "E");
    436583    h->SetTitle("Distribution of  \\Theta [\\circ]");
    437584    h->SetXTitle("\\Theta [\\circ]");
     
    445592    pad->GetPad(2)->cd(2);
    446593    gPad->SetBorderMode(0);
    447     fHProb.Draw();
     594    fHProbTheta.Draw();
    448595
    449596    pad->GetPad(2)->cd(3);
     
    452599    AppendPad("theta");
    453600}
    454 
    455 void 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));
    480 }
    481 
    482 void MHEffectiveOnTime::Calc()
    483 {
    484     TH1D *h = fHDeltaT.ProjectionX("", -1, 99999, "E");
    485     h->SetDirectory(0);
    486 
    487     Double_t res[7];
    488     Bool_t rc = FitH(h, res);
    489     delete h;
    490 
    491     if (!rc)
    492         return;
    493 
    494     const Double_t val   = res[0];
    495     const Double_t error = res[1];
    496 
    497     fParam->SetVal(val>fEffOnTime0?val-fEffOnTime0:0, error-fEffOnErr0);
    498     fParam->SetReadyToSave();
    499 
    500     FillTimeBin(fParam->GetVal(), fParam->GetErr());
    501 
    502     fEffOnTime0 = val;
    503     fEffOnErr0  = error;
    504 
    505     MTime now(*fTime);
    506     now.AddMilliSeconds(fInterval*1000);
    507 
    508     *fLog <<all << now << " - ";// << fLastTime-fTime;
    509     *fLog << Form("T_{eff} = %.1fs \\pm %.1fs",
    510                   fParam->GetVal(), fParam->GetErr());
    511     *fLog << Form("   %.1f   %.1f",
    512                   val, error) << endl;
    513 
    514     fTime->AddMilliSeconds(fInterval*1000);
    515 }
    516 
    517 // --------------------------------------------------------------------------
    518 //
    519 //  Fill the histogram
    520 //
    521 Bool_t MHEffectiveOnTime::Fill(const MParContainer *par, const Stat_t w)
    522 {
    523     const MTime *time = dynamic_cast<const MTime*>(par);
    524     if (!time)
    525     {
    526         *fLog << err << "ERROR - MHEffectiveOnTime::Fill without argument or container doesn't inherit from MTime... abort." << endl;
    527         return kFALSE;
    528     }
    529 
    530     if (*fTime==MTime())
    531     {
    532         *fLog << all << *time << " - " << *fTime << " " << TMath::Floor(*time) << endl;
    533         fEffOnTime0 = 0;
    534         fEffOnErr0  = 0;
    535 
    536         fParam->SetVal(0, 0);
    537         fParam->SetReadyToSave();
    538 
    539         *fTime = *time;
    540 
    541         MBinning bins;
    542         bins.SetEdges(2, fTime->GetAxisTime(), fTime->GetAxisTime()+fInterval);
    543         bins.Apply(fHEffOnTime);
    544 
    545         // Make this just a ns before the first event
    546         fTime->Minus1ns();
    547     }
    548 
    549     if (*fTime+fInterval<*time)
    550     {
    551         FitThetaBins();
    552         Calc();
    553     }
    554 
    555     fHDeltaT.Fill(*time-fLastTime, fPointPos->GetZd(), w);
    556     fLastTime = *time;
    557 
    558     return kTRUE;
    559 }
    560 
  • trunk/MagicSoft/Mars/mhist/MHEffectiveOnTime.h

    r4907 r4920  
    2727    MTime           fLastTime;   //!
    2828
    29     Double_t        fEffOnTime0; //!
    30     Double_t        fEffOnErr0;  //!
    31 
    3229    MTime          *fTime;       //!
    3330    MParameterDerr *fParam;      //!
    3431
    35     TH2D fHDeltaT;
    36     TH1D fHEffOnTheta;
    37     TH1D fHEffOnTime;
    38     TH1D fHChi2;
    39     TH1D fHProb;
     32    TH2D fH2DeltaT;              // Counts vs Delta T and Theta
     33    TH1D fH1DeltaT;              //! Counts vs Delta T (for a time interval)
     34
     35    TH1D fHEffOnTheta;           // Effective On time versus Theta
     36    TH1D fHEffOnTime;            // Effective On time versus Time
     37
     38    TH1D fHProbTheta;            // Chisq prob fit of Effective On time versus Theta
     39    TH1D fHProbTime;             // Chisq prob fit of Effective On time versus Time
     40
    4041    TH1D fHN0;
    4142    TH1D fHLambda;
     
    4344    Bool_t fIsFinalized;
    4445
    45     Int_t fInterval;
     46    Int_t fNumEvents;
    4647
    4748    const TString fNameProjDeltaT;  //! This should make sure, that gROOT doen't confuse the projection with something else
    4849    const TString fNameProjTheta;   //! This should make sure, that gROOT doen't confuse the projection with something else
    4950
    50     Bool_t FitH(TH1D *h, Double_t *res) const;
     51    Bool_t FitH(TH1D *h, Double_t *res, Bool_t paint=kFALSE) const;
    5152    void FitThetaBins();
    52     void FillTimeBin(Double_t val, Double_t err);
    53     void Calc();
     53    void FitTimeBin();
     54    void PaintText(Double_t val, Double_t error) const;
    5455
    5556public:
    5657    MHEffectiveOnTime(const char *name=NULL, const char *title=NULL);
    5758
    58     void SetInterval(Int_t i) { fInterval=i; }
     59    void SetNumEvents(Int_t i) { fNumEvents=i; }
    5960
    6061    Bool_t SetupFill(const MParList *pList);
    6162    Bool_t Fill(const MParContainer *par, const Stat_t w=1);
    6263    Bool_t Finalize();
    63 
    64     const TH2D *GetHist() { return &fHDeltaT; }
    65     const TH2D *GetHist() const { return &fHDeltaT; }
    6664
    6765    void Draw(Option_t *option="");
  • trunk/MagicSoft/Mars/mhist/Makefile

    r4841 r4920  
    2222           -I../mgui -I../mgeom -I../mdata -I../mfilter -I../mimage \
    2323           -I../mmain -I../mmc -I../mreflector -I../mpointing       \
    24            -I../mastro -I../mpedestal -I../mbadpixels
     24           -I../mastro -I../mpedestal -I../msignal -I../mbadpixels
    2525
    2626SRCFILES = MHEvent.cc \
     
    2828           MHCamEvent.cc \
    2929           MHCamEventRot.cc \
     30           MHEffectiveOnTime.cc \
    3031           MHFadcPix.cc \
    3132           MHFadcCam.cc \
  • trunk/MagicSoft/Mars/mjobs/MJStar.cc

    r4906 r4920  
    188188    plist.AddToList(&b1);
    189189
    190     MHVsTime h2("MEffectiveOnTime.fVal", "MEffectiveOnTime.fErr");
    191     h2.SetTitle("Effective On-Time T_{eff} vs. Time;;T_{eff}");
    192 
    193190    MFillH fill0(&evt0, "MCerPhotEvt",            "FillCerPhotEvt");
    194191    MFillH fill1("MHHillas",      "MHillas",      "FillHillas");
     
    201198    MFillH fill8(&h1,             "",             "FillEventRate");
    202199    MFillH fill9("MHEffectiveOnTime", "MTime",    "FillEffOnTime");
    203     MFillH filla(&h2,             "MTimeEffectiveOnTime", "FillEffOnTimeVsTime");
    204200    //MFillH fillb(&h12, "", "FillEvtRate2");
    205201    //MFillH fill9("MHCerPhot");
     
    258254        tlist2.AddToList(&fill8);
    259255        tlist2.AddToList(&fill9);
    260         tlist2.AddToList(&filla);
    261256    }
    262257    //tlist2.AddToList(&fillb);
  • trunk/MagicSoft/Mars/mjobs/MSequence.cc

    r4801 r4920  
    158158        iter.AddDirectory(d, n, 0);
    159159    }
     160
    160161    return iter.GetNumEntries();
    161162}
Note: See TracChangeset for help on using the changeset viewer.