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

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