Changeset 7121 for trunk/MagicSoft


Ignore:
Timestamp:
06/01/05 17:14:46 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r7120 r7121  
    2121
    2222                                                 -*-*- END OF LINE -*-*-
     23 2005/06/01 Thomas Bretz
     24
     25   * mjobs/MJOptimize.[h,cc]:
     26     - moved code for cut optimization to MJOptimizeCuts
     27     - moved code for energy optimization to MJOptimizeEnergy
     28
     29   * mjobs/MJOptimizeCuts.[h,cc], mjobs/MJOptimizeEnergy.[h,cc]:
     30     - added
     31
     32   * mjobs/Makefile, mjobs/JobsLinkDef.h:
     33     - added MJOptimizeCuts
     34     - added MJOptimizeEnergy
     35
     36
     37
    2338 2005/06/01 Daniela Dorner
    2439
  • trunk/MagicSoft/Mars/NEWS

    r7116 r7121  
    4747     For details about the requirements of these plots look
    4848     at the corresponding classes
     49
     50   - MJOptimize: For On/Off and Wobble optimization MJOptimize
     51     has been replaced by MJOptimizeCuts. To use MHThetaSq instead
     52     of MHAlpha call MJOptimizeCuts("MHThetaSq"). Make sure in this
     53     case MAlphaFitter is setup correctly. For On-Only optimization
     54     MJOptimize has been Replaced by MJOptimizeCuts, too. Call
     55     RunOn() instead of Run(). For energy estimation MJOptimize
     56     has been replaced by MJOptimizeEnergy
    4957
    5058   - sponde: The input MC spectrum can now be weighted to fake a
  • trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h

    r6958 r7121  
    1717#pragma link C++ class MJStar+;
    1818#pragma link C++ class MJCut+;
    19 #pragma link C++ class MJOptimize+;
    2019#pragma link C++ class MJSpectrum+;
    2120
     21#pragma link C++ class MJOptimize+;
     22#pragma link C++ class MJOptimizeCuts+;
     23#pragma link C++ class MJOptimizeEnergy+;
     24
    2225#endif
  • trunk/MagicSoft/Mars/mjobs/MJOptimize.cc

    r7071 r7121  
    9090#include <TMultiGraph.h>
    9191
     92#include "MHMatrix.h"
     93
     94// environment
     95#include "MLog.h"
     96#include "MLogManip.h"
     97
     98#include "MDirIter.h"
     99#include "MStatusDisplay.h"
     100
     101// eventloop
    92102#include "MParList.h"
    93103#include "MTaskList.h"
    94 #include "MGeomCamCT1.h"
    95 #include "MFEventSelector.h"
    96 #include "MFDataMember.h"
     104#include "MEvtLoop.h"
     105
     106// parameters
     107#include "MParameters.h"
     108
     109// tasks
    97110#include "MReadTree.h"
    98 #include "MHMatrix.h"
    99 #include "MEnergyEstimate.h"
    100111#include "MMatrixLoop.h"
    101 #include "MChisqEval.h"
    102 #include "MEvtLoop.h"
    103 #include "MDataElement.h"
    104 #include "MDataMember.h"
    105 #include "MLog.h"
    106 #include "MLogManip.h"
    107 #include "MParameters.h"
    108112#include "MFillH.h"
     113
     114// filters
    109115#include "MF.h"
    110116#include "MFilterList.h"
    111 #include "../mfilter/MFMagicCuts.h"
    112 #include "MContinue.h"
    113 #include "MGeomCamMagic.h"
    114 #include "MHillasSrcCalc.h"
    115 #include "MHMatrix.h"
    116 #include "MMatrixLoop.h"
    117 #include "../mhflux/MHAlpha.h"
    118 #include "MStatusDisplay.h"
    119 #include "../mhflux/MHEnergyEst.h"
    120 #include "MDirIter.h"
    121 #include "MSequence.h"
    122117
    123118using namespace std;
     
    507502Bool_t MJOptimize::Optimize(MEvtLoop &evtloop)
    508503{
     504    if (fParameters.GetSize()==0)
     505    {
     506        *fLog << err << GetDescriptor() << "::Optimize: ERROR - Sorry, no parameters defined." << endl;
     507        return kFALSE;
     508    }
     509
    509510    if (fType==kNone)
    510511        return kTRUE;
     
    806807    *fLog << endl;
    807808}
    808 
    809 //------------------------------------------------------------------------
    810 //
    811 Bool_t MJOptimize::Run(const char *fname, MFilter *filter, MAlphaFitter *fit)
    812 {
    813     if (fParameters.GetSize()==0)
    814     {
    815         *fLog << err << "Sorry, no parameters defined." << endl;
    816         return kFALSE;
    817     }
    818 
    819     fLog->Separator("Preparing On-only-optimization");
    820 
    821     MParList parlist;
    822 
    823     MGeomCamMagic geom; // For GetConvMm2Deg
    824     parlist.AddToList(&geom);
    825 
    826     MHMatrix m("M");
    827     AddRulesToMatrix(m);
    828     parlist.AddToList(&m);
    829 
    830     MHAlpha hist;
    831     hist.SkipHistTime();
    832     hist.SkipHistTheta();
    833     hist.SkipHistEnergy();
    834     hist.InitMapping(&m);
    835 
    836     if (filter && filter->InheritsFrom(MFMagicCuts::Class()))
    837         ((MFMagicCuts*)filter)->InitMapping(&m);
    838 
    839     MReadTree read("Events");
    840     read.DisableAutoScheme(); // AutoScheme doesn't seem to be faster!
    841     if (fname)
    842         read.AddFile(fname);
    843     else
    844         AddSequences(read, fNamesOn);
    845     if (!FillMatrix(read, parlist))
    846         return kFALSE;
    847 
    848     MTaskList tasklist;
    849     parlist.Replace(&tasklist);
    850     if (fit)
    851         parlist.AddToList(fit);
    852 
    853     MFilterList list;
    854     SetupFilters(list, filter);
    855 
    856     MContinue contin(&list);
    857     parlist.AddToList(&list);
    858 
    859     MFillH fill(&hist);
    860 
    861     MMatrixLoop loop(&m);
    862 
    863     tasklist.AddToList(&loop);
    864     tasklist.AddToList(&list);
    865     tasklist.AddToList(&contin);
    866     tasklist.AddToList(&fill);
    867 
    868     // Optimize with the tasklist in this parameterlist
    869     if (!Optimize(parlist))
    870         return kFALSE;
    871 
    872     // Copy the result back to be accessible by the user
    873     if (fit)
    874         hist.GetAlphaFitter().Copy(*fit);
    875     // Print the result
    876     hist.GetAlphaFitter().Print("result");
    877 
    878     // Store result if requested
    879     TObjArray cont;
    880     cont.Add(&contin);
    881     return WriteContainer(cont, fNameOut);
    882 }
    883 
    884 //------------------------------------------------------------------------
    885 //
    886 // Make sure, that filter->GetDataMember is correctly implemented!!!!
    887 //
    888 Bool_t MJOptimize::RunOnOff(const char *fname, MFilter *filter, MAlphaFitter *fit, const char *tree)
    889 {
    890     if (fParameters.GetSize()==0)
    891     {
    892         *fLog << err << "Sorry, no parameters defined." << endl;
    893         return kFALSE;
    894     }
    895 
    896     fLog->Separator("Preparing On/Off-optimization");
    897 
    898     MParList parlist;
    899 
    900     MGeomCamMagic geom; // For GetConvMm2Deg
    901     parlist.AddToList(&geom);
    902 
    903     MHMatrix m("M");
    904     AddRulesToMatrix(m);
    905     parlist.AddToList(&m);
    906 
    907     const Int_t idxdatatype = m.AddColumn("DataType.fVal");
    908 
    909     MHAlpha histon, histof("MHAlphaOff");
    910     histon.SkipHistTime();
    911     histon.SkipHistTheta();
    912     //histon.SkipHistEnergy();
    913     histof.SkipHistTime();
    914     histof.SkipHistTheta();
    915     //histof.SkipHistEnergy();
    916     histon.ForceUsingSize();
    917     histof.ForceUsingSize();
    918     histon.InitMapping(&m, 1);
    919     histof.InitMapping(&m, 1);
    920 
    921     if (filter && filter->InheritsFrom(MFMagicCuts::Class()))
    922         ((MFMagicCuts*)filter)->InitMapping(&m);
    923 
    924     parlist.AddToList(&histon);
    925     parlist.AddToList(&histof);
    926 
    927     if (fname)
    928     {
    929         MReadTree read(tree);
    930         read.DisableAutoScheme(); // AutoScheme doesn't seem to be faster!
    931         read.AddFile(fname);
    932         if (!FillMatrix(read, parlist))
    933             return kFALSE;
    934     }
    935     else
    936     {
    937         MParameterI par("DataType");
    938         parlist.AddToList(&par);
    939 
    940         gLog.Separator("Reading On-Data");
    941         par.SetVal(1);
    942         MReadTree readon(tree);
    943         readon.DisableAutoScheme(); // AutoScheme doesn't seem to be faster!
    944         AddSequences(readon, fNamesOn);
    945         if (!FillMatrix(readon, parlist))
    946             return kFALSE;
    947 
    948         gLog.Separator("Reading Off-Data");
    949         par.SetVal(0);
    950         MReadTree readoff(tree);
    951         readoff.DisableAutoScheme(); // AutoScheme doesn't seem to be faster!
    952         AddSequences(readoff, fNamesOff);
    953         if (!FillMatrix(readoff, parlist))
    954             return kFALSE;
    955     }
    956 
    957     MTaskList tasklist;
    958     parlist.Replace(&tasklist);
    959     if (fit)
    960         parlist.AddToList(fit);
    961 
    962     MFilterList list;
    963     SetupFilters(list, filter);
    964 
    965     MContinue contin(&list);
    966     parlist.AddToList(&list);
    967 
    968     MFillH fillof(&histof, "", "FillHistOff");
    969     MFillH fillon(&histon, "", "FillHistOn");
    970 
    971     MF f0(Form("M[%d]<0.5", idxdatatype), "FilterOffData");
    972     MF f1(Form("M[%d]>0.5", idxdatatype), "FilterOnData");
    973 
    974     fillof.SetFilter(&f0);
    975     fillon.SetFilter(&f1);
    976 
    977     MMatrixLoop loop(&m);
    978 
    979     tasklist.AddToList(&loop);
    980     tasklist.AddToList(&list);
    981     tasklist.AddToList(&contin);
    982     tasklist.AddToList(&f0);
    983     tasklist.AddToList(&f1);
    984     tasklist.AddToList(&fillof);
    985     tasklist.AddToList(&fillon);
    986 
    987     // Optimize with the tasklist in this parameterlist
    988     if (!Optimize(parlist))
    989         return kFALSE;
    990 
    991     // Copy the result back to be accessible by the user
    992     if (fit)
    993         histon.GetAlphaFitter().Copy(*fit);
    994     // Print the result
    995     histon.GetAlphaFitter().Print("result");
    996 
    997     // Store result if requested
    998     TObjArray cont;
    999     cont.Add(&contin);
    1000     return WriteContainer(cont, fNameOut);
    1001 }
    1002 
    1003 //------------------------------------------------------------------------
    1004 //
    1005 // Read all events from file which do match rules and optimize
    1006 // energy estimator.
    1007 //
    1008 Bool_t MJOptimize::RunEnergy(const char *fname, const char *rule)
    1009 {
    1010     if (fParameters.GetSize()==0)
    1011     {
    1012         *fLog << err << "Sorry, no parameters defined." << endl;
    1013         return kFALSE;
    1014     }
    1015 
    1016     fLog->Separator("Preparing Energy optimization");
    1017 
    1018     MParList parlist;
    1019 
    1020     MParameterI par("DataType");
    1021     par.SetVal(1);
    1022     parlist.AddToList(&par);
    1023 
    1024     MFDataMember filter("DataType.fVal", '>', 0.5);
    1025     fPreCuts.Add(&filter);
    1026 
    1027     MGeomCamMagic geom; // For GetConvMm2Deg
    1028     parlist.AddToList(&geom);
    1029 
    1030     MHMatrix m("M");
    1031     AddRulesToMatrix(m);
    1032     parlist.AddToList(&m);
    1033 
    1034     MHEnergyEst hist;
    1035     hist.InitMapping(&m);
    1036 
    1037     MEnergyEstimate est("MParameters");
    1038     est.SetRule(rule);
    1039     parlist.AddToList(&est);
    1040 
    1041     MReadTree read("Events");
    1042     // NECESSARY BECAUSE OF MDataFormula GetRules missing
    1043     read.DisableAutoScheme();
    1044     if (fname)
    1045         read.AddFile(fname);
    1046     else
    1047         AddSequences(read, fNamesOn);
    1048     if (!FillMatrix(read, parlist, kTRUE))
    1049         return kFALSE;
    1050 
    1051     fPreCuts.Remove(&filter);
    1052 
    1053     MTaskList tasklist;
    1054     parlist.Replace(&tasklist);
    1055 
    1056     MFillH fill(&hist);
    1057 
    1058     MMatrixLoop loop(&m);
    1059 
    1060     tasklist.AddToList(&loop);
    1061     tasklist.AddToList(&est);
    1062     tasklist.AddToList(&fill);
    1063 
    1064     // Optimize with the tasklist in this parameterlist
    1065     if (!Optimize(parlist))
    1066         return kFALSE;
    1067 
    1068     // Print the result
    1069     hist.Print();
    1070 
    1071     // Store result if requested
    1072     TObjArray cont;
    1073     cont.Add(&est);
    1074     return WriteContainer(cont, fNameOut);
    1075 }
  • trunk/MagicSoft/Mars/mjobs/MJOptimize.h

    r6948 r7121  
    4646    TList fRules;
    4747    TList fFilter;
    48     TList fPreCuts;
    49 
    50     TList fNamesOn;
    51     TList fNamesOff;
    52 
    53     TString fNameOut;
    5448
    5549    void AddPoint(TList *l, Int_t idx, Float_t val) const;
    5650    TList *GetPlots() const;
    5751
    58     void AddRulesToMatrix(MHMatrix &m) const;
    59     void SetupFilters(MFilterList &list, MFilter *filter=0) const;
    60     Bool_t FillMatrix(MReadTree &read, MParList &l, Bool_t userules=kFALSE);
    61 
    6252    MEvtLoop *fEvtLoop;    //!
    63 
    64     Bool_t AddSequences(MRead &read, TList &list) const;
    6553
    6654    // Minuit Interface
     
    8775
    8876    Bool_t Optimize(MEvtLoop &evtloop);
     77
     78protected:
     79    TList   fPreCuts;
     80
     81    TList   fNamesOn;
     82    TList   fNamesOff;
     83
     84    TString fNameOut;
     85
     86    void   AddRulesToMatrix(MHMatrix &m) const;
     87    void   SetupFilters(MFilterList &list, MFilter *filter=0) const;
     88    Bool_t AddSequences(MRead &read, TList &list) const;
     89    Bool_t FillMatrix(MReadTree &read, MParList &l, Bool_t userules=kFALSE);
    8990
    9091public:
     
    153154    Bool_t Optimize(MParList &list);
    154155
    155     // Special optimizing routines
    156     Bool_t Run(const char *fname, MFilter *filter, MAlphaFitter *fit=0);
    157     Bool_t Run(const char *fname, MAlphaFitter *fit=0)
    158     {
    159         return Run(fname, 0, fit);
    160     }
    161 
    162     Bool_t Run(MFilter *filter, MAlphaFitter *fit=0)
    163     {
    164         return Run(0, filter, fit);
    165     }
    166     Bool_t Run(MAlphaFitter *fit=0)
    167     {
    168         return Run(0, 0, fit);
    169     }
    170 
    171     Bool_t RunOnOff(const char *fname, MFilter *filter, MAlphaFitter *fit=0, const char *tree="Events");
    172     Bool_t RunOnOff(const char *fname, MAlphaFitter *fit=0, const char *tree="Events")
    173     {
    174         return RunOnOff(fname, 0, fit, tree);
    175     }
    176     Bool_t RunEnergy(const char *fname, const char *rule);
    177 
    178     Bool_t RunOnOff(MFilter *filter, MAlphaFitter *fit=0, const char *tree="Events")
    179     {
    180         return RunOnOff(0, filter, fit, tree);
    181     }
    182     Bool_t RunOnOff(MAlphaFitter *fit=0, const char *tree="Events")
    183     {
    184         return RunOnOff(fit, tree);
    185     }
    186     Bool_t RunEnergy(const char *rule)
    187     {
    188         return RunEnergy(0, rule);
    189     }
    190 
    191156    ClassDef(MJOptimize, 0) // Class for optimization of the Supercuts
    192157};
  • trunk/MagicSoft/Mars/mjobs/Makefile

    r7099 r7121  
    3636           MJCut.cc \
    3737           MJOptimize.cc \
     38           MJOptimizeCuts.cc \
     39           MJOptimizeEnergy.cc \
    3840           MJSpectrum.cc
    3941
Note: See TracChangeset for help on using the changeset viewer.