Ignore:
Timestamp:
12/22/04 11:24:46 (20 years ago)
Author:
domingo
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mfbase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mfbase/MFEventSelector2.cc

    r5448 r5667  
    1919!   Author(s): Wolfgang Wittek 11/2003 <mailto:wittek@mppmu.mpg.de>
    2020!
    21 !   Copyright: MAGIC Software Development, 2000-2003
     21!   Copyright: MAGIC Software Development, 2000-2005
    2222!
    2323!
     
    2929//
    3030// This is a filter to make a selection of events from a file, according to
    31 // a certain predetermined distribution in a given parameter (or combination
     31// a certain requested distribution in a given parameter (or combination
    3232// of parameters). The distribution is passed to the class through a histogram
    3333// of the relevant parameter(s) contained in an object of type MH3. The filter
     
    3838// values of the parameters, and is dictated by the input histogram).
    3939//
     40// This procedure requires the determination of the original distribution
     41// of the given parameters for the total sample of events on the input file.
     42// If the event loop contains a filter with name "FilterSelector2", this
     43// filter will be applied when determining the original distribution.
     44//
    4045// See Constructor for more instructions and also the example below:
    4146//
     
    111116#include "MH3.h"            // MH3
    112117#include "MRead.h"          // MRead
     118//#include "MProgressBar.h"   //
    113119#include "MEvtLoop.h"       // MEvtLoop
    114120#include "MTaskList.h"      // MTaskList
    115121#include "MBinning.h"       // MBinning
     122#include "MContinue.h"      //
    116123#include "MFillH.h"         // MFillH
    117124#include "MParList.h"       // MParList
     
    148155//     note that also in this case a dummy nominal distribution has to be
    149156//     provided in the first argument (the dummy distribution defines the
    150 //     variable(s) of interest and the binnings)
     157//     variable(s) of interest, their binnings and their requested ranges;
     158//     events outside these ranges won't be accepted).
    151159//
    152160MFEventSelector2::MFEventSelector2(MH3 &hist, const char *name, const char *title)
    153161: fHistOrig(NULL), fHistNom(&hist), fHistRes(NULL),
    154162  fDataX(hist.GetRule('x')), fDataY(hist.GetRule('y')),
    155   fDataZ(hist.GetRule('z')), fNumMax(-1), fHistIsProbability(kFALSE)
     163  fDataZ(hist.GetRule('z')), fNumMax(-1), fHistIsProbability(kFALSE),
     164  fUseOrigDist(kTRUE)
    156165{
    157166    fName  = name  ? (TString)name  : gsDefName;
    158167    fTitle = title ? (TString)title : gsDefTitle;
     168
     169    // name of filter to be applied when determining the original distribution
     170    // for all data on the input file
     171    fFilterName = "FilterSelector2";
    159172}
    160173
     
    195208// Reading task of the present loop is used in a new eventloop.
    196209//
    197 Bool_t MFEventSelector2::ReadDistribution(MRead &read)
     210Bool_t MFEventSelector2::ReadDistribution(MRead &read, MFilter *filter)
    198211{
    199212    if (read.GetEntries() > kMaxUInt) // FIXME: LONG_MAX ???
     
    205218    *fLog << inf << underline << endl;
    206219    *fLog << "MFEventSelector2::ReadDistribution:" << endl;
    207     *fLog << " - Start of eventloop to generate the original distribution..." << endl;
    208 
    209     MEvtLoop run(GetName());
     220    *fLog << "**********************" << endl;
     221    *fLog << " - Start of eventloop to generate the original distribution..."
     222          << endl;
     223
     224    if (filter != NULL)
     225    {
     226      *fLog << "                      filter used : " << filter->GetName()
     227            << endl;
     228    }
     229
     230
     231    MEvtLoop run("ReadDistribution");
     232    //MProgressBar bar;
     233    //run.SetProgressBar(&bar);
     234
    210235    MParList plist;
    211236    MTaskList tlist;
     
    224249
    225250    MFillH fill(fHistOrig);
     251    fill.SetName("FillHistOrig");
    226252    fill.SetBit(MFillH::kDoNotDisplay);
    227253    tlist.AddToList(&read);
     254
     255    MContinue contfilter(filter);
     256    if (filter != NULL)
     257    {
     258      contfilter.SetName("ContFilter");
     259      tlist.AddToList(&contfilter);
     260    }
     261
    228262    tlist.AddToList(&fill);
    229263    run.SetDisplay(fDisplay);
    230264    if (!run.Eventloop())
    231265    {
    232         *fLog << err << dbginf << "Evtloop in MFEventSelector2::ReadDistribution failed." << endl;
     266        *fLog << err << dbginf
     267              << "Evtloop in MFEventSelector2::ReadDistribution failed."
     268              << endl;
    233269        return kFALSE;
    234270    }
    235271
    236     tlist.PrintStatistics();
     272    tlist.PrintStatistics(0, kTRUE);
    237273
    238274    *fLog << inf;
    239275    *fLog << "MFEventSelector2::ReadDistribution:" << endl;
    240     *fLog << " - Original distribution has " << fHistOrig->GetHist().GetEntries() << " entries." << endl;
    241     *fLog << " - End of eventloop to generate the original distribution." << endl;
     276    *fLog << " - Original distribution has "
     277          << fHistOrig->GetHist().GetEntries() << " entries." << endl;
     278    *fLog << " - End of eventloop to generate the original distribution."
     279          << endl;
     280    *fLog << "**********************" << endl;
    242281
    243282    return read.Rewind();
     
    258297    // set the nominal distribution equal to the original distribution
    259298
    260     const Bool_t useorigdist = fHistNom->GetHist().GetEntries()==0;
    261     TH1 *hnp =  useorigdist ? (TH1*)(fHistOrig->GetHist()).Clone() : &fHistNom->GetHist();
     299    const Bool_t fUseOrigDist = fHistNom->GetHist().GetEntries()==0;
     300    TH1 *hnp =  fUseOrigDist ? (TH1*)(fHistOrig->GetHist()).Clone() :
     301                              &fHistNom->GetHist();
    262302
    263303    TH1 &hn = *hnp;
     
    327367    }
    328368
    329     if (useorigdist)
     369    if (fUseOrigDist)
    330370      delete hnp;
    331371}
     
    370410//  3) Initialize the histogram for the resulting distribution
    371411//  4) Prepare the random selection
    372 //  5) Repreprocess the reading task.
     412//  5) Repreprocess the reading and filter task.
    373413//
    374414Int_t MFEventSelector2::PreProcess(MParList *parlist)
     
    386426        return kFALSE;
    387427
    388     fHistNom->SetTitle(fHistIsProbability ? "ProbabilityDistribution" : "Users Nominal Distribution");
     428    fHistNom->SetTitle(fHistIsProbability ? "ProbabilityDistribution" :
     429                                            "Users Nominal Distribution");
    389430
    390431    if (fHistIsProbability)
     
    410451    }
    411452
    412     if (!ReadDistribution(*read))
     453    MFilter *filter = (MFilter*)tasklist->FindObject(fFilterName);
     454    if (!filter)
     455    {
     456      *fLog << inf
     457            << "No filter will be used when making the original distribution"
     458            << endl;
     459      filter = NULL;
     460    }
     461
     462
     463    if (!ReadDistribution(*read, filter))
    413464        return kFALSE;
     465
    414466
    415467    // Prepare histograms and arrays for selection
    416468    PrepareHistograms();
    417469
    418     return read->CallPreProcess(parlist);
     470    *fLog << "MFEventSelector2::PreProcess; call PreProcess() for read and filter object again"
     471          << endl;
     472    Int_t rcr = read->CallPreProcess(parlist);
     473    Int_t rcf = filter->CallPreProcess(parlist);
     474
     475    *fLog << "rcr, rcf = " << rcr << ",  " << rcf << endl;
     476
     477    return rcf*rcr;
    419478}
    420479
     
    426485Bool_t MFEventSelector2::Select(Int_t bin)
    427486{
    428     // under- and overflow bins are not counted
     487    // under- and overflow bins are not accepted
    429488    if (bin<0)
    430489        return kFALSE;
     
    450509}
    451510
     511// --------------------------------------------------------------------------
     512//
    452513Bool_t MFEventSelector2::SelectProb(Int_t ibin) const
    453514{
     
    455516    // If value is outside histogram range, accept event
    456517    //
    457     return ibin<0 ? kTRUE : fHistNom->GetHist().GetBinContent(ibin) > gRandom->Uniform();
     518    return ibin<0 ? kTRUE :
     519           fHistNom->GetHist().GetBinContent(ibin) > gRandom->Uniform();
    458520}
    459521
     
    473535    const Double_t valz=fDataZ.GetValue();
    474536
     537    // don't except the event if it is outside the axis range
     538    // of the requested distribution
    475539    const Int_t ibin = fHistNom->FindFixBin(valx, valy, valz)-1;
    476 
    477     // Get corresponding bin number and check
    478     // whether a selection should be made
     540    if (!fHistIsProbability)
     541    {
     542      if (ibin < 0)
     543      {
     544        fResult = kFALSE;
     545        fCounter[1] += 1;
     546        return kTRUE;
     547      }
     548    }
     549
     550    // check whether a selection should be made
    479551    fResult = fHistIsProbability ? SelectProb(ibin) : Select(ibin);
    480 
    481     fCounter[fResult ? 1 : 0]++;
     552    if (!fResult)
     553    {
     554      fCounter[2] += 1;
     555      return kTRUE;
     556    }
     557
     558    fCounter[0] += 1;
    482559
    483560    return kTRUE;
     
    497574        *fLog << GetDescriptor() << " execution statistics:" << endl;
    498575        *fLog << dec << setfill(' ');
     576
    499577        *fLog << " " << setw(7) << fCounter[1] << " (" << setw(3)
    500               << (int)(fCounter[0]*100/GetNumExecutions())
    501               << "%) Events not selected" << endl;
     578              << (int)((Float_t)(fCounter[1]*100)/(Float_t)(GetNumExecutions())+0.5)
     579              << "%) Events not selected due to under/over flow" << endl;
     580
     581        *fLog << " " << setw(7) << fCounter[2] << " (" << setw(3)
     582              << (int)((Float_t)(fCounter[2]*100)/(Float_t)(GetNumExecutions())+0.5)
     583              << "%) Events not selected due to requested distribution"
     584              << endl;
    502585
    503586        *fLog << " " << fCounter[0] << " ("
    504               << (int)(fCounter[1]*100/GetNumExecutions())
     587              << (int)((Float_t)(fCounter[0]*100)/(Float_t)(GetNumExecutions())+0.5)
    505588              << "%) Events selected" << endl;
    506589        *fLog << endl;
     
    519602    return kTRUE;
    520603}
     604
     605
     606
     607
     608
     609
  • trunk/MagicSoft/Mars/mfbase/MFEventSelector2.h

    r5448 r5667  
    4141    TCanvas   *fCanvas;   //! canvas for online display
    4242
     43    TString    fFilterName; // name of the MFilter object to be used
     44                            // when determining the original distribution
     45
    4346    Bool_t fResult;
    4447    Bool_t fHistIsProbability;
    45     Int_t  fCounter[2];
     48    Bool_t fUseOrigDist;    // flag indicating that in the selection the
     49                            // original distribution is not changed
     50
     51    Int_t  fCounter[3];
    4652
    4753    TH1   &InitHistogram(MH3* &hist);
    48     Bool_t ReadDistribution(MRead &read);
     54    Bool_t ReadDistribution(MRead &read, MFilter *filter);
    4955    void   PrepareHistograms();
    5056    Bool_t PreProcessData(MParList *parlist);
Note: See TracChangeset for help on using the changeset viewer.