Ignore:
Timestamp:
02/15/05 17:20:40 (20 years ago)
Author:
moralejo
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.cc

    r5340 r6491  
    1717!
    1818!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
    19 !   Author(s): Harald Kornmayer 1/2001
     19!   Author(s): Harald Kornmayer  1/2001
     20!   Author(s): Abelardo Moralejo 2/2005 <mailto:moralejo@pd.infn.it>
    2021!
    2122!   Copyright: MAGIC Software Development, 2000-2002
     
    2627//////////////////////////////////////////////////////////////////////////////
    2728//
    28 //  MHMcCollectionAreaCalc
    29 //
    30 //  Remark: The initialization is mainly done in the ReInit function.
    31 //          Please make sure, that you don't use MReadTree when processing
    32 //          a file. Use a 'ReInit'-calling task like MReadMarsFile
     29//  MMcCollectionAreaCalc
    3330//
    3431//////////////////////////////////////////////////////////////////////////////
     
    4239
    4340#include "MMcEvt.hxx"
    44 #include "MMcTrig.hxx"
     41#include "MMcEvtBasic.h"
     42
    4543#include "MMcRunHeader.hxx"
    4644#include "MMcCorsikaRunHeader.h"
     
    5250using namespace std;
    5351
    54 MMcCollectionAreaCalc::MMcCollectionAreaCalc(const char *input,
    55                                              const char *name, const char *title)
     52////////////////////////////////////////////////////////////////////////////////
     53//
     54//  Constructor
     55//
     56MMcCollectionAreaCalc::MMcCollectionAreaCalc(const char *input, const char *name,
     57                                             const char *title):
     58  fBinsTheta(0), fBinsEnergy(0), fSpectrum(0)
    5659{
    5760    fName  = name  ? name  : "MMcCollectionAreaCalc";
    5861    fTitle = title ? title : "Task to calculate the collection area";
    59 
    60     fObjName = input ? input : "MMcTrig";
    61     AddToBranchList(Form("%s.fNumFirstLevel", input));
    62 
    63     AddToBranchList("MMcEvt.fEnergy");
    64     AddToBranchList("MMcEvt.fImpact");
    65 
    66     fCorsikaVersion           =  0;
    67     fAllEvtsTriggered         =  kFALSE;
    68     fTotalNumSimulatedShowers =  0;
    69     fThetaMin                 = -1.;
    70     fThetaMax                 = -1.;
    71 
    7262}
    7363
     64////////////////////////////////////////////////////////////////////////////////
     65//
     66// PreProcess.
     67// Create MHMcCollectionArea object if necessary.
     68// Search in parameter list for MBinning objects with binning in theta and E.
     69// These contain the coarse binning to be used in the analysis. Then search
     70// for other necessary input containers:
     71// if MMcEvt is found, it means we are in the loop over the Events tree,
     72// and so we must fill the histogram MHMcCollectionArea::fHistSel (using
     73// MHMcCollectionArea::FillSel). If MMcEvt is not found, it means that we are in
     74// the loop over the "OriginalMC" tree, containing all the original Corsika events
     75// produced, and hence we must fill the histogram  fHistAll through
     76// MHMcCollectionArea::FillAll.
     77//
    7478Int_t MMcCollectionAreaCalc::PreProcess (MParList *pList)
    7579{
    76     // connect the raw data with this task
     80  fCollArea = (MHMcCollectionArea*)pList->FindCreateObj("MHMcCollectionArea");
    7781
    78     fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
    79     if (!fMcEvt)
     82  // Look for the binnings of the histograms if they have not been already
     83  // found in a previous loop.
     84
     85  if (!fBinsTheta)
    8086    {
    81         *fLog << err << "MMcEvt not found... abort." << endl;
    82         return kFALSE;
     87      fBinsTheta = (MBinning*) pList->FindObject("binsTheta");
     88      if (!fBinsTheta)
     89        {
     90          *fLog << err << "Coarse Theta binning not found... Aborting."
     91            << endl;
     92          return kFALSE;
     93        }
     94    }
     95
     96  if (!fBinsEnergy)
     97    {
     98      fBinsEnergy = (MBinning*) pList->FindObject("binsEnergy");
     99      if (!fBinsEnergy)
     100        {
     101          *fLog << err << "Coarse Energy binning not found... Aborting."
     102                << endl;
     103          return kFALSE;
     104        }
     105    }
     106
     107  fCollArea->SetCoarseBinnings(*fBinsEnergy, *fBinsTheta);
     108
     109
     110  // Look for the input containers
     111
     112  fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
     113  if (fMcEvt)
     114    {
     115        *fLog << inf << "MMcEvt found... I will fill MHMcCollectionArea.fHistSel..." << endl;
     116        return kTRUE;
     117    }
     118
     119  *fLog << inf << "MMcEvt not found... looking for MMcEvtBasic..." << endl;
     120
     121
     122  fMcEvtBasic = (MMcEvtBasic*) pList->FindObject("MMcEvtBasic");
     123   
     124  if (fMcEvtBasic)
     125    {
     126      *fLog << inf << "MMcEvtBasic found... I will fill MHMcCollectionArea.fHistAll..." << endl;
     127      return kTRUE;
     128    }
     129
     130  *fLog << err << "MMcEvtBasic not found. Aborting..." << endl;
     131
     132  return kFALSE;
     133}
     134
     135////////////////////////////////////////////////////////////////////////////////
     136//
     137// Process. Depending on whether fMcEvt or fMcEvtBasic are available, fill
     138// MHMcCollectionArea::fHistAll, else, if fMcEvt is available, fill
     139// MHMcCollectionArea::fHistSel
     140//
     141Int_t MMcCollectionAreaCalc::Process()
     142{
     143    Double_t energy = fMcEvt? fMcEvt->GetEnergy() : fMcEvtBasic->GetEnergy();
     144    Double_t impact = fMcEvt? fMcEvt->GetImpact()/100. : fMcEvtBasic->GetImpact()/100.; // in m
     145    Double_t theta  = fMcEvt? fMcEvt->GetTelescopeTheta()*TMath::RadToDeg() :
     146      fMcEvtBasic->GetTelescopeTheta()*TMath::RadToDeg(); // in deg
     147
     148    if (fMcEvt)
     149      fCollArea->FillSel(energy, impact, theta);
     150    else
     151      fCollArea->FillAll(energy, impact, theta);
     152
     153    return kTRUE;
     154}
     155
     156///////////////////////////////////////////////////////////////////////////////
     157//
     158// Postprocess. If both fHistAll and fHistSel are already filled, calculate
     159// effective areas. Else it means we still have to run one more loop.
     160//
     161Int_t MMcCollectionAreaCalc::PostProcess()
     162{
     163  if ( ((TH2D*)fCollArea->GetHistAll())->GetEntries() > 0 &&
     164       ((TH2D*)fCollArea->GetHistSel())->GetEntries() > 0)
     165    {
     166      *fLog << inf << "Calculation Collection Area..." << endl;
     167      fCollArea->Calc(fSpectrum);
    83168    }
    84169
    85170    return kTRUE;
    86171}
    87 
    88 Bool_t MMcCollectionAreaCalc::ReInit(MParList *plist)
    89 {
    90     fCollArea=0;
    91 
    92     MMcRunHeader *runheader = (MMcRunHeader*)plist->FindObject("MMcRunHeader");
    93     if (!runheader)
    94     {
    95         *fLog << err << "Error - MMcRunHeader not found... abort." << endl;
    96         return kFALSE;
    97     }
    98 
    99     fTotalNumSimulatedShowers += runheader->GetNumSimulatedShowers();
    100     *fLog << inf << "Total Number of Simulated showers: " << fTotalNumSimulatedShowers << endl;
    101 
    102 
    103     if ( (fThetaMin >= 0 && fThetaMin != runheader->GetShowerThetaMin()) ||
    104          (fThetaMax >= 0 && fThetaMax != runheader->GetShowerThetaMax()) )
    105     {
    106         *fLog << warn << "Warning - Read files have different Theta ranges (";
    107         *fLog << "(" << fThetaMin << ", " << fThetaMax << ")   vs   (" <<
    108           runheader->GetShowerThetaMin() << ", " <<
    109           runheader->GetShowerThetaMax() << ")..." << endl;
    110     }
    111     fThetaMin = runheader->GetShowerThetaMin();
    112     fThetaMax = runheader->GetShowerThetaMax();
    113 
    114 
    115     if (fCorsikaVersion!=0 && fCorsikaVersion!=runheader->GetCorsikaVersion())
    116         *fLog << warn << "Warning - Read files have different Corsika versions..." << endl;
    117     fCorsikaVersion = runheader->GetCorsikaVersion();
    118 
    119 
    120     fAllEvtsTriggered |= runheader->GetAllEvtsTriggered();
    121     *fLog << inf << "Only triggered events avail: " << (fAllEvtsTriggered?"yes":"no") << endl;
    122 
    123 
    124     fCollArea = (MHMcCollectionArea*)plist->FindCreateObj("MHMcCollectionArea");
    125     if (!fCollArea)
    126         return kFALSE;
    127 
    128     if (!fAllEvtsTriggered)
    129     {
    130         fMcTrig = (MMcTrig*)plist->FindObject(fObjName);
    131         if (!fMcTrig)
    132         {
    133             *fLog << err << fObjName << " [MMcTrig] not found... anort." << endl;
    134             return kFALSE;
    135         }
    136         return kTRUE;
    137     }
    138 
    139     MMcCorsikaRunHeader *corrunheader  = (MMcCorsikaRunHeader*)plist->FindObject("MMcCorsikaRunHeader");
    140     if (!corrunheader)
    141     {
    142         *fLog << err << "MMcCorsikaRunHeader not found... abort." << endl;
    143         return kFALSE;
    144     }
    145 
    146     //
    147     // Calculate approximately the original number of events in each
    148     // energy bin:
    149     //
    150 
    151     const Float_t emin = corrunheader->GetELowLim();
    152     const Float_t emax = corrunheader->GetEUppLim();
    153     const Float_t expo = 1 + corrunheader->GetSlopeSpec();
    154     const Float_t k = runheader->GetNumSimulatedShowers() /
    155         (pow(emax,expo) - pow(emin,expo)) ;
    156 
    157     TH2 &hall = *fCollArea->GetHistAll();
    158 
    159     const Int_t nbinx = hall.GetNbinsX();
    160 
    161     TAxis &axe = *hall.GetXaxis();
    162     for (Int_t i = 1; i <= nbinx; i++)
    163     {
    164         const Float_t e1 = axe.GetBinLowEdge(i);
    165         const Float_t e2 = axe.GetBinLowEdge(i+1);
    166 
    167         if (e1 < emin || e2 > emax)
    168             continue;
    169 
    170         const Float_t events = k * (pow(e2, expo) - pow(e1, expo));
    171         //
    172         // We fill the i-th energy bin, with the total number of events
    173         // Second argument of Fill would be impact parameter of each
    174         // event, but we don't really need it for the collection area,
    175         // so we just put a dummy value (1.)
    176         //
    177 
    178         const Float_t energy = (e1+e2)/2.;
    179         hall.Fill(energy, 1., events);
    180     }
    181 
    182     return kTRUE;
    183 }
    184 
    185 Int_t MMcCollectionAreaCalc::Process()
    186 {
    187     const Double_t energy = fMcEvt->GetEnergy();
    188     const Double_t impact = fMcEvt->GetImpact()/100.;
    189 
    190     //
    191     // This happens for camera files created with Camera 0.5
    192     //
    193     if (TMath::IsNaN(impact))
    194     {
    195         *fLog << err << dbginf << "ERROR - Impact=NaN (Not a number)... abort." << endl;
    196         return kERROR;
    197     }
    198 
    199     if (!fAllEvtsTriggered)
    200     {
    201         fCollArea->FillAll(energy, impact);
    202 
    203         if (fMcTrig->GetFirstLevel() <= 0)
    204             return kTRUE;
    205     }
    206 
    207     fCollArea->FillSel(energy, impact);
    208 
    209     return kTRUE;
    210 }
    211 
    212 Int_t MMcCollectionAreaCalc::PostProcess()
    213 {
    214     if (!fCollArea)
    215         return kTRUE;
    216 
    217     //
    218     //   do the calculation of the effectiv area
    219     //
    220     *fLog << inf << "Calculation Collection Area..." << endl;
    221 
    222     if (!fAllEvtsTriggered)
    223         fCollArea->CalcEfficiency();
    224     else
    225     {
    226         *fLog << inf << "Total number of showers: " << fTotalNumSimulatedShowers << endl;
    227         fCollArea->CalcEfficiency2();
    228     }
    229 
    230     return kTRUE;
    231 }
    232 
Note: See TracChangeset for help on using the changeset viewer.