| 1 | /* ======================================================================== *\
|
|---|
| 2 | !
|
|---|
| 3 | ! *
|
|---|
| 4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 8 | ! *
|
|---|
| 9 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 10 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 11 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 12 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 13 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 14 | ! * or implied warranty.
|
|---|
| 15 | ! *
|
|---|
| 16 | !
|
|---|
| 17 | !
|
|---|
| 18 | ! Author(s): Javier Lopez 05/2001 <mailto:jlopez@ifae.es>
|
|---|
| 19 | ! Author(s): Thomas Bretz 06/2001 <mailto:tbretz@uni-sw.gwdg.de>
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2001
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | ///////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | //
|
|---|
| 28 | // MMcThresholdCalc
|
|---|
| 29 | //
|
|---|
| 30 | // Input Containers:
|
|---|
| 31 | // MMcEvt, MMcTrig;*
|
|---|
| 32 | //
|
|---|
| 33 | // Output Containers:
|
|---|
| 34 | // MHMcEnergies
|
|---|
| 35 | //
|
|---|
| 36 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 37 |
|
|---|
| 38 | #include "MMcThresholdCalc.h"
|
|---|
| 39 |
|
|---|
| 40 | #include <math.h>
|
|---|
| 41 |
|
|---|
| 42 | #include "MParList.h"
|
|---|
| 43 |
|
|---|
| 44 | #include "MLog.h"
|
|---|
| 45 | #include "MLogManip.h"
|
|---|
| 46 |
|
|---|
| 47 | #include "MMcEvt.hxx"
|
|---|
| 48 | #include "MMcTrig.hxx"
|
|---|
| 49 |
|
|---|
| 50 | #include "MHMcEnergy.h"
|
|---|
| 51 |
|
|---|
| 52 | ClassImp(MMcThresholdCalc);
|
|---|
| 53 |
|
|---|
| 54 | const Float_t MMcThresholdCalc::fSqrt2 = sqrt(2);
|
|---|
| 55 |
|
|---|
| 56 | // --------------------------------------------------------------------------
|
|---|
| 57 | //
|
|---|
| 58 | // Default Constructor.
|
|---|
| 59 | //
|
|---|
| 60 | // Specify the number of trigger conditions you want to use.
|
|---|
| 61 | // The default is 0.
|
|---|
| 62 | //
|
|---|
| 63 | // dim < 0: use only condition number dim (eg "MMcTrig;3")
|
|---|
| 64 | // dim = 0: use only condition without a number ("MMcTrig")
|
|---|
| 65 | // dim > 0: use conditions up to dim (from "MMcTrig;1" to "MMcTrig;dim")
|
|---|
| 66 | //
|
|---|
| 67 | MMcThresholdCalc::MMcThresholdCalc(const Int_t dim, const char* name,
|
|---|
| 68 | const char* title)
|
|---|
| 69 | : fMcTrig(NULL), fEnergy(NULL)
|
|---|
| 70 | {
|
|---|
| 71 | fName = name ? name : "MMcThresholdCalc";
|
|---|
| 72 | fTitle = title ? title : "Task to calculate the energy threshold from Monte Carlo";
|
|---|
| 73 |
|
|---|
| 74 | fFirst = dim>0 ? 1 : -dim;
|
|---|
| 75 | fLast = dim>0 ? dim : -dim;
|
|---|
| 76 |
|
|---|
| 77 | fNum = fLast-fFirst+1;
|
|---|
| 78 |
|
|---|
| 79 | AddToBranchList("MMcEvt.fEnergy");
|
|---|
| 80 | AddToBranchList("MMcTrig", "fNumFirstLevel", fFirst, fLast);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | // -------------------------------------------------------------------------
|
|---|
| 84 | //
|
|---|
| 85 | // Destructor.
|
|---|
| 86 | //
|
|---|
| 87 | MMcThresholdCalc::~MMcThresholdCalc()
|
|---|
| 88 | {
|
|---|
| 89 | if (fMcTrig)
|
|---|
| 90 | delete fMcTrig;
|
|---|
| 91 |
|
|---|
| 92 | if (fEnergy)
|
|---|
| 93 | delete fEnergy;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | // --------------------------------------------------------------------------
|
|---|
| 97 | //
|
|---|
| 98 | // connect Monte Carlo data with this task
|
|---|
| 99 | //
|
|---|
| 100 | Bool_t MMcThresholdCalc::PreProcess(MParList* pList)
|
|---|
| 101 | {
|
|---|
| 102 | //
|
|---|
| 103 | // This task takes into accout if the root file has one trigger
|
|---|
| 104 | // condition (MMcTrig) or severl of them (MMcTrig;#.)
|
|---|
| 105 |
|
|---|
| 106 | fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
|
|---|
| 107 | if (!fMcEvt)
|
|---|
| 108 | {
|
|---|
| 109 | *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
|
|---|
| 110 | return kFALSE;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | UInt_t num;
|
|---|
| 114 |
|
|---|
| 115 | fMcTrig = new TObjArray(pList->FindObjectList("MMcTrig", fFirst, fLast));
|
|---|
| 116 | num = fMcTrig->GetEntriesFast();
|
|---|
| 117 | if (num != fNum)
|
|---|
| 118 | {
|
|---|
| 119 | *fLog << err << dbginf << fNum << " MMcTrig objects requested, ";
|
|---|
| 120 | *fLog << num << " are available... aborting." << endl;
|
|---|
| 121 | return kFALSE;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | fEnergy = new TObjArray(pList->FindCreateObjList("MHMcEnergy", fFirst, fLast));
|
|---|
| 125 | num = fMcTrig->GetEntriesFast();
|
|---|
| 126 | if (num != fNum)
|
|---|
| 127 | {
|
|---|
| 128 | *fLog << err << dbginf << fNum << " MHMcEnergy objects requested, ";
|
|---|
| 129 | *fLog << num << " are available... aborting." << endl;
|
|---|
| 130 | return kFALSE;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | return kTRUE;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | // --------------------------------------------------------------------------
|
|---|
| 137 | //
|
|---|
| 138 | // The histograms are filled with log10 of the energy for triggered
|
|---|
| 139 | // events and weighted with 1/E because it is needed the dN/dE vs. logE
|
|---|
| 140 | // distribution to get the energy threshold.
|
|---|
| 141 | //
|
|---|
| 142 | Bool_t MMcThresholdCalc::Process()
|
|---|
| 143 | {
|
|---|
| 144 | const Float_t energy = fMcEvt->GetEnergy();
|
|---|
| 145 | const Float_t lg10 = log10(energy);
|
|---|
| 146 | const Float_t reciproc = 1./energy;
|
|---|
| 147 |
|
|---|
| 148 | for (UInt_t i=0; i<fNum; i++)
|
|---|
| 149 | if (GetTrig(i)->GetFirstLevel()>0)
|
|---|
| 150 | GetHEnergy(i)->Fill(lg10, reciproc);
|
|---|
| 151 |
|
|---|
| 152 | return kTRUE;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | // --------------------------------------------------------------------------
|
|---|
| 156 | //
|
|---|
| 157 | // fit the energy distribution to get the threshold
|
|---|
| 158 | // Some iterations are done to be sure the fit parameters converge.
|
|---|
| 159 | //
|
|---|
| 160 | Bool_t MMcThresholdCalc::PostProcess()
|
|---|
| 161 | {
|
|---|
| 162 | for (UInt_t i=0; i<fNum; i++)
|
|---|
| 163 | {
|
|---|
| 164 | MHMcEnergy &hist = *GetHEnergy(i);
|
|---|
| 165 |
|
|---|
| 166 | Float_t peak;
|
|---|
| 167 | Float_t sigma;
|
|---|
| 168 |
|
|---|
| 169 | hist.Fit(1, 3);
|
|---|
| 170 |
|
|---|
| 171 | peak = hist.GetGaussPeak();
|
|---|
| 172 | sigma = hist.GetGaussSigma();
|
|---|
| 173 | hist.Fit(peak - 2. *sigma, peak + 2. *sigma);
|
|---|
| 174 |
|
|---|
| 175 | peak = hist.GetGaussPeak();
|
|---|
| 176 | sigma = hist.GetGaussSigma();
|
|---|
| 177 | hist.Fit(peak - fSqrt2*sigma, peak + fSqrt2*sigma);
|
|---|
| 178 |
|
|---|
| 179 | hist.SetReadyToSave();
|
|---|
| 180 | }
|
|---|
| 181 | return kTRUE;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|