Ignore:
Timestamp:
12/22/03 20:07:48 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mfilter
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h

    r2704 r2743  
    2828
    2929#pragma link C++ class MFEnergySlope+;
    30 #pragma link C++ class MFRandomSplit+;
    3130
    3231#endif
  • trunk/MagicSoft/Mars/mfilter/MFEventSelector.cc

    r2206 r2743  
    3030// present implementation you can only use a random selection.
    3131//
     32// This filter can be used for a random split...
     33//
    3234// If you want to fill only 50% of your events into a histogram please use:
    3335//   MFEventSelector sel;
     
    6062// Remark: You can also use the filter together with MContinue
    6163//
     64//
     65// FIXME: Merge MFEventSelector and MFEventSelector2
     66//
    6267/////////////////////////////////////////////////////////////////////////////
    6368#include "MFEventSelector.h"
     
    8186// --------------------------------------------------------------------------
    8287//
    83 // Default Constructor. Don't use.
    84 //
    85 /*
    86 MFEventSelector::MFEventSelector()
    87     : fNumTotalEvts(-1), fNumSelectEvts(-1), fSelRatio(-1), fNumSelectedEvts(0)
    88 {
    89     fName  = gsDefName.Data();
    90     fTitle = gsDefTitle.Data();
    91 }
    92 */
    93 // --------------------------------------------------------------------------
    94 //
    9588// Constructor. For the text describing the filter rule please see
    9689// the class description above.
     
    10598// --------------------------------------------------------------------------
    10699//
     100// Set a probability with which events are selected. Eg, f=0.5
     101// will select roughly half of all events.
     102//
     103void MFEventSelector::SetSelectionRatio(Float_t f)
     104{
     105    if (f < 0)
     106    {
     107        *fLog << warn << "MFEventSelector::SetSelectionRatio: WARNING - Probability less than 0... set to 0." << endl;
     108        f = 0;
     109    }
     110
     111    if (f > 1)
     112    {
     113        *fLog << warn << "MFEventSelector::SetSelectionRatio: WARNING - Probability greater than 1... set to 1." << endl;
     114        f = 1;
     115    }
     116    fSelRatio = f;
     117}
     118
     119// --------------------------------------------------------------------------
     120//
    107121// PreProcess all filters.
    108122//
    109123Int_t MFEventSelector::PreProcess(MParList *plist)
    110124{
    111     memset(fErrors, 0, sizeof(fErrors));
    112 
    113125    fNumSelectedEvts = 0;
     126
     127    // In the case a ratio was set by the user we are done.
    114128    if (fSelRatio>0)
    115129        return kTRUE;
    116130
     131    // If the number of total events wasn't set try to get it
    117132    if (fNumTotalEvts<0)
    118133    {
     
    120135        if (!tlist)
    121136        {
    122             *fLog << err << dbginf << "Sorry can't determin total number of events... no MTaskList." << endl;
     137            *fLog << err << "Can't determin total number of events... no MTaskList." << endl;
    123138            return kFALSE;
    124139        }
     
    127142        if (!read)
    128143        {
    129             *fLog << err << dbginf << "Sorry can't determin total number of events from 'MRead'." << endl;
     144            *fLog << err << "Can't determin total number of events from 'MRead'." << endl;
    130145            return kFALSE;
    131146        }
    132147        fNumTotalEvts = read->GetEntries();
    133148
    134         *fLog << "MFEventSelector::PreProcess; fNumTotalEvts = "
    135               << fNumTotalEvts << endl;
    136 
    137149        SetBit(kNumTotalFromFile);
    138150    }
    139151
     152    // Calculate selection probability
     153    fSelRatio = (Double_t)fNumSelectEvts/fNumTotalEvts;
     154
     155    *fLog << inf << "MFEventSelector:  Selection probability = " << fNumSelectEvts;
     156    *fLog << "/" << fNumTotalEvts << " = " << Form("%.2f", fSelRatio) << endl;
     157
    140158    return kTRUE;
    141159}
     
    143161// --------------------------------------------------------------------------
    144162//
    145 // Process all filters.
     163// Process all filters, FIXME: Make it fit the requested number of events
     164// exactly like it is done in MFEventSelector2. This can be done by merging
     165// both classes!
    146166//
    147167Int_t MFEventSelector::Process()
    148168{
    149     Int_t rc;
    150 
    151     const Float_t evt = gRandom->Uniform();
    152 
    153     if (fNumSelectEvts>0)
    154         fResult = evt*fNumTotalEvts < fNumSelectEvts;
    155     else
    156         fResult = evt < fSelRatio;
    157 
    158     if (fResult)
    159     {
    160         fNumSelectedEvts++;
    161 
    162         rc = 0;
    163         fErrors[rc]++;
     169    fResult = gRandom->Uniform() < fSelRatio;
     170
     171    if (!fResult)
    164172        return kTRUE;
    165     }
    166    
    167     rc = 1;
    168     fErrors[rc]++;
    169 
     173
     174    fNumSelectedEvts++;
    170175    return kTRUE;
    171176}
     
    180185    if (GetNumExecutions() != 0)
    181186    {
    182       *fLog << inf << endl;
    183       *fLog << GetDescriptor() << " execution statistics:" << endl;
    184       *fLog << dec << setfill(' ');
    185       *fLog << " " << setw(7) << fErrors[1] << " (" << setw(3)
    186             << (int)(fErrors[1]*100/GetNumExecutions())
    187             << "%) Events not selected" << endl;
    188 
    189       *fLog << " " << fErrors[0] << " ("
    190             << (int)(fErrors[0]*100/GetNumExecutions())
    191             << "%) Events selected!" << endl;
    192       *fLog << endl;
     187        const Double_t sel = (Double_t)fNumSelectedEvts/GetNumExecutions();
     188        const UInt_t   non = GetNumExecutions()-fNumSelectedEvts;
     189
     190        *fLog << inf << dec << setfill(' ') << endl;
     191        *fLog << GetDescriptor() << " execution statistics:" << endl;
     192
     193        *fLog << " " << setw(7) << non << " (" << setw(3);
     194        *fLog << (int)(100*(1-sel)) << "%) Events not selected" << endl;
     195
     196        *fLog << " " << setw(7) << fNumSelectedEvts << " (";
     197        *fLog << (int)(100*sel) << "%) Events selected!" << endl;
     198        *fLog << endl;
    193199    }
    194200
     
    196202    if (TestBit(kNumTotalFromFile))
    197203        fNumTotalEvts = -1;
     204
    198205    return kTRUE;
    199206}
     
    219226    out << ");" << endl;
    220227    */
    221 
    222 }
     228}
  • trunk/MagicSoft/Mars/mfilter/MFEventSelector.h

    r2206 r2743  
    11#ifndef MARS_MFEventSelector
    22#define MARS_MFEventSelector
    3 
    4 /////////////////////////////////////////////////////////////////////////////
    5 //                                                                         //
    6 // MFEventSelector                                                         //
    7 //                                                                         //
    8 /////////////////////////////////////////////////////////////////////////////
    93
    104#ifndef MARS_MFilter
     
    1711{
    1812private:
    19     Int_t   fNumTotalEvts;
    20     Int_t   fNumSelectEvts;
    21     Float_t fSelRatio;
     13    Int_t   fNumTotalEvts;    // Number of total events from which are selected
     14    Int_t   fNumSelectEvts;   // Number of events to be selected
     15    Float_t fSelRatio;        // Selection Probability
    2216
    23     Int_t   fNumSelectedEvts; //!
     17    Int_t   fNumSelectedEvts; //! Number of events which have been selected
    2418
    25     Bool_t  fResult;
     19    Bool_t  fResult;          //! Reseult of a single selection
    2620
    2721    void StreamPrimitive(ofstream &out) const;
     
    3327    enum { kNumTotalFromFile = BIT(14) };
    3428
    35     Int_t fErrors[2];
    36 
    3729public:
    3830    MFEventSelector(const char *name=NULL, const char *title=NULL);
     
    4032    Bool_t IsExpressionTrue() const { return fResult; }
    4133
    42     void SetNumTotalEvts(Int_t n) { fNumTotalEvts = n; ResetBit(kNumTotalFromFile); }
     34    void SetNumTotalEvts(Int_t n)  { fNumTotalEvts = n; ResetBit(kNumTotalFromFile); }
    4335    void SetNumSelectEvts(Int_t n) { fNumSelectEvts = n; }
    44     void SetSelectionRatio(Float_t f) { fSelRatio = f; }
     36    void SetSelectionRatio(Float_t f);
    4537
    46     ClassDef(MFEventSelector, 0) // A Filter to select events from files
     38    ClassDef(MFEventSelector, 0) // A filter to do a random selection of events
    4739};
    4840
  • trunk/MagicSoft/Mars/mfilter/MFEventSelector2.cc

    r2728 r2743  
    9292// Remark: You can also use the filter together with MContinue
    9393//
     94//
     95// FIXME: Merge MFEventSelector and MFEventSelector2
     96//
    9497/////////////////////////////////////////////////////////////////////////////
    9598#include "MFEventSelector2.h"
     
    225228    }
    226229
    227     tlist.PrintStatistics(0, kTRUE);
     230    tlist.PrintStatistics();
    228231
    229232    *fLog << inf;
  • trunk/MagicSoft/Mars/mfilter/MFEventSelector2.h

    r2693 r2743  
    6363    Bool_t IsExpressionTrue() const { return fResult; }
    6464
    65     ClassDef(MFEventSelector2, 0)
     65    ClassDef(MFEventSelector2, 0) // FIMXE!
    6666};
    6767
    6868#endif
    69 
    70 
    71 
  • trunk/MagicSoft/Mars/mfilter/Makefile

    r2736 r2743  
    5252           MFSelFinal.cc \
    5353           MFSoftwareTrigger.cc \
    54            MFEnergySlope.cc \
    55            MFRandomSplit.cc
     54           MFEnergySlope.cc
    5655
    5756SRCS    = $(SRCFILES)
Note: See TracChangeset for help on using the changeset viewer.