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

Last change on this file since 853 was 851, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 4.3 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/////////////////////////////////////////////////////////////////////////////
31
32#include "MMcThresholdCalc.h"
33
34#include <math.h>
35
36#include "MParList.h"
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MMcEvt.hxx"
42#include "MMcTrig.hxx"
43
44#include "MHMcEnergy.h"
45
46ClassImp(MMcThresholdCalc)
47
48MMcThresholdCalc::MMcThresholdCalc(const UInt_t dim, const char* name,
49 const char* title) : fDimension(dim)
50{
51 *fName = name ? name : "MMcThresholdCalc";
52 *fTitle = title ? title : "Task to calculate the energy threshold from Monte Carlo";
53
54 fMcTrig = new (MMcTrig*)[fDimension];
55 fHMcEnergy = new (MHMcEnergy*)[fDimension];
56 fMustDelete = new Bool_t[fDimension];
57
58 for (unsigned int i=0; i<fDimension; i++)
59 fMustDelete=kFALSE;
60}
61
62MMcThresholdCalc::~MMcThresholdCalc()
63{
64 for (unsigned int i=0; i<fDimension; i++)
65 if (fMustDelete[i])
66 delete fHMcEnergy[i];
67
68 delete fMcTrig;
69 delete fHMcEnergy;
70 delete fMustDelete;
71}
72
73Bool_t MMcThresholdCalc::PreProcess(MParList* pList)
74{
75 // connect Monte Carlo data with this task
76
77 char auxname[15]="MMcTrig"; // string to write container names
78
79 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
80 if (!fMcEvt)
81 {
82 *fLog << dbginf << "MMcEvt not found... aborting." << endl;
83 return kFALSE;
84 }
85
86 for (unsigned int i=0; i<fDimension; i++)
87 {
88 if (fDimension>1)
89 sprintf(auxname+7, ";%i", i+1);
90
91 fMcTrig[i] = (MMcTrig*)pList->FindObject(auxname);
92 if (fMcTrig[i])
93 continue;
94
95 *fLog << dbginf << "'MMcTrig";
96 if (fDimension>1)
97 *fLog << ";" << i+1;
98 *fLog << "' not found... aborting." << endl;
99
100 return kFALSE;
101 }
102
103 strcpy(auxname, "MHMcEnergy");
104 for (unsigned int i=0; i<fDimension; i++)
105 {
106 if (fDimension>1)
107 sprintf(auxname+10, ";%i", i+1);
108
109 fHMcEnergy[i] = (MHMcEnergy*)pList->FindObject(auxname);
110 if (fHMcEnergy[i])
111 continue;
112
113 *fLog << dbginf << "'" << auxname << "' not found in list... creating." << endl;
114
115 fHMcEnergy[i] = new MHMcEnergy(fDimension>1 ? i+1 : 0);
116 fMustDelete[i] = kTRUE;
117 pList->AddToList(fHMcEnergy[i]);
118 }
119
120 return kTRUE;
121}
122
123Bool_t MMcThresholdCalc::Process()
124{
125 const Float_t energy = fMcEvt->GetEnergy();
126 const Float_t lg10 = log10(energy);
127 const Float_t reciproc = 1./energy;
128
129 for (unsigned int i=0; i<fDimension; i++)
130 {
131 if (fMcTrig[i]->GetFirstLevel()<=0)
132 continue;
133
134 fHMcEnergy[i]->Fill(lg10, reciproc);
135 }
136
137 return kTRUE;
138}
139
140Bool_t MMcThresholdCalc::PostProcess()
141{
142 // fit the energy distribution to get the threshold
143
144 const Float_t sqrt2 = sqrt(2);
145
146 for (unsigned int i=0; i<fDimension; i++)
147 {
148 MHMcEnergy &h = *fHMcEnergy[i];
149
150 const Float_t peak = h.GetGaussPeak();
151 const Float_t sigma = h.GetGaussSigma();
152
153 h.Fit(1, 3);
154 h.Fit(peak - 2. *sigma, peak + 2. *sigma);
155 h.Fit(peak - sqrt2*sigma, peak + sqrt2*sigma);
156 }
157 return kTRUE;
158}
159
Note: See TracBrowser for help on using the repository browser.