source: trunk/MagicSoft/Mars/mmontecarlo/MMcThresholdCalc.cc@ 1005

Last change on this file since 1005 was 1004, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 5.0 KB
Line 
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
52ClassImp(MMcThresholdCalc);
53
54const 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//
67MMcThresholdCalc::MMcThresholdCalc(const Int_t dim, const char* name,
68 const char* title)
69 : fDimension(dim), 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
75// -------------------------------------------------------------------------
76//
77// Destructor.
78//
79MMcThresholdCalc::~MMcThresholdCalc()
80{
81 if (fMcTrig)
82 delete fMcTrig;
83
84 if (fEnergy)
85 delete fEnergy;
86}
87
88// --------------------------------------------------------------------------
89//
90// connect Monte Carlo data with this task
91//
92Bool_t MMcThresholdCalc::PreProcess(MParList* pList)
93{
94 //
95 // This task takes into accout if the root file has one trigger
96 // condition (MMcTrig) or severl of them (MMcTrig;#.)
97
98 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
99 if (!fMcEvt)
100 {
101 *fLog << dbginf << "MMcEvt not found... aborting." << endl;
102 return kFALSE;
103 }
104
105 UInt_t from = fDimension>0 ? 1 : -fDimension;
106 UInt_t to = fDimension>0 ? fDimension : -fDimension;
107
108 fNum = to-from+1;
109
110 Int_t num;
111
112 fMcTrig = new TObjArray(pList->FindObjectList("MMcTrig", from, to));
113 num = fMcTrig->GetEntriesFast();
114 if (num != fNum)
115 {
116 *fLog << dbginf << fNum << " MMcTrig objects requested, ";
117 *fLog << num << " are available... aborting." << endl;
118 return kFALSE;
119 }
120
121 fEnergy = new TObjArray(pList->FindCreateObjList("MHMcEnergy", from, to));
122 num = fMcTrig->GetEntriesFast();
123 if (num != fNum)
124 {
125 *fLog << dbginf << fNum << " MHMcEnergy objects requested, ";
126 *fLog << num << " are available... aborting." << endl;
127 return kFALSE;
128 }
129
130 return kTRUE;
131}
132
133// --------------------------------------------------------------------------
134//
135// The histograms are filled with log10 of the energy for triggered
136// events and weighted with 1/E because it is needed the dN/dE vs. logE
137// distribution to get the energy threshold.
138//
139Bool_t MMcThresholdCalc::Process()
140{
141 const Float_t energy = fMcEvt->GetEnergy();
142 const Float_t lg10 = log10(energy);
143 const Float_t reciproc = 1./energy;
144
145 for (Int_t i=0; i<fNum; i++)
146 if (GetTrig(i)->GetFirstLevel()>0)
147 GetHEnergy(i)->Fill(lg10, reciproc);
148
149 return kTRUE;
150}
151
152// --------------------------------------------------------------------------
153//
154// fit the energy distribution to get the threshold
155// Some iterations are done to be sure the fit parameters converge.
156//
157Bool_t MMcThresholdCalc::PostProcess()
158{
159 for (Int_t i=0; i<fNum; i++)
160 {
161 MHMcEnergy &hist = *GetHEnergy(i);
162
163 Float_t peak;
164 Float_t sigma;
165
166 hist.Fit(1, 3);
167
168 peak = hist.GetGaussPeak();
169 sigma = hist.GetGaussSigma();
170 hist.Fit(peak - 2. *sigma, peak + 2. *sigma);
171
172 peak = hist.GetGaussPeak();
173 sigma = hist.GetGaussSigma();
174 hist.Fit(peak - fSqrt2*sigma, peak + fSqrt2*sigma);
175 }
176 return kTRUE;
177}
178
Note: See TracBrowser for help on using the repository browser.