Changeset 7142 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
06/10/05 13:10:09 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r7141 r7142  
    2121
    2222                                                 -*-*- END OF LINE -*-*-
     23 2005/06/10 Daniela Dorner
     24
     25   * datacenter/macros/plotdb.C:
     26     - set minimum and maximum also for ZA graph
     27
     28   * mdata/MDataChain.cc:
     29     - fixed a possible crash to to NULL-acess in GetDataMember
     30
     31   * mhbase/MBinning.[h,cc]:
     32     - added a new binning type "asin" which is used for the
     33       ZA binning
     34
     35   * mhflux/MAlphaFitter.cc:
     36     - allow polynom order 1
     37     - improved result line in PaintResult
     38
     39   * mhflux/MHAlpha.cc:
     40     - call PaintResult also in DrawAll
     41
     42   * mhflux/MHCollectionArea.cc:
     43     - removede nonsense A_{eff} from plot
     44
     45   * mhflux/MHDisp.cc:
     46     - fixed a possible crash if fSrcPos==NULL
     47
     48   * mhflux/MHAlpha.cc, mhflux/MHCollectionArea.cc,
     49     mhflux/MHEffectiveOnTime.cc, mhflux/MHEnergyEst.cc,
     50     mjobs/MJCut.cc:
     51     - replaced SetEdgesCos by new SetEdgesASin (set the correct binning)
     52       the old binning was not well aligned with the MC binning
     53
     54   * mhflux/MMcSpectrumWeight.[h,cc]:
     55     - added the possibility to set ZA-weights
     56       (Could be improved calculating correst sine-weights)
     57
     58   * mimage/MHVsSize.cc:
     59     - fixed. Conc1 was incorrectly scaled
     60
     61   * mjobs/MDataSet.h:
     62     - added getter for TLists
     63
     64   * mjobs/MJCut.cc:
     65     - in non-wobble mode the hcalc2 had been wrrornously added
     66       to the tasklist -> removed
     67       
     68   * mjobs/MJOptimize.h:
     69     - added a comment for EnableTestTrain
     70
     71   * mpointing/MSrcPosCam.[h,cc]:
     72     - implemented Add member function
     73
     74   * mranforest/MRFEnergyEst.[h,cc]:
     75     - fixed a problem with the removal of the last columns
     76     - implemented debug-mode
     77     - interpolate energy in logarithmic grid
     78     - removed Test function completely
     79     - added ReadEnv
     80
     81   * mranforest/MRanTree.[h,cc]:
     82     - replaced some TMatrixFRow by TMatrixFRow_const
     83
     84
     85
    2386 2005/06/08 Daniela Dorner
    2487
  • trunk/MagicSoft/Mars/NEWS

    r7134 r7142  
    22
    33 *** Version <cvs>
     4
     5   - general: Fixed the ZA binning. It didn't correctyl fit the
     6     MC binning
     7
     8   - ganymed: the Conc1 plot was incorrectly scaled in MHVsSize
    49
    510   - mars: show muon parameters graphically
     
    712   - mars: now the file to open can be given as commandline
    813     argument
    9  
     14
     15
    1016
    1117 *** Version 0.9.3 (2005/06/03)
  • trunk/MagicSoft/Mars/datacenter/macros/plotdb.C

    r7129 r7142  
    9797        g.SetNameTitle(name, Form("%s vs Time", name.Data()));
    9898        g.SetMarkerStyle(kFullDotMedium);
     99
     100        TGraph g2;
     101        g2.SetNameTitle(name, Form("%s vs <Zd>", name.Data()));
     102        g2.SetMarkerStyle(kFullDotMedium);
     103
    99104        if (fmax>fmin)
    100105        {
    101106            g.SetMinimum(fmin);
    102107            g.SetMaximum(fmax);
     108            g2.SetMinimum(fmin);
     109            g2.SetMaximum(fmax);
    103110        }
    104 
    105         TGraph g2;
    106         g2.SetNameTitle(name, Form("%s vs <Zd>", name.Data()));
    107         g2.SetMarkerStyle(kFullDotMedium);
    108111
    109112        Int_t first = -1;
  • trunk/MagicSoft/Mars/mdata/MDataChain.cc

    r6831 r7142  
    832832TString MDataChain::GetDataMember() const
    833833{
    834     return fMember->GetDataMember();
     834    return fMember ? fMember->GetDataMember() : "";
    835835}
    836836
    837837void MDataChain::SetVariables(const TArrayD &arr)
    838838{
    839     return fMember->SetVariables(arr);
     839    if (fMember)
     840        fMember->SetVariables(arr);
    840841}
    841842
  • trunk/MagicSoft/Mars/mhbase/MBinning.cc

    r6954 r7142  
    261261//  lo: lowest edge
    262262//  hi: highest edge
    263 //  type: "lin" <default>, "log", "cos" (without quotationmarks)
     263//  type: "lin" <default>, "log", "cos", "asin" (without quotationmarks)
    264264//  title: Whatever the title might be
    265265//
     
    296296        str.Remove(0, pos);
    297297        str = str.Strip(TString::kBoth);
    298         if (typ!=(TString)"lin" && typ!=(TString)"log" && typ!=(TString)"cos")
     298        if (typ!=(TString)"lin" && typ!=(TString)"log" && typ!=(TString)"cos" && typ!=(TString)"asin")
    299299        {
    300300            *fLog << warn << GetDescriptor() << "::SetEdges: Type " << typ << " unknown... ignored." << endl;
     
    384384        return;
    385385    }
     386    if (o.Contains("asin", TString::kIgnoreCase))
     387    {
     388        SetEdgesASin(nbins, lo, up);
     389        return;
     390    }
    386391    if (o.Contains("cos", TString::kIgnoreCase))
    387392    {
     
    420425    const Axis_t ud = up/kRad2Deg;
    421426
    422     const Double_t binsize = (cos(ld)-cos(ud))/nbins;
     427    const Double_t cld = ld<0 ? cos(ld)-1 : 1-cos(ld);
     428    const Double_t cud = ud<0 ? cos(ud)-1 : 1-cos(ud);
     429
     430    SetEdgesASin(nbins, ld, ud);
     431    /*
     432    const Double_t binsize = (cld-cud)/nbins;
    423433    fEdges.Set(nbins+1);
    424434    for (int i=0; i<=nbins; i++)
    425         fEdges[i] = acos(cos(ld)-binsize*i)*kRad2Deg;
     435    {
     436        const Double_t a = cld-binsize*i;
     437        fEdges[i] = a<0 ? -acos(1+a)*kRad2Deg : acos(1-a)*kRad2Deg;
     438        cout << a << " " << fEdges[i] << endl;
     439    }
     440
     441    fType = kIsCosinic;*/
     442}
     443
     444// --------------------------------------------------------------------------
     445//
     446// Specify the number of bins <nbins> (not the number of edges), the
     447// lowest [deg] <lo> and highest [deg] <up> Edge (of your histogram)
     448//
     449void MBinning::SetEdgesASin(const Int_t nbins, Axis_t lo, Axis_t up)
     450{
     451    const Double_t binsize = nbins<=0 ? 0 : (up-lo)/nbins;
     452    fEdges.Set(nbins+1);
     453    for (int i=0; i<=nbins; i++)
     454    {
     455        const Double_t a = binsize*i + lo;
     456        fEdges[i] = a<0 ? -acos(1+a)*kRad2Deg : acos(1-a)*kRad2Deg;
     457    }
    426458
    427459    fType = kIsCosinic;
     
    543575    {
    544576        type = GetEnvValue(env, prefix, "Type", "lin");
    545         if (type!=(TString)"lin" && type!=(TString)"log" && type!=(TString)"cos")
     577        if (type!=(TString)"lin" && type!=(TString)"log" && type!=(TString)"cos" && type!=(TString)"acos")
    546578        {
    547579            *fLog << warn << GetDescriptor() << "::ReadEnv - WARNING: Type is not lin, log nor cos... assuming lin." << endl;
  • trunk/MagicSoft/Mars/mhbase/MBinning.h

    r6958 r7142  
    6666    void SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up);
    6767    void SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up);
     68    void SetEdgesASin(const Int_t nbins, Axis_t lo, Axis_t up);
    6869
    6970    Int_t FindLoEdge(Double_t val) const
  • trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc

    r7093 r7142  
    117117
    118118    fFunc->FixParameter(1, 0);
    119     fFunc->FixParameter(4, 0);
     119    if (fPolynomOrder!=1)
     120        fFunc->FixParameter(4, 0);
    120121    fFunc->SetParLimits(2, 0, 90);
    121122    fFunc->SetParLimits(3, -1, 1);
     
    159160    fFunc->ReleaseParameter(2);
    160161    fFunc->FixParameter(3, fFunc->GetParameter(3));
     162    fFunc->FixParameter(4, fFunc->GetParameter(4));
    161163    for (int i=5; i<fFunc->GetNpar(); i++)
    162164        fFunc->FixParameter(i, fFunc->GetParameter(i));
     
    297299    const Int_t    l1 = w<=0 ? 0 : (Int_t)TMath::Ceil(-TMath::Log10(w));
    298300    const Int_t    l2 = m<=0 ? 0 : (Int_t)TMath::Ceil(-TMath::Log10(m));
    299     const TString fmt = Form("\\sigma_{Li/Ma}=%%.1f  \\omega=%%.%df\\circ  E=%%d  B=%%d  (x<%%.%df)  (\\chi_{b}^{2}/ndf=%%.1f  \\chi_{s}^{2}/ndf=%%.1f  c_{0}=%%.1f)",
     301    const TString fmt = Form("\\sigma_{L/M}=%%.1f  \\omega=%%.%df\\circ  E=%%d B=%%d  x<%%.%df  \\tilde\\chi_{b}=%%.1f  \\tilde\\chi_{s}=%%.1f  c=%%.1f  f=%%.2f",
    300302                             l1<1?1:l1+1, l2<1?1:l2+1);
    301303
    302304    TLatex text(x, y, Form(fmt.Data(), fSignificance, w, (int)fEventsExcess,
    303305                           (int)fEventsBackground, m, fChiSqBg, fChiSqSignal,
    304                            fCoefficients[3]));
     306                           fCoefficients[3], fScaleFactor));
    305307
    306308    text.SetBit(TLatex::kTextNDC);
  • trunk/MagicSoft/Mars/mhflux/MHAlpha.cc

    r7122 r7142  
    139139    binsa.SetEdges(18, 0, 90);
    140140    binse.SetEdgesLog(15, 10, 100000);
    141     binst.SetEdgesCos(50, 0, 60);
     141    binst.SetEdgesASin(51, -0.005, 0.505);
    142142    binse.Apply(fHEnergy);
    143143    binst.Apply(fHTheta);
     
    818818
    819819        if (hof ? fit.Fit(*hon, *hof, alpha) : fit.Fit(*hon))
    820             *fLog << dbg << "Bin " << i << ": sigma=" << fit.GetSignificance() << " omega=" << fit.GetGausSigma() << " events=" << fit.GetEventsExcess() << endl;
     820        {
     821            *fLog << dbg << "Bin " << i << ": sigma=" << fit.GetSignificance() << " omega=" << fit.GetGausSigma() << " events=" << fit.GetEventsExcess() << " scale=" << fit.GetScaleFactor() << endl;
     822            fit.PaintResult();
     823        }
    821824        /*
    822825        if (fit.FitEnergy(fHist, fOffData, i, kTRUE))
  • trunk/MagicSoft/Mars/mhflux/MHCollectionArea.cc

    r7094 r7142  
    9595    MBinning binsa, binse, binst;
    9696    binse.SetEdgesLog(15, 10, 1000000);
    97     binst.SetEdgesCos(50, 0, 60);
     97    binst.SetEdgesASin(51, -0.005, 0.505);
    9898
    9999    binse.Apply(fHEnergy);
     
    289289    if (TString(option)=="paint4")
    290290    {
    291         const TString txt = Form("A_{eff}=%.0fm^{2}  A_{abs}=%.0fm^{2}  r=%.0fm",
    292                                  GetCollectionAreaEff(),
     291        //const TString txt = Form("A_{eff}=%.0fm^{2}  A_{abs}=%.0fm^{2}  r=%.0fm",
     292        //                         GetCollectionAreaEff(),
     293        //                         GetCollectionAreaAbs(), fMcAreaRadius);
     294        const TString txt = Form("A_{abs}=%.0fm^{2}  r=%.0fm",
    293295                                 GetCollectionAreaAbs(), fMcAreaRadius);
    294296
  • trunk/MagicSoft/Mars/mhflux/MHDisp.cc

    r7122 r7142  
    203203
    204204    // Now we can safly derotate both position...
    205     TVector2 srcp(fSrcPos->GetXY());
     205    TVector2 srcp;
     206    if (fSrcPos)
     207        srcp = fSrcPos->GetXY();
     208
    206209    if (rho!=0)
    207210    {
     
    211214    }
    212215
    213     if (fSrcPos)
    214     {
    215         pos1 -= srcp*fMm2Deg;
    216         pos2 -= srcp*fMm2Deg;
    217     }
     216    pos1 -= srcp*fMm2Deg;
     217    pos2 -= srcp*fMm2Deg;
    218218
    219219    fHist.Fill(pos1.X(), pos1.Y(), 0.0, w*gweight);
  • trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc

    r7115 r7142  
    410410    // setup binning
    411411    MBinning btheta("BinningTheta");
    412     btheta.SetEdgesCos(100, 0, 60);
     412    btheta.SetEdgesASin(51, -0.005, 0.505);
    413413
    414414    MBinning btime("BinningDeltaT");
  • trunk/MagicSoft/Mars/mhflux/MHEnergyEst.cc

    r6983 r7142  
    9696    MBinning binsi, binse, binst, binsr;
    9797    binse.SetEdgesLog(15, 10, 1000000);
    98     binst.SetEdgesCos(50, 0, 60);
     98    binst.SetEdgesASin(51, -0.005, 0.505);
    9999    binsi.SetEdges(10, 0, 400);
    100100    binsr.SetEdges(50, -1.3, 1.3);
  • trunk/MagicSoft/Mars/mhflux/MMcSpectrumWeight.cc

    r7130 r7142  
    7272
    7373#include <TF1.h>
     74#include <TH1.h>
    7475
    7576#include "MLog.h"
     
    7980#include "MParameters.h"
    8081
     82#include "MPointingPos.h"
     83
    8184#include "MMcEvt.hxx"
    8285#include "MMcCorsikaRunHeader.h"
     
    106109    fAllowChange = kFALSE;
    107110
    108     fFunc   = NULL;
    109     fMcEvt  = NULL;
    110     fWeight = NULL;
     111    fFunc      = NULL;
     112    fMcEvt     = NULL;
     113    fWeight    = NULL;
     114    fZdWeights = NULL;
     115    fPointing  = NULL;
    111116}
    112117
     
    150155    if (!fWeight)
    151156        return kFALSE;
     157
     158    if (!fZdWeights)
     159        return kTRUE;
     160
     161    fPointing = (MPointingPos*)pList->FindObject("MPointingPos");
     162    if (!fPointing)
     163    {
     164        *fLog << err << "MPointingPos not found... abort." << endl;
     165        return kFALSE;
     166    }
    152167
    153168    return kTRUE;
     
    362377    const Double_t e = fMcEvt->GetEnergy();
    363378
    364     fWeight->SetVal(fFunc->Eval(e));
     379    Double_t w = 1;
     380
     381    if (fZdWeights)
     382    {
     383        const Int_t i = fZdWeights->GetXaxis()->FindFixBin(fPointing->GetZd());
     384        w = fZdWeights->GetBinContent(i);
     385        cout << i << " " << w << " " << fPointing->GetZd() << endl;
     386    }
     387
     388    fWeight->SetVal(fFunc->Eval(e)*w);
    365389
    366390    return kTRUE;
  • trunk/MagicSoft/Mars/mhflux/MMcSpectrumWeight.h

    r7094 r7142  
    77
    88class TF1;
     9class TH1;
    910class MParList;
    1011class MMcEvt;
    1112class MParameterD;
     13class MPointingPos;
    1214class MMcCorsikaRunHeader;
    1315
     
    1719    const MMcEvt *fMcEvt;   // Pointer to the container with the MC energy
    1820    MParameterD  *fWeight;  // Pointer to the output MWeight container
     21    MPointingPos *fPointing;
    1922
    2023    TString fNameWeight;    // Name of the MWeight container
     
    2225
    2326    TF1 *fFunc;             // Function calculating the weights
     27    TH1 *fZdWeights;        // Set additional ZA weights
    2428
    2529    Double_t fOldSlope;     // Slope of energy spectrum generated with Corsika
     
    5963    void SetEnergyRange(Double_t min=-2, Double_t max=-1) { fEnergyMin=min; fEnergyMax=max; }
    6064    void SetOldSlope(Double_t s=-2.6) { fOldSlope=s; }
     65    void SetZdWeights(TH1 *h=0) { fZdWeights = h; }
    6166    Bool_t Set(const MMcCorsikaRunHeader &h);
    6267
  • trunk/MagicSoft/Mars/mimage/MHVsSize.cc

    r6961 r7142  
    9999    binsl.SetEdges(   100,    0, 296.7/2);
    100100    binsd.SetEdges(   100,    0, 600);
    101     binsc.SetEdgesLog(100, 1e-5, 5e-3);
     101    binsc.SetEdgesLog(100, 3e-3, 1);
    102102    binsa.SetEdges(   100,    0, 445*45);
    103103    binsm.SetEdges(   100, -445, 445);
     
    269269    fWidth.Fill( fHillas->GetSize(), scale*fHillas->GetWidth(),      w);
    270270    fDist.Fill(  fHillas->GetSize(), scale*src->GetDist(),           w);
    271     fConc1.Fill( fHillas->GetSize(), scale*fNewImagePar->GetConc1(), w);
     271    fConc1.Fill( fHillas->GetSize(), fNewImagePar->GetConc1(),      w);
    272272    fArea.Fill(  fHillas->GetSize(), scale*scale*fHillas->GetArea(), w);
    273273    fM3Long.Fill(fHillas->GetSize(), scale*fHillasExt->GetM3Long()*TMath::Sign(1.0f, src->GetCosDeltaAlpha()), w);
  • trunk/MagicSoft/Mars/mjobs/MDataSet.h

    r6958 r7142  
    6060    static Int_t  AddFilesToChain(MDirIter &files, TChain &chain);
    6161
     62    const TList &GetSequencesOn() const  { return fSequencesOn; }
     63    const TList &GetSequencesOff() const { return fSequencesOff; }
     64
    6265    Bool_t AddFiles(MRead &read) const;
    6366    Bool_t AddFilesOn(MRead &read) const;
  • trunk/MagicSoft/Mars/mjobs/MJCut.cc

    r7115 r7142  
    448448
    449449    // Initialize default binnings
    450     MBinning bins1(18, 0,  90,   "BinningAlpha",     "lin");
    451     MBinning bins2(15, 10, 1e6 , "BinningEnergyEst", "log");
    452     MBinning bins3(50, 0,  60,   "BinningTheta",     "cos");
     450    MBinning bins1(18,  0,     90,    "BinningAlpha",     "lin");
     451    MBinning bins2(15, 10,     1e6 , "BinningEnergyEst", "log");
     452    MBinning bins3(51, -0.005, 0.505, "BinningTheta",     "asin");
    453453    MBinning bins4("BinningFalseSource");
    454454    MBinning bins5("BinningWidth");
     
    559559    tlist2.AddToList(&scalc);
    560560    tlist2.AddToList(&hcalc);
    561     //if (fIsWobble)
     561    if (fIsWobble)
    562562        tlist2.AddToList(&hcalc2);
    563563    //tlist2.AddToList(&taskenv1);
  • trunk/MagicSoft/Mars/mjobs/MJOptimize.h

    r7121 r7142  
    111111    void SetNumMaxCalls(UInt_t num=0) { fNumMaxCalls=num; }
    112112    void SetTolerance(Float_t tol=0)  { fTolerance=tol; }
    113     void EnableTestTrain(Int_t b=2)   { fTestTrain=b; }
     113    void EnableTestTrain(Int_t b=1)   { fTestTrain=b; } // Use 1 and -1
    114114
    115115    // Parameter access
  • trunk/MagicSoft/Mars/mpointing/MSrcPosCam.cc

    r7109 r7142  
    6262// Copy constructor, set default name and title
    6363//
    64 MSrcPosCam::MSrcPosCam(const MSrcPosCam &p) : fX(p.fX), fY(p,fY)
     64MSrcPosCam::MSrcPosCam(const MSrcPosCam &p) : fX(p.fX), fY(p.fY)
    6565{
    6666    fName  = gsDefName.Data();
     
    6969
    7070// -----------------------------------------------------------------------
     71//
     72// Print contents
    7173//
    7274void MSrcPosCam::Print(Option_t *) const
     
    7880}
    7981
     82// -----------------------------------------------------------------------
     83//
     84// Set fX to v.X() and fY to v.Y()
     85//
    8086void MSrcPosCam::SetXY(const TVector2 &v)
    8187{
     
    8490}
    8591
     92// -----------------------------------------------------------------------
     93//
     94// Add v.X() to fX and v.Y() to fY
     95//
     96void MSrcPosCam::Add(const TVector2 &v)
     97{
     98    fX+=v.X();
     99    fY+=v.Y();
     100}
     101
     102// -----------------------------------------------------------------------
     103//
     104// Get TVector2(fX, fY)
     105//
    86106TVector2 MSrcPosCam::GetXY() const
    87107{
  • trunk/MagicSoft/Mars/mpointing/MSrcPosCam.h

    r7109 r7142  
    2525    void SetXY(const TVector2 &v);
    2626
     27    void Add(const TVector2 &v);
     28
    2729    Float_t GetX() const             { return fX; }
    2830    Float_t GetY() const             { return fY; }
    2931    TVector2 GetXY() const;
     32
    3033
    3134    void Print(Option_t *opt=NULL) const;
  • trunk/MagicSoft/Mars/mpointing/Makefile

    r6048 r7142  
    2828           MSrcPosCam.cc \
    2929           MSrcPosCalc.cc \
     30           MSrcPosCorrect.cc \
    3031           MSrcPosFromModel.cc
    3132
  • trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.cc

    r7130 r7142  
    6969//
    7070MRFEnergyEst::MRFEnergyEst(const char *name, const char *title)
    71     : fNumTrees(-1), fNumTry(-1), fNdSize(-1), fData(0), fEnergyEst(0),
    72     fTestMatrix(0)
     71    : fNumTrees(-1), fNumTry(-1), fNdSize(-1), fDebug(kFALSE),
     72    fData(0), fEnergyEst(0), fTestMatrix(0)
    7373{
    7474    fName  = name  ? name  : gsDefName.Data();
     
    9191    }
    9292
    93     const Int_t ncols = matrixtrain.GetM().GetNcols();
    94     const Int_t nrows = matrixtrain.GetM().GetNrows();
     93    const TMatrix &m = matrixtrain.GetM();
     94
     95    const Int_t ncols = m.GetNcols();
     96    const Int_t nrows = m.GetNrows();
    9597    if (ncols<=0 || nrows <=0)
    9698    {
     
    114116    }
    115117
     118    const Int_t nobs = 3; // Number of obsolete columns
     119
    116120    MDataArray usedrules;
    117     for(Int_t i=0; i<ncols-3; i++) // -3 is important!!!
     121    for(Int_t i=0; i<ncols-nobs; i++) // -3 is important!!!
    118122        usedrules.AddEntry((*matrixtrain.GetColumns())[i].GetRule());
    119 
    120     const TMatrix &m = matrixtrain.GetM();
    121123
    122124    // training of RF for each energy bin
     
    140142        }
    141143
    142         const Bool_t valid = irow1*irow0>0;
    143 
    144         if (!valid)
     144        const Bool_t invalid = irow1==0 || irow0==0;
     145
     146        if (invalid)
    145147            *fLog << warn << "WARNING - Skipping";
    146148        else
    147149            *fLog << inf << "Training RF for";
    148150
    149         *fLog << " energy bin " << ie << " (" << grid[ie] << ", " << grid[ie+1] << ")" << endl;
    150 
    151         if (!valid)
     151        *fLog << " energy bin " << ie << " (" << grid[ie] << ", " << grid[ie+1] << ") " << irow0 << " " << irow1 << endl;
     152
     153        if (invalid)
    152154            continue;
    153155
    154         gLog.SetNullOutput(kTRUE);
     156        if (fDebug)
     157            gLog.SetNullOutput(kTRUE);
    155158
    156159        // last column must be removed (true energy col.)
    157         mat1.ResizeTo(irow1, ncols-1);
    158         mat0.ResizeTo(irow0, ncols-1);
     160        mat1.ResizeTo(irow1, ncols-nobs);
     161        mat0.ResizeTo(irow0, ncols-nobs);
    159162
    160163        // create MHMatrix as input for RF
     
    183186        evtloop.SetParList(&plist);
    184187
    185         gLog.SetNullOutput(kFALSE);
     188        if (fDebug)
     189            gLog.SetNullOutput(kFALSE);
    186190
    187191        if (!evtloop.Eventloop())
    188192            return kFALSE;
    189193
     194        const Double_t E = (log10(grid[ie])+log10(grid[ie+1]))/2;
     195
    190196        // save whole forest
    191197        MRanForest *forest=(MRanForest*)plist.FindObject("MRanForest");
    192         const TString title = Form("%f", TMath::Sqrt(grid[ie]*grid[ie+1]));
    193         //const TString title = Form("%f", (grid[ie]+grid[ie+1])/2);
     198        const TString title = Form("%.10f", E);
    194199        forest->SetTitle(title);
    195200        forest->Write(title);
     
    203208    return kTRUE;
    204209}
    205 /*
    206 Int_t MRFEnergyEst::Test(const MHMatrix &matrixtest)
    207 {
    208     gLog.Separator("MRFEnergyEst - Test");
    209 
    210     const Int_t ncols = matrixtest.GetM().GetNcols();
    211     const Int_t nrows = matrixtest.GetM().GetNrows();
    212 
    213     if (ncols<=0 || nrows <=0)
    214     {
    215         *fLog << err << dbginf << "No. of columns or no. of rows of matrixtrain equal 0 ... aborting." << endl;
    216         return kFALSE;
    217     }
    218 
    219     if (!ReadForests())
    220     {
    221         *fLog << err << dbginf << "Reading RFs failed... aborting." << endl;
    222         return kFALSE;
    223     }
    224 
    225     const Int_t nbins=fEForests.GetSize();
    226 
    227     Double_t elow =  FLT_MAX;
    228     Double_t eup  = -FLT_MAX;
    229 
    230     for(Int_t j=0;j<nbins;j++)
    231     {
    232         elow = TMath::Min(atof(fEForests[j]->GetTitle()), elow);
    233         eup  = TMath::Max(atof(fEForests[j]->GetTitle()), eup);
    234     }
    235 
    236     TH1F hres("hres", "", 1000, -10, 10);
    237     TH2F henergy("henergy", "",100, elow, eup,100, elow, eup);
    238 
    239     const TMatrix &m=matrixtest.GetM();
    240     for(Int_t i=0;i<nrows;i++)
    241     {
    242         Double_t etrue = m(i,ncols-1);
    243         Double_t eest  = 0;
    244         Double_t hsum  = 0;
    245 
    246         for(Int_t j=0;j<nbins;j++)
    247         {
    248             const TVector  v = TMatrixFRow_const(m,i);
    249 
    250             const Double_t h = ((MRanForest*)fEForests[j])->CalcHadroness(v);
    251             const Double_t e = atof(fEForests[j]->GetTitle());
    252 
    253             hsum += h;
    254             eest += h*e;
    255         }
    256         eest /= hsum;
    257         eest  = pow(10., eest);
    258 
    259         //if (etrue>80.)
    260         //    hres.Fill((eest-etrue)/etrue);
    261 
    262         henergy.Fill(log10(etrue),log10(eest));
    263     }
    264 
    265     if(gStyle)
    266         gStyle->SetOptFit(1);
    267 
    268     // show results
    269     TCanvas *c=MH::MakeDefCanvas("c","",300,900);
    270 
    271     c->Divide(1,3);
    272     c->cd(1);
    273     henergy.SetTitle("Estimated vs true energy");
    274     henergy.GetXaxis()->SetTitle("log10(E_{true}[GeV])");
    275     henergy.GetYaxis()->SetTitle("log10(E_{est}[GeV])");
    276     henergy.DrawCopy();
    277 
    278     c->cd(2);
    279     TH1F *hptr=(TH1F*)henergy.ProfileX("_px",1,100,"S");
    280     hptr->SetTitle("Estimated vs true energy - profile");
    281     hptr->GetXaxis()->SetTitle("log10(E_{true}[GeV])");
    282     hptr->GetYaxis()->SetTitle("log10(E_{est}[GeV])");
    283     hptr->DrawCopy();
    284 
    285     c->cd(3);
    286     hres.Fit("gaus");
    287     hres.SetTitle("Energy resolution for E_{true}>80Gev");
    288     hres.GetXaxis()->SetTitle("(E_{estimated}-E_{true})/E_{true})");
    289     hres.GetYaxis()->SetTitle("counts");
    290     hres.DrawCopy();
    291 
    292     c->GetPad(1)->SetGrid();
    293     c->GetPad(2)->SetGrid();
    294     c->GetPad(3)->SetGrid();
    295 
    296     return kTRUE;
    297 }
    298 */
    299 Int_t MRFEnergyEst::ReadForests(MParList *plist)
     210
     211Int_t MRFEnergyEst::ReadForests(MParList &plist)
    300212{
    301213    TFile fileRF(fFileName,"read");
     
    321233
    322234        fEForests.Add(forest);
    323 
    324     }
    325 
    326     if (plist)
    327     {
    328         fData = (MDataArray*)plist->FindCreateObj("MDataArray");
    329         fData->Read("rules");
    330     }
    331 
    332     fileRF.Close();
     235    }
     236
     237    if (fData->Read("rules")<=0)
     238    {
     239        *fLog << err << "ERROR - Reading 'rules' from file " << fFileName << endl;
     240        return kFALSE;
     241    }
    333242
    334243    return kTRUE;
     
    341250        return kFALSE;
    342251
    343     if (!ReadForests(plist))
     252    fData = (MDataArray*)plist->FindCreateObj("MDataArray");
     253    if (!fData)
     254        return kFALSE;
     255
     256    if (!ReadForests(*plist))
    344257    {
    345258        *fLog << err << "Reading RFs failed... aborting." << endl;
    346259        return kFALSE;
    347260    }
     261
     262    *fLog << inf << "RF read from " << fFileName << endl;
    348263
    349264    if (fTestMatrix)
    350265        return kTRUE;
    351266
    352     if (!fData)
    353     {
    354         *fLog << err << "MDataArray not found... aborting." << endl;
    355         return kFALSE;
    356     }
     267    fData->Print();
    357268
    358269    if (!fData->PreProcess(plist))
     
    387298
    388299        hsum += h;
    389         eest += h*e;
    390     }
    391 
    392     fEnergyEst->SetVal(eest/hsum);
     300        eest += e*h;
     301    }
     302
     303    fEnergyEst->SetVal(pow(10, eest/hsum));
    393304    fEnergyEst->SetReadyToSave();
    394305
    395306    return kTRUE;
    396307}
     308
     309// --------------------------------------------------------------------------
     310//
     311//
     312Int_t MRFEnergyEst::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
     313{
     314    Bool_t rc = kFALSE;
     315    if (IsEnvDefined(env, prefix, "FileName", print))
     316    {
     317        rc = kTRUE;
     318        SetFileName(GetEnvValue(env, prefix, "FileName", fFileName));
     319    }
     320    if (IsEnvDefined(env, prefix, "Debug", print))
     321    {
     322        rc = kTRUE;
     323        SetDebug(GetEnvValue(env, prefix, "Debug", fDebug));
     324    }
     325    return rc;
     326}
  • trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.h

    r7134 r7142  
    2323    Int_t        fNdSize;    // Training parameters
    2424
     25    Bool_t       fDebug;     // Debugging of eventloop while training on/off
     26
    2527    TString      fFileName;
    2628    TObjArray    fEForests;
     
    3436    Int_t Process();
    3537
    36     Int_t ReadForests(MParList *plist=NULL);
     38    Int_t ReadForests(MParList &plist);
     39
     40    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
    3741
    3842public:
     
    4145    void  SetFileName(TString str)     { fFileName = str; }
    4246
    43     void  SetNumTrees(Int_t n=-1)   { fNumTrees = n; }
    44     void  SetNdSize(Int_t n=-1)     { fNdSize   = n; }
    45     void  SetNumTry(Int_t n=-1)     { fNumTry   = n; }
     47    void  SetNumTrees(Int_t n=-1)      { fNumTrees = n; }
     48    void  SetNdSize(Int_t n=-1)        { fNdSize   = n; }
     49    void  SetNumTry(Int_t n=-1)        { fNumTry   = n; }
    4650
    4751    void  SetTestMatrix(MHMatrix *m=0) { fTestMatrix=m; }
    4852    void  InitMapping(MHMatrix *m=0)   { fTestMatrix=m; }
     53
     54    void SetDebug(Bool_t b=kTRUE)      { fDebug = b; }
    4955
    5056    Int_t Train(const MHMatrix &n, const TArrayD &grid);
  • trunk/MagicSoft/Mars/mranforest/MRanTree.cc

    r4647 r7142  
    447447    // are coded into fBestVar:
    448448    // status of node kt = TMath::Sign(1,fBestVar[kt])
    449     // class  of node kt = fBestVar[kt]+2 (class defined by larger
    450     //  node population, actually not used)
     449    // class  of node kt = fBestVar[kt]+2
     450    //  (class defined by larger node population, actually not used)
    451451    // hadronness assigned to node kt = fBestSplit[kt]
    452452
     
    463463}
    464464
    465 Double_t MRanTree::TreeHad(const TMatrixRow &event)
     465Double_t MRanTree::TreeHad(const TMatrixFRow_const &event)
    466466{
    467467    Int_t kt=0;
     
    504504Bool_t MRanTree::AsciiWrite(ostream &out) const
    505505{
    506     TString str;
     506    out.width(5);
     507    out << fNumNodes << endl;
     508
    507509    Int_t k;
    508 
    509     out.width(5);out<<fNumNodes<<endl;
    510 
    511     for (k=0;k<fNumNodes;k++)
    512     {
    513         str=Form("%f",GetBestSplit(k));
     510    for (k=0; k<fNumNodes; k++)
     511    {
     512        TString str=Form("%f", GetBestSplit(k));
    514513
    515514        out.width(5);  out << k;
     
    521520        out.width(5);  out << GetNodeClass(k);
    522521    }
    523     out<<endl;
    524 
    525     return k==fNumNodes;
    526 }
     522    out << endl;
     523
     524    return kTRUE;
     525}
  • trunk/MagicSoft/Mars/mranforest/MRanTree.h

    r2307 r7142  
    1616class TMatrix;
    1717class TMatrixRow;
     18class TMatrixFRow_const;
    1819class TVector;
    1920class TRandom;
     
    8485
    8586    Double_t TreeHad(const TVector &event);
    86     Double_t TreeHad(const TMatrixRow &event);
     87    Double_t TreeHad(const TMatrixFRow_const &event);
    8788    Double_t TreeHad(const TMatrix &m, Int_t ievt);
    8889    Double_t TreeHad();
Note: See TracChangeset for help on using the changeset viewer.