Ignore:
Timestamp:
09/08/04 18:49:00 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mhvstime
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mhvstime/MHPixVsTime.cc

    r3539 r4889  
    194194    {
    195195        TAxis *axe = h->GetXaxis();
    196         axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00");
     196        axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
    197197        axe->SetTimeDisplay(1);
    198198        axe->SetLabelSize(0.033);
  • trunk/MagicSoft/Mars/mhvstime/MHSectorVsTime.cc

    r3394 r4889  
    247247    {
    248248        TAxis *axe = h->GetXaxis();
    249         axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00");
     249        axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
    250250        axe->SetTimeDisplay(1);
    251251        axe->SetLabelSize(0.025);
  • trunk/MagicSoft/Mars/mhvstime/MHVsTime.cc

    r4828 r4889  
    4949#include <TCanvas.h>
    5050
    51 #include <TGraph.h>
     51#include <TGraphErrors.h>
    5252
    5353#include "MLog.h"
     
    7171// see MDataChain.
    7272//
    73 MHVsTime::MHVsTime(const char *rule)
    74     : fGraph(NULL), fData(NULL), fScale(1), fMaxPts(-1), fUseEventNumber(0)
    75 
     73MHVsTime::MHVsTime(const char *rule, const char *error)
     74    : fGraph(NULL), fData(NULL), fError(0), fScale(1), fMaxPts(-1),
     75    fNumEvents(1), fUseEventNumber(0)
     76{
    7677    fName  = gsDefName;
    7778    fTitle = gsDefTitle;
     
    8081        return;
    8182
    82     fGraph = new TGraph;
    8383    fData = new MDataChain(rule);
    8484
    85     fGraph->SetMarkerStyle(kFullDotMedium);
     85    if (error)
     86        fError = new MDataChain(error);
     87
     88    fGraph = error ? new TGraphErrors : new TGraph;
     89    fGraph->SetPoint(0, 0, 0); // Dummy point!
     90    fGraph->SetEditable();     // Used as flag: First point? yes/no
    8691}
    8792
     
    116121Bool_t MHVsTime::SetupFill(const MParList *plist)
    117122{
    118     // reset histogram (necessary if the same eventloop is run more than once)
    119     //fGraph->Reset();
    120 
    121     if (fData && !fData->PreProcess(plist))
     123    if (!fGraph || !fData)
     124    {
     125        *fLog << err << "ERROR - MHVsTime cannot be used with its default constructor!" << endl;
    122126        return kFALSE;
    123 
    124     if (fGraph)
    125     {
    126         delete fGraph;
    127         fGraph = new TGraph;
    128     }
     127    }
     128
     129    if (!fData->PreProcess(plist))
     130        return kFALSE;
     131
     132    if (fError && !fError->PreProcess(plist))
     133        return kFALSE;
     134
     135    fGraph->Set(1);
     136    fGraph->SetPoint(0, 0, 0); // Dummy point!
     137    fGraph->SetEditable();     // Used as flag: First point? yes/no
    129138
    130139    TString title(fData ? GetRule() : (TString)"Histogram");
     
    183192        if (!*tm)
    184193            return kTRUE;
     194
     195        // Do not fill events with equal time
     196        if (*tm==fLast || *tm==MTime())
     197            return kTRUE;
     198
     199        fLast = *tm;
     200
    185201        t = tm->GetAxisTime();
    186202    }
    187203
    188     const Double_t v = fData->GetValue()*fScale;
    189 
    190     if (fMaxPts>0 && fGraph->GetN()>fMaxPts)
    191         fGraph->RemovePoint(0);
    192 
    193     fMean += v;
     204    const Double_t v = fData->GetValue();
     205    const Double_t e = fError ? fError->GetValue() : 0;
     206
     207    //*fLog << all << "ADD " << v << " " << e << endl;
     208
     209    fMean    += v;
     210    fMeanErr += e;
    194211    fN++;
    195212
    196213    if (fN==fNumEvents)
    197214    {
    198         fGraph->SetPoint(fGraph->GetN(), t, fMean/fN);
     215        if (fMaxPts>0 && fGraph->GetN()>fMaxPts || fGraph->IsEditable())
     216        {
     217            fGraph->RemovePoint(0);
     218            fGraph->SetEditable(kFALSE);
     219        }
     220
     221        fGraph->SetPoint(fGraph->GetN(), t, fMean/fN*fScale);
     222
     223        if (fError)
     224            static_cast<TGraphErrors*>(fGraph)->SetPointError(fGraph->GetN()-1, 0, fMeanErr/fN*fScale);
     225
    199226        fMean = 0;
     227        fMeanErr = 0;
    200228        fN = 0;
    201229    }
    202230
    203231    return kTRUE;
     232}
     233
     234void MHVsTime::Paint(Option_t *opt)
     235{
     236    // SetPoint deletes the histogram!
     237    if (fUseEventNumber)
     238        fGraph->GetHistogram()->SetXTitle("Event Number");
     239    else
     240    {
     241        fGraph->GetHistogram()->SetXTitle("Time");
     242        fGraph->GetHistogram()->GetXaxis()->SetLabelSize(0.033);
     243        fGraph->GetHistogram()->GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
     244        fGraph->GetHistogram()->GetXaxis()->SetTimeDisplay(1);
     245    }
     246
     247    fGraph->GetHistogram()->SetMarkerStyle(kFullDotMedium);
     248    fGraph->GetHistogram()->SetYTitle(fAxisTitle.IsNull() ? GetRule() : fAxisTitle);
     249    if (fTitle!=gsDefTitle)
     250        fGraph->GetHistogram()->SetTitle(fTitle);
     251
     252    if (TestBit(kIsLogy))
     253        gPad->SetLogy();
     254
     255    // This is a workaround if the TGraph has only one point.
     256    // Otherwise MStatusDisplay::Update hangs.
     257    gPad->GetListOfPrimitives()->Remove(fGraph);
     258    gPad->GetListOfPrimitives()->Add(fGraph, fGraph->GetN()<2 ? "A" : opt);
    204259}
    205260
     
    212267void MHVsTime::Draw(Option_t *opt)
    213268{
     269    if (!fGraph)
     270        return;
     271
    214272    if (fGraph->GetN()==0)
    215273        return;
     
    218276    pad->SetBorderMode(0);
    219277
    220     AppendPad("");
    221 
    222278    TString str(opt);
    223 
    224     if (fUseEventNumber)
    225         fGraph->GetHistogram()->SetXTitle("Event Number");
    226     else
    227     {
    228         fGraph->GetHistogram()->SetXTitle("Time");
    229         fGraph->GetHistogram()->GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00");
    230         fGraph->GetHistogram()->GetXaxis()->SetTimeDisplay(1);
    231         fGraph->GetHistogram()->GetXaxis()->SetLabelSize(0.033);
    232     }
    233     fGraph->GetHistogram()->SetYTitle(GetRule());
    234279
    235280    if (!str.Contains("A"))
     
    244289    }
    245290
     291    AppendPad(str);
    246292    fGraph->Draw(str);
    247     if (fGraph->TestBit(kIsLogy))
    248         pad->SetLogy();
    249 
    250     pad->Modified();
    251     pad->Update();
    252293}
    253294
  • trunk/MagicSoft/Mars/mhvstime/MHVsTime.h

    r4828 r4889  
    44#ifndef MARS_MH
    55#include "MH.h"
     6#endif
     7
     8#ifndef MARS_MTime
     9#include "MTime.h"
    610#endif
    711
     
    1519    TGraph     *fGraph;     // Histogram to fill
    1620    MDataChain *fData;      // Object from which the data is filled
     21    MDataChain *fError;     // Object from which the error is filled
    1722    Double_t    fScale;     // Scale for axis (eg unit)
    1823    Int_t       fMaxPts;    // Maximum number of data points
    1924
    2025    Int_t       fNumEvents; // Number of events to average
     26
    2127    Double_t    fMean;      //! Mean value
    22     Int_t       fN;
     28    Double_t    fMeanErr;   //! Mean error
     29    Int_t       fN;         //! Number of entries in fMean
     30    MTime       fLast;      //! For checks
    2331
     32    TString     fAxisTitle;
    2433
    2534    enum {
    26         kIsLogy         = BIT(18),
    27         kUseEventNumber = BIT(20)
     35        kIsLogy = BIT(18)
    2836    };
    2937
     
    3139
    3240public:
    33     MHVsTime(const char *rule=NULL);
     41    MHVsTime(const char *rule=NULL, const char *ruleerr=NULL);
    3442    ~MHVsTime();
    3543
     
    4048    void SetName(const char *name);
    4149    void SetTitle(const char *title);
     50
     51    void SetLogy(Bool_t b=kTRUE) { b ? SetBit(kIsLogy) : ResetBit(kIsLogy); }
     52    void SetAxisTitle(const char *y) { fAxisTitle=y; }
    4253
    4354    Bool_t SetupFill(const MParList *pList);
     
    5970
    6071    void Draw(Option_t *opt=NULL);
     72    void Paint(Option_t *opt=NULL);
    6173
    6274    MParContainer *New() const;
Note: See TracChangeset for help on using the changeset viewer.