Changeset 5692


Ignore:
Timestamp:
01/03/05 12:02:16 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Makefile

    r5065 r5692  
    5858          mimage \
    5959          mmontecarlo \
     60          mhft \
    6061          mmc \
    6162          mraw \
  • trunk/MagicSoft/Mars/NEWS

    r5691 r5692  
    2020     MGeomCamMagic to a enhanced geometry MGeomCamMagicXT having only
    2121     small pixels
     22
     23   - added possibility to write data to memory (TTree) using MReadTree
     24
     25   - added possibility to read a TTree stored only in memory by MReadTree
    2226
    2327
  • trunk/MagicSoft/Mars/mbase/MLog.cc

    r5551 r5692  
    1818!   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2004
     20!   Copyright: MAGIC Software Development, 2000-2005
    2121!
    2222!
     
    116116using namespace std;
    117117
     118#undef DEBUG
     119//#define DEBUG
     120
     121
    118122// root 3.02:
    119123// check for TObjectWarning, TObject::Info, gErrorIgnoreLevel
     
    216220    DeallocateFile();
    217221
     222#ifdef DEBUG
     223    TIter Next(fPlugins);
     224    TObject *o=0;
     225    while ((o=Next()))
     226    {
     227        cout << "Delete: " << o->GetName() << std::flush;
     228        cout << " [" << o->ClassName() << "]" << endl;
     229        delete o;
     230    }
     231
     232    cout << "Delete: fPlugins " << fPlugins << "..." << std::flush;
     233#endif
     234
    218235    delete fPlugins;
     236#ifdef DEBUG
     237    cout << "done." << endl;
     238#endif
     239
    219240#ifdef _REENTRANT
    220241    delete fMuxStream;
  • trunk/MagicSoft/Mars/mbase/MParContainer.cc

    r5557 r5692  
    1818!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2004
     20!   Copyright: MAGIC Software Development, 2000-2005
    2121!
    2222!
     
    109109{
    110110#ifdef DEBUG
     111    if (fName.IsNull() || fName==(TString)"MTime")
     112        return;
     113
    111114    *fLog << all << "Deleting " << GetDescriptor() << endl;
     115    if (TestBit(kMustCleanup) && gROOT && gROOT->MustClean())
     116    {
     117        *fLog << "Recursive Remove..." << flush;
     118        if (TestBit(kCanDelete))
     119            *fLog << "kCanDelete..." << flush;
     120        TIter Next(gROOT->GetListOfCleanups());
     121        TObject *o=0;
     122        while ((o=Next()))
     123            *fLog << dbg << o->GetName() << " [" << o->ClassName() << "]" << endl;
     124        *fLog << dbg << "Removing..." << flush;
     125        gROOT->GetListOfCleanups()->RecursiveRemove(this);
     126        *fLog << "Removed." << endl;
     127    }
    112128#endif
    113129}
  • trunk/MagicSoft/Mars/mbase/MTaskList.cc

    r5030 r5692  
    879879
    880880}
     881
     882// --------------------------------------------------------------------------
     883//
     884//  Find an object with the same name in the list and replace it with
     885//  the new one. If the kIsOwner flag is set and the object was not
     886//  created automatically, the object is deleted.
     887//
     888Bool_t MTaskList::Replace(MTask *task)
     889{
     890    //
     891    //  check if the object (you want to add) exists
     892    //
     893    if (!task)
     894        return kFALSE;
     895
     896    if (task==this)
     897    {
     898        *fLog << warn << "WARNING - You cannot add a tasklist to itself.  This" << endl;
     899        *fLog << "          would create infinite recursions...ignored." << endl;
     900        return kFALSE;
     901
     902    }
     903
     904    MTask *obj = (MTask*)FindObject(task->GetName());
     905    if (!obj)
     906    {
     907        *fLog << warn << "No object with the same name '";
     908        *fLog << task->GetName() << "' in list... adding." << endl;
     909        return AddToList(task);
     910    }
     911
     912    if (task==obj)
     913        return kTRUE;
     914
     915    *fLog << inf << "Adding " << task->GetName() << " to " << GetName() << " for " << obj->GetStreamId() << "... " << flush;
     916    task->SetStreamId(obj->GetStreamId());
     917    task->SetBit(kMustCleanup);
     918    fTasks->AddAfter((TObject*)obj, task);
     919    *fLog << "Done." << endl;
     920
     921    RemoveFromList(obj);
     922
     923    if (TestBit(kIsOwner))
     924        delete obj;
     925
     926    //*fLog << inf << "MTask '" << task->GetName() << "' found and replaced..." << endl;
     927
     928    return kTRUE;
     929}
  • trunk/MagicSoft/Mars/mbase/MTaskList.h

    r4828 r5692  
    4949    void SetSerialNumber(Byte_t num);
    5050
     51    Bool_t Replace(MTask *obj);
    5152    Bool_t RemoveFromList(MTask *task);
    5253
  • trunk/MagicSoft/Mars/mdata/MDataArray.cc

    r5100 r5692  
    1818!   Author(s): Thomas Bretz  08/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2004
     20!   Copyright: MAGIC Software Development, 2000-2005
    2121!
    2222!
     
    8686// --------------------------------------------------------------------------
    8787//
     88// Try to find a MData which has the same rule (GetRule()).
     89// Be carefull: This may already fail if the rule is A*B and you are
     90// searching for B*A - FIXME: A more intelligent comaparton (based on
     91// IsEqual()) should be developed.
     92//
     93// Returns the index in the array, -1 if rule was not found.
     94//
     95Int_t MDataArray::FindRule(const char *rule) const
     96{
     97    const MDataChain data(rule);
     98    if (!data.IsValid())
     99        return -1;
     100
     101    const TString r(data.GetRule());
     102
     103    TIter Next(&fList);
     104    const MData *d = NULL;
     105    while ((d=(MData*)Next()))
     106        if (d->GetRule()==r)
     107            return fList.IndexOf(d);
     108
     109    return -1;
     110}
     111
     112// --------------------------------------------------------------------------
     113//
    88114// Return the i-th entry
    89115//
     
    131157    Int_t n=0;
    132158
    133     TIter Next(&fList);
    134     MData *data = NULL;
    135     while ((data=(MData*)Next()))
    136     {
    137         *fLog << all << " " << fName << "[" << setw(3) << n++ << "] = " << flush;
     159    const Int_t w = 1+(Int_t)TMath::Log10(fList.GetEntries());
     160
     161    TIter Next(&fList);
     162    MData *data = NULL;
     163    while ((data=(MData*)Next()))
     164    {
     165        *fLog << all << " " << fName << "[" << setw(w) << n++ << "] = " << flush;
    138166        data->Print();
    139167        *fLog << endl;
  • trunk/MagicSoft/Mars/mdata/MDataArray.h

    r3572 r5692  
    3232    void AddEntry(MData *data);
    3333
     34    Int_t FindRule(const char *rule) const;
     35
    3436    MData &operator[](Int_t i) const;
    3537    Double_t operator()(Int_t i) const;
  • trunk/MagicSoft/Mars/mdata/MDataChain.cc

    r3788 r5692  
    1818!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2004
     20!   Copyright: MAGIC Software Development, 2000-2005
    2121!
    2222!
     
    211211        return;
    212212
    213     *fLog << inf << "Trying to resolve rule... " << flush;
     213    *fLog << inf << "Parsing rule... " << flush;
    214214    if (!(fMember=ParseString(rule, 1)))
    215215    {
  • trunk/MagicSoft/Mars/mfbase/MF.cc

    r5300 r5692  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz  01/2002 <mailto:tbretz@uni-sw.gwdg.de>
    19 !
    20 !   Copyright: MAGIC Software Development, 2000-2002
     18!   Author(s): Thomas Bretz  01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
     19!
     20!   Copyright: MAGIC Software Development, 2000-2005
    2121!
    2222!
     
    122122    fTitle = title ? title : gsDefTitle.Data();
    123123
    124     *fLog << inf << "Trying to resolve filter rule... " << flush;
     124    *fLog << inf << "Parsing filter rule... " << flush;
    125125    if (!(fF=ParseString(text, 1)))
    126126    {
  • trunk/MagicSoft/Mars/mfileio/MReadTree.cc

    r5160 r5692  
    1818!   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2003
     20!   Copyright: MAGIC Software Development, 2000-2005
    2121!
    2222!
     
    2424
    2525/////////////////////////////////////////////////////////////////////////////
    26 //                                                                         //
    27 // MReadTree                                                               //
    28 //                                                                         //
    29 // This tasks opens all branches in a specified tree and creates the       //
    30 // corresponding parameter containers if not already existing in the       //
    31 // parameter list.                                                         //
    32 //                                                                         //
    33 // The Process function reads one events from the tree. To go through the  //
    34 // events of one tree make sure that the event number is increased from    //
    35 // outside. It makes also possible to go back by decreasing the number.    //
    36 //                                                                         //
    37 // If you don't want to start reading the first event you have to call     //
    38 // MReadTree::SetEventNum after instantiating your MReadTree-object.       //
    39 //                                                                         //
    40 // To make reading much faster (up to a factor of 10 to 20) you can        //
    41 // ensure that only the data you are really processing is enabled by       //
    42 // calling MReadTree::UseLeaf.                                             //
    43 //                                                                         //
    44 // If the chain switches from one file to another file all                 //
    45 // TObject::Notify() functions are called of TObject objects which were    //
    46 // added to the Notifier list view MReadTree::AddNotify. If MReadTree      //
    47 // is the owner (viw MReadTree::SetOwner) all this objects are deleted     //
    48 // by the destructor of MReadTree                                          //
    49 //                                                                         //
     26//
     27// MReadTree
     28//
     29// This tasks opens all branches in a specified tree and creates the
     30// corresponding parameter containers if not already existing in the
     31// parameter list.
     32//
     33// The Process function reads one events from the tree. To go through the
     34// events of one tree make sure that the event number is increased from
     35// outside. It makes also possible to go back by decreasing the number.
     36//
     37// If you don't want to start reading the first event you have to call
     38// MReadTree::SetEventNum after instantiating your MReadTree-object.
     39//
     40// To make reading much faster (up to a factor of 10 to 20) you can
     41// ensure that only the data you are really processing is enabled by
     42// calling MReadTree::UseLeaf.
     43//
     44// If the chain switches from one file to another file all
     45// TObject::Notify() functions are called of TObject objects which were
     46// added to the Notifier list view MReadTree::AddNotify. If MReadTree
     47// is the owner (viw MReadTree::SetOwner) all this objects are deleted
     48// by the destructor of MReadTree
     49//
     50//
     51// ToDo:
     52// -----
     53//  - Auto Scheme and Branch choosing doesn't work for memory trees
     54//
    5055/////////////////////////////////////////////////////////////////////////////
    5156#include "MReadTree.h"
     
    7378// --------------------------------------------------------------------------
    7479//
    75 //  Default constructor. Don't use it.
    76 //
    77 MReadTree::MReadTree()
     80//  Default constructor. Use this constructor (ONLY) if you want to
     81//  access a memory tree (a TTree not stored in a file) created by
     82//  MWriteRootFile or manually.
     83//
     84MReadTree::MReadTree(TTree *tree)
    7885    : fNumEntry(0), fNumEntries(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE)
    7986{
     
    8188    fTitle = "Task to loop over all events in one single tree";
    8289
    83     fVetoList = NULL;
    84     fNotify = NULL;
     90    fVetoList = new TList;
     91    fVetoList->SetOwner();
     92
     93    fNotify = new TList;
    8594
    8695    fChain = NULL;
     96
     97    fTree = tree;
     98    SetBit(kChainWasChanged);
     99
     100    if (fTree)
     101        fAutoEnable = kFALSE;
     102    /*
     103    if (!fTree)
     104        return;
     105
     106    TIter Next(fTree->GetListOfBranches());
     107    TBranch *b=0;
     108    while ((b=(TBranch*)Next()))
     109        b->ResetAddress();
     110    */
    87111}
    88112
     
    114138    //
    115139    fChain = new MChain(tname);
     140    fTree = fChain;
    116141
    117142    // root 3.02:
     
    122147    if (fname)
    123148        AddFile(fname);
    124 //        if (fChain->Add(fname)>0)
    125 //            SetBit(kChainWasChanged);
    126149}
    127150
     
    137160    // creates a memory leak!
    138161    //
    139     TIter Next(fChain->GetStatus());
    140 
    141     TChainElement *element = NULL;
    142     while ((element=(TChainElement*)Next()))
    143         if (element->GetBaddress())
    144             delete (MParContainer**)element->GetBaddress();
    145 
    146     //
    147     // Delete the chain and the veto list
    148     //
     162    if (fChain) // FIXME: MEMORY LEAK for fTree!=0
     163    {
     164        TIter Next(fChain->GetStatus());
     165
     166        TChainElement *element = NULL;
     167        while ((element=(TChainElement*)Next()))
     168            if (element->GetBaddress())
     169                delete (MParContainer**)element->GetBaddress();
     170
     171        //
     172        // Delete the chain and the veto list
     173        //
    149174#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,00)
    150     if (fChain->GetFile())
    151         delete fChain->GetFile();
     175        if (fChain->GetFile())
     176            delete fChain->GetFile();
    152177#endif
    153     delete fChain;
     178        delete fChain;
     179    }
     180
     181    /* This is AND MUST be done in PostProcess. See there for more details
     182    else
     183    {
     184        TIter Next(fTree->GetListOfBranches());
     185
     186        TBranch *element = NULL;
     187        while ((element=(TBranch*)Next()))
     188            if (element->GetAddress())
     189                delete (MParContainer**)element->GetAddress();
     190        }
     191    */
    154192
    155193    delete fNotify;
     
    179217Bool_t MReadTree::CheckBranchSize()
    180218{
    181     TArrayI entries(fChain->GetStatus()->GetSize());
     219    //if (!fChain) // >FIXME: fTree!=0
     220    //    return kTRUE;
     221
     222    TArrayI entries(fChain ? fChain->GetStatus()->GetSize() : fTree->GetListOfBranches()->GetSize());
    182223    Int_t num=0;
    183224
    184225    // Loop over all branches which have a corresponding container
    185     TIter Next(fChain->GetStatus());
    186 
    187     TChainElement *element = NULL;
    188     while ((element=(TChainElement*)Next()))
    189     {
    190         // Get branch name and find pointer to corresponding branch
    191         const TString name = element->GetName();
    192         const TBranch *b = fChain->FindBranch(name);
    193 
    194         // Skip element without corresponding branches (like "*")
    195         if (!b)
    196             continue;
    197 
    198         entries[num++] = (Int_t)b->GetEntries();
     226    /*
     227    if (fChain)
     228    {
     229        TIter Next(fChain->GetStatus());
     230
     231        TChainElement *element = NULL;
     232        while ((element=(TChainElement*)Next()))
     233        {
     234            // Get branch name and find pointer to corresponding branch
     235            const TString name = element->GetName();
     236            const TBranch *b = fChain->FindBranch(name);
     237
     238            // Skip element without corresponding branches (like "*")
     239            if (!b)
     240                continue;
     241
     242            entries[num++] = (Int_t)b->GetEntries();
     243        }
     244    }
     245    else */
     246    {
     247        TIter Next(fTree->GetListOfBranches());
     248
     249        TBranch *element = NULL;
     250        while ((element=(TBranch*)Next()))
     251            entries[num++] = (Int_t)element->GetEntries();
    199252    }
    200253
     
    209262            *fLog << "  Due to several circumstances (such at a bug in MReadTree or wrong" << endl;
    210263            *fLog << "  usage of the file UPDATE mode) you may have produced a file in which" << endl;
    211             *fLog << "  at least two branches in the same tree (" << fChain->GetName() << ") have different" << endl;
     264            *fLog << "  at least two branches in the same tree (" << fTree->GetName() << ") have different" << endl;
    212265            *fLog << "  number of entries. Sorry, but this file (" << GetFileName() << ")" << endl;
    213266            *fLog << "  is unusable." << endl;
     
    278331Int_t MReadTree::AddFile(const char *fname, Int_t entries)
    279332{
     333    if (!fChain)
     334    {
     335        *fLog << err << "MReadTree::AddFile - ERROR: You cannot add a file, because MReadTree" << endl;
     336        *fLog <<        "                            handles a memory based tree or its default" << endl;
     337        *fLog <<        "                            constructor was called." << endl;
     338        return 0;
     339    }
     340
    280341#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,01)
    281342    //
     
    353414Int_t MReadTree::AddFiles(const MReadTree &read)
    354415{
     416    if (!fChain)
     417    {
     418        *fLog << err << "MReadTree::AddFiles - ERROR: You cannot add a file, because MReadTree" << endl;
     419        *fLog <<        "                             handles a memory based tree or its default" << endl;
     420        *fLog <<        "                             constructor was called." << endl;
     421        return 0;
     422    }
     423
    355424    const Int_t rc = fChain->Add(read.fChain);
    356425
     
    376445void MReadTree::SortFiles()
    377446{
    378     fChain->GetListOfFiles()->Sort();
     447    if (fChain)
     448        fChain->GetListOfFiles()->Sort();
    379449}
    380450
     
    392462
    393463    *fLog << inf << GetDescriptor() << ": Branch choosing enabled (only enabled branches are read)." << endl;
    394     fChain->SetBranchStatus("*", kFALSE);
     464    fTree->SetBranchStatus("*", kFALSE); // *CHANGED-fChain-to-fTree*
    395465    fBranchChoosing = kTRUE;
    396466}
     
    405475void MReadTree::EnableBranch(const char *name)
    406476{
     477    if (!fChain)
     478    {
     479        *fLog << warn << "MReadTree::EnableBranch - WARNING: EnableBranch doesn't work with memory based trees... ignored." << endl;
     480        return;
     481    }
     482
    407483    if (fChain->GetListOfFiles()->GetEntries()==0)
    408484    {
     
    424500void MReadTree::SetBranchStatus(const char *name, Bool_t status)
    425501{
    426     fChain->SetBranchStatus(name, status);
     502    fTree->SetBranchStatus(name, status); // *CHANGED-fChain-to-fTree*
    427503
    428504    *fLog << inf << (status ? "Enabled" : "Disabled");
     
    449525        bn.Remove(bn.Length()-1);
    450526
    451     if (fChain->GetBranch(bn))
     527    if (fTree->GetBranch(bn)) // *CHANGED-fChain-to-fTree*
    452528        SetBranchStatus(name, status);
    453529
     
    461537        return;
    462538
    463     if (fChain->GetBranch(dot+1))
     539    if (fTree->GetBranch(dot+1)) // *CHANGED-fChain-to-fTree*
    464540        SetBranchStatus(dot+1, status);
    465541}
     
    575651    if (TestBit(kChainWasChanged))
    576652    {
    577         *fLog << inf << "Scanning chain " << fChain->GetName() << "... " << flush;
    578         fNumEntries = (UInt_t)fChain->GetEntries();
     653        // *CHANGED-fChain-to-fTree*
     654        *fLog << inf << "Scanning chain " << fTree->GetName() << "... " << flush;
     655        fNumEntries = (UInt_t)fTree->GetEntries();
    579656        *fLog << fNumEntries << " events found." << endl;
    580657        ResetBit(kChainWasChanged);
     
    624701    // tasks are not preprocessed.
    625702    //
    626     fChain->SetNotify(NULL);
     703    fTree->SetNotify(NULL); //*CHANGED-fChain-to-fTree*
    627704
    628705    //
     
    633710    // it crashes. ResetTree makes sure, that the tree number is -1
    634711    //
    635     fChain->ResetTree();
     712    if (fChain) // *CHANGED-fChain-to-fTree*
     713        fChain->ResetTree();
    636714    // Maybe this would be enough, but the above might be safer...
    637715    //if (fChain->GetTreeNumber()==0)
     
    641719    // check for files and for the tree!
    642720    //
    643     if (!fChain->GetFile())
     721    if (fChain && !fChain->GetFile()) // *CHANGED-fChain-to-fTree*
    644722    {
    645723        *fLog << err << GetDescriptor() << ": No file or no tree with name " << fChain->GetName() << " in file." << endl;
     
    665743    // create the Iterator to loop over all branches
    666744    //
    667     TIter Next(fChain->GetListOfBranches());
     745    TIter Next(fTree->GetListOfBranches()); // *CHANGED-fChain-to-fTree*
    668746    TBranch *branch=NULL;
    669747
     
    728806        // If we created one already, delete it.
    729807        //
    730         TChainElement *element = (TChainElement*)fChain->GetStatus()->FindObject(bname);
    731         if (element)
    732             delete (MParContainer**)element->GetBaddress();
     808        // *CHANGED-fChain-to-fTree*
     809        if (fChain)
     810        {
     811            TChainElement *element = (TChainElement*)fChain->GetStatus()->FindObject(bname);
     812            if (element)
     813                delete (MParContainer**)element->GetBaddress();
     814        }
     815        /* This can't be done here for memory trees - see
     816           PostProcess for more details.
     817        else
     818        {
     819            TBranch *branch = (TBranch*)fTree->GetBranch(bname);
     820            if (branch)
     821            {
     822                *fLog << bname << " " << (void*)branch->GetAddress() << " " << pcont << endl;
     823                delete (MParContainer**)branch->GetAddress();
     824            }
     825        }
     826        */
    733827
    734828        //
     
    736830        // the actual branch should be stored - enable branch.
    737831        //
    738         fChain->SetBranchAddress(bname, pcont);
     832        fTree->SetBranchAddress(bname, pcont); // *CHANGED-fChain-to-fTree*
    739833
    740834        *fLog << inf << "Master branch address '" << bname << "' [";
     
    762856    // PreProcess-function.
    763857    //
    764     fChain->ResetTree();
    765     fChain->SetNotify(this);
    766 
    767     return GetSelector() ? GetSelector()->CallPreProcess(pList) : kTRUE;
     858    if (fChain)
     859        fChain->ResetTree(); // *CHANGED-fChain-to-fTree*
     860
     861    fTree->SetNotify(this); // *CHANGED-fChain-to-fTree*
     862
     863    const Int_t rc = GetSelector() ? GetSelector()->CallPreProcess(pList) : kTRUE;
     864    if (rc!=kTRUE || fChain)
     865        return rc;
     866
     867    return Notify();
    768868}
    769869
     
    775875void MReadTree::SetReadyToSave(Bool_t flag)
    776876{
     877    if (!fChain)
     878        return;
     879
    777880    TIter Next(fChain->GetStatus());
    778881
     
    870973    }
    871974
    872     const Bool_t rc = fChain->GetEntry(fNumEntry++) != 0;
     975    const Bool_t rc = fTree->GetEntry(fNumEntry++) != 0; // *CHANGED-fChain-to-fTree*
    873976
    874977    if (fTaskList)
    875         fTaskList->SetStreamId(fChain->GetName());
     978        fTaskList->SetStreamId(fTree->GetName()); // *CHANGED-fChain-to-fTree*
    876979
    877980    if (rc)
     
    887990Int_t MReadTree::PostProcess()
    888991{
     992    // In the case of a memory tree I don't know how we can
     993    // make a decision in PreProcess between a self allocated
     994    // memory address or a pending address set long before.
     995    // So we delete the stuff in PostProcess and not the destructor
     996    // (which might seg faullt if PreProcess has never been called)
     997    if (!fChain)
     998    {
     999        TIter Next(fTree->GetListOfBranches());
     1000        TBranch *b=0;
     1001        while ((b=(TBranch*)Next()))
     1002        {
     1003            if (b->GetAddress())
     1004            {
     1005                delete b->GetAddress();
     1006                b->ResetAddress();
     1007            }
     1008        }
     1009    }
     1010
    8891011    return GetSelector() ? GetSelector()->CallPostProcess() : kTRUE;
    8901012}
     
    8961018Bool_t MReadTree::GetEvent()
    8971019{
    898     Bool_t rc = fChain->GetEntry(fNumEntry) != 0;
     1020    Bool_t rc = fTree->GetEntry(fNumEntry) != 0; // *CHANGED-fChain-to-fTree*
    8991021
    9001022    if (rc)
     
    9811103TString MReadTree::GetFileName() const
    9821104{
    983     const TFile *file = fChain->GetFile();
     1105    const TFile *file = fChain ? fChain->GetFile() : fTree->GetCurrentFile();
    9841106
    9851107    if (!file)
     
    9971119Int_t MReadTree::GetFileIndex() const
    9981120{
    999     return fChain->GetTreeNumber();
     1121    return fChain ? fChain->GetTreeNumber() : 0;
    10001122    /*
    10011123    const TString filename = fChain->GetFile()->GetName();
  • trunk/MagicSoft/Mars/mfileio/MReadTree.h

    r5160 r5692  
    88class MChain;
    99class TBranch;
     10class TTree;
    1011class MTaskList;
    1112
     
    1516
    1617private:
    17     MChain *fChain;            // Pointer to tree
     18    MChain *fChain;            // Pointer to tree==fTree (only if fTree inherits from MChain)
     19    TTree  *fTree;             // Pointer to tree
    1820
    1921    UInt_t  fNumEntry;         // Number of actual entry in chain
     
    2325    Bool_t  fAutoEnable;       // Flag for auto enabeling scheme
    2426
    25     TList  *fVetoList;         // List of Branches which are not allowed to get enabled
    26     TList  *fNotify;           // List of TObjects to notify when switching files
     27    TList  *fVetoList;         //-> List of Branches which are not allowed to get enabled
     28    TList  *fNotify;           //-> List of TObjects to notify when switching files
    2729
    2830    MTaskList *fTaskList;      // Tasklist to set StreamId
     
    4749
    4850public:
    49     MReadTree();
     51    MReadTree(TTree *tree=0);
    5052    MReadTree(const char *treename, const char *filename=NULL, const char *name=NULL, const char *title=NULL);
    5153    ~MReadTree();
  • trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc

    r4826 r5692  
    1818!   Author(s): Thomas Bretz, 6/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2004
     20!   Copyright: MAGIC Software Development, 2000-2005
    2121!
    2222!
     
    3737// ReInit()) For more details se the corresponding constructor.
    3838//
     39// Memory based trees
     40// ------------------
     41// It is possible to store the data into memory (TTrees) instead of
     42// writing the data into a file. To do this either call the default
     43// constructor or specify 'memory' as option in the constructor.
     44//
     45// Afterwards the tree can be found using gROOT->FindObject("treename")
     46//
     47// Currently(!) the tree is not deleted at all! Please make sure to
     48// delete it if it is not used anymore - otherwise you could wast a LOT
     49// of memory. Please consider that this behaviour might change in the
     50// future.
     51//
     52// Such trees are usefull if you want to use more basic root-tools
     53// like TMultiLayerPerceptron or TEventList.
     54//
     55// If you want to process such memory based Trees using Mars make sure,
     56// that you don't need data from the RunHeader tree because you can
     57// only use MReadTree but not MReadMarsFile with such a tree.
     58//
    3959/////////////////////////////////////////////////////////////////////////////
    4060#include "MWriteRootFile.h"
     
    7292
    7393    //
    74     // Believing the root user guide, TTree instanced are owned by the
     94    // Believing the root user guide, TTree instances are owned by the
    7595    // directory (file) in which they are. This means we don't have to
    7696    // care about their destruction.
     
    87107{
    88108    Init();
    89 
    90     //
    91     // Set the Arrays the owner of its entries. This means, that the
    92     // destructor of the arrays will delete all its entries.
    93     //
    94     fBranches.SetOwner();
    95109}
    96110
     
    133147//
    134148MWriteRootFile::MWriteRootFile(const char *fname,
    135                                const Option_t *opt,
     149                               const Option_t *option,
    136150                               const char *ftitle,
    137151                               const Int_t comp,
    138152                               const char *name,
    139                                const char *title)
     153                               const char *title) : fOut(NULL)
    140154{
    141155    Init(name, title);
     156
     157    TString opt(option);
     158    opt.ToLower();
     159
     160    //
     161    // Check if we are writing to memory
     162    //
     163    if (opt.Contains("memory"))
     164    {
     165        fSplitRule = fname;
     166        return;
     167    }
    142168
    143169    //
     
    172198    Print();
    173199
    174     //
    175     // If the file is still open (no error) write the keys. This is necessary
    176     // for appearance of the all trees and branches.
    177     //
    178     if (IsFileOpen())
    179         fOut->Write();
    180 
    181     //
    182     // Delete the file. This'll also close the file (if open)
    183     //
    184     delete fOut;
    185     fOut = 0;
     200    if (fOut)
     201    {
     202        //
     203        // If the file is still open (no error) write the keys. This is necessary
     204        // for appearance of the all trees and branches.
     205        //
     206        if (IsFileOpen())
     207            fOut->Write();
     208
     209        //
     210        // Delete the file. This'll also close the file (if open)
     211        //
     212        delete fOut;
     213        fOut = 0;
     214    }
    186215
    187216    //
     
    257286void MWriteRootFile::AddContainer(const char *cname, const char *tname, Bool_t must)
    258287{
     288    if (!fOut && !tname)
     289        tname = fSplitRule;
     290
    259291    TIter Next(&fBranches);
    260292    TObject *o=0;
     
    262294        if (TString(o->GetName())==TString(tname) && TString(o->GetTitle())==TString(cname))
    263295        {
     296            *fLog << warn;
    264297            *fLog << "WARNING - Container '" << cname << "' in Tree '" << tname << "' already scheduled... ignored." << endl;
    265298            return;
     
    290323                                  Bool_t must)
    291324{
     325    if (!fOut && !tname)
     326        tname = fSplitRule;
     327
    292328    TIter Next(&fBranches);
    293329    TObject *o=0;
     
    296332            static_cast<MRootFileBranch*>(o)->GetContainer()==cont)
    297333        {
     334            *fLog << warn;
    298335            *fLog << "WARNING - Container " << cont << " in Tree '" << tname << "' already scheduled... ignored." << endl;
    299336            return;
     
    378415
    379416        //
    380         // Check if the tree is already existing (part of the file)
    381         //
    382         TTree *tree = (TTree*)fOut->Get(tname);
     417        // Check if the tree is already existing (part of the file or memory)
     418        //
     419        TTree *tree = fOut ? (TTree*)fOut->Get(tname) : dynamic_cast<TTree*>(gROOT->FindObject(tname));
     420        if (!fOut && tree)
     421        {
     422            if (tree->GetCurrentFile())
     423            {
     424                *fLog << err;
     425                *fLog << "ERROR - You are trying to write data into a memory stored root tree," << endl;
     426                *fLog << "        because you either called the default constructor  or  have" << endl;
     427                *fLog << "        instantiated MWriteRootFile using the write option 'memory'." << endl;
     428                *fLog << "        This  tree   '" << tname << "'   is  already  existing  in" << endl;
     429                *fLog << "        memory  (gROOT->FindObject)  and is already belonging  to a" << endl;
     430                *fLog << "        file (" << tree->GetCurrentFile()->GetName() << ")." << endl;
     431                *fLog << "        This can  - for example -  happen if you are reading from a" << endl;
     432                *fLog << "        tree with the same name.  The easiest solution in this case" << endl;
     433                *fLog << "        is to change the name of the tree you want to write to." << endl;
     434                *fLog << endl;
     435                return kFALSE;
     436            }
     437            *fLog << inf << "Tree '" << tname << "' found already in Memory... using." << endl;
     438        }
     439
    383440        if (!tree)
    384441        {
     
    389446            //
    390447            TDirectory *save = gDirectory;
    391             fOut->cd();
    392 
    393             tree = new TTree(tname, ttitle);
     448            if (fOut)
     449                fOut->cd();
     450            else
     451                gROOT->cd();
     452
     453            tree = new TTree(tname, ttitle, fOut ? 99 : 1);
    394454            fTrees.AddLast(tree);
    395455
     
    567627
    568628    //
     629    // If we are writing into memory we don't split into seperate files
     630    //
     631    if (!fOut)
     632        return kTRUE;
     633
     634    //
    569635    // For more information see TTree:ChangeFile()
    570636    //
     
    774840// --------------------------------------------------------------------------
    775841//
    776 // return open state of the root file.
     842// return open state of the root file. If the file is 'memory' kTRUE is
     843// returned.
    777844//
    778845Bool_t MWriteRootFile::IsFileOpen() const
    779846{
     847    if (!fOut)
     848        return kTRUE;
     849
    780850    const char *n = fOut->GetName();
    781851    return n==0 || *n==0 ? kTRUE : fOut->IsOpen();
     
    784854// --------------------------------------------------------------------------
    785855//
    786 // return name of the root-file
     856// return name of the root-file. If the file is "memory" "<memory>" is
     857// returned.
    787858//
    788859const char *MWriteRootFile::GetFileName() const
    789860{
     861    if (!fOut)
     862        return "<memory>";
     863
    790864    const char *n = fOut->GetName();
    791865    return n==0 || *n==0 ? "<dummy>" : n;
     
    794868// --------------------------------------------------------------------------
    795869//
    796 // cd into file. See TFile::cd()
     870// cd into file. See TFile::cd(). If the file is "memory" kTRUE is returned.
    797871//
    798872Bool_t MWriteRootFile::cd(const char *path)
    799873{
    800     return fOut->cd(path);
     874    return fOut ? fOut->cd(path) : kTRUE;
    801875}
    802876
     
    809883void MWriteRootFile::StreamPrimitive(ofstream &out) const
    810884{
    811     out << "   MWriteRootFile " << GetUniqueName() << "(\"";
    812     out << fOut->GetName() << "\", \"";
    813     out << fOut->GetOption() << "\", \"";
    814     out << fOut->GetTitle() << "\", ";
    815     out << fOut->GetCompressionLevel();
    816 
    817     if (fName!=gsDefName || fTitle!=gsDefTitle)
    818     {
    819         out << ", \"" << fName << "\"";
    820         if (fTitle!=gsDefTitle)
    821             out << ", \"" << fTitle << "\"";
    822     }
    823     out << ");" << endl;
    824 
     885    out << "   MWriteRootFile " << GetUniqueName();
     886    if (fOut)
     887    {
     888        out << "(\"";
     889        out << fOut->GetName() << "\", \"";
     890        out << fOut->GetOption() << "\", \"";
     891        out << fOut->GetTitle() << "\", ";
     892        out << fOut->GetCompressionLevel();
     893        out << ")";
     894    }
     895    out << ";" << endl;
     896
     897    if (fName!=gsDefName)
     898        out << "   " << GetUniqueName() << ".SetName(\"" << fName << "\");" << endl;
     899    if (fTitle!=gsDefTitle)
     900        out << "   " << GetUniqueName() << ".SetTitle(\"" << fTitle << "\");" << endl;
    825901
    826902    MRootFileBranch *entry;
  • trunk/MagicSoft/Mars/mhbase/MBinning.h

    r5143 r5692  
    3838    MBinning(const char *name=NULL, const char *title=NULL);
    3939    MBinning(Int_t nbins, Axis_t lo, Axis_t hi, const char *name=0, const char *opt="", const char *title=NULL);
     40    MBinning(const MBinning &bins) { SetEdges(bins); }
     41
     42    void Copy(TObject &named) const
     43    {
     44        MBinning &bins = (MBinning&)named;
     45        bins.SetEdges(*this);
     46    }
    4047
    4148    void SetEdges(const TArrayD &arr)
    4249    {
    4350        fEdges = arr;
    44         fType = kIsUserArray;
     51        fType  = kIsUserArray;
    4552    }
    4653
    4754    void SetEdges(const TAxis &axe);
    48     void SetEdges(const MBinning &bins) { SetEdges(fEdges); }
     55    void SetEdges(const MBinning &bins) { SetEdges(bins.fEdges); fType = bins.fType; }
    4956    void SetEdges(const TH1 &h, const Char_t axis='x');
    5057    void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up);
  • trunk/MagicSoft/Mars/mhbase/MHMatrix.cc

    r5100 r5692  
    160160    }
    161161
     162    const Int_t idx = fData->FindRule(rule);
     163    if (idx>=0)
     164        return idx;
     165
    162166    fData->AddEntry(rule);
    163167    return fData->GetNumEntries()-1;
  • trunk/MagicSoft/Mars/mhbase/MHMatrix.h

    r4646 r5692  
    115115    void ReduceRows(UInt_t num);
    116116
    117     ClassDef(MHMatrix, 1) // Multidimensional Matrix to store events
     117    ClassDef(MHMatrix, 1) // Multidimensional Matrix (TMatrix) to store events
    118118};
    119119
  • trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc

    r5114 r5692  
    4141#include <TF1.h>
    4242#include <TH1.h>
     43#include <TH3.h>
     44
     45#include <TRandom.h>
    4346
    4447#include <TLatex.h>
     
    5154
    5255using namespace std;
     56
     57void MAlphaFitter::Clear(Option_t *o)
     58{
     59    fSignificance=0;
     60    fEventsExcess=0;
     61    fEventsSignal=0;
     62    fEventsBackground=0;
     63
     64    fChiSqSignal=0;
     65    fChiSqBg=0;
     66    fIntegralMax=0;
     67
     68    fCoefficients.Reset();
     69}
    5370
    5471// --------------------------------------------------------------------------
     
    84101Bool_t MAlphaFitter::Fit(TH1D &h, Bool_t paint)
    85102{
     103    Clear();
     104    if (h.GetEntries()==0)
     105        return kFALSE;
     106
    86107    Double_t sigmax=fSigMax;
    87108    Double_t bgmin =fBgMin;
     
    175196     //fSignificance = MMath::SignificanceLiMaSigned(s, b);
    176197
    177 
    178198    const Int_t bin = h.GetXaxis()->FindFixBin(fSigInt*0.999);
    179199
     
    190210}
    191211
     212Bool_t MAlphaFitter::Fit(TH1D &hon, TH1D &hof, Bool_t paint)
     213{
     214    /*
     215     Clear();
     216     if (hon.GetEntries()==0)
     217     return kFALSE;
     218     */
     219
     220    TH1D h(hon);
     221    h.Add(&hof, -1);
     222
     223    MAlphaFitter fit(*this);
     224    fit.SetPolynomOrder(1);
     225
     226    if (!fit.Fit(h, paint))
     227        return kFALSE;
     228
     229    fChiSqSignal = fit.GetChiSqSignal();
     230    fChiSqBg     = fit.GetChiSqBg();
     231    fCoefficients = fit.GetCoefficients();
     232
     233    const Int_t bin = hon.GetXaxis()->FindFixBin(fSigInt*0.999);
     234
     235    fIntegralMax      = hon.GetBinLowEdge(bin+1);
     236    fEventsBackground = hof.Integral(0, bin);
     237    fEventsSignal     = hon.Integral(0, bin);
     238    fEventsExcess     = fEventsSignal-fEventsBackground;
     239    fSignificance     = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground);
     240
     241    if (fEventsExcess<0)
     242        fEventsExcess=0;
     243/*
     244    TF1 func("", "gaus(0)+pol0(3)", 0., 90.);
     245
     246    const Double_t A  = fEventsSignal/bin;
     247    const Double_t dA = TMath::Abs(A);
     248    func.SetParLimits(0, -dA*4, dA*4);
     249    func.SetParLimits(2, 0, 90);
     250    func.SetParLimits(3, -dA, dA);
     251
     252    func.SetParameter(0, A);
     253    func.FixParameter(1, 0);
     254    func.SetParameter(2, fSigMax*0.75);
     255    func.SetParameter(3, 0);
     256
     257    // options : N  do not store the function, do not draw
     258    //           I  use integral of function in bin rather than value at bin center
     259    //           R  use the range specified in the function range
     260    //           Q  quiet mode
     261    TH1D h(hon);
     262    h.Add(&hof, -1);
     263    h.Fit(&func, "NQI", "", 0, 90);
     264
     265    fChiSqSignal = func.GetChisquare()/func.GetNDF();
     266
     267    const Int_t bin1 = h.GetXaxis()->FindFixBin(func.GetParameter(2)*2);
     268
     269    fChiSqBg = 0;
     270    for (int i=bin1; i<=h.GetNbinsX(); i++)
     271    {
     272        const Float_t val = h.GetBinContent(i);
     273        fChiSqBg = val*val;
     274    }
     275    if (fChiSqBg>0)
     276        fChiSqBg /= h.GetNbinsX()+1-bin1;
     277
     278    fCoefficients.Set(func.GetNpar(), func.GetParameters());
     279
     280    // ------------------------------------
     281    if (paint)
     282    {
     283        func.SetLineColor(kBlue);
     284        func.SetLineWidth(2);
     285        func.Paint("same");
     286    }
     287    // ------------------------------------
     288  */
     289    return kTRUE;
     290}
     291
    192292void MAlphaFitter::PaintResult(Float_t x, Float_t y, Float_t size) const
    193293{
    194     TLatex text(x, y, Form("\\sigma_{Li/Ma}=%.1f  \\omega=%.1f\\circ  E=%d  (\\alpha<%.1f\\circ)  (\\chi_{b}^{2}=%.1f  \\chi_{s}^{2}=%.1f)",
     294    TLatex text(x, y, Form("\\sigma_{Li/Ma}=%.1f  \\omega=%.1f\\circ  E=%d  (\\alpha<%.1f\\circ)  (\\chi_{b}^{2}/ndf=%.1f  \\chi_{s}^{2}/ndf=%.1f  c_{0}=%.1f)",
    195295                           fSignificance, GetGausSigma(),
    196296                           (int)fEventsExcess, fIntegralMax,
    197                            fChiSqBg, fChiSqSignal));
     297                           fChiSqBg, fChiSqSignal, fCoefficients[3]));
    198298
    199299    text.SetBit(TLatex::kTextNDC);
     
    210310    f.fBgMin        = fBgMin;
    211311    f.fBgMax        = fBgMax;
     312    f.fScaleMin     = fScaleMin;
     313    f.fScaleMax     = fScaleMax;
    212314    f.fPolynomOrder = fPolynomOrder;
     315    f.fScaleMode    = fScaleMode;
     316    f.fScaleUser    = fScaleUser;
    213317    f.fCoefficients.Set(fCoefficients.GetSize());
    214318    f.fCoefficients.Reset();
     
    227331    *fLog << " ...signal to " << fSigMax << " (integrate into bin at " << fSigInt << ")" << endl;
    228332    *fLog << " ...polynom order " << fPolynomOrder << endl;
    229 }
     333    *fLog << " ...scale mode: ";
     334    switch (fScaleMode)
     335    {
     336    case kNone:        *fLog << "none.";         break;
     337    case kEntries:     *fLog << "entries.";      break;
     338    case kIntegral:    *fLog << "integral.";     break;
     339    case kOffRegion:   *fLog << "off region.";   break;
     340    case kLeastSquare: *fLog << "least square."; break;
     341    case kUserScale:   *fLog << "user def (" << fScaleUser << ")"; break;
     342    }
     343    *fLog << endl;
     344
     345    if (TString(o).Contains("result"))
     346    {
     347        *fLog << "Result:" << endl;
     348        *fLog << " - Significance           " << fSignificance << endl;
     349        *fLog << " - Excess Events          " << fEventsExcess << endl;
     350        *fLog << " - Signal Events          " << fEventsSignal << endl;
     351        *fLog << " - Background Events      " << fEventsBackground << endl;
     352        *fLog << " - Chi^2/ndf (Signal)     " << fChiSqSignal << endl;
     353        *fLog << " - Chi^2/ndf (Background) " << fChiSqBg << endl;
     354        *fLog << " - Signal integrated      " << fIntegralMax << "°" << endl;
     355    }
     356}
     357
     358Bool_t MAlphaFitter::FitEnergy(const TH3D &hon, UInt_t bin, Bool_t paint)
     359{
     360    const TString name(Form("TempAlphaEnergy%06d", gRandom->Integer(1000000)));
     361    TH1D *h = hon.ProjectionZ(name, -1, 9999, bin, bin, "E");
     362    h->SetDirectory(0);
     363
     364    const Bool_t rc = Fit(*h, paint);
     365    delete h;
     366    return rc;
     367}
     368
     369Bool_t MAlphaFitter::FitTheta(const TH3D &hon, UInt_t bin, Bool_t paint)
     370{
     371    const TString name(Form("TempAlphaTheta%06d", gRandom->Integer(1000000)));
     372    TH1D *h = hon.ProjectionZ(name, bin, bin, -1, 9999, "E");
     373    h->SetDirectory(0);
     374
     375    const Bool_t rc = Fit(*h, paint);
     376    delete h;
     377    return rc;
     378}
     379
     380Bool_t MAlphaFitter::FitAlpha(const TH3D &hon, Bool_t paint)
     381{
     382    const TString name(Form("TempAlpha%06d", gRandom->Integer(1000000)));
     383    TH1D *h = hon.ProjectionZ(name, -1, 9999, -1, 9999, "E");
     384    h->SetDirectory(0);
     385
     386    const Bool_t rc = Fit(*h, paint);
     387    delete h;
     388    return rc;
     389}
     390
     391Bool_t MAlphaFitter::FitEnergy(const TH3D &hon, const TH3D &hof, UInt_t bin, Bool_t paint)
     392{
     393    const TString name1(Form("TempAlpha%06d_on",  gRandom->Integer(1000000)));
     394    const TString name0(Form("TempAlpha%06d_off", gRandom->Integer(1000000)));
     395    TH1D *h1 = hon.ProjectionZ(name1, -1, 9999, bin, bin, "E");
     396    TH1D *h0 = hof.ProjectionZ(name0, -1, 9999, bin, bin, "E");
     397    h1->SetDirectory(0);
     398    h0->SetDirectory(0);
     399
     400    Scale(*h0, *h1);
     401
     402    const Bool_t rc = Fit(*h1, *h0, paint);
     403
     404    delete h0;
     405    delete h1;
     406
     407    return rc;
     408}
     409
     410Bool_t MAlphaFitter::FitTheta(const TH3D &hon, const TH3D &hof, UInt_t bin, Bool_t paint)
     411{
     412    const TString name1(Form("TempAlpha%06d_on",  gRandom->Integer(1000000)));
     413    const TString name0(Form("TempAlpha%06d_off", gRandom->Integer(1000000)));
     414
     415    TH1D *h1 = hon.ProjectionZ(name1, bin, bin, -1, 9999, "E");
     416    TH1D *h0 = hof.ProjectionZ(name0, bin, bin, -1, 9999, "E");
     417    h1->SetDirectory(0);
     418    h0->SetDirectory(0);
     419
     420    Scale(*h0, *h1);
     421
     422    const Bool_t rc = Fit(*h1, *h0, paint);
     423
     424    delete h0;
     425    delete h1;
     426
     427    return rc;
     428}
     429
     430Bool_t MAlphaFitter::FitAlpha(const TH3D &hon, const TH3D &hof, Bool_t paint)
     431{
     432    const TString name1(Form("TempAlpha%06d_on",  gRandom->Integer(1000000)));
     433    const TString name0(Form("TempAlpha%06d_off", gRandom->Integer(1000000)));
     434
     435    TH1D *h1 = hon.ProjectionZ(name1, -1, 9999, -1, 9999, "E");
     436    TH1D *h0 = hof.ProjectionZ(name0, -1, 9999, -1, 9999, "E");
     437    h1->SetDirectory(0);
     438    h0->SetDirectory(0);
     439
     440    Scale(*h0, *h1);
     441
     442    const Bool_t rc = Fit(*h1, *h0, paint);
     443
     444    delete h0;
     445    delete h1;
     446
     447    return rc;
     448}
     449
     450void MAlphaFitter::Scale(TH1D &of, const TH1D &on) const
     451{
     452    Float_t scaleon = 1;
     453    Float_t scaleof = 1;
     454    switch (fScaleMode)
     455    {
     456    case kNone:
     457        return;
     458
     459    case kEntries:
     460        scaleon = on.GetEntries();
     461        scaleof = of.GetEntries();
     462        break;
     463
     464    case kIntegral:
     465        scaleon = on.Integral();
     466        scaleof = of.Integral();
     467        break;
     468
     469    case kOffRegion:
     470        {
     471            const Int_t min = on.GetXaxis()->FindFixBin(fScaleMin);
     472            const Int_t max = on.GetXaxis()->FindFixBin(fScaleMax);
     473            scaleon = on.Integral(min, max);
     474            scaleof = of.Integral(min, max);
     475        }
     476        break;
     477
     478    case kUserScale:
     479        scaleon = fScaleUser;
     480        break;
     481
     482    default:
     483        return;
     484    }
     485
     486    if (scaleof!=0)
     487        of.Scale(scaleon/scaleof);
     488}
  • trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h

    r5114 r5692  
    1515
    1616class TH1D;
     17class TH3D;
    1718
    1819class MAlphaFitter : public MParContainer
    1920{
     21public:
     22    enum ScaleMode_t {
     23        kNone,
     24        kEntries,
     25        kIntegral,
     26        kOffRegion,
     27        kLeastSquare,
     28        kUserScale
     29    };
    2030private:
    2131    Float_t fSigInt;
     
    2333    Float_t fBgMin;
    2434    Float_t fBgMax;
     35    Float_t fScaleMin;
     36    Float_t fScaleMax;
    2537    Int_t   fPolynomOrder;
    2638
     
    3850    TF1 *fFunc;
    3951
     52    ScaleMode_t fScaleMode;
     53    Double_t fScaleUser;
     54
    4055public:
    4156    // Implementing the function yourself is only about 5% faster
    42     MAlphaFitter(const char *name=0, const char *title=0) : fSigInt(15), fSigMax(75), fBgMin(45), fBgMax(85), fPolynomOrder(2), fCoefficients(3+fPolynomOrder+1), fFunc(new TF1("", Form("gaus(0) + pol%d(3)", fPolynomOrder), 0, 90))
     57    MAlphaFitter(const char *name=0, const char *title=0) : fSigInt(15), fSigMax(75), fBgMin(45), fBgMax(85), fScaleMin(40), fScaleMax(80), fPolynomOrder(2), fCoefficients(3+fPolynomOrder+1), fFunc(new TF1("", Form("gaus(0) + pol%d(3)", fPolynomOrder), 0, 90)), fScaleMode(kEntries), fScaleUser(1)
    4358    {
    4459        fName  = name  ? name  : "MAlphaFitter";
     
    5873    }
    5974
    60     void Print(Option_t *o=0) const;
     75    void Clear(Option_t *o="");
     76    void Print(Option_t *o="") const;
    6177    void Copy(TObject &o) const;
    6278    /*
     
    6783    */
    6884
     85    void SetScaleUser(Float_t scale)       { fScaleUser = scale; fScaleMode=kUserScale; }
     86    void SetScaleMode(ScaleMode_t mode)    { fScaleMode    = mode; }
    6987    void SetSignalIntegralMax(Float_t s)   { fSigInt       = s; }
    7088    void SetSignalFitMax(Float_t s)        { fSigMax       = s; }
    7189    void SetBackgroundFitMin(Float_t s)    { fBgMin        = s; }
    7290    void SetBackgroundFitMax(Float_t s)    { fBgMax        = s; }
     91    void SetScaleMin(Float_t s)            { fScaleMin     = s; }
     92    void SetScaleMax(Float_t s)            { fScaleMax     = s; }
    7393    void SetPolynomOrder(Int_t s)          { fPolynomOrder = s; delete fFunc; fFunc=new TF1 ("", Form("gaus(0) + pol%d(3)", s));
    7494        gROOT->GetListOfFunctions()->Remove(fFunc);
     
    93113
    94114    Bool_t Fit(TH1D &h, Bool_t paint=kFALSE);
     115    Bool_t Fit(TH1D &on, TH1D &off, Bool_t paint=kFALSE);
     116    Bool_t Fit(TH1D &on, TH1D *off, Bool_t paint=kFALSE)
     117    {
     118        return off ? Fit(on, *off, paint) : Fit(on, paint);
     119    }
     120
     121    Bool_t FitAlpha(const TH3D &h, Bool_t paint=kFALSE);
     122    Bool_t FitEnergy(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE);
     123    Bool_t FitTheta(const TH3D &h,  UInt_t bin, Bool_t paint=kFALSE);
     124
     125    Bool_t FitAlpha(const TH3D &on, const TH3D &off, Bool_t paint=kFALSE);
     126    Bool_t FitEnergy(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
     127    Bool_t FitTheta(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
     128
     129    Bool_t FitAlpha(const TH3D &on, const TH3D *off, Bool_t paint=kFALSE)
     130    {
     131        return off ? FitAlpha(on, *off, paint) : FitAlpha(on, paint);
     132    }
     133    Bool_t FitEnergy(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE)
     134    {
     135        return off ? FitEnergy(on, *off, bin, paint) : FitEnergy(on, bin, paint);
     136    }
     137    Bool_t FitTheta(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE)
     138    {
     139        return off ? FitTheta(on, *off, bin, paint) : FitTheta(on, bin, paint);
     140    }
     141
     142    void Scale(TH1D &off, const TH1D &on) const;
    95143
    96144    ClassDef(MAlphaFitter, 1)
  • trunk/MagicSoft/Mars/mhflux/MHAlpha.cc

    r5300 r5692  
    7575//
    7676MHAlpha::MHAlpha(const char *name, const char *title)
    77     : fResult(0), /*fExcess(0),*/ fEnergy(0), fPointPos(0), fTimeEffOn(0),
    78     fTime(0), fNameProjAlpha(Form("Alpha_%p", this)), fMatrix(0)
     77    : fOffData(0), fResult(0), /*fExcess(0),*/ fEnergy(0), fHillas(0),
     78    fPointPos(0), fTimeEffOn(0), fTime(0),
     79    fSkipHistTime(kFALSE), fSkipHistTheta(kFALSE), fSkipHistEnergy(kFALSE),
     80    //fEnergyMin(-1), fEnergyMax(-1), fSizeMin(-1), fSizeMax(-1),
     81    fMatrix(0)
    7982{
    8083    //
     
    100103
    101104
    102     fHEnergy.SetName("Energy");
    103     fHEnergy.SetTitle(" N_{exc} vs. E_{est} ");
    104     fHEnergy.SetXTitle("E_{est} [GeV]");
     105    //fHEnergy.SetName("Energy");
     106    //fHEnergy.SetTitle(" N_{exc} vs. E_{est} ");
     107    //fHEnergy.SetXTitle("E_{est} [GeV]");
    105108    fHEnergy.SetYTitle("N_{exc}");
    106109    fHEnergy.SetDirectory(NULL);
     
    184187    for (int i=1; i<=n; i++)
    185188    {
    186         TH1D *h = fHAlpha.ProjectionZ("Alpha_EE", -1, 9999, i, i, i==1?"E":"");
    187         if (fit.Fit(*h))
     189        if (fit.FitEnergy(fHAlpha, fOffData, i))
    188190        {
    189191            fHEnergy.SetBinContent(i, fit.GetEventsExcess());
    190192            fHEnergy.SetBinError(i, fit.GetEventsExcess()*0.2);
    191193        }
    192         delete h;
    193194    }
    194195}
     
    203204    for (int i=1; i<=n; i++)
    204205    {
    205         TH1D *h = fHAlpha.ProjectionZ("Alpha_EE", i, i, -1, 9999, i==1?"E":"");
    206         if (fit.Fit(*h))
     206        if (fit.FitTheta(fHAlpha, fOffData, i))
    207207        {
    208208            fHTheta.SetBinContent(i, fit.GetEventsExcess());
    209209            fHTheta.SetBinError(i, fit.GetEventsExcess()*0.2);
    210210        }
    211         delete h;
    212211    }
    213212}
     
    219218    fHTheta.Reset();
    220219
     220    if (fName!=(TString)"MHAlphaOff")
     221    {
     222        MHAlpha *hoff = (MHAlpha*)pl->FindObject("MHAlphaOff");
     223        if (!hoff)
     224            *fLog << inf << "No MHAlphaOff [MHAlpha] found... using current data only!" << endl;
     225        else
     226        {
     227            *fLog << inf << "MHAlphaOff [MHAlpha] found... using on-off mode!" << endl;
     228            SetOffData(*hoff);
     229        }
     230    }
     231
     232    fHillas = 0;
     233    /*
     234    if (fSizeMin>=0 || fSizeMax>=0)
     235    {
     236        fHillas = (MHillas*)pl->FindObject("MHillas");
     237        if (!fHillas)
     238        {
     239            *fLog << warn << "Size cut set, but MHillas not found... abort." << endl;
     240            return kFALSE;
     241        }
     242    }
     243    */
    221244    fEnergy = (MEnergyEst*)pl->FindObject("MEnergyEst");
    222245    if (!fEnergy)
    223         *fLog << warn << "MEnergyEst not found... ignored." << endl;
     246    { /*
     247        if (fEnergyMin>=0 || fEnergyMax>=0)
     248        {
     249            *fLog << warn << "Energy cut set, but MEnergyEst not found... abort." << endl;
     250            return kFALSE;
     251        } */
     252
     253        *fLog << warn << "MEnergyEst not found... " << flush;
     254
     255        if (!fHillas)
     256            fHillas = (MHillas*)pl->FindObject("MHillas");
     257        if (fHillas)
     258            *fLog << "using SIZE instead!" << endl;
     259        else
     260            *fLog << "ignored." << endl;
     261
     262        fHEnergy.SetName("Size");
     263        fHEnergy.SetTitle(" N_{exc} vs. Size ");
     264        fHEnergy.SetXTitle("Size [\\gamma]");
     265    }
     266    else
     267    {
     268        fHEnergy.SetName("Energy");
     269        fHEnergy.SetTitle(" N_{exc} vs. E_{est} ");
     270        fHEnergy.SetXTitle("E_{est} [GeV]");
     271    }
    224272
    225273    fPointPos = (MPointingPos*)pl->FindObject("MPointingPos");
     
    230278    if (!fTimeEffOn)
    231279        *fLog << warn << "MTimeEffectiveOnTime [MTime] not found... ignored." << endl;
     280    else
     281        *fTimeEffOn = MTime(); // FIXME: How to do it different?
    232282
    233283    fTime = (MTime*)pl->FindObject("MTime");
     
    246296
    247297    MBinning binst, binse, binsa;
    248     binst.SetEdges(fHAlpha, 'x');
    249     binse.SetEdges(fHAlpha, 'y');
    250     binsa.SetEdges(fHAlpha, 'z');
    251 
    252     MBinning *bins = (MBinning*)pl->FindObject("BinningTheta", "MBinning");
    253     if (fPointPos && bins)
    254         binst.SetEdges(*bins);
    255     if (!fPointPos)
    256         binst.SetEdges(1, 0, 90);
    257 
    258     bins = (MBinning*)pl->FindObject("BinningEnergyEst", "MBinning");
    259     if (fEnergy && bins)
    260         binse.SetEdges(*bins);
    261     if (!fEnergy)
    262         binse.SetEdges(1, 10, 100000);
    263 
    264     bins = (MBinning*)pl->FindObject("BinningAlpha", "MBinning");
    265     if (bins)
    266         binsa.SetEdges(*bins);
     298    binst.SetEdges(fOffData ? *fOffData : fHAlpha, 'x');
     299    binse.SetEdges(fOffData ? *fOffData : fHAlpha, 'y');
     300    binsa.SetEdges(fOffData ? *fOffData : fHAlpha, 'z');
     301
     302    if (!fOffData)
     303    {
     304        MBinning *bins = (MBinning*)pl->FindObject("BinningTheta", "MBinning");
     305        if (fPointPos && bins)
     306            binst.SetEdges(*bins);
     307        if (!fPointPos)
     308            binst.SetEdges(1, 0, 60);
     309
     310        bins = (MBinning*)pl->FindObject("BinningEnergyEst", "MBinning");
     311        if ((fEnergy||fHillas) && bins)
     312            binse.SetEdges(*bins);
     313        if (!fEnergy && !fHillas)
     314            binse.SetEdges(1, 10, 100000);
     315
     316        bins = (MBinning*)pl->FindObject("BinningAlpha", "MBinning");
     317        if (bins)
     318            binsa.SetEdges(*bins);
     319    }
    267320
    268321    binse.Apply(fHEnergy);
     
    321374    }
    322375
     376    // Check new 'last time'
     377    MTime *time = final ? fTime : fTimeEffOn;
     378
     379    if (time->GetAxisTime()<=fHTime.GetXaxis()->GetXmax())
     380    {
     381        *fLog << warn << "WARNING - New time-stamp " << *time << " lower" << endl;
     382        *fLog << "than upper edge of histogram... skipped." << endl;
     383        *fLog << "This should not happen. Maybe you started you eventloop with" << endl;
     384        *fLog << "an already initialized time stamp MTimeEffectiveOnTime?" << endl;
     385        rebin++;
     386        return;
     387    }
     388
     389    // Fit time histogram
    323390    MAlphaFitter fit(fFit);
    324     if (!fit.Fit(fHAlphaTime))
     391
     392    TH1D *h = fOffData ? fOffData->ProjectionZ("ProjTimeTemp", -1, 9999, -1, 9999, "E") : 0;
     393    const Bool_t rc = fit.Fit(fHAlphaTime, h);
     394    if (h)
     395        delete h;
     396
     397    if (!rc)
    325398        return;
    326399
     
    334407    // Prepare Histogram
    335408    //
    336 
    337     MTime *time = final ? fTime : fTimeEffOn;
    338409    if (final)
    339410        time->Plus1ns();
     
    363434{
    364435    Double_t alpha, energy, theta;
     436    Double_t size=-1;
    365437
    366438    if (fMatrix)
    367439    {
    368440        alpha  = (*fMatrix)[fMap[0]];
    369         energy = 1000;
    370         theta  =    0;
     441        energy = fMap[1]<0 ? -1 : (*fMatrix)[fMap[1]];
     442        size   = fMap[2]<0 ? -1 : (*fMatrix)[fMap[2]];
     443        //<0 ? 1000 : (*fMatrix)[fMap[1]];
     444        theta  = 0;
     445
     446        if (energy<0)
     447            energy=size;
     448        if (size<0)
     449            size=energy;
     450
     451        if (energy<0 && size<0)
     452            energy = size = 1000;
    371453    }
    372454    else
     
    380462
    381463        alpha  = hil->GetAlpha();
    382         energy = fEnergy   ? fEnergy->GetEnergy() : 1000;
     464        if (fHillas)
     465            size = fHillas->GetSize();
     466        energy = fEnergy   ? fEnergy->GetEnergy() : (fHillas?fHillas->GetSize():1000);
    383467        theta  = fPointPos ? fPointPos->GetZd()   : 0;
    384468    }
    385469
     470    // enhance histogram if necessary
    386471    UpdateAlphaTime();
    387472
     473    // Fill histograms
    388474    fHAlpha.Fill(theta, energy, TMath::Abs(alpha), w);
    389     fHAlphaTime.Fill(TMath::Abs(alpha), w);
     475
     476    // Check cuts
     477    /*
     478    if ( (fEnergyMin>=0 && energy<fEnergyMin) ||
     479         (fEnergyMax>=0 && energy>fEnergyMax) ||
     480         (fSizeMin>=0   && size  <fSizeMin)   ||
     481         (fSizeMax>=0   && size  >fSizeMin) )
     482         return kTRUE;
     483         */
     484
     485    if (!fSkipHistTime)
     486        fHAlphaTime.Fill(TMath::Abs(alpha), w);
    390487
    391488    return kTRUE;
     
    441538
    442539        padsave->cd(1);
    443         fHAlpha.ProjectionZ(fNameProjAlpha);
     540        TH1D *hon = fHAlpha.ProjectionZ("ProjAlpha");
     541        if (fOffData)
     542        {
     543            TH1D *hoff = fOffData->ProjectionZ("ProjAlphaOff");
     544            fFit.Scale(*hoff, *hon);
     545
     546            hon->SetMaximum();
     547            hon->SetMaximum(TMath::Max(hon->GetMaximum(), hoff->GetMaximum())*1.05);
     548
     549            if ((h0=(TH1D*)gPad->FindObject("ProjAlphaOnOff")))
     550            {
     551                h0->Reset();
     552                h0->Add(hoff, hon, -1);
     553                const Float_t min = h0->GetMinimum()*1.05;
     554                hon->SetMinimum(min<0 ? min : 0);
     555            }
     556        }
    444557        FitEnergyBins();
    445558        FitThetaBins();
     
    447560
    448561    if (o==(TString)"alpha")
    449         if ((h0 = (TH1D*)gPad->FindObject(fNameProjAlpha)))
     562        if ((h0 = (TH1D*)gPad->FindObject("ProjAlpha")))
    450563        {
    451564            // Do not store the 'final' result in fFit
    452565            MAlphaFitter fit(fFit);
    453             fit.Fit(*h0, kTRUE);
     566            TH1D *hoff = (TH1D*)gPad->FindObject("ProjAlphaOff");
     567            fit.Fit(*h0, hoff, kTRUE);
    454568            fit.PaintResult();
    455569        }
     
    459573
    460574    if (o==(TString)"theta")
     575    {
     576        TH1 *h = (TH1*)gPad->FindObject("Alpha_x");
     577        if (h)
     578        {
     579            TH1D *h2 = (TH1D*)fHAlpha.Project3D("dum_x");
     580            h2->SetDirectory(0);
     581            h2->Scale(fHTheta.Integral()/h2->Integral());
     582            h->Reset();
     583            h->Add(h2);
     584            delete h2;
     585        }
    461586        PaintText(fHTheta.Integral(), 0);
     587    }
    462588
    463589    if (o==(TString)"energy")
    464590    {
     591        TH1 *h = (TH1*)gPad->FindObject("Alpha_y");
     592        if (h)
     593        {
     594            TH1D *h2 = (TH1D*)fHAlpha.Project3D("dum_y");
     595            h2->SetDirectory(0);
     596            h2->Scale(fHEnergy.Integral()/h2->Integral());
     597            h->Reset();
     598            h->Add(h2);
     599            delete h2;
     600        }
     601
    465602        if (fHEnergy.GetMaximum()>1)
    466603        {
     
    469606        }
    470607        FitEnergySpec(kTRUE);
    471 
    472608    }
    473609
     
    494630    pad->cd(1);
    495631    gPad->SetBorderMode(0);
    496     h = fHAlpha.ProjectionZ(fNameProjAlpha, -1, 9999, -1, 9999, "E");
     632
     633    h = fHAlpha.ProjectionZ("ProjAlpha", -1, 9999, -1, 9999, "E");
    497634    h->SetBit(TH1::kNoTitle);
     635    h->SetStats(kTRUE);
    498636    h->SetXTitle("\\alpha [\\circ]");
    499637    h->SetYTitle("Counts");
     
    501639    h->SetMarkerStyle(kFullDotMedium);
    502640    h->SetBit(kCanDelete);
    503     h->Draw();
     641    h->Draw("");
     642
     643    if (fOffData)
     644    {
     645        h->SetMarkerColor(kGreen);
     646
     647        h = fOffData->ProjectionZ("ProjAlphaOff", -1, 9999, -1, 9999, "E");
     648        h->SetBit(TH1::kNoTitle|TH1::kNoStats);
     649        h->SetXTitle("\\alpha [\\circ]");
     650        h->SetYTitle("Counts");
     651        h->SetDirectory(NULL);
     652        h->SetMarkerStyle(kFullDotMedium);
     653        h->SetBit(kCanDelete);
     654        h->SetMarkerColor(kRed);
     655        h->Draw("same");
     656
     657        h = (TH1D*)h->Clone("ProjAlphaOnOff");
     658        h->SetBit(TH1::kNoTitle);
     659        h->SetXTitle("\\alpha [\\circ]");
     660        h->SetYTitle("Counts");
     661        h->SetDirectory(NULL);
     662        h->SetMarkerStyle(kFullDotMedium);
     663        h->SetBit(kCanDelete);
     664        h->SetMarkerColor(kBlue);
     665        h->Draw("same");
     666
     667        TLine lin;
     668        lin.SetLineStyle(kDashed);
     669        lin.DrawLine(0, 0, 90, 0);
     670    }
     671
    504672    // After the Alpha-projection has been drawn. Fit the histogram
    505673    // and paint the result into this pad
     
    511679        gPad->SetBorderMode(0);
    512680        fHEnergy.Draw();
     681
    513682        AppendPad("energy");
     683
     684        h = (TH1D*)fHAlpha.Project3D("y");
     685        h->SetBit(TH1::kNoTitle|TH1::kNoStats);
     686        h->SetXTitle("E [GeV]");
     687        h->SetYTitle("Counts");
     688        h->SetDirectory(NULL);
     689        h->SetMarkerStyle(kFullDotMedium);
     690        h->SetBit(kCanDelete);
     691        h->SetMarkerColor(kCyan);
     692        h->SetLineColor(kCyan);
     693        h->Draw("Psame");
    514694    }
    515695    else
     
    531711        gPad->SetBorderMode(0);
    532712        fHTheta.Draw();
     713
    533714        AppendPad("theta");
     715
     716        h = (TH1D*)fHAlpha.Project3D("x");
     717        h->SetBit(TH1::kNoTitle|TH1::kNoStats);
     718        h->SetXTitle("\\theta [\\circ]");
     719        h->SetYTitle("Counts");
     720        h->SetDirectory(NULL);
     721        h->SetMarkerStyle(kFullDotMedium);
     722        h->SetBit(kCanDelete);
     723        h->SetMarkerColor(kCyan);
     724        h->SetLineColor(kCyan);
     725        h->Draw("Psame");
    534726    }
    535727    else
    536728        delete pad->GetPad(4);
    537 
    538 }
     729}
     730
     731void MHAlpha::DrawAll()
     732{
     733    // FIXME: Do in Paint if special option given!
     734    TCanvas *c = new TCanvas;
     735    Int_t n = fHAlpha.GetNbinsY();
     736    Int_t nc = (Int_t)(TMath::Sqrt((Float_t)n-1)+1);
     737    c->Divide(nc, nc, 0, 0);
     738
     739    // Do not store the 'final' result in fFit
     740    MAlphaFitter fit(fFit);
     741
     742    for (int i=1; i<=fHAlpha.GetNbinsY(); i++)
     743    {
     744        c->cd(i);
     745
     746        TH1D *hon = fHAlpha.ProjectionZ("ProjAlpha", -1, 9999, i, i, "E");
     747        hon->SetBit(TH1::kNoTitle);
     748        hon->SetStats(kTRUE);
     749        hon->SetXTitle("\\alpha [\\circ]");
     750        hon->SetYTitle("Counts");
     751        hon->SetDirectory(NULL);
     752        hon->SetMarkerStyle(kFullDotMedium);
     753        hon->SetBit(kCanDelete);
     754        hon->Draw("");
     755
     756        TH1D *hof = 0;
     757
     758        if (fOffData)
     759        {
     760            hon->SetMarkerColor(kGreen);
     761
     762            hof = fOffData->ProjectionZ("ProjAlphaOff", -1, 9999, i, i, "E");
     763            hof->SetBit(TH1::kNoTitle|TH1::kNoStats);
     764            hof->SetXTitle("\\alpha [\\circ]");
     765            hof->SetYTitle("Counts");
     766            hof->SetDirectory(NULL);
     767            hof->SetMarkerStyle(kFullDotMedium);
     768            hof->SetBit(kCanDelete);
     769            hof->SetMarkerColor(kRed);
     770            hof->Draw("same");
     771
     772            fit.Scale(*hof, *hon);
     773
     774            hon->SetMaximum();
     775            hon->SetMaximum(TMath::Max(hon->GetMaximum(), hof->GetMaximum())*1.05);
     776
     777            TH1D *diff = new TH1D(*hon);
     778            diff->Add(hof, -1);
     779            diff->SetBit(TH1::kNoTitle);
     780            diff->SetXTitle("\\alpha [\\circ]");
     781            diff->SetYTitle("Counts");
     782            diff->SetDirectory(NULL);
     783            diff->SetMarkerStyle(kFullDotMedium);
     784            diff->SetBit(kCanDelete);
     785            diff->SetMarkerColor(kBlue);
     786            diff->Draw("same");
     787
     788            TLine lin;
     789            lin.SetLineStyle(kDashed);
     790            lin.DrawLine(0, 0, 90, 0);
     791
     792            const Float_t min = diff->GetMinimum()*1.05;
     793            hon->SetMinimum(min<0 ? min : 0);
     794        }
     795
     796        if (hof ? fit.Fit(*hon, *hof) : fit.Fit(*hon))
     797                *fLog << dbg << "Bin " << i << ": sigma=" << fit.GetSignificance() << " omega=" << fit.GetGausSigma() << " events=" << fit.GetEventsExcess() << endl;
     798        /*
     799        if (fit.FitEnergy(fHAlpha, fOffData, i, kTRUE))
     800        {
     801            fHEnergy.SetBinContent(i, fit.GetEventsExcess());
     802            fHEnergy.SetBinError(i, fit.GetEventsExcess()*0.2);
     803        }*/
     804    }
     805
     806}
     807
    539808
    540809Bool_t MHAlpha::Finalize()
    541810{
    542     // Store the final result in fFit
    543     TH1D *h = fHAlpha.ProjectionZ("AlphaExc_px", -1, 9999, -1, 9999, "E");
    544     h->SetDirectory(0);
    545     fFit.Print();
    546     Bool_t rc = fFit.Fit(*h);
    547     delete h;
    548     if (!rc)
     811    //TH1D *h = fHAlpha.ProjectionZ("AlphaExc_px", -1, 9999, -1, 9999, "E");
     812    //h->SetDirectory(0);
     813    //Bool_t rc = fFit.Fit(*h);
     814    //delete h;
     815    if (!fFit.FitAlpha(fHAlpha, fOffData))
    549816    {
    550817        *fLog << warn << "Histogram empty." << endl;
     
    552819    }
    553820
     821    // Store the final result in fFit
     822    fFit.Print("result");
     823
    554824    if (fResult)
    555825        fResult->SetVal(fFit.GetSignificance());
    556826
    557     FitEnergyBins();
    558     FitThetaBins();
    559     UpdateAlphaTime(kTRUE);
    560     MH::RemoveFirstBin(fHTime);
     827    if (!fSkipHistEnergy)
     828    {
     829        *fLog << inf << "Processing energy bins..." << endl;
     830        FitEnergyBins();
     831    }
     832    if (!fSkipHistTheta)
     833    {
     834        *fLog << inf << "Processing theta bins..." << endl;
     835        FitThetaBins();
     836    }
     837    if (!fSkipHistTime)
     838    {
     839        *fLog << inf << "Processing time bins..." << endl;
     840        UpdateAlphaTime(kTRUE);
     841        MH::RemoveFirstBin(fHTime);
     842    }
    561843
    562844    return kTRUE;
     
    572854// will take the values from the matrix instead of the containers.
    573855//
    574 void MHAlpha::InitMapping(MHMatrix *mat)
     856// It takes fSkipHist* into account!
     857//
     858void MHAlpha::InitMapping(MHMatrix *mat, Int_t type)
    575859{
    576860    if (fMatrix)
     
    580864
    581865    fMap[0] = fMatrix->AddColumn("MHillasSrc.fAlpha");
    582     //fMap[1] = fMatrix->AddColumn("MEnergyEst.fEnergy");
     866    fMap[1] = -1;
     867    fMap[2] = -1;
     868    fMap[3] = -1;
     869    fMap[4] = -1;
     870
     871    if (!fSkipHistEnergy)
     872        if (type==0)
     873        {
     874            fMap[1] = fMatrix->AddColumn("MEnergyEst.fEnergy");
     875            fMap[2] = -1;
     876        }
     877        else
     878        {
     879            fMap[1] = -1;
     880            fMap[2] = fMatrix->AddColumn("MHillas.fSize");
     881        }
     882
     883    if (!fSkipHistTheta)
     884        fMap[3] = fMatrix->AddColumn("MPointingPos.fZd");
     885
     886   // if (!fSkipHistTime)
     887   //     fMap[4] = fMatrix->AddColumn("MTime.GetAxisTime");
    583888}
    584889
  • trunk/MagicSoft/Mars/mhflux/MHAlpha.h

    r5100 r5692  
    2121class MParameterD;
    2222class MEnergyEst;
     23class MHillas;
    2324class MHMatrix;
    2425class MPointingPos;
     
    8485{
    8586private:
     87    const TH3D *fOffData;
     88
    8689    MAlphaFitter fFit;          // SEEMS THAT STREAMER HAS SOME PROBLEMS... MAYBE IF FUNC IS USED AT THE SAME TIME FOR FITS (PAINT)
    8790
     
    9497    MParameterD  *fResult;      //!
    9598    MEnergyEst   *fEnergy;      //!
     99    MHillas      *fHillas;      //!
    96100    MPointingPos *fPointPos;    //!
    97101
     
    100104    MTime    fLastTime;         //! Last fTimeEffOn
    101105
    102     const TString fNameProjAlpha;  //! This should make sure, that gROOT doen't confuse the projection with something else
     106    //Float_t fEnergyMin;
     107    //Float_t fEnergyMax;
     108    //Float_t fSizeMin;
     109    //Float_t fSizeMax;
     110
     111    Bool_t fSkipHistTime;
     112    Bool_t fSkipHistTheta;
     113    Bool_t fSkipHistEnergy;
     114
     115    //const TString fNameProjAlpha;  //! This should make sure, that gROOT doen't confuse the projection with something else
    103116
    104117    MHMatrix *fMatrix;          //!
    105     Int_t fMap[2];              //!
     118    Int_t fMap[5];              //!
    106119
    107120    void FitEnergySpec(Bool_t paint=kFALSE);
     
    115128    void PaintText(Double_t val, Double_t error) const;
    116129
     130    Int_t DistancetoPrimitive(Int_t px, Int_t py) { return 0; }
     131
    117132public:
    118133    MHAlpha(const char *name=NULL, const char *title=NULL);
     
    125140    const MAlphaFitter &GetAlphaFitter() const { return fFit; }
    126141
     142    void SetOffData(const MHAlpha &h)
     143    {
     144        fOffData = &h.fHAlpha;
     145    }
     146/*
     147    void SetSizeCuts(Float_t min, Float_t max)   { fSizeMin=min; fSizeMax=max; }
     148    void SetSizeMin(Float_t min)                 { fSizeMin=min; }
     149    void SetSizeMax(Float_t max)                 { fSizeMax=max; }
     150    void SetEnergyCuts(Float_t min, Float_t max) { fEnergyMin=min; fEnergyMax=max; }
     151    void SetEnergyMin(Float_t min)               { fEnergyMin=min; }
     152    void SetEnergyMax(Float_t max)               { fEnergyMax=max; }
     153
     154    void SetCuts(const MHAlpha &h) {
     155        fSizeMin = h.fSizeMin; fEnergyMin = h.fEnergyMin;
     156        fSizeMax = h.fSizeMax; fEnergyMax = h.fEnergyMax;
     157    }
     158    */
     159
     160    void SkipHistTime(Bool_t b=kTRUE)   { fSkipHistTime=b; }
     161    void SkipHistTheta(Bool_t b=kTRUE)  { fSkipHistTheta=b; }
     162    void SkipHistEnergy(Bool_t b=kTRUE) { fSkipHistEnergy=b; }
     163
    127164    void Paint(Option_t *opt="");
    128165    void Draw(Option_t *option="");
    129166
    130     void InitMapping(MHMatrix *mat);
     167    void DrawAll(); //*MENU*
     168
     169    void InitMapping(MHMatrix *mat, Int_t type=0);
    131170    void StopMapping();
    132171
  • trunk/MagicSoft/Mars/mjobs/MSequence.cc

    r5316 r5692  
    145145        d += fNight.GetStringFmt("%Y_%m_%d");
    146146    }
     147    else
     148        gSystem->ExpandPathName(d);
    147149
    148150    for (int i=0; i<arr.GetSize(); i++)
     
    174176{
    175177    fName  = fname;
    176     fTitle = Form("Sequence contained in file %s", fName.Data());
    177 
    178     TEnv env(fname);
     178
     179    const char *expname = gSystem->ExpandPathName(fname);
     180
     181    fTitle = Form("Sequence contained in file %s", expname);
     182
     183    TEnv env(expname);
     184    delete [] expname;
    179185
    180186    TString str;
Note: See TracChangeset for help on using the changeset viewer.