Ignore:
Timestamp:
11/18/05 17:15:30 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mfilter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mfilter/MFEnergySlope.cc

    r2206 r7409  
    1818!   Author(s): Antonio Stamerra  02/2003 <mailto:antonio.stamerra@pi.infn.it>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2003
     20!   Copyright: MAGIC Software Development, 2000-2005
    2121!
    2222!
     
    6565// --------------------------------------------------------------------------
    6666//
     67//  Default Constructor
     68//
     69MFEnergySlope::MFEnergySlope(const char *name, const char *title):
     70    fNewSlope(-1), fMcMinEnergy(-1.), fMcMaxEnergy(-1.)
     71{
     72    fName  = name  ? name  : "MFEnergySlope";
     73    fTitle = title ? title : "Filter to select energy with given slope";
     74}
     75
     76// --------------------------------------------------------------------------
     77//
    6778//     Constructor
    6879//
    69 MFEnergySlope::MFEnergySlope(const char *name, const char *title):
    70   fNumSelectedEvts(0), fNewSlope(-1), fMcMinEnergy(-1.), fMcMaxEnergy(-1.)
    71 {
    72   //    fContName = cname;
    73   fName  = name  ? name  : "MFEnergySlope";
    74   fTitle = title ? title : "Filter to select energy with given slope";
     80MFEnergySlope::MFEnergySlope(Float_t slope, const char *name, const char *title):
     81    fNewSlope(TMath::Abs(slope)), fMcMinEnergy(-1.), fMcMaxEnergy(-1.)
     82{
     83    fName  = name  ? name  : "MFEnergySlope";
     84    fTitle = title ? title : "Filter to select energy with given slope";
    7585}
    7686
     
    8494Int_t MFEnergySlope::PreProcess(MParList *pList)
    8595{
    86  
     96    if (fNewSlope<0)
     97    {
     98        *fLog << err << "New slope still undefined... aborting." << endl;
     99        return kFALSE;
     100    }
     101
     102    fEvt = (MMcEvt*)pList->FindObject("MMcEvt");
     103    if (!fEvt)
     104    {
     105        *fLog << err << "MMcEvt not found... aborting." << endl;
     106        return kFALSE;
     107    }
     108
     109    return kTRUE;
     110}
     111
     112// --------------------------------------------------------------------------
     113//
     114//   Preprocess
     115// 
     116//  MC slope and min/max energy are read
     117//  Normalization factor is computed
     118//
     119Bool_t MFEnergySlope::ReInit(MParList *pList)
     120{
    87121    MMcCorsikaRunHeader *runheader = (MMcCorsikaRunHeader*)pList->FindObject("MMcCorsikaRunHeader");
    88 
    89122    if (!runheader)
    90       {
    91         *fLog << err << dbginf << fName << " [MMcCorsikaRunHeader] not found... aborting." << endl;
    92         return kFALSE;
    93       }
     123    {
     124        *fLog << err << "MMcCorsikaRunHeader not found... aborting." << endl;
     125        return kFALSE;
     126    }
     127
    94128    //
    95     // Read info from the MC sample (it must be generated with 
     129    // Read info from the MC sample (it must be generated with
    96130    //   reflector ver.0.6 and camera ver. 0.6)
    97131    //
    98     fMcSlope = runheader->GetSlopeSpec();   
     132    fMcSlope = runheader->GetSlopeSpec();
    99133    if (fMcMinEnergy<0)
    100       fMcMinEnergy = runheader->GetELowLim();
     134        fMcMinEnergy = runheader->GetELowLim();
    101135    if (fMcMinEnergy<0)
    102       fMcMaxEnergy = runheader->GetEUppLim();
    103 
    104     *fLog << inf;
    105     *fLog << "MFEnergySlope::PreProcess: fetched MC info:" << endl;
    106     *fLog << "  E Slope:     " << fMcSlope << endl;
    107     *fLog << "  E Min:       " << fMcMinEnergy << endl;
    108     *fLog << "  E Max:       " << fMcMaxEnergy << endl;
    109     *fLog << "  New E Slope: " << fNewSlope << endl;
    110    
     136        fMcMaxEnergy = runheader->GetEUppLim();
     137
    111138    // Slope is used with positive values in the code
    112139    if (fNewSlope < 0)
    113       fNewSlope *= -1;
     140        fNewSlope *= -1;
    114141    if (fMcSlope < 0)
    115       fMcSlope *= -1;
    116 
    117 
    118   // Set normalization on energy 
    119     fN0 = pow(fNewSlope>fMcSlope?fMcMinEnergy:fMcMaxEnergy,fNewSlope-fMcSlope);
    120 
    121   *fLog << "Normalization factor:" <<fN0 << endl;
    122 
    123   //---
    124     fEvt = (MMcEvt*)pList->FindObject("MMcEvt");
    125     if (!fEvt)
    126       {
    127         *fLog << err << dbginf << fName << " [MMcEvt] not found... aborting." << endl;
    128         return kFALSE;
    129       }
     142        fMcSlope *= -1;
     143
     144    // Calculate normalization factor
     145    fN0 = TMath::Power(fNewSlope>fMcSlope ? fMcMinEnergy : fMcMaxEnergy, fNewSlope-fMcSlope);
     146
     147    // Print some infos
     148    *fLog << inf;
     149    *fLog << "Fetched MC info:" << endl;
     150    *fLog << "  Change E Slope " << fMcSlope << " (" << fMcMinEnergy << " < E < ";
     151    *fLog << fMcMaxEnergy << ") to " << fNewSlope << endl;
     152    *fLog << "  Norm factor: " << fN0 << endl;
    130153
    131154    return kTRUE;
     
    144167Int_t MFEnergySlope::Process()
    145168{
    146   fResult = kTRUE;
    147 
    148   // Energy slopes are the same: skip it
    149   if (fNewSlope == fMcSlope)
     169    fResult = kTRUE;
     170
     171    // Energy slopes are the same: skip it
     172    if (fNewSlope == fMcSlope)
     173        return kTRUE;
     174
     175    //  The value of the normalized spectrum is compared with a
     176    //   random value in [0,1];
     177    //   if the latter is higher the event is accepted
     178    const Float_t energy = fEvt->GetEnergy();
     179
     180    /*
     181     //
     182     // If energy bounds different from MC ones are selected, then
     183     // events outside these bounds are rejected, as their slope has
     184     // not been changed.
     185     //
     186     if (energy > fMcMaxEnergy || energy < fMcMinEnergy)
     187     {
     188        fResult = kFALSE;
     189        return kTRUE;
     190     }
     191     */
     192
     193    const Float_t Nexp = fN0 * pow(energy,fMcSlope-fNewSlope);
     194    const Float_t Nrnd = gRandom->Uniform();
     195
     196    fResult = Nexp > Nrnd;
     197
     198    //if (fResult)
     199    //    fNumSelectedEvts++;
     200
    150201    return kTRUE;
    151  
    152   //  The value of the normalized spectrum is compared with a
    153   //   random value in [0,1];
    154   //   if the latter is higher the event is accepted
    155   const Float_t energy = fEvt->GetEnergy();
    156 
    157   /*
    158   //
    159   // If energy bounds different from MC ones are selected, then
    160   // events outside these bounds are rejected, as their slope has
    161   // not been changed.
    162   //
    163   if (energy > fMcMaxEnergy || energy < fMcMinEnergy)
    164     {
    165       fResult = kFALSE;
    166       return kTRUE;
    167     }
    168   */
    169 
    170   const Float_t Nexp = fN0 * pow(energy,fMcSlope-fNewSlope);
    171   const Float_t Nrnd = gRandom->Uniform();
    172 
    173   fResult = Nexp > Nrnd;
    174 
    175   if (!fResult)
    176       return kTRUE;
    177 
    178   fNumSelectedEvts++;
    179   return kTRUE;
    180 }
    181 
     202}
     203
     204
     205// --------------------------------------------------------------------------
     206//
     207//   MFEnergySlope.NewSlope: -2.8
     208//
     209Int_t MFEnergySlope::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
     210{
     211    Bool_t rc = kFALSE;
     212    if (IsEnvDefined(env, prefix, "NewSlope", print))
     213    {
     214        rc = kTRUE;
     215        SetNewSlope(GetEnvValue(env, prefix, "NewSlope", fNewSlope));
     216    }
     217    return rc;
     218}
  • trunk/MagicSoft/Mars/mfilter/MFEnergySlope.h

    r2206 r7409  
    11#ifndef MARS_MFEnergySlope
    22#define MARS_MFEnergySlope
    3 /////////////////////////////////////////////////////////////////////////////
    4 //                                                                         //
    5 // MFEnergySlope                                                           //
    6 //                                                                         //
    7 /////////////////////////////////////////////////////////////////////////////
    83
    94#ifndef MARS_MFilter
     
    116#endif
    127
     8class MMcEvt;
    139class MParList;
    14 class MMcEvt;
    1510class MMcCorsikaRunHeader;
    1611
     
    1813{
    1914private:
    20     Int_t fNumSelectedEvts; // counter for number of selected events
     15    //Int_t fNumSelectedEvts; // counter for number of selected events
    2116
    22     MMcEvt *fEvt;           // Events used to determin energy slope
     17    MMcEvt *fEvt;           //! Events used to determin energy slope
    2318
    24     Bool_t fResult;         // Result returned by IsExpressionTrue
    2519    Float_t fNewSlope;      // New slope set by user
     20    Float_t fMcSlope;       //! Original energy slope from MC data
    2621
    27     Float_t fMcSlope;       // Original energy slope from MC data
    28     Float_t fMcMinEnergy;   // Starting energy of MC data
    29     Float_t fMcMaxEnergy;   // Ending energy of MC data
     22    Float_t fMcMinEnergy;   //! Starting energy of MC data
     23    Float_t fMcMaxEnergy;   //! Ending energy of MC data
    3024
    31     Float_t fN0;            // Normalization factor
     25    Float_t fN0;            //! Normalization factor
    3226
    33     Int_t PreProcess(MParList *pList);
    34     Int_t Process();
     27    Bool_t  fResult;        //! Result returned by IsExpressionTrue
     28
     29    // MTask
     30    Int_t  PreProcess(MParList *pList);
     31    Bool_t ReInit(MParList *pList);
     32    Int_t  Process();
     33
     34    // MFilter
     35    Bool_t IsExpressionTrue() const { return fResult; }
    3536
    3637public:
    3738    MFEnergySlope(const char *name=NULL, const char *title=NULL);
     39    MFEnergySlope(Float_t slope, const char *name=NULL, const char *title=NULL);
    3840
    39     Bool_t IsExpressionTrue() const { return fResult; }
     41    // Setter
     42    void SetNewSlope(Float_t f)    { fNewSlope = TMath::Abs(f); }
     43    void SetMcSlope(Float_t f)     { fMcSlope  = TMath::Abs(f); }
    4044
    41     // Slope is used with positive values in the code
    42     void SetNewSlope(Float_t f) {fNewSlope = TMath::Abs(f);}
    43     void SetMcSlope(Float_t f) {fMcSlope = TMath::Abs(f);}
     45    void SetMcMinEnergy(Float_t f) { fMcMinEnergy = f; }
     46    void SetMcMaxEnergy(Float_t f) { fMcMaxEnergy = f; }
    4447
    45     void SetMcMinEnergy(Float_t f) {fMcMinEnergy = f;}
    46     void SetMcMaxEnergy(Float_t f) {fMcMaxEnergy = f;}
     48    // MParContainer
     49    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
    4750
    4851    ClassDef(MFEnergySlope, 0) // A Filter to select events with a given energy slope
Note: See TracChangeset for help on using the changeset viewer.