source: trunk/MagicSoft/Mars/mfilter/MFEnergySlope.cc@ 7574

Last change on this file since 7574 was 7409, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 7.2 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): Antonio Stamerra 02/2003 <mailto:antonio.stamerra@pi.infn.it>
19!
20! Copyright: MAGIC Software Development, 2000-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MFEnergySlope //
28// //
29// A filter to select MC events (generated with a energy slope MCSlope) //
30// with a different energy slope NewSlope set by the user. //
31// //
32// The new slope is set by the user with SetSlope(). //
33// Only negative slopes are admitted; positive ones are internally //
34// converted. //
35// Events are selected following the new energy power slope, and the //
36// sample is normalized to the number of events at: //
37// 1. McMaxEnergy, if abs(NewSlope) < abs(McSlope); //
38// 2. McMinEnergy, if abs(NewSlope) > abs(McSlope); //
39// Mc{Max,Min}Energy are set with SetMcMinEnergy() and SetMcMaxEnergy(); //
40// with GeV values. //
41// Default values are the min/max energy of the MC sample. //
42// //
43// With this filter the statistics of the MC sample is reduced. //
44// camera ver.0.6 and reflector ver.0.6 are required to fetch //
45// the correct MC information //
46// //
47/////////////////////////////////////////////////////////////////////////////
48#include "MFEnergySlope.h"
49
50#include <fstream>
51#include <TRandom.h>
52
53#include "MParList.h"
54
55#include "MLog.h"
56#include "MLogManip.h"
57
58#include "MMcEvt.hxx"
59#include "MMcCorsikaRunHeader.h"
60
61ClassImp(MFEnergySlope);
62
63using namespace std;
64
65// --------------------------------------------------------------------------
66//
67// Default Constructor
68//
69MFEnergySlope::MFEnergySlope(const char *name, const char *title):
70 fNewSlope(-1), fMcMinEnergy(-1.), fMcMaxEnergy(-1.)
71{
72 fName = name ? name : "MFEnergySlope";
73 fTitle = title ? title : "Filter to select energy with given slope";
74}
75
76// --------------------------------------------------------------------------
77//
78// Constructor
79//
80MFEnergySlope::MFEnergySlope(Float_t slope, const char *name, const char *title):
81 fNewSlope(TMath::Abs(slope)), fMcMinEnergy(-1.), fMcMaxEnergy(-1.)
82{
83 fName = name ? name : "MFEnergySlope";
84 fTitle = title ? title : "Filter to select energy with given slope";
85}
86
87// --------------------------------------------------------------------------
88//
89// Preprocess
90//
91// MC slope and min/max energy are read
92// Normalization factor is computed
93//
94Int_t MFEnergySlope::PreProcess(MParList *pList)
95{
96 if (fNewSlope<0)
97 {
98 *fLog << err << "New slope still undefined... aborting." << endl;
99 return kFALSE;
100 }
101
102 fEvt = (MMcEvt*)pList->FindObject("MMcEvt");
103 if (!fEvt)
104 {
105 *fLog << err << "MMcEvt not found... aborting." << endl;
106 return kFALSE;
107 }
108
109 return kTRUE;
110}
111
112// --------------------------------------------------------------------------
113//
114// Preprocess
115//
116// MC slope and min/max energy are read
117// Normalization factor is computed
118//
119Bool_t MFEnergySlope::ReInit(MParList *pList)
120{
121 MMcCorsikaRunHeader *runheader = (MMcCorsikaRunHeader*)pList->FindObject("MMcCorsikaRunHeader");
122 if (!runheader)
123 {
124 *fLog << err << "MMcCorsikaRunHeader not found... aborting." << endl;
125 return kFALSE;
126 }
127
128 //
129 // Read info from the MC sample (it must be generated with
130 // reflector ver.0.6 and camera ver. 0.6)
131 //
132 fMcSlope = runheader->GetSlopeSpec();
133 if (fMcMinEnergy<0)
134 fMcMinEnergy = runheader->GetELowLim();
135 if (fMcMinEnergy<0)
136 fMcMaxEnergy = runheader->GetEUppLim();
137
138 // Slope is used with positive values in the code
139 if (fNewSlope < 0)
140 fNewSlope *= -1;
141 if (fMcSlope < 0)
142 fMcSlope *= -1;
143
144 // Calculate normalization factor
145 fN0 = TMath::Power(fNewSlope>fMcSlope ? fMcMinEnergy : fMcMaxEnergy, fNewSlope-fMcSlope);
146
147 // Print some infos
148 *fLog << inf;
149 *fLog << "Fetched MC info:" << endl;
150 *fLog << " Change E Slope " << fMcSlope << " (" << fMcMinEnergy << " < E < ";
151 *fLog << fMcMaxEnergy << ") to " << fNewSlope << endl;
152 *fLog << " Norm factor: " << fN0 << endl;
153
154 return kTRUE;
155}
156
157// --------------------------------------------------------------------------
158//
159// Select events randomly according to the MC ("old") and required ("new")
160// energy slope.
161// Old E slope is fMcSlope
162// New E slope is set by the user (fval; fNewSlope)
163// If old and new energy slope are the same skip the selection.
164// The MC energy slope and lower and upper limits are taken from the
165// run header (requires reflector ver.>0.6 and camera ver.>0.6)
166//
167Int_t MFEnergySlope::Process()
168{
169 fResult = kTRUE;
170
171 // Energy slopes are the same: skip it
172 if (fNewSlope == fMcSlope)
173 return kTRUE;
174
175 // The value of the normalized spectrum is compared with a
176 // random value in [0,1];
177 // if the latter is higher the event is accepted
178 const Float_t energy = fEvt->GetEnergy();
179
180 /*
181 //
182 // If energy bounds different from MC ones are selected, then
183 // events outside these bounds are rejected, as their slope has
184 // not been changed.
185 //
186 if (energy > fMcMaxEnergy || energy < fMcMinEnergy)
187 {
188 fResult = kFALSE;
189 return kTRUE;
190 }
191 */
192
193 const Float_t Nexp = fN0 * pow(energy,fMcSlope-fNewSlope);
194 const Float_t Nrnd = gRandom->Uniform();
195
196 fResult = Nexp > Nrnd;
197
198 //if (fResult)
199 // fNumSelectedEvts++;
200
201 return kTRUE;
202}
203
204
205// --------------------------------------------------------------------------
206//
207// MFEnergySlope.NewSlope: -2.8
208//
209Int_t MFEnergySlope::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
210{
211 Bool_t rc = kFALSE;
212 if (IsEnvDefined(env, prefix, "NewSlope", print))
213 {
214 rc = kTRUE;
215 SetNewSlope(GetEnvValue(env, prefix, "NewSlope", fNewSlope));
216 }
217 return rc;
218}
Note: See TracBrowser for help on using the repository browser.