Changeset 7688 for trunk


Ignore:
Timestamp:
05/04/06 08:26:21 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MTaskList.cc

    r7685 r7688  
    338338// --------------------------------------------------------------------------
    339339//
     340// Add all objects in list to the tasklist after task where. If some of
     341// them do not inherit from MTask return kFALSE, also if AddToListAfter
     342// returns an error for one of the tasks
     343//
     344Bool_t MTaskList::AddToListAfter(const TList &list, const MTask *where, const char *tType)
     345{
     346    TIter Next(&list);
     347    TObject *obj=0;
     348    while ((obj=Next()))
     349    {
     350        if (!obj->InheritsFrom(MTask::Class()))
     351        {
     352            *fLog << err << "ERROR - Object " << obj->GetName() << " doesn't inherit from MTask..." << endl;
     353            return kFALSE;
     354        }
     355
     356        if (!AddToListAfter(static_cast<MTask*>(obj), where, tType))
     357            return kFALSE;
     358
     359        where = static_cast<MTask*>(obj);
     360    }
     361    return kTRUE;
     362}
     363
     364// --------------------------------------------------------------------------
     365//
     366// Add all objects in list to the tasklist before task where. If some of
     367// them do not inherit from MTask return kFALSE, also if AddToListBefore
     368// returns an error for one of the tasks
     369//
     370Bool_t MTaskList::AddToListBefore(const TList &list, const MTask *where, const char *tType)
     371{
     372    TIter Next(&list);
     373    TObject *obj=0;
     374    while ((obj=Next()))
     375    {
     376        if (!obj->InheritsFrom(MTask::Class()))
     377        {
     378            *fLog << err << "ERROR - Object " << obj->GetName() << " doesn't inherit from MTask..." << endl;
     379            return kFALSE;
     380        }
     381
     382        if (!AddToListBefore(static_cast<MTask*>(obj), where, tType))
     383            return kFALSE;
     384    }
     385    return kTRUE;
     386}
     387
     388// --------------------------------------------------------------------------
     389//
    340390//  Find an object in the list.
    341391//  'name' is the name of the object you are searching for.
     
    913963// --------------------------------------------------------------------------
    914964//
     965// Removes all task of the TList from the tasklist. Returns kFALSE if any
     966// of the objects was not an MTask or not found in the list.
     967//
     968Bool_t MTaskList::RemoveFromList(const TList &list)
     969{
     970    Bool_t rc = kTRUE;
     971
     972    TIter Next(&list);
     973    TObject *obj=0;
     974    while ((obj=Next()))
     975    {
     976        if (!obj->InheritsFrom(MTask::Class()))
     977        {
     978            *fLog << err << "ERROR - Object " << obj->GetName() << " doesn't inherit from MTask..." << endl;
     979            rc = kFALSE;
     980            continue;
     981        }
     982
     983        if (!RemoveFromList(static_cast<MTask*>(obj)))
     984            rc = kFALSE;
     985    }
     986    return rc;
     987}
     988
     989// --------------------------------------------------------------------------
     990//
    915991//  Find an object with the same name in the list and replace it with
    916992//  the new one. If the kIsOwner flag is set and the object was not
  • trunk/MagicSoft/Mars/mbase/MTaskList.h

    r7685 r7688  
    4848    Bool_t AddToList(MTask *task, const char *tType="All");
    4949    Bool_t AddToList(const TList &list, const char *tType="All");
     50    Bool_t AddToListAfter(const TList &list, const MTask *where, const char *tType="All");
     51    Bool_t AddToListBefore(const TList &list, const MTask *where, const char *tType="All");
    5052
    5153    void SetSerialNumber(Byte_t num);
     
    5355    Bool_t Replace(MTask *obj);
    5456    Bool_t RemoveFromList(MTask *task);
     57    Bool_t RemoveFromList(const TList &list);
    5558
    5659    TObject *FindObject(const char *name) const;
  • trunk/MagicSoft/Mars/mhflux/MMcSpectrumWeight.cc

    r7535 r7688  
    1919!   Author(s): Marcos Lopez 10/2003 <mailto:marcos@gae.ucm.es>
    2020!
    21 !   Copyright: MAGIC Software Development, 2000-2005
     21!   Copyright: MAGIC Software Development, 2000-2006
    2222!
    2323!
     
    2626//////////////////////////////////////////////////////////////////////////////
    2727//
    28 //  MMcWeightEnergySlopeCalc
     28//  MMcSpectrumWeight
    2929//               
    3030//  Change the spectrum of the MC showers simulated with Corsika (a power law)
     
    104104    AddToBranchList("MMcEvt.fEnergy");
    105105
    106     fNameWeight = "MWeight";
    107     fNameMcEvt  = "MMcEvt";
    108 
    109     fNewSlope  = -1;
    110     fOldSlope  = -1;
    111 
    112     fEnergyMin = -1;
    113     fEnergyMax = -2;
    114 
    115     fNorm      =  1;
     106    fNameWeight  = "MWeight";
     107    fNameMcEvt   = "MMcEvt";
     108
     109    fNewSlope    = -1;
     110    fOldSlope    = -1;
     111
     112    fEnergyMin   = -1;
     113    fEnergyMax   = -2;
     114
     115    fNorm        =  1;
     116    fNormEnergy  =  1;
    116117
    117118    fAllowChange = kFALSE;
     
    235236// Return the formula to calculate weights.
    236237// Is is compiled by
    237 //   o = integral(fEnergyMin, fEnergyMax, GetFormulaSpecOldX());
    238 //   n = integral(fEnergyMin, fEnergyMax, GetFormulaSpecNewX());
    239 //
    240 //   result: fNorm*o/n*GetFormulaNewSpec()/GetFormulaOldSpec()
     238//   o1 = integral(fEnergyMin, fEnergyMax, GetFormulaSpecOldX());
     239//   n1 = integral(fEnergyMin, fEnergyMax, GetFormulaSpecNewX());
     240//   o2 = CalcSpecOld(fNormEnergy);
     241//   n2 = CalcSpecNew(fNormEnergy);
     242//
     243//   result (fNormEnergy<0):
     244//      fNorm*o1/n1*GetFormulaNewSpec()/GetFormulaOldSpec()
     245//
     246//   result (fNormEnergy>0):
     247//      fNorm*o2/n2*GetFormulaNewSpec()/GetFormulaOldSpec()
    241248//
    242249// fNorm is 1 by default but can be overwritten using SetNorm()
     
    254261        return Form("%.16f", fNorm);
    255262
    256     const Double_t iold = GetSpecOldIntegral();
    257     const Double_t inew = GetSpecNewIntegral();
     263    const Double_t iold = fNormEnergy<0 ? GetSpecOldIntegral() : CalcSpecOld(fNormEnergy);
     264    const Double_t inew = fNormEnergy<0 ? GetSpecNewIntegral() : CalcSpecNew(fNormEnergy);
    258265
    259266    const Double_t norm = fNorm*iold/inew;
     
    282289    TF1 funcold("Dummy", GetFormulaSpecOldX());
    283290    return funcold.Integral(fEnergyMin, fEnergyMax);
     291}
     292
     293// ---------------------------------------------------------------------------
     294//
     295// Returns the value of GetFormulaSpecNewX() at the energy e describing
     296// the destination spectrum
     297//
     298Double_t MMcSpectrumWeight::CalcSpecNew(Double_t e) const
     299{
     300    TF1 funcnew("Dummy", GetFormulaSpecNewX());
     301    return funcnew.Eval(e);
     302}
     303
     304// ---------------------------------------------------------------------------
     305//
     306// Returns the value of GetFormulaSpecOldX() at the energy e describing
     307// the simulated spectrum
     308//
     309Double_t MMcSpectrumWeight::CalcSpecOld(Double_t e) const
     310{
     311    TF1 funcnew("Dummy", GetFormulaSpecOldX());
     312    return funcnew.Eval(e);
    284313}
    285314
     
    392421    *fLog << " New spectral slope:       " << fNewSlope << endl;
    393422    *fLog << " User normalization:       " << fNorm << endl;
     423    *fLog << " Spectra are normalized:   " << (fNormEnergy<0?"by integral":Form("at %.1fGeV", fNormEnergy)) << endl;
    394424    *fLog << " Old Spectrum:     " << GetFormulaSpecOldX() << "   (I=" << GetSpecOldIntegral() << ")" << endl;
    395425    *fLog << " New Spectrum:     " << GetFormulaSpecNewX() << "   (I=" << GetSpecNewIntegral() << ")" << endl;
     
    446476//
    447477// Read the setup from a TEnv, eg:
    448 //   MMcSpectrumWeight.NewSlope: -2.6
    449 //   MMcSpectrumWeight.Norm:      1.0
    450 //   MMcSpectrumWeight.Formula:  pow(X, -2.6)
     478//   MMcSpectrumWeight.NewSlope:   -2.6
     479//   MMcSpectrumWeight.Norm:        1.0
     480//   MMcSpectrumWeight.NormEnergy:  200
     481//   MMcSpectrumWeight.Formula:     pow(X, -2.6)
    451482//
    452483Int_t MMcSpectrumWeight::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
     
    463494        SetNorm(GetEnvValue(env, prefix, "Norm", fNorm));
    464495    }
     496    if (IsEnvDefined(env, prefix, "NormEnergy", print))
     497    {
     498        rc = kTRUE;
     499        SetNormEnergy(GetEnvValue(env, prefix, "NormEnergy", fNormEnergy));
     500    }
    465501    if (IsEnvDefined(env, prefix, "Formula", print))
    466502    {
  • trunk/MagicSoft/Mars/mhflux/MMcSpectrumWeight.h

    r7174 r7688  
    4040
    4141    Double_t fNorm;         // Normalization constant (additional normalization constant)
     42    Double_t fNormEnergy;   // Energy at which the spectra are normalized (default -1 means the integral is used)
    4243
    4344    TString fFormula;       // Text Formula for new spectrum: eg. "pow(MMcEvt.fEnergy, -2.0)"
     
    6667    void SetNewSlope(Double_t s=-1) { fNewSlope = s; }
    6768    void SetNorm(Double_t s=1) { fNorm = s; }
     69    void SetNormEnergy(Double_t s=1) { fNormEnergy = s; }
    6870    void SetFormula(const char *f="") { fFormula = f; }
    6971    void SetEnergyRange(Double_t min=-2, Double_t max=-1) { fEnergyMin=min; fEnergyMax=max; }
     
    7173    void SetWeightsZd(TH1 *h=0) { fWeightsZd = h; }
    7274    void SetWeightsSize(TH1D *h=0);
     75
    7376    Bool_t Set(const MMcCorsikaRunHeader &h);
    7477
     
    8588    Double_t GetSpecOldIntegral() const;
    8689
     90    Double_t CalcSpecNew(Double_t e) const;
     91    Double_t CalcSpecOld(Double_t e) const;
     92
    8793    Double_t GetEnergyMin() const { return fEnergyMin; }
    8894    Double_t GetEnergyMax() const { return fEnergyMax; }
Note: See TracChangeset for help on using the changeset viewer.