Changeset 2574 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
11/28/03 08:08:53 (21 years ago)
Author:
wittek
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r2573 r2574  
    44
    55                                                 -*-*- END OF LINE -*-*-
     6
     7
     8
     9  2003/11/27: Wolfgang Wittek
     10
     11  * mfilter/MFEventSelector2.cc
     12    - if number of requested events is too high
     13      reduce it to the maximum number possible
     14    - introduce the flag 'fUseOrigDistribution';
     15      if it is set to kTRUE (by SetOrigDistribution()) the original
     16      distribution will be used as the nominal distribution
     17    - add the member functions SetUseOrigDistribution()
     18                               GetHistOrig()
     19
     20  * mfilter/MFRandomSplit.[h,cc]
     21    - a filter which gives fResult = kTRUE with a certain probability
     22
     23  * mfilter/MFAntiFilter.[h,cc]
     24    - a filter which checks the result of a given filter and returns
     25      the opposite result;
     26      Thomas : could you please add a code which puts the filter whose
     27               result is checked into the task list ?
     28
     29  * mfilter/Makefile
     30            FilterLinkDef.h
     31    - add MFRandomSplit and MFAntiFilter
     32
     33  * manalysis/MCT1FindSupercuts.[h,cc]
     34    - in 'DefineTrainMatrix', 'DefineTestMatrix', and
     35      'DefineTrainTestMatrix()' :
     36      replace call to 'MFEventSelector' by call to 'MFEventSelector2'
     37    - add member function SetUseOrigDistribution(Bool_t b);
     38      if b = kTRUE the events for the training and test samples are
     39      selected randomnly from the input file
     40
     41
     42
    643 2003/11/27: Abelardo Moralejo
    744
     
    1148       where the parameter containers for each telescope are tagged
    1249       with a ';' followed by the telescope number.
     50
    1351
    1452 2003/11/26: Thomas Bretz
  • trunk/MagicSoft/Mars/manalysis/MCT1FindSupercuts.cc

    r2408 r2574  
    5858#include "MFillH.h"
    5959//#include "MGeomCamCT1Daniel.h"
     60#include "MFRandomSplit.h"
    6061#include "MGeomCamCT1.h"
    6162#include "MH3.h"
     
    246247    fTitle = title ? title : "Optimizer of the supercuts";
    247248
     249    fUseOrigDistribution = kFALSE;
     250
    248251    //---------------------------
    249252    // camera geometry is needed for conversion mm ==> degree
     
    277280}
    278281
     282
     283// --------------------------------------------------------------------------
     284//
     285//
     286//
     287void MCT1FindSupercuts::SetUseOrigDistribution(Bool_t b)
     288{
     289  fUseOrigDistribution = b;
     290
     291  *fLog << "MCT1FindSupercuts : when defining training and test matrices use the original distribution"
     292        << endl;
     293}
     294
    279295// --------------------------------------------------------------------------
    280296//
     
    285301//
    286302//
    287 Bool_t MCT1FindSupercuts::DefineTrainMatrix(const TString &nametrain,
    288                           const Int_t howmanytrain, MH3 &hreftrain,
    289                           const TString &filetrain)
     303Bool_t MCT1FindSupercuts::DefineTrainMatrix(
     304                          const TString &nametrain, MH3 &hreftrain,
     305                          const Int_t howmanytrain, const TString &filetrain)
    290306{
    291307    if (nametrain.IsNull() || howmanytrain <= 0)
     
    295311    *fLog << "fill training matrix from file '" << nametrain
    296312          << "',   select " << howmanytrain
    297           << " events according to a distribution given by the MH3 object '"
    298           << hreftrain.GetName() << "'" << endl;
     313          << " events " << endl;
     314    if (!fUseOrigDistribution)
     315    {
     316      *fLog << "     according to a distribution given by the MH3 object '"
     317            << hreftrain.GetName() << "'" << endl;
     318    }
     319    else
     320    {
     321      *fLog << "     randomly" << endl;
     322    }
    299323
    300324
     
    305329    read.DisableAutoScheme();
    306330
    307     //MFEventSelector2 seltrain(hreftrain);
    308     //seltrain.SetNumMax(howmanytrain);
    309     MFEventSelector seltrain;
    310     seltrain.SetNumSelectEvts(howmanytrain);
     331    MFEventSelector2 seltrain(hreftrain);
     332    seltrain.SetNumMax(howmanytrain);
     333    seltrain.SetName("selectTrain");
     334    if (fUseOrigDistribution)
     335      seltrain.SetUseOrigDistribution(kTRUE);
    311336
    312337    MFillH filltrain(fMatrixTrain);
    313338    filltrain.SetFilter(&seltrain);
     339    filltrain.SetName("fillMatrixTrain");
    314340
    315341    //******************************
     
    379405//
    380406//
    381 Bool_t MCT1FindSupercuts::DefineTestMatrix(const TString &nametest,
    382                           const Int_t howmanytest, MH3 &hreftest,
    383                           const TString &filetest)
     407Bool_t MCT1FindSupercuts::DefineTestMatrix(
     408                          const TString &nametest, MH3 &hreftest,
     409                          const Int_t howmanytest, const TString &filetest)
    384410{
    385411    if (nametest.IsNull() || howmanytest<=0)
     
    389415    *fLog << "fill test matrix from file '" << nametest
    390416          << "',   select " << howmanytest
    391           << " events according to a distribution given by the MH3 object '"
    392           << hreftest.GetName() << "'" << endl;
     417          << " events " << endl;
     418    if (!fUseOrigDistribution)
     419    {
     420      *fLog << "     according to a distribution given by the MH3 object '"
     421            << hreftest.GetName() << "'" << endl;
     422    }
     423    else
     424    {
     425      *fLog << "     randomly" << endl;
     426    }
    393427
    394428
     
    399433    read.DisableAutoScheme();
    400434
    401     //MFEventSelector2 seltest(hreftest);
    402     //seltest.SetNumMax(howmanytest);
    403     MFEventSelector seltest;
    404     seltest.SetNumSelectEvts(howmanytest);
    405 
     435    MFEventSelector2 seltest(hreftest);
     436    seltest.SetNumMax(howmanytest);
     437    seltest.SetName("selectTest");
     438    if (fUseOrigDistribution)
     439      seltest.SetUseOrigDistribution(kTRUE);
     440 
    406441    MFillH filltest(fMatrixTest);
    407442    filltest.SetFilter(&seltest);
     
    471506//
    472507Bool_t MCT1FindSupercuts::DefineTrainTestMatrix(
    473                           const TString &name,
    474                           const Int_t howmanytrain, MH3 &hreftrain,
    475                           const Int_t howmanytest,  MH3 &hreftest,
     508                          const TString &name, MH3 &href,
     509                          const Int_t howmanytrain, const Int_t howmanytest,
    476510                          const TString &filetrain, const TString &filetest)
    477511{
    478512    *fLog << "=============================================" << endl;
    479     *fLog << "fill training matrix from file '" << name
    480           << "',   select " << howmanytrain
    481           << " events for the training according to a distribution given by the MH3 object '"
    482           << hreftrain.GetName() << "'" << endl;
    483 
    484     *fLog << "fill test matrix from the same file '" << name
    485           << "',   select " << howmanytest
    486           << " events for the training according to a distribution given by the MH3 object '"
    487           << hreftest.GetName() << "'" << endl;
     513    *fLog << "fill training and test matrix from file '" << name
     514          << "',   select "   << howmanytrain
     515          << " training and " << howmanytest << " test events " << endl;
     516    if (!fUseOrigDistribution)
     517    {
     518      *fLog << "     according to a distribution given by the MH3 object '"
     519            << href.GetName() << "'" << endl;
     520    }
     521    else
     522    {
     523      *fLog << "     randomly" << endl;
     524    }
    488525
    489526
     
    494531    read.DisableAutoScheme();
    495532
    496     //MFEventSelector2 seltrain(hreftrain);
    497     //seltrain.SetNumMax(howmanytrain);
    498     MFEventSelector seltrain;
    499     seltrain.SetName("SelTrain");
    500     seltrain.SetNumSelectEvts(howmanytrain);
     533    MFEventSelector2 selector(href);
     534    selector.SetNumMax(howmanytrain+howmanytest);
     535    selector.SetName("selectTrainTest");
     536    selector.SetInverted();
     537    if (fUseOrigDistribution)
     538      selector.SetUseOrigDistribution(kTRUE);
     539
     540    MContinue cont(&selector);
     541    cont.SetName("ContTrainTest");
     542
     543    Double_t prob =  ( (Double_t) howmanytrain )
     544                   / ( (Double_t)(howmanytrain+howmanytest) );
     545    MFRandomSplit split(prob);
    501546
    502547    MFillH filltrain(fMatrixTrain);
     548    filltrain.SetFilter(&split);
    503549    filltrain.SetName("fillMatrixTrain");
    504     filltrain.SetFilter(&seltrain);
     550
    505551
    506552    // consider this event as candidate for a test event
    507553    // only if event was not accepted as a training event
    508     MContinue cont(&seltrain);
    509 
    510     const Float_t fcorr = (Float_t)read.GetEntries() / (read.GetEntries()-howmanytrain);
    511 
    512     *fLog << "entries, howmanytrain, fcorr = " << read.GetEntries()
    513           << ",  " << howmanytrain << ",  " << fcorr << endl;
    514 
    515     //MFEventSelector2 seltest(hreftest);
    516     //seltrain.SetNumMax(howmanytest*fcorr);
    517     MFEventSelector seltest;
    518     seltest.SetName("SelTest");
    519     seltest.SetNumSelectEvts((Int_t)(fcorr*howmanytest));
     554
     555    MContinue conttrain(&split);
     556    conttrain.SetName("ContTrain");
    520557
    521558    MFillH filltest(fMatrixTest);
    522559    filltest.SetName("fillMatrixTest");
    523     filltest.SetFilter(&seltest);
     560
    524561
    525562    //******************************
     
    535572
    536573    tlist.AddToList(&read);
    537     tlist.AddToList(&seltrain);
     574    tlist.AddToList(&cont);
     575
     576    tlist.AddToList(&split);
    538577    tlist.AddToList(&filltrain);
    539 
    540     tlist.AddToList(&cont);
    541 
    542     tlist.AddToList(&seltest);
     578    tlist.AddToList(&conttrain);
     579
    543580    tlist.AddToList(&filltest);
    544581
  • trunk/MagicSoft/Mars/manalysis/MCT1FindSupercuts.h

    r2357 r2574  
    3737  Int_t   fHowManyTrain;
    3838  Int_t   fHowManyTest;
     39
     40  Bool_t  fUseOrigDistribution;
    3941
    4042  TString  fFilenameParam;
     
    8890  void SetMatrixFilter(MFilter *filter)          {fMatrixFilter = filter;}
    8991
    90   Bool_t DefineTrainMatrix(const TString &name, const Int_t howmany,
    91                            MH3 &href, const TString &filetrain);
     92  Bool_t DefineTrainMatrix(const TString &name, MH3 &href,
     93                           const Int_t howmany, const TString &filetrain);
    9294
    93   Bool_t DefineTestMatrix(const TString &name, const Int_t howmany,
    94                           MH3 &href, const TString &filetest);
     95  Bool_t DefineTestMatrix(const TString &name, MH3 &href,
     96                          const Int_t howmany, const TString &filetest);
    9597
    96   Bool_t DefineTrainTestMatrix(const TString &name,
    97                          const Int_t howmanytrain, MH3 &hreftrain,
    98                          const Int_t howmanytest,  MH3 &hreftest,
     98  Bool_t DefineTrainTestMatrix(const TString &name, MH3 &href,
     99                         const Int_t howmanytrain, const Int_t howmanytest,
    99100                         const TString &filetrain, const TString &filetest);
     101
     102  void SetUseOrigDistribution(Bool_t b);
    100103
    101104  MHMatrix *GetMatrixTrain() { return fMatrixTrain; }
  • trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h

    r2521 r2574  
    2424
    2525#pragma link C++ class MFEnergySlope+;
     26#pragma link C++ class MFRandomSplit+;
     27#pragma link C++ class MFAntiFilter+;
    2628
    2729#endif
  • trunk/MagicSoft/Mars/mfilter/MFEventSelector2.cc

    r2357 r2574  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz, 01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
     18!   Author(s): Thomas Bretz,   01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
     19!              Wolfgang Wittek 11/2003 <mailto:wittek@mppmu.mpg.de>
    1920!
    2021!   Copyright: MAGIC Software Development, 2000-2003
     
    135136//     would result in redistributing cos(Theta).
    136137//
     138//  If 'fUseOrigDistribution' is set to kTRUE (by SetUseOrigDistribution())
     139//     the original distribution will be used as the nominal distribution;
     140//     note that also in this case a dummy nominal distribution has to be
     141//     provided in the first argument (the dummy distribution defines the
     142//     variable(s) of interest and the binnings)
     143//
     144
    137145MFEventSelector2::MFEventSelector2(MH3 &hist, const char *name, const char *title)
    138146: fHistOrig(NULL), fHistNom(&hist), fHistRes(NULL),
     
    142150    fName  = name  ? (TString)name  : gsDefName;
    143151    fTitle = title ? (TString)title : gsDefTitle;
    144 }
    145 
    146 // --------------------------------------------------------------------------
    147 //
    148 // Destructor. Deletes fHistRes if allocated.
     152 
     153    fUseOrigDistribution = kFALSE;
     154}
     155
     156// --------------------------------------------------------------------------
     157//
     158//
    149159//
    150160MFEventSelector2::~MFEventSelector2()
    151161{
    152     if (fHistRes)
    153         delete fHistRes;
    154 }
    155 
    156 // --------------------------------------------------------------------------
     162  if (fHistRes)
     163    delete fHistRes;
     164}
     165
     166// --------------------------------------------------------------------------
     167//
     168//
     169//
     170void MFEventSelector2::SetUseOrigDistribution(Bool_t b)
     171{
     172  fUseOrigDistribution = b;
     173 
     174  *fLog << "MFEventSelector2 : use the distribution from the input file as the target distribution"
     175        << endl;
     176}
     177
     178//---------------------------------------------------------------------------
    157179//
    158180// Recreate a MH3 from fHistNom used as a template. Copy the Binning
     
    189211
    190212    *fLog << "-------------------------" << endl;
    191     *fLog << "MFEventSelector2::ReadDistribution; read input file to generate the original distribution" << endl;
     213    *fLog << "MFEventSelector2 : Start of eventloop to generate the original distribution"
     214          << endl;
    192215
    193216    MEvtLoop run(GetName());
     
    214237    if (!run.Eventloop())
    215238    {
    216         *fLog << err << dbginf << "Evtloop failed." << endl;
     239        *fLog << err << dbginf << "Evtloop in MFEventSelector2::ReadDistribution failed." << endl;
    217240        return kFALSE;
    218241    }
     
    222245    *fLog << "MFEventSelector2::ReadDistribution; Original distribution has "
    223246          << fHistOrig->GetHist().GetEntries() << " entries" << endl;
     247    *fLog << "MFEventSelector2 : End of eventloop to generate the original distribution"
     248          << endl;
    224249    *fLog << "-------------------------" << endl;
    225250
     
    229254// --------------------------------------------------------------------------
    230255//
    231 // After reading the histograms and arrays used for the random event
     256// After reading the histograms the arrays used for the random event
    232257// selction are created. If a MStatusDisplay is set the histograms are
    233258// displayed there.
     
    236261{
    237262    TH1 &ho = fHistOrig->GetHist();
    238     TH1 &hn = fHistNom->GetHist();
    239 
    240     fHistNom->SetTitle("Users Nominal Distribution");
    241     fHistRes->SetTitle("Resulting Distribution");
     263
     264    //-------------------
     265    // if requested
     266    // set the nominal distribution equal to the original distribution
     267
     268    TH1 *hnp;
     269    if (fUseOrigDistribution)
     270      hnp = (TH1*)(fHistOrig->GetHist()).Clone();
     271    else
     272      hnp = &fHistNom->GetHist();
     273
     274    TH1 &hn = *hnp;
     275    //--------------------
    242276
    243277    // normalize to number of counts in primary distribution
     
    268302    if (fNumMax>0)
    269303    {
    270         *fLog << "MFEventSelector2::PrepareHistograms; SCALE : fNumMax = "
    271               << fNumMax << ",  hn.Integral() = "      << hn.Integral()
    272               << ",  fNumMax/hn.Integral() = " << fNumMax/hn.Integral()
    273               << endl;
    274 
    275         hn.Scale(fNumMax/hn.Integral());
     304        *fLog << "MFEventSelector2::PrepareHistograms; requested no.of events = "
     305              << fNumMax << ",  maximum no.of events possible = "     
     306              << hn.Integral() << endl;
     307
     308        if (fNumMax > hn.Integral())
     309        {
     310          *fLog << "MFEventSelector2::PrepareHistograms; requested no.of events ("
     311                << fNumMax << ") is too high" << endl;
     312          *fLog << "                                     reduce it to "
     313                << hn.Integral() << endl;
     314        }
     315
     316        else
     317          hn.Scale(fNumMax/hn.Integral());
    276318    }
    277319
     
    297339        fNom[i] = (Long_t)(hn.GetBinContent(i+1)+0.5);
    298340    }
     341
     342    if (fUseOrigDistribution)
     343      delete hnp;
    299344}
    300345
     
    362407    InitHistogram(fHistRes);
    363408
     409    fHistNom->SetTitle("Users Nominal Distribution");
    364410    fHistOrig->SetTitle("Primary Distribution");
     411    fHistRes->SetTitle("Resulting Distribution");
    365412
    366413    // Initialize online display if requested
     
    369416        fHistOrig->Draw();
    370417
    371     // Read primary distribution
     418    // Generate primary distribution
    372419    if (!ReadDistribution(*read))
    373420        return kFALSE;
     
    467514    return kTRUE;
    468515}
     516
     517
     518
     519
     520
     521
     522
     523
     524
  • trunk/MagicSoft/Mars/mfilter/MFEventSelector2.h

    r2357 r2574  
    4141    TCanvas   *fCanvas;   //! canvas for online display
    4242
     43    Bool_t fUseOrigDistribution;
     44
    4345    Bool_t fResult;
    4446    Int_t fErrors[2];
     
    5759    ~MFEventSelector2();
    5860
     61    void SetUseOrigDistribution(Bool_t b=kTRUE);
     62    MH3 *GetHistOrig()                       { return fHistOrig; }
     63
    5964    void SetNumMax(Long_t max=-1) { fNumMax = max; }
    6065    Bool_t IsExpressionTrue() const { return fResult; }
     
    6469
    6570#endif
     71
     72
     73
  • trunk/MagicSoft/Mars/mfilter/Makefile

    r2521 r2574  
    4848           MFCT1SelStandard.cc \
    4949           MFCT1SelFinal.cc \
    50            MFEnergySlope.cc
     50           MFEnergySlope.cc \
     51           MFRandomSplit.cc \
     52           MFAntiFilter.cc
    5153
    5254SRCS    = $(SRCFILES)
Note: See TracChangeset for help on using the changeset viewer.