Ignore:
Timestamp:
01/17/05 11:54:30 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/manalysis
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.cc

    r2206 r5869  
    2525
    2626/////////////////////////////////////////////////////////////////////////////
    27 //                                                                         //
    28 // MEnergyEstimate                                                         //
    29 //                                                                         //
    30 // Task to estimate the energy                                             //
    31 //                                                                         //
    32 //                                                                         //
     27//
     28// MEnergyEstimate
     29//
     30// Task to estimate the energy by a rule, eg:
     31//
     32// MEnergyEstimate est;
     33// est.SetRule("0.5 + (1.1*MHillas.fLength) + (2.2*MHillasSrc.fDist) + (3.3*MHillas.fSize) +"
     34//             "(4.4*MHillas.fSize*MHillas.fLength) + (5.5*MHillasSrc.fDist*MHillas.fLength)");
     35//
     36// For description of rules, see MDataChain.
     37//
     38// The default rule is "MMcEvt.fEnergy"
     39//
     40// Output:
     41//   MEnergyEst
     42//
    3343/////////////////////////////////////////////////////////////////////////////
    3444#include "MEnergyEstimate.h"
     
    3646#include "MParList.h"
    3747
    38 #include "MMcEvt.hxx"
    39 #include "MHillas.h"
     48#include "MDataChain.h"
    4049#include "MEnergyEst.h"
    4150
     
    4756using namespace std;
    4857
     58// --------------------------------------------------------------------------
     59//
     60// Default constructor. Initialize fData with default rule "MMcEvt.fEnergy"
     61//
     62MEnergyEstimate::MEnergyEstimate(const char *name, const char *title)
     63    : fData(0), fEnergy(0)
     64{
     65    fName  = name  ? name  : "MEnergyEstimate";
     66    fTitle = title ? title : "Task to estimate the energy by a rule";
     67
     68    fData = new MDataChain("MMcEvt.fEnergy");
     69}
    4970
    5071// --------------------------------------------------------------------------
    5172//
    52 // Default constructor.
     73// delete fData
    5374//
    54 MEnergyEstimate::MEnergyEstimate(const char *name, const char *title)
     75MEnergyEstimate::~MEnergyEstimate()
    5576{
    56     fName  = name  ? name  : "MEnergyEstimate";
    57     fTitle = title ? title : "Task to estimate the energy";
    58 
    59     AddToBranchList("MMcEvt.fEnergy");
     77    delete fData;
    6078}
    6179
     80// --------------------------------------------------------------------------
     81//
     82// Delete fData. Initialize a new MDataChain with rule.
     83// Returns if fData->IsValid()
     84//
     85Bool_t MEnergyEstimate::SetRule(const char *rule)
     86{
     87    delete fData;
     88    fData = new MDataChain(rule);
     89
     90    return fData->IsValid();
     91}
     92
     93// --------------------------------------------------------------------------
     94//
     95// Forwards SetVariables to fData to allow optimizations.
     96//
     97void MEnergyEstimate::SetVariables(const TArrayD &arr)
     98{
     99    fData->SetVariables(arr);
     100}
     101
     102// --------------------------------------------------------------------------
     103//
     104// FindCreate "MEnergyEst"
     105// PreProcess fData.
     106//
    62107Int_t MEnergyEstimate::PreProcess(MParList *plist)
    63108{
    64    fHillas = (MHillas*)plist->FindObject("MHillas");
    65    if (!fHillas)
    66    {
    67        *fLog << err << dbginf << "MHillas not found... aborting." << endl;
    68        return kFALSE;
    69    }
     109    fEnergy = (MEnergyEst*)plist->FindCreateObj("MEnergyEst");
     110    if (!fEnergy)
     111        return kFALSE;
    70112
    71    fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
    72    if (!fMcEvt)
    73    {
    74        *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
    75        return kFALSE;
    76    }
     113    if (!fData->PreProcess(plist))
     114        return kFALSE;
    77115
    78    fEnergy = (MEnergyEst*)plist->FindCreateObj("MEnergyEst");
    79    if (!fEnergy)
    80       return kFALSE;
     116    *fLog << inf << "Rule for energy estimation: " << fData->GetRule() << endl;
    81117
    82    return kTRUE;   
     118    return kTRUE;
    83119}
    84120
     121// --------------------------------------------------------------------------
     122//
     123// Get value from fData and set it to fEnergy. SetReadyToSave for fEnergy.
     124// Return kCONTINUE if value is NaN (Not a Number)
     125//
    85126Int_t MEnergyEstimate::Process()
    86127{
    87   //fEnergy->SetEnergy(fHillas->GetSize());
    88   fEnergy->SetEnergy(fMcEvt->GetEnergy());
    89   return kTRUE;
     128    const Double_t val = fData->GetValue();
     129    if (TMath::IsNaN(val))
     130        return kCONTINUE;
     131
     132    fEnergy->SetEnergy(val);
     133    fEnergy->SetReadyToSave();
     134    return kTRUE;
    90135}
  • trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.h

    r2206 r5869  
    66#endif
    77
    8 class MMcEvt;
    9 class MHillas;
     8class MData;
    109class MEnergyEst;
    1110
     
    1312{
    1413private:
    15     MMcEvt     *fMcEvt;
    16     MHillas    *fHillas;
     14    MData      *fData;    //->
    1715    MEnergyEst *fEnergy;
    1816
    1917public:
    2018    MEnergyEstimate(const char *name=NULL, const char *title=NULL);
     19    ~MEnergyEstimate();
     20
     21    Bool_t SetRule(const char *rule);
    2122
    2223    Int_t PreProcess(MParList *plist);
    2324    Int_t Process();
    2425
    25     ClassDef(MEnergyEstimate, 0) // Task to copy the MC energy (preliminary)
     26    void SetVariables(const TArrayD &);
     27
     28    ClassDef(MEnergyEstimate, 0) // Task to estimate the energy by a rule
    2629};
    2730
Note: See TracChangeset for help on using the changeset viewer.