Changeset 1300 for trunk/MagicSoft


Ignore:
Timestamp:
04/25/02 11:21:46 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r1299 r1300  
    11                                                                  -*-*- END -*-*-
     2 2002/04/25: Thomas Bretz
     3
     4   * mmontecarlo/MMcCollectionAreaCalc.[h,cc]:
     5     - counts now the number of simulated showers
     6     - implemented some sanity checks (corsika version, etc)
     7
     8   * mhist/MMcCollectionArea.[h,cc]:
     9     - added a first implementation of a calculation using only triggered
     10       events
     11
     12   * mhist/MH.[h,cc]:
     13     - changed the first argument in SetBinning (according to the number
     14       of axis) to TH2 or TH3
     15
     16   * mhist/MH2.cc:
     17     - changed the first argument in SetBinning (according to the number
     18       of axis) to TH2 or TH3
     19
     20
     21
    222 2002/04/24: Thomas Bretz
    323
  • trunk/MagicSoft/Mars/mhist/MH.cc

    r1283 r1300  
    5050
    5151#include <TH1.h>
     52#include <TH2.h>
     53#include <TH3.h>
    5254#include <TCanvas.h>
    5355
     
    136138}
    137139
    138 void MH::SetBinning(TH1 *h, const MBinning *binsx, const MBinning *binsy)
     140void MH::SetBinning(TH2 *h, const MBinning *binsx, const MBinning *binsy)
    139141{
    140142    TAxis &x = *h->GetXaxis();
     
    169171}
    170172
    171 void MH::SetBinning(TH1 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz)
     173void MH::SetBinning(TH3 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz)
    172174{
    173175    //
     
    214216}
    215217
    216 void MH::SetBinning(TH1 *h, const TArrayD *binsx, const TArrayD *binsy)
     218void MH::SetBinning(TH2 *h, const TArrayD *binsx, const TArrayD *binsy)
    217219{
    218220    MBinning bx;
     
    223225}
    224226
    225 void MH::SetBinning(TH1 *h, const TArrayD *binsx, const TArrayD *binsy, const TArrayD *binsz)
     227void MH::SetBinning(TH3 *h, const TArrayD *binsx, const TArrayD *binsy, const TArrayD *binsz)
    226228{
    227229    MBinning bx;
     
    245247}
    246248
    247 void MH::SetBinning(TH1 *h, const TAxis *binsx, const TAxis *binsy)
     249void MH::SetBinning(TH2 *h, const TAxis *binsx, const TAxis *binsy)
    248250{
    249251    const Int_t nx = binsx->GetNbins();
     
    260262}
    261263
    262 void MH::SetBinning(TH1 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz)
     264void MH::SetBinning(TH3 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz)
    263265{
    264266    const Int_t nx = binsx->GetNbins();
     
    281283void MH::SetBinning(TH1 *h, TH1 *x)
    282284{
    283     SetBinning(h, x->GetXaxis(), x->GetYaxis(), x->GetZaxis());
    284 }
     285    if (h->InheritsFrom(TH3::Class()) && x->InheritsFrom(TH3::Class()))
     286    {
     287        SetBinning((TH3*)h, x->GetXaxis(), x->GetYaxis(), x->GetZaxis());
     288        return;
     289    }
     290    if (h->InheritsFrom(TH2::Class()) && x->InheritsFrom(TH2::Class()))
     291    {
     292        SetBinning((TH2*)h, x->GetXaxis(), x->GetYaxis());
     293        return;
     294    }
     295    if (h->InheritsFrom(TH1::Class()) && x->InheritsFrom(TH1::Class()))
     296    {
     297        SetBinning(h, x->GetXaxis());
     298        return;
     299    }
     300}
  • trunk/MagicSoft/Mars/mhist/MH.h

    r1283 r1300  
    77
    88class TH1;
     9class TH2;
     10class TH3;
    911class TAxis;
    1012class TArrayD;
     
    2830
    2931    static void SetBinning(TH1 *h, const MBinning *binsx);
    30     static void SetBinning(TH1 *h, const MBinning *binsx, const MBinning *binsy);
    31     static void SetBinning(TH1 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz);
     32    static void SetBinning(TH2 *h, const MBinning *binsx, const MBinning *binsy);
     33    static void SetBinning(TH3 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz);
    3234
    3335    static void SetBinning(TH1 *h, const TArrayD *binsx);
    34     static void SetBinning(TH1 *h, const TArrayD *binsx, const TArrayD *binsy);
    35     static void SetBinning(TH1 *h, const TArrayD *binsx, const TArrayD *binsy, const TArrayD *binsz);
     36    static void SetBinning(TH2 *h, const TArrayD *binsx, const TArrayD *binsy);
     37    static void SetBinning(TH3 *h, const TArrayD *binsx, const TArrayD *binsy, const TArrayD *binsz);
    3638
    3739    static void SetBinning(TH1 *h, const TAxis *binsx);
    38     static void SetBinning(TH1 *h, const TAxis *binsx, const TAxis *binsy);
    39     static void SetBinning(TH1 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz);
     40    static void SetBinning(TH2 *h, const TAxis *binsx, const TAxis *binsy);
     41    static void SetBinning(TH3 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz);
    4042
    4143    static void SetBinning(TH1 *h, TH1 *x);
  • trunk/MagicSoft/Mars/mhist/MH3.cc

    r1299 r1300  
    229229    case 2:
    230230        fHist->SetTitle(title+" (2D)");
    231         SetBinning(fHist, binsx, binsy);
     231        SetBinning((TH2*)fHist, binsx, binsy);
    232232        return kTRUE;
    233233    case 3:
    234234        fHist->SetTitle(title+" (3D)");
    235         SetBinning(fHist, binsx, binsy, binsz);
     235        SetBinning((TH3*)fHist, binsx, binsy, binsz);
    236236        return kTRUE;
    237237    }
  • trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.cc

    r1228 r1300  
    196196}
    197197
     198// --------------------------------------------------------------------------
     199//
     200//  Calculate the Efficiency (collection area) and set the 'ReadyToSave'
     201//  flag
     202//
     203void MHMcCollectionArea::CalcEfficiency()
     204{
     205    MHMcEfficiency heff;
     206    heff.Calc(*fHistSel, *fHistAll);
     207
     208    Calc(heff);
     209}
     210
     211void MHMcCollectionArea::CalcEfficiency(UInt_t numevts, Float_t angle)
     212{
     213    // Here we estimate the total number of showers in each energy bin
     214    // known the energy range and spectral index of the generated showers
     215    // (set now by hand since the info is not available in the header!)
     216
     217    TH1D &histsel = *fHistSel->ProjectionX();
     218
     219    TH1D histall;
     220
     221    TAxis &xaxis = *histsel.GetXaxis();
     222
     223    MH::SetBinning(&histall, &xaxis);
     224    MH::SetBinning(fHistCol, &xaxis);
     225
     226    const Float_t emin  = 10.;
     227    const Float_t emax  = 30000.;  // Energies in GeV.
     228    const Float_t index = 2.6;     // Differential spectral Index.
     229
     230    const Float_t expo = 1.-index;
     231
     232    const Float_t k = (Float_t)numevts / (pow(emax,expo) - pow(emin,expo));
     233
     234    const Int_t nbinx = xaxis.GetNbins();
     235
     236    for (Int_t i=1; i<=nbinx; i++)
     237    {
     238        const Float_t e1 = histall.GetBinLowEdge(i);
     239        const Float_t e2 = histall.GetBinLowEdge(i+1);
     240
     241        if (e1 < emin || e2 > emax)
     242            continue;
     243
     244        const Float_t events = k * (pow(e2, expo) - pow(e1, expo));
     245
     246        histall.SetBinContent(i, events);
     247        histall.SetBinError(i, sqrt(events));
     248
     249    }
     250
     251    // -----------------------------------------------------------
     252
     253    // Impact parameter range:
     254    const Float_t r1 = 0;
     255    const Float_t r2 = 400;
     256
     257    const Float_t dr = TMath::Pi() * (r2*r2 - r1*r1);
     258
     259    angle *= TMath::Pi()/180;
     260
     261    for (Int_t ix=1; ix<=nbinx; ix++)
     262    {
     263        const Float_t Na = histall.GetBinContent(ix);
     264
     265        if (Na <= 0)
     266            continue;
     267
     268        const Float_t Ns = histsel.GetBinContent(ix);
     269
     270        // Since Na is an estimate of the total number of showers generated
     271        // in the energy bin, it may happen that Ns (triggered showers) is
     272        // larger than Na. In that case, the bin is skipped:
     273
     274        if (Na < Ns)
     275            continue;
     276
     277        const Double_t eff = Ns/Na;
     278
     279        const Double_t err = sqrt((1.-eff)*Ns)/Na;
     280
     281        const Float_t area = dr * cos(angle);
     282
     283        fHistCol->SetBinContent(ix, eff*area);
     284        fHistCol->SetBinError(ix, err*area);
     285    }
     286
     287    delete &histsel;
     288
     289    SetReadyToSave();
     290}
     291
     292void MHMcCollectionArea::Calc(const MHMcEnergyImpact &mcsel, const MHMcEnergyImpact &mcall)
     293{
     294    MHMcEfficiency heff;
     295    heff.Calc(*mcsel.GetHist(), *mcall.GetHist());
     296
     297    Calc(heff);
     298}
     299
    198300void MHMcCollectionArea::Calc(const MHMcEfficiency &heff)
    199301{
     
    242344//  flag
    243345//
    244 void MHMcCollectionArea::CalcEfficiency()
    245 {
    246     MHMcEfficiency heff;
    247     heff.Calc(*fHistSel, *fHistAll);
    248 
    249     Calc(heff);
    250 }
    251 
    252 void MHMcCollectionArea::Calc(const MHMcEnergyImpact &mcsel, const MHMcEnergyImpact &mcall)
    253 {
    254     MHMcEfficiency heff;
    255     heff.Calc(*mcsel.GetHist(), *mcall.GetHist());
    256 
    257     Calc(heff);
    258 }
     346/*
     347void MHMcCollectionArea::Calc(MHMcEnergyImpact &mcsel, UInt_t numevents, Float_t angle)
     348{
     349}
     350*/
  • trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.h

    r1228 r1300  
    3838
    3939    void CalcEfficiency();
     40    void CalcEfficiency(UInt_t allevts, Float_t theta);
    4041
    4142    void Calc(const MHMcEnergyImpact &mcsel, const MHMcEnergyImpact &mcall);
  • trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.cc

    r1108 r1300  
    3333#include "MMcEvt.hxx"
    3434#include "MMcTrig.hxx"
     35#include "MMcRunHeader.hxx"
    3536
    3637#include "MHMcCollectionArea.h"
     
    7374        return kFALSE;
    7475
     76
     77    fTotalNumSimulatedShowers = 0;
     78    fCorsikaVersion           = 0;
     79    fAllEvtsTriggered         = kFALSE;
     80
     81    return kTRUE;
     82}
     83
     84Bool_t MMcCollectionAreaCalc::ReInit(MParList *plist)
     85{
     86    MMcRunHeader *runheader = (MMcRunHeader*)plist->FindObject("MMcRunHeader");
     87    if (!runheader)
     88    {
     89        *fLog << err << dbginf << "Error - MMcRunHeader not found... exit." << endl;
     90        return kFALSE;
     91    }
     92
     93    fTotalNumSimulatedShowers += runheader->GetNumSimulatedShowers();
     94
     95    *fLog << inf << "Total Number of Simulated showers: " << fTotalNumSimulatedShowers << endl;
     96
     97    if (fTheta>=0 && fTheta!=runheader->GetTelesTheta())
     98        *fLog << warn << dbginf << "Warning - Read files have different TelesTheta... exit." << endl;
     99
     100    fTheta = runheader->GetTelesTheta();
     101
     102    if (fCorsikaVersion!=0 && fCorsikaVersion!=runheader->GetCorsikaVersion())
     103        *fLog << warn << dbginf << "Warning - Read files have different Corsika versions... exit." << endl;
     104
     105    fCorsikaVersion = runheader->GetCorsikaVersion();
     106
     107    fAllEvtsTriggered |= runheader->GetAllEvtsTriggered();
     108
     109    *fLog << inf << "Only triggered events avail: " << (fAllEvtsTriggered?"yes":"no") << endl;
     110
    75111    return kTRUE;
    76112}
     
    81117    const Float_t impact = fMcEvt->GetImpact()/100.;
    82118
    83     fCollArea->FillAll(energy, impact);
     119    if (!fAllEvtsTriggered)
     120        fCollArea->FillAll(energy, impact);
    84121
    85122    if (fMcTrig->GetFirstLevel() <= 0)
     
    96133    //   do the calculation of the effectiv area
    97134    //
    98     fCollArea->CalcEfficiency();
     135    *fLog << inf << "Calculation Collection Area..." << endl;
     136
     137    if (!fAllEvtsTriggered)
     138        fCollArea->CalcEfficiency();
     139    else
     140    {
     141        *fLog << inf << "Total number of showers: " << fTotalNumSimulatedShowers << endl;
     142        fCollArea->CalcEfficiency(fTotalNumSimulatedShowers,
     143                                  fCorsikaVersion == 5200 ? fTheta : 0);
     144    }
    99145
    100146    return kTRUE;
    101147}
     148
  • trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.h

    r1016 r1300  
    2121    TString fObjName;
    2222
     23    UInt_t fTotalNumSimulatedShowers;
     24    UInt_t fCorsikaVersion;
     25    Float_t fTheta;
     26
     27    Bool_t fAllEvtsTriggered;
     28
    2329public:
    2430    MMcCollectionAreaCalc(const char *input=NULL,
    2531                          const char *name=NULL, const char *title=NULL);
     32
     33    Bool_t ReInit(MParList *plist);
    2634
    2735    Bool_t PreProcess(MParList *pList);
Note: See TracChangeset for help on using the changeset viewer.