Changeset 9858


Ignore:
Timestamp:
08/13/10 11:42:15 (14 years ago)
Author:
tbretz
Message:
Implemented TProfile3D in MH3 and MHn and the possibility to skip the reset of the histograms in the SetupFill.
Location:
trunk/Mars
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/Changelog

    r9857 r9858  
    3434   * mfbase/MFEventSelector.cc:
    3535     - if the number of events to be selected is negative select all events
     36
     37   * mhbase/MHn.[h,cc]:
     38     - fixed the complex display for five histograms
     39
     40   * mhbase/MHn.[h,cc], mhbase/MH3.[h,cc]:
     41     - implemented a TProfile3D
     42     - implemented an option to skip reset of the histograms in a new
     43       eventloop
     44
     45   * mhbase/MH3.[h,cc]:
     46     - moved the addition weight to a new data meber fWeight
     47     - increased class version number
    3648
    3749
  • trunk/Mars/mhbase/MH3.cc

    r9851 r9858  
    128128//
    129129//
    130 // Class Version 3:
     130// Class Version 1:
    131131// ----------------
    132132//   - MData      *fData[3];
     
    147147//   + TFormula *fConversion
    148148//
     149// Class Version 5:
     150// ----------------
     151//   + MData      *fWeight;
     152//
    149153/////////////////////////////////////////////////////////////////////////////
    150154#include "MH3.h"
     
    168172#include <TProfile.h>
    169173#include <TProfile2D.h>
     174#include <TProfile3D.h>
    170175
    171176#include "MLog.h"
     
    195200    fStyleBits = 0;
    196201
     202    fWeight  = NULL;
     203
     204    fData[0] = NULL;
     205    fData[1] = NULL;
     206    fData[2] = NULL;
    197207    fData[3] = NULL;
    198208
     
    257267        fHist = new TProfile2D;
    258268        fHist->SetZTitle("Average");
    259         if (type==kProfileSpread)
    260             static_cast<TProfile2D*>(fHist)->SetErrorOption("s");
     269        static_cast<TProfile2D*>(fHist)->BuildOptions(0, 0, type==kProfileSpread?"s":"");
    261270        break;
    262271    case 3:
    263272        fHist = new TH3D;
    264273        break;
    265     }
    266 
    267     fData[0] = NULL;
    268     fData[1] = NULL;
    269     fData[2] = NULL;
     274    case -3:
     275        fHist = new TProfile2D;
     276        fHist->SetZTitle("Average");
     277        static_cast<TProfile2D*>(fHist)->BuildOptions(0, 0, type==kProfileSpread?"s":"");
     278        break;
     279    }
    270280
    271281    Init();
     
    282292    fHist->SetYTitle("Counts");
    283293
     294    Init();
     295
    284296    fData[0] = new MDataPhrase(memberx);
    285     fData[1] = NULL;
    286     fData[2] = NULL;
    287 
    288     Init();
    289297}
    290298
     
    300308        fDimension = 2;
    301309
     310    if (h1.InheritsFrom(TProfile3D::Class()))
     311    {
     312        fDimension = -3;
     313        *fLog << warn << "WARNING - MH3::MH3(TH1&) does not support TProfile3D." << endl;
     314    }
    302315    if (h1.InheritsFrom(TProfile2D::Class()))
    303316        fDimension = -2;
     
    307320    fHist = (TH1*)h1.Clone();
    308321
    309     fData[0] = NULL;
    310     fData[1] = NULL;
    311     fData[2] = NULL;
     322    Init(); // Before without SeUseCurrentStyle!
    312323
    313324    switch (fDimension)
     
    322333        fData[0] = new MDataPhrase(h1.GetXaxis()->GetTitle());
    323334    }
    324 
    325     Init(); // Before without SeUseCurrentStyle!
    326335}
    327336
     
    351360    fHist->SetZTitle(fDimension>0?"Counts":"Average");
    352361
     362    Init();
     363
    353364    fData[0] = new MDataPhrase(memberx);
    354365    fData[1] = new MDataPhrase(membery);
    355     fData[2] = NULL;
    356 
    357     Init();
    358366}
    359367
     
    374382    case -2:
    375383        fHist = static_cast<TH1*>(new TProfile2D);
    376         if (type==kProfileSpread)
    377             static_cast<TProfile2D*>(fHist)->SetErrorOption("s");
    378     }
     384        static_cast<TProfile2D*>(fHist)->BuildOptions(0, 0, type==kProfileSpread?"s":"");
     385    }
     386
     387    Init();
    379388
    380389    fData[0] = new MDataPhrase(memberx);
    381390    fData[1] = new MDataPhrase(membery);
    382391    fData[2] = new MDataPhrase(memberz);
     392}
     393
     394// --------------------------------------------------------------------------
     395//
     396// Creates an TH3D. memberx is filled into the X-bins. membery is filled
     397// into the Y-bins. membery is filled into the Z-bins. Weight is used as a
     398// weight for the profile histogram. For a more detailed description see the
     399// class description above.
     400//
     401MH3::MH3(const char *memberx, const char *membery, const char *memberz, const char *weight, Type_t type)
     402    : fDimension(-3)
     403{
     404    fHist = static_cast<TH1*>(new TProfile3D);
     405    static_cast<TProfile3D*>(fHist)->BuildOptions(0, 0, type==kProfileSpread?"s":"");
    383406
    384407    Init();
     408
     409    fData[0] = new MDataPhrase(memberx);
     410    fData[1] = new MDataPhrase(membery);
     411    fData[2] = new MDataPhrase(memberz);
     412    fData[3] = new MDataPhrase(weight);
    385413}
    386414
     
    396424    if (fConversion)
    397425        delete fConversion;
     426
     427    if (fWeight)
     428        delete fWeight;
    398429
    399430    for (int i=0; i<4; i++)
     
    414445void MH3::SetWeight(const char *phrase)
    415446{
    416     if (fData[3])
    417         delete fData[3];
    418     fData[3] = new MDataPhrase(phrase);
     447    if (fWeight)
     448        delete fWeight;
     449    fWeight = new MDataPhrase(phrase);
    419450}
    420451
     
    573604Bool_t MH3::SetupFill(const MParList *plist)
    574605{
    575     // reset histogram (necessary if the same eventloop is run more than once)
    576     fHist->Reset();
     606    // reset histogram (necessary if the same eventloop is run more than once)
     607    if (!TestBit(kDoNotReset))
     608        fHist->Reset();
    577609
    578610    // Tokenize name into name and binnings names
     
    660692            return kFALSE;
    661693
     694    if (fWeight && !fWeight->PreProcess(plist))
     695        return kFALSE;
     696
    662697    TString title(fDimension>0?"Histogram":"Profile");
    663698    title += " for ";
     
    748783    Double_t y=0;
    749784    Double_t z=0;
     785    Double_t t=0;
    750786    Double_t w=ww;
    751787
    752788    switch (fDimension)
    753789    {
     790    case -3:
     791        t = fData[3]->GetValue();
    754792    case -2:
    755793    case  3:
     
    762800    }
    763801
    764     if (fData[3])
    765         w *= fData[3]->GetValue();
     802    if (fData[4])
     803        w *= fData[4]->GetValue();
    766804
    767805    // If label option is set, convert value to label
     
    862900        }
    863901        break;
     902    case  -3:
     903        switch (type)
     904        {
     905        case kNoLabels:
     906            static_cast<TProfile3D*>(fHist)->Fill(x, y, z, t, w);
     907            return kTRUE;
     908        default:
     909            *fLog << err << "ERROR - Labels not supported in TProfile3D." << endl;
     910        }
     911        break;
    864912    }
    865913
     
    11481196        out << "   " << name << ".SetTitle(\"" << fTitle << "\");" << endl;
    11491197
    1150     if (fData[3])
    1151         out << "   " << name << ".SetWeight(\"" << fData[3]->GetRule() << "\");" << endl;
     1198    if (fWeight)
     1199        out << "   " << name << ".SetWeight(\"" << fWeight->GetRule() << "\");" << endl;
    11521200
    11531201    switch (fDimension)
    11541202    {
     1203    case -3:
     1204        if (fScale[3]!=1)
     1205            out << "   " << name << ".SetScaleT(" << fScale[3] << ");" << endl;
    11551206    case -2:
    11561207    case 3:
     
    11751226    case -2:
    11761227        return TString(static_cast<TProfile2D*>(fHist)->GetErrorOption())=="s" ? kProfileSpread : kProfile;
     1228    case -3:
     1229        return TString(static_cast<TProfile3D*>(fHist)->GetErrorOption())=="s" ? kProfileSpread : kProfile;
    11771230    }
    11781231    return kHistogram;
     
    12061259            h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule(), GetType());
    12071260            break;
     1261        case -3:
     1262            h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule(), fData[3]->GetRule());
     1263            break;
    12081264        }
    12091265
     
    12201276    }
    12211277
    1222     if (fData[3])
    1223         h->SetWeight(fData[3]->GetRule());
     1278    if (fData[4])
     1279        h->SetWeight(fData[4]->GetRule());
    12241280
    12251281    return h;
     
    12431299    case 'Z':
    12441300        return fData[2] ? fData[2]->GetRule() : TString("");
     1301    case 't':
     1302    case 'T':
     1303        return fData[3] ? fData[3]->GetRule() : TString("");
    12451304    case 'w':
    12461305    case 'W':
    1247         return fData[3] ? fData[3]->GetRule() : TString("");
     1306        return fWeight  ? fWeight->GetRule() : TString("");
    12481307    default:
    12491308        return "<n/a>";
  • trunk/Mars/mhbase/MH3.h

    r9829 r9858  
    3737    };
    3838
     39    enum {
     40        kDoNotReset = BIT(20)
     41    };
     42
     43
    3944private:
    4045    static const TString gsDefName;
     
    6368    Int_t       fDimension;      // Number of dimensions of histogram
    6469    TH1        *fHist;           // Histogram to fill
    65     MData      *fData[4];        // Object from which the data is filled (+additional weight)
     70    MData      *fData[4];        // Object from which the data is filled
     71    MData      *fWeight;         // Additional weight
    6672    MBinning   *fBins[3];        // Binning set omitting the parlist access
    6773    Double_t    fScale[3];       // Scale for the three axis (eg unit)
     
    7682
    7783    enum {
    78         kIsLogx = BIT(17),
    79         kIsLogy = BIT(18),
    80         kIsLogz = BIT(19)
     84        kIsLogx     = BIT(17),
     85        kIsLogy     = BIT(18),
     86        kIsLogz     = BIT(19)
    8187    };
    8288
     
    8793    MH3(const char *memberx, const char *membery, Type_t type=MH3::kHistogram);
    8894    MH3(const char *memberx, const char *membery, const char *memberz, Type_t type=MH3::kHistogram);
     95    MH3(const char *memberx, const char *membery, const char *memberz, const char *weight, Type_t type=MH3::kProfile);
    8996    ~MH3();
    9097
     
    171178    void RecursiveRemove(TObject *obj);
    172179
    173     ClassDef(MH3, 5) // Generalized 1/2/3D-histogram for Mars variables
     180    ClassDef(MH3, 6) // Generalized 1/2/3D-histogram for Mars variables
    174181};
    175182
  • trunk/Mars/mhbase/MHn.cc

    r9821 r9858  
    254254// --------------------------------------------------------------------------
    255255//
     256// Add a new 3D-MH3 histogram. An internal pointer is set to it, so that
     257// InitName and InitTitle can be used for this histogram until a new
     258// histogram is added using AddHist
     259//
     260//  e.g. AddHist("MHillas.fWidth", "MHillas.fLength", "MHillas.fSize", "MWeight.fVal")
     261//
     262Bool_t MHn::AddHist(const char *memberx, const char *membery, const char *memberz, const char *weight)
     263{
     264    if (fNum==8)
     265    {
     266        *fLog << err << "ERROR - MHn doesn't support more than six histograms... AddHist ignored." << endl;
     267        return kFALSE;
     268    }
     269
     270    fHist[fNum] = new MH3(memberx, membery, memberz, weight);
     271
     272    InitHist();
     273
     274    return kTRUE;
     275}
     276
     277// --------------------------------------------------------------------------
     278//
    256279// Set the draw option of the n-th MH3. See MH3 for more details of the
    257280// meaning of it.
     
    500523{
    501524    for (int i=0; i<fNum; i++)
     525    {
     526        TestBit(kDoNotReset) ? fHist[i]->SetBit(kDoNotReset) : fHist[i]->ResetBit(kDoNotReset);
     527
    502528        if (!fHist[i]->SetupFill(plist))
    503529            return kFALSE;
     530    }
    504531
    505532    return kTRUE;
     
    581608            break;
    582609        case 13:  // 3
     610            pad->Divide(2,2, 1e-5, 1e-5);
     611            pad->GetPad(1)->SetPad(0.01, 0.505, 0.33, 0.99);
     612            pad->GetPad(2)->SetPad(0.01, 0.01,  0.33, 0.495);
     613            pad->GetPad(3)->SetPad(0.34, 0.01,  0.99, 0.99);
     614            delete pad->GetPad(4);
    583615            break;
    584616        case 14:  // 4
  • trunk/Mars/mhbase/MHn.h

    r9821 r9858  
    1010public:
    1111    enum Layout_t { kSimple, kComplex };
     12
     13    enum { kDoNotReset = BIT(20) };
    1214
    1315protected:
     
    3638    Bool_t AddHist(const char *memberx, const char *membery, MH3::Type_t type=MH3::kHistogram);
    3739    Bool_t AddHist(const char *memberx, const char *membery, const char *memberz, MH3::Type_t type=MH3::kHistogram);
     40    Bool_t AddHist(const char *memberx, const char *membery, const char *memberz, const char *weight);
    3841
    3942    void InitName(const char *n)  { InitName(fNum-1, n); }
Note: See TracChangeset for help on using the changeset viewer.