source: trunk/MagicSoft/Mars/mmontecarlo/MMcEnerThreCalc.cc@ 842

Last change on this file since 842 was 838, checked in by jlopez, 23 years ago
Task to calculate the energy threshold
File size: 4.5 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!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MMcEnerThreCalc
28// //
29/////////////////////////////////////////////////////////////////////////////
30
31#include "MMcEnerThreCalc.h"
32
33#include "MParList.h"
34
35#include "MLog.h"
36#include "MLogManip.h"
37
38#include "MMcEvt.hxx"
39#include "MMcTrig.hxx"
40#include "MMcEnerThre.h"
41#include "MMcEnerHisto.h"
42
43#include <math.h>
44
45ClassImp(MMcEnerThreCalc)
46
47MMcEnerThreCalc::MMcEnerThreCalc (const int dim,
48 const char* name, const char* title)
49{
50 *fName = name ? name : "MMcEnerThreCalc";
51 *fTitle = title ? title : "Task to calculate the energy threshold from Monte Carlo";
52
53 fDimension = dim;
54
55 if (fDimension > 0)
56 fMMcTrig = new MMcTrig * [fDimension];
57 else
58 fMMcTrig = new MMcTrig * [1];
59}
60
61Bool_t MMcEnerThreCalc::PreProcess(MParList* pList)
62{
63 // connect Monte Carlo data with this task
64
65 char auxname[15]; // string to write container names
66
67 fMMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
68 if (!fMMcEvt)
69 {
70 *fLog << dbginf << "MMcEvt not found... aborting." << endl;
71 return kFALSE;
72 }
73
74 if (fDimension == 0)
75 {
76 fMMcTrig[0] = (MMcTrig*)pList->FindObject("MMcTrig");
77 if (!fMMcTrig[0])
78 {
79 *fLog << dbginf << "MMcTrig not found... aborting." << endl;
80 return kFALSE;
81 }
82 }
83 else
84 {
85 for (int i=0; i<fDimension; i++)
86 {
87 sprintf(auxname,"MMcTrig;%i.",i+1);
88 fMMcTrig[i] = (MMcTrig*)pList->FindObject(auxname);
89 if (!fMMcTrig[i])
90 {
91 *fLog << dbginf << "MMcTrig;" << i+1 << " not found... aborting." << endl;
92 return kFALSE;
93 }
94 }
95 }
96
97 fMMcEnerThre = (MMcEnerThre*)pList->FindObject("MMcEnerThre");
98 if (!fMMcEnerThre)
99 {
100 *fLog << dbginf << "MMcEnerThre not found... aborting." << endl;
101 return kFALSE;
102 }
103
104 return kTRUE;
105}
106
107Bool_t MMcEnerThreCalc::Process()
108{
109 const Float_t energy = fMMcEvt->GetEnergy();
110 if (fDimension <= 0)
111 {
112 Int_t trigger[1];
113 trigger[0] = fMMcTrig[0]->GetFirstLevel();
114 if (trigger[0]>0) (*fMMcEnerThre)[0]->Fill(log10(energy),1/energy);
115 }
116 else
117 {
118 Int_t *trigger;
119 trigger=new Int_t [fDimension];
120
121 for (int i=0; i<fDimension; i++)
122 {
123 trigger[i] = fMMcTrig[i]->GetFirstLevel() ;
124 if (trigger[i]>0) (*fMMcEnerThre)[i]->Fill(log10(energy),1/energy);
125 }
126 }
127 return kTRUE;
128}
129
130Bool_t MMcEnerThreCalc::PostProcess()
131{
132 // fit the energy distribution to get the threshold
133
134 char auxname[15];
135
136 if (fDimension <= 0)
137 {
138 (*fMMcEnerThre)[0]->Fit("fLogEner0","RQ","",1.,3.);
139 (*fMMcEnerThre)[0]->Fit("fLogEner0","RQ","",(*fMMcEnerThre)[0]->GetPeakAtLogE()-2*(*fMMcEnerThre)[0]->GetSigmaAtLogE(),(*fMMcEnerThre)[0]->GetPeakAtLogE()+2*(*fMMcEnerThre)[0]->GetSigmaAtLogE());
140 (*fMMcEnerThre)[0]->Fit("fLogEner0","RQ","",(*fMMcEnerThre)[0]->GetPeakAtLogE()-sqrt(2)*(*fMMcEnerThre)[0]->GetSigmaAtLogE(),(*fMMcEnerThre)[0]->GetPeakAtLogE()+sqrt(2)*(*fMMcEnerThre)[0]->GetSigmaAtLogE());
141
142 }
143 else
144 {
145 for (int i=0; i<fDimension; i++)
146 {
147 sprintf (auxname,"fLogEner%i",i);
148
149 (*fMMcEnerThre)[i]->Fit(auxname,"RQ","",1.,3.);
150 (*fMMcEnerThre)[i]->Fit(auxname,"RQ","",(*fMMcEnerThre)[i]->GetPeakAtLogE()-2*(*fMMcEnerThre)[i]->GetSigmaAtLogE(),(*fMMcEnerThre)[i]->GetPeakAtLogE()+2*(*fMMcEnerThre)[i]->GetSigmaAtLogE());
151 (*fMMcEnerThre)[i]->Fit(auxname,"RQ","",(*fMMcEnerThre)[i]->GetPeakAtLogE()-sqrt(2)*(*fMMcEnerThre)[i]->GetSigmaAtLogE(),(*fMMcEnerThre)[i]->GetPeakAtLogE()+sqrt(2)*(*fMMcEnerThre)[i]->GetSigmaAtLogE());
152 }
153 }
154 return kTRUE;
155}
156
157
158
159
Note: See TracBrowser for help on using the repository browser.