Ignore:
Timestamp:
06/13/05 09:41:57 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc

    r7099 r7147  
    3838#include <TFile.h>
    3939#include <TChain.h>
     40#include <TLatex.h>
    4041#include <TCanvas.h>
    4142#include <TObjArray.h>
     
    8485MJSpectrum::MJSpectrum(const char *name, const char *title)
    8586    : fCut0(0),fCut1(0), fCut2(0), fCut3(0), fEstimateEnergy(0),
    86     fRefill(kFALSE), fSimpleMode(kTRUE), fRawMc(kFALSE)
     87    fRefill(kFALSE), fSimpleMode(kTRUE), fRawMc(kFALSE),
     88    fNoThetaWeights(kFALSE)
    8789{
    8890    fName  = name  ? name  : "MJSpectrum";
     
    336338    // Calculate the Probability
    337339    temp1.Divide(&temp2);
    338     temp1.Scale(1./temp1.GetMaximum());
     340    temp1.Scale(fNoThetaWeights ? 1./temp1.GetMaximum() : 1./temp1.Integral());
    339341
    340342    // Some cosmetics: Name, Axis, etc.
     
    348350}
    349351
     352// --------------------------------------------------------------------------
     353//
     354// Display the final theta distribution.
     355//
    350356void MJSpectrum::DisplayResult(const TH2D &h2) const
    351357{
     
    376382}
    377383
     384// --------------------------------------------------------------------------
     385//
     386// Fills the excess histogram (vs E-est) from the events stored in the
     387// ganymed result file and therefor estimates the energy.
     388//
     389// The resulting histogram excess-vs-energy ist copied into h2.
     390//
    378391Bool_t MJSpectrum::Refill(MParList &plist, TH1D &h2) const
    379392{
     
    531544}
    532545
     546// --------------------------------------------------------------------------
     547//
     548// Calculate the final spectrum from:
     549//  - collection area
     550//  - excess
     551//  - correction coefficients
     552//  - ontime
     553// and display it
     554//
    533555TArrayD MJSpectrum::DisplaySpectrum(MHCollectionArea &area, TH1D &excess, MHEnergyEst &hest, Double_t ontime) const
    534556{
     
    573595    weights.DrawCopy();
    574596
    575     //spectrum.Divide(&weights);
    576     spectrum.Multiply(&weights);
    577     spectrum.SetNameTitle("Flux", "N/TeVsm^{2} versus Energy (after unfolding)");
     597    //spectrum.Multiply(&weights);
     598    spectrum.SetNameTitle("Flux", "Spectrum (after unfolding)");
     599    spectrum.SetBit(TH1::kNoStats);
    578600
    579601    for (int i=0; i<excess.GetNbinsX(); i++)
    580602    {
     603        spectrum.SetBinContent(i+1, spectrum.GetBinContent(i+1)*weights.GetBinContent(i+1));
     604        spectrum.SetBinError(i+1,   spectrum.GetBinError(i+1)  *weights.GetBinContent(i+1));
     605
    581606        spectrum.SetBinContent(i+1, spectrum.GetBinContent(i+1)/spectrum.GetBinWidth(i+1)*1000);
    582607        spectrum.SetBinError(i+1,   spectrum.GetBinError(i+1)/  spectrum.GetBinWidth(i+1)*1000);
     
    589614    gPad->SetGridx();
    590615    gPad->SetGridy();
     616    spectrum.SetMinimum(1e-12);
    591617    spectrum.SetXTitle("E [GeV]");
    592618    spectrum.SetYTitle("N/TeVsm^{2}");
    593619    spectrum.DrawCopy();
    594620
    595     TF1 f("f", "[1]*(x/1e3)^[0]", 50, 3e4);
     621    TF1 f("f", "[1]*(x/1e3)^[0]", 10, 3e4);
    596622    f.SetParameter(0, -2.87);
    597623    f.SetParameter(1, 1.9e-6);
    598624    f.SetLineColor(kGreen);
    599     spectrum.Fit(&f, "NIM", "", 55, 2e4);
     625    spectrum.Fit(&f, "NIM", "", 100, 4000);
    600626    f.DrawCopy("same");
    601627
    602     /*
    603      TString str;
    604      str += "(1.68#pm0.15)10^{-7}";
    605      str += "(\\frac{E}{TeV})^{-2.59#pm0.06}";
    606      str += "\\frac{ph}{TeVm^{2}s}";
    607 
    608      TLatex tex;
    609      tex.DrawLatex(2e2, 7e-5, str);
    610      */
     628    const Double_t p0 = f.GetParameter(0);
     629    const Double_t p1 = f.GetParameter(1);
     630
     631    const Double_t e0 = f.GetParError(0);
     632    const Double_t e1 = f.GetParError(1);
     633
     634    const Int_t    np  = TMath::Nint(TMath::Floor(TMath::Log10(p1)));
     635    const Double_t exp = TMath::Power(10, np);
     636
     637    TString str;
     638    str += Form("(%.2f#pm%.2f)10^{%d}", p1/exp, e1/exp, np);
     639    str += Form("(\\frac{E}{TeV})^{-%.2f#pm%.2f}", p0, e0);
     640    str += "\\frac{ph}{TeVm^{2}s}";
     641
     642    TLatex tex;
     643    tex.SetTextSize(0.045);
     644    tex.SetBit(TLatex::kTextNDC);
     645    tex.DrawLatex(0.45, 0.935, str);
     646
     647    str = Form("\\chi^{2}/NDF=%.2f", f.GetChisquare()/f.GetNDF());
     648    tex.DrawLatex(0.70, 0.83, str);
    611649
    612650    TArrayD res(2);
    613651    res[0] = f.GetParameter(0);
    614652    res[1] = f.GetParameter(1);
     653
     654
     655    // Plot other spectra  from Whipple
     656    f.SetParameter(0, -2.45);
     657    f.SetParameter(1, 3.3e-7);
     658    f.SetRange(300, 8000);
     659    f.SetLineColor(kBlack);
     660    f.SetLineStyle(kDashed);
     661    f.DrawCopy("same");
     662
     663    // Plot other spectra  from Cangaroo
     664    f.SetParameter(0, -2.53);
     665    f.SetParameter(1, 2.0e-7);
     666    f.SetRange(7000, 50000);
     667    f.SetLineColor(kBlack);
     668    f.SetLineStyle(kDashed);
     669    f.DrawCopy("same");
     670
     671    // Plot other spectra  from Robert
     672    f.SetParameter(0, -2.59);
     673    f.SetParameter(1, 2.58e-7);
     674    f.SetRange(150, 1500);
     675    f.SetLineColor(kBlack);
     676    f.SetLineStyle(kDashed);
     677    f.DrawCopy("same");
     678
     679    // Plot other spectra  from HEGRA
     680    f.SetParameter(0, -2.61);
     681    f.SetParameter(1, 2.7e-7);
     682    f.SetRange(1000, 20000);
     683    f.SetLineColor(kBlack);
     684    f.SetLineStyle(kDashed);
     685    f.DrawCopy("same");
     686
    615687    return res;
    616688}
    617689
     690// --------------------------------------------------------------------------
     691//
     692// Scale some image parameter plots using the scale factor and plot them
     693// together with the corresponding MC histograms.
     694// Called from DisplaySize
     695//
    618696Bool_t MJSpectrum::PlotSame(MStatusArray &arr, MParList &plist, const char *name, const char *tab, const char *plot, Double_t scale) const
    619697{
     
    664742}
    665743
     744// --------------------------------------------------------------------------
     745//
     746// Take a lot of histograms and plot them together in one plot.
     747// Calls PlotSame
     748//
    666749Bool_t MJSpectrum::DisplaySize(MParList &plist, Double_t scale) const
    667750{
     
    698781    gPad->SetGridy();
    699782
    700     excess->SetTitle("Number of excess events vs Size (data, mc/blue)");
     783    excess->SetTitle("Excess events vs Size (data/black, mc/blue)");
    701784    excess = excess->DrawCopy("E2");
    702785    // Don't do this on the original object!
     
    727810            histsel->KolmogorovTest(excess, "DX");
    728811            fLog->Separator("Chi^2 Test");
    729             histsel->Chi2Test(excess, "P");
     812            const Double_t p = histsel->Chi2Test(excess, "P");
     813
     814            TLatex tex;
     815            tex.SetBit(TLatex::kTextNDC);
     816            tex.DrawLatex(0.7, 0.93, Form("P(\\chi^{2})=%.0f", p*100));
    730817        }
    731818    }
     
    814901    if (!GetThetaDistribution(temp1, temp2))
    815902        return kFALSE;
     903
     904    if (!fNoThetaWeights)
     905        weight.SetZdWeights(&temp1);
    816906
    817907    TH1D excess;
     
    9301020
    9311021    tlist2.AddToList(&read);
    932     if (!fRawMc)
     1022    if (!fRawMc && fNoThetaWeights)
    9331023        tlist2.AddToList(&contsel);
    9341024    tlist2.AddToList(&calc);
Note: See TracChangeset for help on using the changeset viewer.