Ignore:
Timestamp:
08/20/07 11:04:58 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mjobs
Files:
2 edited

Legend:

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

    r8676 r8680  
    1818!   Author(s): Thomas Bretz, 4/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2005
     20!   Copyright: MAGIC Software Development, 2000-2007
    2121!
    2222!
     
    6262#include "../mhflux/MHAlpha.h"
    6363#include "../mhflux/MHCollectionArea.h"
    64 //#include "../mhflux/MHThreshold.h"
    6564#include "../mhflux/MHEnergyEst.h"
    6665#include "../mhflux/MMcSpectrumWeight.h"
     
    8079#include "MFillH.h"
    8180#include "MHillasCalc.h"
    82 //#include "MSrcPosCalc.h"
    8381#include "MContinue.h"
    8482
     
    8987MJSpectrum::MJSpectrum(const char *name, const char *title)
    9088    : fCutQ(0), fCut0(0),fCut1(0), fCut2(0), fCut3(0), fCutS(0),
    91     fEstimateEnergy(0), fCalcHadronness(0), fRefill(kFALSE),
    92     /*fSimpleMode(kTRUE),*/ fForceTheta(kFALSE),
    93     fRawMc(kFALSE), fNoThetaWeights(kFALSE)
     89    fEstimateEnergy(0), fCalcHadronness(0),  fForceTheta(kFALSE)
    9490{
    9591    fName  = name  ? name  : "MJSpectrum";
    9692    fTitle = title ? title : "Standard program to calculate spectrum";
    97 }
    98 
     93
     94    // Make sure that fDisplay is maintained properly
     95    // (i.e. removed via RecursiveRemove if closed)
     96    gROOT->GetListOfCleanups()->Add(this);
     97}
     98
     99// --------------------------------------------------------------------------
     100//
     101// Delete all the fCut* data members and fCalcHadronness/fEstimateEnergy
     102//
    99103MJSpectrum::~MJSpectrum()
    100104{
     
    128132}
    129133
     134// --------------------------------------------------------------------------
     135//
     136// Read a MTask named name into task from the open file. If this task is
     137// required mustexist can be set. Depending on success kTRUE or kFALSE is
     138// returned. If the task is a MContinue SetAllowEmpty is called.
     139// The name of the task is set to name.
     140//
    130141Bool_t MJSpectrum::ReadTask(MTask* &task, const char *name, Bool_t mustexist) const
    131142{
     143    // If a task is set delete task
    132144    if (task)
    133145    {
     
    136148    }
    137149
     150    // Try to get task from file
    138151    task = (MTask*)gFile->Get(name);
    139152    if (!task)
     
    144157        return kFALSE;
    145158    }
     159
     160    // Check if task inherits from MTask
    146161    if (!task->InheritsFrom(MTask::Class()))
    147162    {
     
    151166    }
    152167
     168    // Set name of task
    153169    task->SetName(name);
    154170
     171    // SetAllowEmpty for MContinue tasks
    155172    if (dynamic_cast<MContinue*>(task))
    156173        dynamic_cast<MContinue*>(task)->SetAllowEmpty();
     
    159176}
    160177
     178// --------------------------------------------------------------------------
     179//
     180// Print setup used for the MC processing, namely MAlphaFitter ans all fCut*.
     181//
    161182void MJSpectrum::PrintSetup(const MAlphaFitter &fit) const
    162183{
     
    194215    }
    195216
    196     // Read the first corsika RunHeader from the MC files
    197     TChain chain("RunHeaders");
    198     if (!set.AddFilesOn(chain))
    199         return kFALSE;
    200 
    201     MMcCorsikaRunHeader *h=0;
    202     chain.SetBranchAddress("MMcCorsikaRunHeader.", &h);
    203     chain.GetEntry(1);
    204 
    205     if (!h)
    206     {
    207         *fLog << err << "ERROR - Couldn't read MMcCorsikaRunHeader from DataSet." << endl;
    208         return kFALSE;
    209     }
    210 
    211     // Propagate the run header to MMcSpectrumWeight
    212     if (!w.Set(*h))
    213     {
    214         *fLog << err << "ERROR - Initializing MMcSpectrumWeight failed." << endl;
    215         return kFALSE;
    216     }
    217 
    218     // Print new setup of MMcSpectrumWeight
    219     w.Print();
     217    w.Print("new");
     218
    220219    return kTRUE;
    221220}
     
    281280}
    282281
     282// --------------------------------------------------------------------------
     283//
     284// return maximum value of MMcRunHeader.fImpactMax stored in the RunHeaders
     285// of the files from the MC dataset
     286//
     287Bool_t MJSpectrum::AnalyzeMC(const MDataSet &set, Float_t &impactmax, Float_t &emin/*, Float_t emax*/) const
     288{
     289    if (fDisplay)
     290        fDisplay->SetStatusLine1("Analyzing Monte Carlo headers...");
     291
     292    // ----- Create chain -----
     293    *fLog << inf << "Getting files... " << flush;
     294    TChain chain("RunHeaders");
     295    if (!set.AddFilesOn(chain))
     296        return kFALSE;
     297    *fLog << "done. " << endl;
     298
     299    *fLog << all;
     300    *fLog << "Searching for maximum impact... " << flush;
     301    impactmax = chain.GetMaximum("MMcRunHeader.fImpactMax");
     302    *fLog << "found " << impactmax/100 << "m" << endl;
     303
     304    *fLog << "Searching for minimum lower energy limit... " << flush;
     305    emin = chain.GetMinimum("MMcCorsikaRunHeader.fELowLim");
     306    *fLog << "found " << emin << "GeV" << endl;
     307
     308    *fLog << "Searching for maximum lower energy limit... " << flush;
     309    const Float_t emin2 = chain.GetMaximum("MMcCorsikaRunHeader.fELowLim");
     310    *fLog << "found " << emin2 << "GeV" << endl;
     311
     312    if (emin2>emin)
     313    {
     314        *fLog << warn;
     315        *fLog << "WARNING - You are using files with different lower limits for the simulated" << endl;
     316        *fLog << "          energy, i.e. that the collection area and your correction" << endl;
     317        *fLog << "          coefficients between " << emin << "GeV and ";
     318        *fLog << emin2 << "GeV might be wrong." << endl;
     319    }
     320
     321/*
     322    *fLog << "Getting maximum energy... " << flush;
     323    emax = chain.GetMaximum("MMcCorsikaRunHeader.fEUppLim");
     324    *fLog << "found " << emax << "GeV" << endl;
     325 */
     326    return kTRUE;
     327}
     328
    283329Bool_t MJSpectrum::ReadOrigMCDistribution(const MDataSet &set, TH1 &h, MMcSpectrumWeight &weight) const
    284330{
     
    286332    fLog->Separator("Compiling original MC distribution");
    287333
    288     // The name of the input container is MMcEvtBasic
    289     weight.SetNameMcEvt("MMcEvtBasic");
    290     // Get the corresponding rule for the weights
    291     const TString w(weight.GetFormulaWeights());
    292     // Set back to MMcEvt
    293     weight.SetNameMcEvt();
    294 
    295     *fLog << inf << "Using weights: " << w << endl;
    296     *fLog << "Please stand by, this may take a while..." << endl;
    297 
    298     if (fDisplay)
    299         fDisplay->SetStatusLine1("Getting maximum impact...");
    300 
    301     // ----- Create chain -----
    302     *fLog << "Getting files... " << flush;
    303     TChain chain("RunHeaders");
    304     if (!set.AddFilesOn(chain))
    305         return kFALSE;
    306     *fLog << "done. " << endl;
    307 
    308     *fLog << "Getting maximum impact... " << flush;
    309     const Double_t impactmax = chain.GetMaximum("MMcRunHeader.fImpactMax");
    310     *fLog << "found " << impactmax/100 << "m" << endl;
    311 
    312     *fLog << "Getting files... " << flush;
     334    Float_t impactmax=0, Emin=0;
     335    if (!AnalyzeMC(set, impactmax, Emin))
     336        return kFALSE;
     337
     338    *fLog << inf << "Getting files... " << flush;
    313339    MDirIter iter;
    314340    if (!set.AddFilesOn(iter))
    315341        return kFALSE;
    316342    *fLog << "done. " << endl;
     343
     344    const Int_t tot = iter.GetNumEntries();
    317345
    318346    // Prepare histogram
     
    339367
    340368    if (fDisplay)
    341         fDisplay->SetStatusLine1("Reading OriginalMC");
     369        fDisplay->SetStatusLine1("Reading OriginalMC distribution...");
    342370
    343371    TH1 *hfill = (TH1*)h.Clone(h.InheritsFrom(TH2::Class())?"ThetaEMC":"ThetaMC");
    344372    hfill->SetDirectory(0);
    345373
     374    *fLog << all << "Compiling simulated source spectrum... please stand by, this may take a while." << endl;
     375
     376    Double_t evts = 0;
     377    Int_t    num  = 0;
     378
     379    // Reading this with a eventloop is five times slower :(
    346380    TString fname;
    347     while (1)
    348     {
     381    while (fDisplay)
     382    {
     383        if (fDisplay)
     384            fDisplay->SetProgressBarPosition(Float_t(num++)/tot);
     385
     386        // Get next filename
    349387        fname = iter.Next();
    350388        if (fname.IsNull())
    351389            break;
    352390
     391        if (fDisplay)
     392            fDisplay->SetStatusLine2(fname);
     393
     394        // open file
    353395        TFile file(fname);
    354396        if (file.IsZombie())
     
    358400        }
    359401
     402        // Get tree OriginalMC
     403        TTree *t = dynamic_cast<TTree*>(file.Get("OriginalMC"));
     404        if (!t)
     405        {
     406            *fLog << err << "ERROR - File " << fname << " doesn't contain tree OriginalMC." << endl;
     407            return kFALSE;
     408        }
     409        if (t->GetEntries()==0)
     410        {
     411            *fLog << warn << "WARNING - OriginalMC of " << fname << " empty." << endl;
     412            continue;
     413        }
     414
     415        // Get tree RunHeaders
    360416        TTree *rh = dynamic_cast<TTree*>(file.Get("RunHeaders"));
    361417        if (!rh)
     
    364420            return kFALSE;
    365421        }
    366 
    367422        if (rh->GetEntries()!=1)
    368423        {
     
    371426        }
    372427
    373         TTree *t = dynamic_cast<TTree*>(file.Get("OriginalMC"));
    374         if (!t)
     428        // Get corsika run header
     429        MMcCorsikaRunHeader *head=0;
     430        rh->SetBranchAddress("MMcCorsikaRunHeader.", &head);
     431        rh->GetEntry(0);
     432        if (!head)
    375433        {
    376             *fLog << err << "ERROR - File " << fname << " doesn't contain tree OriginalMC." << endl;
     434            *fLog << err << "ERROR - Couldn't read MMcCorsikaRunHeader from " << fname << "." << endl;
    377435            return kFALSE;
    378436        }
    379437
     438        // Get the maximum impact parameter of this file. Due to different
     439        // production areas an additional scale-factor is applied.
     440        //
     441        // Because it is assumed that the efficiency outside the production
     442        // area is nearly zero no additional weight has to be applied to the
     443        // events after cuts.
     444        const Double_t impact = rh->GetMaximum("MMcRunHeader.fImpactMax");
     445        const Double_t scale  = impactmax/impact;
     446 
     447        // Propagate the run header to MMcSpectrumWeight
     448        if (!weight.Set(*head))
     449        {
     450            *fLog << err << "ERROR - Initializing MMcSpectrumWeight failed." << endl;
     451            return kFALSE;
     452        }
     453
     454        // Get the corresponding rule for the weights
     455        const TString weights(weight.GetFormulaWeights("MMcEvtBasic"));
     456
     457        // No we found everything... go on reading contents
    380458        *fLog << inf << "Reading OriginalMC of " << fname << endl;
    381 
    382         if (t->GetEntries()==0)
    383         {
    384             *fLog << warn << "WARNING - OriginalMC of " << fname << " empty." << endl;
    385             continue;
    386         }
    387 
    388         // Why does it crash if closed within loop (no update?)
    389         //if (fDisplay)
    390         //    fDisplay->SetStatusLine2(fname);
    391 
    392         // Normalize by deviding through production area
    393         const Double_t impact  = rh->GetMaximum("MMcRunHeader.fImpactMax");
    394         const Double_t scale   = impactmax/impact;
    395         const TString  weights = Form("%.16e*(%s)", scale*scale, w.Data());
    396459
    397460        // Fill histogram from tree
     
    403466        }
    404467        hfill->SetDirectory(0);
     468
     469        evts += hfill->GetEntries();
     470
     471        // ----- Complete incomplete energy ranges -----
     472        // ----- and apply production area weights -----
     473        weight.CompleteEnergySpectrum(*hfill, Emin);
     474
     475        hfill->Scale(scale*scale);
     476
     477        // Add weighted data from file to final histogram
    405478        h.Add(hfill);
    406479    }
    407480    delete hfill;
    408481
    409     *fLog << "Total number of events from file: " << h.GetEntries() << endl;
     482    *fLog << all << "Total number of events from files in Monte Carlo dataset: " << evts << endl;
    410483    if (fDisplay)
    411484        fDisplay->SetStatusLine2("done.");
    412485
    413     if (h.GetEntries()>0)
     486    if (!fDisplay || h.GetEntries()>0)
    414487        return kTRUE;
    415488
    416     *fLog << err << "ERROR - Histogram with original MC distribution empty..." << endl;
    417 
     489    *fLog << err << "ERROR - Histogram with distribution from OriginalMC empty..." << endl;
    418490    return kFALSE;
    419491}
    420492
    421 Bool_t MJSpectrum::GetThetaDistribution(TH1D &temp1, TH1D &temp2) const
    422 {
     493void MJSpectrum::GetThetaDistribution(TH1D &temp1, TH2D &hist2) const
     494{
     495    TH1D &temp2 = *hist2.ProjectionX();
     496
    423497    // Display some stuff
    424498    if (fDisplay)
     
    430504        c.cd(1);
    431505        gPad->SetBorderMode(0);
     506        gPad->SetGridx();
     507        gPad->SetGridy();
    432508        temp1.DrawCopy();
    433509
     
    435511        c.cd(2);
    436512        gPad->SetBorderMode(0);
     513        gPad->SetGridx();
     514        gPad->SetGridy();
    437515        temp2.SetName("NVsTheta");
    438516        temp2.DrawCopy("hist");
     
    440518        c.cd(4);
    441519        gPad->SetBorderMode(0);
     520        gPad->SetGridx();
     521        gPad->SetGridy();
    442522
    443523        c.cd(3);
    444524        gPad->SetBorderMode(0);
     525        gPad->SetGridx();
     526        gPad->SetGridy();
    445527    }
    446528
    447529    // Calculate the Probability
    448530    temp1.Divide(&temp2);
    449     temp1.Scale(fNoThetaWeights ? 1./temp1.GetMaximum() : 1./temp1.Integral());
     531    temp1.Scale(1./temp1.Integral());
    450532
    451533    // Some cosmetics: Name, Axis, etc.
     
    456538        temp1.DrawCopy("hist");
    457539
    458     return kTRUE;
     540    delete &temp2;
    459541}
    460542
     
    492574    }
    493575
     576    // Check whether histogram is empty
    494577    if (proj.GetMaximum()==0)
    495578    {
     
    497580        *fLog << "ERROR - The Zenith Angle distribution of your Monte Carlos doesn't overlap" << endl;
    498581        *fLog << "        with the Zenith Angle distribution of your observation." << endl;
    499         *fLog << "        Maybe the energy binning is not defined or wrong." << endl;
     582        *fLog << "        Maybe the energy binning is undefined or wrong (from ";
     583        *fLog << h2.GetYaxis()->GetXmin() << "GeV to " << h2.GetYaxis()->GetXmax() << "GeV)" << endl;
    500584        theta->SetLineColor(kRed);
    501585        return kFALSE;;
    502586    }
    503587
     588    // scale histogram and set new maximum for display
    504589    proj.Scale(theta->GetMaximum()/proj.GetMaximum());
    505590    theta->SetMaximum(1.05*TMath::Max(theta->GetMaximum(), proj.GetMaximum()));
    506591
     592    // draw project
    507593    proj.Draw("same");
    508594
     
    688774    fill0.SetFilter(&sel1);
    689775
    690     if (!fRawMc)
     776    //if (!fRawMc)
    691777        tlist1.AddToList(&sel1);
    692778    tlist1.AddToList(&fill0);
     
    767853TArrayD MJSpectrum::FitSpectrum(TH1D &spectrum) const
    768854{
    769     TF1 f("f", "[1]*(x/1e3)^[0]", 10, 3e4);
    770     f.SetParameter(0, -2.5);
    771     f.SetParameter(1, spectrum.GetBinContent(spectrum.GetXaxis()->FindFixBin(1000)));
     855    Axis_t lo, hi;
     856    MH::GetRangeUser(spectrum, lo, hi);
     857
     858    TF1 f("f", "[1]*(x/500)^[0]", lo, hi);
     859    f.SetParameter(0, -3.0);
     860    f.SetParameter(1, spectrum.GetMaximum());
    772861    f.SetLineColor(kBlue);
    773     spectrum.Fit(&f, "NI", "", 80, 1150); // M skipped
     862    f.SetLineWidth(2);
     863    spectrum.Fit(&f, "NIR"); // M skipped
    774864    f.DrawCopy("same");
    775865
     
    881971    spec = (TH1D*)spectrum.DrawCopy();
    882972
    883     // Calculate Spectrum * E^2
    884     for (int i=0; i<spectrum.GetNbinsX(); i++)
    885     {
    886         const Double_t e = TMath::Sqrt(spectrum.GetBinLowEdge(i+1)*spectrum.GetBinLowEdge(i+2))*1e-3;
    887 
    888         spectrum.SetBinContent(i+1, spectrum.GetBinContent(i+1)*e*e);
    889         spectrum.SetBinError(  i+1, spectrum.GetBinError(i+1)  *e*e);
    890     }
     973    TF1 fc("Crab", "7.0e-6*(x/300)^(-2.31-0.26*log10(x/300))", 100, 6000);
     974    fc.SetLineStyle(7);
     975    fc.SetLineWidth(2);
     976    fc.SetLineColor(14);
     977    fc.DrawCopy("same");
     978
     979    TF1 fa("PG1553", "1.8e-6*(x/200)^-4.21", 90, 600);
     980    static_cast<const TAttLine&>(fc).Copy(fa);
     981    fa.DrawCopy("same");
    891982
    892983    // Display dN/dE*E^2 for conveinience
     
    896987    gPad->SetGrid();
    897988
     989    // Calculate Spectrum * E^2
     990    for (int i=0; i<spectrum.GetNbinsX(); i++)
     991    {
     992        const Double_t e = TMath::Sqrt(spectrum.GetBinLowEdge(i+1)*spectrum.GetBinLowEdge(i+2))*1e-3;
     993
     994        spectrum.SetBinContent(i+1, spectrum.GetBinContent(i+1)*e*e);
     995        spectrum.SetBinError(  i+1, spectrum.GetBinError(i+1)  *e*e);
     996    }
     997
    898998    spectrum.SetName("FluxStd");
    899999    spectrum.SetMarkerStyle(kFullDotMedium);
    9001000    spectrum.SetTitle("Differential flux times E^{2}");
    901     spectrum.SetYTitle("E^{2}dN/dE [N TeV/sm^{2}]");
     1001    spectrum.SetYTitle("E^{2}#cdot dN/dE [N#cdot TeV/sm^{2}]");
    9021002    spectrum.SetDirectory(0);
    9031003    spectrum.DrawCopy();
     1004
     1005    TF1 fc2("Crab*E^2", "x^2*Crab*1e-6", 100, 6000);
     1006    static_cast<const TAttLine&>(fc).Copy(fc2);
     1007    fc2.DrawCopy("same");
     1008
     1009    TF1 fa2("PG1553*E^2", "x^2*PG1553*1e-6", 100, 6000);
     1010    static_cast<const TAttLine&>(fc).Copy(fa2);
     1011    fa2.DrawCopy("same");
    9041012
    9051013    // Fit Spectrum
     
    9431051    return res;
    9441052  */
    945 /*
    946     // Plot other spectra  from Whipple
    947     f.SetParameter(0, -2.45);
    948     f.SetParameter(1, 3.3e-7);
    949     f.SetRange(300, 8000);
    950     f.SetLineColor(kBlack);
    951     f.SetLineStyle(kDashed);
    952     f.DrawCopy("same");
    953 
    954     // Plot other spectra  from Cangaroo
    955     f.SetParameter(0, -2.53);
    956     f.SetParameter(1, 2.0e-7);
    957     f.SetRange(7000, 50000);
    958     f.SetLineColor(kBlack);
    959     f.SetLineStyle(kDashed);
    960     f.DrawCopy("same");
    961 
    962     // Plot other spectra  from Robert
    963     f.SetParameter(0, -2.59);
    964     f.SetParameter(1, 2.58e-7);
    965     f.SetRange(150, 1500);
    966     f.SetLineColor(kBlack);
    967     f.SetLineStyle(kDashed);
    968     f.DrawCopy("same");
    969 
    970     // Plot other spectra  from HEGRA
    971     f.SetParameter(0, -2.61);
    972     f.SetParameter(1, 2.7e-7);
    973     f.SetRange(1000, 20000);
    974     f.SetLineColor(kBlack);
    975     f.SetLineStyle(kDashed);
    976     f.DrawCopy("same");
    977  */
    9781053}
    9791054
     
    11791254    *fLog << endl;
    11801255
     1256    // Setup everything which is read from the ganymed file
    11811257    MBinning bins1("BinningAlpha");
    11821258    MBinning bins2("BinningEnergyEst");
     
    11911267    MBinning binsa("BinningAsym");
    11921268    MBinning binsb("BinningConc1");
    1193 
    11941269
    11951270    MAlphaFitter fit;
     
    12091284    plist.AddToList(&fit);
    12101285
    1211     TH1D temp1, size;
    1212     const Float_t ontime = ReadInput(plist, temp1, size);
     1286    // Read from the ganymed file
     1287    TH1D htheta, size;
     1288    const Float_t ontime = ReadInput(plist, htheta, size);
    12131289    if (ontime<0)
    12141290    {
     
    12171293    }
    12181294
    1219     plist.AddToList(&bins2);
    1220 
    1221     // Initialize weighting to a new spectrum
    1222     // as defined in the resource file
     1295    // Set Zenith angle binning to binning from the ganymed-file
     1296    bins3.SetEdges(htheta, 'x');
     1297
     1298    // Read energy binning from resource file
     1299    if (!CheckEnv(bins2))
     1300    {
     1301        *fLog << err << "ERROR - Reading energy binning from resources failed." << endl;
     1302        return kFALSE;
     1303    }
     1304    plist.AddToList(&bins2); // For later use in MC processing
     1305
     1306    // Initialize weighting to a new spectrum as defined in the resource file
    12231307    MMcSpectrumWeight weight;
    12241308    if (!InitWeighting(set, weight))
    12251309        return kFALSE;
    12261310
    1227     bins3.SetEdges(temp1, 'x');
    1228 
    1229     // Read the MC distribution as produced by corsika into
    1230     // temp2 (1D) and apply the weights previously determined
    1231     TH1D temp2(temp1);
    1232     if (!ReadOrigMCDistribution(set, temp2, weight))
    1233         return kFALSE;
    1234 
    1235     // Calculate the weights according to the zenith angle distribution
    1236     // of the raw-data which have to be applied to the MC events
    1237     if (!GetThetaDistribution(temp1, temp2))
    1238         return kFALSE;
    1239 
    1240     // Tell the weighting task about the ZA-weights
    1241     if (!fNoThetaWeights)
    1242         weight.SetWeightsZd(&temp1);
     1311    // Print Theta and energy binning for cross-checks
     1312    *fLog << all << endl;
     1313    bins2.Print();
     1314    bins3.Print();
     1315
     1316    // Now we read the MC distribution as produced by corsika
     1317    // vs zenith angle and energy.
     1318    // Weight for the new energy spectrum defined in MMcSpectumWeight
     1319    // are applied.
     1320    // Also correction for different lower energy bounds and
     1321    // different production areas (impact parameters) are applied.
     1322    TH2D hist;
     1323    hist.UseCurrentStyle();
     1324    MH::SetBinning(&hist, &bins3, &bins2);
     1325    if (!ReadOrigMCDistribution(set, hist, weight))
     1326        return kFALSE;
     1327
     1328    // Check if user has closed the display
     1329    if (!fDisplay)
     1330        return kTRUE;
     1331
     1332    // Display histograms and calculate za-weights into htheta
     1333    GetThetaDistribution(htheta, hist);
     1334
     1335    // Give the zenoith angle weights to the weighting task
     1336    weight.SetWeightsZd(&htheta);
     1337
     1338    // No we apply the the zenith-angle-weights to the corsika produced
     1339    // MC distribution. Unfortunately this must be done manually
     1340    // because we are multiplying column by column
     1341    for (int y=0; y<hist.GetNbinsY(); y++)
     1342        for (int x=0; x<hist.GetNbinsX(); x++)
     1343        {
     1344            hist.SetBinContent(x, y, hist.GetBinContent(x, y)*htheta.GetBinContent(x));
     1345            hist.SetBinError(x, y,   hist.GetBinError(x, y)  *htheta.GetBinContent(x));
     1346        }
     1347
     1348    // Display the resulting distribution and check it matches
     1349    // the observation time distribution (this could be false
     1350    // for example if you miss MCs of some zenith angles, which you have
     1351    // data for)
     1352    if (!DisplayResult(hist))
     1353        return kFALSE;
     1354
     1355    // -------------- Fill excess events versus energy ---------------
    12431356
    12441357    // Refill excess histogram to determin the excess events
     
    12471360        return kFALSE;
    12481361
    1249     // Print the setup and result of the MAlphaFitter
    1250     // Print used cuts
     1362    // Print the setup and result of the MAlphaFitter, print used cuts
    12511363    PrintSetup(fit);
    1252 
    1253     TH2D hist;
    1254     MH3 mh1("MMcEvtBasic.fTelescopeTheta*kRad2Deg", "MMcEvtBasic.fEnergy");
    1255     //if (fSimpleMode)
    1256     {
    1257         // Now we read the MC distribution as produced by corsika again
    1258         // with the spectral weights applied into a histogram vs.
    1259         // zenith angle and energy
    1260         hist.UseCurrentStyle();
    1261         MH::SetBinning(&hist, &bins3/*temp1.GetXaxis()*/, &bins2/*excess.GetXaxis()*/);
    1262         if (!ReadOrigMCDistribution(set, hist, weight))
    1263             return kFALSE;
    1264 
    1265         // No we apply the the zenith-angle-weights to the corsika produced
    1266         // MC distribution. Unfortunately this must be done manually
    1267         // because we are multiplying column by column
    1268         if (!fRawMc)
    1269         {
    1270             for (int y=0; y<hist.GetNbinsY(); y++)
    1271                 for (int x=0; x<hist.GetNbinsX(); x++)
    1272                 {
    1273                     hist.SetBinContent(x, y, hist.GetBinContent(x, y)*temp1.GetBinContent(x));
    1274                     hist.SetBinError(x, y,   hist.GetBinError(x, y)  *temp1.GetBinContent(x));
    1275                 }
    1276         }
    1277     }/*
    1278     else
    1279     {
    1280         // This rereads the original MC spectrum and aplies both
    1281         // weights, spectral weights and ZA-weights.
    1282         weight.SetNameMcEvt("MMcEvtBasic");
    1283         if (!IntermediateLoop(plist, mh1, temp1, set, weight))
    1284             return kFALSE;
    1285         weight.SetNameMcEvt();
    1286     }*/
    1287 
    1288     if (!DisplayResult(/*fSimpleMode ?*/ hist /*: (TH2D&)mh1.GetHist()*/))
    1289         return kFALSE;
    12901364
    12911365    // ------------------------- Final loop --------------------------
     
    13041378
    13051379    // Selector to get correct (final) theta-distribution
    1306     temp1.SetXTitle("MPointingPos.fZd");
    1307 
    1308     MH3 mh3(temp1);
    1309 
    1310     MFEventSelector2 sel2(mh3);
    1311     sel2.SetHistIsProbability();
    1312 
    1313     MContinue contsel(&sel2);
    1314     contsel.SetInverted();
     1380    //temp1.SetXTitle("MPointingPos.fZd");
     1381    //
     1382    //MH3 mh3(temp1);
     1383    //
     1384    //MFEventSelector2 sel2(mh3);
     1385    //sel2.SetHistIsProbability();
     1386    //
     1387    //MContinue contsel(&sel2);
     1388    //contsel.SetInverted();
    13151389
    13161390    // Get correct source position
     
    13181392
    13191393    // Calculate corresponding Hillas parameters
    1320     /*
    1321      MHillasCalc hcalc1;
    1322      MHillasCalc hcalc2("MHillasCalcAnti");
    1323      hcalc1.SetFlags(MHillasCalc::kCalcHillasSrc);
    1324      hcalc2.SetFlags(MHillasCalc::kCalcHillasSrc);
    1325      hcalc2.SetNameHillasSrc("MHillasSrcAnti");
    1326      hcalc2.SetNameSrcPosCam("MSrcPosAnti");
    1327      */
     1394    //MHillasCalc hcalc1;
     1395    //MHillasCalc hcalc2("MHillasCalcAnti");
     1396    //hcalc1.SetFlags(MHillasCalc::kCalcHillasSrc);
     1397    //hcalc2.SetFlags(MHillasCalc::kCalcHillasSrc);
     1398    //hcalc2.SetNameHillasSrc("MHillasSrcAnti");
     1399    //hcalc2.SetNameSrcPosCam("MSrcPosAnti");
    13281400
    13291401    // Fill collection area and energy estimator (unfolding)
     
    13311403    MHCollectionArea area0("TriggerArea");
    13321404    MHCollectionArea area1;
    1333     area0.SetHistAll(/*fSimpleMode ?*/ hist /*: (TH2D&)mh1.GetHist()*/);
    1334     area1.SetHistAll(/*fSimpleMode ?*/ hist /*: (TH2D&)mh1.GetHist()*/);
     1405    area0.SetHistAll(hist);
     1406    area1.SetHistAll(hist);
    13351407
    13361408    MHEnergyEst      hest;
     
    13711443    MFillH fill7a("MHNewParMCPost [MHNewImagePar]", "MNewImagePar", "FillNewParPost");
    13721444    MFillH fill8a("ExcessMC       [MH3]",           "",             "FillExcessMC");
     1445    fill0a.SetNameTab("EvtDist");
    13731446    fill1a.SetNameTab("PreCut");
    13741447    fill2a.SetNameTab("PostCut");
     
    13991472    // be thrown away according to the theta distribution
    14001473    // it is enabled here
    1401     if (!fRawMc && fNoThetaWeights)
    1402         tlist2.AddToList(&contsel);
     1474    //if (!fRawMc && fNoThetaWeights)
     1475    //    tlist2.AddToList(&contsel);
    14031476    //tlist2.AddToList(&calc);
    14041477    //tlist2.AddToList(&hcalc1);
  • trunk/MagicSoft/Mars/mjobs/MJSpectrum.h

    r8676 r8680  
    3333    MTask *fCalcHadronness;
    3434
    35     Bool_t fRefill;
    36     //Bool_t fSimpleMode;
    3735    Bool_t fForceTheta;
    38     Bool_t fRawMc;
    39     Bool_t fNoThetaWeights;
    4036
    4137    // Read Input
    42     Bool_t  ReadTask(MTask* &task, const char *name, Bool_t mustexist=kTRUE) const;
    43     Float_t ReadInput(MParList &plist, TH1D &h1, TH1D &size);
    44     Bool_t  ReadOrigMCDistribution(const MDataSet &set, TH1 &h, MMcSpectrumWeight &w) const;
    45     Bool_t  GetThetaDistribution(TH1D &temp1, TH1D &temp2) const;
    46     Bool_t  Refill(MParList &plist, TH1D &h) /*const*/;
    47     Bool_t  InitWeighting(const MDataSet &set, MMcSpectrumWeight &w) const;
     38    Bool_t   ReadTask(MTask* &task, const char *name, Bool_t mustexist=kTRUE) const;
     39    Float_t  ReadInput(MParList &plist, TH1D &h1, TH1D &size);
     40    Bool_t   AnalyzeMC(const MDataSet &set, Float_t &impactmax, Float_t &emin/*, Float_t emax*/) const;
     41    Bool_t   ReadOrigMCDistribution(const MDataSet &set, TH1 &h, MMcSpectrumWeight &w) const;
     42    void     GetThetaDistribution(TH1D &temp1, TH2D &temp2) const;
     43    Bool_t   Refill(MParList &plist, TH1D &h) /*const*/;
     44    Bool_t   InitWeighting(const MDataSet &set, MMcSpectrumWeight &w) const;
    4845
    4946    // Display Output
     
    6360    Bool_t Process(const MDataSet &set);
    6461
    65     void EnableRefilling(Bool_t b=kTRUE)  { fRefill=b; }
    66     //void EnableSimpleMode(Bool_t b=kTRUE) { fSimpleMode=b; }
    67     void EnableRawMc(Bool_t b=kTRUE)      { fRawMc=b; }
    68     void ForceTheta(Bool_t b=kTRUE)       { fForceTheta=b; }
     62    void ForceTheta(Bool_t b=kTRUE) { fForceTheta=b; }
    6963
    7064    void SetEnergyEstimator(const MTask *task);
Note: See TracChangeset for help on using the changeset viewer.