| 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 (jlopez@ifae.es)
|
|---|
| 19 | ! Thomas Bretz 06/2001 (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 | MMcThresholdCalc::MMcThresholdCalc(const UInt_t dim, const char* name,
|
|---|
| 61 | const char* title) : fDimension(dim)
|
|---|
| 62 | {
|
|---|
| 63 | *fName = name ? name : "MMcThresholdCalc";
|
|---|
| 64 | *fTitle = title ? title : "Task to calculate the energy threshold from Monte Carlo";
|
|---|
| 65 |
|
|---|
| 66 | // Arrays of MMcTrig* and MHMcEnergy* are created in order to be
|
|---|
| 67 | // able to work with root files with several trigger conditions.
|
|---|
| 68 | fMcTrig = new MMcTrig*[fDimension];
|
|---|
| 69 | fHMcEnergy = new MHMcEnergy*[fDimension];
|
|---|
| 70 | fMustDelete = new Bool_t[fDimension];
|
|---|
| 71 |
|
|---|
| 72 | for (unsigned int i=0; i<fDimension; i++)
|
|---|
| 73 | fMustDelete[i]=kFALSE;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | // -------------------------------------------------------------------------
|
|---|
| 77 | //
|
|---|
| 78 | // Default Destructor.
|
|---|
| 79 | //
|
|---|
| 80 | MMcThresholdCalc::~MMcThresholdCalc()
|
|---|
| 81 | {
|
|---|
| 82 | for (unsigned int i=0; i<fDimension; i++)
|
|---|
| 83 | if (fMustDelete[i])
|
|---|
| 84 | delete fHMcEnergy[i];
|
|---|
| 85 |
|
|---|
| 86 | delete fMcTrig;
|
|---|
| 87 | delete fHMcEnergy;
|
|---|
| 88 | delete fMustDelete;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | // --------------------------------------------------------------------------
|
|---|
| 92 | //
|
|---|
| 93 | // connect Monte Carlo data with this task
|
|---|
| 94 | //
|
|---|
| 95 | Bool_t MMcThresholdCalc::PreProcess(MParList* pList)
|
|---|
| 96 | {
|
|---|
| 97 | // This task takes into accout if the root file has one trigger
|
|---|
| 98 | // condition (MMcTrig) or severl of them (MMcTrig;#.)
|
|---|
| 99 |
|
|---|
| 100 | fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
|
|---|
| 101 | if (!fMcEvt)
|
|---|
| 102 | {
|
|---|
| 103 | *fLog << dbginf << "MMcEvt not found... aborting." << endl;
|
|---|
| 104 | return kFALSE;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | char auxname[15]="MMcTrig"; // string to write container names
|
|---|
| 108 |
|
|---|
| 109 | for (unsigned int i=0; i<fDimension; i++)
|
|---|
| 110 | {
|
|---|
| 111 | if (fDimension>1)
|
|---|
| 112 | sprintf(auxname+7, ";%i", i+1);
|
|---|
| 113 |
|
|---|
| 114 | fMcTrig[i] = (MMcTrig*)pList->FindObject(auxname);
|
|---|
| 115 | if (fMcTrig[i])
|
|---|
| 116 | continue;
|
|---|
| 117 |
|
|---|
| 118 | *fLog << dbginf << "'MMcTrig";
|
|---|
| 119 | if (fDimension>1)
|
|---|
| 120 | *fLog << ";" << i+1;
|
|---|
| 121 | *fLog << "' not found... aborting." << endl;
|
|---|
| 122 |
|
|---|
| 123 | return kFALSE;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | strcpy(auxname, "MHMcEnergy");
|
|---|
| 127 | for (unsigned int i=0; i<fDimension; i++)
|
|---|
| 128 | {
|
|---|
| 129 | if (fDimension>1&&i!=0)
|
|---|
| 130 | sprintf(auxname+10, ";%i", i);
|
|---|
| 131 |
|
|---|
| 132 | fHMcEnergy[i] = (MHMcEnergy*)pList->FindObject(auxname);
|
|---|
| 133 | if (fHMcEnergy[i])
|
|---|
| 134 | continue;
|
|---|
| 135 |
|
|---|
| 136 | *fLog << dbginf << "'" << auxname << "' not found in list... creating." << endl;
|
|---|
| 137 |
|
|---|
| 138 | fHMcEnergy[i] = new MHMcEnergy(fDimension>1&&i!=0 ? i : 0);
|
|---|
| 139 | fMustDelete[i] = kTRUE;
|
|---|
| 140 | pList->AddToList(fHMcEnergy[i]);
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | return kTRUE;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | // --------------------------------------------------------------------------
|
|---|
| 147 | //
|
|---|
| 148 | // The histograms are filled with log10 of the energy for triggered
|
|---|
| 149 | // events and weighted with 1/E because it is needed the dN/dE vs. logE
|
|---|
| 150 | // distribution to get the energy threshold.
|
|---|
| 151 | //
|
|---|
| 152 | Bool_t MMcThresholdCalc::Process()
|
|---|
| 153 | {
|
|---|
| 154 | const Float_t energy = fMcEvt->GetEnergy();
|
|---|
| 155 | const Float_t lg10 = log10(energy);
|
|---|
| 156 | const Float_t reciproc = 1./energy;
|
|---|
| 157 |
|
|---|
| 158 | for (unsigned int i=0; i<fDimension; i++)
|
|---|
| 159 | if (fMcTrig[i]->GetFirstLevel()>0)
|
|---|
| 160 | fHMcEnergy[i]->Fill(lg10, reciproc);
|
|---|
| 161 |
|
|---|
| 162 | return kTRUE;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | // --------------------------------------------------------------------------
|
|---|
| 166 | //
|
|---|
| 167 | // fit the energy distribution to get the threshold
|
|---|
| 168 | // Some iterations are done to be sure the fit parameters converge.
|
|---|
| 169 | //
|
|---|
| 170 | Bool_t MMcThresholdCalc::PostProcess()
|
|---|
| 171 | {
|
|---|
| 172 | for (unsigned int i=0; i<fDimension; i++)
|
|---|
| 173 | {
|
|---|
| 174 | Float_t peak;
|
|---|
| 175 | Float_t sigma;
|
|---|
| 176 |
|
|---|
| 177 | fHMcEnergy[i]->Fit(1, 3);
|
|---|
| 178 |
|
|---|
| 179 | peak = fHMcEnergy[i]->GetGaussPeak();
|
|---|
| 180 | sigma = fHMcEnergy[i]->GetGaussSigma();
|
|---|
| 181 | fHMcEnergy[i]->Fit(peak - 2. *sigma, peak + 2. *sigma);
|
|---|
| 182 |
|
|---|
| 183 | peak = fHMcEnergy[i]->GetGaussPeak();
|
|---|
| 184 | sigma = fHMcEnergy[i]->GetGaussSigma();
|
|---|
| 185 | fHMcEnergy[i]->Fit(peak - fSqrt2*sigma, peak + fSqrt2*sigma);
|
|---|
| 186 | }
|
|---|
| 187 | return kTRUE;
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|