Changeset 2587


Ignore:
Timestamp:
12/02/03 14:33:36 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r2586 r2587  
    44
    55                                                 -*-*- END OF LINE -*-*-
     6 2003/12/02: Thomas Bretz
     7 
     8   * mfilter/MFEventSelector2.[h,cc]:
     9     - fixed and reorganized screen output
     10     - added some small comments to the code
     11     - moved some code from Process() to the new private function Select
     12     - fixed uncounted events (underflow bins were not counted)
     13     - renamed nonsens fErrors to fCounter
     14     - fixed usage of fDisplay
     15
     16
    617
    718 2003/12/01: Markus Gaug
  • trunk/MagicSoft/Mars/mfilter/MFEventSelector2.cc

    r2574 r2587  
    1717!
    1818!   Author(s): Thomas Bretz,   01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
    19 !             Wolfgang Wittek 11/2003 <mailto:wittek@mppmu.mpg.de>
     19!   Author(s): Wolfgang Wittek 11/2003 <mailto:wittek@mppmu.mpg.de>
    2020!
    2121!   Copyright: MAGIC Software Development, 2000-2003
     
    156156// --------------------------------------------------------------------------
    157157//
    158 //
     158// Delete fHistRes if instatiated
    159159//
    160160MFEventSelector2::~MFEventSelector2()
    161161{
    162   if (fHistRes)
    163     delete fHistRes;
     162    if (fHistRes)
     163        delete fHistRes;
    164164}
    165165
     
    170170void MFEventSelector2::SetUseOrigDistribution(Bool_t b)
    171171{
    172   fUseOrigDistribution = b;
    173  
    174   *fLog << "MFEventSelector2 : use the distribution from the input file as the target distribution"
    175         << endl;
     172    fUseOrigDistribution = b;
     173
     174    *fLog << inf;
     175    *fLog << "MFEventSelector2 set ";
     176    if (!b)
     177        *fLog << "not ";
     178    *fLog << "to use the distribution from the input file as target distribution." << endl;
    176179}
    177180
     
    210213    }
    211214
    212     *fLog << "-------------------------" << endl;
    213     *fLog << "MFEventSelector2 : Start of eventloop to generate the original distribution"
    214           << endl;
     215    *fLog << inf << underline << endl;
     216    *fLog << "MFEventSelector2::ReadDistribution:" << endl;
     217    *fLog << " - Start of eventloop to generate the original distribution..." << endl;
    215218
    216219    MEvtLoop run(GetName());
     
    243246    tlist.PrintStatistics(0, kTRUE);
    244247
    245     *fLog << "MFEventSelector2::ReadDistribution; Original distribution has "
    246           << fHistOrig->GetHist().GetEntries() << " entries" << endl;
    247     *fLog << "MFEventSelector2 : End of eventloop to generate the original distribution"
    248           << endl;
    249     *fLog << "-------------------------" << endl;
     248    *fLog << inf;
     249    *fLog << "MFEventSelector2::ReadDistribution:" << endl;
     250    *fLog << " - Original distribution has " << fHistOrig->GetHist().GetEntries() << " entries." << endl;
     251    *fLog << " - End of eventloop to generate the original distribution." << endl;
    250252
    251253    return read.Rewind();
     
    266268    // set the nominal distribution equal to the original distribution
    267269
    268     TH1 *hnp;
    269     if (fUseOrigDistribution)
    270       hnp = (TH1*)(fHistOrig->GetHist()).Clone();
    271     else
    272       hnp = &fHistNom->GetHist();
     270    TH1 *hnp = fUseOrigDistribution ? (TH1*)(fHistOrig->GetHist()).Clone() : &fHistNom->GetHist();
    273271
    274272    TH1 &hn = *hnp;
     
    302300    if (fNumMax>0)
    303301    {
    304         *fLog << "MFEventSelector2::PrepareHistograms; requested no.of events = "
    305               << fNumMax << ",  maximum no.of events possible = "     
    306               << hn.Integral() << endl;
     302        *fLog << inf;
     303        *fLog << "MFEventSelector2::PrepareHistograms:" << endl;
     304        *fLog << " - requested number of events = " << fNumMax << endl;
     305        *fLog << " - maximum number of events possible = " << hn.Integral() << endl;
    307306
    308307        if (fNumMax > hn.Integral())
    309308        {
    310           *fLog << "MFEventSelector2::PrepareHistograms; requested no.of events ("
    311                 << fNumMax << ") is too high" << endl;
    312           *fLog << "                                     reduce it to "
    313                 << hn.Integral() << endl;
     309            *fLog << warn << "WARNING - Requested no.of events (" << fNumMax;
     310            *fLog << ") is too high... reduced to " << hn.Integral() << endl;
    314311        }
    315 
    316         else
    317           hn.Scale(fNumMax/hn.Integral());
     312        else
     313            hn.Scale(fNumMax/hn.Integral());
    318314    }
    319315
     
    358354            return kFALSE;
    359355        }
     356        // FALLTHROUGH!
    360357    case 2:
    361358        if (!fDataY.PreProcess(parlist))
     
    364361            return kFALSE;
    365362        }
     363        // FALLTHROUGH!
    366364    case 1:
    367365        if (!fDataX.PreProcess(parlist))
     
    385383Int_t MFEventSelector2::PreProcess(MParList *parlist)
    386384{
    387     memset(fErrors, 0, sizeof(fErrors));
     385    memset(fCounter, 0, sizeof(fCounter));
    388386
    389387    MTaskList *tasklist = (MTaskList*)parlist->FindObject("MTaskList");
     
    424422
    425423    return read->CallPreProcess(parlist);
     424}
     425
     426// --------------------------------------------------------------------------
     427//
     428// Part of Process(). Select() at the end checks whether a selection should
     429// be done or not. Under-/Overflowbins are rejected.
     430//
     431Bool_t MFEventSelector2::Select(Int_t bin)
     432{
     433    // under- and overflow bins are not counted
     434    if (bin<0)
     435        return kFALSE;
     436
     437    Bool_t rc = kFALSE;
     438
     439    if (gRandom->Rndm()*fIs[bin]<=fNom[bin])
     440    {
     441        // how many events do we still want to read in this bin
     442        fNom[bin] -= 1;
     443        rc = kTRUE;
     444
     445        // fill bin (same as Fill(valx, valy, valz))
     446        TH1 &h = fHistRes->GetHist();
     447        h.AddBinContent(bin+1);
     448        h.SetEntries(h.GetEntries()+1);
     449    }
     450
     451    // how many events are still pending to be read
     452    fIs[bin] -= 1;
     453
     454    return rc;
    426455}
    427456
     
    436465Int_t MFEventSelector2::Process()
    437466{
    438     fResult = kFALSE;
    439 
    440467    // get x,y and z (0 if fData not valid)
    441468    const Double_t valx=fDataX.GetValue();
     
    443470    const Double_t valz=fDataZ.GetValue();
    444471
    445 
    446     // get corresponding bin number
    447     const Int_t bin = fHistNom->FindFixBin(valx, valy, valz)-1;
    448 
    449     // under- and overflow bins are not counted
    450     if (bin<0)
    451         return kTRUE;
    452 
    453 
    454     if (gRandom->Rndm()*fIs[bin]<=fNom[bin])
    455     {
    456         // how many events do we still want to read in this bin
    457         fNom[bin]-=1;
    458         fResult = kTRUE;
    459 
    460         // fill bin (same as Fill(valx, valy, valz))
    461         TH1 &h = fHistRes->GetHist();
    462         h.AddBinContent(bin+1);
    463         h.SetEntries(h.GetEntries()+1);
    464     }
    465     // how many events are still pending to be read
    466     fIs[bin]-=1;
    467 
    468     //----------------------
    469     Int_t rc;
    470     if (fResult)
    471     {
    472         rc = 0;
    473         fErrors[rc]++;
    474         return kTRUE;
    475     }
    476     rc = 1;
    477     fErrors[rc]++;
    478     //----------------------
     472    // Get corresponding bin number and check
     473    // whether a selection should be made
     474    fResult = Select(fHistNom->FindFixBin(valx, valy, valz)-1);
     475
     476    fCounter[fResult ? 1 : 0]++;
    479477
    480478    return kTRUE;
     
    488486{
    489487    //---------------------------------
    490     if (GetNumExecutions() != 0)
     488
     489    if (GetNumExecutions()>0)
    491490    {
    492491      *fLog << inf << endl;
    493492      *fLog << GetDescriptor() << " execution statistics:" << endl;
    494493      *fLog << dec << setfill(' ');
    495       *fLog << " " << setw(7) << fErrors[1] << " (" << setw(3)
    496             << (int)(fErrors[1]*100/GetNumExecutions())
     494      *fLog << " " << setw(7) << fCounter[1] << " (" << setw(3)
     495            << (int)(fCounter[0]*100/GetNumExecutions())
    497496            << "%) Events not selected" << endl;
    498497
    499       *fLog << " " << fErrors[0] << " ("
    500             << (int)(fErrors[0]*100/GetNumExecutions())
    501             << "%) Events selected!" << endl;
     498      *fLog << " " << fCounter[0] << " ("
     499            << (int)(fCounter[1]*100/GetNumExecutions())
     500            << "%) Events selected" << endl;
    502501      *fLog << endl;
    503502    }
     503
    504504    //---------------------------------
    505505
    506     if (!fCanvas || !fDisplay)
    507         return kTRUE;
    508 
    509     fCanvas->cd(4);
    510     fHistRes->DrawClone("nonew");
    511     fCanvas->Modified();
    512     fCanvas->Update();
     506    if (fDisplay && fDisplay->HasCanvas(fCanvas))
     507    {
     508        fCanvas->cd(4);
     509        fHistRes->DrawClone("nonew");
     510        fCanvas->Modified();
     511        fCanvas->Update();
     512    }
    513513
    514514    return kTRUE;
    515515}
    516 
    517 
    518 
    519 
    520 
    521 
    522 
    523 
    524 
  • trunk/MagicSoft/Mars/mfilter/MFEventSelector2.h

    r2574 r2587  
    4444
    4545    Bool_t fResult;
    46     Int_t fErrors[2];
     46    Int_t  fCounter[2];
    4747
    4848    TH1   &InitHistogram(MH3* &hist);
     
    5050    void   PrepareHistograms();
    5151    Bool_t PreProcessData(MParList *parlist);
     52    Bool_t Select(Int_t bin);
    5253
    5354    Int_t PreProcess(MParList *parlist);
Note: See TracChangeset for help on using the changeset viewer.