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

Last change on this file since 3414 was 2206, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.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-2003
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// Constructor
68//
69MFEnergySlope::MFEnergySlope(const char *name, const char *title):
70 fNumSelectedEvts(0), fNewSlope(-1), fMcMinEnergy(-1.), fMcMaxEnergy(-1.)
71{
72 // fContName = cname;
73 fName = name ? name : "MFEnergySlope";
74 fTitle = title ? title : "Filter to select energy with given slope";
75}
76
77// --------------------------------------------------------------------------
78//
79// Preprocess
80//
81// MC slope and min/max energy are read
82// Normalization factor is computed
83//
84Int_t MFEnergySlope::PreProcess(MParList *pList)
85{
86
87 MMcCorsikaRunHeader *runheader = (MMcCorsikaRunHeader*)pList->FindObject("MMcCorsikaRunHeader");
88
89 if (!runheader)
90 {
91 *fLog << err << dbginf << fName << " [MMcCorsikaRunHeader] not found... aborting." << endl;
92 return kFALSE;
93 }
94 //
95 // Read info from the MC sample (it must be generated with
96 // reflector ver.0.6 and camera ver. 0.6)
97 //
98 fMcSlope = runheader->GetSlopeSpec();
99 if (fMcMinEnergy<0)
100 fMcMinEnergy = runheader->GetELowLim();
101 if (fMcMinEnergy<0)
102 fMcMaxEnergy = runheader->GetEUppLim();
103
104 *fLog << inf;
105 *fLog << "MFEnergySlope::PreProcess: fetched MC info:" << endl;
106 *fLog << " E Slope: " << fMcSlope << endl;
107 *fLog << " E Min: " << fMcMinEnergy << endl;
108 *fLog << " E Max: " << fMcMaxEnergy << endl;
109 *fLog << " New E Slope: " << fNewSlope << endl;
110
111 // Slope is used with positive values in the code
112 if (fNewSlope < 0)
113 fNewSlope *= -1;
114 if (fMcSlope < 0)
115 fMcSlope *= -1;
116
117
118 // Set normalization on energy
119 fN0 = pow(fNewSlope>fMcSlope?fMcMinEnergy:fMcMaxEnergy,fNewSlope-fMcSlope);
120
121 *fLog << "Normalization factor:" <<fN0 << endl;
122
123 //---
124 fEvt = (MMcEvt*)pList->FindObject("MMcEvt");
125 if (!fEvt)
126 {
127 *fLog << err << dbginf << fName << " [MMcEvt] not found... aborting." << endl;
128 return kFALSE;
129 }
130
131 return kTRUE;
132}
133
134// --------------------------------------------------------------------------
135//
136// Select events randomly according to the MC ("old") and required ("new")
137// energy slope.
138// Old E slope is fMcSlope
139// New E slope is set by the user (fval; fNewSlope)
140// If old and new energy slope are the same skip the selection.
141// The MC energy slope and lower and upper limits are taken from the
142// run header (requires reflector ver.>0.6 and camera ver.>0.6)
143//
144Int_t MFEnergySlope::Process()
145{
146 fResult = kTRUE;
147
148 // Energy slopes are the same: skip it
149 if (fNewSlope == fMcSlope)
150 return kTRUE;
151
152 // The value of the normalized spectrum is compared with a
153 // random value in [0,1];
154 // if the latter is higher the event is accepted
155 const Float_t energy = fEvt->GetEnergy();
156
157 /*
158 //
159 // If energy bounds different from MC ones are selected, then
160 // events outside these bounds are rejected, as their slope has
161 // not been changed.
162 //
163 if (energy > fMcMaxEnergy || energy < fMcMinEnergy)
164 {
165 fResult = kFALSE;
166 return kTRUE;
167 }
168 */
169
170 const Float_t Nexp = fN0 * pow(energy,fMcSlope-fNewSlope);
171 const Float_t Nrnd = gRandom->Uniform();
172
173 fResult = Nexp > Nrnd;
174
175 if (!fResult)
176 return kTRUE;
177
178 fNumSelectedEvts++;
179 return kTRUE;
180}
181
Note: See TracBrowser for help on using the repository browser.