Changeset 8706


Ignore:
Timestamp:
08/24/07 13:58:50 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/macros/optim/optimonoff.C

    r8671 r8706  
    66
    77    // ------------------- Xi -----------------------
    8     opt.FixParameter(0, 1.3245);
    9     opt.FixParameter(6, 8.2957);
    10     opt.FixParameter(7, 0.8677);
    11 
     8    opt.FixParameter( 0, 1.15136);
     9    opt.FixParameter( 8, 0.0681437);
     10    opt.FixParameter( 9, 2.62932);
     11    opt.FixParameter(10, 1.51279);
     12    opt.FixParameter(11, 0.0507821);
     13                 
    1214    // --------------- Theta Sq ---------------------
    13     opt.SetParameter(1, 0.204);
     15    opt.FixParameter( 1, 0.215);
    1416
    1517    // ----------------- Area -----------------------
    16     opt.SetParameter(2, 0.215);
    17     opt.SetParameter(3, 5.486);
    18     opt.SetParameter(4, 0.0897);
     18    opt.SetParameter( 2, 0.21);
     19    opt.SetParameter( 3, 5.6);
     20    opt.SetParameter( 4, 0.083);
    1921
    2022    // ----------------- M3L ------------------------
    21     opt.FixParameter(5, -0.07);
     23    opt.FixParameter( 5, -0.07);
     24
     25    // ---------------- Slope -----------------------
     26    opt.FixParameter( 6, 7.2);
     27    opt.FixParameter( 7, 0.5);
    2228
    2329    // ----------------- Fit ------------------------
  • trunk/MagicSoft/Mars/macros/optim/optimwobble.C

    r8671 r8706  
    66
    77    // ------------------- Xi -----------------------
    8     opt.FixParameter(0, 1.221);
    9     opt.FixParameter(6, 13.425);
    10     opt.FixParameter(7, 1.04343);
     8    opt.FixParameter( 0, 1.15136);
     9    opt.FixParameter( 8, 0.0681437);
     10    opt.FixParameter( 9, 2.62932);
     11    opt.FixParameter(10, 1.51279);
     12    opt.FixParameter(11, 0.0507821);
    1113                 
    1214    // --------------- Theta Sq ---------------------
    13     opt.SetParameter(1, 0.23);
     15    opt.FixParameter( 1, 0.215);
    1416
    1517    // ----------------- Area -----------------------
    16     opt.SetParameter(2, 0.25);
    17     opt.SetParameter(3, 5.21);
    18     opt.SetParameter(4, 0.11);
     18    opt.SetParameter( 2, 0.21);
     19    opt.SetParameter( 3, 5.6);
     20    opt.SetParameter( 4, 0.083);
    1921
    2022    // ----------------- M3L ------------------------
    21     opt.SetParameter(5, -0.089);
     23    opt.FixParameter( 5, -0.07);
     24
     25    // ---------------- Slope -----------------------
     26    opt.FixParameter( 6, 7.2);
     27    opt.FixParameter( 7, 0.5);
    2228
    2329    // ----------------- Fit ------------------------
     
    2834    fit.SetMinimizationStrategy(MAlphaFitter::kSignificanceLogExcess);
    2935
     36    // For wobble mode with three off-regions
     37    //  (sets also ScaleMode to kUser)
     38    fit.SetScaleUser(1./3);
     39
    3040    // ----------------- Cuts -----------------------
    3141
    3242    MFMagicCuts cuts;
    33     cuts.SetThetaCut(MFMagicCuts::kWobble);
     43    cuts.SetThetaCut(MFMagicCuts::kOn);
    3444
    3545    /* You can also try (switch on scaling):
     
    4757    opt.SetDisplay(d);
    4858
    49     // opt.SetPathOut("optimwobble.root");
    50     opt.RunOnOff("wobblelza-abs.root", &cuts, &fit);
     59    opt.RunOnOff("ganymed00000001-summary.root", &cuts, &fit);
    5160}
  • trunk/MagicSoft/Mars/macros/train/traindisp.C

    r8634 r8706  
     1/* ======================================================================== *\
     2!
     3! *
     4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
     5! * Software. It is distributed to you in the hope that it can be a useful
     6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
     7! * It is distributed WITHOUT ANY WARRANTY.
     8! *
     9! * Permission to use, copy, modify and distribute this software and its
     10! * documentation for any purpose is hereby granted without fee,
     11! * provided that the above copyright notice appear in all copies and
     12! * that both that copyright notice and this permission notice appear
     13! * in supporting documentation. It is provided "as is" without express
     14! * or implied warranty.
     15! *
     16!
     17!
     18!   Author(s): Thomas Bretz, 11/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
     19!
     20!   Copyright: MAGIC Software Development, 2000-2007
     21!
     22!
     23\* ======================================================================== *//////////////////////////////////////////////////////////////////////////////
     24
     25/////////////////////////////////////////////////////////////////////////////
     26//
     27// traindisp.C
     28// ===========
     29//
     30// Trains a random forest for disp estimation.
     31//
     32// The additional code below shows how the MagicCuts can be used in
     33// training and testing. There is also code which allows to change the
     34// slope of the input spectrum. If a min- or max-break energy is given
     35// the new slope is only applied in this region. Further possibilities
     36// for additional cuts are shown.
     37//
     38// SequencesOn:   Monte Carlo Sequences used for training
     39// SequencesOff:  Monte Carlo Sequences used for testing
     40//
     41// Use:
     42//  opt.AddPreCut    to use cut for test and training
     43//  opt.AddTestCut   to use cut for test only
     44//  opt.AddTrainCut  to use cut for train only
     45//  opt.AddPreTask   a task executed before filling the matrix/evaluating the RF
     46//  opt.AddPostTask  a task executed before training, after evaluating the RF
     47//
     48/////////////////////////////////////////////////////////////////////////////
     49
    150void traindisp()
    251{
    3     MDataSet set("mctesttrain.txt");
     52    MDataSet set("mcsponde/mcdataset-for-training.txt");
    453    set.SetNumAnalysis(1);            // Necessary
    554
     
    1059    //opt.SetDebug();
    1160
     61    // These are control parameters how to train the random forest (use with care!)
     62    //opt.SetNumTrees(100);
     63    //opt.SetNdSize(5);
     64    //opt.SetNumTry(0);
     65
    1266    // ------- Parameters to train Random Forest --------
    1367    opt.AddParameter("MHillas.fLength");
     
    1569    opt.AddParameter("MHillas.fSize");
    1670    opt.AddParameter("MNewImagePar.fLeakage1");
    17     opt.AddParameter("MNewImagePar.fLeakage2");
    18     opt.AddParameter("MNewImagePar.fConc");
    19     opt.AddParameter("MNewImagePar.fConc1");
    2071    opt.AddParameter("MPointingPos.fZd");
    21     opt.AddParameter("MNewImagePar.fUsedArea");
    22     opt.AddParameter("MNewImagePar.fCoreArea");
    23     opt.AddParameter("MNewImagePar.fNumUsedPixels");
    24     opt.AddParameter("MNewImagePar.fNumCorePixels");
    25     opt.AddParameter("MImagePar.fSizeSinglePixels");
    26     opt.AddParameter("MHillasExt.fM3Long*sign(MHillasSrc.fCosDeltaAlpha)");
    27     opt.AddParameter("MHillasExt.fAsym*sign(MHillasSrc.fCosDeltaAlpha)");
     72    opt.AddParameter("MHillasExt.fSlopeLong*sign(MHillasSrc.fCosDeltaAlpha)");
     73    //opt.AddParameter("MNewImagePar.fLeakage2");
     74    //opt.AddParameter("MNewImagePar.fConc");
     75    //opt.AddParameter("MNewImagePar.fConc1");
     76    //opt.AddParameter("MNewImagePar.fUsedArea");
     77    //opt.AddParameter("MNewImagePar.fCoreArea");
     78    //opt.AddParameter("MNewImagePar.fNumUsedPixels");
     79    //opt.AddParameter("MNewImagePar.fNumCorePixels");
     80    //opt.AddParameter("MImagePar.fSizeSinglePixels");
     81    //opt.AddParameter("MHillasExt.fM3Long*sign(MHillasSrc.fCosDeltaAlpha)");
     82    //opt.AddParameter("MHillasExt.fAsym*sign(MHillasSrc.fCosDeltaAlpha)");
    2883
    2984    // -------------------- Run ----------------------------
     
    3893     cuts.SetThetaCut(MFMagicCuts::kOn);
    3994
    40      TArrayD arr(10);
    41      arr[0]=  1.3245;
    42      arr[1]=  0.208700;
    43      arr[2]=  0.229200;
    44      arr[3]=  5.305200;
    45      arr[4]=  0.098930;
    46      arr[5]= -0.082950;
    47      arr[6]=  8.2957;
    48      arr[7]=  0.8677;
     95     TArrayD arr(13);
     96     arr[0]  =  1.15136;
     97     arr[1]  =  0.215;
     98     arr[2]  =  0.215468;
     99     arr[3]  =  5.63973;
     100     arr[4]  =  0.0836169;
     101     arr[5]  = -0.07;
     102     arr[6]  =  7.2;
     103     arr[7]  =  0.5;
     104     arr[8]  =  0.0681437;
     105     arr[9]  =  2.62932;
     106     arr[10] =  1.51279;
     107     arr[11] =  0.0507821;
    49108
    50109     cuts.SetVariables(arr);
     
    58117     -------------------- Other cuts ----------------------
    59118     opt.AddPreCut("MNewImagePar.fLeakage1<0.0001");
    60     */
    61 
    62119     opt.AddPreCut("MHillas.fSize>200");
    63120     opt.AddPreCut("MHillasSrc.fDCA*MGeomCam.fConvMm2Deg<0.3");
     121     opt.AddPreCut("MPointingPos.fZd<25");
     122
     123     ------------------ Zd distribution -------------------
     124     TFile file("ganymed00001111.root");
     125
     126     MStatusArray arr;
     127     if (arr.Read()<=0)
     128        return;
     129     TH1D *vstime = (TH1D*)arr.FindObjectInCanvas("Theta",  "TH1D", "OnTime");
     130     if (!vstime)
     131         return;
     132
     133     MMcSpectrumWeight weight;
     134     weight.SetWeightsZd(vstime);
     135     opt.AddPreTask(&weight);
     136
     137     ---------------------- Histogram  --------------------
     138
     139     MHn hist("MyHist", "Energy Residual (lg E_{est} - lg E_{mc})");
     140
     141     MBinning bins(50, -0.5, 0.5);
     142
     143     hist.AddHist("MHillasExt.fM3Long*sign(MHillasSrc.fCosDeltaAlpha)*3.37e-3", "Disp.fVal-MHillasSrc.fDist*3.37e-3");
     144     hist.InitName("ResM3l;M3Long;ResidualDist");
     145     hist.InitTitle(";M3l [\\circ];Disp-Dist [\\circ];");
     146     hist.SetDrawOption("colz profx");
     147     hist.SetBinnings(&bins);
     148
     149     hist.AddHist("MHillasExt.fAsym*sign(MHillasSrc.fCosDeltaAlpha)*3.37e-3", "Disp.fVal-MHillasSrc.fDist*3.37e-3");
     150     hist.InitName("ResAsym;M3Long;ResidualDist");
     151     hist.InitTitle(";Asym [\\circ];Disp-Dist [\\circ];");
     152     hist.SetDrawOption("colz profx");
     153     hist.SetBinnings(&bins);
     154
     155     MFillH fill(&hist, "", "FillMyHist");
     156     //fill.SetWeight(); // Enable weights to be used to fill this histogram
     157     opt.AddTestTask(&fill);
     158
     159     ------------------------------------------------------
     160    */
    64161
    65162     // The number is the number of events read from the file
     
    67164     opt.Train("rf-disp.root", set, 30000);
    68165}
    69 /*
    70  // SequencesOn:   Monte Carlo Sequences used for training
    71  // SequencesOff:  Monte Carlo Sequences used for testing
    72 
    73  // Use:
    74  // opt.AddPreCut    to use cut for test and training
    75  // opt.AddTestCut   to use cut for test only
    76  // opt.AddTrainCut  to use cut for train only
    77  */
  • trunk/MagicSoft/Mars/macros/train/trainenergy.C

    r8634 r8706  
    1818!   Author(s): Thomas Bretz, 11/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2006
     20!   Copyright: MAGIC Software Development, 2000-2007
    2121!
    2222!
     
    3636// for additional cuts are shown.
    3737//
     38// SequencesOn:   Monte Carlo Sequences used for training
     39// SequencesOff:  Monte Carlo Sequences used for testing
     40//
     41// Use:
     42//  opt.AddPreCut    to use cut for test and training
     43//  opt.AddTestCut   to use cut for test only
     44//  opt.AddTrainCut  to use cut for train only
     45//  opt.AddPreTask   a task executed before filling the matrix/evaluating the RF
     46//  opt.AddPostTask  a task executed before training, after evaluating the RF
     47//
    3848/////////////////////////////////////////////////////////////////////////////
    3949void trainenergy()
    4050{
    41     MDataSet set("mcdataset.txt");
     51    MDataSet set("mcsponde/mcdataset-for-training.txt");
    4252    set.SetNumAnalysis(1);            // Necessary
    4353
     
    4858    //opt.SetDebug();
    4959
     60    // These are control parameters how to train the random forest (use with care!)
     61    //opt.SetNumTrees(100);
     62    //opt.SetNdSize(5);
     63    //opt.SetNumTry(0);
     64
    5065    // ------- Parameters to train Random Forest --------
     66    // The following parameters are the best parameters
    5167    opt.AddParameter("MHillas.fSize");
    5268    opt.AddParameter("MHillasSrc.fDist");
    5369    opt.AddParameter("MPointingPos.fZd");
    54     opt.AddParameter("MHillas.GetArea");
    55     opt.AddParameter("MNewImagePar.fUsedArea");
    56     opt.AddParameter("MNewImagePar.fCoreArea");
    5770    opt.AddParameter("MNewImagePar.fLeakage1");
    58     opt.AddParameter("MNewImagePar.fLeakage2");
    59     opt.AddParameter("MNewImagePar.fConc");
    60     opt.AddParameter("MNewImagePar.fConc1");
     71    opt.AddParameter("MHillasExt.fSlopeLong*sign(MHillasSrc.fCosDeltaAlpha)");
     72    // The influence of these parameters is unclear
     73    //opt.AddParameter("MHillasExt.fM3Long*sign(MHillasSrc.fCosDeltaAlpha)");
     74    //opt.AddParameter("MNewImagePar.fConcCOG");
     75    //opt.AddParameter("MHillas.GetArea");
     76    //opt.AddParameter("MNewImagePar.fConc1");
     77    //opt.AddParameter("MNewImagePar.fConc");
     78    //opt.AddParameter("MNewImagePar.fUsedArea");
     79    //opt.AddParameter("MNewImagePar.fCoreArea");
     80    //opt.AddParameter("MNewImagePar.fLeakage2");
     81
     82    // Setup how to train the RF. This one gives best results so far
     83    opt.SetTrainFunc("log(MMcEvt.fEnergy)/log(MHillas.fSize)", "MHillas.fSize^x");
     84    // opt.SetTrainLog(); // Train in log-energy
     85    // opt.SetTrainLin(); // Train just in energy
    6186
    6287    // -------------------- Run ----------------------------
     
    6590    opt.SetDisplay(d);
    6691
     92    // -------------------- Magic-Cuts ----------------------
     93    // It is recommended to test with your cuts, but train with all events
     94
     95    MFMagicCuts cuts;
     96    cuts.SetHadronnessCut(MFMagicCuts::kArea);
     97    cuts.SetThetaCut(MFMagicCuts::kOn);
     98
     99    TArrayD arr(13);
     100    arr[0]  =  1.15136;
     101    arr[1]  =  0.215;
     102    arr[2]  =  0.215468;
     103    arr[3]  =  5.63973;
     104    arr[4]  =  0.0836169;
     105    arr[5]  = -0.07;
     106    arr[6]  =  7.2;
     107    arr[7]  =  0.5;
     108    arr[8]  =  0.0681437;
     109    arr[9]  =  2.62932;
     110    arr[10] =  1.51279;
     111    arr[11] =  0.0507821;
     112
     113    cuts.SetVariables(arr);
     114
     115    // opt.AddPreCut(&cuts);    // add cut for training and testing
     116    // opt.AddTrainCut(&cuts);  // add cut for training only
     117    opt.AddTestCut(&cuts);   // add cut for testing only
     118
    67119    /*
    68      -------------------- Magic-Cuts ----------------------
    69      MFMagicCuts cuts;
    70      cuts.SetHadronnessCut(MFMagicCuts::kArea);
    71      cuts.SetThetaCut(MFMagicCuts::kOn);
     120     -------------------- Energy Slope --------------------
     121     // This is a way to throw away events to a different slope
     122     MFEnergySlope slope(-4.0); // New slope for mc spectrum
     123     opt.AddPreCut(&slope);     // throw away events to change slope
    72124
    73      TArrayD arr(10);
    74      arr[0]=  1.3245;
    75      arr[1]=  0.208700;
    76      arr[2]=  0.229200;
    77      arr[3]=  5.305200;
    78      arr[4]=  0.098930;
    79      arr[5]= -0.082950;
    80      arr[6]=  8.2957;
    81      arr[7]=  0.8677;
    82 
    83      cuts.SetVariables(arr);
    84 
    85      opt.AddPreCut(&cuts);
    86 
    87      -------------------- Energy Slope --------------------
    88      MFEnergySlope slope(-2.8); // New slope for mc spectrum
    89      slope.SetMcMinEnergy(80);  // Set break energy from -2.6 to -2.8
    90      opt.AddPreCut(&slope);     // throw away events to change slope
     125     // This is a way to weight the events to a different spectrum
     126     MMcSpectrumWeight weight;
     127     weight.SetFormula("pow(X/300, -2.31-0.26*log10(X/300))");
     128     opt.SetWeights(&weight);
    91129
    92130     -------------------- Other cuts ----------------------
    93131     opt.AddPreCut("MHillasSrc.fDist*MGeomCam.fConvMm2Deg<1.0");
    94132     opt.AddPreCut("MHillas.fSize>200");
     133
     134     ------------------ Zd distribution -------------------
     135     TFile file("ganymed00001111.root");
     136
     137     MStatusArray arr;
     138     if (arr.Read()<=0)
     139        return;
     140     TH1D *vstime = (TH1D*)arr.FindObjectInCanvas("Theta",  "TH1D", "OnTime");
     141     if (!vstime)
     142         return -1;
     143
     144     MMcSpectrumWeight weight;
     145     weight.SetWeightsZd(vstime);
     146     opt.AddPreTask(&weight);
     147
     148     ---------------------- Histogram  --------------------
     149     MHn hist("MyHist", "Energy Residual (lg E_{est} - lg E_{mc})");
     150
     151     hist.AddHist("MNewImagePar.fConcCOG", "log10(MEnergyEst.fVal)-log10(MMcEvt.fEnergy)");
     152     hist.InitName("ResConc;Conc;EnergyResidual");
     153     hist.InitTitle(";C;\\Delta lg E;");
     154     hist.SetDrawOption("colz profx");
     155
     156     MBinning bins(50, 0, 1);
     157     hist.SetBinnings(&bins);
     158
     159     MFillH fill(&hist, "", "FillMyHist");
     160     //fill.SetWeight(); // Enable weights to be used to fill this histogram
     161     opt.AddTestTask(&fill);
     162
     163     ------------------------------------------------------
    95164    */
    96 
    97     // Things which could be implemented in a future version
    98     // PreCut in Energy oder Size?
    99     // PreCut in Max Dist
    100     // PreCut in Theta^2 (0.25 oder 0.3)
    101     // New spectral slope
    102     // Zenith angle distribution in OnTime
    103165
    104166     opt.Train("rf-energy.root", set, 30000);
    105167}
    106 /*
    107  // SequencesOn:   Monte Carlo Sequences used for training
    108  // SequencesOff:  Monte Carlo Sequences used for testing
    109 
    110  // Use:
    111  // opt.AddPreCut    to use cut for test and training
    112  // opt.AddTestCut   to use cut for test only
    113  // opt.AddTrainCut  to use cut for train only
    114  */
  • trunk/MagicSoft/Mars/mfbase/MFDataPhrase.cc

    r8310 r8706  
    107107// the class description above.
    108108//
    109 MFDataPhrase::MFDataPhrase(const char *text, const char *name, const char *title) : fAllowEmpty(kFALSE)
     109MFDataPhrase::MFDataPhrase(const char *text, const char *name, const char *title) : fData(NULL), fAllowEmpty(kFALSE)
    110110{
    111111    fName  = name  ? name  : gsDefName.Data();
    112112    fTitle = title ? title : gsDefTitle.Data();
     113
     114    if (!text)
     115        return;
    113116
    114117    *fLog << inf << "Parsing filter rule... " << flush;
     
    162165Int_t MFDataPhrase::Process()
    163166{
    164     if (fData)
    165         fResult = fData->GetValue()>0.5;
     167    fResult = fData ? fData->GetValue()>0.5 : fDefault;
    166168
    167169    return kTRUE;
  • trunk/MagicSoft/Mars/mfbase/MFDataPhrase.h

    r8091 r8706  
    1818    MData *fData;
    1919    Bool_t fAllowEmpty;              // Not a Bit to be stored
     20    Bool_t fDefault;                 // Default for empty case
    2021
    2122    Bool_t fResult; //!
     
    3839    void SetAllowEmpty(Bool_t b=kTRUE) { fAllowEmpty = b; }
    3940    Bool_t IsAllowEmpty() const { return fAllowEmpty; }
     41
     42    void SetDefault(Bool_t b) { fDefault = b;    }
     43    Bool_t GetDefault() const { return fDefault; }
    4044
    4145    // MFilter
  • trunk/MagicSoft/Mars/mjobs/MJCut.cc

    r8695 r8706  
    666666
    667667    // Filter for VsSize
    668     MFDataPhrase ftheta("", "CutT");
    669     ftheta.SetAllowEmpty();
     668    MFDataPhrase ftheta(0, "CutT");
    670669
    671670    // ------------- Loop Off Data --------------------
  • trunk/MagicSoft/Mars/mjobs/MJSpectrum.h

    r8701 r8706  
    5353    void    PrintSetup(const MAlphaFitter &fit) const;
    5454    Bool_t  DisplayResult(const TH2D &mh1) const;
    55     Bool_t  IntermediateLoop(MParList &plist, MH3 &h1, TH1D &temp1, const MDataSet &set, MMcSpectrumWeight &w) const;
     55    //Bool_t  IntermediateLoop(MParList &plist, MH3 &h1, TH1D &temp1, const MDataSet &set, MMcSpectrumWeight &w) const;
    5656    TArrayD FitSpectrum(TH1D &spectrum) const;
    5757    TArrayD DisplaySpectrum(MHCollectionArea &area, TH1D &excess, MHEnergyEst &hest, Double_t ontime) const;
  • trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc

    r8704 r8706  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.29 2007-08-24 08:33:48 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.30 2007-08-24 12:58:49 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    167167        // In the case weights should be used initialize the
    168168        // corresponding array
     169        Double_t sum = 0;
     170
    169171        TArrayF weights(nrows);
    170172        if (fLastDataColumnHasWeights)
     173        {
    171174            for (Int_t j=0; j<nrows; j++)
    172175            {
    173176                weights[j] = matrixtrain.GetM()(j, ncols-nobs);
    174                 if (j%250==0)
    175                     cout << weights[j] << " ";
     177                sum += weights[j];
    176178            }
     179        }
     180
     181        *fLog << inf << "MRanForestCalc::Train: Sum of weights " << sum << endl;
    177182
    178183        // Setup the matrix such that the last comlumn contains
Note: See TracChangeset for help on using the changeset viewer.